/** * resize the svg to certain width while keeping the width/height ratio * * @param width in pixel */ public void setSizeForWidth(double width) { double height = width / widthHeightRatio; setSize(width, height); }
@Override public void invalidated() { setSizeRatio(getSize()); } };
/** * resize the svg to a certain width and height * * @param width * @param height */ public void setSize(double width, double height) { this.setMinSize(StackPane.USE_PREF_SIZE, StackPane.USE_PREF_SIZE); this.setPrefSize(width, height); this.setMaxSize(StackPane.USE_PREF_SIZE, StackPane.USE_PREF_SIZE); }
this.glyphId = glyphId; this.name = name; getStyleClass().add(DEFAULT_STYLE_CLASS); this.fill.addListener((observable) -> setBackground(new Background( new BackgroundFill(getFill() == null ? Color.BLACK : getFill(), null, null)))); shapeProperty().addListener(observable -> { Shape shape = getShape(); if (getShape() != null) { widthHeightRatio = shape.prefWidth(-1) / shape.prefHeight(-1); if (getSize() != Region.USE_COMPUTED_SIZE) { setSizeRatio(getSize()); SVGPath shape = new SVGPath(); shape.setContent(svgPathContent); setShape(shape); setFill(fill); setPrefSize(DEFAULT_PREF_SIZE, DEFAULT_PREF_SIZE);
private void refreshView() { if (glyph.getValue() == null) { idLabel.setText(""); nameLabel.setText(""); return; } sizeSlider.valueProperty().addListener(observable -> glyph.get().setSize(sizeSlider.getValue())); idLabel.setText(String.format("%04d", glyph.get().getGlyphId())); nameLabel.setText(glyph.get().getName()); glyph.get().setFill(colorPicker.getValue()); glyph.get().fillProperty().bind(colorPicker.valueProperty()); centeredGlyph.getChildren().setAll(glyph.get()); }
/** * will retrieve icons from the glyphs map for a certain glyphName * * @param glyphName the glyph name * @return SVGGlyph node */ public static SVGGlyph getIcoMoonGlyph(String glyphName) throws Exception{ SVGGlyphBuilder builder = glyphsMap.get(glyphName); if(builder == null) throw new Exception("Glyph '" + glyphName + "' not found!"); SVGGlyph glyph = builder.build(); // we need to apply transformation to correct the icon since // its being inverted after importing from icomoon glyph.getTransforms().add(new Scale(1, -1)); Translate height = new Translate(); height.yProperty().bind(Bindings.createDoubleBinding(() -> -glyph.getHeight(), glyph.heightProperty())); glyph.getTransforms().add(height); return glyph; }
/** * load a single svg icon from a file * * @param url of the svg icon * @return SVGGLyph node * @throws IOException */ public static SVGGlyph loadGlyph(URL url) throws IOException { String urlString = url.toString(); String filename = urlString.substring(urlString.lastIndexOf('/') + 1); int startPos = 0; int endPos = 0; while (endPos < filename.length() && filename.charAt(endPos) != '-') { endPos++; } int id = Integer.parseInt(filename.substring(startPos, endPos)); startPos = endPos + 1; while (endPos < filename.length() && filename.charAt(endPos) != '.') { endPos++; } String name = filename.substring(startPos, endPos); return new SVGGlyph(id, name, extractSvgPath(getStringFromInputStream(url.openStream())), Color.BLACK); }
/** * init fxml when loaded. */ @PostConstruct public void init() { for (int i = 0; i < 100; i++) { contentList.getItems().add("Item " + i); } contentList.setMaxHeight(3400); JFXScrollPane.smoothScrolling((ScrollPane) scroll.getChildren().get(0)); SVGGlyph arrow = new SVGGlyph(0, "FULLSCREEN", "M402.746 877.254l-320-320c-24.994-24.992-24.994-65.516 0-90.51l320-320c24.994-24.992 65.516-24.992 90.51 0 24.994 24.994 " + "24.994 65.516 0 90.51l-210.746 210.746h613.49c35.346 0 64 28.654 64 64s-28.654 64-64 64h-613.49l210.746 210.746c12.496 " + "12.496 18.744 28.876 18.744 45.254s-6.248 32.758-18.744 45.254c-24.994 24.994-65.516 24.994-90.51 0z", Color.WHITE); arrow.setSize(20, 16); backButton.setGraphic(arrow); backButton.setRipplerFill(Color.WHITE); } }
private ScrollPane allGlyphs() { List<SVGGlyph> glyphs = SVGGlyphLoader.getAllGlyphsIDs() .stream() .map(glyphName -> { try { return SVGGlyphLoader.getIcoMoonGlyph(glyphName); } catch (Exception e) { return null; } }) .collect(Collectors.toList()); glyphs.sort(Comparator.comparing(SVGGlyph::getName)); glyphs.forEach(glyph -> glyph.setSize(16)); List<Button> iconButtons = glyphs.stream().map(this::createIconButton).collect(Collectors.toList()); // important to improve the performance of animation in scroll pane so buttons are treated as images iconButtons.forEach(button -> button.setCache(true)); Platform.runLater(()->iconButtons.get(0).fire()); FlowPane glyphLayout = new FlowPane(); glyphLayout.setHgap(10); glyphLayout.setVgap(10); glyphLayout.setPadding(new Insets(10)); glyphLayout.getChildren().setAll(iconButtons); glyphLayout.setPrefSize(600, 300); ScrollPane scrollableGlyphs = new ScrollPane(glyphLayout); scrollableGlyphs.setFitToWidth(true); return scrollableGlyphs; }
suggestions.put("Glass", new MyShape("Glass", SVGGlyphLoader.getIcoMoonGlyph("icomoon.svg.glass"))); suggestions.put("Star", new MyShape("Star", SVGGlyphLoader.getIcoMoonGlyph("icomoon.svg.star"))); suggestions.put("Music", new MyShape("Music", SVGGlyphLoader.getIcoMoonGlyph("icomoon.svg.music"))); final SVGGlyph icoMoonGlyph = SVGGlyphLoader.getIcoMoonGlyph("icomoon.svg.heart"); icoMoonGlyph.getStyleClass().add("heart"); suggestions.put("Heart", new MyShape("Heart", icoMoonGlyph)); suggestions.put("Film", new MyShape("Film", SVGGlyphLoader.getIcoMoonGlyph("icomoon.svg.film")));
SVGGlyph build() { return new SVGGlyph(glyphId, name, svgPathContent, Color.BLACK); } }
new Thread(() -> { try { SVGGlyphLoader.loadGlyphsFont(MainDemo.class.getResourceAsStream("/fonts/icomoon.svg"), "icomoon.svg"); } catch (IOException ioExc) { decorator.setGraphic(new SVGGlyph(""));
private void viewGlyphDetail(SVGGlyph glyph) { try { glyphDetailViewer.setGlyph(SVGGlyphLoader.getIcoMoonGlyph(fileName + "." + glyph.getName())); } catch (Exception e) { } }
public static SVGGlyph getGlyph(String glyphName) { return glyphsMap.get(glyphName).build(); }
@Override public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() { if (STYLEABLES == null) { final List<CssMetaData<? extends Styleable, ?>> styleables = new ArrayList<>(Pane.getClassCssMetaData()); styleables.addAll(getClassCssMetaData()); STYLEABLES = Collections.unmodifiableList(styleables); } return STYLEABLES; }
private void showTabsMenu(boolean value) { final boolean wasTabsMenuShowing = isControlButtonShown(); this.showTabsHeaderControls = value; // need to show & it was not showing if (showTabsHeaderControls && !wasTabsMenuShowing) { arrowButton.setVisible(true); showControlButtons = true; inner.requestLayout(); header.layoutChildren(); } else { // need to hide & was showing if (!showTabsHeaderControls && wasTabsMenuShowing) { container.setPrefWidth(0); // hide control button if (isControlButtonShown()) { showControlButtons = true; } else { setVisible(false); } requestLayout(); } } }
/** * resize the svg to certain width while keeping the width/height ratio * * @param height in pixel */ public void setSizeForHeight(double height) { double width = height * widthHeightRatio; setSize(width, height); }
public JFXDefaultChip(JFXChipView<T> view, T item) { super(view, item); JFXButton closeButton = new JFXButton(null, new SVGGlyph()); closeButton.getStyleClass().add("close-button"); closeButton.setOnAction((event) -> view.getChips().remove(item)); String tagString = null; if (getItem() instanceof String) { tagString = (String) getItem(); } else { tagString = view.getConverter().toString(getItem()); } Label label = new Label(tagString); label.setWrapText(true); root = new HBox(label, closeButton); getChildren().setAll(root); label.setMaxWidth(100); } }
/** * resize the svg to this size while keeping the width/height ratio * * @param size in pixel */ private void setSizeRatio(double size) { double width = widthHeightRatio * size; double height = size / widthHeightRatio; if (width <= size) { setSize(width, size); } else if (height <= size) { setSize(size, height); } else { setSize(size, size); } }
final void setGlyph(SVGGlyph glyph) { glyph.setSize(sizeSlider.getValue()); this.glyph.set(glyph); } }