Java Code Examples for javafx.scene.Scene#getStylesheets()

The following examples show how to use javafx.scene.Scene#getStylesheets() . 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: Main.java    From tools-ocr with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
    new Thread(() -> {
        try {
            SVGGlyphLoader.loadGlyphsFont(Main.class.getResourceAsStream("/fonts/icomoon.svg"),
                    "icomoon.svg");
        } catch (IOException ioExc) {
            ioExc.printStackTrace();
        }
    }).start();

    Flow flow = new Flow(XToolsController.class);
    DefaultFlowContainer container = new DefaultFlowContainer();
    flowContext = new ViewFlowContext();
    flowContext.register("Stage", stage);
    flow.createHandler(flowContext).start(container);

    JFXDecorator decorator = new JFXDecorator(stage, container.getView());
    decorator.setCustomMaximize(true);
    decorator.setGraphic(new SVGGlyph(""));

    stage.setTitle("JFoenix Demo");

    double width = 800;
    double height = 600;
    try {
        Rectangle2D bounds = Screen.getScreens().get(0).getBounds();
        width = bounds.getWidth() / 2.5;
        height = bounds.getHeight() / 1.35;
    }catch (Exception e){ }

    Scene scene = new Scene(decorator, width, height);
    final ObservableList<String> stylesheets = scene.getStylesheets();
    stylesheets.addAll(JFoenixResources.load("css/jfoenix-fonts.css").toExternalForm(),
            JFoenixResources.load("css/jfoenix-design.css").toExternalForm(),
            Main.class.getResource("/css/jfoenix-main-demo.css").toExternalForm());
    stage.setScene(scene);
    stage.show();
}
 
Example 2
Source File: StyleSheetRefresher.java    From scenic-view with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Stylesheets can not be refreshed in they are not outside
 * 
 * @param scene
 * @return
 */
public static boolean canStylesBeRefreshed(final Scene scene) {
    final List<String> sheets = scene.getStylesheets();
    for (final String sheet : sheets) {
        if (sheet.startsWith("file"))
            return true;
    }
    return false;
}
 
Example 3
Source File: DockItem.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private Stage detach()
{
    // For size of new stage, approximate the
    // current size of the item, i.e. the size
    // of its DockPane, adding some extra space
    // for the window border, title bar etc.
    final DockPane old_parent = getDockPane();
    final Scene old_scene = old_parent.getScene();
    final double extra_width = Math.max(0, old_scene.getWindow().getWidth() - old_scene.getWidth());
    final double extra_height = Math.max(0, old_scene.getWindow().getHeight() - old_scene.getHeight());

    // If this tab was the last tab in the DockPane,
    // and that's in a SplitDock, the following call will
    // remove the old_parent from the scene.
    // That's why we fetched the scene info ahead of time.
    old_parent.getTabs().remove(this);

    final Stage other = new Stage();
    other.setTitle(UUID.randomUUID().toString());

    DockStage.configureStage(other, this);
    other.setWidth(old_parent.getWidth() + extra_width);
    other.setHeight(old_parent.getHeight() + extra_height);

    // Assert that styles used in old scene are still available
    for (String css : old_scene.getStylesheets())
        Styles.set(other.getScene(), css);

    other.show();

    return other;
}
 
Example 4
Source File: MainDemo.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
    new Thread(() -> {
        try {
            SVGGlyphLoader.loadGlyphsFont(MainDemo.class.getResourceAsStream("/fonts/icomoon.svg"),
                "icomoon.svg");
        } catch (IOException ioExc) {
            ioExc.printStackTrace();
        }
    }).start();

    Flow flow = new Flow(MainController.class);
    DefaultFlowContainer container = new DefaultFlowContainer();
    flowContext = new ViewFlowContext();
    flowContext.register("Stage", stage);
    flow.createHandler(flowContext).start(container);

    JFXDecorator decorator = new JFXDecorator(stage, container.getView());
    decorator.setCustomMaximize(true);
    decorator.setGraphic(new SVGGlyph(""));

    stage.setTitle("JFoenix Demo");

    double width = 800;
    double height = 600;
    try {
        Rectangle2D bounds = Screen.getScreens().get(0).getBounds();
        width = bounds.getWidth() / 2.5;
        height = bounds.getHeight() / 1.35;
    }catch (Exception e){ }

    Scene scene = new Scene(decorator, width, height);
    final ObservableList<String> stylesheets = scene.getStylesheets();
    stylesheets.addAll(JFoenixResources.load("css/jfoenix-fonts.css").toExternalForm(),
                       JFoenixResources.load("css/jfoenix-design.css").toExternalForm(),
                       MainDemo.class.getResource("/css/jfoenix-main-demo.css").toExternalForm());
    stage.setScene(scene);
    stage.show();
}
 
