How do you implement a custom ActionListener with monkeybars? Is it possible? And from nested components?

85 views
Skip to first unread message

GregD

unread,
Apr 17, 2012, 9:31:42 PM4/17/12
to monkeybars-mvc
Hi all,

I have not seen any activity on this board, but I'll try anyway....

I develop swing client server apps still, believe it or not. I have
tried this in the past and can not figure out how to create a custom
ActionListener on a panel. Does all of the custom ActionListener
have to be in Java?

Here is what I like to do:
Create a ScrollPane and Panel that contain multiple different sub
panel types say PanelA, PanelB, PanelC.
There could be multiple of these panel types within the Main Scroll
Pane/Panel.
Each of these sub panels will have buttons and text areas. Buttons
actions are the only thing I'm concerned with.
When a button is pressed at any of the sub panels the basic action
will be:
1) clear and disable all components in that sub panel.
2) have a custom action listener on the main panel that will send a
comm message to a connected server based off the info from the sub
panel that the button was pressed in.

This is to create a hardware simulator. The simulator can have
different configurations (not worried about that or the comm part
because all of that I can do with ruby)

I have some sample java code that does this sort of thing, but I
really don't know if this can be done with monkeybars or how. I'll
reply later with the java code that does this.

GregD

unread,
Apr 18, 2012, 10:00:05 AM4/18/12
to monkeybars-mvc
Here is a snippet of Java code that implements a custom action
listener on multiple panels when initialized.


protected void initContent()
{
int
x = 10,
y = 325,
w,
h,
pad = 5;
String
level = "";
int
laneNo = 0;
PnlPackLaneDisplay
pnlDisplay;
......
lstLanes = new ArrayList<PnlPackLaneDisplay>();
for(int i = 0; i < 2; i++)
{
for(int j = 1; j <= 8; j++)
{
laneNo++;
pnlDisplay = new PnlPackLaneDisplay(laneNo, level, c);
rl.setLayoutConstraints(pnlDisplay, new Rectangle(x, y, 100,
200 ));
add(pnlDisplay);
lstLanes.add(pnlDisplay);
PackPanelButtonListener ppbl = new
PackPanelButtonListener(pnlDisplay);
pnlDisplay.addPanelActionListener(ppbl);

x = x + 100 + pad;
}

//was "A" level = "B";
y = 120; // + 200 + 5;
x = 10;
}
.....
}
public class PnlPackLaneDisplay extends JPanel
{
.....
public PnlPackLaneDisplay(int laneNo, String level )
{
this(laneNo, level, Color.pink);
}

public PnlPackLaneDisplay(int laneNo, String level, Color
titleColor)
{
super();
this.level = level;
this.laneNo = laneNo;
this.titleColor = titleColor;
init();
}

protected void init()
{
....
}
....
public void addPanelActionListener(ActionListener al)
{
btnPack.addActionListener(al);
btnContents.addActionListener(al);
btnOrder.addActionListener(al);
}

}

/**
* Action listener for buttons on lane display panels; each panel
* gets its own listener object
*/
public class PackPanelButtonListener implements ActionListener
{
protected PnlPackLaneDisplay
pnl;

public PackPanelButtonListener(PnlPackLaneDisplay pnl)
{
this.pnl = pnl;
}

public void actionPerformed(ActionEvent e)
{
String
cmd;

cmd = e.getActionCommand();

if(cmd.equals("contents"))
{
....
}

else if(cmd.equals("pack"))
{
Integer
i;

i = Integer.class.cast(pnl.getCurrentQty());
Tracer.msg(TRACER_PACK_STATION, "Current PACK LOCATION = " +
pnl.getLocationId());
Tracer.msg(TRACER_PACK_STATION, "Current QTY = " +
i.intValue());
sendPackMessage(pnl.getLocationId(), i);
}
}
}


I'd like to implement the a similar thing using ruby and not java.

Is it possible to create a custom listener in the controller or they
always <component>_<event_type>?
Reply all
Reply to author
Forward
0 new messages