You'll need to follow these steps to create your first OpenTool:
initOpenTool()
method. c:/HelloOpenTool/HelloOpenTool.jpr
is the location of the project file. Click the Finish button to create the project.
You can actually define any number of OpenTools in a single project.
This library contains all of the classes that comprise the OpenTools API, so any meaningful OpenTool will need to use at least some of these definitions to extend the IDE.
A single OpenTool can make as many, or as few, changes to the IDE as desired. Whether you create a single OpenTool class or many is up to you, but these tutorials will focus on adding selected functionality with individual OpenTools.
import com.borland.primetime.*; import com.borland.jbuilder.*; import com.borland.primetime.ide.*; import javax.swing.*; import java.awt.event.*;
The Swing and AWT classes are self-explanatory, but the other packages are probably unfamiliar. All packages under com.borland.primetime
define a general-purpose framework for writing an IDE in Java, regardless of the target language. Packages under com.borland.jbuilder are specific to JBuilder, our IDE for Java development. These two hierarchies contain many subpackages that will be introduced in later tutorials.
The name PrimeTime was our original code name for the pure Java IDE project, and it lives on as a package name in the OpenTools SDK.
HelloOpenTool
class:
public static void initOpenTool(byte major, byte minor) { // Check OpenTools version number if (major != PrimeTime.CURRENT_MAJOR_VERSION) return; // Add a new menu item to the Help menu JBuilderMenu.GROUP_Help.add(new BrowserAction( "Say Hello") { public void actionPerformed(Browser browser) { JOptionPane.showConfirmDialog(null, "Hello, World!"); } }); }
The first statement ensures that your OpenTool is being used with a compatible version of the OpenTools API before performing any initialization. The second statement adds a new menu item to the JBuilder help menu.
If you aren't familiar with inner classes in general, and anonymous classes in specific, this code may look unusual to you. The code creates an instance of a subclass of AbstractAction
and overrides an abstract method to define the behavior of the new action. This newly created action is then added to JBuilder's help menu group.
A later tutorial will showcase JBuilder's menus and toolbars in more depth, but a quick look at the JBuilderMenu and JBuilderToolBar classes in the com.borland.jbuilder
package will give you a starting point for experimentation.
c:/HelloOpenTool/classes.opentools
for your newly created file. (Note that if you created your project elsewhere you will want to adjust for the path you chose. Also note that the name "classes.opentools" assumes that your project's outpath is named "classes" and must be adjusted if you use a different outpath name.) Press OK on the resulting dialog to indicate that you want to create a new file.
Note: You've just taken advantage of a feature that allows you to create any file, including projects or Java source code, without using the Wizards in JBuilder. This can be extremely useful once you get used to it.
Double-click the newly created file in the project pane and add the following line to it:
OpenTools-UI: example.HelloOpenTool
Manfiest files must include a newline character at the end of every line, so be sure to press enter when you are done! This file will serve as the manifest file for a JAR created in the next step. You can place as many fully-qualified OpenTools classes on a single line as you like, using spaces to separate the class names.
Exit JBuilder and edit the launch script in JBuilder's bin
directory. This will be the JBuilder.config
file on Windows, or a shell script on Linux or Solaris. Change the CLASSPATH definition to add c:/HelloOpenTool/classes
. (Note that if you created your project elsewhere you will want to adjust for the path you chose.)
Now launch JBuilder again, and look for the Help|Say Hello menu item. If it doesn't appear, check to make sure you've followed these steps carefully. Your OpenTools classes must be in the directory added to the classpath, and the manifest file created in step 7 must be in a file whose name is the same as the directory on the classpath with an additional ".opentools" suffix.
Once you've verified that everything works as expected, remove your changes to JBuilder's CLASSPATH definition.
Open a shell window or DOS prompt, make sure the JDK's bin
directory is in your path, and make c:/HelloOpenTool
your current directory. (Note that if you created your project elsewhere you will want to adjust for the path you chose.) Now type the following command and press enter:
jar -cfm HelloOpenTool.jar classes.opentools -C classes example
Voila. You've created an OpenTools JAR that contains everything needed to extend JBuilder with the thrilling "Say Hello" menu item. Now to install it the professional way...
HelloOpenTool.jar
file you created in the last step into JBuilder's lib/ext
directory, and you're done! The next time you start JBuilder it will automatically discover your OpenTool when it starts.