/** * Creates a container with the given animation type and duration. * * @param duration the duration of the animation * @param animationProducer the {@link KeyFrame} instances that define the animation */ public ExtendedAnimatedFlowContainer(Duration duration, Function<AnimatedFlowContainer, List<KeyFrame>> animationProducer) { this.view = new StackPane(); this.duration = duration; this.animationProducer = animationProducer; placeholder = new ImageView(); placeholder.setPreserveRatio(true); placeholder.setSmooth(true); }
@Override public ImageView createNode() { final ImageView view = new ImageView(); view.setPreserveRatio(true); view.setFitHeight(48); brand.logoLarge() .map(Image::new) .ifPresent(view::setImage); return view; }
private void updatePlaceholder(Node newView) { if (view.getWidth() > 0 && view.getHeight() > 0) { SnapshotParameters parameters = new SnapshotParameters(); parameters.setFill(Color.TRANSPARENT); Image placeholderImage = view.snapshot(parameters, new WritableImage((int) view.getWidth(), (int) view.getHeight())); placeholder.setImage(placeholderImage); placeholder.setFitWidth(placeholderImage.getWidth()); placeholder.setFitHeight(placeholderImage.getHeight()); } else { placeholder.setImage(null); } placeholder.setVisible(true); placeholder.setOpacity(1.0); view.getChildren().setAll(placeholder, newView); placeholder.toFront(); } }
@Override public void cache(Pane node) { if (!cache.containsKey(node)) { SnapshotParameters snapShotparams = new SnapshotParameters(); snapShotparams.setFill(Color.TRANSPARENT); WritableImage temp = node.snapshot(snapShotparams, new WritableImage((int) node.getLayoutBounds().getWidth(), (int) node.getLayoutBounds().getHeight())); ImageView tempImage = new ImageView(temp); tempImage.setCache(true); tempImage.setCacheHint(CacheHint.SPEED); cache.put(node, new ArrayList<>(node.getChildren())); node.getChildren().setAll(tempImage); } }
@Override public ImageView view() { return new ImageView(load()); }
snapShotparams.setFill(Color.TRANSPARENT); WritableImage temp = monthContent.snapshot(snapShotparams, new WritableImage((int) monthContent.getWidth(), (int) monthContent.getHeight())); ImageView tempImage = new ImageView(temp); calendarPlaceHolder.getChildren().add(calendarPlaceHolder.getChildren().size() - 2, tempImage); TranslateTransition imageTransition = new TranslateTransition(Duration.millis(160), tempImage);
public Image load(Document node) { return new Image(getFileInputStream(node)); }
private Image getSLCricle(int width, int height) { WritableImage raster = new WritableImage(width, height); PixelWriter pixelWriter = raster.getPixelWriter(); Point2D center = new Point2D((double) width / 2, (double) height / 2); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { double dy = x - center.getX(); double dx = y - center.getY(); pixelWriter.setColor(x, y, getColor(dx, dy)); } } return raster; }
imageView.getFitWidth(), imageView.getFitHeight() ); clip.setArcWidth(20); clip.setArcHeight(20); imageView.setClip(clip); WritableImage image = imageView.snapshot(parameters, null); imageView.setClip(null); imageView.setEffect(new DropShadow(20, Color.BLACK)); imageView.setImage(image);
private void updateHSLCircleColor(int x, int y) { // transform color to HSL space Color color = huesCircleView.getImage().getPixelReader().getColor(x, y); double max = Math.max(color.getRed(), Math.max(color.getGreen(), color.getBlue())); double min = Math.min(color.getRed(), Math.min(color.getGreen(), color.getBlue())); double hue = 0; if (max != min) { double d = max - min; if (max == color.getRed()) { hue = (color.getGreen() - color.getBlue()) / d + (color.getGreen() < color.getBlue() ? 6 : 0); } else if (max == color.getGreen()) { hue = (color.getBlue() - color.getRed()) / d + 2; } else if (max == color.getBlue()) { hue = (color.getRed() - color.getGreen()) / d + 4; } hue /= 6; } currentHue = map(hue, 0, 1, 0, 255); // refresh the HSL circle refreshHSLCircle(); }
Image tile = new Image("tile.png"); Group house = new Group(); house.setCache(true); house.setCacheHint(CacheHint.SPEED); Effect lighting = new Lighting(); for (int i = 0; i < houseWidth; i++) { // here is the critical part => don't do new ImageView(new Image("tile.png")) ImageView tileView = new ImageView(tile)); tileView.setEffect(lighting); tileView.setCache(true); tileView.setCacheHint(CacheHint.SPEED); house.add(tileView); }
private void refreshHSLCircle() { ColorAdjust colorAdjust = new ColorAdjust(); colorAdjust.setHue(map(currentHue + (currentHue < 127.5 ? 1 : -1) * 127.5, 0, 255, -1, 1)); slCircleView.setEffect(colorAdjust); setColorAtLocation((int) selector.getTranslateX() + selectorSize / 2, (int) selector.getTranslateY() + selectorSize / 2); }
private void showDialog() { if (dialogContainer == null) { throw new RuntimeException("ERROR: JFXDialog container is not set!"); } if (isCacheContainer()) { tempContent = new ArrayList<>(dialogContainer.getChildren()); SnapshotParameters snapShotparams = new SnapshotParameters(); snapShotparams.setFill(Color.TRANSPARENT); WritableImage temp = dialogContainer.snapshot(snapShotparams, new WritableImage((int) dialogContainer.getWidth(), (int) dialogContainer.getHeight())); ImageView tempImage = new ImageView(temp); tempImage.setCache(true); tempImage.setCacheHint(CacheHint.SPEED); dialogContainer.getChildren().setAll(tempImage, this); } else { //prevent error if opening an already opened dialog dialogContainer.getChildren().remove(this); tempContent = null; dialogContainer.getChildren().add(this); } if (animation != null) { animation.play(); } else { setVisible(true); setOpacity(1); Event.fireEvent(JFXDialog.this, new JFXDialogEvent(JFXDialogEvent.OPENED)); } }
public ImageView view() { return new ImageView(image()); }
public Image image() { return new Image(inputStream()); }
private Image getHuesCircle(int width, int height) { WritableImage raster = new WritableImage(width, height); PixelWriter pixelWriter = raster.getPixelWriter(); Point2D center = new Point2D((double) width / 2, (double) height / 2); double rsmall = 0.8 * width / 2; double rbig = (double) width / 2; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { double dx = x - center.getX(); double dy = y - center.getY(); double distance = Math.sqrt((dx * dx) + (dy * dy)); double o = Math.atan2(dy, dx); if (distance > rsmall && distance < rbig) { double H = map(o, -Math.PI, Math.PI, 0, 255); double S = 255; double L = 152; pixelWriter.setColor(x, y, HSL2RGB(H, S, L)); } } } return raster; }
public ImageView view(Document node) { return new ImageView(load(node)); }
public Image load() { return new Image(getFileInputStream()); }