3.10.7 - Diamond Button - JdlDiamondButton

John W. Campbell

3.10.7.1 Introduction

This class provides a press button drawn as a diamond shape. The diamond button may also be drawn in a fixed state - either out or in.

Class, fields, constructor and methods:

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

3.10.7.2 Class Details

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

3.10.7.3 Accessible Fields

The following accessible fields have been defined:

public final static int PRESS_BUTTON
Diamond button mode option: Press button.
public final static int STATIC_OUT
Diamond button mode option: Static raised button.
public final static int STATIC_IN
Diamond button mode option: Static inset button.
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 FREE
Size/Location Constraint: free.
public final static int DEFAULT_SIZE
Size Constraint: default (diamond) size (width or height).
public final static int DEFAULT_DIAMOND_SIZE
Default setting for size determining parameter.
static final long serialVersionUID

3.10.7.4 Constructor

3.10.7.4.1 Introduction

A single constructor is available.

Constructor:

Default constructor

3.10.7.4.2 Default constructor

Constructs diamond button with default resources.

Constructor Definition:
public JdlDiamondButton ()
Parameters List:
none

3.10.7.5 Class Methods

3.10.7.5.1 Introduction

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

Methods:

Find start size - findStartSize
Find start size - findStartSize

3.10.7.5.2 Find start size - findStartSize

Determine the required starting (minimum) size for the JdlDiamondButton object based on the required diamond size.

Method Definition:
public static Dimension findStartSize (int diamond_siz)
Parameters List:
diamond_siz
Diamond size in pixels - this is the dimension of a bounding square.
Method Return:
The calculated size (width, height).

3.10.7.5.3 Find start size - findStartSize

Determine the required starting (minimum) size for the JdlDiamondButton object based on the default diamond size.

Method Definition:
public static Dimension findStartSize ()
Parameters List:
none
Method Return:
The calculated size (width, height).

3.10.7.6 Resource Methods

3.10.7.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 'allow resize' - setAllowButtonResize
Get 'allow resize' - getAllowButtonResize
Set border colour - setBorderColor
Set border colour - setBorderColor
Get border colour - getBorderColor
Set border type - setBorderType
Get border type - getBorderType
Set button mode - setButtonMode
Get button mode - getButtonMode
Set diamond size - setDiamondSize
Get diamond size - getDiamondSize
Set diamond bevel - setDiamondBevel
Get diamond bevel - getDiamondBevel
Set 'in' fill colour - setFillColorIn
Get 'in' fill colour - getFillColorIn
Set 'out' fill colour - setFillColorOut
Get 'out' fill colour - getFillColorOut

3.10.7.6.2 Set 'allow resize' - setAllowButtonResize

This method sets the 'allow button resize' resource.

Method Definition:
public void setAllowButtonResize(boolean flag)
Parameters List:
flag
If the object is resized and this flag is set to true then the button will be expanded to fill the largest square which can be fitted into the new area if this size exceeds the size required by the button resources. (The default is false for no such resize - instead the button will be centred in the expanded area).

3.10.7.6.3 Get 'allow resize' - getAllowButtonResize

This method returns the 'allow button resize' resource.

Method Definition:
public boolean getAllowButtonResize()
Parameters List:
none
Method Return:
Resturns the current value of the allow button resize flag.

3.10.7.6.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 button border. If null (the default), use the background colour if a three dimensional button or black if the button has a solid border.

3.10.7.6.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 button border.
darker
A darker colour for a three dimensional button border.

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

3.10.7.6.8 Get border type - getBorderType

This method returns the border type resource.

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.7.6.9 Set button mode - setButtonMode

This method sets the button mode resource.

Method Definition:
public void setButtonMode (int mode)
Parameters List:
mode
The button mode flag:
= 0, button is a press button (default)
= 1, button is a static button in the raised position
= 2, button is a static button in the inset position
(May use variables PRESS_BUTTON, STATIC_OUT, STATIC_IN)

3.10.7.6.10 Get button mode - getButtonMode

This method returns the button mode resource.

Method Definition:
public int getButtonMode ()
Parameters List:
none
Method Return:
Returns the button mode flag:
= 0, button is a press button
= 1, button is a static button in the raised position
= 2, button is a static button in the inset position

3.10.7.6.11 Set diamond size - setDiamondSize

This method sets the diamond size resource.

Method Definition:
public void setDiamondSize(int siz)
Parameters List:
siz
Diamond size in pixels - this is the dimension of a bounding square. (default = 12)

3.10.7.6.12 Get diamond size - getDiamondSize

This method returns the diamond size resource.

Method Definition:
public int getDiamondSize()
Parameters List:
none
Method Return:
Returns the diamond size resource in pixels.

3.10.7.6.13 Set diamond bevel - setDiamondBevel

This method sets the diamond border bevel resource.

Method Definition:
public void setDiamondBevel(int thickness)
Parameters List:
thickness
This is the required diamond border bevel thickness in pixels. (default = 3)

3.10.7.6.14 Get diamond bevel - getDiamondBevel

This method returns the diamond border bevel resource.

Method Definition:
public int getDiamondBevel()
Parameters List:
none
Method Return:
Returns the diamond border bevel thickness in pixels.

3.10.7.6.15 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.7.6.16 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.7.6.17 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.7.6.18 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.7.7 Standard Positioning and Sizing

3.10.7.7.1 Introduction

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

Methods:

Set position constraints - setLocationConstraints
Set size constraints - setSizeConstraints

3.10.7.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.7.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.7.8 Add/Remove Action Listener

3.10.7.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.7.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.7.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.7.9 Overriden Superclass Methods

3.10.7.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 foreground - setForeground
Get minimum size - getMinimumSize
Get preferred size - getPreferredSize

3.10.7.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.7.9.3 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.7.9.4 Get minimum size - getMinimumSize

This method returns the minimum size of the component.

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

3.10.7.9.5 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