private void calculateNewDimensions() { Dimension2D dim = calculateButtonDimensions(button); // add padding ImageFactory imageFactory = new ImageFactory(); Image img = imageFactory.getSlabImage(dim); imageView.setImage(img); }
/** * Compute the filename based on the stretching factor * @param width of the button * @param height of the button * @return best matching stone slab image file name */ private String getFileName(int width, int height) { float f = width*1f/height; String minDistFileName="StoneSlabBorderless.png"; return getFileName(f, minDistFileName,slabMap); } /**
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); }
public OpenPatricianStoneButtonSkin(final OpenPatricianStoneButton button) { super(button); this.button = button; Dimension2D dim = calculateButtonDimensions(button); ImageFactory imageFactory = new ImageFactory(); Image img = imageFactory.getSlabImage(dim); imageView = new ImageView(img); button.fontProperty().addListener((observable, oldvalue, newValue) -> calculateNewDimensions()); final Label label = new Label(button.getText()); label.onMouseClickedProperty().bind(button.onActionProperty()); imageView.onMouseReleasedProperty().bind(button.onActionProperty()); button.textProperty().addListener((observable, oldValue, newValue) -> calculateNewDimensions()); StackPane stack = new StackPane(); stack.getChildren().addAll(imageView, label); Group group = new Group(stack); group.setManaged(false); getChildren().add(group); }
/** * Compute the filename based on the stretching factor * @param width of the button * @param height of the button * @return best matching stone slab extension file name. */ public String getFileNameExt(double width, double height, int capWidth) { float f = (float)((capWidth-width)/height); return getFileName(f, "StoneSlabExt.png",slabExtMap); }
/** * Draw a borderless stone slab * @param dim dimension of the image */ public Image getSlabImage(Dimension2D dim) { String fileName = getFileName((int)Math.rint(dim.getWidth()),(int)Math.rint(dim.getHeight())); InputStream is = getClass().getResourceAsStream(fileName); return new Image(is, dim.getWidth(), dim.getHeight(), false, true); }