Java Code Examples for javafx.scene.image.ImageView#setFitHeight()

The following examples show how to use javafx.scene.image.ImageView#setFitHeight() . 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: IconAttributeInteraction.java    From constellation with Apache License 2.0 6 votes vote down vote up
@Override
public List<Node> getDisplayNodes(Object value, double width, double height) {
    Image iconImage = null;

    final ConstellationIcon icon = (ConstellationIcon) value;
    if (icon != null) {
        iconImage = icon.buildImage();
    }

    final double rectWidth = width == -1 ? height == -1 ? DEFAULT_NODE_SIZE : height : width;
    final double rectHeight = height == -1 ? rectWidth : height;

    final ImageView imageView = new ImageView(iconImage);
    imageView.setPreserveRatio(true);
    imageView.setFitHeight(rectHeight);
    return Arrays.asList(imageView);
}
 
Example 2
Source File: IndexController.java    From Spring-generator with MIT License 6 votes vote down vote up
/**
 * 加载数据库到树集
 * 
 * @throws Exception
 */
public void loadTVDataBase() throws Exception {
	TreeItem<String> rootTreeItem = tvDataBase.getRoot();
	rootTreeItem.getChildren().clear();
	List<DatabaseConfig> item = null;
	item = ConfigUtil.getDatabaseConfig();
	for (DatabaseConfig dbConfig : item) {
		TreeItem<String> treeItem = new TreeItem<String>();
		treeItem.setValue(dbConfig.getConnName());
		ImageView dbImage = new ImageView("image/database.png");
		dbImage.setFitHeight(20);
		dbImage.setFitWidth(20);
		dbImage.setUserData(dbConfig);
		treeItem.setGraphic(dbImage);
		rootTreeItem.getChildren().add(treeItem);
	}
}
 
Example 3
Source File: FxmlControl.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public static void zoomOut(ScrollPane sPane, ImageView iView, int xZoomStep,
        int yZoomStep) {
    double currentWidth = iView.getFitWidth();
    if (currentWidth == -1) {
        currentWidth = iView.getImage().getWidth();
    }
    if (currentWidth <= xZoomStep) {
        return;
    }
    iView.setFitWidth(currentWidth - xZoomStep);
    double currentHeight = iView.getFitHeight();
    if (currentHeight == -1) {
        currentHeight = iView.getImage().getHeight();
    }
    if (currentHeight <= yZoomStep) {
        return;
    }
    iView.setFitHeight(currentHeight - yZoomStep);
    FxmlControl.moveXCenter(sPane, iView);
}
 
Example 4
Source File: ReflectionSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public ReflectionSample() {
    super(100,200);
    ImageView sample = new ImageView(BOAT);
    sample.setPreserveRatio(true);
    sample.setFitHeight(100);
    final Reflection reflection = new Reflection();
    sample.setEffect(reflection);
    getChildren().add(sample);
    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Reflection Bottom Opacity", reflection.bottomOpacityProperty(), 0d, 1d),
            new SimplePropertySheet.PropDesc("Reflection Top Opacity", reflection.topOpacityProperty(), 0d, 1d),
            new SimplePropertySheet.PropDesc("Reflection Fraction", reflection.fractionProperty(), 0d, 1d),
            new SimplePropertySheet.PropDesc("Reflection Top Offset", reflection.topOffsetProperty(), -10d, 10d)
    );
    // END REMOVE ME
}
 
