org.formaria.swing
Class Label

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLabel
                  extended by org.formaria.swing.Label
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.Scrollable, javax.swing.SwingConstants, TextHolder
Direct Known Subclasses:
GraphicButton, Unknown

public class Label
extends javax.swing.JLabel
implements TextHolder, javax.swing.Scrollable

Draws text. The text may be wrapped over multiple lines.

Copyright (c) Formaria Ltd.,
License: see license.txt

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JLabel
javax.swing.JLabel.AccessibleJLabel
 
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  boolean antiAlias
           
protected  TextRenderer renderer
          The renderer that will paint the component
 
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
Label()
           
 
Method Summary
 void addNotify()
          Repaint the component once it has been created
 int getAlignment()
          Get the horizontal alignment style constant, the function is same to getHorizontalAlignment()
 boolean getAntiAlias()
          Gets the antialias property of the text.
 int getHorizontalAlignment()
          Get the horizontal alignment style constant
 java.awt.Dimension getPreferredScrollableViewportSize()
          Returns the preferred size of the viewport for a view component.
 java.awt.Dimension getPreferredSize()
          Gets the preferred size of this component.
 int getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Components that display logical rows or columns should compute the scroll increment that will completely expose one block of rows or columns, depending on the value of orientation.
 boolean getScrollableTracksViewportHeight()
          Return true if a viewport should always force the height of this Scrollable to match the height of the viewport.
 boolean getScrollableTracksViewportWidth()
          Return true if a viewport should always force the width of this Scrollable to match the width of the viewport.
 int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Components that display logical rows or columns should compute the scroll increment that will completely expose one new row or column, depending on the value of orientation.
 int getVerticalAlignment()
          Get the vertical alignment style constant
 void paintComponent(java.awt.Graphics g)
          Render the text
 void setAlign(int align)
          Deprecated. use setAlignment instead
 void setAlignment(int align)
          Set one or more attributes of the component.
 void setAlignment(java.lang.String value)
          Set one or more attributes of the component.
 void setAntiAlias(boolean b)
          Sets the antialias property of the text.
 void setBuffered(boolean buffer)
          Set the double buffering
 void setHorizontalAlignment(int align)
          Set one or more attributes of the component.
 void setText(java.lang.String value)
          Set the text
 void setTransparent(boolean b)
          Sets the transparency of the text.
 void setUseRenderer(boolean state)
          Set the renderering to the TextRenderer
 void setVerticalAlignment(int align)
          Set one or more attributes of the component.
 void setVerticalAlignment(java.lang.String value)
          Set the vertical alignment
 void update(java.awt.Graphics g)
          Update the component
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setUI, setVerticalTextPosition, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, 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, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, 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
 
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, 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
 
Methods inherited from interface org.formaria.aria.TextHolder
getText
 

Field Detail

renderer

protected TextRenderer renderer
The renderer that will paint the component


antiAlias

protected boolean antiAlias
Constructor Detail

Label

public Label()
Method Detail

update

public void update(java.awt.Graphics g)
Update the component

Overrides:
update in class javax.swing.JComponent
Parameters:
g - the graphcis context

addNotify

public void addNotify()
Repaint the component once it has been created

Overrides:
addNotify in class javax.swing.JComponent

paintComponent

public void paintComponent(java.awt.Graphics g)
Render the text

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - the graphcis context

getAlignment

public int getAlignment()
Get the horizontal alignment style constant, the function is same to getHorizontalAlignment()

Returns:
the horizontal alignment value

setAlignment

public void setAlignment(int align)
Set one or more attributes of the component. The function is same to setHorizontalAlignment(int). Attributes include
align (left|right|center ) or
alignment (left|right|center )
buffered (true|false) double buffering

Parameters:
align - 1 to right align the text, 0 for left alignment and 2 for centered text

setAlign

public void setAlign(int align)
Deprecated. use setAlignment instead

Set one or more attributes of the component. The function is same to setHorizontalAlignment(int). Attributes include
align (left|right|center ) or
alignment (left|right|center )
buffered (true|false) double buffering

Parameters:
align - 1 to right align the text, 0 for left alignment and 2 for centered text

setAlignment

public void setAlignment(java.lang.String value)
Set one or more attributes of the component. The function is same to setHorizontalAlignment(int). Attributes include
align (left|right|center ) or
alignment (left|right|center )
buffered (true|false) double buffering

Parameters:
align - 1 to right align the text, 0 for left alignment and 2 for centered text

getHorizontalAlignment

public int getHorizontalAlignment()
Get the horizontal alignment style constant

Overrides:
getHorizontalAlignment in class javax.swing.JLabel
Returns:
the horizontal alignment value

setHorizontalAlignment

