下面列出了怎么用javafx.geometry.Side的API类实例代码及写法,或者点击链接到github查看源代码。
public void onViewMemory(Event event) {
// if (memoryStage == null) {
// memoryStage = FxUtils.newStage(null, "内存查看",
// "memory.fxml", "main.css");
// }
// memoryStage.show();
// memoryStage.toFront();
if (machine.getRomFile() == null) {
onViewRAM(event);
} else {
MenuItem ramViewItem = new MenuItem("查看RAM");
ramViewItem.setOnAction(event1 -> onViewRAM(event1));
MenuItem romViewItem = new MenuItem("查看ROM");
romViewItem.setOnAction(event1 -> onViewROM(event1));
new ContextMenu(ramViewItem, romViewItem).show(memoryButton, Side.TOP, 0, 0);
}
}
@Override
@SneakyThrows
public Tab getRoot(RequestContainer request) {
val script = request.getAspect(ScriptingAspect.class).get();
Tab preTab = getTab(script::getPreRequestScript, script::setPreRequestScript, "Before Request");
Tab postTab = getTab(script::getPostRequestScript, script::setPostRequestScript, "After Request");
TabPane tabs = new TabPane(preTab, postTab);
tabs.getSelectionModel().select(1); //default to show after request script
tabs.setSide(Side.LEFT);
tabs.getStyleClass().add("options-tabs");
tabs.tabMinWidthProperty().setValue(20);
tabs.tabMaxWidthProperty().setValue(20);
tabs.tabMinHeightProperty().setValue(150);
tabs.tabMaxHeightProperty().setValue(150);
tabs.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
return new Tab("Scripting", tabs);
}
public MediaService() {
MobileApplication.getInstance().addLayerFactory(POPUP_NAME, () -> {
imageView = new ImageView();
imageView.setFitHeight(50);
imageView.setPreserveRatio(true);
HBox adsBox = new HBox(imageView);
adsBox.getStyleClass().add("mediaBox");
return new SidePopupView(adsBox, Side.BOTTOM, false);
});
Services.get(LifecycleService.class).ifPresent(service -> {
service.addListener(LifecycleEvent.PAUSE, this::stopExecutor);
service.addListener(LifecycleEvent.RESUME, this::startExecutor);
});
startExecutor();
}
private void updateBottomLine() {
if (Side.TOP == side) {
borderPane.setTop(hBox);
hBox.setMinHeight(bottomLineSize);
} else if (Side.RIGHT == side) {
borderPane.setRight(hBox);
hBox.setMinWidth(bottomLineSize);
} else if (Side.BOTTOM == side) {
borderPane.setBottom(hBox);
hBox.setMinHeight(bottomLineSize);
} else if (Side.LEFT == side) {
borderPane.setLeft(hBox);
hBox.setMinWidth(bottomLineSize);
} else {
borderPane.setBottom(hBox);
hBox.setMinHeight(bottomLineSize);
}
}
public void selected(int index) {
Node node = null;
if (Side.TOP == side) {
node = hBox.getChildren().get(index);
} else if (Side.RIGHT == side) {
node = vBox.getChildren().get(index);
} else if (Side.BOTTOM == side) {
node = hBox.getChildren().get(index);
} else if (Side.LEFT == side) {
node = vBox.getChildren().get(index);
} else {
node = hBox.getChildren().get(index);
}
if (node instanceof FlatTab) {
FlatTab tabTemp = (FlatTab) node;
selected(tabTemp);
}
}
public void setSide(Side side) {
if (Side.TOP == side) {
borderPane.setTop(hBox);
hBox.setMinHeight(2);
} else if (Side.RIGHT == side) {
borderPane.setRight(hBox);
hBox.setMinWidth(2);
} else if (Side.BOTTOM == side) {
borderPane.setBottom(hBox);
hBox.setMinHeight(2);
} else if (Side.LEFT == side) {
borderPane.setLeft(hBox);
hBox.setMinWidth(2);
} else {
borderPane.setBottom(hBox);
hBox.setMinHeight(2);
}
}
private void init() {
this.setCenter(rootPane);
this.setTitle("组件测试");
this.setWidth(380);
this.setHeight(600);
this.setRadius(10);
VBox topBox = new VBox();
topBox.setPrefHeight(50);
HBox hBox=new HBox();
hBox.getChildren().add(button);
rootPane.setTop(topBox);
rootPane.setBottom(hBox);
button.setOnAction(a->{
menu.show(button, Side.TOP, button.getLayoutX(), button.getLayoutY());
});
}
@Test
void showDrawerInputValidation() {
robot.interact(() -> {
// null check
assertThrows(NullPointerException.class, () -> workbench.showDrawer(drawer, null, 0));
assertThrows(NullPointerException.class, () -> workbench.showDrawer(null, Side.LEFT, 0));
// Percentage range
assertThrows(IllegalArgumentException.class,
() -> workbench.showDrawer(drawer, Side.LEFT, Integer.MIN_VALUE));
assertThrows(IllegalArgumentException.class,
() -> workbench.showDrawer(drawer, Side.LEFT, -2));
workbench.showDrawer(drawer, Side.LEFT, -1); // valid
workbench.showDrawer(drawer, Side.LEFT, 0); // valid
workbench.showDrawer(drawer, Side.LEFT, 1); // valid
workbench.showDrawer(drawer, Side.LEFT, 100); // valid
assertThrows(IllegalArgumentException.class,
() -> workbench.showDrawer(drawer, Side.LEFT, 101));
assertThrows(IllegalArgumentException.class,
() -> workbench.showDrawer(drawer, Side.LEFT, Integer.MAX_VALUE));
});
}
@Test
void hideDrawerGlassPaneClick() {
robot.interact(() -> {
// given
assertTrue(workbench.getBlockingOverlaysShown().isEmpty());
assertTrue(workbench.getNonBlockingOverlaysShown().isEmpty());
assertNull(workbench.getDrawerShown());
workbench.showDrawer(drawer, Side.LEFT);
// when:
simulateGlassPaneClick(drawer);
// then: drawer is hidden
assertTrue(workbench.getBlockingOverlaysShown().isEmpty());
assertTrue(workbench.getNonBlockingOverlaysShown().isEmpty());
assertNull(workbench.getDrawerShown());
});
}
/**
* {@inheritDoc}
*/
@Override
public void layoutParts() {
// but always add the categoryController
contentBox.getChildren().addAll(breadCrumbView, categoryController);
VBox.setVgrow(categoryController, Priority.ALWAYS);
if (!model.isOneCategoryLayout()) {
preferencesPane.setDetailSide(Side.LEFT);
preferencesPane.setDetailNode(navigationView);
preferencesPane.setMasterNode(contentBox);
setCenter(preferencesPane);
} else {
setCenter(new StackPane(contentBox));
}
}
public static LabeledHorizontalBarChart create(boolean displayCategoryAxis, ChartCoordinate chartCoordinate) {
CategoryAxis categoryAxis = new CategoryAxis();
categoryAxis.setSide(Side.LEFT);
categoryAxis.setTickLabelsVisible(displayCategoryAxis);
categoryAxis.setGapStartAndEnd(true);
NumberAxis numberAxis = new NumberAxis();
numberAxis.setSide(Side.TOP);
switch (chartCoordinate) {
case LogarithmicE:
numberAxis.setTickLabelFormatter(new LogarithmicECoordinate());
break;
case Logarithmic10:
numberAxis.setTickLabelFormatter(new Logarithmic10Coordinate());
break;
case SquareRoot:
numberAxis.setTickLabelFormatter(new SquareRootCoordinate());
break;
}
return new LabeledHorizontalBarChart(numberAxis, categoryAxis)
.setChartCoordinate(chartCoordinate);
}
public static LabeledBarChart create(boolean displayCategoryAxis, ChartCoordinate chartCoordinate) {
CategoryAxis categoryAxis = new CategoryAxis();
categoryAxis.setSide(Side.BOTTOM);
categoryAxis.setTickLabelsVisible(displayCategoryAxis);
categoryAxis.setGapStartAndEnd(true);
NumberAxis numberAxis = new NumberAxis();
numberAxis.setSide(Side.LEFT);
switch (chartCoordinate) {
case LogarithmicE:
numberAxis.setTickLabelFormatter(new LogarithmicECoordinate());
break;
case Logarithmic10:
numberAxis.setTickLabelFormatter(new Logarithmic10Coordinate());
break;
case SquareRoot:
numberAxis.setTickLabelFormatter(new SquareRootCoordinate());
break;
}
return new LabeledBarChart(categoryAxis, numberAxis)
.setChartCoordinate(chartCoordinate);
}
private DemoTab(String title, String sourceFile) throws Exception {
super(title);
setClosable(false);
TabPane content = new TabPane();
setContent(content);
content.setSide(Side.BOTTOM);
Tab widgets = new Tab("Widgets");
widgets.setClosable(false);
URL location = getClass().getResource(sourceFile);
FXMLLoader fxmlLoader = new FXMLLoader(location);
Node node = fxmlLoader.load();
widgets.setContent(node);
Tab source = new Tab("Source");
source.setClosable(false);
XMLEditor editor = new XMLEditor();
editor.setEditable(false);
String text = IOUtils.toString(getClass().getResourceAsStream(sourceFile));
editor.setText(text);
source.setContent(editor);
content.getTabs().addAll(widgets, source);
}
protected ScatterChart<Number, Number> createChart() {
final NumberAxis xAxis = new NumberAxis();
xAxis.setSide(Side.TOP);
final NumberAxis yAxis = new NumberAxis();
yAxis.setSide(Side.RIGHT);
final ScatterChart<Number,Number> sc = new ScatterChart<Number,Number>(xAxis,yAxis);
// setup chart
xAxis.setLabel("X Axis");
yAxis.setLabel("Y Axis");
// add starting data
for (int s=0;s<5;s++) {
XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
series.setName("Data Series "+s);
for (int i=0; i<30; i++) series.getData().add(new XYChart.Data<Number, Number>(Math.random()*98, Math.random()*98));
sc.getData().add(series);
}
return sc;
}
/**
* Handle a mouse click.
*/
@FxThread
private void processClick(@NotNull final MouseEvent event) {
final TreeNode<?> item = getItem();
if (item == null) {
return;
}
final MouseButton button = event.getButton();
if (button != MouseButton.SECONDARY) {
return;
}
final M nodeTree = getNodeTree();
final ContextMenu contextMenu = nodeTree.getContextMenu(item);
if (contextMenu == null) {
return;
}
EXECUTOR_MANAGER.addFxTask(() -> contextMenu.show(this, Side.BOTTOM, 0, 0));
}
protected ScatterChart<Number, Number> createChart() {
final NumberAxis xAxis = new NumberAxis();
xAxis.setSide(Side.TOP);
final NumberAxis yAxis = new NumberAxis();
yAxis.setSide(Side.RIGHT);
final ScatterChart<Number,Number> sc = new ScatterChart<Number,Number>(xAxis,yAxis);
// setup chart
xAxis.setLabel("X Axis");
yAxis.setLabel("Y Axis");
// add starting data
for (int s=0;s<5;s++) {
XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
series.setName("Data Series "+s);
for (int i=0; i<30; i++) series.getData().add(new XYChart.Data<Number, Number>(Math.random()*98, Math.random()*98));
sc.getData().add(series);
}
return sc;
}
public DownArrowMenu(@NotNull Image arrowImg, @NotNull MenuItem... items) {
ImageView img = new ImageView(arrowImg);
img.setOnMouseEntered(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (popupMenu.isShowing()) {
return;
}
popupMenu.show(DownArrowMenu.this, Side.BOTTOM, 0, 0);
}
});
popupMenu.setAutoHide(true);
getItems().addAll(items);
setAlignment(Pos.CENTER_LEFT);
getChildren().add(img);
}
public ConfigurationPane(final ImportController importController) {
this.importController = importController;
setMaxHeight(Double.MAX_VALUE);
setMaxWidth(Double.MAX_VALUE);
setMinSize(0, 0);
// Add the tab pane that will hold a tab for each run
tabPane = new TabPane();
tabPane.setMaxHeight(Double.MAX_VALUE);
tabPane.setSide(Side.TOP);
AnchorPane.setTopAnchor(tabPane, 5.0);
AnchorPane.setLeftAnchor(tabPane, 5.0);
AnchorPane.setRightAnchor(tabPane, 5.0);
AnchorPane.setBottomAnchor(tabPane, 5.0);
getChildren().add(tabPane);
// Create a button to allow the user to add a new tab (RunPane).
Button newRunButton = new Button("", new ImageView(ADD_IMAGE));
newRunButton.setOnAction((ActionEvent event) -> {
importController.createNewRun();
});
AnchorPane.setTopAnchor(newRunButton, 10.0);
AnchorPane.setRightAnchor(newRunButton, 10.0);
getChildren().add(newRunButton);
// Add a single run to start with
createTab();
}
/**
* Gets the side corresponding to the currently selected connector position in the menu.
*
* @return the {@link Side} corresponding to the currently selected connector position
*/
private Side getSelectedConnectorPosition() {
if (leftConnectorPositionButton.isSelected()) {
return Side.LEFT;
} else if (rightConnectorPositionButton.isSelected()) {
return Side.RIGHT;
} else if (topConnectorPositionButton.isSelected()) {
return Side.TOP;
} else {
return Side.BOTTOM;
}
}
/**
* @param edge which side crossing is wanted.
* @return crossing coordinates (already) normalized to [0.0..1.0].
*/
public float[] getXY(final Side edge) {
switch (edge) {
case BOTTOM:
return new float[] { bottom, 0.0F };
case LEFT:
return new float[] { 0.0F, left };
case RIGHT:
return new float[] { 1.0F, right };
case TOP:
return new float[] { top, 1.0F };
default:
throw new IllegalStateException("getXY: N/A w/o a non-trivial edge");
}
}
private void configureYAxis(NumberAxis axis) {
configureAxis(axis);
axis.setForceZeroInRange(true);
axis.setTickLabelGap(5);
axis.setSide(Side.RIGHT);
}
/**
* Draws the tail based additionally on the sides of the nodes it starts and ends at.
*
* @param start the start position of the tail
* @param end the end position of the tail
* @param target the connector the tail is attaching to
*/
private void drawSmart(final Point2D start, final Point2D end, final GConnector target) {
clearPoints();
addPoint(start);
final Side startSide = DefaultConnectorTypes.getSide(getConnector().getType());
final Side endSide = DefaultConnectorTypes.getSide(target.getType());
final List<Point2D> points = RectangularPathCreator.createPath(start, end, startSide, endSide);
points.stream().forEachOrdered(point -> addPoint(point));
addPoint(end);
}
public void addSeries(final XYChart.Series<Number, Number> series, final Color lineColor) {
final NumberAxis yAxis = new NumberAxis();
final NumberAxis xAxis = new NumberAxis();
// style x-axis
xAxis.setAutoRanging(false);
xAxis.setVisible(false);
xAxis.setOpacity(0.0); // somehow the upper setVisible does not work
xAxis.lowerBoundProperty().bind(((NumberAxis) baseChart.getXAxis()).lowerBoundProperty());
xAxis.upperBoundProperty().bind(((NumberAxis) baseChart.getXAxis()).upperBoundProperty());
xAxis.tickUnitProperty().bind(((NumberAxis) baseChart.getXAxis()).tickUnitProperty());
// style y-axis
yAxis.setSide(Side.RIGHT);
yAxis.setLabel(series.getName());
// create chart
final LineChart<Number, Number> lineChart = new LineChart<>(xAxis, yAxis);
lineChart.setAnimated(false);
lineChart.setLegendVisible(false);
lineChart.getData().add(series);
styleBackgroundChart(lineChart, lineColor);
setFixedAxisWidth(lineChart);
chartColorMap.put(lineChart, lineColor);
backgroundCharts.add(lineChart);
}
@Override
public void init() {
stateManager.setPersistenceMode(StateManager.PersistenceMode.USER);
tabs.setSide(Side.BOTTOM);
stateManager.getPropertyAsString("repoLocations").ifPresent(s -> {
String locations = s.trim();
if (locations.length() > 0) {
for (String location : locations.split(",")) {
openRepo(new File(location));
}
}
});
}
public void setTabPadding(Insets value) {
if (Side.TOP == side) {
hBox.setPadding(value);
} else if (Side.RIGHT == side) {
vBox.setPadding(value);
} else if (Side.BOTTOM == side) {
hBox.setPadding(value);
} else if (Side.LEFT == side) {
vBox.setPadding(value);
} else {
hBox.setPadding(value);
}
}
private void initComponent() {
StackPane stackPane = new StackPane();
this.getChildren().add(borderPane);
borderPane.setCenter(stackPane);
// borderPane.setBottom(hBox);
// // vbox.getChildren().add(stackPane);
//
// // this.getChildren().add(imageButton);
// hBox.setMinHeight(2);
stackPane.getChildren().add(imageButton);
imageButton.getStyleClass().clear();
imageButton.setBackground(Background.EMPTY);
imageButton.setBorder(Border.EMPTY);
imageButton.setFocusTraversable(false);
imageButton.setGraphic(imageView);
hBox.setStyle("-fx-background-color:rgba(194, 194, 173, 1)");
// imageButton.setOnAction(new EventHandler() {
// @Override
// public void handle(Event event) {
//
// }
// });
// setStyle("-fx-background-color:rgba(0, 0, 0, 1);");
setSide(Side.BOTTOM);
}
/**
* Repaints the tile image that depends on the grid cell size only. The tile
* image is repeated when repainting the grid.
*/
protected void repaintGrid() {
Image tile = createGridTile();
// create a background fill for this node from the tile image
BackgroundPosition backgroundPosition = new BackgroundPosition(
Side.LEFT, 0, false, Side.TOP, 0, false);
BackgroundImage backgroundImage = new BackgroundImage(tile,
BackgroundRepeat.REPEAT, BackgroundRepeat.REPEAT,
backgroundPosition, BackgroundSize.DEFAULT);
Background background = new Background(backgroundImage);
// apply that background fill
grid.setBackground(background);
}
private void setupEventHandlers() {
// Map
MapDrawer drawer = new MapDrawer();
leftBtn.setOnAction(event -> {
getWorkbench().showDrawer(drawer, Side.LEFT);
});
rightBtn.setOnAction(event -> getWorkbench().showDrawer(new MapDrawer(), Side.RIGHT));
topBtn.setOnAction(event -> getWorkbench().showDrawer(new MapDrawer(), Side.TOP));
bottomBtn.setOnAction(event -> getWorkbench().showDrawer(new MapDrawer(), Side.BOTTOM));
leftPercentBtn.setOnAction(event -> getWorkbench().showDrawer(new MapDrawer(), Side.LEFT, 33));
rightPercentBtn.setOnAction(
event -> getWorkbench().showDrawer(new MapDrawer(), Side.RIGHT, 33));
topPercentBtn.setOnAction(event -> getWorkbench().showDrawer(new MapDrawer(), Side.TOP, 33));
bottomPercentBtn.setOnAction(
event -> getWorkbench().showDrawer(new MapDrawer(), Side.BOTTOM, 33));
// Calendar
calendarLeftBtn.setOnAction(
event -> getWorkbench().showDrawer(new CalendarDrawer(getWorkbench()), Side.LEFT));
calendarRightBtn.setOnAction(
event -> getWorkbench().showDrawer(new CalendarDrawer(getWorkbench()), Side.RIGHT));
calendarTopBtn.setOnAction(
event -> getWorkbench().showDrawer(new CalendarDrawer(getWorkbench()), Side.TOP));
calendarBottomBtn.setOnAction(
event -> getWorkbench().showDrawer(new CalendarDrawer(getWorkbench()), Side.BOTTOM));
calendarLeftPercentBtn.setOnAction(
event -> getWorkbench().showDrawer(new CalendarDrawer(getWorkbench()), Side.LEFT, 33));
calendarRightPercentBtn.setOnAction(
event -> getWorkbench().showDrawer(new CalendarDrawer(getWorkbench()), Side.RIGHT, 33));
calendarTopPercentBtn.setOnAction(
event -> getWorkbench().showDrawer(new CalendarDrawer(getWorkbench()), Side.TOP, 33));
calendarBottomPercentBtn.setOnAction(
event -> getWorkbench().showDrawer(new CalendarDrawer(getWorkbench()), Side.BOTTOM, 33));
}
private MenuButton buildSubmenu(MenuItem item) {
Menu menu = (Menu) item;
MenuButton menuButton = new MenuButton();
menuButton.setPopupSide(Side.RIGHT);
menuButton.graphicProperty().bind(menu.graphicProperty());
menuButton.textProperty().bind(menu.textProperty());
menuButton.disableProperty().bind(menu.disableProperty());
menuButton.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
menuButton.getStyleClass().addAll(item.getStyleClass());
Bindings.bindContent(menuButton.getItems(), menu.getItems());
// To determine if a TOUCH_RELEASED event happens.
// The MOUSE_ENTERED results in an unexpected behaviour on touch events.
// Event filter triggers before the handler.
menuButton.addEventFilter(TouchEvent.TOUCH_RELEASED, e -> isTouchUsed = true);
// Only when ALWAYS or SOMETIMES
if (!Priority.NEVER.equals(getSkinnable().getMenuHoverBehavior())) {
menuButton.addEventHandler(MouseEvent.MOUSE_ENTERED, e -> { // Triggers on hovering over Menu
if (isTouchUsed) {
isTouchUsed = false;
return;
}
// When ALWAYS, then trigger immediately. Else check if clicked before (case: SOMETIMES)
if (Priority.ALWAYS.equals(getSkinnable().getMenuHoverBehavior())
|| (hoveredBtn != null && hoveredBtn.isShowing())) {
menuButton.show(); // Shows the context-menu
if (hoveredBtn != null && hoveredBtn != menuButton) {
hoveredBtn.hide(); // Hides the previously hovered Button if not null and not self
}
}
hoveredBtn = menuButton; // Add the button as previously hovered
});
}
return menuButton;
}
/**
* Handles the initial animation of an overlay.
*
* <p>An overlay will have a default size of {@code 0}, when it is <b>first being shown</b> by
* {@link WorkbenchPresenter#showOverlay(Region, boolean)}, because it has not been added to the
* scene graph or a layout pass has not been performed yet. This means the animation won't be
* played by {@link WorkbenchPresenter#showOverlay(Region, boolean)} as well.<br>
* For this reason, we wait for the {@link WorkbenchOverlay} to be initialized and then initially
* set the coordinates of the overlay to be outside of the {@link Scene}, followed by playing the
* initial starting animation.<br>
* Any subsequent calls which show this {@code workbenchOverlay} again will <b>not</b> cause this
* to trigger again, as the {@link Event} of {@link WorkbenchOverlay#onInitializedProperty()}
* will only be fired once, since calling {@link Workbench#hideOverlay(Region)} only makes the
* overlays not visible, which means the nodes remain with their size already initialized in the
* scene graph.
*
* @param workbenchOverlay for which to prepare the initial animation handler for
* @param side from which the sliding animation should originate
*/
private void addInitialAnimationHandler(WorkbenchOverlay workbenchOverlay, Side side) {
Region overlay = workbenchOverlay.getOverlay();
// prepare values for setting the listener
ReadOnlyDoubleProperty size =
side.isVertical() ? overlay.widthProperty() : overlay.heightProperty();
// LEFT or RIGHT side TOP or BOTTOM side
// make sure this code only gets run the first time the overlay has been shown and
// rendered in the scene graph, to ensure the overlay has a size for the calculations
workbenchOverlay.setOnInitialized(event -> {
// prepare variables
TranslateTransition start = workbenchOverlay.getAnimationStart();
TranslateTransition end = workbenchOverlay.getAnimationEnd();
DoubleExpression hiddenCoordinate = DoubleBinding.doubleExpression(size);
if (Side.LEFT.equals(side) || Side.TOP.equals(side)) {
hiddenCoordinate = hiddenCoordinate.negate(); // make coordinates in hidden state negative
}
if (side.isVertical()) { // LEFT or RIGHT => X
overlay.setTranslateX(hiddenCoordinate.get()); // initial position
start.setToX(0);
if (!end.toXProperty().isBound()) {
end.toXProperty().bind(hiddenCoordinate);
}
}
if (side.isHorizontal()) { // TOP or BOTTOM => Y
overlay.setTranslateY(hiddenCoordinate.get()); // initial position
start.setToY(0);
if (!end.toYProperty().isBound()) {
end.toYProperty().bind(hiddenCoordinate);
}
}
start.play();
});
}