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.
DOUBLE
- Constant to set border with double raised appearance and 5 pixels width.
NONE
- Constant to set no border or no shadow.
SIMPLE1
- Constant to set border with simple raised appearance and 1 pixel width.
SIMPLE2
- Constant to set border with simple raised appearance and 2 pixels width.
SIMPLE3
- Constant to set border with simple raised appearance and 3 pixels width.
SIMPLE4
- Constant to set border with simple raised appearance and 4 pixels width.
SIMPLE5
- Constant to set border with simple raised appearance and 5 pixels width.
STANDARD1
- Constant to set border with standard raised 3D appearance and 2 pixels width.
STANDARD2
- Constant to set border with standard raised 3D appearance and 3 pixels width.
STANDARD3
- Constant to set border with standard raised 3D appearance and 5 pixels width.
VAGUE
- Constant to set border without sharp edges and 5 pixels width.
PVButton()
- Constructor.
PVButton(String)
- Constructor.
PVButton(String, int, int)
- Constructor.
addActionListener(ActionListener)
- Add action listener to the PVButton.
addMouseListener(MouseListener)
- Add mouse listener to the PVButton.
getAureole()
- Get text painting style.
getAutoResize()
- Get option to auto adjust size of the button.
getBackColor()
- Get color of the button's face.
getBorder()
- Get border style.
getBorderLines()
- Get the set of the lines to draw the border.
getCanGetFocus()
- Get an option to get focus.
getCanKeepPressed()
- Get button behaviour.
getClientRect()
- Get size of client rectangle.
getExtraPoppedUp()
- Get text position.
getFocusRect()
- Painting the focus rectangle when button has focus.
getMultiLine()
- Get style of text painting.
getPressed()
- Get button state.
getShadow()
- Get shadow style.
getShadowColor()
- Get shadow color.
getShadowWidth()
- Get shadow width.
getSwitchColorsOnPress()
- Get text colors for pressed button state.
getSwitchShadowOnPress()
- Get shadow style for pressed button state.
getText()
- Get button text.
getText3D()
- Get the text 3D effect.
getText3DColor()
- Get color of the text 3D (highlighted edges) effect or aureole.
getTextDimension()
- Dimension of the button text.
getTextPressed()
- Get text for pressed button state.
getThreeButtonStates()
- Get button behaviour.
removeActionListener(ActionListener)
- Remove action listener from the PVButton.
removeMouseListener(MouseListener)
- Remove mouse listener from the PVButton.
setAureole(boolean)
- Set text painting style.
setAutoResize(boolean)
- Set button behaviour.
setBackColor(Color)
- Set color for the button's face.
setBorder(int)
- Set border style.
setBorderLines(int)
- Set the set of the lines to draw the border.
setCanGetFocus(boolean)
- Set an option to get focus.
setCanKeepPressed(boolean)
- Set button behaviour.
setExtraPoppedUp(boolean)
- Set additional shift of the text position to the left-top when button is in popped up
state.
setFocusRect(boolean)
- Painting the focus rectangle when button has focus.
setMultiLine(boolean)
- Set option to draw multilined text.
setPressed(boolean)
- Set button state.
setShadow(int)
- Set shadow style.
setShadowColor(Color)
- Set shadow color.
setShadowWidth(int)
- Set shadow width.
setSwitchColorsOnPress(boolean)
- Set text colors for pressed button state.
setSwitchShadowOnPress(boolean)
- Set shadow style for pressed button state.
setText(String)
- Set button text.
setText3D(Dimension)
- Set the text 3D effect.
setText3DColor(Color)
- Set color of the text 3D (highlighted edges) effect or aureole.
setTextPressed(String)
- Set text for pressed button state.
setThreeButtonStates(boolean)
- Set button behaviour.
NONE
public static final int NONE
- Constant to set no border or no shadow. Value is equal 0.
- See Also:
- setBorder, setShadow
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
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
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
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
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
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
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
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
VAGUE
public static final int VAGUE
- Constant to set border without sharp edges and 5 pixels width. Value is equal 9.
- See Also:
- setBorder
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
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.
PVButton
public PVButton(String text)
- Constructor.
- Parameters:
- text - the button text.
Other properties are set:
fontSize - 12;
border - STANDARD2;
PVButton
public PVButton()
- Constructor.
It calls this("Button");
getText
public String getText()
- Get button text.
- Returns:
- Text string.
- See Also:
- setText
setText
public void setText(String text)
- Set button text.
- Parameters:
- text - new text string.
- See Also:
- getText
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
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
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
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
getBorderLines
public int getBorderLines()
- Get the set of the lines to draw the border.
- Returns:
- Combination of border lines.
- See Also:
- setBorderLines, getBorder
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
getShadow
public int getShadow()
- Get shadow style.
- Returns:
- Shadow style.
- See Also:
- setShadow
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
getShadowWidth
public int getShadowWidth()
- Get shadow width.
- Returns:
- Shadow width in pixels.
- See Also:
- setShadowWidth
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
getText3D
public Dimension getText3D()
- Get the text 3D effect.
- Returns:
- Text 3D effect.
- See Also:
- setText3D
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
getPressed
public boolean getPressed()
- Get button state.
- Returns:
- State of button.
- See Also:
- setPressed
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
getAutoResize
public boolean getAutoResize()
- Get option to auto adjust size of the button.
- Returns:
- An option.
- See Also:
- setAutoResize
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
getCanKeepPressed
public boolean getCanKeepPressed()
- Get button behaviour.
- Returns:
- An option.
- See Also:
- setCanKeepPressed
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
getThreeButtonStates
public boolean getThreeButtonStates()
- Get button behaviour.
- Returns:
- An option.
- See Also:
- setThreeButtonStates
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
getCanGetFocus
public boolean getCanGetFocus()
- Get an option to get focus.
- Returns:
- An option.
- See Also:
- setCanGetFocus
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
getFocusRect
public boolean getFocusRect()
- Painting the focus rectangle when button has focus.
- Returns:
- An option.
- See Also:
- setFocusRect
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.
getAureole
public boolean getAureole()
- Get text painting style.
- Returns:
- An option.
- See Also:
- setAureole
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
getSwitchColorsOnPress
public boolean getSwitchColorsOnPress()
- Get text colors for pressed button state.
- Returns:
- An option.
- See Also:
- setSwitchColorsOnPress
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
getSwitchShadowOnPress
public boolean getSwitchShadowOnPress()
- Get shadow style for pressed button state.
- Returns:
- An option.
- See Also:
- setSwitchShadowOnPress
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
getExtraPoppedUp
public boolean getExtraPoppedUp()
- Get text position.
- Returns:
- An option.
- See Also:
- setExtraPoppedUp
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
getMultiLine
public boolean getMultiLine()
- Get style of text painting.
- Returns:
- An option.
- See Also:
- setMultiLine
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
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
getBackColor
public Color getBackColor()
- Get color of the button's face.
- Returns:
- Color of the button.
- See Also:
- setBackColor
getText3DColor
public Color getText3DColor()
- Get color of the text 3D (highlighted edges) effect or aureole.
- Returns:
- Color of text 3D effect.
- See Also:
- setText3DColor
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
getShadowColor
public Color getShadowColor()
- Get shadow color.
- Returns:
- Shadow color.
- See Also:
- setShadowColor
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
getClientRect
public Rectangle getClientRect()
- Get size of client rectangle.
- Returns:
- Rectangle of client area (without shadow and border).
addActionListener
public synchronized void addActionListener(ActionListener al)
removeActionListener
public synchronized void removeActionListener(ActionListener al)
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
removeMouseListener
public synchronized void removeMouseListener(MouseListener ml)
- Overrides:
- removeMouseListener in class Component