Example 5
Source File: DatePickerDemo.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Stage stage) {

    FlowPane main = new FlowPane();
    main.setVgap(20);
    main.setHgap(20);


    DatePicker datePicker = new DatePicker();

    main.getChildren().add(datePicker);
    JFXDatePicker datePickerFX = new JFXDatePicker();

    main.getChildren().add(datePickerFX);
    datePickerFX.setPromptText("pick a date");
    JFXTimePicker blueDatePicker = new JFXTimePicker();
    blueDatePicker.setDefaultColor(Color.valueOf("#3f51b5"));
    blueDatePicker.setOverLay(true);
    main.getChildren().add(blueDatePicker);


    StackPane pane = new StackPane();
    pane.getChildren().add(main);
    StackPane.setMargin(main, new Insets(100));
    pane.setStyle("-fx-background-color:WHITE");

    final Scene scene = new Scene(pane, 400, 700);
    final ObservableList<String> stylesheets = scene.getStylesheets();
    stylesheets.addAll(MainDemo.class.getResource("/css/jfoenix-fonts.css").toExternalForm(),
                       MainDemo.class.getResource("/css/jfoenix-design.css").toExternalForm());
    stage.setTitle("JFX Date Picker Demo");
    stage.setScene(scene);
    stage.show();

}
 
Example 6
Source File: DockPane.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
/** Accept a dropped tab */
private void handleDrop(final DragEvent event)
{
    final DockItem item = DockItem.dragged_item.getAndSet(null);
    if (item == null)
        logger.log(Level.SEVERE, "Empty drop, " + event);
    else
    {
        logger.log(Level.INFO, "Somebody dropped " + item + " into " + this);
        final TabPane old_parent = item.getTabPane();

        // Unexpected, but would still "work" at this time
        if (! (old_parent instanceof DockPane))
            logger.log(Level.SEVERE, "DockItem is not in DockPane but " + old_parent);

        // When moving to a new scene,
        // assert that styles used in old scene are still available
        final Scene old_scene = old_parent.getScene();
        final Scene scene = getScene();
        if (scene != old_scene)
            for (String css : old_scene.getStylesheets())
                Styles.set(scene, css);



        // Move tab. In principle,
        // (1) first remove from old parent,
        // (2) then add to new parent.
        // But modifying tabs triggers tab listener, which registers SplitPane.merge()
        // in Platform.runLater(). The merge could re-arrange tab panes,
        // we when we later want to add the tab, we'll face a different scene graph.
        // Issue the tab addition (2) with runlater right now so it'll happen before any
        // split pane cleanup.
        Platform.runLater(() ->
        {
            // When adding the tab to its new parent (this dock) right away,
            // the tab would sometimes not properly render until the pane is resized.
            // Moving to the next UI tick helps
            logger.log(Level.INFO, "Adding " + item + " to " + this);
            addTab(item);
            Platform.runLater(this::autoHideTabs);
        });

        // With tab addition already in the UI thread queue, remove item from old tab
        logger.log(Level.INFO, "Removing " + item + " from " + old_parent);
        old_parent.getTabs().remove(item);
    }
    event.setDropCompleted(true);
    event.consume();
}
 
Example 7
Source File: DrawerDemo.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage stage) {
    FlowPane content = new FlowPane();
    JFXButton leftButton = new JFXButton(LEFT);
    JFXButton topButton = new JFXButton(TOP);
    JFXButton rightButton = new JFXButton(RIGHT);
    JFXButton bottomButton = new JFXButton(BOTTOM);
    content.getChildren().addAll(leftButton, topButton, rightButton, bottomButton);
    content.setMaxSize(200, 200);


    JFXDrawer leftDrawer = new JFXDrawer();
    StackPane leftDrawerPane = new StackPane();
    leftDrawerPane.getStyleClass().add("red-400");
    leftDrawerPane.getChildren().add(new JFXButton("Left Content"));
    leftDrawer.setSidePane(leftDrawerPane);
    leftDrawer.setDefaultDrawerSize(150);
    leftDrawer.setResizeContent(true);
    leftDrawer.setOverLayVisible(false);
    leftDrawer.setResizableOnDrag(true);


    JFXDrawer bottomDrawer = new JFXDrawer();
    StackPane bottomDrawerPane = new StackPane();
    bottomDrawerPane.getStyleClass().add("deep-purple-400");
    bottomDrawerPane.getChildren().add(new JFXButton("Bottom Content"));
    bottomDrawer.setDefaultDrawerSize(150);
    bottomDrawer.setDirection(DrawerDirection.BOTTOM);
    bottomDrawer.setSidePane(bottomDrawerPane);
    bottomDrawer.setResizeContent(true);
    bottomDrawer.setOverLayVisible(false);
    bottomDrawer.setResizableOnDrag(true);


    JFXDrawer rightDrawer = new JFXDrawer();
    StackPane rightDrawerPane = new StackPane();
    rightDrawerPane.getStyleClass().add("blue-400");
    rightDrawerPane.getChildren().add(new JFXButton("Right Content"));
    rightDrawer.setDirection(DrawerDirection.RIGHT);
    rightDrawer.setDefaultDrawerSize(150);
    rightDrawer.setSidePane(rightDrawerPane);
    rightDrawer.setOverLayVisible(false);
    rightDrawer.setResizableOnDrag(true);


    JFXDrawer topDrawer = new JFXDrawer();
    StackPane topDrawerPane = new StackPane();
    topDrawerPane.getStyleClass().add("green-400");
    topDrawerPane.getChildren().add(new JFXButton("Top Content"));
    topDrawer.setDirection(DrawerDirection.TOP);
    topDrawer.setDefaultDrawerSize(150);
    topDrawer.setSidePane(topDrawerPane);
    topDrawer.setOverLayVisible(false);
    topDrawer.setResizableOnDrag(true);


    JFXDrawersStack drawersStack = new JFXDrawersStack();
    drawersStack.setContent(content);

    leftDrawer.setId(LEFT);
    rightDrawer.setId(RIGHT);
    bottomDrawer.setId(BOTTOM);
    topDrawer.setId(TOP);

    leftButton.addEventHandler(MOUSE_PRESSED, e -> drawersStack.toggle(leftDrawer));
    bottomButton.addEventHandler(MOUSE_PRESSED, e -> drawersStack.toggle(bottomDrawer));
    rightButton.addEventHandler(MOUSE_PRESSED, e -> drawersStack.toggle(rightDrawer));
    topButton.addEventHandler(MOUSE_PRESSED, e -> drawersStack.toggle(topDrawer));


    final Scene scene = new Scene(drawersStack, 800, 800);
    final ObservableList<String> stylesheets = scene.getStylesheets();
    stylesheets.addAll(DrawerDemo.class.getResource("/css/jfoenix-components.css").toExternalForm(),
                       DrawerDemo.class.getResource("/css/jfoenix-design.css").toExternalForm());

    stage.setTitle("JFX Drawer Demo");
    stage.setScene(scene);
    stage.setResizable(true);
    stage.show();
}
 
