LEONARDI Application Composer - 8.9.0.40 by W4 S.A.

leon.view.win.swing.component
Class LyJMultiLineLabel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by leon.view.win.swing.component.LyJMultiLineLabel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class LyJMultiLineLabel
extends javax.swing.JPanel

This example is from the book _Java in a Nutshell_ by David Flanagan.
Written by David Flanagan.
Copyright (c) 1998 O'Reilly & Associates.
You may study, use, modify, and distribute this example for any purpose. This example is provided WITHOUT WARRANTY either expressed or implied.

Tilman 05/07/96: added a maxChars parameter to specify a maximum line length. If any of the lines is longer, it will be cut at the last space character before maxChars, until it fits into maxChars. Set maxChars to -1 if you don't care.

Van 07/30/96: added the removal of backslash-r from the multi-line string that might have been added by strings in Windows (which expect newlines to be indicated by backslash-r backslash-n)

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
static java.lang.String __VERSION
           
static int CENTER
          Center alignment constant.
static int LEFT
          Left alignment constant.
static int RIGHT
          Right alignment constant.
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
LyJMultiLineLabel()
          Creates a new multiline label object from the specified attributes.
LyJMultiLineLabel(java.lang.String label)
          Creates a new multiline label object from the specified attributes.
LyJMultiLineLabel(java.lang.String label, int maxChars)
          Creates a new multiline label object from the specified attributes.
LyJMultiLineLabel(java.lang.String label, int maxChars, int alignment)
          Creates a new multiline label object from the specified attributes.
LyJMultiLineLabel(java.lang.String label, int maxChars, int margin_width, int margin_height)
          Creates a new multiline label object from the specified attributes.
LyJMultiLineLabel(java.lang.String label, int maxChars, int margin_width, int margin_height, int alignment)
          Creates a new multiline label object from the specified attributes.
 
Method Summary
 void addNotify()
          Invoked after our Canvas is first created but before it can actually be displayed.
 int getAlignment()
          Gets the alignment policy of this component.
 java.lang.String getLabel()
          Gets the label of this component.
 int getMarginHeight()
          Gets the vertical margin for this component.
 int getMarginWidth()
          Gets the horizontal margin for this component.
 java.awt.Dimension getMinimumSize()
          (non-Javadoc).
 int getNumLines()
          Returns the number of lines used to display label.
 java.awt.Dimension getPreferredSize()
          (non-Javadoc).
 void paintComponent(java.awt.Graphics g)
          Draws the label (applets use the same method).
 void setAlignment(int a)
          Sets the alignment policy of this label.
 void setBigFont(java.awt.Font f)
          Sets the biggest font for this component.
 void setFont(java.awt.Font f)
          (non-Javadoc).
 void setForeground(java.awt.Color c)
          (non-Javadoc).
 void setLabel(java.lang.String label)
          Sets the label of this component.
 void setMarginHeight(int mh)
          Sets the vertical margins of this component.
 void setMarginWidth(int mw)
          Sets the horizontal margins of this component.
 void setMaxWidth(int maxWidth)
          Sets the maximum number of characters per line
 void setMinimumWidth(int minimumWidth)
          Set the minimum width of this component.
 void setNCols(int nCols)
          Sets the number of columns, or -1 if automatic calculation.
 void setNRows(int nRows)
          Sets the number of rows, or -1 if automatic calculation.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, 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, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

__VERSION

public static final java.lang.String __VERSION
See Also:
Constant Field Values

LEFT

public static final int LEFT
Left alignment constant.

See Also:
Constant Field Values

CENTER

public static final int CENTER
Center alignment constant.

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
Right alignment constant.

See Also:
Constant Field Values
Constructor Detail

LyJMultiLineLabel

public LyJMultiLineLabel(java.lang.String label,
                         int maxChars,
                         int margin_width,
                         int margin_height,
                         int alignment)
Creates a new multiline label object from the specified attributes. Breaks the label up into separate lines, and saves the other info.

Parameters:
label - the multiline label
maxChars - the maximum number of characters per line
margin_width - the left and right margins
margin_height - the top and bottom margins
alignment - the alignment of the text

LyJMultiLineLabel

public LyJMultiLineLabel(java.lang.String label,
                         int maxChars,
                         int margin_width,
                         int margin_height)
Creates a new multiline label object from the specified attributes. Breaks the label up into separate lines, and saves the other info. By default, the alignment is on the left.

Parameters:
label - the multiline label
maxChars - the maximum number of characters per line
margin_width - the left and right margins
margin_height - the top and bottom margins

LyJMultiLineLabel

public LyJMultiLineLabel(java.lang.String label,
                         int maxChars,
                         int alignment)
Creates a new multiline label object from the specified attributes. Breaks the label up into separate lines, and saves the other info. By default, the horizontal and vertical margins are 20 pixels.

