gc.setFill(Color.FORESTGREEN); gc.fillOval( x.doubleValue(), y.doubleValue(), D,
public double getWidth() { return width.doubleValue(); } public void setFont(Font f) {
@Override public double doubleValue() { return delegate.doubleValue(); }
/** * Define the max width for the content. The value of the property is taken * as width * * @param width of the pagination container * @return this */ public PaginationV2Builder contentMaxWidth(DoubleProperty width) { contentMaxWidth = new SimpleDoubleProperty(this, "contentMaxWidth", width.doubleValue()); return this; }
/** * Define the max width for the content. The value of the property is taken * as width * * @param height conent height of the pagination container * @return this */ public PaginationV2Builder contentMaxHeight(DoubleProperty height) { contentMaxHeight = new SimpleDoubleProperty(this, "contentMaxHeight", height.doubleValue()); return this; }
DoubleProperty a = ... DoubleProperty b = ... DoubleBinding maxBinding= new DoubleBinding() { { super.bind(a, b); } @Override protected double computeValue() { return Math.max(a.doubleValue(), b.doubleValue()); } @Override public void dispose() { super.unbind(a, b); } };
private void setImage() { final InputStream is = getClass().getResourceAsStream("InputPlank.jpg"); Image img1 = new Image(is,width.doubleValue(), height.doubleValue(), false, true); imgView.setImage(img1); imgView.setLayoutY(0); }
/** * Snap to the correct angle. Correct angle is angle belonging to the nearest label. */ void snapToNearestAngle() { double currentAngle = currentRotation.doubleValue() + 180; double currentMin = 360; int minIndex = 0; for (int i = 0; i < angles.size(); i++) { double angle = angles.get(i); double diff = Math.abs(angle - currentAngle); if (diff < currentMin) { currentMin = diff; minIndex = i; } } Double destinationAngle = angles.get(minIndex); if (destinationAngle < 180 + 10 || destinationAngle > 360 - 10) { throw new IllegalStateException("Angle is out of range: "+currentRotation.doubleValue()+" -> "+destinationAngle); } control.selectedIndexProperty().set(minIndex); currentRotation.set(destinationAngle - 180); } /**
/** * Returns the width of a cell * @return Computed width of a cell */ protected double computeCellWidth() { return getSkinnable().cellWidthProperty().doubleValue() + (getSkinnable().horizontalCellSpacingProperty().doubleValue() * 2); }
private void redrawPath(double oldScale) { double scaleCorrection = 1/oldScale; double scale = this.scale.doubleValue() * scaleCorrection; logger.debug("Rescale path from {} to {}, which is a correction of {}", oldScale, this.scale, scale); for (Node node : shipCanvas.getChildren()) { if (node instanceof Path) { for (PathElement pathElement : ((Path) node).getElements()) { rescale(pathElement, scale); } } } }
private void drawShipPresenceInCity(ICity city) { int radius = 8; int cityX = (int) Math.rint(city.getCoordinates().getX()); int cityY = (int) Math.rint(city.getCoordinates().getY()); double lScale = scale.doubleValue(); Circle c = new Circle(cityX * lScale, cityY * lScale, radius * lScale, Color.WHITE); shipCanvas.getChildren().add(c); }
private void calculateDimensions(OpenPatricianDialogInput input) { Dimension2D dim = sizing.calculate(input.getSize(), input.getFont()); width.set(dim.getWidth()); height.set(dim.getHeight() + 10); textField.setMaxSize(width.doubleValue(), height.doubleValue()); } }
private void calculateDimensions(OpenPatricianWoodenTextInput input) { Dimension2D dim = sizing.calculate(input.getSize(), input.getFont()); double inputHeigth = textField.getHeight(); width.set(dim.getWidth()); height.set(Math.max(dim.getHeight(), inputHeigth)); textField.setMaxSize(width.doubleValue(), height.doubleValue()); setImage(); }
@Subscribe public void handleShipLeavesCity(ShipLeavingPort event) { ICity city = event.getCity(); final IShipOwner owner = event.getShip().getOwner(); if (owner instanceof IHumanPlayer && owner.equals(viewState.getPlayer())) { List<INavigableVessel> ships = ((IHumanPlayer)owner).findShips(city); if (ships.isEmpty()) { double cityX = (int) Math.rint(city.getCoordinates().getX()) * scale.doubleValue(); double cityY = (int) Math.rint(city.getCoordinates().getY()) * scale.doubleValue(); for (Iterator<Node> iterator = shipCanvas.getChildren().iterator(); iterator.hasNext(); ) { Node node = iterator.next(); if (node instanceof Circle) { Circle c = (Circle) node; if (c.getCenterX() == cityX && c.getCenterY() == cityY) { Platform.runLater(iterator::remove); break; } } } } } }
/** * Calculate a new path for the <code>vessel</code> and draw it on the map. * @param vessel that travels along the path * @param path series of points defining the path. */ private void drawPath(INavigableVessel vessel, List<Point2D> path) { if (path != null) { clearLines(); Optional<Path> p = pathConverter.createPath(vessel, path, scale.doubleValue()); if (p.isPresent()) { drawPathOnMap(vessel, path, p.get()); } else { logger.warn("Path not available for {} of {} {}", vessel.getName(), vessel.getOwner().getName(), vessel.getOwner().getLastName()); } } }
/** * Split up the text into lines and pages, that can be displayed. * @param text component that is to be split up. */ private void splitTextToPages(Text text) { final double width = getContentWidth(); final double heigh = contentHeight.doubleValue(); Font font = control.getNavigationLabelFont(); PageSplitter splitter = new PageSplitter(heigh, width, contentContainer.getSpacing(), calculateContentInitialHeigth(), font); splitter.setWordSplitter(new NonAlphaNumWordSplitter()); pages.addAll(splitter.splitIntoPages(text)); } private double getContentWidth() {
/** * Create the labels and add them to the group. * @param g group the labels are added to * @param centerPoint central point around which the labels are placed. */ private void createAndAddLabels(Group g, final Point2D centerPoint) { List<String> values = control.valuesProperty(); angles = new ArrayList<>(values.size()); double angle = currentRotation.doubleValue() + 180; double step = (180.0 - 2 * currentRotation.doubleValue()) / (values.size() - 1); int radius = 120; for (String value : values) { angles.add(angle); Point2D basePoint = calculateBasePoint(centerPoint, radius, angle); Dimension2D dim = sizeing.calculate(value, control.getFont()); Label l = new Label(value); l.setFont(control.getFont()); l.getStyleClass().add("openPatricianSlider"); l.setTranslateX(basePoint.getX() - dim.getWidth() * calculateMoveFactor(angle)); l.setTranslateY(basePoint.getY() - dim.getHeight()); g.getChildren().add(l); angle += step; } double initialAngle = Math.max(INITIAL_ROTATION, control.getSelectedIndex() * step); currentRotation.setValue(initialAngle); } /**
public ViewStatus() { setManaged(false); getStylesheets().add(getClass().getResource(getClass().getSimpleName() + ".css").toExternalForm()); city = new SimpleStringProperty(this, "city", ""); width = new SimpleDoubleProperty(this, "controlWidth", 0); cityName = new Text(); cityName.setFill(Color.WHITE); cityName.getStyleClass().add("cityName"); cityName.textProperty().bind(city); cityName.setOnMouseReleased(createHistoryDisplayHandler()); // handler to close any open dialog and open a history dialog Rectangle placeholder = new Rectangle(width.doubleValue(), 50); placeholder.setFill(Color.TRANSPARENT); placeholder.widthProperty().bind(width); StackPane centering = new StackPane(); centering.prefWidthProperty().bind(width); centering.getChildren().add(cityName); getChildren().addAll(placeholder, centering); } @PostConstruct
public OpenPatricianDialogInputSkin(OpenPatricianDialogInput input) { super(input); textField = new TextField(input.getText()); calculateDimensions(input); input.fontProperty().addListener((observable, oldValue, newValue) -> calculateDimensions(input)); textField.textProperty().bindBidirectional(input.textProperty()); textField.getStyleClass().add("openPatricianDialogInput"); Rectangle background = new Rectangle(); background.setHeight(height.doubleValue()); background.setWidth(width.doubleValue()); background.setFill(Color.rgb(150, 150, 150)); background.heightProperty().bind(height); background.widthProperty().bind(width); StackPane stack = new StackPane(); stack.getChildren().addAll(background, textField); Group group = new Group(stack); group.setManaged(false); getChildren().add(group); }
public OpenPatricianSliderSkin(OpenPatricianSlider slider) { super(slider); control = slider; currentRotation = new SimpleDoubleProperty(this, "currentRotation", INITIAL_ROTATION); sizeing = new TextSizingUtility(); final SteeringWheelGroup background = new SteeringWheelGroup(control.getInitialWidth(), currentRotation.doubleValue()); background.setManaged(false); Group g = new Group(background); final Point2D centerPoint = new Point2D(control.getInitialWidth()/2, control.getInitialWidth()/2); createAndAddLabels(g, centerPoint); background.setTranslateX(centerPoint.getX() - background.getImageWidth()/2); background.setTranslateY(centerPoint.getY() - background.getImageWidth()/2 - yTranslation); getChildren().add(g); } /**