List of usage examples for javafx.scene.image Image isError
public final boolean isError()
From source file:ch.tuason.djbattlescore.lib.components.comps.NowPlayingImageRotator.java
private void addRightImageToView(DjEntity leadingDj) { if (leadingDj != null && !StringUtils.isEmpty(leadingDj.getAvatarPicPathMain())) { Image image = getImageFromCache(leadingDj); if (image == null) { try { image = new Image( DjBattleConstants.IMAGE_RESOURCE_BASE_FOR_DJ_PICS + leadingDj.getAvatarPicPathMain()); if (!image.isError()) { imageCache.put(leadingDj.getId(), image); }/*from w w w .j av a 2s . c o m*/ } catch (Exception e) { System.out.println("the image for dj '" + leadingDj.getName() + "' could not be loaded for the image rotator... " + e.getMessage()); image = null; } try { // it might be an absolute path? if (image == null) { image = new Image(DjBattleConstants.ABSOLUTE_IMAGE_FILEPATH_PREFIX + leadingDj.getAvatarPicPathMain()); if (!image.isError()) { imageCache.put(leadingDj.getId(), image); } } } catch (Exception e) { System.out.println("the image for dj '" + leadingDj.getName() + "' could not be loaded for the image rotator... " + e.getMessage()); image = null; } } if (image == null) { image = getStandardImage(); } getImageView().setImage(image); } else { getImageView().setImage(getStandardImage()); } }
From source file:ch.tuason.djbattlescore.lib.components.comps.ResultGridPane.java
/** * adds a certain DjEntity to the ranking grid panel... * /*from www. j a va 2s . c om*/ * @param results a Collection of DjEntity... */ public void addCurrentDJRanking(Collection<DjEntity> results) { this.addedRankingComponents.clear(); this.currentDjRanking = results; if (this.currentDjRanking != null && !this.currentDjRanking.isEmpty()) { int iPos = 1; for (DjEntity dj : this.currentDjRanking) { Image djImage = null; if (!StringUtils.isEmpty(dj.getAvatarPicPath32())) { djImage = getImageFromCache(dj); if (djImage == null) { try { djImage = new Image(getClass().getResourceAsStream( DjBattleConstants.IMAGE_RESOURCE_BASE_FOR_DJ_PICS + dj.getAvatarPicPath32())); if (!djImage.isError()) { imageCache.put(dj.getId(), djImage); } } catch (Exception e) { System.out.println("the image for dj '" + dj.getName() + "' could not be loaded for the avatar image... " + e.getMessage()); djImage = null; } } // it might be an absolute path? if (djImage == null) { try { djImage = new Image( DjBattleConstants.ABSOLUTE_IMAGE_FILEPATH_PREFIX + dj.getAvatarPicPath32()); if (!djImage.isError()) { imageCache.put(dj.getId(), djImage); } } catch (Exception e) { System.out.println("the image for dj '" + dj.getName() + "' could not be loaded for the avatar image... " + e.getMessage()); djImage = null; } } if (djImage == null) { djImage = getStandardImage(); } } if (StringUtils.isEmpty(dj.getAvatarPicPath32()) || djImage == null) { djImage = getStandardImage(); } HBox djComponent = new HBox(); djComponent.setPadding(new Insets(5, 0, 0, 20)); Label djLabel = new Label(dj.getDjNameWithSoundStyle(), new ImageView(djImage)); djLabel.setFont(new Font("Arial", 20)); // component.setTextFill(Color.web(DjBattleConstants.COLOR_RESULT_TITLE_TEXT)); djComponent.getChildren().add(djLabel); this.addedRankingComponents.add(djComponent); this.add(djComponent, 0, iPos); iPos++; } } }
From source file:com.adr.mimame.PlatformList.java
public Image getCachedImage(String url) { if (url == null) { return null; } else if (!"http".equalsIgnoreCase(url.substring(0, 4)) && !"ftp".equalsIgnoreCase(url.substring(0, 3))) { // a local image return new Image(url, true); } else {/* w w w. j a va 2 s . com*/ // a remote image try { File cachedir = new File(mimamememuhome, "IMGCACHE"); FileUtils.forceMkdir(cachedir); MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(url.getBytes("UTF-8")); String cachefilename = Base64.getUrlEncoder().encodeToString(md.digest()); File cachefile = new File(cachedir, cachefilename + ".png"); File cachefilenull = new File(cachedir, cachefilename + ".null"); if (cachefilenull.exists()) { return null; } else if (cachefile.exists()) { return new Image(cachefile.toURI().toURL().toString(), true); } else { Image img = new Image(url, true); img.progressProperty().addListener( (ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> { if (newValue.doubleValue() == 1.0) { exec.execute(() -> { try { if (img.isError()) { cachefilenull.createNewFile(); } else { ImageIO.write(SwingFXUtils.fromFXImage(img, null), "png", cachefile); } } catch (IOException ex) { logger.log(Level.SEVERE, "Cannot save image cache.", ex); } }); } }); return img; } } catch (IOException | NoSuchAlgorithmException ex) { logger.log(Level.SEVERE, "Cannot create image cache.", ex); return new Image(url); } } }
From source file:org.sleuthkit.autopsy.imageanalyzer.ThumbnailCache.java
/** * generate a new thumbnail for the given file and save it to the disk cache * * @param file//from w w w . ja va2s .co m * * @return the newly generated thumbnail {@link Image}, or {@code null} if a * thumbnail could not be generated */ private Image generateAndSaveThumbnail(final DrawableFile<?> file) { //create a buffered input stream for the underlying Abstractfile try (InputStream inputStream = new BufferedInputStream( new ReadContentInputStream(file.getAbstractFile()))) { final Image thumbnail = new Image(inputStream, MAX_ICON_SIZE, MAX_ICON_SIZE, true, true); if (thumbnail.isError()) { //if there was an error loading the image via JFX, fall back on Swing LOGGER.log(Level.WARNING, "problem loading image: " + file.getName() + " .", thumbnail.getException()); return fallbackToSwingImage(file); } else { //if the load went successfully, save the thumbnail to disk on a background thread imageSaver.execute(() -> { saveIcon(file, thumbnail); }); return thumbnail; } } catch (IOException ex) { //if the JX load throws an exception fall back to Swing return fallbackToSwingImage(file); } }
From source file:org.sleuthkit.autopsy.imagegallery.ThumbnailCache.java
/** * generate a new thumbnail for the given file and save it to the disk cache * * @param file// w ww . jav a2 s . co m * * @return the newly generated thumbnail {@link Image}, or {@code null} if a * thumbnail could not be generated */ private Image generateAndSaveThumbnail(final DrawableFile<?> file) { //create a buffered input stream for the underlying Abstractfile try (InputStream inputStream = new BufferedInputStream( new ReadContentInputStream(file.getAbstractFile()))) { final Image thumbnail = new Image(inputStream, MAX_ICON_SIZE, MAX_ICON_SIZE, true, true); if (thumbnail.isError()) { //if there was an error loading the image via JFX, fall back on Swing LOGGER.log(Level.WARNING, "problem loading thumbnail for image: " + file.getName() + " ."); // Doing it this way puts the whole stack trace in the console output, which is probably not // needed. There are a significant number of cases where this is expected to fail (bitmaps, // empty files, etc.) //LOGGER.log(Level.WARNING, "problem loading image: " + file.getName() + " .", thumbnail.getException()); return fallbackToSwingImage(file); } else { //if the load went successfully, save the thumbnail to disk on a background thread imageSaver.execute(() -> { saveIcon(file, thumbnail); }); return thumbnail; } } catch (IOException ex) { //if the JX load throws an exception fall back to Swing return fallbackToSwingImage(file); } }