Class pvWinJ.PVButton

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----pvWinJ.PVButton

public class PVButton
extends Canvas
implements Serializable

The PVButton class is designed to implement a windows button behavior.
It supports two/three button states,
can keep button pressed,
can draw multiple lines of the button text,
can display another text string in pressed state,
can switch colors and the shadow position in the pressed state,
can create the 3D or aureole text appearance,
can draw the focus rectangle while having the focus,
has various build in border styles.
All aspects of the button's painting and behavior can be customized through get/setProperies().

PVButton supports ActionListener and MouseListener interfaces.
When the property canKeepPressed is set to false, then the actionPerformed is fired when the mouse button is released; othewise the actionPerformed is fired when the mouse button is pressed.

Example to insert an instance of the PVButton class in an applet and set some properties:
public void init()
{
setSize(480, 300);
setLayout(null);
PVButton butt1 = new PVButton("PVButton1", 12, PVButton.STANDARD3);
add(butt1);
butt1.setTextPressed("Pressed");
butt1.setAureole(true);
butt1.setBounds(5, 40, 150, 30);
PVButton butt2 = new PVButton("PVButton2 with multilined text");
add(butt2);
butt2.setMultiLine(true);
butt2.setFont(new Font("Courier", Font.BOLD | Font.ITALIC, 24));
butt2.setText3D(new Dimension(-2, -1));
butt2.setBackColor(Color.orange);
butt2.setCanKeepPressed(true);
butt2.setThreeButtonStates(false);
butt2.setBounds(5, 100, 150, 150);
...
}

Notes:
To set/get background color, the get/setBackColor() should be used rather than the get/setBackground().
When font with aureole is enabled, then the text 3D effect is disabled.


Variable Index

 o DOUBLE
Constant to set border with double raised appearance and 5 pixels width.
 o NONE
Constant to set no border or no shadow.
 o SIMPLE1
Constant to set border with simple raised appearance and 1 pixel width.
 o SIMPLE2
Constant to set border with simple raised appearance and 2 pixels width.
 o SIMPLE3
Constant to set border with simple raised appearance and 3 pixels width.
 o SIMPLE4
Constant to set border with simple raised appearance and 4 pixels width.
 o SIMPLE5
Constant to set border with simple raised appearance and 5 pixels width.
 o STANDARD1
Constant to set border with standard raised 3D appearance and 2 pixels width.
 o STANDARD2
Constant to set border with standard raised 3D appearance and 3 pixels width.
 o STANDARD3
Constant to set border with standard raised 3D appearance and 5 pixels width.
 o VAGUE
Constant to set border without sharp edges and 5 pixels width.

Constructor Index

 o PVButton()
Constructor.
 o PVButton(String)
Constructor.
 o PVButton(String, int, int)
Constructor.

Method Index

 o addActionListener(ActionListener)
Add action listener to the PVButton.
 o addMouseListener(MouseListener)
Add mouse listener to the PVButton.
 o getAureole()
Get text painting style.
 o getAutoResize()
Get option to auto adjust size of the button.
 o getBackColor()
Get color of the button's face.
 o getBorder()
Get border style.
 o getBorderLines()
Get the set of the lines to draw the border.
 o getCanGetFocus()
Get an option to get focus.
 o getCanKeepPressed()
Get button behaviour.
 o getClientRect()
Get size of client rectangle.
 o getExtraPoppedUp()
Get text position.
 o getFocusRect()
Painting the focus rectangle when button has focus.
 o getMultiLine()
Get style of text painting.
 o getPressed()
Get button state.
 o getShadow()
Get shadow style.
 o getShadowColor()
Get shadow color.
 o getShadowWidth()
Get shadow width.
 o getSwitchColorsOnPress()
Get text colors for pressed button state.
 o getSwitchShadowOnPress()
Get shadow style for pressed button state.
 o getText()
Get button text.
 o getText3D()
Get the text 3D effect.
 o getText3DColor()
