sm
Class SMWidget

java.lang.Object
  extended bysm.SMShape
      extended bysm.SMWidget
All Implemented Interfaces:
java.lang.Cloneable, InteractiveObject

public class SMWidget
extends SMShape

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:
  1.  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.
  2.  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.
  3.  ((SMWidget)smw).setBasicListener(false);
     
    Clicking on the button just fills it in red.
  4.  smw.setPickable(false);
     
    Clicking on the button does anything.
  5.  ((SMWidget)smw).setBasicListener(true);
     
    Clicking on the button just causes the message "OK" written on standard output.

Author:
Caroline Appert

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 sm.SMShape
above, aboveAll, addChild, addGhost, addTag, addTag, addTag, addTo, asEllipse, asImage, asPolyLine, asRectangle, asRectangularShape, asText, attachSM, below, belowAll, canvasToShape, clone, contains, contains, contains, contains, containsPoint, containsPoint, copyTo, detachSM, duplicate, equals, getAbsShape, getAbsTransform, getBoundingBox, getCanvas, getCenterX, getCenterY, getChildren, getClip, getFillPaint, getHeight, getHierarchy, getID, getMaxX, getMaxY, getMinX, getMinY, getOutlinePaint, getParent, getReferenceX, getReferenceY, getRotation, getScaleX, getScaleY, getShape, getStroke, getTransform, getTranslateX, getTranslateY, getTransparency, getWidth, hasTag, hasTag, intersects, intersects, isAbove, isAntialiased, isBelow, isDrawable, isEmpty, isFilled, isOnOutline, isOutlined, isPickable, remove, removeChild, removeGhost, removeTag, removeTag, rotateBy, rotateTo, scaleBy, scaleBy, scaleTo, scaleTo, setAntialiased, setClip, setDrawable, setFilled, setOutlined, setOutlinePaint, setParent, setPickable, setReferencePoint, setShape, setStroke, setTransparency, shapeToCanvas, translateBy, translateTo
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SMWidget

public SMWidget(javax.swing.JComponent w)
Builds a smwidget based on a swing component.

Parameters:
w - The component.

SMWidget

public SMWidget(javax.swing.JComponent w,
                double x,
                double y)
Builds a smwidget based on a swing component.

Parameters:
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.

SMWidget

public SMWidget(javax.swing.JComponent w,
                double x,
                double y,
                double width,
                double height)
Builds a smwidget based on a swing component.

Parameters:
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

setFillPaint

public SMShape setFillPaint(java.awt.Paint fp)
Description copied from class: SMShape
Sets the fill Paint, which is used to display the interior of the shape when it is filled.

Overrides:
setFillPaint in class SMShape
Parameters:
fp - The fill Paint.
Returns:
Returns this shape.

paint

public void paint(java.awt.Graphics g)
Description copied from class: SMShape
Paints the shape. Normally this method need not be called, since the canvas paints the display list automatically.

Overrides:
paint in class SMShape
Parameters:
g - The graphics with which the shape must be painted.

isBasicListener

public boolean isBasicListener()
Tests if this smwidget's listeners are or are not notified by input events.

Returns:
Returns true if this smwidget's listeners are notified by input events, false, if they are not.

setBasicListener

public void setBasicListener(boolean basicListener)
Sets this smwidget's listeners be notified or not by input events.

Parameters:
basicListener - True, if this smwidget's listeners must be notified by input events, false, if not.