|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsm.SMShape
sm.SMWidget
A widget shape for use with an Canvas
.
Like any other smcanvas shape type, it can be rendered in a smcanvas and interaction
with it can be described in a state machine.
It is built on any JComponent and, thus, can have its own listener.
This following code makes a button "ok" at location (10, 10) rotated by pi in a smcanvas.
JButton ok = new JButton("ok"); CShape smw = canvas.newWidget(ok, 100, 100, 50, 15).rotateBy(Math.PI/2);Now, let's see how to manage interaction with the button
ok
:
ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("OK"); } });Clicking on the button ok causes the message "OK" written on standard output.
StateMachine sm = new StateMachine("widgets") { public State colorButton = new State() { Transition click = new ClickOnShape(BUTTON1) { public void action(){ getShape().setFillPaint(Color.RED); } }; }; }; canvas.attach(sm);Clicking on the button ok fills it in red AND causes the message "OK" written on standard output.
((SMWidget)smw).setBasicListener(false);Clicking on the button just fills it in red.
smw.setPickable(false);Clicking on the button does anything.
((SMWidget)smw).setBasicListener(true);Clicking on the button just causes the message "OK" written on standard output.
Field Summary |
Fields inherited from class sm.SMShape |
cptId |
Constructor Summary | |
SMWidget(javax.swing.JComponent w)
Builds a smwidget based on a swing component. |
|
SMWidget(javax.swing.JComponent w,
double x,
double y)
Builds a smwidget based on a swing component. |
|
SMWidget(javax.swing.JComponent w,
double x,
double y,
double width,
double height)
Builds a smwidget based on a swing component. |
Method Summary | |
boolean |
isBasicListener()
Tests if this smwidget's listeners are or are not notified by input events. |
void |
paint(java.awt.Graphics g)
Paints the shape. |
void |
setBasicListener(boolean basicListener)
Sets this smwidget's listeners be notified or not by input events. |
SMShape |
setFillPaint(java.awt.Paint fp)
Sets the fill Paint, which is used to display the interior of the shape when it is filled. |
Methods inherited from class java.lang.Object |
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public SMWidget(javax.swing.JComponent w)
w
- The component.public SMWidget(javax.swing.JComponent w, double x, double y)
w
- The component.x
- The x coordinate of the upper left point of the bounding box.y
- The y coordinate of the upper left point of the bounding box.public SMWidget(javax.swing.JComponent w, double x, double y, double width, double height)
w
- The component.x
- The x coordinate of the upper left point of the bounding box.y
- The y coordinate of the upper left point of the bounding box.width
- The width of the bounding box.height
- The height of the bounding box.Method Detail |
public SMShape setFillPaint(java.awt.Paint fp)
SMShape
setFillPaint
in class SMShape
fp
- The fill Paint.
public void paint(java.awt.Graphics g)
SMShape
paint
in class SMShape
g
- The graphics with which the shape must be painted.public boolean isBasicListener()
public void setBasicListener(boolean basicListener)
basicListener
- True, if this smwidget's listeners must be notified by input events, false, if not.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |