X

Geertjan's Blog

  • March 8, 2006

NetBeans API Quiz

Geertjan Wielenga
Product Manager
This quiz consists of one question and the prize is that you will be "the world's greatest NetBeans plug-in module developer" for one whole day. The question is: Why is the "Edit Music String" menu item in the NetBeans editor's popup menu (left side below) activated, while if I call up the pop-up menu in the JEditorPane (on the right side below), the same menu item is greyed out? (And your answer can't be: "Because you need to add something or other to your TopComponent's Lookup." In other words, you also have to say what, where, and how. And you have to include code...)

By the way, if you're wondering whether this "quiz" is just me asking "How the #@$#@$% do I get that menu item in the JEditorPane activated?", the answer is: "Maybe."

In other news, I just got interviewed by the Sun Developer Network Channel. It was quite fun. (It took three takes before the producer was happy.) It was all about how cool plug-in module development is in 5.0. But I'm pretty sure that I'm not going to be watching the result (which is planned to be available from the 18th). Not often that you get to see and hear yourself like that. Pretty sure I'm too chicken to find out what I look and sound like in real life (I'll just keep imagining instead, probably much better).

Join the discussion

Comments ( 5 )
  • Sandip Wednesday, March 8, 2006
    See the section:

    Using InstanceProvider for declaration of compound folder objects and inheritance

    of http://www.netbeans.org/download/dev/javadoc/org-netbeans-modules-editor-mimelookup/overview-summary.html

    I guess you added the "Edit Music String" action through "Editors/text/>music file mime type>/Popup" folder of the module's layer file for the mime type of music files. No?

  • Geertjan Thursday, March 9, 2006
    Yes, that's what I did. I also spent some time looking at the section you pointed to, but it doesn't seem to help:

    1. I created META-INF/services and put a file there with this name:

    org.netbeans.spi.editor.mimelookup.Class2LayerFolder

    2. Inside that file is this content:

    org.netbeans.modules.jfuguetest.PopupInitializer

    3. I created that file. It has this content:

    public class PopupInitializer implements Class2LayerFolder{
    public PopupInitializer() {
    }
    public Class getClazz(){
    return PopupActions.class;
    }
    public String getLayerFolderName(){
    return "Popup"; //NOI18N
    }
    public InstanceProvider getInstanceProvider() {
    return new PopupActions();
    }
    }

    4. Then I created this file:

    public class PopupActions implements InstanceProvider{
    List ordered;
    public PopupActions(){
    }
    public PopupActions(List ordered){
    this.ordered = ordered;
    }
    public List getPopupActions(){
    List retList = new ArrayList();
    for (int i = 0; i<ordered.size(); i++){
    DataObject dob = (DataObject) ordered.get(i);
    InstanceCookie ic = (InstanceCookie)dob.getCookie(InstanceCookie.class);
    if (ic!=null){
    try{
    if (String.class.isAssignableFrom(ic.instanceClass()) ||
    Action.class.isAssignableFrom(ic.instanceClass()) ||
    SystemAction.class.isAssignableFrom(ic.instanceClass()) ||
    JSeparator.class.isAssignableFrom(ic.instanceClass())){
    Object instance = ic.instanceCreate();
    retList.add(instance);
    }
    }catch(IOException ioe){
    ioe.printStackTrace();
    }catch(ClassNotFoundException cnfe){
    cnfe.printStackTrace();
    }
    } else{
    retList.add(dob.getName());
    }
    }
    return retList;
    }
    public Object createInstance(List ordered) {
    return new PopupActions(ordered);
    }
    }

    5. Finally, I added this to the constructor of MidiEditorKit (which extends NbEditorKit):

       MimeLookup lookup = MimeLookup.getMimeLookup("audio/midi");
    PopupActions actions = (PopupActions) lookup.lookup(PopupActions.class);
    List popupActions = actions.getPopupActions();

    Maybe I was wrong to put that code in the editorkit's constructor, I tried a few other places too. Still, the menu item is greyed out.

    have you tried the above steps yourself? Successfully? Hope you can give me further advice. I'm assuming that all of this is necessary for the JEditorPane because the NetBeans editor handles this automatically, while the JEditorPane needs these steps manually. Am I right?

  • Geertjan Thursday, March 9, 2006

    Just added a closing bold tag...

  • Geertjan Thursday, March 9, 2006
    tried it again
  • Geertjan Thursday, March 9, 2006
    and again
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.