Dienstag, 19. August 2014

ProperiesOnChange

This little feature is an extraction of my JavaFX-3D-Editor you can see on the post: http://javafxstuff.blogspot.de/p/javafx-3d-editor.html

It is about Objects including properties. Properties may has to be changed during the execution of a program. JavaFX gives a nice implementation for properties. One benefit of them is binding. That means that you can bind two properties. Let's say we bind property A to B.
If I change the value of property B, the value of A will be updated by the JavaFX Framework. I use this feature very often.
This little implementation (I don't want to call it framework, because it too small) provides a UI to change properties of an object. This properties can be bind to an other property and will be updated as soon as you change the property in the UI.

You can find the implementation on: https://drive.google.com/file/d/0B1zC0qGiWz40U2hWc0oyQWlLNEk/edit?usp=sharing

Just include the jar-file into your build-path.

The following little example shows the using of the PropertiesOnChange.



  1. Include the jar-file into your build-path.
  2. Set up you Class including the properties
    public class TestPropertyObject {
    
     DoubleProperty testProperty = new SimpleDoubleProperty();
    
     @Property(hasChildren=false, name="test")
     public DoubleProperty getTestProperty() {
      return testProperty;
     }
    
     @PropertyChange(hasChildren = false, name = "test")
     public void setTestProperty(double value) {
      this.testProperty.set(value);
      System.out.println(getTestProperty().get());
     }
    }
    
  3. Include the UI into a stage and set up the property-object to the UI.
    public class Lauch extends Application {
    
     @Override
     public void start(Stage stage) throws Exception {
      GUIManipulatingMenu guiManipulatingMenu = new GUIManipulatingMenu();
      guiManipulatingMenu.setPropertyObject(new TestPropertyObject());
      
      Scene s = new Scene(guiManipulatingMenu);
      stage.setScene(s);
      stage.show();
    
     }
     
     public static void main(String[] args) {
      launch(args);
     }
    
  4. Do some changes!


Give me some feedback, please ;-)