Current Page:
NeXtMidas User's Guide
Graphics
Creating Custom Widgets
|
|
The BEAN Control WidgetSince NeXtMidas 2.9.1, a user may develop their own custom widget controls and
call them as they would a regular macro We will use the simple The following subsections provide an overview of creating a custom control:
Creating Your ClassThe custom control's class should be added to the UCL/libg folder or your own option tree.
The class must extend Class Stub Examplepackage nxm.ucl.libg;
import nxm.sys.inc.MessageHandler;
import nxm.sys.libg.BeanWidget;
import nxm.sys.libg.GWidget;
/**
A simple class to create a Swing-based JLabel from the GCONTROL BEAN widget.
This class will be expanded upon as new examples or techniques are added
to the NeXtMidas User's Guide.
@author NeXtMidas Developer
@version $Id: BeanWidgets.html,v 1.3 2011/03/09 16:22:56 jwb Exp $
@since NeXtMidas 2.9.1
*/
public class GSwingLabel extends GWidget implements BeanWidget {
private MessageHandler mh;
private String labelText = "";
protected JLabel swingLabel;
/**
Empty constructor. Required!
*/
public GSwingLabel () {}
/**
Called by GCONTROL to "create" this BEAN-based widget.
@param name The name of the widget/control.
@param parent The parent widget/control.
@param title The Midas title of the widget/control.
@param flags Any applicable flags passed into the widget/control.
@param mh The MessageHandler reference for sending processMessages.
@param argTable The table of Midas arguments sent into this widget/control.
*/
public void setupBean(String name, Object parent, String title,
int flags, MessageHandler mh, nxm.sys.lib.Table argTable) {
// Must call GWidget.setupBean. Required!
super.setupBean(name, parent, title, flags, mh, argTable);
// Define attributes of this class
this.mh = mh; // Store a local reference to MessageHandler
// Parse through the control arguments
// We will add this functionality in the next step
// Additional functionality
// We will add this functionality in the next step
// Add to the parent MWindow. Required!
addTo(parent); // calls GWidget's addTo method
}
}
In the "Class Stub Example" above, you will notice that the Configuring the setupBean() Method
public void setupBean (String name, Object parent, String title,
int flags, MessageHandler mh, nxm.sys.lib.Table argTable) {
// Must call GWidget.setupBean
super.setupBean(name, parent, title, flags, mh, argTable);
// Define attributes of this class
this.mh = mh; // Store a local reference to MessageHandler
// Parse through the control arguments
if (argTable != null) {
// Argument "P1" is already used for the class name
if (argTable.size() > 0)
labelText = argTable.getS("LABELTEXT");
// Additional functionality
if (labelText != null) {
open(labelText); // user should define this open() method
}
// Add to the parent MWindow. Required!
addTo(parent); // calls GWidget's addTo method
}
At this point, the functionality required for the class to function as a
custom Adding the Control to the GWidget PanelNote that at some point your control, panel, or combination of the two,
must be added to the // Add the JLabel to the NeXtMidas panel panel.add(swingLabel); Building the Custom ControlTo build your custom control, issue the bld GSwingLabel libg ucl Calling the Custom ControlNext, the user will need to create a user macro in order to test their newly
compiled custom control. In the macro, the new control is added by using the
GCONTROL BEAN mySwingLabel "mySwingLabel" P1=nxm.ucl.libg.GSwingLabel TABLE={LABELTEXT="HELLO,WORLD!"}
Closing NotesThe GSwingLabel control is a very simple example of how a user may create
a simple widget control. For more extensive examples of using the BEAN widget
to create complicated control widgets, please see the |
|