private void playAudio(Media media) { if (mediaView.isVisible() == true) { mediaView.setVisible(false); display.setVisible(true); } if (mp != null) { mp.dispose(); } mp = new MediaPlayer(media); mp.play(); mp.setAudioSpectrumListener( (double timestamp, double duration1, float[] magnitudes, float[] phases) -> { display.getChildren().clear(); int i = 0; int x = 10; double y = root.getScene().getHeight() / 2; Random rand = new Random(System.currentTimeMillis()); for (float phase : phases) { int red = rand.nextInt(255); int green = rand.nextInt(255); int blue = rand.nextInt(255); Circle circle = new Circle(10); circle.setCenterX(x + i); circle.setCenterY(y + (phase * 100)); circle.setFill(Color.rgb(red, green, blue, .70)); display.getChildren().add(circle); i += 10; } }); }
private void init(double firingRadius, double templateWidth) { double x0 = templateWidth / 2.0; double y0 = -templateWidth / 2.0; double x5 = templateWidth / 2.0; double y5 = templateWidth / 2.0; double x1 = x0 + firingRadius * Math.cos(45.0 / 180.0 * Math.PI); double y1 = y0 - firingRadius * Math.sin(45.0 / 180.0 * Math.PI); double x2 = x0 + firingRadius; double y2 = y0; double x3 = x5 + firingRadius; double y3 = y5; double x4 = x5 + firingRadius * Math.cos(45.0 / 180.0 * Math.PI); double y4 = y5 + firingRadius * Math.sin(45.0 / 180.0 * Math.PI); this.getElements().add(new MoveTo(x0, y0)); this.getElements().add(new LineTo(x1, y1)); this.getElements().add(new ArcTo(firingRadius, firingRadius, 45, x2, y2, false, true)); this.getElements().add(new LineTo(x3, y3)); this.getElements().add(new ArcTo(firingRadius, firingRadius, 45, x4, y4, false, true)); this.getElements().add(new LineTo(x5, y5)); this.getElements().add(new LineTo(x0, y0)); this.setFill(Color.rgb(255, 0, 0, 0.35)); this.setStroke(Color.rgb(255, 0, 0, 0.5)); this.setFillRule(FillRule.NON_ZERO); }
@Override public void init() { bigGauge = GaugeBuilder.create() .foregroundBaseColor(Color.WHITE) .prefSize(400, 400) .startAngle(270) .angleRange(270) .minValue(100) .maxValue(1000) .tickLabelLocation(TickLabelLocation.OUTSIDE) .tickLabelOrientation(TickLabelOrientation.ORTHOGONAL) .minorTickMarksVisible(false) .majorTickMarkType(TickMarkType.BOX) .valueVisible(false) .knobType(KnobType.FLAT) .needleShape(NeedleShape.FLAT) .needleColor(Color.WHITE) .sectionsVisible(true) .sections( new Section(100, 450, Color.rgb(60, 130, 145, 0.7)), new Section(650, 1000, Color.rgb(200, 100, 0, 0.7))) .animated(true) .build(); smallGauge = GaugeBuilder.create() .prefSize(170, 170) .foregroundBaseColor(Color.WHITE) .minValue(0) .maxValue(10) .minorTickMarksVisible(false) .mediumTickMarkType(TickMarkType.DOT) .majorTickMarkType(TickMarkType.BOX) .tickLabelOrientation(TickLabelOrientation.ORTHOGONAL) .knobType(KnobType.FLAT) .needleShape(NeedleShape.FLAT) .needleColor(Color.WHITE) .valueVisible(false) .customTickLabelsEnabled(true) .customTickLabels("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10") .customTickLabelFontSize(28) .animated(true) .build(); lastTimerCall = System.nanoTime(); timer = new AnimationTimer() { @Override public void handle(long now) { if (now > lastTimerCall + 3_000_000_000l) { bigGauge.setValue(RND.nextDouble() * 900 + 100); smallGauge.setValue(RND.nextDouble() * 10); lastTimerCall = now; } } }; }
/* * initialize lights used in this app */ private void lightSetting() { // Creating Ambient Light AmbientLight ambient = new AmbientLight(); ambient.setColor(Color.rgb(0, 255, 0, 0.6)); // Creating Point Light PointLight point = new PointLight(); point.setColor(Color.rgb(255, 255, 255, 1)); point.setLayoutX(400); point.setLayoutY(100); point.setTranslateZ(-1100); root.getChildren().addAll(ambient, point); }
private Node createBackground(Scene scene) { // application area Rectangle applicationArea = RectangleBuilder.create() .arcWidth(20) .arcHeight(20) .fill(Color.rgb(0, 0, 0, .80)) .x(0) .y(0) .strokeWidth(2) .stroke(Color.rgb(255, 255, 255, .70)) .build(); applicationArea.widthProperty().bind(scene.widthProperty()); applicationArea.heightProperty().bind(scene.heightProperty()); return applicationArea; }
/** * Called by the native code to notify this class when a shot is detected. * * @param x the x coordinate of the new shot * @param y the y coordinate of the new shot * @param rgb the rgb color of the new shot */ public void foundShot(int x, int y, int rgb) { if (!cameraManager.isDetecting()) return; Color c = Color.rgb((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, (rgb >> 8) & 0xFF, 1.0); super.addShot(c, x, y, true); }
/** @author thomas */ public class CellDrawer { private static final int CELL_SIZE = 10; private static final Color COLOR_GREEN_GOSSIP = Color.rgb(135, 211, 124); private Stage primaryStage; private GraphicsContext gc; public void init(final Stage primaryStage, final GraphicsContext gc) { this.primaryStage = primaryStage; this.gc = gc; } public void draw(List<Cell> cells) { gc.clearRect(0, 0, primaryStage.getWidth(), primaryStage.getHeight()); gc.setFill(COLOR_GREEN_GOSSIP); for (Cell cell : cells) { gc.fillOval(CELL_SIZE * cell.getX(), CELL_SIZE * cell.getY(), CELL_SIZE, CELL_SIZE); } gc.restore(); } }
// ******************** Constructors ************************************** public LcdSkin(Gauge gauge) { super(gauge); width = PREFERRED_WIDTH; height = PREFERRED_HEIGHT; valueOffsetLeft = 0.0; valueOffsetRight = 0.0; digitalFontSizeFactor = 1.0; backgroundTextBuilder = new StringBuilder(); valueFormatString = new StringBuilder("%.") .append(Integer.toString(gauge.getDecimals())) .append("f") .toString(); otherFormatString = new StringBuilder("%.") .append(Integer.toString(gauge.getTickLabelDecimals())) .append("f") .toString(); sections = gauge.getSections(); sectionColorMap = new HashMap<>(sections.size()); updateSectionColors(); FOREGROUND_SHADOW.setOffsetX(0); FOREGROUND_SHADOW.setOffsetY(1); FOREGROUND_SHADOW.setColor(Color.rgb(0, 0, 0, 0.5)); FOREGROUND_SHADOW.setBlurType(BlurType.TWO_PASS_BOX); FOREGROUND_SHADOW.setRadius(2); init(); initGraphics(); registerListeners(); }
private Group createButtonArea(final Scene scene) { // create button area final Group buttonGroup = new Group(); // rounded rect Rectangle buttonArea = RectangleBuilder.create() .arcWidth(15) .arcHeight(20) .fill(new Color(0, 0, 0, .55)) .x(0) .y(0) .width(60) .height(30) .stroke(Color.rgb(255, 255, 255, .70)) .build(); buttonGroup.getChildren().add(buttonArea); // move button group when scene is resized buttonGroup .translateXProperty() .bind(scene.widthProperty().subtract(buttonArea.getWidth() + 6)); buttonGroup .translateYProperty() .bind(scene.heightProperty().subtract(buttonArea.getHeight() + 6)); return buttonGroup; }
public static void startValueSetAnimation(final Pane parent) { final javafx.scene.shape.Rectangle rectangle = new javafx.scene.shape.Rectangle(); Insets margin = BorderPane.getMargin(parent); if (margin == null) { margin = new Insets(0); } rectangle .widthProperty() .bind(parent.widthProperty().subtract(margin.getLeft() + margin.getRight())); rectangle .heightProperty() .bind(parent.heightProperty().subtract(margin.getTop() + margin.getBottom())); rectangle.setFill(Color.rgb(0, 150, 201)); parent.getChildren().add(rectangle); BoxBlur bb = new BoxBlur(); bb.setWidth(5); bb.setHeight(5); bb.setIterations(3); rectangle.setEffect(bb); FadeTransition ft = new FadeTransition(Duration.millis(250), rectangle); ft.setFromValue(0.2); ft.setToValue(0.8); ft.setCycleCount(2); ft.setAutoReverse(true); ft.play(); ft.setOnFinished( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { parent.getChildren().remove(rectangle); } }); }
private Rectangle createTic(double angle, double width, double height) { Rectangle rectangle = new Rectangle(-width / 2, -height / 2, width, height); rectangle.setFill(Color.rgb(10, 10, 10)); rectangle.setRotate(angle); rectangle.setLayoutX(radius * Math.cos(Math.toRadians(angle))); rectangle.setLayoutY(radius * Math.sin(Math.toRadians(angle))); return rectangle; }
public LcdClock() { onColor = new SimpleObjectProperty(Color.ORANGERED); offColor = new SimpleObjectProperty(Color.rgb(50, 50, 50)); onEffect = new SimpleObjectProperty<>(new Glow(1.7f)); offEffect = new SimpleObjectProperty(new Glow(1.7f)); onEffect.get().setInput(new InnerShadow()); offEffect.get().setInput(new InnerShadow()); updateBackgroundColor(); }
private void setRGB(final WritableImage IMAGE, final int X, final int Y, final int[] PIXELS) { final PixelWriter RASTER = IMAGE.getPixelWriter(); for (int x = 0; x < PIXELS.length; x++) { RASTER.setColor( X + x, Y, Color.rgb((PIXELS[x] >> 16) & 0xFF, (PIXELS[x] >> 8) & 0xFF, (PIXELS[x] & 0xFF))); } }
private Node createStopControl() { // stop audio control Rectangle stopButton = RectangleBuilder.create() .arcWidth(5) .arcHeight(5) .fill(Color.rgb(255, 255, 255, .80)) .x(0) .y(0) .width(10) .height(10) .translateX(15) .translateY(10) .stroke(Color.rgb(255, 255, 255, .70)) .build(); return stopButton; }
public final class Colors { public static final Color TUD_DARKBLUE = Color.rgb(11, 42, 81); public static final Color TUD_BLUE = Color.rgb(78, 100, 126); public static final Color TUD_LIGHTBLUE = Color.rgb(164, 174, 184); public static final Color TUD_EXTRALIGHTBLUE = Color.rgb(204, 214, 223); public static final String toCSSColorString(final Color color) { return "#" + color.toString().substring(2, 8); } public static Color fromCSSColorString(String string) { return Color.rgb( Integer.parseInt(string.substring(1, 3), 16), Integer.parseInt(string.substring(3, 5), 16), Integer.parseInt(string.substring(5, 7), 16)); } }
private Color[] getSectionColors( final Color LCD_BACKGROUND_COLOR, final Color LCD_FOREGROUND_COLOR) { double hue = LCD_BACKGROUND_COLOR.getHue(); double sat = LCD_BACKGROUND_COLOR.getSaturation(); Color[] colors; if (Helper.isMonochrome(LCD_BACKGROUND_COLOR)) { // Section color is monochrome colors = new Color[] { Color.hsb(hue, 0, 0.69), Color.hsb(hue, 0, 1.0), Color.hsb(hue, 0, 0.76), Color.hsb(hue, 0, 0.76), Color.hsb(hue, sat, 0.69), Helper.isDark(LCD_BACKGROUND_COLOR) ? Color.WHITE : Color.BLACK, Helper.isDark(LCD_BACKGROUND_COLOR) ? Color.rgb(255, 255, 255, 0.1) : Color.rgb(0, 0, 0, 0.1) }; } else { // Section color is not monochrome colors = new Color[] { Color.hsb(hue, sat, 0.69), Color.hsb(hue, sat, 1.0), Color.hsb(hue, sat, 0.76), Color.hsb(hue, sat, 0.76), Color.hsb(hue, sat, 0.69), LCD_FOREGROUND_COLOR, Color.color( LCD_BACKGROUND_COLOR.getRed(), LCD_BACKGROUND_COLOR.getGreen(), LCD_BACKGROUND_COLOR.getBlue(), 0.1) }; } return colors; }
/** * Draw the background color (brown) with the 6" x 6" grid (grey). * * @param origin Origin of the canvases (in the GRF in feet) */ public void initializePane(Point origin) { // set the background color Background background = new Background(new BackgroundFill(Color.rgb(136, 84, 49), CornerRadii.EMPTY, Insets.EMPTY)); displayPane.setBackground(background); GridCanvas grid = new GridCanvas(gridCanvas); // setup the grid grid.init(); // Setup the path stuff path = new PathCanvas(pathCanvas); // setup the robot robot = new RobotCanvas(robotCanvas, path, origin); robot.init(); }
// REMOVE ME public static Node createIconContent() { Path path = new Path(); path.getElements() .addAll(new MoveTo(25, 25), new HLineTo(45), new ArcTo(20, 20, 0, 80, 25, true, true)); path.setStroke(Color.web("#b9c0c5")); path.setStrokeWidth(5); path.getStrokeDashArray().addAll(15d, 15d); path.setFill(null); javafx.scene.effect.InnerShadow effect = new javafx.scene.effect.InnerShadow(); effect.setOffsetX(1); effect.setOffsetY(1); effect.setRadius(3); effect.setColor(Color.rgb(0, 0, 0, 0.6)); path.setEffect(effect); return path; }
private void initialize() { this.setVisible(false); this.getStyleClass().add(DEFAULT_STYLE_CLASS); contentHolder = new StackPane(); contentHolder.setBackground( new Background(new BackgroundFill(Color.WHITE, new CornerRadii(2), null))); JFXDepthManager.setDepth(contentHolder, 4); contentHolder.setPickOnBounds(false); // ensure stackpane is never resized beyond it's preferred size contentHolder.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE); overlayPane = new StackPane(); overlayPane.getChildren().add(contentHolder); overlayPane.getStyleClass().add("jfx-dialog-overlay-pane"); StackPane.setAlignment(contentHolder, Pos.CENTER); overlayPane.setVisible(false); overlayPane.setBackground( new Background(new BackgroundFill(Color.rgb(0, 0, 0, 0.1), null, null))); // close the dialog if clicked on the overlay pane if (overlayClose.get()) overlayPane.addEventHandler(MouseEvent.MOUSE_PRESSED, closeHandler); // prevent propagating the events to overlay pane contentHolder.addEventHandler(MouseEvent.ANY, (e) -> e.consume()); }
private Node createCloseButton(Scene scene) { // close button final Group closeApp = new Group(); Circle closeButton = CircleBuilder.create() .centerX(5) .centerY(0) .radius(7) .fill(Color.rgb(255, 255, 255, .80)) .build(); Text closeXmark = new Text(2, 4, "X"); closeApp.translateXProperty().bind(scene.widthProperty().subtract(15)); closeApp.setTranslateY(10); closeApp.getChildren().addAll(closeButton, closeXmark); closeApp.setOnMouseClicked( new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { Platform.exit(); } }); return closeApp; }
@Override public void start(Stage stage) { DropShadow dropShadow = new DropShadow(10.0, Color.rgb(150, 50, 50, .688)); dropShadow.setOffsetX(4); dropShadow.setOffsetY(6); StackPane stackPane = new StackPane(); stackPane.setAlignment(Pos.CENTER); stackPane.setEffect(dropShadow); Rectangle rectangle = new Rectangle(100, 50, Color.LEMONCHIFFON); rectangle.setArcWidth(30); rectangle.setArcHeight(30); Text text = new Text(); text.setFont(Font.font("Tahoma", FontWeight.BOLD, 18)); stackPane.getChildren().addAll(rectangle, text); final Scene scene = new Scene(stackPane, 400, 200, Color.LIGHTSKYBLUE); stage.setTitle("Custom Binding"); rectangle.widthProperty().bind(scene.widthProperty().divide(2)); rectangle.heightProperty().bind(scene.heightProperty().divide(2)); DoubleBinding opacityBinding = new DoubleBinding() { { // List the dependencies with super.bind() super.bind(scene.widthProperty(), scene.heightProperty()); } @Override protected double computeValue() { // Return the computed value double opacity = (scene.getWidth() + scene.getHeight()) / 1000; return (opacity > 1.0) ? 1.0 : opacity; } }; rectangle.opacityProperty().bind(opacityBinding); text.textProperty().bind((Bindings.format("opacity = %.2f", opacityBinding))); ObjectBinding<Color> colorBinding = new ObjectBinding<Color>() { { super.bind(scene.fillProperty()); } @Override protected Color computeValue() { if (scene.getFill() instanceof Color) { return ((Color) scene.getFill()).darker(); } else { return Color.GRAY; } } }; text.fillProperty().bind(colorBinding); stage.setScene(scene); stage.show(); }
/** Updates DisplacementMap and path for current coordinates. */ public void update() { setUpdateNeeded(false); if (newWidth == map.getWidth() && newHeight == map.getHeight() && targetX == oldTargetX && targetY == oldTargetY) { return; } oldTargetX = targetX; oldTargetY = targetY; if (newWidth != map.getWidth() || newHeight != map.getHeight()) { map.setWidth(newWidth); map.setHeight(newHeight); } final double W = node.getLayoutBounds().getWidth(); final double H = node.getLayoutBounds().getHeight(); // target point F for folded corner final double xF = Math.min(targetX, W - 1); final double yF = Math.min(targetY, H - 1); final Point2D F = new Point2D(xF, yF); // corner point O final double xO = W; final double yO = H; // distance between them final double FO = Math.hypot(xF - xO, yF - yO); final double AF = FO / 2; final double AC = Math.min(AF * 0.5, 200); // radius of the fold as seen along the l2 line final double R = AC / Math.PI * 1.5; final double BC = R; final double flat_R = AC; // Gradient for the line from target point to corner point final double K = (yO - yF) / (xO - xF); // angle of a line l1 final double ANGLE = Math.atan(1 / K); // point A (on line l1 - the mirror line of target and corner points) final double xA = (xO + xF) / 2; final double yA = (yO + yF) / 2; // end points of line l1 final double bottomX = xA - (H - yA) * K; final double bottomY = H; final double rightX = W; final double rightY = yA - (W - xA) / K; final Point2D RL1 = new Point2D(rightX, rightY); final Point2D BL1 = new Point2D(bottomX, bottomY); // point C (on line l2 - the line when distortion begins) final double kC = AC / AF; final double xC = xA - (xA - xF) * kC; final double yC = yA - (yA - yF) * kC; final Point2D C = new Point2D(xC, yC); final Point2D RL2 = new Point2D(W, yC - (W - xC) / K); final Point2D BL2 = new Point2D(xC - (H - yC) * K, H); // point B (on line l3 - the line where distortion ends) final double kB = BC / AC; final double xB = xC + (xA - xC) * kB; final double yB = yC + (yA - yC) * kB; // Bottom ellipse calculations final Point2D BP1 = calcIntersection(F, BL1, BL2, C); final Point2D BP3 = BL2; final Point2D BP2 = middle(BP1, BP3, 0.5); final Point2D BP4 = new Point2D(xB + BP2.getX() - xC, yB + BP2.getY() - yC); final double bE_x1 = hypot(BP2, BP3); final double bE_y2 = -hypot(BP2, BP4); final double bE_yc = -hypot(BP2, BL1); final double bE_y0 = bE_y2 * bE_y2 / (2 * bE_y2 - bE_yc); final double bE_b = bE_y0 - bE_y2; final double bE_a = Math.sqrt(-bE_x1 * bE_x1 / bE_y0 * bE_b * bE_b / bE_yc); // Right ellipse calculations final Point2D RP1 = calcIntersection(F, RL1, RL2, C); final Point2D RP3 = RL2; final Point2D RP2 = middle(RP1, RP3, 0.5); final Point2D RP4 = new Point2D(xB + RP2.getX() - xC, yB + RP2.getY() - yC); final double rE_x1 = hypot(RP2, RP3); final double rE_y2 = -hypot(RP2, RP4); final double rE_yc = -hypot(RP2, RL1); final double rE_y0 = rE_y2 * rE_y2 / (2 * rE_y2 - rE_yc); final double rE_b = rE_y0 - rE_y2; final double rE_a = Math.sqrt(-rE_x1 * rE_x1 / rE_y0 * rE_b * rE_b / rE_yc); p.setFill( new LinearGradient( xF, yF, xO, yO, false, CycleMethod.NO_CYCLE, new Stop(0, pathColor), new Stop((xC - xF) / (xO - xF), bendStartColor), new Stop((xB - xF) / (xO - xF), bendEndColor))); p.getElements() .setAll( new MoveTo(BP4.getX(), BP4.getY()), ArcToBuilder.create() .XAxisRotation(Math.toDegrees(-ANGLE)) .radiusX(bE_a) .radiusY(bE_b) .x(BP1.getX()) .y(BP1.getY()) .build(), new LineTo(xF, yF), new LineTo(RP1.getX(), RP1.getY()), ArcToBuilder.create() .XAxisRotation(Math.toDegrees(-ANGLE)) .radiusX(rE_a) .radiusY(rE_b) .x(RP4.getX()) .y(RP4.getY()) .build(), new ClosePath()); if (shadow != null) { double level0 = (xB - xF) / (xO - xF) - R / FO * 0.5; double level1 = (xB - xF) / (xO - xF) + (0.3 + (200 - AC) / 200) * R / FO; shadow.setFill( new LinearGradient( xF, yF, xO, yO, false, CycleMethod.NO_CYCLE, new Stop(level0, Color.rgb(0, 0, 0, 0.7)), new Stop(level0 * 0.3 + level1 * 0.7, Color.rgb(0, 0, 0, 0.25)), new Stop(level1, Color.rgb(0, 0, 0, 0.0)), new Stop(1, Color.rgb(0, 0, 0, 0)))); shadow .getElements() .setAll( new MoveTo(RP3.getX(), RP3.getY()), ArcToBuilder.create() .XAxisRotation(Math.toDegrees(-ANGLE)) .radiusX(rE_a) .radiusY(rE_b) .x(RP4.getX()) .y(RP4.getY()) .sweepFlag(true) .build(), new LineTo(BP4.getX(), BP4.getY()), ArcToBuilder.create() .XAxisRotation(Math.toDegrees(-ANGLE)) .radiusX(bE_a) .radiusY(bE_b) .x(BP3.getX()) .y(BP3.getY()) .sweepFlag(true) .build(), new LineTo(xO, yO), new ClosePath()); } if (clip != null) { final Point2D RL3 = new Point2D(W, yB - (W - xB) / K); final Point2D BL3 = new Point2D(xB - (H - yB) * K, H); clip.getElements() .setAll( new MoveTo(0, 0), RL3.getY() > 0 ? new LineTo(W, 0) : new LineTo(0, 0), RL3.getY() >= 0 ? new LineTo(RL3.getX(), RL3.getY()) : new LineTo(xB - (0 - yB) * K, 0), BL3.getX() >= 0 ? new LineTo(BL3.getX(), BL3.getY()) : new LineTo(0, yB - (0 - xB) / K), BL3.getX() > 0 ? new LineTo(0, H) : new LineTo(0, 0), new ClosePath()); } final double K2 = -K; final double C2 = BP3.getX() - K2 * H; final double K3 = -K; final double C3 = xB - K3 * yB; final double STEP = Math.max(0.1, R / (buffer.length - 1)); final double HYPOT = Math.hypot(1, K); final double yR = 1.5 * R; double x_1 = 0, y_1 = 0, cur_len = 0; for (double len = 0; len <= R; len += STEP) { final int index = (int) Math.round(len / STEP); final double angle = Math.asin(len / R); final double y = yR * Math.cos(angle); if (len > 0) { cur_len += Math.hypot(y - y_1, len - x_1); } buffer[index][0] = (float) angle; buffer[index][1] = (float) (cur_len * flat_R); x_1 = len; y_1 = y; } double total_len = cur_len; for (double len = 0; len <= R; len += STEP) { final int index = (int) Math.round(len / STEP); final double flat_len = buffer[index][1] / total_len; final double delta_len = flat_len - len; final double xs = delta_len / HYPOT; final double ys = K * delta_len / HYPOT; buffer[index][0] = (float) (xs / W); buffer[index][1] = (float) (ys / H); } for (int y = 0; y < map.getHeight(); y++) { final double lx2 = K2 * (y + 0.5) + C2; final double lx3 = K3 * (y + 0.5) + C3; for (int x = 0; x < map.getWidth(); x++) { if (x + 0.5 < lx2) { map.setSamples(x, y, 0, 0); } else if (x + 0.5 >= lx3 - 1) { map.setSamples(x, y, 1, 0); } else { final double len = Math.abs((x + 0.5) - K2 * (y + 0.5) - C2) / HYPOT; final int index = (int) Math.round(len / STEP); map.setSamples(x, y, buffer[index][0], buffer[index][1]); } } } }
/** Created by hansolo on 21.01.16. */ public class LcdSkin extends SkinBase<Gauge> implements Skin<Gauge> { private static final double PREFERRED_WIDTH = 275; private static final double PREFERRED_HEIGHT = 100; private static final double MINIMUM_WIDTH = 5; private static final double MINIMUM_HEIGHT = 5; private static final double MAXIMUM_WIDTH = 1024; private static final double MAXIMUM_HEIGHT = 1024; private static final Color DARK_NOISE_COLOR = Color.rgb(100, 100, 100, 0.10); private static final Color BRIGHT_NOISE_COLOR = Color.rgb(200, 200, 200, 0.05); private static final DropShadow FOREGROUND_SHADOW = new DropShadow(); private static double aspectRatio = 0.36363636; private static Text oneSegment = new Text("8"); private static Text dotSegment = new Text("."); private double width; private double height; private Pane pane; private Paint lcdPaint; private Paint lcdFramePaint; private ImageView crystalOverlay; private Image crystalImage; private Rectangle crystalClip; private InnerShadow mainInnerShadow0; private InnerShadow mainInnerShadow1; private Path threshold; private Text valueText; private Text backgroundText; private Text unitText; private Text title; private Text lowerRightText; private Text upperLeftText; private Text upperRightText; private Text lowerCenterText; private double valueOffsetLeft; private double valueOffsetRight; private double digitalFontSizeFactor; private Font valueFont; private Font unitFont; private Font titleFont; private Font smallFont; private double oneSegmentWidth; private double dotSegmentWidth; private double widthOfDecimals; private double availableWidth; private int noOfSegments; private StringBuilder backgroundTextBuilder; private Group shadowGroup; private String valueFormatString; private String otherFormatString; private List<Section> sections; private Map<Section, Color[]> sectionColorMap; // ******************** Constructors ************************************** public LcdSkin(Gauge gauge) { super(gauge); width = PREFERRED_WIDTH; height = PREFERRED_HEIGHT; valueOffsetLeft = 0.0; valueOffsetRight = 0.0; digitalFontSizeFactor = 1.0; backgroundTextBuilder = new StringBuilder(); valueFormatString = new StringBuilder("%.") .append(Integer.toString(gauge.getDecimals())) .append("f") .toString(); otherFormatString = new StringBuilder("%.") .append(Integer.toString(gauge.getTickLabelDecimals())) .append("f") .toString(); sections = gauge.getSections(); sectionColorMap = new HashMap<>(sections.size()); updateSectionColors(); FOREGROUND_SHADOW.setOffsetX(0); FOREGROUND_SHADOW.setOffsetY(1); FOREGROUND_SHADOW.setColor(Color.rgb(0, 0, 0, 0.5)); FOREGROUND_SHADOW.setBlurType(BlurType.TWO_PASS_BOX); FOREGROUND_SHADOW.setRadius(2); init(); initGraphics(); registerListeners(); } // ******************** Initialization ************************************ private void init() { if (Double.compare(getSkinnable().getPrefWidth(), 0.0) <= 0 || Double.compare(getSkinnable().getPrefHeight(), 0.0) <= 0 || Double.compare(getSkinnable().getWidth(), 0.0) <= 0 || Double.compare(getSkinnable().getHeight(), 0.0) <= 0) { if (getSkinnable().getPrefWidth() > 0 && getSkinnable().getPrefHeight() > 0) { getSkinnable().setPrefSize(getSkinnable().getPrefWidth(), getSkinnable().getPrefHeight()); } else { getSkinnable().setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT); } } if (Double.compare(getSkinnable().getMinWidth(), 0.0) <= 0 || Double.compare(getSkinnable().getMinHeight(), 0.0) <= 0) { getSkinnable().setMinSize(MINIMUM_WIDTH, MINIMUM_HEIGHT); } if (Double.compare(getSkinnable().getMaxWidth(), 0.0) <= 0 || Double.compare(getSkinnable().getMaxHeight(), 0.0) <= 0) { getSkinnable().setMaxSize(MAXIMUM_WIDTH, MAXIMUM_HEIGHT); } if (getSkinnable().getPrefWidth() != PREFERRED_WIDTH || getSkinnable().getPrefHeight() != PREFERRED_HEIGHT) { aspectRatio = getSkinnable().getPrefHeight() / getSkinnable().getPrefWidth(); } } private void initGraphics() { mainInnerShadow0 = new InnerShadow(); mainInnerShadow0.setOffsetX(0.0); mainInnerShadow0.setOffsetY(0.0); mainInnerShadow0.setRadius(0.0625 * PREFERRED_HEIGHT); mainInnerShadow0.setColor(Color.rgb(255, 255, 255, 0.5)); mainInnerShadow0.setBlurType(BlurType.TWO_PASS_BOX); mainInnerShadow1 = new InnerShadow(); mainInnerShadow1.setOffsetX(0.0); mainInnerShadow1.setOffsetY(1.0); mainInnerShadow1.setRadius(0.04166667 * PREFERRED_HEIGHT); mainInnerShadow1.setColor(Color.rgb(0, 0, 0, 0.65)); mainInnerShadow1.setBlurType(BlurType.TWO_PASS_BOX); mainInnerShadow1.setInput(mainInnerShadow0); crystalClip = new Rectangle(0, 0, width, height); crystalClip.setArcWidth(5); crystalClip.setArcHeight(5); crystalImage = Helper.createNoiseImage( PREFERRED_WIDTH, PREFERRED_HEIGHT, DARK_NOISE_COLOR, BRIGHT_NOISE_COLOR, 8); crystalOverlay = new ImageView(crystalImage); crystalOverlay.setClip(crystalClip); boolean crystalEnabled = getSkinnable().isLcdCrystalEnabled(); crystalOverlay.setManaged(crystalEnabled); crystalOverlay.setVisible(crystalEnabled); threshold = new Path(); threshold.setManaged(getSkinnable().isThresholdVisible()); threshold.setVisible(getSkinnable().isThresholdVisible()); threshold.setStroke(null); backgroundText = new Text(String.format(Locale.US, valueFormatString, getSkinnable().getCurrentValue())); backgroundText.setFill(getSkinnable().getLcdDesign().lcdBackgroundColor); backgroundText.setOpacity( (LcdFont.LCD == getSkinnable().getLcdFont() || LcdFont.ELEKTRA == getSkinnable().getLcdFont()) ? 1 : 0); valueText = new Text(String.format(Locale.US, valueFormatString, getSkinnable().getCurrentValue())); valueText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor); unitText = new Text(getSkinnable().getUnit()); unitText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor); unitText.setManaged(!getSkinnable().getUnit().isEmpty()); unitText.setVisible(!getSkinnable().getUnit().isEmpty()); title = new Text(getSkinnable().getTitle()); title.setFill(getSkinnable().getLcdDesign().lcdForegroundColor); title.setManaged(!getSkinnable().getTitle().isEmpty()); title.setVisible(!getSkinnable().getTitle().isEmpty()); lowerRightText = new Text(getSkinnable().getSubTitle()); lowerRightText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor); lowerRightText.setManaged(!getSkinnable().getSubTitle().isEmpty()); lowerRightText.setVisible(!getSkinnable().getSubTitle().isEmpty()); upperLeftText = new Text(String.format(Locale.US, otherFormatString, getSkinnable().getMinMeasuredValue())); upperLeftText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor); upperLeftText.setManaged(getSkinnable().isMinMeasuredValueVisible()); upperLeftText.setVisible(getSkinnable().isMinMeasuredValueVisible()); upperRightText = new Text(String.format(Locale.US, otherFormatString, getSkinnable().getMaxMeasuredValue())); upperRightText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor); upperRightText.setManaged(getSkinnable().isMaxMeasuredValueVisible()); upperRightText.setVisible(getSkinnable().isMaxMeasuredValueVisible()); lowerCenterText = new Text(String.format(Locale.US, otherFormatString, getSkinnable().getOldValue())); lowerCenterText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor); lowerCenterText.setManaged(getSkinnable().isOldValueVisible()); lowerCenterText.setVisible(getSkinnable().isOldValueVisible()); shadowGroup = new Group(); shadowGroup.setEffect(getSkinnable().isShadowsEnabled() ? FOREGROUND_SHADOW : null); shadowGroup .getChildren() .setAll( threshold, valueText, unitText, title, lowerRightText, upperLeftText, upperRightText, lowerCenterText); pane = new Pane(crystalOverlay, backgroundText, shadowGroup); pane.setEffect(getSkinnable().isShadowsEnabled() ? mainInnerShadow1 : null); getChildren().setAll(pane); } private void registerListeners() { getSkinnable().widthProperty().addListener(o -> handleEvents("RESIZE")); getSkinnable().heightProperty().addListener(o -> handleEvents("RESIZE")); getSkinnable().setOnUpdate(e -> handleEvents(e.eventType.name())); getSkinnable().currentValueProperty().addListener(e -> handleEvents("REDRAW")); } // ******************** Methods ******************************************* protected void handleEvents(final String EVENT_TYPE) { if ("REDRAW".equals(EVENT_TYPE)) { pane.setEffect(getSkinnable().isShadowsEnabled() ? mainInnerShadow1 : null); shadowGroup.setEffect(getSkinnable().isShadowsEnabled() ? FOREGROUND_SHADOW : null); updateLcdDesign(height); redraw(); } else if ("RESIZE".equals(EVENT_TYPE)) { aspectRatio = getSkinnable().getPrefHeight() / getSkinnable().getPrefWidth(); resize(); redraw(); } else if ("LCD".equals(EVENT_TYPE)) { updateLcdDesign(height); } else if ("VISIBILITY".equals(EVENT_TYPE)) { crystalOverlay.setManaged(getSkinnable().isLcdCrystalEnabled()); crystalOverlay.setVisible(getSkinnable().isLcdCrystalEnabled()); unitText.setManaged(!getSkinnable().getUnit().isEmpty()); unitText.setVisible(!getSkinnable().getUnit().isEmpty()); upperLeftText.setManaged(getSkinnable().isMinMeasuredValueVisible()); upperLeftText.setVisible(getSkinnable().isMinMeasuredValueVisible()); upperRightText.setManaged(getSkinnable().isMaxMeasuredValueVisible()); upperRightText.setVisible(getSkinnable().isMaxMeasuredValueVisible()); lowerRightText.setManaged(!getSkinnable().getSubTitle().isEmpty()); lowerRightText.setVisible(!getSkinnable().getSubTitle().isEmpty()); lowerCenterText.setManaged(getSkinnable().isOldValueVisible()); lowerCenterText.setVisible(getSkinnable().isOldValueVisible()); resize(); redraw(); } else if ("SECTION".equals(EVENT_TYPE)) { sections = getSkinnable().getSections(); updateSectionColors(); resize(); redraw(); } } // ******************** Private Methods *********************************** private boolean isNoOfDigitsInvalid() { final double AVAILABLE_WIDTH = width - 2 - valueOffsetLeft - valueOffsetRight; final double NEEDED_WIDTH = valueText.getLayoutBounds().getWidth(); return Double.compare(AVAILABLE_WIDTH, NEEDED_WIDTH) < 0; } private void updateLcdDesign(final double HEIGHT) { LcdDesign lcdDesign = getSkinnable().getLcdDesign(); Color[] lcdColors = lcdDesign.getColors(); if (LcdDesign.SECTIONS == lcdDesign) { double currentValue = getSkinnable().getCurrentValue(); int listSize = sections.size(); for (int i = 0; i < listSize; i++) { Section section = sections.get(i); if (section.contains(currentValue)) { lcdColors = sectionColorMap.get(section); break; } } } lcdPaint = new LinearGradient( 0, 1, 0, HEIGHT - 1, false, CycleMethod.NO_CYCLE, new Stop(0, lcdColors[0]), new Stop(0.03, lcdColors[1]), new Stop(0.5, lcdColors[2]), new Stop(0.5, lcdColors[3]), new Stop(1.0, lcdColors[4])); if (lcdDesign.name().startsWith("FLAT")) { lcdFramePaint = getSkinnable().getBorderPaint(); lcdPaint = getSkinnable().getBackgroundPaint(); Color lcdForegroundColor = (Color) getSkinnable().getForegroundPaint(); backgroundText.setFill( Color.color( lcdForegroundColor.getRed(), lcdForegroundColor.getGreen(), lcdForegroundColor.getBlue(), 0.1)); valueText.setFill(lcdForegroundColor); upperLeftText.setFill(lcdForegroundColor); title.setFill(lcdForegroundColor); upperRightText.setFill(lcdForegroundColor); unitText.setFill(lcdForegroundColor); lowerRightText.setFill(lcdForegroundColor); lowerCenterText.setFill(lcdForegroundColor); threshold.setFill(lcdForegroundColor); } else { lcdFramePaint = new LinearGradient( 0, 0.02083333 * height, 0, HEIGHT - 0.02083333 * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0.0, Color.rgb(26, 26, 26)), new Stop(0.015, Color.rgb(77, 77, 77)), new Stop(0.985, Color.rgb(77, 77, 77)), new Stop(1.0, Color.rgb(221, 221, 221))); lcdPaint = new LinearGradient( 0, 1, 0, HEIGHT - 1, false, CycleMethod.NO_CYCLE, new Stop(0, lcdColors[0]), new Stop(0.03, lcdColors[1]), new Stop(0.5, lcdColors[2]), new Stop(0.5, lcdColors[3]), new Stop(1.0, lcdColors[4])); backgroundText.setFill(lcdDesign.lcdBackgroundColor); valueText.setFill(lcdDesign.lcdForegroundColor); upperLeftText.setFill(lcdDesign.lcdForegroundColor); title.setFill(lcdDesign.lcdForegroundColor); upperRightText.setFill(lcdDesign.lcdForegroundColor); unitText.setFill(lcdDesign.lcdForegroundColor); lowerRightText.setFill(lcdDesign.lcdForegroundColor); lowerCenterText.setFill(lcdDesign.lcdForegroundColor); threshold.setFill(lcdDesign.lcdForegroundColor); } pane.setBackground( new Background( new BackgroundFill(lcdPaint, new CornerRadii(0.10416667 * HEIGHT), Insets.EMPTY))); pane.setBorder( new Border( new BorderStroke( lcdFramePaint, BorderStrokeStyle.SOLID, new CornerRadii(0.05 * HEIGHT), new BorderWidths(0.02083333 * HEIGHT)))); } private void updateSectionColors() { int listSize = sections.size(); sectionColorMap.clear(); for (int i = 0; i < listSize; i++) { Color sectionColor = sections.get(i).getColor(); Color lcdForegroundColor; if (Helper.isMonochrome(sectionColor)) { lcdForegroundColor = Helper.isDark(sectionColor) ? Color.WHITE : Color.BLACK; } else { lcdForegroundColor = Color.hsb( sectionColor.getHue(), sectionColor.getSaturation(), sectionColor.getBrightness() * 0.3); } Color lcdBackgroundColor = Color.color(sectionColor.getRed(), sectionColor.getGreen(), sectionColor.getBlue(), 0.1); sectionColorMap.put( sections.get(i), getSectionColors(lcdBackgroundColor, lcdForegroundColor)); } } private Color[] getSectionColors( final Color LCD_BACKGROUND_COLOR, final Color LCD_FOREGROUND_COLOR) { double hue = LCD_BACKGROUND_COLOR.getHue(); double sat = LCD_BACKGROUND_COLOR.getSaturation(); Color[] colors; if (Helper.isMonochrome(LCD_BACKGROUND_COLOR)) { // Section color is monochrome colors = new Color[] { Color.hsb(hue, 0, 0.69), Color.hsb(hue, 0, 1.0), Color.hsb(hue, 0, 0.76), Color.hsb(hue, 0, 0.76), Color.hsb(hue, sat, 0.69), Helper.isDark(LCD_BACKGROUND_COLOR) ? Color.WHITE : Color.BLACK, Helper.isDark(LCD_BACKGROUND_COLOR) ? Color.rgb(255, 255, 255, 0.1) : Color.rgb(0, 0, 0, 0.1) }; } else { // Section color is not monochrome colors = new Color[] { Color.hsb(hue, sat, 0.69), Color.hsb(hue, sat, 1.0), Color.hsb(hue, sat, 0.76), Color.hsb(hue, sat, 0.76), Color.hsb(hue, sat, 0.69), LCD_FOREGROUND_COLOR, Color.color( LCD_BACKGROUND_COLOR.getRed(), LCD_BACKGROUND_COLOR.getGreen(), LCD_BACKGROUND_COLOR.getBlue(), 0.1) }; } return colors; } private void updateFonts() { digitalFontSizeFactor = 1.0; switch (getSkinnable().getLcdFont()) { case LCD: valueFont = Fonts.digital(0.6 * height); digitalFontSizeFactor = 1.4; break; case DIGITAL: valueFont = Fonts.digitalReadout(0.5833333333 * height); break; case DIGITAL_BOLD: valueFont = Fonts.digitalReadoutBold(0.5833333333 * height); break; case ELEKTRA: valueFont = Fonts.elektra(0.62 * height); break; case STANDARD: default: valueFont = Fonts.robotoMedium(0.5 * height); break; } backgroundText.setFont(valueFont); backgroundText.setOpacity( (LcdFont.LCD == getSkinnable().getLcdFont() || LcdFont.DIGITAL == getSkinnable().getLcdFont() || LcdFont.DIGITAL_BOLD == getSkinnable().getLcdFont() || LcdFont.ELEKTRA == getSkinnable().getLcdFont()) ? 1 : 0); valueText.setFont(valueFont); unitFont = Fonts.latoBold(0.26 * height); titleFont = Fonts.latoBold(0.1666666667 * height); smallFont = Fonts.latoBold(0.1666666667 * height); } private void updateBackgroundText() { // Setup the semitransparent background text backgroundText.setCache(false); backgroundText.setTextOrigin(VPos.BASELINE); backgroundText.setTextAlignment(TextAlignment.RIGHT); // Setup the semitransparent background text // Width of one segment oneSegment.setFont(valueFont); dotSegment.setText("."); if (LcdFont.LCD == getSkinnable().getLcdFont()) { oneSegment.setText("8"); } else if (LcdFont.DIGITAL == getSkinnable().getLcdFont()) { oneSegment.setText("_"); } else if (LcdFont.DIGITAL_BOLD == getSkinnable().getLcdFont()) { oneSegment.setText("_"); } else if (LcdFont.ELEKTRA == getSkinnable().getLcdFont()) { oneSegment.setText("_"); } oneSegmentWidth = oneSegment.getLayoutBounds().getWidth(); dotSegmentWidth = dotSegment.getLayoutBounds().getWidth(); // Width of decimals widthOfDecimals = 0 == getSkinnable().getDecimals() ? 0 : getSkinnable().getDecimals() * oneSegmentWidth + (LcdFont.LCD == getSkinnable().getLcdFont() ? oneSegmentWidth : dotSegmentWidth); // Available width availableWidth = width - (0.0151515152 * width) - (0.0416666667 * height) - 2 - valueOffsetRight - widthOfDecimals; // Number of segments noOfSegments = (int) Math.floor(availableWidth / oneSegmentWidth); // Add segments to background text backgroundTextBuilder.setLength(0); for (int i = 0; i < getSkinnable().getDecimals(); i++) { backgroundTextBuilder.append(oneSegment.getText()); } if (getSkinnable().getDecimals() != 0) { backgroundTextBuilder.insert(0, "."); } for (int i = 0; i < noOfSegments; i++) { backgroundTextBuilder.insert(0, oneSegment.getText()); } backgroundText.setText(backgroundTextBuilder.toString()); backgroundText.setCache(true); backgroundText.setCacheHint(CacheHint.SCALE); } private void resize() { width = getSkinnable().getWidth() - getSkinnable().getInsets().getLeft() - getSkinnable().getInsets().getRight(); height = getSkinnable().getHeight() - getSkinnable().getInsets().getTop() - getSkinnable().getInsets().getBottom(); if (aspectRatio * width > height) { width = 1 / (aspectRatio / height); } else if (1 / (aspectRatio / height) > width) { height = aspectRatio * width; } if (width > 0 && height > 0) { pane.setMaxSize(width, height); pane.relocate( (getSkinnable().getWidth() - width) * 0.5, (getSkinnable().getHeight() - height) * 0.5); updateLcdDesign(height); mainInnerShadow0.setRadius(0.0625 * height); mainInnerShadow1.setRadius(0.04166667 * height); if (crystalOverlay.isVisible()) { crystalClip.setWidth(width); crystalClip.setHeight(height); crystalOverlay.setImage( Helper.createNoiseImage(width, height, DARK_NOISE_COLOR, BRIGHT_NOISE_COLOR, 8)); crystalOverlay.setCache(true); } double tSize = 0.2 * height; threshold.getElements().clear(); threshold.getElements().add(new MoveTo(0.41666667 * tSize, 0.75 * tSize)); threshold.getElements().add(new LineTo(0.583333333333333 * tSize, 0.75 * tSize)); threshold.getElements().add(new LineTo(0.583333333333333 * tSize, 0.916666666666667 * tSize)); threshold.getElements().add(new LineTo(0.416666666666667 * tSize, 0.916666666666667 * tSize)); threshold.getElements().add(new LineTo(0.416666666666667 * tSize, 0.75 * tSize)); threshold.getElements().add(new ClosePath()); threshold.getElements().add(new MoveTo(0.416666666666667 * tSize, 0.333333333333333 * tSize)); threshold.getElements().add(new LineTo(0.583333333333333 * tSize, 0.333333333333333 * tSize)); threshold.getElements().add(new LineTo(0.583333333333333 * tSize, 0.666666666666667 * tSize)); threshold.getElements().add(new LineTo(0.416666666666667 * tSize, 0.666666666666667 * tSize)); threshold.getElements().add(new LineTo(0.416666666666667 * tSize, 0.333333333333333 * tSize)); threshold.getElements().add(new ClosePath()); threshold.getElements().add(new MoveTo(tSize, tSize)); threshold.getElements().add(new LineTo(0.5 * tSize, 0)); threshold.getElements().add(new LineTo(0, tSize)); threshold.getElements().add(new LineTo(tSize, tSize)); threshold.getElements().add(new ClosePath()); threshold.relocate(0.027961994662429348 * width, 0.75 * height - 2); updateFonts(); // Setup the lcd unit unitText.setFont(unitFont); unitText.setTextOrigin(VPos.BASELINE); unitText.setTextAlignment(TextAlignment.RIGHT); unitText.setText(getSkinnable().getUnit()); if (unitText.visibleProperty().isBound()) { unitText.visibleProperty().unbind(); } valueOffsetLeft = height * 0.04; if (getSkinnable().getUnit().isEmpty()) { valueOffsetRight = height * 0.0833333333; valueText.setX((width - valueText.getLayoutBounds().getWidth()) - valueOffsetRight); } else { unitText.setX((width - unitText.getLayoutBounds().getWidth()) - height * 0.04); unitText.setY( height - (valueText.getLayoutBounds().getHeight() * digitalFontSizeFactor) * 0.5); valueOffsetRight = (unitText.getLayoutBounds().getWidth() + height * 0.0833333333); // distance between value and unit valueText.setX(width - 2 - valueText.getLayoutBounds().getWidth() - valueOffsetRight); } valueText.setY( height - (valueText.getLayoutBounds().getHeight() * digitalFontSizeFactor) * 0.5); // Visualize the lcd semitransparent background text updateBackgroundText(); if (getSkinnable().getUnit().isEmpty()) { backgroundText.setX( (width - backgroundText.getLayoutBounds().getWidth()) - valueOffsetRight); } else { backgroundText.setX( width - 2 - backgroundText.getLayoutBounds().getWidth() - valueOffsetRight); } backgroundText.setY( height - (backgroundText.getLayoutBounds().getHeight() * digitalFontSizeFactor) * 0.5); // Setup the font for the lcd title, number system, min measured, max measure and former value // Title title.setFont(titleFont); title.setTextOrigin(VPos.BASELINE); title.setTextAlignment(TextAlignment.CENTER); title.setText(getSkinnable().getTitle()); title.setX((width - title.getLayoutBounds().getWidth()) * 0.5); title.setY( pane.getLayoutBounds().getMinY() + title.getLayoutBounds().getHeight() - 0.04 * height + 4); // Info Text lowerRightText.setFont(smallFont); lowerRightText.setTextOrigin(VPos.BASELINE); lowerRightText.setTextAlignment(TextAlignment.RIGHT); lowerRightText.setText(getSkinnable().getSubTitle()); lowerRightText.setX( pane.getLayoutBounds().getMinX() + (pane.getLayoutBounds().getWidth() - lowerRightText.getLayoutBounds().getWidth()) * 0.5); lowerRightText.setY(pane.getLayoutBounds().getMinY() + height - 4 - 0.0416666667 * height); // Min measured value upperLeftText.setFont(smallFont); upperLeftText.setTextOrigin(VPos.BASELINE); upperLeftText.setTextAlignment(TextAlignment.RIGHT); upperLeftText.setX(pane.getLayoutBounds().getMinX() + 0.0416666667 * height); upperLeftText.setY( pane.getLayoutBounds().getMinY() + upperLeftText.getLayoutBounds().getHeight() - 0.04 * height + 4); // Max measured value upperRightText.setFont(smallFont); upperRightText.setTextOrigin(VPos.BASELINE); upperRightText.setTextAlignment(TextAlignment.RIGHT); upperRightText.setY( pane.getLayoutBounds().getMinY() + upperRightText.getLayoutBounds().getHeight() - 0.04 * height + 4); // Former value lowerCenterText.setFont(smallFont); lowerCenterText.setTextOrigin(VPos.BASELINE); lowerCenterText.setTextAlignment(TextAlignment.CENTER); lowerCenterText.setX((width - lowerCenterText.getLayoutBounds().getWidth()) * 0.5); lowerCenterText.setY(pane.getLayoutBounds().getMinY() + height - 4 - 0.0416666667 * height); } } private void redraw() { valueFormatString = new StringBuilder("%.") .append(Integer.toString(getSkinnable().getDecimals())) .append("f") .toString(); otherFormatString = new StringBuilder("%.") .append(Integer.toString(getSkinnable().getTickLabelDecimals())) .append("f") .toString(); threshold.setVisible( Double.compare(getSkinnable().getCurrentValue(), getSkinnable().getThreshold()) >= 0); if (isNoOfDigitsInvalid()) { valueText.setText("-E-"); } else { valueText.setText( String.format(Locale.US, valueFormatString, getSkinnable().getCurrentValue())); } updateBackgroundText(); // Visualize the lcd semitransparent background text if (getSkinnable().getUnit().isEmpty()) { backgroundText.setX((width - backgroundText.getLayoutBounds().getWidth()) - valueOffsetRight); } else { backgroundText.setX( width - 2 - backgroundText.getLayoutBounds().getWidth() - valueOffsetRight); } backgroundText.setY( height - (backgroundText.getLayoutBounds().getHeight() * digitalFontSizeFactor) * 0.5); if (getSkinnable().getUnit().isEmpty()) { valueText.setX((width - valueText.getLayoutBounds().getWidth()) - valueOffsetRight); } else { valueText.setX((width - 2 - valueText.getLayoutBounds().getWidth()) - valueOffsetRight); } // Update the title title.setText(getSkinnable().getTitle()); title.setX((width - title.getLayoutBounds().getWidth()) * 0.5); // Update the upper left text upperLeftText.setText( String.format(Locale.US, otherFormatString, getSkinnable().getMinMeasuredValue())); if (upperLeftText.getX() + upperLeftText.getLayoutBounds().getWidth() > title.getX()) { upperLeftText.setText("..."); } // Update the upper right text upperRightText.setText( String.format(Locale.US, otherFormatString, getSkinnable().getMaxMeasuredValue())); upperRightText.setX( width - upperRightText.getLayoutBounds().getWidth() - 0.0416666667 * height); if (upperRightText.getX() < title.getX() + title.getLayoutBounds().getWidth()) { upperRightText.setText("..."); upperRightText.setX( width - upperRightText.getLayoutBounds().getWidth() - 0.0416666667 * height); } // Update the lower center text lowerCenterText.setText( String.format(Locale.US, otherFormatString, getSkinnable().getOldValue())); lowerCenterText.setX((width - lowerCenterText.getLayoutBounds().getWidth()) * 0.5); // Update the lower right text lowerRightText.setText(getSkinnable().getSubTitle()); lowerRightText.setX( width - lowerRightText.getLayoutBounds().getWidth() - 0.0416666667 * height); lowerRightText.setY(pane.getLayoutBounds().getMinY() + height - 3 - 0.0416666667 * height); if (lowerRightText.getX() < lowerCenterText.getX() + lowerCenterText.getLayoutBounds().getWidth()) { lowerRightText.setText("..."); lowerRightText.setX( width - lowerRightText.getLayoutBounds().getWidth() - 0.0416666667 * height); } } }
private void updateLcdDesign(final double HEIGHT) { LcdDesign lcdDesign = getSkinnable().getLcdDesign(); Color[] lcdColors = lcdDesign.getColors(); if (LcdDesign.SECTIONS == lcdDesign) { double currentValue = getSkinnable().getCurrentValue(); int listSize = sections.size(); for (int i = 0; i < listSize; i++) { Section section = sections.get(i); if (section.contains(currentValue)) { lcdColors = sectionColorMap.get(section); break; } } } lcdPaint = new LinearGradient( 0, 1, 0, HEIGHT - 1, false, CycleMethod.NO_CYCLE, new Stop(0, lcdColors[0]), new Stop(0.03, lcdColors[1]), new Stop(0.5, lcdColors[2]), new Stop(0.5, lcdColors[3]), new Stop(1.0, lcdColors[4])); if (lcdDesign.name().startsWith("FLAT")) { lcdFramePaint = getSkinnable().getBorderPaint(); lcdPaint = getSkinnable().getBackgroundPaint(); Color lcdForegroundColor = (Color) getSkinnable().getForegroundPaint(); backgroundText.setFill( Color.color( lcdForegroundColor.getRed(), lcdForegroundColor.getGreen(), lcdForegroundColor.getBlue(), 0.1)); valueText.setFill(lcdForegroundColor); upperLeftText.setFill(lcdForegroundColor); title.setFill(lcdForegroundColor); upperRightText.setFill(lcdForegroundColor); unitText.setFill(lcdForegroundColor); lowerRightText.setFill(lcdForegroundColor); lowerCenterText.setFill(lcdForegroundColor); threshold.setFill(lcdForegroundColor); } else { lcdFramePaint = new LinearGradient( 0, 0.02083333 * height, 0, HEIGHT - 0.02083333 * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0.0, Color.rgb(26, 26, 26)), new Stop(0.015, Color.rgb(77, 77, 77)), new Stop(0.985, Color.rgb(77, 77, 77)), new Stop(1.0, Color.rgb(221, 221, 221))); lcdPaint = new LinearGradient( 0, 1, 0, HEIGHT - 1, false, CycleMethod.NO_CYCLE, new Stop(0, lcdColors[0]), new Stop(0.03, lcdColors[1]), new Stop(0.5, lcdColors[2]), new Stop(0.5, lcdColors[3]), new Stop(1.0, lcdColors[4])); backgroundText.setFill(lcdDesign.lcdBackgroundColor); valueText.setFill(lcdDesign.lcdForegroundColor); upperLeftText.setFill(lcdDesign.lcdForegroundColor); title.setFill(lcdDesign.lcdForegroundColor); upperRightText.setFill(lcdDesign.lcdForegroundColor); unitText.setFill(lcdDesign.lcdForegroundColor); lowerRightText.setFill(lcdDesign.lcdForegroundColor); lowerCenterText.setFill(lcdDesign.lcdForegroundColor); threshold.setFill(lcdDesign.lcdForegroundColor); } pane.setBackground( new Background( new BackgroundFill(lcdPaint, new CornerRadii(0.10416667 * HEIGHT), Insets.EMPTY))); pane.setBorder( new Border( new BorderStroke( lcdFramePaint, BorderStrokeStyle.SOLID, new CornerRadii(0.05 * HEIGHT), new BorderWidths(0.02083333 * HEIGHT)))); }
private void initGraphics() { mainInnerShadow0 = new InnerShadow(); mainInnerShadow0.setOffsetX(0.0); mainInnerShadow0.setOffsetY(0.0); mainInnerShadow0.setRadius(0.0625 * PREFERRED_HEIGHT); mainInnerShadow0.setColor(Color.rgb(255, 255, 255, 0.5)); mainInnerShadow0.setBlurType(BlurType.TWO_PASS_BOX); mainInnerShadow1 = new InnerShadow(); mainInnerShadow1.setOffsetX(0.0); mainInnerShadow1.setOffsetY(1.0); mainInnerShadow1.setRadius(0.04166667 * PREFERRED_HEIGHT); mainInnerShadow1.setColor(Color.rgb(0, 0, 0, 0.65)); mainInnerShadow1.setBlurType(BlurType.TWO_PASS_BOX); mainInnerShadow1.setInput(mainInnerShadow0); crystalClip = new Rectangle(0, 0, width, height); crystalClip.setArcWidth(5); crystalClip.setArcHeight(5); crystalImage = Helper.createNoiseImage( PREFERRED_WIDTH, PREFERRED_HEIGHT, DARK_NOISE_COLOR, BRIGHT_NOISE_COLOR, 8); crystalOverlay = new ImageView(crystalImage); crystalOverlay.setClip(crystalClip); boolean crystalEnabled = getSkinnable().isLcdCrystalEnabled(); crystalOverlay.setManaged(crystalEnabled); crystalOverlay.setVisible(crystalEnabled); threshold = new Path(); threshold.setManaged(getSkinnable().isThresholdVisible()); threshold.setVisible(getSkinnable().isThresholdVisible()); threshold.setStroke(null); backgroundText = new Text(String.format(Locale.US, valueFormatString, getSkinnable().getCurrentValue())); backgroundText.setFill(getSkinnable().getLcdDesign().lcdBackgroundColor); backgroundText.setOpacity( (LcdFont.LCD == getSkinnable().getLcdFont() || LcdFont.ELEKTRA == getSkinnable().getLcdFont()) ? 1 : 0); valueText = new Text(String.format(Locale.US, valueFormatString, getSkinnable().getCurrentValue())); valueText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor); unitText = new Text(getSkinnable().getUnit()); unitText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor); unitText.setManaged(!getSkinnable().getUnit().isEmpty()); unitText.setVisible(!getSkinnable().getUnit().isEmpty()); title = new Text(getSkinnable().getTitle()); title.setFill(getSkinnable().getLcdDesign().lcdForegroundColor); title.setManaged(!getSkinnable().getTitle().isEmpty()); title.setVisible(!getSkinnable().getTitle().isEmpty()); lowerRightText = new Text(getSkinnable().getSubTitle()); lowerRightText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor); lowerRightText.setManaged(!getSkinnable().getSubTitle().isEmpty()); lowerRightText.setVisible(!getSkinnable().getSubTitle().isEmpty()); upperLeftText = new Text(String.format(Locale.US, otherFormatString, getSkinnable().getMinMeasuredValue())); upperLeftText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor); upperLeftText.setManaged(getSkinnable().isMinMeasuredValueVisible()); upperLeftText.setVisible(getSkinnable().isMinMeasuredValueVisible()); upperRightText = new Text(String.format(Locale.US, otherFormatString, getSkinnable().getMaxMeasuredValue())); upperRightText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor); upperRightText.setManaged(getSkinnable().isMaxMeasuredValueVisible()); upperRightText.setVisible(getSkinnable().isMaxMeasuredValueVisible()); lowerCenterText = new Text(String.format(Locale.US, otherFormatString, getSkinnable().getOldValue())); lowerCenterText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor); lowerCenterText.setManaged(getSkinnable().isOldValueVisible()); lowerCenterText.setVisible(getSkinnable().isOldValueVisible()); shadowGroup = new Group(); shadowGroup.setEffect(getSkinnable().isShadowsEnabled() ? FOREGROUND_SHADOW : null); shadowGroup .getChildren() .setAll( threshold, valueText, unitText, title, lowerRightText, upperLeftText, upperRightText, lowerCenterText); pane = new Pane(crystalOverlay, backgroundText, shadowGroup); pane.setEffect(getSkinnable().isShadowsEnabled() ? mainInnerShadow1 : null); getChildren().setAll(pane); }
@SuppressWarnings("unchecked") public StackPane viewStock(String categoryId, String categoryName) { stack = new StackPane(); GridPane grid = new GridPane(); grid.setVgap(8); grid.setPadding(new Insets(30)); final ObservableList<ItemVO> dataTable; // final ObservableList<ItemVO> dataTable1; // final ObservableList<ItemVO> dataTable2; ObservableList<CategoryTypeVO> typeList; Rectangle roundRect = RectangleBuilder.create() .x(50) .y(50) .width(Screen.getPrimary().getVisualBounds().getWidth() - 428) .height(Screen.getPrimary().getVisualBounds().getHeight() - 150) .arcWidth(30) .arcHeight(30) .build(); roundRect.setFill(Color.DARKGRAY); roundRect.setOpacity(0.2); roundRect.setStroke(Color.TRANSPARENT); HBox hlabel = new HBox(); hlabel.setMaxWidth(Screen.getPrimary().getVisualBounds().getWidth() - 170); hlabel.setMaxHeight(30); hlabel.setStyle("-fx-background-color:black;"); hlabel.setOpacity(0.3); hlabel.setLayoutX(20); try { typeList = FXCollections.observableArrayList(); typeList = UtiliesDAO.getUtiliesDAO().fetchTypes(categoryId); dataTable = FXCollections.observableArrayList(); dataTable.addAll(stockDetailsService.viewStock(categoryId)); /*dataTable1 = FXCollections.observableArrayList(); dataTable2 = FXCollections.observableArrayList(); for(int i=0;i<dataTable.size();i++) { dataTable1.add(dataTable.get(i++)); if(i<=dataTable.size()-1) { dataTable2.add(dataTable.get(i)); } }*/ final Label label = new Label(categoryName + " Stock"); final Text text5 = new Text(25, 175, categoryName + " Stock"); text5.setFill(Color.DARKORANGE); // text5.setFont(Font.font ("Edwardian Script ITC", 50)); text5.setFont(Font.loadFont("file:resources/fonts/ITCEDSCR.TTF", 50)); final Light.Distant light = new Light.Distant(); light.setAzimuth(-135.0); final Lighting lighting = new Lighting(); lighting.setLight(light); lighting.setSurfaceScale(9.0); text5.setEffect(lighting); label.setAlignment(Pos.CENTER_LEFT); // grid.add(label,1,0); final TableView<ItemVO> table1 = new TableView<ItemVO>(); table1.setEditable(false); // table1.setMaxSize(roundRect.getWidth()*0.41, roundRect.getHeight()*0.519);//400,300 table1.setMinSize(roundRect.getWidth() * 0.41, roundRect.getHeight() * 0.519); // 400,300 table1.setMaxSize(roundRect.getWidth() - 50, roundRect.getHeight() - 200); table1.getSelectionModel().setCellSelectionEnabled(false); table1.setStyle("-fx-background-color: transparent;"); TableColumn<ItemVO, String> itemName = new TableColumn<ItemVO, String>("Item"); itemName.setResizable(false); itemName.setMaxWidth(roundRect.getWidth() * 0.5); itemName.setMinWidth(roundRect.getWidth() * 0.5); // 200 itemName.setCellValueFactory(new PropertyValueFactory<ItemVO, String>("itemName")); TableColumn<ItemVO, Integer> quantity = new TableColumn<ItemVO, Integer>("Quantity#"); quantity.setResizable(false); quantity.setMinWidth(roundRect.getWidth() * 0.107); // 200 /*quantity.setCellValueFactory( new PropertyValueFactory<ItemVO, Integer>("quantity"));*/ for (final CategoryTypeVO type : typeList) { TableColumn<ItemVO, Integer> col = new TableColumn<ItemVO, Integer>(type.getTypeName()); col.setMinWidth(roundRect.getWidth() * 0.107); // 100 col.setResizable(false); col.setCellValueFactory( new Callback<CellDataFeatures<ItemVO, Integer>, ObservableValue<Integer>>() { @Override public ObservableValue<Integer> call(CellDataFeatures<ItemVO, Integer> item) { ItemVO itemVO = item.getValue(); if (itemVO == null) { return null; // or perhaps // return new ReadOnlyObjectWrapper<Integer>(null); } else { ObservableMap<String, ItemTypeVO> itemTypesMap = FXCollections.observableHashMap(); itemTypesMap = item.getValue().getListType(); return new ReadOnlyObjectWrapper<Integer>( itemTypesMap.get(type.getTypeId()).getQuantity()); } } }); col.setCellFactory( new Callback<TableColumn<ItemVO, Integer>, TableCell<ItemVO, Integer>>() { @Override public TableCell<ItemVO, Integer> call(TableColumn<ItemVO, Integer> paramP) { // TODO Auto-generated method stub return new TableCell<ItemVO, Integer>() { @Override public void updateItem(Integer item, boolean empty) { super.updateItem(item, empty); if (!isEmpty()) { setText(item.toString()); if (item <= 5) { this.getStyleClass().add("celllow"); setTextFill(Color.RED); } } } }; } }); quantity.getColumns().add(col); } if (quantity.getColumns().size() >= 5 && quantity.getColumns().size() <= 7) { itemName.setMinWidth(itemName.getWidth() - (quantity.getColumns().size() - 4) * 100); } if (quantity.getColumns().size() > 7) { itemName.setMinWidth(itemName.getWidth() - ((7 - 4) * 100)); } table1.setItems(dataTable); final TableColumn[] columns1 = {itemName, quantity}; table1.getColumns().addAll(columns1); table1 .getColumns() .addListener( new ListChangeListener() { public boolean suspended; @Override public void onChanged(Change change) { change.next(); if (change.wasReplaced() && !suspended) { this.suspended = true; table1.getColumns().setAll(columns1); this.suspended = false; } } }); /*//final TableView<ItemVO> table2 = new TableView<ItemVO>(); table2.setEditable(false); table2.setMaxSize(roundRect.getWidth()*0.41, roundRect.getHeight()*0.519); table2.setMinSize(roundRect.getWidth()*0.35, roundRect.getHeight()*0.519);//400,300 table2.setStyle("-fx-background-color: transparent;"); TableColumn<ItemVO,String> itemName2 = new TableColumn<ItemVO,String> ("Item"); itemName2.setMinWidth(roundRect.getWidth()*0.3);//200 itemName2.setCellValueFactory( new PropertyValueFactory<ItemVO, String>("itemName")); TableColumn<ItemVO, Integer> quantity2 = new TableColumn<ItemVO, Integer> ("Quantity#"); quantity2.setMinWidth(roundRect.getWidth()*0.107);//200 quantity.setCellValueFactory( new PropertyValueFactory<ItemVO, Integer>("quantity")); for (final CategoryTypeVO type : typeList) { TableColumn<ItemVO, Integer> col2 = new TableColumn<ItemVO, Integer>(type.getTypeName()); col2.setMinWidth(roundRect.getWidth()*0.107);//100 col2.setResizable(false); col2.setCellValueFactory(new Callback<CellDataFeatures<ItemVO,Integer>, ObservableValue<Integer>>() { @Override public ObservableValue<Integer> call(CellDataFeatures<ItemVO,Integer> item) { ItemVO itemVO = item.getValue(); if (itemVO == null) { return null ; // or perhaps // return new ReadOnlyObjectWrapper<Integer>(null); } else { ObservableMap<String,ItemTypeVO> itemTypesMap = FXCollections.observableHashMap(); itemTypesMap = item.getValue().getListType(); return new ReadOnlyObjectWrapper<Integer>(itemTypesMap.get(type.getTypeId()).getQuantity()); } } }); col2.setCellFactory(new Callback<TableColumn<ItemVO,Integer>, TableCell<ItemVO,Integer>>() { @Override public TableCell<ItemVO, Integer> call(TableColumn<ItemVO, Integer> paramP) { // TODO Auto-generated method stub return new TableCell<ItemVO, Integer>(){ @Override public void updateItem(Integer item, boolean empty) { super.updateItem(item, empty); if(item!=null) { setText(item.toString()); if(item<=5) { this.getStyleClass().add("celllow"); setTextFill(Color.RED); } } } }; } }); quantity2.getColumns().add(col2); } table2.setItems(dataTable2); final TableColumn[] columns2 = {itemName2, quantity2}; table2.getColumns().addAll(columns2); table2.getColumns().addListener(new ListChangeListener() { public boolean suspended; @Override public void onChanged(Change change) { change.next(); if (change.wasReplaced() && !suspended) { this.suspended = true; table2.getColumns().setAll(columns2); this.suspended = false; } } });*/ Rectangle qtyRect = RectangleBuilder.create().x(50).y(50).width(10).height(10).build(); qtyRect.setFill(Color.rgb(240, 128, 128)); grid.add(table1, 0, 12); // grid.add(table2,1,12); grid.setAlignment(Pos.TOP_CENTER); Text man_text = new Text(CommonConstants.STAR_MSG); man_text.setFill(Color.DARKKHAKI); man_text.setFont(Font.font("Arial", 12)); Text msg_qty = new Text(CommonConstants.QTY_MSG1); msg_qty.setFill(Color.DARKKHAKI); msg_qty.setFont(Font.font("Arial", 12)); Text msg_qtyLow = new Text(CommonConstants.QTY_LOW); msg_qtyLow.setFill(Color.DARKKHAKI); msg_qtyLow.setFont(Font.font("Arial", 12)); StackPane.setMargin(grid, new Insets(10, 0, 0, 0)); StackPane.setMargin(qtyRect, new Insets(197, 850, 100, 0)); StackPane.setAlignment(qtyRect, Pos.BASELINE_CENTER); StackPane.setMargin(msg_qtyLow, new Insets(197, 765, 100, 0)); StackPane.setAlignment(msg_qtyLow, Pos.BASELINE_CENTER); StackPane.setAlignment(roundRect, Pos.TOP_CENTER); StackPane.setMargin(text5, new Insets(50, 8, 8, 8)); StackPane.setAlignment(text5, Pos.TOP_CENTER); StackPane.setMargin(man_text, new Insets(197, 100, 20, 0)); StackPane.setAlignment(man_text, Pos.BASELINE_RIGHT); StackPane.setMargin(msg_qty, new Insets(210, 95, 20, 0)); StackPane.setAlignment(msg_qty, Pos.BASELINE_RIGHT); stack.getChildren().addAll(text5, roundRect, grid, man_text, msg_qty, qtyRect, msg_qtyLow); } catch (Exception e) { e.printStackTrace(); } return stack; }
public void start(final Stage stage) { for (ConditionalFeature f : EnumSet.allOf(ConditionalFeature.class)) { System.err.println(f + ": " + Platform.isSupported(f)); } Rectangle2D screen = Screen.getPrimary().getVisualBounds(); final Random rand = new Random(); /* final Group starfield = new Group(); for(int i=0;i<66;i++) { int size = rand.nextInt(3)+1; if(size==3) { size = rand.nextInt(3)+1; } Circle circ = new Circle(rand.nextInt((int)screen.getWidth()), rand.nextInt(200+(int)screen.getHeight())-200, size); circ.setFill(Color.rgb(200,200,200+rand.nextInt(56))); circ.setTranslateZ(1+rand.nextInt(40)); starfield.getChildren().add(circ); } */ final List<Starfield> stars = new ArrayList<>(); for (int i = 0; i < 10; i++) { int sw = (int) screen.getWidth(), sh = (int) screen.getHeight(); Starfield sf = new Starfield(rand, -sw, -sh, 2 * sw, 2 * sh, rand.nextInt(30) + 10); sf.setTranslateZ(rand.nextInt(2000) + 50); stars.add(sf); } // final Starfield starfield2 = new Starfield(rand, -200, -200, (int)screen.getWidth(), // (int)screen.getHeight()+200, 40); final Ruleset1D rules = new Ruleset1D(new int[] {Colors.randomColor(rand), Colors.randomColor(rand)}); final Ruleset rules2 = new Rulespace1D(rules); // Rule rule = rules.random(rand).next(); Iterator<Rule> it = rules.iterator(); GridPane gridp = new GridPane(); int i = 0, j = 0; while (it.hasNext()) { Rule rule = it.next(); CA ca = new CA(rule, new RandomInitializer(), rand, 42, 100, 100); Plane plane = ca.createPlane(); ImageView imview = new ImageView(plane.toImage()); imview.setSmooth(true); imview.setFitWidth(30); imview.setPreserveRatio(true); gridp.add(imview, i, j); if (++i == 16) { i = 0; j++; } } // gridp.setScaleX(0.3); // gridp.setScaleY(0.3); // gridp.setPrefSize(100*3/3, 100*3/3); // gridp.setMaxSize(100*3/3, 100*3/3); final double XTRANS = screen.getWidth() / 2 - 30 * 16 / 2; final double YTRANS = screen.getHeight() / 2 - 30 * 16 / 2; // gridp.setTranslateX((screen.getWidth()/2+100*16/2)*0.3); // gridp.setTranslateX(0); gridp.setTranslateX(XTRANS); gridp.setTranslateY(YTRANS); // gridp.setAlignment(Pos.CENTER); Group grid = new Group(gridp); // grid.setTranslateX(0); // grid.setTranslateY(0); // gridp.relocate(-400, -400); // gridp.setTranslateX(-300); // gridp.setTranslateY(-150); /* final RotateTransition rt = new RotateTransition(Duration.millis(3000), gridp); rt.setByAngle(180); rt.setCycleCount(4); rt.setAutoReverse(true); */ // rt.setAutoReverse(false); /*` final BorderPane border = new BorderPane(); */ // Label title = new Label("EXPLORATIONS IN CELLULAR SPACES"); Label title = new Label("E X P L O R A T I O N S"); title.setFont(new Font("Helvetica Neue Condensed Bold", 36)); title.setTextFill(Color.WHITE); // Label title2 = new Label("IN CELLULAR SPACES"); Label title2 = new Label("EXPLORATIONS IN CELLULAR SPACES"); title2.setFont(new Font("Helvetica Neue Condensed Bold", 28)); title2.setTextFill(Color.WHITE); /*` title.setAlignment(Pos.CENTER); title.setContentDisplay(ContentDisplay.CENTER); title.setTextAlignment(TextAlignment.CENTER); */ final HBox toptitle = new HBox(); toptitle.setAlignment(Pos.CENTER); toptitle.getChildren().add(title); toptitle.setTranslateX(XTRANS); toptitle.setTranslateY(YTRANS - 36); final HBox btitle = new HBox(); btitle.setAlignment(Pos.CENTER); title2.setAlignment(Pos.CENTER); btitle.getChildren().add(title2); btitle.setTranslateX(XTRANS); // btitle.setTranslateX(screen.getWidth()/2-title2.getPrefWidth()/2); btitle.setTranslateY(YTRANS + 30 * 16); Group border = new Group(); // border.getChildren().add(toptitle); for (Starfield st : stars) { border.getChildren().add(st); } // border.getChildren().add(starfield2); border.getChildren().add(btitle); border.getChildren().add(grid); final List<TranslateTransition> tts = new ArrayList<>(); final TranslateTransition tt = new TranslateTransition(Duration.millis(6000), grid); tt.setByY(2000); tts.add(tt); for (Starfield sf : stars) { TranslateTransition st = new TranslateTransition(Duration.millis(6000), sf); st.setByY(200); st.setByZ(100 + rand.nextInt(100)); tts.add(st); } /* final TranslateTransition tt2 = new TranslateTransition(Duration.millis(6000), starfield1); tt2.setByY(200); tt2.setByZ(200); final TranslateTransition tt3 = new TranslateTransition(Duration.millis(6000), starfield2); tt3.setByY(300); tt3.setByZ(200); */ // final ParallelTransition infinite = new ParallelTransition(tt, tt2, tt3); final ParallelTransition infinite = new ParallelTransition(tts.toArray(new TranslateTransition[0])); final BorderPane ctrl = new BorderPane(); // ctrl.setPrefSize(200, 100); // ctrl.setMaxSize(200, 100); Label start = new Label("Start"); start.setTextFill(Color.WHITE); start.setFont(new Font("Helvetica", 28)); start.setAlignment(Pos.CENTER_LEFT); start.setContentDisplay(ContentDisplay.CENTER); start.setTranslateX(XTRANS + 30 * 16 + 100); start.setTranslateY(screen.getHeight() / 2); // start.setTranslateX(-400); Circle ico = new Circle(15); ico.setOnMouseClicked( new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { FadeTransition ft = new FadeTransition(Duration.millis(500), ctrl); ft.setFromValue(1.0); ft.setToValue(0.0); FadeTransition tft = new FadeTransition(Duration.millis(500), btitle); tft.setFromValue(1.0); tft.setToValue(0.0); ParallelTransition pt = new ParallelTransition(ft, tft); // TranslateTransition fft = new TranslateTransition(Duration.millis(3000), border); // tt.setByY(2000); SequentialTransition st = new SequentialTransition(pt, infinite); st.setOnFinished( new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { State state = State.state().rules(rules2).random(new Rand()).size(400); Iterator<Rule> it = state.rules().random(state.random().create()); CA ca = new CA( it.next(), new RandomInitializer(), state.random().create(), 0, state.size(), state.size()); state.ca(ca); // final Futures futures = new Futures(rules2, new Rand()); final Controls controls = new Controls(state); // controls.setTranslateX(screen.getWidth()/2 - // futures.getPossibilityWidth()/2); // controls.setTranslateY(screen.getHeight()/2 - // futures.getPossiblityHeight()/2-20); // controls.setTranslateX(screen.getWidth()/2 - (3*200+2*10)/2); // controls.setTranslateY(screen.getHeight()/2 - (3*200+2*10)/2-20); for (Starfield sf : stars) { state.addListener(sf); // futures.addFutureListener(sf); } // futures.addFutureListener(starfield1); // futures.addFutureListener(starfield2); border.getChildren().remove(grid); border.getChildren().remove(btitle); // border.getChildren().add(futures); border.getChildren().add(controls); // futures.setTranslateX(screen.getWidth()/2 - futures.getPossibilityWidth()/2); // futures.setTranslateY(screen.getHeight()/2 - // futures.getPossiblityHeight()/2); // border.setCenter(futures); // border.setAlignment(futures, Pos.CENTER); } }); st.play(); } }); // Sphere ico = new Sphere(15); // ico.setDrawMode(DrawMode.LINE); ico.setFill(Color.rgb(10, 10, 10)); ico.setStroke(Color.WHITE); ico.setStrokeWidth(3); ico.setTranslateX(XTRANS + 30 * 16 + 100); ico.setTranslateY(screen.getHeight() / 2); // ctrl.setTop(ico); ctrl.setCenter(ico); /* border.setRight(ctrl); border.setMaxSize(800,600); border.setPrefSize(800,600); */ border.getChildren().add(ctrl); Group root = new Group(); root.getChildren().add(border); // root.setAutoSizeChildren(false); // root.setLayoutX(-400); // root.setLayoutY(-400); // Scene scene = new Scene(root, 1200, 1000); Scene scene = new Scene(root, 1280, 1024, true, SceneAntialiasing.DISABLED); scene.setFill(Color.BLACK); scene.setCamera(new PerspectiveCamera()); // set Stage boundaries to visible bounds of the main screen stage.setX(screen.getMinX()); stage.setY(screen.getMinY()); stage.setWidth(screen.getWidth()); stage.setHeight(screen.getHeight()); stage.setTitle("Explorations in Cellular Spaces"); stage.setScene(scene); stage.setResizable(false); // root.autosize(); // stage.sizeToScene(); stage.show(); }
@Override public void start(final Stage primaryStage) { primaryStage.setTitle("Chapter 3-2 Playing Video"); primaryStage.centerOnScreen(); primaryStage.initStyle(StageStyle.TRANSPARENT); final Group root = new Group(); final Scene scene = new Scene(root, 540, 300, Color.rgb(0, 0, 0, 0)); // rounded rectangle with slightly transparent Node applicationArea = createBackground(scene); root.getChildren().add(applicationArea); // allow the user to drag window on the desktop attachMouseEvents(scene, primaryStage); // allows the user to see the progress of the video playing progressSlider = createSlider(scene); root.getChildren().add(progressSlider); // Dragging over surface scene.setOnDragOver( new EventHandler<DragEvent>() { @Override public void handle(DragEvent event) { Dragboard db = event.getDragboard(); if (db.hasFiles() || db.hasUrl() || db.hasString()) { event.acceptTransferModes(TransferMode.COPY); if (mediaPlayer != null) { mediaPlayer.stop(); } } else { event.consume(); } } }); // update slider as video is progressing (later removal) progressListener = new ChangeListener<Duration>() { public void changed( ObservableValue<? extends Duration> observable, Duration oldValue, Duration newValue) { progressSlider.setValue(newValue.toSeconds()); } }; // Dropping over surface scene.setOnDragDropped( new EventHandler<DragEvent>() { @Override public void handle(DragEvent event) { Dragboard db = event.getDragboard(); boolean success = false; URI resourceUrlOrFile = null; // dragged from web browser address line? if (db.hasContent(DataFormat.URL)) { try { resourceUrlOrFile = new URI(db.getUrl().toString()); } catch (URISyntaxException ex) { ex.printStackTrace(); } } else if (db.hasFiles()) { // dragged from the file system String filePath = null; for (File file : db.getFiles()) { filePath = file.getAbsolutePath(); } resourceUrlOrFile = new File(filePath).toURI(); success = true; } // load media Media media = new Media(resourceUrlOrFile.toString()); // stop previous media player and clean up if (mediaPlayer != null) { mediaPlayer.stop(); mediaPlayer.currentTimeProperty().removeListener(progressListener); mediaPlayer.setOnPaused(null); mediaPlayer.setOnPlaying(null); mediaPlayer.setOnReady(null); } // create a new media player mediaPlayer = MediaPlayerBuilder.create().media(media).build(); // as the media is playing move the slider for progress mediaPlayer.currentTimeProperty().addListener(progressListener); // play video when ready status mediaPlayer.setOnReady( new Runnable() { @Override public void run() { progressSlider.setValue(1); progressSlider.setMax(mediaPlayer.getMedia().getDuration().toMillis() / 1000); mediaPlayer.play(); } }); // Lazy init media viewer if (mediaView == null) { mediaView = MediaViewBuilder.create() .mediaPlayer(mediaPlayer) .x(4) .y(4) .preserveRatio(true) .opacity(.85) .smooth(true) .build(); mediaView.fitWidthProperty().bind(scene.widthProperty().subtract(220)); mediaView.fitHeightProperty().bind(scene.heightProperty().subtract(30)); // make media view as the second node on the scene. root.getChildren().add(1, mediaView); } // sometimes loading errors occur mediaView.setOnError( new EventHandler<MediaErrorEvent>() { public void handle(MediaErrorEvent event) { event.getMediaError().printStackTrace(); } }); mediaView.setMediaPlayer(mediaPlayer); event.setDropCompleted(success); event.consume(); } }); // rectangular area holding buttons final Group buttonArea = createButtonArea(scene); // stop button will stop and rewind the media Node stopButton = createStopControl(); // play button can resume or start a media final Node playButton = createPlayControl(); // pauses media play final Node pauseButton = createPauseControl(); stopButton.setOnMousePressed( new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { if (mediaPlayer != null) { buttonArea.getChildren().removeAll(pauseButton, playButton); buttonArea.getChildren().add(playButton); mediaPlayer.stop(); } } }); // pause media and swap button with play button pauseButton.setOnMousePressed( new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { if (mediaPlayer != null) { buttonArea.getChildren().removeAll(pauseButton, playButton); buttonArea.getChildren().add(playButton); mediaPlayer.pause(); paused = true; } } }); // play media and swap button with pause button playButton.setOnMousePressed( new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { if (mediaPlayer != null) { buttonArea.getChildren().removeAll(pauseButton, playButton); buttonArea.getChildren().add(pauseButton); paused = false; mediaPlayer.play(); } } }); // add stop button to button area buttonArea.getChildren().add(stopButton); // set pause button as default buttonArea.getChildren().add(pauseButton); // add buttons root.getChildren().add(buttonArea); // create a close button Node closeButton = createCloseButton(scene); root.getChildren().add(closeButton); primaryStage.setOnShown( new EventHandler<WindowEvent>() { public void handle(WindowEvent we) { previousLocation = new Point2D(primaryStage.getX(), primaryStage.getY()); } }); primaryStage.setScene(scene); primaryStage.show(); }
public WeightCoverageChart() { weightA.addListener( new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { pieData.set( 0, new PieChart.Data("A " + weightA.doubleValue() + "kgs", (weightA.doubleValue()))); } }); weightB.addListener( new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { pieData.set(1, new PieChart.Data("B", (weightB.doubleValue()))); } }); weightC.addListener( new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { pieData.set(2, new PieChart.Data("C", (weightC.doubleValue()))); } }); weightD.addListener( new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { pieData.set(3, new PieChart.Data("D", (weightD.doubleValue()))); } }); weightE.addListener( new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { pieData.set(4, new PieChart.Data("E", (weightE.doubleValue()))); } }); weightF.addListener( new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { pieData.set(5, new PieChart.Data("F", (weightF.doubleValue()))); } }); weightG.addListener( new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { pieData.set(6, new PieChart.Data("G", (weightG.doubleValue()))); } }); weightH.addListener( new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { pieData.set(7, new PieChart.Data("H", (weightH.doubleValue()))); } }); weightI.addListener( new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { pieData.set(8, new PieChart.Data("I", (weightI.doubleValue()))); } }); this.setCache(true); pie.setData(pieData); Rectangle pieBG = RectangleBuilder.create() .cache(true) .x(pie.getTranslateX() + 127) .y(pie.getTranslateY() + 84) .fill(Color.rgb(50, 50, 50)) .id("envelopeBG") .width(265) .height(245) .arcWidth(5) .arcHeight(5) .build(); Group group = new Group(); group.getChildren().addAll(pieBG, pie); getChildren().add(group); }
public ColorPickerPopover() { getStyleClass().add("color-picker-popover"); popup.setAutoHide(true); // add this to popup popup.getContent().add(this); // load stylesheet getStylesheets().add(ColorPicker.class.getResource("ColorPicker.css").toString()); // create popover path for main shape final Path p = new Path(); p.getElements() .addAll( new MoveTo(PICKER_PADDING, PICKER_PADDING + ARROW_SIZE + RADIUS), new ArcTo( RADIUS, RADIUS, 90, PICKER_PADDING + RADIUS, PICKER_PADDING + ARROW_SIZE, false, true), new LineTo(PICKER_PADDING + ARROW_X - (ARROW_SIZE * 0.8), PICKER_PADDING + ARROW_SIZE), new LineTo(PICKER_PADDING + ARROW_X, PICKER_PADDING), new LineTo(PICKER_PADDING + ARROW_X + (ARROW_SIZE * 0.8), PICKER_PADDING + ARROW_SIZE), new LineTo(PICKER_PADDING + PICKER_WIDTH - RADIUS, PICKER_PADDING + ARROW_SIZE), new ArcTo( RADIUS, RADIUS, 90, PICKER_PADDING + PICKER_WIDTH, PICKER_PADDING + ARROW_SIZE + RADIUS, false, true), new LineTo( PICKER_PADDING + PICKER_WIDTH, PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT - RADIUS), new ArcTo( RADIUS, RADIUS, 90, PICKER_PADDING + PICKER_WIDTH - RADIUS, PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT, false, true), new LineTo(PICKER_PADDING + RADIUS, PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT), new ArcTo( RADIUS, RADIUS, 90, PICKER_PADDING, PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT - RADIUS, false, true), new ClosePath()); p.setFill( new LinearGradient( 0, 0, 0, 1, true, CycleMethod.NO_CYCLE, new Stop(0, Color.web("#313131")), new Stop(0.5, Color.web("#5f5f5f")), new Stop(1, Color.web("#313131")))); p.setStroke(null); p.setEffect(new DropShadow(15, 0, 1, Color.gray(0, 0.6))); p.setCache(true); // create rectangle to capture mouse events to hide Rectangle windowClickRect = RectangleBuilder.create() .width(PICKER_PADDING + PICKER_WIDTH + PICKER_PADDING) .height(PICKER_PADDING + PICKER_HEIGHT + PICKER_PADDING) .fill(Color.TRANSPARENT) .onMouseClicked( new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { System.out.println("x= " + event.getX()); System.out.println( "p.contains(event.getX(), event.getY()) = " + p.contains(event.getX(), event.getY())); if (!p.contains(event.getX(), event.getY())) { hide(); } } }) .build(); final Circle colorRectIndicator = CircleBuilder.create() .centerX(60) .centerY(60) .radius(5) .stroke(Color.WHITE) .fill(null) .effect(new DropShadow(2, 0, 1, Color.BLACK)) .build(); colorRectIndicator .centerXProperty() .bind( new DoubleBinding() { { bind(sat); } @Override protected double computeValue() { return (PICKER_PADDING + 10) + (RECT_SIZE * (sat.get() / 100)); } }); colorRectIndicator .centerYProperty() .bind( new DoubleBinding() { { bind(bright); } @Override protected double computeValue() { return (PICKER_PADDING + ARROW_SIZE + 10) + (RECT_SIZE * (1 - (bright.get() / 100))); } }); final Rectangle colorRect = RectangleBuilder.create() .x(PICKER_PADDING + 10) .y(PICKER_PADDING + ARROW_SIZE + 10) .width(RECT_SIZE) .height(RECT_SIZE) .build(); colorRect .fillProperty() .bind( new ObjectBinding<Paint>() { { bind(color); } @Override protected Paint computeValue() { return Color.hsb(hue.getValue(), 1, 1); } }); Rectangle colorRectOverlayOne = RectangleBuilder.create() .x(PICKER_PADDING + 10) .y(PICKER_PADDING + ARROW_SIZE + 10) .width(RECT_SIZE) .height(RECT_SIZE) .fill( new LinearGradient( 0, 0, 1, 0, true, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(255, 255, 255, 1)), new Stop(1, Color.rgb(255, 255, 255, 0)))) .build(); EventHandler<MouseEvent> rectMouseHandler = new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { final double x = event.getX() - colorRect.getX(); final double y = event.getY() - colorRect.getY(); sat.set(clamp(x / RECT_SIZE) * 100); bright.set(100 - (clamp(y / RECT_SIZE) * 100)); } }; Rectangle colorRectOverlayTwo = RectangleBuilder.create() .x(PICKER_PADDING + 10) .y(PICKER_PADDING + ARROW_SIZE + 10) .width(RECT_SIZE) .height(RECT_SIZE) .fill( new LinearGradient( 0, 0, 0, 1, true, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(0, 0, 0, 0)), new Stop(1, Color.rgb(0, 0, 0, 1)))) .onMouseDragged(rectMouseHandler) .onMouseClicked(rectMouseHandler) .build(); final Rectangle colorBar = RectangleBuilder.create() .x(PICKER_PADDING + PICKER_WIDTH - 30) .y(PICKER_PADDING + ARROW_SIZE + 10) .width(20) .height(RECT_SIZE) .fill(createHueGradient()) .build(); final Rectangle colorBarIndicator = RectangleBuilder.create() .x(PICKER_PADDING + PICKER_WIDTH - 32) .y(PICKER_PADDING + ARROW_SIZE + 15) .width(24) .height(10) .arcWidth(4) .arcHeight(4) .stroke(Color.WHITE) .fill(null) .effect(new DropShadow(2, 0, 1, Color.BLACK)) .build(); colorBarIndicator .yProperty() .bind( new DoubleBinding() { { bind(hue); } @Override protected double computeValue() { return (PICKER_PADDING + ARROW_SIZE + 5) + (RECT_SIZE * (hue.get() / 360)); } }); EventHandler<MouseEvent> barMouseHandler = new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { final double y = event.getY() - colorBar.getY(); hue.set(clamp(y / RECT_SIZE) * 360); } }; colorBar.setOnMouseDragged(barMouseHandler); colorBar.setOnMouseClicked(barMouseHandler); Label brightnessLabel = new Label("Brightness:"); brightnessLabel.setMinWidth(Control.USE_PREF_SIZE); GridPane.setConstraints(brightnessLabel, 0, 0); Slider brightnessSlider = SliderBuilder.create().min(0).max(100).id("BrightnessSlider").build(); brightnessSlider.valueProperty().bindBidirectional(bright); GridPane.setConstraints(brightnessSlider, 1, 0); IntegerField brightnessField = new IntegerField(); brightnessField.valueProperty().bindBidirectional(bright); brightnessField.setPrefColumnCount(7); GridPane.setConstraints(brightnessField, 2, 0); Label saturationLabel = new Label("Saturation:"); saturationLabel.setMinWidth(Control.USE_PREF_SIZE); GridPane.setConstraints(saturationLabel, 0, 1); Slider saturationSlider = SliderBuilder.create().min(0).max(100).id("SaturationSlider").build(); saturationSlider.valueProperty().bindBidirectional(sat); GridPane.setConstraints(saturationSlider, 1, 1); saturationSlider .styleProperty() .bind( new StringBinding() { { bind(color); } @Override protected String computeValue() { return "picker-color: hsb(" + hue.get() + ",100%,100%);"; } }); IntegerField saturationField = new IntegerField(); saturationField.valueProperty().bindBidirectional(sat); saturationField.setPrefColumnCount(7); GridPane.setConstraints(saturationField, 2, 1); Label webLabel = new Label("Web:"); webLabel.setMinWidth(Control.USE_PREF_SIZE); GridPane.setConstraints(webLabel, 0, 2); WebColorField webField = new WebColorField(); webField.valueProperty().bindBidirectional(color); GridPane.setConstraints(webField, 1, 2, 2, 1); GridPane controls = new GridPane(); controls.setVgap(5); controls.setHgap(5); controls .getChildren() .addAll( brightnessLabel, brightnessSlider, brightnessField, saturationLabel, saturationSlider, saturationField, webLabel, webField); controls.setManaged(false); controls.resizeRelocate( PICKER_PADDING + 10, PICKER_PADDING + ARROW_SIZE + 10 + 170 + 10, PICKER_WIDTH - 20, controls.getPrefHeight()); getChildren() .addAll( windowClickRect, p, colorRect, colorRectOverlayOne, colorRectOverlayTwo, colorBar, colorRectIndicator, colorBarIndicator, controls); }