org.tentackle.print
Class PrintLabel

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.tentackle.print.PrintLabel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants, PrintComponent
Direct Known Subclasses:
DatePrintLabel, NumberPrintLabel

public class PrintLabel
extends JLabel
implements PrintComponent

Text printing bean.
This is the base class for all text-field based printing beans.

Author:
harald
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JLabel
JLabel.AccessibleJLabel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  Object value
          last printed value
 
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
PrintLabel()
          Creates a print label with minimum width and a LEADING horizontal alignment.
PrintLabel(int columns)
          Creates a print label with a LEADING horizontal alignment.
PrintLabel(int columns, int horizontalAlignment)
          Creates a print label.
PrintLabel(String text, int columns, int horizontalAlignment)
          Creates a print label.
 
Method Summary
 int getColumns()
          Gets the column width.
protected  int getColumnWidth()
          Gets the column width.
 int getPreferredHeight()
          Gets the preferred height.
 Dimension getPreferredSize()
          If the preferredSize has been set to a non-null value just returns it.
 int getPreferredWidth()
          Gets the preferred width.
 Object getPrintValue()
          Gets the value to be printed
 void setBounds(int x, int y, int width, int height)
          Moves and resizes this component.
 void setBounds(Rectangle r)
          Moves and resizes this component to conform to the new bounding rectangle r.
 void setColumns(int columns)
          Sets the width according to the number of columns.
 void setFont(Font font)
          Sets the font for this component.
 void setPreferredHeight(int height)
          Sets the height to control Labelsize without automatic FontMetrics.
 void setPreferredWidth(int width)
          Sets the width to control Labelsize without automatic FontMetrics.
 void setPrintValue(Object value)
          Sets the value to be printed
 void setSize(Dimension d)
          Resizes this component so that it has width d.width and height d.height.
 void setSize(int width, int height)
          Resizes this component so that it has width width and height height.
 
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, setText, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, 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, paintComponent, 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, setForeground, setInheritsPopupMenu, 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, 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, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, 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

value

protected Object value
last printed value

Constructor Detail

PrintLabel

public PrintLabel(String text,
                  int columns,
                  int horizontalAlignment)
Creates a print label.

Parameters:
text - the initial text, null = none
columns - the width in columns, 0 = minimum width
horizontalAlignment - the horizontal alignment
See Also:
JLabel

PrintLabel

public PrintLabel(int columns,
                  int horizontalAlignment)
Creates a print label.

Parameters:
columns - the width in columns, 0 = minimum width
horizontalAlignment - the horizontal alignment
See Also:
JLabel

PrintLabel

public PrintLabel(int columns)
Creates a print label with a LEADING horizontal alignment.

Parameters:
columns - the width in columns, 0 = minimum width
See Also:
JLabel

PrintLabel

public PrintLabel()
Creates a print label with minimum width and a LEADING horizontal alignment.

See Also:
JLabel
Method Detail

setColumns

public void setColumns(int columns)
Sets the width according to the number of columns.

Parameters:
columns - the columns, 0 = minimum width (default)
Throws:
IllegalArgumentException - if width is negative

getColumns

public int getColumns()
Gets the column width.

Returns:
the width according to the number of columns

getColumnWidth

protected int getColumnWidth()
Gets the column width.

The meaning of what a column is can be considered a fairly weak notion for some fonts. This method is used to define the width of a column. By default this is defined to be the width of the character m for the font used. This method can be redefined to be some alternative amount

Returns:
the column width >= 1

setFont

public void setFont(Font font)
Sets the font for this component.

Overridden to clear columnWidth.

Overrides:
setFont in class JComponent
Parameters:
font - the desired Font for this component
See Also:
Component.getFont()

getPreferredSize

public Dimension getPreferredSize()
If the preferredSize has been set to a non-null value just returns it. If the UI delegate's getPreferredSize method returns a non null value then return that; otherwise defer to the component's layout manager.

Overridden to allow columns to be honored and the preferred fixed width/height Returns the preferred size Dimensions needed for this TextField. If a non-zero number of columns has been set, the width is set to the columns multiplied by the column width.

Overrides:
getPreferredSize in class JComponent
Returns:
the value of the preferredSize property
See Also:
JComponent.setPreferredSize(java.awt.Dimension), ComponentUI

setPreferredHeight

public void setPreferredHeight(int height)
Sets the height to control Labelsize without automatic FontMetrics. Use this method to control *ONLY* the height.

Parameters:
height - the preferred height, 0 = automatic according to font

getPreferredHeight

public int getPreferredHeight()
Gets the preferred height.

Returns:
the preferred height, 0 = not yet computed

setPreferredWidth

public void setPreferredWidth(int width)
Sets the width to control Labelsize without automatic FontMetrics. Use this method to control *ONLY* the width.

Parameters:
width - the preferred width, 0 = automatic according to font

getPreferredWidth

public int getPreferredWidth()
Gets the preferred width.

Returns:
the preferred width, 0 = not yet computed

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Moves and resizes this component. The new location of the top-left corner is specified by x and y, and the new size is specified by width and height.

Overridden to allow columns to be honored.

Overrides:
setBounds in class Component
Parameters:
x - the new x-coordinate of this component
y - the new y-coordinate of this component
width - the new width of this component
height - the new height of this component
See Also:
Component.getBounds(), Component.setLocation(int, int), Component.setLocation(Point), Component.setSize(int, int), Component.setSize(Dimension)

setBounds

public void setBounds(Rectangle r)
Description copied from class: java.awt.Component
Moves and resizes this component to conform to the new bounding rectangle r. This component's new position is specified by r.x and r.y, and its new size is specified by r.width and r.height

Overrides:
setBounds in class Component
Parameters:
r - the new bounding rectangle for this component
See Also:
Component.getBounds(), Component.setLocation(int, int), Component.setLocation(Point), Component.setSize(int, int), Component.setSize(Dimension)

setSize

public void setSize(Dimension d)
Resizes this component so that it has width d.width and height d.height.

Overridden due to setBounds().

Overrides:
setSize in class Component
Parameters:
d - the dimension specifying the new size of this component
See Also:
Component.setSize(int, int), Component.setBounds(int, int, int, int)

setSize

public void setSize(int width,
                    int height)
Resizes this component so that it has width width and height height.

Overridden due to setBounds().

Overrides:
setSize in class Component
Parameters:
width - the new width of this component in pixels
height - the new height of this component in pixels
See Also:
Component.getSize(), Component.setBounds(int, int, int, int)

setPrintValue

public void setPrintValue(Object value)
Description copied from interface: PrintComponent
Sets the value to be printed

Specified by:
setPrintValue in interface PrintComponent
Parameters:
value - the value object

getPrintValue

public Object getPrintValue()
Description copied from interface: PrintComponent
Gets the value to be printed

Specified by:
getPrintValue in interface PrintComponent
Returns:
the value object


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de