Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.eclipse.swt.custom
Class CLabel  view CLabel download CLabel.java

java.lang.Object
  extended byorg.eclipse.swt.widgets.Widget
      extended byorg.eclipse.swt.widgets.Control
          extended byorg.eclipse.swt.widgets.Scrollable
              extended byorg.eclipse.swt.widgets.Composite
                  extended byorg.eclipse.swt.widgets.Canvas
                      extended byorg.eclipse.swt.custom.CLabel
All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable

public class CLabel
extends org.eclipse.swt.widgets.Canvas

A Label which supports aligned text and/or an image and different border styles.

If there is not enough space a CLabel uses the following strategy to fit the information into the available space:

 		ignores the indent in left align mode
 		ignores the image and the gap
 		shortens the text by replacing the center portion of the label with an ellipsis
 		shortens the text by removing the center portion of the label
 

Styles:
LEFT, RIGHT, CENTER, SHADOW_IN, SHADOW_OUT, SHADOW_NONE
Events:

IMPORTANT: This class is not intended to be subclassed.


Field Summary
private  int align
          the alignment.
private  java.lang.String appToolTipText
           
private  org.eclipse.swt.graphics.Image backgroundImage
           
private static java.lang.String ELLIPSIS
          a string inserted in the middle of text that has been shortened
private static int GAP
          Gap between icon and text
private  org.eclipse.swt.graphics.Color[] gradientColors
           
private  int[] gradientPercents
           
private  boolean gradientVertical
           
private  int hIndent
           
private  org.eclipse.swt.graphics.Image image
          the current icon
private static int INDENT
          Left and right margins
private  java.lang.String text
          the current text
private  int vIndent
           
 
Fields inherited from class org.eclipse.swt.widgets.Canvas
 
Fields inherited from class org.eclipse.swt.widgets.Composite
embeddedHandle
 
Fields inherited from class org.eclipse.swt.widgets.Scrollable
 
Fields inherited from class org.eclipse.swt.widgets.Control
 
Fields inherited from class org.eclipse.swt.widgets.Widget
handle
 
Constructor Summary
CLabel(org.eclipse.swt.widgets.Composite parent, int style)
          Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
 
Method Summary
private static int checkStyle(int style)
          Check the style bits to ensure that no invalid styles are applied.
 org.eclipse.swt.graphics.Point computeSize(int wHint, int hHint, boolean changed)
          Returns the preferred size of the receiver.
private  void drawBevelRect(org.eclipse.swt.graphics.GC gc, int x, int y, int w, int h, org.eclipse.swt.graphics.Color topleft, org.eclipse.swt.graphics.Color bottomright)
          Draw a rectangle in the given colors.
 int getAlignment()
          Returns the alignment.
 org.eclipse.swt.graphics.Image getImage()
          Return the CLabel's image or null.
 java.lang.String getText()
          Return the Label's text.
 java.lang.String getToolTipText()
          Returns the receiver's tool tip text, or null if it has not been set.
private  org.eclipse.swt.graphics.Point getTotalSize(org.eclipse.swt.graphics.Image image, java.lang.String text)
          Compute the minimum size.
private  void initAccessible()
           
(package private)  void onDispose(org.eclipse.swt.events.DisposeEvent event)
           
(package private)  void onPaint(org.eclipse.swt.events.PaintEvent event)
           
private  void paintBorder(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle r)
          Paint the Label's border.
 void setAlignment(int align)
          Set the alignment of the CLabel.
 void setBackground(org.eclipse.swt.graphics.Color color)
          Sets the receiver's background color to the color specified by the argument, or to the default system color for the control if the argument is null.
 void setBackground(org.eclipse.swt.graphics.Color[] colors, int[] percents)
          Specify a gradient of colours to be drawn in the background of the CLabel.
 void setBackground(org.eclipse.swt.graphics.Color[] colors, int[] percents, boolean vertical)
          Specify a gradient of colours to be drawn in the background of the CLabel.
 void setBackground(org.eclipse.swt.graphics.Image image)
          Set the image to be drawn in the background of the label.
 void setFont(org.eclipse.swt.graphics.Font font)
          Sets the font that the receiver will use to paint textual information to the font specified by the argument, or to the default font for that kind of control if the argument is null.
 void setImage(org.eclipse.swt.graphics.Image image)
          Set the label's Image.
 void setText(java.lang.String text)
          Set the label's text.
 void setToolTipText(java.lang.String string)
          Sets the receiver's tool tip text to the argument, which may be null indicating that no tool tip text should be shown.
protected  java.lang.String shortenText(org.eclipse.swt.graphics.GC gc, java.lang.String t, int width)
          Shorten the given text t so that its length doesn't exceed the given width.
 
Methods inherited from class org.eclipse.swt.widgets.Canvas
getCaret, scroll, setCaret
 
Methods inherited from class org.eclipse.swt.widgets.Composite
checkSubclass, getChildren, getLayout, getTabList, layout, layout, setFocus, setLayout, setTabList
 
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getBorderWidth, getClientArea, getHorizontalBar, getVerticalBar
 
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addFocusListener, addHelpListener, addKeyListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addPaintListener, addTraverseListener, computeSize, forceFocus, getAccessible, getBackground, getBounds, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getShell, getSize, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removePaintListener, removeTraverseListener, setBounds, setBounds, setCapture, setCursor, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setSize, setSize, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, update
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, setData, setData, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GAP

private static final int GAP
Gap between icon and text

See Also:
Constant Field Values

INDENT

private static final int INDENT
Left and right margins

See Also:
Constant Field Values