Example 5
Source File: App.java    From java-ml-projects with Apache License 2.0 6 votes vote down vote up
private Parent buildUI() {
	fc = new FileChooser();
	fc.getExtensionFilters().clear();
	ExtensionFilter jpgFilter = new ExtensionFilter("JPG, JPEG images", "*.jpg", "*.jpeg", "*.JPG", ".JPEG");
	fc.getExtensionFilters().add(jpgFilter);
	fc.setSelectedExtensionFilter(jpgFilter);
	fc.setTitle("Select a JPG image");
	lstLabels = new ListView<>();
	lstLabels.setPrefHeight(200);
	Button btnLoad = new Button("Select an Image");
	btnLoad.setOnAction(e -> validateUrlAndLoadImg());

	HBox hbBottom = new HBox(10, btnLoad);
	hbBottom.setAlignment(Pos.CENTER);

	loadedImage = new ImageView();
	loadedImage.setFitWidth(300);
	loadedImage.setFitHeight(250);
	
	Label lblTitle = new Label("Label image using TensorFlow");
	lblTitle.setFont(Font.font(Font.getDefault().getFamily(), FontWeight.BOLD, 40));
	VBox root = new VBox(10,lblTitle, loadedImage, new Label("Results:"), lstLabels, hbBottom);
	root.setAlignment(Pos.TOP_CENTER);
	return root;
}
 
Example 6
Source File: ReflectionSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public ReflectionSample() {
    super(100,200);
    ImageView sample = new ImageView(BOAT);
    sample.setPreserveRatio(true);
    sample.setFitHeight(100);
    final Reflection reflection = new Reflection();
    sample.setEffect(reflection);
    getChildren().add(sample);
    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Reflection Bottom Opacity", reflection.bottomOpacityProperty(), 0d, 1d),
            new SimplePropertySheet.PropDesc("Reflection Top Opacity", reflection.topOpacityProperty(), 0d, 1d),
            new SimplePropertySheet.PropDesc("Reflection Fraction", reflection.fractionProperty(), 0d, 1d),
            new SimplePropertySheet.PropDesc("Reflection Top Offset", reflection.topOffsetProperty(), -10d, 10d)
    );
    // END REMOVE ME
}
 
Example 7
Source File: SampleController.java    From ExoVisix with MIT License 6 votes vote down vote up
private ImageView createImageView(final File imageFile) {

		try {
			final Image img = new Image(new FileInputStream(imageFile), 120, 0, true, true);
			imageView1 = new ImageView(img);

			imageView1.setStyle("-fx-background-color: BLACK");
			imageView1.setFitHeight(120);

			imageView1.setPreserveRatio(true);
			imageView1.setSmooth(true);
			imageView1.setCache(true);

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		return imageView1;
	}
 
Example 8
Source File: Builders.java    From PDF4Teachers with Apache License 2.0 6 votes vote down vote up
public static ImageView buildImage(Image image, int width, int height) {
    ImageView imageView = new ImageView(image);

    if(width == 0 && height == 0) return imageView;

    if(width == 0){
        imageView.setFitHeight(height);
        imageView.setPreserveRatio(true);
    }else if(height == 0){
        imageView.setFitWidth(width);
        imageView.setPreserveRatio(true);
    }else{
        imageView.setFitWidth(width);
        imageView.setFitHeight(height);
    }
    return imageView;
}
 
Example 9
Source File: DeckShipPane.java    From logbook-kai with MIT License 6 votes vote down vote up
@Override
protected void updateItem(SlotitemMst item, boolean empty) {
    super.updateItem(item, empty);
    if (!empty) {
        if (item != null) {
            ImageView view = new ImageView(Items.itemImage(item));
            view.setFitHeight(24);
            view.setFitWidth(24);
            this.setGraphic(view);
            this.setText(itemNameStringConverter.toString(item));
        } else {
            this.setGraphic(null);
            this.setText(null);
        }
    } else {
        this.setGraphic(null);
        this.setText(null);
    }
}
 
Example 10
Source File: ImageOperatorSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static Node createIconContent() {
    final WritableImage img = new WritableImage(80, 80);
    renderImage(img, 3.0, 12.0, 240.0);
    ImageView iv = new ImageView(img);
    iv.setFitWidth(80);
    iv.setFitHeight(80);
    return iv;
}
 
Example 11
Source File: WelcomeWindow.java    From MSPaintIDE with MIT License 5 votes vote down vote up
public WelcomeWindow(MainGUI mainGUI) throws IOException {
    this.mainGUI = mainGUI;
    FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("gui/ProjectManageWindow.fxml"));
    loader.setController(this);
    Parent root = loader.load();

    ImageView icon = new ImageView(getClass().getClassLoader().getResource("icons/taskbar/ms-paint-logo-colored.png").toString());
    icon.setFitHeight(25);
    icon.setFitWidth(25);

    JFXDecorator jfxDecorator = new JFXDecorator(this, root, false, true, true);
    jfxDecorator.setOnCloseButtonAction(() -> System.exit(0));
    jfxDecorator.setGraphic(icon);
    jfxDecorator.setTitle("Welcome to MS Paint IDE");

    Scene scene = new Scene(jfxDecorator);
    scene.getStylesheets().add("style.css");

    setScene(scene);
    //this.mainGUI.getThemeManager().addStage(this);
    show();

    setTitle("Welcome to MS Paint IDE");
    getIcons().add(new Image(getClass().getClassLoader().getResourceAsStream("ms-paint-logo-taskbar.png")));

    this.mainGUI.getThemeManager().onDarkThemeChange(root, Map.of(
            ".logo-image", "dark",
            ".recent-projects", "recent-projects-dark"
    ));
}
 
