home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
ToolBarPanel.java
< prev
next >
Wrap
Text File
|
1998-08-21
|
14KB
|
428 lines
package symantec.itools.awt.util;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.FlowLayout;
import java.awt.LayoutManager;
import symantec.itools.awt.BorderPanel;
import symantec.itools.awt.BevelStyle;
import java.beans.PropertyVetoException;
import java.beans.PropertyChangeEvent;
import java.beans.VetoableChangeListener;
import java.beans.PropertyChangeListener;
import java.util.ResourceBundle;
// 01/29/97 TWB Integrated changes from Windows
// 05/22/97 RKM Removed call to super to call getComponents in preferredSize
// Java 1.1 compiler does not like this
// 06/03/97 TGL Converted to 1.1, added bound/constrained
// 07/23/97 LAB Updated preferredSize to getPreferredSize and eliminated minimumSize since
// BorderPanel already overrides it to call getPreferredSize. Added Orientaion
// property to allow the toolbar's getPreferredSize to return a Dimenstion that
// is best suited for a vertical orientation. Added a new constructor with
// parameters. Constrained the Orientation property to known Orientations.
// Updated version to 1.1. Added initialization to the default constructor
// (it was missing initialization before).
// 08/13/97 LAB Added a check in setOrientation() to see if the panel contains any components,
// if not then the call does not result in a reshape. Addresses Mac Bug #7253.
// 10/01/97 LAB Made getPreferredSize() independent from the base class to make sure the
// size is always calculated correctly, regardless of changes to the base class.
// This was affecting the HORIZONTAL orientation (Addresses Mac Bug #6987).
// Changed names of strings in PropertyChangeEvent handling to follow Bean Spec
// naming conventions.
/**
* ToolBarPanel component.
* This component creates a panel to which you can add buttons to create a toolbar
* in a window. Toolbars commonly contain buttons, but a ToolBarPanel can hold
* other types of components like static text, check boxes, even images.
*
* Tool bar components are separated with a ToolBarSpacer component.
*
* @see symantec.itools.awt.util.ToolBarSpacer
*
* @version 1.1, July 23, 1997
* @author Symantec
*/
public class ToolBarPanel extends BorderPanel
{
/**
* The constant to use to have a horizontally oriented toolbar.
* @see #setOrientation
* @see #getOrientation
*/
public static final int HORIZONTAL = 0;
/**
* The constant to use to have a vertically oriented toolbar.
* @see #setOrientation
* @see #getOrientation
*/
public static final int VERTICAL = 1;
/**
* Create ToolBarPanel. Default ToolBarPanel uses a BEVEL_RAISED style and is
* HORIZONTAL.
*/
public ToolBarPanel()
{
padleft = 0;
padright = 0;
padtop = 0;
padbottom = 0;
ixPad = 4;
iyPadTop = 4;
iyPadBottom = 3;
super.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
try
{
setBevelStyle(BevelStyle.BEVEL_RAISED);
setOrientation(HORIZONTAL);
}
catch(PropertyVetoException veto) {};
}
/**
* Create ToolBarPanel.
* @param bevelStyle either BEVEL_RAISED, BEVEL_LOWERED, BEVEL_LINE, or BEVEL_NONE.
* If the value passed is not valid, it will default to BEVEL_RAISED.
* @param orientationType either HORIZONTAL or VERTICAL. If the value passed is not
* valid, it will default to HORIZONTAL.
* @see BevelStyle#BEVEL_RAISED
* @see BevelStyle#BEVEL_LOWERED
* @see BevelStyle#BEVEL_LINE
* @see BevelStyle#BEVEL_NONE
* @see #HORIZONTAL
* @see #VERTICAL
*/
public ToolBarPanel(int bevelStyle, int orientationType)
{
this();
try
{
setBevelStyle(bevelStyle);
}
catch (PropertyVetoException exc) {}
try
{
setOrientation(orientationType);
}
catch (PropertyVetoException exc) {}
}
/**
* Sets the orientation of the toolbar. Modifies the results from getPreferredSize.
* If the orientation is VERTICAL, getPreferredSize will return the Dimension
* best suited for this toolbar layed out vertically. If the orientaion
* is HORIZONTAL getPreferredSize will return the Dimension best suited for this
* toolbar layed out horizontally.
* @param orientationType the orientation to adhere to. Either HORIZONTAL or VERTICAL
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getOrientation
* @see #HORIZONTAL
* @see #VERTICAL
*/
public void setOrientation(int orientationType) throws PropertyVetoException
{
if (orientation != orientationType)
{
Integer oldValue = new Integer(orientation);
Integer newValue = new Integer(orientationType);
vetos.fireVetoableChange("orientation", oldValue, newValue);
orientation = orientationType;
FlowLayout temp = (FlowLayout)panel.getLayout();
if (orientation == HORIZONTAL)
{
temp.setAlignment(FlowLayout.LEFT);
}
else if (orientation == VERTICAL)
{
temp.setAlignment(FlowLayout.CENTER);
}
panel.setLayout(temp);
if(getComponentCount() > 0)
{
setSize(getPreferredSize());
validate();
}
changes.firePropertyChange("orientation", oldValue, newValue);
}
}
/**
* Gets the orientation of the toolbar.
* @return VERTICAL: getPreferredSize will return the Dimension
* best suited for this toolbar layed out vertically. HORIZONTAL: getPreferredSize
* will return the Dimension best suited for this toolbar layed out horizontally.
* @see #setOrientation
*/
public int getOrientation()
{
return orientation;
}
/**
* Takes no action.
* This is a standard Java AWT method which gets called to specify
* which layout manager should be used to layout the components in
* standard containers.
*
* Since layout managers CANNOT BE USED with this container the standard
* setLayout has been OVERRIDDEN for this container and does nothing.
*
* @param lm the layout manager to use to layout this container's components
* (IGNORED)
* @see java.awt.Container#getLayout
**/
public void setLayout(LayoutManager lm)
{
}
/**
* 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 symantec.itools.awt.BorderPanel#getMinimumSize
*/
public synchronized Dimension getPreferredSize()
{
Dimension s = new Dimension(0, 0);
Component[] list = getComponents();
switch(orientation)
{
case HORIZONTAL:
for (int i = 0; i < list.length; ++i)
{
Dimension cs = list[i].getSize();
s.width += cs.width;
s.height = Math.max(s.height, cs.height);
}
break;
case VERTICAL:
for (int i = 0; i < list.length; ++i)
{
Dimension cs = list[i].getSize();
s.height += cs.height;
s.width = Math.max(s.width, cs.width);
}
break;
}
s.width += (padleft + padright + ixPad * 2) + 1;
s.height += (getLabelTopMargin() + padbottom + iyPadTop + iyPadBottom) + 1;
if (s.width == 0)
s.width = 50;
if (s.height == 0)
s.height = 50;
return s;
}
/**
* Is the specified orientation type valid?
* @param orientationType the type to test
* @return if true then the parameter was equal to either HORIZONTAL or VERTICAL.
* @see #setOrientation
* @see #getOrientation
* @see #HORIZONTAL
* @see #VERTICAL
*/
public boolean isValidOrientation(int orientationType)
{
switch(orientationType)
{
case HORIZONTAL:
case VERTICAL:
return true;
default:
return false;
}
}
/**
* 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()
{
super.addNotify();
errors = ResourceBundle.getBundle("symantec.itools.resources.ErrorsBundle");
//Hook up listeners
if (veto == null)
{
veto = new Veto();
addOrientationListener(veto);
}
}
/**
* 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 (veto != null)
{
removeOrientationListener(veto);
veto = null;
}
super.removeNotify();
}
/**
* Adds a listener for all event changes.
* @param 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 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 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 listener the listener to remove
* @see #addVetoableChangeListener
*/
public synchronized void removeVetoableChangeListener(VetoableChangeListener listener)
{
super.removeVetoableChangeListener(listener);
vetos.removeVetoableChangeListener(listener);
}
/**
* Adds a listener for Orienation changes.
* @param listener the listener to add
* @see #removeOrientationListener
*/
public synchronized void addOrientationListener(PropertyChangeListener listener)
{
changes.addPropertyChangeListener("orientation", listener);
}
/**
* Removes a listener for Orienation changes.
* @param listener the listener to remove
* @see #addOrientationListener
*/
public synchronized void removeOrientationListener(PropertyChangeListener listener)
{
changes.removePropertyChangeListener("orientation", listener);
}
/**
* Adds a vetoable listener for Orienation changes.
* @param listener the listener to add
* @see #removeOrientationListener
*/
public synchronized void addOrientationListener(VetoableChangeListener listener)
{
vetos.addVetoableChangeListener("orientation", listener);
}
/**
* Removes a vetoable listener for Orienation changes.
* @param listener the listener to remove
* @see #addOrientationListener
*/
public synchronized void removeOrientationListener(VetoableChangeListener listener)
{
vetos.removeVetoableChangeListener("orientation", listener);
}
/**
* This is the PropertyChangeEvent handling inner class for the constrained Orientation property.
* Handles vetoing Orientations that are not valid.
*/
class Veto implements VetoableChangeListener
{
/**
* This method gets called when an attempt to change the constrained Orientation property is made.
* Ensures the given Orientation is valid.
*
* @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 (!isValidOrientation(i))
{
throw new PropertyVetoException(errors.getString("InvalidOrientation") + i, e);
}
}
}
/**
* The orientation for the toolbar. Either HORIZONTAL or VERTICAL.
* @see #HORIZONTAL
* @see #VERTICAL
*/
protected int orientation;
/**
* Error strings.
*/
transient protected ResourceBundle errors;
private Veto veto = 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);
}