ELLIPSIS

private static final java.lang.String ELLIPSIS
a string inserted in the middle of text that has been shortened

See Also:
Constant Field Values

align

private int align
the alignment. Either CENTER, RIGHT, LEFT. Default is LEFT


hIndent

private int hIndent

vIndent

private int vIndent

text

private java.lang.String text
the current text


image

private org.eclipse.swt.graphics.Image image
the current icon


appToolTipText

private java.lang.String appToolTipText

backgroundImage

private org.eclipse.swt.graphics.Image backgroundImage

gradientColors

private org.eclipse.swt.graphics.Color[] gradientColors

gradientPercents

private int[] gradientPercents

gradientVertical

private boolean gradientVertical
Constructor Detail

CLabel

public CLabel(org.eclipse.swt.widgets.Composite parent,
              int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

The style value is either one of the style constants defined in class SWT which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using the int "|" operator) two or more of those SWT style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.

Method Detail

checkStyle

private static int checkStyle(int style)
Check the style bits to ensure that no invalid styles are applied.


computeSize

public org.eclipse.swt.graphics.Point computeSize(int wHint,
                                                  int hHint,
                                                  boolean changed)
Description copied from class: org.eclipse.swt.widgets.Control
Returns the preferred size of the receiver.

The preferred size of a control is the size that it would best be displayed at. The width hint and height hint arguments allow the caller to ask a control questions such as "Given a particular width, how high does the control need to be to show all of the contents?" To indicate that the caller does not wish to constrain a particular dimension, the constant SWT.DEFAULT is passed for the hint.

If the changed flag is true, it indicates that the receiver's contents have changed, therefore any caches that a layout manager containing the control may have been keeping need to be flushed. When the control is resized, the changed flag will be false, so layout manager caches can be retained.


drawBevelRect

private void drawBevelRect(org.eclipse.swt.graphics.GC gc,
                           int x,
                           int y,
                           int w,
                           int h,
                           org.eclipse.swt.graphics.Color topleft,
                           org.eclipse.swt.graphics.Color bottomright)
Draw a rectangle in the given colors.


getAlignment

public int getAlignment()
Returns the alignment. The alignment style (LEFT, CENTER or RIGHT) is returned.


getImage

public org.eclipse.swt.graphics.Image getImage()
Return the CLabel's image or null.


getTotalSize

private org.eclipse.swt.graphics.Point getTotalSize(org.eclipse.swt.graphics.Image image,
                                                    java.lang.String text)
Compute the minimum size.


setToolTipText

public void setToolTipText(java.lang.String string)
Description copied from class: org.eclipse.swt.widgets.Control
Sets the receiver's tool tip text to the argument, which may be null indicating that no tool tip text should be shown.


getText

public java.lang.String getText()
Return the Label's text.


getToolTipText

public java.lang.String getToolTipText()
Description copied from class: org.eclipse.swt.widgets.Control
Returns the receiver's tool tip text, or null if it has not been set.


paintBorder

private void paintBorder(org.eclipse.swt.graphics.GC gc,
                         org.eclipse.swt.graphics.Rectangle r)
Paint the Label's border.


initAccessible

private void initAccessible()

onDispose

void onDispose(org.eclipse.swt.events.DisposeEvent event)

onPaint

void onPaint(org.eclipse.swt.events.PaintEvent event)

setAlignment

public void setAlignment(int align)
Set the alignment of the CLabel. Use the values LEFT, CENTER and RIGHT to align image and text within the available space.


setBackground

public void setBackground(org.eclipse.swt.graphics.Color color)
Description copied from class: org.eclipse.swt.widgets.Control
Sets the receiver's background color to the color specified by the argument, or to the default system color for the control if the argument is null.


setBackground

public void setBackground(org.eclipse.swt.graphics.Color[] colors,
                          int[] percents)
Specify a gradient of colours to be drawn in the background of the CLabel.

For example, to draw a gradient that varies from dark blue to blue and then to white and stays white for the right half of the label, use the following call to setBackground:

	clabel.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE), 
		                           display.getSystemColor(SWT.COLOR_BLUE),
		                           display.getSystemColor(SWT.COLOR_WHITE), 
		                           display.getSystemColor(SWT.COLOR_WHITE)},
		               new int[] {25, 50, 100});
 


setBackground

public void setBackground(org.eclipse.swt.graphics.Color[] colors,
                          int[] percents,
                          boolean vertical)
Specify a gradient of colours to be drawn in the background of the CLabel.

For example, to draw a gradient that varies from dark blue to white in the vertical, direction use the following call to setBackground:

	clabel.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE), 
		                           display.getSystemColor(SWT.COLOR_WHITE)},
		                 new int[] {100}, true);
 

Since:
3.0

setBackground

public void setBackground(org.eclipse.swt.graphics.Image image)
Set the image to be drawn in the background of the label.


setFont

public void setFont(org.eclipse.swt.graphics.Font font)
Description copied from class: org.eclipse.swt.widgets.Control
Sets the font that the receiver will use to paint textual information to the font specified by the argument, or to the default font for that kind of control if the argument is null.


setImage

public void setImage(org.eclipse.swt.graphics.Image image)
Set the label's Image. The value null clears it.


setText

public void setText(java.lang.String text)
Set the label's text. The value null clears it.


shortenText

protected java.lang.String shortenText(org.eclipse.swt.graphics.GC gc,
                                       java.lang.String t,
                                       int width)
Shorten the given text t so that its length doesn't exceed the given width. The default implementation replaces characters in the center of the original string with an ellipsis ("..."). Override if you need a different strategy.