org.formaria.swing
Class FlowedTextComponent

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by org.formaria.swing.animation.AnimationSurface
                  extended by org.formaria.swing.FlowedTextComponent
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, java.io.Serializable, TextHolder
Direct Known Subclasses:
AnimatedText, PolygonalTextArea, ReflectedText, RotatedText

public class FlowedTextComponent
extends AnimationSurface

A component that flows text around other components, child components and components that overlap this component. Assumes that the area within which the text is flowed is composed of rectangular blocks.

Copyright (c) Formaria Ltd., 2008, This software is licensed under the GNU Public License (GPL), please see license.txt for more details. If you make commercial use of this software you must purchase a commercial license from formaria.

$Revision: 1.23 $

See Also:
Serialized Form

Nested Class Summary
protected  class FlowedTextComponent.Attrib
          A structure for holding references to the attributes of the string
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  float ascent
           
protected  java.util.Hashtable attributedStrings
           
protected  boolean clip
           
protected  int cols
           
protected  int colSpacing
           
protected  int currentColumn
           
protected  int deltaX
           
protected  int deltaY
           
protected  java.awt.geom.Area flowArea
           
protected  int oH
           
protected  int oW
           
protected  int oX
           
protected  int oY
           
 
Fields inherited from class org.formaria.swing.animation.AnimationSurface
animationContext, animator, antiAlias, autoStart, bimg, composite, currentProject, finished, imageType, increment, label, loopTime, oldH, oldW, position, rendering, sleepTime, startTime, texture, timingFraction
 
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 java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
FlowedTextComponent()
          Create a new flowed text component
 
Method Summary
 void applyState(java.awt.Graphics2D g2)
          Apply the current state to the graphics rendering context
 void drawObjects(int w, int h, java.awt.Graphics2D g2)
          All classes that extend JAnimationSurface must implement this routine...
protected  java.text.AttributedString getAttributedString(java.lang.String localCopy, java.awt.Font font, int[] lengths)
          Get an AttribtedString for this component, converting the tags <b>, <i>, <u>, <sub>, <super>, <swap>, <justify>, <strike> to the proper internal form.
 boolean getClip()
          Get the clip state
 int getColSpacing()
          Get the column spacing
 int getNumColumns()
          Get the number of columns into which the flow area is divided
 java.lang.String getText()
          Get the label/text of the component.
 void init()
          Attempts to load and reference the associated view/datastore.
 void reset(int w, int h)
          Adjust the settings for the next step.
 void setClip(boolean state)
          Set the clip state
 void setCols(int numCols)
          Set the number of columns
 void setColSpacing(int spacing)
          Set the column spacing as the number of pixels between each column.
 void setNumColumns(int columns)
          Set the number of columns in which to divide the flow area
 void setText(java.lang.String text)
          Set the label/text of the component.
 void step(int w, int h)
          Adjust the settings for the next step.
protected  double wrapString(java.awt.Graphics2D g2, java.lang.String text, double currentPos, double y, java.awt.geom.Area[] columns)
          Draw text that wraps within the flow area
 
Methods inherited from class org.formaria.swing.animation.AnimationSurface
autoStart, begin, createBufferedImage, createGraphics2D, end, getAnimator, getAntiAlias, getAutoStart, getComposite, getImageType, getIncrement, getLoopTime, getRendering, getSleepTime, isAnimated, isFinished, isStarted, paintComponent, print, quoteReplacement, render, repeat, replace, reset, setAnimator, setAntiAlias, setAutoStart, setComposite, setImageType, setIncrement, setLoopTime, setRendering, setSleepTime, setTexture, start, stop, timingEvent
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, 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
 

Field Detail

clip

protected boolean clip

ascent

protected float ascent

flowArea

protected java.awt.geom.Area flowArea

oX

protected int oX

oY

protected int oY

oW

protected int oW

oH

protected int oH

deltaX

protected int deltaX

deltaY

protected int deltaY

cols

protected int cols

colSpacing

protected int colSpacing

currentColumn

protected int currentColumn

attributedStrings

protected java.util.Hashtable attributedStrings
Constructor Detail

FlowedTextComponent

public FlowedTextComponent()
Create a new flowed text component

Method Detail

setNumColumns

public void setNumColumns(int columns)
Set the number of columns in which to divide the flow area

Parameters:
columns - the number of columns, if <1 a single flow area is used

getNumColumns

public int getNumColumns()
Get the number of columns into which the flow area is divided

Returns:
the number of columns

setColSpacing

public void setColSpacing(int spacing)
Set the column spacing as the number of pixels between each column. The spacing has no effect if there is a single column.

Parameters:
spacing - the column spacing in pixels

getColSpacing

public int getColSpacing()
Get the column spacing

Returns:
the spacing in pixels

setText

public void setText(java.lang.String text)
Set the label/text of the component. Usage depends on the concrete component type

Specified by:
setText in interface TextHolder
Overrides:
setText in class AnimationSurface
Parameters:
text - the new text.

getText

public java.lang.String getText()
Get the label/text of the component.

Specified by:
getText in interface TextHolder
Overrides:
getText in class AnimationSurface
Returns:
the component text.

init

public void init()
Attempts to load and reference the associated view/datastore.

Overrides:
init in class AnimationSurface

reset

public void reset(int w,
                  int h)
Adjust the settings for the next step.

Parameters:
w - the width
h - the height

step

public void step(int w,
                 int h)
Adjust the settings for the next step.

Parameters:
w - the width
h - the height

drawObjects

public void drawObjects(int w,
                        int h,
                        java.awt.Graphics2D g2)
All classes that extend JAnimationSurface must implement this routine... This component renders text in the flow area. The flow area is calculated to be the non-overlapped client area

Specified by:
drawObjects in class AnimationSurface
Parameters:
w - the width
h - the height
g2 - the graphics context

applyState

public void applyState(java.awt.Graphics2D g2)
Apply the current state to the graphics rendering context

Parameters:
g2 - the graphics context

wrapString

protected double wrapString(java.awt.Graphics2D g2,
                            java.lang.String text,
                            double currentPos,
                            double y,
                            java.awt.geom.Area[] columns)
Draw text that wraps within the flow area

Parameters:
g2 - the graphics context
text - the text
currentPos - the current y offset for a new column
y - the current y offset within the column for a new block of text
columns - the area of the columns
Returns:
the latest y position for drawing/rendering

getAttributedString

protected java.text.AttributedString getAttributedString(java.lang.String localCopy,
                                                         java.awt.Font font,
                                                         int[] lengths)
Get an AttribtedString for this component, converting the tags <b>, <i>, <u>, <sub>, <super>, <swap>, <justify>, <strike> to the proper internal form.

Parameters:
localCopy - the text being rendered
font - the current font
lengths - on return contains the length of the text to be rendered - the argument should be a string[1]
Returns:
the new AttributedString

setCols

public void setCols(int numCols)
Set the number of columns

Parameters:
numCols - the number of columns

setClip

public void setClip(boolean state)
Set the clip state

Parameters:
state - true to clip siblings

getClip

public boolean getClip()
Get the clip state

Returns:
true if siblings are clipped