From 5214f0ab3cd7a1aa0fb6127af5036bc168df6014 Mon Sep 17 00:00:00 2001 From: Oliver-Loeffler Date: Sat, 22 Oct 2022 15:30:42 +0200 Subject: [PATCH 1/3] fix: Enables Scene Builder to provide Insets editor for custom controls which expose Insets properties. --- .../scenebuilder/kit/metadata/MetadataIntrospector.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/MetadataIntrospector.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/MetadataIntrospector.java index b80f608d9..78b2e21d2 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/MetadataIntrospector.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/MetadataIntrospector.java @@ -40,6 +40,7 @@ import com.oracle.javafx.scenebuilder.kit.metadata.property.value.DurationPropertyMetadata; import com.oracle.javafx.scenebuilder.kit.metadata.property.value.EventHandlerPropertyMetadata; import com.oracle.javafx.scenebuilder.kit.metadata.property.value.ImagePropertyMetadata; +import com.oracle.javafx.scenebuilder.kit.metadata.property.value.InsetsPropertyMetadata; import com.oracle.javafx.scenebuilder.kit.metadata.property.value.list.StringListPropertyMetadata; import com.oracle.javafx.scenebuilder.kit.metadata.property.value.paint.ColorPropertyMetadata; import com.oracle.javafx.scenebuilder.kit.metadata.property.value.DoublePropertyMetadata; @@ -73,6 +74,7 @@ import java.util.logging.Logger; import javafx.fxml.FXMLLoader; +import javafx.geometry.Insets; import javafx.scene.paint.Color; import javafx.scene.paint.Paint; import javafx.scene.text.Font; @@ -253,6 +255,9 @@ private PropertyMetadata makePropertyMetadata(PropertyName name, readWrite, null, inspectorPath); + } else if (propertyType == javafx.geometry.Insets.class) { + Insets defaultValues = (Insets)getDefaultValue(sample, propertyDescriptor.getReadMethod(), Insets.EMPTY); + result = new InsetsPropertyMetadata(name, readWrite, defaultValues, inspectorPath); } else if (propertyType == javafx.util.Duration.class) { Duration defaultValue = (Duration)getDefaultValue(sample, propertyDescriptor.getReadMethod(), null); result = new DurationPropertyMetadata( From 2d3d3093b6f944469f4ae4d1d2dc7cd5b13f120c Mon Sep 17 00:00:00 2001 From: Oliver-Loeffler Date: Wed, 29 Mar 2023 21:10:03 +0200 Subject: [PATCH 2/3] Applied checkstyle format corrections. Added custom control for Insets editing capability demonstration to test sources. --- .../kit/metadata/MetadataIntrospector.java | 26 +-- .../app/view/CustomNodeWithInsets.java | 149 ++++++++++++++++++ 2 files changed, 162 insertions(+), 13 deletions(-) create mode 100644 kit/src/test/java/com/example/app/view/CustomNodeWithInsets.java diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/MetadataIntrospector.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/MetadataIntrospector.java index 78b2e21d2..2317cd547 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/MetadataIntrospector.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/MetadataIntrospector.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2022, Gluon and/or its affiliates. + * Copyright (c) 2016, 2023, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -117,7 +117,7 @@ public ComponentClassMetadata introspect() { } } exception = null; - } catch(IOException | IntrospectionException x) { + } catch (IOException | IntrospectionException x) { exception = x; } @@ -162,7 +162,7 @@ private Object instantiate() throws IOException { try { fxmlLoader.setClassLoader(componentClass.getClassLoader()); result = fxmlLoader.load(new ByteArrayInputStream(fxmlBytes)); - } catch(RuntimeException x) { + } catch (RuntimeException x) { throw new IOException(x); } @@ -204,38 +204,38 @@ private PropertyMetadata makePropertyMetadata(PropertyName name, name, propertyType, readWrite, - (Enum)getDefaultValue(sample, propertyDescriptor.getReadMethod(), fallback), + (Enum) getDefaultValue(sample, propertyDescriptor.getReadMethod(), fallback), inspectorPath); } else if (propertyType == Boolean.class) { result = new BooleanPropertyMetadata( name, readWrite, - (Boolean)getDefaultValue(sample, propertyDescriptor.getReadMethod(), false), + (Boolean) getDefaultValue(sample, propertyDescriptor.getReadMethod(), false), inspectorPath); } else if (propertyType == Integer.class) { result = new IntegerPropertyMetadata( name, readWrite, - (Integer)getDefaultValue(sample, propertyDescriptor.getReadMethod(), 0), + (Integer) getDefaultValue(sample, propertyDescriptor.getReadMethod(), 0), inspectorPath); } else if (propertyType == Double.class) { result = new DoublePropertyMetadata( name, DoubleKind.COORDINATE, readWrite, - (Double)getDefaultValue(sample, propertyDescriptor.getReadMethod(), 0.0), + (Double) getDefaultValue(sample, propertyDescriptor.getReadMethod(), 0.0), inspectorPath); } else if (propertyType == String.class) { result = new StringPropertyMetadata( name, readWrite, - (String)getDefaultValue(sample, propertyDescriptor.getReadMethod(), null), + (String) getDefaultValue(sample, propertyDescriptor.getReadMethod(), null), inspectorPath); } else if (propertyType == javafx.scene.paint.Color.class) { result = new ColorPropertyMetadata( name, readWrite, - (Color)getDefaultValue(sample, propertyDescriptor.getReadMethod(), null), + (Color) getDefaultValue(sample, propertyDescriptor.getReadMethod(), null), inspectorPath); } else if (propertyType == javafx.scene.paint.Paint.class) { result = new PaintPropertyMetadata( @@ -256,14 +256,14 @@ private PropertyMetadata makePropertyMetadata(PropertyName name, null, inspectorPath); } else if (propertyType == javafx.geometry.Insets.class) { - Insets defaultValues = (Insets)getDefaultValue(sample, propertyDescriptor.getReadMethod(), Insets.EMPTY); + Insets defaultValues = (Insets) getDefaultValue(sample, propertyDescriptor.getReadMethod(), Insets.EMPTY); result = new InsetsPropertyMetadata(name, readWrite, defaultValues, inspectorPath); } else if (propertyType == javafx.util.Duration.class) { - Duration defaultValue = (Duration)getDefaultValue(sample, propertyDescriptor.getReadMethod(), null); + Duration defaultValue = (Duration) getDefaultValue(sample, propertyDescriptor.getReadMethod(), null); result = new DurationPropertyMetadata( name, readWrite, - defaultValue == null? null : new SBDuration(defaultValue), + defaultValue == null ? null : new SBDuration(defaultValue), inspectorPath); } else if (propertyType == javafx.event.EventHandler.class) { @@ -335,7 +335,7 @@ private Object getDefaultValue(Object sample, Method readMethod, Object fallback try { result = readMethod.invoke(sample); - } catch(InvocationTargetException|IllegalAccessException x) { + } catch (InvocationTargetException | IllegalAccessException x) { result = fallback; } diff --git a/kit/src/test/java/com/example/app/view/CustomNodeWithInsets.java b/kit/src/test/java/com/example/app/view/CustomNodeWithInsets.java new file mode 100644 index 000000000..566609553 --- /dev/null +++ b/kit/src/test/java/com/example/app/view/CustomNodeWithInsets.java @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2023, Gluon and/or its affiliates. + * All rights reserved. Use is subject to license terms. + * + * This file is available and licensed under the following license: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the distribution. + * - Neither the name of Oracle Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.example.app.view; + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.geometry.Insets; +import javafx.scene.control.Label; +import javafx.scene.layout.Background; +import javafx.scene.layout.BackgroundFill; +import javafx.scene.layout.Border; +import javafx.scene.layout.BorderStroke; +import javafx.scene.layout.BorderStrokeStyle; +import javafx.scene.layout.BorderWidths; +import javafx.scene.layout.CornerRadii; +import javafx.scene.layout.StackPane; +import javafx.scene.paint.Color; +import javafx.scene.text.Font; +import javafx.scene.text.FontWeight; + +public class CustomNodeWithInsets extends StackPane { + + private final StackPane innerPane; + + private final StackPane centerPane; + + /** + * A control with various nested insets to demonstrate the insets editing capability for custom controls. + */ + public CustomNodeWithInsets() { + setBackground(new Background(new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY))); + setBorder(new Border(new BorderStroke(Color.WHITE, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(2)))); + innerPane = new StackPane(); + innerPane.setBackground(new Background(new BackgroundFill(Color.ORANGE, new CornerRadii(10), Insets.EMPTY))); + innerPane.setBorder(new Border(new BorderStroke(Color.WHITE, BorderStrokeStyle.SOLID, new CornerRadii(10), new BorderWidths(2)))); + innerPane.setMinSize(100, 100); + innerPane.setMaxSize(590, 590); + innerPane.setPrefSize(590, 380); + innerPane.paddingProperty().bind(innerFrameProperty()); + + centerPane = new StackPane(); + centerPane.setBackground(new Background(new BackgroundFill(Color.BLUEVIOLET, new CornerRadii(10), Insets.EMPTY))); + centerPane.setBorder(new Border(new BorderStroke(Color.WHITE, BorderStrokeStyle.SOLID, new CornerRadii(10), new BorderWidths(2)))); + centerPane.setMinSize(100, 100); + centerPane.setMaxSize(580, 570); + centerPane.setPrefSize(580, 360); + + Label label = new Label("Custom Control Insets Demo"); + label.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, new CornerRadii(8), new BorderWidths(4)))); + label.paddingProperty().bind(textPaddingProperty()); + label.setBackground(new Background(new BackgroundFill(Color.WHITE, new CornerRadii(10), Insets.EMPTY))); + label.setFont(Font.font(label.getFont().getFamily(), FontWeight.BLACK, 14)); + centerPane.getChildren().add(label); + innerPane.getChildren().add(centerPane); + + getChildren().add(innerPane); + setMinSize(100, 100); + setMaxSize(600, 600); + setPrefSize(598, 396); + setWidth(600); + setHeight(400); + + paddingProperty().bind(outerFrameProperty()); + } + + private ObjectProperty outerFrame; + + public void setOuterFrame(Insets value) { + this.outerFrameProperty().setValue(value); + } + + public Insets getOuterFrame() { + return this.outerFrame == null ? new Insets(90, 40, 30, 160) : outerFrameProperty().getValue(); + } + + public ObjectProperty outerFrameProperty() { + if (this.outerFrame != null) { + return this.outerFrame; + } + this.outerFrame = new SimpleObjectProperty<>(new Insets(90, 40, 30, 160)); + return this.outerFrame; + }; + + private ObjectProperty innerFrame; + + public void setInnerFrame(Insets value) { + this.innerFrameProperty().setValue(value); + } + + public Insets getInnerFrame() { + return this.innerFrame == null ? new Insets(20) : innerFrameProperty().getValue(); + } + + public ObjectProperty innerFrameProperty() { + if (this.innerFrame != null) { + return this.innerFrame; + } + + this.innerFrame = new SimpleObjectProperty<>(new Insets(20)); + return this.innerFrame; + }; + + private ObjectProperty textPadding; + + public void setTextPadding(Insets value) { + this.textPaddingProperty().setValue(value); + } + + public Insets getTextPadding() { + return this.textPadding == null ? new Insets(15, 40, 15, 40) : textPaddingProperty().getValue(); + } + + public ObjectProperty textPaddingProperty() { + if (this.textPadding != null) { + return this.textPadding; + } + this.textPadding = new SimpleObjectProperty<>(new Insets(15, 40, 15, 40)); + return this.textPadding; + }; +} \ No newline at end of file From 48b222f3be602954c073250d5f4a842a1024b978 Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Wed, 13 Mar 2024 11:01:03 +0530 Subject: [PATCH 3/3] update license year --- .../javafx/scenebuilder/kit/metadata/MetadataIntrospector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/MetadataIntrospector.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/MetadataIntrospector.java index 2317cd547..5a6222279 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/MetadataIntrospector.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/MetadataIntrospector.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2023, Gluon and/or its affiliates. + * Copyright (c) 2016, 2024, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. *