Sonntag, 14. September 2014

JavaFX-3D-Editor - Update 11.1

This week I didn't commit new features, beacuse there where several bugs in the last update.

The bugfixes:

  •  API-comments to implement new painting tools
  • nested CGOs can be saved

JAR and sources: https://github.com/gundermann/JFX3D


Sonntag, 7. September 2014

JavaFx-3D-Editor - Update 11

It's been two weeks ago since you heard something of the Fx3De from myself.


The reason is that I tried to make the code of the program a bit more comfortable in order to make it easyer to implement new painting tools.
During this I change the notation of the .dxml-files. 

If you had already saved some 3d-models - sorry.
Joke! - If you have a .dxml-file you could use them with this update too.
The only thing you have to do for it, is to convert the files. 
Therefore you can use the converter-program I commited here: 
https://drive.google.com/file/d/0B1zC0qGiWz40ZDU2UUFMNXp4Mlk/edit?usp=sharing

Just choose your existing old .dxml-file and save it in the second step.
The editor will load the model with no difference.

Unfourtunally with this update you won't get any new tool.
But in this post you can read how to build your own painting tools:


If you want to try it - feel free to do it. But please sent me the code so that I can check this and give you the right to commit it ;-)

Have fun with the new update.

Source: https://github.com/gundermann/JFX3D

How to create new painting tools on Fx3De

Here I want to explain to you how to implement new painting tools for the Fx3De.

There are almost  steps to get a additional painting tool. I will show an example. (Ellipse)

1. This is the main steps. Here you have to define your tool. So first of all you need a class which extends from AbstractPaintableObject3D. 


 public class Ellipse3D extends AbstractPaintableObject3D

After this add all umimpleneted methods.

@Override

 public void changeHeightTo(double d) {
  // TODO Auto-generated method stub

  }

  @Override
 public void changeWidthTo(double d) {
  // TODO Auto-generated method stub

  }

  @Override
 public void paint(double x, double y, double initinalX, double initinalY) {
  // TODO Auto-generated method stub

  }

  @Override
 public DoubleProperty getHeightProperty() {
  // TODO Auto-generated method stub
  return null;
 }

  @Override
 public DoubleProperty getWidthProperty() {
  // TODO Auto-generated method stub
  return null;
 }

  @Override
 public Object3DFactory getFactory() {
  // TODO Auto-generated method stub
  return null;
 }

  @Override
 protected Class getShapeClass() {
  // TODO Auto-generated method stub
  return null;
 }

Done this you have to define the behavior by filling the mehtods in this class. The description of the methods will help you to da this.

If you implement the methods you can define additional properties of your new painting tool.
You do this by annotations. Notice that every property needs a Property-Annotation and a PropertyChange-Annotation. Consequently you need two methods. If you are not familliar with the Property-Framework please read this post:
http://javafxstuff.blogspot.de/2014/08/properiesonchange.html

Here is the example:

@Override

 public void changeHeightTo(double d) {
  // TODO Auto-generated method stub

  }

  @Override
 public void changeWidthTo(double d) {
  // TODO Auto-generated method stub

  }

  @Override
 public void paint(double x, double y, double initinalX, double initinalY) {
  // TODO Auto-generated method stub

  }

  @Override
 public DoubleProperty getHeightProperty() {
  // TODO Auto-generated method stub
  return null;
 }

  @Override
 public DoubleProperty getWidthProperty() {
  // TODO Auto-generated method stub
  return null;
 }

  @Override
 public Object3DFactory getFactory() {
  // TODO Auto-generated method stub
  return null;
 }

  @Override
 protected Class getShapeClass() {
  // TODO Auto-generated method stub
  return null;
 }


2. Implement a Factory. The Factory needs to entends the Object3DFactory. Just implement the unimplemented methods and the getInstance method:

public class Ellipse3DFactory extends Object3DFactory {

  private static Object3DFactory _instance;

  @Override
 public Object3D createPlainObject3D() {
  return new Ellipse3D();
 }

  public static Object3DFactory getInstance() {
  if(_instance == null)
   _instance = new Ellipse3DFactory();
  return _instance;
 }

  @Override
 public String getType() {
  return "Ellipse";
 }

}




3. Set up a Painting-Value for the new painting tool in the Painting-Enum:

Rectangle, Ellipse, None;


4. Connect the Painting-Value from the Painting-Enum with the Factory. You do this in the FactoryPaintingAssoziator. Just extends the map in the method getFactoryFromPaintingMode:

public Map getFactoryFormPaintingMode() {
  Map paintingStartListener = new HashMap();
  paintingStartListener.put(Painting.Rectangle,
    Rectangle3DFactory.getInstance());
  paintingStartListener.put(Painting.Ellipse,
    Ellipse3DFactory.getInstance());
  return paintingStartListener;
 }


6. To persist the new painting tool you also have to connect the factory with a preference-type. You do this by extendsing the map in the method getFactoryFromPreference of the FactoryPreferenceTypeAssoziator:


public Object3DFactory getFactoryFormPreference(String type) {
  Map paintingStartListener = new HashMap();
  paintingStartListener
    .put("Rectangle", Rectangle3DFactory.getInstance());
  paintingStartListener.put("Ellipse", Ellipse3DFactory.getInstance());
  paintingStartListener.put("complex",
    ComplexObject3DFactory.getInstance());
  return paintingStartListener.get(type);
 }


Notice that the String refered to the Factory has to be equal to the value returned by the method getType in the factory-class.

7. UI changes.
To choose your new painting tool you have to change the UI. So open the paintingmenu.fxml with the SceneBuilder and add a new button. During that son't forgett to define an On-Action-Method for this button. Done this you have to implement the On-Action-Method in the PaintingMenuController:

@FXML
 public void selectPaintEllipse() {
  actualPaintingArea.initPainting(Painting.Ellipse);
 }


I hope it works :-D
If not please sent me an email: gundermann.niels.ng@googlemail.com