Get color of the text 3D (highlighted edges) effect or aureole.
 o getTextDimension()
Dimension of the button text.
 o getTextPressed()
Get text for pressed button state.
 o getThreeButtonStates()
Get button behaviour.
 o removeActionListener(ActionListener)
Remove action listener from the PVButton.
 o removeMouseListener(MouseListener)
Remove mouse listener from the PVButton.
 o setAureole(boolean)
Set text painting style.
 o setAutoResize(boolean)
Set button behaviour.
 o setBackColor(Color)
Set color for the button's face.
 o setBorder(int)
Set border style.
 o setBorderLines(int)
Set the set of the lines to draw the border.
 o setCanGetFocus(boolean)
Set an option to get focus.
 o setCanKeepPressed(boolean)
Set button behaviour.
 o setExtraPoppedUp(boolean)
Set additional shift of the text position to the left-top when button is in popped up state.
 o setFocusRect(boolean)
Painting the focus rectangle when button has focus.
 o setMultiLine(boolean)
Set option to draw multilined text.
 o setPressed(boolean)
Set button state.
 o setShadow(int)
Set shadow style.
 o setShadowColor(Color)
Set shadow color.
 o setShadowWidth(int)
Set shadow width.
 o setSwitchColorsOnPress(boolean)
Set text colors for pressed button state.
 o setSwitchShadowOnPress(boolean)
Set shadow style for pressed button state.
 o setText(String)
Set button text.
 o setText3D(Dimension)
Set the text 3D effect.
 o setText3DColor(Color)
Set color of the text 3D (highlighted edges) effect or aureole.
 o setTextPressed(String)
Set text for pressed button state.
 o setThreeButtonStates(boolean)
Set button behaviour.

Variables

 o NONE

 public static final int NONE
Constant to set no border or no shadow. Value is equal 0.
See Also:
setBorder, setShadow

 o SIMPLE1

 public static final int SIMPLE1
Constant to set border with simple raised appearance and 1 pixel width. Value is equal 1.
See Also:
setBorder

 o SIMPLE2

 public static final int SIMPLE2
Constant to set border with simple raised appearance and 2 pixels width. Value is equal 2.
See Also:
setBorder

 o SIMPLE3

 public static final int SIMPLE3
Constant to set border with simple raised appearance and 3 pixels width. Value is equal 3.
See Also:
setBorder

 o SIMPLE4

 public static final int SIMPLE4
Constant to set border with simple raised appearance and 4 pixels width. Value is equal 4.
See Also:
setBorder

 o SIMPLE5

 public static final int SIMPLE5
Constant to set border with simple raised appearance and 5 pixels width. Value is equal 5.
See Also:
setBorder

 o STANDARD1

 public static final int STANDARD1
Constant to set border with standard raised 3D appearance and 2 pixels width. Value is equal 6.
See Also:
setBorder

 o STANDARD2

 public static final int STANDARD2
Constant to set border with standard raised 3D appearance and 3 pixels width. Value is equal 7.
See Also:
setBorder

 o STANDARD3

 public static final int STANDARD3
Constant to set border with standard raised 3D appearance and 5 pixels width. Value is equal 8.
See Also:
setBorder

 o VAGUE

 public static final int VAGUE
Constant to set border without sharp edges and 5 pixels width. Value is equal 9.
See Also:
setBorder

 o DOUBLE

 public static final int DOUBLE
Constant to set border with double raised appearance and 5 pixels width. Value is equal 10.
See Also:
setBorder

Constructors

 o PVButton

 public PVButton(String text,
                 int fontSize,
                 int borderStyle)
Constructor.
Parameters:
text - the text string on the button.
fontSize - the size of the font.
borderStyle - the border style.
Other properties are set:
textPressed - null (the same as text);
font - Arial, bold;
enabled - true;
canKeepButtonPressed - false;
threeButtonStates - true;
switchColorsOnPress - false;
switchShadowOnPress - false;
extraPoppedUp - false;
fontWithAureole - false;
focusRectangle - false;
autoResize - false;
text3D horizontal - 0;
text3D vertical - 0;
shadow - NONE;
shadowWidth - 5;
foreground - black;
backColor - the same as the background color;
shadowColor - darker than the background color;
text3DColor - lighter than the backColor.

 o PVButton

 public PVButton(String text)
