3.10.2 - Label - JdlLabel

John W. Campbell

3.10.2.1 Introduction

This class provides a label with an optional border. The label may contain a user supplied string and/or have its drawing area filled by a user supplied JdlLabelDrawer object.

Class, fields, constructor and methods:

Class Details
Accessible Fields
Constructor
Class Methods
Operational Methods
Resource Methods
Standard Positioning and Sizing
Overriden Superclass Methods

3.10.2.2 Class Details

Package:
Jdl.JdlView;
Class name:
JdlLabel
Class definition:
public class JdlLabel
Extends:
JPanel
Implements:
none
Actions:
none

3.10.2.3 Accessible Fields

The following accessible fields have been defined:

public final static int SOLID
Border type option: Solid.
public final static int INSET
Border type option: Three dimensional (inset).
public final static int RAISED
Border type option: Three dimensional (raised).
public final static int CENTER
Label alignment: centred.
public final static int LEFT
Label alignment: left justified.
public final static int RIGHT
Label alignment: right justified.
public final static int STRING_SIZE
Size Constraint: string size (width or height).
public final static int DEFAULT_LABEL_BORDER
Default label border.
public final static int DEFAULT_LABEL_SURROUND_HEIGHT
Default label surround height.
public final static int DEFAULT_LABEL_SURROUND_WIDTH
Default label surround width.
static final long serialVersionUID
public final static int PREFERRED
Size Constraint: preferred size.
public final static int FREE
Size/Location Constraint: free.

3.10.2.4 Constructor

3.10.2.4.1 Introduction

Four constructors are available.

Constructor:

Default constructor
Constructor 2
Constructor 3
Constructor 4

3.10.2.4.2 Default constructor

Constructs a label with default resources.

Constructor Definition:
public JdlLabel()
Parameters List:
none

3.10.2.4.3 Constructor 2

Constructs a label with a requested label string and the default font.

Constructor Definition:
public JdlLabel(String string)
Parameters List:
string
The label string.

3.10.2.4.4 Constructor 3

Constructs a label with a requested label string and font.

Constructor Definition:
public JdlLabel(String string, Font font)
Parameters List:
string
The label string.
font
The font for the label string.

3.10.2.4.5 Constructor 4

Constructs a blank label of a given size

Constructor Definition:
public JdlLabel(int w, int h)
Parameters List:
w
Label width
h
Label height

3.10.2.5 Class Methods

3.10.2.5.1 Introduction

This section has methods to determine the required size for the object.

Method:

Find size - findStartSize
Find size - findStartSize
Find size - findStartSize

3.10.2.5.2 Find size - findStartSize

Determine the required starting (minimum) size for the JdlLabel object based on the relevant parameters (from string & font with default border & surround parameters).

Method Definition:
public static Dimension findStartSize (String str, Font font)
Parameters List:
str
Label string.
font
Label font.
Method Return:
The calculated size (width, height).

3.10.2.5.3 Find size - findStartSize

Determine the required starting (minimum) size for the JdlLabel object based on the relevant parameters (from pre-determined string size with default border & surround parameters).

Method Definition:
public static Dimension findStartSize (int w, int h)
Parameters List:
w
Pre-calculated string width.
h
Pre-calculated string height.
Method Return:
The calculated size (width, height).

3.10.2.5.4 Find size - findStartSize

Determine the required starting (minimum) size for the JdlLabel object based on the relevant parameters (from pre-determined string size, border & surround parameters).

Method Definition:
public static Dimension findStartSize (int w, int h, int brdr, int surround_w, int surround_h)
Parameters List:
w
Pre-calculated string width.
h
Pre-calculated string height.
brdr
Border width.
surround_w
The surround width.
surround_h
The surround height.
Method Return:
The calculated size (width, height).

3.10.2.6 Operational Methods

3.10.2.6.1 Introduction

This section contains the main methods used with normal operation of the object.

Methods:

Set label - setLabelString

3.10.2.6.2 Set label - setLabelString

This method sets the label string resource.

Method Definition:
public void setLabelString(String str)
Parameters List:
str
The label string (default = null).

3.10.2.7 Resource Methods

3.10.2.7.1 Introduction

This section has methods to set/get the resources associated with the object determining its appearance and mode of action.

Methods:

Set border - setLabelBorder
Get border - getLabelBorder
Set border colour - setBorderColor
Set border colour - setBorderColor
Get border colour - getBorderColor
Set border type - setBorderType
Get border type - getBorderType
Set label drawer - setDrawer
Get label drawer - getDrawer
Get drawer identifier - getDrawerId
Set fill colour - setFillColor
Get fill colour - getFillColor
Set string width - setInputStringWidth
Set label alignment - setLabelAlignment
Get label alignment - getLabelAlignment
Set font - setLabelFont
Get font - getLabelFont
Set surround height - setSurroundHeight
Get surround height - getSurroundHeight
Set surround width - setSurroundWidth
Get surround width - getSurroundWidth