public void setHorizontalAlignment(int align)
Set one or more attributes of the component. Attributes include
halign (left|right|center ) or
horizontalalignment (left|right|center )

Overrides:
setHorizontalAlignment in class javax.swing.JLabel
Parameters:
align - 1 to right align the text, 0 for left alignment and 2 for centered text

getVerticalAlignment

public int getVerticalAlignment()
Get the vertical alignment style constant

Overrides:
getVerticalAlignment in class javax.swing.JLabel
Returns:
the alignment value

setVerticalAlignment

public void setVerticalAlignment(int align)
Set one or more attributes of the component. Attributes include
valign (top|bottom|center ) or
verticalalignment (top|bottom|center )

Overrides:
setVerticalAlignment in class javax.swing.JLabel
Parameters:
align - 1 to right align the text, 0 for left alignment and 2 for centered text

setTransparent

public void setTransparent(boolean b)
Sets the transparency of the text.

Parameters:
b - true to make text transparent

setAntiAlias

public void setAntiAlias(boolean b)
Sets the antialias property of the text.

Parameters:
b - true if text is antialiased

getAntiAlias

public boolean getAntiAlias()
Gets the antialias property of the text.

Returns:
true if text is antialiased

setBuffered

public void setBuffered(boolean buffer)
Set the double buffering

Parameters:
buffer -

setVerticalAlignment

public void setVerticalAlignment(java.lang.String value)
Set the vertical alignment

Parameters:
value - top, bottom, center

setUseRenderer

public void setUseRenderer(boolean state)
Set the renderering to the TextRenderer


setText

public void setText(java.lang.String value)
Set the text

Specified by:
setText in interface TextHolder
Overrides:
setText in class javax.swing.JLabel
Parameters:
value -

getPreferredSize

public java.awt.Dimension getPreferredSize()
Gets the preferred size of this component.

Overrides:
getPreferredSize in class javax.swing.JComponent
Returns:
a dimension object indicating this component's preferred size
See Also:
JComponent.getMinimumSize(), LayoutManager

getPreferredScrollableViewportSize

public java.awt.Dimension getPreferredScrollableViewportSize()
Returns the preferred size of the viewport for a view component. For example, the preferred size of a JList component is the size required to accommodate all of the cells in its list. However, the value of preferredScrollableViewportSize is the size required for JList.getVisibleRowCount rows. A component without any properties that would affect the viewport size should just return getPreferredSize here.

Specified by:
getPreferredScrollableViewportSize in interface javax.swing.Scrollable
Returns:
the preferredSize of a JViewport whose view is this Scrollable
See Also:
JComponent.getPreferredSize()

getScrollableUnitIncrement

public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Components that display logical rows or columns should compute the scroll increment that will completely expose one new row or column, depending on the value of orientation. Ideally, components should handle a partially exposed row or column by returning the distance required to completely expose the item.

Scrolling containers, like JScrollPane, will use this method each time the user requests a unit scroll.

Specified by:
getScrollableUnitIncrement in interface javax.swing.Scrollable
Parameters:
visibleRect - The view area visible within the viewport
orientation - Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
direction - Less than zero to scroll up/left, greater than zero for down/right.
Returns:
The "unit" increment for scrolling in the specified direction. This value should always be positive.
See Also:
JScrollBar.setUnitIncrement(int)

getScrollableBlockIncrement

public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Components that display logical rows or columns should compute the scroll increment that will completely expose one block of rows or columns, depending on the value of orientation.

Scrolling containers, like JScrollPane, will use this method each time the user requests a block scroll.

Specified by:
getScrollableBlockIncrement in interface javax.swing.Scrollable
Parameters:
visibleRect - The view area visible within the viewport
orientation - Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
direction - Less than zero to scroll up/left, greater than zero for down/right.
Returns:
The "block" increment for scrolling in the specified direction. This value should always be positive.
See Also:
JScrollBar.setBlockIncrement(int)

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Return true if a viewport should always force the width of this Scrollable to match the width of the viewport. For example a normal text view that supported line wrapping would return true here, since it would be undesirable for wrapped lines to disappear beyond the right edge of the viewport. Note that returning true for a Scrollable whose ancestor is a JScrollPane effectively disables horizontal scrolling.

Scrolling containers, like JViewport, will use this method each time they are validated.

Specified by:
getScrollableTracksViewportWidth in interface javax.swing.Scrollable
Returns:
True if a viewport should force the Scrollables width to match its own.

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Return true if a viewport should always force the height of this Scrollable to match the height of the viewport. For example a columnar text view that flowed text in left to right columns could effectively disable vertical scrolling by returning true here.

Scrolling containers, like JViewport, will use this method each time they are validated.

Specified by:
getScrollableTracksViewportHeight in interface javax.swing.Scrollable
Returns:
True if a viewport should force the Scrollables height to match its own.