Class pvWinJ.PVImageButton

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

public class PVImageButton
extends PVButton

The PVImageButton class is designed to implement a windows button behavior.
It inherits the PVButton and supports all PVButton methods.
Beside a text string it allows to display an image on the button.
An image and a text string can be displayed on the button with different alignments: bottom, top, center, left, right.
The PVImageButton can display up to 4 images for different button states: popped up, pressed, flat, disabled.
Images can be loaded from files or created at the run time.

All aspects of the button's painting and behavior can be customized through get/setProperies().

PVImageButton 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 PVImageButton class in an applet and set some properties:
public void init()
{
setSize(580, 400);
setLayout(null);

// create an image
Image im = createImage(50, 40);
Graphics gr = im.getGraphics();
gr.setColor(Color.red);
gr.fillRect(0, 0, 50, 40);
gr.setColor(Color.green);
gr.fillOval(5, 5, 40, 30);

PVImageButton imButt = new PVImageButton("ImageButton", 12, PVButton.STANDARD3);
add(imButt);
// set image from the file that is at the applet location
imButt.setFileImageAt("appletFile.gif", 0);
// set image (for pressed button state) that was cteated on the run
imButt.setImageAt(im, 1);
imButt.setTextPressed("Pressed");
imButt.setAureole(true);
imButt.setBounds(5, 40, 200, 100);
...
}

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 BOTTOM
Constant that specifies text and image alignment.
 o CENTER
Constant that specifies text and image alignment.
 o LEFT
Constant that specifies text and image alignment.
 o RIGHT
Constant that specifies text and image alignment.
 o TOP
Constant that specifies text and image alignment.

Constructor Index

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

Method Index

 o drawTriangle(int, int, int)
This method creates two images of triangle and sets them to button.
 o getAlignment()
Get text and image alignment inside of the button rectangle.
 o getFileImageAt(int)
Get a file name for a button image.
 o getImageAt(int)
Get a button image.
 o setAlignment(int)
Set text and image alignment inside of the button rectangle.
 o setFileImageAt(String, int)
Set a button image from the file.
 o setImageAt(Image, int)
Set a button image from the Image.

Variables

 o RIGHT

 public static final int RIGHT
Constant that specifies text and image alignment. Image is painted on on the right, text - the left.
See Also:
setAlignment

 o LEFT

 public static final int LEFT
Constant that specifies text and image alignment. Image is painted on the left, text - on the right.
See Also:
setAlignment

 o BOTTOM

 public static final int BOTTOM
Constant that specifies text and image alignment. Image is painted at the bottom, text - at the top.
See Also:
setAlignment

 o TOP

 public static final int TOP
Constant that specifies text and image alignment. Image is painted at the top, text - at the bottom.
See Also:
setAlignment

 o CENTER

 public static final int CENTER
Constant that specifies text and image alignment. Text and image are painted at the center.
See Also:
setAlignment

Constructors

 o PVImageButton

 public PVImageButton(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:
font - Arial, bold;
textPressed - null;
all four images - null;
all four image files - "";
alignment - right;
enabled - true;
canKeepPressed - false;
threeButtonStates - true;
switchColorsOnPress - false;
switchShadowOnPress - false;
extraPoppedUp - false;
fontWithAureole - false;
focusRect - false;
autoResize - false;
text3D horizontal - 0;
text3D vertical - 0;
shadow - 0(no shadow);
shadowWidth - 5;
foreground - black;
backColor - lightGray;
shadowColor - gray;
text3DColor - white.
See Also:
setImageAt, setFileImageAt, setAlignment

 o PVImageButton

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

 o PVImageButton

 public PVImageButton()
Constructor.
It calls this("ImButton");

Methods

 o setFileImageAt

 public boolean setFileImageAt(String fileImage,
                               int imageID)
Set a button image from the file.
Parameters:
fileImage - the file name that contains the image.
imageID - the id of the image.
Value of this parameter specifies which image is set:
0 - button in popped up state (main image),
1 - button in the pressed state,
2 - button is flat (for 3 button states),
3 - button is disabled.
Note:
In this method the getDocumentBase() of an Applet is used.
Returns:
The true when image is loaded successfully, false - failure to load image.
See Also:
setImageAt, getFileImageAt

 o getFileImageAt

 public String getFileImageAt(int imageID)
Get a file name for a button image.
Parameters:
imageID - the id of the image.
Value of this parameter specifies which image is set:
0 - button in popped up state (main image),
1 - button in the pressed state,
2 - button is flat (for 3 button states),
3 - button is disabled.
Returns:
File name that contains and image.
See Also:
setFileImageAt, getImageAt

 o getAlignment

 public int getAlignment()
Get text and image alignment inside of the button rectangle.
See Also:
setAlignment

 o setAlignment

 public void setAlignment(int textImageAlignment)
Set text and image alignment inside of the button rectangle.
Parameters:
textImageAlignment - an option.
Default value text - right, image - left.
See Also:
RIGHT, LEFT, BOTTOM, TOP, CENTER

 o setImageAt

 public void setImageAt(Image image,
                        int imageID)
Set a button image from the Image.
Parameters:
image - image to be set.
imageID - the id of the image.
Value of this parameter specifies which image is set:
0 - button in popped up state (main image),
1 - button in the pressed state,
2 - button is flat (3 button states),
3 - button is disabled.
Notes:
If main image is not null but any other is null, then the main image is used to display an image for the corresponding button state.
Default values for all four images are set to null.
See Also:
getImageAt, setFileImageAt

 o getImageAt

 public Image getImageAt(int imageID)
Get a button image.
Parameters:
imageID - the id of requested image.
0 - main image,
1 - pressed button image,
2 - flat button image,
3 - disabled button image,
Value of this parameter specifies which image is set: main (button in popped up state), pressed, flat (3 button states), or disabled.
See Also:
setImageAt

 o drawTriangle

 public synchronized void drawTriangle(int iStyle,
                                       int iWidth,
                                       int iHeight)
This method creates two images of triangle and sets them to button.
One image is for main (popped up) button state, the other is for pressed button state.
The colors of triangles are based on the back color of button.
Parameters:
iStyle - type and direction of triangle.
0 - empty triangle directed down with extra square around it,
1 - solid triangle directed to the left;
2 - solid, up;
3 - solid, right;
4 - solid, down.
iWidth - width of the image.
iHeight - height of the image.