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

The following examples show how to use javafx.scene.image.ImageView#setFitWidth() . 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: TableBooleanCell.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@Override
    public TableCell<T, Boolean> call(TableColumn<T, Boolean> param) {
        final ImageView imageview = new ImageView(ControlStyle.getIcon("iconYes.png"));
        imageview.setPreserveRatio(true);
        imageview.setFitWidth(AppVariables.iconSize);
        imageview.setFitHeight(AppVariables.iconSize);
        TableCell<T, Boolean> cell = new TableCell<T, Boolean>() {
            @Override
            public void updateItem(Boolean item, boolean empty) {
                super.updateItem(item, empty);
                if (empty || item == null || !((boolean) item)) {
                    setText(null);
                    setGraphic(null);
                    return;
                }
//                setGraphic(AppVariables.getTrueImage());
//                setText(AppVariables.message("True"));
//                setGraphic(null);

                setGraphic(imageview);
                setText(null);
            }
        };
        return cell;
    }
 
Example 2
Source File: Builders.java    From PDF4Teachers with Apache License 2.0 6 votes vote down vote up
public static ImageView buildImage(FileInputStream file, int width, int height) {
    ImageView imageView = new ImageView(new Image(file));

    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 3
Source File: ImagePropertiesSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static Node createIconContent() {
    //TODO better icon?
    ImageView iv = new ImageView(BRIDGE);
    iv.setFitWidth(80);
    iv.setFitHeight(80);
    iv.setViewport(new Rectangle2D(0, 85, 330, 330));
    return iv;
}
 
Example 4
Source File: ShipTablePane.java    From logbook-kai with MIT License 5 votes vote down vote up
@Override
protected void updateItem(Integer itemId, boolean empty) {
    super.updateItem(itemId, empty);

    if (!empty) {
        if (itemId == 0) {
            this.getStyleClass().add("none");
        } else {
            this.getStyleClass().removeAll("none");
        }
        SlotItem item = this.itemMap.get(itemId);
        if (item != null) {
            if (AppConfig.get().isHideItemImageFromShipTablePane()) {
                this.setGraphic(null);
            } else {
                ImageView img = new ImageView(Items.itemImage(item));
                int percent = AppConfig.get().getImageZoomRate();
                int size = 32;
                if (percent > 0) {
                    size = (int) Math.min(size, 60 * ((double) percent / 100));
                }
                img.setFitWidth(size);
                img.setFitHeight(size);
                this.setGraphic(img);
            }
            this.setText(Items.name(item));
        } else {
            this.setGraphic(null);
            this.setText(null);
        }
    } else {
        this.setGraphic(null);
        this.setText(null);
        this.getStyleClass().removeAll("none");
    }
}
 
Example 5
Source File: CreateProjectWindow.java    From MSPaintIDE with MIT License 5 votes vote down vote up
public CreateProjectWindow(MainGUI mainGUI) throws IOException {
    super();
    this.mainGUI = mainGUI;
    FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("gui/CreateProject.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("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(".search-label", "dark",
            ".found-context", "dark",
            ".language-selection", "language-selection-dark"
    ));
}
 
Example 6
Source File: MainToolbar.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
private MenuItem getMenuItemFromImage(String uri, int width, int height, boolean preserveRatio, boolean smooth) {
    ImageView iv = new ImageView(new Image(QueleaProperties.get().getUseDarkTheme() ? uri.replace(".png", "-light.png") : uri, width, height, preserveRatio, smooth));
    iv.setSmooth(true);
    iv.setFitWidth(24);
    iv.setFitHeight(24);
    return new MenuItem("", iv);
}
 
Example 7
Source File: WebDrawer.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void draw(Displayable displayable) {
    clear();
    if(displayable==null) {
        return;
    }
    d = (WebDisplayable) displayable;
    webView = d.getWebView();
    webEngine = d.getWebEngine();
    if (!getCanvas().isStageView()) {
        if (!d.getUrl().startsWith("http")) {
            d.setUrl("http://" + d.getUrl());
        } else {
            if (webEngine.getTitle() == null) {
                webEngine.load(d.getUrl());
            }
        }
        addWebView(webView);
    } else {
        ImageView imageView = getCanvas().getNewImageView();
        imageView.setFitWidth(getCanvas().getWidth());
        Image image = Utils.getImageFromColour(QueleaProperties.get().getStageBackgroundColor());
        imageView.setImage(image);
        getCanvas().getChildren().add(imageView);
    }

}
 
Example 8
Source File: LyricDrawer.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
public 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 9
Source File: Main.java    From FXTutorials with MIT License 5 votes vote down vote up
private Parent createContent() {
    Pane root = new Pane();
    root.setPrefSize(1280, 720);

    menu.setTranslateX(600);
    menu.setTranslateY(300);
    menu.setScaleX(2);
    menu.setScaleY(2);

    menu.selectedItem.addListener((obs, old, newValue) -> {
        System.out.println("Selected: " + newValue);
    });

    try (InputStream is = getClass().getResourceAsStream("farcry_gameplay.jpg")) {
        Image img = new Image(is);
        ImageView imgView = new ImageView(img);
        imgView.setFitWidth(1280);
        imgView.setFitHeight(720);
        root.getChildren().add(imgView);
    }
    catch (Exception e) {
        System.out.println("Failed to load image: " + e.getMessage());
    }

    root.getChildren().addAll(menu);
    return root;
}
 
Example 10
Source File: Civ6MenuApp.java    From FXTutorials with MIT License 5 votes vote down vote up
private void addBackground() {
    ImageView imageView = new ImageView(new Image(getClass().getResource("res/Civ6_bg.png").toExternalForm()));
    imageView.setFitWidth(WIDTH);
    imageView.setFitHeight(HEIGHT);

    root.getChildren().add(imageView);
}
 
Example 11
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 12
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 13
Source File: SepiaToneSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static Node createIconContent() {
    ImageView iv = new ImageView(BOAT);
    iv.setFitWidth(80);
    iv.setFitHeight(80);
    iv.setViewport(new Rectangle2D(90,0,332,332));
    final SepiaTone SepiaTone = new SepiaTone();
    SepiaTone.setLevel(1);
    iv.setEffect(SepiaTone);
    return iv;
}
 
Example 14
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 15
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 16
Source File: SettingsWindow.java    From MSPaintIDE with MIT License 4 votes vote down vote up
public SettingsWindow(MainGUI mainGUI, List<SettingItem> settingItems, String startPath) throws IOException {
    super();
    this.mainGUI = mainGUI;
    this.settingItems = settingItems;
    this.startPath = startPath;
    FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("gui/PopupWindow.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("Settings");

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

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

    setTitle("Settings");
    getIcons().add(new Image(getClass().getClassLoader().getResourceAsStream("ms-paint-logo-taskbar.png")));

    toggleStuff = newValue -> Map.of(
            "gridpane-theme", "gridpane-theme-dark",
            "theme-text", "dark-text",
            "search-label", "dark",
            "found-context", "dark",
            "language-selection", "language-selection-dark"
    ).forEach((key, value) -> root.lookupAll("." + key)
            .stream()
            .map(Node::getStyleClass)
            .forEach(styles -> {
                if (newValue) {
                    styles.add(value);
                } else {
                    while (styles.remove(value));
                }
            }));

    SettingsManager.getInstance().onChangeSetting(Setting.DARK_THEME, toggleStuff, true);

    List<TreeItem<SettingItem>> children = tree.getRoot().getChildren();

    if (startPath != null) {
        children.stream().flatMap(x -> Stream.of(x.isLeaf() ? x : x.getChildren())).map(TreeItem.class::cast).forEach(genericItem -> {
            SettingItem item = ((TreeItem<SettingItem>) genericItem).getValue();

            MultipleSelectionModel<TreeItem<SettingItem>> selectionModel = tree.getSelectionModel();
            if (item.toString().equalsIgnoreCase(startPath)) selectionModel.select(genericItem);
        });
    }

    tree.getSelectionModel().select(0);
}
 
Example 17
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 18
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static Image addMarginsFx2(Image image, Color color, int MarginWidth,
        boolean addTop, boolean addBottom, boolean addLeft, boolean addRight) {
    try {
        if (image == null || MarginWidth <= 0) {
            return image;
        }
        Group group = new Group();
        double imageWidth = image.getWidth(), imageHeight = image.getHeight();
        double totalWidth = image.getWidth(), totalHeight = image.getHeight();
        ImageView view = new ImageView(image);
        view.setPreserveRatio(true);
        view.setFitWidth(imageWidth);
        view.setFitHeight(imageHeight);
        if (addLeft) {
            view.setX(MarginWidth);
            totalWidth += MarginWidth;
        } else {
            view.setX(0);
        }
        if (addTop) {
            view.setY(MarginWidth);
            totalHeight += MarginWidth;
        } else {
            view.setY(0);
        }
        if (addBottom) {
            totalHeight += MarginWidth;
        }
        if (addRight) {
            totalWidth += MarginWidth;
        }
        group.getChildren().add(view);

        Blend blend = new Blend(BlendMode.SRC_OVER);
        blend.setBottomInput(new ColorInput(0, 0, totalWidth, totalHeight, color));
        group.setEffect(blend);

        SnapshotParameters parameters = new SnapshotParameters();
        parameters.setFill(Color.TRANSPARENT);
        WritableImage newImage = group.snapshot(parameters, null);
        return newImage;

    } catch (Exception e) {
        logger.error(e.toString());
        return image;
    }

}
 
Example 19
Source File: FXColorPicker.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Constructs a new {@link FXColorPicker}.
 *
 * @param parent
 *            The parent {@link Composite}.
 * @param color
 *            The initial {@link Color} to set.
 */
public FXColorPicker(final Composite parent, Color color) {
	super(parent, SWT.NONE);
	setLayout(new FillLayout());

	FXCanvas canvas = new FXCanvas(this, SWT.NONE);

	// container
	Group colorPickerGroup = new Group();
	HBox hbox = new HBox();
	colorPickerGroup.getChildren().add(hbox);

	// color wheel
	WritableImage colorWheelImage = new WritableImage(64, 64);
	renderColorWheel(colorWheelImage, 0, 0, 64);
	ImageView colorWheel = new ImageView(colorWheelImage);
	colorWheel.setFitWidth(16);
	colorWheel.setFitHeight(16);

	BorderPane colorWheelPane = new BorderPane();
	Insets insets = new Insets(2.0);
	colorWheelPane.setPadding(insets);
	colorWheelPane.setCenter(colorWheel);
	// use background color of parent composite (the wheel image is
	// transparent outside the wheel, so otherwise the hbox color would look
	// through)
	colorWheelPane.setStyle("-fx-background-color: "
			+ computeRgbString(Color.rgb(parent.getBackground().getRed(),
					parent.getBackground().getGreen(),
					parent.getBackground().getBlue())));

	colorRectangle = new Rectangle(50, 20);
	// bind to ColorWheel instead of buttonPane to prevent layout
	// problems.
	colorRectangle.widthProperty().bind(colorWheel.fitWidthProperty()
			.add(insets.getLeft()).add(insets.getRight()).multiply(2.5));
	colorRectangle.heightProperty().bind(colorWheelPane.heightProperty());

	// draw 'border' around hbox (and fill background, which covers the
	// space beween color rect and wheel
	hbox.setStyle("-fx-border-color: " + computeRgbString(Color.DARKGREY)
			+ "; -fx-background-color: "
			+ computeRgbString(Color.DARKGREY));
	hbox.getChildren().addAll(colorRectangle, colorWheelPane);
	hbox.setSpacing(0.5);

	// interaction
	colorWheelPane.setOnMouseClicked(new EventHandler<MouseEvent>() {
		@Override
		public void handle(MouseEvent event) {
			Color colorOrNull = FXColorPicker.pickColor(getShell(),
					getColor());
			if (colorOrNull != null) {
				setColor(colorOrNull);
			}
		}
	});

	Scene scene = new Scene(colorPickerGroup);

	// copy background color from parent composite
	org.eclipse.swt.graphics.Color backgroundColor = parent.getBackground();
	scene.setFill(Color.rgb(backgroundColor.getRed(),
			backgroundColor.getGreen(), backgroundColor.getBlue()));
	canvas.setScene(scene);

	// initialize some color
	setColor(color);

	colorRectangle.fillProperty().bind(this.color);
}
 
Example 20
Source File: Icons.java    From Jupiter with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Creates an image view from an image icon with the given width and height.
 *
 * @param name image name
 * @param width image view fit width
 * @param height image view fit height
 * @return image view
 */
public static ImageView get(String name, double width, double height) {
  ImageView img = new ImageView();
  img.setFitWidth(width);
  img.setFitHeight(height);
  img.setImage(new Image(Icons.class.getResourceAsStream(String.format("/jupiter/img/icons/%s.png", name))));
  return img;
}