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

The following examples show how to use javafx.scene.layout.StackPane#setPrefHeight() . 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: DockPane.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private void doAutoHideTabs(final Scene scene)
{
    final boolean do_hide = getTabs().size() == 1  &&  !always_show_tabs;

    // Hack from https://www.snip2code.com/Snippet/300911/A-trick-to-hide-the-tab-area-in-a-JavaFX :
    // Locate the header's pane and set height to zero
    final StackPane header = findTabHeader();
    if (header == null)
        logger.log(Level.WARNING, "Cannot locate tab header for " + getTabs());
    else
        header.setPrefHeight(do_hide  ?  0  :  -1);

    // If header for single tab is not shown,
    // and this is the only tab in the window,
    // put its label into the window tile
    if (! (scene.getWindow() instanceof Stage))
        throw new IllegalStateException("Expect Stage, got " + scene.getWindow());
    final Stage stage = ((Stage) scene.getWindow());
    if (do_hide  &&  DockStage.getPaneOrSplit(stage) == this)
    {   // Bind to get actual header, which for DockItemWithInput may contain 'dirty' marker,
        // and keep updating as it changes
        final Tab tab = getTabs().get(0);
        if (! (tab instanceof DockItem))
            throw new IllegalStateException("Expected DockItem, got " + tab);
        stage.titleProperty().bind(((DockItem)tab).labelTextProperty());
    }
    else
    {   // Fixed title
        stage.titleProperty().unbind();
        stage.setTitle(Messages.FixedTitle);
    }
}
 
Example 3
Source File: Sprite.java    From DeskChan with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void applyMargin(){
    if (spriteContent == null)
        return;

    boolean turn = sprite.getScaleX() < 0;
    Insets newMargin = new Insets(margin.getTop(), (!turn) ? margin.getRight() : margin.getLeft(),
            margin.getBottom(), (turn) ? margin.getRight() : margin.getLeft());

    StackPane parent = (StackPane) spriteContent.getParent();
    parent.setPrefHeight(getFitHeight());
    parent.setMaxWidth(getFitWidth());
    StackPane.setMargin(spriteContent, newMargin);
}
 
Example 4
Source File: MainScene.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public StackPane createChatBox() {
	chatBox = new ChatBox(this);
	chatBox.getAutoFillTextBox().getTextbox().requestFocus();
	chatBoxPane = new StackPane(chatBox);
	chatBoxPane.setMinHeight(chatBoxHeight);
	chatBoxPane.setPrefHeight(chatBoxHeight);
	chatBoxPane.setMaxHeight(chatBoxHeight);
	chatBoxPane.setPadding(new Insets(0, 0, 0, 0));
	return chatBoxPane;
}
 
Example 5
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 6
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 7
Source File: ViolationCollectionView.java    From pmd-designer with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ViolationCollectionView(@NamedArg("designerRoot") DesignerRoot root) {
    this.root = root;

    this.getStyleClass().addAll("property-collection-view");

    view = new ListView<>();
    initListView(view);

    StackPane footer = new StackPane();
    footer.setPrefHeight(LIST_CELL_HEIGHT);
    footer.getStyleClass().addAll("footer");
    footer.getStylesheets().addAll(DesignerUtil.getCss("flat").toString());

    Label addProperty = new Label("Drag and drop nodes from anywhere");
    StackPane.setAlignment(addProperty, Pos.CENTER);


    footer.getChildren().addAll(addProperty);
    this.getChildren().addAll(view, footer);


}
 
Example 8
Source File: TranslatePanel.java    From Quelea with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Create the translation dialog.
 */
