3.10.4 - Button - JdlButton

John W. Campbell

3.10.4.1 Introduction

This class provides a press button with a three dimensional look. The button may contain a user supplied string and/or have its drawing area filled by a user supplied JdlButtonDrawer object.

Class, fields, constructor and methods:

Class Details
Accessible Fields
Constructors
Class Methods
Resource Methods
Standard Positioning and Sizing
Add/Remove Action Listener
Overriden Superclass Methods

3.10.4.2 Class Details

Package:
Jdl.JdlView;
Class name:
JdlButton
Class definition:
public class JdlButton
Extends:
JPanel
Implements:
MouseListener
FocusListener
KeyListener
Actions:
An action event will be generated when the button is pressed. The associated action command string is "button pressed".

3.10.4.3 Accessible Fields

The following accessible fields have been defined:

public final static int SOLID
Border type option: Solid.
public final static int INOUT
Border type option: Three dimensional (raised/inset).
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 (preferred size), (width or height) (Note same as the standard PREFERRED flag).
public final static int DEFAULT_BUTTON_BORDER
Default button border.
public final static int DEFAULT_BUTTON_SURROUND_HEIGHT
Default button surround height.
public final static int DEFAULT_BUTTON_SURROUND_WIDTH
Default button 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.4.4 Constructors

3.10.4.4.1 Introduction

Two constructors are available.

Constructors:

Default constructor
Constructor 2

3.10.4.4.2 Default constructor

Constructs a button with default resources.

Constructor Definition:
public JdlButton()
Parameters List:
none

3.10.4.4.3 Constructor 2

Constructs a button with a requested label string.

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

3.10.4.5 Class Methods

3.10.4.5.1 Introduction

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

Methods:

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

3.10.4.5.2 Find start size - findStartSize

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

Method Definition:
public static Dimension findStartSize (String str, Font font, Font fonth)
Parameters List:
str
Button string.
font
Button font.
fonth
Button highlight font (if null then Button font will be used).
Method Return:
The calculated size (width, height)

3.10.4.5.3 Find start size - findStartSize

Determine the required starting (minimum) size for the JdlButton 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.4.5.4 Find start size - findStartSize

Determine the required starting (minimum) size for the JdlButton 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 (must be at least 1).
surround_h
The surround height (must be at least 1).
Method Return:
The calculated size (width, height)

3.10.4.6 Resource Methods

3.10.4.6.1 Introduction

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

Methods:

Set button border - setButtonBorder
Get button border - getButtonBorder
Set border type - setBorderType
This method returns the border type resource. - getBorderType
Set button drawer - setDrawer
Get button drawer - getDrawer
Get drawer identifier - getDrawerId
Set button disable - setDisable
Get button disable - getDisable
Set 'in' fill colour - setFillColorIn
Get 'in' fill colour - getFillColorIn
Set 'out' fill colour - setFillColorOut
Get 'out' fill colour - getFillColorOut
Set string width - setInputStringWidth
Set label alignment - setLabelAlignment
This method returns the label alignment resource. - getLabelAlignment
Set label font - setLabelFont
Get label font - getLabelFont
Set highlight font - setLabelHighlightFont
Get highlight font - getLabelHighlightFont
Set label string - setLabelString
Get label string - getLabelString
Set suppress label - setSuppressLabel
Get suppress label - getSuppressLabel
Set surround height - setSurroundHeight
Get surround height - getSurroundHeight
Set surround width - setSurroundWidth
Get surround width - getSurroundWidth
Set focus option - setUseFocus

3.10.4.6.2 Set button border - setButtonBorder

This method sets the button border resource.

Method Definition:
public void setButtonBorder(int thickness)
Parameters List:
thickness
This is the required Button border thickness in pixels. (default = 4)

3.10.4.6.3 Get button border - getButtonBorder

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

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

3.10.4.6.4 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, in/out (3-dimensional) (the default)
(May use variables SOLID, INOUT)

3.10.4.6.5 This method returns the border type resource. - getBorderType

Method Definition:
public int getBorderType()
Parameters List:
none
Method Return:
Returns the current border type flag:
= 0, solid
= 1, in/out (3-dimensional)

3.10.4.6.6 Set button drawer - setDrawer

This method sets the JdlButtonDrawer object resource.

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

3.10.4.6.7 Get button drawer - getDrawer

This method returns the JdlButtonDrawer object resource.

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

3.10.4.6.8 Get drawer identifier - getDrawerId

This method returns the JdlButtonDrawer identifier resource.

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

3.10.4.6.9 Set button disable - setDisable

This method sets the button disable resource.

