Wednesday June 06, 2007
Snippet Creation for Java Source Files
With this module, you open a Java source file, select some code with the mouse, and drag it over an existing category or item in the palette. Somewhere along the way, you need to hold down the Ctrl key, because you need to do a copy action, not a cut or move action. If all the above conditions are met, you get the following dialog box, which in this case I have filled out with a display name and tooltip:

You can either choose new icons or accept the default. But what if you want to change the default? There are some new buttons in the Palette Manager for Java source files (which is also installed by the module), which lets you choose a different default:

The icon pressed above will be shown in the Create New Palette Item dialog box (i.e., in that dialog box's Preview panel), as the default to be used for when no icons are selected by the user. If no display name or tooltip is entered, a default one is generated. Then the dragged code is available via a node in the palette, which can then be dragged back into the editor:

It completely works, but has a few issues and areas that can be enhanced, listed below.
Current limitations in random order:
- Palette should open when a Java source file opens, need to create a window group for this, probably. Currently, the palette needs to be opened separately (either from the menu item in the Tools menu or using Ctrl-Shift-8).
- Items are always added to the "Items" category, even when you drop the item in a different category. But, as a workaround, you can manually move the item after dropping it in the palette.
When you change a default icon, which can only be done in the Palette Manager, you get no visual feedback. So, you can't see, currently, which of the icons is selected (until you access the Create New Palette Item dialog box again).- You cannot rename a palette item after you drop it in the palette.
- Would be nice to have a drag image, but that doesn't seem to be possible in this scenario.
- The code in the JEditorPane isn't formatted (i.e., correctly indented) and neither is the code formatted when you drop it back from the palette.
- Would be nice to have the right-click contextual menu items from the Java editor in the JEditorPane, but don't know how to do that.
- Must do the drop either on a category or on another existing palette item. Cannot do the drop on the rest of the palette, which would be preferable.
Preview panel shows big icon, for both small icon and big icon.Currently, the code for the snippet is taken from the editor, not from the JEditorPane, so the illusion is created that the selection can be modified prior to being added to the palette. Need to fix this.No check is done to make sure that the selected icons are of the correct dimensions. So, if the small icon that you select is extremely large, there's nothing protecting you from making that mistake.- No way of getting from the Create New Palette Item dialog box to the Palette Manager, so if you don't like the default icon, you must close the dialog box, open the Palette Manager, change the icon, and then go back to the Create New Palette Item dialog box. This must be smoothed out somehow.
- Very occasionally weird errors are thrown, such as "multiple instances of shared class".
- Probably only works in the very latest 6.0 development builds. Definitely doesn't work in M9.
Jun 06 2007, 09:30:19 AM PDT Permalink


