JGoButton Example?

I can’t seem to find an example of how to use JGoButton correctly.

I add the JGoButtons to my view object but never get my doMouseClick() called.

I also tried adding a JGoViewListener:

    if (evt.getHint() == JGoViewEvent.CLICKED &&
            evt.getJGoObject() instanceof JGoButton) {
        System.err.println("OBJ_CLICKED " + "--Button pressed.");
        JGoButton button = (JGoButton) evt.getJGoObject();
    } else

but this also never gets hit (the evt.getJGoObject() == null)…

What’s a guy to do???

dWiGhT

It depends on whether you want a “native” Java button control (Swing JComponent or SWT widget Control, depending on your platform). If you do, then you should use a JGoButton. If not, then you can use any approprate JGoObject (including JGoAreas consisting of whatever you want to include in your button) and implement a mouse click event handler, either as a separate listener or as an override of JGoObject.doMouseClick.
The following code in a view listener handles both kinds of cases:
case JGoViewEvent.CLICKED: {
if (e.getObject() instanceof Button) {
Button but = (Button)e.getObject();
MessageBox dlg = new MessageBox(myShell, SWT.ICON_INFORMATION | SWT.OK);
dlg.setText(“Button Clicked”);
dlg.setMessage(“Clicked on a Button”);
dlg.open();
} else if (e.getJGoObject() != null) {
JGoObject obj = e.getJGoObject().getParentNode();
if (obj instanceof JGoBasicNode) {
JGoBasicNode bn = (JGoBasicNode)obj;
startTransaction();
bn.setBrush(JGoBrush.makeStockBrush(getRandomColor()));
endTransaction(“changed node color”);
}
}
}
When the user clicks on a JGoButton’s Button Control, the JGoViewEvent.getObject() is a Button.
When the user clicks on a JGoObject, JGoViewEvent.getJGoObject() will be non-null. This particular example checks for clicking on a JGoBasicNode [note the call to JGoObject.getParentNode(), since the user is probably clicking on a child object of the node] and changes the brush color or the JGoBasicNode’s drawable shape.

xcellent!

dWiGhT