public class CWidget extends CShape
A widget shape for use with an Canvas
.
Like any other canvas 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.
WARNING:
JComboBox
which
brings up a JPopupMenu
, the behaviour can not be satisfying.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() { 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.
((CWidget)smw).setBasicListener(false);Clicking on the button just fills it in red.
smw.setPickable(false);Clicking on the button does anything.
((CWidget)smw).setBasicListener(true);Clicking on the button just causes the message "OK" written on standard output.
Constructor and Description |
---|
CWidget(javax.swing.JComponent w)
Builds a
CWidget based on a swing component. |
CWidget(javax.swing.JComponent w,
double x,
double y)
Builds a
CWidget based on a swing component. |
CWidget(javax.swing.JComponent w,
double x,
double y,
double width,
double height)
Builds a
CWidget based on a swing component. |
Modifier and Type | Method and Description |
---|---|
CShape |
copyTo(CShape sms)
Copies this widget into a destination widget.
|
CShape |
duplicate()
Creates a new copy of this shape and returns it.
|
javax.swing.JComponent |
getWidget() |
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.
|
CElement |
setFillPaint(java.awt.Paint fp)
Sets the fill Paint, which is used to display the interior of the shape
when it is filled.
|
CElement |
widgetChanged()
Requests a refresh of the
CWidget . |
above, aboveAll, addChild, addGhost, addTag, addTag, addTag, addTo, animate, asEllipse, asImage, asPolyLine, asRectangle, asRectangularShape, asText, attachSM, below, belowAll, canvasToShape, canvasToShapeRef, clone, contains, contains, contains, contains, detachSM, duplicateWithTags, firstShape, fixReferenceShapeToCurrent, getAbsShape, getAbsTransform, getAntialiasedShapes, getBoundingBox, getCanvas, getCenterX, getCenterY, getChild, getChildren, getChildrenCount, getClip, getFilledShapes, getFillPaint, getFirstAntialiasedShape, getFirstFilledShape, getFirstHavingTag, getFirstOutlinedShape, getGhost, getHeight, getHierarchy, getIntersection, getMaxX, getMaxY, getMinX, getMinY, getOutlinedShapes, getOutlinePaint, getParent, getReferenceX, getReferenceY, getRenderingHint, getRotation, getScaleX, getScaleY, getShape, getStroke, getSubtraction, getTags, getTransform, getTranslateX, getTranslateY, getTransparencyFill, getTransparencyOutline, getWidth, hasTag, hasTag, indexOf, intersects, isAbove, isAntialiased, isBelow, isDrawable, isFilled, isOnOutline, isOutlined, isPickable, isPicked, pick, pickStyle, remove, removeAllChildren, removeChild, removeChild, removeGhost, removeTag, removeTag, rotateBy, rotateTo, scaleBy, scaleBy, scaleTo, scaleTo, setAntialiased, setClip, setDrawable, setFilled, setOutlined, setOutlinePaint, setParent, setPickable, setReferencePoint, setReferencePoint, setRenderingHint, setShape, setStroke, setTransformToIdentity, setTransparencyFill, setTransparencyFill, setTransparencyOutline, setTransparencyOutline, shapeToCanvas, translateBy, translateTo
public CWidget(javax.swing.JComponent w)
CWidget
based on a swing component.w
- The component.public CWidget(javax.swing.JComponent w, double x, double y)
CWidget
based on a swing component.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 CWidget(javax.swing.JComponent w, double x, double y, double width, double height)
CWidget
based on a swing component.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.public CElement widgetChanged()
CWidget
.
Actually, a CWidget
is repainted only when
an input event occurs on it.CWidget
.public CElement setFillPaint(java.awt.Paint fp)
setFillPaint
in interface CElement
setFillPaint
in class CShape
fp
- The fill Paint.CShape.setFillPaint(Paint)
public void paint(java.awt.Graphics g)
public boolean isBasicListener()
public void setBasicListener(boolean basicListener)
basicListener
- True, if this smwidget's listeners must be notified by input events, false, if not.public CShape copyTo(CShape sms)
copyTo
in class CShape
sms
- The destination shapeCShape.copyTo(fr.lri.swingstates.canvas.CShape)
public CShape duplicate()
duplicate
in class CShape
CShape.duplicateWithTags()
public javax.swing.JComponent getWidget()
JComponent
widget.