3.10.2.7.2 Set border - setLabelBorder

This method sets the label border resource.

Method Definition:
public void setLabelBorder(int thickness)
Parameters List:
thickness
This is the required Label border thickness in pixels. (default = 0 - no border)

3.10.2.7.3 Get border - getLabelBorder

This method returns the current value of the label border resource.

Method Definition:
public int getLabelBorder()
Parameters List:
none
Method Return:
Returns the arrow border thickness in pixels.

3.10.2.7.4 Set border colour - setBorderColor

This method sets the border colour resource.

Method Definition:
public void setBorderColor (Color colr)
Parameters List:
colr
The border colour - sets this colour for a solid border or lighter and darker shades of if for a three dimensional label border. If null (the default), use the background colour if a three dimensional label or black if the label has a solid border.

3.10.2.7.5 Set border colour - setBorderColor

This method sets the border colour resources.

Method Definition:
public void setBorderColor (Color colr, Color brighter, Color darker)
Parameters List:
colr
The border colour - sets the colour for a solid border.
brighter
A brighter colour for a three dimensional label border.
darker
A darker colour for a three dimensional label border.

3.10.2.7.6 Get border colour - getBorderColor

This method returns the border colour resource.

Method Definition:
public Color getBorderColor()
Parameters List:
none
Method Return:
Returns the border colour resource as set.

3.10.2.7.7 Set border type - setBorderType

This method sets the border type resource.

Method Definition:
public void setBorderType (int type)
Parameters List:
type
Border type flag:
= 0, solid
= 1, inset (3-D)
= 2, raised (3D)
(May use variables SOLID, INSET, RAISED)

3.10.2.7.8 Get border type - getBorderType

This method returns the border type resource.

Method Definition:
public int getBorderType()
Parameters List:
none
Method Return:
Returns the border type flag:
= 0, solid
= 1, inset (3-D)
= 2, raised (3D)

3.10.2.7.9 Set label drawer - setDrawer

This method sets the JdlLabelDrawer object resource.

Method Definition:
public void setDrawer (JdlLabelDrawer dr, int id)
Parameters List:
dr
A JdlLabelDrawer interfaced object to carry out the drawing on the label (default = null). Its jdl_label_drawer method is called from the paint routine after the border has been drawn. The parameters include details of the label size and state. Unless suppressed the label string (if defined) will be drawn on the label after the drawing routine has been invoked.
id
Identifier to be passed to the drawing method when called.

3.10.2.7.10 Get label drawer - getDrawer

This method returns the JdlLabelDrawer object resource.

Method Definition:
public JdlLabelDrawer getDrawer()
Parameters List:
none
Method Return:
Returns the currently installed JdlLabelDrawer object or null if none has been set up.

3.10.2.7.11 Get drawer identifier - getDrawerId

This method returns the JdlLabelDrawer identifier resource.

Method Definition:
public int getDrawerId()
Parameters List:
none
Method Return:
Returns the identifier of the currently installed JdlLabelDrawer object.

3.10.2.7.12 Set fill colour - setFillColor

This method sets the label fill colour resource.

Method Definition:
public void setFillColor (Color colr)
Parameters List:
colr
The fill colour for the label. If null (the default), then the background colour will be used.

3.10.2.7.13 Get fill colour - getFillColor

This method returns the label fill colour resource.

Method Definition:
public Color getFillColor()
Parameters List:
none
Method Return:
Returns the current value of the label fill colour resource.

3.10.2.7.14 Set string width - setInputStringWidth

This method sets a pre-calculated string width to override the string width calculated from the current label string.

Method Definition:
public void setInputStringWidth (int width)
Parameters List:
string_width
The pre-calculated string width (default =0, ignore).

3.10.2.7.15 Set label alignment - setLabelAlignment

This method sets the label alignment resource.

Method Definition:
public void setLabelAlignment (int align)
Parameters List:
align
A flag indicating the required label alignment:
= 0, to centre
= 1, for left justification
= 2, for right justification
(May use the variables CENTER, LEFT, RIGHT)

3.10.2.7.16 Get label alignment - getLabelAlignment

This method returns the label alignment resource.

Method Definition:
public int getLabelAlignment()
Parameters List:
none
Method Return:
Returns the label alignment flag:
= 0, centre
= 1, left justification
= 2, right justification

3.10.2.7.17 Set font - setLabelFont

This method sets the label font resource.

Method Definition:
public void setLabelFont (Font font)
Parameters List:
font
The font for a label label

3.10.2.7.18 Get font - getLabelFont

