public class CLabel
extends org.eclipse.swt.widgets.Canvas
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
IMPORTANT: This class is not intended to be subclassed.
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
protected String |
beginShortenText(org.eclipse.swt.graphics.GC gc,
String t,
int width,
int w) |
protected String |
centerShortenText(org.eclipse.swt.graphics.GC gc,
String t,
int width,
int w) |
org.eclipse.swt.graphics.Point |
computeSize(int wHint,
int hHint,
boolean changed) |
protected String |
endShortenText(org.eclipse.swt.graphics.GC gc,
String t,
int width,
int w) |
int |
getAlignment()
Returns the horizontal alignment.
|
int |
getBottomMargin()
Return the CLabel's bottom margin.
|
String |
getEllipsis()
Return the CLabel's ellipsis.
|
int |
getEllipsisAligment()
Return the CLabel's ellipsis alignment.
|
org.eclipse.swt.graphics.Image |
getImage()
Return the CLabel's image or
null . |
int |
getLeftMargin()
Return the CLabel's left margin.
|
int |
getRightMargin()
Return the CLabel's right margin.
|
int |
getStyle() |
String |
getText()
Return the Label's text.
|
String |
getToolTipText() |
int |
getTopMargin()
Return the CLabel's top margin.
|
void |
setAlignment(int align)
Set the horizontal alignment of the CLabel.
|
void |
setBackground(org.eclipse.swt.graphics.Color color) |
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 |
setBottomMargin(int bottomMargin)
Set the label's bottom margin, in pixels.
|
void |
setEllipsis(String ellipsis)
Set the label's ellipsis
|
void |
setEllipsisAlignment(int ellipsisAlign)
Set the alignment of the ellipsis.
|
void |
setFont(org.eclipse.swt.graphics.Font font) |
void |
setImage(org.eclipse.swt.graphics.Image image)
Set the label's Image.
|
void |
setLeftMargin(int leftMargin)
Set the label's horizontal left margin, in pixels.
|
void |
setMargins(int leftMargin,
int topMargin,
int rightMargin,
int bottomMargin)
Set the label's margins, in pixels.
|
void |
setRightMargin(int rightMargin)
Set the label's right margin, in pixels.
|
void |
setText(String text)
Set the label's text.
|
void |
setToolTipText(String string) |
void |
setTopMargin(int topMargin)
Set the label's top margin, in pixels.
|
protected String |
shortenText(org.eclipse.swt.graphics.GC gc,
String t,
int width)
Shorten the given text
t so that its length doesn't exceed
the given width. |
drawBackground, getCaret, getIME, scroll, setCaret, setIME
changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
public CLabel(org.eclipse.swt.widgets.Composite parent, int style)
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.
parent
- a widget which will be the parent of the new instance (cannot be null)style
- the style of widget to constructIllegalArgumentException
- org.eclipse.swt.SWTException
- SWT.LEFT
,
SWT.RIGHT
,
SWT.CENTER
,
SWT.SHADOW_IN
,
SWT.SHADOW_OUT
,
SWT.SHADOW_NONE
,
getStyle()
public org.eclipse.swt.graphics.Point computeSize(int wHint, int hHint, boolean changed)
computeSize
in class org.eclipse.swt.widgets.Composite
public int getAlignment()
public int getBottomMargin()
public String getEllipsis()
public int getEllipsisAligment()
public org.eclipse.swt.graphics.Image getImage()
null
.public int getLeftMargin()
public int getRightMargin()
public int getStyle()
getStyle
in class org.eclipse.swt.widgets.Widget
public String getText()
public String getToolTipText()
getToolTipText
in class org.eclipse.swt.widgets.Control
public int getTopMargin()
public void setAlignment(int align)
align
- the alignment style of LEFT, RIGHT or CENTERorg.eclipse.swt.SWTException
- public void setBackground(org.eclipse.swt.graphics.Color color)
setBackground
in class org.eclipse.swt.widgets.Control
public void setBackground(org.eclipse.swt.graphics.Color[] colors, int[] percents)
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});
colors
- an array of Color that specifies the colors to appear in the gradient
in order of appearance from left to right; The value null
clears the background gradient; the value null
can be used
inside the array of Color to specify the background color.percents
- an array of integers between 0 and 100 specifying the percent of the width
of the widget at which the color should change; the size of the percents
array must be one less than the size of the colors array.org.eclipse.swt.SWTException
- public void setBackground(org.eclipse.swt.graphics.Color[] colors, int[] percents, boolean vertical)
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);
colors
- an array of Color that specifies the colors to appear in the gradient
in order of appearance from left/top to right/bottom; The value null
clears the background gradient; the value null
can be used
inside the array of Color to specify the background color.percents
- an array of integers between 0 and 100 specifying the percent of the width/height
of the widget at which the color should change; the size of the percents
array must be one less than the size of the colors array.vertical
- indicate the direction of the gradient. True is vertical and false is horizontal.org.eclipse.swt.SWTException
- public void setBackground(org.eclipse.swt.graphics.Image image)
image
- the image to be drawn in the backgroundorg.eclipse.swt.SWTException
- public void setBottomMargin(int bottomMargin)
bottomMargin
- the bottom margin of the label, which must be equal to or greater than zeroorg.eclipse.swt.SWTException
- public void setEllipsis(String ellipsis)
ellipsis
- the ellipsis to use instead of the DEFAULT_ELLIPSIS
org.eclipse.swt.SWTException
- public void setEllipsisAlignment(int ellipsisAlign)
Use the values LEFT, CENTER, RIGHT, BEGINNING or END to align the ellipsis in the text.
BEGINNING and END are mapped to LEFT and RIGHT according to the current LEFT_TO_RIGHT and RIGHT_TO_LEFT style.
align
- the alignment style of LEFT, RIGHT, CENTER, BEGINNING or ENDorg.eclipse.swt.SWTException
- public void setFont(org.eclipse.swt.graphics.Font font)
setFont
in class org.eclipse.swt.widgets.Canvas
public void setImage(org.eclipse.swt.graphics.Image image)
null
clears it.image
- the image to be displayed in the label or nullorg.eclipse.swt.SWTException
- public void setLeftMargin(int leftMargin)
leftMargin
- the left margin of the label, which must be equal to or greater than zeroorg.eclipse.swt.SWTException
- public void setMargins(int leftMargin, int topMargin, int rightMargin, int bottomMargin)
leftMargin
- the left margin.topMargin
- the top margin.rightMargin
- the right margin.bottomMargin
- the bottom margin.org.eclipse.swt.SWTException
- public void setRightMargin(int rightMargin)
rightMargin
- the right margin of the label, which must be equal to or greater than zeroorg.eclipse.swt.SWTException
- public void setText(String text)
null
clears it.
Mnemonics are indicated by an '&' that causes the next character to be the mnemonic. When the user presses a key sequence that matches the mnemonic, focus is assigned to the control that follows the label. On most platforms, the mnemonic appears underlined but may be emphasised in a platform specific manner. The mnemonic indicator character '&' can be escaped by doubling it in the string, causing a single '&' to be displayed.
text
- the text to be displayed in the label or nullorg.eclipse.swt.SWTException
- public void setToolTipText(String string)
setToolTipText
in class org.eclipse.swt.widgets.Control
public void setTopMargin(int topMargin)
topMargin
- the top margin of the label, which must be equal to or greater than zeroorg.eclipse.swt.SWTException
- protected String shortenText(org.eclipse.swt.graphics.GC gc, String t, int width)
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.gc
- the gc to use for text measurementt
- the text to shortenwidth
- the width to shorten the text to, in pixelsprotected String beginShortenText(org.eclipse.swt.graphics.GC gc, String t, int width, int w)
protected String endShortenText(org.eclipse.swt.graphics.GC gc, String t, int width, int w)
Copyright © 2016 Eclipse NeoSCADA Project. All rights reserved.