Step 7 - Add a menu for the plugin
In this step we will extend the existing CADEMIA menu bar by a Plugin menu.
Plugin structure
The Plugin project is structured as follows:
MY_PLUGIN
- src
- myPlugin
| - cmds
| | - AddComp.java
| | - AddMenu.java
| - cmps
| - ComponentDimLine.java
- META-INF
- plugin.cademia_macro
- plugin.ini
There are no changes in the file /MY_PLUGIN/src/myPlugin/cmps/ComponentDimLine.java.
Command AddComp
There are no changes in the file /MY_PLUGIN/src/myPlugin/cmds/AddComp.java.
Command AddMenu
File /MY_PLUGIN/src/myPlugin/cmds/AddMenu.java
package myPlugin.cmds;
import . . .
public class AddMenu extends
CmdAdapter {
public void doCmd(Object context) throws CmdAbortedException {
Kernel krnl = (Kernel)context;
GraphicalUserInterface gui =
(GraphicalUserInterface)krnl.getUserInterface();
// Register an input device at the Graphical User Interface
final
InputDeviceAdapter inputDevice = new InputDeviceAdapter();
gui.addInputDevice(inputDevice);
// Add a menu to the menu bar
JMenuBar menuBar = gui.getJMenuBar();
JMenu menu = new JMenu("MyPlugin");
menuBar.add(menu);
// Add a menu item to the menu
JMenuItem menuItem = new JMenuItem("Add DimLine");
menuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
inputDevice.fireInput("addComp");
}
});
  menu.add(menuItem);
}
}
META-INF Files
The commands AddComp and AddMenu must be added to CADEMIA's
command table. This is done via the CADEMIA command putcmd in the
following macro that is executed when the Plugin is loaded. The assigned command
names are addComp and _m. The command AddMenu is
executed after being registered in order to add the Plugin menu when the Plugin
is loaded. The command message shows an information message box about
how to use this Plugin.
File /META-INF/plugin.cademia_macro
putcmd myPlugin.cmds.AddComp addComp;
putcmd myPlugin.cmds.AddMenu _m;
_m;
message "MY_PLUGIN (step 7):\nEnter \"addComp\" or Menu 'MY_PLUGIN > Add DimLine' to start.";
The properties of the plugin are defined in the following ini file.
File /META-INF/plugin.ini
#
#MY_PLUGIN
#
Name=MY_PLUGIN
Version=7.0
Info=Adds a ComponentDimLine with Text, Control points and Features.
Now load the Plugin and execute the Command AddComp via the CADEMIA
menu 'MyPlugin > Add DimLine'.