Method Definition:
public void setDisable(boolean flag)
Parameters List:
flag
Set the flag to true to disable the button or false (the default) for normal button operation.

3.10.4.6.10 Get button disable - getDisable

This method returns the value of the button disable resource.

Method Definition:
public boolean getDisable()
Parameters List:
none
Method Return:
Returns a flag =true if the button is disabled or false if the button is in its normal mode of operation.

3.10.4.6.11 Set 'in' fill colour - setFillColorIn

This method sets the 'button in' fill colour resource.

Method Definition:
public void setFillColorIn (Color colr)
Parameters List:
colr
The fill colour when the button is in the inset (pressed) state. If null (the default), then the 'button out' fill colour will be used.

3.10.4.6.12 Get 'in' fill colour - getFillColorIn

This method returns the 'button in' fill colour resource.

Method Definition:
public Color getFillColorIn()
Parameters List:
none
Method Return:
Returns the current value of the 'button in' fill colour resource.

3.10.4.6.13 Set 'out' fill colour - setFillColorOut

This method sets the 'button out' fill colour resource.

Method Definition:
public void setFillColorOut (Color colr)
Parameters List:
colr
The fill colour when the button is in the raise (unpressed) state. If null (the default), then the background colour will be used.

3.10.4.6.14 Get 'out' fill colour - getFillColorOut

This method returns the 'button out' fill colour resource.

Method Definition:
public Color getFillColorOut()
Parameters List:
none
Method Return:
Returns the current value of the 'button out' fill colour resource.

3.10.4.6.15 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.4.6.16 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.4.6.17 This method returns the label alignment resource. - getLabelAlignment

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.4.6.18 Set label font - setLabelFont

This method sets the label font resource.

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

3.10.4.6.19 Get label 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.4.6.20 Set highlight font - setLabelHighlightFont

This method sets the label highlight font resource (font used when pointer is in button window) - the suggested font is the bold version equivalent of the label font.

Method Definition:
public void setLabelHighlightFont (Font font)
Parameters List:
font
The font for a button label (default of null = do not change font when pointer is in button window).

3.10.4.6.21 Get highlight font - getLabelHighlightFont

This method returns the label highlight font resource.

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

3.10.4.6.22 Set label string - 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.4.6.23 Get label string - getLabelString

This method returns the label string resource.

Method Definition:
public String getLabelString()
Parameters List:
none
Method Return:
Returns the label string.

3.10.4.6.24 Set suppress label - setSuppressLabel

This method sets the 'suppress label' resource.

Method Definition:
public void setSuppressLabel (boolean flag)
Parameters List:
flag
Set this flag to true if the label output is to be suppressed or false if it is to be shown (the default). Note that the label is drawn after any drawer routine has been invoked unless suppressed by this flag.

3.10.4.6.25 Get suppress label - getSuppressLabel

This method returns the value of the 'suppress label' resource.

Method Definition:
public boolean getSuppressLabel()
Parameters List:
none
Method Return:
Returns the value of the suppress label resource.

3.10.4.6.26 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 button border and the top and bottom of the label text (default = 2) - must be at least 1 to allow for focus indication.

3.10.4.6.27 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.4.6.28 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 button border and the left and right of the label text (default = 4) - must be at least 1 to allow for focus indication.

3.10.4.6.29 Get surround width - getSurroundWidth

This method returns the surround height resource.

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

3.10.4.6.30 Set focus option - setUseFocus

This method sets the required keyboard focus option.

Method Definition:
public void setUseFocus(boolean on)
Parameters List:
on
If on is true, display a dotted border around the button text area when the button has the keyboard focus and respond to a Carriage Return or Enter key press as for a button press (default). If false, do not indicate focus or respond to a Carriage Return or Enter key press.

3.10.4.7 Standard Positioning and Sizing

3.10.4.7.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.4.7.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.4.7.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.4.7.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.4.7.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.4.8 Add/Remove Action Listener

3.10.4.8.1 Introduction

This section has methods to add or remove an action listener.

Methods:

Add action listener - addActionListener
Remove action listener - removeActionListener

3.10.4.8.2 Add action listener - addActionListener

This adds the specified action listener to receive action events from this object.

Method Definition:
public void addActionListener(ActionListener listener)
Parameters List:
listener
The action listener to be added.

3.10.4.8.3 Remove action listener - removeActionListener

This removes the specified action listener so that it no longer receives action events from this object.

Method Definition:
public void removeActionListener(ActionListener listener)
Parameters List:
listener
The action listener to be removed.

3.10.4.9 Overriden Superclass Methods

3.10.4.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.4.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.4.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.4.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.4.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.4.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