下面列出了javafx.scene.layout.AnchorPane#setLeftAnchor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public InfoTextField() {
arrowLocation = PopOver.ArrowLocation.RIGHT_TOP;
textField = new BisqTextField();
textField.setLabelFloat(true);
textField.setEditable(false);
textField.textProperty().bind(text);
textField.setFocusTraversable(false);
textField.setId("info-field");
infoIcon = getIcon(AwesomeIcon.INFO_SIGN);
infoIcon.setLayoutY(5);
infoIcon.getStyleClass().addAll("icon", "info");
AnchorPane.setRightAnchor(infoIcon, 7.0);
AnchorPane.setRightAnchor(textField, 0.0);
AnchorPane.setLeftAnchor(textField, 0.0);
hideIcons();
getChildren().addAll(textField, infoIcon);
}
private void onSelectMinorStoppagesPareto() throws Exception {
List<ParetoItem> items = EquipmentLossManager.getParetoData(equipmentLoss, TimeLoss.MINOR_STOPPAGES);
Number divisor = equipmentLoss.getLoss(TimeLoss.MINOR_STOPPAGES).getSeconds();
StackPane spMinorStoppagesPareto = new StackPane();
AnchorPane.setBottomAnchor(spMinorStoppagesPareto, 0.0);
AnchorPane.setLeftAnchor(spMinorStoppagesPareto, 0.0);
AnchorPane.setRightAnchor(spMinorStoppagesPareto, 0.0);
AnchorPane.setTopAnchor(spMinorStoppagesPareto, 0.0);
apMinorStoppagesPareto.getChildren().clear();
apMinorStoppagesPareto.getChildren().add(0, spMinorStoppagesPareto);
ParetoChartController controller = new ParetoChartController();
controller.createParetoChart(DesignerLocalizer.instance().getLangString("stoppages.pareto"),
spMinorStoppagesPareto, items, divisor, DesignerLocalizer.instance().getLangString("time.by.reason"));
}
private void onSelectPlannedDowntimePareto() throws Exception {
List<ParetoItem> items = EquipmentLossManager.getParetoData(equipmentLoss, TimeLoss.PLANNED_DOWNTIME);
Number divisor = equipmentLoss.getLoss(TimeLoss.PLANNED_DOWNTIME).getSeconds();
StackPane spPlannedDowntimePareto = new StackPane();
AnchorPane.setBottomAnchor(spPlannedDowntimePareto, 0.0);
AnchorPane.setLeftAnchor(spPlannedDowntimePareto, 0.0);
AnchorPane.setRightAnchor(spPlannedDowntimePareto, 0.0);
AnchorPane.setTopAnchor(spPlannedDowntimePareto, 0.0);
apPlannedDowntimePareto.getChildren().clear();
apPlannedDowntimePareto.getChildren().add(0, spPlannedDowntimePareto);
ParetoChartController controller = new ParetoChartController();
controller.createParetoChart(DesignerLocalizer.instance().getLangString("planned.downtime.pareto"),
spPlannedDowntimePareto, items, divisor, DesignerLocalizer.instance().getLangString("time.by.reason"));
}
private Pane makeTitlePane(String title) {
HBox hbLeft = new HBox();
hbLeft.setSpacing(10d);
lblTitle = new Label();
lblTitle.textProperty().bind(titleProperty());
setTitle(title);
lblTitle.getStyleClass().add("internal-window-titlebar-title");
if (icon != null) { hbLeft.getChildren().add(icon); }
hbLeft.getChildren().add(lblTitle);
hbLeft.setAlignment(Pos.CENTER_LEFT);
AnchorPane.setLeftAnchor(hbLeft, 10d);
AnchorPane.setBottomAnchor(hbLeft, 0d);
AnchorPane.setRightAnchor(hbLeft, 20d);
AnchorPane.setTopAnchor(hbLeft, 0d);
return hbLeft;
}
/**
* Opens the Minimap / Mars Navigator
*/
public void openMinimap() {
desktop.openToolWindow(NavigatorWindow.NAME);
navWin.getGlobeDisplay().drawSphere();// updateDisplay();
AnchorPane.setLeftAnchor(minimapGroup, 3.0);
AnchorPane.setTopAnchor(minimapGroup, 0.0); // 45.0
boolean flag = false;
for (Node node : mapsAnchorPane.getChildrenUnmodifiable()) {
if (node == minimapGroup) {
flag = true;
break;
}
}
if (!flag)
mapsAnchorPane.getChildren().addAll(minimapGroup);
minimapGroup.toFront();
navWin.showSurfaceMap();
navWin.toFront();
navWin.requestFocus();
minimapToggle.setSelected(true);
minimapToggle.setText("Minimap On");
minimapToggle.toFront();
}
void showCronTrendDialog(EventResolver eventResolver) throws Exception {
// Load the fxml file and create a new stage for the pop-up dialog.
FXMLLoader loader = FXMLLoaderFactory.cronTrendLoader();
AnchorPane page = (AnchorPane) loader.getRoot();
// Create the dialog Stage.
Stage dialogStage = new Stage(StageStyle.DECORATED);
dialogStage.setTitle(DesignerLocalizer.instance().getLangString("cron.event.trend"));
dialogStage.initModality(Modality.NONE);
Scene scene = new Scene(page);
dialogStage.setScene(scene);
// get the controller
CronTrendController cronTrendController = loader.getController();
cronTrendController.setDialogStage(dialogStage);
cronTrendController.setApp(this);
// add the trend chart
SplitPane chartPane = cronTrendController.initializeTrend();
AnchorPane.setBottomAnchor(chartPane, 50.0);
AnchorPane.setLeftAnchor(chartPane, 5.0);
AnchorPane.setRightAnchor(chartPane, 5.0);
AnchorPane.setTopAnchor(chartPane, 50.0);
page.getChildren().add(0, chartPane);
// set the script resolver
cronTrendController.setEventResolver(eventResolver);
// start the job
cronTrendController.subscribeToDataSource();
// show the window
cronTrendController.getDialogStage().show();
}
private Axis createLeftYAxis(final double MIN, final double MAX, final boolean AUTO_SCALE) {
Axis axis = new Axis(Orientation.VERTICAL, Position.LEFT);
axis.setMinValue(MIN);
axis.setMaxValue(MAX);
axis.setPrefWidth(AXIS_WIDTH);
axis.setAutoScale(AUTO_SCALE);
AnchorPane.setTopAnchor(axis, 0d);
AnchorPane.setBottomAnchor(axis, 25d);
AnchorPane.setLeftAnchor(axis, 0d);
return axis;
}
private Axis createLeftYAxis(final double MIN, final double MAX, final boolean AUTO_SCALE) {
Axis axis = new Axis(Orientation.VERTICAL, Position.LEFT);
axis.setMinValue(MIN);
axis.setMaxValue(MAX);
axis.setPrefWidth(AXIS_WIDTH);
axis.setAutoScale(AUTO_SCALE);
AnchorPane.setTopAnchor(axis, 0d);
AnchorPane.setBottomAnchor(axis, 25d);
AnchorPane.setLeftAnchor(axis, 0d);
return axis;
}
private void configureTab(Tab tab, String title, String iconPath, AnchorPane containerPane, URL resourceURL, EventHandler<Event> onSelectionChangedEvent) {
double imageWidth = 40.0;
ImageView imageView = new ImageView(new Image(iconPath));
imageView.setFitHeight(imageWidth);
imageView.setFitWidth(imageWidth);
Label label = new Label(title);
label.setMaxWidth(tabWidth - 20);
label.setPadding(new Insets(5, 0, 0, 0));
label.setStyle("-fx-text-fill: black; -fx-font-size: 10pt; -fx-font-weight: bold;");
label.setTextAlignment(TextAlignment.CENTER);
BorderPane tabPane = new BorderPane();
tabPane.setRotate(90.0);
tabPane.setMaxWidth(tabWidth);
tabPane.setCenter(imageView);
tabPane.setBottom(label);
tab.setText("");
tab.setGraphic(tabPane);
tab.setOnSelectionChanged(onSelectionChangedEvent);
if (containerPane != null && resourceURL != null) {
try {
Parent contentView = FXMLLoader.load(resourceURL);
containerPane.getChildren().add(contentView);
AnchorPane.setTopAnchor(contentView, 0.0);
AnchorPane.setBottomAnchor(contentView, 0.0);
AnchorPane.setRightAnchor(contentView, 0.0);
AnchorPane.setLeftAnchor(contentView, 0.0);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void setOverlayTop(VBox progress) {
// TODO Auto-generated method stub
progressBar.getChildren().clear();
progressBar.getChildren().add(progress);
AnchorPane.setTopAnchor(progress, 0.0);
AnchorPane.setLeftAnchor(progress, 0.0);
AnchorPane.setRightAnchor(progress, 0.0);
AnchorPane.setBottomAnchor(progress, 0.0);
}
private Axis createBottomXAxis(final double MIN, final double MAX, final boolean AUTO_SCALE, final double AXIS_WIDTH) {
Axis axis = new Axis(Orientation.HORIZONTAL, Position.BOTTOM);
axis.setMinValue(MIN);
axis.setMaxValue(MAX);
axis.setPrefHeight(AXIS_WIDTH);
axis.setAutoScale(AUTO_SCALE);
AnchorPane.setBottomAnchor(axis, 0d);
AnchorPane.setLeftAnchor(axis, AXIS_WIDTH);
AnchorPane.setRightAnchor(axis, AXIS_WIDTH);
return axis;
}
private Axis createCenterXAxis(final double MIN, final double MAX, final boolean AUTO_SCALE, final double AXIS_WIDTH) {
Axis axis = new Axis(Orientation.HORIZONTAL, Position.CENTER);
axis.setMinValue(MIN);
axis.setMaxValue(MAX);
axis.setPrefHeight(AXIS_WIDTH);
axis.setAutoScale(AUTO_SCALE);
AnchorPane.setBottomAnchor(axis, axis.getZeroPosition());
AnchorPane.setLeftAnchor(axis, AXIS_WIDTH);
AnchorPane.setRightAnchor(axis, AXIS_WIDTH);
return axis;
}
@Override public void init() {
xAxisBottom = new Axis(0, 1000, Orientation.HORIZONTAL, AxisType.LOGARITHMIC, Position.BOTTOM);
xAxisBottom.setPrefHeight(20);
AnchorPane.setLeftAnchor(xAxisBottom, 20d);
AnchorPane.setRightAnchor(xAxisBottom, 20d);
AnchorPane.setBottomAnchor(xAxisBottom, 0d);
yAxisLeft = new Axis(0, 1000, Orientation.VERTICAL, AxisType.LOGARITHMIC, Position.LEFT);
yAxisLeft.setPrefWidth(20);
AnchorPane.setLeftAnchor(yAxisLeft, 0d);
AnchorPane.setTopAnchor(yAxisLeft, 20d);
AnchorPane.setBottomAnchor(yAxisLeft, 20d);
}
void showMQTTTrendDialog(EventResolver eventResolver) throws Exception {
// Load the fxml file
FXMLLoader loader = FXMLLoaderFactory.mqttTrendLoader();
AnchorPane page = (AnchorPane) loader.getRoot();
// Create the dialog Stage.
Stage dialogStage = new Stage(StageStyle.DECORATED);
dialogStage.setTitle(DesignerLocalizer.instance().getLangString("mqtt.event.trend"));
dialogStage.initModality(Modality.NONE);
Scene scene = new Scene(page);
dialogStage.setScene(scene);
// get the controller
MqttTrendController mqttTrendController = loader.getController();
mqttTrendController.setDialogStage(dialogStage);
mqttTrendController.setApp(this);
// add the trend chart
SplitPane chartPane = mqttTrendController.initializeTrend();
AnchorPane.setBottomAnchor(chartPane, 50.0);
AnchorPane.setLeftAnchor(chartPane, 5.0);
AnchorPane.setRightAnchor(chartPane, 5.0);
AnchorPane.setTopAnchor(chartPane, 50.0);
page.getChildren().add(0, chartPane);
// set the script resolver
mqttTrendController.setEventResolver(eventResolver);
// subscribe to broker
mqttTrendController.subscribeToDataSource();
// show the window
mqttTrendController.getDialogStage().show();
}
private Axis createLeftYAxis(final double MIN, final double MAX, final boolean AUTO_SCALE) {
Axis axis = new Axis(Orientation.VERTICAL, Position.LEFT);
axis.setMinValue(MIN);
axis.setMaxValue(MAX);
axis.setPrefWidth(AXIS_WIDTH);
axis.setAutoScale(AUTO_SCALE);
AnchorPane.setTopAnchor(axis, 0d);
AnchorPane.setBottomAnchor(axis, 25d);
AnchorPane.setLeftAnchor(axis, 0d);
return axis;
}
private Axis createLeftYAxis(final double MIN, final double MAX, final boolean AUTO_SCALE) {
Axis axis = new Axis(Orientation.VERTICAL, Position.LEFT);
axis.setMinValue(MIN);
axis.setMaxValue(MAX);
axis.setPrefWidth(AXIS_WIDTH);
axis.setAutoScale(AUTO_SCALE);
AnchorPane.setTopAnchor(axis, 0d);
AnchorPane.setBottomAnchor(axis, 25d);
AnchorPane.setLeftAnchor(axis, 0d);
return axis;
}
public BorderPaneSample() {
super(400, 400);
BorderPane borderPane = new BorderPane();
//Top content
Rectangle topRectangle = new Rectangle(400, 23, Color.DARKSEAGREEN);
topRectangle.setStroke(Color.BLACK);
borderPane.setTop(topRectangle);
//Left content
Label label1 = new Label("Left hand");
Label label2 = new Label("Choice One");
Label label3 = new Label("Choice Two");
Label label4 = new Label("Choice Three");
VBox leftVbox = new VBox();
leftVbox.getChildren().addAll(label1, label2, label3, label4);
borderPane.setLeft(leftVbox);
//Right content
Label rightlabel1 = new Label("Right hand");
Label rightlabel2 = new Label("Thing A");
Label rightlabel3 = new Label("Thing B");
VBox rightVbox = new VBox();
rightVbox.getChildren().addAll(rightlabel1, rightlabel2, rightlabel3);
borderPane.setRight(rightVbox);
//Center content
Label centerLabel = new Label("We're in the center area.");
ImageView imageView = new ImageView(ICON_48);
//Using AnchorPane only to position items in the center
AnchorPane centerAP = new AnchorPane();
AnchorPane.setTopAnchor(centerLabel, Double.valueOf(5));
AnchorPane.setLeftAnchor(centerLabel, Double.valueOf(20));
AnchorPane.setTopAnchor(imageView, Double.valueOf(40));
AnchorPane.setLeftAnchor(imageView, Double.valueOf(30));
centerAP.getChildren().addAll(centerLabel, imageView);
borderPane.setCenter(centerAP);
//Bottom content
Label bottomLabel = new Label("I am a status message, and I am at the bottom.");
borderPane.setBottom(bottomLabel);
getChildren().add(borderPane);
}
public static ListCell<TradeCurrency> getTradeCurrencyButtonCell(String postFixSingle,
String postFixMulti,
Map<String, Integer> offerCounts) {
return new ListCell<>() {
@Override
protected void updateItem(TradeCurrency item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
String code = item.getCode();
AnchorPane pane = new AnchorPane();
Label currency = new AutoTooltipLabel(code + " - " + item.getName());
currency.getStyleClass().add("currency-label-selected");
AnchorPane.setLeftAnchor(currency, 0.0);
pane.getChildren().add(currency);
Optional<Integer> offerCountOptional = Optional.ofNullable(offerCounts.get(code));
switch (code) {
case GUIUtil.SHOW_ALL_FLAG:
currency.setText(Res.get("list.currency.showAll"));
break;
case GUIUtil.EDIT_FLAG:
currency.setText(Res.get("list.currency.editList"));
break;
default:
if (offerCountOptional.isPresent()) {
Label numberOfOffers = new AutoTooltipLabel(offerCountOptional.get() + " " +
(offerCountOptional.get() == 1 ? postFixSingle : postFixMulti));
numberOfOffers.getStyleClass().add("offer-label-small");
AnchorPane.setRightAnchor(numberOfOffers, 0.0);
AnchorPane.setBottomAnchor(numberOfOffers, 2.0);
pane.getChildren().add(numberOfOffers);
}
}
setGraphic(pane);
setText("");
} else {
setGraphic(null);
setText("");
}
}
};
}
public BorderPaneSample() {
super(400, 400);
BorderPane borderPane = new BorderPane();
//Top content
Rectangle topRectangle = new Rectangle(400, 23, Color.DARKSEAGREEN);
topRectangle.setStroke(Color.BLACK);
borderPane.setTop(topRectangle);
//Left content
Label label1 = new Label("Left hand");
Label label2 = new Label("Choice One");
Label label3 = new Label("Choice Two");
Label label4 = new Label("Choice Three");
VBox leftVbox = new VBox();
leftVbox.getChildren().addAll(label1, label2, label3, label4);
borderPane.setLeft(leftVbox);
//Right content
Label rightlabel1 = new Label("Right hand");
Label rightlabel2 = new Label("Thing A");
Label rightlabel3 = new Label("Thing B");
VBox rightVbox = new VBox();
rightVbox.getChildren().addAll(rightlabel1, rightlabel2, rightlabel3);
borderPane.setRight(rightVbox);
//Center content
Label centerLabel = new Label("We're in the center area.");
ImageView imageView = new ImageView(ICON_48);
//Using AnchorPane only to position items in the center
AnchorPane centerAP = new AnchorPane();
AnchorPane.setTopAnchor(centerLabel, Double.valueOf(5));
AnchorPane.setLeftAnchor(centerLabel, Double.valueOf(20));
AnchorPane.setTopAnchor(imageView, Double.valueOf(40));
AnchorPane.setLeftAnchor(imageView, Double.valueOf(30));
centerAP.getChildren().addAll(centerLabel, imageView);
borderPane.setCenter(centerAP);
//Bottom content
Label bottomLabel = new Label("I am a status message, and I am at the bottom.");
borderPane.setBottom(bottomLabel);
getChildren().add(borderPane);
}
public void buildDashboardTiles() {
// OEE tile
bciOee = new BarChartItem(DesignerLocalizer.instance().getLangString("oee"), 0, Tile.BLUE);
bciOee.setFormatString(OEE_FORMAT);
bciPerformance = new BarChartItem(DesignerLocalizer.instance().getLangString("performance"), 0, Tile.GREEN);
bciPerformance.setFormatString(OEE_FORMAT);
bciAvailability = new BarChartItem(DesignerLocalizer.instance().getLangString("availability"), 0, Tile.RED);
bciAvailability.setFormatString(OEE_FORMAT);
bciQuality = new BarChartItem(DesignerLocalizer.instance().getLangString("quality"), 0, Tile.ORANGE);
bciQuality.setFormatString(OEE_FORMAT);
tiOee = TileBuilder.create().skinType(SkinType.BAR_CHART).prefSize(TILE_WIDTH, TILE_HEIGHT)
.title(DesignerLocalizer.instance().getLangString("oee.title"))
.barChartItems(bciOee, bciAvailability, bciPerformance, bciQuality).decimals(0).sortedData(false)
.animated(false).build();
// production tile
lbiGoodProduction = new LeaderBoardItem(DesignerLocalizer.instance().getLangString("good"), 0);
lbiRejectProduction = new LeaderBoardItem(DesignerLocalizer.instance().getLangString("reject"), 0);
lbiStartupProduction = new LeaderBoardItem(DesignerLocalizer.instance().getLangString("startup"), 0);
String productionText = DesignerLocalizer.instance().getLangString("quantity.change");
tiProduction = TileBuilder.create().skinType(SkinType.LEADER_BOARD).prefSize(TILE_WIDTH, TILE_HEIGHT)
.title(DesignerLocalizer.instance().getLangString("current.production")).text(productionText)
.leaderBoardItems(lbiGoodProduction, lbiRejectProduction, lbiStartupProduction).sortedData(false)
.animated(false).build();
// availability tile
tiAvailability = TileBuilder.create().skinType(SkinType.TEXT).prefSize(TILE_WIDTH, TILE_HEIGHT)
.title(DesignerLocalizer.instance().getLangString("availability")).textVisible(true)
.descriptionAlignment(Pos.CENTER).build();
tiAvailability.setDescriptionTextSize(TextSize.BIGGER);
// material and job
tiJobMaterial = TileBuilder.create().skinType(SkinType.TEXT).prefSize(TILE_WIDTH, TILE_HEIGHT)
.title(DesignerLocalizer.instance().getLangString("material.title")).textVisible(true)
.descriptionAlignment(Pos.CENTER).build();
tiJobMaterial.setDescriptionTextSize(TextSize.NORMAL);
tiJobMaterial.setDescriptionColor(Color.WHITE);
// time losses
tiLoss = TileBuilder.create().skinType(SkinType.DONUT_CHART).prefSize(TILE_WIDE, TILE_HEIGHT)
.title(DesignerLocalizer.instance().getLangString("loss.time")).textVisible(true).animated(true)
.sortedData(false).build();
FlowGridPane pane = new FlowGridPane(5, 1, tiOee, tiProduction, tiAvailability, tiJobMaterial, tiLoss);
pane.setHgap(TILE_VGAP);
pane.setVgap(TILE_HGAP);
pane.setAlignment(Pos.CENTER);
pane.setCenterShape(true);
pane.setPadding(new Insets(5));
pane.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
apTileLayout.getChildren().add(pane);
AnchorPane.setTopAnchor(pane, 0.0);
AnchorPane.setBottomAnchor(pane, 0.0);
AnchorPane.setLeftAnchor(pane, 0.0);
AnchorPane.setRightAnchor(pane, 0.0);
}