Custom Control property editor

This is probably more a general Java question than a JME one but here I go anyways. I’m trying to add a custom property to my control that will give you a list of strings to choose from in the property editor. I’m not sure how to do this. If someone could point me in the right direction I would appreciate it.

Just have proper getters and setters, you can actually create them for fields, just right-click it and select “create getter/setter”. Make a new Control using right-click on a package (e.g. mygame in the BasicGame project) → New → Other → JME3 Classes → New Control. It says what to do right in the comments in that file.

@normen I have my get/set methods. I actually used ctrl+space shortcut. My issue is I’m looking for a drop down box with multiple options. For example if I have a objectPickUp property and it has multiple possible options such as “addInventory” “destroy” “move” etc. I want those options to appear in a list of string via a drop down box.

To be frank I’m not familiar with the net beans property editor so I’m lost. I was able to get basic variables into the editor for things such as int , String etc. but those can only accept one value.

Did you try an Enumeration already? Since that would be the Java equivalent to a drop down box.
Other than that, did you already try to google?
It could be that you need some additional implementations (maybe using Annotations) for it to work?

Yeah, to have it automatically appear you’ll have to use enums. Otherwise you’ll have to create your own SDK property wrapper plugin for your Control: http://wiki.jmonkeyengine.org/doku.php/sdk:development:sceneexplorer

The enum’s are making the property editor crash.

No they’re not - as you can see in the Spatial dropdowns for e.g. CullHint.

private Testing test6;

    public Testing getTest6() {
        return test6;
    }

    public void setTest6(Testing test6) {
        this.test6 = test6;
    }

 enum Testing {
    TESTONE,
    TESTTWO
  }

I tried several different iterations of enum and they all caused the IDE to either crash or go super slow.

I think this is about it for tonight. I’m taking a break from making gamse and I’m going to go take out my frustration by delivering virtual ass whoopings in league of legends :smile:

make the enum public, its package-private in your example. And “crash” is saying nothing without a stack trace.

I tried making it public already and I can’t get the crash report because it locks up the whole IDE to the point where I have to restart it.

Show us code that would actually compile.

You forgot the read and write methods.

@Override
public void write(JmeExporter ex) throws IOException {
OutputCapsule out = ex.getCapsule(this);
out.write(getTest6(), “Test6”, null);
}

@Override
public void read(JmeImporter im) throws IOException {
InputCapsule ic = im.getCapsule(this);
setTest6(ic.readEnum(“Test6”, Testing.class, null));
}

The property editor relies on the JME serialization to get and set your values not your getters and setters. If you don’t define the read and write code you will not be able to save and load your values either through the scene composer.

Hope this helps.

1 Like

@zissis You seem to be familiar with the property editor. I have my control showing with all of the options but when I set a variable via the control it doesn’t accept the change in the class. I’ve been trying to set a variable called distance via the property editor but it doesn’t take it. Here is my code so far.

 package JWB.controls;

import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.export.Savable;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.control.Control;
import java.io.IOException;


public class PhysicsControl extends AbstractControl implements Savable, Cloneable {

    private boolean collidable = true;
    private float distance = 50;

    public float getDistance() {
        return distance;
    }

    public void setDistance(float distance) {
        this.distance = distance;
    }
    
    public boolean isCollidable() {
        return collidable;
    }

    public void setCollidable(boolean collidable) {
        this.collidable = collidable;
    }
    
  public PhysicsControl(){} // empty serialization constructor
 
  @Override
  public void setSpatial(Spatial spatial) {
    super.setSpatial(spatial);
    /* Example:
    if (spatial != null){
        // initialize
    }else{
        // cleanup
    }
    */
  }
 
  @Override
  protected void controlUpdate(float tpf){
    if(spatial != null) {
      
    }
  }
 
  @Override
  public Control cloneForSpatial(Spatial spatial){
    final PhysicsControl control = new PhysicsControl();
    control.setSpatial(spatial);
    return control;
  }
 
  @Override
  protected void controlRender(RenderManager rm, ViewPort vp){
  
  }
 
 @Override
public void write(JmeExporter ex) throws IOException {
OutputCapsule out = ex.getCapsule(this);
out.write(distance, "distance", distance);
out.write(isCollidable(), "collidable", collidable);
}

@Override
public void read(JmeImporter im) throws IOException {
InputCapsule ic = im.getCapsule(this);
setDistance(ic.readFloat("distance", distance));
setCollidable(ic.readBoolean("collidable", collidable));
}

 
}

There is a bug in the property editor when it comes to custom properties like this one. You have two options.

Option #1) Make sure you hit the TAB key after setting your distance so that the focus listener actually fires and the value gets saved.

Option #2) Instead of editing your values in the property editor on the top right of your screen, press the “…” button that is to the right of your property. This will give you a popup that you can use to save your values property all the time.

I personally always use option #2. I also tab out of each cell after editing the value just in case.