John W. Campbell
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
- 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".
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.
Two constructors are available.
Constructors:
Default constructor
Constructor 2
Constructs a button with default resources.
- Constructor Definition:
- public JdlButton()
- Parameters List:
- none
Constructs a button with a requested label string.
- Constructor Definition:
- public JdlButton(String str)
- Parameters List:
- string
- The label string.
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
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)
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).
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)
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
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)
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.
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)
- Method Definition:
- public int getBorderType()
- Parameters List:
- none
- Method Return:
-
Returns the current border type flag:
= 0, solid
= 1, in/out (3-dimensional)
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.
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.
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.
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.
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.
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.
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.
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.
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.
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).
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)
- Method Definition:
- public int getLabelAlignment()
- Parameters List:
- none
- Method Return:
-
Returns the label alignment flag:
= 0, centre
= 1, left justification
= 2, right justification
This method sets the label font resource.
- Method Definition:
- public void setLabelFont (Font font)
- Parameters List:
- font
- The font for a button label.
This method returns the label font resource.
- Method Definition:
- public Font getLabelFont()
- Parameters List:
- none
- Method Return:
-
Returns the label font.
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).
This method returns the label highlight font resource.
- Method Definition:
- public Font getLabelHighlightFont()
- Parameters List:
- none
- Method Return:
-
Returns the label highlight font.
This method sets the label string resource.
- Method Definition:
- public void setLabelString(String str)
- Parameters List:
- str
- The label string (default = null).
This method returns the label string resource.
- Method Definition:
- public String getLabelString()
- Parameters List:
- none
- Method Return:
-
Returns the label string.
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.
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.
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.
This method returns the surround height resource.
- Method Definition:
- public int getSurroundHeight()
- Parameters List:
- none
- Method Return:
-
Returns the surround height.
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.
This method returns the surround height resource.
- Method Definition:
- public int getSurroundWidth()
- Parameters List:
- none
- Method Return:
-
Returns the surround height.
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.
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
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.
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.
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).
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).
This section has methods to add or remove an action listener.
Methods:
Add action listener - addActionListener
Remove action listener - removeActionListener
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.
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.
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
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.
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.
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.
This method returns the minimum size of the component.
- Method Definition:
- public Dimension getMinimumSize()
- Parameters List:
- none
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