Example 12
Source File: FindReplaceWindow.java    From MSPaintIDE with MIT License 5 votes vote down vote up
public FindReplaceWindow(MainGUI mainGUI, boolean replace) throws IOException {
    super();
    this.mainGUI = mainGUI;
    this.searchManager = new SearchManager(mainGUI);
    this.initiallyReplace = replace;
    FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("gui/FindReplace.fxml"));
    loader.setController(this);
    Parent root = loader.load();
    setResizable(false);

    ImageView icon = new ImageView(getClass().getClassLoader().getResource("icons/taskbar/ms-paint-logo-colored.png").toString());
    icon.setFitHeight(25);
    icon.setFitWidth(25);

    JFXDecorator jfxDecorator = new JFXDecorator(this, root, false, false, true);
    jfxDecorator.setGraphic(icon);
    jfxDecorator.setTitle("Find" + (replace ? "/Replace" : ""));

    Scene scene = new Scene(jfxDecorator);
    scene.getStylesheets().add("style.css");

    setScene(scene);
    this.mainGUI.getThemeManager().addStage(this);
    show();

    setTitle("Find" + (replace ? "/Replace" : ""));
    getIcons().add(new Image(getClass().getClassLoader().getResourceAsStream("ms-paint-logo-taskbar.png")));

    this.mainGUI.getThemeManager().onDarkThemeChange(root, Map.of("#searchResults", "dark"));
}
 
Example 13
Source File: InspectWindow.java    From MSPaintIDE with MIT License 5 votes vote down vote up
public InspectWindow(MainGUI mainGUI, File inspecting) throws IOException {
    super();
    this.mainGUI = mainGUI;
    this.inspecting = inspecting;

    FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("gui/InspectWindow.fxml"));
    loader.setController(this);
    Parent root = loader.load();

    ImageView icon = new ImageView(getClass().getClassLoader().getResource("icons/taskbar/ms-paint-logo-colored.png").toString());
    icon.setFitHeight(25);
    icon.setFitWidth(25);

    JFXDecorator jfxDecorator = new JFXDecorator(this, root, false, true, true);
    jfxDecorator.setGraphic(icon);
    jfxDecorator.setTitle("Inspecting " + this.inspecting.getName());
    jfxDecorator.setOnCloseButtonAction(() -> Platform.runLater(this::close));

    Scene scene = new Scene(jfxDecorator);
    scene.getStylesheets().add("style.css");

    setScene(scene);
    this.mainGUI.getThemeManager().addStage(this);
    show();

    setTitle("Inspecting " + this.inspecting.getName());
    getIcons().add(new Image(getClass().getClassLoader().getResourceAsStream("ms-paint-logo-taskbar.png")));

    this.mainGUI.getThemeManager().onDarkThemeChange(root, Collections.emptyMap());
}
 