Constructor.
Parameters:
text - the button text.
Other properties are set:
fontSize - 12;
border - STANDARD2;

 o PVButton

 public PVButton()
Constructor.
It calls this("Button");

Methods

 o getText

 public String getText()
Get button text.
Returns:
Text string.
See Also:
setText

 o setText

 public void setText(String text)
Set button text.
Parameters:
text - new text string.
See Also:
getText

 o getTextPressed

 public String getTextPressed()
Get text for pressed button state.
Returns:
string that is used to draw button text when button is pressed.
Value null means that the textPressed is the same as the text.
See Also:
setTextPressed, setText

 o setTextPressed

 public void setTextPressed(String textPressed)
Set text for pressed button state.
Parameters:
textPressed - new text string for pressed button state.
See Also:
getTextPressed, setText

 o getBorder

 public int getBorder()
Get border style.
If the border style was set using the setBorderLines, then the return value is equal -1.
Returns:
Border style.
See Also:
setBorder, getBorderLines

 o setBorder

 public void setBorder(int borderStyle)
Set border style.
Parameters:
borderStyle - new border style.
Range of values 0..10.
Predefined constants can be used.
See Also:
getBorder, setBorderLines, NONE, SIMPLE1, SIMPLE2, SIMPLE3, SIMPLE4, STANDARD1, STANDARD2, STANDARD3, VAGUE, DOUBLE

 o getBorderLines

 public int getBorderLines()
Get the set of the lines to draw the border.
Returns:
Combination of border lines.
See Also:
setBorderLines, getBorder

 o setBorderLines

 public void setBorderLines(int lines)
Set the set of the lines to draw the border.
This is an advanced method. It allows to specify number of lines and their color to draw border of the button.
The following rules should be considered:
Every 3 bits (an octal number) represent a line with a particular color. This octal number can be in the range of 1..7. The lower number, - the darker color; and the larger number, - the lighter color of the line. The value 0 means the end of the set.
Up to 5 lines can be specified for right/bottom and left/top edges of the button. The number of lines for both edges should match. The lower 15 bits represent the set of octal numbers to draw right/bottom border, the next 15 bits represent the set for the left/top border and the highest 2 bits are the width factor.
The width factor can be in the range of 0..3. The 0 means that the border is defined by the lower 30 bits as they are. Values 1..3 will increase the border width in 2..4 times.
The count of the lines begins from the right number (inside of the every 15-bits-set) and drawing starts from the outter edge of the button.
To draw sharp raised border with the width of one line, the "lines" can be set to the 00000700001.
The border style SIMPLE3 can be represented in the "borderLines"as the 00066600222, the STANDARD1 can be represented as the 00004600031. To create initially sunken border style that is opposite to the border style STANDARD3 with twice width, the "lines" can be set to the 010432105673
Parameters:
lines - new combination of the border lines.
See Also:
getBorderLines, setBorder

 o getShadow

 public int getShadow()
Get shadow style.
Returns:
Shadow style.
See Also:
setShadow

 o setShadow

 public void setShadow(int shadowStyle)
Set shadow style.
Parameters:
shadowStyle - new shadow style.
0 - no shadow;
1 - shadow at the right-bottom;
2 - shadow at the left-bottom;
3 - shadow at the left-top;
4 - shadow at the right-top.
See Also:
getShadow

 o getShadowWidth

 public int getShadowWidth()
Get shadow width.
Returns:
Shadow width in pixels.
See Also:
setShadowWidth

 o setShadowWidth

 public void setShadowWidth(int shadowWidth)
Set shadow width.
Parameters:
shadowWidth - new shadow width in pixels.
Note: To paint the shadow, the shadowStyle should not be equal 0.
See Also:
getShadowWidth, getShadow

 o getText3D

 public Dimension getText3D()