Parameters:
label - the multiline label
maxChars - the maximum number of characters per line
alignment - the alignment of the text

LyJMultiLineLabel

public LyJMultiLineLabel(java.lang.String label,
                         int maxChars)
Creates a new multiline label object from the specified attributes. Breaks the label up into separate lines, and saves the other info. By default, the horizontal and vertical margins are 20 pixels and the alignment is on the left.

Parameters:
label - the multiline label
maxChars - the maximum number of characters per line

LyJMultiLineLabel

public LyJMultiLineLabel(java.lang.String label)
Creates a new multiline label object from the specified attributes. Breaks the label up into separate lines, and saves the other info. By default, the width of this label is the maximum available, its horizontal and vertical margins are 20 pixels and the alignment is on the left.

Parameters:
label - the multiline label

LyJMultiLineLabel

public LyJMultiLineLabel()
Creates a new multiline label object from the specified attributes. Breaks the label up into separate lines, and saves the other info. By default, the label is "MultiLineLabel", the width of this label is the maximum available, its horizontal and vertical margins are 20 pixels and the alignment is on the left.

Method Detail

setLabel

public void setLabel(java.lang.String label)
Sets the label of this component. This label is broken in multiple lines and it is measured again.

Parameters:
label - the new label
See Also:
getLabel()

getLabel

public java.lang.String getLabel()
Gets the label of this component.

Returns:
the label
See Also:
setLabel(String)

setBigFont

public void setBigFont(java.awt.Font f)
Sets the biggest font for this component.

Parameters:
f - the font that is the biggest for the measurement computations

setFont

public void setFont(java.awt.Font f)
(non-Javadoc).

Overrides:
setFont in class javax.swing.JComponent
See Also:
Component.setFont(java.awt.Font)

setForeground

public void setForeground(java.awt.Color c)
(non-Javadoc).

Overrides:
setForeground in class javax.swing.JComponent
See Also:
Component.setForeground(java.awt.Color)

setAlignment

public void setAlignment(int a)
Sets the alignment policy of this label.

Parameters:
a - the alignment value. One of the following:
See Also:
getAlignment()

setMarginWidth

public void setMarginWidth(int mw)
Sets the horizontal margins of this component.

Parameters:
mw - the margin width, in pixels
See Also:
getMarginWidth()

setMarginHeight

public void setMarginHeight(int mh)
Sets the vertical margins of this component.

Parameters:
mh - the margin height, in pixels
See Also:
getMarginHeight()

getAlignment

public int getAlignment()
Gets the alignment policy of this component.

Returns:
the alignment policy
See Also:
setAlignment(int)

getMarginWidth

public int getMarginWidth()
Gets the horizontal margin for this component.

Returns:
the margin width, in pixels
See Also:
setMarginWidth(int)

getMarginHeight

public int getMarginHeight()
Gets the vertical margin for this component.

Returns:
the margin height, in pixels
See Also:
setMarginHeight(int)

addNotify

public void addNotify()
Invoked after our Canvas is first created but before it can actually be displayed. After this superclass' JComponent.addNotify(), this component font metrics is set and the measure() method can be called to figure out how big the label is.

Overrides:
addNotify in class javax.swing.JComponent
See Also:
Component.addNotify()

getPreferredSize

public java.awt.Dimension getPreferredSize()
(non-Javadoc).

Overrides:
getPreferredSize in class javax.swing.JComponent
See Also:
Component.getPreferredSize()

setMinimumWidth

public void setMinimumWidth(int minimumWidth)
Set the minimum width of this component.

Parameters:
minimumWidth - the new minimum width of the component (a negative value means that there is no minimum width).

getMinimumSize

public java.awt.Dimension getMinimumSize()
(non-Javadoc).

Overrides:
getMinimumSize in class javax.swing.JComponent
See Also:
Component.getMinimumSize()

getNumLines

public int getNumLines()
Returns the number of lines used to display label.


paintComponent

public void paintComponent(java.awt.Graphics g)
Draws the label (applets use the same method). The margins and alignment are handled here, and the color and fonts are set by the superclass in the Graphics context object passed.

Overrides:
paintComponent in class javax.swing.JComponent
See Also:
JComponent.paintComponent(java.awt.Graphics)

setNCols

public void setNCols(int nCols)
Sets the number of columns, or -1 if automatic calculation.

Parameters:
nCols - the number of columns

setNRows

public void setNRows(int nRows)
Sets the number of rows, or -1 if automatic calculation.

Parameters:
nRows - the number of rows

setMaxWidth

public void setMaxWidth(int maxWidth)
Sets the maximum number of characters per line

Parameters:
maxWidth - the maximum number of characters per line

(c) January 2013 - W4 S.A.

Website: W4 S.A., contact us: support@w4global.com