This method returns the label font resource.

Method Definition:
public Font getLabelFont()
Parameters List:
none
Method Return:
Returns the label font.

3.10.2.7.19 Set surround height - setSurroundHeight

This method sets the surround height resource.

Method Definition:
public void setSurroundHeight(int minh)
Parameters List:
minh
The minimum height required between the label border and the top and bottom of the label text (default = 2)

3.10.2.7.20 Get surround height - getSurroundHeight

This method returns the surround height resource.

Method Definition:
public int getSurroundHeight()
Parameters List:
none
Method Return:
Returns the surround height.

3.10.2.7.21 Set surround width - setSurroundWidth

This method sets the surround width resource.

Method Definition:
public void setSurroundWidth(int minw)
Parameters List:
minw
The minimum width required between the label border and the left and right of the label text (default = 2)

3.10.2.7.22 Get surround width - getSurroundWidth

This method returns the surround width resource.

Method Definition:
public int getSurroundWidth()
Parameters List:
none
Method Return:
Returns the surround width.

3.10.2.8 Standard Positioning and Sizing

3.10.2.8.1 Introduction

This section contains the standard methods for positioning and sizing the object.

Methods:

Set position constraints - setLocationConstraints
Set size constraints - setSizeConstraints
Set minimum height - setMinimumHeight
Set minimum width - setMinimumWidth

3.10.2.8.2 Set position constraints - setLocationConstraints

Set constraints on the Jdl object positioning.

Method Definition:
public void setLocationConstraints (int constraint_x, int constraint_y)
Parameters List:
constraint_x
Constrain the Jdl Object 'x' position = the required Jdl Object 'x' position (overrides setLocation method) or FREE if the 'x' position may be set by the setLocation method and hence possibly by the layout manager.
constraint_y
Constrain the Jdl Object 'y' position = the required the Jdl Object 'y'position (overrides setLocation method) or FREE if the 'y' position may be set by the setLocation method and hence possibly by the layout manager.

3.10.2.8.3 Set size constraints - setSizeConstraints

Set constraints on the Jdl Object resizing permitted.

Method Definition:
public void setSizeConstraints (int constraint_w, int constraint_h)
Parameters List:
constraint_w
Constrain the Jdl Object width = the required Jdl Object width, or PREFERRED (default) if the width is to be calculated from the current resources, or FREE if the width may be resized to anything greater than the minimum width required.
constraint_h
Constrain the Jdl Object height = the required Jdl Object height, or PREFERRED (default) if the height is to be calculated from the current resources, or FREE if the height may be resized to anything greater than the minimum height required.

3.10.2.8.4 Set minimum height - setMinimumHeight

Set the minimum height resource.

Method Definition:
public void setMinimumHeight(int minh)
Parameters List:
minh
The minimum height required for the object (ignored if less than that required by the minimum layout) (default = 0).

3.10.2.8.5 Set minimum width - setMinimumWidth

Set the minimum width resource.

Method Definition:
public void setMinimumWidth(int minw)
Parameters List:
minh
The minimum width required for the object (ignored if less than that required by the minimum layout) (default = 0).

3.10.2.9 Overriden Superclass Methods

3.10.2.9.1 Introduction

This section contains methods which override the corresponding superclass methods. These are basically standard for JdlView objects and comprise methods to set background and foreground colours and to get the minimum and preferred sizes for the object. (The paintComponent method is also over-ridden but is not normally called by the user).

Methods:

Set background - setBackground
Set background colours - setBackground
Set foreground - setForeground
Get minimum size - getMinimumSize
Get preferred size - getPreferredSize

3.10.2.9.2 Set background - setBackground

This method sets the background colour resource.

Method Definition:
public void setBackground (Color c)
Parameters List:
c
The color to become this object's background color.

3.10.2.9.3 Set background colours - setBackground

This method sets the background colour resource and brighter and darker shades of that colour (e.g. for 3-D frames).

Method Definition:
public void setBackground (Color c, Color brighter, Color darker)
Parameters List:
c
The background colour.
brighter
A brighter shade of the background colour.
darker
A darker shade of the background colour.

3.10.2.9.4 Set foreground - setForeground

This method sets the foreground colour resource.

Method Definition:
public void setForeground (Color c)
Parameters List:
c
The color to become this object's foreground color.

3.10.2.9.5 Get minimum size - getMinimumSize

This method returns the minimum size of the component.

Method Definition:
public Dimension getMinimumSize()
Parameters List:
none

3.10.2.9.6 Get preferred size - getPreferredSize

This method returns the preferred size of the component.

Method Definition:
public Dimension getPreferredSize()
Parameters List:
none

⇑ Up 3   ⇑ Up 2   ⇑ Up 1   ⇑ Top of this