Get the text 3D effect.
Returns:
Text 3D effect.
See Also:
setText3D

 o setText3D

 public void setText3D(Dimension newText3D)
Set the text 3D effect.
Parameters:
newText3D - horizontal (newText3D.width) and vertical (newText3D.height) shifts of the text 3D from the main text in pixels.
Range of horizontal and vertical shifts: -2..2.
Default value: -1, -1.
Example:
pvButton1.setText3D(new Dimension(1, 0));
See Also:
getText3D

 o getPressed

 public boolean getPressed()
Get button state.
Returns:
State of button.
See Also:
setPressed

 o setPressed

 public void setPressed(boolean buttonPressed)
Set button state.
Parameters:
buttonPressed - sets button state.
Value true - make button pressed, false - release button pressed state.
See Also:
getPressed

 o getAutoResize

 public boolean getAutoResize()
Get option to auto adjust size of the button.
Returns:
An option.
See Also:
setAutoResize

 o setAutoResize

 public void setAutoResize(boolean autoResize)
Set button behaviour.
Parameters:
autoResize - an option.
True - adjust button size to fit text.
False - no size adjustment.
Default - true.
See Also:
getAutoResize

 o getCanKeepPressed

 public boolean getCanKeepPressed()
Get button behaviour.
Returns:
An option.
See Also:
setCanKeepPressed

 o setCanKeepPressed

 public void setCanKeepPressed(boolean canKeepPressed)
Set button behaviour.
Parameters:
canKeepPressed - an option.
Value false allows to keep button in pressed state after mouse-down event, button remains pressed until the next mouse-down event.
Value true anables that behaviour, false - disables.
Default - false.
See Also:
getCanKeepPressed

 o getThreeButtonStates

 public boolean getThreeButtonStates()
Get button behaviour.
Returns:
An option.
See Also:
setThreeButtonStates

 o setThreeButtonStates

 public void setThreeButtonStates(boolean threeButtonStates)
Set button behaviour.
Parameters:
threeButtonStates - an option.
Value true allows three button states:
1. flat - mouse pointer is outside the button;
2. popped up - mouse pointer is inside of button rectangle;
3. pressed - mouse pointer is inside of button rectangle and mouse button is pressed.
Value false sets the standard two states button behaviour.
Default - false.
See Also:
getThreeButtonStates

 o getCanGetFocus

 public boolean getCanGetFocus()
Get an option to get focus.
Returns:
An option.
See Also:
setCanGetFocus

 o setCanGetFocus

 public void setCanGetFocus(boolean canGetFocus)
Set an option to get focus.
Parameters:
canGetFocus - an option.
Value true will allow to get focus on mouse click or tab; false - no focus.
Default - true.
See Also:
getCanGetFocus

 o getFocusRect

 public boolean getFocusRect()
Painting the focus rectangle when button has focus.
Returns:
An option.
See Also:
setFocusRect

 o setFocusRect

 public void setFocusRect(boolean focusRectangle)
Painting the focus rectangle when button has focus.
Parameters:
focusRectangle - an option.
Value true will draw focus rectangle; false - no focus rectangle.
Default - false.

 o getAureole

 public boolean getAureole()
Get text painting style.
Returns:
An option.
See Also:
setAureole

 o setAureole

 public void setAureole(boolean fontWithAureole)
Set text painting style.
Parameters:
fontWithAureole - an option.
Value true anables painting the aureole around every character by text3DColor and 1 pixel wide; text-3D effect is disabled.
Value false - regular text painting with 3D effect if any.
Default value is set to false.
See Also:
getAureole

 o getSwitchColorsOnPress

 public boolean getSwitchColorsOnPress()
Get text colors for pressed button state.
Returns:
An option.
See Also:
setSwitchColorsOnPress

 o setSwitchColorsOnPress

 public void setSwitchColorsOnPress(boolean switchColorsOnPress)
