Java Code Examples for javafx.scene.layout.StackPane#setPrefWidth()

The following examples show how to use javafx.scene.layout.StackPane#setPrefWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CSSFXTab.java    From scenic-view with GNU General Public License v3.0 7 votes vote down vote up
private Node createTabGraphic() {
    SVGPath p = new SVGPath();
    p.setContent("m 180.75256,334.77228 -0.53721,2.68603 10.93285,0 -0.3412,1.73502 -10.9401,0 -0.52996,2.68603 10.93286,0 -0.6098,3.06352 -4.40654,1.45917 -3.81851,-1.45917 0.26134,-1.32849 -2.68602,0 -0.63884,3.22323 6.31579,2.41742 7.2813,-2.41742 0.96552,-4.84937 0.19601,-0.97277 1.24138,-6.2432 z");
    StackPane sp = new StackPane(p);
    sp.setMaxWidth(24.0);
    sp.setMaxHeight(24.0);
    sp.setPrefWidth(24.0);
    sp.setPrefHeight(24.0);
    return sp;
}
 
Example 2
Source File: QuestProgress.java    From logbook-kai with MIT License 6 votes vote down vote up
private static void setConditionIcon(TreeItem<String> item, Boolean result) {
    GlyphFont fontAwesome = GlyphFontRegistry.font("FontAwesome");

    StackPane pane = new StackPane();
    pane.setPrefWidth(18);

    if (result != null) {
        if (result) {
            pane.getChildren().add(fontAwesome.create(FontAwesome.Glyph.CHECK).color(Color.GREEN));
        } else {
            pane.getChildren().add(fontAwesome.create(FontAwesome.Glyph.EXCLAMATION).color(Color.RED));
        }
    } else {
        pane.getChildren().add(fontAwesome.create(FontAwesome.Glyph.QUESTION).color(Color.GRAY));
    }
    item.setGraphic(pane);
}
 
Example 3
Source File: MissionCheck.java    From logbook-kai with MIT License 6 votes vote down vote up
private void setIcon(TreeItem<String> item, Boolean result) {
    GlyphFont fontAwesome = GlyphFontRegistry.font("FontAwesome");

    StackPane pane = new StackPane();
    pane.setPrefWidth(18);

    if (result != null) {
        if (result) {
            pane.getChildren().add(fontAwesome.create(FontAwesome.Glyph.CHECK).color(Color.GREEN));
        } else {
            pane.getChildren().add(fontAwesome.create(FontAwesome.Glyph.EXCLAMATION).color(Color.RED));
        }
    } else {
        pane.getChildren().add(fontAwesome.create(FontAwesome.Glyph.QUESTION).color(Color.GRAY));
    }
    item.setGraphic(pane);
}
 
Example 4
Source File: MainScene.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the stage properly on the monitor where the mouse pointer is
 * 
 * @param stage
 */
public void setMonitor(Stage stage) {
	// TODO: how to run on the "Active monitor" as chosen by user ?
	// Note : "Active monitor is defined by whichever computer screen the mouse
	// pointer is or where the command console that starts mars-sim.
	// By default, it runs on the primary monitor (aka monitor 0 as reported by
	// windows os only.
	// see
	// http://stackoverflow.com/questions/25714573/open-javafx-application-on-active-screen-or-monitor-in-multi-screen-setup/25714762#25714762
	StartUpLocation startUpLoc = null;

	if (rootStackPane == null) {
		StackPane pane = new StackPane();
		pane.setPrefHeight(sceneWidth.get());
		pane.setPrefWidth(sceneHeight.get());
		// pane.prefHeightProperty().bind(scene.heightProperty());
		// pane.prefWidthProperty().bind(scene.widthProperty());
		startUpLoc = new StartUpLocation(pane.getPrefWidth(), pane.getPrefHeight());
	} else {
		startUpLoc = new StartUpLocation(rootStackPane.getWidth(), rootStackPane.getHeight());
	}

	double xPos = startUpLoc.getXPos();
	double yPos = startUpLoc.getYPos();
	// Set Only if X and Y are not zero and were computed correctly
	// if (xPos != 0 && yPos != 0) {
	stage.setX(xPos+1);
	stage.setY(yPos+1);
	// }

	// stage.centerOnScreen(); // this will cause the stage to be pinned slight
	// upward.
}
 
Example 5
Source File: QuestProgress.java    From logbook-kai with MIT License 5 votes vote down vote up
private static void setFilterIcon(TreeItem<String> item) {
    GlyphFont fontAwesome = GlyphFontRegistry.font("FontAwesome");
    StackPane pane = new StackPane();
    pane.setPrefWidth(18);
    pane.getChildren().add(fontAwesome.create(FontAwesome.Glyph.FILTER).color(Color.ROYALBLUE));
    item.setGraphic(pane);
}
 
Example 6
Source File: QuestProgress.java    From logbook-kai with MIT License 5 votes vote down vote up
private static void setFilterListIcon(TreeItem<String> item) {
    GlyphFont fontAwesome = GlyphFontRegistry.font("FontAwesome");
    StackPane pane = new StackPane();
    pane.setPrefWidth(18);
    pane.getChildren().add(fontAwesome.create(FontAwesome.Glyph.ANGLE_RIGHT).color(Color.ROYALBLUE));
    item.setGraphic(pane);
}
 
