예제 #1
0
 private void updateIcon() {
   // As we are probably in the animation frame we make this call non blocking by either setting
   // the icon
   // immediately if it is already loaded and present in cache, or deferring the icon load in the
   // background
   String url = getNode().getImageUrl();
   int fitWidth = getNode().getFitWidth().intValue();
   int fitHeight = getNode().getFitHeight().intValue();
   Icon cachedIcon = SwingImageStore.getIconFromCache(url, fitWidth, fitHeight);
   if (cachedIcon != null || url == null)
     swingImage.setIcon(cachedIcon); // Setting the image immediately
   else { // Deferring the image load in the background because it can take more than 16ms
          // (breaking 60 FPS)
     UiScheduler uiScheduler = Toolkit.get().scheduler();
     uiScheduler.runInBackground(
         () -> {
           // Loading the image
           Icon icon = SwingImageStore.getIcon(url, fitWidth, fitHeight);
           // Now that we have the image, we update the JavaFx node (in the UI thread)
           uiScheduler.runInUiThread(() -> swingImage.setIcon(icon));
           // In case the icon is in a table cell, the above call didn't update the UI so we
           // request a UI refresh
           uiScheduler.requestNextPulse();
         });
   }
 }
예제 #2
0
 @Override
 public void paint(Graphics2D g) {
   Icon icon = swingImage.getIcon();
   if (icon != null) {
     ImageView node = getNode();
     swingImage.setBounds(
         node.getX().intValue(),
         node.getY().intValue(),
         icon.getIconWidth(),
         icon.getIconHeight());
     swingImage.paint(g);
   }
 }
예제 #3
0
 public SwingImageViewViewer() {
   super(new ImageViewViewerBase());
   swingImage.setBackground(null); // transparent background
 }
예제 #4
0
 @Override
 public double prefHeight(double width) {
   Icon icon = swingImage.getIcon();
   return icon == null ? getNode().getFitHeight() : icon.getIconHeight();
 }
예제 #5
0
 @Override
 public double prefWidth(double height) {
   Icon icon = swingImage.getIcon();
   return icon == null ? getNode().getFitWidth() : icon.getIconWidth();
 }