public String calculateEllipsis(Font font, final String text, double maxWidth){ double ellipsisWidth = sizing.calculate(ELLIPSIS, font).getWidth(); int guessNbChars = Math.min(sizing.guessNumberOfCharacters(maxWidth - ellipsisWidth, font), text.length()); String substr; double currentCalculatedWidth = sizing.calculate(substr, font).getWidth(); reducedNbCharacters = true; substr = text.substring(0, guessNbChars)+ELLIPSIS; currentCalculatedWidth = sizing.calculate(substr, font).getWidth(); substr = text.substring(0, guessNbChars) + ELLIPSIS; currentCalculatedWidth = sizing.calculate(substr, font).getWidth();
private Dimension2D calculateButtonDimensions( final OpenPatricianButton button) { Dimension2D dim = new TextSizingUtility().calculate(button.getText(), button.getFont()); return new Dimension2D(dim.getWidth()*1.2, dim.getHeight()*1.2); }
/** * 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); } /**
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(); }
private void calculateNewDimension(Font font) { final ObservableList<OpenPatricianSpinnerOptionDataModel> options = spinner.getOptions(); Dimension2D dim4heigth = sizing.calculate(1, font); double maxWidth = spinner.getMaxWidth(); // This must be initialized before appended to the scene double destinationHeigth = dim4heigth.getHeight(); Dimension2D dim4width = sizing.calculate(word, font); if (dim4width.getWidth() > dim.getWidth()) { double percentage = dim.getWidth() / dim4width.getWidth();
private void calculateNewDimenstions(OpenPatricianRadioButton radioButton, String text, Image rbBG) { InputStream is; final int remainWidth = 28; // width that is left from the background final int destHight = 27; final double xStart = rbBG.getWidth(); final int yStart = 0; Dimension2D dim = sizing.calculate(text, radioButton.getFont()); double width = dim.getWidth(); double destWidth = width-remainWidth + 10; String fileName = imageFactory.getFileNameExt(destWidth,destHight,remainWidth); is = getClass().getResourceAsStream(fileName); Image slab = new Image(is, destWidth, destHight, false, true); slabView.setImage(slab); slabView.translateXProperty().set(xStart); slabView.translateYProperty().set(yStart); double posX = destWidth/2+(xStart-remainWidth-10); label.translateXProperty().set(posX); }
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()); } }
public DisplayMessageOverlayLabelSkin(DisplayMessageOverlayLabel control, TextSizingUtility sizing) { super(control); textLength.set(sizing.calculate(control.getText(), control.getFont()).getWidth()); control.fontProperty().addListener((observable, oldFont, newFont) -> textLength.set(sizing.calculate(control.getText(), newFont).getWidth())); control.textProperty().addListener((observable, oldText, newText) -> textLength.set(sizing.calculate(newText, control.getFont()).getWidth())); InputStream is = getClass().getResourceAsStream("waxButton-middle.png"); waxBtnMiddle = new Image(is);
public OpenPatricianWoodenTextInputSkin(OpenPatricianWoodenTextInput input) { super(input); textField = new TextField(input.getText()); imgView = new ImageView(); calculateDimensions(input); textField.textProperty().bindBidirectional(input.textProperty()); textField.getStyleClass().add("openPatricianWoodenTextInput"); Insets padding = textField.getPadding(); Insets newPadding = new Insets(0, padding.getRight(), 0, padding.getLeft()); textField.setPadding(newPadding); // Listeners input.sizeProperty().addListener((observable, oldValue, newValue) -> calculateDimensions(input)); textField.heightProperty().addListener((observable, oldValue, newValue) -> { Dimension2D dim = sizing.calculate(input.getSize(), input.getFont()); height.set(Math.max(dim.getHeight(), newValue.doubleValue())); setImage(); }); StackPane stack = new StackPane(); stack.getChildren().addAll(imgView, textField); Group group = new Group(stack); group.setManaged(false); getChildren().add(group); }
background.setWidth(newValue.getWidth()); background.setHeight(newValue.getHeight()); Dimension2D titleDim = textSize.calculate(control.getTitle(), openPatrician24); title.setLayoutX((newValue.getWidth() - titleDim.getWidth())/2 + frame.getInsetBackground().getX()); titleBackground.setLayoutX((newValue.getWidth() - titleWidth)/2 + frame.getInsetBackground().getX() + 20); background.setLayoutX(newValue.getX()); background.setLayoutY(newValue.getX()); Dimension2D titleDim = textSize.calculate(control.getTitle(), openPatrician24); descBackground.setFitHeight(newValue.getHeight() - 1080 * localScale + 2); Dimension2D descDimension = textSize.calculate(control.getDescription(), openPatrician18); double wrappingWidth = Math.min(descDimension.getWidth(), newValue.getWidth()); desc.setWrappingWidth(wrappingWidth); }); title.textProperty().addListener((observable, oldValue, newValue) -> { Dimension2D titleDim = textSize.calculate(control.getTitle(), openPatrician24); title.setLayoutX((frame.getBackgroundDimension().getWidth() - titleDim.getWidth())/2 + frame.getInsetBackground().getX()); }); desc.textProperty().addListener((observable, oldValue, newValue) -> { Dimension2D descDimension = textSize.calculate(control.getDescription(), openPatrician18); double wrappingWidth = Math.min(descDimension.getWidth(), frame.getInnerDimension().getWidth()); desc.setWrappingWidth(wrappingWidth);