Example 7
Source File: MissionCheck.java    From logbook-kai with MIT License 5 votes vote down vote up
private TreeItem<String> buildTree0(Mission mission, List<Ship> fleet) {
    try {
        TreeItem<String> item;
        Optional<MissionCondition> condition = Missions.getMissionCondition(mission.getId());
        if (condition.isPresent()) {
            MissionCondition cond = condition.get();
            cond.test(fleet);
            item = this.buildLeaf(cond);
        } else if (mission.getSampleFleet() != null) {
            item = new TreeItem<>();
            setIcon(item, null);
        } else {
            return null;
        }
        item.setValue(mission.toString());
        if (mission.getSampleFleet() != null) {
            TreeItem<String> sample = new TreeItem<>("サンプル編成");

            GlyphFont fontAwesome = GlyphFontRegistry.font("FontAwesome");

            StackPane pane = new StackPane();
            pane.setPrefWidth(18);
            pane.getChildren().add(fontAwesome.create(FontAwesome.Glyph.INFO));
            sample.setGraphic(pane);

            for (Integer type : mission.getSampleFleet()) {
                Optional.ofNullable(StypeCollection.get()
                        .getStypeMap()
                        .get(type))
                        .map(Stype::getName)
                        .ifPresent(name -> sample.getChildren().add(new TreeItem<>(name)));
            }
            item.getChildren().add(sample);
        }
        return item;
    } catch (Exception e) {
        LoggerHolder.get().error("遠征確認画面で例外", e);
    }
    return null;
}
 
Example 8
Source File: JFXUtil.java    From jfxutils with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a "Scale Pane", which is a pane that scales as it resizes, instead of reflowing layout
 * like a normal pane. It can be used to create an effect like a presentation slide. There is no
 * attempt to preserve the aspect ratio.
 * <p>
 * If the region has an explicitly set preferred width and height, those are used unless
 * override is set true.
 * <p>
 * If the region already has a parent, the returned pane will replace it via the
 * {@link #replaceComponent(Node, Node)} method. The Region's parent must be a Pane in this case.
 *
 * @param region   non-null Region
 * @param w        default width, used if the region's width is calculated
 * @param h        default height, used if the region's height is calculated
 * @param override if true, w,h is the region's "100%" size even if the region has an explicit
 *                 preferred width and height set.
 *
 * @return the created StackPane, with preferred width and height set based on size determined by
 *         w, h, and override parameters.
 */
public static StackPane createScalePane( Region region, double w, double h, boolean override ) {
	//If the Region containing the GUI does not already have a preferred width and height, set it.
	//But, if it does, we can use that setting as the "standard" resolution.
	if ( override || region.getPrefWidth() == Region.USE_COMPUTED_SIZE )
		region.setPrefWidth( w );
	else
		w = region.getPrefWidth();

	if ( override || region.getPrefHeight() == Region.USE_COMPUTED_SIZE )
		region.setPrefHeight( h );
	else
		h = region.getPrefHeight();

	StackPane ret = new StackPane();
	ret.setPrefWidth( w );
	ret.setPrefHeight( h );
	if ( region.getParent() != null )
		replaceComponent( region, ret );

	//Wrap the resizable content in a non-resizable container (Group)
	Group group = new Group( region );
	//Place the Group in a StackPane, which will keep it centered
	ret.getChildren().add( group );

	//Bind the scene's width and height to the scaling parameters on the group
	group.scaleXProperty().bind( ret.widthProperty().divide( w ) );
	group.scaleYProperty().bind( ret.heightProperty().divide( h ) );

	return ret;
}
 
Example 9
Source File: Clustering.java    From java-ml-projects with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
	loadData();
	tree = new J48();
	tree.buildClassifier(data);

	noClassificationChart = buildChart("No Classification (click to add new data)", buildSingleSeries());
	clusteredChart = buildChart("Clustered", buildClusteredSeries());
	realDataChart = buildChart("Real Data (+ Decision Tree classification for new data)", buildLabeledSeries());

	noClassificationChart.setOnMouseClicked(e -> {
		Axis<Number> xAxis = noClassificationChart.getXAxis();
		Axis<Number> yAxis = noClassificationChart.getYAxis();
		Point2D mouseSceneCoords = new Point2D(e.getSceneX(), e.getSceneY());
		double x = xAxis.sceneToLocal(mouseSceneCoords).getX();
		double y = yAxis.sceneToLocal(mouseSceneCoords).getY();
		Number xValue = xAxis.getValueForDisplay(x);
		Number yValue = yAxis.getValueForDisplay(y);
		reloadSeries(xValue, yValue);
	});

	Label lblDecisionTreeTitle = new Label("Decision Tree generated for the Iris dataset:");
	Text txtTree = new Text(tree.toString());
	String graph = tree.graph();
	SwingNode sw = new SwingNode();
	SwingUtilities.invokeLater(() -> {
		TreeVisualizer treeVisualizer = new TreeVisualizer(null, graph, new PlaceNode2());
		treeVisualizer.setPreferredSize(new Dimension(600, 500));
		sw.setContent(treeVisualizer);
	});

	Button btnRestore = new Button("Restore original data");
	Button btnSwapColors = new Button("Swap clustered chart colors");
	StackPane spTree = new StackPane(sw);
	spTree.setPrefWidth(300);
	spTree.setPrefHeight(350);
	VBox vbDecisionTree = new VBox(5, lblDecisionTreeTitle, new Separator(), spTree,
			new HBox(10, btnRestore, btnSwapColors));
	btnRestore.setOnAction(e -> {
		loadData();
		reloadSeries();
	});
	btnSwapColors.setOnAction(e -> swapClusteredChartSeriesColors());
	lblDecisionTreeTitle.setTextFill(Color.DARKRED);
	lblDecisionTreeTitle.setFont(Font.font(Font.getDefault().getFamily(), FontWeight.BOLD, FontPosture.ITALIC, 16));
	txtTree.setTranslateX(100);
	txtTree.setFont(Font.font(Font.getDefault().getFamily(), FontWeight.BOLD, FontPosture.ITALIC, 14));
	txtTree.setLineSpacing(1);
	txtTree.setTextAlignment(TextAlignment.LEFT);
	vbDecisionTree.setTranslateY(20);
	vbDecisionTree.setTranslateX(20);

	GridPane gpRoot = new GridPane();
	gpRoot.add(realDataChart, 0, 0);
	gpRoot.add(clusteredChart, 1, 0);
	gpRoot.add(noClassificationChart, 0, 1);
	gpRoot.add(vbDecisionTree, 1, 1);

	stage.setScene(new Scene(gpRoot));
	stage.setTitle("Íris dataset clustering and visualization");
	stage.show();
}
 
