home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
ImageListBox.java
< prev
next >
Wrap
Text File
|
1998-12-02
|
115KB
|
3,600 lines
package symantec.itools.awt;
import java.awt.Panel;
import java.awt.Dimension;
import java.awt.Component;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.Scrollbar;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.SystemColor;
import java.util.Vector;
import java.awt.image.MemoryImageSource;
import java.awt.event.MouseEvent;
import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.AdjustmentEvent;
import java.beans.PropertyVetoException;
import java.beans.PropertyChangeListener;
import java.beans.VetoableChangeListener;
import java.awt.AWTEvent;
import java.awt.AWTEventMulticaster;
import java.net.URL;
import symantec.itools.awt.util.ColorUtils;
import java.util.ResourceBundle;
import java.text.MessageFormat;
// 03/02/97 RKM In ctor, make certain bar size is correct for Macs
// 03/21/97 RKM Removed repaint hack from paint
// 03/21/97 LAB Updated to Java 1.1. Removed setDirectNotify(boolean bDirectNotify),
// as it is not needed with the new event model.
// 07/18/97 LAB Added add/removeNotify to handle event listener registration.
// 07/29/97 CAR marked fields transient as needed
// inner adaptor classes implement java.io.Serializable
// implemented readObject
// added property imageURL (ListItem needs to store URL in addition to Image for serialization)
// 08/09/97 LAB Removed ListBoxFont property and made the standard Font property do it's work. Removed
// DisabledTextColor property. Removed DefaultEnabledTextColor property. Added a getter to the
// EnabledTextColor property. Removed dependency on bOsFlag private data member. Removed the bOsFlag
// member. Removed SelectImage and dependencies. Removed default initialization of Font and
// Background color in the constructor. Now hide the scrollbars before adding them to their
// container. Made the border calculate it's colors based on the background color. Deprecated
// preferredSize and minimumSize methods in favor of getPreferredSize and getMinimumSize.
// 08/15/97 LAB Reworked the way colors were calculated to avoid NullPointerExceptions,
// and potential redraw problems. Now colors are recalculated in paint,
// if needed.
// 08/22/97 CAR Fixed bug re: scrollbars were scrolling in the reverse directions
// Fixed bug on Windows platform re: ImageListBox in combomode would not display all of list
// Fixed bug on Windows platform re: Scrollbars would not appear
// Fixed bug in setSelectedItem re: item was not selected or highlighted
// Fixed bug in setSelectedIndex re: first item selected was not highlighted
// Fixed bug in delSelectedItem re: item not deleted and NegativeArraySizeException
// for non-multiple selection and ArrayIndexOUtOfBoundsException for multiple selection
// 08/25/97 ADI Fixed bug Scrollbars:
// VBar.setValues(nTopRow, visibleRows, 0, nItems - visibleRows);
// modified in:
// VBar.setValues(nTopRow, visibleRows, 0, nItems);
// 08/31/97 CAR Fixed bug re: selection of item while multiple selection set to true leads to ArrayIndexOutOfBoundsException
// Fixed bug re: last item in multiple selection will not delete
// Fixed bug re: after deleting an item that index could not be re-selected w/o first selecting another item
// 09/23/97 RKM Fixed bug in setFont - was not handling setFont(null)
// 10/01/97 LAB Fixed a bug where the barSize variable was not getting set correctly, which
// resulted in the scrollbars not showing up properly (Addresses Mac Bug #7571
// and #7538). Fixed a bug when in ComboBoxMode, you could autoscroll down,
// but not up (changed yAdj from 0 in setComboBoxMode). Added accessors for
// CellHeight and BorderWidth to allow ComboBox (and anyone else) to access them.
// Removed the use of yAdj everywhere except in mouseCalcIndex where its use
// makes sense.
// 03/02/98 DS Added isFocusedTraversable & call to RequestFocus to MousePressed
// 12/02/98 MSH Fixed a bug in SetVisibleIndex() that caused an exception in Calendar if the month was set to November.
// This problem is probably reproducable using a standard combo box. #68795
/**
* A box containing a list of images and/or text.
* <p>
* Use an ImageListBox to display a set of images and/or text that the user
* can select.
* The user cannot enter text in an ImageListBox.
* <p>
* @version 1.1, June 7, 1997
* @author Symantec
*/
public class ImageListBox extends Panel implements java.awt.ItemSelectable
{
/**
* The ID of the event posted when the image portion of a list item
* is selected.
*/
public static final int EVT_IMAGE_SELECT = 0x4004;
/**
* Defines the "regular" (lowered) border style. This makes the list box
* appear lower than the surrounding area.
* @see #setBorderType
* @see #getBorderType
*/
public static final int BORDER_REGULAR = 0;
/**
* Defines the "no border" style. This indicates the list box will have no
* border drawn around it.
* @see #setBorderType
* @see #getBorderType
*/
public static final int BORDER_NONE = 1;
/**
* Defines the width of all images displayed in the list, in pixels.
*/
public static final int IMAGE_WIDTH = 19;
/**
* Constructs a default ImageListBox.
* A default ImageListBox has no label, will size to show all of the
* existing list items when automatically laid out, and allows single list
* item selection.
*/
public ImageListBox()
{
this("", -1, false);
}
/**
* Constructs an ImageListBox with the specified label. It will size to show
* all of the existing list items when automatically laid out, and allows
* single list item selection.
* Note: he label of an ImageListBox does not get displayed.
*
* @param label the label of the list box (not displayed)
*/
public ImageListBox(String label)
{
this(label, -1, false);
}
/**
* Constructs an ImageListBox with the specified label and
* conditionally allows multiple selections.
* It will size to show all of the existing list items when
* automatically laid out.
* Note: the label of an ImageListBox does not get displayed.
* @param label the name label of the list box (not displayed)
* @param bMultipleSelections if true then multiple selections are allowed;
* if false only single item selections are allowed
*/
public ImageListBox(String label, boolean bMultipleSelections)
{
this(label, -1, bMultipleSelections);
}
/**
* Constructs an ImageListBox with the specified label, the
* specified number of visible rows, and conditionally allows multiple
* list item selection.
* @param slabel the label of the list box (not displayed)
* @param rows the number of row items to show. If rows is less than or equal
* to zero,
* it will size to show all of the existing list items when
* automatically laid out.
* @param bMultipleSelections if true then multiple selections are allowed;
* if false only single item selections are allowed
*/
public ImageListBox(String slabel, int rows, boolean bMultipleSelections)
{
items = new Vector();
ilbLabel = slabel;
rowsToShow = rows;
this.bMultipleSelections = bMultipleSelections;
setLayout(null);
VBar = new Scrollbar();
VBar.setBackground(SystemColor.control);
VBar.hide();
add(VBar);
HBar = new Scrollbar(Scrollbar.HORIZONTAL);
HBar.setBackground(SystemColor.control);
HBar.hide();
add(HBar);
//Initilize the cached color.
cachedBackground = getBackground();
}
/**
* @deprecated
* see constructor ImageListBox(String slabel, int rows, boolean bMultipleSelections)
*/
public ImageListBox(Component parent, String slabel, int rows, boolean bMultipleSelections)
{
this(slabel, rows, bMultipleSelections);
}
/**
* @deprecated
* see constructor ImageListBox(String slabel, int rows, boolean bMultipleSelections)
*/
public ImageListBox(Component parent, String label)
{
this(label);
}
//--------------------------------------------------
// accessor methods
//--------------------------------------------------
/**
* Sets ImageListBox "ComboBox mode".
* "ComboBox mode" allows the selection point to follow
* the mouse even when the mouse button is not down.
* This only applies when the ImageListBox is not allowing multiple
* selections.
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #isComboMode
*/
public void setComboMode(boolean cond) throws PropertyVetoException
{
if(bComboMode != cond)
{
Boolean oldValue = new Boolean(bComboMode);
Boolean newValue = new Boolean(cond);
vetos.fireVetoableChange("ComboMode", oldValue, newValue);
bComboMode = cond;
yAdj = 3;
invalidate();
changes.firePropertyChange("ComboMode", oldValue, newValue);
}
}
/**
* Gets the current "ComboBox mode" setting.
* "ComboBox mode" allows the selection point to follow
* the mouse even when the mouse button is not down.
* This only applies when the ImageListBox is not allowing multiple
* selections.
* @return true if in "ComboBox mode", otherwise false
* @see #setComboMode
*/
public boolean isComboMode()
{
return bComboMode;
}
/**
* @deprecated
* @see #isComboMode
*/
public boolean getComboMode()
{
return isComboMode();
}
/**
* Sets the number of rows to display in the ImageListBox.
* This affects the dimensions returned by getPreferredSize and determines
* the number of rows displayed when this component is automatically laid out.
* @param rows number of rows to automatically display
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getRowsToShow
*/
public void setRowsToShow(int rows) throws PropertyVetoException
{
if(rowsToShow != rows)
{
Integer oldValue = new Integer(rowsToShow);
Integer newValue = new Integer(rows);
vetos.fireVetoableChange("RowsToShow", oldValue, newValue);
rowsToShow = rows;
invalidate();
changes.firePropertyChange("RowsToShow", oldValue, newValue);
}
}
/**
* Gets the current number of rows to display.
* This affects the dimensions returned by getPreferredSize and determines
* the number of rows displayed when this component is automatically laid out.
* @return the current number of rows to automatically display
* @see #setRowsToShow
*/
public int getRowsToShow()
{
return rowsToShow;
}
/**
* Sets the vertical scrollbar visibility flag.
* @param cond if true, the vertical scrollbar will be made
* visible when necessary; if false, the vertical scrollbar
* will never be made visible
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #isShowVerticalScroll
*/
public void setShowVerticalScroll(boolean cond) throws PropertyVetoException
{
if(bAllowShowVBar != cond)
{
Boolean oldValue = new Boolean(bAllowShowVBar);
Boolean newValue = new Boolean(cond);
vetos.fireVetoableChange("ShowVerticalScroll", oldValue, newValue);
bAllowShowVBar = cond;
invalidate();
changes.firePropertyChange("ShowVerticalScroll", oldValue, newValue);
}
}
/**
* Gets the current vertical scrollbar visibility flag.
* @return true if the vertical scrollbar will be made
* visible when necessary; false if the vertical scrollbar
* will never be made visible
* @see #setShowVerticalScroll
*/
public boolean isShowVerticalScroll()
{
return bAllowShowVBar;
}
/**
* @deprecated
* @see #isShowVerticalScroll
*/
public boolean getShowVerticalScroll()
{
return isShowVerticalScroll();
}
/**
* Sets the horizontal scrollbar visibility flag.
* @param cond if true, the horizontal scrollbar will be made
* visible when necessary; if false, the horizontal scrollbar
* will never be made visible
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #isShowHorizontalScroll
*/
public void setShowHorizontalScroll(boolean cond) throws PropertyVetoException
{
if(bAllowShowHBar != cond)
{
Boolean oldValue = new Boolean(bAllowShowHBar);
Boolean newValue = new Boolean(cond);
vetos.fireVetoableChange("ShowHorizontalScroll", oldValue, newValue);
bAllowShowHBar = cond;
invalidate();
changes.firePropertyChange("ShowHorizontalScroll", oldValue, newValue);
}
}
/**
* Gets the current horizontal scrollbar visibility flag.
* @return true if the horizontal scrollbar will be made
* visible when necessary; false if the horizontal scrollbar
* will never be made visible
* @see #setShowHorizontalScroll
*/
public boolean isShowHorizontalScroll()
{
return bAllowShowHBar;
}
/**
* @deprecated
* @see #isShowHorizontalScroll
*/
public boolean getShowHorizontalScroll()
{
return isShowHorizontalScroll();
}
/**
* Sets the border type of the ImageListBox.
* A regular border makes the list box appear lower than the surrounding area.
* @param type new border type, BORDER_REGULAR or BORDER_NONE
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getBorderType
* @see #BORDER_REGULAR
* @see #BORDER_NONE
*/
public void setBorderType(int type) throws PropertyVetoException
{
if(borderType != type)
{
Integer oldValue = new Integer(borderType);
Integer newValue = new Integer(type);
vetos.fireVetoableChange("BorderType", oldValue, newValue);
borderType = type;
if (type == BORDER_REGULAR)
{
borderWidth = 4;
halfBorderWidth = 2;
}
else
{
borderWidth = 0;
halfBorderWidth = 0;
}
invalidate();
changes.firePropertyChange("BorderType", oldValue, newValue);
}
}
/**
* Gets the current border type of the ImageListBox.
* A regular border makes the list box appear lower than the surrounding area.
* @return the current border type, BORDER_REGULAR or BORDER_NONE
* @see #setBorderType
* @see #BORDER_REGULAR
* @see #BORDER_NONE
*/
public int getBorderType()
{
return borderType;
}
/**
* Conditionally show a border around the cell at the specified index.
* Cell borders are always shown as a solid single-pixel wide line around
* the cell.
* @param index the zero-relative index of the cell
* @param bOn true to show the cell borders; false to not show them
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #setCellBorders
*/
public void setCellBorder(int index, boolean bOn) throws PropertyVetoException
{
if (validIndex(index))
{
ListItem li = (ListItem) items.elementAt(index);
if (li.bCellBorder != bOn)
{
Boolean oldValue = new Boolean(li.bCellBorder);
Boolean newValue = new Boolean(bOn);
vetos.fireVetoableChange("CellBorder", oldValue, newValue);
li.bCellBorder = bOn;
li.bDirty = true;
invalidate();
changes.firePropertyChange("CellBorder", oldValue, newValue);
}
}
}
/**
* Sets the ImageListBox cell border display default, and
* resets all items to have the border conditionally.
* Cell borders are always shown as a solid single-pixel wide line around
* the cell.
* @param bOn true for "grid lines on by default" mode,
* false for "grid lines off by default" mode.
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #setCellBorder
* @see #isCellBorders
*/
public void setCellBorders(boolean bOn) throws PropertyVetoException
{
if(bCellBorders != bOn)
{
Boolean oldValue = new Boolean(bCellBorders);
Boolean newValue = new Boolean(bOn);
vetos.fireVetoableChange("CellBorders", oldValue, newValue);
bCellBorders = bOn;
int s = items.size();
ListItem li = null;
for (int x = 0; x < s; x++)
{
li = (ListItem) items.elementAt(x);
li.bCellBorder = bOn;
}
bAllDirty = true;
invalidate();
changes.firePropertyChange("CellBorders", oldValue, newValue);
}
}
/**
* Gets the current default cell border display mode.
* Cell borders are always shown as a solid single-pixel wide line around
* the cell.
* @return true if the "grid lines on by default" mode is on, otherwise false
* @see #setCellBorders
*/
public boolean isCellBorders()
{
return bCellBorders;
}
/**
* @deprecated
* @see #isCellBorders
*/
public boolean getCellBorders()
{
return isCellBorders();
}
/**
* Sets the text color for an item at the given index.
* @param index the zero-relative index of the item
* @param color the color, null to use the default text color
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void setEnabledTextColor(int index, Color color) throws PropertyVetoException
{
if (validIndex(index))
{
ListItem tempItem = ((ListItem)items.elementAt(index));
if (!symantec.itools.util.GeneralUtils.objectsEqual(tempItem, color))
{
Color oldValue = tempItem.color;
vetos.fireVetoableChange("EnabledTextColor", oldValue, color);
tempItem.color = color;
changes.firePropertyChange("EnabledTextColor", oldValue, color);
}
}
}
/**
* Gets the text color for an item at the given index.
* @param index the zero-relative index of the item
* @return the color, null if the default text color is used
* or the index is not valid.
*/
public Color getEnabledTextColor(int index)
{
if (validIndex(index))
{
ListItem tempItem = ((ListItem)items.elementAt(index));
return(tempItem.color);
}
return null;
}
/**
* Sets the mode of the ImageListBox to "MultiColumnListBox
* mode". This method always sets the border type to BORDER_NONE,
* the "ComboBox mode" to be false,
* and conditionally sets whether the grid should be displayed.
* @param bCellBorders true to display the cell grid,
* false to not display the grid
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #BORDER_NONE
*/
public synchronized void setMultiColumnMode(boolean bCellBorders) throws PropertyVetoException
{
if(isCellBorders() != bCellBorders)
{
setComboMode(false);
setBorderType(BORDER_NONE);
setCellBorders(bCellBorders);
yAdj = 2;
}
}
/**
* Initializes the list with the string array. Any pre-existing items are
* lost.
* @param items the new list items
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getListItems
* @see #setListItems(java.lang.String[])
* @see #addItem(java.lang.String)
* @see #addItem(java.lang.String, boolean)
* @see #addItem(java.awt.Image, java.lang.String)
* @see #addItem(java.awt.Image, java.lang.String, boolean)
* @see #addItem(java.awt.Image, java.lang.String, boolean, java.awt.Color)
*/
public void setListItems(String[] items) throws PropertyVetoException
{
String[] oldValue = getListItems();
vetos.fireVetoableChange("ListItems", oldValue, items);
clear();
for (int i = 0; i < items.length; ++i)
{
addItem(items[i]);
}
changes.firePropertyChange("ListItems", oldValue, items);
}
/**
* Returns the current list as an array.
* @return String[] current list
* @see #setListItems
*/
public String[] getListItems()
{
int len = countItems();
String[] items = new String[len];
for (int i = 0; i < len; ++i)
{
items[i] = getItem(i);
}
return items;
}
/**
* Set a flag indicating that the item at the given zero-relative index
* has been edited.
* @param index the zero-relative position of the item
* @param bCond the "edited" flag
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #isEdited
*/
public void setEdited(int index, boolean bCond) throws PropertyVetoException
{
if (validIndex(index))
{
ListItem tempItem = ((ListItem)items.elementAt(index));
if(tempItem.bEdited != bCond)
{
Boolean oldValue = new Boolean(tempItem.bEdited);
Boolean newValue = new Boolean(bCond);
vetos.fireVetoableChange("Edited", oldValue, newValue);
tempItem.bEdited = bCond;
changes.firePropertyChange("Edited", oldValue, newValue);
}
}
}
/**
* Gets the "edited" flag state for the item at the given
* zero-relative index.
* @param index the zero-relative position of the item
* @return true if flagged as edited, false if not
* @see #setEdited
*/
public boolean isEdited(int index)
{
if (validIndex(index))
{
ListItem tempItem = ((ListItem)items.elementAt(index));
return tempItem.bEdited;
}
return false;
}
/**
* @deprecated
* @see #isEdited
*/
public boolean getEdited(int index)
{
return isEdited(index);
}
/**
* Sets whether this list should allow multiple selections
* or not.
* @param cond whether to allow multiple selections
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #allowsMultipleSelections
*/
public void setMultipleSelections(boolean cond) throws PropertyVetoException
{
if (bMultipleSelections != cond)
{
Boolean oldValue = new Boolean(bMultipleSelections);
Boolean newValue = new Boolean(cond);
vetos.fireVetoableChange("MultipleSelections", oldValue, newValue);
if (!cond) // deselect first because deselect works differently according to bMultipleSelections flag
deselectAll();
bMultipleSelections = cond;
changes.firePropertyChange("MultipleSelections", oldValue, newValue);
}
}
/**
* Returns true if this list allows multiple selections.
* @return true if multiple selections allowed, false otherwise
* @see #setMultipleSelections
*/
public boolean isMultipleSelections()
{
return bMultipleSelections;
}
/**
* Conditionally enables the specified item in the list.
* @param index the zero-relative position of the item
* @param cond if true, enable the item; if false, disable the
* item
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #isEnabled
*/
public void setEnabled(int index, boolean cond) throws PropertyVetoException
{
if (validIndex(index))
{
ListItem tempItem = ((ListItem)items.elementAt(index));
if(tempItem.bEnabled != cond)
{
Boolean oldValue = new Boolean(tempItem.bEnabled);
Boolean newValue = new Boolean(cond);
vetos.fireVetoableChange("Enabled", oldValue, newValue);
tempItem.bEnabled = cond;
if(!cond)
{
deselect(index);
}
tempItem.bDirty = true;
if (!bInternalBlockPaint)
repaint();
changes.firePropertyChange("Enabled", oldValue, newValue);
}
}
}
/**
* Gets the enabled state of a specific item in the list.
* @param index the zero-relative position of the item in the list
* @return true if the item is enabled, false
* if the item is disabled.
* @see #setEnabled(int, boolean)
*/
public boolean isEnabled(int index)
{
if (validIndex(index))
{
ListItem tempItem = ((ListItem)items.elementAt(index));
return tempItem.bEnabled;
}
return false;
}
/**
* Changes the text associated with the item at the specified
* zero-relative index.
* @param index the zero-relative position of the item
* @param text the new text to associate with the item
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getText
*/
public void setText(int index, String text) throws PropertyVetoException
{
if (validIndex(index))
{
ListItem tempItem = ((ListItem)items.elementAt(index));
if(!symantec.itools.util.GeneralUtils.objectsEqual(tempItem, text))
{
String oldValue = tempItem.sText;
vetos.fireVetoableChange("Text", oldValue, text);
tempItem.sText = text;
tempItem.bDirty = true;
tempItem.updateWidth(fm);
updateWidth(tempItem);
if (!bInternalBlockPaint)
repaint();
changes.firePropertyChange("Text", oldValue, text);
}
}
}
/**
* Gets the item text associated with the specified zero-relative index.
* @param index the zero-relative position of the item
* @return the item text, or null if the index is invalid
* @see #setText
*/
public String getText(int index)
{
if (validIndex(index))
return ((ListItem)items.elementAt(index)).sText;
else
return null;
}
/**
* @deprecated
* @see #getText
*/
public String getItem(int index)
{
return getText(index);
}
/**
* Sets the URL of the image to display at the given zero based index
* @param aURL the image URL
* @exception java.net.MalformedURLException
* if the URL parameter is bad
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getImage
*/
public void setImageURL(int index, URL aUrl) throws java.net.MalformedURLException, PropertyVetoException
{
if (validIndex(index)) {
ListItem tempItem = ((ListItem)items.elementAt(index));
URL oldValue = tempItem.url;
Image image = getToolkit().getImage(aUrl);
if (image != null)
{
setImage(index, image);
}
tempItem.url = aUrl;
changes.firePropertyChange("ImageURL", oldValue, aUrl);
}
}
/**
* Gets the URL of the image displayed at the given zero-based index.
* @param index the zero-relative index of the image to get
* @return the URL of the image
* @see #setImage
*/
public URL getImageURL(int index)
{
if (validIndex(index))
return ((ListItem)items.elementAt(index)).url;
else
return null;
}
/**
* Change the image associated with an item at a
* specific zero-relative index.
* @param index the zero-relative position of the item
* @param image the image to associate with an item
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getImage(int)
*/
public void setImage(int index, Image image) throws PropertyVetoException
{
if (validIndex(index))
{
ListItem tempItem = ((ListItem)items.elementAt(index));
if(!symantec.itools.util.GeneralUtils.objectsEqual(tempItem, image))
{
Image oldValue = tempItem.image;
vetos.fireVetoableChange("Image", oldValue, image);
tempItem.image = image;
tempItem.bDirty = true;
if (!bInternalBlockPaint)
repaint();
changes.firePropertyChange("Image", oldValue, image);
}
}
}
/**
* Gets the image associated with the specified zero-relative index.
* @param index the zero-relative position of the item
* @return the image at the index, or null if the index is invalid
* @see #setImage(int, java.awt.Image)
*/
public Image getImage(int index)
{
if (validIndex(index))
return ((ListItem)items.elementAt(index)).image;
else
return null;
}
/**
* Sets the slelection state of the first item in the list which has exactly
* matching text.
* @param str the String to select in the list
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see getSelectedItem
*/
public synchronized void setSelectedItem(String str, boolean isSelected) throws PropertyVetoException
{
ListItem li;
int z = items.size();
for (int i = 0; i < z; i++)
{
li = (ListItem) items.elementAt(i);
if (symantec.itools.util.GeneralUtils.objectsEqual(li.sText, str)/*&& li.bEnabled != isSelected*/)
{
//Make up the new string array before it happens.
String[] oldValue = getSelectedItems();
Vector tempVect = new Vector(oldValue.length);
for(int count = 0; count < oldValue.length; count++)
tempVect.insertElementAt(oldValue[count], count);
if(isSelected)
tempVect.addElement(li.sText);
else
tempVect.removeElement(li.sText);
String[] newValue = new String[tempVect.size()];
tempVect.copyInto(newValue);
vetos.fireVetoableChange("SelectedItems", oldValue, newValue);
setSelectedIndex(i, isSelected);
if (!bInternalBlockPaint)
repaint();
changes.firePropertyChange("SelectedItems", oldValue, getSelectedItems());
return;
}
}
}
/**
* Returns the currently selected item in the list.
* If multiple items are selected, the item most recently
* selected is returned.
* @return the currently selected item, or null if no item is selected.
* @see #setSelectedItem
* @see #getSelectedItems
* @see #deselect
* @see #isSelected
*/
public synchronized String getSelectedItem()
{
return (lastSelected < 0) ? null : getItem(lastSelected);
}
/**
* Select the item at the specified index.
* This method deselects all others when multiple
* selections not enabled.
* @param index the zero-relative position of the item to select
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getSelectedItem
* @see #deselect
* @see #isSelected
*/
public synchronized void setSelectedIndex(int index, boolean isSelected) throws PropertyVetoException
{
ListItem listItem = null;
if (bMultipleSelections)
{
listItem = (ListItem)items.elementAt(index);
//Make up the new int array before it happens.
int[] oldValue = getSelectedIndexes();
Vector tempVect = new Vector(oldValue.length);
for(int count = 0; count < oldValue.length; count++)
tempVect.insertElementAt(new Integer(oldValue[count]), count);
if(isSelected)
tempVect.addElement(new Integer(index));
else
tempVect.removeElement(new Integer(index));
int[] newValue = new int[tempVect.size()];
for(int count = 0; count < tempVect.size(); count++)
newValue[count] = ((Integer)tempVect.elementAt(count)).intValue();
vetos.fireVetoableChange("SelectedIndex", oldValue, newValue);
if(isSelected) {
try {
deselectAll();
} catch (java.beans.PropertyVetoException e) {}
}
listItem.bSelected = isSelected;
listItem.bDirty = true;
if(isSelected)
countSelected++;
changes.firePropertyChange("SelectedIndex", oldValue, getSelectedIndexes());
}
else
{
int s = items.size();
if(index < s && index > -1)
{
//Make up the new int array before it happens.
int[] oldValue = getSelectedIndexes();
int[] newValue = new int[0];
if(isSelected)
{
newValue = new int[1];
newValue[0] = index;
}
vetos.fireVetoableChange("SelectedIndexes", oldValue, newValue);
listItem = (ListItem)items.elementAt(index);
boolean wasSelected = listItem.bSelected;
//If they want to select something, we must deselect everything else.
if(isSelected)
{
for(int i = 0; i < s; i++)
{
listItem = (ListItem)items.elementAt(i);
if(listItem.bSelected)
{
listItem.bSelected = false;
listItem.bDirty = true;
}
}
listItem = (ListItem)items.elementAt(index);
listItem.bSelected = true;
if(wasSelected)
listItem.bDirty = false;
countSelected = 1;
}
else
{
listItem.bSelected = false;
if(wasSelected){
listItem.bDirty = true;
countSelected--;
}
}
changes.firePropertyChange("SelectedIndexes", oldValue, getSelectedIndexes());
}
}
lastSelected = index;
setVisibleIndex(index);
if (!bInternalBlockPaint) repaint();
}
/**
* Gets the zero-relative index of the selected item in the list.
* If multiple items are selected, the index of the item most recently
* selected is returned.
* @return the zero-relative index of the selected item, or -1 if no item is
* selected
* @see #select
* @see #deselect
* @see #isSelected
*/
public synchronized int getSelectedIndex()
{
return lastSelected;
}
/**
* Returns the indexes of all the selected items in the list.
* @return an array of the zero-relative indexes of the selected items
* @see #select
* @see #deselect
* @see #isSelected
*/
public synchronized int[] getSelectedIndexes()
{
int sel[] = new int[countSelected];
if (countSelected == 1)
sel[0] = lastSelected;
else if (countSelected > 1)
{
int x = 0;
int s = items.size();
for (int i = 0; i < s; i++)
{
ListItem tempItem = (ListItem)items.elementAt(i);
if (tempItem.bSelected)
{
sel[x++] = i;
if (x == countSelected)
break;
}
}
}
return sel;
}
/**
* Returns all of the the selected items in the list.
* @return an array of all the selected items in the list
* @see #getSelectedItem
* @see #setSelectedItem
* @see #isSelected
*/
public synchronized String[] getSelectedItems()
{
String str[] = new String[java.lang.Math.max(1,countSelected)];
ListItem tempItem;
if (!bMultipleSelections)
{
if (lastSelected != -1)
{
tempItem = (ListItem)items.elementAt(lastSelected);
str[0] = tempItem.sText;
}
}
else if (countSelected > 0)
{
int x = 0;
int s = items.size();
for (int i = 0; i < s; i++)
{
tempItem = (ListItem)items.elementAt(i);
if (tempItem.bSelected)
{
str[x] = tempItem.sText;
if (++x == countSelected)
break;
}
}
}
return str;
}
/**
* Returns the selected items in the list.
* Needed in order to implement the java.awt.ItemSelectable interface
* @return an array of selected items in the list, as an array of Objects.
* @see #getSelectedItem
* @see #setSelectedItem
* @see #isSelected
* @see java.awt.ItemSelectable
*/
public Object[] getSelectedObjects()
{
return getSelectedItems();
}
/**
* Get the selected state of the item at the given index.
* @param index the zero-relative index of the item to be checked
* @return true if the item at the specified index
* is selected; false if it is not selected
* @see #select
* @see #deselect
* @see #isSelected
*/
public synchronized boolean isSelected(int index)
{
if (validIndex(index))
{
ListItem listItem = (ListItem)items.elementAt(index);
return listItem.bSelected;
}
return false;
}
/**
* Sets the current list box label.
* @param label the new list box label
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getLabel
*/
public synchronized void setLabel(String label) throws PropertyVetoException
{
if(!symantec.itools.util.GeneralUtils.objectsEqual(ilbLabel, label))
{
String oldValue = ilbLabel;
vetos.fireVetoableChange("Label", oldValue, label);
ilbLabel = label;
changes.firePropertyChange("Label", oldValue, label);
}
}
/**
* Returns the current list box label.
* @return the current list box label
* @see #setLabel
*/
public synchronized String getLabel()
{
return new String(ilbLabel);
}
/**
* Forces the item at the specified index to be visible in
* the window.
* @param index the zero-relative position of the item to be
* made visible
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getVisibleIndex
*/
public synchronized void setVisibleIndex(int index) throws PropertyVetoException
{
if(visibleIndex != index)
{
Integer oldValue = new Integer(visibleIndex);
Integer newValue = new Integer(index);
vetos.fireVetoableChange("VisibleIndex", oldValue, newValue);
visibleIndex = index;
if ( nTopRow > index )
scrollVertical(index, true);
else if (index >= (nTopRow + visibleRows))
scrollVertical(index - (visibleRows + 1 ), true);
changes.firePropertyChange("VisibleIndex", oldValue, newValue);
}
}
/**
* Gets the index of the item that was last made visible by
* the method makeVisible.
* @return the zero-relative index of the item last made visible by the
* makeVisible method
* @see #makeVisible
*/
public int getVisibleIndex()
{
return visibleIndex;
}
/**
* Forces the item at the specified index to be visible at
* the top of the window.
* @param index the zero-relative position of the item
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getTopRow
*/
public void setTopRow(int index) throws PropertyVetoException
{
int s = items.size();
if (s < visibleRows)
index = 0;
else if (index > (s - visibleRows))
index = s - visibleRows;
if (nTopRow != index)
{
Integer oldValue = new Integer(nTopRow);
Integer newValue = new Integer(index);
vetos.fireVetoableChange("TopRow", oldValue, newValue);
nTopRow = index;
bAllDirty = true;
invalidate();
changes.firePropertyChange("TopRow", oldValue, newValue);
}
}
/**
* Returns the index of the item visible at
* the top of the window.
* @return index the zero-relative position of the item
* @see #setTopRow
*/
public synchronized int getTopRow()
{
return nTopRow;
}
/**
* Sets the number of columns to be used by getMinimumSize().
* @param columns the number of columns
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getColumns
*/
public synchronized void setColumns(int columns) throws PropertyVetoException
{
if (colsToShow != columns)
{
Integer oldValue = new Integer(colsToShow);
Integer newValue = new Integer(columns);
vetos.fireVetoableChange("Columns", oldValue, newValue);
colsToShow = columns;
invalidate();
changes.firePropertyChange("Columns", oldValue, newValue);
}
}
/**
* Returns the number of columns to be used by minimumSize().
* @return the number of columns
* @see #setColumns
*/
public synchronized int getColumns()
{
return colsToShow;
}
/**
* Returns the number of currently visible lines in this list.
* @return the number of visible lines in the list.
*/
public int getRows()
{
return visibleRows;
}
/**
* Set the font for the items in the list box.
* @param f new font to use for list box items
*/
public synchronized void setFont(Font f)
{
super.setFont(f);
f = getFont();
if (f != null)
{
fm = getFontMetrics(f);
updateWidths(fm);
xCoord = 0;
bAllDirty = true;
invalidate();
}
}
/**
* Set the list to be "dirty" (true) to force a complete
* paint on next repaint, or "clean" (false) to avoid a complete
* paint on the next repaint.
* @param isDirty true if the list is dirty (needs repaint)
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #isDirty
*/
public synchronized void setDirty(boolean isDirty) throws PropertyVetoException
{
Boolean oldValue = new Boolean(bAllDirty);
Boolean newValue = new Boolean(isDirty);
vetos.fireVetoableChange("Dirty", oldValue, newValue);
bAllDirty = isDirty;
changes.firePropertyChange("Dirty", oldValue, newValue);
}
/**
* Query the lists all "dirty" state
* @return true if on the next repaint the entire list will be
* repainted, or false if the list will not be repainted.
* @see #setDirty(boolean)
*/
public synchronized boolean isDirty()
{
return bAllDirty;
}
/**
* @deprecated
* @see #setDirty(boolean)
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public synchronized void setDirty() throws PropertyVetoException
{
setDirty(true);
}
/**
* Query if all rows are selected.
* @return returns true if all rows in the ImageListBox
* are selected
*/
public boolean isAllSelected()
{
return (countSelected == items.size());
}
/**
* @deprecated
* @see #isAllSelected
*/
public boolean allSelected()
{
return isAllSelected();
}
/**
* Adds an item to the end of the list and enables the item.
* @param item the item to be added
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #setListItems(java.lang.String[])
* @see #addItem(java.lang.String, boolean)
* @see #addItem(java.awt.Image, java.lang.String)
* @see #addItem(java.awt.Image, java.lang.String, boolean)
* @see #addItem(java.awt.Image, java.lang.String, boolean, java.awt.Color)
*/
public synchronized void addItem(String item) throws PropertyVetoException
{
addItem(new ListItem((Image)null, item, true, fm, bCellBorders));
}
/**
* Adds an item to the end of the list and conditionally enables
* it.
* @param item the item to be added
* @param bEnabled if true, enable the item; if false, disable
* the item
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #setListItems(java.lang.String[])
* @see #addItem(java.lang.String)
* @see #addItem(java.awt.Image, java.lang.String)
* @see #addItem(java.awt.Image, java.lang.String, boolean)
* @see #addItem(java.awt.Image, java.lang.String, boolean, java.awt.Color)
*/
public synchronized void addItem(String item, boolean bEnabled) throws PropertyVetoException
{
addItem(new ListItem((Image)null, item, bEnabled, fm, bCellBorders));
}
/**
* Adds an item with an image to the end of the list and enables
* it.
* @param image the image to display on the item line
* @param item the item to be added
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #setListItems(java.lang.String[])
* @see #addItem(java.lang.String)
* @see #addItem(java.lang.String, boolean)
* @see #addItem(java.awt.Image, java.lang.String, boolean)
* @see #addItem(java.awt.Image, java.lang.String, boolean, java.awt.Color)
*/
public synchronized void addItem(Image image, String item) throws PropertyVetoException
{
addItem(new ListItem(image, item, true, fm, bCellBorders));
}
/**
* Adds an item with an image to the end of the list and
* conditionally enables it.
* @param image the image to display on item line
* @param item the item to be added
* @param bEnabled if true, enable the item; if false, disable the item
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #setListItems(java.lang.String[])
* @see #addItem(java.lang.String)
* @see #addItem(java.lang.String, boolean)
* @see #addItem(java.awt.Image, java.lang.String)
* @see #addItem(java.awt.Image, java.lang.String, boolean, java.awt.Color)
*/
public synchronized void addItem(Image image, String item, boolean bEnabled) throws PropertyVetoException
{
addItem(new ListItem(image, item, bEnabled, fm, bCellBorders));
}
/**
* Adds an item with an image to the end of the list and
* conditionally enables it. The item text will be displayed in the
* given color.
* @param image the image to display on item line
* @param item the item to be added
* @param bEnabled if true, enable the item; if false, disable the item
* @param color the color of the item's text
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #setListItems(java.lang.String[])
* @see #addItem(java.lang.String)
* @see #addItem(java.lang.String, boolean)
* @see #addItem(java.awt.Image, java.lang.String)
* @see #addItem(java.awt.Image, java.lang.String, boolean)
*/
public synchronized void addItem(Image image, String item, boolean bEnabled, Color color) throws PropertyVetoException
{
ListItem li = new ListItem(image, item, bEnabled, fm, bCellBorders);
li.color = color;
addItem(li);
}
/**
* Inserts an item with an image at a specific zero-relative index and
* conditionally enables it.
* @param index the zero-relative index to insert at
* @param image the image to display on the item line
* @param item the item to be added
* @param bEnabled if true, enable the item; if false, disable the item
*/
public synchronized void insertItem(int index, Image image, String item, boolean bEnabled)
{
ListItem li = null;
if ( validIndex(index) )
{
items.insertElementAt(li = new ListItem(image, item, bEnabled, fm, bCellBorders), index);
bAllDirty = true;
if (lastSelected >= index)
lastSelected++;
}
else
items.addElement(li = new ListItem(image, item, bEnabled, fm, bCellBorders));
updateWidth(li);
if (!bInternalBlockPaint) repaint();
}
/**
* Inserts a vector list of items at a specific zero-relative index and
* conditionally enables them.
* Each item will be displayed with the given image.
* @param index the zero-relative index to insert at
* @param itemVector the item vector to be added
* @param image the image to display for all inserted items
* @param bEnabled if true, enable the items; if false, disable the items
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public synchronized void insertItems(int index, Vector itemVector, Image image, boolean bEnabled) throws PropertyVetoException
{
int s = itemVector.size();
int x = 0;
int idx = index;
if ( validIndex(index) )
{
for (x = 0; x < s; x++)
items.insertElementAt(new ListItem(image, (String) itemVector.elementAt(x), bEnabled, fm, bCellBorders), index++);
}
else
{
for (x = 0; x < s; x++)
items.addElement(new ListItem(image, (String) itemVector.elementAt(x), bEnabled, fm, bCellBorders));
}
deselectAll();
bAllDirty = true;
updateWidths(fm);
if (!bInternalBlockPaint) repaint();
}
/**
* Returns the total number of items in the list.
* @return the number of items in the list
* @see #getItem
*/
public int countItems()
{
return items.size();
}
/**
* @deprecated
* @see #setImage(int, java.awt.Image)
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void changeImage(int index, Image image) throws PropertyVetoException
{
setImage(index, image);
}
/**
* @deprecated
* @see #setText(int, java.lang.String)
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void changeText(int index, String text) throws PropertyVetoException
{
setText(index, text);
}
/**
* @deprecated
* @see #isMultipleSelections
*/
public boolean allowsMultipleSelections()
{
return isMultipleSelections();
}
/**
* @deprecated
* @see #setEnabled(int, boolean)
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void enable(int index, boolean cond) throws PropertyVetoException
{
setEnabled(index, cond);
}
/**
* @deprecated
* @see #setEnabled(int, boolean)
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void enable(int index) throws PropertyVetoException
{
setEnabled(index, true);
}
/**
* @deprecated
* @see #setEnabled(int, boolean)
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void disable(int index) throws PropertyVetoException
{
setEnabled(index, false);
}
/**
* Clears the list.
* @see #delItem
* @see #delItems
*/
public synchronized void clear()
{
items = new Vector();
nTopRow = 0;
visibleIndex = -1;
lastDownModifiers = -1;
lastSelected = -1;
lastIndex = -1;
lastTempIndex = -1;
countSelected = 0;
prevSelectTime = -1;
prevSelectRow = -1;
VBar.setValues(1, 1, 0, 2);
VBar.hide();
bVBarVisible = false;
HBar.setValues(1, 1, 0, 2);
HBar.hide();
bHBarVisible = false;
bAllDirty = true;
bInternalBlockPaint = false;
bBlockPaint = false;
longestLineValue = 0;
xCoord = 0;
repaint();
}
/**
* Delete an item from the list.
* @param index the zero-relative index of the item to delete
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #delItems
* @see #delSelectedItems
*/
public synchronized void delItem(int index) throws PropertyVetoException
{
if (validIndex(index))
{
String[] oldValue = getListItems();
String[] newValue = new String[oldValue.length - 1];
Vector tempVect = new Vector(oldValue.length);
for(int count = 0; count < oldValue.length; count++)
tempVect.insertElementAt(new String(oldValue[count]), count);
tempVect.removeElementAt(index);
for(int count = 0; count < tempVect.size(); count++)
newValue[count] = new String((String)tempVect.elementAt(count));
vetos.fireVetoableChange("ListItems", oldValue, newValue);
setSelectedIndex(index, false);
if (!bInternalBlockPaint) repaint();
items.removeElementAt(index);
bAllDirty = true;
scrollVertical(nTopRow, true);
updateWidths(null);
if (!bInternalBlockPaint) repaint();
changes.firePropertyChange("ListItems", oldValue, getListItems());
}
}
/**
* Delete multiple items from the list.
* Note that the end index must be greater than or
* equal to the start index.
* @param start the zero-relative start index of the items
* @param end the zero-relative end index of the items
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #delItem
* @see #delSelectedItems
*/
public synchronized void delItems(int start, int end) throws PropertyVetoException
{
int s = items.size();
if (s > 0)
{
if (end >= s)
end = s - 1;
if (start < 0)
start = 0;
if (start <= end)
{
String[] oldValue = getListItems();
String[] newValue = new String[oldValue.length - (end - start) - 1];
Vector tempVect = new Vector(newValue.length);
for(int count = 0; count < start; count++)
tempVect.insertElementAt(new Integer(oldValue[count]), count);
for(int count = end + 1; count < oldValue.length; count ++)
tempVect.insertElementAt(new String(oldValue[count]), start + (count - (end + 1)));
for(int count = 0; count < tempVect.size(); count++)
newValue[count] = new String((String)tempVect.elementAt(count));
vetos.fireVetoableChange("ListItems", oldValue, newValue);
bInternalBlockPaint = true;
for (int i = end; i >= start; i--)
{
setSelectedIndex(i, false);
items.removeElementAt(i);
}
bInternalBlockPaint = false;
bAllDirty = true;
scrollVertical(nTopRow, true);
updateWidths(null);
repaint();
changes.firePropertyChange("ListItems", oldValue, getListItems());
}
}
}
/**
* Deletes the currently selected items from the list.
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #delItem
* @see #delItems
*/
public synchronized void delSelectedItems() throws PropertyVetoException
{
int s = items.size();
bInternalBlockPaint = true;
for (int x = 0; x < s; )
{
ListItem tempItem = (ListItem) items.elementAt(x);
if (tempItem.bSelected)
{
//setSelectedIndex(x, false);
delItem(x);
s--;
}
else
x++;
}
bAllDirty = true;
scrollVertical(nTopRow, true);
updateWidths(null);
bInternalBlockPaint = false;
repaint();
}
/**
* @deprecated
* @see #setSelectedIndex(int, boolean)
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public synchronized void select(int index) throws PropertyVetoException
{
setSelectedIndex(index, true);
}
/**
* @deprecated
* @see #setSelectedItem(java.lang.String, boolean)
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public synchronized void select(String str) throws PropertyVetoException
{
setSelectedItem(str, true);
}
/**
* Selects an item at the specified index in a multiple-selection-enabled ImageListBox
* using Shift, Ctrl or Ctrl-Shift modifiers to mimic mouse
* selecting with the Shift, Ctrl or Ctrl-Shift modifiers.
* @param index the zero-relative position of the item to select
* @param bShift whether to select with the Shift modifier
* @param bControl whether to select with the Ctrl modifier
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public synchronized void selectMultiple(int index, boolean bShift, boolean bControl) throws PropertyVetoException
{
if (!bMultipleSelections)
{
bShift = false;
bControl = false;
}
if (bShift)
shiftSelect(index, bControl);
else if (bControl)
ctrlSelect(index);
else
setSelectedIndex(index, true);
}
/**
* Selects all the items in the list.
* @see #select
* @see #deselectAll
*/
public synchronized void selectAll()
{
if (!bMultipleSelections)
return;
int s = items.size();
ListItem li;
for (int i = 0; i < s; i++)
{
li = (ListItem)items.elementAt(i);
if (li.bEnabled)
li.bSelected = true;
}
countSelected = s;
lastSelected = s - 1;
repaint();
}
/**
* @deprecated
* @see #setSelectedIndex(int, boolean)
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public synchronized void deselect(int index) throws PropertyVetoException
{
if (validIndex(index))
{
setSelectedIndex(index, false);
if (!bInternalBlockPaint) repaint();
}
}
/**
* Deselects all items in the list.
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #selectAll
*/
public synchronized void deselectAll() throws PropertyVetoException
{
int[] oldValue = getSelectedIndexes();
int[] newValue = new int[0];
vetos.fireVetoableChange("SelectedIndexes", oldValue, newValue);
ListItem li;
if (!bMultipleSelections)
{
if (lastSelected != -1)
{
li = (ListItem)items.elementAt(lastSelected);
li.bSelected = false;
li.bDirty = true;
}
}
else
{
int s = items.size();
for (int i = 0; i < s; i++)
{
li = (ListItem)items.elementAt(i);
if (li.bSelected)
{
li.bSelected = false;
li.bDirty = true;
}
}
}
lastSelected = -1;
countSelected = 0;
repaint();
changes.firePropertyChange("SelectedIndexes", oldValue, getSelectedIndexes());
}
/**
* @deprecated
* @see #setVisibleIndex
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public synchronized void makeVisible(int index) throws PropertyVetoException
{
setVisibleIndex(index);
}
/**
* Get the height of an individual row.
* @return the height in pixels
*/
public int getCellHeight()
{
return cellHt;
}
/**
* Get the width of the border around the component.
* This value is the number of pixels needed to display the border
* completely on both sides of the component; it is not the width of
* one side of the border.
* @return the width in pixels
*/
public int getBorderWidth()
{
return borderWidth;
}
/**
* Returns the preferred dimensions needed for the list with
* the specified number of rows.
* @param rows the number of visible rows in the list
* @return the preferred size to show the specified number of rows
*/
public Dimension getPreferredSize(int rows)
{
Dimension d = getMinimumSize(rows);
Dimension s = size();
return new Dimension(Math.max(d.width, s.width), Math.max(d.height, s.height));
}
/**
* 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.
*
* The size returned is big enough to show the maximum number of visible
* rows as requested when constructed, or all the rows currently in the list.
*
* @see #minimumSize
*/
public Dimension getPreferredSize()
{
if (rowsToShow > 0)
return getPreferredSize(rowsToShow);
return getPreferredSize(items.size());
}
/**
* Returns the minimum dimensions needed to show the given number of rows
* in the list.
* @param rows the number of visible rows in the list
* @return the minimum size of this list to show the given number of rows
*/
public Dimension getMinimumSize(int rows)
{
font = getFont();
if (font != null)
{
fm = getFontMetrics(font);
if (fm != null)
{
fontHeight = fm.getHeight();
if (bCellBorders)
cellHt = fontHeight+5;
else
cellHt = fontHeight+1;
return new Dimension( ((fm.stringWidth("WN") * colsToShow) / 2) + LINE_SLOP, (rows * cellHt + borderWidth) );
}
}
return new Dimension(borderWidth + LINE_SLOP, borderWidth);
}
/**
* 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.
*
* The size returned is big enough to show the maximum number of visible
* rows as requested when constructed, or all the rows currently in the list.
*
* @see #preferredSize
*/
public Dimension getMinimumSize()
{
if (rowsToShow > 0)
return getMinimumSize(rowsToShow);
return getMinimumSize(items.size());
}
/**
* @deprecated
* @see #getPreferredSize(int)
*/
public Dimension preferredSize(int rows)
{
return getPreferredSize(rows);
}
/**
* @deprecated
* @see #getPreferredSize
*/
public Dimension preferredSize()
{
return getPreferredSize();
}
/**
* @deprecated
* @see #getMinimumSize(int)
*/
public Dimension minimumSize(int rows)
{
return getMinimumSize(rows);
}
/**
* @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.
* It is also used to handle list metrics after the peer is created.
*
* @see #removeNotify
*/
public synchronized void addNotify()
{
super.addNotify();
errors = ResourceBundle.getBundle("symantec.itools.resources.ErrorsBundle");
//Calculate the default width of a scrollbar.
barSize = VBar.getPreferredSize().width;
//Hook up listeners
if (mouse == null)
{
mouse = new Mouse();
addMouseListener(mouse);
}
if (mouseMotion == null)
{
mouseMotion = new MouseMotion();
addMouseMotionListener(mouseMotion);
}
if (key == null)
{
key = new Key();
addKeyListener(key);
}
if (adjustment == null)
{
adjustment = new Adjustment();
VBar.addAdjustmentListener(adjustment);
HBar.addAdjustmentListener(adjustment);
}
font = getFont();
fm = getFontMetrics(font);
fontHeight = fm.getHeight();
updateWidths(fm);
}
public boolean isFocusTraversable()
{
return (true);
}
/**
* 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 (mouse != null)
{
removeMouseListener(mouse);
mouse = null;
}
if (mouseMotion != null)
{
removeMouseMotionListener(mouseMotion);
mouseMotion = null;
}
if (key != null)
{
removeKeyListener(key);
key = null;
}
if (adjustment != null)
{
VBar.removeAdjustmentListener(adjustment);
HBar.removeAdjustmentListener(adjustment);
adjustment = null;
}
super.removeNotify();
}
/**
* Blocks the repainting of the control.
* @param cond true to prevent updating the component, false for normal
* painting behavior
*/
public synchronized void blockPaint(boolean cond)
{
bBlockPaint = cond;
if (!bBlockPaint)
repaint();
}
/**
* Scrolls the ImageListBox vertically.
* @param info either an absolute value or Event.SCROLL_PAGE_DOWN,
* Event.SCROLL_PAGE_UP, Event.SCROLL_LINE_DOWN, Event.SCROLL_LINE_UP.
* The range for an absolute value should be between 0 and (number of rows-1).
* @param bAbsolute true to treat the info parameter as an absolute value,
* false to treat it as one of the SCROLL_... constants
*/
public synchronized void scrollVertical(int info, boolean bAbsolute)
{
int temp = nTopRow;
if (visibleRows == 0)
temp = 0;
else
{
if (bAbsolute)
temp = info;
else
{
switch (info)
{
case AdjustmentEvent.BLOCK_DECREMENT: temp -= visibleRows; break;
case AdjustmentEvent.BLOCK_INCREMENT: temp += visibleRows; break;
case AdjustmentEvent.UNIT_DECREMENT: temp -= 1; break;
case AdjustmentEvent.UNIT_INCREMENT: temp += 1; break;
}
}
if (temp < 0)
temp = 0;
else if (temp > (items.size() - visibleRows))
{
temp = items.size() - visibleRows;
if (temp < 0)
temp = 0;
}
}
if (nTopRow != temp)
{
nTopRow = temp;
VBar.setValue(temp);
bAllDirty = true;
if (!bInternalBlockPaint) repaint();
}
}
/**
* Scrolls the ImageListBox horizontally
* @param info either an absolute value or Event.SCROLL_PAGE_DOWN,
* Event.SCROLL_PAGE_UP, Event.SCROLL_LINE_DOWN, Event.SCROLL_LINE_UP.
* The range for absolute value should be between 0 and the width of the
* largest item, in pixels
* @param bAbsolute true to treat the info parameter as an absolute value,
* false to treat it as one of the SCROLL_... constants
*/
public synchronized void scrollHorizontal(int info, boolean bAbsolute)
{
int temp = xCoord;
if (bAbsolute)
temp = -info;
else
{
switch (info)
{
case AdjustmentEvent.BLOCK_DECREMENT: temp += lWidth; break;
case AdjustmentEvent.BLOCK_INCREMENT: temp -= lWidth; break;
case AdjustmentEvent.UNIT_DECREMENT: temp += 1; break;
case AdjustmentEvent.UNIT_INCREMENT: temp -= 1; break;
}
}
if (temp > 0)
temp = 0;
else if ( (-temp) > HBar.getMaximum() - lWidth)
temp = -(HBar.getMaximum() - lWidth);
if (xCoord != temp)
{
xCoord = temp;
HBar.setValue(-temp);
bAllDirty = true;
if (!bInternalBlockPaint) repaint();
}
}
/**
* 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 prevent the flicker associated with the standard
* update() method's repainting of the background before painting the component
* itself,
* and to allow the blocking of painting entirely.
*
* @param g the graphics context
* @see java.awt.Component#repaint
* @see #paint
*/
public synchronized void update(Graphics g)
{
if (!bBlockPaint && !bInternalBlockPaint)
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 synchronized void paint(Graphics g)
{
ListItem item;
int nItems;
int xSelectStartLoc;
int i, j, rows;
int vWid = 0;
int hHt = 0;
int gridAdj = 0;
int yLoc = 0;
int ySLoc = 0;
boolean bShowV = false;
boolean bShowH = false;
//Make sure cached colors are correct.
Color curBackground = getBackground();
if (!symantec.itools.util.GeneralUtils.objectsEqual(curBackground, cachedBackground))
{
cachedBackground = curBackground;
calculateBorderColors(curBackground);
}
// Size size of ListBox
Rectangle rect = bounds();
font = g.getFont();
fm = g.getFontMetrics(font);
fontHeight = fm.getHeight();
fontDescent = fm.getDescent();
nItems = items.size();
if (bCellBorders)
cellHt = fontHeight+5;
else
cellHt = fontHeight+1;
if (nItems == 0)
{
nTopRow = 0;
visibleRows = 0;
bShowH = false;
bShowV = false;
xCoord = 0;
}
else
{
if ( bAllowShowHBar && (longestLineValue > (rect.width - borderWidth)) )
{
bShowH = true;
hHt = barSize;
}
else
{
bShowH = false;
hHt = 0;
}
rows = (rect.height - hHt - borderWidth) / cellHt;
if ( bAllowShowVBar && (nItems > rows) )
{
bShowV = true;
vWid = barSize;
if (!bShowH)
{
if ( bAllowShowHBar && (longestLineValue > (rect.width - borderWidth - vWid)) )
{
bShowH = true;
hHt = barSize;
rows = (rect.height - hHt - borderWidth) / cellHt;
}
}
}
else
{
bShowV = false;
vWid = 0;
}
if (visibleRows != rows)
{
visibleRows = rows;
bAllDirty = true;
}
if (bShowV)
{
VBar.reshape(rect.width - barSize - halfBorderWidth, halfBorderWidth, barSize, rect.height - borderWidth - hHt);
VBar.setValues(nTopRow, visibleRows, 0, nItems);
VBar.setPageIncrement(visibleRows);
lWidth = rect.width - vWid - borderWidth;
if (!bVBarVisible)
{
bVBarVisible = true;
VBar.show();
}
}
else
{
lWidth = rect.width - borderWidth;
if (bVBarVisible)
{
bVBarVisible = false;
VBar.hide();
}
}
if (bShowH)
{
HBar.reshape(halfBorderWidth, rect.height-barSize-halfBorderWidth, rect.width-borderWidth-vWid, barSize);
HBar.setValues(-xCoord, lWidth, 0, longestLineValue);
HBar.setPageIncrement(lWidth);
if (!bHBarVisible)
{
bHBarVisible = true;
HBar.show();
}
}
else
{
if (bHBarVisible)
{
bHBarVisible = false;
HBar.hide();
}
}
}
if (nItems == 0 || bAllDirty)
{
g.clearRect(halfBorderWidth, halfBorderWidth, rect.width - borderWidth - 1, rect.height - borderWidth - 1);
}
if (borderType == 0)
{
g.setColor(borderDarkerColor);
g.drawLine(0, 0, rect.width - 1, 0);
g.drawLine(0, 0, 0, rect.height - 1);
g.setColor(borderDarkColor);
g.drawLine(1, 1, rect.width - 2, 1);
g.drawLine(1, 1, 1, rect.height - 2);
g.setColor(borderLightColor);
g.drawLine(1, rect.height - 2, rect.width - 2, rect.height - 2 );
g.drawLine(rect.width - 2, 1, rect.width - 2, rect.height - 2 );
g.setColor(borderLighterColor);
g.drawLine(0, rect.height - 1, rect.width - 1, rect.height - 1 );
g.drawLine(rect.width - 1, 0, rect.width - 1, rect.height - 1 );
}
g.clipRect(halfBorderWidth, halfBorderWidth, lWidth, rect.height - borderWidth);
if (nTopRow >= nItems)
nTopRow -= visibleRows + 1;
i = nTopRow;
j = Math.min(nTopRow + visibleRows, nItems);
for (int dp = 0; i < j && items.size() > 0; ++i, ++dp)
{
yLoc = ( (dp) * (cellHt) ) + halfBorderWidth;
ySLoc = ( (dp + 1) * (cellHt) ) + halfBorderWidth;
item = (ListItem)items.elementAt(i);
if (item.bDirty || bAllDirty)
{
item.bDirty = false;
g.clearRect(halfBorderWidth, yLoc, lWidth, cellHt);
}
if (item.image != null)
xSelectStartLoc = halfBorderWidth + IMAGE_WIDTH + 2;
else
xSelectStartLoc = halfBorderWidth;
if (item.bCellBorder)
gridAdj = 2;
else
gridAdj = 0;
if (item.bSelected)
{
g.setColor(textHighlight);
g.fillRect(xCoord + xSelectStartLoc + gridAdj, yLoc, lWidth-xCoord, cellHt);
g.setColor(textHighlightText);
}
else
{
if (item.bEnabled)
{
if (item.color == null)
g.setColor(enabledColor);
else
g.setColor(item.color);
}
else
g.setColor(disabledColor);
}
g.drawString(item.sText, xCoord + xSelectStartLoc + gridAdj + 2, ySLoc-fontDescent);
if (item.image != null)
g.drawImage(item.image, xCoord + halfBorderWidth + gridAdj + 2, yLoc+2, IMAGE_WIDTH, cellHt-3, this);
if (item.bCellBorder)
{
g.setColor(item.cellBorderColor);
g.drawRect(halfBorderWidth, yLoc, lWidth, cellHt);
}
}
extraPaint(g, rect);
bAllDirty = false;
}
/**
* Override this method to add any special painting effects after text and images are painted
* @param g the graphics
* @param rect the bounding rectangle
*/
public void extraPaint(Graphics g, Rectangle rect)
{
}
/**
* Makes this component visible.
* This is a standard Java AWT method which gets called to show this
* component. If this component was invisible due to a previous hide()
* call it make this component visible again.
*
* @see java.awt.Component#hide
*/
public synchronized void show()
{
bAllDirty = true;
super.show();
}
/**
* Moves and/or resizes this component.
* This is a standard Java AWT method which gets called to move and/or
* resize this component. Components that are in containers with layout
* managers should not call this method, but rely on the layout manager
* instead.
*
* @param x horizontal position in the parent's coordinate space
* @param y vertical position in the parent's coordinate space
* @param width the new width
* @param height the new height
*/
public synchronized void reshape(int x, int y, int width, int height)
{
bAllDirty = true;
super.reshape(x, y, width, height);
}
//--------------------------------------------------
// event methods
//--------------------------------------------------
/**
* Adds the specified item listener to receive item events
* @param l the item listener
* @see #removeItemListener
* @see #sourceItemEvent
*/
public synchronized void addItemListener(ItemListener l)
{
itemListener = AWTEventMulticaster.add(itemListener, l);
}
/**
* Removes the specified item listener so it no longer receives
* item events.
* @param l the action listener
* @see #addItemListener
* @see #sourceItemEvent
*/
public synchronized void removeItemListener(ItemListener l)
{
itemListener = AWTEventMulticaster.remove(itemListener, l);
}
/**
* Adds the specified action listener to receive action events
* from this component.
* @param l the action listener
*/
public synchronized void addActionListener(ActionListener l)
{
actionListener = AWTEventMulticaster.add(actionListener, l);
}
/**
* Removes the specified action listener so it no longer receives
* action events from this component.
* @param l the action listener
*/
public synchronized void removeActionListener(ActionListener l)
{
actionListener = AWTEventMulticaster.remove(actionListener, l);
}
/**
* Adds a listener for all event changes.
* @param PropertyChangeListener listener the listener to add.
* @see #removePropertyChangeListener
*/
public synchronized void addPropertyChangeListener(PropertyChangeListener 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)
{
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)
{
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)
{
vetos.removeVetoableChangeListener(listener);
}
/**
* This is the Mouse Event handling innerclass.
*/
class Mouse extends java.awt.event.MouseAdapter implements java.io.Serializable
{
/**
* Handles Mouse Pressed events
* @param e the MouseEvent
*/
public void mousePressed(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
int index = -1;
requestFocus();
fastDownCount++;
bMouseDrawHandled = false;
if ( (x > -1) && (x < lWidth) )
{
index = mouseCalcIndex(y);
if (index == -1)
return;
if (bMultipleSelections)
{
if(e.isShiftDown() && e.isControlDown())
{
bMouseDrawHandled = true;
try { shiftSelect(index, true); } catch(PropertyVetoException exc) {}
}
else if(e.isShiftDown())
{
bMouseDrawHandled = true;
try { shiftSelect(index, false); } catch(PropertyVetoException exc) {}
}
else if(e.isControlDown())
{
bMouseDrawHandled = true;
ctrlSelect(index);
}
else
{
try { setSelectedIndex(index, true); } catch(PropertyVetoException exc) {}
}
}
else
{
lastTempIndex = index;
try { setSelectedIndex(index, true); } catch(PropertyVetoException exc) {}
}
repaint();
}
}
/**
* Handles Mouse Released events
* @param e the MouseEvent
*/
public void mouseReleased(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
int index = -1;
boolean bDoubleClick;
long selectTime;
fastDownCount--;
if (bMouseDrawHandled) // multi-selected ctrl or shift
{
notifyHelper(-1, y, -1, false);
return;
}
index = mouseCalcIndex(y);
if ( (index == -1) || (x < 0) || (x >= lWidth) )
{
fastDownCount = 0;
index = lastTempIndex;
if (index == -1)
return;
}
if (bComboMode)
{
fastDownCount = 0;
bDoubleClick = false;
}
else
{
// sometimes you get two MOUSE_DOWNS before the first MOUSE_UP
if (fastDownCount > 0)
{
fastDownCount = 0;
bDoubleClick = true;
prevSelectTime = -1;
prevSelectRow = -1;
}
else
{
selectTime = System.currentTimeMillis();
if ( (prevSelectTime != -1) && // valid prevSelectTime
(prevSelectRow == index) && //
((prevSelectTime + 250) > selectTime) // A double click
)
{
bDoubleClick = true;
prevSelectTime = -1;
prevSelectRow = -1;
}
else
{
bDoubleClick = false;
prevSelectTime = selectTime;
prevSelectRow = index;
}
}
}
if (lastSelected != index)
{
try { setSelectedIndex(index, true); } catch(PropertyVetoException exc) {}
repaint();
}
if (bMultipleSelections)
{
notifyHelper(x, y, lastSelected, bDoubleClick);
lastIndex = lastSelected;
}
else
{
notifyHelper(x, y, index, bDoubleClick);
lastIndex = index;
}
lastTempIndex = -1;
lastDownModifiers = -1;
}
/**
* Handles Mouse Exited events
* @param e the MouseEvent
*/
public void mouseExited(MouseEvent e)
{
if (!bMultipleSelections && bComboMode)
lastIndex = -1;
}
}
/**
* This is the MouseMotion Event handling innerclass.
*/
class MouseMotion implements java.awt.event.MouseMotionListener, java.io.Serializable
{
/**
* Handles Mouse Moved events
* @param e the MouseEvent
*/
public void mouseMoved(MouseEvent e)
{
if(!bMultipleSelections)
{
int x = e.getX();
int y = e.getY();
int index = -1;
if ( (x > -1) && (x < lWidth) )
{
if (bComboMode)
{
index = mouseCalcIndex(y);
if (index == -1 || index == lastIndex)
return;
lastIndex = index;
try { setSelectedIndex(index, true); } catch(PropertyVetoException exc) {}
repaint();
}
}
}
}
/**
* Handles Mouse Dragged events
* @param e the MouseEvent
*/
public void mouseDragged(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
int index = -1;
if ( (x > -1) && (x < lWidth) )
{
if (bComboMode)
{
index = mouseCalcIndex(y);
if (index == -1 || index == lastIndex)
return;
lastIndex = index;
try { setSelectedIndex(index, true); } catch(PropertyVetoException exc) {}
repaint();
}
else
{
index = mouseCalcIndex(y);
if (index != -1 && index != lastIndex)
{
if (bMultipleSelections)
{
if (e.getModifiers() != 0)
return;
bInternalBlockPaint = true;
try { setVisibleIndex(index); } catch(PropertyVetoException exc){}
bInternalBlockPaint = false;
try { shiftSelect(index, false); } catch(PropertyVetoException exc) {}
}
else
{
try { setSelectedIndex(index, true); } catch(PropertyVetoException exc) {}
}
lastIndex = index;
}
}
}
}
}
/**
* This is the Key Event handling innerclass.
*/
class Key extends java.awt.event.KeyAdapter implements java.io.Serializable
{
/**
* Handles Key Pressed events
* @param e the KeyEvent
*/
public void keyPressed(KeyEvent e)
{
if (e.isControlDown() || e.isMetaDown() || e.isAltDown())
return;
int index = -1;
switch(e.getKeyCode())
{
case KeyEvent.VK_HOME:
index = keyCalcIndex(0, true);
break;
case KeyEvent.VK_END:
index = keyCalcIndex(items.size() - 1, true);
break;
case KeyEvent.VK_PAGE_UP:
index = keyCalcIndex(-visibleRows, false);
break;
case KeyEvent.VK_PAGE_DOWN:
index = keyCalcIndex(visibleRows, false);
break;
case KeyEvent.VK_UP:
index = keyCalcIndex(-1, false);
break;
case KeyEvent.VK_DOWN:
index = keyCalcIndex(1, false);
break;
}
if (index == -1)
return;
if (bMultipleSelections && e.isShiftDown())
{
try { setVisibleIndex(index); } catch(PropertyVetoException exc){}
try { shiftSelect(index, false); } catch(PropertyVetoException exc){}
return;
}
// regular select, multiple or single
try { setSelectedIndex(index, true); } catch(PropertyVetoException exc) {}
repaint();
notifyHelper(-1, -1, index, false);
prevSelectTime = -1;
prevSelectRow = -1;
}
}
/**
* This is the Adjustment Event handling innerclass.
*/
class Adjustment implements java.awt.event.AdjustmentListener, java.io.Serializable
{
/**
* Handles ScrollBar events
* @param e the AdjustmentEvent
*/
public void adjustmentValueChanged(AdjustmentEvent e)
{
//We are only listening to the VBar and the HBar...
if(e.getSource() == VBar)
{
if(e.getAdjustmentType() == AdjustmentEvent.TRACK)
scrollVertical(e.getValue(), true);
else
scrollVertical(e.getAdjustmentType(), false);
}
else if(e.getSource() == HBar)
{
if(e.getAdjustmentType() == AdjustmentEvent.TRACK)
scrollHorizontal(e.getValue(), true);
else
scrollHorizontal(e.getAdjustmentType(), false);
}
}
}
/**
* Fire an item event to the listeners
* @see #addItemListener
* @see #removeItemListener
*/
protected void sourceItemEvent()
{
if (itemListener != null)
itemListener.itemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED, this, ItemEvent.SELECTED));
}
/**
* Fire an action event to the listeners
* @param command the string containing the command to send
* with the event.
*/
protected void sourceActionEvent(String command)
{
if (actionListener != null)
actionListener.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, command));
}
/**
* Determines if the given index is valid.
* @param index a zero-relative index to check
* @return true if the index is valid, false if not
*/
protected boolean validIndex(int index)
{
if (index >= 0 && index < items.size())
return true;
return false;
}
/**
* Determines if the item at the given index is visible.
* @param index the zero-relative index of the item to check
* @return true if the item is visible, false if not
*/
protected boolean isVisibleIndex(int index)
{
if (index >= nTopRow && index < (nTopRow + visibleRows))
return true;
return false;
}
/**
* Returns a string representing the state of this object.
* This is a standard Java AWT method which can be usefull for debugging.
*
* @return a handy string for debugging purposes
*/
protected String paramString()
{
return super.paramString() + ", selected=" + getSelectedItem();
}
/**
* Selects an index in a multiple-selection-enabled ImageListBox
* using Shift or Ctrl-Shift modifiers to mimic mouse
* selecting with the Shift or Ctrl-Shift modifiers.
* @param index the zero-relative position of the item to select
* @param bControl whether to select with the Ctrl modifier
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
protected void shiftSelect(int index, boolean bControl) throws PropertyVetoException
{
int i = 0;
int s = 0;
ListItem li;
if (lastSelected == -1)
setSelectedIndex(index, true);
else if (lastSelected == index)
{
if (!bControl)
{
bInternalBlockPaint = true;
setSelectedIndex(index, true);
bInternalBlockPaint = false;
}
}
else if (lastSelected < index)
{
if ( !isEnabled(index) )
return;
if (bControl)
{
i = lastSelected + 1;
s = Math.min(items.size(), index + 1);
}
else
{
i = 0;
s = items.size();
}
for (; i < s; i++)
{
li = (ListItem)items.elementAt(i);
if (i < lastSelected || i > index)
{
if (li.bSelected)
{
li.bDirty = true;
li.bSelected = false;
countSelected--;
}
}
else
{
if (!li.bSelected)
{
li.bDirty = true;
li.bSelected = true;
countSelected++;
}
}
}
}
else if (lastSelected > index)
{
if ( !isEnabled(index) )
return;
if (bControl)
{
i = index;
s = Math.min(items.size(), lastSelected);
}
else
{
i = 0;
s = items.size();
}
for (i = 0; i < s; i++)
{
li = (ListItem)items.elementAt(i);
if (i < index || i > lastSelected)
{
if (li.bSelected)
{
li.bDirty = true;
li.bSelected = false;
countSelected--;
}
}
else
{
if (!li.bSelected)
{
li.bDirty = true;
li.bSelected = true;
countSelected++;
}
}
}
}
if (!bInternalBlockPaint) repaint();
}
/**
* Selects an index in a ImageListBox using the Ctrl modifier
* to mimic mouse selecting with the Ctrl modifier.
* @param index the zero-relative position of the item to select
*/
protected void ctrlSelect(int index)
{
ListItem listItem = (ListItem)items.elementAt(index);
if (!listItem.bEnabled)
return;
if (listItem.bSelected)
{
listItem.bSelected = false;
countSelected--;
lastSelected = -1;
}
else
{
listItem.bSelected = true;
countSelected++;
lastSelected = index;
}
listItem.bDirty = true;
if (!bInternalBlockPaint) repaint();
}
/**
* A utility routine that determines the index of the item the mouse is in,
* given the vertical coordinate of the mouse.
* @param y mouse vertical (y) coordinate
* @return the zero-relative index of the item the mouse is in, or -1 if
* past the end of the list
*/
protected int mouseCalcIndex(int y)
{
int mci;
if (y < yAdj)
mci = nTopRow - 1;
else
mci = ((y - yAdj) / cellHt) + nTopRow;
if (mci >= items.size())
mci = -1;
else if (mci < 0)
mci = 0;
return mci;
}
/**
* Adds an ListItem to the end of the list.
* @param li the item to add
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #setListItems(java.lang.String[])
* @see #addItem(java.lang.String)
* @see #addItem(java.lang.String, boolean)
* @see #addItem(java.awt.Image, java.lang.String)
* @see #addItem(java.awt.Image, java.lang.String, boolean)
* @see #addItem(java.awt.Image, java.lang.String, boolean, java.awt.Color)
*/
protected void addItem(ListItem li) throws PropertyVetoException
{
if(li != null)
{
String[] oldValue = getListItems();
String[] newValue = new String[oldValue.length + 1];
for(int count = 0; count < oldValue.length; count++)
newValue[count] = new String(oldValue[count]);
newValue[oldValue.length] = new String(li.sText);
vetos.fireVetoableChange("ListItems", oldValue, newValue);
if(nTopRow < 0)
{
nTopRow = 0;
}
items.addElement(li);
updateWidth(li);
if (!bInternalBlockPaint) repaint();
changes.firePropertyChange("ListItems", oldValue, getListItems());
}
}
private void updateWidth(ListItem li)
{
int lineWidth = li.lineWidth + LINE_SLOP;
if (li.image != null)
lineWidth += IMAGE_WIDTH;
if ( lineWidth > longestLineValue)
longestLineValue = lineWidth;
}
private void updateWidths(FontMetrics fm)
{
longestLineValue = 0;
int s = items.size();
int lineWidth = 0;
ListItem li;
for (int x = 0; x < s; x++)
{
li = (ListItem)items.elementAt(x);
li.updateWidth(fm);
lineWidth = li.lineWidth + LINE_SLOP;
if (li.image != null)
lineWidth += IMAGE_WIDTH;
if ( lineWidth > longestLineValue)
longestLineValue = lineWidth;
}
}
/**
* Utility routine to generate action and/or item events in response to
* key or mouse events.
* @param x mouse component-relative horizontal position, in pixels
* @param x mouse component-relative vertical position, in pixels
* @param index zero-relative index of currently selected item
* @param bDoubleClick true if mouse double-clicked on item
*/
protected void notifyHelper(int x, int y, int index, boolean bDoubleClick)
{
if (bDoubleClick)
{
sourceActionEvent("DoubleClicked");
}
else
{
//inside image display area, and line has image!
if (x >= 0 && (x - xCoord) < IMAGE_WIDTH)
{
ListItem listItem = (ListItem)items.elementAt(index);
if (listItem.image != null)
{
sourceActionEvent("ImageSelected");
}
}
sourceItemEvent();
}
}
/**
* Used to calculate the border colors from the background color.
* @see #addNotify
* @see java.awt.Component#setBackground
*/
protected void calculateBorderColors(Color c)
{
borderLighterColor = ColorUtils.calculateHilightColor(c);
borderDarkerColor = ColorUtils.calculateShadowColor(c);
borderLightColor = ColorUtils.darken(borderLighterColor, 0.200);
borderDarkColor = ColorUtils.darken(borderDarkerColor, 0.200);
}
/**
* Determines the current index given a new absolute or relative index.
* @param offset the value used to compute the new index
* @param boolean true if offset is zero-relative, false if offset is
* relative to the current index value
* @return the new current index value
*/
protected int keyCalcIndex(int offset, boolean bAbsolute)
{
if (bAbsolute)
lastIndex = offset;
else
lastIndex += offset;
if (lastIndex >= items.size())
lastIndex = items.size() - 1;
else if (lastIndex < 0)
lastIndex = 0;
return lastIndex;
}
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException
{
in.defaultReadObject();
ListItem li = null;
for (int i = 0; i < items.size(); i++)
{
li = (ListItem) items.elementAt(i);
if (li.url != null) {
li.image = getToolkit().getImage(li.url);
java.awt.MediaTracker tracker = new java.awt.MediaTracker(this);
tracker.addImage(li.image, 0);
try {
tracker.waitForAll();
}
catch(InterruptedException e) {
Object[] args = { li.url };
throw new java.io.IOException(MessageFormat.format(errors.getString("ErrorLoadingImageForURL"), args));
}
}
}
}
/**
* Zero-relative index of the item displayed in the top row.
*/
protected int nTopRow = 0;
/**
* Width of the list content portion of this component, in pixels.
* This excludes the border and vertical scroll bar, if present.
*/
protected int lWidth = 0;
/**
* Height of a single list cell, in pixels.
*/
protected int cellHt = 0;
/**
* Top margin before the contents of the first list item, in pixels.
*/
protected int yAdj = 0;
/**
* Width of the left and right borders combined, in pixels.
*/
protected int borderWidth = 4;
/**
* Width of the left or right border, in pixels.
*/
protected int halfBorderWidth = 2;
ActionListener actionListener = null;
ItemListener itemListener = null;
/**
* Extra space at end of a line.
*/
protected final int LINE_SLOP = 6;
/**
* The label of this listbox (not displayed).
*/
protected String ilbLabel;
/**
* The vertical scroll bar. It always exists event if not shown or showable.
*/
protected Scrollbar VBar = null;
/**
* The horizontal scroll bar. It always exists event if not shown or showable.
*/
protected Scrollbar HBar = null;
/**
* A vector of the items in the list.
*/
protected Vector items;
/**
* The font used for drawing text.
*/
protected Font font;
/**
* The font metrics of the font used for drawing text.
*/
transient protected FontMetrics fm = null;
/**
* If true the list is dirty (needs repaint).
*/
transient protected boolean bAllDirty = true;
/**
* It true multiple list items can be selected at the same time.
*/
protected boolean bMultipleSelections = false;
/**
* If true the repainting of the control is prevented.
*/
protected boolean bBlockPaint = false;
/**
* True if the vertical scroll bar is currently visible.
*/
protected boolean bVBarVisible = false;
/**
* True if the horizontal scroll bar is currently visible.
*/
protected boolean bHBarVisible = false;
/**
* True if repainting is temporarily disabled for efficiency purposes.
*/
transient protected boolean bInternalBlockPaint = false;
/**
* The number of rows to show when this component is automatically laid out.
* If rows is less than or equal to zero, it will size to show all of the
* existing list items when automatically laid out.
*/
protected int rowsToShow = -1;
/**
* The number of columns to show when this component is automatically laid out.
*/
protected int colsToShow = 10;
/**
* The number of currently visible lines in this list.
*/
transient protected int visibleRows = -1;
/**
* The number of currently visible columns in this list.
*/
transient protected int visibleCols = -1;
/**
* The zero-relative index of the first visible list item.
*/
protected int visibleIndex = -1;
/**
* The standard height of a line of text in the current font.
*/
transient protected int fontHeight;
/**
* The typical distance from the base line to the bottom of most characters
* in the current font.
*/
transient protected int fontDescent;
/**
* Not used.
*/
transient protected int lastDownModifiers = -1;
/**
* The zero-relative index of the currently selected item in the list.
* If multiple items are selected, this is the index of the item most
* recently selected. If no items are selected, the value is -1.
*/
transient protected int lastSelected = -1;
/**
* The zero-relative index of the item the mouse was last moved over,
* dragged over, or clicked on. This field is only valid while the
* mouse is over this component. When the mouse is not over this component
* the value is -1.
*/
transient protected int lastIndex = -1;
/**
* The zero-relative index of the item the mouse was pressed on.
* It is used when bMultipleSelections is false, and valid
* between the time the mouse is pressed and released.
* All other times it equals -1.
*/
transient protected int lastTempIndex = -1;
/**
* The number of list items currently selected.
*/
transient protected int countSelected = 0;
/**
* The current border type of this ImageListBox, one of BORDER_REGULAR or
* BORDER_NONE.
* A regular border makes the list box appear lower than the surrounding area.
* @see #getBorderType
* @see #BORDER_REGULAR
* @see #BORDER_NONE
*/
protected int borderType = 0;
/**
* The width of the widest list item, in pixels.
*/
protected int longestLineValue = 0;
/**
* The width of scroll bars, in pixels. Calculated in addNotify.
*/
transient protected int barSize = 0;
/**
* The amount the list items are scrolled horizontally, in pixels.
*/
protected int xCoord = 0;
/**
* The time at which the mouse was released, in milliseconds.
* This is used to determine when a double-click occurs.
*/
transient protected long prevSelectTime = -1;
/**
* The zero-relative index of the row at which the mouse was
* previously released.
* This is used to determine when a double-click occurs.
*/
transient protected long prevSelectRow = -1;
/**
* If true this ImageListBox is in "ComboBox mode".
* "ComboBox mode" allows the selection point to follow
* the mouse even when the mouse button is not down.
* This only applies when the ImageListBox is not allowing multiple
* selections.
*
* @see #setComboMode
*/
protected boolean bComboMode = false;
/**
* If true list items have borders by default.
* Borders are always shown as a solid single-pixel wide line around
* the cell.
*
* @see #setCellBorders
*/
protected boolean bCellBorders = false;
/**
* If true the vertical scrollbar will be made
* visible when necessary, false if it will never be made visible.
* @see #setShowVerticalScroll
*/
protected boolean bAllowShowVBar = true;
/**
* If true the horizontal scrollbar will be made
* visible when necessary, false if it will never be made visible.
* @see #setShowHorizontalScroll
*/
protected boolean bAllowShowHBar = true;
/**
* Color used in drawing of the border.
*/
protected Color borderLighterColor = null;
/**
* Color used in drawing of the border.
*/
protected Color borderDarkerColor = null;
/**
* Color used in drawing of the border.
*/
protected Color borderLightColor = null;
/**
* Color used in drawing of the border.
*/
protected Color borderDarkColor = null;
/**
* Cached value of the background color. Used to determine if calculated colors need to be updated.
*/
protected Color cachedBackground = null;
//!!! LAB !!! Come back and remove this isMacintosh stuff once MRJ handles SystemColor!
/**
* The background color for highlighted text.
*/
protected Color textHighlight = symantec.itools.lang.OS.isMacintosh() ? new Color(0,0,128) : SystemColor.textHighlight;
/**
* The text color for highlighted text.
*/
protected Color textHighlightText = symantec.itools.lang.OS.isMacintosh() ? Color.white : SystemColor.textHighlightText;
/**
* The default color for enabled text items.
*/
protected Color enabledColor = symantec.itools.lang.OS.isMacintosh() ? Color.black : SystemColor.textText;
/**
* The default color for disabled text items.
*/
protected Color disabledColor = symantec.itools.lang.OS.isMacintosh() ? Color.gray : SystemColor.textInactiveText;
/**
* Used to detect two mouse pressed events without a mouse released
* event in-between. This may sometimes happen if the mouse is pressed
* twice very quickly.
*/
protected int fastDownCount = 0;
/**
* True if drawing was handled on mouse down and no drawing action needs
* to be taken on mouse up.
*/
protected boolean bMouseDrawHandled = false;
/**
* Error strings.
*/
transient protected ResourceBundle errors;
private Mouse mouse = null;
private MouseMotion mouseMotion = null;
private Key key = null;
private Adjustment adjustment = 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);
}