public TranslatePanel() {
    splitPane = new SplitPane();
    defaultLyricsArea = new LyricsTextArea();
    StackPane translationPane = new StackPane();
    tabPane = new TabPane();
    translationPane.getChildren().add(tabPane);
    addTranslationButton = new Button("", new ImageView(new Image("file:icons/newstar.png", 16, 16, false, true)));
    Utils.setToolbarButtonStyle(addTranslationButton);
    addTranslationButton.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent t) {
            final String name = NewTranslationDialog.getTranslationName(getExistingNames());
            if (name != null) {
                final TranslateTab tab = new TranslateTab(name, "");
                tabPane.getTabs().add(tab);
                copyStage.showAndAssociate(TranslatePanel.this);
                translateThread = new Thread() {
                    @Override
                    public void run() {
                        interrupted = false;
                        String lyrics = null;
                        try {
                            lyrics = getTranslatedLyrics(name);
                        } catch (Exception ex) {
                            LOGGER.log(Level.INFO, "Interrupted translating", ex);
                            interrupted = true;
                        }

                        if (!interrupted) {
                            final String fiLyrics = lyrics;
                            Platform.runLater(new Runnable() {
                                @Override
                                public void run() {
                                    copyStage.hide();
                                    if (fiLyrics != null && !fiLyrics.isEmpty()) {
                                        tab.setLyrics(fiLyrics);
                                    }
                                }
                            });
                        }
                    }
                };
                translateThread.start();
            }
        }
    });
    addTranslationButton.setTooltip(new Tooltip(LabelGrabber.INSTANCE.getLabel("add.translation.button")));
    StackPane.setAlignment(addTranslationButton, Pos.TOP_RIGHT);
    translationPane.getChildren().add(addTranslationButton);
    StackPane.setMargin(addTranslationButton, new Insets(5));
    BorderPane leftArea = new BorderPane();
    StackPane topRegion = new StackPane();
    Text defaultTranslationLabel = new Text(LabelGrabber.INSTANCE.getLabel("default.translation.label"));
    defaultTranslationLabel.setFill(Color.WHITE);
    StackPane.setAlignment(defaultTranslationLabel, Pos.CENTER_LEFT);
    StackPane.setMargin(defaultTranslationLabel, new Insets(5));
    topRegion.getChildren().add(defaultTranslationLabel);
    topRegion.setPrefHeight(31);
    topRegion.setStyle("-fx-background-color:rgb(166,166,166);"); //Match the tabpane header background.
    topRegion.setMaxWidth(Double.MAX_VALUE);
    leftArea.setTop(topRegion);
    leftArea.setCenter(defaultLyricsArea);
    splitPane.getItems().add(leftArea);
    splitPane.getItems().add(translationPane);

    setCenter(splitPane);
}
 
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: ParetoPanel.java    From charts with Apache License 2.0 4 votes vote down vote up
private void init() {
    modelStack = new Stack<>();
    dataDots = new ArrayList<>();
    popup = new ParetoInfoPopup();
    mouseHandler       = this::handleMouseEvents;
    modelStack.push(paretoModel);

    _labelingColor = Color.BLACK;

    _singelSubBarCentered = true;

    initGraphics();
    registerListeners();

    colorThemes = new HashMap<>();
    ArrayList<Color> defaultColorTheme = new ArrayList<>();
    defaultColorTheme.add(Color.BLUE);
    colorThemes.putIfAbsent("Default", defaultColorTheme);

    _valueFontYPosition         = 20;
    _identifierFontYPosition    = 40;
    _pathFontYPositon           = 65;
    _percentageLineDataDotColor = Color.BLACK;
    _percentageLineColor        = Color.BLACK;
    _useCalculatedSubBarColors  = true;
    _smoothPercentageCurve      = false;
    _showSubBars                = true;

    textPane   = new AnchorPane();

    yAxisLeft  = Helper.createLeftAxis(0, paretoModel.getTotal(), false, 80d);
    yAxisRight = Helper.createRightAxis(0,100,true,80d);

    maxValue   = new DoublePropertyBase(paretoModel.getTotal()) {
        @Override public Object getBean() { return ParetoPanel.this; }
        @Override public String getName() { return "maxValue"; }
    };

    yAxisLeft.setTitle(paretoModel.getTitle());
    yAxisLeft.setTitleFontSize(30);

    //yAxisRight.setTitle("Percentage"); //title written into the numbers of scale
    yAxisRight.setTitleFontSize(30);

    yAxisRight.setUnit("\\u0025");

    yAxisLeft.maxValueProperty().bindBidirectional(maxValue);

    yAxisRight.setPosition(Position.CENTER);
    bPane = new BorderPane();
    bPane.setPrefWidth(yAxisRight.getWidth()+ canvas.getWidth()+ yAxisRight.getWidth());
    bPane.setCenter(canvas);

    yAxisRightProperty = new ObjectPropertyBase<Axis>(yAxisRight) {
        @Override public Object getBean() { return ParetoPanel.this; }
        @Override public String getName() { return "yAxisRight"; }
    };
    yAxisLeftProperty  = new ObjectPropertyBase<Axis>(yAxisLeft) {
        @Override public Object getBean() { return ParetoPanel.this; }
        @Override public String getName() { return "yAxisLeft"; }
    };

    bPane.rightProperty().bind(yAxisRightProperty);
    bPane.leftProperty().bind(yAxisLeftProperty);

    _barSpacing = 5;

    width  = getWidth() - getInsets().getLeft() - getInsets().getRight();
    height = getHeight() - getInsets().getTop() - getInsets().getBottom();
    bPane.setMaxSize(width, height);
    bPane.setPrefSize(width, height);

    canvas.setWidth(width-yAxisRight.getWidth()-yAxisLeft.getWidth());

    textPane.setMaxHeight(80);
    textPane.setMinHeight(80);

    StackPane test = new StackPane();
    test.setPrefHeight(80d);
    labelingCanvas = new Canvas();

    labelingCanvas.setHeight(80);
    labelingCtx = labelingCanvas.getGraphicsContext2D();

    delayRedraw = false;

    bPane.setBottom(labelingCanvas);

    getChildren().setAll(bPane);

    drawParetoChart();
}
 
Example 11
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);
}