Example 8
Source File: AnimationDemo.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage stage) {

    FlowPane main = new FlowPane();
    main.setVgap(20);
    main.setHgap(20);

    StackPane colorPane = new StackPane();
    colorPane.setStyle(STYLE);
    colorPane.getStyleClass().add("red-500");
    main.getChildren().add(colorPane);

    StackPane colorPane1 = new StackPane();
    colorPane1.setStyle(STYLE);
    colorPane1.getStyleClass().add("blue-500");

    StackPane placeHolder = new StackPane(colorPane1);
    placeHolder.setStyle(STYLE);
    main.getChildren().add(placeHolder);


    StackPane colorPane2 = new StackPane();
    colorPane2.setStyle(STYLE);
    colorPane2.getStyleClass().add("green-500");
    main.getChildren().add(colorPane2);

    StackPane colorPane3 = new StackPane();
    colorPane3.setStyle(STYLE);
    colorPane3.getStyleClass().add("yellow-500");
    main.getChildren().add(colorPane3);


    StackPane colorPane4 = new StackPane();
    colorPane4.setStyle(STYLE);
    colorPane4.getStyleClass().add("purple-500");
    main.getChildren().add(colorPane4);


    StackPane wizard = new StackPane();
    wizard.getChildren().add(main);
    StackPane.setMargin(main, new Insets(100));
    wizard.setStyle("-fx-background-color:WHITE");

    StackPane nextPage = new StackPane();

    StackPane newPlaceHolder = new StackPane();
    newPlaceHolder.setStyle("-fx-background-radius:50; -fx-max-width:50; -fx-max-height:50;");
    nextPage.getChildren().add(newPlaceHolder);
    StackPane.setAlignment(newPlaceHolder, Pos.TOP_LEFT);


    JFXHamburger h4 = new JFXHamburger();
    h4.setMaxSize(40, 40);
    HamburgerBackArrowBasicTransition burgerTask3 = new HamburgerBackArrowBasicTransition(h4);
    burgerTask3.setRate(-1);
    h4.addEventHandler(MouseEvent.MOUSE_PRESSED, e -> {
        burgerTask3.setRate(burgerTask3.getRate() * -1);
        burgerTask3.play();
    });
    nextPage.getChildren().add(h4);
    StackPane.setAlignment(h4, Pos.TOP_LEFT);
    StackPane.setMargin(h4, new Insets(10));


    JFXNodesAnimation<FlowPane, StackPane> animation = new FlowPaneStackPaneJFXNodesAnimation(main,
                                                                                              nextPage,
                                                                                              wizard,
                                                                                              colorPane1);

    colorPane1.setOnMouseClicked((click) -> animation.animate());

    final Scene scene = new Scene(wizard, 800, 200);
    final ObservableList<String> stylesheets = scene.getStylesheets();
    stylesheets.addAll(ButtonDemo.class.getResource("/css/jfoenix-design.css").toExternalForm(),
                       ButtonDemo.class.getResource("/css/jfoenix-components.css").toExternalForm());
    stage.setTitle("JFX Button Demo");
    stage.setScene(scene);
    stage.show();

}