private void initProgressBinding() { DoubleExpression tmp = constantOf(0); for (Command command : registeredCommands) { final ReadOnlyDoubleProperty progressProperty = command.progressProperty(); /** * When the progress of a command is "undefined", the progress property has a value of -1. * But in our use case we like to have a value of 0 in this case. * Therefore we create a custom binding here. */ final DoubleBinding normalizedProgress = Bindings .createDoubleBinding(() -> (progressProperty.get() == -1) ? 0.0 : progressProperty.get(), progressProperty); tmp = tmp.add(normalizedProgress); } int divisor = registeredCommands.isEmpty() ? 1 : registeredCommands.size(); progress.bind(Bindings.divide(tmp, divisor)); }
static ReadOnlyDoubleProperty fillImage(ImageView imageView, int zoom, long i, long j) { Image image = fromFileCache(zoom, i, j); if (image == null) { String urlString = host + zoom + "/" + i + "/" + j + ".png"; if (hasFileCache) { Task<Object> task = new Task() { @Override protected Object call() throws Exception { cacheThread.cacheImage(urlString, zoom, i, j); return null; // can't return image yet } }; Thread t = new Thread(task); t.start(); } image = new Image(urlString, true); } imageView.setImage(image); return image.progressProperty(); }
public MenuBar buildMenuBarWithMenus(HTMLEditor editor, final ReadOnlyDoubleProperty menuWidthProperty, String STYLE_CSS){ MenuBar menuBar = new MenuBar(); menuBar.setStyle(STYLE_CSS); // Add File menu to menu bar menuBar.getMenus().add(new FileMenuBuilder().getProduct(editor)); //Add Edit menu to menu bar menuBar.getMenus().add(new EditMenuBuilder().getProduct(editor)) ; //Add Insert menu to menu bar menuBar.getMenus().add(new InsertMenuBuilder().getProduct(editor)); //Add Indent menu to menu bar menuBar.getMenus().add(new IndentMenuBuilder().getProduct(editor)); // Add View menu to menu bar menuBar.getMenus().add(new ViewMenuBuilder().getProduct(editor)); // bind width of menu bar to width of associated stage menuBar.prefWidthProperty().bind(menuWidthProperty); return menuBar; }
public DraggableItem(SpriteObject item, ReadOnlyDoubleProperty width, ReadOnlyDoubleProperty height, SimpleDoubleProperty x, SimpleDoubleProperty y){ myItem=item; myWidth=item.getImage().getFitWidth(); myHeight=item.getImage().getFitHeight(); gridWidth=width.getValue().doubleValue(); gridHeight=height.getValue().doubleValue(); startX=x.getValue().doubleValue(); startY=y.getValue().doubleValue(); addListener(x, (toChange)->changeX(toChange)); addListener(y, (toChange)->changeY(toChange)); addListener(myItem.getObservableWidth(), (toChange)->changeWidth(toChange)); addListener(myItem.getObservableHeight(), (toChange)->changeHeight(toChange)); addListener(width, (toChange)->changeGridWidth(toChange)); addListener(height, (toChange)->changeGridHeight(toChange)); drag(); }
/** Replies the property for the arc width. * * @return the arcWidth property. */ public DoubleProperty arcWidthProperty() { if (this.arcWidth == null) { this.arcWidth = new DependentSimpleDoubleProperty<ReadOnlyDoubleProperty>( this, MathFXAttributeNames.ARC_WIDTH, widthProperty()) { @Override protected void invalidated(ReadOnlyDoubleProperty dependency) { final double value = get(); if (value < 0.) { set(0.); } else { final double maxArcWidth = dependency.get() / 2.; if (value > maxArcWidth) { set(maxArcWidth); } } } }; } return this.arcWidth; }
/** Replies the property for the arc height. * * @return the arcHeight property. */ public DoubleProperty arcHeightProperty() { if (this.arcHeight == null) { this.arcHeight = new DependentSimpleDoubleProperty<ReadOnlyDoubleProperty>( this, MathFXAttributeNames.ARC_HEIGHT, heightProperty()) { @Override protected void invalidated(ReadOnlyDoubleProperty dependency) { final double value = get(); if (value < 0.) { set(0.); } else { final double maxArcHeight = dependency.get() / 2.; if (value > maxArcHeight) { set(maxArcHeight); } } } }; } return this.arcHeight; }
@Test public void widthProperty() { assertEpsilonEquals(5, this.shape.getWidth()); ReadOnlyDoubleProperty property = this.shape.widthProperty(); assertNotNull(property); assertEpsilonEquals(5, property.get()); this.shape.setMinX(7); assertEpsilonEquals(3, property.get()); this.shape.setMinX(-5); assertEpsilonEquals(15, property.get()); this.shape.setMaxX(0); assertEpsilonEquals(5, property.get()); }
@Test public void heightProperty() { assertEpsilonEquals(10, this.shape.getHeight()); ReadOnlyDoubleProperty property = this.shape.heightProperty(); assertNotNull(property); assertEpsilonEquals(10, property.get()); this.shape.setMinY(9); assertEpsilonEquals(9, property.get()); this.shape.setMinY(-5); assertEpsilonEquals(23, property.get()); this.shape.setMaxY(0); assertEpsilonEquals(5, property.get()); }
@Test public void depthProperty() { assertEpsilonEquals(0, this.shape.getDepth()); ReadOnlyDoubleProperty property = this.shape.depthProperty(); assertNotNull(property); assertEpsilonEquals(0, property.get()); this.shape.setMinZ(9); assertEpsilonEquals(0, property.get()); this.shape.setMinZ(-5); assertEpsilonEquals(14, property.get()); this.shape.setMaxZ(0); assertEpsilonEquals(5, property.get()); }
private Pane createTraceWidget(ITraceExtractor<Step<?>, State<?,?>, TracedObject<?>, Dimension<?>, Value<?>> extractor, String label, ReadOnlyDoubleProperty width) { final Pane pane = new Pane(); pane.setBackground(TRANSPARENT_BACKGROUND); final Rectangle rectangle = new Rectangle(0, 0, 0, 12); rectangle.setFill(Color.LIGHTGRAY); rectangle.widthProperty().bind(width.subtract(10)); rectangle.setArcHeight(12); rectangle.setArcWidth(12); Label text = new Label(label); text.setTextOverrun(OverrunStyle.ELLIPSIS); text.setAlignment(Pos.CENTER); text.setMouseTransparent(true); text.setTextFill(Color.WHITE); text.setFont(FONT); text.setMaxWidth(0); text.maxWidthProperty().bind(rectangle.widthProperty()); StackPane layout = new StackPane(); layout.getChildren().addAll(rectangle, text); pane.getChildren().add(layout); layout.setTranslateY(13); layout.setTranslateX(5); pane.setPrefHeight(25); pane.setMinHeight(25); pane.setMaxHeight(25); final Shape arrow1 = createCursor(); final Shape arrow2 = createCursor(); arrow1.setTranslateX(5); arrow1.setTranslateY(4); arrow2.translateXProperty().bind(rectangle.widthProperty().add(5)); arrow2.setTranslateY(4); pane.getChildren().add(arrow1); pane.getChildren().add(arrow2); return pane; }
/** * create a horizontal axis * * @param maxReadLength * @return axis */ public static Pane createAxis(final ReadOnlyIntegerProperty maxReadLength, final ReadOnlyDoubleProperty widthProperty) { final Pane pane = new Pane(); pane.prefWidthProperty().bind(widthProperty); final NumberAxis axis = new NumberAxis(); axis.setSide(Side.TOP); axis.setAutoRanging(false); axis.setLowerBound(0); axis.prefHeightProperty().set(20); axis.prefWidthProperty().bind(widthProperty.subtract(60)); final ChangeListener<Number> changeListener = new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { int minX = Math.round(maxReadLength.get() / 2000.0f); // at most 2000 major ticks for (int x = 10; x < 10000000; x *= 10) { if (x >= minX && widthProperty.doubleValue() * x >= 50 * maxReadLength.doubleValue()) { axis.setUpperBound(maxReadLength.get()); axis.setTickUnit(x); return; } } axis.setTickUnit(maxReadLength.get()); axis.setUpperBound(maxReadLength.get()); } }; maxReadLength.addListener(changeListener); widthProperty.addListener(changeListener); pane.getChildren().add(axis); return pane; }
/** * constructor * * @param doc * @param cNames * @param classificationName * @param tableView */ public TableItemTask(Document doc, String[] cNames, String classificationName, Set<Integer> classIds, TableView<TableItem> tableView, FloatProperty maxBitScore, FloatProperty maxNormalizedBitScore, IntegerProperty maxReadLength, ReadOnlyDoubleProperty layoutWidth) { this.doc = doc; this.cNames = cNames; this.classificationName = classificationName; this.classIds = classIds; this.tableView = tableView; this.maxBitScore = maxBitScore; this.maxNormalizedBitScore = maxNormalizedBitScore; this.maxReadLength = maxReadLength; this.layoutWidth = layoutWidth; }
public WCFXPanel(RecordingManager r, ReadOnlyDoubleProperty heightProp, ReadOnlyDoubleProperty widthProp) { rManager = r; wcImg = new ImageView(); setCenter(wcImg); Platform.runLater(new Runnable() { @Override public void run() { initView(heightProp, widthProp); } }); }
private void initView(ReadOnlyDoubleProperty heightProp, ReadOnlyDoubleProperty widthProp) { wcImg.fitWidthProperty().bind(widthProp); wcImg.fitHeightProperty().bind(heightProp); wcImg.setPreserveRatio(true); wcImg.minWidth(0); wcImg.minHeight(0); minWidth(0); minHeight(0); }
@MustCallOnJavaFXThread public LogView( BindableValue<Font> fontValue, ReadOnlyDoubleProperty widthProperty, HighlightOptions highlightOptions, FileContentReader fileContentReader, TaskRunner taskRunner ) { this.highlightOptions = highlightOptions; this.fileContentReader = fileContentReader; this.taskRunner = taskRunner; this.selectionHandler = new SelectionHandler( this ); this.file = fileContentReader.getFile(); final LogLineColors logLineColors = highlightOptions.logLineColorsFor( "" ); final NumberBinding width = Bindings.max( widthProperty(), widthProperty ); logLineFactory = () -> new LogLine( fontValue, width, logLineColors.getBackground(), logLineColors.getFill() ); for ( int i = 0; i < MAX_LINES; i++ ) { getChildren().add( logLineFactory.get() ); } this.colorChangeListener = ( Observable observable ) -> { for ( int i = 0; i < MAX_LINES; i++ ) { updateLine( i ); } }; highlightOptions.getObservableExpressions().addListener( colorChangeListener ); highlightOptions.getStandardLogColors().addListener( colorChangeListener ); tailingFile.addListener( event -> { if ( tailingFile.get() ) { onFileChange(); } } ); this.fileChangeWatcher = new FileChangeWatcher( file, taskRunner, this::onFileChange ); }
private Pane createTraceWidget(ITraceExtractor extractor, String label, ReadOnlyDoubleProperty width) { final Pane pane = new Pane(); pane.setBackground(TRANSPARENT_BACKGROUND); final Rectangle rectangle = new Rectangle(0, 0, 0, 12); rectangle.setFill(Color.LIGHTGRAY); rectangle.widthProperty().bind(width.subtract(10)); rectangle.setArcHeight(12); rectangle.setArcWidth(12); Label text = new Label(label); text.setTextOverrun(OverrunStyle.ELLIPSIS); text.setAlignment(Pos.CENTER); text.setMouseTransparent(true); text.setTextFill(Color.WHITE); text.setFont(FONT); text.setMaxWidth(0); text.maxWidthProperty().bind(rectangle.widthProperty()); StackPane layout = new StackPane(); layout.getChildren().addAll(rectangle, text); pane.getChildren().add(layout); layout.setTranslateY(13); layout.setTranslateX(5); pane.setPrefHeight(25); pane.setMinHeight(25); pane.setMaxHeight(25); final Group group1 = new Group(); final Label label1 = new Label(); final Shape arrow1 = createCursor(); final Group group2 = new Group(); final Shape arrow2 = createCursor(); arrow1.setTranslateX(5); arrow1.setTranslateY(4); arrow2.translateXProperty().bind(rectangle.widthProperty().add(5)); arrow2.setTranslateY(4); pane.getChildren().add(arrow1); pane.getChildren().add(arrow2); return pane; }
public void addDoubleListener(ReadOnlyDoubleProperty prop, DoubleChangeListener listener){ prop.addListener(new ChangeListener<Number>(){ public void changed(ObservableValue<? extends Number> arg0, Number arg1, Number arg2) { listener.change(arg2.doubleValue()); } }); }
private void addListener(ReadOnlyDoubleProperty readOnlyDoubleProperty, DoubleChangeListener doubleChange){ readOnlyDoubleProperty.addListener(new ChangeListener<Number>(){ @Override public void changed(ObservableValue<? extends Number> arg0, Number arg1, Number arg2) { doubleChange.change((arg2.doubleValue())); } }); }
public RfxVerticalFlingScroller(Node node, ReadOnlyDoubleProperty totalContentHeightProperty) { this.node = node; this.totalContentHeightProperty = totalContentHeightProperty; this.velocityTracker = new VelocityTracker(); node.setOnMousePressed(createOnMousePressedHandler()); node.setOnMouseReleased(createOnMouseReleasedHandler()); node.setOnMouseDragged(createOnMouseDraggerdHandler()); }
private static ReadOnlyDoubleProperty createTotalContentHeightProperty(ListView<?> listView) { return new ReadOnlyDoublePropertyBase() { @SuppressWarnings({ "rawtypes" }) @Override public double get() { VirtualFlow flow = (VirtualFlow) listView.lookup(".virtual-flow"); int nrOfItems = listView.getItems().size(); if (nrOfItems == 0) { return 0; } IndexedCell cell = flow.getCell(0); // assuming all cells have same size double cellHeight = cell.getBoundsInLocal().getHeight(); double totalContentHeight = cellHeight * nrOfItems; return totalContentHeight; } @Override public String getName() { return null; } @Override public Object getBean() { return null; } }; }
@Test public void testReadOnlyDoubleProperty(){ ReadOnlyDoubleProperty actual = new SimpleDoubleProperty(30.2); assertThat(actual).hasValue(30.2); assertThat(actual).hasSameValue(actual); }
/** Replies the x property. * * @return the x property. */ @Pure public ReadOnlyDoubleProperty xProperty() { if (isBound()) { return super.get().xProperty(); } return internalXProperty().getReadOnlyProperty(); }
/** Replies the y property. * * @return the y property. */ @Pure public ReadOnlyDoubleProperty yProperty() { if (isBound()) { return super.get().yProperty(); } return internalYProperty().getReadOnlyProperty(); }
/** Replies the property that represents the length of the vector. * * @return the length property */ public ReadOnlyDoubleProperty lengthProperty() { if (this.lengthProperty == null) { this.lengthProperty = new ReadOnlyDoubleWrapper(this, MathFXAttributeNames.LENGTH); this.lengthProperty.bind(Bindings.createDoubleBinding(() -> Math.sqrt(lengthSquaredProperty().doubleValue()), lengthSquaredProperty())); } return this.lengthProperty.getReadOnlyProperty(); }
/** Replies the property that represents the length of the vector. * * @return the length property */ public ReadOnlyDoubleProperty lengthSquaredProperty() { if (this.lengthSquareProperty == null) { this.lengthSquareProperty = new ReadOnlyDoubleWrapper(this, MathFXAttributeNames.LENGTH_SQUARED); this.lengthSquareProperty.bind(Bindings.createDoubleBinding(() -> Vector2dfx.this.x.doubleValue() * Vector2dfx.this.x.doubleValue() + Vector2dfx.this.y.doubleValue() * Vector2dfx.this.y.doubleValue(), this.x, this.y)); } return this.lengthSquareProperty.getReadOnlyProperty(); }
/** Replies the property that represents the length of the vector. * * @return the length property */ public ReadOnlyDoubleProperty lengthSquaredProperty() { if (this.lengthSquareProperty == null) { this.lengthSquareProperty = new ReadOnlyDoubleWrapper(this, MathFXAttributeNames.LENGTH_SQUARED); this.lengthSquareProperty.bind(Bindings.createDoubleBinding(() -> Vector3dfx.this.x.doubleValue() * Vector3dfx.this.x.doubleValue() + Vector3dfx.this.y.doubleValue() * Vector3dfx.this.y.doubleValue() + Vector3dfx.this.z.doubleValue() * Vector3dfx.this.z.doubleValue(), this.x, this.y, this.z)); } return this.lengthSquareProperty.getReadOnlyProperty(); }
/** Replies the z property. * * @return the z property. */ @Pure public ReadOnlyDoubleProperty zProperty() { if (isBound()) { return super.get().zProperty(); } return internalZProperty().getReadOnlyProperty(); }
@Test public void lengthProperty() { Vector2dfx vector = new Vector2dfx(1, 2); assertEpsilonEquals(2.23607, vector.getLength()); ReadOnlyDoubleProperty property = vector.lengthProperty(); assertNotNull(property); assertEpsilonEquals(2.23607, property.get()); vector.set(4, -10); assertEpsilonEquals(10.77033, property.get()); }
@Test public void lengthSquaredProperty() { Vector2dfx vector = new Vector2dfx(1, 2); assertEpsilonEquals(5, vector.getLengthSquared()); ReadOnlyDoubleProperty property = vector.lengthSquaredProperty(); assertNotNull(property); assertEpsilonEquals(5, property.get()); vector.set(4, -10); assertEpsilonEquals(116, property.get()); }
@Test @Ignore public void lengthProperty() { Vector3dfx vector = new Vector3dfx(1, 2, 3); assertEpsilonEquals(2.23607, vector.getLength()); ReadOnlyDoubleProperty property = vector.lengthProperty(); assertNotNull(property); assertEpsilonEquals(2.23607, property.get()); vector.set(4, -10, 7); assertEpsilonEquals(12.84523, property.get()); }