/** * 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); }
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; }
/** * init fxml when loaded. */ @PostConstruct public void init() throws Exception { final Stage stage = (Stage) context.getRegisteredObject("Stage"); glyphDetailViewer = new GlyphDetailViewer(); detailsContainer.getChildren().add(glyphDetailViewer); ScrollPane scrollableGlyphs = allGlyphs(); scrollableGlyphs.setStyle(FX_BACKGROUND_INSETS_0); iconsContainer.getChildren().add(scrollableGlyphs); browseFont.setOnAction((action) -> { FileChooser fileChooser = new FileChooser(); FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("SVG files (*.svg)", "*.svg"); fileChooser.getExtensionFilters().add(extFilter); File file = fileChooser.showOpenDialog(stage); if (file != null) { SVGGlyphLoader.clear(); try { SVGGlyphLoader.loadGlyphsFont(new FileInputStream(file), file.getName()); ScrollPane newglyphs = allGlyphs(); newglyphs.setStyle(FX_BACKGROUND_INSETS_0); iconsContainer.getChildren().clear(); iconsContainer.getChildren().add(newglyphs); } catch (IOException ioExc) { ioExc.printStackTrace(); } } }); }
private void viewGlyphDetail(SVGGlyph glyph) { try { glyphDetailViewer.setGlyph(SVGGlyphLoader.getIcoMoonGlyph(fileName + "." + glyph.getName())); } catch (Exception e) { } }
new Thread(() -> { try { SVGGlyphLoader.loadGlyphsFont(MainDemo.class.getResourceAsStream("/fonts/icomoon.svg"), "icomoon.svg"); } catch (IOException ioExc) {
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")));
/** * 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); }