Class JDSwingObject

All Implemented Interfaces:
MouseListener, EventListener

public class JDSwingObject extends JDRectangular implements MouseListener
JDraw Swing graphic object. JDSwingObject allows a JComponent to be edited (and played) within JDraw as if it is a JDObject. The JComponent must implements the JDrawable interface. Implementing JDrawable for a Component is interresting if you want to make your component available in the JDrawEditor. Adding a component for playing only can be done by using the classic add(Component) method, no need here to be JDrawable ,however the add() method shoud be called after initPlayer() or loadFile() is called. Here is an example of a simple JDrawable JButton:
 public class MyJDButton extends JButton implements JDrawable {

  static String[] extensions = {"text"};

  public void initForEditing() {
    setText("Button");
    setBorder(JDSwingObject.etchedBevelBorder);
  }

  public JComponent getComponent() {
    return this;
  }

  public String[] getExtensionList() {
    return extensions;
  }

  public boolean setExtendedParam(String name,String value,boolean popupAllowed) {
    if(name.equalsIgnoreCase("text")) {
      setText(value);
      return true;
    }
    return false;
  }

  public String getExtendedParam(String name) {
    if(name.equalsIgnoreCase("text")) {
      return getText();
    }
    return "";
  }

  public String getDescription(String extName) {
    if(extName.equalsIgnoreCase("text")) {
      return "JButton label";
    }
    return "";
  }

}
 
See Also: