home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
ProgressBar.java
< prev
next >
Wrap
Text File
|
1998-10-20
|
35KB
|
1,139 lines
package symantec.itools.awt.util;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Image;
import java.awt.MediaTracker;
import java.beans.PropertyVetoException;
import java.beans.PropertyChangeListener;
import java.beans.VetoableChangeListener;
import java.beans.PropertyChangeEvent;
import symantec.itools.awt.AlignStyle;
import symantec.itools.awt.BevelStyle;
import symantec.itools.awt.util.ColorUtils;
import symantec.itools.util.GeneralUtils;
// 06/02/97 TG Updated to support Java 1.1
// Made properties bound & constrained
// 06/09/97 LAB Polished for 1.1. Added binding and constraining to setValue(...)
// 07/18/97 LAB Changed incorrect calls to invalidate() to repaint(). Deprecated preferredSize and
// minimumSize in favor of getPreferredSize and getMinimumSize
// 08/26/97 LAB Changed the default bevel style to line (Addresses Mac Bug #7380). Changed the
// property name strings in bound and constrained event messages to match the Bean
// Spec naming conventions. Deprecated ProgressBarTextColor property and made the
// text use the Foreground color (Addresses Mac Bug #7498). Made the bar use an
// offscreen buffer to draw into to eliminate flicker when in box mode. Deprecated
// BorderedColor property in favor of BorderColor. Updated the way the component
// draws itself (Addresses Mac Bug #7492).
// 08/27/97 LAB Removed an unnecessary fillRect in updateBufferImage.
// 10/23/97 LAB Constrained the BoxWidth and GapWidth properties (Addresses Mac Bug #9702).
/**
* ProgressBar component.
* Creates a bar that displays a percentage.
* Commonly used to indicate the percentage completed of a
* lengthy task.
* @version 1.1, August 26, 1997
* @author Symantec
*/
public class ProgressBar extends Canvas implements BevelStyle, AlignStyle
{
/**
* Border Indent constant INDENT_ZERO.
*/
public static final int INDENT_ZERO = 0;
/**
* Border Indent constant INDENT_ONE.
*/
public static final int INDENT_ONE = 1;
/**
* Border Indent constant INDENT_TWO.
*/
public static final int INDENT_TWO = 2;
/**
* Constructs a progress bar with a centered progress %, line border and zero indentation.
*/
public ProgressBar()
{
this(ALIGN_CENTERED, BEVEL_LINE, INDENT_ZERO);
}
/**
* Constructs a progress bar with the style and indentation variables specified.
* The default parameters are the border color and progress % color as black, the progress bar color
* as blue.
* @param align progress bar alignment style
* @param bevel progress bar bevel style
* @param indent border indent INDENT_ZERO, INDENT_ONE, or INDENT_TWO
*/
public ProgressBar(int align, int bevel, int indent)
{
// set default values
borderColor = Color.black;
progressColor = Color.blue;
bShowProgress = true;
bDrawBoxes = false;
progress = 0;
boxWidth = 8;
gapWidth = 2;
cachedBackground = getBackground();
// process arguments
try
{
setBorderIndent(indent, false);
setBevelStyle(bevel);
setAlignStyle(align);
}
catch(PropertyVetoException veto) {};
//Hook up listeners here so bad values set before addNotify is called get range checked.
if (boxVeto == null)
{
boxVeto = new BoxVeto();
addBoxWidthListener(boxVeto);
}
if (gapVeto == null)
{
gapVeto = new GapVeto();
addGapWidthListener(gapVeto);
}
}
/**
* Set the color that the progress bar will be drawn in.
* @param color the color that the progress bar will be drawn in.
* @see #getProgressBarColor
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void setProgressBarColor(Color c) throws PropertyVetoException
{
if (!symantec.itools.util.GeneralUtils.objectsEqual(progressColor,c))
{
Color oldValue = progressColor;
vetos.fireVetoableChange("progressBarColor", oldValue, c);
progressColor = c;
repaint();
changes.firePropertyChange("progressBarColor", oldValue, c);
}
}
/**
* Get the color that the progress bar will be drawing in. The default color is blue.
* @return Color that the Progress Bar will be drawn in.
* @see #setProgressBarColor
*/
public Color getProgressBarColor()
{
return progressColor;
}
/**
* @deprecated
* @see java.awt.Component#setForeground
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void setProgressBarTextColor(Color c) throws PropertyVetoException
{
setForeground(c);
}
/**
* @deprecated
* @see java.awt.Component#getForeground()
*/
public Color getProgressBarTextColor()
{
return getForeground();
}
/**
* Set the boolean that controls the drawing of the progress bar as a series of boxes.
* @param b indicating if the bar should be composed of multiple boxes.
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getDrawBoxes
*/
public void setDrawBoxes(boolean b) throws PropertyVetoException
{
if (bDrawBoxes != b)
{
Boolean oldDrawBoxesBoolean = new Boolean(bDrawBoxes);
Boolean newDrawBoxesBoolean = new Boolean(b);
vetos.fireVetoableChange("drawBoxes", oldDrawBoxesBoolean, newDrawBoxesBoolean);
bDrawBoxes = b;
repaint();
changes.firePropertyChange("drawBoxes", oldDrawBoxesBoolean, newDrawBoxesBoolean);
}
}
/**
* Get the boolean that controls the drawing of the progress bar as a series of boxes.
* The default value is false.
* @return boolean indicating if the bar should be composed of multiple boxes.
* @see #setDrawBoxes
*/
public boolean isDrawBoxes()
{
return bDrawBoxes;
}
/**
* @deprecated
* @see #isDrawBoxes()
*/
public boolean getDrawBoxes()
{
return isDrawBoxes();
}
/**
* Set the width of the boxes drawn for the progress bar.
* @param i the pixel width of the boxes in the progress bar.
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getBoxWidth
*/
public void setBoxWidth(int i) throws PropertyVetoException
{
Integer newValue = new Integer(i);
Integer oldValue = new Integer(boxWidth);
vetos.fireVetoableChange("boxWidth", oldValue, newValue);
boxWidth = i;
repaint();
changes.firePropertyChange("boxWidth", oldValue, newValue);
}
/**
* Get the width of the boxes drawn for the progress bar. The default value is 8 pixels.
* @return int the pixel width of the boxes in the progress bar.
* @see #setBoxWidth
*/
public int getBoxWidth()
{
return boxWidth;
}
/**
* Set the gap width between boxes drawn for the progress bar.
* @param i the pixel width of the boxes in the progress bar.
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getBoxWidth
* @see #getGapWidth
*/
public void setGapWidth(int i) throws PropertyVetoException
{
Integer newValue = new Integer(i);
Integer oldValue = new Integer(gapWidth);
vetos.fireVetoableChange("gapWidth", oldValue, newValue);
gapWidth = i;
repaint();
changes.firePropertyChange("gapWidth", oldValue, newValue);
}
/**
* Get the gap width of the boxes drawn for the progress bar. The default value is 2 pixels.
* @return i the pixel width of the gap between boxes in the progress bar.
* @see #setBoxWidth
* @see #setGapWidth
*/
public int getGapWidth()
{
return gapWidth;
}
/**
* @deprecated
* @see #isShowProgress
*/
public boolean getShowProgress()
{
return isShowProgress();
}
/**
* Set the boolean that controls the display of the progress number as an percentage.
* @param b indicating if the progress percentage should be displayed.
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getShowProgress
*/
public void setShowProgress(boolean b) throws PropertyVetoException
{
if ( bShowProgress != b)
{
Boolean oldValue = new Boolean(bShowProgress);
Boolean newValue = new Boolean(b);
vetos.fireVetoableChange("showProgress", oldValue, newValue);
bShowProgress = b;
repaint();
changes.firePropertyChange("showProgress", oldValue, newValue);
}
}
/**
* Get the boolean that controls the display of the progress number as a percentage.
* The default value is true
* @return boolean indicating if the number should be displayed.
* @see #setShowProgress
*/
public boolean isShowProgress()
{
return bShowProgress;
}
/**
* Set the style of the progress bar's alignment.
* @param style numeric value indicating the progress bar's alignment
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getAlignStyle
*/
public void setAlignStyle(int style) throws PropertyVetoException
{
Integer newValue = new Integer (style);
Integer oldValue = new Integer (align);
vetos.fireVetoableChange("alignStyle", oldValue, newValue);
align = style;
repaint();
changes.firePropertyChange("alignStyle", oldValue, newValue);
}
/**
* Get the current style of the progress bar's alignment
* @return int the style numeric value indicating progress bar's alignment
* @see #setAlignStyle
*/
public int getAlignStyle()
{
return align;
}
/**
* Set the style of the progress bar's border.
* @param style numeric value indicating the progress bar's style
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getBevelStyle
*/
public void setBevelStyle(int style) throws PropertyVetoException
{
if(type != style)
{
Integer oldValue = new Integer (type);
Integer newValue = new Integer (style);
vetos.fireVetoableChange("bevelStyle", oldValue, newValue);
type = style;
repaint();
changes.firePropertyChange("bevelStyle", oldValue, newValue);
}
}
/**
* Get the current style of the progress bar's border
* @return int the style numeric value indicating progress bar's border, such as BEVEL_LOWERED
* @see #setBevelStyle
*/
public int getBevelStyle()
{
return type;
}
/**
* Set the border indent amount.
* @param indent INDENT_ZERO, INDENT_ONE or INDENT_TWO
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getBorderIndent
* @see #setBorderIndent(int, boolean)
*/
public void setBorderIndent(int indent) throws PropertyVetoException
{
setBorderIndent(indent, true);
}
/**
* Get the border indent amount. The default value is INDENT_ZERO.
* @return int INDENT_ZERO, INDENT_ONE or INDENT_TWO
* @see #setBorderIndent
*/
public int getBorderIndent()
{
return indent;
}
/**
* Set the color for the border of BEVEL_LINE style ProgressBar. This will not be used for other styles.
* @param color color that the border will be drawn in.
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getBorderColor
*/
public void setBorderColor(Color color) throws PropertyVetoException
{
if (!symantec.itools.util.GeneralUtils.objectsEqual(borderColor, color))
{
Color oldValue = getBorderColor();
vetos.fireVetoableChange("borderColor", oldValue, color);
borderColor = color;
repaint();
changes.firePropertyChange("borderColor", oldValue, color);
}
}
/**
* Get the color for the border of BEVEL_LINE style ProgressBar. This will not be used for other styles.
* @return Color that the border will be drawn in.
* @see #setBorderColor
*/
public Color getBorderColor()
{
return borderColor;
}
/**
* @deprecated
* @see #setBorderColor
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void setBorderedColor(Color color) throws PropertyVetoException
{
setBorderColor(color);
}
/**
* @deprecated
* @see #getBorderColor
*/
public Color getBorderedColor()
{
return getBorderColor();
}
/**
* Set the percentage complete for the process being tracked.
* @param p percentage complete as an integer
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void setProgressPercent(int p) throws PropertyVetoException
{
if (p < 0) p = 0;
if (p > 100) p = 100;
if(progress != p)
{
Integer oldValue = new Integer(progress);
Integer newValue = new Integer(p);
vetos.fireVetoableChange("progressPercent", oldValue, newValue);
progress = p;
repaint();
changes.firePropertyChange("progressPercent", oldValue, newValue);
}
}
/**
* @deprecated
* @see #setProgressPercent
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void updateProgress(int p) throws PropertyVetoException
{
setProgressPercent(p);
}
/**
* Get the current percentage complete.
* @return int - current percentage complete
* @see #setProgressPercent
*/
public int getProgressPercent()
{
return progress;
}
/**
* Set the current percentage complete.
* @param p percentage complete
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getValue
*/
public void setValue(int p) throws PropertyVetoException
{
// !!! LAB !!! In the future this should be different from ProgressPercent
// in that, the user could specify a start and end value, and the percent
// would be calculated for them. Thus, this would set some intermediate
// value, not the percentage.
setProgressPercent(p);
}
/**
* Get the current percentage complete.
* @return int - current percentage complete
* @see #setValue
*/
public int getValue()
{
// !!! LAB !!! In the future this should be different from ProgressPercent
// in that, the user could specify a start and end value, and the percent
// would be calculated for them. Thus, this would get some intermediate
// value, not the percentage.
return progress;
}
/**
* Handles redrawing of this component on the screen.
* This is a standard Java AWT method which gets called by the Java
* AWT (repaint()) to handle repainting this component on the screen.
* The graphics context clipping region is set to the bounding rectangle
* of this component and its <0,0> coordinate is this component's
* top-left corner.
* Typically this method paints the background color to clear the
* component's drawing space, sets graphics context to be the foreground
* color, and then calls paint() to draw the component.
*
* It is overridden here to reduce flicker by eliminating the uneeded
* clearing of the background.
*
* @param g the graphics context
* @see java.awt.Component#repaint
* @see #paint
*/
public void update(Graphics g)
{
paint(g);
}
/**
* Paints this component using the given graphics context.
* This is a standard Java AWT method which typically gets called
* by the AWT to handle painting this component. It paints this component
* using the given graphics context. The graphics context clipping region
* is set to the bounding rectangle of this component and its <0,0>
* coordinate is this component's top-left corner.
*
* @param g the graphics context used for painting
* @see java.awt.Component#repaint
* @see #update
*/
public void paint(Graphics g)
{
Color curBackground = getBackground();
if (!symantec.itools.util.GeneralUtils.objectsEqual(curBackground, cachedBackground))
{
cachedBackground = curBackground;
calculateHilightColors(curBackground);
}
updateBufferImage();
g.drawImage(bufferImage, 0, 0, this);
}
/**
* Returns the recommended dimensions to properly display this component.
* This is a standard Java AWT method which gets called to determine
* the recommended size of this component.
*
* @see #getMinimumSize
*/
public Dimension getPreferredSize()
{
Dimension s = getSize();
Dimension m = getMinimumSize();
return new Dimension(Math.max(s.width, m.width), Math.max(s.height, m.height));
}
/**
* @deprecated
* @see #getPreferredSize
*/
public Dimension preferredSize()
{
return getPreferredSize();
}
/**
* Returns the minimum dimensions to properly display this component.
* This is a standard Java AWT method which gets called to determine
* the minimum size of this component.
*
* @see #getPreferredSize
*/
public Dimension getMinimumSize()
{
Font f = null;
FontMetrics fm = null;
f = getFont();
if(f != null)
fm = getFontMetrics(f);
if(fm != null) {
return new Dimension(50, fm.getHeight() + 4);
}
else {
return new Dimension(50, 20);
}
}
/**
* @deprecated
* @see #getMinimumSize
*/
public Dimension minimumSize()
{
return getMinimumSize();
}
/**
* Tells this component that it has been added to a container.
* This is a standard Java AWT method which gets called by the AWT when
* this component is added to a container. Typically, it is used to
* create this component's peer.
*
* It has been overridden here to hook-up event listeners.
*
* @see #removeNotify
*/
public synchronized void addNotify()
{
//Hook up listeners
if (boxVeto == null)
{
boxVeto = new BoxVeto();
addBoxWidthListener(boxVeto);
}
if (gapVeto == null)
{
gapVeto = new GapVeto();
addGapWidthListener(gapVeto);
}
//Add after the listeners are hooked up
super.addNotify();
}
/**
* Tells this component that it is being removed from a container.
* This is a standard Java AWT method which gets called by the AWT when
* this component is removed from a container. Typically, it is used to
* destroy the peers of this component and all its subcomponents.
*
* It has been overridden here to unhook event listeners.
*
* @see #addNotify
*/
public synchronized void removeNotify()
{
//Unhook listeners
if (boxVeto != null)
{
removeBoxWidthListener(boxVeto);
boxVeto = null;
}
if (gapVeto != null)
{
removeGapWidthListener(gapVeto);
gapVeto = null;
}
super.removeNotify();
}
/**
* Adds a listener for all event changes.
* @param PropertyChangeListener listener the listener to add.
* @see #removePropertyChangeListener
*/
public synchronized void addPropertyChangeListener(PropertyChangeListener listener)
{
//super.addPropertyChangeListener(listener);
changes.addPropertyChangeListener(listener);
}
/**
* Removes a listener for all event changes.
* @param PropertyChangeListener listener the listener to remove.
* @see #addPropertyChangeListener
*/
public synchronized void removePropertyChangeListener(PropertyChangeListener listener)
{
//super.removePropertyChangeListener(listener);
changes.removePropertyChangeListener(listener);
}
/**
* Adds a vetoable listener for all event changes.
* @param VetoableChangeListener listener the listener to add.
* @see #removeVetoableChangeListener
*/
public synchronized void addVetoableChangeListener(VetoableChangeListener listener)
{
//super.addVetoableChangeListener(listener);
vetos.addVetoableChangeListener(listener);
}
/**
* Removes a vetoable listener for all event changes.
* @param VetoableChangeListener listener the listener to remove.
* @see #addVetoableChangeListener
*/
public synchronized void removeVetoableChangeListener(VetoableChangeListener listener)
{
//super.removeVetoableChangeListener(listener);
vetos.removeVetoableChangeListener(listener);
}
/**
* Adds a listener for the GapWidth property changes.
* @param listener the listener to add.
* @see #removeGapWidthListener(java.beans.PropertyChangeListener)
*/
public synchronized void addGapWidthListener(PropertyChangeListener listener)
{
changes.addPropertyChangeListener("gapWidth", listener);
}
/**
* Removes a listener for the GapWidth property changes.
* @param listener the listener to remove.
* @see #addGapWidthListener(java.beans.PropertyChangeListener)
*/
public synchronized void removeGapWidthListener(PropertyChangeListener listener)
{
changes.removePropertyChangeListener("gapWidth", listener);
}
/**
* Adds a vetoable listener for the GapWidth property changes.
* @param listener the listener to add.
* @see #removeGapWidthListener(java.beans.VetoableChangeListener)
*/
public synchronized void addGapWidthListener(VetoableChangeListener listener)
{
vetos.addVetoableChangeListener("gapWidth", listener);
}
/**
* Removes a vetoable listener for the GapWidth property changes.
* @param listener the listener to remove.
* @see #addGapWidthListener(java.beans.VetoableChangeListener)
*/
public synchronized void removeGapWidthListener(VetoableChangeListener listener)
{
vetos.removeVetoableChangeListener("gapWidth", listener);
}
/**
* Adds a listener for the BoxWidth property changes.
* @param listener the listener to add.
* @see #removeBoxWidthListener(java.beans.PropertyChangeListener)
*/
public synchronized void addBoxWidthListener(PropertyChangeListener listener)
{
changes.addPropertyChangeListener("boxWidth", listener);
}
/**
* Removes a listener for the BoxWidth property changes.
* @param listener the listener to remove.
* @see #addBoxWidthListener(java.beans.PropertyChangeListener)
*/
public synchronized void removeBoxWidthListener(PropertyChangeListener listener)
{
changes.removePropertyChangeListener("boxWidth", listener);
}
/**
* Adds a vetoable listener for the BoxWidth property changes.
* @param listener the listener to add.
* @see #removeBoxWidthListener(java.beans.VetoableChangeListener)
*/
public synchronized void addBoxWidthListener(VetoableChangeListener listener)
{
vetos.addVetoableChangeListener("boxWidth", listener);
}
/**
* Removes a vetoable listener for the BoxWidth property changes.
* @param listener the listener to remove.
* @see #addBoxWidthListener(java.beans.VetoableChangeListener)
*/
public synchronized void removeBoxWidthListener(VetoableChangeListener listener)
{
vetos.removeVetoableChangeListener("boxWidth", listener);
}
/**
* This is the PropertyChangeEvent handling inner class for the constrained BoxWidth property.
* Handles vetoing BevelHeights that are not valid.
*/
class BoxVeto implements java.beans.VetoableChangeListener, java.io.Serializable
{
/**
* This method gets called when an attempt to change the constrained BoxWidth property is made.
* Ensures the given box width is valid for this component.
*
* @param e a <code>PropertyChangeEvent</code> object describing the
* event source and the property that has changed.
* @exception PropertyVetoException if the recipient wishes the property
* change to be rolled back.
*/
public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException
{
int i = ((Integer)e.getNewValue()).intValue();
if (!isValidBoxWidth(i))
{
throw new PropertyVetoException("Invalid box width: " + i, e);
}
}
}
/**
* This is the PropertyChangeEvent handling inner class for the constrained GapWidth property.
* Handles vetoing BevelHeights that are not valid.
*/
class GapVeto implements java.beans.VetoableChangeListener, java.io.Serializable
{
/**
* This method gets called when an attempt to change the constrained GapWidth property is made.
* Ensures the given gap width is valid for this component.
*
* @param e a <code>PropertyChangeEvent</code> object describing the
* event source and the property that has changed.
* @exception PropertyVetoException if the recipient wishes the property
* change to be rolled back.
*/
public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException
{
int i = ((Integer)e.getNewValue()).intValue();
if (!isValidGapWidth(i))
{
throw new PropertyVetoException("Invalid gap width: " + i, e);
}
}
}
/**
* Is the given box width valid for this component.
* @param i the given box width
* @return true if the given box width is acceptable, false if not.
*/
protected boolean isValidBoxWidth(int i)
{
return (i > 0);
}
/**
* Is the given gap width valid for this component.
* @param i the given gap width
* @return true if the given gap width is acceptable, false if not.
*/
protected boolean isValidGapWidth(int i)
{
return (i >= 0);
}
/**
* Maintains the bufferImage size and draws the
* button in the bufferImage offscreen image.
* @see #paint
*/
protected void updateBufferImage()
{
Dimension s = getSize();
int width = s.width - 1;
int height = s.height - 1;
int barHeight = height - indent - indent - 1;
int barOffset = indent + 1;
Color color1 = null, color2 = null;
if(isBufferImageInvalid())
{
bufferImage = createImage(s.width, s.height);
try
{
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(bufferImage, 0);
tracker.waitForID(0);
}
catch(InterruptedException e){}
}
Graphics g = bufferImage.getGraphics();
if ( g.getClip() == null )
g.clipRect(0, 0, s.width, s.height);
Color oldColor = g.getColor();
//Erase before we draw
g.setColor(cachedBackground);
g.fillRect(0, 0, s.width, s.height);
//progress area and shading
g.setColor(progressColor);
int position = ((s.width - indent - indent - 2) * progress) / 100;
g.fillRect(barOffset, barOffset, position, barHeight);
if (bDrawBoxes)
{
int totalWidth = boxWidth + gapWidth;
int offsetConstant = boxWidth + barOffset;
int offset = offsetConstant;
int i = 0;
int internalPos = position + barOffset;
g.setColor(cachedBackground);
while (offset <= internalPos)
{
g.fillRect(offset, barOffset, gapWidth, barHeight);
offset = (totalWidth * ++i) + offsetConstant;
}
//Erase partial boxes
int xpos = (totalWidth * (i -1)) + offsetConstant + gapWidth;
int rWidth = internalPos - xpos;
if(rWidth < boxWidth)
g.fillRect(xpos, barOffset, rWidth, barHeight);
}
if(type != BEVEL_NONE)
{
switch(type)
{
case BEVEL_LINE:
color1 = color2 = borderColor;
break;
case BEVEL_RAISED:
color1 = bevelLighterColor;
color2 = bevelDarkerColor;
break;
case BEVEL_LOWERED:
color1 = bevelDarkerColor;
color2 = bevelLighterColor;
break;
}
// top
g.setColor(color1);
g.drawLine(indent, indent, width - indent, indent);
// bottom
g.setColor(color2);
g.drawLine(indent, height - indent, width - indent, height - indent);
// left
g.setColor(color1);
g.drawLine(indent, indent, indent, height - indent);
// right
g.setColor(color2);
g.drawLine(width - indent, indent, width - indent, height - indent);
}
// text
if (bShowProgress)
{
g.setColor(getForeground());
FontMetrics fm = getFontMetrics(getFont());
String sz = (Integer.toString(progress) + "%");
int yTemp = ((s.height + fm.getAscent()) / 2) - 2;
int xTemp;
switch (align)
{
case ALIGN_LEFT:
if (type == BEVEL_NONE)
g.drawString(sz, 4, yTemp);
else
g.drawString(sz, 8, yTemp);
break;
case ALIGN_RIGHT:
xTemp = s.width - fm.stringWidth(sz);
if (type == BEVEL_NONE)
g.drawString(sz, xTemp - 6, yTemp);
else
g.drawString(sz, xTemp - 10, yTemp);
break;
case ALIGN_CENTERED:
xTemp = (s.width - fm.stringWidth(sz)) / 2;
if (type == BEVEL_NONE)
g.drawString(sz, xTemp, yTemp);
else
g.drawString(sz, xTemp, yTemp);
break;
}
}
//Restore the original color
g.setColor(oldColor);
}
/**
* Returns true if a buffer image has been set, but it is not the
* size of this component.
*/
protected boolean isBufferImageInvalid()
{
Dimension s = getSize();
return (bufferImage == null || s.width != bufferImage.getWidth(this) || s.height != bufferImage.getHeight(this));
}
/**
* Used to calculate the hilight colors from the background color.
* @see #paint
*/
protected void calculateHilightColors(Color c)
{
bevelLighterColor = ColorUtils.calculateHilightColor(c);
bevelDarkerColor = ColorUtils.calculateShadowColor(c);
}
/**
* Set the border indent amount and optionally repaint.
* @param indent INDENT_ZERO, INDENT_ONE or INDENT_TWO
* @param bRepaint if true, causes a repaint to occur.
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getBorderIndent
* @see #setBorderIndent(int)
*/
protected void setBorderIndent(int indent, boolean bRepaint) throws PropertyVetoException
{
if(this.indent != indent)
{
Integer oldValue = new Integer(this.indent);
Integer newValue = new Integer(indent);
vetos.fireVetoableChange("borderIndent", oldValue, newValue);
if (indent < INDENT_ZERO)
{
this.indent = INDENT_ZERO;
}
else if (indent > INDENT_TWO)
{
this.indent = INDENT_TWO;
}
else
{
this.indent = indent;
}
if (bRepaint)
repaint();
changes.firePropertyChange("borderIndent", oldValue, new Integer(this.indent));
}
}
/**
* The offscreen buffer to draw the button in.
*/
transient protected Image bufferImage = null;
/**
* The color to use as a hilight when BevelStyle is BEVEL_RAISED or BEVEL_LOWERED.
*/
protected Color bevelLighterColor;
/**
* The color to use as a hilight when BevelStyle is BEVEL_RAISED or BEVEL_LOWERED.
*/
protected Color bevelDarkerColor;
/**
* Cached value of the background color. Used to determine if calculated colors need to be updated.
*/
protected Color cachedBackground = null;
/**
* The value of the Border Color property.
*/
protected Color borderColor = null;
/**
* The value of the Progress Bar Color property.
*/
protected Color progressColor = null;
/**
* The value of the Show Progress property.
*/
protected boolean bShowProgress;
/**
* The value of the Draw Boxes property.
*/
protected boolean bDrawBoxes;
/**
* The value of the Progress Percent property.
*/
protected int progress;
/**
* The value of the Box Width property.
*/
protected int boxWidth;
/**
* The value of the Gap Width property.
*/
protected int gapWidth;
/**
* The value of the Border Indent property.
*/
protected int indent;
/**
* The value of the Alignment Style property.
*/
protected int align;
/**
* The value of the Bevel Style property.
*/
protected int type;
// Private members
private BoxVeto boxVeto = null;
private GapVeto gapVeto = null;
private symantec.itools.beans.VetoableChangeSupport vetos = new symantec.itools.beans.VetoableChangeSupport(this);
private symantec.itools.beans.PropertyChangeSupport changes = new symantec.itools.beans.PropertyChangeSupport(this);
}