Example 10
Source File: MasonryPaneController.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
/**
 * init fxml when loaded.
 */
@PostConstruct
public void init() {
    ArrayList<Node> children = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        StackPane child = new StackPane();
        double width = Math.random() * 100 + 100;
        child.setPrefWidth(width);
        double height = Math.random() * 100 + 100;
        child.setPrefHeight(height);
        JFXDepthManager.setDepth(child, 1);
        children.add(child);

        // create content
        StackPane header = new StackPane();
        String headerColor = getDefaultColor(i % 12);
        header.setStyle("-fx-background-radius: 5 5 0 0; -fx-background-color: " + headerColor);
        VBox.setVgrow(header, Priority.ALWAYS);
        StackPane body = new StackPane();
        body.setMinHeight(Math.random() * 20 + 50);
        VBox content = new VBox();
        content.getChildren().addAll(header, body);
        body.setStyle("-fx-background-radius: 0 0 5 5; -fx-background-color: rgb(255,255,255,0.87);");


        // create button
        JFXButton button = new JFXButton("");
        button.setButtonType(ButtonType.RAISED);
        button.setStyle("-fx-background-radius: 40;-fx-background-color: " + getDefaultColor((int) ((Math.random() * 12) % 12)));
        button.setPrefSize(40, 40);
        button.setRipplerFill(Color.valueOf(headerColor));
        button.setScaleX(0);
        button.setScaleY(0);
        SVGGlyph glyph = new SVGGlyph(-1,
            "test",
            "M1008 6.286q18.857 13.714 15.429 36.571l-146.286 877.714q-2.857 16.571-18.286 25.714-8 4.571-17.714 4.571-6.286 "
            + "0-13.714-2.857l-258.857-105.714-138.286 168.571q-10.286 13.143-28 13.143-7.429 "
            + "0-12.571-2.286-10.857-4-17.429-13.429t-6.571-20.857v-199.429l493.714-605.143-610.857 "
            + "528.571-225.714-92.571q-21.143-8-22.857-31.429-1.143-22.857 18.286-33.714l950.857-548.571q8.571-5.143 18.286-5.143"
            + " 11.429 0 20.571 6.286z",
            Color.WHITE);
        glyph.setSize(20, 20);
        button.setGraphic(glyph);
        button.translateYProperty().bind(Bindings.createDoubleBinding(() -> {
            return header.getBoundsInParent().getHeight() - button.getHeight() / 2;
        }, header.boundsInParentProperty(), button.heightProperty()));
        StackPane.setMargin(button, new Insets(0, 12, 0, 0));
        StackPane.setAlignment(button, Pos.TOP_RIGHT);

        Timeline animation = new Timeline(new KeyFrame(Duration.millis(240),
                                                       new KeyValue(button.scaleXProperty(),
                                                                    1,
                                                                    EASE_BOTH),
                                                       new KeyValue(button.scaleYProperty(),
                                                                    1,
                                                                    EASE_BOTH)));
        animation.setDelay(Duration.millis(100 * i + 1000));
        animation.play();
        child.getChildren().addAll(content, button);
    }
    masonryPane.getChildren().addAll(children);
    Platform.runLater(() -> scrollPane.requestLayout());

    JFXScrollPane.smoothScrolling(scrollPane);
}