下面列出了javafx.scene.control.SeparatorMenuItem#javafx.scene.layout.Region 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected StructuredListCellSkin(StructuredListCell control) {
super(control);
getSkinnable().leftContentProperty().addListener(e -> updateContent());
getSkinnable().centerContentProperty().addListener(e -> updateContent());
getSkinnable().rightContentProperty().addListener(e -> updateContent());
updateContent();
leftContentAlignment = CssHelper.createProperty(StyleableProperties.LEFT_CONTENT_ALIGNMENT, this);
rightContentAlignment = CssHelper.createProperty(StyleableProperties.RIGHT_CONTENT_ALIGNMENT, this);
centerContentAlignment = CssHelper.createProperty(StyleableProperties.CENTER_CONTENT_ALIGNMENT, this);
spacing = CssHelper.createProperty(StyleableProperties.SPACING, this);
componentForPrefHeight = CssHelper.createProperty(StyleableProperties.CONTENT_FOR_PREF_HEIGHT, this);
getSkinnable().itemProperty().addListener(e -> {
updateVisibility();
});
getSkinnable().setMaxHeight(Region.USE_PREF_SIZE);
getSkinnable().setMinHeight(Region.USE_PREF_SIZE);
}
@Spawns("cardPlaceholder")
public Entity newPlaceholder(SpawnData data) {
var bg = new Region();
bg.setPrefSize(CARD_WIDTH, CARD_HEIGHT);
bg.setStyle(
"-fx-background-color: gold;" +
"-fx-border-color: black;" +
"-fx-border-width: 5;" +
"-fx-border-style: segments(10, 15, 15, 15) line-cap round;"
);
var text = getUIFactory().newText(data.get("isPlayer") ? "+" : "?", Color.WHITE, 76);
text.setStroke(Color.BLACK);
text.setStrokeWidth(2);
return entityBuilder()
.from(data)
.view(new StackPane(bg, text))
.build();
}
private HBox getCountryItem(final Flag flag, final String text, final String data) {
ImageView imageView = new ImageView(flag.getImage(22));
HBox.setHgrow(imageView, Priority.NEVER);
Label name = new Label(text);
name.setTextFill(Tile.FOREGROUND);
name.setAlignment(Pos.CENTER_LEFT);
HBox.setHgrow(name, Priority.NEVER);
Region spacer = new Region();
spacer.setPrefSize(5, 5);
HBox.setHgrow(spacer, Priority.ALWAYS);
Label views = new Label(data);
views.setTextFill(Tile.FOREGROUND);
views.setAlignment(Pos.CENTER_RIGHT);
HBox.setHgrow(views, Priority.NEVER);
HBox hBox = new HBox(5, imageView, name, spacer, views);
hBox.setAlignment(Pos.CENTER_LEFT);
hBox.setFillHeight(true);
return hBox;
}
private void initCheckList() {
ToolBar toolBar = new ToolBar();
toolBar.getItems().add(new Text("Check Lists"));
toolBar.setMinWidth(Region.USE_PREF_SIZE);
leftPane.setTop(toolBar);
checkListElements = checkListInfo.getCheckListElements();
checkListView = new ListView<CheckListForm.CheckListElement>(checkListElements);
checkListView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
CheckListElement selectedItem = checkListView.getSelectionModel().getSelectedItem();
if (selectedItem == null) {
doneButton.setDisable(true);
return;
}
Node checkListForm = getChecklistFormNode(selectedItem, Mode.DISPLAY);
if (checkListForm == null) {
doneButton.setDisable(true);
return;
}
doneButton.setDisable(false);
ScrollPane sp = new ScrollPane(checkListForm);
sp.setFitToWidth(true);
sp.setPadding(new Insets(0, 0, 0, 10));
rightPane.setCenter(sp);
});
leftPane.setCenter(checkListView);
}
@Test
public void test_minimumSize_Region() {
/*
* This test ensures that Bugzilla #512620 is not re-introduced by a
* later change.
*/
// check resize policy is reset
assertEquals(0d, resizePolicy.getDeltaWidth(), 0.01);
assertEquals(0d, resizePolicy.getDeltaHeight(), 0.01);
// set region's min-size to USE_COMPUTED_SIZE
Region region = (Region) resizePolicy.getHost().getVisual();
region.setMinSize(Region.USE_COMPUTED_SIZE, Region.USE_COMPUTED_SIZE);
assertEquals(Region.USE_COMPUTED_SIZE, region.getMinWidth(), 0.01);
assertEquals(Region.USE_COMPUTED_SIZE, region.getMinHeight(), 0.01);
// resize below minimum size using ResizePolicy
resizePolicy.resize(region.minWidth(-1) - 5, region.minHeight(-1) - 5);
// ensure minimum size is respected
assertEquals(region.minWidth(-1), resizePolicy.getDeltaWidth(), 0.01);
assertEquals(region.minHeight(-1), resizePolicy.getDeltaHeight(), 0.01);
}
@Spawns("cardPlaceholder")
public Entity newPlaceholder(SpawnData data) {
var bg = new Region();
bg.setPrefSize(CARD_WIDTH, CARD_HEIGHT);
bg.setStyle(
"-fx-background-color: gold;" +
"-fx-border-color: black;" +
"-fx-border-width: 5;" +
"-fx-border-style: segments(10, 15, 15, 15) line-cap round;"
);
var text = getUIFactory().newText(data.get("isPlayer") ? "+" : "?", Color.WHITE, 76);
text.setStroke(Color.BLACK);
text.setStrokeWidth(2);
return entityBuilder()
.from(data)
.view(new StackPane(bg, text))
.build();
}
@Override
public Node apply(Region region, Wrapper<Point2D> mouseLocation) {
final DoubleProperty xProperty = region.layoutXProperty();
final DoubleProperty yProperty = region.layoutYProperty();
final ReadOnlyDoubleProperty widthProperty = region.prefWidthProperty();
final ReadOnlyDoubleProperty heightProperty = region.prefHeightProperty();
final DoubleBinding halfHeightProperty = heightProperty.divide(2);
final Rectangle resizeHandleE = new Rectangle(handleRadius, handleRadius, Color.BLACK);
resizeHandleE.xProperty().bind(xProperty.add(widthProperty).subtract(handleRadius / 2));
resizeHandleE.yProperty().bind(yProperty.add(halfHeightProperty).subtract(handleRadius / 2));
setUpDragging(resizeHandleE, mouseLocation, Cursor.E_RESIZE);
resizeHandleE.setOnMouseDragged(event -> {
if(mouseLocation.value != null) {
dragEast(event, mouseLocation, region, handleRadius);
mouseLocation.value = new Point2D(event.getSceneX(), event.getSceneY());
}
});
return resizeHandleE;
}
private void initialize() {
this.setVisible(false);
this.getStyleClass().add(DEFAULT_STYLE_CLASS);
this.transitionType.addListener((o, oldVal, newVal) -> {
animation = getShowAnimation(transitionType.get());
});
contentHolder = new StackPane();
contentHolder.setBackground(new Background(new BackgroundFill(Color.WHITE, new CornerRadii(2), null)));
JFXDepthManager.setDepth(contentHolder, 4);
contentHolder.setPickOnBounds(false);
// ensure stackpane is never resized beyond it's preferred size
contentHolder.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
this.getChildren().add(contentHolder);
this.getStyleClass().add("jfx-dialog-overlay-pane");
StackPane.setAlignment(contentHolder, Pos.CENTER);
this.setBackground(new Background(new BackgroundFill(Color.rgb(0, 0, 0, 0.1), null, null)));
// close the dialog if clicked on the overlay pane
if (overlayClose.get()) {
this.addEventHandler(MouseEvent.MOUSE_PRESSED, closeHandler);
}
// prevent propagating the events to overlay pane
contentHolder.addEventHandler(MouseEvent.ANY, e -> e.consume());
}
public void addRow(RadioButton radio, Region field, Text helpIcon) {
requireNotNullArg(radio, "Cannot add a null radio");
requireNotNullArg(field, "Cannot add a null field");
GridPane.setValignment(radio, VPos.BOTTOM);
GridPane.setValignment(field, VPos.BOTTOM);
GridPane.setHalignment(radio, HPos.LEFT);
GridPane.setHalignment(field, HPos.LEFT);
GridPane.setFillWidth(field, true);
field.setPrefWidth(300);
field.setDisable(true);
radio.selectedProperty().addListener((o, oldVal, newVal) -> {
field.setDisable(!newVal);
if (newVal) {
field.requestFocus();
}
});
radio.setToggleGroup(group);
add(radio, 0, rows);
add(field, 1, rows);
if (nonNull(helpIcon)) {
add(helpIcon, 2, rows);
}
rows++;
}
@Override
public void afterSuccessful() {
if (statisticCheck == null) {
return;
}
if (statisticCheck.isSelected()) {
startStatistic();
} else {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("MyBox");
alert.setContentText(message("EpidemicReportStatistic"));
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
ButtonType buttonOK = new ButtonType(AppVariables.message("OK"));
ButtonType buttonCancel = new ButtonType(AppVariables.message("Cancel"));
alert.getButtonTypes().setAll(buttonOK, buttonCancel);
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
stage.toFront();
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == buttonOK) {
startStatistic();
}
}
}
public static void alertInformation(Stage myStage, String information) {
try {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle(myStage.getTitle());
alert.setHeaderText(null);
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alert.getDialogPane().setContent(new Label(information));
// alert.setContentText(information);
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
stage.toFront();
alert.showAndWait();
} catch (Exception e) {
logger.error(e.toString());
}
}
private void initGraphics() {
frame = new Region();
frame.getStyleClass().setAll("frame");
frame.setOpacity(isFrameVisible() ? 1 : 0);
led = new Region();
led.getStyleClass().setAll("main");
led.setStyle("-led-color: " + (getLedColor()).toString().replace("0x", "#") + ";");
innerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 8, 0d, 0d, 0d);
glow = new DropShadow(BlurType.TWO_PASS_BOX, getLedColor(), 20, 0d, 0d, 0d);
glow.setInput(innerShadow);
highlight = new Region();
highlight.getStyleClass().setAll("highlight");
// Add all nodes
getChildren().addAll(frame, led, highlight);
}
public static void alertError(Stage myStage, String information) {
try {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(myStage.getTitle());
alert.setHeaderText(null);
alert.setContentText(information);
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
// https://stackoverflow.com/questions/38799220/javafx-how-to-bring-dialog-alert-to-the-front-of-the-screen?r=SearchResults
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
stage.toFront();
alert.showAndWait();
} catch (Exception e) {
logger.error(e.toString());
}
}
@Override
protected void layoutChildren(final double x, final double y, final double w, final double h) {
super.layoutChildren(x, y, w, h);
final double height = getSkinnable().getHeight();
final double width = getSkinnable().getWidth();
linesWrapper.layoutLines(x - 2, y - 2, width, h, height, promptText == null ? 0 : promptText.getLayoutBounds().getHeight() + 3);
errorContainer.layoutPane(x, height + linesWrapper.focusedLine.getHeight(), width, h);
linesWrapper.updateLabelFloatLayout();
if (invalid) {
invalid = false;
// set the default background of text area viewport to white
Region viewPort = (Region) scrollPane.getChildrenUnmodifiable().get(0);
viewPort.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT,
CornerRadii.EMPTY,
Insets.EMPTY)));
// reapply css of scroll pane in case set by the user
viewPort.applyCss();
errorContainer.invalid(w);
// focus
linesWrapper.invalid();
}
}
public boolean clearSettings() {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(getBaseTitle());
alert.setContentText(AppVariables.message("SureClear"));
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
ButtonType buttonSure = new ButtonType(AppVariables.message("Sure"));
ButtonType buttonCancel = new ButtonType(AppVariables.message("Cancel"));
alert.getButtonTypes().setAll(buttonSure, buttonCancel);
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
stage.toFront();
Optional<ButtonType> result = alert.showAndWait();
if (result.get() != buttonSure) {
return false;
}
DerbyBase.clearData();
cleanAppPath();
AppVariables.initAppVaribles();
return true;
}
public static void setHBoxPosition(Region element, double width, double height, Insets margin){
if(width == -1){
HBox.setHgrow(element, Priority.ALWAYS);
element.setMaxWidth(Double.MAX_VALUE);
}else if(width != 0){
element.setPrefWidth(width);
element.minWidthProperty().bind(new SimpleDoubleProperty(width));
}
if(height == -1){
VBox.setVgrow(element, Priority.ALWAYS);
}else if(height != 0){
element.setPrefHeight(height);
element.minHeightProperty().bind(new SimpleDoubleProperty(height));
}
HBox.setMargin(element, margin);
}
private void rebuild() {
// update indeterminate indicator
final int segments = skin.indeterminateSegmentCount.get();
opacities.clear();
pathsG.getChildren().clear();
final double step = 0.8 / (segments - 1);
for (int i = 0; i < segments; i++) {
Region region = new Region();
region.setScaleShape(false);
region.setCenterShape(false);
region.getStyleClass().addAll("segment", "segment" + i);
if (fillOverride instanceof Color) {
Color c = (Color) fillOverride;
region.setStyle("-fx-background-color: rgba(" + ((int) (255 * c.getRed())) + "," +
"" + ((int) (255 * c.getGreen())) + "," + ((int) (255 * c.getBlue())) + "," +
"" + c.getOpacity() + ");");
} else {
region.setStyle(null);
}
double opacity = Math.min(1, i * step);
opacities.add(opacity);
region.setOpacity(opacity);
pathsG.getChildren().add(region);
}
}
public JFXTable(JFXContainer<? extends Region> parent, boolean headerVisible, boolean checkable) {
super(new TableView<UITableItem<T>>(), parent);
this.selectionListener = new JFXSelectionListenerChangeManagerAsync<UITableItem<T>>(this);
this.checkSelectionListener = new JFXCheckTableSelectionListenerManager<T>(this);
this.cellFactory = new JFXTableCellFactory<T>(this, checkable);
this.cellValueFactory = new JFXTableCellValueFactory<T>();
this.getControl().setEditable(true);
this.getControl().getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
this.getControl().widthProperty().addListener(new ChangeListener<Number>() {
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
JFXTable.this.fillAvailableWidth();
}
});
}
/**
* Shows the {@code overlay} on top of the view, with a {@link GlassPane} in the background.
*
* @param overlay to be shown
* @param blocking If false (non-blocking), clicking outside of the {@code overlay} will cause it
* to get hidden, together with its {@link GlassPane}. If true (blocking),
* clicking outside of the {@code overlay} will not do anything. The {@code
* overlay} itself must call {@link Workbench#hideOverlay(Region)} to hide it.
* @return true if the overlay is not being shown already
*/
public final boolean showOverlay(Region overlay, boolean blocking) {
LOGGER.trace("showOverlay");
if (!overlays.containsKey(overlay)) {
overlays.put(overlay, new WorkbenchOverlay(overlay, new GlassPane()));
}
// To prevent showing the same overlay twice
if (blockingOverlaysShown.contains(overlay) || nonBlockingOverlaysShown.contains(overlay)) {
return false;
}
if (blocking) {
LOGGER.trace("showOverlay - blocking");
return blockingOverlaysShown.add(overlay);
} else {
LOGGER.trace("showOverlay - non-blocking");
return nonBlockingOverlaysShown.add(overlay);
}
}
/** adds an empty region with the FILL constraint */
public void fill()
{
Region n = new Region();
massage(n);
getChildren().add(n);
FX.setProperty(n, KEY_CONSTRAINT, FILL);
}
/**
* Resizes the visual of this {@link IResizableContentPart} to the given
* size.
*
* @param totalSize
* The new size for this {@link IResizableContentPart}'s visual.
*/
public default void setVisualSize(Dimension totalSize) {
if (getVisual() instanceof Region) {
// A Region should not be resized directly. Instead, its size
// constraints should be adjusted so that it will be resized to the
// desired size during the next layout pass.
((Region) getVisual()).setPrefSize(totalSize.width,
totalSize.height);
((Region) getVisual()).autosize();
} else {
// resize manually
getVisual().resize(totalSize.width, totalSize.height);
}
}
private void initComponents() {
okButton.setOnAction((e) -> onOk());
cancelButton.setOnAction((e) -> onCancel());
defaultsButton.setOnAction((e) -> onDefault());
buttonBar.setButtonMinWidth(Region.USE_PREF_SIZE);
buttonBar.getButtons().addAll(okButton, cancelButton, defaultsButton);
}
private static void dragSouth(MouseEvent event, Wrapper<Point2D> mouseLocation, Region region, double handleRadius) {
final double deltaY = event.getSceneY() - mouseLocation.value.getY();
final double newMaxY = region.getLayoutY() + region.getHeight() + deltaY;
if(newMaxY >= region.getLayoutY() && newMaxY <= region.getParent().getBoundsInLocal().getHeight() - handleRadius) {
region.setPrefHeight(region.getPrefHeight() + deltaY);
}
}
public void startMainApp(Stage ms) {
try {
long time = System.currentTimeMillis();
Stage stage = new Stage();
stage.setTitle(Undecorator.LOC.getString("AppName") + " " + Undecorator.LOC.getString("Version") + " 版本号:" + Undecorator.LOC.getString("VersionCode"));
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"));
Region root = (Region) fxmlLoader.load();
final UndecoratorScene undecoratorScene = new UndecoratorScene(stage, root);
stage.setOnCloseRequest((WindowEvent we) -> {
we.consume();
undecoratorScene.setFadeOutTransition();
});
undecoratorScene.getStylesheets().add("/styles/main.css");
stage.setScene(undecoratorScene);
stage.toFront();
stage.getIcons().add(new Image(getClass().getResourceAsStream("/skin/icon.png")));
stage.setOnShown((event) -> {
new Timer().schedule(new TimerTask() {
@Override
public void run() {
Platform.runLater(() -> {
ms.close();
});
}
}, 1000);
});
stage.show();
ApplicationStageManager.putStageAndController(ApplicationStageManager.StateAndController.MAIN, stage, fxmlLoader.getController());
LOGGER.info("主页面加载耗时:" + (System.currentTimeMillis() - time) + "毫秒");
} catch (IOException ex) {
LOGGER.error("启动主程序异常", ex);
}
}
/**
* Configures the central grid pane before it's used.
*/
private static void setupGridPane(GridPane grid) {
grid.setAlignment(Pos.CENTER);
grid.setHgap(7);
grid.setVgap(10);
grid.setPadding(new Insets(25));
grid.setPrefSize(390, 100);
grid.setMaxSize(Region.USE_COMPUTED_SIZE, Region.USE_COMPUTED_SIZE);
applyColumnConstraints(grid, 20, 16, 33, 2, 29);
}
/**
* UndecoratorScene constructor
*
* @param stage The main stage
* @param stageStyle could be StageStyle.UTILITY or StageStyle.TRANSPARENT
* @param root your UI to be displayed in the Stage
* @param stageDecorationFxml Your own Stage decoration or null to use the
* built-in one
*/
public UndecoratorScene(Stage stage, StageStyle stageStyle, Region root, String stageDecorationFxml) {
super(root);
myRoot = root;
/*
* Fxml
*/
if (stageDecorationFxml == null) {
if (stageStyle == StageStyle.UTILITY) {
stageDecorationFxml = STAGEDECORATION_UTILITY;
} else {
stageDecorationFxml = STAGEDECORATION;
}
}
undecorator = new Undecorator(stage, root, stageDecorationFxml, stageStyle);
super.setRoot(undecorator);
// Customize it by CSS if needed:
if (stageStyle == StageStyle.UTILITY) {
undecorator.getStylesheets().add(STYLESHEET_UTILITY);
} else {
undecorator.getStylesheets().add(STYLESHEET);
}
// Transparent scene and stage
if (stage.getStyle() != StageStyle.TRANSPARENT) {
stage.initStyle(StageStyle.TRANSPARENT);
}
super.setFill(Color.TRANSPARENT);
// Default Accelerators
undecorator.installAccelerators(this);
// Forward pref and max size to main stage
stage.setMinWidth(undecorator.getMinWidth());
stage.setMinHeight(undecorator.getMinHeight());
stage.setWidth(undecorator.getPrefWidth());
stage.setHeight(undecorator.getPrefHeight());
}
public JFXKnob(JFXContainer<? extends Region> parent) {
super(parent, false);
this.maximum = DEFAULT_MAXIMUM;
this.minimum = DEFAULT_MINIMUM;
this.increment = DEFAULT_INCREMENT;
this.selectionHandler = new UISelectionListenerManager();
this.addPaintListener(this);
this.addMouseUpListener(this);
this.addMouseDragListener(this);
this.addMouseWheelListener(this);
}
private HBox createHallOfFameEntry(final Player player) {
Label playerName = new Label(player.name);
playerName.setTextFill(SPACEFX_COLOR);
Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);
Label playerScore = new Label(Long.toString(player.score));
playerScore.setTextFill(SPACEFX_COLOR);
playerScore.setAlignment(Pos.CENTER_RIGHT);
HBox entry = new HBox(20, playerName, spacer, playerScore);
entry.setPrefWidth(WIDTH);
return entry;
}
/**
* set the content of the dialog
*
* @param content
*/
public void setContent(Region content) {
if (content != null) {
this.content = content;
this.content.setPickOnBounds(false);
contentHolder.getChildren().setAll(content);
}
}
protected void massage(Node n)
{
// once in an HPane, surrender your limitations!
if(n instanceof Region)
{
Region r = (Region)n;
r.setMaxHeight(Double.MAX_VALUE);
r.setMaxWidth(Double.MAX_VALUE);
}
}