Example 14
Source File: WordDrawer.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
protected void draw(Displayable displayable, double fontSize) {
    drawText(fontSize, displayable instanceof BiblePassage);
    if (getCanvas().getCanvasBackground() instanceof ImageView) {
        ImageView imgBackground = (ImageView) getCanvas().getCanvasBackground();
        imgBackground.setFitHeight(getCanvas().getHeight());
        imgBackground.setFitWidth(getCanvas().getWidth());
    } else if (getCanvas().getCanvasBackground() != null) {
        LOGGER.log(Level.WARNING, "BUG: Unrecognised image background - " + getCanvas().getCanvasBackground().getClass(), new RuntimeException("DEBUG EXCEPTION"));
    }
}
 
Example 15
Source File: TabController.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
private void configureTab(Tab tab, String title, String iconPath, AnchorPane containerPane, URL resourceURL, EventHandler<Event> onSelectionChangedEvent) {
    double imageWidth = 40.0;

    ImageView imageView = new ImageView(new Image(iconPath));
    imageView.setFitHeight(imageWidth);
    imageView.setFitWidth(imageWidth);

    Label label = new Label(title);
    label.setMaxWidth(tabWidth - 20);
    label.setPadding(new Insets(5, 0, 0, 0));
    label.setStyle("-fx-text-fill: black; -fx-font-size: 10pt; -fx-font-weight: bold;");
    label.setTextAlignment(TextAlignment.CENTER);

    BorderPane tabPane = new BorderPane();
    tabPane.setRotate(90.0);
    tabPane.setMaxWidth(tabWidth);
    tabPane.setCenter(imageView);
    tabPane.setBottom(label);

    tab.setText("");
    tab.setGraphic(tabPane);

    tab.setOnSelectionChanged(onSelectionChangedEvent);

    if (containerPane != null && resourceURL != null) {
        try {
            Parent contentView = FXMLLoader.load(resourceURL);
            containerPane.getChildren().add(contentView);
            AnchorPane.setTopAnchor(contentView, 0.0);
            AnchorPane.setBottomAnchor(contentView, 0.0);
            AnchorPane.setRightAnchor(contentView, 0.0);
            AnchorPane.setLeftAnchor(contentView, 0.0);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
Example 16
Source File: ListImageNameCell.java    From MyBox with Apache License 2.0 4 votes vote down vote up
private void init() {
    view = new ImageView();
    view.setPreserveRatio(true);
    view.setFitHeight(height);
}
 
Example 17
Source File: PauseView.java    From CrazyAlpha with GNU General Public License v2.0 4 votes vote down vote up
public PauseView() {
    root = new Pane();
    Game.getInstance().resetMedia();

    map = Game.getInstance().getMapManager().getCurrentMap();
    mapIv = new ImageView(map.getMapImage());
    mapIv.setFitWidth(Game.getInstance().getWidth());
    mapIv.setFitHeight(Game.getInstance().getHeight());

    nameLbl = new Label("CrazyAlpha!");
    nameLbl.setTextFill(Color.WHITESMOKE);
    nameLbl.setFont(Game.getInstance().getResouceManager().getFont("Starcraft", 120));
    nameLbl.setLayoutX(50);
    nameLbl.setLayoutY(50);

    Reflection reflection1 = new Reflection();
    reflection1.setFraction(1.0);
    nameLbl.setEffect(reflection1);

    Reflection reflection02 = new Reflection();
    reflection02.setFraction(0.4);

    resumeBtn = new ImageView(Game.getInstance().getResouceManager().getControl("btn_resume"));
    resumeBtn.setFitWidth(165 * 1.5);
    resumeBtn.setFitHeight(65 * 1.5);
    exitBtn = new ImageView(Game.getInstance().getResouceManager().getControl("btn_exit"));
    exitBtn.setFitWidth(165 * 1.5);
    exitBtn.setFitHeight(65 * 1.5);

    resumeBtn.setLayoutX(map.getWidth() - resumeBtn.getFitWidth() - 20);
    resumeBtn.setLayoutY(map.getHeight() - resumeBtn.getFitHeight() - exitBtn.getFitHeight() - 120);
    resumeBtn.setEffect(reflection02);
    resumeBtn.setOnMouseEntered(event -> {
        resumeBtn.setEffect(new Glow(0.8));
        Game.getInstance().getButtonOverMusic().play();
    });
    resumeBtn.setOnMouseExited(event -> {
        resumeBtn.setEffect(reflection02);
        Game.getInstance().getButtonClickMusic().stop();
    });
    resumeBtn.setOnMousePressed(event -> {
        resumeBtn.setEffect(new GaussianBlur());
        Game.getInstance().getButtonClickMusic().play();
        Game.getInstance().resume();
    });
    resumeBtn.setOnMouseReleased(event -> {
        resumeBtn.setEffect(new Glow(0.8));
    });

    exitBtn.setLayoutX(map.getWidth() - exitBtn.getFitWidth() - 20);
    exitBtn.setLayoutY(map.getHeight() - exitBtn.getFitHeight() - 60);
    exitBtn.setEffect(reflection02);
    exitBtn.setOnMouseEntered(event -> {
        exitBtn.setEffect(new Glow(0.8));
        Game.getInstance().getButtonOverMusic().play();
    });
    exitBtn.setOnMouseExited(event -> {
        exitBtn.setEffect(reflection02);
        Game.getInstance().getButtonOverMusic().stop();
    });
    exitBtn.setOnMousePressed(event -> {
        exitBtn.setEffect(new GaussianBlur());
        Game.getInstance().getButtonClickMusic().play();
    });
    exitBtn.setOnMouseReleased(event -> {
        exitBtn.setEffect(new Glow(0.8));
        Game.getInstance().exit();
    });


    root.getChildren().add(mapIv);
    root.getChildren().add(nameLbl);
    root.getChildren().add(resumeBtn);
    root.getChildren().add(exitBtn);

    makeFadeTransition(resumeBtn, 2000, 1, 0.7);
    makeFadeTransition(exitBtn, 2000, 1, 0.7);
    makeFadeTransition(mapIv, 3000, 1, 0.8);
    makeScaleTransition(mapIv, 10000, 0.25, 0.25);
}
 
Example 18
Source File: ListImageCell.java    From MyBox with Apache License 2.0 4 votes vote down vote up
private void init() {
    view = new ImageView();
    view.setPreserveRatio(true);
    view.setFitHeight(height);
}
 
Example 19
Source File: OverView.java    From CrazyAlpha with GNU General Public License v2.0 4 votes vote down vote up
public OverView() {
    root = new Pane();
    Game.getInstance().resetMedia();

    GameMap map = Game.getInstance().getMapManager().getCurrentMap();
    ImageView mapIv = new ImageView(map.getMapImage());
    mapIv.setFitWidth(Game.getInstance().getWidth());
    mapIv.setFitHeight(Game.getInstance().getHeight());

    Label nameLbl = new Label("Game Over!");
    nameLbl.setTextFill(Color.WHITESMOKE);
    nameLbl.setFont(Game.getInstance().getResouceManager().getFont("Starcraft", 80));
    nameLbl.setLayoutX(50);
    nameLbl.setLayoutY(50);


    Label scoreLbl = new Label();
    scoreLbl.setTextFill(Color.WHITESMOKE);
    scoreLbl.setFont(Game.getInstance().getResouceManager().getFont("Starcraft", 60));
    scoreLbl.setLayoutX(50);
    scoreLbl.setLayoutY(map.getHeight() - scoreLbl.getHeight() - 140);
    if (Game.getInstance().getScore() > Game.getInstance().getDataManager().getHighestScore()) {
        // 刷新高分记录!
        scoreLbl.setText("New Record: " + Game.getInstance().getScore());
        Game.getInstance().getDataManager().setHighestScore(Game.getInstance().getScore());
    } else
        scoreLbl.setText("Score: " + Game.getInstance().getScore());

    Reflection reflection = new Reflection();
    reflection.setFraction(1.0);
    nameLbl.setEffect(reflection);

    ImageView homeBtn = new ImageView(Game.getInstance().getResouceManager().getControl("btn_home"));
    homeBtn.setFitWidth(165 * 1.5);
    homeBtn.setFitHeight(65 * 1.5);

    homeBtn.setLayoutX(map.getWidth() - homeBtn.getFitWidth() - 20);
    homeBtn.setLayoutY(map.getHeight() - homeBtn.getFitHeight() - 60);
    homeBtn.setEffect(reflection);
    homeBtn.setOnMouseEntered(event -> {
        homeBtn.setEffect(new Glow(0.8));
        Game.getInstance().getButtonOverMusic().play();
    });
    homeBtn.setOnMouseExited(event -> {
        homeBtn.setEffect(reflection);
        Game.getInstance().getButtonOverMusic().stop();
    });
    homeBtn.setOnMousePressed(event -> {
        homeBtn.setEffect(new GaussianBlur());
        Game.getInstance().getButtonClickMusic().play();
    });
    homeBtn.setOnMouseReleased(event -> {
        homeBtn.setEffect(new Glow(0.8));
        Game.getInstance().home();
    });

    root.getChildren().add(mapIv);
    root.getChildren().add(nameLbl);
    root.getChildren().add(scoreLbl);
    root.getChildren().add(homeBtn);

    makeFadeTransition(homeBtn, 2000, 1, 0.7);
    makeFadeTransition(mapIv, 3000, 1, 0.8);
    makeScaleTransition(mapIv, 10000, 0.25, 0.25);
}
 
Example 20
Source File: PhoebusApplication.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private ToolBar createToolbar() {
    final ToolBar toolBar = new ToolBar();

    ImageView homeIcon = ImageCache.getImageView(ImageCache.class, "/icons/home.png");
    homeIcon.setFitHeight(16.0);
    homeIcon.setFitWidth(16.0);
    home_display_button = new Button(null, homeIcon);
    home_display_button.setTooltip(new Tooltip(Messages.HomeTT));
    toolBar.getItems().add(home_display_button);

    final TopResources homeResource = TopResources.parse(Preferences.home_display);

    home_display_button.setOnAction(event -> openResource(homeResource.getResource(0), false));

    top_resources_button = new MenuButton(null, ImageCache.getImageView(getClass(), "/icons/fldr_obj.png"));
    top_resources_button.setTooltip(new Tooltip(Messages.TopResources));
    top_resources_button.setDisable(true);
    toolBar.getItems().add(top_resources_button);

    layout_menu_button = new MenuButton(null, ImageCache.getImageView(getClass(), "/icons/layouts.png"));
    layout_menu_button.setTooltip(new Tooltip(Messages.LayoutTT));
    toolBar.getItems().add(layout_menu_button);

    // Contributed Entries
    ToolbarEntryService.getInstance().listToolbarEntries().forEach((entry) -> {
        final AtomicBoolean open_new = new AtomicBoolean();

        // If entry has icon, use that with name as tool tip.
        // Otherwise use the label as button text.
        final Button button = new Button();
        final Image icon = entry.getIcon();
        if (icon == null)
            button.setText(entry.getName());
        else
        {
            button.setGraphic(new ImageView(icon));
            button.setTooltip(new Tooltip(entry.getName()));
        }

        // Want to handle button presses with 'Control' in different way,
        // but action event does not carry key modifier information.
        // -> Add separate event filter to remember the 'Control' state.
        button.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> {
            open_new.set(event.isControlDown());
            // Still allow the button to react by 'arming' it
            button.arm();
        });

        button.setOnAction((event) -> {
            try {
                // Future<?> future = executor.submit(entry.getActions());

                if (open_new.get()) { // Invoke with new stage
                    final Window existing = DockPane.getActiveDockPane().getScene().getWindow();

                    final Stage new_stage = new Stage();
                    DockStage.configureStage(new_stage);
                    entry.call();
                    // Position near but not exactly on top of existing stage
                    new_stage.setX(existing.getX() + 10.0);
                    new_stage.setY(existing.getY() + 10.0);
                    new_stage.show();
                } else
                    entry.call();
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Error invoking toolbar " + entry.getName(), ex);
            }
        });

        toolBar.getItems().add(button);
    });

    toolBar.setPrefWidth(600);
    return toolBar;
}