Set text colors for pressed button state.
Parameters:
switchColorsOnPress - an option.
Value true will switch foreground and text3D colors; false will keep on the initial colors.
Default - false.
See Also:
getSwitchColorsOnPress

 o getSwitchShadowOnPress

 public boolean getSwitchShadowOnPress()
Get shadow style for pressed button state.
Returns:
An option.
See Also:
setSwitchShadowOnPress

 o setSwitchShadowOnPress

 public void setSwitchShadowOnPress(boolean switchShadowOnPress)
Set shadow style for pressed button state.
Parameters:
switchShadowOnPress - an option.
Value true will switch shadow position to opposite corner.
Value false will not change shadow position.
Default value is set to false.
See Also:
getSwitchShadowOnPress

 o getExtraPoppedUp

 public boolean getExtraPoppedUp()
Get text position.
Returns:
An option.
See Also:
setExtraPoppedUp

 o setExtraPoppedUp

 public void setExtraPoppedUp(boolean extraPoppedUp)
Set additional shift of the text position to the left-top when button is in popped up state.
Parameters:
extraPoppedUp - an option.
Value true will shift the text 1 pixel up and 1 pixel left from the popped up text position.
Value false will keep text position unchanged.
Default - false.
See Also:
getExtraPoppedUp

 o getMultiLine

 public boolean getMultiLine()
Get style of text painting.
Returns:
An option.
See Also:
setMultiLine

 o setMultiLine

 public void setMultiLine(boolean multiLine)
Set option to draw multilined text.
Parameters:
multiLine - an option.
Value true will draw multilined text.
Value false will draw text in one line.
Default - false.
See Also:
getMultiLine

 o setBackColor

 public void setBackColor(Color color)
Set color for the button's face.
Parameters:
color - Color.
If it is set to the "null", then the background color is used.
Default value is set to the background color (null).
See Also:
getBackColor

 o getBackColor

 public Color getBackColor()
Get color of the button's face.
Returns:
Color of the button.
See Also:
setBackColor

 o getText3DColor

 public Color getText3DColor()
Get color of the text 3D (highlighted edges) effect or aureole.
Returns:
Color of text 3D effect.
See Also:
setText3DColor

 o setText3DColor

 public void setText3DColor(Color color)
Set color of the text 3D (highlighted edges) effect or aureole.
Parameters:
color - Color.
If it is set to the "null", then the color that is lighter than the backColor is used.
Default value is set to the color lighter than the backColor (null).
See Also:
getText3DColor, setBackColor, setText3D, setAureole

 o getShadowColor

 public Color getShadowColor()
Get shadow color.
Returns:
Shadow color.
See Also:
setShadowColor

 o setShadowColor

 public void setShadowColor(Color color)
Set shadow color.
Parameters:
color - Color.
If it is set to the "null", then the color darker than the background color is used.
Default value is set to the color darker than the background color (null).
See Also:
getShadowColor

 o getClientRect

 public Rectangle getClientRect()
Get size of client rectangle.
Returns:
Rectangle of client area (without shadow and border).

 o addActionListener

 public synchronized void addActionListener(ActionListener al)

 o removeActionListener

 public synchronized void removeActionListener(ActionListener al)

 o addMouseListener

 public synchronized void addMouseListener(MouseListener ml)
Example how to use the MouseListener with an instance of the PVButton:
pvbutton1.addMouseListener(new MouseListener()
        {
            public void mouseExited(MouseEvent e)
            { System.err.println("exit");}
            public void mouseEntered(MouseEvent e)
            { System.err.println("enter");}
            public void mouseClicked(MouseEvent e)
            { System.err.println("click");}
            public void mousePressed(MouseEvent e)
            { System.err.println("press");}
            public void mouseReleased(MouseEvent e)
            { System.err.println("release");}
        });
Overrides:
addMouseListener in class Component

 o removeMouseListener

 public synchronized void removeMouseListener(MouseListener ml)
Overrides:
removeMouseListener in class Component