canvas
Class StringComponent

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JLabel
                          |
                          +--canvas.StringComponent
All Implemented Interfaces:
Accessible, CanvasComponent, ImageObserver, MenuContainer, Serializable, SwingConstants

public class StringComponent
extends JLabel
implements CanvasComponent

Allows text labels to be added to a DrawingPane

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JLabel
JLabel.AccessibleJLabel
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 int fontSize
           
 String text
           
 
Fields inherited from class javax.swing.JLabel
labelFor
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
StringComponent(double x, double y, String text, canvas.DrawingGrid dg)
           
StringComponent(int x, int y, String text)
          Creates a StringComponent at the given position that is just large enough for the given text.
StringComponent(String text)
          Creates a StringComponent that is initially positioned at 0,0.
StringComponent(String text, canvas.DrawingGrid dg)
           
 
Method Summary
 canvas.DrawingPane getDrawingPane()
          Returns the DrawingPane that this StringComponent has been added to.
 void moveTo(double x, double y)
          Moves the component to the desired location.
 void moveTo(double x, double y, canvas.DrawingGrid dg)
           
 void redraw()
          Calls Component.repaint() in a thread-safe way.
 void resizeTo(double x, double y)
          Resizes the component to the desired size.
 void resizeTo(double x, double y, canvas.DrawingGrid dg)
           
 void setFeedbackText(String text)
          If possible, sets the text at the bottom of the window that this component is displayed in.
 void setFontColor(Color color)
          Sets the Color of the StringComponent to be the given color
 void setFontSize(int size)
          Sets the Size of the StringComponent's Font
 void setText(String text)
          Changes the text of the component and updates the size of the component to fit it.
 void smoothMove(double x, double y, int milliseconds)
          Smoothly moves this component to the given coordinates over the time interval given.
 void smoothMove(double x, double y, int milliseconds, canvas.DrawingGrid dg)
           
 void smoothResize(double width, double height, int milliseconds)
          Smoothly resizes this component to the given dimensions over the time interval given.
 void smoothResize(double width, double height, int milliseconds, canvas.DrawingGrid dg)
           
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface canvas.CanvasComponent
getHeight, getWidth
 

Field Detail

fontSize

public int fontSize

text

public String text
Constructor Detail

StringComponent

public StringComponent(String text)
Creates a StringComponent that is initially positioned at 0,0.


StringComponent

public StringComponent(String text,
                       canvas.DrawingGrid dg)

StringComponent

public StringComponent(int x,
                       int y,
                       String text)
Creates a StringComponent at the given position that is just large enough for the given text.

Parameters:
x - the x coordinate of the upper left corner
y - the y coordinate of the upper left corner
text - the 'String' to be displayed

StringComponent

public StringComponent(double x,
                       double y,
                       String text,
                       canvas.DrawingGrid dg)
Method Detail

moveTo

public void moveTo(double x,
                   double y)
Moves the component to the desired location. Coordinates are rounded to the nearest integer.

Specified by:
moveTo in interface CanvasComponent

moveTo

public void moveTo(double x,
                   double y,
                   canvas.DrawingGrid dg)

resizeTo

public void resizeTo(double x,
                     double y)
Resizes the component to the desired size. The text is *not* scaled with the size. Use setFontSize for that. Coordinates are rounded to the nearest integer.

Specified by:
resizeTo in interface CanvasComponent

resizeTo

public void resizeTo(double x,
                     double y,
                     canvas.DrawingGrid dg)

setFeedbackText

public void setFeedbackText(String text)
Description copied from interface: CanvasComponent
If possible, sets the text at the bottom of the window that this component is displayed in.

Specified by:
setFeedbackText in interface CanvasComponent

smoothResize

public void smoothResize(double width,
                         double height,
                         int milliseconds,
                         canvas.DrawingGrid dg)

smoothResize

public void smoothResize(double width,
                         double height,
                         int milliseconds)
Description copied from interface: CanvasComponent
Smoothly resizes this component to the given dimensions over the time interval given.

Specified by:
smoothResize in interface CanvasComponent

smoothMove

public void smoothMove(double x,
                       double y,
                       int milliseconds,
                       canvas.DrawingGrid dg)

smoothMove

public void smoothMove(double x,
                       double y,
                       int milliseconds)
Description copied from interface: CanvasComponent
Smoothly moves this component to the given coordinates over the time interval given.

Specified by:
smoothMove in interface CanvasComponent

redraw

public void redraw()
Description copied from interface: CanvasComponent
Calls Component.repaint() in a thread-safe way. The component is re-drawn on the screen. This is especially useful for PictureComponent objects.

Specified by:
redraw in interface CanvasComponent

setText

public void setText(String text)
Changes the text of the component and updates the size of the component to fit it.

Overrides:
setText in class JLabel
Parameters:
text - the new text

setFontSize

public void setFontSize(int size)
Sets the Size of the StringComponent's Font

Parameters:
size - the size of the font

setFontColor

public void setFontColor(Color color)
Sets the Color of the StringComponent to be the given color


getDrawingPane

public canvas.DrawingPane getDrawingPane()
Returns the DrawingPane that this StringComponent has been added to.