[llvm-commits] [llvm-gcc-4.2] r43913 [50/80] - in /llvm-gcc-4.2/trunk: boehm-gc/ boehm-gc/Mac_files/ boehm-gc/cord/ boehm-gc/doc/ boehm-gc/include/ boehm-gc/include/private/ boehm-gc/tests/ libffi/ libffi/include/ libffi/src/ libffi/src/alpha/ libffi/src/arm/ libffi/src/cris/ libffi/src/frv/ libffi/src/ia64/ libffi/src/m32r/ libffi/src/m68k/ libffi/src/mips/ libffi/src/pa/ libffi/src/powerpc/ libffi/src/s390/ libffi/src/sh/ libffi/src/sh64/ libffi/src/sparc/ libffi/src/x86/ libffi/testsuite/ libffi/testsuite/config/ li...
Bill Wendling
isanbard at gmail.com
Thu Nov 8 14:57:11 PST 2007
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/JTree.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/JTree.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/JTree.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/JTree.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,3087 @@
+/* JTree.java
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import java.awt.Color;
+import java.awt.Cursor;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.event.FocusListener;
+import java.beans.PropertyChangeListener;
+import java.io.Serializable;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Vector;
+
+import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleAction;
+import javax.accessibility.AccessibleComponent;
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleRole;
+import javax.accessibility.AccessibleSelection;
+import javax.accessibility.AccessibleState;
+import javax.accessibility.AccessibleStateSet;
+import javax.accessibility.AccessibleText;
+import javax.accessibility.AccessibleValue;
+import javax.swing.event.TreeExpansionEvent;
+import javax.swing.event.TreeExpansionListener;
+import javax.swing.event.TreeModelEvent;
+import javax.swing.event.TreeModelListener;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.event.TreeWillExpandListener;
+import javax.swing.plaf.TreeUI;
+import javax.swing.text.Position;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.DefaultTreeSelectionModel;
+import javax.swing.tree.ExpandVetoException;
+import javax.swing.tree.TreeCellEditor;
+import javax.swing.tree.TreeCellRenderer;
+import javax.swing.tree.TreeModel;
+import javax.swing.tree.TreeNode;
+import javax.swing.tree.TreePath;
+import javax.swing.tree.TreeSelectionModel;
+
+public class JTree extends JComponent implements Scrollable, Accessible
+{
+
+ /**
+ * This class implements accessibility support for the JTree class. It
+ * provides an implementation of the Java Accessibility API appropriate
+ * to tree user-interface elements.
+ */
+ protected class AccessibleJTree extends JComponent.AccessibleJComponent
+ implements AccessibleSelection, TreeSelectionListener, TreeModelListener,
+ TreeExpansionListener
+ {
+
+ /**
+ * This class implements accessibility support for the JTree child. It provides
+ * an implementation of the Java Accessibility API appropriate to tree nodes.
+ */
+ protected class AccessibleJTreeNode extends AccessibleContext
+ implements Accessible, AccessibleComponent, AccessibleSelection,
+ AccessibleAction
+ {
+
+ private JTree tree;
+ private TreePath tp;
+ private Accessible acc;
+ private AccessibleStateSet states;
+ private Vector selectionList;
+ private Vector actionList;
+ private TreeModel mod;
+ private Cursor cursor;
+
+ /**
+ * Constructs an AccessibleJTreeNode
+ *
+ * @param t - the current tree
+ * @param p - the current path to be dealt with
+ * @param ap - the accessible object to use
+ */
+ public AccessibleJTreeNode(JTree t, TreePath p, Accessible ap)
+ {
+ states = new AccessibleStateSet();
+ selectionList = new Vector();
+ actionList = new Vector();
+ mod = tree.getModel();
+ cursor = JTree.this.getCursor();
+
+ tree = t;
+ tp = p;
+ acc = ap;
+
+ // Add all the children of this path that may already be
+ // selected to the selection list.
+ TreePath[] selected = tree.getSelectionPaths();
+ for (int i = 0; i < selected.length; i++)
+ {
+ TreePath sel = selected[i];
+ if ((sel.getParentPath()).equals(tp))
+ selectionList.add(sel);
+ }
+
+ // Add all the actions available for a node to
+ // the action list.
+ actionList.add("EXPAND");
+ actionList.add("COLLAPSE");
+ actionList.add("EDIT");
+ actionList.add("SELECT");
+ actionList.add("DESELECT");
+ }
+
+ /**
+ * Adds the specified selected item in the object to the object's
+ * selection.
+ *
+ * @param i - the i-th child of this node.
+ */
+ public void addAccessibleSelection(int i)
+ {
+ if (mod != null)
+ {
+ Object child = mod.getChild(tp.getLastPathComponent(), i);
+ if (child != null)
+ {
+ if (!states.contains(AccessibleState.MULTISELECTABLE))
+ clearAccessibleSelection();
+ selectionList.add(child);
+ tree.addSelectionPath(tp.pathByAddingChild(child));
+ }
+ }
+ }
+
+ /**
+ * Adds the specified focus listener to receive focus events
+ * from this component.
+ *
+ * @param l - the new focus listener
+ */
+ public void addFocusListener(FocusListener l)
+ {
+ tree.addFocusListener(l);
+ }
+
+ /**
+ * Add a PropertyChangeListener to the listener list.
+ *
+ * @param l - the new property change listener
+ */
+ public void addPropertyChangeListener(PropertyChangeListener l)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Clears the selection in the object, so that nothing in the
+ * object is selected.
+ */
+ public void clearAccessibleSelection()
+ {
+ selectionList.clear();
+ }
+
+ /**
+ * Checks whether the specified point is within this object's
+ * bounds, where the point's x and y coordinates are defined to be
+ * relative to the coordinate system of the object.
+ *
+ * @param p - the point to check
+ * @return true if p is in the bounds
+ */
+ public boolean contains(Point p)
+ {
+ return getBounds().contains(p);
+ }
+
+ /**
+ * Perform the specified Action on the tree node.
+ *
+ * @param i - the i-th action to perform
+ * @return true if the the action was performed; else false.
+ */
+ public boolean doAccessibleAction(int i)
+ {
+ if (i >= actionList.size() || i < 0)
+ return false;
+
+ if (actionList.get(i).equals("EXPAND"))
+ tree.expandPath(tp);
+ else if (actionList.get(i).equals("COLLAPSE"))
+ tree.collapsePath(tp);
+ else if (actionList.get(i).equals("SELECT"))
+ tree.addSelectionPath(tp);
+ else if (actionList.get(i).equals("DESELECT"))
+ tree.removeSelectionPath(tp);
+ else if (actionList.get(i).equals("EDIT"))
+ tree.startEditingAtPath(tp);
+ else
+ return false;
+ return true;
+ }
+
+ /**
+ * Get the AccessibleAction associated with this object.
+ *
+ * @return the action
+ */
+ public AccessibleAction getAccessibleAction()
+ {
+ return this;
+ }
+
+ /**
+ * Returns the number of accessible actions available in this tree node.
+ *
+ * @return the number of actions
+ */
+ public int getAccessibleActionCount()
+ {
+ return actionList.size();
+ }
+
+ /**
+ * Return a description of the specified action of the tree node.
+ *
+ * @param i - the i-th action's description
+ * @return a description of the action
+ */
+ public String getAccessibleActionDescription(int i)
+ {
+ if (i < 0 || i >= actionList.size())
+ return (actionList.get(i)).toString();
+ return super.getAccessibleDescription();
+ }
+
+ /**
+ * Returns the Accessible child, if one exists, contained at the
+ * local coordinate Point.
+ *
+ * @param p - the point of the accessible
+ * @return the accessible at point p if it exists
+ */
+ public Accessible getAccessibleAt(Point p)
+ {
+ TreePath acc = tree.getClosestPathForLocation(p.x, p.y);
+ if (acc != null)
+ return new AccessibleJTreeNode(tree, acc, this);
+ return null;
+ }
+
+ /**
+ * Return the specified Accessible child of the object.
+ *
+ * @param i - the i-th child of the current path
+ * @return the child if it exists
+ */
+ public Accessible getAccessibleChild(int i)
+ {
+ if (mod != null)
+ {
+ Object child = mod.getChild(tp.getLastPathComponent(), i);
+ if (child != null)
+ return new AccessibleJTreeNode(tree, tp.pathByAddingChild(child),
+ acc);
+ }
+ return null;
+ }
+
+ /**
+ * Returns the number of accessible children in the object.
+ *
+ * @return the number of children the current node has
+ */
+ public int getAccessibleChildrenCount()
+ {
+ TreeModel mod = getModel();
+ if (mod != null)
+ return mod.getChildCount(tp.getLastPathComponent());
+ return 0;
+ }
+
+ /**
+ * Get the AccessibleComponent associated with this object.
+ *
+ * @return the accessible component if it is supported.
+ */
+ public AccessibleComponent getAccessibleComponent()
+ {
+ return this;
+ }
+
+ /**
+ * Get the AccessibleContext associated with this tree node.
+ *
+ * @return an instance of this class
+ */
+ public AccessibleContext getAccessibleContext()
+ {
+ return this;
+ }
+
+ /**
+ * Get the accessible description of this object.
+ *
+ * @return the accessible description
+ */
+ public String getAccessibleDescription()
+ {
+ return super.getAccessibleDescription();
+ }
+
+ /**
+ * Get the index of this object in its accessible parent.
+ *
+ * @return the index of this in the parent.
+ */
+ public int getAccessibleIndexInParent()
+ {
+ AccessibleContext parent = getAccessibleParent().getAccessibleContext();
+ if (parent != null)
+ for (int i = 0; i < parent.getAccessibleChildrenCount(); i++)
+ {
+ if ((parent.getAccessibleChild(i)).equals(this))
+ return i;
+ }
+ return -1;
+ }
+
+ /**
+ * Get the accessible name of this object.
+ *
+ * @return the accessible name
+ */
+ public String getAccessibleName()
+ {
+ return super.getAccessibleName();
+ }
+
+ /**
+ * Get the Accessible parent of this object.
+ *
+ * @return the accessible parent if it exists.
+ */
+ public Accessible getAccessibleParent()
+ {
+ return super.getAccessibleParent();
+ }
+
+ /**
+ * Get the role of this object.
+ *
+ * @return the accessible role
+ */
+ public AccessibleRole getAccessibleRole()
+ {
+ return AccessibleJTree.this.getAccessibleRole();
+ }
+
+ /**
+ * Get the AccessibleSelection associated with this object if one exists.
+ *
+ * @return the accessible selection for this.
+ */
+ public AccessibleSelection getAccessibleSelection()
+ {
+ return this;
+ }
+
+ /**
+ * Returns an Accessible representing the specified selected item
+ * in the object.
+ *
+ * @return the accessible representing a certain selected item.
+ */
+ public Accessible getAccessibleSelection(int i)
+ {
+ if (i > 0 && i < getAccessibleSelectionCount())
+ return new AccessibleJTreeNode(tree,
+ tp.pathByAddingChild(selectionList.get(i)), acc);
+ return null;
+ }
+
+ /**
+ * Returns the number of items currently selected.
+ *
+ * @return the number of items selected.
+ */
+ public int getAccessibleSelectionCount()
+ {
+ return selectionList.size();
+ }
+
+ /**
+ * Get the state set of this object.
+ *
+ * @return the state set for this object
+ */
+ public AccessibleStateSet getAccessibleStateSet()
+ {
+ if (isVisible())
+ states.add(AccessibleState.VISIBLE);
+ if (tree.isCollapsed(tp))
+ states.add(AccessibleState.COLLAPSED);
+ if (tree.isEditable())
+ states.add(AccessibleState.EDITABLE);
+ if (mod != null &&
+ !mod.isLeaf(tp.getLastPathComponent()))
+ states.add(AccessibleState.EXPANDABLE);
+ if (tree.isExpanded(tp))
+ states.add(AccessibleState.EXPANDED);
+ if (isFocusable())
+ states.add(AccessibleState.FOCUSABLE);
+ if (hasFocus())
+ states.add(AccessibleState.FOCUSED);
+ if (tree.getSelectionModel().getSelectionMode() !=
+ TreeSelectionModel.SINGLE_TREE_SELECTION)
+ states.add(AccessibleState.MULTISELECTABLE);
+ if (tree.isOpaque())
+ states.add(AccessibleState.OPAQUE);
+ if (tree.isPathSelected(tp))
+ states.add(AccessibleState.SELECTED);
+ if (isShowing())
+ states.add(AccessibleState.SHOWING);
+
+ states.add(AccessibleState.SELECTABLE);
+ return states;
+ }
+
+ /**
+ * Get the AccessibleText associated with this object if one exists.
+ *
+ * @return the accessible text
+ */
+ public AccessibleText getAccessibleText()
+ {
+ return super.getAccessibleText();
+ }
+
+ /**
+ * Get the AccessibleValue associated with this object if one exists.
+ *
+ * @return the accessible value if it exists
+ */
+ public AccessibleValue getAccessibleValue()
+ {
+ return super.getAccessibleValue();
+ }
+
+ /**
+ * Get the background color of this object.
+ *
+ * @return the color of the background.
+ */
+ public Color getBackground()
+ {
+ return tree.getBackground();
+ }
+
+ /**
+ * Gets the bounds of this object in the form of a Rectangle object.
+ *
+ * @return the bounds of the current node.
+ */
+ public Rectangle getBounds()
+ {
+ return tree.getPathBounds(tp);
+ }
+
+ /**
+ * Gets the Cursor of this object.
+ *
+ * @return the cursor for the current node
+ */
+ public Cursor getCursor()
+ {
+ return cursor;
+ }
+
+ /**
+ * Gets the Font of this object.
+ *
+ * @return the font for the current node
+ */
+ public Font getFont()
+ {
+ return tree.getFont();
+ }
+
+ /**
+ * Gets the FontMetrics of this object.
+ *
+ * @param f - the current font.
+ * @return the font metrics for the given font.
+ */
+ public FontMetrics getFontMetrics(Font f)
+ {
+ return tree.getFontMetrics(f);
+ }
+
+ /**
+ * Get the foreground color of this object.
+ *
+ * @return the foreground for this object.
+ */
+ public Color getForeground()
+ {
+ return tree.getForeground();
+ }
+
+ /**
+ * Gets the locale of the component.
+ *
+ * @return the locale of the component.
+ */
+ public Locale getLocale()
+ {
+ return tree.getLocale();
+ }
+
+ /**
+ * Gets the location of the object relative to the
+ * parent in the form of a point specifying the object's
+ * top-left corner in the screen's coordinate space.
+ *
+ * @return the location of the current node.
+ */
+ public Point getLocation()
+ {
+ return getLocationInJTree();
+ }
+
+ /**
+ * Returns the location in the tree.
+ *
+ * @return the location in the JTree.
+ */
+ protected Point getLocationInJTree()
+ {
+ Rectangle bounds = tree.getPathBounds(tp);
+ return new Point(bounds.x, bounds.y);
+ }
+
+ /**
+ * Returns the location of the object on the screen.
+ *
+ * @return the location of the object on the screen.
+ */
+ public Point getLocationOnScreen()
+ {
+ Point loc = getLocation();
+ SwingUtilities.convertPointToScreen(loc, tree);
+ return loc;
+ }
+
+ /**
+ * Returns the size of this object in the form of a Dimension object.
+ *
+ * @return the size of the object
+ */
+ public Dimension getSize()
+ {
+ Rectangle b = getBounds();
+ return b.getSize();
+ }
+
+ /**
+ * Returns true if the current child of this object is selected.
+ *
+ * @param i - the child of the current node
+ * @return true if the child is selected.
+ */
+ public boolean isAccessibleChildSelected(int i)
+ {
+ Object child = mod.getChild(tp.getLastPathComponent(), i);
+ if (child != null)
+ return tree.isPathSelected(tp.pathByAddingChild(child));
+ return false;
+ }
+
+ /**
+ * Determines if the object is enabled.
+ *
+ * @return true if the tree is enabled
+ */
+ public boolean isEnabled()
+ {
+ return tree.isEnabled();
+ }
+
+ /**
+ * Returns whether this object can accept focus or not.
+ *
+ * @return true, it is always focus traversable
+ */
+ public boolean isFocusTraversable()
+ {
+ return true;
+ }
+
+ /**
+ * Determines if the object is showing.
+ *
+ * @return true if the object is visible and the
+ * parent is visible.
+ */
+ public boolean isShowing()
+ {
+ return isVisible() && tree.isShowing();
+ }
+
+ /**
+ * Determines if the object is visible.
+ *
+ * @return true if the object is visible.
+ */
+ public boolean isVisible()
+ {
+ return tree.isVisible(tp);
+ }
+
+ /**
+ * Removes the specified selected item in the object from the
+ * object's selection.
+ *
+ * @param i - the specified item to remove
+ */
+ public void removeAccessibleSelection(int i)
+ {
+ if (mod != null)
+ {
+ Object child = mod.getChild(tp.getLastPathComponent(), i);
+ if (child != null)
+ {
+ if (!states.contains(AccessibleState.MULTISELECTABLE))
+ clearAccessibleSelection();
+ if (selectionList.contains(child))
+ {
+ selectionList.remove(child);
+ tree.removeSelectionPath(tp.pathByAddingChild(child));
+ }
+ }
+ }
+ }
+
+ /**
+ * Removes the specified focus listener so it no longer receives focus
+ * events from this component.
+ *
+ * @param l - the focus listener to remove
+ */
+ public void removeFocusListener(FocusListener l)
+ {
+ tree.removeFocusListener(l);
+ }
+
+ /**
+ * Remove a PropertyChangeListener from the listener list.
+ *
+ * @param l - the property change listener to remove.
+ */
+ public void removePropertyChangeListener(PropertyChangeListener l)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Requests focus for this object.
+ */
+ public void requestFocus()
+ {
+ tree.requestFocus();
+ }
+
+ /**
+ * Causes every selected item in the object to be selected if the object
+ * supports multiple selections.
+ */
+ public void selectAllAccessibleSelection()
+ {
+ Object parent = tp.getLastPathComponent();
+ if (mod != null)
+ {
+ for (int i = 0; i < mod.getChildCount(parent); i++)
+ {
+ Object child = mod.getChild(parent, i);
+ if (child != null)
+ {
+ if (!states.contains(AccessibleState.MULTISELECTABLE))
+ clearAccessibleSelection();
+ if (selectionList.contains(child))
+ {
+ selectionList.add(child);
+ tree.addSelectionPath(tp.pathByAddingChild(child));
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Set the accessible description of this object.
+ *
+ * @param s - the string to set the accessible description to.
+ */
+ public void setAccessibleDescription(String s)
+ {
+ super.setAccessibleDescription(s);
+ }
+
+ /**
+ * Set the localized accessible name of this object.
+ *
+ * @param s - the string to set the accessible name to.
+ */
+ public void setAccessibleName(String s)
+ {
+ super.setAccessibleName(s);
+ }
+
+ /**
+ * Set the background color of this object.
+ *
+ * @param c - the color to set the background to.
+ */
+ public void setBackground(Color c)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Sets the bounds of this object in the form of a Rectangle object.
+ *
+ * @param r - the bounds to set the object o
+ */
+ public void setBounds(Rectangle r)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Sets the Cursor of this object.
+ *
+ * @param c - the new cursor
+ */
+ public void setCursor(Cursor c)
+ {
+ cursor = c;
+ }
+
+ /**
+ * Sets the enabled state of the object.
+ *
+ * @param b - boolean to enable or disable object
+ */
+ public void setEnabled(boolean b)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Sets the Font of this object.
+ *
+ * @param f - the new font.
+ */
+ public void setFont(Font f)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Sets the foreground color of this object.
+ *
+ * @param c - the new foreground color.
+ */
+ public void setForeground(Color c)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Sets the location of the object relative to the parent.
+ *
+ * @param p - the new location for the object.
+ */
+ public void setLocation(Point p)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Resizes this object so that it has width and height.
+ *
+ * @param d - the new size for the object.
+ */
+ public void setSize(Dimension d)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Sets the visible state of the object.
+ *
+ * @param b - sets the objects visibility.
+ */
+ public void setVisible(boolean b)
+ {
+ // Nothing to do here.
+ }
+ }
+
+ /**
+ * Constructor
+ */
+ public AccessibleJTree()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Adds the specified selected item in the object to the object's selection.
+ *
+ * @param i - the row to add to the tree's selection
+ */
+ public void addAccessibleSelection(int i)
+ {
+ addSelectionInterval(i, i);
+ }
+
+ /**
+ * Clears the selection in the object, so that nothing in the object is selected.
+ */
+ public void clearAccessibleSelection()
+ {
+ clearSelection();
+ }
+
+ /**
+ * Fire a visible data property change notification.
+ */
+ public void fireVisibleDataPropertyChange()
+ {
+ treeDidChange();
+ }
+
+ /**
+ * Returns the Accessible child, if one exists, contained at the local
+ * coordinate Point.
+ *
+ * @param p - the point of the accessible to get.
+ * @return the accessible at point p.
+ */
+ public Accessible getAccessibleAt(Point p)
+ {
+ TreePath tp = getClosestPathForLocation(p.x, p.y);
+ if (tp != null)
+ return new AccessibleJTreeNode(JTree.this, tp, null);
+ return null;
+ }
+
+ /**
+ * Return the nth Accessible child of the object.
+ *
+ * @param i - the accessible child to get
+ * @return the i-th child
+ */
+ public Accessible getAccessibleChild(int i)
+ {
+ return null;
+ }
+
+ /**
+ * Returns the number of top-level children nodes of this JTree.
+ *
+ * @return the number of top-level children
+ */
+ public int getAccessibleChildrenCount()
+ {
+ TreeModel model = getModel();
+ if (model != null)
+ return model.getChildCount(model.getRoot());
+ return 0;
+ }
+
+ /**
+ * Get the index of this object in its accessible parent.
+ *
+ * @return the index of this object.
+ */
+ public int getAccessibleIndexInParent()
+ {
+ return 0;
+ }
+
+ /**
+ * Get the role of this object.
+ *
+ * @return the role of this object
+ */
+ public AccessibleRole getAccessibleRole()
+ {
+ return AccessibleRole.TREE;
+ }
+
+ /**
+ * Get the AccessibleSelection associated with this object.
+ *
+ * @return the accessible selection of the tree
+ */
+ public AccessibleSelection getAccessibleSelection()
+ {
+ TreeModel mod = getModel();
+ if (mod != null)
+ return (new AccessibleJTreeNode(JTree.this,
+ new TreePath(mod.getRoot()), null)).getAccessibleSelection();
+ return null;
+ }
+
+ /**
+ * Returns an Accessible representing the specified selected item in the object.
+ *
+ * @return the i-th accessible in the selection
+ */
+ public Accessible getAccessibleSelection(int i)
+ {
+ TreeModel mod = getModel();
+ if (mod != null)
+ return (new AccessibleJTreeNode(JTree.this,
+ new TreePath(mod.getRoot()), null)).getAccessibleSelection(i);
+ return null;
+ }
+
+ /**
+ * Returns the number of items currently selected.
+ *
+ * @return the number of selected accessibles.
+ */
+ public int getAccessibleSelectionCount()
+ {
+ return getSelectionCount();
+ }
+
+ /**
+ * Returns true if the current child of this object is selected.
+ *
+ * @param i - the child of this object
+ * @return true if the i-th child is selected.
+ */
+ public boolean isAccessibleChildSelected(int i)
+ {
+ // Nothing to do here.
+ return false;
+ }
+
+ /**
+ * Removes the specified selected item in the object from the object's
+ * selection.
+ *
+ * @param i - the i-th selected item to remove
+ */
+ public void removeAccessibleSelection(int i)
+ {
+ removeSelectionInterval(i, i);
+ }
+
+ /**
+ * Causes every selected item in the object to be selected if the object
+ * supports multiple selections.
+ */
+ public void selectAllAccessibleSelection()
+ {
+ if (getSelectionModel().getSelectionMode() !=
+ TreeSelectionModel.SINGLE_TREE_SELECTION)
+ addSelectionInterval(0, getVisibleRowCount());
+ }
+
+ /**
+ * Tree Collapsed notification
+ *
+ * @param e - the event
+ */
+ public void treeCollapsed(TreeExpansionEvent e)
+ {
+ fireTreeCollapsed(e.getPath());
+ }
+
+ /**
+ * Tree Model Expansion notification.
+ *
+ * @param e - the event
+ */
+ public void treeExpanded(TreeExpansionEvent e)
+ {
+ fireTreeExpanded(e.getPath());
+ }
+
+ /**
+ * Tree Model Node change notification.
+ *
+ * @param e - the event
+ */
+ public void treeNodesChanged(TreeModelEvent e)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Tree Model Node change notification.
+ *
+ * @param e - the event
+ */
+ public void treeNodesInserted(TreeModelEvent e)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Tree Model Node change notification.
+ *
+ * @param e - the event
+ */
+ public void treeNodesRemoved(TreeModelEvent e)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Tree Model structure change change notification.
+ *
+ * @param e - the event
+ */
+ public void treeStructureChanged(TreeModelEvent e)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Tree Selection Listener value change method.
+ *
+ * @param e - the event
+ */
+ public void valueChanged(TreeSelectionEvent e)
+ {
+ fireValueChanged(e);
+ }
+ }
+
+ public static class DynamicUtilTreeNode extends DefaultMutableTreeNode
+ {
+ protected Object childValue;
+
+ protected boolean loadedChildren;
+
+ /**
+ * Currently not set or used by this class. It might be set and used in
+ * later versions of this class.
+ */
+ protected boolean hasChildren;
+
+ public DynamicUtilTreeNode(Object value, Object children)
+ {
+ super(value);
+ childValue = children;
+ loadedChildren = false;
+ }
+
+ public int getChildCount()
+ {
+ loadChildren();
+ return super.getChildCount();
+ }
+
+ protected void loadChildren()
+ {
+ if (!loadedChildren)
+ {
+ createChildren(this, childValue);
+ loadedChildren = true;
+ }
+ }
+
+ public Enumeration children()
+ {
+ loadChildren();
+ return super.children();
+ }
+
+ /**
+ * Returns the child node at position <code>pos</code>. Subclassed
+ * here to load the children if necessary.
+ *
+ * @param pos the position of the child node to fetch
+ *
+ * @return the childnode at the specified position
+ */
+ public TreeNode getChildAt(int pos)
+ {
+ loadChildren();
+ return super.getChildAt(pos);
+ }
+
+ public boolean isLeaf()
+ {
+ return childValue == null || !(childValue instanceof Hashtable
+ || childValue instanceof Vector
+ || childValue.getClass().isArray());
+ }
+
+ public static void createChildren(DefaultMutableTreeNode parent,
+ Object children)
+ {
+ if (children instanceof Hashtable)
+ {
+ Hashtable tab = (Hashtable) children;
+ Enumeration e = tab.keys();
+ while (e.hasMoreElements())
+ {
+ Object key = e.nextElement();
+ Object val = tab.get(key);
+ parent.add(new DynamicUtilTreeNode(key, val));
+ }
+ }
+ else if (children instanceof Vector)
+ {
+ Iterator i = ((Vector) children).iterator();
+ while (i.hasNext())
+ {
+ Object n = i.next();
+ parent.add(new DynamicUtilTreeNode(n, n));
+ }
+ }
+ else if (children != null && children.getClass().isArray())
+ {
+ Object[] arr = (Object[]) children;
+ for (int i = 0; i < arr.length; ++i)
+ parent.add(new DynamicUtilTreeNode(arr[i], arr[i]));
+ }
+ }
+ }
+
+ /**
+ * Listens to the model of the JTree and updates the property
+ * <code>expandedState</code> if nodes are removed or changed.
+ */
+ protected class TreeModelHandler implements TreeModelListener
+ {
+
+ /**
+ * Creates a new instance of TreeModelHandler.
+ */
+ protected TreeModelHandler()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Notifies when a node has changed in some ways. This does not include
+ * that a node has changed its location or changed it's children. It
+ * only means that some attributes of the node have changed that might
+ * affect its presentation.
+ *
+ * This method is called after the actual change occured.
+ *
+ * @param ev the TreeModelEvent describing the change
+ */
+ public void treeNodesChanged(TreeModelEvent ev)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Notifies when a node is inserted into the tree.
+ *
+ * This method is called after the actual change occured.
+ *
+ * @param ev the TreeModelEvent describing the change
+ */
+ public void treeNodesInserted(TreeModelEvent ev)
+ {
+ // nothing to do here
+ }
+
+ /**
+ * Notifies when a node is removed from the tree.
+ *
+ * This method is called after the actual change occured.
+ *
+ * @param ev the TreeModelEvent describing the change
+ */
+ public void treeNodesRemoved(TreeModelEvent ev)
+ {
+ // TODO: The API docs suggest that this method should do something
+ // but I cannot really see what has to be done here ...
+ }
+
+ /**
+ * Notifies when the structure of the tree is changed.
+ *
+ * This method is called after the actual change occured.
+ *
+ * @param ev the TreeModelEvent describing the change
+ */
+ public void treeStructureChanged(TreeModelEvent ev)
+ {
+ // Set state of new path.
+ TreePath path = ev.getTreePath();
+ setExpandedState(path, isExpanded(path));
+ }
+ }
+
+ /**
+ * This redirects TreeSelectionEvents and rewrites the source of it to be
+ * this JTree. This is typically done when the tree model generates an
+ * event, but the JTree object associated with that model should be listed
+ * as the actual source of the event.
+ */
+ protected class TreeSelectionRedirector implements TreeSelectionListener,
+ Serializable
+ {
+ /** The serial version UID. */
+ private static final long serialVersionUID = -3505069663646241664L;
+
+ /**
+ * Creates a new instance of TreeSelectionRedirector
+ */
+ protected TreeSelectionRedirector()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Notifies when the tree selection changes.
+ *
+ * @param ev the TreeSelectionEvent that describes the change
+ */
+ public void valueChanged(TreeSelectionEvent ev)
+ {
+ TreeSelectionEvent rewritten =
+ (TreeSelectionEvent) ev.cloneWithSource(JTree.this);
+ fireValueChanged(rewritten);
+
+ // Only repaint the changed nodes.
+ TreePath[] changed = ev.getPaths();
+ for (int i = 0; i < changed.length; i++)
+ {
+ repaint(getPathBounds(changed[i]));
+ }
+ }
+ }
+
+ /**
+ * A TreeModel that does not allow anything to be selected.
+ */
+ protected static class EmptySelectionModel extends DefaultTreeSelectionModel
+ {
+ /** The serial version UID. */
+ private static final long serialVersionUID = -5815023306225701477L;
+
+ /**
+ * The shared instance of this model.
+ */
+ protected static final EmptySelectionModel sharedInstance =
+ new EmptySelectionModel();
+
+ /**
+ * Creates a new instance of EmptySelectionModel.
+ */
+ protected EmptySelectionModel()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Returns the shared instance of EmptySelectionModel.
+ *
+ * @return the shared instance of EmptySelectionModel
+ */
+ public static EmptySelectionModel sharedInstance()
+ {
+ return sharedInstance;
+ }
+
+ /**
+ * This catches attempts to set a selection and sets nothing instead.
+ *
+ * @param paths not used here
+ */
+ public void setSelectionPaths(TreePath[] paths)
+ {
+ // We don't allow selections in this class.
+ }
+
+ /**
+ * This catches attempts to add something to the selection.
+ *
+ * @param paths not used here
+ */
+ public void addSelectionPaths(TreePath[] paths)
+ {
+ // We don't allow selections in this class.
+ }
+
+ /**
+ * This catches attempts to remove something from the selection.
+ *
+ * @param paths not used here
+ */
+ public void removeSelectionPaths(TreePath[] paths)
+ {
+ // We don't allow selections in this class.
+ }
+ }
+
+ private static final long serialVersionUID = 7559816092864483649L;
+
+ public static final String CELL_EDITOR_PROPERTY = "cellEditor";
+
+ public static final String CELL_RENDERER_PROPERTY = "cellRenderer";
+
+ public static final String EDITABLE_PROPERTY = "editable";
+
+ public static final String INVOKES_STOP_CELL_EDITING_PROPERTY =
+ "invokesStopCellEditing";
+
+ public static final String LARGE_MODEL_PROPERTY = "largeModel";
+
+ public static final String ROOT_VISIBLE_PROPERTY = "rootVisible";
+
+ public static final String ROW_HEIGHT_PROPERTY = "rowHeight";
+
+ public static final String SCROLLS_ON_EXPAND_PROPERTY = "scrollsOnExpand";
+
+ public static final String SELECTION_MODEL_PROPERTY = "selectionModel";
+
+ public static final String SHOWS_ROOT_HANDLES_PROPERTY = "showsRootHandles";
+
+ public static final String TOGGLE_CLICK_COUNT_PROPERTY = "toggleClickCount";
+
+ public static final String TREE_MODEL_PROPERTY = "model";
+
+ public static final String VISIBLE_ROW_COUNT_PROPERTY = "visibleRowCount";
+
+ /** @since 1.3 */
+ public static final String ANCHOR_SELECTION_PATH_PROPERTY =
+ "anchorSelectionPath";
+
+ /** @since 1.3 */
+ public static final String LEAD_SELECTION_PATH_PROPERTY = "leadSelectionPath";
+
+ /** @since 1.3 */
+ public static final String EXPANDS_SELECTED_PATHS_PROPERTY =
+ "expandsSelectedPaths";
+
+ private static final Object EXPANDED = Boolean.TRUE;
+
+ private static final Object COLLAPSED = Boolean.FALSE;
+
+ private boolean dragEnabled;
+
+ private boolean expandsSelectedPaths;
+
+ private TreePath anchorSelectionPath;
+
+ /**
+ * This contains the state of all nodes in the tree. Al/ entries map the
+ * TreePath of a note to to its state. Valid states are EXPANDED and
+ * COLLAPSED. Nodes not in this Hashtable are assumed state COLLAPSED.
+ */
+ private Hashtable nodeStates = new Hashtable();
+
+ protected transient TreeCellEditor cellEditor;
+
+ protected transient TreeCellRenderer cellRenderer;
+
+ protected boolean editable;
+
+ protected boolean invokesStopCellEditing;
+
+ protected boolean largeModel;
+
+ protected boolean rootVisible;
+
+ protected int rowHeight;
+
+ protected boolean scrollsOnExpand;
+
+ protected transient TreeSelectionModel selectionModel;
+
+ protected boolean showsRootHandles;
+
+ protected int toggleClickCount;
+
+ protected transient TreeModel treeModel;
+
+ protected int visibleRowCount;
+
+ /**
+ * Handles TreeModelEvents to update the expandedState.
+ */
+ protected transient TreeModelListener treeModelListener;
+
+ /**
+ * Redirects TreeSelectionEvents so that the source is this JTree.
+ */
+ protected TreeSelectionRedirector selectionRedirector =
+ new TreeSelectionRedirector();
+
+ /**
+ * Indicates if the rowHeight property has been set by a client
+ * program or by the UI.
+ *
+ * @see #setUIProperty(String, Object)
+ * @see LookAndFeel#installProperty(JComponent, String, Object)
+ */
+ private boolean clientRowHeightSet = false;
+
+ /**
+ * Indicates if the scrollsOnExpand property has been set by a client
+ * program or by the UI.
+ *
+ * @see #setUIProperty(String, Object)
+ * @see LookAndFeel#installProperty(JComponent, String, Object)
+ */
+ private boolean clientScrollsOnExpandSet = false;
+
+ /**
+ * Indicates if the showsRootHandles property has been set by a client
+ * program or by the UI.
+ *
+ * @see #setUIProperty(String, Object)
+ * @see LookAndFeel#installProperty(JComponent, String, Object)
+ */
+ private boolean clientShowsRootHandlesSet = false;
+
+ /**
+ * Creates a new <code>JTree</code> object.
+ */
+ public JTree()
+ {
+ this(getDefaultTreeModel());
+ }
+
+ /**
+ * Creates a new <code>JTree</code> object.
+ *
+ * @param value the initial nodes in the tree
+ */
+ public JTree(Hashtable value)
+ {
+ this(createTreeModel(value));
+ }
+
+ /**
+ * Creates a new <code>JTree</code> object.
+ *
+ * @param value the initial nodes in the tree
+ */
+ public JTree(Object[] value)
+ {
+ this(createTreeModel(value));
+ }
+
+ /**
+ * Creates a new <code>JTree</code> object.
+ *
+ * @param model the model to use
+ */
+ public JTree(TreeModel model)
+ {
+ setRootVisible(true);
+ setSelectionModel(new EmptySelectionModel());
+ selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+
+ // The root node appears expanded by default.
+ nodeStates = new Hashtable();
+
+ // The cell renderer gets set by the UI.
+ cellRenderer = null;
+
+ // Install the UI before installing the model. This way we avoid double
+ // initialization of lots of UI and model stuff inside the UI and related
+ // classes. The necessary UI updates are performed via property change
+ // events to the UI.
+ updateUI();
+ setModel(model);
+ }
+
+ /**
+ * Creates a new <code>JTree</code> object.
+ *
+ * @param root the root node
+ */
+ public JTree(TreeNode root)
+ {
+ this(root, false);
+ }
+
+ /**
+ * Creates a new <code>JTree</code> object.
+ *
+ * @param root the root node
+ * @param asksAllowChildren if false, all nodes without children are leaf
+ * nodes. If true, only nodes that do not allow children are leaf
+ * nodes.
+ */
+ public JTree(TreeNode root, boolean asksAllowChildren)
+ {
+ this(new DefaultTreeModel(root, asksAllowChildren));
+ }
+
+ /**
+ * Creates a new <code>JTree</code> object.
+ *
+ * @param value the initial nodes in the tree
+ */
+ public JTree(Vector value)
+ {
+ this(createTreeModel(value));
+ }
+
+ public int getRowForPath(TreePath path)
+ {
+ TreeUI ui = getUI();
+
+ if (ui != null)
+ return ui.getRowForPath(this, path);
+
+ return -1;
+ }
+
+ public TreePath getPathForRow(int row)
+ {
+ TreeUI ui = getUI();
+ return ui != null ? ui.getPathForRow(this, row) : null;
+ }
+
+ /**
+ * Get the pathes that are displayes between the two given rows.
+ *
+ * @param index0 the starting row, inclusive
+ * @param index1 the ending row, inclusive
+ *
+ * @return the array of the tree pathes
+ */
+ protected TreePath[] getPathBetweenRows(int index0, int index1)
+ {
+ TreeUI ui = getUI();
+
+ if (ui == null)
+ return null;
+
+ int minIndex = Math.min(index0, index1);
+ int maxIndex = Math.max(index0, index1);
+ TreePath[] paths = new TreePath[maxIndex - minIndex + 1];
+
+ for (int i = minIndex; i <= maxIndex; ++i)
+ paths[i - minIndex] = ui.getPathForRow(this, i);
+
+ return paths;
+ }
+
+ /**
+ * Creates a new <code>TreeModel</code> object.
+ *
+ * @param value the values stored in the model
+ */
+ protected static TreeModel createTreeModel(Object value)
+ {
+ return new DefaultTreeModel(new DynamicUtilTreeNode(value, value));
+ }
+
+ /**
+ * Return the UI associated with this <code>JTree</code> object.
+ *
+ * @return the associated <code>TreeUI</code> object
+ */
+ public TreeUI getUI()
+ {
+ return (TreeUI) ui;
+ }
+
+ /**
+ * Sets the UI associated with this <code>JTree</code> object.
+ *
+ * @param ui the <code>TreeUI</code> to associate
+ */
+ public void setUI(TreeUI ui)
+ {
+ super.setUI(ui);
+ }
+
+ /**
+ * This method resets the UI used to the Look and Feel defaults..
+ */
+ public void updateUI()
+ {
+ setUI((TreeUI) UIManager.getUI(this));
+ }
+
+ /**
+ * This method returns the String ID of the UI class of Separator.
+ *
+ * @return The UI class' String ID.
+ */
+ public String getUIClassID()
+ {
+ return "TreeUI";
+ }
+
+ /**
+ * Gets the AccessibleContext associated with this
+ * <code>JTree</code>.
+ *
+ * @return the associated context
+ */
+ public AccessibleContext getAccessibleContext()
+ {
+ return new AccessibleJTree();
+ }
+
+ /**
+ * Returns the preferred viewport size.
+ *
+ * @return the preferred size
+ */
+ public Dimension getPreferredScrollableViewportSize()
+ {
+ return getPreferredSize();
+ }
+
+ /**
+ * Return the preferred scrolling amount (in pixels) for the given scrolling
+ * direction and orientation. This method handles a partially exposed row by
+ * returning the distance required to completely expose the item.
+ *
+ * @param visibleRect the currently visible part of the component.
+ * @param orientation the scrolling orientation
+ * @param direction the scrolling direction (negative - up, positive -down).
+ * The values greater than one means that more mouse wheel or similar
+ * events were generated, and hence it is better to scroll the longer
+ * distance.
+ * @author Audrius Meskauskas (audriusa at bioinformatics.org)
+ */
+ public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation,
+ int direction)
+ {
+ int delta;
+
+ // Round so that the top would start from the row boundary
+ if (orientation == SwingConstants.VERTICAL)
+ {
+ // One pixel down, otherwise picks another row too high.
+ int row = getClosestRowForLocation(visibleRect.x, visibleRect.y + 1);
+ row = row + direction;
+ if (row < 0)
+ row = 0;
+
+ Rectangle newTop = getRowBounds(row);
+ delta = newTop.y - visibleRect.y;
+ }
+ else
+ delta = direction * rowHeight == 0 ? 20 : rowHeight;
+ return delta;
+ }
+
+ public int getScrollableBlockIncrement(Rectangle visibleRect,
+ int orientation, int direction)
+ {
+ return getScrollableUnitIncrement(visibleRect, orientation, direction);
+ }
+
+ public boolean getScrollableTracksViewportHeight()
+ {
+ if (getParent() instanceof JViewport)
+ return ((JViewport) getParent()).getHeight() > getPreferredSize().height;
+ return false;
+ }
+
+ public boolean getScrollableTracksViewportWidth()
+ {
+ if (getParent() instanceof JViewport)
+ return ((JViewport) getParent()).getWidth() > getPreferredSize().width;
+ return false;
+ }
+
+ /**
+ * Adds a <code>TreeExpansionListener</code> object to the tree.
+ *
+ * @param listener the listener to add
+ */
+ public void addTreeExpansionListener(TreeExpansionListener listener)
+ {
+ listenerList.add(TreeExpansionListener.class, listener);
+ }
+
+ /**
+ * Removes a <code>TreeExpansionListener</code> object from the tree.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeTreeExpansionListener(TreeExpansionListener listener)
+ {
+ listenerList.remove(TreeExpansionListener.class, listener);
+ }
+
+ /**
+ * Returns all added <code>TreeExpansionListener</code> objects.
+ *
+ * @return an array of listeners
+ */
+ public TreeExpansionListener[] getTreeExpansionListeners()
+ {
+ return (TreeExpansionListener[]) getListeners(TreeExpansionListener.class);
+ }
+
+ /**
+ * Notifies all listeners that the tree was collapsed.
+ *
+ * @param path the path to the node that was collapsed
+ */
+ public void fireTreeCollapsed(TreePath path)
+ {
+ TreeExpansionEvent event = new TreeExpansionEvent(this, path);
+ TreeExpansionListener[] listeners = getTreeExpansionListeners();
+
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].treeCollapsed(event);
+ }
+
+ /**
+ * Notifies all listeners that the tree was expanded.
+ *
+ * @param path the path to the node that was expanded
+ */
+ public void fireTreeExpanded(TreePath path)
+ {
+ TreeExpansionEvent event = new TreeExpansionEvent(this, path);
+ TreeExpansionListener[] listeners = getTreeExpansionListeners();
+
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].treeExpanded(event);
+ }
+
+ /**
+ * Adds a <code>TreeSelctionListener</code> object to the tree.
+ *
+ * @param listener the listener to add
+ */
+ public void addTreeSelectionListener(TreeSelectionListener listener)
+ {
+ listenerList.add(TreeSelectionListener.class, listener);
+ }
+
+ /**
+ * Removes a <code>TreeSelectionListener</code> object from the tree.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeTreeSelectionListener(TreeSelectionListener listener)
+ {
+ listenerList.remove(TreeSelectionListener.class, listener);
+ }
+
+ /**
+ * Returns all added <code>TreeSelectionListener</code> objects.
+ *
+ * @return an array of listeners
+ */
+ public TreeSelectionListener[] getTreeSelectionListeners()
+ {
+ return (TreeSelectionListener[])
+ getListeners(TreeSelectionListener.class);
+ }
+
+ /**
+ * Notifies all listeners when the selection of the tree changed.
+ *
+ * @param event the event to send
+ */
+ protected void fireValueChanged(TreeSelectionEvent event)
+ {
+ TreeSelectionListener[] listeners = getTreeSelectionListeners();
+
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].valueChanged(event);
+ }
+
+ /**
+ * Adds a <code>TreeWillExpandListener</code> object to the tree.
+ *
+ * @param listener the listener to add
+ */
+ public void addTreeWillExpandListener(TreeWillExpandListener listener)
+ {
+ listenerList.add(TreeWillExpandListener.class, listener);
+ }
+
+ /**
+ * Removes a <code>TreeWillExpandListener</code> object from the tree.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeTreeWillExpandListener(TreeWillExpandListener listener)
+ {
+ listenerList.remove(TreeWillExpandListener.class, listener);
+ }
+
+ /**
+ * Returns all added <code>TreeWillExpandListener</code> objects.
+ *
+ * @return an array of listeners
+ */
+ public TreeWillExpandListener[] getTreeWillExpandListeners()
+ {
+ return (TreeWillExpandListener[])
+ getListeners(TreeWillExpandListener.class);
+ }
+
+ /**
+ * Notifies all listeners that the tree will collapse.
+ *
+ * @param path the path to the node that will collapse
+ */
+ public void fireTreeWillCollapse(TreePath path) throws ExpandVetoException
+ {
+ TreeExpansionEvent event = new TreeExpansionEvent(this, path);
+ TreeWillExpandListener[] listeners = getTreeWillExpandListeners();
+
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].treeWillCollapse(event);
+ }
+
+ /**
+ * Notifies all listeners that the tree will expand.
+ *
+ * @param path the path to the node that will expand
+ */
+ public void fireTreeWillExpand(TreePath path) throws ExpandVetoException
+ {
+ TreeExpansionEvent event = new TreeExpansionEvent(this, path);
+ TreeWillExpandListener[] listeners = getTreeWillExpandListeners();
+
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].treeWillExpand(event);
+ }
+
+ /**
+ * Returns the model of this <code>JTree</code> object.
+ *
+ * @return the associated <code>TreeModel</code>
+ */
+ public TreeModel getModel()
+ {
+ return treeModel;
+ }
+
+ /**
+ * Sets the model to use in <code>JTree</code>.
+ *
+ * @param model the <code>TreeModel</code> to use
+ */
+ public void setModel(TreeModel model)
+ {
+ if (treeModel == model)
+ return;
+
+ // Remove listeners from old model.
+ if (treeModel != null && treeModelListener != null)
+ treeModel.removeTreeModelListener(treeModelListener);
+
+ // add treeModelListener to the new model
+ if (treeModelListener == null)
+ treeModelListener = createTreeModelListener();
+ if (model != null) // as setModel(null) is allowed
+ model.addTreeModelListener(treeModelListener);
+
+ TreeModel oldValue = treeModel;
+ treeModel = model;
+ clearToggledPaths();
+
+ if (treeModel != null)
+ {
+ if (treeModelListener == null)
+ treeModelListener = createTreeModelListener();
+ if (treeModelListener != null)
+ treeModel.addTreeModelListener(treeModelListener);
+ Object root = treeModel.getRoot();
+ if (root != null && !treeModel.isLeaf(root))
+ {
+ nodeStates.put(new TreePath(root), Boolean.TRUE);
+ }
+ }
+
+ firePropertyChange(TREE_MODEL_PROPERTY, oldValue, model);
+ }
+
+ /**
+ * Checks if this <code>JTree</code> object is editable.
+ *
+ * @return <code>true</code> if this tree object is editable,
+ * <code>false</code> otherwise
+ */
+ public boolean isEditable()
+ {
+ return editable;
+ }
+
+ /**
+ * Sets the <code>editable</code> property.
+ *
+ * @param flag <code>true</code> to make this tree object editable,
+ * <code>false</code> otherwise
+ */
+ public void setEditable(boolean flag)
+ {
+ if (editable == flag)
+ return;
+
+ boolean oldValue = editable;
+ editable = flag;
+ firePropertyChange(EDITABLE_PROPERTY, oldValue, editable);
+ }
+
+ /**
+ * Checks if the root element is visible.
+ *
+ * @return <code>true</code> if the root element is visible,
+ * <code>false</code> otherwise
+ */
+ public boolean isRootVisible()
+ {
+ return rootVisible;
+ }
+
+ public void setRootVisible(boolean flag)
+ {
+ if (rootVisible == flag)
+ return;
+
+ // If the root is currently selected, unselect it
+ if (rootVisible && !flag)
+ {
+ TreeSelectionModel model = getSelectionModel();
+ // The root is always shown in the first row
+ TreePath rootPath = getPathForRow(0);
+ model.removeSelectionPath(rootPath);
+ }
+
+ boolean oldValue = rootVisible;
+ rootVisible = flag;
+ firePropertyChange(ROOT_VISIBLE_PROPERTY, oldValue, flag);
+
+ }
+
+ public boolean getShowsRootHandles()
+ {
+ return showsRootHandles;
+ }
+
+ public void setShowsRootHandles(boolean flag)
+ {
+ clientShowsRootHandlesSet = true;
+
+ if (showsRootHandles == flag)
+ return;
+
+ boolean oldValue = showsRootHandles;
+ showsRootHandles = flag;
+ firePropertyChange(SHOWS_ROOT_HANDLES_PROPERTY, oldValue, flag);
+ }
+
+ public TreeCellEditor getCellEditor()
+ {
+ return cellEditor;
+ }
+
+ public void setCellEditor(TreeCellEditor editor)
+ {
+ if (cellEditor == editor)
+ return;
+
+ TreeCellEditor oldValue = cellEditor;
+ cellEditor = editor;
+ firePropertyChange(CELL_EDITOR_PROPERTY, oldValue, editor);
+ }
+
+ public TreeCellRenderer getCellRenderer()
+ {
+ return cellRenderer;
+ }
+
+ public void setCellRenderer(TreeCellRenderer newRenderer)
+ {
+ if (cellRenderer == newRenderer)
+ return;
+
+ TreeCellRenderer oldValue = cellRenderer;
+ cellRenderer = newRenderer;
+ firePropertyChange(CELL_RENDERER_PROPERTY, oldValue, newRenderer);
+ }
+
+ public TreeSelectionModel getSelectionModel()
+ {
+ return selectionModel;
+ }
+
+ public void setSelectionModel(TreeSelectionModel model)
+ {
+ if (selectionModel == model)
+ return;
+
+ if (selectionModel != null)
+ selectionModel.removeTreeSelectionListener(selectionRedirector);
+
+ TreeSelectionModel oldValue = selectionModel;
+ selectionModel = model;
+
+ if (selectionModel != null)
+ selectionModel.addTreeSelectionListener(selectionRedirector);
+
+ firePropertyChange(SELECTION_MODEL_PROPERTY, oldValue, model);
+ revalidate();
+ repaint();
+ }
+
+ public int getVisibleRowCount()
+ {
+ return visibleRowCount;
+ }
+
+ public void setVisibleRowCount(int rows)
+ {
+ if (visibleRowCount == rows)
+ return;
+
+ int oldValue = visibleRowCount;
+ visibleRowCount = rows;
+ firePropertyChange(VISIBLE_ROW_COUNT_PROPERTY, oldValue, rows);
+ }
+
+ public boolean isLargeModel()
+ {
+ return largeModel;
+ }
+
+ public void setLargeModel(boolean large)
+ {
+ if (largeModel == large)
+ return;
+
+ boolean oldValue = largeModel;
+ largeModel = large;
+ firePropertyChange(LARGE_MODEL_PROPERTY, oldValue, large);
+ }
+
+ public int getRowHeight()
+ {
+ return rowHeight;
+ }
+
+ public void setRowHeight(int height)
+ {
+ clientRowHeightSet = true;
+
+ if (rowHeight == height)
+ return;
+
+ int oldValue = rowHeight;
+ rowHeight = height;
+ firePropertyChange(ROW_HEIGHT_PROPERTY, oldValue, height);
+ }
+
+ public boolean isFixedRowHeight()
+ {
+ return rowHeight > 0;
+ }
+
+ public boolean getInvokesStopCellEditing()
+ {
+ return invokesStopCellEditing;
+ }
+
+ public void setInvokesStopCellEditing(boolean invoke)
+ {
+ if (invokesStopCellEditing == invoke)
+ return;
+
+ boolean oldValue = invokesStopCellEditing;
+ invokesStopCellEditing = invoke;
+ firePropertyChange(INVOKES_STOP_CELL_EDITING_PROPERTY,
+ oldValue, invoke);
+ }
+
+ /**
+ * @since 1.3
+ */
+ public int getToggleClickCount()
+ {
+ return toggleClickCount;
+ }
+
+ /**
+ * @since 1.3
+ */
+ public void setToggleClickCount(int count)
+ {
+ if (toggleClickCount == count)
+ return;
+
+ int oldValue = toggleClickCount;
+ toggleClickCount = count;
+ firePropertyChange(TOGGLE_CLICK_COUNT_PROPERTY, oldValue, count);
+ }
+
+ public void scrollPathToVisible(TreePath path)
+ {
+ if (path == null)
+ return;
+ Rectangle rect = getPathBounds(path);
+ scrollRectToVisible(rect);
+ }
+
+ public void scrollRowToVisible(int row)
+ {
+ scrollPathToVisible(getPathForRow(row));
+ }
+
+ public boolean getScrollsOnExpand()
+ {
+ return scrollsOnExpand;
+ }
+
+ public void setScrollsOnExpand(boolean scroll)
+ {
+ clientScrollsOnExpandSet = true;
+ if (scrollsOnExpand == scroll)
+ return;
+
+ boolean oldValue = scrollsOnExpand;
+ scrollsOnExpand = scroll;
+ firePropertyChange(SCROLLS_ON_EXPAND_PROPERTY, oldValue, scroll);
+ }
+
+ public void setSelectionPath(TreePath path)
+ {
+ selectionModel.setSelectionPath(path);
+ }
+
+ public void setSelectionPaths(TreePath[] paths)
+ {
+ selectionModel.setSelectionPaths(paths);
+ }
+
+ public void setSelectionRow(int row)
+ {
+ TreePath path = getPathForRow(row);
+
+ if (path != null)
+ selectionModel.setSelectionPath(path);
+ }
+
+ public void setSelectionRows(int[] rows)
+ {
+ // Make sure we have an UI so getPathForRow() does not return null.
+ if (rows == null || getUI() == null)
+ return;
+
+ TreePath[] paths = new TreePath[rows.length];
+
+ for (int i = rows.length - 1; i >= 0; --i)
+ paths[i] = getPathForRow(rows[i]);
+
+ setSelectionPaths(paths);
+ }
+
+ public void setSelectionInterval(int index0, int index1)
+ {
+ TreePath[] paths = getPathBetweenRows(index0, index1);
+
+ if (paths != null)
+ setSelectionPaths(paths);
+ }
+
+ public void addSelectionPath(TreePath path)
+ {
+ selectionModel.addSelectionPath(path);
+ }
+
+ public void addSelectionPaths(TreePath[] paths)
+ {
+ selectionModel.addSelectionPaths(paths);
+ }
+
+ public void addSelectionRow(int row)
+ {
+ TreePath path = getPathForRow(row);
+
+ if (path != null)
+ selectionModel.addSelectionPath(path);
+ }
+
+ public void addSelectionRows(int[] rows)
+ {
+ // Make sure we have an UI so getPathForRow() does not return null.
+ if (rows == null || getUI() == null)
+ return;
+
+ TreePath[] paths = new TreePath[rows.length];
+
+ for (int i = rows.length - 1; i >= 0; --i)
+ paths[i] = getPathForRow(rows[i]);
+
+ addSelectionPaths(paths);
+ }
+
+ /**
+ * Select all rows between the two given indexes, inclusive. The method
+ * will not select the inner leaves and braches of the currently collapsed
+ * nodes in this interval.
+ *
+ * @param index0 the starting row, inclusive
+ * @param index1 the ending row, inclusive
+ */
+ public void addSelectionInterval(int index0, int index1)
+ {
+ TreePath[] paths = getPathBetweenRows(index0, index1);
+
+ if (paths != null)
+ addSelectionPaths(paths);
+ }
+
+ public void removeSelectionPath(TreePath path)
+ {
+ selectionModel.removeSelectionPath(path);
+ }
+
+ public void removeSelectionPaths(TreePath[] paths)
+ {
+ selectionModel.removeSelectionPaths(paths);
+ }
+
+ public void removeSelectionRow(int row)
+ {
+ TreePath path = getPathForRow(row);
+
+ if (path != null)
+ selectionModel.removeSelectionPath(path);
+ }
+
+ public void removeSelectionRows(int[] rows)
+ {
+ if (rows == null || getUI() == null)
+ return;
+
+ TreePath[] paths = new TreePath[rows.length];
+
+ for (int i = rows.length - 1; i >= 0; --i)
+ paths[i] = getPathForRow(rows[i]);
+
+ removeSelectionPaths(paths);
+ }
+
+ public void removeSelectionInterval(int index0, int index1)
+ {
+ TreePath[] paths = getPathBetweenRows(index0, index1);
+
+ if (paths != null)
+ removeSelectionPaths(paths);
+ }
+
+ public void clearSelection()
+ {
+ selectionModel.clearSelection();
+ setLeadSelectionPath(null);
+ }
+
+ public TreePath getLeadSelectionPath()
+ {
+ if (selectionModel == null)
+ return null;
+ else
+ return selectionModel.getLeadSelectionPath();
+ }
+
+ /**
+ * @since 1.3
+ */
+ public void setLeadSelectionPath(TreePath path)
+ {
+ if (selectionModel != null)
+ {
+ TreePath oldValue = selectionModel.getLeadSelectionPath();
+ if (path.equals(oldValue))
+ return;
+
+ // Repaint the previous and current rows with the lead selection path.
+ if (path != null)
+ {
+ repaint(getPathBounds(path));
+ selectionModel.addSelectionPath(path);
+ }
+
+ if (oldValue != null)
+ repaint(getPathBounds(oldValue));
+
+ firePropertyChange(LEAD_SELECTION_PATH_PROPERTY, oldValue, path);
+ }
+ }
+
+ /**
+ * @since 1.3
+ */
+ public TreePath getAnchorSelectionPath()
+ {
+ return anchorSelectionPath;
+ }
+
+ /**
+ * @since 1.3
+ */
+ public void setAnchorSelectionPath(TreePath path)
+ {
+ if (anchorSelectionPath == path)
+ return;
+
+ TreePath oldValue = anchorSelectionPath;
+ anchorSelectionPath = path;
+ firePropertyChange(ANCHOR_SELECTION_PATH_PROPERTY, oldValue, path);
+ }
+
+ public int getLeadSelectionRow()
+ {
+ return selectionModel.getLeadSelectionRow();
+ }
+
+ public int getMaxSelectionRow()
+ {
+ return selectionModel.getMaxSelectionRow();
+ }
+
+ public int getMinSelectionRow()
+ {
+ return selectionModel.getMinSelectionRow();
+ }
+
+ public int getSelectionCount()
+ {
+ return selectionModel.getSelectionCount();
+ }
+
+ public TreePath getSelectionPath()
+ {
+ return selectionModel.getSelectionPath();
+ }
+
+ public TreePath[] getSelectionPaths()
+ {
+ return selectionModel.getSelectionPaths();
+ }
+
+ public int[] getSelectionRows()
+ {
+ return selectionModel.getSelectionRows();
+ }
+
+ public boolean isPathSelected(TreePath path)
+ {
+ return selectionModel.isPathSelected(path);
+ }
+
+ public boolean isRowSelected(int row)
+ {
+ return selectionModel.isPathSelected(getPathForRow(row));
+ }
+
+ public boolean isSelectionEmpty()
+ {
+ return selectionModel.isSelectionEmpty();
+ }
+
+ /**
+ * Return the value of the <code>dragEnabled</code> property.
+ *
+ * @return the value
+ *
+ * @since 1.4
+ */
+ public boolean getDragEnabled()
+ {
+ return dragEnabled;
+ }
+
+ /**
+ * Set the <code>dragEnabled</code> property.
+ *
+ * @param enabled new value
+ *
+ * @since 1.4
+ */
+ public void setDragEnabled(boolean enabled)
+ {
+ dragEnabled = enabled;
+ }
+
+ public int getRowCount()
+ {
+ TreeUI ui = getUI();
+
+ if (ui != null)
+ return ui.getRowCount(this);
+
+ return 0;
+ }
+
+ public void collapsePath(TreePath path)
+ {
+ try
+ {
+ fireTreeWillCollapse(path);
+ }
+ catch (ExpandVetoException ev)
+ {
+ // We do nothing if attempt has been vetoed.
+ }
+ setExpandedState(path, false);
+ fireTreeCollapsed(path);
+ }
+
+ public void collapseRow(int row)
+ {
+ if (row < 0 || row >= getRowCount())
+ return;
+
+ TreePath path = getPathForRow(row);
+
+ if (path != null)
+ collapsePath(path);
+ }
+
+ public void expandPath(TreePath path)
+ {
+ // Don't expand if path is null
+ // or is already expanded.
+ if (path == null || isExpanded(path))
+ return;
+
+ try
+ {
+ fireTreeWillExpand(path);
+ }
+ catch (ExpandVetoException ev)
+ {
+ // We do nothing if attempt has been vetoed.
+ }
+
+ setExpandedState(path, true);
+ fireTreeExpanded(path);
+ }
+
+ public void expandRow(int row)
+ {
+ if (row < 0 || row >= getRowCount())
+ return;
+
+ TreePath path = getPathForRow(row);
+
+ if (path != null)
+ expandPath(path);
+ }
+
+ public boolean isCollapsed(TreePath path)
+ {
+ return !isExpanded(path);
+ }
+
+ public boolean isCollapsed(int row)
+ {
+ if (row < 0 || row >= getRowCount())
+ return false;
+
+ TreePath path = getPathForRow(row);
+
+ if (path != null)
+ return isCollapsed(path);
+
+ return false;
+ }
+
+ public boolean isExpanded(TreePath path)
+ {
+ if (path == null)
+ return false;
+
+ Object state = nodeStates.get(path);
+
+ if ((state == null) || (state != EXPANDED))
+ return false;
+
+ TreePath parent = path.getParentPath();
+
+ if (parent != null)
+ return isExpanded(parent);
+
+ return true;
+ }
+
+ public boolean isExpanded(int row)
+ {
+ if (row < 0 || row >= getRowCount())
+ return false;
+
+ TreePath path = getPathForRow(row);
+
+ if (path != null)
+ return isExpanded(path);
+
+ return false;
+ }
+
+ /**
+ * @since 1.3
+ */
+ public boolean getExpandsSelectedPaths()
+ {
+ return expandsSelectedPaths;
+ }
+
+ /**
+ * @since 1.3
+ */
+ public void setExpandsSelectedPaths(boolean flag)
+ {
+ if (expandsSelectedPaths == flag)
+ return;
+
+ boolean oldValue = expandsSelectedPaths;
+ expandsSelectedPaths = flag;
+ firePropertyChange(EXPANDS_SELECTED_PATHS_PROPERTY, oldValue, flag);
+ }
+
+ public Rectangle getPathBounds(TreePath path)
+ {
+ TreeUI ui = getUI();
+
+ if (ui == null)
+ return null;
+
+ return ui.getPathBounds(this, path);
+ }
+
+ public Rectangle getRowBounds(int row)
+ {
+ TreePath path = getPathForRow(row);
+
+ if (path != null)
+ return getPathBounds(path);
+
+ return null;
+ }
+
+ public boolean isEditing()
+ {
+ TreeUI ui = getUI();
+
+ if (ui != null)
+ return ui.isEditing(this);
+
+ return false;
+ }
+
+ public boolean stopEditing()
+ {
+ TreeUI ui = getUI();
+
+ if (isEditing())
+ if (ui != null)
+ return ui.stopEditing(this);
+
+ return false;
+ }
+
+ public void cancelEditing()
+ {
+ TreeUI ui = getUI();
+
+ if (isEditing())
+ if (ui != null)
+ ui.cancelEditing(this);
+ }
+
+ public void startEditingAtPath(TreePath path)
+ {
+ TreeUI ui = getUI();
+
+ if (ui != null)
+ ui.startEditingAtPath(this, path);
+ }
+
+ public TreePath getEditingPath()
+ {
+ TreeUI ui = getUI();
+
+ if (ui != null)
+ return ui.getEditingPath(this);
+
+ return null;
+ }
+
+ public TreePath getPathForLocation(int x, int y)
+ {
+ TreePath path = getClosestPathForLocation(x, y);
+
+ if (path != null)
+ {
+ Rectangle rect = getPathBounds(path);
+
+ if ((rect != null) && rect.contains(x, y))
+ return path;
+ }
+
+ return null;
+ }
+
+ public int getRowForLocation(int x, int y)
+ {
+ TreePath path = getPathForLocation(x, y);
+
+ if (path != null)
+ return getRowForPath(path);
+
+ return -1;
+ }
+
+ public TreePath getClosestPathForLocation(int x, int y)
+ {
+ TreeUI ui = getUI();
+
+ if (ui != null)
+ return ui.getClosestPathForLocation(this, x, y);
+
+ return null;
+ }
+
+ public int getClosestRowForLocation(int x, int y)
+ {
+ TreePath path = getClosestPathForLocation(x, y);
+
+ if (path != null)
+ return getRowForPath(path);
+
+ return -1;
+ }
+
+ public Object getLastSelectedPathComponent()
+ {
+ TreePath path = getSelectionPath();
+
+ if (path != null)
+ return path.getLastPathComponent();
+
+ return null;
+ }
+
+ private void doExpandParents(TreePath path, boolean state)
+ {
+ TreePath parent = path.getParentPath();
+
+ if (!isExpanded(parent) && parent != null)
+ doExpandParents(parent, false);
+
+ nodeStates.put(path, state ? EXPANDED : COLLAPSED);
+ }
+
+ protected void setExpandedState(TreePath path, boolean state)
+ {
+ if (path == null)
+ return;
+
+ doExpandParents(path, state);
+ }
+
+ protected void clearToggledPaths()
+ {
+ nodeStates.clear();
+ }
+
+ protected Enumeration getDescendantToggledPaths(TreePath parent)
+ {
+ if (parent == null)
+ return null;
+
+ Enumeration nodes = nodeStates.keys();
+ Vector result = new Vector();
+
+ while (nodes.hasMoreElements())
+ {
+ TreePath path = (TreePath) nodes.nextElement();
+
+ if (path.isDescendant(parent))
+ result.addElement(path);
+ }
+
+ return result.elements();
+ }
+
+ public boolean hasBeenExpanded(TreePath path)
+ {
+ if (path == null)
+ return false;
+
+ return nodeStates.get(path) != null;
+ }
+
+ public boolean isVisible(TreePath path)
+ {
+ if (path == null)
+ return false;
+
+ TreePath parent = path.getParentPath();
+
+ if (parent == null)
+ return true; // Is root node.
+
+ return isExpanded(parent);
+ }
+
+ public void makeVisible(TreePath path)
+ {
+ if (path == null)
+ return;
+
+ expandPath(path.getParentPath());
+ }
+
+ public boolean isPathEditable(TreePath path)
+ {
+ return isEditable();
+ }
+
+ /**
+ * Creates and returns an instance of {@link TreeModelHandler}.
+ *
+ * @return an instance of {@link TreeModelHandler}
+ */
+ protected TreeModelListener createTreeModelListener()
+ {
+ return new TreeModelHandler();
+ }
+
+ /**
+ * Returns a sample TreeModel that can be used in a JTree. This can be used
+ * in Bean- or GUI-Builders to show something interesting.
+ *
+ * @return a sample TreeModel that can be used in a JTree
+ */
+ protected static TreeModel getDefaultTreeModel()
+ {
+ DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root node");
+ DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Child node 1");
+ DefaultMutableTreeNode child11 =
+ new DefaultMutableTreeNode("Child node 1.1");
+ DefaultMutableTreeNode child12 =
+ new DefaultMutableTreeNode("Child node 1.2");
+ DefaultMutableTreeNode child13 =
+ new DefaultMutableTreeNode("Child node 1.3");
+ DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Child node 2");
+ DefaultMutableTreeNode child21 =
+ new DefaultMutableTreeNode("Child node 2.1");
+ DefaultMutableTreeNode child22 =
+ new DefaultMutableTreeNode("Child node 2.2");
+ DefaultMutableTreeNode child23 =
+ new DefaultMutableTreeNode("Child node 2.3");
+ DefaultMutableTreeNode child24 =
+ new DefaultMutableTreeNode("Child node 2.4");
+
+ DefaultMutableTreeNode child3 = new DefaultMutableTreeNode("Child node 3");
+ root.add(child1);
+ root.add(child2);
+ root.add(child3);
+ child1.add(child11);
+ child1.add(child12);
+ child1.add(child13);
+ child2.add(child21);
+ child2.add(child22);
+ child2.add(child23);
+ child2.add(child24);
+ return new DefaultTreeModel(root);
+ }
+
+ /**
+ * Converts the specified value to a String. This is used by the renderers
+ * of this JTree and its nodes.
+ *
+ * This implementation simply returns <code>value.toString()</code> and
+ * ignores all other parameters. Subclass this method to control the
+ * conversion.
+ *
+ * @param value the value that is converted to a String
+ * @param selected indicates if that value is selected or not
+ * @param expanded indicates if that value is expanded or not
+ * @param leaf indicates if that value is a leaf node or not
+ * @param row the row of the node
+ * @param hasFocus indicates if that node has focus or not
+ */
+ public String convertValueToText(Object value, boolean selected,
+ boolean expanded, boolean leaf, int row, boolean hasFocus)
+ {
+ return value.toString();
+ }
+
+ /**
+ * A String representation of this JTree. This is intended to be used for
+ * debugging. The returned string may be empty but may not be
+ * <code>null</code>.
+ *
+ * @return a String representation of this JTree
+ */
+ protected String paramString()
+ {
+ // TODO: this is completely legal, but it would possibly be nice
+ // to return some more content, like the tree structure, some properties
+ // etc ...
+ return "";
+ }
+
+ /**
+ * Returns all TreePath objects which are a descendants of the given path
+ * and are exapanded at the moment of the execution of this method. If the
+ * state of any node is beeing toggled while this method is executing this
+ * change may be left unaccounted.
+ *
+ * @param path The parent of this request
+ *
+ * @return An Enumeration containing TreePath objects
+ */
+ public Enumeration getExpandedDescendants(TreePath path)
+ {
+ Enumeration paths = nodeStates.keys();
+ Vector relevantPaths = new Vector();
+ while (paths.hasMoreElements())
+ {
+ TreePath nextPath = (TreePath) paths.nextElement();
+ if (nodeStates.get(nextPath) == EXPANDED
+ && path.isDescendant(nextPath))
+ {
+ relevantPaths.add(nextPath);
+ }
+ }
+ return relevantPaths.elements();
+ }
+
+ /**
+ * Returns the next table element (beginning from the row
+ * <code>startingRow</code> that starts with <code>prefix</code>.
+ * Searching is done in the direction specified by <code>bias</code>.
+ *
+ * @param prefix the prefix to search for in the cell values
+ * @param startingRow the index of the row where to start searching from
+ * @param bias the search direction, either {@link Position.Bias#Forward} or
+ * {@link Position.Bias#Backward}
+ *
+ * @return the path to the found element or -1 if no such element has been
+ * found
+ *
+ * @throws IllegalArgumentException if prefix is <code>null</code> or
+ * startingRow is not valid
+ *
+ * @since 1.4
+ */
+ public TreePath getNextMatch(String prefix, int startingRow,
+ Position.Bias bias)
+ {
+ if (prefix == null)
+ throw new IllegalArgumentException("The argument 'prefix' must not be"
+ + " null.");
+ if (startingRow < 0)
+ throw new IllegalArgumentException("The argument 'startingRow' must not"
+ + " be less than zero.");
+
+ int size = getRowCount();
+ if (startingRow > size)
+ throw new IllegalArgumentException("The argument 'startingRow' must not"
+ + " be greater than the number of"
+ + " elements in the TreeModel.");
+
+ TreePath foundPath = null;
+ if (bias == Position.Bias.Forward)
+ {
+ for (int i = startingRow; i < size; i++)
+ {
+ TreePath path = getPathForRow(i);
+ Object o = path.getLastPathComponent();
+ // FIXME: in the following call to convertValueToText the
+ // last argument (hasFocus) should be done right.
+ String item = convertValueToText(o, isRowSelected(i),
+ isExpanded(i), treeModel.isLeaf(o),
+ i, false);
+ if (item.startsWith(prefix))
+ {
+ foundPath = path;
+ break;
+ }
+ }
+ }
+ else
+ {
+ for (int i = startingRow; i >= 0; i--)
+ {
+ TreePath path = getPathForRow(i);
+ Object o = path.getLastPathComponent();
+ // FIXME: in the following call to convertValueToText the
+ // last argument (hasFocus) should be done right.
+ String item = convertValueToText(o, isRowSelected(i),
+ isExpanded(i), treeModel.isLeaf(o), i, false);
+ if (item.startsWith(prefix))
+ {
+ foundPath = path;
+ break;
+ }
+ }
+ }
+ return foundPath;
+ }
+
+ /**
+ * Removes any paths in the current set of selected paths that are
+ * descendants of <code>path</code>. If <code>includePath</code> is set
+ * to <code>true</code> and <code>path</code> itself is selected, then
+ * it will be removed too.
+ *
+ * @param path the path from which selected descendants are to be removed
+ * @param includeSelected if <code>true</code> then <code>path</code> itself
+ * will also be remove if it's selected
+ *
+ * @return <code>true</code> if something has been removed,
+ * <code>false</code> otherwise
+ *
+ * @since 1.3
+ */
+ protected boolean removeDescendantSelectedPaths(TreePath path,
+ boolean includeSelected)
+ {
+ boolean removedSomething = false;
+ TreePath[] selected = getSelectionPaths();
+ for (int index = 0; index < selected.length; index++)
+ {
+ if ((selected[index] == path && includeSelected)
+ || (selected[index].isDescendant(path)))
+ {
+ removeSelectionPath(selected[index]);
+ removedSomething = true;
+ }
+ }
+ return removedSomething;
+ }
+
+ /**
+ * Removes any descendants of the TreePaths in toRemove that have been
+ * expanded.
+ *
+ * @param toRemove - Enumeration of TreePaths that need to be removed from
+ * cache of toggled tree paths.
+ */
+ protected void removeDescendantToggledPaths(Enumeration toRemove)
+ {
+ while (toRemove.hasMoreElements())
+ {
+ TreePath current = (TreePath) toRemove.nextElement();
+ Enumeration descendants = getDescendantToggledPaths(current);
+
+ while (descendants.hasMoreElements())
+ {
+ TreePath currentDes = (TreePath) descendants.nextElement();
+ if (isExpanded(currentDes))
+ nodeStates.remove(currentDes);
+ }
+ }
+ }
+
+ /**
+ * <p>
+ * Sent when the tree has changed enough that we need to resize the bounds,
+ * but not enough that we need to remove the expanded node set (e.g nodes were
+ * expanded or collapsed, or nodes were inserted into the tree). You should
+ * never have to invoke this, the UI will invoke this as it needs to.
+ * </p>
+ * <p>
+ * If the tree uses {@link DefaultTreeModel}, you must call
+ * {@link DefaultTreeModel#reload(TreeNode)} or
+ * {@link DefaultTreeModel#reload()} after adding or removing nodes. Following
+ * the official Java 1.5 API standard, just calling treeDidChange, repaint()
+ * or revalidate() does <i>not</i> update the tree appearance properly.
+ *
+ * @see DefaultTreeModel#reload()
+ */
+ public void treeDidChange()
+ {
+ repaint();
+ }
+
+ /**
+ * Helper method for
+ * {@link LookAndFeel#installProperty(JComponent, String, Object)}.
+ *
+ * @param propertyName the name of the property
+ * @param value the value of the property
+ *
+ * @throws IllegalArgumentException if the specified property cannot be set
+ * by this method
+ * @throws ClassCastException if the property value does not match the
+ * property type
+ * @throws NullPointerException if <code>c</code> or
+ * <code>propertyValue</code> is <code>null</code>
+ */
+ void setUIProperty(String propertyName, Object value)
+ {
+ if (propertyName.equals("rowHeight"))
+ {
+ if (! clientRowHeightSet)
+ {
+ setRowHeight(((Integer) value).intValue());
+ clientRowHeightSet = false;
+ }
+ }
+ else if (propertyName.equals("scrollsOnExpand"))
+ {
+ if (! clientScrollsOnExpandSet)
+ {
+ setScrollsOnExpand(((Boolean) value).booleanValue());
+ clientScrollsOnExpandSet = false;
+ }
+ }
+ else if (propertyName.equals("showsRootHandles"))
+ {
+ if (! clientShowsRootHandlesSet)
+ {
+ setShowsRootHandles(((Boolean) value).booleanValue());
+ clientShowsRootHandlesSet = false;
+ }
+ }
+ else
+ {
+ super.setUIProperty(propertyName, value);
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/JViewport.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/JViewport.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/JViewport.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/JViewport.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,951 @@
+/* JViewport.java --
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import gnu.classpath.SystemProperties;
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Insets;
+import java.awt.LayoutManager;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.io.Serializable;
+
+import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleRole;
+import javax.swing.border.Border;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.plaf.ViewportUI;
+
+/**
+ *
+ * <pre>
+ * _
+ * +-------------------------------+ ...........Y1 \
+ * | view | . \
+ * | (this component's child) | . > VY
+ * | | . / = Y2-Y1
+ * | +------------------------------+ ....Y2_/
+ * | | viewport | | .
+ * | | (this component) | | .
+ * | | | | .
+ * | | | | .
+ * | | | | .
+ * | | | | .
+ * | +------------------------------+ ....Y3
+ * | | .
+ * | . | . .
+ * | . | . .
+ * +---------.---------------------+ ...........Y4
+ * . . . .
+ * . . . .
+ * . . . .
+ * X1.......X2.....................X3.......X4
+ * \____ ___/
+ * \/
+ * VX = X2-X1
+ *</pre>
+ *
+ * <p>A viewport is, like all swing components, located at some position in
+ * the swing component tree; that location is exactly the same as any other
+ * components: the viewport's "bounds".</p>
+ *
+ * <p>But in terms of drawing its child, the viewport thinks of itself as
+ * covering a particular position <em>of the view's coordinate space</em>.
+ * For example, the {@link #getViewPosition} method returns
+ * the position <code>(VX,VY)</code> shown above, which is an position in
+ * "view space", even though this is <em>implemented</em> by positioning
+ * the underlying child at position <code>(-VX,-VY)</code></p>
+ *
+ */
+public class JViewport extends JComponent implements Accessible
+{
+ /**
+ * Provides accessibility support for <code>JViewport</code>.
+ *
+ * @author Roman Kennke (roman at kennke.org)
+ */
+ protected class AccessibleJViewport extends AccessibleJComponent
+ {
+ /**
+ * Creates a new instance of <code>AccessibleJViewport</code>.
+ */
+ protected AccessibleJViewport()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Returns the accessible role of <code>JViewport</code>, which is
+ * {@link AccessibleRole#VIEWPORT}.
+ *
+ * @return the accessible role of <code>JViewport</code>
+ */
+ public AccessibleRole getAccessibleRole()
+ {
+ return AccessibleRole.VIEWPORT;
+ }
+ }
+
+ /**
+ * A {@link java.awt.event.ComponentListener} that listens for
+ * changes of the view's size. This triggers a revalidate() call on the
+ * viewport.
+ */
+ protected class ViewListener extends ComponentAdapter implements Serializable
+ {
+ private static final long serialVersionUID = -2812489404285958070L;
+
+ /**
+ * Creates a new instance of ViewListener.
+ */
+ protected ViewListener()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Receives notification when a component (in this case: the view
+ * component) changes it's size. This simply triggers a revalidate() on the
+ * viewport.
+ *
+ * @param ev the ComponentEvent describing the change
+ */
+ public void componentResized(ComponentEvent ev)
+ {
+ revalidate();
+ }
+ }
+
+ public static final int SIMPLE_SCROLL_MODE = 0;
+ public static final int BLIT_SCROLL_MODE = 1;
+ public static final int BACKINGSTORE_SCROLL_MODE = 2;
+
+ private static final long serialVersionUID = -6925142919680527970L;
+
+ /**
+ * The default scrollmode to be used by all JViewports as determined by
+ * the system property gnu.javax.swing.JViewport.scrollMode.
+ */
+ private static final int defaultScrollMode;
+
+ protected boolean scrollUnderway;
+ protected boolean isViewSizeSet;
+
+ /**
+ * This flag indicates whether we use a backing store for drawing.
+ *
+ * @deprecated since JDK 1.3
+ */
+ protected boolean backingStore;
+
+ /**
+ * The backingstore image used for the backingstore and blit scroll methods.
+ */
+ protected Image backingStoreImage;
+
+ /**
+ * The position at which the view has been drawn the last time. This is used
+ * to determine the bittable area.
+ */
+ protected Point lastPaintPosition;
+
+ ChangeEvent changeEvent = new ChangeEvent(this);
+
+ int scrollMode;
+
+ /**
+ * The width and height of the Viewport's area in terms of view
+ * coordinates. Typically this will be the same as the width and height
+ * of the viewport's bounds, unless the viewport transforms units of
+ * width and height, which it may do, for example if it magnifies or
+ * rotates its view.
+ *
+ * @see #toViewCoordinates(Dimension)
+ */
+ Dimension extentSize;
+
+ /**
+ * The width and height of the view in its own coordinate space.
+ */
+ Dimension viewSize;
+
+ /**
+ * The ViewListener instance.
+ */
+ ViewListener viewListener;
+
+ /**
+ * Stores the location from where to blit. This is a cached Point object used
+ * in blitting calculations.
+ */
+ Point cachedBlitFrom;
+
+ /**
+ * Stores the location where to blit to. This is a cached Point object used
+ * in blitting calculations.
+ */
+ Point cachedBlitTo;
+
+ /**
+ * Stores the width of the blitted area. This is a cached Dimension object
+ * used in blitting calculations.
+ */
+ Dimension cachedBlitSize;
+
+ /**
+ * Stores the bounds of the area that needs to be repainted. This is a cached
+ * Rectangle object used in blitting calculations.
+ */
+ Rectangle cachedBlitPaint;
+
+ boolean damaged = true;
+
+ /**
+ * A flag indicating if the size of the viewport has changed since the
+ * last repaint. This is used in double buffered painting to check if we
+ * need a new double buffer, or can reuse the old one.
+ */
+ boolean sizeChanged = true;
+
+ /**
+ * Indicates if this JViewport is the paint root or not. If it is not, then
+ * we may not assume that the offscreen buffer still has the right content
+ * because parent components may have cleared the background already.
+ */
+ private boolean isPaintRoot = false;
+
+ /**
+ * Initializes the default setting for the scrollMode property.
+ */
+ static
+ {
+ String scrollModeProp =
+ SystemProperties.getProperty("gnu.javax.swing.JViewport.scrollMode",
+ "BLIT");
+ if (scrollModeProp.equalsIgnoreCase("simple"))
+ defaultScrollMode = SIMPLE_SCROLL_MODE;
+ else if (scrollModeProp.equalsIgnoreCase("backingstore"))
+ defaultScrollMode = BACKINGSTORE_SCROLL_MODE;
+ else
+ defaultScrollMode = BLIT_SCROLL_MODE;
+ }
+
+ public JViewport()
+ {
+ setOpaque(true);
+ setScrollMode(defaultScrollMode);
+ updateUI();
+ setLayout(createLayoutManager());
+ lastPaintPosition = new Point();
+ cachedBlitFrom = new Point();
+ cachedBlitTo = new Point();
+ cachedBlitSize = new Dimension();
+ cachedBlitPaint = new Rectangle();
+ }
+
+ public Dimension getExtentSize()
+ {
+ if (extentSize == null)
+ return toViewCoordinates(getSize());
+ else
+ return extentSize;
+ }
+
+ public Dimension toViewCoordinates(Dimension size)
+ {
+ return size;
+ }
+
+ public Point toViewCoordinates(Point p)
+ {
+ Point pos = getViewPosition();
+ return new Point(p.x + pos.x,
+ p.y + pos.y);
+ }
+
+ public void setExtentSize(Dimension newSize)
+ {
+ extentSize = newSize;
+ fireStateChanged();
+ }
+
+ /**
+ * Returns the viewSize when set, or the preferred size of the set
+ * Component view. If no viewSize and no Component view is set an
+ * empty Dimension is returned.
+ */
+ public Dimension getViewSize()
+ {
+ if (isViewSizeSet)
+ return viewSize;
+ else
+ {
+ Component view = getView();
+ if (view != null)
+ return view.getPreferredSize();
+ else
+ return new Dimension();
+ }
+ }
+
+
+ public void setViewSize(Dimension newSize)
+ {
+ viewSize = newSize;
+ Component view = getView();
+ if (view != null)
+ {
+ if (newSize != view.getSize())
+ {
+ view.setSize(viewSize);
+ fireStateChanged();
+ }
+ }
+ isViewSizeSet = true;
+ }
+
+ /**
+ * Get the viewport's position in view space. Despite confusing name,
+ * this really does return the viewport's (0,0) position in view space,
+ * not the view's position.
+ */
+
+ public Point getViewPosition()
+ {
+ Component view = getView();
+ if (view == null)
+ return new Point(0,0);
+ else
+ {
+ Point p = view.getLocation();
+ p.x = -p.x;
+ p.y = -p.y;
+ return p;
+ }
+ }
+
+ public void setViewPosition(Point p)
+ {
+ if (getViewPosition().equals(p))
+ return;
+ Component view = getView();
+ if (view != null)
+ {
+ Point q = new Point(-p.x, -p.y);
+ view.setLocation(q);
+ isViewSizeSet = false;
+ fireStateChanged();
+ }
+ repaint();
+ }
+
+ public Rectangle getViewRect()
+ {
+ return new Rectangle(getViewPosition(),
+ getExtentSize());
+ }
+
+ /**
+ * @deprecated 1.4
+ */
+ public boolean isBackingStoreEnabled()
+ {
+ return scrollMode == BACKINGSTORE_SCROLL_MODE;
+ }
+
+ /**
+ * @deprecated 1.4
+ */
+ public void setBackingStoreEnabled(boolean b)
+ {
+ if (b && scrollMode != BACKINGSTORE_SCROLL_MODE)
+ {
+ scrollMode = BACKINGSTORE_SCROLL_MODE;
+ fireStateChanged();
+ }
+ }
+
+ public void setScrollMode(int mode)
+ {
+ scrollMode = mode;
+ fireStateChanged();
+ }
+
+ public int getScrollMode()
+ {
+ return scrollMode;
+ }
+
+ public Component getView()
+ {
+ if (getComponentCount() == 0)
+ return null;
+
+ return getComponents()[0];
+ }
+
+ public void setView(Component v)
+ {
+ Component currView = getView();
+ if (viewListener != null && currView != null)
+ currView.removeComponentListener(viewListener);
+
+ if (v != null)
+ {
+ if (viewListener == null)
+ viewListener = createViewListener();
+ v.addComponentListener(viewListener);
+ add(v);
+ fireStateChanged();
+ }
+ revalidate();
+ repaint();
+ }
+
+ public void reshape(int x, int y, int w, int h)
+ {
+ if (w != getWidth() || h != getHeight())
+ sizeChanged = true;
+ super.reshape(x, y, w, h);
+ if (sizeChanged)
+ {
+ damaged = true;
+ fireStateChanged();
+ }
+ }
+
+ public final Insets getInsets()
+ {
+ return new Insets(0, 0, 0, 0);
+ }
+
+ public final Insets getInsets(Insets insets)
+ {
+ if (insets == null)
+ return getInsets();
+ insets.top = 0;
+ insets.bottom = 0;
+ insets.left = 0;
+ insets.right = 0;
+ return insets;
+ }
+
+
+ /**
+ * Overridden to return <code>false</code>, so the JViewport's paint method
+ * gets called instead of directly calling the children. This is necessary
+ * in order to get a useful clipping and translation on the children.
+ *
+ * @return <code>false</code>
+ */
+ public boolean isOptimizedDrawingEnabled()
+ {
+ return false;
+ }
+
+ public void paint(Graphics g)
+ {
+ Component view = getView();
+
+ if (view == null)
+ return;
+
+ Point pos = getViewPosition();
+ Rectangle viewBounds = view.getBounds();
+ Rectangle portBounds = getBounds();
+
+ if (viewBounds.width == 0
+ || viewBounds.height == 0
+ || portBounds.width == 0
+ || portBounds.height == 0)
+ return;
+
+ switch (getScrollMode())
+ {
+
+ case JViewport.BACKINGSTORE_SCROLL_MODE:
+ paintBackingStore(g);
+ break;
+ case JViewport.BLIT_SCROLL_MODE:
+ paintBlit(g);
+ break;
+ case JViewport.SIMPLE_SCROLL_MODE:
+ default:
+ paintSimple(g);
+ break;
+ }
+ damaged = false;
+ }
+
+ public void addChangeListener(ChangeListener listener)
+ {
+ listenerList.add(ChangeListener.class, listener);
+ }
+
+ public void removeChangeListener(ChangeListener listener)
+ {
+ listenerList.remove(ChangeListener.class, listener);
+ }
+
+ public ChangeListener[] getChangeListeners()
+ {
+ return (ChangeListener[]) getListeners(ChangeListener.class);
+ }
+
+ /**
+ * This method returns the String ID of the UI class of Separator.
+ *
+ * @return The UI class' String ID.
+ */
+ public String getUIClassID()
+ {
+ return "ViewportUI";
+ }
+
+ /**
+ * This method resets the UI used to the Look and Feel defaults..
+ */
+ public void updateUI()
+ {
+ setUI((ViewportUI) UIManager.getUI(this));
+ }
+
+ /**
+ * This method returns the viewport's UI delegate.
+ *
+ * @return The viewport's UI delegate.
+ */
+ public ViewportUI getUI()
+ {
+ return (ViewportUI) ui;
+ }
+
+ /**
+ * This method sets the viewport's UI delegate.
+ *
+ * @param ui The viewport's UI delegate.
+ */
+ public void setUI(ViewportUI ui)
+ {
+ super.setUI(ui);
+ }
+
+ public final void setBorder(Border border)
+ {
+ if (border != null)
+ throw new IllegalArgumentException();
+ }
+
+ /**
+ * Scrolls the view so that contentRect becomes visible.
+ *
+ * @param contentRect the rectangle to make visible within the view
+ */
+ public void scrollRectToVisible(Rectangle contentRect)
+ {
+ Component view = getView();
+ if (view == null)
+ return;
+
+ Point pos = getViewPosition();
+ Rectangle viewBounds = getView().getBounds();
+ Rectangle portBounds = getBounds();
+
+ if (isShowing())
+ getView().validate();
+
+ // If the bottom boundary of contentRect is below the port
+ // boundaries, scroll up as necessary.
+ if (contentRect.y + contentRect.height + viewBounds.y > portBounds.height)
+ pos.y = contentRect.y + contentRect.height - portBounds.height;
+ // If contentRect.y is above the port boundaries, scroll down to
+ // contentRect.y.
+ if (contentRect.y + viewBounds.y < 0)
+ pos.y = contentRect.y;
+ // If the right boundary of contentRect is right from the port
+ // boundaries, scroll left as necessary.
+ if (contentRect.x + contentRect.width + viewBounds.x > portBounds.width)
+ pos.x = contentRect.x + contentRect.width - portBounds.width;
+ // If contentRect.x is left from the port boundaries, scroll right to
+ // contentRect.x.
+ if (contentRect.x + viewBounds.x < 0)
+ pos.x = contentRect.x;
+ setViewPosition(pos);
+ }
+
+ /**
+ * Returns the accessible context for this <code>JViewport</code>. This
+ * will be an instance of {@link AccessibleJViewport}.
+ *
+ * @return the accessible context for this <code>JViewport</code>
+ */
+ public AccessibleContext getAccessibleContext()
+ {
+ if (accessibleContext == null)
+ accessibleContext = new AccessibleJViewport();
+ return accessibleContext;
+ }
+
+ /**
+ * Forward repaint to parent to make sure only one paint is performed by the
+ * RepaintManager.
+ *
+ * @param tm number of milliseconds to defer the repaint request
+ * @param x the X coordinate of the upper left corner of the dirty area
+ * @param y the Y coordinate of the upper left corner of the dirty area
+ * @param w the width of the dirty area
+ * @param h the height of the dirty area
+ */
+ public void repaint(long tm, int x, int y, int w, int h)
+ {
+// Component parent = getParent();
+// if (parent != null)
+// parent.repaint(tm, x + getX(), y + getY(), w, h);
+// else
+// super.repaint(tm, x, y, w, h);
+
+ // The specs suggest to implement something like the above. This however
+ // breaks blit painting, because the parent (most likely a JScrollPane)
+ // clears the background of the offscreen area of the JViewport, thus
+ // destroying the pieces that we want to clip. So we simply call super here
+ // instead.
+ super.repaint(tm, x, y, w, h);
+
+ }
+
+ protected void addImpl(Component comp, Object constraints, int index)
+ {
+ if (getComponentCount() > 0)
+ remove(getComponents()[0]);
+
+ super.addImpl(comp, constraints, index);
+ }
+
+ protected void fireStateChanged()
+ {
+ ChangeListener[] listeners = getChangeListeners();
+ for (int i = 0; i < listeners.length; ++i)
+ listeners[i].stateChanged(changeEvent);
+ }
+
+ /**
+ * Creates a {@link ViewListener} that is supposed to listen for
+ * size changes on the view component.
+ *
+ * @return a ViewListener instance
+ */
+ protected ViewListener createViewListener()
+ {
+ return new ViewListener();
+ }
+
+ /**
+ * Creates the LayoutManager that is used for this viewport. Override
+ * this method if you want to use a custom LayoutManager.
+ *
+ * @return a LayoutManager to use for this viewport
+ */
+ protected LayoutManager createLayoutManager()
+ {
+ return new ViewportLayout();
+ }
+
+ /**
+ * Computes the parameters for the blitting scroll method. <code>dx</code>
+ * and <code>dy</code> specifiy the X and Y offset by which the viewport
+ * is scrolled. All other arguments are output parameters and are filled by
+ * this method.
+ *
+ * <code>blitFrom</code> holds the position of the blit rectangle in the
+ * viewport rectangle before scrolling, <code>blitTo</code> where the blitArea
+ * is copied to.
+ *
+ * <code>blitSize</code> holds the size of the blit area and
+ * <code>blitPaint</code> is the area of the view that needs to be painted.
+ *
+ * This method returns <code>true</code> if blitting is possible and
+ * <code>false</code> if the viewport has to be repainted completetly without
+ * blitting.
+ *
+ * @param dx the horizontal delta
+ * @param dy the vertical delta
+ * @param blitFrom the position from where to blit; set by this method
+ * @param blitTo the position where to blit area is copied to; set by this
+ * method
+ * @param blitSize the size of the blitted area; set by this method
+ * @param blitPaint the area that needs repainting; set by this method
+ *
+ * @return <code>true</code> if blitting is possible,
+ * <code>false</code> otherwise
+ */
+ protected boolean computeBlit(int dx, int dy, Point blitFrom, Point blitTo,
+ Dimension blitSize, Rectangle blitPaint)
+ {
+ if ((dx != 0 && dy != 0) || (dy == 0 && dy == 0) || damaged)
+ // We cannot blit if the viewport is scrolled in both directions at
+ // once. Also, we do not want to blit if the viewport is not scrolled at
+ // all, because that probably means the view component repaints itself
+ // and the buffer needs updating.
+ return false;
+
+ Rectangle portBounds = SwingUtilities.calculateInnerArea(this, getBounds());
+
+ // Compute the blitFrom and blitTo parameters.
+ blitFrom.x = portBounds.x;
+ blitFrom.y = portBounds.y;
+ blitTo.x = portBounds.x;
+ blitTo.y = portBounds.y;
+
+ if (dy > 0)
+ {
+ blitFrom.y = portBounds.y + dy;
+ }
+ else if (dy < 0)
+ {
+ blitTo.y = portBounds.y - dy;
+ }
+ else if (dx > 0)
+ {
+ blitFrom.x = portBounds.x + dx;
+ }
+ else if (dx < 0)
+ {
+ blitTo.x = portBounds.x - dx;
+ }
+
+ // Compute size of the blit area.
+ if (dx != 0)
+ {
+ blitSize.width = portBounds.width - Math.abs(dx);
+ blitSize.height = portBounds.height;
+ }
+ else if (dy != 0)
+ {
+ blitSize.width = portBounds.width;
+ blitSize.height = portBounds.height - Math.abs(dy);
+ }
+
+ // Compute the blitPaint parameter.
+ blitPaint.setBounds(portBounds);
+ if (dy > 0)
+ {
+ blitPaint.y = portBounds.y + portBounds.height - dy;
+ blitPaint.height = dy;
+ }
+ else if (dy < 0)
+ {
+ blitPaint.height = -dy;
+ }
+ if (dx > 0)
+ {
+ blitPaint.x = portBounds.x + portBounds.width - dx;
+ blitPaint.width = dx;
+ }
+ else if (dx < 0)
+ {
+ blitPaint.width = -dx;
+ }
+
+ return true;
+ }
+
+ /**
+ * Paints the viewport in case we have a scrollmode of
+ * {@link #SIMPLE_SCROLL_MODE}.
+ *
+ * This simply paints the view directly on the surface of the viewport.
+ *
+ * @param g the graphics context to use
+ */
+ void paintSimple(Graphics g)
+ {
+ // We need to call this to properly clear the background.
+ paintComponent(g);
+
+ Point pos = getViewPosition();
+ Component view = getView();
+ Shape oldClip = g.getClip();
+ g.clipRect(0, 0, getWidth(), getHeight());
+ boolean translated = false;
+ try
+ {
+ g.translate(-pos.x, -pos.y);
+ translated = true;
+ view.paint(g);
+ }
+ finally
+ {
+ if (translated)
+ g.translate (pos.x, pos.y);
+ g.setClip(oldClip);
+ }
+ }
+
+ /**
+ * Paints the viewport in case we have a scroll mode of
+ * {@link #BACKINGSTORE_SCROLL_MODE}.
+ *
+ * This method uses a backing store image to paint the view to, which is then
+ * subsequently painted on the screen. This should make scrolling more
+ * smooth.
+ *
+ * @param g the graphics context to use
+ */
+ void paintBackingStore(Graphics g)
+ {
+ // If we have no backing store image yet or the size of the component has
+ // changed, we need to rebuild the backing store.
+ if (backingStoreImage == null || sizeChanged)
+ {
+ backingStoreImage = createImage(getWidth(), getHeight());
+ sizeChanged = false;
+ Graphics g2 = backingStoreImage.getGraphics();
+ paintSimple(g2);
+ g2.dispose();
+ }
+ // Otherwise we can perform the blitting on the backing store image:
+ // First we move the part that remains visible after scrolling, then
+ // we only need to paint the bit that becomes newly visible.
+ else
+ {
+ Graphics g2 = backingStoreImage.getGraphics();
+ Point viewPosition = getViewPosition();
+ int dx = viewPosition.x - lastPaintPosition.x;
+ int dy = viewPosition.y - lastPaintPosition.y;
+ boolean canBlit = computeBlit(dx, dy, cachedBlitFrom, cachedBlitTo,
+ cachedBlitSize, cachedBlitPaint);
+ if (canBlit)
+ {
+ // Copy the part that remains visible during scrolling.
+ g2.copyArea(cachedBlitFrom.x, cachedBlitFrom.y,
+ cachedBlitSize.width, cachedBlitSize.height,
+ cachedBlitTo.x - cachedBlitFrom.x,
+ cachedBlitTo.y - cachedBlitFrom.y);
+ // Now paint the part that becomes newly visible.
+ g2.setClip(cachedBlitPaint.x, cachedBlitPaint.y,
+ cachedBlitPaint.width, cachedBlitPaint.height);
+ paintSimple(g2);
+ }
+ // If blitting is not possible for some reason, fall back to repainting
+ // everything.
+ else
+ {
+ // If the image has not been scrolled at all, only the changed
+ // clip must be updated in the buffer.
+ if (dx == 0 && dy == 0)
+ g2.setClip(g.getClip());
+
+ paintSimple(g2);
+ }
+ g2.dispose();
+ }
+ // Actually draw the backingstore image to the graphics context.
+ g.drawImage(backingStoreImage, 0, 0, this);
+ // Update the lastPaintPosition so that we know what is already drawn when
+ // we paint the next time.
+ lastPaintPosition.setLocation(getViewPosition());
+ }
+
+ /**
+ * Paints the viewport in case we have a scrollmode of
+ * {@link #BLIT_SCROLL_MODE}.
+ *
+ * This paints the viewport using a backingstore and a blitting algorithm.
+ * Only the newly exposed area of the view is painted from the view painting
+ * methods, the remainder is copied from the backing store.
+ *
+ * @param g the graphics context to use
+ */
+ void paintBlit(Graphics g)
+ {
+ // First we move the part that remains visible after scrolling, then
+ // we only need to paint the bit that becomes newly visible.
+ Point viewPosition = getViewPosition();
+ int dx = viewPosition.x - lastPaintPosition.x;
+ int dy = viewPosition.y - lastPaintPosition.y;
+ boolean canBlit = computeBlit(dx, dy, cachedBlitFrom, cachedBlitTo,
+ cachedBlitSize, cachedBlitPaint);
+ if (canBlit && isPaintRoot)
+ {
+ // Copy the part that remains visible during scrolling.
+ g.copyArea(cachedBlitFrom.x, cachedBlitFrom.y,
+ cachedBlitSize.width, cachedBlitSize.height,
+ cachedBlitTo.x - cachedBlitFrom.x,
+ cachedBlitTo.y - cachedBlitFrom.y);
+ // Now paint the part that becomes newly visible.
+ Shape oldClip = g.getClip();
+ g.clipRect(cachedBlitPaint.x, cachedBlitPaint.y,
+ cachedBlitPaint.width, cachedBlitPaint.height);
+ try
+ {
+ paintSimple(g);
+ }
+ finally
+ {
+ g.setClip(oldClip);
+ }
+ }
+ // If blitting is not possible for some reason, fall back to repainting
+ // everything.
+ else
+ paintSimple(g);
+ lastPaintPosition.setLocation(getViewPosition());
+ }
+
+ /**
+ * Overridden from JComponent to set the {@link #isPaintRoot} flag.
+ *
+ * @param r the rectangle to paint
+ */
+ void paintImmediately2(Rectangle r)
+ {
+ isPaintRoot = true;
+ super.paintImmediately2(r);
+ isPaintRoot = false;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/JWindow.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/JWindow.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/JWindow.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/JWindow.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,285 @@
+/* JWindow.java --
+ Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.GraphicsConfiguration;
+import java.awt.LayoutManager;
+import java.awt.Window;
+import java.awt.event.KeyEvent;
+
+import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleContext;
+
+/**
+ * Unlike JComponent derivatives, JWindow inherits from
+ * java.awt.Window. But also lets a look-and-feel component to its work.
+ *
+ * @author Ronald Veldema (rveldema at cs.vu.nl)
+ */
+public class JWindow extends Window implements Accessible, RootPaneContainer
+{
+ /**
+ * Provides accessibility support for <code>JWindow</code>.
+ */
+ protected class AccessibleJWindow extends Window.AccessibleAWTWindow
+ {
+ /**
+ * Creates a new instance of <code>AccessibleJWindow</code>.
+ */
+ protected AccessibleJWindow()
+ {
+ super();
+ // Nothing to do here.
+ }
+ }
+
+ private static final long serialVersionUID = 5420698392125238833L;
+
+ protected JRootPane rootPane;
+
+ /**
+ * @specnote rootPaneCheckingEnabled is false to comply with J2SE 5.0
+ */
+ protected boolean rootPaneCheckingEnabled = false;
+
+ protected AccessibleContext accessibleContext;
+
+ /**
+ * Creates a new <code>JWindow</code> that has a shared invisible owner frame
+ * as its parent.
+ */
+ public JWindow()
+ {
+ super(SwingUtilities.getOwnerFrame(null));
+ windowInit();
+ }
+
+ /**
+ * Creates a new <code>JWindow</code> that uses the specified graphics
+ * environment. This can be used to open a window on a different screen for
+ * example.
+ *
+ * @param gc the graphics environment to use
+ */
+ public JWindow(GraphicsConfiguration gc)
+ {
+ super(SwingUtilities.getOwnerFrame(null), gc);
+ windowInit();
+ }
+
+ /**
+ * Creates a new <code>JWindow</code> that has the specified
+ * <code>owner</code> frame. If <code>owner</code> is <code>null</code>, then
+ * an invisible shared owner frame is installed as owner frame.
+ *
+ * @param owner the owner frame of this window; if <code>null</code> a shared
+ * invisible owner frame is used
+ */
+ public JWindow(Frame owner)
+ {
+ super(SwingUtilities.getOwnerFrame(owner));
+ windowInit();
+ }
+
+ /**
+ * Creates a new <code>JWindow</code> that has the specified
+ * <code>owner</code> window. If <code>owner</code> is <code>null</code>,
+ * then an invisible shared owner frame is installed as owner frame.
+ *
+ * @param owner the owner window of this window; if <code>null</code> a
+ * shared invisible owner frame is used
+ */
+ public JWindow(Window owner)
+ {
+ super(SwingUtilities.getOwnerFrame(owner));
+ windowInit();
+ }
+
+ /**
+ * Creates a new <code>JWindow</code> for the given graphics configuration
+ * and that has the specified <code>owner</code> window. If
+ * <code>owner</code> is <code>null</code>, then an invisible shared owner
+ * frame is installed as owner frame.
+ *
+ * The <code>gc</code> parameter can be used to open the window on a
+ * different screen for example.
+ *
+ * @param owner the owner window of this window; if <code>null</code> a
+ * shared invisible owner frame is used
+ * @param gc the graphics configuration to use
+ */
+ public JWindow(Window owner, GraphicsConfiguration gc)
+ {
+ super(SwingUtilities.getOwnerFrame(owner), gc);
+ windowInit();
+ }
+
+ protected void windowInit()
+ {
+ super.setLayout(new BorderLayout(1, 1));
+ getRootPane(); // will do set/create
+ // Now we're done init stage, adds and layouts go to content pane.
+ setRootPaneCheckingEnabled(true);
+ }
+
+ public Dimension getPreferredSize()
+ {
+ return super.getPreferredSize();
+ }
+
+ public void setLayout(LayoutManager manager)
+ {
+ // Check if we're in initialization stage. If so, call super.setLayout
+ // otherwise, valid calls go to the content pane.
+ if (isRootPaneCheckingEnabled())
+ getContentPane().setLayout(manager);
+ else
+ super.setLayout(manager);
+ }
+
+ public void setLayeredPane(JLayeredPane layeredPane)
+ {
+ getRootPane().setLayeredPane(layeredPane);
+ }
+
+ public JLayeredPane getLayeredPane()
+ {
+ return getRootPane().getLayeredPane();
+ }
+
+ public JRootPane getRootPane()
+ {
+ if (rootPane == null)
+ setRootPane(createRootPane());
+ return rootPane;
+ }
+
+ protected void setRootPane(JRootPane root)
+ {
+ if (rootPane != null)
+ remove(rootPane);
+
+ rootPane = root;
+ add(rootPane, BorderLayout.CENTER);
+ }
+
+ protected JRootPane createRootPane()
+ {
+ return new JRootPane();
+ }
+
+ public Container getContentPane()
+ {
+ return getRootPane().getContentPane();
+ }
+
+ public void setContentPane(Container contentPane)
+ {
+ getRootPane().setContentPane(contentPane);
+ }
+
+ public Component getGlassPane()
+ {
+ return getRootPane().getGlassPane();
+ }
+
+ public void setGlassPane(Component glassPane)
+ {
+ getRootPane().setGlassPane(glassPane);
+ }
+
+
+ protected void addImpl(Component comp, Object constraints, int index)
+ {
+ // If we're adding in the initialization stage use super.add.
+ // otherwise pass the add onto the content pane.
+ if (isRootPaneCheckingEnabled())
+ getContentPane().add(comp, constraints, index);
+ else
+ super.addImpl(comp, constraints, index);
+ }
+
+ public void remove(Component comp)
+ {
+ // If we're removing the root pane, use super.remove. Otherwise
+ // pass it on to the content pane instead.
+ if (comp == rootPane)
+ super.remove(rootPane);
+ else
+ getContentPane().remove(comp);
+ }
+
+ protected boolean isRootPaneCheckingEnabled()
+ {
+ return rootPaneCheckingEnabled;
+ }
+
+ protected void setRootPaneCheckingEnabled(boolean enabled)
+ {
+ rootPaneCheckingEnabled = enabled;
+ }
+
+ public void update(Graphics g)
+ {
+ paint(g);
+ }
+
+ protected void processKeyEvent(KeyEvent e)
+ {
+ super.processKeyEvent(e);
+ }
+
+ public AccessibleContext getAccessibleContext()
+ {
+ if (accessibleContext == null)
+ accessibleContext = new AccessibleJWindow();
+ return accessibleContext;
+ }
+
+ protected String paramString()
+ {
+ return "JWindow";
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/KeyStroke.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/KeyStroke.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/KeyStroke.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/KeyStroke.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,123 @@
+/* KeyStroke.java --
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.awt.AWTKeyStroke;
+import java.awt.event.KeyEvent;
+import java.io.Serializable;
+
+public class KeyStroke
+ extends AWTKeyStroke
+ implements Serializable
+{
+ private static final long serialVersionUID = -9060180771037902530L;
+
+ // Called by java.awt.AWTKeyStroke.registerSubclass via reflection.
+ private KeyStroke()
+ {
+ // Nothing to do here.
+ }
+
+ private KeyStroke(char keyChar, int keyCode, int modifiers,
+ boolean onKeyRelease)
+ {
+ super(keyChar, keyCode, modifiers, onKeyRelease);
+ }
+
+ static
+ {
+ AWTKeyStroke.registerSubclass(KeyStroke.class);
+ }
+
+ public static KeyStroke getKeyStroke(char keyChar)
+ {
+ return (KeyStroke) getAWTKeyStroke(keyChar);
+ }
+
+ /**
+ * @deprecated Use {@link #getKeyStroke(char)}
+ *
+ * This method, unlike all the other factory methods on this object,
+ * returns a non-cached, non-shared object. New code should not use it.
+ */
+ public static KeyStroke getKeyStroke(char keyChar, boolean onKeyRelease)
+ {
+ return new KeyStroke(keyChar, KeyEvent.VK_UNDEFINED, 0, onKeyRelease);
+ }
+
+ public static KeyStroke getKeyStroke(Character keyChar, int modifiers)
+ {
+ return (KeyStroke) getAWTKeyStroke(keyChar, modifiers);
+ }
+
+ public static KeyStroke getKeyStroke(int keyCode, int modifiers,
+ boolean onKeyRelease)
+ {
+ return (KeyStroke) getAWTKeyStroke(keyCode, modifiers, onKeyRelease);
+ }
+
+ public static KeyStroke getKeyStroke(int keyCode, int modifiers)
+ {
+ return (KeyStroke) getAWTKeyStroke(keyCode, modifiers);
+ }
+
+ /**
+ * Returns the KeyStroke according to <code>getAWTKeyStroke()</code>.
+ * But it returns null instead of throwing
+ * <code>IllegalArugmentException</code> when
+ * the keystoke sequence cannot be parsed from the given string.
+ */
+ public static KeyStroke getKeyStroke(String str)
+ {
+ try
+ {
+ return (KeyStroke) getAWTKeyStroke(str);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ return null;
+ }
+ }
+
+ public static KeyStroke getKeyStrokeForEvent(KeyEvent event)
+ {
+ return (KeyStroke) getAWTKeyStrokeForEvent(event);
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/KeyboardManager.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/KeyboardManager.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/KeyboardManager.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/KeyboardManager.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,281 @@
+/* KeyboardManager.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.applet.Applet;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Window;
+import java.awt.event.KeyEvent;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
+import java.util.WeakHashMap;
+
+/**
+ * This class maintains a mapping from top-level containers to a
+ * Hashtable. The Hashtable maps KeyStrokes to Components to be used when
+ * Components register keyboard actions with the condition
+ * JComponent.WHEN_IN_FOCUSED_WINDOW.
+ *
+ * @author Anthony Balkissoon abalkiss at redhat dot com
+ *
+ */
+class KeyboardManager
+{
+ /** Shared instance of KeyboardManager **/
+ static KeyboardManager manager = new KeyboardManager();
+
+ /**
+ * A mapping between top level containers and Hashtables that
+ * map KeyStrokes to Components.
+ */
+ WeakHashMap topLevelLookup = new WeakHashMap();
+
+ /**
+ * A mapping between top level containers and Vectors of JMenuBars
+ * used to allow all the JMenuBars within a top level container
+ * a chance to consume key events.
+ */
+ Hashtable menuBarLookup = new Hashtable();
+ /**
+ * Returns the shared instance of KeyboardManager.
+ * @return the shared instance of KeybaordManager.
+ */
+ public static KeyboardManager getManager()
+ {
+ return manager;
+ }
+ /**
+ * Returns the top-level ancestor for the given JComponent.
+ * @param c the JComponent whose top-level ancestor we want
+ * @return the top-level ancestor for the given JComponent.
+ */
+ static Container findTopLevel (Component c)
+ {
+ Container topLevel = (c instanceof Container) ? (Container) c
+ : c.getParent();
+ while (topLevel != null &&
+ !(topLevel instanceof Window) &&
+ !(topLevel instanceof Applet) &&
+ !(topLevel instanceof JInternalFrame))
+ topLevel = topLevel.getParent();
+ return topLevel;
+ }
+
+ /**
+ * Returns the Hashtable that maps KeyStrokes to Components, for
+ * the specified top-level container c. If no Hashtable exists
+ * we create and register it here and return the newly created
+ * Hashtable.
+ *
+ * @param c the top-level container whose Hashtable we want
+ * @return the Hashtable mapping KeyStrokes to Components for the
+ * specified top-level container
+ */
+ Hashtable getHashtableForTopLevel (Container c)
+ {
+ Hashtable keyToComponent = (Hashtable)topLevelLookup.get(c);
+ if (keyToComponent == null)
+ {
+ keyToComponent = new Hashtable();
+ topLevelLookup.put(c, keyToComponent);
+ }
+ return keyToComponent;
+ }
+
+ /**
+ * Registers a KeyStroke with a Component. This does not register
+ * the KeyStroke to a specific Action. When searching for a
+ * WHEN_IN_FOCUSED_WINDOW binding we will first go up to the focused
+ * top-level Container, then get the Hashtable that maps KeyStrokes
+ * to components for that particular top-level Container, then
+ * call processKeyBindings on that component with the condition
+ * JComponent.WHEN_IN_FOCUSED_WINDOW.
+ * @param comp the JComponent associated with the KeyStroke
+ * @param key the KeyStroke
+ */
+ public void registerBinding(JComponent comp, KeyStroke key)
+ {
+ // This method associates a KeyStroke with a particular JComponent
+ // When the KeyStroke occurs, if this component's top-level ancestor
+ // has focus (one of its children is the focused Component) then
+ // comp.processKeyBindings will be called with condition
+ // JComponent.WHEN_IN_FOCUSED_WINDOW.
+
+ // Look for the JComponent's top-level parent and return if it is null
+ Container topLevel = findTopLevel(comp);
+ if (topLevel == null)
+ return;
+
+ // Now get the Hashtable for this top-level container
+ Hashtable keyToComponent = getHashtableForTopLevel(topLevel);
+
+ // And add the new binding to this Hashtable
+ // FIXME: should allow more than one JComponent to be associated
+ // with a KeyStroke, in case one of them is disabled
+ keyToComponent.put(key, comp);
+ }
+
+ public void clearBindingsForComp(JComponent comp)
+ {
+ // This method clears all the WHEN_IN_FOCUSED_WINDOW bindings associated
+ // with <code>comp</code>. This is used for a terribly ineffcient
+ // strategy in which JComponent.updateComponentInputMap simply clears
+ // all bindings associated with its component and then reloads all the
+ // bindings from the updated ComponentInputMap. This is only a preliminary
+ // strategy and should be improved upon once the WHEN_IN_FOCUSED_WINDOW
+ // bindings work.
+
+ // Find the top-level ancestor
+
+ Container topLevel = findTopLevel(comp);
+ if (topLevel == null)
+ return;
+ // And now get its Hashtable
+ Hashtable keyToComponent = getHashtableForTopLevel(topLevel);
+
+ Enumeration keys = keyToComponent.keys();
+ Object temp;
+
+ // Iterate through the keys and remove any key whose value is comp
+ while (keys.hasMoreElements())
+ {
+ temp = keys.nextElement();
+ if (comp == (JComponent)keyToComponent.get(temp))
+ keyToComponent.remove(temp);
+ }
+ }
+
+ /**
+ * This method registers all the bindings in the given ComponentInputMap.
+ * Rather than call registerBinding on all the keys, we do the work here
+ * so that we don't duplicate finding the top-level container and
+ * getting its Hashtable.
+ *
+ * @param map the ComponentInputMap whose bindings we want to register
+ */
+ public void registerEntireMap (ComponentInputMap map)
+ {
+ if (map == null)
+ return;
+ JComponent comp = map.getComponent();
+ KeyStroke[] keys = map.allKeys();
+ if (keys == null)
+ return;
+ // Find the top-level container associated with this ComponentInputMap
+ Container topLevel = findTopLevel(comp);
+ if (topLevel == null)
+ return;
+
+ // Register the KeyStrokes in the top-level container's Hashtable
+ Hashtable keyToComponent = getHashtableForTopLevel(topLevel);
+ for (int i = 0; i < keys.length; i++)
+ keyToComponent.put(keys[i], comp);
+ }
+
+ public boolean processKeyStroke (Component comp, KeyStroke key, KeyEvent e)
+ {
+ boolean pressed = e.getID() == KeyEvent.KEY_PRESSED;
+
+ // Look for the top-level ancestor
+ Container topLevel = findTopLevel(comp);
+ if (topLevel == null)
+ return false;
+ // Now get the Hashtable for that top-level container
+ Hashtable keyToComponent = getHashtableForTopLevel(topLevel);
+ Enumeration keys = keyToComponent.keys();
+ JComponent target = (JComponent)keyToComponent.get(key);
+ if (target != null && target.processKeyBinding
+ (key, e, JComponent.WHEN_IN_FOCUSED_WINDOW, pressed))
+ return true;
+
+ // Have to give all the JMenuBars a chance to consume the event
+ Vector menuBars = getVectorForTopLevel(topLevel);
+ for (int i = 0; i < menuBars.size(); i++)
+ if (((JMenuBar)menuBars.elementAt(i)).processKeyBinding(key, e, JComponent.WHEN_IN_FOCUSED_WINDOW, pressed))
+ return true;
+ return false;
+ }
+
+ /**
+ * Returns the Vector of JMenuBars associated with the top-level
+ * @param c the top-level container whose JMenuBar Vector we want
+ * @return the Vector of JMenuBars for this top level container
+ */
+ Vector getVectorForTopLevel(Container c)
+ {
+ Vector result = (Vector) menuBarLookup.get(c);
+ if (result == null)
+ {
+ result = new Vector();
+ menuBarLookup.put (c, result);
+ }
+ return result;
+ }
+
+ /**
+ * In processKeyStroke, KeyManager must give all JMenuBars in the
+ * focused top-level container a chance to process the event. So,
+ * JMenuBars must be registered in KeyManager and associated with a
+ * top-level container. That's what this method is for.
+ * @param menuBar the JMenuBar to register
+ */
+ public void registerJMenuBar (JMenuBar menuBar)
+ {
+ Container topLevel = findTopLevel(menuBar);
+ Vector menuBars = getVectorForTopLevel(topLevel);
+ if (!menuBars.contains(menuBar))
+ menuBars.add(menuBar);
+ }
+
+ /**
+ * Unregisters a JMenuBar from its top-level container. This is
+ * called before the JMenuBar is actually removed from the container
+ * so findTopLevel will still find us the correct top-level container.
+ * @param menuBar the JMenuBar to unregister.
+ */
+ public void unregisterJMenuBar (JMenuBar menuBar)
+ {
+ Container topLevel = findTopLevel(menuBar);
+ Vector menuBars = getVectorForTopLevel(topLevel);
+ if (menuBars.contains(menuBar))
+ menuBars.remove(menuBar);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/LayoutFocusTraversalPolicy.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/LayoutFocusTraversalPolicy.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/LayoutFocusTraversalPolicy.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/LayoutFocusTraversalPolicy.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,89 @@
+/* LayoutFocusTraversalPolicy.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.awt.Component;
+import java.io.Serializable;
+import java.util.Comparator;
+
+/**
+ * @author Graydon Hoare
+ * @author Michael Koch
+ *
+ * @since 1.4
+ */
+public class LayoutFocusTraversalPolicy
+ extends SortingFocusTraversalPolicy
+ implements Serializable
+{
+ private static class LayoutComparator
+ implements Comparator
+ {
+ public LayoutComparator()
+ {
+ // Do nothing here.
+ }
+
+ public int compare(Object o1, Object o2)
+ {
+ Component comp1 = (Component) o1;
+ Component comp2 = (Component) o2;
+
+ int x1 = comp1.getX();
+ int y1 = comp1.getY();
+ int x2 = comp2.getX();
+ int y2 = comp2.getY();
+
+ if (x1 == x2 && y1 == y2)
+ return 0;
+
+ if ((y1 < y2) || ((y1 == y2) && (x1 < x2)))
+ return -1;
+
+ return 1;
+ }
+ }
+
+ private static final long serialVersionUID = 4312146927238881442L;
+
+ public LayoutFocusTraversalPolicy()
+ {
+ super(new LayoutComparator());
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ListCellRenderer.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ListCellRenderer.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ListCellRenderer.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ListCellRenderer.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,50 @@
+/* ListCellRenderer.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import java.awt.Component;
+
+/**
+ * Renders the cells of a {@link JList}.
+ */
+public interface ListCellRenderer
+{
+ Component getListCellRendererComponent(JList list, Object value, int index,
+ boolean isSelected,
+ boolean cellHasFocus);
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ListModel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ListModel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ListModel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ListModel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,80 @@
+/* ListModel.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import javax.swing.event.ListDataListener;
+
+/**
+ * The data model that is typically used in {@link JList}.
+ *
+ * @author Graydon Hoare (graydon at redhat.com)
+ */
+public interface ListModel
+{
+ /**
+ * Return the number of data elements in the list.
+ *
+ * @return The number of data elements in the list
+ */
+ int getSize();
+
+ /**
+ * Retrieves a data element at a specified index.
+ *
+ * @param index The index of the element to retrieve
+ *
+ * @return The data element at the specified index
+ */
+ Object getElementAt(int index);
+
+ /**
+ * Add a listener object to this model. The listener will be called
+ * any time the set of elements in the model is changed.
+ *
+ * @param l The listener to add
+ */
+ void addListDataListener(ListDataListener l);
+
+ /**
+ * Add a listener object to this model. The listener will no longer be
+ * called when the set of elements in the model is changed.
+ *
+ * @param l The listener to remove
+ */
+ void removeListDataListener(ListDataListener l);
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ListSelectionModel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ListSelectionModel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ListSelectionModel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ListSelectionModel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,332 @@
+/* ListSelectionModel.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+
+/**
+ * A model that tracks the selection status of a list of items. Each item in
+ * the list is identified by a zero-based index only, so the model can be used
+ * to track the selection status of any type of list. The model
+ * supports three modes:
+ * <ul>
+ * <li><code>SINGLE_SELECTION</code> - only one item in the list may be
+ * selected;</li>
+ * <li><code>SINGLE_INTERVAL_SELECTION</code> - only one interval in the list
+ * may be selected;</li>
+ * <li><code>MULTIPLE_INTERVAL_SELECTION</code> - any combination of items in
+ * the list may be selected.</li>
+ * </ul>
+ * The model uses an event notification mechanism to notify listeners (see
+ * {@link ListSelectionListener}) about updates to the selection model.
+ * <p>
+ * This model is used to track row selections in the {@link JList} component,
+ * and row and column selections in the {@link JTable} component.
+ */
+public interface ListSelectionModel
+{
+
+ /**
+ * A selection mode in which only one item can be selected.
+ *
+ * @see #setSelectionMode(int)
+ */
+ int SINGLE_SELECTION = 0;
+
+ /**
+ * A selection mode in which a single interval can be selected (an interval
+ * is a range containing one or more contiguous items).
+ *
+ * @see #setSelectionMode(int)
+ */
+ int SINGLE_INTERVAL_SELECTION = 1;
+
+ /**
+ * A selection mode in which any combination of items can be selected.
+ *
+ * @see #setSelectionMode(int)
+ */
+ int MULTIPLE_INTERVAL_SELECTION = 2;
+
+ /**
+ * Sets the selection mode.
+ * <p>
+ * FIXME: The spec is silent about what happens to existing selections, for
+ * example when changing from an interval selection to single selection.
+ *
+ * @param mode one of {@link #SINGLE_SELECTION},
+ * {@link #SINGLE_INTERVAL_SELECTION} and
+ * {@link #MULTIPLE_INTERVAL_SELECTION}.
+ *
+ * @see #getSelectionMode()
+ *
+ * @throws IllegalArgumentException if <code>mode</code> is not one of the
+ * specified values.
+ */
+ void setSelectionMode(int mode);
+
+ /**
+ * Returns the selection mode, which is one of {@link #SINGLE_SELECTION},
+ * {@link #SINGLE_INTERVAL_SELECTION} and
+ * {@link #MULTIPLE_INTERVAL_SELECTION}.
+ *
+ * @return The selection mode.
+ *
+ * @see #setSelectionMode(int)
+ */
+ int getSelectionMode();
+
+ /**
+ * Clears the current selection from the model. If the selection state
+ * changes (that is, the existing selection is non-empty) a
+ * {@link ListSelectionEvent} should be sent to all registered listeners.
+ * <p>
+ * FIXME: what happens to the anchor and lead selection indices (the spec
+ * is silent about this)? See:
+ * <p>
+ * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4334792
+ */
+ void clearSelection();
+
+ /**
+ * Returns the lowest selected index, or <code>-1</code> if there is no
+ * selection.
+ *
+ * @return The lowest selected index.
+ *
+ * @see #getMaxSelectionIndex()
+ */
+ int getMinSelectionIndex();
+
+ /**
+ * Returns the highest selected index, or <code>-1</code> if there is no
+ * selection.
+ *
+ * @return The highest selected index.
+ *
+ * @see #getMinSelectionIndex()
+ */
+ int getMaxSelectionIndex();
+
+ /**
+ * Returns <code>true</code> if the specified item is selected, and
+ * <code>false</code> otherwise. Special note: if <code>index</code> is
+ * negative, this method should return <code>false</code> (no exception
+ * should be thrown).
+ *
+ * @param index the item index (zero-based).
+ *
+ * @return <code>true</code> if the specified item is selected, and
+ * <code>false</code> otherwise.
+ */
+ boolean isSelectedIndex(int index);
+
+ /**
+ * Returns <code>true</code> if there is no selection, and <code>false</code>
+ * otherwise.
+ *
+ * @return <code>true</code> if there is no selection, and
+ * <code>false</code> otherwise.
+ */
+ boolean isSelectionEmpty();
+
+ /**
+ * Sets the selection interval to the specified range (note that
+ * <code>anchor</code> can be less than, equal to, or greater than
+ * <code>lead</code>). If this results in the selection being changed,
+ * a {@link ListSelectionEvent} is sent to all registered listeners.
+ * <p>
+ * If the selection mode is {@link #SINGLE_SELECTION}, only the
+ * <code>lead</code> item is selected.
+ *
+ * @param anchor the anchor index.
+ * @param lead the lead index.
+ */
+ void setSelectionInterval(int anchor, int lead);
+
+ /**
+ * Marks the items in the specified interval as selected. The behaviour of
+ * this method depends on the selection mode:
+ * <ul>
+ * <li><code>SINGLE_SELECTION</code> - only the <code>lead</code> item is
+ * selected;</li>
+ * <li><code>SINGLE_INTERVAL_SELECTION</code> - the existing selection
+ * interval is replaced by the specified interval;</li>
+ * <li><code>MULTIPLE_INTERVAL_SELECTION</code> - the specified interval is
+ * merged into the currently selected intervals.</li>
+ * </ul>
+ * Note that <code>anchor</code> can be less than, equal to, or greater than
+ * <code>lead</code>.
+ *
+ * @param anchor the index of the anchor item
+ * @param lead the index of the lead item.
+ */
+ void addSelectionInterval(int anchor, int lead);
+
+ /**
+ * Marks the items in the specified interval as not selected. The behaviour
+ * of this method depends on the selection mode:
+ * <ul>
+ * <li><code>SINGLE_SELECTION</code> - XXX;</li>
+ * <li><code>SINGLE_INTERVAL_SELECTION</code> - XXX;</li>
+ * <li><code>MULTIPLE_INTERVAL_SELECTION</code> - XXX.</li>
+ * </ul>
+ * Note that <code>anchor</code> can be less than, equal to, or greater than
+ * <code>lead</code>.
+ *
+ * @param anchor the index of the anchor item
+ * @param lead the index of the lead item.
+ */
+ void removeSelectionInterval(int anchor, int lead);
+
+ /**
+ * Inserts a new interval containing <code>length</code> items at the
+ * specified <code>index</code> (the <code>before</code> flag indicates
+ * whether the range is inserted before or after the existing item at
+ * <code>index</code>).
+ *
+ * FIXME: What is the selection status of the new items? Bug 4870694.
+ * FIXME: What event is generated?
+ *
+ * @param index the index of the item.
+ * @param length the number of items in the interval to be inserted.
+ * @param before if <code>true</code>, the interval should be inserted
+ * before <code>index</code>, otherwise it is inserted after.
+ *
+ * @see #removeIndexInterval(int, int)
+ */
+ void insertIndexInterval(int index, int length, boolean before);
+
+ /**
+ * Removes the items in the specified range (inclusive) from the selection
+ * model. This method should be called when an interval is deleted from
+ * the underlying list.
+ *
+ * FIXME: what happens to the lead and anchor indices if they are part of
+ * the range that is removed?
+ * FIXME: what event is generated
+ *
+ * @param index0 XXX
+ * @param index1 XXX
+ *
+ * @see #insertIndexInterval(int, int, boolean)
+ */
+ void removeIndexInterval(int index0, int index1);
+
+ /**
+ * Returns the index of the anchor item.
+ *
+ * @return The index of the anchor item.
+ *
+ * @see #setAnchorSelectionIndex(int)
+ */
+ int getAnchorSelectionIndex();
+
+ /**
+ * Sets the index of the anchor item.
+ *
+ * @param index the item index.
+ *
+ * @see #getAnchorSelectionIndex()
+ */
+ void setAnchorSelectionIndex(int index);
+
+ /**
+ * Returns the index of the lead item.
+ *
+ * @return The index of the lead item.
+ *
+ * @see #setLeadSelectionIndex(int)
+ */
+ int getLeadSelectionIndex();
+
+ /**
+ * Sets the index of the lead item.
+ *
+ * @param index the item index.
+ *
+ * @see #getLeadSelectionIndex()
+ */
+ void setLeadSelectionIndex(int index);
+
+ /**
+ * Sets the flag that is passed to listeners for each change notification.
+ * If a sequence of changes is made to the selection model, this flag should
+ * be set to <code>true</code> at the start of the sequence, and
+ * <code>false</code> for the last change - this gives listeners the option
+ * to ignore interim changes if that is more efficient.
+ *
+ * @param valueIsAdjusting the flag value.
+ *
+ * @see #getValueIsAdjusting()
+ */
+ void setValueIsAdjusting(boolean valueIsAdjusting);
+
+ /**
+ * Returns a flag that is passed to registered listeners when changes are
+ * made to the model. See the description for
+ * {@link #setValueIsAdjusting(boolean)} for more information.
+ *
+ * @return The flag.
+ */
+ boolean getValueIsAdjusting();
+
+ /**
+ * Registers a listener with the model so that it receives notification
+ * of changes to the model.
+ *
+ * @param listener the listener (<code>null</code> ignored).
+ *
+ * @see #removeListSelectionListener(ListSelectionListener)
+ */
+ void addListSelectionListener(ListSelectionListener listener);
+
+ /**
+ * Deregisters a listener so that it no longer receives notification of
+ * changes to the model. If the specified listener is not registered with
+ * the model, or is <code>null</code>, this method does nothing.
+ *
+ * @param listener the listener (<code>null</code> ignored).
+ *
+ * @see #addListSelectionListener(ListSelectionListener)
+ */
+ void removeListSelectionListener(ListSelectionListener listener);
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/LookAndFeel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/LookAndFeel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/LookAndFeel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/LookAndFeel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,433 @@
+/* LookAndFeel.java --
+ Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Font;
+import java.awt.Toolkit;
+import java.net.URL;
+
+import javax.swing.border.Border;
+import javax.swing.plaf.ComponentInputMapUIResource;
+import javax.swing.plaf.IconUIResource;
+import javax.swing.plaf.InputMapUIResource;
+import javax.swing.plaf.UIResource;
+import javax.swing.plaf.metal.MetalLookAndFeel;
+import javax.swing.text.JTextComponent;
+
+/**
+ * A <i>look-and-feel</i> controls most aspects of the appearance and
+ * operation of user interface components in <code>javax.swing</code>. A
+ * cross-platform look-and-feel (the {@link MetalLookAndFeel}) is provided.
+ *
+ * @see UIManager#getInstalledLookAndFeels()
+ * @see UIManager#setLookAndFeel(LookAndFeel)
+ */
+public abstract class LookAndFeel
+{
+ /**
+ * Creates and returns a look-and-feel specific defaults table. This method
+ * is called once by {@link UIManager#setLookAndFeel(LookAndFeel)} and
+ * shouldn't be called again (as it creates a large table of defaults).
+ *
+ * @return The UI defaults.
+ */
+ public UIDefaults getDefaults()
+ {
+ return null;
+ }
+
+ /**
+ * Returns a description of the look and feel.
+ *
+ * @return A description of the look and feel.
+ */
+ public abstract String getDescription();
+
+ /**
+ * Returns the value of <code>Toolkit.getDefaultToolkit()
+ * .getDesktopProperty(systemPropertyName)</code>, or
+ * <code>fallbackValue</code> if no such property is defined.
+ *
+ * @param systemPropertyName the system property name.
+ * @param fallbackValue the fallback value.
+ *
+ * @return The property value or <code>fallbackValue</code>.
+ */
+ public static Object getDesktopPropertyValue(String systemPropertyName,
+ Object fallbackValue)
+ {
+ Object value = Toolkit.getDefaultToolkit().getDesktopProperty(
+ systemPropertyName);
+ return value != null ? value : fallbackValue;
+ }
+
+ /**
+ * Returns an identifier for the look and feel.
+ *
+ * @return An identifier for the look and feel.
+ */
+ public abstract String getID();
+
+ /**
+ * Returns the name for the look and feel.
+ *
+ * @return The name for the look and feel.
+ */
+ public abstract String getName();
+
+ /**
+ * Returns <code>true</code> when the look-and-feel supports window
+ * decorations, and <code>false</code> otherwise. This default implementation
+ * always returns <code>false</code> and needs to be overridden when the
+ * derived look-and-feel supports this.
+ *
+ * @return <code>false</code>.
+ *
+ * @since 1.4
+ */
+ public boolean getSupportsWindowDecorations()
+ {
+ return false;
+ }
+
+ /**
+ * Initializes the look-and-feel. The
+ * {@link UIManager#setLookAndFeel(LookAndFeel)} method calls this method
+ * before the first call (and typically the only call) to
+ * {@link #getDefaults()}. This default implementation does nothing, but
+ * subclasses can override this behaviour.
+ */
+ public void initialize()
+ {
+ // We do nothing here. This method is meant to be overridden by
+ // LookAndFeel implementations.
+ }
+
+ /**
+ * Convenience method for installing a component's default {@link Border}
+ * object on the specified component if either the border is currently
+ * <code>null</code> or already an instance of {@link UIResource}.
+ *
+ * @param c the component (<code>null</code> not permitted).
+ * @param defaultBorderName the border name (for lookup in the UIDefaults
+ * table).
+ */
+ public static void installBorder(JComponent c, String defaultBorderName)
+ {
+ Border b = c.getBorder();
+ if (b == null || b instanceof UIResource)
+ c.setBorder(UIManager.getBorder(defaultBorderName));
+ }
+
+ /**
+ * Convenience method for initializing a component's foreground and
+ * background color properties with values from the current defaults table.
+ *
+ * @param c the component (<code>null</code> not permitted).
+ * @param defaultBgName the key for the background color in the UIDefaults
+ * table.
+ * @param defaultFgName the key for the foreground color in the UIDefaults
+ * table.
+ */
+ public static void installColors(JComponent c, String defaultBgName,
+ String defaultFgName)
+ {
+ // Install background.
+ Color bg = c.getBackground();
+ if (bg == null || bg instanceof UIResource)
+ c.setBackground(UIManager.getColor(defaultBgName));
+
+ // Install foreground.
+ Color fg = c.getForeground();
+ if (fg == null || fg instanceof UIResource)
+ c.setForeground(UIManager.getColor(defaultFgName));
+ }
+
+ /**
+ * Convenience method for initializing a component's foreground, background
+ * and font properties with values from the current defaults table.
+ *
+ * @param component the component (<code>null</code> not permitted).
+ * @param defaultBgName the key for the background color in the UIDefaults
+ * table.
+ * @param defaultFgName the key for the foreground color in the UIDefaults
+ * table.
+ * @param defaultFontName the key for the font in the UIDefaults table.
+ */
+ public static void installColorsAndFont(JComponent component,
+ String defaultBgName,
+ String defaultFgName,
+ String defaultFontName)
+ {
+ // Install colors.
+ installColors(component, defaultBgName, defaultFgName);
+ // Install font.
+ Font f = component.getFont();
+ if (f == null || f instanceof UIResource)
+ component.setFont(UIManager.getFont(defaultFontName));
+ }
+
+ /**
+ * Returns <code>true</code> if the look-and-feel is the "native"
+ * look-and-feel for the current platform, and <code>false</code> otherwise.
+ * A native look-and-feel emulates the appearance and behaviour of the
+ * default windowing system on the host operating system.
+ *
+ * @return A flag indicating whether or not this is the native look and feel
+ * for the current platform.
+ */
+ public abstract boolean isNativeLookAndFeel();
+
+ /**
+ * Returns <code>true</code> if the look-and-feel is supported on the
+ * current operating system, and <code>false</code> otherwise. This
+ * mechanism is provided so that it is possible to prevent a look-and-feel
+ * from being used on some operating systems (usually for legal, not
+ * technical, reasons).
+ *
+ * @return A flag indicating whether or not the look-and-feel is supported
+ * on the current platform.
+ */
+ public abstract boolean isSupportedLookAndFeel();
+
+ /**
+ * Loads the bindings in keys into retMap. Does not remove existing entries
+ * from retMap. <code>keys</code> describes the InputMap, every even indexed
+ * item is either a KeyStroke or a String representing a KeyStroke and every
+ * odd indexed item is the Object associated with that KeyStroke in an
+ * ActionMap.
+ *
+ * @param retMap the InputMap into which we load bindings
+ * @param keys the Object array describing the InputMap as above
+ */
+ public static void loadKeyBindings(InputMap retMap, Object[] keys)
+ {
+ if (keys == null)
+ return;
+ for (int i = 0; i < keys.length - 1; i += 2)
+ {
+ Object key = keys[i];
+ KeyStroke keyStroke;
+ if (key instanceof KeyStroke)
+ keyStroke = (KeyStroke) key;
+ else
+ keyStroke = KeyStroke.getKeyStroke((String) key);
+ retMap.put(keyStroke, keys[i + 1]);
+ }
+ }
+
+ /**
+ * Creates a ComponentInputMap from keys.
+ * <code>keys</code> describes the InputMap, every even indexed
+ * item is either a KeyStroke or a String representing a KeyStroke and every
+ * odd indexed item is the Object associated with that KeyStroke in an
+ * ActionMap.
+ *
+ * @param c the JComponent associated with the ComponentInputMap
+ * @param keys the Object array describing the InputMap as above
+ *
+ * @return A new input map.
+ */
+ public static ComponentInputMap makeComponentInputMap(JComponent c,
+ Object[] keys)
+ {
+ ComponentInputMap retMap = new ComponentInputMapUIResource(c);
+ loadKeyBindings(retMap, keys);
+ return retMap;
+ }
+
+ /**
+ * Utility method that creates a UIDefaults.LazyValue that creates an
+ * ImageIcon UIResource for the specified gifFile filename.
+ *
+ * @param baseClass the base class for accessing the icon resource.
+ * @param gifFile the file name.
+ *
+ * @return A {@link UIDefaults.LazyValue} that serves up an
+ * {@link IconUIResource}.
+ */
+ public static Object makeIcon(Class baseClass, String gifFile)
+ {
+ final URL file = baseClass.getResource(gifFile);
+ return new UIDefaults.LazyValue()
+ {
+ public Object createValue(UIDefaults table)
+ {
+ return new IconUIResource(new ImageIcon(file));
+ }
+ };
+ }
+
+ /**
+ * Creates a InputMap from keys.
+ * <code>keys</code> describes the InputMap, every even indexed
+ * item is either a KeyStroke or a String representing a KeyStroke and every
+ * odd indexed item is the Object associated with that KeyStroke in an
+ * ActionMap.
+ *
+ * @param keys the Object array describing the InputMap as above
+ *
+ * @return A new input map.
+ */
+ public static InputMap makeInputMap(Object[] keys)
+ {
+ InputMap retMap = new InputMapUIResource();
+ loadKeyBindings(retMap, keys);
+ return retMap;
+ }
+
+ /**
+ * Convenience method for building lists of KeyBindings.
+ * <code>keyBindingList</code> is an array of KeyStroke-Action pairs where
+ * even indexed elements are KeyStrokes or Strings representing KeyStrokes
+ * and odd indexed elements are the associated Actions.
+ *
+ * @param keyBindingList the array of KeyStroke-Action pairs
+ * @return a JTextComponent.KeyBinding array
+ */
+ public static JTextComponent.KeyBinding[] makeKeyBindings(
+ Object[] keyBindingList)
+ {
+ JTextComponent.KeyBinding[] retBindings =
+ new JTextComponent.KeyBinding[keyBindingList.length / 2];
+ for (int i = 0; i < keyBindingList.length - 1; i += 2)
+ {
+ KeyStroke stroke;
+ if (keyBindingList[i] instanceof KeyStroke)
+ stroke = (KeyStroke) keyBindingList[i];
+ else
+ stroke = KeyStroke.getKeyStroke((String) keyBindingList[i]);
+ retBindings[i / 2] = new JTextComponent.KeyBinding(stroke,
+ (String) keyBindingList[i + 1]);
+ }
+ return retBindings;
+ }
+
+ /**
+ * Invoked when the user attempts an invalid operation. The default
+ * implementation just beeps. Subclasses that wish to change this need to
+ * override this method.
+ *
+ * @param component the component the error occured in
+ */
+ public void provideErrorFeedback(Component component)
+ {
+ Toolkit.getDefaultToolkit().beep();
+ }
+
+ /**
+ * Returns a string that displays and identifies this object's properties.
+ *
+ * @return string containing the description and class name.
+ */
+ public String toString()
+ {
+ return getDescription() + " " + getClass().getName();
+ }
+
+ /**
+ * UIManager.setLookAndFeel calls this method just before we're replaced by
+ * a new default look and feel.
+ */
+ public void uninitialize()
+ {
+ // We do nothing here. This method is meant to be overridden by
+ // LookAndFeel implementations.
+ }
+
+ /**
+ * Convenience method for un-installing a component's default border on the
+ * specified component if the border is currently an instance of UIResource.
+ *
+ * @param c the component (<code>null</code> not permitted).
+ */
+ public static void uninstallBorder(JComponent c)
+ {
+ if (c.getBorder() instanceof UIResource)
+ c.setBorder(null);
+ }
+
+ /**
+ * This methods installs a UI property if it hasn't already been set by an
+ * application. This method is used by UI delegates that install a default
+ * value for a property with a primitive type but do not want to override
+ * a value that has been set by an application.
+ *
+ * The supported properties depend on the actual type of the component and
+ * are listed in the table below. The supported properties are of course
+ * inherited to subclasses.
+ *
+ * <table>
+ * <tr><th>Type</th><th>Supported properties</th></tr>
+ * <tr><td><code>JComponent</code></td>
+ * <td><code>opaque, autoscrolls</code></td></tr>
+ * <tr><td><code>AbstractButton</code></td>
+ * <td><code>borderPainted, rolloverEnabled, iconTextGap,
+ * contentAreaFilled</code></td></tr>
+ * <tr><td><code>JDesktopPane</code></td>
+ * <td><code>dragMode</code></td></tr>
+ * <tr><td><code>JSplitPane</code></td>
+ * <td><code>dividerSize, oneTouchExpandable</code></td></tr>
+ * <tr><td><code>JTable</code></td>
+ * <td><code>rowHeight</code></td></tr>
+ * <tr><td><code>JTree</code></td>
+ * <td><code>rowHeight, scrollsOnExpand, showsRootHandles</code></td></tr>
+ * </table>
+ *
+ * @param c the component to install the property to
+ * @param propertyName the name of the property
+ * @param value the value of the property
+ *
+ * @throws IllegalArgumentException if the specified property cannot be set
+ * by this method
+ * @throws ClassCastException if the property value does not match the
+ * property type
+ * @throws NullPointerException if <code>c</code> or
+ * <code>propertyValue</code> is <code>null</code>
+ *
+ * @since 1.5
+ */
+ public static void installProperty(JComponent c, String propertyName,
+ Object value)
+ {
+ c.setUIProperty(propertyName, value);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/MenuElement.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/MenuElement.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/MenuElement.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/MenuElement.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,89 @@
+/* MenuElement.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import java.awt.Component;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+
+/**
+ * Defines the methods that any menu element in a {@link JMenu} must
+ * implement.
+ *
+ * @author Andrew Selkirk
+ */
+public interface MenuElement
+{
+
+ /**
+ * processMouseEvent
+ * @param event TODO
+ * @param path TODO
+ * @param manager TODO
+ */
+ void processMouseEvent(MouseEvent event, MenuElement[] path,
+ MenuSelectionManager manager);
+
+ /**
+ * processKeyEvent
+ * @param event TODO
+ * @param path TODO
+ * @param manager TODO
+ */
+ void processKeyEvent(KeyEvent event, MenuElement[] path,
+ MenuSelectionManager manager);
+
+ /**
+ * menuSelectionChanged
+ * @param included TODO
+ */
+ void menuSelectionChanged(boolean included);
+
+ /**
+ * getSubElements
+ * @returns MenuElement[]
+ */
+ MenuElement[] getSubElements();
+
+ /**
+ * getComponent
+ * @returns Component
+ */
+ Component getComponent();
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/MenuSelectionManager.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/MenuSelectionManager.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/MenuSelectionManager.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/MenuSelectionManager.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,440 @@
+/* MenuSelectionManager.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Point;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.Vector;
+
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.EventListenerList;
+
+/**
+ * This class manages current menu selectection. It provides
+ * methods to clear and set current selected menu path.
+ * It also fires StateChange event to its registered
+ * listeners whenever selected path of the current menu hierarchy
+ * changes.
+ *
+ */
+public class MenuSelectionManager
+{
+ /** ChangeEvent fired when selected path changes*/
+ protected ChangeEvent changeEvent = new ChangeEvent(this);
+
+ /** List of listeners for this MenuSelectionManager */
+ protected EventListenerList listenerList = new EventListenerList();
+
+ /** Default manager for the current menu hierarchy*/
+ private static final MenuSelectionManager manager = new MenuSelectionManager();
+
+ /** Path to the currently selected menu */
+ private Vector selectedPath = new Vector();
+
+ /**
+ * Fires StateChange event to registered listeners
+ */
+ protected void fireStateChanged()
+ {
+ ChangeListener[] listeners = getChangeListeners();
+
+ for (int i = 0; i < listeners.length; i++)
+ listeners[i].stateChanged(changeEvent);
+ }
+
+ /**
+ * Adds ChangeListener to this MenuSelectionManager
+ *
+ * @param listener ChangeListener to add
+ */
+ public void addChangeListener(ChangeListener listener)
+ {
+ listenerList.add(ChangeListener.class, listener);
+ }
+
+ /**
+ * Removes ChangeListener from the list of registered listeners
+ * for this MenuSelectionManager.
+ *
+ * @param listener ChangeListner to remove
+ */
+ public void removeChangeListener(ChangeListener listener)
+ {
+ listenerList.remove(ChangeListener.class, listener);
+ }
+
+ /**
+ * Returns list of registered listeners with MenuSelectionManager
+ *
+ * @since 1.4
+ */
+ public ChangeListener[] getChangeListeners()
+ {
+ return (ChangeListener[]) listenerList.getListeners(ChangeListener.class);
+ }
+
+ /**
+ * Unselects all the menu elements on the selection path
+ */
+ public void clearSelectedPath()
+ {
+ // Send events from the bottom most item in the menu - hierarchy to the
+ // top most
+ for (int i = selectedPath.size() - 1; i >= 0; i--)
+ ((MenuElement) selectedPath.get(i)).menuSelectionChanged(false);
+
+ // clear selected path
+ selectedPath.clear();
+
+ // notify all listeners that the selected path was changed
+ fireStateChanged();
+ }
+
+ /**
+ * This method returns menu element on the selected path that contains
+ * given source point. If no menu element on the selected path contains this
+ * point, then null is returned.
+ *
+ * @param source Component relative to which sourcePoint is given
+ * @param sourcePoint point for which we want to find menu element that contains it
+ *
+ * @return Returns menu element that contains given source point and belongs
+ * to the currently selected path. Null is return if no such menu element found.
+ */
+ public Component componentForPoint(Component source, Point sourcePoint)
+ {
+ // Convert sourcePoint to screen coordinates.
+ Point sourcePointOnScreen = sourcePoint;
+
+ if (source.isShowing())
+ SwingUtilities.convertPointToScreen(sourcePointOnScreen, source);
+
+ Point compPointOnScreen;
+ Component resultComp = null;
+
+ // For each menu element on the selected path, express its location
+ // in terms of screen coordinates and check if there is any
+ // menu element on the selected path that contains given source point.
+ for (int i = 0; i < selectedPath.size(); i++)
+ {
+ Component comp = ((Component) selectedPath.get(i));
+ Dimension size = comp.getSize();
+
+ // convert location of this menu item to screen coordinates
+ compPointOnScreen = comp.getLocationOnScreen();
+
+ if (compPointOnScreen.x <= sourcePointOnScreen.x
+ && sourcePointOnScreen.x < compPointOnScreen.x + size.width
+ && compPointOnScreen.y <= sourcePointOnScreen.y
+ && sourcePointOnScreen.y < compPointOnScreen.y + size.height)
+ {
+ Point p = sourcePointOnScreen;
+
+ if (comp.isShowing())
+ SwingUtilities.convertPointFromScreen(p, comp);
+
+ resultComp = SwingUtilities.getDeepestComponentAt(comp, p.x, p.y);
+ break;
+ }
+ }
+ return resultComp;
+ }
+
+ /**
+ * Returns shared instance of MenuSelection Manager
+ *
+ * @return default Manager
+ */
+ public static MenuSelectionManager defaultManager()
+ {
+ return manager;
+ }
+
+ /**
+ * Returns path representing current menu selection
+ *
+ * @return Current selection path
+ */
+ public MenuElement[] getSelectedPath()
+ {
+ MenuElement[] path = new MenuElement[selectedPath.size()];
+
+ for (int i = 0; i < path.length; i++)
+ path[i] = (MenuElement) selectedPath.get(i);
+
+ return path;
+ }
+
+ /**
+ * Returns true if specified component is part of current menu
+ * heirarchy and false otherwise
+ *
+ * @param c Component for which to check
+ * @return True if specified component is part of current menu
+ */
+ public boolean isComponentPartOfCurrentMenu(Component c)
+ {
+ MenuElement[] subElements;
+ boolean ret = false;
+ for (int i = 0; i < selectedPath.size(); i++)
+ {
+ // Check first element.
+ MenuElement first = (MenuElement) selectedPath.get(i);
+ if (SwingUtilities.isDescendingFrom(c, first.getComponent()))
+ {
+ ret = true;
+ break;
+ }
+ else
+ {
+ // Check sub elements.
+ subElements = first.getSubElements();
+ for (int j = 0; j < subElements.length; j++)
+ {
+ MenuElement me = subElements[j];
+ if (me != null
+ && (SwingUtilities.isDescendingFrom(c, me.getComponent())))
+ {
+ ret = true;
+ break;
+ }
+ }
+ }
+ }
+
+ return ret;
+ }
+
+ /**
+ * Processes key events on behalf of the MenuElements. MenuElement
+ * instances should always forward their key events to this method and
+ * get their {@link MenuElement#processKeyEvent(KeyEvent, MenuElement[],
+ * MenuSelectionManager)} eventually called back.
+ *
+ * @param e the key event
+ */
+ public void processKeyEvent(KeyEvent e)
+ {
+ MenuElement[] selection = (MenuElement[])
+ selectedPath.toArray(new MenuElement[selectedPath.size()]);
+ if (selection.length == 0)
+ return;
+
+ MenuElement[] path;
+ for (int index = selection.length - 1; index >= 0; index--)
+ {
+ MenuElement el = selection[index];
+ // This method's main purpose is to forward key events to the
+ // relevant menu items, so that they can act in response to their
+ // mnemonics beeing typed. So we also need to forward the key event
+ // to all the subelements of the currently selected menu elements
+ // in the path.
+ MenuElement[] subEls = el.getSubElements();
+ path = null;
+ for (int subIndex = 0; subIndex < subEls.length; subIndex++)
+ {
+ MenuElement sub = subEls[subIndex];
+ // Skip elements that are not showing or not enabled.
+ if (sub == null || ! sub.getComponent().isShowing()
+ || ! sub.getComponent().isEnabled())
+ {
+ continue;
+ }
+
+ if (path == null)
+ {
+ path = new MenuElement[index + 2];
+ System.arraycopy(selection, 0, path, 0, index + 1);
+ }
+ path[index + 1] = sub;
+ sub.processKeyEvent(e, path, this);
+ if (e.isConsumed())
+ break;
+ }
+ if (e.isConsumed())
+ break;
+ }
+
+ // Dispatch to first element in selection if it hasn't been consumed.
+ if (! e.isConsumed())
+ {
+ path = new MenuElement[1];
+ path[0] = selection[0];
+ path[0].processKeyEvent(e, path, this);
+ }
+ }
+
+ /**
+ * Forwards given mouse event to all of the source subcomponents.
+ *
+ * @param event Mouse event
+ */
+ public void processMouseEvent(MouseEvent event)
+ {
+ Component source = ((Component) event.getSource());
+
+ // In the case of drag event, event.getSource() returns component
+ // where drag event originated. However menu element processing this
+ // event should be the one over which mouse is currently located,
+ // which is not necessary the source of the drag event.
+ Component mouseOverMenuComp;
+
+ // find over which menu element the mouse is currently located
+ if (event.getID() == MouseEvent.MOUSE_DRAGGED
+ || event.getID() == MouseEvent.MOUSE_RELEASED)
+ mouseOverMenuComp = componentForPoint(source, event.getPoint());
+ else
+ mouseOverMenuComp = source;
+
+ // Process this event only if mouse is located over some menu element
+ if (mouseOverMenuComp != null && (mouseOverMenuComp instanceof MenuElement))
+ {
+ MenuElement[] path = getPath(mouseOverMenuComp);
+ ((MenuElement) mouseOverMenuComp).processMouseEvent(event, path,
+ manager);
+
+ // FIXME: Java specification says that mouse events should be
+ // forwarded to subcomponents. The code below does it, but
+ // menu's work fine without it. This code is commented for now.
+
+ /*
+ MenuElement[] subComponents = ((MenuElement) mouseOverMenuComp)
+ .getSubElements();
+
+ for (int i = 0; i < subComponents.length; i++)
+ {
+ subComponents[i].processMouseEvent(event, path, manager);
+ }
+ */
+ }
+ else
+ {
+ if (event.getID() == MouseEvent.MOUSE_RELEASED)
+ clearSelectedPath();
+ }
+ }
+
+ /**
+ * Sets menu selection to the specified path
+ *
+ * @param path new selection path
+ */
+ public void setSelectedPath(MenuElement[] path)
+ {
+ if (path == null)
+ {
+ clearSelectedPath();
+ return;
+ }
+
+ int minSize = path.length; // size of the smaller path.
+ int currentSize = selectedPath.size();
+ int firstDiff = 0;
+
+ // Search first item that is different in the current and new path.
+ for (int i = 0; i < minSize; i++)
+ {
+ if (i < currentSize && (MenuElement) selectedPath.get(i) == path[i])
+ firstDiff++;
+ else
+ break;
+ }
+
+ // Remove items from selection and send notification.
+ for (int i = currentSize - 1; i >= firstDiff; i--)
+ {
+ MenuElement el = (MenuElement) selectedPath.get(i);
+ selectedPath.remove(i);
+ el.menuSelectionChanged(false);
+ }
+
+ // Add new items to selection and send notification.
+ for (int i = firstDiff; i < minSize; i++)
+ {
+ if (path[i] != null)
+ {
+ selectedPath.add(path[i]);
+ path[i].menuSelectionChanged(true);
+ }
+ }
+
+ fireStateChanged();
+ }
+
+ /**
+ * Returns path to the specified component
+ *
+ * @param c component for which to find path for
+ *
+ * @return path to the specified component
+ */
+ private MenuElement[] getPath(Component c)
+ {
+ // FIXME: There is the same method in BasicMenuItemUI. However I
+ // cannot use it here instead of this method, since I cannot assume that
+ // all the menu elements on the selected path are JMenuItem or JMenu.
+ // For now I've just duplicated it here. Please
+ // fix me or delete me if another better approach will be found, and
+ // this method will not be necessary.
+ ArrayList path = new ArrayList();
+
+ // if given component is JMenu, we also need to include
+ // it's popup menu in the path
+ if (c instanceof JMenu)
+ path.add(((JMenu) c).getPopupMenu());
+ while (c instanceof MenuElement)
+ {
+ path.add(0, (MenuElement) c);
+
+ if (c instanceof JPopupMenu)
+ c = ((JPopupMenu) c).getInvoker();
+ else
+ c = c.getParent();
+ }
+
+ MenuElement[] pathArray = new MenuElement[path.size()];
+ path.toArray(pathArray);
+ return pathArray;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/MutableComboBoxModel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/MutableComboBoxModel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/MutableComboBoxModel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/MutableComboBoxModel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,82 @@
+/* MutableComboBoxModel.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+/**
+ * A data model used in {@link JComboBox}es that keeps track of the
+ * components data and provides methods to insert and remove elements from
+ * it. The classes implementing this interface should
+ * fire appropriate events indicating the undergoing change in the data model.
+ *
+ * @author Andrew Selkirk
+ * @author Olga Rodimina
+ */
+public interface MutableComboBoxModel extends ComboBoxModel
+{
+ /**
+ * This method adds given object to its data model.
+ *
+ * @param object element to add to the data model.
+ */
+ void addElement(Object object);
+
+ /**
+ * This method removes elements located at the given index in the data
+ * model.
+ *
+ * @param index index specifying location of the element to remove.
+ */
+ void removeElementAt(int index);
+
+ /**
+ * This method inserts givent element to the data model, at the specified
+ * index.
+ *
+ * @param object element to insert
+ * @param index index specifying the position in the data model where the
+ * given element should be inserted.
+ */
+ void insertElementAt(Object object, int index);
+
+ /**
+ * This method removes given element from the data model
+ *
+ * @param object element to remove.
+ */
+ void removeElement(Object object);
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/OverlayLayout.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/OverlayLayout.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/OverlayLayout.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/OverlayLayout.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,412 @@
+/* OverlayLayout.java -- A layout manager
+ Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import java.awt.AWTError;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Insets;
+import java.awt.LayoutManager2;
+import java.io.Serializable;
+
+/**
+ * A layout manager that lays out the components of a container one over
+ * another.
+ *
+ * The components take as much space as is available in the container, but not
+ * more than specified by their maximum size.
+ *
+ * The overall layout is mainly affected by the components
+ * <code>alignmentX</code> and <code>alignmentY</code> properties. All
+ * components are aligned, so that their alignment points (for either
+ * direction) are placed in one line (the baseline for this direction).
+ *
+ * For example: An X alignment of 0.0 means that the component's alignment
+ * point is at it's left edge, an X alignment of 0.5 means that the alignment
+ * point is in the middle, an X alignment of 1.0 means, the aligment point is
+ * at the right edge. So if you have three components, the first with 0.0, the
+ * second with 0.5 and the third with 1.0, then they are laid out like this:
+ *
+ * <pre>
+ * +-------+
+ * | 1 |
+ * +-------+
+ * +-------+
+ * | 2 |
+ * +-------+
+ * +---------+
+ * | 3 +
+ * +---------+
+ * </pre>
+ * The above picture shows the X alignment between the components. An Y
+ * alignment like shown above cannot be achieved with this layout manager. The
+ * components are place on top of each other, with the X alignment shown above.
+ *
+ * @author Roman Kennke (kennke at aicas.com)
+ * @author Andrew Selkirk
+ */
+public class OverlayLayout implements LayoutManager2, Serializable
+{
+ private static final long serialVersionUID = 18082829169631543L;
+
+ /**
+ * The container to be laid out.
+ */
+ private Container target;
+
+ /**
+ * The size requirements of the containers children for the X direction.
+ */
+ private SizeRequirements[] xChildren;
+
+ /**
+ * The size requirements of the containers children for the Y direction.
+ */
+ private SizeRequirements[] yChildren;
+
+ /**
+ * The size requirements of the container to be laid out for the X direction.
+ */
+ private SizeRequirements xTotal;
+
+ /**
+ * The size requirements of the container to be laid out for the Y direction.
+ */
+ private SizeRequirements yTotal;
+
+ /**
+ * The offsets of the child components in the X direction.
+ */
+ private int[] offsetsX;
+
+ /**
+ * The offsets of the child components in the Y direction.
+ */
+ private int[] offsetsY;
+
+ /**
+ * The spans of the child components in the X direction.
+ */
+ private int[] spansX;
+
+ /**
+ * The spans of the child components in the Y direction.
+ */
+ private int[] spansY;
+
+ /**
+ * Creates a new OverlayLayout for the specified container.
+ *
+ * @param target the container to be laid out
+ */
+ public OverlayLayout(Container target)
+ {
+ this.target = target;
+ }
+
+ /**
+ * Notifies the layout manager that the layout has become invalid. It throws
+ * away cached layout information and recomputes it the next time it is
+ * requested.
+ *
+ * @param target not used here
+ */
+ public void invalidateLayout(Container target)
+ {
+ xChildren = null;
+ yChildren = null;
+ xTotal = null;
+ yTotal = null;
+ offsetsX = null;
+ offsetsY = null;
+ spansX = null;
+ spansY = null;
+ }
+
+ /**
+ * This method is not used in this layout manager.
+ *
+ * @param string not used here
+ * @param component not used here
+ */
+ public void addLayoutComponent(String string, Component component)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * This method is not used in this layout manager.
+ *
+ * @param component not used here
+ * @param constraints not used here
+ */
+ public void addLayoutComponent(Component component, Object constraints)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * This method is not used in this layout manager.
+ *
+ * @param component not used here
+ */
+ public void removeLayoutComponent(Component component)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Returns the preferred size of the container that is laid out. This is
+ * computed by the children's preferred sizes, taking their alignments into
+ * account.
+ *
+ * @param target not used here
+ *
+ * @return the preferred size of the container that is laid out
+ */
+ public Dimension preferredLayoutSize(Container target)
+ {
+ if (target != this.target)
+ throw new AWTError("OverlayLayout can't be shared");
+
+ checkTotalRequirements();
+ return new Dimension(xTotal.preferred, yTotal.preferred);
+ }
+
+ /**
+ * Returns the minimum size of the container that is laid out. This is
+ * computed by the children's minimum sizes, taking their alignments into
+ * account.
+ *
+ * @param target not used here
+ *
+ * @return the minimum size of the container that is laid out
+ */
+ public Dimension minimumLayoutSize(Container target)
+ {
+ if (target != this.target)
+ throw new AWTError("OverlayLayout can't be shared");
+
+ checkTotalRequirements();
+ return new Dimension(xTotal.minimum, yTotal.minimum);
+ }
+
+ /**
+ * Returns the maximum size of the container that is laid out. This is
+ * computed by the children's maximum sizes, taking their alignments into
+ * account.
+ *
+ * @param target not used here
+ *
+ * @return the maximum size of the container that is laid out
+ */
+ public Dimension maximumLayoutSize(Container target)
+ {
+ if (target != this.target)
+ throw new AWTError("OverlayLayout can't be shared");
+
+ checkTotalRequirements();
+ return new Dimension(xTotal.maximum, yTotal.maximum);
+ }
+
+ /**
+ * Returns the X alignment of the container that is laid out. This is
+ * computed by the children's preferred sizes, taking their alignments into
+ * account.
+ *
+ * @param target not used here
+ *
+ * @return the X alignment of the container that is laid out
+ */
+ public float getLayoutAlignmentX(Container target)
+ {
+ if (target != this.target)
+ throw new AWTError("OverlayLayout can't be shared");
+
+ checkTotalRequirements();
+ return xTotal.alignment;
+ }
+
+ /**
+ * Returns the Y alignment of the container that is laid out. This is
+ * computed by the children's preferred sizes, taking their alignments into
+ * account.
+ *
+ * @param target not used here
+ *
+ * @return the X alignment of the container that is laid out
+ */
+ public float getLayoutAlignmentY(Container target)
+ {
+ if (target != this.target)
+ throw new AWTError("OverlayLayout can't be shared");
+
+ checkTotalRequirements();
+ return yTotal.alignment;
+ }
+
+ /**
+ * Lays out the container and it's children.
+ *
+ * The children are laid out one over another.
+ *
+ * The components take as much space as is available in the container, but
+ * not more than specified by their maximum size.
+ *
+ * The overall layout is mainly affected by the components
+ * <code>alignmentX</code> and <code>alignmentY</code> properties. All
+ * components are aligned, so that their alignment points (for either
+ * direction) are placed in one line (the baseline for this direction).
+ *
+ * For example: An X alignment of 0.0 means that the component's alignment
+ * point is at it's left edge, an X alignment of 0.5 means that the alignment
+ * point is in the middle, an X alignment of 1.0 means, the aligment point is
+ * at the right edge. So if you have three components, the first with 0.0,
+ * the second with 0.5 and the third with 1.0, then they are laid out like
+ * this:
+ *
+ * <pre>
+ * +-------+
+ * | 1 |
+ * +-------+
+ * +-------+
+ * | 2 |
+ * +-------+
+ * +---------+
+ * | 3 +
+ * +---------+
+ * </pre>
+ * The above picture shows the X alignment between the components. An Y
+ * alignment like shown above cannot be achieved with this layout manager.
+ * The components are place on top of each other, with the X alignment shown
+ * above.
+ *
+ * @param target not used here
+ */
+ public void layoutContainer(Container target)
+ {
+ if (target != this.target)
+ throw new AWTError("OverlayLayout can't be shared");
+
+ checkLayout();
+ Component[] children = target.getComponents();
+ for (int i = 0; i < children.length; i++)
+ children[i].setBounds(offsetsX[i], offsetsY[i], spansX[i], spansY[i]);
+ }
+
+ /**
+ * Makes sure that the xChildren and yChildren fields are correctly set up.
+ * A call to {@link #invalidateLayout(Container)} sets these fields to null,
+ * so they have to be set up again.
+ */
+ private void checkRequirements()
+ {
+ if (xChildren == null || yChildren == null)
+ {
+ Component[] children = target.getComponents();
+ xChildren = new SizeRequirements[children.length];
+ yChildren = new SizeRequirements[children.length];
+ for (int i = 0; i < children.length; i++)
+ {
+ if (! children[i].isVisible())
+ {
+ xChildren[i] = new SizeRequirements();
+ yChildren[i] = new SizeRequirements();
+ }
+ else
+ {
+ xChildren[i] =
+ new SizeRequirements(children[i].getMinimumSize().width,
+ children[i].getPreferredSize().width,
+ children[i].getMaximumSize().width,
+ children[i].getAlignmentX());
+ yChildren[i] =
+ new SizeRequirements(children[i].getMinimumSize().height,
+ children[i].getPreferredSize().height,
+ children[i].getMaximumSize().height,
+ children[i].getAlignmentY());
+ }
+ }
+ }
+ }
+
+ /**
+ * Makes sure that the xTotal and yTotal fields are set up correctly. A call
+ * to {@link #invalidateLayout} sets these fields to null and they have to be
+ * recomputed.
+ */
+ private void checkTotalRequirements()
+ {
+ if (xTotal == null || yTotal == null)
+ {
+ checkRequirements();
+ xTotal = SizeRequirements.getAlignedSizeRequirements(xChildren);
+ yTotal = SizeRequirements.getAlignedSizeRequirements(yChildren);
+ }
+ }
+
+ /**
+ * Makes sure that the offsetsX, offsetsY, spansX and spansY fields are set
+ * up correctly. A call to {@link #invalidateLayout} sets these fields
+ * to null and they have to be recomputed.
+ */
+ private void checkLayout()
+ {
+ if (offsetsX == null || offsetsY == null || spansX == null
+ || spansY == null)
+ {
+ checkRequirements();
+ checkTotalRequirements();
+ int len = target.getComponents().length;
+ offsetsX = new int[len];
+ offsetsY = new int[len];
+ spansX = new int[len];
+ spansY = new int[len];
+
+ Insets in = target.getInsets();
+ int width = target.getWidth() - in.left - in.right;
+ int height = target.getHeight() - in.top - in.bottom;
+
+ SizeRequirements.calculateAlignedPositions(width, xTotal,
+ xChildren, offsetsX, spansX);
+ SizeRequirements.calculateAlignedPositions(height, yTotal,
+ yChildren, offsetsY, spansY);
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Popup.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Popup.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Popup.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Popup.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,301 @@
+/* Popup.java --
+ Copyright (C) 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.awt.Component;
+import java.awt.FlowLayout;
+import java.awt.Point;
+import java.awt.Rectangle;
+
+
+/**
+ * Manages a popup window that displays a Component on top of
+ * everything else.
+ *
+ * <p>To obtain an instance of <code>Popup</code>, use the
+ * {@link javax.swing.PopupFactory}.
+ *
+ * @since 1.4
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class Popup
+{
+ /**
+ * Constructs a new <code>Popup</code> given its owner,
+ * contents and the screen position where the popup
+ * will appear.
+ *
+ * @param owner the Component to which <code>x</code> and
+ * <code>y</code> are relative, or <code>null</code> for
+ * placing the popup relative to the origin of the screen.
+ *
+ * @param contents the contents that will be displayed inside
+ * the <code>Popup</code>.
+ *
+ * @param x the horizontal position where the Popup will appear.
+ *
+ * @param y the vertical position where the Popup will appear.
+ *
+ * @throws IllegalArgumentException if <code>contents</code>
+ * is <code>null</code>.
+ */
+ protected Popup(Component owner, Component contents,
+ int x, int y)
+ {
+ if (contents == null)
+ throw new IllegalArgumentException();
+
+ // The real stuff happens in the implementation of subclasses,
+ // for instance JWindowPopup.
+ }
+
+
+ /**
+ * Constructs a new <code>Popup</code>.
+ */
+ protected Popup()
+ {
+ // Nothing to do here.
+ }
+
+
+ /**
+ * Displays the <code>Popup</code> on the screen. Nothing happens
+ * if it is currently shown.
+ */
+ public void show()
+ {
+ // Implemented by subclasses, for instance JWindowPopup.
+ }
+
+
+ /**
+ * Removes the <code>Popup</code> from the screen. Nothing happens
+ * if it is currently hidden.
+ */
+ public void hide()
+ {
+ // Implemented by subclasses, for instance JWindowPopup.
+ }
+
+
+ /**
+ * A <code>Popup</code> that uses a <code>JWindow</code> for
+ * displaying its contents.
+ *
+ * @see PopupFactory#getPopup
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+ static class JWindowPopup
+ extends Popup
+ {
+ /**
+ * The <code>JWindow</code> used for displaying the contents
+ * of the popup.
+ */
+ JWindow window;
+
+ private Component contents;
+
+ /**
+ * Constructs a new <code>JWindowPopup</code> given its owner,
+ * contents and the screen position where the popup
+ * will appear.
+ *
+ * @param owner the Component to which <code>x</code> and
+ * <code>y</code> are relative, or <code>null</code> for
+ * placing the popup relative to the origin of the screen.
+ *
+ * @param contents the contents that will be displayed inside
+ * the <code>Popup</code>.
+ *
+ * @param x the horizontal position where the Popup will appear.
+ *
+ * @param y the vertical position where the Popup will appear.
+ *
+ * @throws IllegalArgumentException if <code>contents</code>
+ * is <code>null</code>.
+ */
+ public JWindowPopup(Component owner, Component contents,
+ int x, int y)
+ {
+ /* Checks whether contents is null. */
+ super(owner, contents, x, y);
+
+ this.contents = contents;
+ window = new JWindow(SwingUtilities.getWindowAncestor(owner));
+ window.getContentPane().add(contents);
+ window.setLocation(x, y);
+ window.setFocusableWindowState(false);
+ }
+
+
+ /**
+ * Displays the popup's <code>JWindow</code> on the screen.
+ * Nothing happens if it is already visible.
+ */
+ public void show()
+ {
+ window.setSize(contents.getSize());
+ window.show();
+ }
+
+
+ /**
+ * Removes the popup's <code>JWindow</code> from the
+ * screen. Nothing happens if it is currently not visible.
+ */
+ public void hide()
+ {
+ /* Calling dispose() instead of hide() will conserve native
+ * system resources, for example memory in an X11 server.
+ * They will automatically be re-allocated by a call to
+ * show().
+ */
+ window.dispose();
+ }
+ }
+
+ /**
+ * A popup that displays itself within the JLayeredPane of a JRootPane of
+ * the containment hierarchy of the owner component.
+ *
+ * @author Roman Kennke (kennke at aicas.com)
+ */
+ static class LightweightPopup extends Popup
+ {
+ /**
+ * The owner component for this popup.
+ */
+ Component owner;
+
+ /**
+ * The contents that should be shown.
+ */
+ Component contents;
+
+ /**
+ * The X location in screen coordinates.
+ */
+ int x;
+
+ /**
+ * The Y location in screen coordinates.
+ */
+ int y;
+
+ /**
+ * The panel that holds the content.
+ */
+ private JPanel panel;
+
+ /**
+ * The layered pane of the owner.
+ */
+ private JLayeredPane layeredPane;
+
+ /**
+ * Constructs a new <code>LightweightPopup</code> given its owner,
+ * contents and the screen position where the popup
+ * will appear.
+ *
+ * @param owner the component that should own the popup window; this
+ * provides the JRootPane in which we place the popup window
+ *
+ * @param contents the contents that will be displayed inside
+ * the <code>Popup</code>.
+ *
+ * @param x the horizontal position where the Popup will appear in screen
+ * coordinates
+ *
+ * @param y the vertical position where the Popup will appear in screen
+ * coordinates
+ *
+ * @throws IllegalArgumentException if <code>contents</code>
+ * is <code>null</code>.
+ */
+ public LightweightPopup(Component owner, Component contents, int x, int y)
+ {
+ super(owner, contents, x, y);
+ this.owner = owner;
+ this.contents = contents;
+ this.x = x;
+ this.y = y;
+
+ JRootPane rootPane = SwingUtilities.getRootPane(owner);
+ JLayeredPane layeredPane = rootPane.getLayeredPane();
+ this.layeredPane = layeredPane;
+ }
+
+ /**
+ * Places the popup within the JLayeredPane of the owner component and
+ * makes it visible.
+ */
+ public void show()
+ {
+ // We insert a JPanel between the layered pane and the contents so we
+ // can fiddle with the setLocation() method without disturbing a
+ // JPopupMenu (which overrides setLocation in an unusual manner).
+ if (panel == null)
+ {
+ panel = new JPanel();
+ panel.setLayout(new FlowLayout(0, 0, 0));
+ }
+
+ panel.add(contents);
+ panel.setSize(contents.getSize());
+ Point layeredPaneLoc = layeredPane.getLocationOnScreen();
+ panel.setLocation(x - layeredPaneLoc.x, y - layeredPaneLoc.y);
+ layeredPane.add(panel, JLayeredPane.POPUP_LAYER);
+ panel.repaint();
+ }
+
+ /**
+ * Removes the popup from the JLayeredPane thus making it invisible.
+ */
+ public void hide()
+ {
+ Rectangle bounds = panel.getBounds();
+ layeredPane.remove(panel);
+ layeredPane.repaint(bounds.x, bounds.y, bounds.width, bounds.height);
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/PopupFactory.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/PopupFactory.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/PopupFactory.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/PopupFactory.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,171 @@
+/* PopupFactory.java --
+ Copyright (C) 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Point;
+
+
+/**
+ * A factory for <code>Popup</code> objects. These are used to
+ * managed little windows that float over everything else,
+ * typically containing a popup menu.
+ *
+ * @since 1.4
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class PopupFactory
+{
+ /**
+ * The shared factory object.
+ *
+ * @see #getSharedInstance
+ * @see #setSharedInstance
+ */
+ private static PopupFactory sharedFactory;
+
+
+ /**
+ * Constructs a new <code>PopupFactory</code>. Usually, a single
+ * <code>PopupFactory</code> is shared among multiple consumers
+ * of <code>Popup</code>. Use {@link #getSharedInstance} to retrieve
+ * the current factory.
+ */
+ public PopupFactory()
+ {
+ // Nothing to do here.
+ }
+
+
+ /**
+ * Sets the shared factory.
+ *
+ * @param factory the PopupFactory that future invocations of
+ * {@link #getSharedInstance} will return.
+ *
+ * @throws IllegalArgumentException if <code>factory</code>
+ * is <code>null</code>.
+ */
+ public static void setSharedInstance(PopupFactory factory)
+ {
+ if (factory == null)
+ throw new IllegalArgumentException();
+
+ /* Swing is not designed to be thread-safe, so there is no
+ * need to synchronize the access to the global variable.
+ */
+ sharedFactory = factory;
+ }
+
+
+ /**
+ * Retrieves the shared factory, creating a new factory if
+ * necessary.
+ *
+ * @return a <code>PopupFactory</code> that can be used
+ * to create <code>Popup</code> objects.
+ */
+ public static PopupFactory getSharedInstance()
+ {
+ /* Swing is not designed to be thread-safe, so there is no
+ * need to synchronize the access to the global variable.
+ */
+ if (sharedFactory == null)
+ sharedFactory = new PopupFactory();
+
+ return sharedFactory;
+ }
+
+
+ /**
+ * Creates a new <code>Popup</code> given its owner,
+ * contents and the screen position where the popup
+ * will appear.
+ *
+ * @param owner the Component to which <code>x</code> and
+ * <code>y</code> are relative, or <code>null</code> for
+ * placing the popup relative to the origin of the screen.
+ *
+ * @param contents the contents that will be displayed inside
+ * the <code>Popup</code>.
+ *
+ * @param x the horizontal position where the Popup will appear.
+ *
+ * @param y the vertical position where the Popup will appear.
+ *
+ * @throws IllegalArgumentException if <code>contents</code>
+ * is <code>null</code>.
+ */
+ public Popup getPopup(Component owner, Component contents,
+ int x, int y)
+ {
+ Popup popup = null;
+ // By default we enable lightweight popups since they are more efficient
+ // than heavyweight popups.
+ boolean lightweightEnabled = true;
+ // Special case JPopupMenu here, since it supports a lightweightEnabled
+ // flag that we must respect.
+ if (contents instanceof JPopupMenu)
+ {
+ JPopupMenu menu = (JPopupMenu) contents;
+ lightweightEnabled = menu.isLightWeightPopupEnabled();
+ }
+
+ // If we have a root pane and the contents fits within the root pane and
+ // lightweight popups are enabled, than we can use a lightweight popup.
+ JRootPane root = SwingUtilities.getRootPane(owner);
+ if (root != null)
+ {
+ Point rootLoc = root.getLocationOnScreen();
+ Dimension contentsSize = contents.getSize();
+ Dimension rootSize = root.getSize();
+ if (x >= rootLoc.x && y > rootLoc.y
+ && (x - rootLoc.x) + contentsSize.width < rootSize.width
+ && (y - rootLoc.y) + contentsSize.height < rootSize.height)
+ popup = new Popup.LightweightPopup(owner, contents, x, y);
+ else
+ popup = new Popup.JWindowPopup(owner, contents, x, y);
+ }
+ else
+ popup = new Popup.JWindowPopup(owner, contents, x, y);
+ return popup;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ProgressMonitor.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ProgressMonitor.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ProgressMonitor.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ProgressMonitor.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,460 @@
+/* ProgressMonitor.java --
+ Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.accessibility.AccessibleContext;
+
+/**
+ * <p>Using this class you can easily monitor tasks where you cannot
+ * estimate the duration exactly.</p>
+ *
+ * <p>A ProgressMonitor instance waits until the first time setProgress
+ * is called. When <code>millisToDecideToPopup</code> time elapsed the
+ * instance estimates the duration until the whole operation is completed.
+ * If this duration exceeds <code>millisToPopup</code> a non-modal dialog
+ * with a message and a progress bar is shown.</p>
+ *
+ * <p>The value of <code>millisToDecideToPopup</code> defaults to
+ * <code>500</code> and <code>millisToPopup</code> to
+ * <code>2000</code>.</p>
+ *
+ * @author Andrew Selkirk
+ * @author Robert Schuster (robertschuster at fsfe.org)
+ * @since 1.2
+ * @status updated to 1.2
+ */
+public class ProgressMonitor
+{
+
+ /**
+ * The accessible content for this component
+ */
+ protected AccessibleContext accessibleContext;
+
+ /**
+ * parentComponent
+ */
+ Component component;
+
+ /**
+ * note
+ */
+ String note;
+
+ /**
+ * message
+ */
+ Object message;
+
+ /**
+ * millisToDecideToPopup
+ */
+ int millisToDecideToPopup = 500;
+
+ /**
+ * millisToPopup
+ */
+ int millisToPopup = 2000;
+
+ int min, max, progress;
+
+ JProgressBar progressBar;
+
+ JLabel noteLabel;
+
+ JDialog progressDialog;
+
+ Timer timer;
+
+ boolean canceled;
+
+ /**
+ * Creates a new <code>ProgressMonitor</code> instance. This is used to
+ * monitor a task and pops up a dialog if the task is taking a long time to
+ * run.
+ *
+ * @param component The parent component of the progress dialog or
+ * <code>null</code>.
+ * @param message A constant message object which works in the way it does
+ * in {@link JOptionPane}.
+ * @param note A string message which can be changed while the operation goes
+ * on.
+ * @param minimum The minimum value for the operation (start value).
+ * @param maximum The maximum value for the operation (end value).
+ */
+ public ProgressMonitor(Component component, Object message,
+ String note, int minimum, int maximum)
+ {
+
+ // Set data.
+ this.component = component;
+ this.message = message;
+ this.note = note;
+
+ min = minimum;
+ max = maximum;
+ }
+
+ /**
+ * <p>Hides the dialog and stops any measurements.</p>
+ *
+ * <p>Has no effect when <code>setProgress</code> is not at least
+ * called once.</p>
+ */
+ public void close()
+ {
+ if (progressDialog != null)
+ {
+ progressDialog.setVisible(false);
+ }
+
+ if (timer != null)
+ {
+ timer.stop();
+ timer = null;
+ }
+ }
+
+ /**
+ * <p>Updates the progress value.</p>
+ *
+ * <p>When called for the first time this initializes a timer
+ * which decides after <code>millisToDecideToPopup</code> time
+ * whether to show a progress dialog or not.</p>
+ *
+ * <p>If the progress value equals or exceeds the maximum
+ * value the progress dialog is closed automatically.</p>
+ *
+ * @param progress New progress value.
+ */
+ public void setProgress(int progress)
+ {
+ this.progress = progress;
+
+ // Initializes and starts a timer with a task
+ // which measures the duration and displays
+ // a progress dialog if neccessary.
+ if (timer == null && progressDialog == null)
+ {
+ timer = new Timer(25, null);
+ timer.addActionListener(new TimerListener());
+ timer.start();
+ }
+
+ // Cancels timer and hides progress dialog if the
+ // maximum value is reached.
+ if (progressBar != null && this.progress >= progressBar.getMaximum())
+ {
+ // The reason for using progressBar.getMaximum() instead of max is that
+ // we want to prevent that changes to the value have any effect after the
+ // progress dialog is visible (This is how the JDK behaves.).
+ close();
+ }
+
+ }
+
+ /**
+ * Returns the minimum or start value of the operation.
+ *
+ * @return Minimum or start value of the operation.
+ */
+ public int getMinimum()
+ {
+ return min;
+ }
+
+ /**
+ * <p>Use this method to set the minimum or start value of
+ * your operation.</p>
+ *
+ * <p>For typical application like copy operation this will be
+ * zero.</p>
+ *
+ * <p>Keep in mind that changing this value after the progress
+ * dialog is made visible has no effect upon the progress bar.</p>
+ *
+ * @param minimum The new minimum value.
+ */
+ public void setMinimum(int minimum)
+ {
+ min = minimum;
+ }
+
+ /**
+ * Return the maximum or end value of your operation.
+ *
+ * @return Maximum or end value.
+ */
+ public int getMaximum()
+ {
+ return max;
+ }
+
+ /**
+ * <p>Sets the maximum or end value of the operation to the
+ * given integer.</p>
+ *
+ * @param maximum
+ */
+ public void setMaximum(int maximum)
+ {
+ max = maximum;
+ }
+
+ /**
+ * Returns whether the user canceled the operation.
+ *
+ * @return Whether the operation was canceled.
+ */
+ public boolean isCanceled()
+ {
+ // The value is predefined to false
+ // and changes only when the user clicks
+ // the cancel button in the progress dialog.
+ return canceled;
+ }
+
+ /**
+ * Returns the amount of milliseconds to wait
+ * until the ProgressMonitor should decide whether
+ * a progress dialog is to be shown or not.
+ *
+ * @return The duration in milliseconds.
+ */
+ public int getMillisToDecideToPopup()
+ {
+ return millisToDecideToPopup;
+ }
+
+ /**
+ * Sets the amount of milliseconds to wait until the
+ * ProgressMonitor should decide whether a progress dialog
+ * is to be shown or not.
+ *
+ * <p>This method has no effect when the progress dialog
+ * is already visible.</p>
+ *
+ * @param time The duration in milliseconds.
+ */
+ public void setMillisToDecideToPopup(int time)
+ {
+ millisToDecideToPopup = time;
+ }
+
+ /**
+ * Returns the number of milliseconds to wait before displaying the progress
+ * dialog. The default value is 2000.
+ *
+ * @return The number of milliseconds.
+ *
+ * @see #setMillisToPopup(int)
+ */
+ public int getMillisToPopup()
+ {
+ return millisToPopup;
+ }
+
+ /**
+ * Sets the number of milliseconds to wait before displaying the progress
+ * dialog.
+ *
+ * @param time the number of milliseconds.
+ *
+ * @see #getMillisToPopup()
+ */
+ public void setMillisToPopup(int time)
+ {
+ millisToPopup = time;
+ }
+
+ /**
+ * Returns a message which is shown in the progress dialog.
+ *
+ * @return The changeable message visible in the progress dialog.
+ */
+ public String getNote()
+ {
+ return note;
+ }
+
+ /**
+ * <p>Set the message shown in the progess dialog.</p>
+ *
+ * <p>Changing the note while the progress dialog is visible
+ * is possible.</p>
+ *
+ * @param note A message shown in the progress dialog.
+ */
+ public void setNote(String note)
+ {
+ if (noteLabel != null)
+ {
+ noteLabel.setText(note);
+ }
+ else
+ {
+ this.note = note;
+ }
+ }
+
+ /**
+ * Internal method that creates the progress dialog.
+ */
+ void createDialog()
+ {
+ // If there is no note we suppress the generation of the
+ // label.
+ Object[] tmp = (note == null) ?
+ new Object[]
+ {
+ message,
+ progressBar = new JProgressBar(min, max)
+ }
+ :
+ new Object[]
+ {
+ message,
+ noteLabel = new JLabel(note),
+ progressBar = new JProgressBar(min, max)
+ };
+
+ JOptionPane pane = new JOptionPane(tmp, JOptionPane.INFORMATION_MESSAGE);
+
+ // FIXME: Internationalize the button
+ JButton cancelButton = new JButton("Cancel");
+ cancelButton.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent ae)
+ {
+ canceled = true;
+ }
+ });
+
+ pane.setOptions(new Object[] { cancelButton });
+
+ // FIXME: Internationalize the title
+ progressDialog = pane.createDialog(component, "Progress ...");
+ progressDialog.setModal(false);
+ progressDialog.setResizable(true);
+
+ progressDialog.pack();
+ progressDialog.setVisible(true);
+
+ }
+
+ /** An ActionListener implementation which does the measurements
+ * and estimations of the ProgressMonitor.
+ */
+ class TimerListener implements ActionListener
+ {
+ long timestamp;
+
+ int lastProgress;
+
+ boolean first = true;
+
+ TimerListener()
+ {
+ timestamp = System.currentTimeMillis();
+ }
+
+ public void actionPerformed(ActionEvent ae)
+ {
+ long now = System.currentTimeMillis();
+
+ if (first)
+ {
+ if ((now - timestamp) > millisToDecideToPopup)
+ {
+ first = false;
+
+
+ long expected = (progress - min == 0) ?
+ (now - timestamp) * (max - min) :
+ (now - timestamp) * (max - min) / (progress - min);
+
+ if (expected > millisToPopup)
+ {
+ createDialog();
+ }
+ }
+ else
+ {
+ // We have not waited long enough to make a decision,
+ // so return and try again when the timer is invoked.
+ return;
+ }
+ }
+ else if (progressDialog != null)
+ {
+ // The progress dialog is being displayed. We now calculate
+ // whether setting the progress bar to the current progress
+ // value would result in a visual difference.
+ int delta = progress - progressBar.getValue();
+
+ if ((delta * progressBar.getWidth() / (max - min)) > 0)
+ {
+ // At least one pixel would change.
+ progressBar.setValue(progress);
+ }
+ }
+ else
+ {
+ // No dialog necessary
+ timer.stop();
+ timer = null;
+ }
+
+ timestamp = now;
+ }
+ }
+
+ /**
+ * Gets the accessible context.
+ *
+ * @return the accessible context.
+ */
+ public AccessibleContext getAccessibleContext()
+ {
+ return accessibleContext;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ProgressMonitorInputStream.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ProgressMonitorInputStream.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ProgressMonitorInputStream.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ProgressMonitorInputStream.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,249 @@
+/* ProgressMonitorInputStream.java --
+ Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.awt.Component;
+
+import java.io.FilterInputStream;
+import java.io.InputStream;
+import java.io.InterruptedIOException;
+import java.io.IOException;
+
+/**
+ * An input stream with a {@link ProgressMonitor}.
+ *
+ * @author Andrew Selkirk
+ * @author Robert Schuster (robertschuster at fsfe.org)
+ * @status updated to 1.2
+ * @since 1.2
+ */
+public class ProgressMonitorInputStream extends FilterInputStream
+{
+
+ /**
+ * The monitor watching the progress of the input stream.
+ */
+ private ProgressMonitor monitor;
+
+ /**
+ * read
+ */
+ private int read;
+
+ /**
+ * Creates a new <code>ProgressMonitorInputStream</code>.
+ *
+ * @param component the parent component for the progress monitor dialog.
+ * @param message the task description.
+ * @param stream the underlying input stream.
+ */
+ public ProgressMonitorInputStream(Component component, Object message,
+ InputStream stream)
+ {
+ super(stream);
+
+ int max = 0;
+
+ try
+ {
+ max = stream.available();
+ }
+ catch ( IOException ioe )
+ {
+ // Behave like the JDK here.
+ }
+
+ monitor = new ProgressMonitor(component, message, null, 0, max);
+ }
+
+ /**
+ * Resets the input stream to the point where {@link #mark(int)} was called.
+ *
+ * @exception IOException TODO
+ */
+ public void reset() throws IOException
+ {
+ super.reset();
+
+ checkMonitorCanceled();
+
+ // TODO: The docs says the monitor should be resetted. But to which
+ // value? (mark is not overridden)
+ }
+
+ /**
+ * Reads an unsigned byte from the input stream and returns it as an
+ * <code>int</code> in the range of 0-255. Returns -1 if the end of the
+ * stream has been reached. The progress monitor is updated.
+ *
+ * @return int
+ *
+ * @exception IOException if there is a problem reading the stream.
+ */
+ public int read() throws IOException
+ {
+ int t = super.read();
+
+ monitor.setProgress(++read);
+
+ checkMonitorCanceled();
+
+ return t;
+ }
+
+ /**
+ * Reads bytes from the input stream and stores them in the supplied array,
+ * and updates the progress monitor (or closes it if the end of the stream
+ * is reached).
+ *
+ * @param data the data array for returning bytes read from the stream.
+ *
+ * @return The number of bytes read, or -1 if there are no more bytes in the
+ * stream.
+ *
+ * @throws IOException if there is a problem reading bytes from the stream.
+ */
+ public int read(byte[] data) throws IOException
+ {
+ int t = super.read(data);
+
+ if ( t > 0 )
+ {
+ read += t;
+ monitor.setProgress(read);
+
+ checkMonitorCanceled();
+ }
+ else
+ {
+ monitor.close();
+ }
+
+ return t;
+ }
+
+ /**
+ * Reads up to <code>length</code> bytes from the input stream and stores
+ * them in the supplied array at the given index, and updates the progress
+ * monitor (or closes it if the end of the stream is reached).
+ *
+ * @param data the data array for returning bytes read from the stream.
+ * @param offset the offset into the array where the bytes should be written.
+ * @param length the maximum number of bytes to read from the stream.
+ *
+ * @return The number of bytes read, or -1 if there are no more bytes in the
+ * stream.
+ *
+ * @throws IOException if there is a problem reading bytes from the stream.
+ */
+ public int read(byte[] data, int offset, int length) throws IOException
+ {
+ int t = super.read(data, offset, length);
+
+ if ( t > 0 )
+ {
+ read += t;
+ monitor.setProgress(read);
+
+ checkMonitorCanceled();
+ }
+ else
+ {
+ monitor.close();
+ }
+
+ return t;
+ }
+
+ /**
+ * Skips the specified number of bytes and updates the
+ * {@link ProgressMonitor}.
+ *
+ * @param length the number of bytes to skip.
+ *
+ * @return The actual number of bytes skipped.
+ *
+ * @throws IOException if there is a problem skipping bytes in the stream.
+ */
+ public long skip(long length) throws IOException
+ {
+ long t = super.skip(length);
+
+ // 'read' may overflow here in rare situations.
+ assert ( (long) read + t <= (long) Integer.MAX_VALUE );
+
+ read += (int) t;
+
+ monitor.setProgress(read);
+
+ checkMonitorCanceled();
+
+ return t;
+ }
+
+ /**
+ * Closes the input stream and the associated {@link ProgressMonitor}.
+ *
+ * @throws IOException if there is a problem closing the input stream.
+ */
+ public void close() throws IOException
+ {
+ super.close();
+ monitor.close();
+ }
+
+ /**
+ * Returns the {@link ProgressMonitor} used by this input stream.
+ *
+ * @return The progress monitor.
+ */
+ public ProgressMonitor getProgressMonitor()
+ {
+ return monitor;
+ }
+
+ private void checkMonitorCanceled() throws InterruptedIOException
+ {
+ if (monitor.isCanceled())
+ {
+ throw new InterruptedIOException("ProgressMonitor was canceled");
+ }
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Renderer.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Renderer.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Renderer.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Renderer.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,68 @@
+/* Renderer.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import java.awt.Component;
+
+/**
+ * This interface is not used and exists only for compatibility.
+ * It probably has been replaced by {@link ListCellRenderer}, {@link
+ * javax.swing.table.TableCellRenderer} and {@link
+ * javax.swing.tree.TreeCellRenderer}.
+ *
+ * @specnote This interface is not used and exists only for compatibility.
+ *
+ * @author Andrew Selkirk
+ */
+public interface Renderer
+{
+ /**
+ * setValue
+ * @param value TODO
+ * @param selected TODO
+ */
+ void setValue(Object value, boolean selected);
+
+ /**
+ * getComponent
+ * @returns Component
+ */
+ Component getComponent();
+
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/RepaintManager.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/RepaintManager.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/RepaintManager.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/RepaintManager.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,861 @@
+/* RepaintManager.java --
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Rectangle;
+import java.awt.Window;
+import java.awt.image.VolatileImage;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+/**
+ * <p>The repaint manager holds a set of dirty regions, invalid components,
+ * and a double buffer surface. The dirty regions and invalid components
+ * are used to coalesce multiple revalidate() and repaint() calls in the
+ * component tree into larger groups to be refreshed "all at once"; the
+ * double buffer surface is used by root components to paint
+ * themselves.</p>
+ *
+ * <p>See <a
+ * href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">this
+ * document</a> for more details.</p>
+ *
+ * @author Roman Kennke (kennke at aicas.com)
+ * @author Graydon Hoare (graydon at redhat.com)
+ * @author Audrius Meskauskas (audriusa at bioinformatics.org)
+ */
+public class RepaintManager
+{
+ /**
+ * The current repaint managers, indexed by their ThreadGroups.
+ */
+ static WeakHashMap currentRepaintManagers;
+
+ /**
+ * A rectangle object to be reused in damaged regions calculation.
+ */
+ private static Rectangle rectCache = new Rectangle();
+
+ /**
+ * <p>A helper class which is placed into the system event queue at
+ * various times in order to facilitate repainting and layout. There is
+ * typically only one of these objects active at any time. When the
+ * {@link RepaintManager} is told to queue a repaint, it checks to see if
+ * a {@link RepaintWorker} is "live" in the system event queue, and if
+ * not it inserts one using {@link SwingUtilities#invokeLater}.</p>
+ *
+ * <p>When the {@link RepaintWorker} comes to the head of the system
+ * event queue, its {@link RepaintWorker#run} method is executed by the
+ * swing paint thread, which revalidates all invalid components and
+ * repaints any damage in the swing scene.</p>
+ */
+ private class RepaintWorker
+ implements Runnable
+ {
+
+ boolean live;
+
+ public RepaintWorker()
+ {
+ live = false;
+ }
+
+ public synchronized void setLive(boolean b)
+ {
+ live = b;
+ }
+
+ public synchronized boolean isLive()
+ {
+ return live;
+ }
+
+ public void run()
+ {
+ try
+ {
+ ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
+ RepaintManager rm =
+ (RepaintManager) currentRepaintManagers.get(threadGroup);
+ rm.validateInvalidComponents();
+ rm.paintDirtyRegions();
+ }
+ finally
+ {
+ setLive(false);
+ }
+ }
+
+ }
+
+ /**
+ * A table storing the dirty regions of components. The keys of this
+ * table are components, the values are rectangles. Each component maps
+ * to exactly one rectangle. When more regions are marked as dirty on a
+ * component, they are union'ed with the existing rectangle.
+ *
+ * This is package private to avoid a synthetic accessor method in inner
+ * class.
+ *
+ * @see #addDirtyRegion
+ * @see #getDirtyRegion
+ * @see #isCompletelyDirty
+ * @see #markCompletelyClean
+ * @see #markCompletelyDirty
+ */
+ private HashMap dirtyComponents;
+
+ /**
+ * The dirtyComponents which is used in paintDiryRegions to avoid unnecessary
+ * locking.
+ */
+ private HashMap dirtyComponentsWork;
+
+ /**
+ * A single, shared instance of the helper class. Any methods which mark
+ * components as invalid or dirty eventually activate this instance. It
+ * is added to the event queue if it is not already active, otherwise
+ * reused.
+ *
+ * @see #addDirtyRegion
+ * @see #addInvalidComponent
+ */
+ private RepaintWorker repaintWorker;
+
+ /**
+ * The set of components which need revalidation, in the "layout" sense.
+ * There is no additional information about "what kind of layout" they
+ * need (as there is with dirty regions), so it is just a vector rather
+ * than a table.
+ *
+ * @see #addInvalidComponent
+ * @see #removeInvalidComponent
+ * @see #validateInvalidComponents
+ */
+ private ArrayList invalidComponents;
+
+ /**
+ * Whether or not double buffering is enabled on this repaint
+ * manager. This is merely a hint to clients; the RepaintManager will
+ * always return an offscreen buffer when one is requested.
+ *
+ * @see #isDoubleBufferingEnabled
+ * @see #setDoubleBufferingEnabled
+ */
+ private boolean doubleBufferingEnabled;
+
+ /**
+ * The offscreen buffers. This map holds one offscreen buffer per
+ * Window/Applet and releases them as soon as the Window/Applet gets garbage
+ * collected.
+ */
+ private WeakHashMap offscreenBuffers;
+
+ /**
+ * Indicates if the RepaintManager is currently repainting an area.
+ */
+ private boolean repaintUnderway;
+
+ /**
+ * This holds buffer commit requests when the RepaintManager is working.
+ * This maps Component objects (the top level components) to Rectangle
+ * objects (the area of the corresponding buffer that must be blitted on
+ * the component).
+ */
+ private HashMap commitRequests;
+
+ /**
+ * The maximum width and height to allocate as a double buffer. Requests
+ * beyond this size are ignored.
+ *
+ * @see #paintDirtyRegions
+ * @see #getDoubleBufferMaximumSize
+ * @see #setDoubleBufferMaximumSize
+ */
+ private Dimension doubleBufferMaximumSize;
+
+
+ /**
+ * Create a new RepaintManager object.
+ */
+ public RepaintManager()
+ {
+ dirtyComponents = new HashMap();
+ dirtyComponentsWork = new HashMap();
+ invalidComponents = new ArrayList();
+ repaintWorker = new RepaintWorker();
+ doubleBufferMaximumSize = new Dimension(2000,2000);
+ doubleBufferingEnabled = true;
+ offscreenBuffers = new WeakHashMap();
+ repaintUnderway = false;
+ commitRequests = new HashMap();
+ }
+
+ /**
+ * Returns the <code>RepaintManager</code> for the current thread's
+ * thread group. The default implementation ignores the
+ * <code>component</code> parameter and returns the same repaint manager
+ * for all components.
+ *
+ * @param component a component to look up the manager of
+ *
+ * @return the current repaint manager for the calling thread's thread group
+ * and the specified component
+ *
+ * @see #setCurrentManager
+ */
+ public static RepaintManager currentManager(Component component)
+ {
+ if (currentRepaintManagers == null)
+ currentRepaintManagers = new WeakHashMap();
+ ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
+ RepaintManager currentManager =
+ (RepaintManager) currentRepaintManagers.get(threadGroup);
+ if (currentManager == null)
+ {
+ currentManager = new RepaintManager();
+ currentRepaintManagers.put(threadGroup, currentManager);
+ }
+ return currentManager;
+ }
+
+ /**
+ * Returns the <code>RepaintManager</code> for the current thread's
+ * thread group. The default implementation ignores the
+ * <code>component</code> parameter and returns the same repaint manager
+ * for all components.
+ *
+ * This method is only here for backwards compatibility with older versions
+ * of Swing and simply forwards to {@link #currentManager(Component)}.
+ *
+ * @param component a component to look up the manager of
+ *
+ * @return the current repaint manager for the calling thread's thread group
+ * and the specified component
+ *
+ * @see #setCurrentManager
+ */
+ public static RepaintManager currentManager(JComponent component)
+ {
+ return currentManager((Component)component);
+ }
+
+ /**
+ * Sets the repaint manager for the calling thread's thread group.
+ *
+ * @param manager the repaint manager to set for the current thread's thread
+ * group
+ *
+ * @see #currentManager(Component)
+ */
+ public static void setCurrentManager(RepaintManager manager)
+ {
+ if (currentRepaintManagers == null)
+ currentRepaintManagers = new WeakHashMap();
+
+ ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
+ currentRepaintManagers.put(threadGroup, manager);
+ }
+
+ /**
+ * Add a component to the {@link #invalidComponents} vector. If the
+ * {@link #repaintWorker} class is not active, insert it in the system
+ * event queue.
+ *
+ * @param component The component to add
+ *
+ * @see #removeInvalidComponent
+ */
+ public void addInvalidComponent(JComponent component)
+ {
+ Component validateRoot = null;
+ Component c = component;
+ while (c != null)
+ {
+ // Special cases we don't bother validating are when the invalidated
+ // component (or any of it's ancestors) is inside a CellRendererPane
+ // or if it doesn't have a peer yet (== not displayable).
+ if (c instanceof CellRendererPane || ! c.isDisplayable())
+ return;
+ if (c instanceof JComponent && ((JComponent) c).isValidateRoot())
+ {
+ validateRoot = c;
+ break;
+ }
+
+ c = c.getParent();
+ }
+
+ // If we didn't find a validate root, then we don't validate.
+ if (validateRoot == null)
+ return;
+
+ // Make sure the validate root and all of it's ancestors are visible.
+ c = validateRoot;
+ while (c != null)
+ {
+ if (! c.isVisible() || ! c.isDisplayable())
+ return;
+ c = c.getParent();
+ }
+
+ if (invalidComponents.contains(validateRoot))
+ return;
+
+ //synchronized (invalidComponents)
+ // {
+ invalidComponents.add(validateRoot);
+ // }
+
+ if (! repaintWorker.isLive())
+ {
+ repaintWorker.setLive(true);
+ SwingUtilities.invokeLater(repaintWorker);
+ }
+ }
+
+ /**
+ * Remove a component from the {@link #invalidComponents} vector.
+ *
+ * @param component The component to remove
+ *
+ * @see #addInvalidComponent
+ */
+ public void removeInvalidComponent(JComponent component)
+ {
+ synchronized (invalidComponents)
+ {
+ invalidComponents.remove(component);
+ }
+ }
+
+ /**
+ * Add a region to the set of dirty regions for a specified component.
+ * This involves union'ing the new region with any existing dirty region
+ * associated with the component. If the {@link #repaintWorker} class
+ * is not active, insert it in the system event queue.
+ *
+ * @param component The component to add a dirty region for
+ * @param x The left x coordinate of the new dirty region
+ * @param y The top y coordinate of the new dirty region
+ * @param w The width of the new dirty region
+ * @param h The height of the new dirty region
+ *
+ * @see #addDirtyRegion
+ * @see #getDirtyRegion
+ * @see #isCompletelyDirty
+ * @see #markCompletelyClean
+ * @see #markCompletelyDirty
+ */
+ public void addDirtyRegion(JComponent component, int x, int y,
+ int w, int h)
+ {
+ if (w <= 0 || h <= 0 || !component.isShowing())
+ return;
+
+ Component parent = component.getParent();
+
+ component.computeVisibleRect(rectCache);
+ SwingUtilities.computeIntersection(x, y, w, h, rectCache);
+
+ if (! rectCache.isEmpty())
+ {
+ if (dirtyComponents.containsKey(component))
+ {
+ SwingUtilities.computeUnion(rectCache.x, rectCache.y,
+ rectCache.width, rectCache.height,
+ (Rectangle) dirtyComponents.get(component));
+ }
+ else
+ {
+ synchronized (dirtyComponents)
+ {
+ dirtyComponents.put(component, rectCache.getBounds());
+ }
+ }
+
+ if (! repaintWorker.isLive())
+ {
+ repaintWorker.setLive(true);
+ SwingUtilities.invokeLater(repaintWorker);
+ }
+ }
+ }
+
+ /**
+ * Get the dirty region associated with a component, or <code>null</code>
+ * if the component has no dirty region.
+ *
+ * @param component The component to get the dirty region of
+ *
+ * @return The dirty region of the component
+ *
+ * @see #dirtyComponents
+ * @see #addDirtyRegion
+ * @see #isCompletelyDirty
+ * @see #markCompletelyClean
+ * @see #markCompletelyDirty
+ */
+ public Rectangle getDirtyRegion(JComponent component)
+ {
+ Rectangle dirty = (Rectangle) dirtyComponents.get(component);
+ if (dirty == null)
+ dirty = new Rectangle();
+ return dirty;
+ }
+
+ /**
+ * Mark a component as dirty over its entire bounds.
+ *
+ * @param component The component to mark as dirty
+ *
+ * @see #dirtyComponents
+ * @see #addDirtyRegion
+ * @see #getDirtyRegion
+ * @see #isCompletelyDirty
+ * @see #markCompletelyClean
+ */
+ public void markCompletelyDirty(JComponent component)
+ {
+ addDirtyRegion(component, 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
+ }
+
+ /**
+ * Remove all dirty regions for a specified component
+ *
+ * @param component The component to mark as clean
+ *
+ * @see #dirtyComponents
+ * @see #addDirtyRegion
+ * @see #getDirtyRegion
+ * @see #isCompletelyDirty
+ * @see #markCompletelyDirty
+ */
+ public void markCompletelyClean(JComponent component)
+ {
+ synchronized (dirtyComponents)
+ {
+ dirtyComponents.remove(component);
+ }
+ }
+
+ /**
+ * Return <code>true</code> if the specified component is completely
+ * contained within its dirty region, otherwise <code>false</code>
+ *
+ * @param component The component to check for complete dirtyness
+ *
+ * @return Whether the component is completely dirty
+ *
+ * @see #dirtyComponents
+ * @see #addDirtyRegion
+ * @see #getDirtyRegion
+ * @see #isCompletelyDirty
+ * @see #markCompletelyClean
+ */
+ public boolean isCompletelyDirty(JComponent component)
+ {
+ boolean dirty = false;
+ Rectangle r = getDirtyRegion(component);
+ if(r.width == Integer.MAX_VALUE && r.height == Integer.MAX_VALUE)
+ dirty = true;
+ return dirty;
+ }
+
+ /**
+ * Validate all components which have been marked invalid in the {@link
+ * #invalidComponents} vector.
+ */
+ public void validateInvalidComponents()
+ {
+ // We don't use an iterator here because that would fail when there are
+ // components invalidated during the validation of others, which happens
+ // quite frequently. Instead we synchronize the access a little more.
+ while (invalidComponents.size() > 0)
+ {
+ Component comp;
+ synchronized (invalidComponents)
+ {
+ comp = (Component) invalidComponents.remove(0);
+ }
+ // Validate the validate component.
+ if (! (comp.isVisible() && comp.isShowing()))
+ continue;
+ comp.validate();
+ }
+ }
+
+ /**
+ * Repaint all regions of all components which have been marked dirty in the
+ * {@link #dirtyComponents} table.
+ */
+ public void paintDirtyRegions()
+ {
+ // Short cicuit if there is nothing to paint.
+ if (dirtyComponents.size() == 0)
+ return;
+
+ // Swap dirtyRegions with dirtyRegionsWork to avoid locking.
+ synchronized (dirtyComponents)
+ {
+ HashMap swap = dirtyComponents;
+ dirtyComponents = dirtyComponentsWork;
+ dirtyComponentsWork = swap;
+ }
+
+ // Compile a set of repaint roots.
+ HashSet repaintRoots = new HashSet();
+ Set components = dirtyComponentsWork.keySet();
+ for (Iterator i = components.iterator(); i.hasNext();)
+ {
+ JComponent dirty = (JComponent) i.next();
+ compileRepaintRoots(dirtyComponentsWork, dirty, repaintRoots);
+ }
+
+ repaintUnderway = true;
+ for (Iterator i = repaintRoots.iterator(); i.hasNext();)
+ {
+ JComponent comp = (JComponent) i.next();
+ Rectangle damaged = (Rectangle) dirtyComponentsWork.remove(comp);
+ if (damaged == null || damaged.isEmpty())
+ continue;
+ comp.paintImmediately(damaged);
+ }
+ dirtyComponentsWork.clear();
+ repaintUnderway = false;
+ commitRemainingBuffers();
+ }
+
+ /**
+ * Compiles a list of components that really get repainted. This is called
+ * once for each component in the dirtyComponents HashMap, each time with
+ * another <code>dirty</code> parameter. This searches up the component
+ * hierarchy of <code>dirty</code> to find the highest parent that is also
+ * marked dirty and merges the dirty regions.
+ *
+ * @param dirtyRegions the dirty regions
+ * @param dirty the component for which to find the repaint root
+ * @param roots the list to which new repaint roots get appended
+ */
+ private void compileRepaintRoots(HashMap dirtyRegions, JComponent dirty,
+ HashSet roots)
+ {
+ Component current = dirty;
+ Component root = dirty;
+
+ // Search the highest component that is also marked dirty.
+ Component parent;
+ while (true)
+ {
+ parent = current.getParent();
+ if (parent == null || !(parent instanceof JComponent))
+ break;
+
+ current = parent;
+ // We can skip to the next up when this parent is not dirty.
+ if (dirtyRegions.containsKey(parent))
+ {
+ root = current;
+ }
+ }
+
+ // Merge the rectangles of the root and the requested component if
+ // the are different.
+ if (root != dirty)
+ {
+ Rectangle dirtyRect = (Rectangle) dirtyRegions.get(dirty);
+ dirtyRect = SwingUtilities.convertRectangle(dirty, dirtyRect, root);
+ Rectangle rootRect = (Rectangle) dirtyRegions.get(root);
+ SwingUtilities.computeUnion(dirtyRect.x, dirtyRect.y, dirtyRect.width,
+ dirtyRect.height, rootRect);
+ }
+
+ // Adds the root to the roots set.
+ roots.add(root);
+ }
+
+ /**
+ * Get an offscreen buffer for painting a component's image. This image
+ * may be smaller than the proposed dimensions, depending on the value of
+ * the {@link #doubleBufferMaximumSize} property.
+ *
+ * @param component The component to return an offscreen buffer for
+ * @param proposedWidth The proposed width of the offscreen buffer
+ * @param proposedHeight The proposed height of the offscreen buffer
+ *
+ * @return A shared offscreen buffer for painting
+ */
+ public Image getOffscreenBuffer(Component component, int proposedWidth,
+ int proposedHeight)
+ {
+ Component root = SwingUtilities.getWindowAncestor(component);
+ Image buffer = (Image) offscreenBuffers.get(root);
+ if (buffer == null
+ || buffer.getWidth(null) < proposedWidth
+ || buffer.getHeight(null) < proposedHeight)
+ {
+ int width = Math.max(proposedWidth, root.getWidth());
+ width = Math.min(doubleBufferMaximumSize.width, width);
+ int height = Math.max(proposedHeight, root.getHeight());
+ height = Math.min(doubleBufferMaximumSize.height, height);
+ buffer = root.createImage(width, height);
+ offscreenBuffers.put(root, buffer);
+ }
+ return buffer;
+ }
+
+ /**
+ * Blits the back buffer of the specified root component to the screen. If
+ * the RepaintManager is currently working on a paint request, the commit
+ * requests are queued up and committed at once when the paint request is
+ * done (by {@link #commitRemainingBuffers}). This is package private because
+ * it must get called by JComponent.
+ *
+ * @param comp the component to be painted
+ * @param area the area to paint on screen, in comp coordinates
+ */
+ void commitBuffer(Component comp, Rectangle area)
+ {
+ // Determine the component that we finally paint the buffer upon.
+ // We need to paint on the nearest heavyweight component, so that Swing
+ // hierarchies inside (non-window) heavyweights get painted correctly.
+ // Otherwise we would end up blitting the backbuffer behind the heavyweight
+ // which is wrong.
+ Component root = getHeavyweightParent(comp);
+ // FIXME: Optimize this.
+ Rectangle rootRect = SwingUtilities.convertRectangle(comp, area, root);
+
+ // We synchronize on dirtyComponents here because that is what
+ // paintDirtyRegions also synchronizes on while painting.
+ synchronized (dirtyComponents)
+ {
+ // If the RepaintManager is not currently painting, then directly
+ // blit the requested buffer on the screen.
+ if (true || ! repaintUnderway)
+ {
+ blitBuffer(root, rootRect);
+ }
+
+ // Otherwise queue this request up, until all the RepaintManager work
+ // is done.
+ else
+ {
+ if (commitRequests.containsKey(root))
+ SwingUtilities.computeUnion(rootRect.x, rootRect.y,
+ rootRect.width, rootRect.height,
+ (Rectangle) commitRequests.get(root));
+ else
+ commitRequests.put(root, rootRect);
+ }
+ }
+ }
+
+ /**
+ * Copies the buffer to the screen. Note that the root component here is
+ * not necessarily the component with which the offscreen buffer is
+ * associated. The offscreen buffers are always allocated for the toplevel
+ * windows. However, painted is performed on lower-level heavyweight
+ * components too, if they contain Swing components.
+ *
+ * @param root the heavyweight component to blit upon
+ * @param rootRect the rectangle in the root component's coordinate space
+ */
+ private void blitBuffer(Component root, Rectangle rootRect)
+ {
+ if (! root.isShowing())
+ return;
+
+ // Find the Window from which we use the backbuffer.
+ Component bufferRoot = root;
+ Rectangle bufferRect = rootRect.getBounds();
+ if (!(bufferRoot instanceof Window))
+ {
+ bufferRoot = SwingUtilities.getWindowAncestor(bufferRoot);
+ SwingUtilities.convertRectangleToAncestor(root, rootRect, bufferRoot);
+ }
+
+ Graphics g = root.getGraphics();
+ Image buffer = (Image) offscreenBuffers.get(bufferRoot);
+
+ // Make sure we have a sane clip at this point.
+ g.clipRect(rootRect.x, rootRect.y, rootRect.width, rootRect.height);
+ g.drawImage(buffer, rootRect.x - bufferRect.x, rootRect.y - bufferRect.y,
+ root);
+ g.dispose();
+
+ }
+
+ /**
+ * Finds and returns the nearest heavyweight parent for the specified
+ * component. If the component isn't contained inside a heavyweight parent,
+ * this returns null.
+ *
+ * @param comp the component
+ *
+ * @return the nearest heavyweight parent for the specified component or
+ * null if the component has no heavyweight ancestor
+ */
+ private Component getHeavyweightParent(Component comp)
+ {
+ while (comp != null && comp.isLightweight())
+ comp = comp.getParent();
+ return comp;
+ }
+
+ /**
+ * Commits the queued up back buffers to screen all at once.
+ */
+ private void commitRemainingBuffers()
+ {
+ // We synchronize on dirtyComponents here because that is what
+ // paintDirtyRegions also synchronizes on while painting.
+ synchronized (dirtyComponents)
+ {
+ Set entrySet = commitRequests.entrySet();
+ Iterator i = entrySet.iterator();
+ while (i.hasNext())
+ {
+ Map.Entry entry = (Map.Entry) i.next();
+ Component root = (Component) entry.getKey();
+ Rectangle area = (Rectangle) entry.getValue();
+ blitBuffer(root, area);
+ i.remove();
+ }
+ }
+ }
+
+ /**
+ * Creates and returns a volatile offscreen buffer for the specified
+ * component that can be used as a double buffer. The returned image
+ * is a {@link VolatileImage}. Its size will be <code>(proposedWidth,
+ * proposedHeight)</code> except when the maximum double buffer size
+ * has been set in this RepaintManager.
+ *
+ * @param comp the Component for which to create a volatile buffer
+ * @param proposedWidth the proposed width of the buffer
+ * @param proposedHeight the proposed height of the buffer
+ *
+ * @since 1.4
+ *
+ * @see VolatileImage
+ */
+ public Image getVolatileOffscreenBuffer(Component comp, int proposedWidth,
+ int proposedHeight)
+ {
+ Component root = SwingUtilities.getWindowAncestor(comp);
+ Image buffer = (Image) offscreenBuffers.get(root);
+ if (buffer == null
+ || buffer.getWidth(null) < proposedWidth
+ || buffer.getHeight(null) < proposedHeight
+ || !(buffer instanceof VolatileImage))
+ {
+ int width = Math.max(proposedWidth, root.getWidth());
+ width = Math.min(doubleBufferMaximumSize.width, width);
+ int height = Math.max(proposedHeight, root.getHeight());
+ height = Math.min(doubleBufferMaximumSize.height, height);
+ buffer = root.createVolatileImage(width, height);
+ if (buffer != null)
+ offscreenBuffers.put(root, buffer);
+ }
+ return buffer;
+ }
+
+
+ /**
+ * Get the value of the {@link #doubleBufferMaximumSize} property.
+ *
+ * @return The current value of the property
+ *
+ * @see #setDoubleBufferMaximumSize
+ */
+ public Dimension getDoubleBufferMaximumSize()
+ {
+ return doubleBufferMaximumSize;
+ }
+
+ /**
+ * Set the value of the {@link #doubleBufferMaximumSize} property.
+ *
+ * @param size The new value of the property
+ *
+ * @see #getDoubleBufferMaximumSize
+ */
+ public void setDoubleBufferMaximumSize(Dimension size)
+ {
+ doubleBufferMaximumSize = size;
+ }
+
+ /**
+ * Set the value of the {@link #doubleBufferingEnabled} property.
+ *
+ * @param buffer The new value of the property
+ *
+ * @see #isDoubleBufferingEnabled
+ */
+ public void setDoubleBufferingEnabled(boolean buffer)
+ {
+ doubleBufferingEnabled = buffer;
+ }
+
+ /**
+ * Get the value of the {@link #doubleBufferingEnabled} property.
+ *
+ * @return The current value of the property
+ *
+ * @see #setDoubleBufferingEnabled
+ */
+ public boolean isDoubleBufferingEnabled()
+ {
+ return doubleBufferingEnabled;
+ }
+
+ public String toString()
+ {
+ return "RepaintManager";
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/RootPaneContainer.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/RootPaneContainer.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/RootPaneContainer.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/RootPaneContainer.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,96 @@
+/* RootPaneContainer.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.awt.Component;
+import java.awt.Container;
+
+/**
+ * Components that contain a single {@link JRootPane} as only child
+ * implement this interface, typically this is implemented by the
+ * Swing top-level containers.
+ *
+ * @author Andrew Selkirk
+ */
+public interface RootPaneContainer
+{
+
+ /**
+ * getRootPane
+ * @returns JRootPane
+ */
+ JRootPane getRootPane();
+
+ /**
+ * setContentPane
+ * @param contentPane TODO
+ */
+ void setContentPane(Container contentPane);
+
+ /**
+ * getContentPane
+ * @returns Container
+ */
+ Container getContentPane();
+
+ /**
+ * setLayeredPane
+ * @param layeredPane TODO
+ */
+ void setLayeredPane(JLayeredPane layeredPane);
+
+ /**
+ * getLayeredPane
+ * @returns JLayeredPane
+ */
+ JLayeredPane getLayeredPane();
+
+ /**
+ * setGlassPane
+ * @param glassPane TODO
+ */
+ void setGlassPane(Component glassPane);
+
+ /**
+ * getGlassPane
+ * @returns Component
+ */
+ Component getGlassPane();
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ScrollPaneConstants.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ScrollPaneConstants.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ScrollPaneConstants.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ScrollPaneConstants.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,152 @@
+/* ScrollPaneConstants.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+/**
+ * Defines some constants that are used in {@link JScrollPane} and related
+ * components.
+ *
+ * @author Andrew Selkirk
+ */
+public interface ScrollPaneConstants
+{
+ /**
+ * VIEWPORT
+ */
+ String VIEWPORT = "VIEWPORT";
+
+ /**
+ * VERTICAL_SCROLLBAR
+ */
+ String VERTICAL_SCROLLBAR = "VERTICAL_SCROLLBAR";
+
+ /**
+ * HORIZONTAL_SCROLLBAR
+ */
+ String HORIZONTAL_SCROLLBAR = "HORIZONTAL_SCROLLBAR";
+
+ /**
+ * ROW_HEADER
+ */
+ String ROW_HEADER = "ROW_HEADER";
+
+ /**
+ * COLUMN_HEADER
+ */
+ String COLUMN_HEADER = "COLUMN_HEADER";
+
+ /**
+ * LOWER_LEFT_CORNER
+ */
+ String LOWER_LEFT_CORNER = "LOWER_LEFT_CORNER";
+
+ /**
+ * LOWER_RIGHT_CORNER
+ */
+ String LOWER_RIGHT_CORNER = "LOWER_RIGHT_CORNER";
+
+ /**
+ * UPPER_LEFT_CORNER
+ */
+ String UPPER_LEFT_CORNER = "UPPER_LEFT_CORNER";
+
+ /**
+ * UPPER_RIGHT_CORNER
+ */
+ String UPPER_RIGHT_CORNER = "UPPER_RIGHT_CORNER";
+
+ /**
+ * LOWER_LEADING_CORNER
+ */
+ String LOWER_LEADING_CORNER = "LOWER_LEADING_CORNER";
+
+ /**
+ * LOWER_TRAILING_CORNER
+ */
+ String LOWER_TRAILING_CORNER = "LOWER_TRAILING_CORNER";
+
+ /**
+ * UPPER_LEADING_CORNER
+ */
+ String UPPER_LEADING_CORNER = "UPPER_LEADING_CORNER";
+
+ /**
+ * UPPER_TRAILING_CORNER
+ */
+ String UPPER_TRAILING_CORNER = "UPPER_TRAILING_CORNER";
+
+ /**
+ * VERTICAL_SCROLLBAR_POLICY
+ */
+ String VERTICAL_SCROLLBAR_POLICY = "VERTICAL_SCROLLBAR_POLICY";
+
+ /**
+ * HORIZONTAL_SCROLLBAR_POLICY
+ */
+ String HORIZONTAL_SCROLLBAR_POLICY = "HORIZONTAL_SCROLLBAR_POLICY";
+
+ /**
+ * VERTICAL_SCROLLBAR_AS_NEEDED
+ */
+ int VERTICAL_SCROLLBAR_AS_NEEDED = 20;
+
+ /**
+ * VERTICAL_SCROLLBAR_NEVER
+ */
+ int VERTICAL_SCROLLBAR_NEVER = 21;
+
+ /**
+ * VERTICAL_SCROLLBAR_ALWAYS
+ */
+ int VERTICAL_SCROLLBAR_ALWAYS = 22;
+
+ /**
+ * HORIZONTAL_SCROLLBAR_AS_NEEDED
+ */
+ int HORIZONTAL_SCROLLBAR_AS_NEEDED = 30;
+
+ /**
+ * HORIZONTAL_SCROLLBAR_NEVER
+ */
+ int HORIZONTAL_SCROLLBAR_NEVER = 31;
+
+ /**
+ * HORIZONTAL_SCROLLBAR_ALWAYS
+ */
+ int HORIZONTAL_SCROLLBAR_ALWAYS = 32;
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ScrollPaneLayout.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ScrollPaneLayout.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ScrollPaneLayout.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ScrollPaneLayout.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,459 @@
+/* ScrollPaneLayout.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Insets;
+import java.awt.LayoutManager;
+import java.awt.Rectangle;
+import java.io.Serializable;
+
+/**
+ * ScrollPaneLayout
+ * @author Andrew Selkirk
+ * @version 1.0
+ */
+public class ScrollPaneLayout
+ implements LayoutManager, ScrollPaneConstants, Serializable
+{
+ private static final long serialVersionUID = -4480022884523193743L;
+
+ public static class UIResource extends ScrollPaneLayout
+ implements javax.swing.plaf.UIResource
+ {
+ public UIResource()
+ {
+ super();
+ }
+ }
+
+ protected JViewport viewport;
+ protected JScrollBar vsb;
+ protected JScrollBar hsb;
+ protected JViewport rowHead;
+ protected JViewport colHead;
+ protected Component lowerLeft;
+ protected Component lowerRight;
+ protected Component upperLeft;
+ protected Component upperRight;
+ protected int vsbPolicy;
+ protected int hsbPolicy;
+
+ public ScrollPaneLayout()
+ {
+ // Nothing to do here.
+ }
+
+ public void syncWithScrollPane(JScrollPane scrollPane)
+ {
+ viewport = scrollPane.getViewport();
+ rowHead = scrollPane.getRowHeader();
+ colHead = scrollPane.getColumnHeader();
+ vsb = scrollPane.getVerticalScrollBar();
+ hsb = scrollPane.getHorizontalScrollBar();
+ vsbPolicy = scrollPane.getVerticalScrollBarPolicy();
+ hsbPolicy = scrollPane.getHorizontalScrollBarPolicy();
+ lowerLeft = scrollPane.getCorner(LOWER_LEFT_CORNER);
+ lowerRight = scrollPane.getCorner(LOWER_RIGHT_CORNER);
+ upperLeft = scrollPane.getCorner(UPPER_LEFT_CORNER);
+ upperRight = scrollPane.getCorner(UPPER_RIGHT_CORNER);
+ }
+
+ /**
+ * Removes an existing component. If oldComponent is not null
+ * and is not equal to newComponent, oldComponent must be removed
+ * from its parent.
+ * @param oldComponent the old Component that may need to be removed.
+ * @param newComponent the Component to add.
+ * @return the newComponent
+ */
+ protected Component addSingletonComponent(Component oldComponent,
+ Component newComponent)
+ {
+ if (oldComponent != null && oldComponent != newComponent)
+ oldComponent.getParent().remove(oldComponent);
+ return newComponent;
+ }
+
+ /**
+ * Add the specified component to the layout.
+ * @param key must be one of VIEWPORT, VERTICAL_SCROLLBAR,
+ * HORIZONTAL_SCROLLBAR, ROW_HEADER, COLUMN_HEADER,
+ * LOWER_RIGHT_CORNER, LOWER_LEFT_CORNER, UPPER_RIGHT_CORNER,
+ * UPPER_LEFT_CORNER.
+ * @param component the Component to add
+ * @throws IllegalArgumentException if key is not as above
+ */
+ public void addLayoutComponent(String key, Component component)
+ {
+ if (key == VIEWPORT)
+ viewport = (JViewport) component;
+ else if (key == VERTICAL_SCROLLBAR)
+ vsb = (JScrollBar) component;
+ else if (key == HORIZONTAL_SCROLLBAR)
+ hsb = (JScrollBar) component;
+ else if (key == ROW_HEADER)
+ rowHead = (JViewport) component;
+ else if (key == COLUMN_HEADER)
+ colHead = (JViewport) component;
+ else if (key == LOWER_RIGHT_CORNER)
+ lowerRight = component;
+ else if (key == UPPER_RIGHT_CORNER)
+ upperRight = component;
+ else if (key == LOWER_LEFT_CORNER)
+ lowerLeft = component;
+ else if (key == UPPER_LEFT_CORNER)
+ upperLeft = component;
+ else
+ throw new IllegalArgumentException();
+ }
+
+ public void removeLayoutComponent(Component component)
+ {
+ if (component == viewport)
+ viewport = null;
+ else if (component == vsb)
+ vsb = null;
+ else if (component == hsb)
+ hsb = null;
+ else if (component == rowHead)
+ rowHead = null;
+ else if (component == colHead)
+ colHead = null;
+ else if (component == lowerRight)
+ lowerRight = null;
+ else if (component == upperRight)
+ upperRight = null;
+ else if (component == lowerLeft)
+ lowerLeft = null;
+ else if (component == upperLeft)
+ upperLeft = null;
+ }
+
+ public int getVerticalScrollBarPolicy()
+ {
+ return vsbPolicy;
+ }
+
+ /**
+ * Sets the vertical scrollbar policy.
+ * @param policy must be one of VERTICAL_SCROLLBAR_AS_NEEDED,
+ * VERTICAL_SCROLLBAR_NEVER, VERTICAL_SCROLLBAR_ALWAYS.
+ * @throws IllegalArgumentException if policy is not one of the valid
+ * JScrollBar policies.
+ */
+ public void setVerticalScrollBarPolicy(int policy)
+ {
+ if (policy != VERTICAL_SCROLLBAR_AS_NEEDED &&
+ policy != VERTICAL_SCROLLBAR_NEVER &&
+ policy != VERTICAL_SCROLLBAR_ALWAYS)
+ throw new IllegalArgumentException("Illegal Scrollbar Policy");
+ vsbPolicy = policy;
+ }
+
+ public int getHorizontalScrollBarPolicy()
+ {
+ return hsbPolicy;
+ }
+
+ /**
+ * Sets the horizontal scrollbar policy.
+ * @param policy must be one of HORIZONTAL_SCROLLBAR_AS_NEEDED,
+ * HORIZONTAL_SCROLLBAR_NEVER, HORIZONTAL_SCROLLBAR_ALWAYS.
+ * @throws IllegalArgumentException if policy is not one of the valid
+ * JScrollbar policies.
+ */
+ public void setHorizontalScrollBarPolicy(int policy)
+ {
+ if (policy != HORIZONTAL_SCROLLBAR_AS_NEEDED &&
+ policy != HORIZONTAL_SCROLLBAR_NEVER &&
+ policy != HORIZONTAL_SCROLLBAR_ALWAYS)
+ throw new IllegalArgumentException("Illegal Scrollbar Policy");
+ hsbPolicy = policy;
+ }
+
+ public JViewport getViewport()
+ {
+ return viewport;
+ }
+
+ public JScrollBar getHorizontalScrollBar()
+ {
+ return hsb;
+ }
+
+ public JScrollBar getVerticalScrollBar()
+ {
+ return vsb;
+ }
+
+ public JViewport getRowHeader()
+ {
+ return rowHead;
+ }
+
+ public JViewport getColumnHeader()
+ {
+ return colHead;
+ }
+
+ /**
+ * Returns the Component at the specified corner.
+ * @param key the corner.
+ * @return the Component at the specified corner, or null if
+ * key is not one of the four valid corners.
+ */
+ public Component getCorner(String key)
+ {
+ if (key == LOWER_RIGHT_CORNER)
+ return lowerRight;
+ else if (key == UPPER_RIGHT_CORNER)
+ return upperRight;
+ else if (key == LOWER_LEFT_CORNER)
+ return lowerLeft;
+ else if (key == UPPER_LEFT_CORNER)
+ return upperLeft;
+ return null;
+ }
+
+ public Dimension preferredLayoutSize(Container parent)
+ {
+ // Sun's implementation simply throws a ClassCastException if
+ // parent is no JScrollPane, so do we.
+ JScrollPane sc = (JScrollPane) parent;
+ Dimension viewportSize = viewport.getPreferredSize();
+ Dimension viewSize = viewport.getViewSize();
+ int width = viewportSize.width;
+ int height = viewportSize.height;
+
+ // horizontal scrollbar needed if the view's preferred width
+ // is larger than the viewport's preferred width
+ if (hsb != null && viewSize.width > viewportSize.width)
+ height += hsb.getPreferredSize().height;
+
+ // vertical scrollbar needed if the view's preferred height
+ // is larger than the viewport's preferred height
+ if (vsb != null && viewSize.height > viewportSize.height)
+ width += vsb.getPreferredSize().width;
+ if (rowHead != null && rowHead.isVisible())
+ width += rowHead.getPreferredSize().width;
+ if (colHead != null && colHead.isVisible())
+ height += colHead.getPreferredSize().height;
+ Insets i = sc.getInsets();
+ return new Dimension(width + i.left + i.right,
+ height + i.left + i.right);
+ }
+
+ public Dimension minimumLayoutSize(Container parent)
+ {
+ // Sun's implementation simply throws a ClassCastException if
+ // parent is no JScrollPane, so do we.
+ JScrollPane sc = (JScrollPane) parent;
+ Insets i = sc.getInsets();
+ Dimension viewportMinSize = sc.getViewport().getMinimumSize();
+
+ int width = i.left + i.right + viewportMinSize.width;
+ if (sc.getVerticalScrollBarPolicy()
+ != JScrollPane.VERTICAL_SCROLLBAR_NEVER)
+ width += sc.getVerticalScrollBar().getMinimumSize().width;
+
+ int height = i.top + i.bottom + viewportMinSize.height;
+ if (sc.getHorizontalScrollBarPolicy()
+ != JScrollPane.HORIZONTAL_SCROLLBAR_NEVER)
+ height += sc.getHorizontalScrollBar().getMinimumSize().height;
+
+ return new Dimension(width, height);
+ }
+
+ /**
+ *
+ * +----+--------------------+----+ y1
+ * | c1 | column header | c2 |
+ * +----+--------------------+----+ y2
+ * | r | | v |
+ * | o | | |
+ * | w | | s |
+ * | | | r |
+ * | h | | o |
+ * | e | viewport | l |
+ * | a | | l |
+ * | d | | b |
+ * | e | | a |
+ * | r | | r |
+ * +----+--------------------+----+ y3
+ * | c3 | h scrollbar | c4 |
+ * +----+--------------------+----+ y4
+ * x1 x2 x3 x4
+ *
+ */
+ public void layoutContainer(Container parent)
+ {
+ // Sun's implementation simply throws a ClassCastException if
+ // parent is no JScrollPane, so do we.
+ JScrollPane sc = (JScrollPane) parent;
+ JViewport viewport = sc.getViewport();
+ Component view = viewport.getView();
+
+ // If there is no view in the viewport, there is no work to be done.
+ if (view == null)
+ return;
+
+ Dimension viewSize = viewport.getView().getPreferredSize();
+
+ int x1 = 0, x2 = 0, x3 = 0, x4 = 0;
+ int y1 = 0, y2 = 0, y3 = 0, y4 = 0;
+ Rectangle scrollPaneBounds = SwingUtilities.calculateInnerArea(sc, null);
+
+ x1 = scrollPaneBounds.x;
+ y1 = scrollPaneBounds.y;
+ x4 = scrollPaneBounds.x + scrollPaneBounds.width;
+ y4 = scrollPaneBounds.y + scrollPaneBounds.height;
+ if (colHead != null)
+ y2 = y1 + colHead.getPreferredSize().height;
+ else
+ y2 = y1;
+
+ if (rowHead != null)
+ x2 = x1 + rowHead.getPreferredSize().width;
+ else
+ x2 = x1;
+
+ int vsbPolicy = sc.getVerticalScrollBarPolicy();
+ int hsbPolicy = sc.getHorizontalScrollBarPolicy();
+
+ int vsWidth = 0;
+ int hsHeight = 0;
+
+ boolean showVsb =
+ (vsb != null)
+ && ((vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS)
+ || (vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED
+ && viewSize.height > (y4 - y2)));
+
+ if (showVsb)
+ vsWidth = vsb.getPreferredSize().width;
+
+ // The horizontal scroll bar may become necessary if the vertical scroll
+ // bar appears, reducing the space, left for the component.
+
+ boolean showHsb =
+ (hsb != null)
+ && ((hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS)
+ || (hsbPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED
+ && viewSize.width > (x4 - x2 - vsWidth)));
+
+ if (showHsb)
+ hsHeight = hsb.getPreferredSize().height;
+
+ // If the horizontal scroll bar appears, and the vertical scroll bar
+ // was not necessary assuming that there is no horizontal scroll bar,
+ // the vertical scroll bar may become necessary because the horizontal
+ // scroll bar reduces the vertical space for the component.
+ if (!showVsb)
+ {
+ showVsb =
+ (vsb != null)
+ && ((vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS)
+ || (vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED
+ && viewSize.height > (y4 - y2)));
+
+ if (showVsb)
+ vsWidth = vsb.getPreferredSize().width;
+ }
+
+ x3 = x4 - vsWidth;
+ y3 = y4 - hsHeight;
+
+ // now set the layout
+ if (viewport != null)
+ viewport.setBounds(new Rectangle(x2, y2, x3 - x2, y3 - y2));
+
+ if (colHead != null)
+ colHead.setBounds(new Rectangle(x2, y1, x3 - x2, y2 - y1));
+
+ if (rowHead != null)
+ rowHead.setBounds(new Rectangle(x1, y2, x2 - x1, y3 - y2));
+
+ if (showVsb)
+ {
+ vsb.setVisible(true);
+ vsb.setBounds(new Rectangle(x3, y2, x4 - x3, y3 - y2));
+ }
+ else if (vsb != null)
+ vsb.setVisible(false);
+
+ if (showHsb)
+ {
+ hsb.setVisible(true);
+ hsb.setBounds(new Rectangle(x2, y3, x3 - x2, y4 - y3));
+ }
+ else if (hsb != null)
+ hsb.setVisible(false);
+
+ if (upperLeft != null)
+ upperLeft.setBounds(new Rectangle(x1, y1, x2 - x1, y2 - y1));
+
+ if (upperRight != null)
+ upperRight.setBounds(new Rectangle(x3, y1, x4 - x3, y2 - y1));
+
+ if (lowerLeft != null)
+ lowerLeft.setBounds(new Rectangle(x1, y3, x2 - x1, y4 - y3));
+
+ if (lowerRight != null)
+ lowerRight.setBounds(new Rectangle(x3, y3, x4 - x3, y4 - y3));
+ }
+
+ /**
+ * Returns the bounds of the border around a ScrollPane's viewport.
+ *
+ * @param scrollPane the ScrollPane for which's viewport the border
+ * is requested
+ *
+ * @deprecated As of Swing 1.1 replaced by
+ * {@link javax.swing.JScrollPane#getViewportBorderBounds}.
+ */
+ public Rectangle getViewportBorderBounds(JScrollPane scrollPane)
+ {
+ return null;
+ }
+
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Scrollable.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Scrollable.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Scrollable.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Scrollable.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,106 @@
+/* Scrollable.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import java.awt.Dimension;
+import java.awt.Rectangle;
+
+/**
+ * Defines the method that a component should implement to behave nicely
+ * in {@link JScrollPane}s. Note that this is not required for a component
+ * to be used in a <code>JScrollPane</code>, but can highly improve the
+ * user experience when scrolling the component.
+ */
+public interface Scrollable
+{
+ Dimension getPreferredScrollableViewportSize();
+
+ /**
+ * Return the preferred scrolling amount (in pixels) for the given
+ * scrolling direction and orientation when scrolling in small amounts
+ * like table lines.
+ *
+ * @param visibleRect the currently visible part of the component.
+ * @param orientation the scrolling orientation
+ * @param direction the scrolling direction (negative - up, positive -down).
+ * The values greater than one means that more mouse wheel or similar
+ * events were generated, and hence it is better to scroll the longer
+ * distance.
+ *
+ * @return the preferred scrolling distance, negative if up or left.
+ */
+ int getScrollableUnitIncrement(Rectangle visibleRect, int orientation,
+ int direction);
+
+ /**
+ * Return the preferred scrolling amount (in pixels) for the given
+ * scrolling direction and orientation when scrolling in large amounts
+ * (pages).
+ *
+ * @param visibleRect the currently visible part of the component.
+ * @param orientation the scrolling orientation
+ * @param direction the scrolling direction (negative - up, positive -down).
+ * The values greater than one means that more mouse wheel or similar
+ * events were generated, and hence it is better to scroll the longer
+ * distance.
+ *
+ * @return the preferred scrolling distance, negative if up or left.
+ */
+ int getScrollableBlockIncrement(Rectangle visibleRect, int orientation,
+ int direction);
+
+ /**
+ * Return true if the width of the scrollable is always equal to the
+ * view, where it is displayed, width (for instance, the text area with
+ * the word wrap). In such case, the horizontal scrolling should not be
+ * performed.
+ *
+ * @return true is no horizontal scrolling is assumed, faster otherwise.
+ */
+ boolean getScrollableTracksViewportWidth();
+
+ /**
+ * Return true if the height of the scrollable is always equal to the view,
+ * where it is displayed, height.In such case, the vertical scrolling should
+ * not be performed.
+ *
+ * @return true is no horizontal scrolling is assumed, faster otherwise.
+ */
+ boolean getScrollableTracksViewportHeight();
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SingleSelectionModel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SingleSelectionModel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SingleSelectionModel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SingleSelectionModel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,103 @@
+/* SingleSelectionModel.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+/**
+ * A data model that is used in components that support at most one
+ * selected element, like {@link JTabbedPane}, {@link JMenu} and
+ * {@link JPopupMenu}.
+ *
+ * @author Andrew Selkirk
+ */
+public interface SingleSelectionModel
+{
+ /**
+ * Returns the selected index or <code>-1</code> if there is no selection.
+ *
+ * @return The selected index.
+ *
+ * @see #setSelectedIndex(int)
+ */
+ int getSelectedIndex();
+
+ /**
+ * Sets the selected index and, if this is different to the previous
+ * selection, sends a {@link ChangeEvent} to all registered listeners.
+ *
+ * @param index the index (use <code>-1</code> to represent no selection).
+ *
+ * @see #getSelectedIndex()
+ * @see #clearSelection
+ */
+ void setSelectedIndex(int index);
+
+ /**
+ * Clears the selection by setting the selected index to <code>-1</code> and
+ * sends a {@link ChangeEvent} to all registered listeners. If the selected
+ * index is already <code>-1</code>, this method does nothing.
+ */
+ void clearSelection();
+
+ /**
+ * Returns <code>true</code> if there is a selection, and <code>false</code>
+ * otherwise.
+ *
+ * @return A boolean.
+ */
+ boolean isSelected();
+
+ /**
+ * Registers a listener to receive {@link ChangeEvent} notifications from
+ * this model whenever the selected index changes.
+ *
+ * @param listener the listener to add.
+ */
+ void addChangeListener(ChangeListener listener);
+
+ /**
+ * Deregisters a listener so that it no longer receives {@link ChangeEvent}
+ * notifications from this model.
+ *
+ * @param listener the listener to remove.
+ */
+ void removeChangeListener(ChangeListener listener);
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SizeRequirements.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SizeRequirements.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SizeRequirements.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SizeRequirements.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,523 @@
+/* SizeRequirements.java --
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import java.io.Serializable;
+
+/**
+ * This class calculates information about the size and position requirements
+ * of components.
+ *
+ * Two types of layout are supported:
+ * <ul>
+ * <li>Tiled: the components are placed at position top-left or bottom-right
+ * position within their allocated space</li>
+ * <li>Aligned: the components are placed aligned in their allocated space
+ * according to their alignment value</li>
+ * </ul>
+ *
+ * @author Andrew Selkirk
+ * @author Roman Kennke (roman at kennke.org)
+ */
+public class SizeRequirements implements Serializable
+{
+ /**
+ * The serialVersionUID.
+ */
+ private static final long serialVersionUID = 9217749429906736553L;
+
+ /**
+ * The minimum reasonable width or height of a component.
+ */
+ public int minimum;
+
+ /**
+ * The preferred width or height of a component.
+ */
+ public int preferred;
+
+ /**
+ * The maximum reasonable width or height of a component.
+ */
+ public int maximum;
+
+ /**
+ * The horizontal or vertical alignment of a component.
+ */
+ public float alignment;
+
+ /**
+ * Creates a SizeRequirements object with minimum, preferred and
+ * maximum size set to zero, and an alignment value of 0.5.
+ */
+ public SizeRequirements()
+ {
+ this (0, 0, 0, 0.5F);
+ }
+
+ /**
+ * Creates a SizeRequirements object with the specified minimum,
+ * preferred, maximum and alignment values.
+ *
+ * @param min the minimum reasonable size of the component
+ * @param pref the preferred size of the component
+ * @param max the maximum size of the component
+ * @param align the alignment of the component
+ */
+ public SizeRequirements(int min, int pref, int max, float align)
+ {
+ minimum = min;
+ preferred = pref;
+ maximum = max;
+ alignment = align;
+ }
+
+ /**
+ * Returns a String representation of this SizeRequirements object,
+ * containing information about the minimum, preferred, maximum and
+ * alignment value.
+ *
+ * @return a String representation of this SizeRequirements object
+ */
+ public String toString()
+ {
+ StringBuilder b = new StringBuilder();
+ b.append("<[");
+ b.append(minimum);
+ b.append(',');
+ b.append(preferred);
+ b.append(',');
+ b.append(maximum);
+ b.append("]@");
+ b.append(alignment);
+ b.append('>');
+ return b.toString();
+ }
+
+ /**
+ * Calculates how much space is nessecary to place a set of components
+ * end-to-end. The size requirements of the components is specified
+ * in <code>children</code>.
+ *
+ * @param children the SizeRequirements of each of the components
+ *
+ * @return the SizeRequirements that describe how much space is needed
+ * to place the components end-to-end
+ */
+ public static SizeRequirements
+ getTiledSizeRequirements(SizeRequirements[] children)
+ {
+ long minimum = 0;
+ long preferred = 0;
+ long maximum = 0;
+ for (int i = 0; i < children.length; i++)
+ {
+ minimum += children[i].minimum;
+ preferred += children[i].preferred;
+ maximum += children[i].maximum;
+ }
+ // Overflow check.
+ if (minimum > Integer.MAX_VALUE)
+ minimum = Integer.MAX_VALUE;
+ if (preferred > Integer.MAX_VALUE)
+ preferred = Integer.MAX_VALUE;
+ if (maximum > Integer.MAX_VALUE)
+ maximum = Integer.MAX_VALUE;
+ SizeRequirements result = new SizeRequirements((int) minimum,
+ (int) preferred,
+ (int) maximum,
+ 0.5F);
+ return result;
+ }
+
+ /**
+ * Calculates how much space is nessecary to place a set of components
+ * aligned according to their alignment value.
+ * The size requirements of the components is specified in
+ * <code>children</code>.
+ *
+ * @param children the SizeRequirements of each of the components
+ *
+ * @return the SizeRequirements that describe how much space is needed
+ * to place the components aligned
+ */
+ public static SizeRequirements
+ getAlignedSizeRequirements(SizeRequirements[] children)
+ {
+ float minLeft = 0;
+ float minRight = 0;
+ float prefLeft = 0;
+ float prefRight = 0;
+ float maxLeft = 0;
+ float maxRight = 0;
+ for (int i = 0; i < children.length; i++)
+ {
+ float myMinLeft = children[i].minimum * children[i].alignment;
+ float myMinRight = children[i].minimum - myMinLeft;
+ minLeft = Math.max(myMinLeft, minLeft);
+ minRight = Math.max(myMinRight, minRight);
+ float myPrefLeft = children[i].preferred * children[i].alignment;
+ float myPrefRight = children[i].preferred - myPrefLeft;
+ prefLeft = Math.max(myPrefLeft, prefLeft);
+ prefRight = Math.max(myPrefRight, prefRight);
+ float myMaxLeft = children[i].maximum * children[i].alignment;
+ float myMaxRight = children[i].maximum - myMaxLeft;
+ maxLeft = Math.max(myMaxLeft, maxLeft);
+ maxRight = Math.max(myMaxRight, maxRight);
+ }
+ int minSize = (int) (minLeft + minRight);
+ int prefSize = (int) (prefLeft + prefRight);
+ int maxSize = (int) (maxLeft + maxRight);
+ float align = prefLeft / (prefRight + prefLeft);
+ if (Float.isNaN(align))
+ align = 0;
+ return new SizeRequirements(minSize, prefSize, maxSize, align);
+ }
+
+ /**
+ * Calculate the offsets and spans of the components, when they should
+ * be placed end-to-end.
+ *
+ * You must specify the amount of allocated space in
+ * <code>allocated</code>, the total size requirements of the set of
+ * components in <code>total</code> (this can be calculated using
+ * {@link #getTiledSizeRequirements} and the size requirements of the
+ * components in <code>children</code>.
+ *
+ * The calculated offset and span values for each component are then
+ * stored in the arrays <code>offsets</code> and <code>spans</code>.
+ *
+ * The components are placed in the forward direction, beginning with
+ * an offset of 0.
+ *
+ * @param allocated the amount of allocated space
+ * @param total the total size requirements of the components
+ * @param children the size requirement of each component
+ * @param offsets will hold the offset values for each component
+ * @param spans will hold the span values for each component
+ */
+ public static void calculateTiledPositions(int allocated,
+ SizeRequirements total,
+ SizeRequirements[] children,
+ int[] offsets, int[] spans)
+ {
+ calculateTiledPositions(allocated, total, children, offsets, spans, true);
+ }
+
+ /**
+ * Calculate the offsets and spans of the components, when they should
+ * be placed end-to-end.
+ *
+ * You must specify the amount of allocated space in
+ * <code>allocated</code>, the total size requirements of the set of
+ * components in <code>total</code> (this can be calculated using
+ * {@link #getTiledSizeRequirements} and the size requirements of the
+ * components in <code>children</code>.
+ *
+ * The calculated offset and span values for each component are then
+ * stored in the arrays <code>offsets</code> and <code>spans</code>.
+ *
+ * Depending on the value of <code>forward</code> the components are
+ * placed in the forward direction (left-right or top-bottom), where
+ * the offsets begin with 0, or in the reverse direction
+ * (right-left or bottom-top).
+ *
+ * @param allocated the amount of allocated space
+ * @param total the total size requirements of the components
+ * @param children the size requirement of each component
+ * @param offsets will hold the offset values for each component
+ * @param spans will hold the span values for each component
+ * @param forward whether the components should be placed in the forward
+ * direction (left-right or top-bottom) or reverse direction
+ * (right-left or bottom-top)
+ */
+ public static void calculateTiledPositions(int allocated,
+ SizeRequirements total,
+ SizeRequirements[] children,
+ int[] offsets, int[] spans,
+ boolean forward)
+ {
+ int span = 0;
+ if (forward)
+ {
+ int offset = 0;
+ for (int i = 0; i < children.length; i++)
+ {
+ offsets[i] = offset;
+ spans[i] = children[i].preferred;
+ span += spans[i];
+ offset += children[i].preferred;
+ }
+ }
+ else
+ {
+ int offset = allocated;
+ for (int i = 0; i < children.length; i++)
+ {
+ offset -= children[i].preferred;
+ offsets[i] = offset;
+ span += spans[i];
+ spans[i] = children[i].preferred;
+ }
+ }
+ // Adjust spans so that we exactly fill the allocated region. If
+ if (span > allocated)
+ adjustSmaller(allocated, children, spans, span);
+ else if (span < allocated)
+ adjustGreater(allocated, children, spans, span);
+
+ // Adjust offsets.
+ if (forward)
+ {
+ int offset = 0;
+ for (int i = 0; i < children.length; i++)
+ {
+ offsets[i] = offset;
+ offset += spans[i];
+ }
+ }
+ else
+ {
+ int offset = allocated;
+ for (int i = 0; i < children.length; i++)
+ {
+ offset -= spans[i];
+ offsets[i] = offset;
+ }
+ }
+ }
+
+ private static void adjustSmaller(int allocated, SizeRequirements[] children,
+ int[] spans, int span)
+ {
+ // Sum up (prefSize - minSize) over all children
+ int sumDelta = 0;
+ for (int i = 0; i < children.length; i++)
+ sumDelta += children[i].preferred - children[i].minimum;
+
+ // If we have sumDelta == 0, then all components have prefSize == maxSize
+ // and we can't do anything about it.
+ if (sumDelta == 0)
+ return;
+
+ // Adjust all sizes according to their preferred and minimum sizes.
+ for (int i = 0; i < children.length; i++)
+ {
+ double factor = ((double) (children[i].preferred - children[i].minimum))
+ / ((double) sumDelta);
+ // In case we have a sumDelta of 0, the factor should also be 0.
+ if (Double.isNaN(factor))
+ factor = 0;
+ spans[i] -= factor * (span - allocated);
+ }
+ }
+
+ private static void adjustGreater(int allocated, SizeRequirements[] children,
+ int[] spans, int span)
+ {
+ // Sum up (maxSize - prefSize) over all children
+ long sumDelta = 0;
+ for (int i = 0; i < children.length; i++)
+ {
+ sumDelta += children[i].maximum - children[i].preferred;
+ }
+
+ // If we have sumDelta == 0, then all components have prefSize == maxSize
+ // and we can't do anything about it.
+ if (sumDelta == 0)
+ return;
+
+ // Adjust all sizes according to their preferred and minimum sizes.
+ for (int i = 0; i < children.length; i++)
+ {
+ double factor = ((double) (children[i].maximum - children[i].preferred))
+ / ((double) sumDelta);
+ spans[i] += factor * (allocated - span);
+ }
+ }
+
+ /**
+ * Calculate the offsets and spans of the components, when they should
+ * be placed end-to-end.
+ *
+ * You must specify the amount of allocated space in
+ * <code>allocated</code>, the total size requirements of the set of
+ * components in <code>total</code> (this can be calculated using
+ * {@link #getTiledSizeRequirements} and the size requirements of the
+ * components in <code>children</code>.
+ *
+ * The calculated offset and span values for each component are then
+ * stored in the arrays <code>offsets</code> and <code>spans</code>.
+ *
+ * The components are tiled in the forward direction, beginning with
+ * an offset of 0.
+ *
+ * @param allocated the amount of allocated space
+ * @param total the total size requirements of the components
+ * @param children the size requirement of each component
+ * @param offsets will hold the offset values for each component
+ * @param spans will hold the span values for each component
+ */
+ public static void calculateAlignedPositions(int allocated,
+ SizeRequirements total,
+ SizeRequirements[] children,
+ int[] offsets, int[] spans)
+ {
+ calculateAlignedPositions(allocated, total, children, offsets, spans,
+ true);
+ }
+
+ /**
+ * Calculate the offsets and spans of the components, when they should
+ * be placed end-to-end.
+ *
+ * You must specify the amount of allocated space in
+ * <code>allocated</code>, the total size requirements of the set of
+ * components in <code>total</code> (this can be calculated using
+ * {@link #getTiledSizeRequirements} and the size requirements of the
+ * components in <code>children</code>.
+ *
+ * The calculated offset and span values for each component are then
+ * stored in the arrays <code>offsets</code> and <code>spans</code>.
+ *
+ * Depending on the value of <code>forward</code> the components are
+ * placed in the forward direction (left-right or top-bottom), where
+ * the offsets begin with 0, or in the reverse direction
+ * (right-left or bottom-top).
+ *
+ * @param allocated the amount of allocated space
+ * @param total the total size requirements of the components
+ * @param children the size requirement of each component
+ * @param spans will hold the span values for each component
+ * @param forward whether the components should be placed in the forward
+ * direction (left-right or top-bottom) or reverse direction
+ * (right-left or bottom-top)
+ */
+ public static void calculateAlignedPositions(int allocated,
+ SizeRequirements total,
+ SizeRequirements[] children,
+ int[] offset, int[] spans,
+ boolean forward)
+ {
+ // First we compute the position of the baseline.
+ float baseline = allocated * total.alignment;
+
+ // Now we can layout the components along the baseline.
+ for (int i = 0; i < children.length; i++)
+ {
+ float align = children[i].alignment;
+ // Try to fit the component into the available space.
+ int[] spanAndOffset = new int[2];
+ if (align < .5F || baseline == 0)
+ adjustFromRight(children[i], baseline, allocated, spanAndOffset);
+ else
+ adjustFromLeft(children[i], baseline, allocated, spanAndOffset);
+ spans[i] = spanAndOffset[0];
+ offset[i] = spanAndOffset[1];
+ }
+ }
+
+ /**
+ * Adjusts the span and offset of a component for the aligned layout.
+ *
+ * @param reqs
+ * @param baseline
+ * @param allocated
+ * @param spanAndOffset
+ */
+ private static void adjustFromRight(SizeRequirements reqs, float baseline,
+ int allocated, int[] spanAndOffset)
+ {
+ float right = allocated - baseline;
+ // If the resulting span exceeds the maximum of the component, then adjust
+ // accordingly.
+ float maxRight = ((float) reqs.maximum) * (1.F - reqs.alignment);
+ if (right / (1.F - reqs.alignment) > reqs.maximum)
+ right = maxRight;
+ // If we have not enough space on the left side, then adjust accordingly.
+ if (right / (1.F - reqs.alignment) * reqs.alignment > allocated - baseline)
+ right = ((float) (allocated - baseline))
+ / reqs.alignment * (1.F - reqs.alignment);
+
+ spanAndOffset[0] = (int) (right / (1.F - reqs.alignment));
+ spanAndOffset[1] = (int) (baseline - spanAndOffset[0] * reqs.alignment);
+ }
+
+ /**
+ * Adjusts the span and offset of a component for the aligned layout.
+ *
+ * @param reqs
+ * @param baseline
+ * @param allocated
+ * @param spanAndOffset
+ */
+ private static void adjustFromLeft(SizeRequirements reqs, float baseline,
+ int allocated, int[] spanAndOffset)
+ {
+ float left = baseline;
+ // If the resulting span exceeds the maximum of the component, then adjust
+ // accordingly.
+ float maxLeft = ((float) reqs.maximum) * reqs.alignment;
+ if (left / reqs.alignment > reqs.maximum)
+ left = maxLeft;
+ // If we have not enough space on the right side, then adjust accordingly.
+ if (left / reqs.alignment * (1.F - reqs.alignment) > allocated - baseline)
+ left = ((float) (allocated - baseline))
+ / (1.F - reqs.alignment) * reqs.alignment;
+
+ spanAndOffset[0] = (int) (left / reqs.alignment);
+ spanAndOffset[1] = (int) (baseline - spanAndOffset[0] * reqs.alignment);
+ }
+
+ /**
+ * Returns an array of new preferred sizes for the children based on
+ * <code>delta</code>. <code>delta</code> specifies a change in the
+ * allocated space. The sizes of the children will be shortened or
+ * lengthened to accomodate the new allocation.
+ *
+ * @param delta the change of the size of the total allocation for
+ * the components
+ * @param children the size requirements of each component
+ *
+ * @return the new preferred sizes for each component
+ */
+ public static int[] adjustSizes(int delta, SizeRequirements[] children)
+ {
+ return null; // TODO
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SizeSequence.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SizeSequence.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SizeSequence.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SizeSequence.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,221 @@
+/* SizeSequence.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import java.util.Arrays;
+
+/**
+ * A sequence of values that represent the dimensions (widths or heights) of
+ * some collection of items (for example, the widths of the columns in a table).
+ *
+ * @author Andrew Selkirk
+ */
+public class SizeSequence
+{
+ // TODO: Sun's API specification for this class contains an implementation
+ // note regarding the encoding for the element sizes. We currently use the
+ // simple size encoding but we should look at improving this.
+
+ /** Storage for the element sizes. */
+ private int[] sizes;
+
+ /**
+ * Creates a new empty <code>SizeSequence</code> instance.
+ */
+ public SizeSequence()
+ {
+ sizes = new int[0];
+ }
+
+ /**
+ * Creates a new <code>SizeSequence</code> instance with the specified number
+ * of elements, each having a size of 0.
+ *
+ * @param numEntries the number of elements.
+ */
+ public SizeSequence(int numEntries)
+ {
+ this(numEntries, 0);
+ }
+
+ /**
+ * Creates a new <code>SizeSequence</code> instance with the specified number
+ * of elements all having the same size (<code>value</code>).
+ *
+ * @param numEntries the number of elements.
+ * @param value the value for each element.
+ */
+ public SizeSequence(int numEntries, int value)
+ {
+ sizes = new int[numEntries];
+ Arrays.fill(sizes, value);
+ }
+
+ /**
+ * Creates a new <code>SizeSequence</code> instance using the specified
+ * element sizes.
+ *
+ * @param sizes the element sizes (<code>null</code> not permitted).
+ */
+ public SizeSequence(int[] sizes)
+ {
+ this.sizes = (int[]) sizes.clone();
+ }
+
+ /**
+ * Sets the size of the element at the specified index.
+ *
+ * @param index the index.
+ * @param size the size.
+ */
+ public void setSize(int index, int size)
+ {
+ if (index >= 0 && index < sizes.length)
+ sizes[index] = size;
+ }
+
+ /**
+ * Returns the index of the element that contains the specified position.
+ *
+ * @param position the position.
+ *
+ * @return The index of the element that contains the specified position.
+ */
+ public int getIndex(int position)
+ {
+ int i = 0;
+ int runningTotal = 0;
+ while (i < sizes.length && position >= runningTotal + sizes[i])
+ {
+ runningTotal += sizes[i];
+ i++;
+ }
+ return i;
+ }
+
+ /**
+ * Returns the size of the specified element.
+ *
+ * @param index the element index.
+ *
+ * @return The size of the specified element.
+ */
+ public int getSize(int index)
+ {
+ return sizes[index];
+ }
+
+ /**
+ * Sets the sizes for the elements in the sequence.
+ *
+ * @param sizes the element sizes (<code>null</code> not permitted).
+ */
+ public void setSizes(int[] sizes)
+ {
+ this.sizes = (int[]) sizes.clone();
+ }
+
+ /**
+ * Returns an array containing the sizes for all the elements in the sequence.
+ *
+ * @return The element sizes.
+ */
+ public int[] getSizes()
+ {
+ return (int[]) sizes.clone();
+ }
+
+ /**
+ * Returns the position of the specified element.
+ *
+ * @param index the element index.
+ *
+ * @return The position.
+ */
+ public int getPosition(int index)
+ {
+ int position;
+ int loop;
+ position = 0;
+ for (loop = 0; loop < index; loop++)
+ position += sizes[loop];
+ return position;
+
+ }
+
+ /**
+ * Inserts new entries into the sequence at the <code>start</code> position.
+ * There are <code>length</code> new entries each having the specified
+ * <code>value</code>.
+ *
+ * @param start the start element.
+ * @param length the number of elements to insert.
+ * @param value the size for each of the new elements.
+ */
+ public void insertEntries(int start, int length, int value)
+ {
+ int[] newSizes = new int[sizes.length + length];
+ System.arraycopy(sizes, 0, newSizes, 0, start);
+ for (int i = start; i < start + length; i++)
+ newSizes[i] = value;
+ System.arraycopy(sizes, start, newSizes, start + length,
+ sizes.length - start);
+ sizes = newSizes;
+ }
+
+ /**
+ * Removes the element(s) at index <code>start</code> (the number of elements
+ * removed is <code>length</code>).
+ *
+ * @param start the index of the first element to remove.
+ * @param length the number of elements to remove.
+ */
+ public void removeEntries(int start, int length)
+ {
+ // Sanity check.
+ if ((start + length) > sizes.length)
+ throw new IllegalArgumentException("Specified start/length that "
+ + "is greater than available sizes");
+
+ int[] newSizes = new int[sizes.length - length];
+ System.arraycopy(sizes, 0, newSizes, 0, start);
+ System.arraycopy(sizes, start + length, newSizes, start,
+ sizes.length - start - length);
+ sizes = newSizes;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SortingFocusTraversalPolicy.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SortingFocusTraversalPolicy.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SortingFocusTraversalPolicy.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SortingFocusTraversalPolicy.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,333 @@
+/* SortingFocusTraversalPolicy.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.awt.Component;
+import java.awt.Container;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.TreeSet;
+
+/**
+ * @author Graydon Hoare
+ * @author Michael Koch
+ *
+ * @since 1.4
+ */
+public class SortingFocusTraversalPolicy
+ extends InternalFrameFocusTraversalPolicy
+{
+ /**
+ * The comparator used to sort elements in the focus traversal cycle
+ * managed by this class.
+ */
+ Comparator comparator;
+
+ /**
+ * <p>Whether or not to perform an "implicit DownCycle" when selecting
+ * successor components within a focus cycle.</p>
+ *
+ * <p>When this is true, requesting the "next" component following a
+ * component which is a focus cycle root (and, necessarily, a container)
+ * will enter the focus cycle root of that container, and return its
+ * default focus.</p>
+ *
+ * <p>When this property is false, requesting the "next" component will
+ * simply advance within the containing focus cycle, subject to the
+ * {@link #comparator} order and the {@link #accept} judgment.</p>
+ *
+ * @see #getImplicitDownCycleTraversal()
+ */
+ boolean implicitDownCycleTraversal = true;
+
+ /**
+ * Creates a new <code>SortingFocusTraversalPolicy</code> with no
+ * comparator set.
+ */
+ protected SortingFocusTraversalPolicy()
+ {
+ // Do nothing here.
+ }
+
+ /**
+ * Creates a new <code>SortingFocusTraversalPolicy</code> with the given
+ * comparator set.
+ *
+ * @param comparator the comparator to set
+ */
+ public SortingFocusTraversalPolicy(Comparator comparator)
+ {
+ this.comparator = comparator;
+ }
+
+ /**
+ * Decide whether a component is an acceptable focus owner.
+ *
+ * @param comp The component which is a candidate for focus ownership.
+ *
+ * @return true if the component is focusable, displayable, visible, and
+ * enabled; otherwise false
+ */
+ protected boolean accept(Component comp)
+ {
+ return (comp.isVisible()
+ && comp.isDisplayable()
+ && comp.isEnabled()
+ && comp.isFocusable());
+ }
+
+ /**
+ * Get the current value of the {@link #comparator} property.
+ *
+ * @return the current value of the property
+ *
+ * @see #setComparator
+ */
+ protected Comparator getComparator()
+ {
+ return comparator;
+ }
+
+ /**
+ * Set the current value of the {@link #comparator} property.
+ *
+ * @param comparator the new value of the property
+ *
+ * @see #getComparator
+ */
+ protected void setComparator(Comparator comparator)
+ {
+ this.comparator = comparator;
+ }
+
+ private TreeSet getSortedCycle(Container root, TreeSet set)
+ {
+ if (set == null)
+ set = (getComparator() == null
+ ? new TreeSet()
+ : new TreeSet(getComparator()));
+
+ if (root != null)
+ {
+ Component[] comps = root.getComponents();
+ for (int i = 0; i < comps.length; ++i)
+ {
+ Component c = comps[i];
+ if (accept(c))
+ set.add(c);
+ if (c instanceof Container)
+ getSortedCycle((Container) c, set);
+ }
+ }
+ return set;
+ }
+
+ /**
+ * Return the component which follows the specified component in this
+ * focus cycle, relative to the order imposed by {@link
+ * #comparator}. Candidate components are only considered if they are
+ * accepted by the {@link #accept} method.
+ *
+ * If {@link #getImplicitDownCycleTraversal} is <code>true</code> and the
+ * <code>comp</code> is a focus cycle root, an "implicit DownCycle"
+ * occurs and the method returns the
+ * <code>getDefaultComponent(comp)</code>.
+ *
+ * @param root the focus cycle root to search for a successor within
+ * @param comp the component to search for the successor of
+ *
+ * @return the component following the specified component under
+ * the specified root, or null if no such component is found
+ *
+ * @throws IllegalArgumentException if either argument is null, or
+ * if the root is not a focus cycle root of the component
+ */
+ public Component getComponentAfter(Container root,
+ Component comp)
+ {
+ if (comp == null || root == null || !comp.isFocusCycleRoot(root))
+ throw new IllegalArgumentException();
+
+ if (getImplicitDownCycleTraversal()
+ && comp instanceof Container
+ && ((Container)comp).isFocusCycleRoot())
+ {
+ return getDefaultComponent((Container) comp);
+ }
+
+ TreeSet set = getSortedCycle(root, null);
+ Iterator i = set.iterator();
+ while (i.hasNext())
+ {
+ Component c = (Component) i.next();
+ if (c != null && c.equals(comp))
+ {
+ if (i.hasNext())
+ return (Component) i.next();
+ break;
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ * Return the component which precedes the specified component in this
+ * focus cycle, relative to the order imposed by {@link
+ * #comparator}. Candidate components are only considered if they are
+ * accepted by the {@link #accept} method.
+ *
+ * @param root the focus cycle root to search for a predecessor within
+ * @param comp the component to search for the predecessor of
+ *
+ * @return the component preceding the specified component under the
+ * specified root, or null if no such component is found
+ *
+ * @throws IllegalArgumentException if either argument is null, or
+ * if the root is not a focus cycle root of the component
+ */
+ public Component getComponentBefore(Container root,
+ Component comp)
+ {
+ if (comp == null || root == null || !comp.isFocusCycleRoot(root))
+ throw new IllegalArgumentException();
+ TreeSet set = getSortedCycle(root, null);
+ Iterator i = set.iterator();
+ Component prev = null;
+ while (i.hasNext())
+ {
+ Component c = (Component) i.next();
+ if (c != null && c.equals(comp))
+ break;
+ prev = c;
+ }
+ return prev;
+ }
+
+ /**
+ * Return the default component of <code>root</code>, which is by default
+ * the same as the first component, returned by {@link
+ * #getFirstComponent}.
+ *
+ * @param root the focus cycle root to return the default component of
+ *
+ * @return the default focus component for <code>root</code>
+ *
+ * @throws IllegalArgumentException if root is null
+ */
+ public Component getDefaultComponent(Container root)
+ {
+ return getFirstComponent(root);
+ }
+
+ /**
+ * Return the first focusable component of the focus cycle root
+ * <code>comp</code> under the ordering imposed by the {@link
+ * #comparator} property. Candidate components are only considered if
+ * they are accepted by the {@link #accept} method.
+ *
+ * @param root the focus cycle root to search for the first component of
+ *
+ * @return the first component under <code>root</code>, or null if
+ * no components are found.
+ *
+ * @throws IllegalArgumentException if root is null
+ */
+ public Component getFirstComponent(Container root)
+ {
+ if (root == null)
+ throw new IllegalArgumentException();
+ TreeSet set = getSortedCycle(root, null);
+ Iterator i = set.iterator();
+ if (i.hasNext())
+ return (Component) i.next();
+ return null;
+ }
+
+ /**
+ * Return the last focusable component of the focus cycle root
+ * <code>comp</code> under the ordering imposed by the {@link
+ * #comparator} property. Candidate components are only considered if
+ * they are accepted by the {@link #accept} method.
+ *
+ * @param root the focus cycle root to search for the last component of
+ *
+ * @return the last component under <code>root</code>, or null if
+ * no components are found.
+ *
+ * @throws IllegalArgumentException if root is null
+ */
+ public Component getLastComponent(Container root)
+ {
+ if (root == null)
+ throw new IllegalArgumentException();
+ TreeSet set = getSortedCycle(root, null);
+ Iterator i = set.iterator();
+ Component last = null;
+ while (i.hasNext())
+ last = (Component) i.next();
+ return last;
+ }
+
+ /**
+ * Return the current value of the {@link #implicitDownCycleTraversal}
+ * property.
+ *
+ * @return the current value of the property
+ *
+ * @see #setImplicitDownCycleTraversal
+ */
+ public boolean getImplicitDownCycleTraversal()
+ {
+ return implicitDownCycleTraversal;
+ }
+
+ /**
+ * Set the current value of the {@link #implicitDownCycleTraversal}
+ * property.
+ *
+ * @param down the new value of the property
+ *
+ * @see #getImplicitDownCycleTraversal
+ */
+ public void setImplicitDownCycleTraversal(boolean down)
+ {
+ implicitDownCycleTraversal = down;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpinnerDateModel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpinnerDateModel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpinnerDateModel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpinnerDateModel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,317 @@
+/* SpinnerDateModel.java --
+ Copyright (C) 2002, 2004, 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.io.Serializable;
+import java.util.Calendar;
+import java.util.Date;
+
+import javax.swing.event.ChangeEvent;
+
+/**
+ * A date model used by the {@link JSpinner} component. This implements a
+ * spinner model for dates, rotating a calendar field such as month, year,
+ * day, week, hour, minute.
+ *
+ * @author Sven de Marothy
+ * @since 1.4
+ */
+public class SpinnerDateModel extends AbstractSpinnerModel
+ implements Serializable
+{
+ /** The current date. */
+ private Calendar date;
+
+ /**
+ * A constraint on the start or earliest permitted date (<code>null</code>
+ * for no minimum).
+ */
+ private Comparable start;
+
+ /**
+ * A constraint on the end or latest permitted date (<code>null</code> for no
+ * maximum).
+ */
+ private Comparable end;
+
+ /**
+ * The calendar field used to calculate the previous or next date.
+ */
+ private int calendarField;
+
+ /**
+ * For compatability with Sun's JDK
+ */
+ private static final long serialVersionUID = -4802518107105940612L;
+
+ /**
+ * Constructs a <code>SpinnerDateModel</code> using the current date,
+ * no start or end limit, and {@link Calendar#DAY_OF_MONTH} as the calendar
+ * field.
+ */
+ public SpinnerDateModel()
+ {
+ this(new Date(), null, null, Calendar.DAY_OF_MONTH);
+ }
+
+ /**
+ * Constructs a <code>SpinnerDateModel</code> with the specified value, lower
+ * and upper bounds, and which spins the specified calendar field.
+ * <p>
+ * The <code>start</code> and <code>end</code> limits must have a
+ * <code>compareTo</code> method that supports instances of {@link Date}, but
+ * do not themselves need to be instances of {@link Date} (although typically
+ * they are).
+ *
+ * @param value the initial value/date (<code>null</code> not permitted).
+ * @param start a constraint that specifies the earliest permitted date
+ * value, or <code>null</code> for no lower limit.
+ * @param end a constraint that specifies the latest permitted date value,
+ * or <code>null</code> for no upper limit.
+ * @param calendarField the <code>Calendar</code> field to spin,
+ * (Calendar.ZONE_OFFSET and Calendar.DST_OFFSET are invalid)
+ */
+ public SpinnerDateModel(Date value, Comparable start, Comparable end,
+ int calendarField)
+ {
+ if (value == null)
+ throw new IllegalArgumentException("Null 'value' argument.");
+ if (start != null && start.compareTo(value) > 0)
+ throw new IllegalArgumentException("Require value on or after start.");
+ if (end != null && end.compareTo(value) < 0)
+ throw new IllegalArgumentException("Require value on or before end.");
+ date = Calendar.getInstance();
+ date.setTime(value);
+ this.start = start;
+ this.end = end;
+ setCalendarField(calendarField);
+ }
+
+ /**
+ * Returns the {@link Calendar} field used to calculate the previous and
+ * next dates in the sequence.
+ *
+ * @return The date field code.
+ */
+ public int getCalendarField()
+ {
+ return calendarField;
+ }
+
+ /**
+ * Returns the current date/time.
+ *
+ * @return The current date/time (never <code>null</code>).
+ *
+ * @see #getValue()
+ */
+ public Date getDate()
+ {
+ return date.getTime();
+ }
+
+ /**
+ * Returns the lower limit on the date/time value, or <code>null</code> if
+ * there is no minimum date/time.
+ *
+ * @return The lower limit.
+ *
+ * @see #setStart(Comparable)
+ */
+ public Comparable getStart()
+ {
+ return start;
+ }
+
+ /**
+ * Returns the upper limit on the date/time value, or <code>null</code> if
+ * there is no maximum date/time.
+ *
+ * @return The upper limit.
+ *
+ * @see #setEnd(Comparable)
+ */
+ public Comparable getEnd()
+ {
+ return end;
+ }
+
+ /**
+ * Returns the current date in the sequence (this method returns the same as
+ * {@link #getDate()}).
+ *
+ * @return The current date (never <code>null</code>).
+ */
+ public Object getValue()
+ {
+ return date.getTime();
+ }
+
+ /**
+ * Returns the next date in the sequence, or <code>null</code> if the
+ * next date is past the upper limit (if one is specified). The current date
+ * is not changed.
+ *
+ * @return The next date, or <code>null</code> if the current value is
+ * the latest date represented by the model.
+ *
+ * @see #getEnd()
+ */
+ public Object getNextValue()
+ {
+ Calendar nextCal = Calendar.getInstance();
+ nextCal.setTime(date.getTime());
+ nextCal.roll(calendarField, true);
+ Date nextDate = nextCal.getTime();
+ if (end != null)
+ if (end.compareTo(nextDate) < 0)
+ return null;
+ return nextDate;
+ }
+
+ /**
+ * Returns the previous date in the sequence, or <code>null</code> if the
+ * previous date is prior to the lower limit (if one is specified). The
+ * current date is not changed.
+ *
+ * @return The previous date, or <code>null</code> if the current value is
+ * the earliest date represented by the model.
+ *
+ * @see #getStart()
+ */
+ public Object getPreviousValue()
+ {
+ Calendar prevCal = Calendar.getInstance();
+ prevCal.setTime(date.getTime());
+ prevCal.roll(calendarField, false);
+ Date prevDate = prevCal.getTime();
+ if (start != null)
+ if (start.compareTo(prevDate) > 0)
+ return null;
+ return prevDate;
+ }
+
+ /**
+ * Sets the date field to change when calculating the next and previous
+ * values. It must be a valid {@link Calendar} field, excluding
+ * {@link Calendar#ZONE_OFFSET} and {@link Calendar#DST_OFFSET}.
+ *
+ * @param calendarField the calendar field to set.
+ *
+ * @throws IllegalArgumentException if <code>calendarField</code> is not
+ * a valid code.
+ */
+ public void setCalendarField(int calendarField)
+ {
+ if (calendarField < 0 || calendarField >= Calendar.FIELD_COUNT
+ || calendarField == Calendar.ZONE_OFFSET
+ || calendarField == Calendar.DST_OFFSET)
+ throw new IllegalArgumentException("Illegal calendarField");
+
+ if (this.calendarField != calendarField)
+ {
+ this.calendarField = calendarField;
+ fireStateChanged();
+ }
+ }
+
+ /**
+ * Sets the lower limit for the date/time value and, if the new limit is
+ * different to the old limit, sends a {@link ChangeEvent} to all registered
+ * listeners. A <code>null</code> value is interpreted as "no lower limit".
+ * No check is made to ensure that the current date/time is on or after the
+ * new lower limit - the caller is responsible for ensuring that this
+ * relationship holds. In addition, the caller should ensure that
+ * <code>start</code> is {@link Serializable}.
+ *
+ * @param start the new lower limit for the date/time value
+ * (<code>null</code> permitted).
+ */
+ public void setStart(Comparable start)
+ {
+ if (this.start != start)
+ {
+ this.start = start;
+ fireStateChanged();
+ }
+ }
+
+ /**
+ * Sets the upper limit for the date/time value and, if the new limit is
+ * different to the old limit, sends a {@link ChangeEvent} to all registered
+ * listeners. A <code>null</code> value is interpreted as "no upper limit".
+ * No check is made to ensure that the current date/time is on or before the
+ * new upper limit - the caller is responsible for ensuring that this
+ * relationship holds. In addition, the caller should ensure that
+ * <code>end</code> is {@link Serializable}.
+ *
+ * @param end the new upper limit for the date/time value (<code>null</code>
+ * permitted).
+ */
+ public void setEnd(Comparable end)
+ {
+ if (this.end != end)
+ {
+ this.end = end;
+ fireStateChanged();
+ }
+ }
+
+ /**
+ * Sets the current date and, if the new value is different to the old
+ * value, sends a {@link ChangeEvent} to all registered listeners.
+ *
+ * @param value the new date (<code>null</code> not permitted, must be an
+ * instance of <code>Date</code>).
+ *
+ * @throws IllegalArgumentException if <code>value</code> is not an instance
+ * of <code>Date</code>.
+ */
+ public void setValue(Object value)
+ {
+ if (! (value instanceof Date) || value == null)
+ throw new IllegalArgumentException("Value not a date.");
+
+ if (!date.getTime().equals(value))
+ {
+ date.setTime((Date) value);
+ fireStateChanged();
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpinnerListModel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpinnerListModel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpinnerListModel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpinnerListModel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,295 @@
+/* SpinnerListModel.java -- A spinner model backed by a list or an array.
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.swing.event.ChangeEvent;
+
+/**
+ * An implementation of <code>SpinnerModel</code> which uses the values
+ * contained within a list or an array. The backing list or array is
+ * only stored as a reference within the class. As a result, changes
+ * made elsewhere to the members of the list or array are reflected by
+ * this model.
+ * <p>
+ *
+ * The model itself inherits a list of <code>ChangeListener</code>s from
+ * <code>AbstractSpinnerModel</code>. As this code is unaware of changes
+ * made to the backing list or array, it is the responsibility of the
+ * application using the model to invoke <code>fireStateChanged()</code>,
+ * in order to notify any <code>ChangeListener</code>s, when the list or array
+ * changes. The model handles notification when the reference itself
+ * is changed via <code>setList()</code> or when the current value is
+ * set directly using <code>setValue()</code>.
+ *
+ * @author Andrew John Hughes (gnu_andrew at member.fsf.org)
+ * @see SpinnerModel
+ * @see AbstractSpinnerModel
+ * @see JSpinner
+ * @since 1.4
+ */
+
+public class SpinnerListModel extends AbstractSpinnerModel
+ implements Serializable
+{
+ /**
+ * For compatability with Sun's JDK
+ */
+ private static final long serialVersionUID = 3358804052191994516L;
+
+ /**
+ * The backing list for this model.
+ */
+ private List list;
+
+ /**
+ * The current index in the list.
+ */
+ private transient int index;
+
+ /**
+ * Constructs a default <code>SpinnerListModel</code>. This
+ * is a model backed by a list containing only the single
+ * <code>String</code> element, "empty".
+ */
+ public SpinnerListModel()
+ {
+ List defaultList;
+
+ // Create an empty list.
+ defaultList = new ArrayList();
+ // Add the string "empty".
+ defaultList.add("empty");
+ // Set the list.
+ setList(defaultList);
+ }
+
+ /**
+ * Constructs a <code>SpinnerListModel</code> using the supplied list.
+ * The model maintains a reference to this list, and returns
+ * consecutive elements in response to calls to <code>getNextValue()</code>.
+ * The initial value is that at position 0, so an initial call
+ * to <code>getValue()</code> returns the same as <code>list.get(0)</code>.
+ *
+ * @param list The list to use for this model.
+ *
+ * @throws IllegalArgumentException if the list is null or contains no
+ * elements.
+ *
+ * @see SpinnerListModel#getNextValue()
+ * @see SpinnerListModel#getValue()
+ */
+ public SpinnerListModel(List list)
+ {
+ // Retain a reference to the valid list.
+ setList(list);
+ }
+
+ /**
+ * Constructs a <code>SpinnerListModel</code> using the supplied array.
+ * The model stores a reference to the wrapper list returned by
+ * <code>Arrays.asList()</code>. The wrapper list reflects modifications
+ * in the underlying array, so these changes will also be reflected
+ * by the model. The model produces consecutive elements from the array
+ * in response to calls to <code>getNextValue()</code>. The initial
+ * value returned by <code>getValue()</code> is the same as
+ * <code>array[0]</code>.
+ *
+ * @param array The array to use for this model.
+ *
+ * @throws IllegalArgumentException if the array is null or contains
+ * no elements.
+ *
+ * @see Arrays#asList(Object[])
+ * @see SpinnerListModel#getNextValue()
+ * @see SpinnerListModel#getValue()
+ */
+ public SpinnerListModel(Object[] array)
+ {
+ // Check for a null or zero-sized array.
+ if (array == null || array.length == 0)
+ {
+ throw new IllegalArgumentException("The supplied array was invalid.");
+ }
+
+ // Retain a reference to a wrapper around the valid array.
+ // The array, in list form, will be tested again here, but we can't really
+ // avoid this -- a null value to Arrays.asList will throw a
+ // NullPointerException.
+ setList(Arrays.asList(array));
+ }
+
+ /**
+ * Returns the backing list for this model.
+ *
+ * @return The backing list.
+ */
+ public List getList()
+ {
+ return list;
+ }
+
+ /**
+ * Returns the next value from the list, which is the same as the element
+ * stored at the current index + 1. Null is returned if there are no more
+ * values to be returned (the end of the list has been reached). An
+ * ambiguity can occur here, as null may also be returned as a valid list
+ * element. This operation does not change the current value.
+ *
+ * @return The next value from the list or null.
+ */
+ public Object getNextValue()
+ {
+ // Check for a next value.
+ if (index < (list.size() - 1))
+ // Return the element at the next index.
+ return list.get(index + 1);
+ else
+ // Return null as this is the end of the list.
+ return null;
+ }
+
+ /**
+ * Returns the previous value from the list, which is the same as the element
+ * stored at the current index - 1. Null is returned if there are no more
+ * values to be returned (the start of the list has been reached). An
+ * ambiguity can occur here, as null may also be returned as a valid list
+ * element. This operation does not change the current value.
+ *
+ * @return The previous value from the list or null.
+ */
+ public Object getPreviousValue()
+ {
+ // Check for a previous value.
+ if (index > 0)
+ // Return the element at the previous position.
+ return list.get(index - 1);
+ else
+ // Return null as this is the start of the list.
+ return null;
+ }
+
+ /**
+ * Returns the current value of the model. Initially, this will
+ * be the element at position 0. On later invocations, this will
+ * be the last element returned by <code>getNextValue()</code>
+ * or <code>getPreviousValue()</code>.
+ *
+ * @return The current value.
+ *
+ * @see SpinnerListModel#getPreviousValue()
+ * @see SpinnerListModel#getNextValue()
+ */
+ public Object getValue()
+ {
+ return list.get(index);
+ }
+
+ /**
+ * Changes the backing list for this model. The model only stores
+ * a reference to the list, so any changes made to the list elsewhere
+ * will be reflected in the values returned by the model. A
+ * <code>ChangeEvent</code> is fired if the list being used actually
+ * changes (i.e. the new list is not referentially equal (!=) to the
+ * old one).
+ *
+ * @param list The new list to use.
+ *
+ * @throws IllegalArgumentException if the list is null or contains
+ * no elements.
+ *
+ * @see ChangeEvent
+ */
+ public void setList(List list)
+ {
+ // Check for null or zero size list.
+ if (list == null || list.size() == 0)
+ throw new IllegalArgumentException("The supplied list was invalid.");
+
+ // Check for a change of referenced list.
+ if (this.list != list)
+ {
+ // Store the new list.
+ this.list = list;
+ // Notify listeners of a change.
+ fireStateChanged();
+ }
+ // We reset the other values in either case.
+ // Set the index to 0.
+ index = 0;
+ }
+
+ /**
+ * Sets the current value of the model to be the one supplied.
+ * The value must exist within the backing list in order for
+ * the change to take place. Otherwise, an exception is thrown.
+ * The value used is the first occurrence of the value within
+ * the backing list. Listeners are notified of this change.
+ * Following the change, <code>getNextValue()</code> and
+ * <code>getPreviousValue()</code> return the objects following
+ * and prior to the supplied value, respectively.
+ *
+ * @param value The requested new value of the list.
+ *
+ * @throws IllegalArgumentException if the supplied value does
+ * not exist in the backing list.
+ *
+ * @see SpinnerListModel#getPreviousValue()
+ * @see SpinnerListModel#getNextValue()
+ */
+ public void setValue(Object value)
+ {
+ int valueIndex;
+
+ // Search for the value in the list.
+ valueIndex = list.indexOf(value);
+ // Check for the value being found.
+ if (valueIndex == -1)
+ throw new IllegalArgumentException("The supplied value does not "
+ + "exist in this list");
+ // Make the indices match.
+ index = valueIndex;
+ // Notify the listeners.
+ fireStateChanged();
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpinnerModel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpinnerModel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpinnerModel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpinnerModel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,111 @@
+/* SpinnerModel.java --
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import javax.swing.event.ChangeListener;
+
+/**
+ * The data model that is used in {@link JSpinner}s.
+ *
+ * @since 1.4
+ */
+public interface SpinnerModel
+{
+ /**
+ * Sets the current value of the model to that specified.
+ * Implementations can choose to refuse to accept the value
+ * and throw an exception instead. For example, a date model
+ * may throw invalid dates, or a list model may throw out
+ * values which don't exist in the underlying list. Models
+ * may also throw out unusual values, such as null. The decision
+ * is left to the discretion of the implementator. If the
+ * operation succeeds, the implementation should also notify
+ * any registered <code>ChangeListener</code>s.
+ *
+ * @param value The new value of the model.
+ * @throws IllegalArgumentException if the model does not accept
+ * the given value.
+ */
+ void setValue(Object value);
+
+ /**
+ * Returns the current value of the model.
+ *
+ * @return The current value.
+ */
+ Object getValue();
+
+ /**
+ * Returns the next value from the model. If the model is bounded,
+ * this method may return null when the upper bound is met.
+ * The current value is not changed.
+ *
+ * @return The next value, or null if there are no more values
+ * to retrieve.
+ */
+ Object getNextValue();
+
+ /**
+ * Returns the previous value from the model. If the model is
+ * bounded, this method may return null when the lower bound is
+ * met. The current value is not changed.
+ *
+ * @return The previous value, or null if there are no more
+ * values to retrieve.
+ */
+ Object getPreviousValue();
+
+ /**
+ * Adds a <code>ChangeListener</code> to the list of registered
+ * listeners. Each listener is notified when the current value
+ * is changed.
+ *
+ * @param listener The new listener to register.
+ */
+ void addChangeListener(ChangeListener listener);
+
+ /**
+ * Removes a given <code>ChangeListener</code> from the list
+ * of registered listeners.
+ *
+ * @param listener The listener to remove.
+ */
+ void removeChangeListener(ChangeListener listener);
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpinnerNumberModel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpinnerNumberModel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpinnerNumberModel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpinnerNumberModel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,361 @@
+/* SpinnerNumberModel.java --
+ Copyright (C) 2002, 2004, 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import java.io.Serializable;
+
+import javax.swing.event.ChangeEvent;
+
+/**
+ * A model used by the {@link JSpinner} component.
+ *
+ * @author Ka-Hing Cheung
+ * @since 1.4
+ */
+public class SpinnerNumberModel extends AbstractSpinnerModel
+ implements Serializable
+{
+ /**
+ * For compatability with Sun's JDK
+ */
+ private static final long serialVersionUID = 7279176385485777821L;
+
+ /** The current value. */
+ private Number value;
+
+ /** The minimum value (or <code>null</code>). */
+ private Comparable minimum;
+
+ /** The maximum value (or <code>null</code>). */
+ private Comparable maximum;
+
+ /** The step size. */
+ private Number stepSize;
+
+ /**
+ * Creates a <code>SpinnerNumberModel</code> with initial value 0, step 1,
+ * and no maximum nor minimum.
+ */
+ public SpinnerNumberModel()
+ {
+ this(new Integer(0), null, null, new Integer(1));
+ }
+
+ /**
+ * Creates a <code>SpinnerNumberModel</code> with double precision.
+ *
+ * @param value the initial value
+ * @param minimum the minimum value
+ * @param maximum the maximum value
+ * @param stepSize the step size
+ * @throws IllegalArgumentException if minimum <= value <= maximum does
+ * not hold.
+ */
+ public SpinnerNumberModel(double value, double minimum, double maximum,
+ double stepSize)
+ {
+ this(new Double(value), new Double(minimum), new Double(maximum),
+ new Double(stepSize));
+ }
+
+ /**
+ * Creates a <code>SpinnerNumberModel</code> with integer precision.
+ *
+ * @param value the initial value
+ * @param minimum the minimum value
+ * @param maximum the maximum value
+ * @param stepSize the step size
+ * @throws IllegalArgumentException if minimum <= value <= maximum does
+ * not hold.
+ */
+ public SpinnerNumberModel(int value, int minimum, int maximum, int stepSize)
+ {
+ this(new Integer(value), new Integer(minimum), new Integer(maximum),
+ new Integer(stepSize));
+ }
+
+ /**
+ * Creates a <code>SpinnerNumberModel</code> with the given attributes. The
+ * caller should ensure that both <code>minimum</code> and
+ * <code>maximum</code> are serializable.
+ *
+ * @param value the initial value (<code>null</code> not permitted).
+ * @param minimum the minimum value (<code>null</code> permitted).
+ * @param maximum the maximum value (<code>null</code> permitted).
+ * @param stepSize the step size (<code>null</code> not permitted).
+ *
+ * @throws IllegalArgumentException if minimum <= value <= maximum
+ * does not hold
+ * @throws IllegalArgumentException if <code>value</code> is
+ * <code>null</code>.
+ * @throws IllegalArgumentException if <code>stepSize</code> is
+ * <code>null</code>.
+ */
+ public SpinnerNumberModel(Number value, Comparable minimum,
+ Comparable maximum, Number stepSize)
+ {
+ if (stepSize == null)
+ throw new IllegalArgumentException("stepSize may not be null");
+ if (value == null)
+ throw new IllegalArgumentException("value may not be null");
+ if (minimum != null)
+ {
+ if (minimum.compareTo(value) > 0)
+ throw new IllegalArgumentException("minimum is not <= value");
+ }
+ if (maximum != null)
+ {
+ if (maximum.compareTo(value) < 0)
+ throw new IllegalArgumentException("maximum is not >= value");
+ }
+
+ this.value = value;
+ this.stepSize = stepSize;
+ this.minimum = minimum;
+ this.maximum = maximum;
+ }
+
+ /**
+ * Sets the current value and, if the new value is different to the old
+ * value, sends a {@link ChangeEvent} to all registered listeners.
+ *
+ * @param value the new value (<code>null</code> not permitted, must be an
+ * instance of <code>Number</code>).
+ *
+ * @throws IllegalArgumentException if <code>value</code> is not an instance
+ * of <code>Number</code>.
+ */
+ public void setValue(Object value)
+ {
+ if (! (value instanceof Number))
+ throw new IllegalArgumentException("value must be a Number");
+
+ if (!this.value.equals(value))
+ {
+ this.value = (Number) value;
+ fireStateChanged();
+ }
+ }
+
+ /**
+ * Returns the current value, which for this class is always an instance of
+ * {@link Number}.
+ *
+ * @return The current value.
+ *
+ * @see #getNumber()
+ */
+ public Object getValue()
+ {
+ return value;
+ }
+
+ /**
+ * Returns the next value, or <code>null</code> if adding the step size to
+ * the current value results in a value greater than the maximum value.
+ * The current value is not changed.
+ *
+ * @return The next value, or <code>null</code> if the current value is the
+ * maximum value represented by this model.
+ */
+ public Object getNextValue()
+ {
+ Number num;
+
+ if (value instanceof Double)
+ num = new Double(value.doubleValue() + stepSize.doubleValue());
+ else if (value instanceof Float)
+ num = new Double(value.floatValue() + stepSize.floatValue());
+ else if (value instanceof Long)
+ num = new Long(value.longValue() + stepSize.longValue());
+ else if (value instanceof Integer)
+ num = new Integer(value.intValue() + stepSize.intValue());
+ else if (value instanceof Short)
+ num = new Short((short) (value.shortValue() + stepSize.shortValue()));
+ else
+ num = new Byte((byte) (value.byteValue() + stepSize.byteValue()));
+
+ // check upper bound if set
+ if ((maximum != null) && maximum.compareTo(num) < 0)
+ num = null;
+
+ return num;
+ }
+
+ /**
+ * Returns the previous value, or <code>null</code> if subtracting the
+ * step size from the current value results in a value less than the minimum
+ * value. The current value is not changed.
+ *
+ * @return The previous value, or <code>null</code> if the current value
+ * is the minimum value represented by this model.
+ */
+ public Object getPreviousValue()
+ {
+ Number num;
+
+ if (value instanceof Double)
+ num = new Double(value.doubleValue() - stepSize.doubleValue());
+ else if (value instanceof Float)
+ num = new Double(value.floatValue() - stepSize.floatValue());
+ else if (value instanceof Long)
+ num = new Long(value.longValue() - stepSize.longValue());
+ else if (value instanceof Integer)
+ num = new Integer(value.intValue() - stepSize.intValue());
+ else if (value instanceof Short)
+ num = new Short((short) (value.shortValue() - stepSize.shortValue()));
+ else
+ num = new Byte((byte) (value.byteValue() - stepSize.byteValue()));
+
+ // check lower bound if set
+ if ((minimum != null) && minimum.compareTo(num) > 0)
+ num = null;
+
+ return num;
+ }
+
+ /**
+ * Returns the current value.
+ *
+ * @return The current value.
+ */
+ public Number getNumber()
+ {
+ return value;
+ }
+
+ /**
+ * Returns the minimum value, or <code>null</code> if there is no minimum.
+ *
+ * @return The minimum value.
+ *
+ * @see #setMinimum(Comparable)
+ */
+ public Comparable getMinimum()
+ {
+ return minimum;
+ }
+
+ /**
+ * Sets the minimum value and, if the new value is different to the old
+ * value, sends a {@link ChangeEvent} to all registered listeners. A
+ * <code>null</code> value is interpreted as "no minimum value". No check
+ * is made to ensure that the new minimum is less than or equal to the
+ * current value, the caller is responsible for ensuring that this
+ * relationship holds. In addition, the caller should ensure that
+ * <code>newMinimum</code> is {@link Serializable}.
+ *
+ * @param newMinimum the new minimum value (<code>null</code> permitted).
+ *
+ * @see #getMinimum()
+ */
+ public void setMinimum(Comparable newMinimum)
+ {
+ if (minimum != null ? !minimum.equals(newMinimum) : newMinimum != null)
+ {
+ minimum = newMinimum;
+ fireStateChanged();
+ }
+ }
+
+ /**
+ * Returns the maximum value, or <code>null</code> if there is no maximum.
+ *
+ * @return The maximum value.
+ *
+ * @see #getMinimum()
+ * @see #setMaximum(Comparable)
+ */
+ public Comparable getMaximum()
+ {
+ return maximum;
+ }
+
+ /**
+ * Sets the maximum value and, if the new value is different to the old
+ * value, sends a {@link ChangeEvent} to all registered listeners. A
+ * <code>null</code> value is interpreted as "no maximum value". No check
+ * is made to ensure that the new maximum is greater than or equal to the
+ * current value, the caller is responsible for ensuring that this
+ * relationship holds. In addition, the caller should ensure that
+ * <code>newMaximum</code> is {@link Serializable}.
+ *
+ * @param newMaximum the new maximum (<code>null</code> permitted).
+ *
+ * @see #getMaximum()
+ */
+ public void setMaximum(Comparable newMaximum)
+ {
+ if (maximum != null ? !maximum.equals(newMaximum) : newMaximum != null)
+ {
+ maximum = newMaximum;
+ fireStateChanged();
+ }
+ }
+
+ /**
+ * Returns the step size.
+ *
+ * @return The step size (never <code>null</code>).
+ */
+ public Number getStepSize()
+ {
+ return stepSize;
+ }
+
+ /**
+ * Sets the step size and, if the new step size is different to the old
+ * step size, sends a {@link ChangeEvent} to all registered listeners.
+ *
+ * @param newStepSize the new step size (<code>null</code> not permitted).
+ *
+ * @throws IllegalArgumentException if <code>newStepSize</code> is
+ * <code>null</code>.
+ */
+ public void setStepSize(Number newStepSize)
+ {
+ if (newStepSize == null)
+ throw new IllegalArgumentException();
+
+ if (!stepSize.equals(newStepSize))
+ {
+ stepSize = newStepSize;
+ fireStateChanged();
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Spring.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Spring.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Spring.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Spring.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,745 @@
+/* Spring.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import java.awt.Component;
+import java.awt.Dimension;
+
+/**
+ * Calculates the space between component edges, that are layed out by
+ * {@link SpringLayout}.
+ * <p>
+ * A Spring defines a minimum, preferred and maximum distance for each edge
+ * (north, east, south, west) of a component.
+ * </p>
+ * However, springs are not static, their actual values are computed at
+ * runtime. That means, if a Spring C is defined as the sum of Spring A and
+ * Spring B, then the values (min, pref and max) are not calculated at
+ * creation of Spring C, but instead always when {@link #getValue} is
+ * called. So, when Spring A or Spring B changes, this is reflected in
+ * Spring C.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+public abstract class Spring
+{
+
+ /** Indicates a not-set value. **/
+ public static final int UNSET = Integer.MIN_VALUE;
+
+ /**
+ * Creates a new Spring object. This constructor is used by the static
+ * methods which create Springs.
+ */
+ protected Spring()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Creates a Spring which min, pref and max values are all the same.
+ * These kind of Springs are 'struts'.
+ *
+ * @param val the constant for min, pref and max values.
+ * @return a Spring object with constant values for min, pref and max.
+ */
+ public static Spring constant(int val)
+ {
+ return new SimpleSpring(val, val, val);
+ }
+
+ /** Creates a Spring which min, pref and max values are constants.
+ * @param min the constant for the minimum value.
+ * @param pref the constant for the preferred value.
+ * @param max the constant for the maximum value.
+ * @return a Spring object with constant values for min, pref and max.
+ */
+ public static Spring constant(int min, int pref, int max)
+ {
+ return new SimpleSpring(min, pref, max);
+ }
+
+ /**
+ * Returns the maximum value of the Spring.
+ *
+ * @return the maximum value.
+ */
+ public abstract int getMaximumValue();
+
+ /**
+ * Returns the minimum value of this Spring.
+ *
+ * @return the minimum value.
+ */
+ public abstract int getMinimumValue();
+
+ /**
+ * Return the preferred value of this Spring.
+ *
+ * @return the preferred value.
+ */
+ public abstract int getPreferredValue();
+
+ /**
+ * Return the actual value of this Spring.
+ *
+ * @return the actual value of this Spring.
+ */
+ public abstract int getValue();
+
+ /**
+ * Creates and returns a Spring, which always has the maximum values
+ * min = max(min_s1, min_s2), pref = max(pref_s1, pref_s2), max =
+ * max(max_s1, max_s2).
+ *
+ * @param s1 the first summand of the max Spring.
+ * @param s2 the second summand of the max Spring.
+ * @return a Spring which is max(s1, s2).
+ */
+ public static Spring max(Spring s1, Spring s2)
+ {
+ return new MaxSpring(s1, s2);
+ }
+
+ /**
+ * Creates and returns a Spring, which is always the negation of s.
+ * min = -min_s, pref = -pref_s, max = -max_pref.
+ *
+ * @param s the Spring to be negated.
+ * @return the negative of <code>s</code>.
+ */
+ public static Spring minus(Spring s)
+ {
+ return new MinusSpring(s);
+ }
+
+ /**
+ * Sets the actual value. If <code>value</code> is out of the (min, max)
+ * bounds, then the value is adjusted, so that is inside these bounds.
+ *
+ * @param value the value to be set.
+ */
+ public abstract void setValue(int value);
+
+ private int getShrinkRange()
+ {
+ return (getPreferredValue() - getMinimumValue());
+ }
+
+ private int getExpandRange()
+ {
+ return (getMaximumValue() - getPreferredValue());
+ }
+
+ double getStrain()
+ {
+ int v = getValue();
+ int p = getPreferredValue();
+ int r = (v < p) ? getShrinkRange() : getExpandRange();
+ if (r == 0)
+ r = 1;
+ return (double)(v - p) / r;
+ }
+
+ void setStrain(double strain)
+ {
+ int r = (strain < 0) ? getShrinkRange() : getExpandRange();
+ int v = (getPreferredValue() + (int)(strain * r));
+ setValue(v);
+ }
+
+ /**
+ * Creates and returns a Spring, which is always the sum of s1 and s2.
+ * min_sum = min_s1 + min_s2, pref_sum = pref_s1 + pref_s2, max_sum =
+ * max_s1 + max_s2.
+ *
+ * @param s1 the 1st summand of the sum Spring.
+ * @param s2 the 2nd summand of the sum Spring.
+ * @return a sum which is <code>s1 + s2</code>.
+ */
+ public static Spring sum(Spring s1, Spring s2)
+ {
+ return new AddSpring(s1, s2);
+ }
+
+ /**
+ * Return a new Spring which computes its values by scaling
+ * the values of another spring by a constant factor. If the
+ * factor is negative, the minimum and maximum values of
+ * the argument spring will be interchanged.
+ * @param spring the spring to track
+ * @param factor the factor by which to scale
+ * @return a new multiplicative Spring
+ * @since 1.5
+ */
+ public static Spring scale(final Spring spring, final float factor)
+ {
+ if (spring == null)
+ throw new NullPointerException("spring argument is null");
+ return new Spring()
+ {
+ public int getMaximumValue()
+ {
+ return (int) ((factor < 0 ? spring.getMinimumValue()
+ : spring.getMaximumValue())
+ * factor);
+ }
+
+ public int getMinimumValue()
+ {
+ return (int) ((factor < 0 ? spring.getMaximumValue()
+ : spring.getMinimumValue())
+ * factor);
+ }
+
+ public int getPreferredValue()
+ {
+ return (int) (spring.getPreferredValue() * factor);
+ }
+
+ public int getValue()
+ {
+ return (int) (spring.getValue() * factor);
+ }
+
+ public void setValue(int value)
+ {
+ spring.setValue((int) (value / factor));
+ }
+ };
+ }
+
+ /**
+ * Return a new Spring which takes its values from the specified
+ * Component. In particular, the maximum value is taken from
+ * the maximumSize, the minimum value is taken from the minimumSize,
+ * the preferred value is taken from the preferredSize, and the
+ * value is taken from the component's current size. These values
+ * change as the component changes size.
+ * @param component the component
+ * @return a new Spring which tracks the component's width
+ * @since 1.5
+ */
+ public static Spring width(final Component component)
+ {
+ return new Spring()
+ {
+ public int getMaximumValue()
+ {
+ return component.getMaximumSize().width;
+ }
+
+ public int getMinimumValue()
+ {
+ return component.getMinimumSize().width;
+ }
+
+ public int getPreferredValue()
+ {
+ return component.getPreferredSize().width;
+ }
+
+ public int getValue()
+ {
+ return component.getSize().width;
+ }
+
+ public void setValue(int value)
+ {
+ Dimension d = component.getSize();
+ component.setSize(value, d.height);
+ }
+ };
+ }
+
+ /**
+ * Return a new Spring which takes its values from the specified
+ * Component. In particular, the maximum value is taken from
+ * the maximumSize, the minimum value is taken from the minimumSize,
+ * the preferred value is taken from the preferredSize, and the
+ * value is taken from the component's current size. These values
+ * change as the component changes size.
+ * @param component the component
+ * @return a new Spring which tracks the component's height
+ * @since 1.5
+ */
+ public static Spring height(final Component component)
+ {
+ return new Spring()
+ {
+ public int getMaximumValue()
+ {
+ return component.getMaximumSize().height;
+ }
+
+ public int getMinimumValue()
+ {
+ return component.getMinimumSize().height;
+ }
+
+ public int getPreferredValue()
+ {
+ return component.getPreferredSize().height;
+ }
+
+ public int getValue()
+ {
+ return component.getSize().height;
+ }
+
+ public void setValue(int value)
+ {
+ Dimension d = component.getSize();
+ component.setSize(d.width, value);
+ }
+ };
+ }
+
+ /**
+ * A simple Spring, that holds constant values for min, pref and max.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+ private static final class SimpleSpring extends Spring
+ {
+
+ /** The constant value for min. */
+ private final int min;
+
+ /** The constant value for pref. */
+ private final int pref;
+
+ /** The constant value for max. */
+ private final int max;
+
+ /** The actual value of the spring. */
+ private int value;
+
+ public String toString()
+ {
+ return "SimpleSpring of " + value;
+ }
+
+ /**
+ * Creates a new SimpleSpring object.
+ *
+ * @param newMin the constant minimum value.
+ * @param newPref the constant preferred value.
+ * @param newMax the constant maximum value.
+ */
+ public SimpleSpring(int newMin, int newPref, int newMax)
+ {
+ min = newMin;
+ pref = newPref;
+ max = newMax;
+ value = newPref;
+ }
+
+ /**
+ * Returns the maximum value of this Spring.
+ *
+ * @return the maximum value.
+ */
+ public int getMaximumValue()
+ {
+ return max;
+ }
+
+ /**
+ * Returns the minimum value of this Spring.
+ *
+ * @return the minimum value.
+ */
+ public int getMinimumValue()
+ {
+ return min;
+ }
+
+ /**
+ * Returns the preferred value of this Spring.
+ *
+ * @return the preferred value.
+ */
+ public int getPreferredValue()
+ {
+ return pref;
+ }
+
+ /**
+ * Return the actual current value of this Spring.
+ *
+ * @return the current value.
+ */
+ public int getValue()
+ {
+ if (value == Spring.UNSET)
+ return pref;
+ return value;
+ }
+
+ /**
+ * Sets the current value.
+ *
+ * @param val the value to be set.
+ */
+ public void setValue(int val)
+ {
+ value = val;
+ }
+ }
+
+
+ /**
+ * A Spring, that is the sum of two other Springs.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+ private static final class AddSpring extends Spring
+ {
+
+ /** The springs, that are the 'operands' of this Spring. */
+ private final Spring s1;
+ private final Spring s2;
+
+ /** The current value for this Spring. */
+ private int value;
+
+ public String toString()
+ {
+ return "AddSpring of " + s1 + " and " + s2;
+ }
+
+ /**
+ * Creates a new AddSpring object.
+ *
+ * @param s1 the first operand.
+ * @param s2 the second operand.
+ */
+ protected AddSpring(Spring s1, Spring s2)
+ {
+ super();
+ this.s1 = s1;
+ this.s2 = s2;
+ value = Spring.UNSET;
+ }
+
+ /**
+ * Returns the maximum value of this Spring.
+ *
+ * @return the maximum value.
+ */
+ public int getMaximumValue()
+ {
+ int max1 = s1.getMaximumValue();
+ int max2 = s2.getMaximumValue();
+ return max1 + max2;
+ }
+
+ /**
+ * Return the minimum value of this Spring.
+ *
+ * @return the minimum value.
+ */
+ public int getMinimumValue()
+ {
+ int min1 = s1.getMinimumValue();
+ int min2 = s2.getMinimumValue();
+ return min1 + min2;
+ }
+
+ /**
+ * Returns the preferred value of this Spring.
+ *
+ * @return the preferred value.
+ */
+ public int getPreferredValue()
+ {
+ int pref1 = s1.getPreferredValue();
+ int pref2 = s2.getPreferredValue();
+ return pref1 + pref2;
+ }
+
+ /**
+ * Returns the actual current value of this Spring.
+ *
+ * @return the current value of this Spring.
+ */
+ public int getValue()
+ {
+ if (value == Spring.UNSET)
+ {
+ int val1 = s1.getValue();
+ int val2 = s2.getValue();
+ value = val1 + val2;
+ }
+ return value;
+ }
+
+ /**
+ * Sets the current value.
+ *
+ * @param val the value to be set.
+ */
+ public void setValue(int val)
+ {
+ if (val == Spring.UNSET)
+ {
+ if (value != Spring.UNSET)
+ {
+ s1.setValue(Spring.UNSET);
+ s2.setValue(Spring.UNSET);
+ }
+ value = Spring.UNSET;
+ return;
+ }
+
+ value = val;
+
+ //Spead the value over the two components
+ double fStrain = getStrain();
+ s1.setStrain(fStrain);
+ int remainder = val - s1.getValue();
+ s2.setValue(remainder);
+ }
+
+ }
+
+
+ /**
+ * A Spring that is calculated as the negation of another Spring.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+ private static final class MinusSpring extends Spring
+ {
+
+ /** The Spring from which to calculate the negation. */
+ private final Spring s;
+
+ public String toString()
+ {
+ return "MinusSpring of " + s;
+ }
+
+ /**
+ * Creates a new MinusSpring object.
+ * @param s the Spring from which to calculate the negation.
+ */
+ protected MinusSpring(Spring s)
+ {
+ super();
+ this.s = s;
+ }
+
+ /** Returns the maximum value of this Spring.
+ *
+ * @return the maximum value.
+ */
+ public int getMaximumValue()
+ {
+ return -s.getMinimumValue();
+ }
+
+ /**
+ * Returns the minimum value of this Spring.
+ *
+ * @return the minimum value.
+ */
+ public int getMinimumValue()
+ {
+ return -s.getMaximumValue();
+ }
+
+ /**
+ * Returns the preferred value of this Spring.
+ *
+ * @return the preferred value.
+ */
+ public int getPreferredValue()
+ {
+ return -s.getPreferredValue();
+ }
+
+ /**
+ * Returns the current value of this Spring.
+ *
+ * @return the current value.
+ */
+ public int getValue()
+ {
+ return -s.getValue();
+ }
+
+ /**
+ * Sets the current value.
+ *
+ * @param val the value to be set.
+ */
+ public void setValue(int val)
+ {
+ if (val == Spring.UNSET)
+ s.setValue(Spring.UNSET);
+ else
+ s.setValue(-val);
+ }
+ }
+
+
+ /**
+ * A Spring, that is calculated as the maximum of two Springs.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+ private static final class MaxSpring extends Spring
+ {
+
+ /** The two other Springs from which to calculate the maximum. */
+ private final Spring s1;
+ private final Spring s2;
+
+ public String toString()
+ {
+ return "MaxSpring of " + s1 + " and " + s2;
+ }
+
+ /** The current value of this Spring. */
+ private int value;
+
+ /**
+ * Creates a new MaxSpring object.
+ *
+ * @param s1 the 1st operand.
+ * @param s2 the 2nd operand.
+ */
+ protected MaxSpring(Spring s1, Spring s2)
+ {
+ super();
+ this.s1 = s1;
+ this.s2 = s2;
+ value = Spring.UNSET;
+ }
+
+
+ /**
+ * Returns the maximum value of this Spring.
+ *
+ * @return the maximum value.
+ */
+ public int getMaximumValue()
+ {
+ int max1 = s1.getMaximumValue();
+ int max2 = s2.getMaximumValue();
+ return Math.max(max1, max2);
+ }
+
+ /**
+ * Returns the minimum value of this Spring.
+ *
+ * @return the minimum value.
+ */
+ public int getMinimumValue()
+ {
+ int min1 = s1.getMinimumValue();
+ int min2 = s2.getMinimumValue();
+ return Math.max(min1, min2);
+ }
+
+ /**
+ * Returns the preferred value of this Spring.
+ *
+ * @return the preferred value.
+ */
+ public int getPreferredValue()
+ {
+ int pref1 = s1.getPreferredValue();
+ int pref2 = s2.getPreferredValue();
+ return Math.max(pref1, pref2);
+ }
+
+ /**
+ * Returns the actual value of this Spring.
+ *
+ * @return the current value.
+ */
+ public int getValue()
+ {
+ if (value == Spring.UNSET)
+ {
+ int val1 = s1.getValue();
+ int val2 = s2.getValue();
+ value = Math.max(val1, val2);
+ }
+ return value;
+ }
+
+ /**
+ * Sets the current value.
+ *
+ * @param val the value to be set.
+ */
+ public void setValue(int val)
+ {
+ if (val == Spring.UNSET)
+ {
+ if (value != Spring.UNSET)
+ {
+ s1.setValue(Spring.UNSET);
+ s2.setValue(Spring.UNSET);
+ }
+ value = Spring.UNSET;
+ return;
+ }
+
+ value = val;
+
+ int p1 = s1.getPreferredValue();
+ int p2 = s2.getPreferredValue();
+
+ if (p1 < p2)
+ {
+ s1.setValue(Math.min(val, p1));
+ s2.setValue(val);
+ }
+ else
+ {
+ s1.setValue(val);
+ s2.setValue(Math.min(val, p2));
+ }
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpringLayout.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpringLayout.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpringLayout.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SpringLayout.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,832 @@
+/* SpringLayout.java --
+ Copyright (C) 2004, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.LayoutManager2;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A very flexible layout manager. Components are laid out by defining the
+ * relationships between them. The relationships are expressed as
+ * {@link Spring}s. You can attach a Spring for each edge of a component and
+ * link it to an edge of a different component. For example, you can say,
+ * the northern edge of component A should be attached to the southern edge
+ * of component B, and the space between them should be something between
+ * x and y pixels, and preferably z pixels.
+ * <p>While quite simple, this layout manager can be used to emulate most other
+ * layout managers, and can also be used to solve some layout problems, which
+ * would be hard to solve with other layout managers.</p>
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+public class SpringLayout implements LayoutManager2
+{
+
+ /** The right edge of a component. */
+ public static final String EAST = "East";
+
+ /** The top edge of a component. */
+ public static final String NORTH = "North";
+
+ /** The bottom edge of a component. */
+ public static final String SOUTH = "South";
+
+ /** The left edge of a component. */
+ public static final String WEST = "West";
+
+ /** maps components to their constraints. */
+ private Map constraintsMap;
+
+ /**
+ * The constraints that define the relationships between components.
+ * Each Constraints object can hold 4 Springs: one for each edge of the
+ * component. Additionally it can hold Springs for the components width
+ * and the components height. Since the height and width constraints are
+ * dependend on the other constraints, a component can be over-constraint.
+ * In this case (like when all of NORTH, SOUTH and HEIGHT are constraint),
+ * the values are adjusted, so that the mathematics still hold true.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+ public static class Constraints
+ {
+
+ // The constraints for each edge, and width and height.
+ /** The Spring for the left edge. */
+ private Spring x;
+
+ /** The Spring for the upper edge. */
+ private Spring y;
+
+ /** The Spring for the height. */
+ private Spring height;
+
+ /** The Spring for the width. */
+ private Spring width;
+
+ /** The Spring for the right edge. */
+ private Spring east;
+
+ /** The Spring for the bottom edge. */
+ private Spring south;
+
+ /**
+ In each axis the user can set three values, i.e. x, width, east, if all
+ three are set, then there's no room for manoeuvre so in those cases the
+ third will be described by the below spring which is calculated in terms
+ of the other two
+ */
+ private Spring v;
+ private Spring h;
+
+ /**
+ * Creates a new Constraints object.
+ * There is no constraint set.
+ */
+ public Constraints()
+ {
+ x = y = height = width = east = south = v = h = null;
+ }
+
+ /**
+ * Creates a new Constraints object.
+ *
+ * @param x the constraint for the left edge of the component.
+ * @param y the constraint for the upper edge of the component.
+ */
+ public Constraints(Spring x, Spring y)
+ {
+ this.x = x;
+ this.y = y;
+ width = height = east = south = v = h = null;
+ }
+
+ /**
+ * Creates a new Constraints object.
+ *
+ * @param x the constraint for the left edge of the component.
+ * @param y the constraint for the upper edge of the component.
+ * @param width the constraint for the width of the component.
+ * @param height the constraint for the height of the component.
+ */
+ public Constraints(Spring x, Spring y, Spring width, Spring height)
+ {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ east = south = v = h = null;
+ }
+
+ /**
+ * Create a new Constraints object which tracks the indicated
+ * component. The x and y positions for this Constraints object
+ * are constant Springs created with the component's location at
+ * the time this constructor is called. The width and height
+ * of this Constraints are Springs created using
+ * {@link Spring#width(Component)} and {@link Spring#height(Component)},
+ * respectively.
+ * @param component the component to track
+ * @since 1.5
+ */
+ public Constraints(Component component)
+ {
+ this(Spring.constant(component.getX()),
+ Spring.constant(component.getY()),
+ Spring.width(component),
+ Spring.height(component));
+ }
+
+ /**
+ * Returns the constraint for the edge with the <code>edgeName</code>.
+ * This is expected to be one of
+ * {@link #EAST}, {@link #WEST}, {@link #NORTH} or {@link #SOUTH}.
+ *
+ * @param edgeName the name of the edge.
+ * @return the constraint for the specified edge.
+ */
+ public Spring getConstraint(String edgeName)
+ {
+ Spring retVal = null;
+ if (edgeName.equals(SpringLayout.NORTH))
+ retVal = getY();
+ else if (edgeName.equals(SpringLayout.WEST))
+ retVal = getX();
+ else if (edgeName.equals(SpringLayout.SOUTH))
+ retVal = getSouth();
+ else if (edgeName.equals(SpringLayout.EAST))
+ retVal = getEast();
+ return retVal;
+ }
+
+ /**
+ * Returns the constraint for the height of the component.
+ *
+ * @return the height constraint.
+ */
+ public Spring getHeight()
+ {
+ if (height != null)
+ return height;
+ else if ((v == null) && (y != null) && (south != null))
+ v = Spring.sum(south, Spring.minus(y));
+ return v;
+ }
+
+ /**
+ * Returns the constraint for the width of the component.
+ *
+ * @return the width constraint.
+ */
+ public Spring getWidth()
+ {
+ if (width != null)
+ return width;
+ else if ((h == null) && (x != null) && (east != null))
+ h = Spring.sum(east, Spring.minus(x));
+ return h;
+ }
+
+ /**
+ * Returns the constraint for the left edge of the component.
+ *
+ * @return the left-edge constraint (== WEST).
+ */
+ public Spring getX()
+ {
+ if (x != null)
+ return x;
+ else if ((h == null) && (width != null) && (east != null))
+ h = Spring.sum(east, Spring.minus(width));
+ return h;
+ }
+
+ /**
+ * Returns the constraint for the upper edge of the component.
+ *
+ * @return the upper-edge constraint (== NORTH).
+ */
+ public Spring getY()
+ {
+ if (y != null)
+ return y;
+ else if ((v == null) && (height != null) && (south != null))
+ v = Spring.sum(south, Spring.minus(height));
+ return v;
+ }
+
+ /**
+ * Returns the constraint for the lower edge of the component.
+ *
+ * @return the lower-edge constraint (== SOUTH).
+ */
+ public Spring getSouth()
+ {
+ if (south != null)
+ return south;
+ else if ((v == null) && (height != null) && (y != null))
+ v = Spring.sum(y, height);
+ return v;
+ }
+
+ /**
+ * Returns the constraint for the right edge of the component.
+ *
+ * @return the right-edge constraint (== EAST).
+ */
+ public Spring getEast()
+ {
+ if (east != null)
+ return east;
+ else if ((h == null) && (width != null) && (x != null))
+ h = Spring.sum(x, width);
+ return h;
+ }
+
+ /**
+ * Sets a constraint for the specified edge. If this leads to an
+ * over-constrained situation, the constraints get adjusted, so that
+ * the mathematics still hold true.
+ *
+ * @param edgeName the name of the edge, one of {@link #EAST},
+ * {@link #WEST}, {@link #NORTH} or {@link #SOUTH}.
+ * @param s the constraint to be set.
+ */
+ public void setConstraint(String edgeName, Spring s)
+ {
+
+ if (edgeName.equals(SpringLayout.WEST))
+ setX(s);
+ else if (edgeName.equals(SpringLayout.NORTH))
+ setY(s);
+ else if (edgeName.equals(SpringLayout.EAST))
+ setEast(s);
+ else if (edgeName.equals(SpringLayout.SOUTH))
+ setSouth(s);
+
+ }
+
+ /**
+ * Sets the height-constraint.
+ *
+ * @param s the constraint to be set.
+ */
+ public void setHeight(Spring s)
+ {
+ height = s;
+ v = null;
+ if ((south != null) && (y != null) && (height != null))
+ south = null;
+ }
+
+ /**
+ * Sets the width-constraint.
+ *
+ * @param s the constraint to be set.
+ */
+ public void setWidth(Spring s)
+ {
+ width = s;
+ h = null;
+ if ((east != null) && (x != null) && (width != null))
+ east = null;
+ }
+
+ /**
+ * Sets the WEST-constraint.
+ *
+ * @param s the constraint to be set.
+ */
+ public void setX(Spring s)
+ {
+ x = s;
+ h = null;
+ if ((width != null) && (east != null) && (x != null))
+ width = null;
+ }
+
+ /**
+ * Sets the NORTH-constraint.
+ *
+ * @param s the constraint to be set.
+ */
+ public void setY(Spring s)
+ {
+ y = s;
+ v = null;
+ if ((height != null) && (south != null) && (y != null))
+ height = null;
+ }
+
+ /**
+ * Sets the SOUTH-constraint.
+ *
+ * @param s the constraint to be set.
+ */
+ public void setSouth(Spring s)
+ {
+ south = s;
+ v = null;
+ if ((height != null) && (south != null) && (y != null))
+ y = null;
+ }
+
+ /**
+ * Sets the EAST-constraint.
+ *
+ * @param s the constraint to be set.
+ */
+ public void setEast(Spring s)
+ {
+ east = s;
+ h = null;
+ if ((width != null) && (east != null) && (x != null))
+ x = null;
+ }
+
+ public void dropCalcResult()
+ {
+ if (x != null)
+ x.setValue(Spring.UNSET);
+ if (y != null)
+ y.setValue(Spring.UNSET);
+ if (width != null)
+ width.setValue(Spring.UNSET);
+ if (height != null)
+ height.setValue(Spring.UNSET);
+ if (east != null)
+ east.setValue(Spring.UNSET);
+ if (south != null)
+ south.setValue(Spring.UNSET);
+ if (h != null)
+ h.setValue(Spring.UNSET);
+ if (v != null)
+ v.setValue(Spring.UNSET);
+ }
+ }
+
+ /**
+ * Creates a new SpringLayout.
+ */
+ public SpringLayout()
+ {
+ constraintsMap = new HashMap();
+ }
+
+ /**
+ * Adds a layout component and a constraint object to this layout.
+ * This method is usually only called by a {@link java.awt.Container}s add
+ * method.
+ *
+ * @param component the component to be added.
+ * @param constraint the constraint to be set.
+ */
+ public void addLayoutComponent(Component component, Object constraint)
+ {
+ constraintsMap.put(component, constraint);
+ }
+
+ /**
+ * Adds a layout component and a constraint object to this layout.
+ * This method is usually only called by a {@link java.awt.Container}s add
+ * method. This method does nothing, since SpringLayout does not manage
+ * String-indexed components.
+ *
+ * @param name the name.
+ * @param c the component to be added.
+ */
+ public void addLayoutComponent(String name, Component c)
+ {
+ // do nothing here.
+ }
+
+ /**
+ * The trick to SpringLayout is that the network of Springs needs to
+ * completely created before the positioning results are generated.
+ *
+ * Using the springs directly during network creation will set their values
+ * before the network is completed, Using Deferred Springs during creation of
+ * the network allows all the edges to be connected together and the network
+ * to be created without resolving the Springs until their results need to be
+ * known, at which point the network is complete and the spring addition and
+ * and substitution calculations will work on a complete and valid network.
+ *
+ * @author Caolan McNamara (caolanm at redhat.com)
+ */
+ private static class DeferredSpring extends Spring
+ {
+ private SpringLayout sl;
+ private String edgeName;
+ private Component c;
+
+ public String toString()
+ {
+ return "DeferredSpring of edge" + edgeName + " of " + "something";
+ }
+
+ public DeferredSpring(SpringLayout s, String edge, Component component)
+ {
+ sl = s;
+ edgeName = edge;
+ c = component;
+ }
+
+ private Spring resolveSpring()
+ {
+ return sl.getConstraints(c).getConstraint(edgeName);
+ }
+
+ public int getMaximumValue()
+ {
+ return resolveSpring().getMaximumValue();
+ }
+
+ public int getMinimumValue()
+ {
+ return resolveSpring().getMinimumValue();
+ }
+
+ public int getPreferredValue()
+ {
+ return resolveSpring().getPreferredValue();
+ }
+
+ public int getValue()
+ {
+ int nRet = resolveSpring().getValue();
+ if (nRet == Spring.UNSET)
+ nRet = getPreferredValue();
+ return nRet;
+ }
+
+ public void setValue(int size)
+ {
+ resolveSpring().setValue(size);
+ }
+ }
+
+ private abstract static class DeferredDimension extends Spring
+ {
+ private int value;
+
+ public DeferredDimension()
+ {
+ value = Spring.UNSET;
+ }
+
+ public void setValue(int val)
+ {
+ value = val;
+ }
+
+ public int getValue()
+ {
+ if (value == Spring.UNSET)
+ return getPreferredValue();
+ return value;
+ }
+ }
+
+ private static class DeferredWidth extends DeferredDimension
+ {
+ private Component c;
+
+
+ public DeferredWidth(Component component)
+ {
+ c = component;
+ }
+
+ public String toString()
+ {
+ return "DeferredWidth of " + "something";
+ }
+
+ //clip max to a value we can do meaningful calculation with
+ public int getMaximumValue()
+ {
+ int widget_width = c.getMaximumSize().width;
+ return Math.min(Short.MAX_VALUE, widget_width);
+ }
+
+ public int getMinimumValue()
+ {
+ return c.getMinimumSize().width;
+ }
+
+ public int getPreferredValue()
+ {
+ return c.getPreferredSize().width;
+ }
+ }
+
+ private static class DeferredHeight extends DeferredDimension
+ {
+ private Component c;
+
+ public String toString()
+ {
+ return "DeferredHeight of " + "something";
+ }
+
+ public DeferredHeight(Component component)
+ {
+ c = component;
+ }
+
+ //clip max to a value we can do meaningful calculations with it
+ public int getMaximumValue()
+ {
+ int widget_height = c.getMaximumSize().height;
+ return Math.min(Short.MAX_VALUE, widget_height);
+ }
+
+ public int getMinimumValue()
+ {
+ return c.getMinimumSize().height;
+ }
+
+ public int getPreferredValue()
+ {
+ return c.getPreferredSize().height;
+ }
+ }
+
+ /**
+ * Returns the constraint of the edge named by <code>edgeName</code>.
+ *
+ * @param c the component from which to get the constraint.
+ * @param edgeName the name of the edge, one of {@link #EAST},
+ * {@link #WEST}, {@link #NORTH} or {@link #SOUTH}.
+ * @return the constraint of the edge <code>edgeName</code> of the
+ * component c.
+ */
+ public Spring getConstraint(String edgeName, Component c)
+ {
+ return new DeferredSpring(this, edgeName, c);
+ }
+
+ /**
+ * Returns the {@link Constraints} object associated with the specified
+ * component.
+ *
+ * @param c the component for which to determine the constraint.
+ * @return the {@link Constraints} object associated with the specified
+ * component.
+ */
+ public SpringLayout.Constraints getConstraints(Component c)
+ {
+ Constraints constraints = (Constraints) constraintsMap.get(c);
+
+ if (constraints == null)
+ {
+ constraints = new Constraints();
+
+ constraints.setWidth(new DeferredWidth(c));
+ constraints.setHeight(new DeferredHeight(c));
+ constraints.setX(Spring.constant(0));
+ constraints.setY(Spring.constant(0));
+
+ constraintsMap.put(c, constraints);
+ }
+
+ return constraints;
+ }
+
+ /**
+ * Returns the X alignment of the Container <code>p</code>.
+ *
+ * @param p
+ * the {@link java.awt.Container} for which to determine the X
+ * alignment.
+ * @return always 0.0
+ */
+ public float getLayoutAlignmentX(Container p)
+ {
+ return 0.0F;
+ }
+
+ /**
+ * Returns the Y alignment of the Container <code>p</code>.
+ *
+ * @param p the {@link java.awt.Container} for which to determine the Y
+ * alignment.
+ * @return always 0.0
+ */
+ public float getLayoutAlignmentY(Container p)
+ {
+ return 0.0F;
+ }
+
+ /**
+ * Recalculate a possibly cached layout.
+ */
+ public void invalidateLayout(Container p)
+ {
+ // nothing to do here yet
+ }
+
+ private Constraints initContainer(Container p)
+ {
+ Constraints c = getConstraints(p);
+
+ c.setX(Spring.constant(0));
+ c.setY(Spring.constant(0));
+ c.setWidth(null);
+ c.setHeight(null);
+ if (c.getEast() == null)
+ c.setEast(Spring.constant(0, 0, Integer.MAX_VALUE));
+ if (c.getSouth() == null)
+ c.setSouth(Spring.constant(0, 0, Integer.MAX_VALUE));
+
+ return c;
+ }
+
+ /**
+ * Lays out the container <code>p</code>.
+ *
+ * @param p the container to be laid out.
+ */
+ public void layoutContainer(Container p)
+ {
+ java.awt.Insets insets = p.getInsets();
+
+ Component[] components = p.getComponents();
+
+ Constraints cs = initContainer(p);
+ cs.dropCalcResult();
+
+ for (int index = 0 ; index < components.length; index++)
+ {
+ Component c = components[index];
+ getConstraints(c).dropCalcResult();
+ }
+
+ int offsetX = p.getInsets().left;
+ int offsetY = p.getInsets().right;
+
+ cs.getX().setValue(0);
+ cs.getY().setValue(0);
+ cs.getWidth().setValue(p.getWidth() - offsetX - insets.right);
+ cs.getHeight().setValue(p.getHeight() - offsetY - insets.bottom);
+
+ for (int index = 0; index < components.length; index++)
+ {
+ Component c = components[index];
+
+ Constraints constraints = getConstraints(c);
+
+ int x = constraints.getX().getValue();
+ int y = constraints.getY().getValue();
+ int width = constraints.getWidth().getValue();
+ int height = constraints.getHeight().getValue();
+
+ c.setBounds(x + offsetX, y + offsetY, width, height);
+ }
+ }
+
+ /**
+ * Calculates the maximum size of the layed out container. This
+ * respects the maximum sizes of all contained components.
+ *
+ * @param p the container to be laid out.
+ * @return the maximum size of the container.
+ */
+ public Dimension maximumLayoutSize(Container p)
+ {
+ java.awt.Insets insets = p.getInsets();
+
+ Constraints cs = initContainer(p);
+
+ int maxX = cs.getWidth().getMaximumValue() + insets.left + insets.right;
+ int maxY = cs.getHeight().getMaximumValue() + insets.top + insets.bottom;
+
+ return new Dimension(maxX, maxY);
+ }
+
+
+ /**
+ * Calculates the minimum size of the layed out container. This
+ * respects the minimum sizes of all contained components.
+ *
+ * @param p the container to be laid out.
+ * @return the minimum size of the container.
+ */
+ public Dimension minimumLayoutSize(Container p)
+ {
+ java.awt.Insets insets = p.getInsets();
+
+ Constraints cs = initContainer(p);
+
+ int maxX = cs.getWidth().getMinimumValue() + insets.left + insets.right;
+ int maxY = cs.getHeight().getMinimumValue() + insets.top + insets.bottom;
+
+ return new Dimension(maxX, maxY);
+ }
+
+ /**
+ * Calculates the preferred size of the layed out container. This
+ * respects the preferred sizes of all contained components.
+ *
+ * @param p the container to be laid out.
+ * @return the preferred size of the container.
+ */
+ public Dimension preferredLayoutSize(Container p)
+ {
+ java.awt.Insets insets = p.getInsets();
+
+ Constraints cs = initContainer(p);
+
+ int maxX = cs.getWidth().getPreferredValue() + insets.left + insets.right;
+ int maxY = cs.getHeight().getPreferredValue() + insets.top + insets.bottom;
+
+ return new Dimension(maxX, maxY);
+ }
+
+ /**
+ * Attaches the edge <code>e1</code> of component <code>c1</code> to
+ * the edge <code>e2</code> of component <code>c2</code> width the
+ * fixed strut <code>pad</code>.
+ *
+ * @param e1 the edge of component 1.
+ * @param c1 the component 1.
+ * @param pad the space between the components in pixels.
+ * @param e2 the edge of component 2.
+ * @param c2 the component 2.
+ */
+ public void putConstraint(String e1, Component c1, int pad, String e2,
+ Component c2)
+ {
+ putConstraint(e1, c1, Spring.constant(pad), e2, c2);
+ }
+
+ /**
+ * Attaches the edge <code>e1</code> of component <code>c1</code> to
+ * the edge <code>e2</code> of component <code>c2</code> width the
+ * {@link Spring} <code>s</code>.
+ *
+ * @param e1 the edge of component 1.
+ * @param c1 the component 1.
+ * @param s the space between the components as a {@link Spring} object.
+ * @param e2 the edge of component 2.
+ * @param c2 the component 2.
+ */
+ public void putConstraint(String e1, Component c1, Spring s, String e2,
+ Component c2)
+ {
+ Constraints constraints1 = getConstraints(c1);
+
+ Spring otherEdge = getConstraint(e2, c2);
+ constraints1.setConstraint(e1, Spring.sum(s, otherEdge));
+
+ }
+
+ /**
+ * Removes a layout component.
+ * @param c the layout component to remove.
+ */
+ public void removeLayoutComponent(Component c)
+ {
+ // do nothing here
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SwingConstants.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SwingConstants.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SwingConstants.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SwingConstants.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,77 @@
+/* SwingConstants.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+/**
+ * Defines constant values that are used throughout the Swing packages.
+ */
+public interface SwingConstants
+{
+ int CENTER = 0;
+ int TOP = 1;
+ int LEFT = 2;
+ int BOTTOM = 3;
+ int RIGHT = 4;
+
+ int NORTH = 1;
+ int NORTH_EAST = 2;
+ int EAST = 3;
+ int SOUTH_EAST = 4;
+ int SOUTH = 5;
+ int SOUTH_WEST = 6;
+ int WEST = 7;
+ int NORTH_WEST = 8;
+
+ int HORIZONTAL = 0;
+ int VERTICAL = 1;
+
+ int LEADING = 10;
+ int TRAILING = 11;
+
+ /**
+ * @since 1.4
+ */
+ int NEXT = 12;
+
+ /**
+ * @since 1.4
+ */
+ int PREVIOUS = 13;
+}
+
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SwingUtilities.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SwingUtilities.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SwingUtilities.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/SwingUtilities.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,1624 @@
+/* SwingUtilities.java --
+ Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.applet.Applet;
+import java.awt.Component;
+import java.awt.ComponentOrientation;
+import java.awt.Container;
+import java.awt.FontMetrics;
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.KeyboardFocusManager;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.awt.Window;
+import java.awt.event.ActionEvent;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleStateSet;
+import javax.swing.plaf.ActionMapUIResource;
+import javax.swing.plaf.InputMapUIResource;
+
+/**
+ * A number of static utility functions which are
+ * useful when drawing swing components, dispatching events, or calculating
+ * regions which need painting.
+ *
+ * @author Graydon Hoare (graydon at redhat.com)
+ * @author Andrew John Hughes (gnu_andrew at member.fsf.org)
+ */
+public class SwingUtilities
+ implements SwingConstants
+{
+ /**
+ * This frame should be used as parent for JWindow or JDialog
+ * that doesn't an owner
+ */
+ private static OwnerFrame ownerFrame;
+
+ private SwingUtilities()
+ {
+ // Do nothing.
+ }
+
+ /**
+ * Calculates the portion of the component's bounds which is inside the
+ * component's border insets. This area is usually the area a component
+ * should confine its painting to. The coordinates are returned in terms
+ * of the <em>component's</em> coordinate system, where (0,0) is the
+ * upper left corner of the component's bounds.
+ *
+ * @param c the component to measure the bounds of (if <code>null</code>,
+ * this method returns <code>null</code>).
+ * @param r a carrier to store the return value in (if <code>null</code>, a
+ * new <code>Rectangle</code> instance is created).
+ *
+ * @return The calculated area inside the component and its border insets.
+ */
+ public static Rectangle calculateInnerArea(JComponent c, Rectangle r)
+ {
+ if (c == null)
+ return null;
+ r = c.getBounds(r);
+ Insets i = c.getInsets();
+ r.x = i.left;
+ r.width = r.width - i.left - i.right;
+ r.y = i.top;
+ r.height = r.height - i.top - i.bottom;
+ return r;
+ }
+
+ /**
+ * Returns the focus owner or <code>null</code> if <code>comp</code> is not
+ * the focus owner or a parent of it.
+ *
+ * @param comp the focus owner or a parent of it
+ *
+ * @return the focus owner, or <code>null</code>
+ *
+ * @deprecated 1.4 Replaced by
+ * <code>KeyboardFocusManager.getFocusOwner()</code>.
+ */
+ public static Component findFocusOwner(Component comp)
+ {
+ // Get real focus owner.
+ Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager()
+ .getFocusOwner();
+
+ // Check if comp is the focus owner or a parent of it.
+ Component tmp = focusOwner;
+
+ while (tmp != null)
+ {
+ if (tmp == comp)
+ return focusOwner;
+
+ tmp = tmp.getParent();
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the <code>Accessible</code> child of the specified component
+ * which appears at the supplied <code>Point</code>. If there is no
+ * child located at that particular pair of co-ordinates, null is returned
+ * instead.
+ *
+ * @param c the component whose children may be found at the specified
+ * point.
+ * @param p the point at which to look for the existence of children
+ * of the specified component.
+ * @return the <code>Accessible</code> child at the point, <code>p</code>,
+ * or null if there is no child at this point.
+ * @see javax.accessibility.AccessibleComponent#getAccessibleAt
+ */
+ public static Accessible getAccessibleAt(Component c, Point p)
+ {
+ return c.getAccessibleContext().getAccessibleComponent().getAccessibleAt(p);
+ }
+
+ /**
+ * <p>
+ * Returns the <code>Accessible</code> child of the specified component
+ * that has the supplied index within the parent component. The indexing
+ * of the children is zero-based, making the first child have an index of
+ * 0.
+ * </p>
+ * <p>
+ * Caution is advised when using this method, as its operation relies
+ * on the behaviour of varying implementations of an abstract method.
+ * For greater surety, direct use of the AWT component implementation
+ * of this method is advised.
+ * </p>
+ *
+ * @param c the component whose child should be returned.
+ * @param i the index of the child within the parent component.
+ * @return the <code>Accessible</code> child at index <code>i</code>
+ * in the component, <code>c</code>.
+ * @see javax.accessibility.AccessibleContext#getAccessibleChild
+ * @see java.awt.Component.AccessibleAWTComponent#getAccessibleChild
+ */
+ public static Accessible getAccessibleChild(Component c, int i)
+ {
+ return c.getAccessibleContext().getAccessibleChild(i);
+ }
+
+ /**
+ * <p>
+ * Returns the number of <code>Accessible</code> children within
+ * the supplied component.
+ * </p>
+ * <p>
+ * Caution is advised when using this method, as its operation relies
+ * on the behaviour of varying implementations of an abstract method.
+ * For greater surety, direct use of the AWT component implementation
+ * of this method is advised.
+ * </p>
+ *
+ * @param c the component whose children should be counted.
+ * @return the number of children belonging to the component,
+ * <code>c</code>.
+ * @see javax.accessibility.AccessibleContext#getAccessibleChildrenCount
+ * @see java.awt.Component.AccessibleAWTComponent#getAccessibleChildrenCount
+ */
+ public static int getAccessibleChildrenCount(Component c)
+ {
+ return c.getAccessibleContext().getAccessibleChildrenCount();
+ }
+
+ /**
+ * <p>
+ * Returns the zero-based index of the specified component
+ * within its parent. If the component doesn't have a parent,
+ * -1 is returned.
+ * </p>
+ * <p>
+ * Caution is advised when using this method, as its operation relies
+ * on the behaviour of varying implementations of an abstract method.
+ * For greater surety, direct use of the AWT component implementation
+ * of this method is advised.
+ * </p>
+ *
+ * @param c the component whose parental index should be found.
+ * @return the index of the component within its parent, or -1
+ * if the component doesn't have a parent.
+ * @see javax.accessibility.AccessibleContext#getAccessibleIndexInParent
+ * @see java.awt.Component.AccessibleAWTComponent#getAccessibleIndexInParent
+ */
+ public static int getAccessibleIndexInParent(Component c)
+ {
+ return c.getAccessibleContext().getAccessibleIndexInParent();
+ }
+
+ /**
+ * <p>
+ * Returns a set of <code>AccessibleState</code>s, which represent
+ * the state of the supplied component.
+ * </p>
+ * <p>
+ * Caution is advised when using this method, as its operation relies
+ * on the behaviour of varying implementations of an abstract method.
+ * For greater surety, direct use of the AWT component implementation
+ * of this method is advised.
+ * </p>
+ *
+ * @param c the component whose accessible state should be retrieved.
+ * @return a set of <code>AccessibleState</code> objects, which represent
+ * the state of the supplied component.
+ * @see javax.accessibility.AccessibleContext#getAccessibleStateSet
+ * @see java.awt.Component.AccessibleAWTComponent#getAccessibleStateSet
+ */
+ public static AccessibleStateSet getAccessibleStateSet(Component c)
+ {
+ return c.getAccessibleContext().getAccessibleStateSet();
+ }
+
+ /**
+ * Calculates the bounds of a component in the component's own coordinate
+ * space. The result has the same height and width as the component's
+ * bounds, but its location is set to (0,0).
+ *
+ * @param aComponent The component to measure
+ *
+ * @return The component's bounds in its local coordinate space
+ */
+ public static Rectangle getLocalBounds(Component aComponent)
+ {
+ Rectangle bounds = aComponent.getBounds();
+ return new Rectangle(0, 0, bounds.width, bounds.height);
+ }
+
+ /**
+ * If <code>comp</code> is a RootPaneContainer, return its JRootPane.
+ * Otherwise call <code>getAncestorOfClass(JRootPane.class, a)</code>.
+ *
+ * @param comp The component to get the JRootPane of
+ *
+ * @return a suitable JRootPane for <code>comp</code>, or <code>null</code>
+ *
+ * @see javax.swing.RootPaneContainer#getRootPane
+ * @see #getAncestorOfClass
+ */
+ public static JRootPane getRootPane(Component comp)
+ {
+ if (comp instanceof RootPaneContainer)
+ return ((RootPaneContainer)comp).getRootPane();
+ else
+ return (JRootPane) getAncestorOfClass(JRootPane.class, comp);
+ }
+
+ /**
+ * Returns the least ancestor of <code>comp</code> which has the
+ * specified name.
+ *
+ * @param name The name to search for
+ * @param comp The component to search the ancestors of
+ *
+ * @return The nearest ancestor of <code>comp</code> with the given
+ * name, or <code>null</code> if no such ancestor exists
+ *
+ * @see java.awt.Component#getName
+ * @see #getAncestorOfClass
+ */
+ public static Container getAncestorNamed(String name, Component comp)
+ {
+ while (comp != null && (comp.getName() != name))
+ comp = comp.getParent();
+ return (Container) comp;
+ }
+
+ /**
+ * Returns the least ancestor of <code>comp</code> which is an instance
+ * of the specified class.
+ *
+ * @param c The class to search for
+ * @param comp The component to search the ancestors of
+ *
+ * @return The nearest ancestor of <code>comp</code> which is an instance
+ * of the given class, or <code>null</code> if no such ancestor exists
+ *
+ * @see #getAncestorOfClass
+ * @see #windowForComponent
+ */
+ public static Container getAncestorOfClass(Class c, Component comp)
+ {
+ while (comp != null && (! c.isInstance(comp)))
+ comp = comp.getParent();
+ return (Container) comp;
+ }
+
+ /**
+ * Returns the first ancestor of <code>comp</code> that is a {@link Window}
+ * or <code>null</code> if <code>comp</code> is not contained in a
+ * {@link Window}.
+ *
+ * This is equivalent to calling
+ * <code>getAncestorOfClass(Window, comp)</code> or
+ * <code>windowForComponent(comp)</code>.
+ *
+ * @param comp the component for which we are searching the ancestor Window
+ *
+ * @return the first ancestor Window of <code>comp</code> or
+ * <code>null</code> if <code>comp</code> is not contained in a Window
+ */
+ public static Window getWindowAncestor(Component comp)
+ {
+ return (Window) getAncestorOfClass(Window.class, comp);
+ }
+
+ /**
+ * Equivalent to calling <code>getAncestorOfClass(Window, comp)</code>.
+ *
+ * @param comp The component to search for an ancestor window
+ *
+ * @return An ancestral window, or <code>null</code> if none exists
+ */
+ public static Window windowForComponent(Component comp)
+ {
+ return (Window) getAncestorOfClass(Window.class, comp);
+ }
+
+ /**
+ * Returns the "root" of the component tree containint <code>comp</code>
+ * The root is defined as either the <em>least</em> ancestor of
+ * <code>comp</code> which is a {@link Window}, or the <em>greatest</em>
+ * ancestor of <code>comp</code> which is a {@link Applet} if no {@link
+ * Window} ancestors are found.
+ *
+ * @param comp The component to search for a root
+ *
+ * @return The root of the component's tree, or <code>null</code>
+ */
+ public static Component getRoot(Component comp)
+ {
+ Applet app = null;
+ Window win = null;
+
+ while (comp != null)
+ {
+ if (win == null && comp instanceof Window)
+ win = (Window) comp;
+ else if (comp instanceof Applet)
+ app = (Applet) comp;
+ comp = comp.getParent();
+ }
+
+ if (win != null)
+ return win;
+ return app;
+ }
+
+ /**
+ * Return true if a descends from b, in other words if b is an ancestor of a.
+ *
+ * @param a The child to search the ancestry of
+ * @param b The potential ancestor to search for
+ * @return true if a is a descendent of b, false otherwise
+ */
+ public static boolean isDescendingFrom(Component a, Component b)
+ {
+ while (true)
+ {
+ if (a == null || b == null)
+ return false;
+ if (a == b)
+ return true;
+ a = a.getParent();
+ }
+ }
+
+ /**
+ * Returns the deepest descendent of parent which is both visible and
+ * contains the point <code>(x,y)</code>. Returns parent when either
+ * parent is not a container, or has no children which contain
+ * <code>(x,y)</code>. Returns <code>null</code> when either
+ * <code>(x,y)</code> is outside the bounds of parent, or parent is
+ * <code>null</code>.
+ *
+ * @param parent The component to search the descendents of
+ * @param x Horizontal coordinate to search for
+ * @param y Vertical coordinate to search for
+ *
+ * @return A component containing <code>(x,y)</code>, or
+ * <code>null</code>
+ *
+ * @see java.awt.Container#findComponentAt(int, int)
+ */
+ public static Component getDeepestComponentAt(Component parent, int x, int y)
+ {
+ if (parent == null || (! parent.contains(x, y)))
+ return null;
+
+ if (! (parent instanceof Container))
+ return parent;
+
+ Container c = (Container) parent;
+ return c.findComponentAt(x, y);
+ }
+
+ /**
+ * Converts a point from a component's local coordinate space to "screen"
+ * coordinates (such as the coordinate space mouse events are delivered
+ * in). This operation is equivalent to translating the point by the
+ * location of the component (which is the origin of its coordinate
+ * space).
+ *
+ * @param p The point to convert
+ * @param c The component which the point is expressed in terms of
+ *
+ * @see #convertPointFromScreen
+ */
+ public static void convertPointToScreen(Point p, Component c)
+ {
+ Point c0 = c.getLocationOnScreen();
+ p.translate(c0.x, c0.y);
+ }
+
+ /**
+ * Converts a point from "screen" coordinates (such as the coordinate
+ * space mouse events are delivered in) to a component's local coordinate
+ * space. This operation is equivalent to translating the point by the
+ * negation of the component's location (which is the origin of its
+ * coordinate space).
+ *
+ * @param p The point to convert
+ * @param c The component which the point should be expressed in terms of
+ */
+ public static void convertPointFromScreen(Point p, Component c)
+ {
+ Point c0 = c.getLocationOnScreen();
+ p.translate(-c0.x, -c0.y);
+ }
+
+ /**
+ * Converts a point <code>(x,y)</code> from the coordinate space of one
+ * component to another. This is equivalent to converting the point from
+ * <code>source</code> space to screen space, then back from screen space
+ * to <code>destination</code> space. If exactly one of the two
+ * Components is <code>null</code>, it is taken to refer to the root
+ * ancestor of the other component. If both are <code>null</code>, no
+ * transformation is done.
+ *
+ * @param source The component which the point is expressed in terms of
+ * @param x Horizontal coordinate of point to transform
+ * @param y Vertical coordinate of point to transform
+ * @param destination The component which the return value will be
+ * expressed in terms of
+ *
+ * @return The point <code>(x,y)</code> converted from the coordinate space of the
+ * source component to the coordinate space of the destination component
+ *
+ * @see #convertPointToScreen
+ * @see #convertPointFromScreen
+ * @see #convertRectangle
+ * @see #getRoot
+ */
+ public static Point convertPoint(Component source, int x, int y,
+ Component destination)
+ {
+ Point pt = new Point(x, y);
+
+ if (source == null && destination == null)
+ return pt;
+
+ if (source == null)
+ source = getRoot(destination);
+
+ if (destination == null)
+ destination = getRoot(source);
+
+ if (source.isShowing() && destination.isShowing())
+ {
+ convertPointToScreen(pt, source);
+ convertPointFromScreen(pt, destination);
+ }
+
+ return pt;
+ }
+
+ public static Point convertPoint(Component source, Point aPoint, Component destination)
+ {
+ return convertPoint(source, aPoint.x, aPoint.y, destination);
+ }
+
+ /**
+ * Converts a rectangle from the coordinate space of one component to
+ * another. This is equivalent to converting the rectangle from
+ * <code>source</code> space to screen space, then back from screen space
+ * to <code>destination</code> space. If exactly one of the two
+ * Components is <code>null</code>, it is taken to refer to the root
+ * ancestor of the other component. If both are <code>null</code>, no
+ * transformation is done.
+ *
+ * @param source The component which the rectangle is expressed in terms of
+ * @param rect The rectangle to convert
+ * @param destination The component which the return value will be
+ * expressed in terms of
+ *
+ * @return A new rectangle, equal in size to the input rectangle, but
+ * with its position converted from the coordinate space of the source
+ * component to the coordinate space of the destination component
+ *
+ * @see #convertPointToScreen
+ * @see #convertPointFromScreen
+ * @see #convertPoint(Component, int, int, Component)
+ * @see #getRoot
+ */
+ public static Rectangle convertRectangle(Component source,
+ Rectangle rect,
+ Component destination)
+ {
+ Point pt = convertPoint(source, rect.x, rect.y, destination);
+ return new Rectangle(pt.x, pt.y, rect.width, rect.height);
+ }
+
+ /**
+ * Convert a mouse event which refrers to one component to another. This
+ * includes changing the mouse event's coordinate space, as well as the
+ * source property of the event. If <code>source</code> is
+ * <code>null</code>, it is taken to refer to <code>destination</code>'s
+ * root component. If <code>destination</code> is <code>null</code>, the
+ * new event will remain expressed in <code>source</code>'s coordinate
+ * system.
+ *
+ * @param source The component the mouse event currently refers to
+ * @param sourceEvent The mouse event to convert
+ * @param destination The component the new mouse event should refer to
+ *
+ * @return A new mouse event expressed in terms of the destination
+ * component's coordinate space, and with the destination component as
+ * its source
+ *
+ * @see #convertPoint(Component, int, int, Component)
+ */
+ public static MouseEvent convertMouseEvent(Component source,
+ MouseEvent sourceEvent,
+ Component destination)
+ {
+ Point newpt = convertPoint(source, sourceEvent.getX(), sourceEvent.getY(),
+ destination);
+
+ return new MouseEvent(destination, sourceEvent.getID(),
+ sourceEvent.getWhen(), sourceEvent.getModifiersEx(),
+ newpt.x, newpt.y, sourceEvent.getClickCount(),
+ sourceEvent.isPopupTrigger(), sourceEvent.getButton());
+ }
+
+ /**
+ * Recursively walk the component tree under <code>comp</code> calling
+ * <code>updateUI</code> on each {@link JComponent} found. This causes
+ * the entire tree to re-initialize its UI delegates.
+ *
+ * @param comp The component to walk the children of, calling <code>updateUI</code>
+ */
+ public static void updateComponentTreeUI(Component comp)
+ {
+ updateComponentTreeUIImpl(comp);
+ if (comp instanceof JComponent)
+ {
+ JComponent jc = (JComponent) comp;
+ jc.revalidate();
+ }
+ else
+ {
+ comp.invalidate();
+ comp.validate();
+ }
+ comp.repaint();
+ }
+
+ /**
+ * Performs the actual work for {@link #updateComponentTreeUI(Component)}.
+ * This calls updateUI() on c if it is a JComponent, and then walks down
+ * the component tree and calls this method on each child component.
+ *
+ * @param c the component to update the UI
+ */
+ private static void updateComponentTreeUIImpl(Component c)
+ {
+ if (c instanceof JComponent)
+ {
+ JComponent jc = (JComponent) c;
+ jc.updateUI();
+ }
+
+ Component[] components = null;
+ if (c instanceof JMenu)
+ components = ((JMenu) c).getMenuComponents();
+ else if (c instanceof Container)
+ components = ((Container) c).getComponents();
+ if (components != null)
+ {
+ for (int i = 0; i < components.length; ++i)
+ updateComponentTreeUIImpl(components[i]);
+ }
+ }
+
+ /**
+ * <p>Layout a "compound label" consisting of a text string and an icon
+ * which is to be placed near the rendered text. Once the text and icon
+ * are laid out, the text rectangle and icon rectangle parameters are
+ * altered to store the calculated positions.</p>
+ *
+ * <p>The size of the text is calculated from the provided font metrics
+ * object. This object should be the metrics of the font you intend to
+ * paint the label with.</p>
+ *
+ * <p>The position values control where the text is placed relative to
+ * the icon. The horizontal position value should be one of the constants
+ * <code>LEADING</code>, <code>TRAILING</code>, <code>LEFT</code>,
+ * <code>RIGHT</code> or <code>CENTER</code>. The vertical position value
+ * should be one fo the constants <code>TOP</code>, <code>BOTTOM</code>
+ * or <code>CENTER</code>.</p>
+ *
+ * <p>The text-icon gap value controls the number of pixels between the
+ * icon and the text.</p>
+ *
+ * <p>The alignment values control where the text and icon are placed, as
+ * a combined unit, within the view rectangle. The horizontal alignment
+ * value should be one of the constants <code>LEADING</code>,
+ * <code>TRAILING</code>, <code>LEFT</code>, <code>RIGHT</code> or
+ * <code>CENTER</code>. The vertical alignment valus should be one of the
+ * constants <code>TOP</code>, <code>BOTTOM</code> or
+ * <code>CENTER</code>.</p>
+ *
+ * <p>If the <code>LEADING</code> or <code>TRAILING</code> constants are
+ * given for horizontal alignment or horizontal text position, they are
+ * interpreted relative to the provided component's orientation property,
+ * a constant in the {@link java.awt.ComponentOrientation} class. For
+ * example, if the component's orientation is <code>LEFT_TO_RIGHT</code>,
+ * then the <code>LEADING</code> value is a synonym for <code>LEFT</code>
+ * and the <code>TRAILING</code> value is a synonym for
+ * <code>RIGHT</code></p>
+ *
+ * <p>If the text and icon are equal to or larger than the view
+ * rectangle, the horizontal and vertical alignment values have no
+ * affect.</p>
+ *
+ * @param c A component used for its orientation value
+ * @param fm The font metrics used to measure the text
+ * @param text The text to place in the compound label
+ * @param icon The icon to place next to the text
+ * @param verticalAlignment The vertical alignment of the label relative
+ * to its component
+ * @param horizontalAlignment The horizontal alignment of the label
+ * relative to its component
+ * @param verticalTextPosition The vertical position of the label's text
+ * relative to its icon
+ * @param horizontalTextPosition The horizontal position of the label's
+ * text relative to its icon
+ * @param viewR The view rectangle, specifying the area which layout is
+ * constrained to
+ * @param iconR A rectangle which is modified to hold the laid-out
+ * position of the icon
+ * @param textR A rectangle which is modified to hold the laid-out
+ * position of the text
+ * @param textIconGap The distance between text and icon
+ *
+ * @return The string of characters, possibly truncated with an elipsis,
+ * which is laid out in this label
+ */
+
+ public static String layoutCompoundLabel(JComponent c,
+ FontMetrics fm,
+ String text,
+ Icon icon,
+ int verticalAlignment,
+ int horizontalAlignment,
+ int verticalTextPosition,
+ int horizontalTextPosition,
+ Rectangle viewR,
+ Rectangle iconR,
+ Rectangle textR,
+ int textIconGap)
+ {
+
+ // Fix up the orientation-based horizontal positions.
+
+ if (horizontalTextPosition == LEADING)
+ {
+ if (c.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT)
+ horizontalTextPosition = RIGHT;
+ else
+ horizontalTextPosition = LEFT;
+ }
+ else if (horizontalTextPosition == TRAILING)
+ {
+ if (c.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT)
+ horizontalTextPosition = LEFT;
+ else
+ horizontalTextPosition = RIGHT;
+ }
+
+ // Fix up the orientation-based alignments.
+
+ if (horizontalAlignment == LEADING)
+ {
+ if (c.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT)
+ horizontalAlignment = RIGHT;
+ else
+ horizontalAlignment = LEFT;
+ }
+ else if (horizontalAlignment == TRAILING)
+ {
+ if (c.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT)
+ horizontalAlignment = LEFT;
+ else
+ horizontalAlignment = RIGHT;
+ }
+
+ return layoutCompoundLabel(fm, text, icon,
+ verticalAlignment,
+ horizontalAlignment,
+ verticalTextPosition,
+ horizontalTextPosition,
+ viewR, iconR, textR, textIconGap);
+ }
+
+ /**
+ * <p>Layout a "compound label" consisting of a text string and an icon
+ * which is to be placed near the rendered text. Once the text and icon
+ * are laid out, the text rectangle and icon rectangle parameters are
+ * altered to store the calculated positions.</p>
+ *
+ * <p>The size of the text is calculated from the provided font metrics
+ * object. This object should be the metrics of the font you intend to
+ * paint the label with.</p>
+ *
+ * <p>The position values control where the text is placed relative to
+ * the icon. The horizontal position value should be one of the constants
+ * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>. The
+ * vertical position value should be one fo the constants
+ * <code>TOP</code>, <code>BOTTOM</code> or <code>CENTER</code>.</p>
+ *
+ * <p>The text-icon gap value controls the number of pixels between the
+ * icon and the text.</p>
+ *
+ * <p>The alignment values control where the text and icon are placed, as
+ * a combined unit, within the view rectangle. The horizontal alignment
+ * value should be one of the constants <code>LEFT</code>, <code>RIGHT</code> or
+ * <code>CENTER</code>. The vertical alignment valus should be one of the
+ * constants <code>TOP</code>, <code>BOTTOM</code> or
+ * <code>CENTER</code>.</p>
+ *
+ * <p>If the text and icon are equal to or larger than the view
+ * rectangle, the horizontal and vertical alignment values have no
+ * affect.</p>
+ *
+ * <p>Note that this method does <em>not</em> know how to deal with
+ * horizontal alignments or positions given as <code>LEADING</code> or
+ * <code>TRAILING</code> values. Use the other overloaded variant of this
+ * method if you wish to use such values.
+ *
+ * @param fm The font metrics used to measure the text
+ * @param text The text to place in the compound label
+ * @param icon The icon to place next to the text
+ * @param verticalAlignment The vertical alignment of the label relative
+ * to its component
+ * @param horizontalAlignment The horizontal alignment of the label
+ * relative to its component
+ * @param verticalTextPosition The vertical position of the label's text
+ * relative to its icon
+ * @param horizontalTextPosition The horizontal position of the label's
+ * text relative to its icon
+ * @param viewR The view rectangle, specifying the area which layout is
+ * constrained to
+ * @param iconR A rectangle which is modified to hold the laid-out
+ * position of the icon
+ * @param textR A rectangle which is modified to hold the laid-out
+ * position of the text
+ * @param textIconGap The distance between text and icon
+ *
+ * @return The string of characters, possibly truncated with an elipsis,
+ * which is laid out in this label
+ */
+
+ public static String layoutCompoundLabel(FontMetrics fm,
+ String text,
+ Icon icon,
+ int verticalAlignment,
+ int horizontalAlignment,
+ int verticalTextPosition,
+ int horizontalTextPosition,
+ Rectangle viewR,
+ Rectangle iconR,
+ Rectangle textR,
+ int textIconGap)
+ {
+
+ // Work out basic height and width.
+
+ if (icon == null)
+ {
+ textIconGap = 0;
+ iconR.width = 0;
+ iconR.height = 0;
+ }
+ else
+ {
+ iconR.width = icon.getIconWidth();
+ iconR.height = icon.getIconHeight();
+ }
+ if (text == null || text.equals(""))
+ {
+ textIconGap = 0;
+ textR.width = 0;
+ textR.height = 0;
+ }
+ else
+ {
+ int fromIndex = 0;
+ textR.width = fm.stringWidth(text);
+ textR.height = fm.getHeight();
+ while (text.indexOf('\n', fromIndex) != -1)
+ {
+ textR.height += fm.getHeight();
+ fromIndex = text.indexOf('\n', fromIndex) + 1;
+ }
+ }
+
+ // Work out the position of text and icon, assuming the top-left coord
+ // starts at (0,0). We will fix that up momentarily, after these
+ // "position" decisions are made and we look at alignment.
+
+ switch (horizontalTextPosition)
+ {
+ case LEFT:
+ textR.x = 0;
+ iconR.x = textR.width + textIconGap;
+ break;
+ case RIGHT:
+ iconR.x = 0;
+ textR.x = iconR.width + textIconGap;
+ break;
+ case CENTER:
+ int centerLine = Math.max(textR.width, iconR.width) / 2;
+ textR.x = centerLine - textR.width/2;
+ iconR.x = centerLine - iconR.width/2;
+ break;
+ }
+
+ switch (verticalTextPosition)
+ {
+ case TOP:
+ textR.y = 0;
+ iconR.y = (horizontalTextPosition == CENTER
+ ? textR.height + textIconGap : 0);
+ break;
+ case BOTTOM:
+ iconR.y = 0;
+ textR.y = (horizontalTextPosition == CENTER
+ ? iconR.height + textIconGap
+ : Math.max(iconR.height - textR.height, 0));
+ break;
+ case CENTER:
+ int centerLine = Math.max(textR.height, iconR.height) / 2;
+ textR.y = centerLine - textR.height/2;
+ iconR.y = centerLine - iconR.height/2;
+ break;
+ }
+ // The two rectangles are laid out correctly now, but only assuming
+ // that their upper left corner is at (0,0). If we have any alignment other
+ // than TOP and LEFT, we need to adjust them.
+
+ Rectangle u = textR.union(iconR);
+ int horizontalAdjustment = viewR.x;
+ int verticalAdjustment = viewR.y;
+ switch (verticalAlignment)
+ {
+ case TOP:
+ break;
+ case BOTTOM:
+ verticalAdjustment += (viewR.height - u.height);
+ break;
+ case CENTER:
+ verticalAdjustment += ((viewR.height/2) - (u.height/2));
+ break;
+ }
+ switch (horizontalAlignment)
+ {
+ case LEFT:
+ break;
+ case RIGHT:
+ horizontalAdjustment += (viewR.width - u.width);
+ break;
+ case CENTER:
+ horizontalAdjustment += ((viewR.width/2) - (u.width/2));
+ break;
+ }
+
+ iconR.x += horizontalAdjustment;
+ iconR.y += verticalAdjustment;
+
+ textR.x += horizontalAdjustment;
+ textR.y += verticalAdjustment;
+
+ return text;
+ }
+
+ /**
+ * Calls {@link java.awt.EventQueue#invokeLater} with the
+ * specified {@link Runnable}.
+ */
+ public static void invokeLater(Runnable doRun)
+ {
+ java.awt.EventQueue.invokeLater(doRun);
+ }
+
+ /**
+ * Calls {@link java.awt.EventQueue#invokeAndWait} with the
+ * specified {@link Runnable}.
+ */
+ public static void invokeAndWait(Runnable doRun)
+ throws InterruptedException,
+ InvocationTargetException
+ {
+ java.awt.EventQueue.invokeAndWait(doRun);
+ }
+
+ /**
+ * Calls {@link java.awt.EventQueue#isDispatchThread()}.
+ *
+ * @return <code>true</code> if the current thread is the current AWT event
+ * dispatch thread.
+ */
+ public static boolean isEventDispatchThread()
+ {
+ return java.awt.EventQueue.isDispatchThread();
+ }
+
+ /**
+ * This method paints the given component at the given position and size.
+ * The component will be reparented to the container given.
+ *
+ * @param g The Graphics object to draw with.
+ * @param c The Component to draw
+ * @param p The Container to reparent to.
+ * @param x The x coordinate to draw at.
+ * @param y The y coordinate to draw at.
+ * @param w The width of the drawing area.
+ * @param h The height of the drawing area.
+ */
+ public static void paintComponent(Graphics g, Component c, Container p,
+ int x, int y, int w, int h)
+ {
+ Container parent = c.getParent();
+ if (parent != null)
+ parent.remove(c);
+ if (p != null)
+ p.add(c);
+
+ Shape savedClip = g.getClip();
+
+ g.setClip(x, y, w, h);
+ g.translate(x, y);
+
+ c.paint(g);
+
+ g.translate(-x, -y);
+ g.setClip(savedClip);
+ }
+
+ /**
+ * This method paints the given component in the given rectangle.
+ * The component will be reparented to the container given.
+ *
+ * @param g The Graphics object to draw with.
+ * @param c The Component to draw
+ * @param p The Container to reparent to.
+ * @param r The rectangle that describes the drawing area.
+ */
+ public static void paintComponent(Graphics g, Component c,
+ Container p, Rectangle r)
+ {
+ paintComponent(g, c, p, r.x, r.y, r.width, r.height);
+ }
+
+ /**
+ * This method returns the common Frame owner used in JDialogs or
+ * JWindow when no owner is provided.
+ *
+ * @return The common Frame
+ */
+ static Window getOwnerFrame(Window owner)
+ {
+ Window result = owner;
+ if (result == null)
+ {
+ if (ownerFrame == null)
+ ownerFrame = new OwnerFrame();
+ result = ownerFrame;
+ }
+ return result;
+ }
+
+ /**
+ * Checks if left mouse button was clicked.
+ *
+ * @param event the event to check
+ *
+ * @return true if left mouse was clicked, false otherwise.
+ */
+ public static boolean isLeftMouseButton(MouseEvent event)
+ {
+ return ((event.getModifiers() & InputEvent.BUTTON1_MASK) != 0);
+ }
+
+ /**
+ * Checks if middle mouse button was clicked.
+ *
+ * @param event the event to check
+ *
+ * @return true if middle mouse was clicked, false otherwise.
+ */
+ public static boolean isMiddleMouseButton(MouseEvent event)
+ {
+ return ((event.getModifiersEx() & InputEvent.BUTTON2_DOWN_MASK)
+ == InputEvent.BUTTON2_DOWN_MASK);
+ }
+
+ /**
+ * Checks if right mouse button was clicked.
+ *
+ * @param event the event to check
+ *
+ * @return true if right mouse was clicked, false otherwise.
+ */
+ public static boolean isRightMouseButton(MouseEvent event)
+ {
+ return ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK)
+ == InputEvent.BUTTON3_DOWN_MASK);
+ }
+
+ /**
+ * This frame should be used when constructing a Window/JDialog without
+ * a parent. In this case, we are forced to use this frame as a window's
+ * parent, because we simply cannot pass null instead of parent to Window
+ * constructor, since doing it will result in NullPointerException.
+ */
+ private static class OwnerFrame extends Frame
+ {
+ public void setVisible(boolean b)
+ {
+ // Do nothing here.
+ }
+
+ public boolean isShowing()
+ {
+ return true;
+ }
+ }
+
+ public static boolean notifyAction(Action action,
+ KeyStroke ks,
+ KeyEvent event,
+ Object sender,
+ int modifiers)
+ {
+ if (action != null && action.isEnabled())
+ {
+ String name = (String) action.getValue(Action.ACTION_COMMAND_KEY);
+ if (name == null
+ && event.getKeyChar() != KeyEvent.CHAR_UNDEFINED)
+ name = new String(new char[] {event.getKeyChar()});
+ action.actionPerformed(new ActionEvent(sender,
+ ActionEvent.ACTION_PERFORMED,
+ name, modifiers));
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * <p>Change the shared, UI-managed {@link ActionMap} for a given
+ * component. ActionMaps are arranged in a hierarchy, in order to
+ * encourage sharing of common actions between components. The hierarchy
+ * unfortunately places UI-managed ActionMaps at the <em>end</em> of the
+ * parent-pointer chain, as illustrated:</p>
+ *
+ * <pre>
+ * [{@link javax.swing.JComponent#getActionMap()}]
+ * --> [{@link javax.swing.ActionMap}]
+ * parent --> [{@link javax.swing.text.JTextComponent.KeymapActionMap}]
+ * parent --> [{@link javax.swing.plaf.ActionMapUIResource}]
+ * </pre>
+ *
+ * <p>Our goal with this method is to replace the first ActionMap along
+ * this chain which is an instance of {@link ActionMapUIResource}, since
+ * these are the ActionMaps which are supposed to be shared between
+ * components.</p>
+ *
+ * <p>If the provided ActionMap is <code>null</code>, we interpret the
+ * call as a request to remove the UI-managed ActionMap from the
+ * component's ActionMap parent chain.</p>
+ */
+ public static void replaceUIActionMap(JComponent component,
+ ActionMap uiActionMap)
+ {
+ ActionMap child = component.getActionMap();
+ if (child == null)
+ component.setActionMap(uiActionMap);
+ else
+ {
+ ActionMap parent = child.getParent();
+ while (parent != null && !(parent instanceof ActionMapUIResource))
+ {
+ child = parent;
+ parent = child.getParent();
+ }
+ // Sanity check to avoid loops.
+ if (child != uiActionMap)
+ child.setParent(uiActionMap);
+ }
+ }
+
+ /**
+ * <p>Change the shared, UI-managed {@link InputMap} for a given
+ * component. InputMaps are arranged in a hierarchy, in order to
+ * encourage sharing of common input mappings between components. The
+ * hierarchy unfortunately places UI-managed InputMaps at the
+ * <em>end</em> of the parent-pointer chain, as illustrated:</p>
+ *
+ * <pre>
+ * [{@link javax.swing.JComponent#getInputMap()}]
+ * --> [{@link javax.swing.InputMap}]
+ * parent --> [{@link javax.swing.text.JTextComponent.KeymapWrapper}]
+ * parent --> [{@link javax.swing.plaf.InputMapUIResource}]
+ * </pre>
+ *
+ * <p>Our goal with this method is to replace the first InputMap along
+ * this chain which is an instance of {@link InputMapUIResource}, since
+ * these are the InputMaps which are supposed to be shared between
+ * components.</p>
+ *
+ * <p>If the provided InputMap is <code>null</code>, we interpret the
+ * call as a request to remove the UI-managed InputMap from the
+ * component's InputMap parent chain.</p>
+ */
+ public static void replaceUIInputMap(JComponent component,
+ int condition,
+ InputMap uiInputMap)
+ {
+ InputMap child = component.getInputMap(condition);
+ if (child == null)
+ component.setInputMap(condition, uiInputMap);
+ else
+ {
+ InputMap parent = child.getParent();
+ while (parent != null && !(parent instanceof InputMapUIResource))
+ {
+ child = parent;
+ parent = parent.getParent();
+ }
+ // Sanity check to avoid loops.
+ if (child != uiInputMap)
+ child.setParent(uiInputMap);
+ }
+ }
+
+ /**
+ * Subtracts a rectangle from another and return the area as an array
+ * of rectangles.
+ * Returns the areas of rectA which are not covered by rectB.
+ * If the rectangles do not overlap, or if either parameter is
+ * <code>null</code>, a zero-size array is returned.
+ * @param rectA The first rectangle
+ * @param rectB The rectangle to subtract from the first
+ * @return An array of rectangles representing the area in rectA
+ * not overlapped by rectB
+ */
+ public static Rectangle[] computeDifference(Rectangle rectA, Rectangle rectB)
+ {
+ if (rectA == null || rectB == null)
+ return new Rectangle[0];
+
+ Rectangle[] r = new Rectangle[4];
+ int x1 = rectA.x;
+ int y1 = rectA.y;
+ int w1 = rectA.width;
+ int h1 = rectA.height;
+ int x2 = rectB.x;
+ int y2 = rectB.y;
+ int w2 = rectB.width;
+ int h2 = rectB.height;
+
+ // (outer box = rectA)
+ // -------------
+ // |_____0_____|
+ // | |rectB| |
+ // |_1|_____|_2|
+ // | 3 |
+ // -------------
+ int H0 = (y2 > y1) ? y2 - y1 : 0; // height of box 0
+ int H3 = (y2 + h2 < y1 + h1) ? y1 + h1 - y2 - h2 : 0; // height box 3
+ int W1 = (x2 > x1) ? x2 - x1 : 0; // width box 1
+ int W2 = (x1 + w1 > x2 + w2) ? x1 + w1 - x2 - w2 : 0; // w. box 2
+ int H12 = (H0 + H3 < h1) ? h1 - H0 - H3 : 0; // height box 1 & 2
+
+ if (H0 > 0)
+ r[0] = new Rectangle(x1, y1, w1, H0);
+ else
+ r[0] = null;
+
+ if (W1 > 0 && H12 > 0)
+ r[1] = new Rectangle(x1, y1 + H0, W1, H12);
+ else
+ r[1] = null;
+
+ if (W2 > 0 && H12 > 0)
+ r[2] = new Rectangle(x2 + w2, y1 + H0, W2, H12);
+ else
+ r[2] = null;
+
+ if (H3 > 0)
+ r[3] = new Rectangle(x1, y1 + H0 + H12, w1, H3);
+ else
+ r[3] = null;
+
+ // sort out null objects
+ int n = 0;
+ for (int i = 0; i < 4; i++)
+ if (r[i] != null)
+ n++;
+ Rectangle[] out = new Rectangle[n];
+ for (int i = 3; i >= 0; i--)
+ if (r[i] != null)
+ out[--n] = r[i];
+
+ return out;
+ }
+
+ /**
+ * Calculates the intersection of two rectangles. The result is stored
+ * in <code>rect</code>. This is basically the same
+ * like {@link Rectangle#intersection(Rectangle)}, only that it does not
+ * create new Rectangle instances. The tradeoff is that you loose any data in
+ * <code>rect</code>.
+ *
+ * @param x upper-left x coodinate of first rectangle
+ * @param y upper-left y coodinate of first rectangle
+ * @param w width of first rectangle
+ * @param h height of first rectangle
+ * @param rect a Rectangle object of the second rectangle
+ *
+ * @throws NullPointerException if rect is null
+ *
+ * @return a rectangle corresponding to the intersection of the
+ * two rectangles. An empty rectangle is returned if the rectangles
+ * do not overlap
+ */
+ public static Rectangle computeIntersection(int x, int y, int w, int h,
+ Rectangle rect)
+ {
+ int x2 = (int) rect.x;
+ int y2 = (int) rect.y;
+ int w2 = (int) rect.width;
+ int h2 = (int) rect.height;
+
+ int dx = (x > x2) ? x : x2;
+ int dy = (y > y2) ? y : y2;
+ int dw = (x + w < x2 + w2) ? (x + w - dx) : (x2 + w2 - dx);
+ int dh = (y + h < y2 + h2) ? (y + h - dy) : (y2 + h2 - dy);
+
+ if (dw >= 0 && dh >= 0)
+ rect.setBounds(dx, dy, dw, dh);
+ else
+ rect.setBounds(0, 0, 0, 0);
+
+ return rect;
+ }
+
+ /**
+ * Calculates the width of a given string.
+ *
+ * @param fm the <code>FontMetrics</code> object to use
+ * @param str the string
+ *
+ * @return the width of the the string.
+ */
+ public static int computeStringWidth(FontMetrics fm, String str)
+ {
+ return fm.stringWidth(str);
+ }
+
+ /**
+ * Calculates the union of two rectangles. The result is stored in
+ * <code>rect</code>. This is basically the same as
+ * {@link Rectangle#union(Rectangle)} except that it avoids creation of new
+ * Rectangle objects. The tradeoff is that you loose any data in
+ * <code>rect</code>.
+ *
+ * @param x upper-left x coodinate of first rectangle
+ * @param y upper-left y coodinate of first rectangle
+ * @param w width of first rectangle
+ * @param h height of first rectangle
+ * @param rect a Rectangle object of the second rectangle
+ *
+ * @throws NullPointerException if rect is null
+ *
+ * @return a rectangle corresponding to the union of the
+ * two rectangles; a rectangle encompassing both is returned if the
+ * rectangles do not overlap
+ */
+ public static Rectangle computeUnion(int x, int y, int w, int h,
+ Rectangle rect)
+ {
+ int x2 = (int) rect.x;
+ int y2 = (int) rect.y;
+ int w2 = (int) rect.width;
+ int h2 = (int) rect.height;
+
+ int dx = (x < x2) ? x : x2;
+ int dy = (y < y2) ? y : y2;
+ int dw = (x + w > x2 + w2) ? (x + w - dx) : (x2 + w2 - dx);
+ int dh = (y + h > y2 + h2) ? (y + h - dy) : (y2 + h2 - dy);
+
+ if (dw >= 0 && dh >= 0)
+ rect.setBounds(dx, dy, dw, dh);
+ else
+ rect.setBounds(0, 0, 0, 0);
+ return rect;
+ }
+
+ /**
+ * Tests if a rectangle contains another.
+ * @param a first rectangle
+ * @param b second rectangle
+ * @return true if a contains b, false otherwise
+ * @throws NullPointerException
+ */
+ public static boolean isRectangleContainingRectangle(Rectangle a, Rectangle b)
+ {
+ // Note: zero-size rects inclusive, differs from Rectangle.contains()
+ return b.width >= 0 && b.height >= 0 && b.width >= 0 && b.height >= 0
+ && b.x >= a.x && b.x + b.width <= a.x + a.width && b.y >= a.y
+ && b.y + b.height <= a.y + a.height;
+ }
+
+ /**
+ * Returns the InputMap that is provided by the ComponentUI of
+ * <code>component</code> for the specified condition.
+ *
+ * @param component the component for which the InputMap is returned
+ * @param cond the condition that specifies which of the three input
+ * maps should be returned, may be
+ * {@link JComponent#WHEN_IN_FOCUSED_WINDOW},
+ * {@link JComponent#WHEN_FOCUSED} or
+ * {@link JComponent#WHEN_ANCESTOR_OF_FOCUSED_COMPONENT}
+ *
+ * @return The input map.
+ */
+ public static InputMap getUIInputMap(JComponent component, int cond)
+ {
+ if (UIManager.getUI(component) != null)
+ // we assume here that the UI class sets the parent of the component's
+ // InputMap, which is the correct behaviour. If it's not, then
+ // this can be considered a bug
+ return component.getInputMap(cond).getParent();
+ else
+ return null;
+ }
+
+ /**
+ * Returns the ActionMap that is provided by the ComponentUI of
+ * <code>component</code>.
+ *
+ * @param component the component for which the ActionMap is returned
+ */
+ public static ActionMap getUIActionMap(JComponent component)
+ {
+ if (UIManager.getUI(component) != null)
+ // we assume here that the UI class sets the parent of the component's
+ // ActionMap, which is the correct behaviour. If it's not, then
+ // this can be considered a bug
+ return component.getActionMap().getParent();
+ else
+ return null;
+ }
+
+ /**
+ * Processes key bindings for the component that is associated with the
+ * key event. Note that this method does not make sense for
+ * JComponent-derived components, except when
+ * {@link JComponent#processKeyEvent(KeyEvent)} is overridden and super is
+ * not called.
+ *
+ * This method searches through the component hierarchy of the component's
+ * top-level container to find a <code>JComponent</code> that has a binding
+ * for the key event in the WHEN_IN_FOCUSED_WINDOW scope.
+ *
+ * @param ev the key event
+ *
+ * @return <code>true</code> if a binding has been found and processed,
+ * <code>false</code> otherwise
+ *
+ * @since 1.4
+ */
+ public static boolean processKeyBindings(KeyEvent ev)
+ {
+ Component c = ev.getComponent();
+ KeyStroke s = KeyStroke.getKeyStrokeForEvent(ev);
+ KeyboardManager km = KeyboardManager.getManager();
+ return km.processKeyStroke(c, s, ev);
+ }
+
+ /**
+ * Returns a string representing one of the horizontal alignment codes
+ * defined in the {@link SwingConstants} interface. The following table
+ * lists the constants and return values:
+ * <p>
+ * <table border="0">
+ * <tr>
+ * <th>Code:</th><th>Returned String:</th>
+ * </tr>
+ * <tr>
+ * <td>{@link SwingConstants#CENTER}</td>
+ * <td><code>"CENTER"</code></td>
+ * </tr>
+ * <tr>
+ * <td>{@link SwingConstants#LEFT}</td>
+ * <td><code>"LEFT"</code></td>
+ * </tr>
+ * <tr>
+ * <td>{@link SwingConstants#RIGHT}</td>
+ * <td><code>"RIGHT"</code></td>
+ * </tr>
+ * <tr>
+ * <td>{@link SwingConstants#LEADING}</td>
+ * <td><code>"LEADING"</code></td>
+ * </tr>
+ * <tr>
+ * <td>{@link SwingConstants#TRAILING}</td>
+ * <td><code>"TRAILING"</code></td>
+ * </tr>
+ * </table>
+ * </p>
+ * If the supplied code is not one of those listed, this methods will throw
+ * an {@link IllegalArgumentException}.
+ *
+ * @param code the code.
+ *
+ * @return A string representing the given code.
+ */
+ static String convertHorizontalAlignmentCodeToString(int code)
+ {
+ switch (code)
+ {
+ case SwingConstants.CENTER:
+ return "CENTER";
+ case SwingConstants.LEFT:
+ return "LEFT";
+ case SwingConstants.RIGHT:
+ return "RIGHT";
+ case SwingConstants.LEADING:
+ return "LEADING";
+ case SwingConstants.TRAILING:
+ return "TRAILING";
+ default:
+ throw new IllegalArgumentException("Unrecognised code: " + code);
+ }
+ }
+
+ /**
+ * Returns a string representing one of the vertical alignment codes
+ * defined in the {@link SwingConstants} interface. The following table
+ * lists the constants and return values:
+ * <p>
+ * <table border="0">
+ * <tr>
+ * <th>Code:</th><th>Returned String:</th>
+ * </tr>
+ * <tr>
+ * <td>{@link SwingConstants#CENTER}</td>
+ * <td><code>"CENTER"</code></td>
+ * </tr>
+ * <tr>
+ * <td>{@link SwingConstants#TOP}</td>
+ * <td><code>"TOP"</code></td>
+ * </tr>
+ * <tr>
+ * <td>{@link SwingConstants#BOTTOM}</td>
+ * <td><code>"BOTTOM"</code></td>
+ * </tr>
+ * </table>
+ * </p>
+ * If the supplied code is not one of those listed, this methods will throw
+ * an {@link IllegalArgumentException}.
+ *
+ * @param code the code.
+ *
+ * @return A string representing the given code.
+ */
+ static String convertVerticalAlignmentCodeToString(int code)
+ {
+ switch (code)
+ {
+ case SwingConstants.CENTER:
+ return "CENTER";
+ case SwingConstants.TOP:
+ return "TOP";
+ case SwingConstants.BOTTOM:
+ return "BOTTOM";
+ default:
+ throw new IllegalArgumentException("Unrecognised code: " + code);
+ }
+ }
+
+ /**
+ * Returns a string representing one of the default operation codes
+ * defined in the {@link WindowConstants} interface. The following table
+ * lists the constants and return values:
+ * <p>
+ * <table border="0">
+ * <tr>
+ * <th>Code:</th><th>Returned String:</th>
+ * </tr>
+ * <tr>
+ * <td>{@link WindowConstants#DO_NOTHING_ON_CLOSE}</td>
+ * <td><code>"DO_NOTHING_ON_CLOSE"</code></td>
+ * </tr>
+ * <tr>
+ * <td>{@link WindowConstants#HIDE_ON_CLOSE}</td>
+ * <td><code>"HIDE_ON_CLOSE"</code></td>
+ * </tr>
+ * <tr>
+ * <td>{@link WindowConstants#DISPOSE_ON_CLOSE}</td>
+ * <td><code>"DISPOSE_ON_CLOSE"</code></td>
+ * </tr>
+ * <tr>
+ * <td>{@link WindowConstants#EXIT_ON_CLOSE}</td>
+ * <td><code>"EXIT_ON_CLOSE"</code></td>
+ * </tr>
+ * </table>
+ * </p>
+ * If the supplied code is not one of those listed, this method will throw
+ * an {@link IllegalArgumentException}.
+ *
+ * @param code the code.
+ *
+ * @return A string representing the given code.
+ */
+ static String convertWindowConstantToString(int code)
+ {
+ switch (code)
+ {
+ case WindowConstants.DO_NOTHING_ON_CLOSE:
+ return "DO_NOTHING_ON_CLOSE";
+ case WindowConstants.HIDE_ON_CLOSE:
+ return "HIDE_ON_CLOSE";
+ case WindowConstants.DISPOSE_ON_CLOSE:
+ return "DISPOSE_ON_CLOSE";
+ case WindowConstants.EXIT_ON_CLOSE:
+ return "EXIT_ON_CLOSE";
+ default:
+ throw new IllegalArgumentException("Unrecognised code: " + code);
+ }
+ }
+
+ /**
+ * Converts a rectangle in the coordinate system of a child component into
+ * a rectangle of one of it's Ancestors. The result is stored in the input
+ * rectangle.
+ *
+ * @param comp the child component
+ * @param r the rectangle to convert
+ * @param ancestor the ancestor component
+ */
+ static void convertRectangleToAncestor(Component comp, Rectangle r,
+ Component ancestor)
+ {
+ if (comp == ancestor)
+ return;
+
+ r.x += comp.getX();
+ r.y += comp.getY();
+
+ Component parent = comp.getParent();
+ if (parent != null && parent != ancestor)
+ convertRectangleToAncestor(parent, r, ancestor);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Timer.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Timer.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Timer.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/Timer.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,476 @@
+/* Timer.java --
+ Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.Serializable;
+import java.util.EventListener;
+
+import javax.swing.event.EventListenerList;
+
+/**
+ * Fires one or more action events after the specified delay. This is
+ * a specialised version of <code>java.util.Timer</code> just for
+ * firing <code>ActionEvent</code>s. All Timers share one (daemon)
+ * Thread (or java.util.Timer). All events are fired from the event
+ * queue.
+ *
+ * @author Ronald Veldema
+ * @author Audrius Meskauskas (audriusa at Bionformatics.org) - bug fixes
+ * and documentation comments
+ */
+public class Timer
+ implements Serializable
+{
+ /**
+ * Given to the shared java.util.Timer to (possibly repeatedly) call
+ * queueEvent().
+ */
+ private class Task extends java.util.TimerTask
+ {
+ public void run()
+ {
+ if (logTimers)
+ System.out.println("javax.swing.Timer -> queueEvent()");
+ queueEvent();
+
+ if (!repeats)
+ task = null;
+ }
+ }
+
+ /**
+ * Use serialVersionUID for interoperability.
+ */
+ private static final long serialVersionUID = -1116180831621385484L;
+
+ /**
+ * The encloding class, used with {@link SwingUtilities#invokeLater}
+ * to invoke the {@link #drainEvents()}.
+ */
+ private Runnable drainer = new Runnable()
+ {
+ public void run()
+ {
+ drainEvents();
+ }
+ };
+
+ /**
+ * The static java.util.Timer daemon which will be used to schedule
+ * all javax.swing.Timer.Task objects. The daemon will always be
+ * running, even if there's no task scheduled in it.
+ */
+ private static java.util.Timer timer = new java.util.Timer("swing.Timer",
+ true);
+
+ /**
+ * If <code>true</code>, the timer prints a message to
+ * {@link System#out} when firing each event.
+ */
+ static boolean logTimers;
+
+ /**
+ * A field to store all listeners who are listening to this timer.
+ */
+ protected EventListenerList listenerList = new EventListenerList();
+
+ /**
+ * <code>true</code> if the timer coalesces events.
+ */
+ boolean coalesce = true;
+
+ /**
+ * <code>true</code> if the timer is firing repetetive events.
+ */
+ boolean repeats = true;
+
+ /**
+ * The delay between subsequent repetetive events.
+ */
+ int delay;
+
+ /**
+ * The initial delay before the first event.
+ */
+ int initialDelay;
+
+ /**
+ * The number of events that have been already fired by this timer.
+ * This is used as a numeric identifier for the next event that would
+ * be fired.
+ */
+ int ticks;
+
+ /**
+ * The task that calls queueEvent(). When null this Timer is stopped.
+ * This is package private to avoid synthetic accessor method.
+ */
+ Task task;
+
+ /**
+ * This object manages a "queue" of virtual actionEvents, maintained as a
+ * simple long counter. When the timer expires, a new event is queued,
+ * and a dispatcher object is pushed into the system event queue. When
+ * the system thread runs the dispatcher, it will fire as many
+ * ActionEvents as have been queued, unless the timer is set to
+ * coalescing mode, in which case it will fire only one ActionEvent.
+ */
+ private long queue;
+
+ /**
+ * <code>synchronized(queueLock)</code> replaces
+ * <code>synchronized(queue)</code> that is not supported by this language.
+ */
+ private Object queueLock = new Object();
+
+ /**
+ * Creates a new Timer object.
+ *
+ * @param d the default value for both initial and between event delay, in
+ * milliseconds.
+ * @param listener the first action listener, can be <code>null</code>.
+ */
+ public Timer(int d, ActionListener listener)
+ {
+ delay = d;
+ initialDelay = d;
+
+ if (listener != null)
+ addActionListener(listener);
+ }
+
+ /**
+ * Get the array of action listeners.
+ *
+ * @return the array of action listeners that are listening for the events,
+ * fired by this timer
+ *
+ * @since 1.4
+ */
+ public ActionListener[] getActionListeners()
+ {
+ return (ActionListener[]) listenerList.getListeners(ActionListener.class);
+ }
+
+ /**
+ * Sets whether the Timer coalesces multiple pending event firings.
+ * If the coalescing is enabled, the multiple events that have not been
+ * fired on time are replaced by the single event. The events may not
+ * be fired on time if the application is busy.
+ *
+ * @param c <code>true</code> (default) to enable the event coalescing,
+ * <code>false</code> otherwise
+ */
+ public void setCoalesce(boolean c)
+ {
+ coalesce = c;
+ }
+
+ /**
+ * Checks if the Timer coalesces multiple pending event firings.
+ * If the coalescing is enabled, the multiple events that have not been
+ * fired on time are replaced by the single event. The events may not
+ * be fired on time if the application is busy.
+ *
+ * @return <code>true</code> if the coalescing is enabled,
+ * <code>false</code> otherwise
+ */
+ public boolean isCoalesce()
+ {
+ return coalesce;
+ }
+
+ /**
+ * Get the event listeners of the given type that are listening for the
+ * events, fired by this timer.
+ *
+ * @param listenerType the listener type (for example, ActionListener.class)
+ *
+ * @return the array of event listeners that are listening for the events,
+ * fired by this timer
+ * @since 1.3
+ */
+ public EventListener[] getListeners(Class listenerType)
+ {
+ return listenerList.getListeners(listenerType);
+ }
+
+ /**
+ * Set the timer logging state. If it is set to <code>true</code>, the
+ * timer prints a message to {@link System#out} when firing each
+ * action event.
+ *
+ * @param lt <code>true</code> if logging is enabled, <code>false</code>
+ * (default value) otherwise
+ */
+ public static void setLogTimers(boolean lt)
+ {
+ logTimers = lt;
+ }
+
+ /**
+ * Return the logging state.
+ *
+ * @return <code>true</code> if the timer is printing a message to
+ * {@link System#out}
+ * when firing each action event
+ */
+ public static boolean getLogTimers()
+ {
+ return logTimers;
+ }
+
+ /**
+ * Set the delay between firing the subsequent events.
+ * This parameter does not change the value of the initial delay before
+ * firing the first event.
+ *
+ * @param d The time gap between the subsequent events, in milliseconds
+ *
+ * @throws IllegalArgumentException if <code>d</code> is less than zero.
+ */
+ public void setDelay(int d)
+ {
+ if (d < 0)
+ throw new IllegalArgumentException("Invalid delay: " + d);
+ delay = d;
+ }
+
+ /**
+ * Get the delay between firing the subsequent events.
+ *
+ * @return The delay between subsequent events, in milliseconds
+ */
+ public int getDelay()
+ {
+ return delay;
+ }
+
+ /**
+ * Set the intial delay before firing the first event since calling
+ * the {@link #start()} method. If the initial delay has not been
+ * set, it is assumed having the same value as the delay between the
+ * subsequent events.
+ *
+ * @param i the initial delay, in milliseconds
+ *
+ * @throws IllegalArgumentException if <code>i</code> is less than zero.
+ */
+ public void setInitialDelay(int i)
+ {
+ if (i < 0)
+ throw new IllegalArgumentException("Invalid initial delay: " + i);
+ initialDelay = i;
+ }
+
+ /**
+ * Get the intial delay before firing the first event since calling
+ * the {@link #start()} method. If the initial delay has not been
+ * set, returns the same value as {@link #getDelay()}.
+ *
+ * @return the initial delay before firing the first action event.
+ */
+ public int getInitialDelay()
+ {
+ return initialDelay;
+ }
+
+ /**
+ * Enable firing the repetetive events.
+ *
+ * @param r <code>true</code> (default value) to fire repetetive events.
+ * <code>false</code> to fire
+ * only one event after the initial delay
+ */
+ public void setRepeats(boolean r)
+ {
+ repeats = r;
+ }
+
+ /**
+ * Check is this timer fires repetetive events.
+ *
+ * @return <code>true</code> if the timer fires repetetive events,
+ * <code>false</code> if it fires
+ * only one event after the initial delay
+ */
+ public boolean isRepeats()
+ {
+ return repeats;
+ }
+
+ /**
+ * Get the timer state.
+ *
+ * @return <code>true</code> if the timer has been started and is firing
+ * the action events as scheduled. <code>false</code>
+ * if the timer is inactive.
+ */
+ public boolean isRunning()
+ {
+ return task != null;
+ }
+
+ /**
+ * Add the action listener
+ *
+ * @param listener the action listener to add
+ */
+ public void addActionListener(ActionListener listener)
+ {
+ listenerList.add(ActionListener.class, listener);
+ }
+
+ /**
+ * Remove the action listener.
+ *
+ * @param listener the action listener to remove
+ */
+ public void removeActionListener(ActionListener listener)
+ {
+ listenerList.remove(ActionListener.class, listener);
+ }
+
+ /**
+ * Cancel all pending tasks and fire the first event after the initial
+ * delay.
+ */
+ public void restart()
+ {
+ stop();
+ start();
+ }
+
+ /**
+ * Start firing the action events.
+ */
+ public void start()
+ {
+ Task t = task;
+ if (t == null)
+ {
+ t = new Task();
+ if (isRepeats())
+ timer.schedule(t, getInitialDelay(), getDelay());
+ else
+ timer.schedule(t, getInitialDelay());
+ task = t;
+ }
+ }
+
+ /**
+ * Stop firing the action events.
+ */
+ public void stop()
+ {
+ Task t = task;
+ if (t != null)
+ {
+ t.cancel();
+ task = null;
+ }
+ }
+
+ /**
+ * Fire the given action event to the action listeners.
+ *
+ * @param event the event to fire
+ */
+ protected void fireActionPerformed(ActionEvent event)
+ {
+ ActionListener[] listeners = getActionListeners();
+
+ for (int i = 0; i < listeners.length; i++)
+ listeners [ i ].actionPerformed(event);
+ }
+
+ /**
+ * Fire the action event, named "Timer" and having the numeric
+ * identifier, equal to the numer of events that have been
+ * already fired before.
+ */
+ void fireActionPerformed()
+ {
+ fireActionPerformed(new ActionEvent(this, ticks++, "Timer"));
+ }
+
+ /**
+ * Fire the queued action events.
+ * In the coalescing mode, a single event is fired as a replacement
+ * for all queued events. In non coalescing mode, a series of
+ * all queued events is fired.
+ * This is package-private to avoid an accessor method.
+ */
+ void drainEvents()
+ {
+ synchronized (queueLock)
+ {
+ if (isCoalesce())
+ {
+ if (queue > 0)
+ fireActionPerformed();
+ }
+ else
+ {
+ while (queue > 0)
+ {
+ fireActionPerformed();
+ queue--;
+ }
+ }
+ queue = 0;
+ }
+ }
+
+ /**
+ * Post a scheduled event to the event queue.
+ * Package-private to avoid an accessor method.
+ */
+ void queueEvent()
+ {
+ synchronized(queueLock)
+ {
+ queue++;
+ if (queue == 1)
+ SwingUtilities.invokeLater(drainer);
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ToolTipManager.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ToolTipManager.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ToolTipManager.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ToolTipManager.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,544 @@
+/* ToolTipManager.java --
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Point;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionListener;
+
+/**
+ * This class is responsible for the registration of JToolTips to Components
+ * and for displaying them when appropriate.
+ */
+public class ToolTipManager extends MouseAdapter implements MouseMotionListener
+{
+ /**
+ * This ActionListener is associated with the Timer that listens to whether
+ * the JToolTip can be hidden after four seconds.
+ */
+ protected class stillInsideTimerAction implements ActionListener
+ {
+ /**
+ * This method creates a new stillInsideTimerAction object.
+ */
+ protected stillInsideTimerAction()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * This method hides the JToolTip when the Timer has finished.
+ *
+ * @param event The ActionEvent.
+ */
+ public void actionPerformed(ActionEvent event)
+ {
+ hideTip();
+ }
+ }
+
+ /**
+ * This Actionlistener is associated with the Timer that listens to whether
+ * the mouse cursor has re-entered the JComponent in time for an immediate
+ * redisplay of the JToolTip.
+ */
+ protected class outsideTimerAction implements ActionListener
+ {
+ /**
+ * This method creates a new outsideTimerAction object.
+ */
+ protected outsideTimerAction()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * This method is called when the Timer that listens to whether the mouse
+ * cursor has re-entered the JComponent has run out.
+ *
+ * @param event The ActionEvent.
+ */
+ public void actionPerformed(ActionEvent event)
+ {
+ // TODO: What should be done here, if anything?
+ }
+ }
+
+ /**
+ * This ActionListener is associated with the Timer that listens to whether
+ * it is time for the JToolTip to be displayed after the mouse has entered
+ * the JComponent.
+ */
+ protected class insideTimerAction implements ActionListener
+ {
+ /**
+ * This method creates a new insideTimerAction object.
+ */
+ protected insideTimerAction()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * This method displays the JToolTip when the Mouse has been still for the
+ * delay.
+ *
+ * @param event The ActionEvent.
+ */
+ public void actionPerformed(ActionEvent event)
+ {
+ showTip();
+ }
+ }
+
+ /**
+ * The Timer that determines whether the Mouse has been still long enough
+ * for the JToolTip to be displayed.
+ */
+ Timer enterTimer;
+
+ /**
+ * The Timer that determines whether the Mouse has re-entered the JComponent
+ * quickly enough for the JToolTip to be displayed immediately.
+ */
+ Timer exitTimer;
+
+ /**
+ * The Timer that determines whether the JToolTip has been displayed long
+ * enough for it to be hidden.
+ */
+ Timer insideTimer;
+
+ /** A global enabled setting for the ToolTipManager. */
+ private transient boolean enabled = true;
+
+ /** lightWeightPopupEnabled */
+ protected boolean lightWeightPopupEnabled = true;
+
+ /** heavyWeightPopupEnabled */
+ protected boolean heavyWeightPopupEnabled = false;
+
+ /** The shared instance of the ToolTipManager. */
+ private static ToolTipManager shared;
+
+ /** The current component the tooltip is being displayed for. */
+ private static Component currentComponent;
+
+ /** The current tooltip. */
+ private static JToolTip currentTip;
+
+ /** The last known position of the mouse cursor. */
+ private static Point currentPoint;
+
+ /** */
+ private static Popup popup;
+
+ /**
+ * Creates a new ToolTipManager and sets up the timers.
+ */
+ ToolTipManager()
+ {
+ enterTimer = new Timer(750, new insideTimerAction());
+ enterTimer.setRepeats(false);
+
+ insideTimer = new Timer(4000, new stillInsideTimerAction());
+ insideTimer.setRepeats(false);
+
+ exitTimer = new Timer(500, new outsideTimerAction());
+ exitTimer.setRepeats(false);
+ }
+
+ /**
+ * This method returns the shared instance of ToolTipManager used by all
+ * JComponents.
+ *
+ * @return The shared instance of ToolTipManager.
+ */
+ public static ToolTipManager sharedInstance()
+ {
+ if (shared == null)
+ shared = new ToolTipManager();
+
+ return shared;
+ }
+
+ /**
+ * This method sets whether ToolTips are enabled or disabled for all
+ * JComponents.
+ *
+ * @param enabled Whether ToolTips are enabled or disabled for all
+ * JComponents.
+ */
+ public void setEnabled(boolean enabled)
+ {
+ if (! enabled)
+ {
+ enterTimer.stop();
+ exitTimer.stop();
+ insideTimer.stop();
+ }
+
+ this.enabled = enabled;
+ }
+
+ /**
+ * This method returns whether ToolTips are enabled.
+ *
+ * @return Whether ToolTips are enabled.
+ */
+ public boolean isEnabled()
+ {
+ return enabled;
+ }
+
+ /**
+ * This method returns whether LightweightToolTips are enabled.
+ *
+ * @return Whether LighweightToolTips are enabled.
+ */
+ public boolean isLightWeightPopupEnabled()
+ {
+ return lightWeightPopupEnabled;
+ }
+
+ /**
+ * This method sets whether LightweightToolTips are enabled. If you mix
+ * Lightweight and Heavyweight components, you must set this to false to
+ * ensure that the ToolTips popup above all other components.
+ *
+ * @param enabled Whether LightweightToolTips will be enabled.
+ */
+ public void setLightWeightPopupEnabled(boolean enabled)
+ {
+ lightWeightPopupEnabled = enabled;
+ heavyWeightPopupEnabled = ! enabled;
+ }
+
+ /**
+ * This method returns the initial delay before the ToolTip is shown when
+ * the mouse enters a Component.
+ *
+ * @return The initial delay before the ToolTip is shown.
+ */
+ public int getInitialDelay()
+ {
+ return enterTimer.getDelay();
+ }
+
+ /**
+ * Sets the initial delay before the ToolTip is shown when the
+ * mouse enters a Component.
+ *
+ * @param delay The initial delay before the ToolTip is shown.
+ *
+ * @throws IllegalArgumentException if <code>delay</code> is less than zero.
+ */
+ public void setInitialDelay(int delay)
+ {
+ enterTimer.setDelay(delay);
+ }
+
+ /**
+ * This method returns the time the ToolTip will be shown before being
+ * hidden.
+ *
+ * @return The time the ToolTip will be shown before being hidden.
+ */
+ public int getDismissDelay()
+ {
+ return insideTimer.getDelay();
+ }
+
+ /**
+ * Sets the time the ToolTip will be shown before being hidden.
+ *
+ * @param delay the delay (in milliseconds) before tool tips are hidden.
+ *
+ * @throws IllegalArgumentException if <code>delay</code> is less than zero.
+ */
+ public void setDismissDelay(int delay)
+ {
+ insideTimer.setDelay(delay);
+ }
+
+ /**
+ * This method returns the amount of delay where if the mouse re-enters a
+ * Component, the tooltip will be shown immediately.
+ *
+ * @return The reshow delay.
+ */
+ public int getReshowDelay()
+ {
+ return exitTimer.getDelay();
+ }
+
+ /**
+ * Sets the amount of delay where if the mouse re-enters a
+ * Component, the tooltip will be shown immediately.
+ *
+ * @param delay The reshow delay (in milliseconds).
+ *
+ * @throws IllegalArgumentException if <code>delay</code> is less than zero.
+ */
+ public void setReshowDelay(int delay)
+ {
+ exitTimer.setDelay(delay);
+ }
+
+ /**
+ * This method registers a JComponent with the ToolTipManager.
+ *
+ * @param component The JComponent to register with the ToolTipManager.
+ */
+ public void registerComponent(JComponent component)
+ {
+ component.addMouseListener(this);
+ component.addMouseMotionListener(this);
+ }
+
+ /**
+ * This method unregisters a JComponent with the ToolTipManager.
+ *
+ * @param component The JComponent to unregister with the ToolTipManager.
+ */
+ public void unregisterComponent(JComponent component)
+ {
+ component.removeMouseMotionListener(this);
+ component.removeMouseListener(this);
+ }
+
+ /**
+ * This method is called whenever the mouse enters a JComponent registered
+ * with the ToolTipManager. When the mouse enters within the period of time
+ * specified by the reshow delay, the tooltip will be displayed
+ * immediately. Otherwise, it must wait for the initial delay before
+ * displaying the tooltip.
+ *
+ * @param event The MouseEvent.
+ */
+ public void mouseEntered(MouseEvent event)
+ {
+ if (currentComponent != null
+ && getContentPaneDeepestComponent(event) == currentComponent)
+ return;
+ currentPoint = event.getPoint();
+
+ currentComponent = (Component) event.getSource();
+
+ if (exitTimer.isRunning())
+ {
+ exitTimer.stop();
+ showTip();
+ return;
+ }
+ // This should always be stopped unless we have just fake-exited.
+ if (!enterTimer.isRunning())
+ enterTimer.start();
+ }
+
+ /**
+ * This method is called when the mouse exits a JComponent registered with the
+ * ToolTipManager. When the mouse exits, the tooltip should be hidden
+ * immediately.
+ *
+ * @param event
+ * The MouseEvent.
+ */
+ public void mouseExited(MouseEvent event)
+ {
+ if (getContentPaneDeepestComponent(event) == currentComponent)
+ return;
+
+ currentPoint = event.getPoint();
+ currentComponent = null;
+ hideTip();
+
+ if (! enterTimer.isRunning())
+ exitTimer.start();
+ if (enterTimer.isRunning())
+ enterTimer.stop();
+ if (insideTimer.isRunning())
+ insideTimer.stop();
+ }
+
+ /**
+ * This method is called when the mouse is pressed on a JComponent
+ * registered with the ToolTipManager. When the mouse is pressed, the
+ * tooltip (if it is shown) must be hidden immediately.
+ *
+ * @param event The MouseEvent.
+ */
+ public void mousePressed(MouseEvent event)
+ {
+ currentPoint = event.getPoint();
+ if (enterTimer.isRunning())
+ enterTimer.restart();
+ else if (insideTimer.isRunning())
+ {
+ insideTimer.stop();
+ hideTip();
+ }
+ }
+
+ /**
+ * This method is called when the mouse is dragged in a JComponent
+ * registered with the ToolTipManager.
+ *
+ * @param event The MouseEvent.
+ */
+ public void mouseDragged(MouseEvent event)
+ {
+ currentPoint = event.getPoint();
+ if (enterTimer.isRunning())
+ enterTimer.restart();
+ }
+
+ /**
+ * This method is called when the mouse is moved in a JComponent registered
+ * with the ToolTipManager.
+ *
+ * @param event The MouseEvent.
+ */
+ public void mouseMoved(MouseEvent event)
+ {
+ currentPoint = event.getPoint();
+ if (enterTimer.isRunning())
+ enterTimer.restart();
+ }
+
+ /**
+ * This method displays the ToolTip. It can figure out the method needed to
+ * show it as well (whether to display it in heavyweight/lightweight panel
+ * or a window.) This is package-private to avoid an accessor method.
+ */
+ void showTip()
+ {
+ if (!enabled || currentComponent == null || !currentComponent.isEnabled()
+ || !currentComponent.isShowing())
+ {
+ popup = null;
+ return;
+ }
+
+ if (currentTip == null || currentTip.getComponent() != currentComponent
+ && currentComponent instanceof JComponent)
+ currentTip = ((JComponent) currentComponent).createToolTip();
+
+ Point p = currentPoint;
+ Point cP = currentComponent.getLocationOnScreen();
+ Dimension dims = currentTip.getPreferredSize();
+
+ JLayeredPane pane = null;
+ JRootPane r = ((JRootPane) SwingUtilities.getAncestorOfClass(JRootPane.class,
+ currentComponent));
+ if (r != null)
+ pane = r.getLayeredPane();
+ if (pane == null)
+ return;
+
+ p.translate(cP.x, cP.y);
+ adjustLocation(p, pane, dims);
+
+ currentTip.setBounds(0, 0, dims.width, dims.height);
+
+ PopupFactory factory = PopupFactory.getSharedInstance();
+ popup = factory.getPopup(currentComponent, currentTip, p.x, p.y);
+ popup.show();
+ }
+
+ /**
+ * Adjusts the point to a new location on the component,
+ * using the currentTip's dimensions.
+ *
+ * @param p - the point to convert.
+ * @param c - the component the point is on.
+ * @param d - the dimensions of the currentTip.
+ */
+ private Point adjustLocation(Point p, Component c, Dimension d)
+ {
+ if (p.x + d.width > c.getWidth())
+ p.x -= d.width;
+ if (p.x < 0)
+ p.x = 0;
+ if (p.y + d.height < c.getHeight())
+ p.y += d.height;
+ if (p.y + d.height > c.getHeight())
+ p.y -= d.height;
+
+ return p;
+ }
+
+ /**
+ * This method hides the ToolTip.
+ * This is package-private to avoid an accessor method.
+ */
+ void hideTip()
+ {
+ if (popup != null)
+ popup.hide();
+ }
+
+ /**
+ * This method returns the deepest component in the content pane for the
+ * first RootPaneContainer up from the currentComponent. This method is
+ * used in conjunction with one of the mouseXXX methods.
+ *
+ * @param e The MouseEvent.
+ *
+ * @return The deepest component in the content pane.
+ */
+ private Component getContentPaneDeepestComponent(MouseEvent e)
+ {
+ Component source = (Component) e.getSource();
+ Container parent = (Container) SwingUtilities.getAncestorOfClass(JRootPane.class,
+ currentComponent);
+ if (parent == null)
+ return null;
+ parent = ((JRootPane) parent).getContentPane();
+ Point p = e.getPoint();
+ p = SwingUtilities.convertPoint(source, p, parent);
+ Component target = SwingUtilities.getDeepestComponentAt(parent, p.x, p.y);
+ return target;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/TransferHandler.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/TransferHandler.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/TransferHandler.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/TransferHandler.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,197 @@
+/* TransferHandler.java --
+ Copyright (C) 2004, 2005, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import gnu.classpath.NotImplementedException;
+
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.event.ActionEvent;
+import java.awt.event.InputEvent;
+import java.io.Serializable;
+
+public class TransferHandler implements Serializable
+{
+ static class TransferAction extends AbstractAction
+ {
+ private String command;
+
+ public TransferAction(String command)
+ {
+ super(command);
+ this.command = command;
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ JComponent component = (JComponent) event.getSource();
+ TransferHandler transferHandler = component.getTransferHandler();
+ Clipboard clipboard = getClipboard(component);
+
+ if (clipboard == null)
+ {
+ // Access denied!
+ Toolkit.getDefaultToolkit().beep();
+ return;
+ }
+
+ if (command.equals(COMMAND_COPY))
+ transferHandler.exportToClipboard(component, clipboard, COPY);
+ else if (command.equals(COMMAND_CUT))
+ transferHandler.exportToClipboard(component, clipboard, MOVE);
+ else if (command.equals(COMMAND_PASTE))
+ {
+ Transferable transferable = clipboard.getContents(null);
+
+ if (transferable != null)
+ transferHandler.importData(component, transferable);
+ }
+ }
+
+ /**
+ * Get the system cliboard or null if the caller isn't allowed to
+ * access the system clipboard.
+ *
+ * @param component a component, used to get the toolkit.
+ * @return the clipboard
+ */
+ private static Clipboard getClipboard(JComponent component)
+ {
+ try
+ {
+ return component.getToolkit().getSystemClipboard();
+ }
+ catch (SecurityException se)
+ {
+ return null;
+ }
+ }
+ }
+
+ private static final long serialVersionUID = -967749805571669910L;
+
+ private static final String COMMAND_COPY = "copy";
+ private static final String COMMAND_CUT = "cut";
+ private static final String COMMAND_PASTE = "paste";
+
+ public static final int NONE = 0;
+ public static final int COPY = 1;
+ public static final int MOVE = 2;
+ public static final int COPY_OR_MOVE = 3;
+
+ private static Action copyAction = new TransferAction(COMMAND_COPY);
+ private static Action cutAction = new TransferAction(COMMAND_CUT);
+ private static Action pasteAction = new TransferAction(COMMAND_PASTE);
+
+ private int sourceActions;
+ private Icon visualRepresentation;
+
+ public static Action getCopyAction()
+ {
+ return copyAction;
+ }
+
+ public static Action getCutAction()
+ {
+ return cutAction;
+ }
+
+ public static Action getPasteAction()
+ {
+ return pasteAction;
+ }
+
+ protected TransferHandler()
+ {
+ this.sourceActions = NONE;
+ }
+
+ public TransferHandler(String property)
+ {
+ this.sourceActions = property != null ? COPY : NONE;
+ }
+
+ public boolean canImport(JComponent c, DataFlavor[] flavors)
+ throws NotImplementedException
+ {
+ return false;
+ }
+
+ protected Transferable createTransferable(JComponent c)
+ throws NotImplementedException
+ {
+ return null;
+ }
+
+ public void exportAsDrag(JComponent c, InputEvent e, int action)
+ throws NotImplementedException
+ {
+ // TODO: Implement this properly
+ }
+
+ protected void exportDone(JComponent c, Transferable data, int action)
+ throws NotImplementedException
+ {
+ // TODO: Implement this properly
+ }
+
+ public void exportToClipboard(JComponent c, Clipboard clip, int action)
+ throws NotImplementedException
+ {
+ // TODO: Implement this properly
+ }
+
+ public int getSourceActions(JComponent c)
+ {
+ return sourceActions;
+ }
+
+ public Icon getVisualRepresentation(Transferable t)
+ {
+ return visualRepresentation;
+ }
+
+ public boolean importData(JComponent c, Transferable t)
+ throws NotImplementedException
+ {
+ return false;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/UIDefaults.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/UIDefaults.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/UIDefaults.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/UIDefaults.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,847 @@
+/* UIDefaults.java -- database for all settings and interface bindings.
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Insets;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.lang.reflect.Method;
+import java.util.Hashtable;
+import java.util.LinkedList;
+import java.util.ListIterator;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import javax.swing.border.Border;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.InputMapUIResource;
+
+/**
+ * UIDefaults is a database where all settings and interface bindings are
+ * stored into. A PLAF implementation fills one of these (see for example
+ * plaf/basic/BasicLookAndFeel.java) with "ButtonUI" -> new BasicButtonUI().
+ *
+ * @author Ronald Veldema (rveldema at cs.vu.nl)
+ */
+public class UIDefaults extends Hashtable
+{
+
+ /** Our ResourceBundles. */
+ private LinkedList bundles;
+
+ /** The default locale. */
+ private Locale defaultLocale;
+
+ /** We use this for firing PropertyChangeEvents. */
+ private PropertyChangeSupport propertyChangeSupport;
+
+ /**
+ * Used for lazy instantiation of UIDefaults values so that they are not
+ * all loaded when a Swing application starts up, but only the values that
+ * are really needed. An <code>ActiveValue</code> is newly instantiated
+ * every time when the value is requested, as opposed to the normal
+ * {@link LazyValue} that is only instantiated once.
+ */
+ public static interface ActiveValue
+ {
+ Object createValue(UIDefaults table);
+ }
+
+ public static class LazyInputMap implements LazyValue
+ {
+ Object[] bind;
+ public LazyInputMap(Object[] bindings)
+ {
+ bind = bindings;
+ }
+ public Object createValue(UIDefaults table)
+ {
+ InputMapUIResource im = new InputMapUIResource();
+ for (int i = 0; 2 * i + 1 < bind.length; ++i)
+ {
+ Object curr = bind[2 * i];
+ if (curr instanceof KeyStroke)
+ im.put((KeyStroke) curr, bind[2 * i + 1]);
+ else
+ im.put(KeyStroke.getKeyStroke((String) curr),
+ bind[2 * i + 1]);
+ }
+ return im;
+ }
+ }
+
+ /**
+ * Used for lazy instantiation of UIDefaults values so that they are not
+ * all loaded when a Swing application starts up, but only the values that
+ * are really needed. A <code>LazyValue</code> is only instantiated once,
+ * as opposed to the {@link ActiveValue} that is newly created every time
+ * it is requested.
+ */
+ public static interface LazyValue
+ {
+ Object createValue(UIDefaults table);
+ }
+
+ public static class ProxyLazyValue implements LazyValue
+ {
+ LazyValue inner;
+ public ProxyLazyValue(String s)
+ {
+ final String className = s;
+ inner = new LazyValue()
+ {
+ public Object createValue(UIDefaults table)
+ {
+ try
+ {
+ return Class
+ .forName(className)
+ .getConstructor(new Class[] {})
+ .newInstance(new Object[] {});
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ }
+ };
+ }
+
+ public ProxyLazyValue(String c, String m)
+ {
+ final String className = c;
+ final String methodName = m;
+ inner = new LazyValue()
+ {
+ public Object createValue(UIDefaults table)
+ {
+ try
+ {
+ return Class
+ .forName(className)
+ .getMethod(methodName, new Class[] {})
+ .invoke(null, new Object[] {});
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ }
+ };
+ }
+
+ public ProxyLazyValue(String c, Object[] os)
+ {
+ final String className = c;
+ final Object[] objs = os;
+ final Class[] clss = new Class[objs.length];
+ for (int i = 0; i < objs.length; ++i)
+ {
+ clss[i] = objs[i].getClass();
+ }
+ inner = new LazyValue()
+ {
+ public Object createValue(UIDefaults table)
+ {
+ try
+ {
+ return Class
+ .forName(className)
+ .getConstructor(clss)
+ .newInstance(objs);
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ }
+ };
+ }
+
+ public ProxyLazyValue(String c, String m, Object[] os)
+ {
+ final String className = c;
+ final String methodName = m;
+ final Object[] objs = os;
+ final Class[] clss = new Class[objs.length];
+ for (int i = 0; i < objs.length; ++i)
+ {
+ clss[i] = objs[i].getClass();
+ }
+ inner = new LazyValue()
+ {
+ public Object createValue(UIDefaults table)
+ {
+ try
+ {
+ return Class
+ .forName(className)
+ .getMethod(methodName, clss)
+ .invoke(null, objs);
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ }
+ };
+ }
+
+ public Object createValue(UIDefaults table)
+ {
+ return inner.createValue(table);
+ }
+ }
+
+ /** Our serialVersionUID for serialization. */
+ private static final long serialVersionUID = 7341222528856548117L;
+
+ /**
+ * Constructs a new empty UIDefaults instance.
+ */
+ public UIDefaults()
+ {
+ bundles = new LinkedList();
+ defaultLocale = Locale.getDefault();
+ propertyChangeSupport = new PropertyChangeSupport(this);
+ }
+
+ /**
+ * Constructs a new UIDefaults instance and loads the specified entries.
+ * The entries are expected to come in pairs, that means
+ * <code>entries[0]</code> is a key, <code>entries[1]</code> is a value,
+ * <code>entries[2]</code> a key and so forth.
+ *
+ * @param entries the entries to initialize the UIDefaults instance with
+ */
+ public UIDefaults(Object[] entries)
+ {
+ this();
+
+ for (int i = 0; (2 * i + 1) < entries.length; ++i)
+ put(entries[2 * i], entries[2 * i + 1]);
+ }
+
+ /**
+ * Returns the entry for the specified <code>key</code> in the default
+ * locale.
+ *
+ * @return the entry for the specified <code>key</code>
+ */
+ public Object get(Object key)
+ {
+ return this.get(key, getDefaultLocale());
+ }
+
+ /**
+ * Returns the entry for the specified <code>key</code> in the Locale
+ * <code>loc</code>.
+ *
+ * @param key the key for which we return the value
+ * @param loc the locale
+ */
+ public Object get(Object key, Locale loc)
+ {
+ Object obj = null;
+
+ if (super.containsKey(key))
+ {
+ obj = super.get(key);
+ }
+ else if (key instanceof String)
+ {
+ String keyString = (String) key;
+ ListIterator i = bundles.listIterator(0);
+ while (i.hasNext())
+ {
+ String bundle_name = (String) i.next();
+ ResourceBundle res =
+ ResourceBundle.getBundle(bundle_name, loc);
+ if (res != null)
+ {
+ try
+ {
+ obj = res.getObject(keyString);
+ break;
+ }
+ catch (MissingResourceException me)
+ {
+ // continue, this bundle has no such key
+ }
+ }
+ }
+ }
+
+ // now we've found the object, resolve it.
+ // nb: LazyValues aren't supported in resource bundles, so it's correct
+ // to insert their results in the locale-less hashtable.
+
+ if (obj == null)
+ return null;
+
+ if (obj instanceof LazyValue)
+ {
+ Object resolved = ((LazyValue) obj).createValue(this);
+ super.remove(key);
+ super.put(key, resolved);
+ return resolved;
+ }
+ else if (obj instanceof ActiveValue)
+ {
+ return ((ActiveValue) obj).createValue(this);
+ }
+
+ return obj;
+ }
+
+ /**
+ * Puts a key and value into this UIDefaults object.<br>
+ * In contrast to
+ * {@link java.util.Hashtable}s <code>null</code>-values are accepted
+ * here and treated like #remove(key).
+ * <br>
+ * This fires a PropertyChangeEvent with key as name and the old and new
+ * values.
+ *
+ * @param key the key to put into the map
+ * @param value the value to put into the map
+ *
+ * @return the old value for key or <code>null</code> if <code>key</code>
+ * had no value assigned
+ */
+ public Object put(Object key, Object value)
+ {
+ Object old = checkAndPut(key, value);
+
+ if (key instanceof String && old != value)
+ firePropertyChange((String) key, old, value);
+ return old;
+ }
+
+ /**
+ * Puts a set of key-value pairs into the map.
+ * The entries are expected to come in pairs, that means
+ * <code>entries[0]</code> is a key, <code>entries[1]</code> is a value,
+ * <code>entries[2]</code> a key and so forth.
+ * <br>
+ * If a value is <code>null</code> it is treated like #remove(key).
+ * <br>
+ * This unconditionally fires a PropertyChangeEvent with
+ * <code>'UIDefaults'</code> as name and <code>null</code> for
+ * old and new value.
+ *
+ * @param entries the entries to be put into the map
+ */
+ public void putDefaults(Object[] entries)
+ {
+ for (int i = 0; (2 * i + 1) < entries.length; ++i)
+ {
+ checkAndPut(entries[2 * i], entries[2 * i + 1]);
+ }
+ firePropertyChange("UIDefaults", null, null);
+ }
+
+ /**
+ * Checks the value for <code>null</code> and put it into the Hashtable, if
+ * it is not <code>null</code>. If the value is <code>null</code> then
+ * remove the corresponding key.
+ *
+ * @param key the key to put into this UIDefauls table
+ * @param value the value to put into this UIDefaults table
+ *
+ * @return the old value for <code>key</code>
+ */
+ private Object checkAndPut(Object key, Object value)
+ {
+ Object old;
+
+ if (value != null)
+ old = super.put(key, value);
+ else
+ old = super.remove(key);
+
+ return old;
+ }
+
+ /**
+ * Returns a font entry for the default locale.
+ *
+ * @param key the key to the requested entry
+ *
+ * @return the font entry for <code>key</code> or null if no such entry
+ * exists
+ */
+ public Font getFont(Object key)
+ {
+ Object o = get(key);
+ return o instanceof Font ? (Font) o : null;
+ }
+
+ /**
+ * Returns a font entry for a specic locale.
+ *
+ * @param key the key to the requested entry
+ * @param locale the locale to the requested entry
+ *
+ * @return the font entry for <code>key</code> or null if no such entry
+ * exists
+ */
+ public Font getFont(Object key, Locale locale)
+ {
+ Object o = get(key, locale);
+ return o instanceof Font ? (Font) o : null;
+ }
+
+ /**
+ * Returns a color entry for the default locale.
+ *
+ * @param key the key to the requested entry
+ *
+ * @return the color entry for <code>key</code> or null if no such entry
+ * exists
+ */
+ public Color getColor(Object key)
+ {
+ Object o = get(key);
+ return o instanceof Color ? (Color) o : null;
+ }
+
+ /**
+ * Returns a color entry for a specic locale.
+ *
+ * @param key the key to the requested entry
+ * @param locale the locale to the requested entry
+ *
+ * @return the color entry for <code>key</code> or null if no such entry
+ * exists
+ */
+ public Color getColor(Object key, Locale locale)
+ {
+ Object o = get(key, locale);
+ return o instanceof Color ? (Color) o : null;
+ }
+
+ /**
+ * Returns an icon entry for the default locale.
+ *
+ * @param key the key to the requested entry
+ *
+ * @return the icon entry for <code>key</code> or null if no such entry
+ * exists
+ */
+ public Icon getIcon(Object key)
+ {
+ Object o = get(key);
+ return o instanceof Icon ? (Icon) o : null;
+ }
+
+ /**
+ * Returns an icon entry for a specic locale.
+ *
+ * @param key the key to the requested entry
+ * @param locale the locale to the requested entry
+ *
+ * @return the icon entry for <code>key</code> or null if no such entry
+ * exists
+ */
+ public Icon getIcon(Object key, Locale locale)
+ {
+ Object o = get(key, locale);
+ return o instanceof Icon ? (Icon) o : null;
+ }
+
+ /**
+ * Returns a border entry for the default locale.
+ *
+ * @param key the key to the requested entry
+ *
+ * @return the border entry for <code>key</code> or null if no such entry
+ * exists
+ */
+ public Border getBorder(Object key)
+ {
+ Object o = get(key);
+ return o instanceof Border ? (Border) o : null;
+ }
+
+ /**
+ * Returns a border entry for a specic locale.
+ *
+ * @param key the key to the requested entry
+ * @param locale the locale to the requested entry
+ *
+ * @return the border entry for <code>key</code> or null if no such entry
+ * exists
+ */
+ public Border getBorder(Object key, Locale locale)
+ {
+ Object o = get(key, locale);
+ return o instanceof Border ? (Border) o : null;
+ }
+
+ /**
+ * Returns a string entry for the default locale.
+ *
+ * @param key the key to the requested entry
+ *
+ * @return the string entry for <code>key</code> or null if no such entry
+ * exists
+ */
+ public String getString(Object key)
+ {
+ Object o = get(key);
+ return o instanceof String ? (String) o : null;
+ }
+
+ /**
+ * Returns a string entry for a specic locale.
+ *
+ * @param key the key to the requested entry
+ * @param locale the locale to the requested entry
+ *
+ * @return the string entry for <code>key</code> or null if no such entry
+ * exists
+ */
+ public String getString(Object key, Locale locale)
+ {
+ Object o = get(key, locale);
+ return o instanceof String ? (String) o : null;
+ }
+
+ /**
+ * Returns an integer entry for the default locale.
+ *
+ * @param key the key to the requested entry
+ *
+ * @return the integer entry for <code>key</code> or null if no such entry
+ * exists
+ */
+ public int getInt(Object key)
+ {
+ Object o = get(key);
+ return o instanceof Integer ? ((Integer) o).intValue() : 0;
+ }
+
+ /**
+ * Returns an integer entry for a specic locale.
+ *
+ * @param key the key to the requested entry
+ * @param locale the locale to the requested entry
+ *
+ * @return the integer entry for <code>key</code> or null if no such entry
+ * exists
+ */
+ public int getInt(Object key, Locale locale)
+ {
+ Object o = get(key, locale);
+ return o instanceof Integer ? ((Integer) o).intValue() : 0;
+ }
+
+ /**
+ * Returns a boolean entry for the default locale.
+ *
+ * @param key the key to the requested entry
+ *
+ * @return The boolean entry for <code>key</code> or <code>false</code> if no
+ * such entry exists.
+ */
+ public boolean getBoolean(Object key)
+ {
+ return Boolean.TRUE.equals(get(key));
+ }
+
+ /**
+ * Returns a boolean entry for a specic locale.
+ *
+ * @param key the key to the requested entry
+ * @param locale the locale to the requested entry
+ *
+ * @return the boolean entry for <code>key</code> or null if no such entry
+ * exists
+ */
+ public boolean getBoolean(Object key, Locale locale)
+ {
+ return Boolean.TRUE.equals(get(key, locale));
+ }
+
+ /**
+ * Returns an insets entry for the default locale.
+ *
+ * @param key the key to the requested entry
+ *
+ * @return the insets entry for <code>key</code> or null if no such entry
+ * exists
+ */
+ public Insets getInsets(Object key)
+ {
+ Object o = get(key);
+ return o instanceof Insets ? (Insets) o : null;
+ }
+
+ /**
+ * Returns an insets entry for a specic locale.
+ *
+ * @param key the key to the requested entry
+ * @param locale the locale to the requested entry
+ *
+ * @return the boolean entry for <code>key</code> or null if no such entry
+ * exists
+ */
+ public Insets getInsets(Object key, Locale locale)
+ {
+ Object o = get(key, locale);
+ return o instanceof Insets ? (Insets) o : null;
+ }
+
+ /**
+ * Returns a dimension entry for the default locale.
+ *
+ * @param key the key to the requested entry
+ *
+ * @return the dimension entry for <code>key</code> or null if no such entry
+ * exists
+ */
+ public Dimension getDimension(Object key)
+ {
+ Object o = get(key);
+ return o instanceof Dimension ? (Dimension) o : null;
+ }
+
+ /**
+ * Returns a dimension entry for a specic locale.
+ *
+ * @param key the key to the requested entry
+ * @param locale the locale to the requested entry
+ *
+ * @return the boolean entry for <code>key</code> or null if no such entry
+ * exists
+ */
+ public Dimension getDimension(Object key, Locale locale)
+ {
+ Object o = get(key, locale);
+ return o instanceof Dimension ? (Dimension) o : null;
+ }
+
+ /**
+ * Returns the ComponentUI class that renders a component. <code>id</code>
+ * is the ID for which the String value of the classname is stored in
+ * this UIDefaults map.
+ *
+ * @param id the ID of the UI class
+ * @param loader the ClassLoader to use
+ *
+ * @return the UI class for <code>id</code>
+ */
+ public Class getUIClass(String id, ClassLoader loader)
+ {
+ String className = (String) get(id);
+ if (className == null)
+ return null;
+ try
+ {
+ if (loader == null)
+ loader = ClassLoader.getSystemClassLoader();
+ return loader.loadClass (className);
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the ComponentUI class that renders a component. <code>id</code>
+ * is the ID for which the String value of the classname is stored in
+ * this UIDefaults map.
+ *
+ * @param id the ID of the UI class
+ *
+ * @return the UI class for <code>id</code>
+ */
+ public Class getUIClass(String id)
+ {
+ return getUIClass (id, null);
+ }
+
+ /**
+ * If a key is requested in #get(key) that has no value, this method
+ * is called before returning <code>null</code>.
+ *
+ * @param msg the error message
+ */
+ protected void getUIError(String msg)
+ {
+ System.err.println ("UIDefaults.getUIError: " + msg);
+ }
+
+ /**
+ * Returns the {@link ComponentUI} for the specified {@link JComponent}.
+ *
+ * @param target the component for which the ComponentUI is requested
+ *
+ * @return the {@link ComponentUI} for the specified {@link JComponent}
+ */
+ public ComponentUI getUI(JComponent target)
+ {
+ String classId = target.getUIClassID ();
+ Class cls = getUIClass (classId);
+ if (cls == null)
+ {
+ getUIError ("failed to locate UI class:" + classId);
+ return null;
+ }
+
+ Method factory;
+
+ try
+ {
+ factory = cls.getMethod ("createUI", new Class[] { JComponent.class } );
+ }
+ catch (NoSuchMethodException nme)
+ {
+ getUIError ("failed to locate createUI method on " + cls.toString ());
+ return null;
+ }
+
+ try
+ {
+ return (ComponentUI) factory.invoke (null, new Object[] { target });
+ }
+ catch (java.lang.reflect.InvocationTargetException ite)
+ {
+ getUIError ("InvocationTargetException ("+ ite.getTargetException()
+ +") calling createUI(...) on " + cls.toString ());
+ return null;
+ }
+ catch (Exception e)
+ {
+ getUIError ("exception calling createUI(...) on " + cls.toString ());
+ return null;
+ }
+ }
+
+ /**
+ * Adds a {@link PropertyChangeListener} to this UIDefaults map.
+ * Registered PropertyChangeListener are notified when values
+ * are beeing put into this UIDefaults map.
+ *
+ * @param listener the PropertyChangeListener to add
+ */
+ public void addPropertyChangeListener(PropertyChangeListener listener)
+ {
+ propertyChangeSupport.addPropertyChangeListener(listener);
+ }
+
+ /**
+ * Removes a PropertyChangeListener from this UIDefaults map.
+ *
+ * @param listener the PropertyChangeListener to remove
+ */
+ public void removePropertyChangeListener(PropertyChangeListener listener)
+ {
+ propertyChangeSupport.removePropertyChangeListener(listener);
+ }
+
+ /**
+ * Returns an array of all registered PropertyChangeListeners.
+ *
+ * @return all registered PropertyChangeListeners
+ */
+ public PropertyChangeListener[] getPropertyChangeListeners()
+ {
+ return propertyChangeSupport.getPropertyChangeListeners();
+ }
+
+ /**
+ * Fires a PropertyChangeEvent.
+ *
+ * @param property the property name
+ * @param oldValue the old value
+ * @param newValue the new value
+ */
+ protected void firePropertyChange(String property,
+ Object oldValue, Object newValue)
+ {
+ propertyChangeSupport.firePropertyChange(property, oldValue, newValue);
+ }
+
+ /**
+ * Adds a ResourceBundle for localized values.
+ *
+ * @param name the name of the ResourceBundle to add
+ */
+ public void addResourceBundle(String name)
+ {
+ bundles.addFirst(name);
+ }
+
+ /**
+ * Removes a ResourceBundle.
+ *
+ * @param name the name of the ResourceBundle to remove
+ */
+ public void removeResourceBundle(String name)
+ {
+ bundles.remove(name);
+ }
+
+ /**
+ * Sets the current locale to <code>loc</code>.
+ *
+ * @param loc the Locale to be set
+ */
+ public void setDefaultLocale(Locale loc)
+ {
+ defaultLocale = loc;
+ }
+
+ /**
+ * Returns the current default locale.
+ *
+ * @return the current default locale
+ */
+ public Locale getDefaultLocale()
+ {
+ return defaultLocale;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/UIManager.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/UIManager.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/UIManager.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/UIManager.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,763 @@
+/* UIManager.java --
+ Copyright (C) 2002, 2003, 2004, 2005, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Insets;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.io.Serializable;
+import java.util.Enumeration;
+import java.util.Locale;
+
+import javax.swing.border.Border;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.metal.MetalLookAndFeel;
+
+/**
+ * Manages the current {@link LookAndFeel} and any auxiliary {@link LookAndFeel}
+ * instances.
+ */
+public class UIManager implements Serializable
+{
+ /**
+ * Represents the basic information about a {@link LookAndFeel} (LAF), so
+ * that a list of installed LAFs can be presented without actually loading
+ * the LAF class(es).
+ */
+ public static class LookAndFeelInfo
+ {
+ String name, clazz;
+
+ /**
+ * Creates a new instance.
+ *
+ * @param name the look and feel name.
+ * @param clazz the look and feel class name.
+ */
+ public LookAndFeelInfo(String name,
+ String clazz)
+ {
+ this.name = name;
+ this.clazz = clazz;
+ }
+
+ /**
+ * Returns the name of the look and feel.
+ *
+ * @return The name of the look and feel.
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Returns the fully qualified class name for the {@link LookAndFeel}.
+ *
+ * @return The fully qualified class name for the {@link LookAndFeel}.
+ */
+ public String getClassName()
+ {
+ return clazz;
+ }
+
+ /**
+ * Returns a String representation of the LookAndFeelInfo object.
+ *
+ * @return a String representation of the LookAndFeelInfo object
+ */
+ public String toString()
+ {
+ StringBuffer s = new StringBuffer();
+ s.append(getClass().getName());
+ s.append('[');
+ s.append(getName());
+ s.append(' ');
+ s.append(getClassName());
+ s.append(']');
+ return s.toString();
+ }
+ }
+
+ /**
+ * A UIDefaults subclass that multiplexes between itself and a 'fallback'
+ * UIDefaults instance. This is used to protect the L&F UIDefaults from beeing
+ * overwritten by applications.
+ */
+ private static class MultiplexUIDefaults
+ extends UIDefaults
+ {
+ private class MultiplexEnumeration
+ implements Enumeration
+ {
+ Enumeration[] enums;
+ int i;
+ MultiplexEnumeration(Enumeration e1, Enumeration e2)
+ {
+ enums = new Enumeration[]{ e1, e2 };
+ i = 0;
+ }
+
+ public boolean hasMoreElements()
+ {
+ return enums[i].hasMoreElements() || i < enums.length - 1;
+ }
+
+ public Object nextElement()
+ {
+ Object val = enums[i].nextElement();
+ if (! enums[i].hasMoreElements() && i < enums.length - 1)
+ i++;
+ return val;
+ }
+
+ }
+
+ UIDefaults fallback;
+
+ MultiplexUIDefaults(UIDefaults d)
+ {
+ fallback = d;
+ }
+
+ public Object get(Object key)
+ {
+ Object val = super.get(key);
+ if (val == null)
+ val = fallback.get(key);
+ return val;
+ }
+
+ public Object get(Object key, Locale l)
+ {
+ Object val = super.get(key, l);
+ if (val == null)
+ val = fallback.get(key, l);
+ return val;
+ }
+
+ public Object remove(Object key)
+ {
+ Object val = super.remove(key);
+ if (val == null)
+ val = fallback.remove(key);
+ return val;
+ }
+
+ public int size()
+ {
+ return super.size() + fallback.size();
+ }
+
+ public Enumeration keys()
+ {
+ return new MultiplexEnumeration(super.keys(), fallback.keys());
+ }
+
+ public Enumeration elements()
+ {
+ return new MultiplexEnumeration(super.elements(), fallback.elements());
+ }
+ }
+
+ private static final long serialVersionUID = -5547433830339189365L;
+
+ /** The installed look and feel(s). */
+ static LookAndFeelInfo [] installed = {
+ new LookAndFeelInfo("Metal", "javax.swing.plaf.metal.MetalLookAndFeel"),
+ new LookAndFeelInfo("GNU", "gnu.javax.swing.plaf.gnu.GNULookAndFeel")
+ };
+
+ /** The installed auxiliary look and feels. */
+ static LookAndFeel[] auxLookAndFeels;
+
+ /** The current look and feel. */
+ static LookAndFeel currentLookAndFeel;
+
+ static MultiplexUIDefaults currentUIDefaults;
+
+ static UIDefaults lookAndFeelDefaults;
+
+ /** Property change listener mechanism. */
+ static PropertyChangeSupport listeners
+ = new PropertyChangeSupport(UIManager.class);
+
+ static
+ {
+ String defaultlaf = System.getProperty("swing.defaultlaf");
+ try
+ {
+ if (defaultlaf != null)
+ {
+ setLookAndFeel(defaultlaf);
+ }
+ else
+ {
+ setLookAndFeel(new MetalLookAndFeel());
+ }
+ }
+ catch (Exception ex)
+ {
+ System.err.println("cannot initialize Look and Feel: " + defaultlaf);
+ System.err.println("error: " + ex.toString());
+ ex.printStackTrace();
+ System.err.println("falling back to Metal Look and Feel");
+ try
+ {
+ setLookAndFeel(new MetalLookAndFeel());
+ }
+ catch (Exception ex2)
+ {
+ throw (Error) new AssertionError("There must be no problem installing"
+ + " the MetalLookAndFeel.")
+ .initCause(ex2);
+ }
+ }
+ }
+
+ /**
+ * Creates a new instance of the <code>UIManager</code>. There is no need
+ * to construct an instance of this class, since all methods are static.
+ */
+ public UIManager()
+ {
+ // Do nothing here.
+ }
+
+ /**
+ * Add a <code>PropertyChangeListener</code> to the listener list.
+ *
+ * @param listener the listener to add
+ */
+ public static void addPropertyChangeListener(PropertyChangeListener listener)
+ {
+ listeners.addPropertyChangeListener(listener);
+ }
+
+ /**
+ * Remove a <code>PropertyChangeListener</code> from the listener list.
+ *
+ * @param listener the listener to remove
+ */
+ public static void removePropertyChangeListener(PropertyChangeListener
+ listener)
+ {
+ listeners.removePropertyChangeListener(listener);
+ }
+
+ /**
+ * Returns an array of all added <code>PropertyChangeListener</code> objects.
+ *
+ * @return an array of listeners
+ *
+ * @since 1.4
+ */
+ public static PropertyChangeListener[] getPropertyChangeListeners()
+ {
+ return listeners.getPropertyChangeListeners();
+ }
+
+ /**
+ * Add a {@link LookAndFeel} to the list of auxiliary look and feels.
+ *
+ * @param laf the auxiliary look and feel (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if <code>laf</code> is <code>null</code>.
+ *
+ * @see #getAuxiliaryLookAndFeels()
+ */
+ public static void addAuxiliaryLookAndFeel(LookAndFeel laf)
+ {
+ if (laf == null)
+ throw new NullPointerException("Null 'laf' argument.");
+ if (auxLookAndFeels == null)
+ {
+ auxLookAndFeels = new LookAndFeel[1];
+ auxLookAndFeels[0] = laf;
+ return;
+ }
+
+ LookAndFeel[] temp = new LookAndFeel[auxLookAndFeels.length + 1];
+ System.arraycopy(auxLookAndFeels, 0, temp, 0, auxLookAndFeels.length);
+ auxLookAndFeels = temp;
+ auxLookAndFeels[auxLookAndFeels.length - 1] = laf;
+ }
+
+ /**
+ * Removes a {@link LookAndFeel} (LAF) from the list of auxiliary LAFs.
+ *
+ * @param laf the LAF to remove.
+ *
+ * @return <code>true</code> if the LAF was removed, and <code>false</code>
+ * otherwise.
+ */
+ public static boolean removeAuxiliaryLookAndFeel(LookAndFeel laf)
+ {
+ if (auxLookAndFeels == null)
+ return false;
+ int count = auxLookAndFeels.length;
+ if (count == 1 && auxLookAndFeels[0] == laf)
+ {
+ auxLookAndFeels = null;
+ return true;
+ }
+ for (int i = 0; i < count; i++)
+ {
+ if (auxLookAndFeels[i] == laf)
+ {
+ LookAndFeel[] temp = new LookAndFeel[auxLookAndFeels.length - 1];
+ if (i == 0)
+ {
+ System.arraycopy(auxLookAndFeels, 1, temp, 0, count - 1);
+ }
+ else if (i == count - 1)
+ {
+ System.arraycopy(auxLookAndFeels, 0, temp, 0, count - 1);
+ }
+ else
+ {
+ System.arraycopy(auxLookAndFeels, 0, temp, 0, i);
+ System.arraycopy(auxLookAndFeels, i + 1, temp, i,
+ count - i - 1);
+ }
+ auxLookAndFeels = temp;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns an array (possibly <code>null</code>) containing the auxiliary
+ * {@link LookAndFeel}s that are in use. These are used by the
+ * {@link javax.swing.plaf.multi.MultiLookAndFeel} class.
+ *
+ * @return The auxiliary look and feels (possibly <code>null</code>).
+ *
+ * @see #addAuxiliaryLookAndFeel(LookAndFeel)
+ */
+ public static LookAndFeel[] getAuxiliaryLookAndFeels()
+ {
+ return auxLookAndFeels;
+ }
+
+ /**
+ * Returns an object from the {@link UIDefaults} table for the current
+ * {@link LookAndFeel}.
+ *
+ * @param key the key.
+ *
+ * @return The object.
+ */
+ public static Object get(Object key)
+ {
+ return getDefaults().get(key);
+ }
+
+ /**
+ * Returns an object from the {@link UIDefaults} table for the current
+ * {@link LookAndFeel}.
+ *
+ * @param key the key.
+ *
+ * @return The object.
+ */
+ public static Object get(Object key, Locale locale)
+ {
+ return getDefaults().get(key, locale);
+ }
+
+ /**
+ * Returns a boolean value from the defaults table,
+ * <code>false</code> if key is not present.
+ *
+ * @since 1.4
+ */
+ public static boolean getBoolean(Object key)
+ {
+ Boolean value = (Boolean) get(key);
+ return value != null ? value.booleanValue() : false;
+ }
+
+ /**
+ * Returns a boolean value from the defaults table,
+ * <code>false</code> if key is not present.
+ *
+ * @since 1.4
+ */
+ public static boolean getBoolean(Object key, Locale locale)
+ {
+ Boolean value = (Boolean) get(key, locale);
+ return value != null ? value.booleanValue() : false;
+ }
+
+ /**
+ * Returns a border from the defaults table.
+ */
+ public static Border getBorder(Object key)
+ {
+ return (Border) get(key);
+ }
+
+ /**
+ * Returns a border from the defaults table.
+ *
+ * @since 1.4
+ */
+ public static Border getBorder(Object key, Locale locale)
+ {
+ return (Border) get(key, locale);
+ }
+
+ /**
+ * Returns a drawing color from the defaults table.
+ */
+ public static Color getColor(Object key)
+ {
+ return (Color) get(key);
+ }
+
+ /**
+ * Returns a drawing color from the defaults table.
+ */
+ public static Color getColor(Object key, Locale locale)
+ {
+ return (Color) get(key);
+ }
+
+ /**
+ * The fully qualified class name of the cross platform (Metal) look and feel.
+ * This string can be passed to Class.forName()
+ *
+ * @return <code>"javax.swing.plaf.metal.MetalLookAndFeel"</code>
+ */
+ public static String getCrossPlatformLookAndFeelClassName()
+ {
+ return "javax.swing.plaf.metal.MetalLookAndFeel";
+ }
+
+ /**
+ * Returns the default values for this look and feel.
+ *
+ * @return The {@link UIDefaults} for the current {@link LookAndFeel}.
+ */
+ public static UIDefaults getDefaults()
+ {
+ if (currentUIDefaults == null)
+ currentUIDefaults = new MultiplexUIDefaults(null);
+ return currentUIDefaults;
+ }
+
+ /**
+ * Returns a dimension from the defaults table.
+ */
+ public static Dimension getDimension(Object key)
+ {
+ return (Dimension) get(key);
+ }
+
+ /**
+ * Returns a dimension from the defaults table.
+ */
+ public static Dimension getDimension(Object key, Locale locale)
+ {
+ return (Dimension) get(key, locale);
+ }
+
+ /**
+ * Retrieves a font from the defaults table of the current
+ * LookAndFeel.
+ *
+ * @param key an Object that specifies the font. Typically,
+ * this is a String such as
+ * <code>TitledBorder.font</code>.
+ */
+ public static Font getFont(Object key)
+ {
+ return (Font) get(key);
+ }
+
+ /**
+ * Retrieves a font from the defaults table of the current
+ * LookAndFeel.
+ *
+ * @param key an Object that specifies the font. Typically,
+ * this is a String such as
+ * <code>TitledBorder.font</code>.
+ */
+ public static Font getFont(Object key, Locale locale)
+ {
+ return (Font) get(key, locale);
+ }
+
+ /**
+ * Returns an Icon from the defaults table.
+ */
+ public static Icon getIcon(Object key)
+ {
+ return (Icon) get(key);
+ }
+
+ /**
+ * Returns an Icon from the defaults table.
+ */
+ public static Icon getIcon(Object key, Locale locale)
+ {
+ return (Icon) get(key, locale);
+ }
+
+ /**
+ * Returns an Insets object from the defaults table.
+ */
+ public static Insets getInsets(Object key)
+ {
+ Object o = get(key);
+ if (o instanceof Insets)
+ return (Insets) o;
+ else
+ return null;
+ }
+
+ /**
+ * Returns an Insets object from the defaults table.
+ */
+ public static Insets getInsets(Object key, Locale locale)
+ {
+ Object o = get(key, locale);
+ if (o instanceof Insets)
+ return (Insets) o;
+ else
+ return null;
+ }
+
+ /**
+ * Returns an array containing information about the {@link LookAndFeel}s
+ * that are installed.
+ *
+ * @return A list of the look and feels that are available (installed).
+ */
+ public static LookAndFeelInfo[] getInstalledLookAndFeels()
+ {
+ return installed;
+ }
+
+ public static int getInt(Object key)
+ {
+ Integer x = (Integer) get(key);
+ if (x == null)
+ return 0;
+ return x.intValue();
+ }
+
+ public static int getInt(Object key, Locale locale)
+ {
+ Integer x = (Integer) get(key, locale);
+ if (x == null)
+ return 0;
+ return x.intValue();
+ }
+
+ /**
+ * Returns the current look and feel (which may be <code>null</code>).
+ *
+ * @return The current look and feel.
+ *
+ * @see #setLookAndFeel(LookAndFeel)
+ */
+ public static LookAndFeel getLookAndFeel()
+ {
+ return currentLookAndFeel;
+ }
+
+ /**
+ * Returns the <code>UIDefaults</code> table of the currently active
+ * look and feel.
+ *
+ * @return The {@link UIDefaults} for the current {@link LookAndFeel}.
+ */
+ public static UIDefaults getLookAndFeelDefaults()
+ {
+ return lookAndFeelDefaults;
+ }
+
+ /**
+ * Returns a string from the defaults table.
+ */
+ public static String getString(Object key)
+ {
+ return (String) get(key);
+ }
+
+ /**
+ * Returns a string from the defaults table.
+ */
+ public static String getString(Object key, Locale locale)
+ {
+ return (String) get(key, locale);
+ }
+
+ /**
+ * Returns the name of the {@link LookAndFeel} class that implements the
+ * native systems look and feel if there is one, otherwise the name
+ * of the default cross platform LookAndFeel class.
+ *
+ * @return The fully qualified class name for the system look and feel.
+ *
+ * @see #getCrossPlatformLookAndFeelClassName()
+ */
+ public static String getSystemLookAndFeelClassName()
+ {
+ return getCrossPlatformLookAndFeelClassName();
+ }
+
+ /**
+ * Returns UI delegate from the current {@link LookAndFeel} that renders the
+ * target component.
+ *
+ * @param target the target component.
+ */
+ public static ComponentUI getUI(JComponent target)
+ {
+ return getDefaults().getUI(target);
+ }
+
+ /**
+ * Creates a new look and feel and adds it to the current array.
+ *
+ * @param name the look and feel name.
+ * @param className the fully qualified name of the class that implements the
+ * look and feel.
+ */
+ public static void installLookAndFeel(String name, String className)
+ {
+ installLookAndFeel(new LookAndFeelInfo(name, className));
+ }
+
+ /**
+ * Adds the specified look and feel to the current array and then calls
+ * setInstalledLookAndFeels(javax.swing.UIManager.LookAndFeelInfo[]).
+ */
+ public static void installLookAndFeel(LookAndFeelInfo info)
+ {
+ LookAndFeelInfo[] newInstalled = new LookAndFeelInfo[installed.length + 1];
+ System.arraycopy(installed, 0, newInstalled, 0, installed.length);
+ newInstalled[newInstalled.length - 1] = info;
+ setInstalledLookAndFeels(newInstalled);
+ }
+
+ /**
+ * Stores an object in the defaults table.
+ */
+ public static Object put(Object key, Object value)
+ {
+ return getDefaults().put(key, value);
+ }
+
+ /**
+ * Replaces the current array of installed LookAndFeelInfos.
+ */
+ public static void setInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos)
+ {
+ installed = infos;
+ }
+
+ /**
+ * Sets the current {@link LookAndFeel}.
+ *
+ * @param newLookAndFeel the new look and feel (<code>null</code> permitted).
+ *
+ * @throws UnsupportedLookAndFeelException if the look and feel is not
+ * supported on the current platform.
+ *
+ * @see LookAndFeel#isSupportedLookAndFeel()
+ */
+ public static void setLookAndFeel(LookAndFeel newLookAndFeel)
+ throws UnsupportedLookAndFeelException
+ {
+ if (newLookAndFeel != null && ! newLookAndFeel.isSupportedLookAndFeel())
+ throw new UnsupportedLookAndFeelException(newLookAndFeel.getName()
+ + " not supported on this platform");
+ LookAndFeel oldLookAndFeel = currentLookAndFeel;
+ if (oldLookAndFeel != null)
+ oldLookAndFeel.uninitialize();
+
+ // Set the current default look and feel using a LookAndFeel object.
+ currentLookAndFeel = newLookAndFeel;
+ if (newLookAndFeel != null)
+ {
+ newLookAndFeel.initialize();
+ lookAndFeelDefaults = newLookAndFeel.getDefaults();
+ if (currentUIDefaults == null)
+ currentUIDefaults =
+ new MultiplexUIDefaults(lookAndFeelDefaults);
+ else
+ currentUIDefaults.fallback = lookAndFeelDefaults;
+ }
+ else
+ {
+ currentUIDefaults = null;
+ }
+ listeners.firePropertyChange("lookAndFeel", oldLookAndFeel, newLookAndFeel);
+ //revalidate();
+ //repaint();
+ }
+
+ /**
+ * Set the current default look and feel using a class name.
+ *
+ * @param className the look and feel class name.
+ *
+ * @throws UnsupportedLookAndFeelException if the look and feel is not
+ * supported on the current platform.
+ *
+ * @see LookAndFeel#isSupportedLookAndFeel()
+ */
+ public static void setLookAndFeel(String className)
+ throws ClassNotFoundException, InstantiationException, IllegalAccessException,
+ UnsupportedLookAndFeelException
+ {
+ Class c = Class.forName(className, true,
+ Thread.currentThread().getContextClassLoader());
+ LookAndFeel a = (LookAndFeel) c.newInstance(); // throws class-cast-exception
+ setLookAndFeel(a);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/UnsupportedLookAndFeelException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/UnsupportedLookAndFeelException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/UnsupportedLookAndFeelException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/UnsupportedLookAndFeelException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,57 @@
+/* UnsupportedLookAndFeelException.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+/**
+ * Thrown by the {@link UIManager#setLookAndFeel(LookAndFeel)} method when the
+ * specified look and feel is not supported on the current platform.
+ *
+ * @see LookAndFeel#isSupportedLookAndFeel()
+ */
+public class UnsupportedLookAndFeelException extends Exception
+{
+ /**
+ * Creates a new exception instance with the specified message.
+ *
+ * @param s the exception message.
+ */
+ public UnsupportedLookAndFeelException(String s)
+ {
+ super(s);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ViewportLayout.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ViewportLayout.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ViewportLayout.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/ViewportLayout.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,202 @@
+/* ViewportLayout.java --
+ Copyright (C) 2002, 2004, 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.LayoutManager;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.io.Serializable;
+
+/**
+ * The default layout for {@link JViewport}. The viewport makes its view the
+ * same size as itself, but not smaller than its minimum size.
+ *
+ * If the port extends extends into space <em>past</em> the edge of the view,
+ * this layout manager moves the port up or to the left, in view space, by the
+ * amount of empty space (keep the lower and right edges lined up).
+ *
+ * @author Andrew Selkirk
+ * @author Graydon Hoare
+ * @author Audrius Meskauskas (audriusa at Bioinformatics.org)
+ */
+public class ViewportLayout implements LayoutManager, Serializable
+{
+ private static final long serialVersionUID = -788225906076097229L;
+
+ public ViewportLayout()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * The method is not used with this manager.
+ */
+ public void addLayoutComponent(String name, Component c)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * The method is not used with this manager.
+ */
+ public void removeLayoutComponent(Component c)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Get the preferred layout size. If the view implements
+ * {@link Scrollable}, this method returns
+ * {@link Scrollable#getPreferredScrollableViewportSize}.
+ * Otherwise, it returns {@link Component#getPreferredSize()}.
+ *
+ * @return the preferred layout size, as described about.
+ */
+ public Dimension preferredLayoutSize(Container parent)
+ {
+ JViewport vp = (JViewport)parent;
+ Component view = vp.getView();
+ if (view != null)
+ {
+ if (view instanceof Scrollable)
+ return ((Scrollable)view).getPreferredScrollableViewportSize();
+ return view.getPreferredSize();
+ }
+ else
+ return new Dimension();
+ }
+
+ /**
+ * Get the minimum layout size. Normally this method returns the value,
+ * returned by the view method {@link Component#getMinimumSize()}.
+ *
+ * If the view is not set, the zero size is returned.
+ *
+ * @param parent the viewport
+ * @return the minimum layout size.
+ */
+ public Dimension minimumLayoutSize(Container parent)
+ {
+ // These values have been determined by the Mauve test for this method.
+ return new Dimension(4, 4);
+ }
+
+ /**
+ * Layout the view and viewport to respect the following rules. These are not
+ * precisely the rules described in sun's javadocs, but they are the rules
+ * which sun's swing implementation follows, if you watch its behavior:
+ * <ol>
+ * <li>If the port is smaller than the view, leave the view at its current
+ * size.</li>
+ * <li>If the view is smaller than the port, the view is top aligned.</li>
+ * <li>If the view tracks the port size, the view position is always zero and
+ * the size equal to the viewport size</li>
+ * <li>In {@link JViewport#setViewSize(Dimension)}, the view size is never
+ * set smaller that its minimum size.</li>
+ * </ol>
+ *
+ * @see JViewport#getViewSize
+ * @see JViewport#setViewSize
+ * @see JViewport#getViewPosition
+ * @see JViewport#setViewPosition
+ */
+ public void layoutContainer(Container parent)
+ {
+ // The way to interpret this function is basically to ignore the names
+ // of methods it calls, and focus on the variable names here. getViewRect
+ // doesn't, for example, return the view; it returns the port bounds in
+ // view space. Likwise setViewPosition doesn't reposition the view; it
+ // positions the port, in view coordinates.
+
+ JViewport port = (JViewport) parent;
+ Component view = port.getView();
+
+ if (view == null)
+ return;
+
+ // These dimensions and positions are in *view space*. Do not mix
+ // variables in here from port space (eg. parent.getBounds()). This
+ // function should be entirely in view space, because the methods on
+ // the viewport require inputs in view space.
+
+ Rectangle portBounds = port.getViewRect();
+ Dimension viewPref = new Dimension(view.getPreferredSize());
+
+ Point portLowerRight = new Point(portBounds.x + portBounds.width,
+ portBounds.y + portBounds.height);
+
+ // vertical implementation of the above rules
+ if (view instanceof Scrollable)
+ {
+ Scrollable sView = (Scrollable) view;
+
+ // If the view size matches viewport size, the port offset can
+ // only be zero.
+ if (sView.getScrollableTracksViewportWidth())
+ {
+ viewPref.width = portBounds.width;
+ portBounds.x = 0;
+ }
+ if (sView.getScrollableTracksViewportHeight())
+ {
+ viewPref.height = portBounds.height;
+ portBounds.y = 0;
+ }
+ }
+
+ if (viewPref.width < portBounds.width)
+ viewPref.width = portBounds.width;
+ if (viewPref.height < portBounds.height)
+ viewPref.height = portBounds.height;
+
+ // If the view is larger than the port, the port is top and right
+ // aligned.
+ if (portLowerRight.x > viewPref.width)
+ portBounds.x = 0;
+
+ if (portLowerRight.y > viewPref.height)
+ portBounds.y = 0;
+
+ port.setViewSize(viewPref);
+ port.setViewPosition(portBounds.getLocation());
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/WindowConstants.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/WindowConstants.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/WindowConstants.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/WindowConstants.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,79 @@
+/* WindowConstants.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+/**
+ * Defines some constants that are used in Swing's top-level containers. See
+ * the following methods:
+ * <ul>
+ * <li>{@link JFrame#setDefaultCloseOperation(int)};</li>
+ * <li>{@link JInternalFrame#setDefaultCloseOperation(int)};</li>
+ * <li>{@link JDialog#setDefaultCloseOperation(int)};</li>
+ * </ul>
+ *
+ * @author Andrew Selkirk
+ */
+public interface WindowConstants
+{
+ /**
+ * Do nothing when the container is closed.
+ */
+ int DO_NOTHING_ON_CLOSE = 0;
+
+ /**
+ * Hide the container when it is closed.
+ */
+ int HIDE_ON_CLOSE = 1;
+
+ /**
+ * Dispose the container when it is closed.
+ *
+ * @see Window#dispose()
+ */
+ int DISPOSE_ON_CLOSE = 2;
+
+ /**
+ * Exit the application when the container is closed.
+ *
+ * @see System#exit(int)
+ *
+ * @since 1.4
+ */
+ int EXIT_ON_CLOSE = 3;
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/AbstractBorder.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/AbstractBorder.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/AbstractBorder.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/AbstractBorder.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,199 @@
+/* AbstractBorder.java --
+ Copyright (C) 2003, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.border;
+
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.Rectangle;
+import java.io.Serializable;
+
+
+/**
+ * An invisible zero-width border, serving as a base class for
+ * implementing more interesting borders.
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ * @author Ronald Veldema (rveldema at cs.vu.nl)
+ */
+public abstract class AbstractBorder implements Border, Serializable
+{
+ static final long serialVersionUID = -545885975315191844L;
+
+ /**
+ * Constructs a new AbstractBorder.
+ */
+ public AbstractBorder()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Performs nothing, because the default implementation provided by
+ * this class is an invisible, zero-width border. Subclasses will
+ * likely want to override this method, but they are not required
+ * to do so.
+ *
+ * @param c the component whose border is to be painted.
+ * @param g the graphics for painting.
+ * @param x the horizontal position for painting the border.
+ * @param y the vertical position for painting the border.
+ * @param width the width of the available area for painting the border.
+ * @param height the height of the available area for painting the border.
+ */
+ public void paintBorder(Component c, Graphics g, int x, int y, int width,
+ int height)
+ {
+ // A previous version of Classpath had emitted a warning when
+ // this method was called. The warning was removed because it is
+ // perfectly legal for a subclass to not override the paintBorder
+ // method. An example would be EmptyBorder.
+ }
+
+ /**
+ * Returns the insets required for drawing this border around the specified
+ * component.
+ *
+ * @param c the component that the border applies to (ignored here,
+ * subclasses may use it).
+ *
+ * @return an Insets object whose <code>left</code>, <code>right</code>,
+ * <code>top</code> and <code>bottom</code> fields indicate the
+ * width of the border at the respective edge, which is zero
+ * for the default implementation provided by AbstractButton.
+ *
+ * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
+ */
+ public Insets getBorderInsets(Component c)
+ {
+ return new Insets(0, 0, 0, 0);
+ }
+
+ /**
+ * Returns the insets required for drawing this border around the specified
+ * component. The default implementation provided here sets the
+ * <code>left</code>, <code>right</code>, <code>top</code> and
+ * <code>bottom</code> fields of the passed <code>insets</code> parameter to
+ * zero.
+ *
+ * @param c the component that the border applies to (ignored here,
+ * subclasses may use it).
+ * @param insets an instance that will be overwritten and returned as the
+ * result (<code>null</code> not permitted).
+ *
+ * @return The border insets (the same object that was passed as the
+ * <code>insets</code> argument).
+ *
+ * @see #getBorderInsets(Component)
+ *
+ * @throws NullPointerException if <code>insets</code> is <code>null</code>.
+ */
+ public Insets getBorderInsets(Component c, Insets insets)
+ {
+ insets.left = insets.right = insets.top = insets.bottom = 0;
+ return insets;
+ }
+
+ /**
+ * Determines whether or not this border is opaque. An opaque border
+ * fills every pixel in its area when painting. Partially
+ * translucent borders must return <code>false</code>, or ugly
+ * artifacts can appear on screen. The default implementation
+ * provided here always returns <code>false</code>.
+ *
+ * @return <code>false</code>.
+ */
+ public boolean isBorderOpaque()
+ {
+ return false;
+ }
+
+ /**
+ * Returns a rectangle that covers the specified area minus the insets
+ * required to draw this border. Components that wish to determine an area
+ * into which they can safely draw without intersecting with a border might
+ * want to use this helper method.
+ *
+ * @param c the component in the center of this border.
+ * @param x the horizontal position of the border.
+ * @param y the vertical position of the border.
+ * @param width the width of the available area for the border.
+ * @param height the height of the available area for the border.
+ *
+ * @return The interior rectangle.
+ */
+ public Rectangle getInteriorRectangle(Component c, int x, int y, int width,
+ int height)
+ {
+ return getInteriorRectangle(c, this, x, y, width, height);
+ }
+
+ /**
+ * Returns a rectangle that covers the specified area minus the insets
+ * required to draw the specified border (if the border is <code>null</code>,
+ * zero insets are assumed). Components that wish to determine an area into
+ * which they can safely draw without intersecting with a border might want
+ * to use this helper method.
+ *
+ * @param c the component in the center of this border.
+ * @param b the border (<code>null</code> permitted).
+ * @param x the horizontal position of the border.
+ * @param y the vertical position of the border.
+ * @param width the width of the available area for the border.
+ * @param height the height of the available area for the border.
+ *
+ * @return The interior rectangle.
+ */
+ public static Rectangle getInteriorRectangle(Component c, Border b, int x,
+ int y, int width, int height)
+ {
+ Insets borderInsets;
+
+ if (b != null)
+ {
+ borderInsets = b.getBorderInsets(c);
+ x += borderInsets.left;
+ y += borderInsets.top;
+ width -= borderInsets.left + borderInsets.right;
+ height -= borderInsets.top + borderInsets.bottom;
+ }
+
+ return new Rectangle(x, y, width, height);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/BevelBorder.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/BevelBorder.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/BevelBorder.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/BevelBorder.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,585 @@
+/* BevelBorder.java --
+ Copyright (C) 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.border;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Insets;
+
+
+/**
+ * A rectangular, two pixel thick border that causes the enclosed area
+ * to appear as if it was raising out of or lowered into the screen. Some
+ * LookAndFeels use this kind of border for rectangular buttons.
+ *
+ * <p>A BevelBorder has a highlight and a shadow color. In the raised
+ * variant, the highlight color is used for the top and left edges,
+ * and the shadow color is used for the bottom and right edge. For an
+ * image, see the documentation of the individual constructors.
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class BevelBorder extends AbstractBorder
+{
+ /**
+ * Determined using the <code>serialver</code> tool
+ * of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5.
+ */
+ static final long serialVersionUID = -1034942243356299676L;
+
+
+ /**
+ * Indicates that the BevelBorder looks like if the enclosed area was
+ * raising out of the screen.
+ */
+ public static final int RAISED = 0;
+
+
+ /**
+ * Indicates that the BevelBorder looks like if the enclosed area was
+ * pressed into the screen.
+ */
+ public static final int LOWERED = 1;
+
+
+ /**
+ * The type of this BevelBorder, which is either {@link #RAISED}
+ * or {@link #LOWERED}.
+ */
+ protected int bevelType;
+
+
+ /**
+ * The outer highlight color, or <code>null</code> to indicate that
+ * the color shall be derived from the background of the component
+ * whose border is being painted.
+ */
+ protected Color highlightOuter;
+
+
+ /**
+ * The inner highlight color, or <code>null</code> to indicate that
+ * the color shall be derived from the background of the component
+ * whose border is being painted.
+ */
+ protected Color highlightInner;
+
+
+ /**
+ * The outer shadow color, or <code>null</code> to indicate that the
+ * color shall be derived from the background of the component whose
+ * border is being painted.
+ */
+ protected Color shadowOuter;
+
+
+ /**
+ * The inner shadow color, or <code>null</code> to indicate that the
+ * color shall be derived from the background of the component whose
+ * border is being painted.
+ */
+ protected Color shadowInner;
+
+
+ /**
+ * Constructs a BevelBorder whose colors will be derived from the
+ * background of the enclosed component. The background color is
+ * retrieved each time the border is painted, so a BevelBorder
+ * constructed by this method will automatically reflect a change
+ * to the component’s background color.
+ *
+ * <p><img src="doc-files/BevelBorder-1.png" width="500" height="150"
+ * alt="[An illustration showing raised and lowered BevelBorders]" />
+ *
+ * @param bevelType the desired appearance of the border. The value
+ * must be either {@link #RAISED} or {@link #LOWERED}.
+ *
+ * @throws IllegalArgumentException if <code>bevelType</code> has
+ * an unsupported value.
+ */
+ public BevelBorder(int bevelType)
+ {
+ if ((bevelType != RAISED) && (bevelType != LOWERED))
+ throw new IllegalArgumentException();
+
+ this.bevelType = bevelType;
+ }
+
+
+ /**
+ * Constructs a BevelBorder given its appearance type and two colors
+ * for its highlight and shadow.
+ *
+ * <p><img src="doc-files/BevelBorder-2.png" width="500" height="150"
+ * alt="[An illustration showing BevelBorders that were constructed
+ * with this method]" />
+ *
+ * @param bevelType the desired appearance of the border. The value
+ * must be either {@link #RAISED} or {@link #LOWERED}.
+ *
+ * @param highlight the color that will be used for the inner
+ * side of the highlighted edges (top and left if
+ * if <code>bevelType</code> is {@link #RAISED}; bottom
+ * and right otherwise). The color for the outer side
+ * is a brightened version of this color.
+ *
+ * @param shadow the color that will be used for the outer
+ * side of the shadowed edges (bottom and right
+ * if <code>bevelType</code> is {@link #RAISED}; top
+ * and left otherwise). The color for the inner side
+ * is a brightened version of this color.
+ *
+ * @throws IllegalArgumentException if <code>bevelType</code> has
+ * an unsupported value.
+ *
+ * @throws NullPointerException if <code>highlight</code> or
+ * <code>shadow</code> is <code>null</code>.
+ *
+ * @see java.awt.Color#brighter()
+ */
+ public BevelBorder(int bevelType, Color highlight, Color shadow)
+ {
+ this(bevelType,
+ /* highlightOuter */ highlight.brighter(),
+ /* highlightInner */ highlight,
+ /* shadowOuter */ shadow,
+ /* shadowInner */ shadow.brighter());
+ }
+
+
+ /**
+ * Constructs a BevelBorder given its appearance type and all
+ * colors.
+ *
+ * <p><img src="doc-files/BevelBorder-3.png" width="500" height="150"
+ * alt="[An illustration showing BevelBorders that were constructed
+ * with this method]" />
+ *
+ * @param bevelType the desired appearance of the border. The value
+ * must be either {@link #RAISED} or {@link #LOWERED}.
+ *
+ * @param highlightOuter the color that will be used for the outer
+ * side of the highlighted edges (top and left if
+ * <code>bevelType</code> is {@link #RAISED}; bottom and
+ * right otherwise).
+ *
+ * @param highlightInner the color that will be used for the inner
+ * side of the highlighted edges.
+ *
+ * @param shadowOuter the color that will be used for the outer
+ * side of the shadowed edges (bottom and right
+ * if <code>bevelType</code> is {@link #RAISED}; top
+ * and left otherwise).
+ *
+ * @param shadowInner the color that will be used for the inner
+ * side of the shadowed edges.
+ *
+ * @throws IllegalArgumentException if <code>bevelType</code> has
+ * an unsupported value.
+ *
+ * @throws NullPointerException if one of the passed colors
+ * is <code>null</code>.
+ */
+ public BevelBorder(int bevelType,
+ Color highlightOuter, Color highlightInner,
+ Color shadowOuter, Color shadowInner)
+ {
+ this(bevelType); // checks the validity of bevelType
+
+ if ((highlightOuter == null) || (highlightInner == null)
+ || (shadowOuter == null) || (shadowInner == null))
+ throw new NullPointerException();
+
+ this.highlightOuter = highlightOuter;
+ this.highlightInner = highlightInner;
+ this.shadowOuter = shadowOuter;
+ this.shadowInner = shadowInner;
+ }
+
+
+ /**
+ * Paints the border for a given component.
+ *
+ * @param c the component whose border is to be painted.
+ * @param g the graphics for painting.
+ * @param x the horizontal position for painting the border.
+ * @param y the vertical position for painting the border.
+ * @param width the width of the available area for painting the border.
+ * @param height the height of the available area for painting the border.
+ */
+ public void paintBorder(Component c, Graphics g,
+ int x, int y, int width, int height)
+ {
+ switch (bevelType)
+ {
+ case RAISED:
+ paintRaisedBevel(c, g, x, y, width, height);
+ break;
+
+ case LOWERED:
+ paintLoweredBevel(c, g, x, y, width, height);
+ break;
+ }
+ }
+
+
+ /**
+ * Measures the width of this border.
+ *
+ * @param c the component whose border is to be measured.
+ *
+ * @return an Insets object whose <code>left</code>, <code>right</code>,
+ * <code>top</code> and <code>bottom</code> fields indicate the
+ * width of the border at the respective edge.
+ *
+ * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
+ */
+ public Insets getBorderInsets(Component c)
+ {
+ return new Insets(2, 2, 2, 2);
+ }
+
+
+ /**
+ * Measures the width of this border, storing the results into a
+ * pre-existing Insets object.
+ *
+ * @param insets an Insets object for holding the result values.
+ * After invoking this method, the <code>left</code>,
+ * <code>right</code>, <code>top</code> and
+ * <code>bottom</code> fields indicate the width of the
+ * border at the respective edge.
+ *
+ * @return the same object that was passed for <code>insets</code>.
+ *
+ * @see #getBorderInsets(Component)
+ */
+ public Insets getBorderInsets(Component c, Insets insets)
+ {
+ insets.left = insets.right = insets.top = insets.bottom = 2;
+ return insets;
+ }
+
+
+ /**
+ * Determines the color that will be used for the outer side of
+ * highlighted edges when painting the border. If a highlight color
+ * has been specified upon constructing the border, that color is
+ * returned. Otherwise, the inner highlight color is brightened.
+ *
+ * @param c the component enclosed by this border.
+ *
+ * @return The color.
+ *
+ * @see #getHighlightInnerColor(java.awt.Component)
+ * @see java.awt.Color#brighter()
+ */
+ public Color getHighlightOuterColor(Component c)
+ {
+ if (highlightOuter != null)
+ return highlightOuter;
+ else
+ return getHighlightInnerColor(c).brighter();
+ }
+
+
+ /**
+ * Determines the color that will be used for the inner side of
+ * highlighted edges when painting the border. If a highlight color
+ * has been specified upon constructing the border, that color is
+ * returned. Otherwise, the background color of the enclosed
+ * component is brightened.
+ *
+ * @param c the component enclosed by this border.
+ *
+ * @return The color.
+ *
+ * @see java.awt.Component#getBackground()
+ * @see java.awt.Color#brighter()
+ */
+ public Color getHighlightInnerColor(Component c)
+ {
+ if (highlightInner != null)
+ return highlightInner;
+ else
+ return c.getBackground().brighter();
+ }
+
+
+ /**
+ * Determines the color that will be used for the inner side of
+ * shadowed edges when painting the border. If a shadow color has
+ * been specified upon constructing the border, that color is
+ * returned. Otherwise, the background color of the enclosed
+ * component is darkened.
+ *
+ * @param c the component enclosed by this border.
+ *
+ * @return The color.
+ *
+ * @see java.awt.Component#getBackground()
+ * @see java.awt.Color#darker()
+ */
+ public Color getShadowInnerColor(Component c)
+ {
+ if (shadowInner != null)
+ return shadowInner;
+ else
+ return c.getBackground().darker();
+ }
+
+
+ /**
+ * Determines the color that will be used for the outer side of
+ * shadowed edges when painting the border. If a shadow color
+ * has been specified upon constructing the border, that color is
+ * returned. Otherwise, the inner shadow color is darkened.
+ *
+ * @param c the component enclosed by this border.
+ *
+ * @return The color.
+ *
+ * @see #getShadowInnerColor(java.awt.Component)
+ * @see java.awt.Color#darker()
+ */
+ public Color getShadowOuterColor(Component c)
+ {
+ if (shadowOuter != null)
+ return shadowOuter;
+ else
+ return getShadowInnerColor(c).darker();
+ }
+
+
+ /**
+ * Returns the color that will be used for the outer side of
+ * highlighted edges when painting the border, or <code>null</code>
+ * if that color will be derived from the background of the enclosed
+ * Component.
+ *
+ * @return The color (possibly <code>null</code>).
+ */
+ public Color getHighlightOuterColor()
+ {
+ return highlightOuter;
+ }
+
+
+ /**
+ * Returns the color that will be used for the inner side of
+ * highlighted edges when painting the border, or <code>null</code>
+ * if that color will be derived from the background of the enclosed
+ * Component.
+ *
+ * @return The color (possibly <code>null</code>).
+ */
+ public Color getHighlightInnerColor()
+ {
+ return highlightInner;
+ }
+
+
+ /**
+ * Returns the color that will be used for the inner side of
+ * shadowed edges when painting the border, or <code>null</code> if
+ * that color will be derived from the background of the enclosed
+ * Component.
+ *
+ * @return The color (possibly <code>null</code>).
+ */
+ public Color getShadowInnerColor()
+ {
+ return shadowInner;
+ }
+
+
+ /**
+ * Returns the color that will be used for the outer side of
+ * shadowed edges when painting the border, or <code>null</code> if
+ * that color will be derived from the background of the enclosed
+ * Component.
+ *
+ * @return The color (possibly <code>null</code>).
+ */
+ public Color getShadowOuterColor()
+ {
+ return shadowOuter;
+ }
+
+
+ /**
+ * Returns the appearance of this border, which is either {@link
+ * #RAISED} or {@link #LOWERED}.
+ *
+ * @return The bevel type ({@link #RAISED} or {@link #LOWERED}).
+ */
+ public int getBevelType()
+ {
+ return bevelType;
+ }
+
+
+ /**
+ * Determines whether this border fills every pixel in its area
+ * when painting.
+ *
+ * <p>If the border colors are derived from the background color of
+ * the enclosed component, the result is <code>true</code> because
+ * the derivation method always returns opaque colors. Otherwise,
+ * the result depends on the opacity of the individual colors.
+ *
+ * @return <code>true</code> if the border is fully opaque, or
+ * <code>false</code> if some pixels of the background
+ * can shine through the border.
+ */
+ public boolean isBorderOpaque()
+ {
+ /* If the colors are to be drived from the enclosed Component's
+ * background color, the border is guaranteed to be fully opaque
+ * because Color.brighten() and Color.darken() always return an
+ * opaque color.
+ */
+ return
+ ((highlightOuter == null) || (highlightOuter.getAlpha() == 255))
+ && ((highlightInner == null) || (highlightInner.getAlpha() == 255))
+ && ((shadowInner == null) || (shadowInner.getAlpha() == 255))
+ && ((shadowOuter == null) || (shadowOuter.getAlpha() == 255));
+ }
+
+
+ /**
+ * Paints a raised bevel border around a component.
+ *
+ * @param c the component whose border is to be painted.
+ * @param g the graphics for painting.
+ * @param x the horizontal position for painting the border.
+ * @param y the vertical position for painting the border.
+ * @param width the width of the available area for painting the border.
+ * @param height the height of the available area for painting the border.
+ */
+ protected void paintRaisedBevel(Component c, Graphics g,
+ int x, int y, int width, int height)
+ {
+ paintBevel(g, x, y, width, height,
+ getHighlightOuterColor(c), getHighlightInnerColor(c),
+ getShadowInnerColor(c), getShadowOuterColor(c));
+ }
+
+
+ /**
+ * Paints a lowered bevel border around a component.
+ *
+ * @param c the component whose border is to be painted.
+ * @param g the graphics for painting.
+ * @param x the horizontal position for painting the border.
+ * @param y the vertical position for painting the border.
+ * @param width the width of the available area for painting the border.
+ * @param height the height of the available area for painting the border.
+ */
+ protected void paintLoweredBevel(Component c, Graphics g,
+ int x, int y, int width, int height)
+ {
+ paintBevel(g, x, y, width, height,
+ getShadowInnerColor(c), getShadowOuterColor(c),
+ getHighlightInnerColor(c), getHighlightOuterColor(c));
+ }
+
+
+ /**
+ * Paints a two-pixel bevel in four colors.
+ *
+ * <pre>
+ * ++++++++++++
+ * +..........# + = color a
+ * +. X# . = color b
+ * +. X# X = color c
+ * +.XXXXXXXXX# # = color d
+ * ############</pre>
+ *
+ * @param g the graphics for painting.
+ * @param x the horizontal position for painting the border.
+ * @param y the vertical position for painting the border.
+ * @param width the width of the available area for painting the border.
+ * @param height the height of the available area for painting the border.
+ * @param a the color for the outer side of the top and left edges.
+ * @param b the color for the inner side of the top and left edges.
+ * @param c the color for the inner side of the bottom and right edges.
+ * @param d the color for the outer side of the bottom and right edges.
+ */
+ private static void paintBevel(Graphics g,
+ int x, int y, int width, int height,
+ Color a, Color b, Color c, Color d)
+ {
+ Color oldColor;
+
+ oldColor = g.getColor();
+ g.translate(x, y);
+ width = width - 1;
+ height = height - 1;
+
+ try
+ {
+ /* To understand this code, it might be helpful to look at the
+ * images that are included with the JavaDoc. They are located
+ * in the "doc-files" subdirectory.
+ */
+ g.setColor(a);
+ g.drawLine(0, 0, width, 0); // a, horizontal
+ g.drawLine(0, 1, 0, height); // a, vertical
+
+ g.setColor(b);
+ g.drawLine(1, 1, width - 1, 1); // b, horizontal
+ g.drawLine(1, 2, 1, height - 1); // b, vertical
+
+ g.setColor(c);
+ g.drawLine(2, height - 1, width - 1, height - 1); // c, horizontal
+ g.drawLine(width - 1, 2, width - 1, height - 2); // c, vertical
+
+ g.setColor(d);
+ g.drawLine(1, height, width, height); // d, horizontal
+ g.drawLine(width, 1, width, height - 1); // d, vertical
+ }
+ finally
+ {
+ g.translate(-x, -y);
+ g.setColor(oldColor);
+ }
+ }
+}
+
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/Border.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/Border.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/Border.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/Border.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,103 @@
+/* Border.java --
+ Copyright (C) 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.border;
+
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Insets;
+
+
+/**
+ * An public interface for decorative or spacing borders around a Component.
+ *
+ * <p>To reduce memory consumption, several Components may share a
+ * single Border instance. {@link javax.swing.BorderFactory} is a
+ * factory class for producing commonly used shared borders.
+ *
+ * @see javax.swing.BorderFactory
+ * @see EmptyBorder
+ * @see CompoundBorder
+ * @see BevelBorder
+ * @see EtchedBorder
+ * @see LineBorder
+ * @see MatteBorder
+ * @see SoftBevelBorder
+ * @see TitledBorder
+ * @see AbstractBorder
+ *
+ * @author Ronald Veldema (rveldema at cs.vu.nl)
+ * @author Michael Koch (konqueror at gmx.de)
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public interface Border
+{
+ /**
+ * Paints the border for a given component.
+ *
+ * @param c the component whose border is to be painted.
+ * @param g the graphics for painting.
+ * @param x the horizontal position for painting the border.
+ * @param y the vertical position for painting the border.
+ * @param width the width of the available area for painting the border.
+ * @param height the height of the available area for painting the border.
+ */
+ void paintBorder(Component c, Graphics g, int x, int y, int width,
+ int height);
+
+ /**
+ * Measures the width of this border.
+ *
+ * @param c the component whose border is to be measured.
+ *
+ * @return an Insets object whose <code>left</code>, <code>right</code>,
+ * <code>top</code> and <code>bottom</code> fields indicate the
+ * width of the border at the respective edge.
+ */
+ Insets getBorderInsets(Component c);
+
+ /**
+ * Determines whether this border fills every pixel in its area
+ * when painting.
+ *
+ * @return <code>true</code> if the border is fully opaque, or
+ * <code>false</code> if some pixels of the background
+ * can shine through the border.
+ */
+ boolean isBorderOpaque();
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/CompoundBorder.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/CompoundBorder.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/CompoundBorder.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/CompoundBorder.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,246 @@
+/* CompoundBorder.java --
+ Copyright (C) 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.border;
+
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Insets;
+
+/**
+ * A Border that is composed of an interior and an exterior border,
+ * where the interior border is tightly nested into the exterior.
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class CompoundBorder extends AbstractBorder
+{
+ /**
+ * Determined using the <code>serialver</code> tool
+ * of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5.
+ */
+ static final long serialVersionUID = 9054540377030555103L;
+
+ /**
+ * The inside border, which is painted between the bordered
+ * Component and the outside border. It is valid for
+ * <code>insideBorder</code> to be <code>null</code>.
+ */
+ protected Border insideBorder;
+
+ /**
+ * The outside border, which is painted outside both the
+ * bordered Component and the inside border. It is valid for
+ * <code>outsideBorder</code> to be <code>null</code>.
+ */
+ protected Border outsideBorder;
+
+ /**
+ * Constructs a CompoundBorder whose inside and outside borders
+ * are both <code>null</code>. While this does not really make
+ * any sense (there exists a class EmptyBorder as well, and not
+ * every Component needs to have a border at all), the API
+ * specification requires the existence of this constructor.
+ *
+ * @see EmptyBorder
+ */
+ public CompoundBorder()
+ {
+ this (null, null);
+ }
+
+ /**
+ * Constructs a CompoundBorder with the specified inside and
+ * outside borders.
+ *
+ * @param outsideBorder the outside border, which is painted to the
+ * outside of both <code>insideBorder</code> and the enclosed
+ * component. It is acceptable to pass <code>null</code>, in
+ * which case no outside border is painted.
+ *
+ * @param insideBorder the inside border, which is painted to
+ * between <code>outsideBorder</code> and the enclosed
+ * component. It is acceptable to pass <code>null</code>, in
+ * which case no inside border is painted.
+ */
+ public CompoundBorder(Border outsideBorder, Border insideBorder)
+ {
+ this.outsideBorder = outsideBorder;
+ this.insideBorder = insideBorder;
+ }
+
+ /**
+ * Determines whether or not this border is opaque. An opaque
+ * border fills every pixel in its area when painting. Partially
+ * translucent borders must return <code>false</code>, or ugly
+ * artifacts can appear on screen.
+ *
+ * @return <code>true</code> if both the inside and outside borders
+ * are opaque, or <code>false</code> otherwise.
+ */
+ public boolean isBorderOpaque()
+ {
+ // While it would be safe to assume true for the opacity of
+ // a null border, this behavior would not be according to
+ // the API specification. Also, it is pathological to have
+ // null borders anyway.
+ if ((insideBorder == null) || (outsideBorder == null))
+ return false;
+
+ return insideBorder.isBorderOpaque()
+ && outsideBorder.isBorderOpaque();
+ }
+
+ /**
+ * Paints the compound border by first painting the outside border,
+ * then painting the inside border tightly nested into the outside.
+ *
+ * @param c the component whose border is to be painted.
+ * @param g the graphics for painting.
+ * @param x the horizontal position for painting the border.
+ * @param y the vertical position for painting the border.
+ * @param width the width of the available area for painting the border.
+ * @param height the height of the available area for painting the border.
+ */
+ public void paintBorder(Component c, Graphics g,
+ int x, int y, int width, int height)
+ {
+ // If there is an outside border, paint it and reduce the
+ // bounding box by its insets.
+ //
+ if (outsideBorder != null)
+ {
+ Insets outsideInsets;
+
+ outsideBorder.paintBorder(c, g, x, y, width, height);
+ outsideInsets = outsideBorder.getBorderInsets(c);
+
+ x += outsideInsets.left;
+ y += outsideInsets.top;
+
+ // Reduce width and height by the respective extent of the
+ // outside border.
+ width -= outsideInsets.left + outsideInsets.right;
+ height -= outsideInsets.top + outsideInsets.bottom;
+ }
+
+ if (insideBorder != null)
+ insideBorder.paintBorder(c, g, x, y, width, height);
+ }
+
+ /**
+ * Changes the specified insets to the insets of this border,
+ * which is the sum of the insets of the inside and the outside
+ * border.
+ *
+ * @param c the component in the center of this border.
+ * @param insets an Insets object for holding the added insets.
+ *
+ * @return the <code>insets</code> object.
+ */
+ public Insets getBorderInsets(Component c, Insets insets)
+ {
+ Insets borderInsets;
+
+ if (insets == null)
+ insets = new Insets(0, 0, 0, 0);
+ else
+ insets.left = insets.right = insets.top = insets.bottom = 0;
+
+ // If there is an outside border, add it to insets.
+ if (outsideBorder != null)
+ {
+ borderInsets = outsideBorder.getBorderInsets(c);
+ insets.left += borderInsets.left;
+ insets.right += borderInsets.right;
+ insets.top += borderInsets.top;
+ insets.bottom += borderInsets.bottom;
+ }
+
+ // If there is an inside border, add it to insets.
+ if (insideBorder != null)
+ {
+ borderInsets = insideBorder.getBorderInsets(c);
+ insets.left += borderInsets.left;
+ insets.right += borderInsets.right;
+ insets.top += borderInsets.top;
+ insets.bottom += borderInsets.bottom;
+ }
+
+ return insets;
+ }
+
+ /**
+ * Determines the insets of this border, which is the sum of the
+ * insets of the inside and the outside border.
+ *
+ * @param c the component in the center of this border.
+ */
+ public Insets getBorderInsets(Component c)
+ {
+ // It is not clear why CompoundBorder does not simply inherit
+ // the implementation from AbstractBorder. However, we want
+ // to be compatible with the API specification, which overrides
+ // the getBorderInsets(Component) method.
+ return getBorderInsets(c, null);
+ }
+
+ /**
+ * Returns the outside border, which is painted outside both the
+ * bordered Component and the inside border. It is valid for the
+ * result to be <code>null</code>.
+ *
+ * @return The outside border (possibly <code>null</code>).
+ */
+ public Border getOutsideBorder()
+ {
+ return outsideBorder;
+ }
+
+ /**
+ * Returns the inside border, which is painted between the bordered
+ * Component and the outside border. It is valid for the result to
+ * be <code>null</code>.
+ *
+ * @return The inside border (possibly <code>null</code>).
+ */
+ public Border getInsideBorder()
+ {
+ return insideBorder;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/EmptyBorder.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/EmptyBorder.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/EmptyBorder.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/EmptyBorder.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,223 @@
+/* EmptyBorder.java --
+ Copyright (C) 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.border;
+
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Insets;
+
+
+/**
+ * A border for leaving a specifiable number of pixels empty around
+ * the enclosed component. An EmptyBorder requires some space on each
+ * edge, but does not perform any drawing.
+ *
+ * <p><img src="EmptyBorder-1.png" width="290" height="200"
+ * alt="[An illustration of EmptyBorder]" />
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class EmptyBorder extends AbstractBorder
+{
+ /**
+ * Determined using the <code>serialver</code> tool
+ * of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5.
+ */
+ static final long serialVersionUID = -8116076291731988694L;
+
+
+ /**
+ * The number of pixels required at the left edge.
+ */
+ protected int left;
+
+
+ /**
+ * The number of pixels required at the right edge.
+ */
+ protected int right;
+
+
+ /**
+ * The number of pixels required at the top edge.
+ */
+ protected int top;
+
+
+ /**
+ * The number of pixels required at the bottom edge.
+ */
+ protected int bottom;
+
+
+ /**
+ * Constructs an empty border given the number of pixels required
+ * on each side.
+ *
+ * @param top the number of pixels that the border will need
+ * for its top edge.
+ *
+ * @param left the number of pixels that the border will need
+ * for its left edge.
+ *
+ * @param bottom the number of pixels that the border will need
+ * for its bottom edge.
+ *
+ * @param right the number of pixels that the border will need
+ * for its right edge.
+ */
+ public EmptyBorder(int top, int left, int bottom, int right)
+ {
+ this.top = top;
+ this.left = left;
+ this.bottom = bottom;
+ this.right = right;
+ }
+
+
+ /**
+ * Constructs an empty border given the number of pixels required
+ * on each side, passed in an Insets object.
+ *
+ * @param borderInsets the Insets for the new border.
+ */
+ public EmptyBorder(Insets borderInsets)
+ {
+ this(borderInsets.top, borderInsets.left,
+ borderInsets.bottom, borderInsets.right);
+ }
+
+
+ /**
+ * Performs nothing because an EmptyBorder does not paint any
+ * pixels. While the inherited implementation provided by
+ * {@link AbstractBorder#paintBorder} is a no-op as well,
+ * it is overwritten in order to match the API of the Sun
+ * reference implementation.
+ *
+ * @param c the component whose border is to be painted.
+ * @param g the graphics for painting.
+ * @param x the horizontal position for painting the border.
+ * @param y the vertical position for painting the border.
+ * @param width the width of the available area for painting the border.
+ * @param height the height of the available area for painting the border.
+ */
+ public void paintBorder(Component c, Graphics g,
+ int x, int y, int width, int height)
+ {
+ // Nothing to do here.
+ }
+
+
+ /**
+ * Measures the width of this border.
+ *
+ * @param c the component whose border is to be measured.
+ *
+ * @return an Insets object whose <code>left</code>, <code>right</code>,
+ * <code>top</code> and <code>bottom</code> fields indicate the
+ * width of the border at the respective edge.
+ *
+ * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
+ */
+ public Insets getBorderInsets(Component c)
+ {
+ return getBorderInsets(c, null);
+ }
+
+
+ /**
+ * Measures the width of this border, storing the results into a
+ * pre-existing Insets object.
+ *
+ * @param insets an Insets object for holding the result values.
+ * After invoking this method, the <code>left</code>,
+ * <code>right</code>, <code>top</code> and
+ * <code>bottom</code> fields indicate the width of the
+ * border at the respective edge.
+ *
+ * @return the same object that was passed for <code>insets</code>.
+ *
+ * @see #getBorderInsets()
+ */
+ public Insets getBorderInsets(Component c, Insets insets)
+ {
+ if (insets == null)
+ insets = new Insets(0, 0, 0, 0);
+
+ insets.left = left;
+ insets.right = right;
+ insets.top = top;
+ insets.bottom = bottom;
+ return insets;
+ }
+
+
+ /**
+ * Measures the width of this border.
+ *
+ * @return an Insets object whose <code>left</code>, <code>right</code>,
+ * <code>top</code> and <code>bottom</code> fields indicate the
+ * width of the border at the respective edge.
+ *
+ * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
+ */
+ public Insets getBorderInsets()
+ {
+ return getBorderInsets(null, null);
+ }
+
+
+ /**
+ * Determines whether this border fills every pixel in its area
+ * when painting. Since an empty border does not paint any pixels
+ * whatsoever, the result is <code>false</code>.
+ *
+ * @return <code>false</code>.
+ */
+ public boolean isBorderOpaque()
+ {
+ /* The inherited implementation of AbstractBorder.isBorderOpaque()
+ * would also return false. It is not clear why this is overriden
+ * in the Sun implementation, at least not from just reading the
+ * JavaDoc.
+ */
+ return false;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/EtchedBorder.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/EtchedBorder.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/EtchedBorder.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/EtchedBorder.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,414 @@
+/* EtchedBorder.java --
+ Copyright (C) 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.border;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Insets;
+
+
+/**
+ * A border that looks like an engraving etched into the background
+ * surface, or (in its raised variant) coming out of the surface
+ * plane. Using different constructors, it is possible to either
+ * explicitly specify the border colors, or to let the colors derive
+ * from the background color of the enclosed Component.
+ *
+ * <p><img src="doc-files/EtchedBorder-1.png" width="500" height="200"
+ * alt="[An illustration of the two EtchedBorder variants]" />
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class EtchedBorder extends AbstractBorder
+{
+ /**
+ * Determined using the <code>serialver</code> tool
+ * of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5.
+ */
+ static final long serialVersionUID = 4001244046866360638L;
+
+
+ /**
+ * Indicates that the border appears as coming out of the
+ * background.
+ */
+ public static final int RAISED = 0;
+
+
+ /**
+ * Indicates that the border appears as engraved into the
+ * background.
+ */
+ public static final int LOWERED = 1;
+
+
+ /**
+ * The type of this EtchedBorder, which is either {@link #RAISED}
+ * or {@link #LOWERED}.
+ */
+ protected int etchType;
+
+
+ /**
+ * The highlight color, or <code>null</code> to indicate that the
+ * color shall be derived from the background of the enclosed
+ * component.
+ */
+ protected Color highlight;
+
+
+ /**
+ * The shadow color, or <code>null</code> to indicate that the
+ * color shall be derived from the background of the enclosed
+ * component.
+ */
+ protected Color shadow;
+
+
+ /**
+ * Constructs a lowered EtchedBorder. The colors will be derived
+ * from the background color of the enclosed Component when the
+ * border gets painted.
+ */
+ public EtchedBorder()
+ {
+ this(LOWERED);
+ }
+
+
+ /**
+ * Constructs an EtchedBorder with the specified appearance. The
+ * colors will be derived from the background color of the enclosed
+ * Component when the border gets painted.
+ *
+ * <p><img src="doc-files/EtchedBorder-1.png" width="500" height="200"
+ * alt="[An illustration of the two EtchedBorder variants]" />
+ *
+ * @param etchType the desired appearance of the border. The value
+ * must be either {@link #RAISED} or {@link #LOWERED}.
+ *
+ * @throws IllegalArgumentException if <code>etchType</code> has
+ * an unsupported value.
+ */
+ public EtchedBorder(int etchType)
+ {
+ if ((etchType != RAISED) && (etchType != LOWERED))
+ throw new IllegalArgumentException();
+
+ this.etchType = etchType;
+
+ /* The highlight and shadow fields already have a null value
+ * when the constructor gets called, so there is no need to
+ * assign a value here.
+ */
+ }
+
+
+ /**
+ * Constructs a lowered EtchedBorder, explicitly selecting the
+ * colors that will be used for highlight and shadow.
+ *
+ * @param highlight the color that will be used for painting
+ * the highlight part of the border.
+ *
+ * @param shadow the color that will be used for painting
+ * the shadow part of the border.
+ *
+ * @see #EtchedBorder(int, Color, Color)
+ */
+ public EtchedBorder(Color highlight, Color shadow)
+ {
+ this(LOWERED, highlight, shadow);
+ }
+
+
+ /**
+ * Constructs an EtchedBorder with the specified appearance,
+ * explicitly selecting the colors that will be used for
+ * highlight and shadow.
+ *
+ * <p><img src="doc-files/EtchedBorder-2.png" width="500" height="200"
+ * alt="[An illustration that shows which pixels get painted
+ * in what color]" />
+ *
+ * @param etchType the desired appearance of the border. The value
+ * must be either {@link #RAISED} or {@link #LOWERED}.
+ *
+ * @param highlight the color that will be used for painting
+ * the highlight part of the border.
+ *
+ * @param shadow the color that will be used for painting
+ * the shadow part of the border.
+ *
+ * @throws IllegalArgumentException if <code>etchType</code> has
+ * an unsupported value.
+ */
+ public EtchedBorder(int etchType, Color highlight, Color shadow)
+ {
+ this(etchType); // Checks the validity of the value.
+ this.highlight = highlight;
+ this.shadow = shadow;
+ }
+
+
+ /**
+ * Paints the border for a given component.
+ *
+ * @param c the component whose border is to be painted.
+ * @param g the graphics for painting.
+ * @param x the horizontal position for painting the border.
+ * @param y the vertical position for painting the border.
+ * @param width the width of the available area for painting the border.
+ * @param height the height of the available area for painting the border.
+ */
+ public void paintBorder(Component c, Graphics g, int x, int y, int width,
+ int height)
+ {
+ switch (etchType)
+ {
+ case RAISED:
+ paintEtchedBorder(g, x, y, width, height,
+ getHighlightColor(c), getShadowColor(c));
+ break;
+
+ case LOWERED:
+ paintEtchedBorder(g, x, y, width, height,
+ getShadowColor(c), getHighlightColor(c));
+ break;
+ }
+ }
+
+
+ /**
+ * Measures the width of this border.
+ *
+ * @param c the component whose border is to be measured.
+ *
+ * @return an Insets object whose <code>left</code>, <code>right</code>,
+ * <code>top</code> and <code>bottom</code> fields indicate the
+ * width of the border at the respective edge.
+ *
+ * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
+ */
+ public Insets getBorderInsets(Component c)
+ {
+ return new Insets(2, 2, 2, 2);
+ }
+
+
+ /**
+ * Measures the width of this border, storing the results into a
+ * pre-existing Insets object.
+ *
+ * @param insets an Insets object for holding the result values.
+ * After invoking this method, the <code>left</code>,
+ * <code>right</code>, <code>top</code> and
+ * <code>bottom</code> fields indicate the width of the
+ * border at the respective edge.
+ *
+ * @return the same object that was passed for <code>insets</code>.
+ *
+ * @see #getBorderInsets(Component)
+ */
+ public Insets getBorderInsets(Component c, Insets insets)
+ {
+ insets.left = insets.right = insets.top = insets.bottom = 2;
+ return insets;
+ }
+
+
+ /**
+ * Determines whether this border fills every pixel in its area
+ * when painting.
+ *
+ * <p>If the border colors are derived from the background color of
+ * the enclosed component, the result is <code>true</code> because
+ * the derivation method always returns opaque colors. Otherwise,
+ * the result depends on the opacity of the individual colors.
+ *
+ * @return <code>true</code> if the border is fully opaque, or
+ * <code>false</code> if some pixels of the background
+ * can shine through the border.
+ */
+ public boolean isBorderOpaque()
+ {
+ // If the colors are to be derived from the enclosed Component's
+ // background color, the border is guaranteed to be fully opaque
+ // because Color.brighten() and Color.darken() always return an
+ // opaque color.
+ return
+ ((highlight == null) || (highlight.getAlpha() == 255))
+ && ((shadow == null) || (shadow.getAlpha() == 255));
+ }
+
+ /**
+ * Returns the appearance of this EtchedBorder, which is either
+ * {@link #RAISED} or {@link #LOWERED}.
+ *
+ * @return The type ({@link #RAISED} or {@link #LOWERED}).
+ */
+ public int getEtchType()
+ {
+ return etchType;
+ }
+
+
+ /**
+ * Determines the color that will be used for highlighted parts when
+ * painting the border around a given component. If a highlight
+ * color has been specified upon constructing the border, that color
+ * is returned. Otherwise, the background color of the enclosed
+ * component is brightened.
+ *
+ * @param c the component enclosed by this border.
+ *
+ * @return The color.
+ *
+ * @see java.awt.Component#getBackground()
+ * @see java.awt.Color#brighter()
+ */
+ public Color getHighlightColor(Component c)
+ {
+ if (highlight != null)
+ return highlight;
+ else
+ return c.getBackground().brighter();
+ }
+
+ /**
+ * Returns the color that will be used for highlighted parts when
+ * painting the border, or <code>null</code> if that color will be
+ * derived from the background of the enclosed Component.
+ *
+ * @return The highlight color (possibly <code>null</code>).
+ */
+ public Color getHighlightColor()
+ {
+ return highlight;
+ }
+
+
+ /**
+ * Determines the color that will be used for shadowed parts when
+ * painting the border around a given component. If a shadow color
+ * has been specified upon constructing the border, that color is
+ * returned. Otherwise, the background color of the enclosed
+ * component is darkened.
+ *
+ * @param c the component enclosed by this border.
+ *
+ * @return The shadow color.
+ *
+ * @see java.awt.Component#getBackground()
+ * @see java.awt.Color#darker()
+ */
+ public Color getShadowColor(Component c)
+ {
+ if (shadow != null)
+ return shadow;
+ else
+ return c.getBackground().darker();
+ }
+
+
+ /**
+ * Returns the color that will be used for shadowed parts when
+ * painting the border, or <code>null</code> if that color will be
+ * derived from the background of the enclosed Component.
+ *
+ * @return The shadow color (possibly <code>null</code>).
+ */
+ public Color getShadowColor()
+ {
+ return shadow;
+ }
+
+
+ /**
+ * Paints a two-pixel etching in two colors.
+ *
+ * <pre>
+ * +++++++++++.
+ * +.........+. + = color a
+ * +. +. . = color b
+ * +. +.
+ * +++++++++++.
+ * ............</pre>
+ *
+ * @param g the graphics for painting.
+ * @param x the horizontal position for painting the border.
+ * @param y the vertical position for painting the border.
+ * @param width the width of the available area for painting the border.
+ * @param height the height of the available area for painting the border.
+ * @param a one of the two colors.
+ * @param b the second of the two colors.
+ */
+ private static void paintEtchedBorder(Graphics g, int x, int y, int width,
+ int height, Color a, Color b)
+ {
+ Color oldColor;
+
+ oldColor = g.getColor();
+ g.translate(x, y);
+ width = width - 1;
+ height = height - 1;
+
+ try
+ {
+ // To understand this code, it might be helpful to look at the
+ // images that are included with the JavaDoc. They are located
+ // in the "doc-files" subdirectory. EtchedBorder-2.png might
+ // be especially informative.
+ g.setColor(a);
+ g.drawRect(0, 0, width - 1, height - 1);
+
+ g.setColor(b);
+ g.drawLine(1, 1, width - 2, 1); // top edge
+ g.drawLine(1, 2, 1, height - 2); // left edge
+ g.drawLine(0, height, width, height); // bottom edge
+ g.drawLine(width, 0, width, height - 1); // right edge
+ }
+ finally
+ {
+ g.translate(-x, -y);
+ g.setColor(oldColor);
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/LineBorder.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/LineBorder.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/LineBorder.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/LineBorder.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,347 @@
+/* LineBorder.java --
+ Copyright (C) 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.border;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Insets;
+
+
+/**
+ * A border that consists of a line whose thickness and color can be
+ * specified. There also is a variant with rounded corners.
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class LineBorder extends AbstractBorder
+{
+ /**
+ * Determined using the <code>serialver</code> tool
+ * of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5.
+ */
+ static final long serialVersionUID = -787563427772288970L;
+
+
+ /**
+ * A shared instance of a black, one pixel thick, plain LineBorder.
+ * The singleton object is lazily created by {@link
+ * #createBlackLineBorder()} upon its first invocation.
+ */
+ private static LineBorder blackLineBorder;
+
+
+ /**
+ * A shared instance of a gray, one pixel thick, plain LineBorder.
+ * The singleton object is lazily created by {@link
+ * #createGrayLineBorder()} upon its first invocation.
+ */
+ private static LineBorder grayLineBorder;
+
+
+ /**
+ * The width of the line in pixels.
+ */
+ protected int thickness;
+
+
+ /**
+ * The color of the line.
+ */
+ protected Color lineColor;
+
+
+ /**
+ * Indicates whether the line is drawn with rounded corners
+ * (<code>true</code>) or not ((<code>false</code>).
+ */
+ protected boolean roundedCorners;
+
+
+ /**
+ * Constructs a LineBorder given its color. The border will be one
+ * pixel thick and have plain corners.
+ *
+ * @param color the color for drawing the border.
+ *
+ * @see #LineBorder(java.awt.Color, int, boolean)
+ */
+ public LineBorder(Color color)
+ {
+ this(color, /* thickness */ 1, /* roundedCorners */ false);
+ }
+
+
+ /**
+ * Constructs a LineBorder given its color and thickness. The
+ * border will have plain corners.
+ *
+ * @param color the color for drawing the border.
+ * @param thickness the width of the line in pixels.
+ *
+ * @see #LineBorder(java.awt.Color, int, boolean)
+ */
+ public LineBorder(Color color, int thickness)
+ {
+ this (color, thickness, /* roundedCorners */ false);
+ }
+
+
+ /**
+ * Constructs a LineBorder given its color, thickness, and whether
+ * it has rounded corners.
+ *
+ * <p><img src="doc-files/LineBorder-1.png" width="500" height="200"
+ * alt="[An illustration of two LineBorders]" />
+ *
+ * <p>Note that the enlarged view in the right-hand picture shows
+ * that the implementation draws one more pixel than specified,
+ * provided that <code>roundedCorders</code> is <code>true</code>
+ * and anti-aliasing is turned on while painting. While this might
+ * be considered a bug, the Sun reference implementation (at least
+ * JDK 1.3.1 on Apple MacOS X 10.1.5) can be observed to fill
+ * exactly the same pixels as shown above. The GNU Classpath
+ * LineBorder replicates the observed behavior of the Sun
+ * implementation.
+ *
+ * @param color the color for drawing the border.
+ * @param thickness the width of the line in pixels.
+ * @param roundedCorners <code>true</code> for rounded corners,
+ * <code>false</code> for plain corners.
+ *
+ * @since 1.3
+ */
+ // For the bug mentioned in the JavaDoc, please see also the comment
+ // in the paintBorder method below.
+ //
+ public LineBorder(Color color, int thickness, boolean roundedCorners)
+ {
+ if ((color == null) || (thickness < 0))
+ throw new IllegalArgumentException();
+
+ this.lineColor = color;
+ this.thickness = thickness;
+ this.roundedCorners = roundedCorners;
+ }
+
+
+ /**
+ * Returns a black, one pixel thick, plain {@link LineBorder}. The method
+ * may always return the same (singleton) {@link LineBorder} instance.
+ *
+ * @return The border.
+ */
+ public static Border createBlackLineBorder()
+ {
+ /* Swing is not designed to be thread-safe, so there is no
+ * need to synchronize the access to the global variable.
+ */
+ if (blackLineBorder == null)
+ blackLineBorder = new LineBorder(Color.black);
+
+ return blackLineBorder;
+ }
+
+
+ /**
+ * Returns a gray, one pixel thick, plain {@link LineBorder}. The method
+ * may always return the same (singleton) {@link LineBorder} instance.
+ *
+ * @return The border.
+ */
+ public static Border createGrayLineBorder()
+ {
+ /* Swing is not designed to be thread-safe, so there is no
+ * need to synchronize the access to the global variable.
+ */
+ if (grayLineBorder == null)
+ grayLineBorder = new LineBorder(Color.gray);
+
+ return grayLineBorder;
+ }
+
+
+ /**
+ * Paints the line border around a given Component.
+ *
+ * @param c the component whose border is to be painted.
+ * @param g the graphics for painting.
+ * @param x the horizontal position for painting the border.
+ * @param y the vertical position for painting the border.
+ * @param width the width of the available area for painting the border.
+ * @param height the height of the available area for painting the border.
+ */
+ public void paintBorder(Component c, Graphics g,
+ int x, int y, int width, int height)
+ {
+ Color oldColor = g.getColor();
+
+ try
+ {
+ g.setColor(lineColor);
+
+ // If width and height were not adjusted, the border would
+ // appear one pixel too large in both directions.
+ width -= 1;
+ height -= 1;
+
+ // Blurred, too large appearance
+ // -----------------------------
+ // While Java 2D has introduced line strokes of arbitrary width,
+ // it seems desirable to keep this code independent of Java 2D.
+ // Therefore, multiple nested rectangles (or rounded rectangles)
+ // are drawn in order to simulate a line whose thickness is
+ // greater than one pixel.
+ //
+ // This hack causes a blurred appearance when anti-aliasing is
+ // on. Interestingly enough, though, the Sun JDK 1.3.1 (at least
+ // on MacOS X 10.1.5) shows exactly the same appearance under
+ // this condition. It thus seems likely that Sun does the same
+ // hack for simulating thick lines. For this reason, the
+ // blurred appearance seems acceptable -- especially since GNU
+ // Classpath tries to be compatible with the Sun reference
+ // implementation.
+ for (int i = 0; i < thickness; i++)
+ {
+ if (roundedCorners)
+ g.drawRoundRect(x, y, width, height, thickness, thickness);
+ else
+ g.drawRect(x, y, width, height);
+
+ x += 1;
+ y += 1;
+ width -= 2;
+ height -= 2;
+ }
+ }
+ finally
+ {
+ g.setColor(oldColor);
+ }
+ }
+
+
+ /**
+ * Measures the width of this border.
+ *
+ * @param c the component whose border is to be measured.
+ *
+ * @return an Insets object whose <code>left</code>, <code>right</code>,
+ * <code>top</code> and <code>bottom</code> fields indicate the
+ * width of the border at the respective edge, which is the
+ * thickness of the line.
+ *
+ * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
+ */
+ public Insets getBorderInsets(Component c)
+ {
+ return new Insets(thickness, thickness, thickness, thickness);
+ }
+
+
+ /**
+ * Measures the width of this border, storing the results into a
+ * pre-existing Insets object.
+ *
+ * @param insets an Insets object for holding the result values.
+ * After invoking this method, the <code>left</code>,
+ * <code>right</code>, <code>top</code> and
+ * <code>bottom</code> fields indicate the width of the
+ * border at the respective edge, which is the thickness
+ * of the line.
+ *
+ * @return the same object that was passed for <code>insets</code>.
+ *
+ * @see #getBorderInsets(Component)
+ */
+ public Insets getBorderInsets(Component c, Insets insets)
+ {
+ insets.left = insets.right = insets.top = insets.bottom = thickness;
+ return insets;
+ }
+
+
+ /**
+ * Returns the color of the line.
+ *
+ * @return The line color (never <code>null</code>).
+ */
+ public Color getLineColor()
+ {
+ return lineColor;
+ }
+
+
+ /**
+ * Returns the thickness of the line in pixels.
+ *
+ * @return The line thickness (in pixels).
+ */
+ public int getThickness()
+ {
+ return thickness;
+ }
+
+
+ /**
+ * Returns whether this LineBorder os drawm with rounded
+ * or with plain corners.
+ *
+ * @return <code>true</code> if the corners are rounded,
+ * <code>false</code> if the corners are plain.
+ */
+ public boolean getRoundedCorners()
+ {
+ return roundedCorners;
+ }
+
+
+ /**
+ * Determines whether this border fills every pixel in its area
+ * when painting.
+ *
+ * @return <code>true</code> if the corners are plain and the line
+ * color is fully opaque; <code>false</code> if the corners
+ * are rounded or the line color is partially transparent.
+ */
+ public boolean isBorderOpaque()
+ {
+ return (!roundedCorners) && (lineColor.getAlpha() == 255);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/MatteBorder.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/MatteBorder.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/MatteBorder.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/MatteBorder.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,407 @@
+/* MatteBorder.java --
+ Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.border;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Insets;
+
+import javax.swing.Icon;
+
+/**
+ * A border that is filled with either a solid color or with repeated
+ * icon tiles.
+ *
+ * <p><img src="doc-files/MatteBorder-1.png" width="500" height="150"
+ * alt="[Two MatteBorders]" />
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class MatteBorder extends EmptyBorder
+{
+ /**
+ * Determined using the <code>serialver</code> tool
+ * of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5.
+ */
+ static final long serialVersionUID = 4422248989617298224L;
+
+
+ /**
+ * The color that is used for filling the border, or
+ * <code>null</code> if the border is filled with repetitions of a
+ * tile icon.
+ *
+ * @see #tileIcon
+ */
+ protected Color color;
+
+
+ /**
+ * The icon is used for filling the border with a tile, or
+ * <code>null</code> if the border is filled with a solid
+ * color.
+ *
+ * @see #color
+ */
+ protected Icon tileIcon;
+
+
+ /**
+ * Constructs a MatteBorder given the width on each side
+ * and a fill color.
+ *
+ * <p><img src="doc-files/MatteBorder-2.png" width="500" height="150"
+ * alt="[A picture of a MatteBorder made by this constructor]" />
+ *
+ * @param top the width of the border at its top edge.
+ * @param left the width of the border at its left edge.
+ * @param bottom the width of the border at its bottom edge.
+ * @param right the width of the border at its right edge.
+ * @param matteColor the color for filling the border.
+ */
+ public MatteBorder(int top, int left, int bottom, int right,
+ Color matteColor)
+ {
+ super(top, left, bottom, right);
+
+ if (matteColor == null)
+ throw new IllegalArgumentException();
+
+ this.color = matteColor;
+ }
+
+
+ /**
+ * Constructs a MatteBorder given its insets and fill color.
+ *
+ * <p><img src="doc-files/MatteBorder-3.png" width="500" height="150"
+ * alt="[A picture of a MatteBorder made by this constructor]" />
+ *
+ * @param borderInsets an Insets object whose <code>top</code>,
+ * <code>left</code>, <code>bottom</code> and <code>right</code>
+ * fields indicate the with of the border at the respective
+ * edge.
+ *
+ * @param matteColor the color for filling the border.
+ */
+ public MatteBorder(Insets borderInsets, Color matteColor)
+ {
+ this(borderInsets.top, borderInsets.left,
+ borderInsets.bottom, borderInsets.right,
+ matteColor);
+ }
+
+
+ /**
+ * Constructs a MatteBorder given the width on each side
+ * and an icon for tiling the border area.
+ *
+ * <p><img src="doc-files/MatteBorder-4.png" width="500" height="150"
+ * alt="[A picture of a MatteBorder made by this constructor]" />
+ *
+ * @param top the width of the border at its top edge.
+ * @param left the width of the border at its left edge.
+ * @param bottom the width of the border at its bottom edge.
+ * @param right the width of the border at its right edge.
+ * @param tileIcon an icon for tiling the border area.
+ */
+ public MatteBorder(int top, int left, int bottom, int right,
+ Icon tileIcon)
+ {
+ super(top, left, bottom, right);
+
+ this.tileIcon = tileIcon;
+ }
+
+
+ /**
+ * Constructs a MatteBorder given its insets and an icon
+ * for tiling the border area.
+ *
+ * <p><img src="doc-files/MatteBorder-5.png" width="500" height="150"
+ * alt="[A picture of a MatteBorder made by this constructor]" />
+ *
+ * @param borderInsets an Insets object whose <code>top</code>,
+ * <code>left</code>, <code>bottom</code> and <code>right</code>
+ * fields indicate the with of the border at the respective
+ * edge.
+ *
+ * @param tileIcon an icon for tiling the border area.
+ */
+ public MatteBorder(Insets borderInsets, Icon tileIcon)
+ {
+ this(borderInsets.top, borderInsets.left,
+ borderInsets.bottom, borderInsets.right,
+ tileIcon);
+ }
+
+
+ /**
+ * Constructs a MatteBorder given an icon for tiling the
+ * border area. The icon width is used for the border insets
+ * at the left and right edge, the icon height for the top and
+ * bottom edge.
+ *
+ * <p><img src="doc-files/MatteBorder-6.png" width="379" height="150"
+ * alt="[A picture of a MatteBorder made by this constructor]" />
+ *
+ * @param tileIcon an icon for tiling the border area.
+ */
+ public MatteBorder(Icon tileIcon)
+ {
+ this(-1, -1, -1, -1, tileIcon);
+ }
+
+
+ /**
+ * Paints the border for a given component.
+ *
+ * @param c the component whose border is to be painted.
+ * @param g the graphics for painting.
+ * @param x the horizontal position for painting the border.
+ * @param y the vertical position for painting the border.
+ * @param width the width of the available area for painting the border.
+ * @param height the height of the available area for painting the border.
+ */
+ public void paintBorder(Component c, Graphics g,
+ int x, int y, int width, int height)
+ {
+ Insets i = getBorderInsets();
+ paintEdge(c, g, x, y, width, i.top, 0, 0); // top edge
+ paintEdge(c, g, x, y + height - i.bottom, // bottom edge
+ width, i.bottom,
+ 0, height - i.bottom);
+ paintEdge(c, g, x, y + i.top, // left edge
+ i.left, height - i.top,
+ 0, i.top);
+ paintEdge(c, g, x + width - i.right, y + i.top, // right edge
+ i.right, height - i.bottom,
+ width - i.right, i.top);
+ }
+
+
+ /**
+ * Measures the width of this border.
+ *
+ * @param c the component whose border is to be measured.
+ *
+ * @return an Insets object whose <code>left</code>, <code>right</code>,
+ * <code>top</code> and <code>bottom</code> fields indicate the
+ * width of the border at the respective edge.
+ *
+ * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
+ */
+ public Insets getBorderInsets(Component c)
+ {
+ /* There is no obvious reason for overriding this method, but we
+ * try to have exactly the same API as the Sun reference
+ * implementation.
+ */
+ return this.getBorderInsets(c, null);
+ }
+
+
+ /**
+ * Measures the width of this border, storing the results into a
+ * pre-existing Insets object.
+ *
+ * @param insets an Insets object for holding the result values.
+ * After invoking this method, the <code>left</code>,
+ * <code>right</code>, <code>top</code> and
+ * <code>bottom</code> fields indicate the width of the
+ * border at the respective edge.
+ *
+ * @return the same object that was passed for <code>insets</code>.
+ *
+ * @see #getBorderInsets()
+ */
+ public Insets getBorderInsets(Component c, Insets insets)
+ {
+ if (insets == null)
+ insets = new Insets(0, 0, 0, 0);
+
+ if ((tileIcon != null)
+ && (top < 0) && (left < 0)
+ && (right < 0) && (bottom < 0))
+ {
+ insets.left = insets.right = tileIcon.getIconWidth();
+ insets.top = insets.bottom = tileIcon.getIconHeight();
+ return insets;
+ }
+
+ /* Copy top, left, bottom and right into the respective
+ * field of insets.
+ */
+ return super.getBorderInsets(c, insets);
+ }
+
+
+ /**
+ * Measures the width of this border.
+ *
+ * @return an Insets object whose <code>left</code>, <code>right</code>,
+ * <code>top</code> and <code>bottom</code> fields indicate the
+ * width of the border at the respective edge.
+ *
+ * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
+ */
+ public Insets getBorderInsets()
+ {
+ /* The inherited implementation of EmptyBorder.isBorderOpaque()
+ * would do the same. It is not clear why this is overriden in the
+ * Sun implementation, at least not from just reading the JavaDoc.
+ */
+ return this.getBorderInsets(null, null);
+ }
+
+
+ /**
+ * Returns the color that is used for filling the border, or
+ * <code>null</code> if the border is filled with repetitions of a
+ * tile icon.
+ *
+ * @return The color (possibly <code>null</code>).
+ */
+ public Color getMatteColor()
+ {
+ return color;
+ }
+
+
+ /**
+ * Returns the icon is used for tiling the border, or
+ * <code>null</code> if the border is filled with a color instead of
+ * an icon.
+ *
+ * @return The icon (possibly <code>null</code>).
+ */
+ public Icon getTileIcon()
+ {
+ return tileIcon;
+ }
+
+
+ /**
+ * Determines whether this border fills every pixel in its area
+ * when painting.
+ *
+ * @return <code>true</code> if the border is filled with an
+ * opaque color; <code>false</code> if it is filled with
+ * a semi-transparent color or with an icon.
+ */
+ public boolean isBorderOpaque()
+ {
+ return (color != null) && (color.getAlpha() == 255);
+ }
+
+
+ /**
+ * Paints a rectangular area of the border. This private helper
+ * method is called once for each of the border edges
+ * by {@link #paintBorder}.
+ *
+ * @param c the component whose border is being painted.
+ * @param g the graphics for painting.
+ * @param x the horizontal position of the rectangular area.
+ * @param y the vertical position of the rectangular area.
+ * @param width the width of the rectangular area.
+ * @param height the height of the rectangular area.
+ * @param dx the x displacement for repeating the tile.
+ * @param dy the y displacement for repeating the tile.
+ */
+ private void paintEdge(Component c, Graphics g,
+ int x, int y, int width, int height,
+ int dx, int dy)
+ {
+ Color oldColor;
+ int iconWidth, iconHeight;
+ Graphics clipped;
+
+ if ((width <= 0) || (height <= 0))
+ return;
+
+ /* Paint a colored rectangle if desired. */
+ if (color != null)
+ {
+ oldColor = g.getColor();
+ try
+ {
+ g.setColor(color);
+ g.fillRect(x, y, width, height);
+ }
+ finally
+ {
+ g.setColor(oldColor);
+ }
+ return;
+ }
+
+ // If this border has no icon end painting here.
+ if (tileIcon == null)
+ return;
+
+ /* Determine the width and height of the icon. Some icons return
+ * -1 if it is an image whose dimensions have not yet been
+ * retrieved. There is not much we can do about this, but we
+ * should at least avoid entering the paint loop below
+ * with negative increments.
+ */
+ iconWidth = tileIcon.getIconWidth();
+ iconHeight = tileIcon.getIconHeight();
+ if ((iconWidth <= 0) || (iconHeight <= 0))
+ return;
+
+ dx = dx % iconWidth;
+ dy = dy % iconHeight;
+
+ clipped = g.create();
+ try
+ {
+ clipped.setClip(x, y, width, height);
+ for (int ty = y - dy; ty < y + height; ty += iconHeight)
+ for (int tx = x - dx; tx < x + width; tx += iconWidth)
+ tileIcon.paintIcon(c, clipped, tx, ty);
+ }
+ finally
+ {
+ clipped.dispose();
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/SoftBevelBorder.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/SoftBevelBorder.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/SoftBevelBorder.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/SoftBevelBorder.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,327 @@
+/* SoftBevelBorder.java --
+ Copyright (C) 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.border;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Insets;
+
+
+/**
+ * A rectangular, three pixel thick border that looks like a BevelBorder
+ * with slightly softened corners.
+ *
+ * <p>Like BevelBorder, SoftBevelBorder has a highlight and a shadow
+ * color. In the raised variant, the highlight color is used for the
+ * top and left edges, and the shadow color is used for the bottom and
+ * right edge. In the lowered variant, color usage is reversed. For
+ * an image, see the documentation of the individual constructors.
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class SoftBevelBorder extends BevelBorder
+{
+ /**
+ * Determined using the <code>serialver</code> tool
+ * of Sun JDK 1.4.1_01 on GNU/Linux 2.4.20. Interestingly,
+ * the Apple/Sun JDK 1.3.1 on MacOS X 10.1.5 gives a different
+ * value, namely -6658357140774549493L.
+ */
+ static final long serialVersionUID = 5248789787305979975L;
+
+
+ /**
+ * Constructs a SoftBevelBorder whose colors will be derived from the
+ * background of the enclosed component. The background color is
+ * retrieved each time the border is painted, so a SoftBevelBorder
+ * constructed by this method will automatically reflect a change
+ * to the component’s background color.
+ *
+ * <p><img src="doc-files/SoftBevelBorder-1.png" width="500" height="200"
+ * alt="[An illustration showing raised and lowered SoftBevelBorders]" />
+ *
+ * @param bevelType the desired appearance of the border. The value
+ * must be either {@link BevelBorder#RAISED}
+ * or {@link BevelBorder#LOWERED}.
+ *
+ * @throws IllegalArgumentException if <code>bevelType</code> has
+ * an unsupported value.
+ */
+ public SoftBevelBorder(int bevelType)
+ {
+ super(bevelType);
+ }
+
+
+ /**
+ * Constructs a SoftBevelBorder given its appearance type and two
+ * colors for its highlight and shadow.
+ *
+ * <p><img src="doc-files/SoftBevelBorder-2.png" width="500" height="150"
+ * alt="[An illustration showing SoftBevelBorders that were
+ * constructed with this method]" />
+ *
+ * @param bevelType the desired appearance of the border. The value
+ * must be either {@link BevelBorder#RAISED} or {@link
+ * BevelBorder#LOWERED}.
+ *
+ * @param highlight the color that will be used for the inner side
+ * of the highlighted edges (top and left if if
+ * <code>bevelType</code> is {@link BevelBorder#RAISED};
+ * bottom and right otherwise). The color for the outer side
+ * is a brightened version of this color.
+ *
+ * @param shadow the color that will be used for the outer side of
+ * the shadowed edges (bottom and right if
+ * <code>bevelType</code> is {@link BevelBorder#RAISED}; top
+ * and left otherwise). The color for the inner side is a
+ * brightened version of this color.
+ *
+ * @throws IllegalArgumentException if <code>bevelType</code> has an
+ * unsupported value.
+ *
+ * @throws NullPointerException if <code>highlight</code> or
+ * <code>shadow</code> is <code>null</code>.
+ *
+ * @see java.awt.Color#brighter()
+ */
+ public SoftBevelBorder(int bevelType, Color highlight, Color shadow)
+ {
+ this(bevelType,
+ /* highlightOuter */ highlight.brighter(),
+ /* highlightInner */ highlight,
+ /* shadowOuter */ shadow,
+ /* shadowInner */ shadow.brighter());
+ }
+
+
+ /**
+ * Constructs a SoftBevelBorder given its appearance type and all
+ * colors.
+ *
+ * <p><img src="doc-files/SoftBevelBorder-3.png" width="500" height="150"
+ * alt="[An illustration showing SoftBevelBorders that were
+ * constructed with this method]" />
+ *
+ * @param bevelType the desired appearance of the border. The value
+ * must be either {@link BevelBorder#RAISED} or {@link
+ * BevelBorder#LOWERED}.
+ *
+ * @param highlightOuter the color that will be used for the outer
+ * side of the highlighted edges (top and left if
+ * <code>bevelType</code> is {@link BevelBorder#RAISED};
+ * bottom and right otherwise).
+ *
+ * @param highlightInner the color that will be used for the inner
+ * side of the highlighted edges.
+ *
+ * @param shadowOuter the color that will be used for the outer side
+ * of the shadowed edges (bottom and right if
+ * <code>bevelType</code> is {@link BevelBorder#RAISED}; top
+ * and left otherwise).
+ *
+ * @param shadowInner the color that will be used for the inner
+ * side of the shadowed edges.
+ *
+ * @throws IllegalArgumentException if <code>bevelType</code> has
+ * an unsupported value.
+ *
+ * @throws NullPointerException if one of the passed colors
+ * is <code>null</code>.
+ */
+ public SoftBevelBorder(int bevelType,
+ Color highlightOuter, Color highlightInner,
+ Color shadowOuter, Color shadowInner)
+ {
+ super(bevelType,
+ highlightOuter, highlightInner,
+ shadowOuter, shadowInner);
+ }
+
+
+ /**
+ * Paints the border for a given component.
+ *
+ * @param c the component whose border is to be painted.
+ * @param g the graphics for painting.
+ * @param x the horizontal position for painting the border.
+ * @param y the vertical position for painting the border.
+ * @param width the width of the available area for painting the border.
+ * @param height the height of the available area for painting the border.
+ */
+ public void paintBorder(Component c, Graphics g,
+ int x, int y, int width, int height)
+ {
+ switch (bevelType)
+ {
+ case RAISED:
+ paintSoftBevel(g, x, y, width, height,
+ getHighlightOuterColor(c), getHighlightInnerColor(c),
+ getShadowInnerColor(c), getShadowOuterColor(c));
+ break;
+
+ case LOWERED:
+ paintSoftBevel(g, x, y, width, height,
+ getShadowOuterColor(c), getShadowInnerColor(c),
+ getHighlightInnerColor(c), getHighlightOuterColor(c));
+ break;
+ }
+ }
+
+
+ /**
+ * Measures the width of this border.
+ *
+ * @param c the component whose border is to be measured.
+ *
+ * @return an Insets object whose <code>left</code>, <code>right</code>,
+ * <code>top</code> and <code>bottom</code> fields indicate the
+ * width of the border at the respective edge.
+ *
+ * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
+ */
+ public Insets getBorderInsets(Component c)
+ {
+ return new Insets(3, 3, 3, 3);
+ }
+
+
+ /**
+ * Measures the width of this border, storing the results into a
+ * pre-existing Insets object.
+ *
+ * @param insets an Insets object for holding the result values.
+ * After invoking this method, the <code>left</code>,
+ * <code>right</code>, <code>top</code> and
+ * <code>bottom</code> fields indicate the width of the
+ * border at the respective edge.
+ *
+ * @return the same object that was passed for <code>insets</code>.
+ *
+ * @see #getBorderInsets(Component)
+ */
+ public Insets getBorderInsets(Component c, Insets insets)
+ {
+ insets.left = insets.right = insets.top = insets.bottom = 3;
+ return insets;
+ }
+
+
+ /**
+ * Determines whether this border fills every pixel in its area
+ * when painting.
+ *
+ * <p>The enlarged view (see documentation for constructors) shows
+ * that a SoftBevelBorder does not paint all pixels. Therefore,
+ * this method always returns <code>false</code>.
+ *
+ * @return <code>false</code>.
+ */
+ public boolean isBorderOpaque()
+ {
+ return false;
+ }
+
+
+ /**
+ * Paints a soft bevel in four colors.
+ *
+ * <pre>
+ * +++++++++++.
+ * ++.........# + = color a
+ * +.. # . = color b
+ * +. # X = color c
+ * .. X# # = color d
+ * . ##########</pre>
+ *
+ * @param g the graphics for painting.
+ * @param x the horizontal position for painting the border.
+ * @param y the vertical position for painting the border.
+ * @param width the width of the available area for painting the border.
+ * @param height the height of the available area for painting the border.
+ * @param a the color for the outer side of the top and left edges.
+ * @param b the color for the inner side of the top and left edges.
+ * @param c the color for the inner side of the bottom and right edges.
+ * @param d the color for the outer side of the bottom and right edges.
+ */
+ private static void paintSoftBevel(Graphics g,
+ int x, int y, int width, int height,
+ Color a, Color b, Color c, Color d)
+ {
+ Color oldColor;
+
+ oldColor = g.getColor();
+ g.translate(x, y);
+ width = width - 1;
+ height = height - 1;
+
+ try
+ {
+ /* To understand this code, it might be helpful to look at the
+ * images that are included with the JavaDoc, especially
+ * SoftBevelBorder-3.png. They are located in the "doc-files"
+ * subdirectory.
+ */
+ g.setColor(a);
+ g.drawLine(0, 0, width - 1, 0); // a, horizontal
+ g.drawLine(0, 1, 2, 1); // a, horizontal
+ g.drawLine(0, 2, 0, height - 1); // a, vertical
+
+ g.setColor(b);
+ g.drawLine(width, 0, width, 0); // b, horizontal
+ g.drawLine(2, 1, width - 1, 1); // b, horizontal
+ g.drawLine(1, 2, 2, 2); // b, horizontal
+ g.drawLine(1, 3, 1, height - 1); // b, vertical
+ g.drawLine(0, height - 1, 0, height); // b, vertical
+
+ g.setColor(c);
+ g.drawLine(width - 1, height - 1, // c, one pixel
+ width - 1, height - 1);
+
+ g.setColor(d);
+ g.drawLine(2, height, width, height); // d, horizontal
+ g.drawLine(width, 2, width, height - 1); // d, vertical
+ }
+ finally
+ {
+ g.translate(-x, -y);
+ g.setColor(oldColor);
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/TitledBorder.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/TitledBorder.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/TitledBorder.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/TitledBorder.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,1078 @@
+/* TitledBorder.java --
+ Copyright (C) 2003, 2004, 2005, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.border;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Rectangle;
+
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+
+
+/**
+ * A border that paints a title on top of another border.
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class TitledBorder extends AbstractBorder
+{
+ /**
+ * A value for the <code>titlePosition</code> property that vertically
+ * positions the title text at the default vertical position, which
+ * is in the middle of the top line of the border.
+ *
+ * @see #getTitlePosition()
+ * @see #setTitlePosition(int)
+ */
+ public static final int DEFAULT_POSITION = 0;
+
+
+ /**
+ * A value for the <code>titlePosition</code> property that vertically
+ * positions the title text above the top line of the border.
+ *
+ * @see #getTitlePosition()
+ * @see #setTitlePosition(int)
+ */
+ public static final int ABOVE_TOP = 1;
+
+
+ /**
+ * A value for the <code>titlePosition</code> property that vertically
+ * positions the title text at the middle of the top line
+ * of the border.
+ *
+ * @see #getTitlePosition()
+ * @see #setTitlePosition(int)
+ */
+ public static final int TOP = 2;
+
+
+ /**
+ * A value for the <code>titlePosition</code> property that vertically
+ * positions the title text below the top line of the border.
+ *
+ * @see #getTitlePosition()
+ * @see #setTitlePosition(int)
+ */
+ public static final int BELOW_TOP = 3;
+
+
+ /**
+ * A value for the <code>titlePosition</code> property that vertically
+ * positions the title text above the bottom line of the border.
+ *
+ * @see #getTitlePosition()
+ * @see #setTitlePosition(int)
+ */
+ public static final int ABOVE_BOTTOM = 4;
+
+
+ /**
+ * A value for the <code>titlePosition</code> property that vertically
+ * positions the title text at the center of the bottom line
+ * of the border.
+ *
+ * @see #getTitlePosition()
+ * @see #setTitlePosition(int)
+ */
+ public static final int BOTTOM = 5;
+
+
+ /**
+ * A value for the <code>titlePosition</code> property that vertically
+ * positions the title text below the bottom line of the border.
+ *
+ * @see #getTitlePosition()
+ * @see #setTitlePosition(int)
+ */
+ public static final int BELOW_BOTTOM = 6;
+
+
+ /**
+ * A value for the <code>titleJustification</code> property that
+ * horizontally aligns the title text with either the left or the
+ * right edge of the border, depending on the orientation of the
+ * component nested into the border. If the component orientation
+ * is left-to-right, the title text is aligned with the left edge;
+ * otherwise, it is aligned with the right edge. This is the same
+ * behavior as with {@link #LEADING}.
+ *
+ * @see #getTitleJustification()
+ * @see #setTitleJustification(int)
+ * @see java.awt.ComponentOrientation#isLeftToRight()
+ */
+ public static final int DEFAULT_JUSTIFICATION = 0;
+
+
+ /**
+ * A value for the <code>titleJustification</code> property that
+ * horizontally aligns the title text with the left-hand edge of
+ * the border.
+ *
+ * @see #getTitleJustification()
+ * @see #setTitleJustification(int)
+ */
+ public static final int LEFT = 1;
+
+
+ /**
+ * A value for the <code>titleJustification</code> property that
+ * horizontally aligns the title text with the center of the border.
+ *
+ * @see #getTitleJustification()
+ * @see #setTitleJustification(int)
+ */
+ public static final int CENTER = 2;
+
+
+ /**
+ * A value for the <code>titleJustification</code> property that
+ * horizontally aligns the title text with the right-hand edge of
+ * the border.
+ *
+ * @see #getTitleJustification()
+ * @see #setTitleJustification(int)
+ */
+ public static final int RIGHT = 3;
+
+
+ /**
+ * A value for the <code>titleJustification</code> property that
+ * horizontally aligns the title text with either the left or the
+ * right edge of the border, depending on the orientation of the
+ * component nested into the border. If the component orientation
+ * is left-to-right, the title text is aligned with the left edge;
+ * otherwise, it is aligned with the right edge. This is the same
+ * behavior as with {@link #DEFAULT_JUSTIFICATION}.
+ *
+ * @see #getTitleJustification()
+ * @see #setTitleJustification(int)
+ * @see java.awt.ComponentOrientation#isLeftToRight()
+ */
+ public static final int LEADING = 4;
+
+
+ /**
+ * A value for the <code>titleJustification</code> property that
+ * horizontally aligns the title text with either the right or the
+ * left edge of the border, depending on the orientation of the
+ * component nested into the border. If the component orientation
+ * is left-to-right, the title text is aligned with the right edge;
+ * otherwise, it is aligned with the left edge.
+ *
+ * @see #getTitleJustification()
+ * @see #setTitleJustification(int)
+ * @see java.awt.ComponentOrientation#isLeftToRight()
+ */
+ public static final int TRAILING = 5;
+
+
+ /**
+ * The number of pixels between the inside of {@link #border}
+ * and the bordered component.
+ */
+ protected static final int EDGE_SPACING = 2;
+
+
+ /**
+ * The number of pixels between the outside of this TitledBorder
+ * and the beginning (if left-aligned) or end (if right-aligned)
+ * of the title text.
+ */
+ protected static final int TEXT_INSET_H = 5;
+
+
+ /**
+ * The number of pixels between the title text and {@link #border}.
+ * This value is only relevant if the title text does not intersect
+ * {@link #border}. No intersection occurs if {@link #titlePosition}
+ * is one of {@link #ABOVE_TOP}, {@link #BELOW_TOP}, {@link #ABOVE_BOTTOM},
+ * or {@link #BELOW_BOTTOM}.
+ */
+ protected static final int TEXT_SPACING = 2;
+
+
+ /**
+ * Determined using the <code>serialver</code> tool of Apple/Sun JDK 1.3.1
+ * on MacOS X 10.1.5.
+ */
+ static final long serialVersionUID = 8012999415147721601L;
+
+
+ /**
+ * The title, or <code>null</code> to display no title.
+ */
+ protected String title;
+
+
+ /**
+ * The border underneath the title. If this value is
+ * <code>null</code>, the border will be retrieved from the {@link
+ * javax.swing.UIManager}’s defaults table using the key
+ * <code>TitledBorder.border</code>.
+ */
+ protected Border border;
+
+
+ /**
+ * The vertical position of the title text relative to the border,
+ * which is one of {@link #ABOVE_TOP}, {@link #TOP}, {@link
+ * #BELOW_TOP}, {@link #ABOVE_BOTTOM}, {@link #BOTTOM}, {@link
+ * #BELOW_BOTTOM}, or {@link #DEFAULT_POSITION}.
+ */
+ protected int titlePosition;
+
+
+ /**
+ * The horizontal alignment of the title text in relation to the
+ * border, which is one of {@link #LEFT}, {@link #CENTER}, {@link
+ * #RIGHT}, {@link #LEADING}, {@link #TRAILING}, or {@link
+ * #DEFAULT_JUSTIFICATION}.
+ */
+ protected int titleJustification;
+
+
+ /**
+ * The font for displaying the title text. If this value is
+ * <code>null</code>, the font will be retrieved from the {@link
+ * javax.swing.UIManager}’s defaults table using the key
+ * <code>TitledBorder.font</code>.
+ */
+ protected Font titleFont;
+
+
+ /**
+ * The color for displaying the title text. If this value is
+ * <code>null</code>, the color will be retrieved from the {@link
+ * javax.swing.UIManager}’s defaults table using the key
+ * <code>TitledBorder.titleColor</code>.
+ */
+ protected Color titleColor;
+
+
+ /**
+ * Constructs a TitledBorder given the text of its title.
+ *
+ * @param title the title text, or <code>null</code> to use no title text.
+ */
+ public TitledBorder(String title)
+ {
+ this(/* border */ null,
+ title, LEADING, TOP,
+ /* titleFont */ null, /* titleColor */ null);
+ }
+
+
+ /**
+ * Constructs an initially untitled TitledBorder given another border.
+ *
+ * @param border the border underneath the title, or <code>null</code>
+ * to use a default from the current look and feel.
+ */
+ public TitledBorder(Border border)
+ {
+ this(border, /* title */ "", LEADING, TOP,
+ /* titleFont */ null, /* titleColor */ null);
+ }
+
+
+ /**
+ * Constructs a TitledBorder given its border and title text.
+ *
+ * @param border the border underneath the title, or <code>null</code>
+ * to use a default from the current look and feel.
+ *
+ * @param title the title text, or <code>null</code> to use no title
+ * text.
+ */
+ public TitledBorder(Border border, String title)
+ {
+ this(border, title, LEADING, TOP,
+ /* titleFont */ null, /* titleColor */ null);
+ }
+
+
+ /**
+ * Constructs a TitledBorder given its border, title text, horizontal
+ * alignment, and vertical position.
+ *
+ * @param border the border underneath the title, or <code>null</code>
+ * to use a default from the current look and feel.
+ *
+ * @param title the title text, or <code>null</code> to use no title
+ * text.
+ *
+ * @param titleJustification the horizontal alignment of the title
+ * text in relation to the border. The value must be one of
+ * {@link #LEFT}, {@link #CENTER}, {@link #RIGHT}, {@link #LEADING},
+ * {@link #TRAILING}, or {@link #DEFAULT_JUSTIFICATION}.
+
+ * @param titlePosition the vertical position of the title text
+ * in relation to the border. The value must be one of
+ * {@link #ABOVE_TOP}, {@link #TOP}, {@link #BELOW_TOP},
+ * {@link #ABOVE_BOTTOM}, {@link #BOTTOM}, {@link #BELOW_BOTTOM},
+ * or {@link #DEFAULT_POSITION}.
+ *
+ * @throws IllegalArgumentException if <code>titleJustification</code>
+ * or <code>titlePosition</code> have an unsupported value.
+ */
+ public TitledBorder(Border border, String title, int titleJustification,
+ int titlePosition)
+ {
+ this(border, title, titleJustification, titlePosition,
+ /* titleFont */ null, /* titleColor */ null);
+ }
+
+
+ /**
+ * Constructs a TitledBorder given its border, title text, horizontal
+ * alignment, vertical position, and font.
+ *
+ * @param border the border underneath the title, or <code>null</code>
+ * to use a default from the current look and feel.
+ *
+ * @param title the title text, or <code>null</code> to use no title
+ * text.
+ *
+ * @param titleJustification the horizontal alignment of the title
+ * text in relation to the border. The value must be one of
+ * {@link #LEFT}, {@link #CENTER}, {@link #RIGHT}, {@link #LEADING},
+ * {@link #TRAILING}, or {@link #DEFAULT_JUSTIFICATION}.
+ *
+ * @param titlePosition the vertical position of the title text
+ * in relation to the border. The value must be one of
+ * {@link #ABOVE_TOP}, {@link #TOP}, {@link #BELOW_TOP},
+ * {@link #ABOVE_BOTTOM}, {@link #BOTTOM}, {@link #BELOW_BOTTOM},
+ * or {@link #DEFAULT_POSITION}.
+ *
+ * @param titleFont the font for the title text, or <code>null</code>
+ * to use a default from the current look and feel.
+ *
+ * @throws IllegalArgumentException if <code>titleJustification</code>
+ * or <code>titlePosition</code> have an unsupported value.
+ */
+ public TitledBorder(Border border, String title, int titleJustification,
+ int titlePosition, Font titleFont)
+ {
+ this(border, title, titleJustification, titlePosition, titleFont,
+ /* titleColor */ null);
+ }
+
+
+ /**
+ * Constructs a TitledBorder given its border, title text, horizontal
+ * alignment, vertical position, font, and color.
+ *
+ * @param border the border underneath the title, or <code>null</code>
+ * to use a default from the current look and feel.
+ *
+ * @param title the title text, or <code>null</code> to use no title
+ * text.
+ *
+ * @param titleJustification the horizontal alignment of the title
+ * text in relation to the border. The value must be one of
+ * {@link #LEFT}, {@link #CENTER}, {@link #RIGHT}, {@link #LEADING},
+ * {@link #TRAILING}, or {@link #DEFAULT_JUSTIFICATION}.
+ *
+ * @param titlePosition the vertical position of the title text
+ * in relation to the border. The value must be one of
+ * {@link #ABOVE_TOP}, {@link #TOP}, {@link #BELOW_TOP},
+ * {@link #ABOVE_BOTTOM}, {@link #BOTTOM}, {@link #BELOW_BOTTOM},
+ * or {@link #DEFAULT_POSITION}.
+ *
+ * @param titleFont the font for the title text, or <code>null</code>
+ * to use a default from the current look and feel.
+ *
+ * @param titleColor the color for the title text, or <code>null</code>
+ * to use a default from the current look and feel.
+ *
+ * @throws IllegalArgumentException if <code>titleJustification</code>
+ * or <code>titlePosition</code> have an unsupported value.
+ */
+ public TitledBorder(Border border, String title, int titleJustification,
+ int titlePosition, Font titleFont, Color titleColor)
+ {
+ this.border = border;
+ this.title = title;
+
+ /* Invoking the setter methods ensures that the newly constructed
+ * TitledBorder has valid property values.
+ */
+ setTitleJustification(titleJustification);
+ setTitlePosition(titlePosition);
+
+ this.titleFont = titleFont;
+ this.titleColor = titleColor;
+ }
+
+
+ /**
+ * Paints the border and the title text.
+ *
+ * @param c the component whose border is to be painted.
+ * @param g the graphics for painting.
+ * @param x the horizontal position for painting the border.
+ * @param y the vertical position for painting the border.
+ * @param width the width of the available area for painting the border.
+ * @param height the height of the available area for painting the border.
+ */
+ public void paintBorder(Component c, Graphics g,
+ int x, int y, int width, int height)
+ {
+ Rectangle borderRect = new Rectangle(x + EDGE_SPACING, y + EDGE_SPACING,
+ width - (EDGE_SPACING * 2),
+ height - (EDGE_SPACING * 2));
+ Point textLoc = new Point();
+
+ // Save color and font.
+ Color savedColor = g.getColor();
+ Font savedFont = g.getFont();
+
+ // The font metrics.
+ Font font = getFont(c);
+ g.setFont(font);
+ FontMetrics fm = c.getFontMetrics(font);
+
+ layoutBorderWithTitle(c, fm, borderRect, textLoc);
+ paintBorderWithTitle(c, g, x, y, width, height, borderRect, textLoc, fm);
+
+ g.setColor(getTitleColor());
+ g.drawString(getTitle(), textLoc.x, textLoc.y);
+ g.setFont(savedFont);
+ g.setColor(savedColor);
+ }
+
+ /**
+ * Calculates the bounding box of the inner border and the location of the
+ * title string.
+ *
+ * @param c the component on which to paint the border
+ * @param fm the font metrics
+ * @param borderRect output parameter, holds the bounding box of the inner
+ * border on method exit
+ * @param textLoc output parameter, holds the location of the title text
+ * on method exit
+ */
+ private void layoutBorderWithTitle(Component c, FontMetrics fm,
+ Rectangle borderRect,
+ Point textLoc)
+ {
+ Border b = getBorder();
+
+ // The font metrics.
+ int fontHeight = fm.getHeight();
+ int fontDescent = fm.getDescent();
+ int fontAscent = fm.getAscent();
+ int titleWidth = fm.stringWidth(getTitle());
+
+ // The base insets.
+ Insets insets;
+ if (b == null)
+ insets = new Insets(0, 0, 0, 0);
+ else
+ insets = b.getBorderInsets(c);
+
+ // The offset of the border rectangle, dependend on the title placement.
+ int offset;
+
+ // Layout border and text vertically.
+ int titlePosition = getTitlePosition();
+ switch (titlePosition)
+ {
+ case ABOVE_BOTTOM:
+ textLoc.y = borderRect.y + borderRect.height - insets.bottom
+ - fontDescent - TEXT_SPACING;
+ break;
+ case BOTTOM:
+ borderRect.height -= fontHeight / 2;
+ textLoc.y = borderRect.y + borderRect.height - fontDescent
+ + (fontAscent + fontDescent - insets.bottom) / 2;
+ break;
+ case BELOW_BOTTOM:
+ borderRect.height -= fontHeight;
+ textLoc.y = borderRect.y + borderRect.height + fontAscent
+ + TEXT_SPACING;
+ break;
+ case ABOVE_TOP:
+ offset = fontAscent + fontDescent
+ + Math.max(EDGE_SPACING, TEXT_SPACING * 2) - EDGE_SPACING;
+ borderRect.y += offset;
+ borderRect.height -= offset;
+ textLoc.y = borderRect.y - (fontDescent + TEXT_SPACING);
+ break;
+ case BELOW_TOP:
+ textLoc.y = borderRect.y + insets.top + fontAscent + TEXT_SPACING;
+ break;
+ case TOP:
+ case DEFAULT_POSITION:
+ default:
+ offset = Math.max(0, ((fontAscent / 2) + TEXT_SPACING) - EDGE_SPACING);
+ borderRect.y += offset;
+ borderRect.height -= offset;
+ textLoc.y = borderRect.y - fontDescent
+ + (insets.top + fontAscent + fontDescent) / 2;
+ break;
+ }
+
+ // Layout border and text horizontally.
+ int justification = getTitleJustification();
+ // Adjust justification for LEADING and TRAILING depending on the direction
+ // of the component.
+ if (c.getComponentOrientation().isLeftToRight())
+ {
+ if (justification == LEADING || justification == DEFAULT_JUSTIFICATION)
+ justification = LEFT;
+ else if (justification == TRAILING)
+ justification = RIGHT;
+ }
+ else
+ {
+ if (justification == LEADING || justification == DEFAULT_JUSTIFICATION)
+ justification = RIGHT;
+ else if (justification == TRAILING)
+ justification = LEFT;
+ }
+
+ switch (justification)
+ {
+ case CENTER:
+ textLoc.x = borderRect.x + (borderRect.width - titleWidth) / 2;
+ break;
+ case RIGHT:
+ textLoc.x = borderRect.x + borderRect.width - titleWidth
+ - TEXT_INSET_H - insets.right;
+ break;
+ case LEFT:
+ default:
+ textLoc.x = borderRect.x + TEXT_INSET_H + insets.left;
+ }
+ }
+
+ /**
+ * Paints the border with the title.
+ *
+ * @param c the component to paint on
+ * @param g the graphics context used for paintin
+ * @param x the upper left corner of the whole border
+ * @param y the upper left corner of the whole border
+ * @param width the width of the whole border
+ * @param height the width of the whole border
+ * @param borderRect the bounding box of the inner border
+ * @param textLoc the location of the border title
+ * @param fm the font metrics of the title
+ */
+ private void paintBorderWithTitle(Component c, Graphics g, int x, int y,
+ int width, int height,
+ Rectangle borderRect, Point textLoc,
+ FontMetrics fm)
+ {
+ Border b = getBorder();
+ int fontDescent = fm.getDescent();
+ int fontAscent = fm.getAscent();
+ int titleWidth = fm.stringWidth(getTitle());
+
+ if (b != null)
+ {
+ // Paint border in segments, when the title is painted above the
+ // border.
+ if (((titlePosition == TOP || titlePosition == DEFAULT_POSITION)
+ && (borderRect.y > textLoc.y - fontAscent))
+ || (titlePosition == BOTTOM
+ && borderRect.y + borderRect.height < textLoc.y + fontDescent))
+ {
+ Rectangle clip = new Rectangle();
+ Rectangle saved = g.getClipBounds();
+
+ // Paint border left from the text.
+ clip.setBounds(saved);
+ SwingUtilities.computeIntersection(x, y, textLoc.x - x - 1,
+ height, clip);
+ if (! clip.isEmpty())
+ {
+ g.setClip(clip);
+ b.paintBorder(c, g, borderRect.x, borderRect.y,
+ borderRect.width,
+ borderRect.height);
+ }
+ // Paint border right from the text.
+ clip.setBounds(saved);
+ SwingUtilities.computeIntersection(textLoc.x + titleWidth + 1, y,
+ x + width - (textLoc.x + titleWidth + 1), height, clip);
+ if (! clip.isEmpty())
+ {
+ g.setClip(clip);
+ b.paintBorder(c, g, borderRect.x, borderRect.y,
+ borderRect.width,
+ borderRect.height);
+ }
+
+ if (titlePosition == TOP || titlePosition == DEFAULT_POSITION)
+ {
+ // Paint border below the text.
+ clip.setBounds(saved);
+ SwingUtilities.computeIntersection(textLoc.x - 1,
+ textLoc.y + fontDescent,
+ titleWidth + 2,
+ y + height - textLoc.y - fontDescent,
+ clip);
+ if (! clip.isEmpty())
+ {
+ g.setClip(clip);
+ b.paintBorder(c, g, borderRect.x, borderRect.y,
+ borderRect.width,
+ borderRect.height);
+ }
+
+ }
+ else
+ {
+ // Paint border above the text.
+ clip.setBounds(saved);
+ SwingUtilities.computeIntersection(textLoc.x - 1, y,
+ titleWidth + 2,
+ textLoc.y - fontDescent - y,
+ clip);
+ if (! clip.isEmpty())
+ {
+ g.setClip(clip);
+ b.paintBorder(c, g, borderRect.x, borderRect.y,
+ borderRect.width,
+ borderRect.height);
+ }
+
+ }
+ g.setClip(saved);
+ }
+ else
+ {
+ b.paintBorder(c, g, borderRect.x, borderRect.y, borderRect.width,
+ borderRect.height);
+ }
+ }
+ }
+
+ /**
+ * Measures the width of this border.
+ *
+ * @param c the component whose border is to be measured.
+ *
+ * @return an Insets object whose <code>left</code>, <code>right</code>,
+ * <code>top</code> and <code>bottom</code> fields indicate the
+ * width of the border at the respective edge.
+ *
+ * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
+ */
+ public Insets getBorderInsets(Component c)
+ {
+ return getBorderInsets(c, new Insets(0, 0, 0, 0));
+ }
+
+
+ /**
+ * Measures the width of this border, storing the results into a
+ * pre-existing Insets object.
+ *
+ * @param insets an Insets object for holding the result values.
+ * After invoking this method, the <code>left</code>,
+ * <code>right</code>, <code>top</code> and
+ * <code>bottom</code> fields indicate the width of the
+ * border at the respective edge.
+ *
+ * @return the same object that was passed for <code>insets</code>.
+ *
+ * @see #getBorderInsets(Component)
+ */
+ public Insets getBorderInsets(Component c, Insets insets)
+ {
+ // Initialize insets with the insets from our border.
+ Border border = getBorder();
+ if (border != null)
+ {
+ if (border instanceof AbstractBorder)
+ {
+ AbstractBorder aBorder = (AbstractBorder) border;
+ aBorder.getBorderInsets(c, insets);
+ }
+ else
+ {
+ Insets i = border.getBorderInsets(c);
+ insets.top = i.top;
+ insets.bottom = i.bottom;
+ insets.left = i.left;
+ insets.right = i.right;
+ }
+ }
+ else
+ {
+ insets.top = 0;
+ insets.bottom = 0;
+ insets.left = 0;
+ insets.right = 0;
+ }
+
+ // Add spacing.
+ insets.top += EDGE_SPACING + TEXT_SPACING;
+ insets.bottom += EDGE_SPACING + TEXT_SPACING;
+ insets.left += EDGE_SPACING + TEXT_SPACING;
+ insets.right += EDGE_SPACING + TEXT_SPACING;
+
+ String title = getTitle();
+ if (c != null && title != null && !title.equals(""))
+ {
+ Font font = getFont(c);
+ FontMetrics fm = c.getFontMetrics(font);
+ int ascent = fm.getAscent();
+ int descent = fm.getDescent();
+ int height = fm.getHeight();
+ switch (getTitlePosition())
+ {
+ case ABOVE_BOTTOM:
+ insets.bottom += ascent + descent + TEXT_SPACING;
+ break;
+ case BOTTOM:
+ insets.bottom += ascent + descent;
+ break;
+ case BELOW_BOTTOM:
+ insets.bottom += height;
+ break;
+ case ABOVE_TOP:
+ insets.top += ascent + descent +
+ Math.max(EDGE_SPACING, TEXT_SPACING * 2)
+ - EDGE_SPACING;
+ break;
+ case BELOW_TOP:
+ insets.top += ascent + descent + TEXT_SPACING;
+ break;
+ case TOP:
+ case DEFAULT_POSITION:
+ default:
+ insets.top += ascent + descent;
+ }
+ }
+ return insets;
+ }
+
+
+ /**
+ * Returns <code>false</code>, indicating that there are pixels inside
+ * the area of this border where the background shines through.
+ *
+ * @return <code>false</code>.
+ */
+ public boolean isBorderOpaque()
+ {
+ /* Note that the AbstractBorder.isBorderOpaque would also return
+ * false, so there is actually no need to override the inherited
+ * implementation. However, GNU Classpath strives for exact
+ * compatibility with the Sun reference implementation, which
+ * overrides isBorderOpaque for unknown reasons.
+ */
+ return false;
+ }
+
+
+ /**
+ * Returns the text of the title.
+ *
+ * @return the title text, or <code>null</code> if no title is
+ * displayed.
+ */
+ public String getTitle()
+ {
+ return title;
+ }
+
+
+ /**
+ * Retrieves the border underneath the title. If no border has been
+ * set, or if it has been set to<code>null</code>, the current
+ * {@link javax.swing.LookAndFeel} will be asked for a border
+ * using the key <code>TitledBorder.border</code>.
+ *
+ * @return a border, or <code>null</code> if the current LookAndFeel
+ * does not provide a border for the key
+ * <code>TitledBorder.border</code>.
+ *
+ * @see javax.swing.UIManager#getBorder(Object)
+ */
+ public Border getBorder()
+ {
+ if (border != null)
+ return border;
+
+ return UIManager.getBorder("TitledBorder.border");
+ }
+
+
+ /**
+ * Returns the vertical position of the title text in relation
+ * to the border.
+ *
+ * @return one of the values {@link #ABOVE_TOP}, {@link #TOP},
+ * {@link #BELOW_TOP}, {@link #ABOVE_BOTTOM}, {@link #BOTTOM},
+ * {@link #BELOW_BOTTOM}, or {@link #DEFAULT_POSITION}.
+ */
+ public int getTitlePosition()
+ {
+ return titlePosition;
+ }
+
+
+ /**
+ * Returns the horizontal alignment of the title text in relation to
+ * the border.
+ *
+ * @return one of the values {@link #LEFT}, {@link #CENTER}, {@link
+ * #RIGHT}, {@link #LEADING}, {@link #TRAILING}, or {@link
+ * #DEFAULT_JUSTIFICATION}.
+ */
+ public int getTitleJustification()
+ {
+ return titleJustification;
+ }
+
+
+ /**
+ * Retrieves the font for displaying the title text. If no font has
+ * been set, or if it has been set to<code>null</code>, the current
+ * {@link javax.swing.LookAndFeel} will be asked for a font
+ * using the key <code>TitledBorder.font</code>.
+ *
+ * @return a font, or <code>null</code> if the current LookAndFeel
+ * does not provide a font for the key
+ * <code>TitledBorder.font</code>.
+ *
+ * @see javax.swing.UIManager#getFont(Object)
+ */
+ public Font getTitleFont()
+ {
+ if (titleFont != null)
+ return titleFont;
+
+ return UIManager.getFont("TitledBorder.font");
+ }
+
+
+ /**
+ * Retrieves the color for displaying the title text. If no color has
+ * been set, or if it has been set to<code>null</code>, the current
+ * {@link javax.swing.LookAndFeel} will be asked for a color
+ * using the key <code>TitledBorder.titleColor</code>.
+ *
+ * @return a color, or <code>null</code> if the current LookAndFeel
+ * does not provide a color for the key
+ * <code>TitledBorder.titleColor</code>.
+ *
+ * @see javax.swing.UIManager#getColor(Object)
+ */
+ public Color getTitleColor()
+ {
+ if (titleColor != null)
+ return titleColor;
+
+ return UIManager.getColor("TitledBorder.titleColor");
+ }
+
+
+ /**
+ * Sets the text of the title.
+ *
+ * @param title the new title text, or <code>null</code> for displaying
+ * no text at all.
+ */
+ public void setTitle(String title)
+ {
+ // Swing borders are not JavaBeans, thus no need to fire an event.
+ this.title = title;
+ }
+
+
+ /**
+ * Sets the border underneath the title.
+ *
+ * @param border a border, or <code>null</code> to use the
+ * border that is supplied by the current LookAndFeel.
+ *
+ * @see #getBorder()
+ */
+ public void setBorder(Border border)
+ {
+ // Swing borders are not JavaBeans, thus no need to fire an event.
+ this.border = border;
+ }
+
+
+ /**
+ * Sets the vertical position of the title text in relation
+ * to the border.
+ *
+ * @param titlePosition one of the values {@link #ABOVE_TOP},
+ * {@link #TOP}, {@link #BELOW_TOP}, {@link #ABOVE_BOTTOM},
+ * {@link #BOTTOM}, {@link #BELOW_BOTTOM},
+ * or {@link #DEFAULT_POSITION}.
+ *
+ * @throws IllegalArgumentException if an unsupported value is passed
+ * for <code>titlePosition</code>.
+ */
+ public void setTitlePosition(int titlePosition)
+ {
+ if ((titlePosition < DEFAULT_POSITION) || (titlePosition > BELOW_BOTTOM))
+ throw new IllegalArgumentException(titlePosition
+ + " is not a valid title position.");
+
+ // Swing borders are not JavaBeans, thus no need to fire an event.
+ this.titlePosition = titlePosition;
+ }
+
+
+ /**
+ * Sets the horizontal alignment of the title text in relation to the border.
+ *
+ * @param titleJustification the new alignment, which must be one of
+ * {@link #LEFT}, {@link #CENTER}, {@link #RIGHT}, {@link #LEADING},
+ * {@link #TRAILING}, or {@link #DEFAULT_JUSTIFICATION}.
+ *
+ * @throws IllegalArgumentException if an unsupported value is passed
+ * for <code>titleJustification</code>.
+ */
+ public void setTitleJustification(int titleJustification)
+ {
+ if ((titleJustification < DEFAULT_JUSTIFICATION)
+ || (titleJustification > TRAILING))
+ throw new IllegalArgumentException(titleJustification
+ + " is not a valid title justification.");
+
+ // Swing borders are not JavaBeans, thus no need to fire an event.
+ this.titleJustification = titleJustification;
+ }
+
+
+ /**
+ * Sets the font for displaying the title text.
+ *
+ * @param titleFont the font, or <code>null</code> to use the font
+ * provided by the current {@link javax.swing.LookAndFeel}.
+ *
+ * @see #getTitleFont()
+ */
+ public void setTitleFont(Font titleFont)
+ {
+ // Swing borders are not JavaBeans, thus no need to fire an event.
+ this.titleFont = titleFont;
+ }
+
+
+ /**
+ * Sets the color for displaying the title text.
+ *
+ * @param titleColor the color, or <code>null</code> to use the color
+ * provided by the current {@link javax.swing.LookAndFeel}.
+ *
+ * @see #getTitleColor()
+ */
+ public void setTitleColor(Color titleColor)
+ {
+ // Swing borders are not JavaBeans, thus no need to fire an event.
+ this.titleColor = titleColor;
+ }
+
+
+ /**
+ * Calculates the minimum size needed for displaying the border
+ * and its title.
+ *
+ * @param c the Component for which this TitledBorder constitutes
+ * a border.
+ *
+ * @return The minimum size.
+ */
+ public Dimension getMinimumSize(Component c)
+ {
+ Insets i = getBorderInsets(c);
+ Dimension minSize = new Dimension(i.left + i.right, i.top + i.bottom);
+ Font font = getFont(c);
+ FontMetrics fm = c.getFontMetrics(font);
+ int titleWidth = fm.stringWidth(getTitle());
+ switch (getTitlePosition())
+ {
+ case ABOVE_TOP:
+ case BELOW_BOTTOM:
+ minSize.width = Math.max(minSize.width, titleWidth);
+ break;
+ case BELOW_TOP:
+ case ABOVE_BOTTOM:
+ case TOP:
+ case BOTTOM:
+ case DEFAULT_POSITION:
+ default:
+ minSize.width += titleWidth;
+ }
+ return minSize;
+ }
+
+
+ /**
+ * Returns the font that is used for displaying the title text for
+ * a given Component.
+ *
+ * @param c the Component for which this TitledBorder is the border.
+ *
+ * @return The font returned by {@link #getTitleFont()}, or a fallback
+ * if {@link #getTitleFont()} returned <code>null</code>.
+ */
+ protected Font getFont(Component c)
+ {
+ Font f;
+
+ f = getTitleFont();
+ if (f != null)
+ return f;
+
+ return new Font("Dialog", Font.PLAIN, 12);
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/BevelBorder-1.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/BevelBorder-1.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/BevelBorder-1.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/BevelBorder-2.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/BevelBorder-2.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/BevelBorder-2.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/BevelBorder-3.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/BevelBorder-3.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/BevelBorder-3.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/EmptyBorder-1.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/EmptyBorder-1.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/EmptyBorder-1.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/EtchedBorder-1.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/EtchedBorder-1.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/EtchedBorder-1.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/EtchedBorder-2.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/EtchedBorder-2.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/EtchedBorder-2.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/LineBorder-1.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/LineBorder-1.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/LineBorder-1.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-1.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-1.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-1.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-2.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-2.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-2.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-3.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-3.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-3.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-4.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-4.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-4.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-5.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-5.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-5.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-6.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-6.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/MatteBorder-6.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/SoftBevelBorder-1.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/SoftBevelBorder-1.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/SoftBevelBorder-1.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/SoftBevelBorder-2.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/SoftBevelBorder-2.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/SoftBevelBorder-2.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/SoftBevelBorder-3.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/SoftBevelBorder-3.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/doc-files/SoftBevelBorder-3.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/border/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,47 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in javax.swing.border package.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. -->
+
+<html>
+<head><title>GNU Classpath - javax.swing.border</title></head>
+
+<body>
+<p>Provides borders for use by components in the <code>javax.swing</code>
+package.</p>
+
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/AbstractColorChooserPanel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/AbstractColorChooserPanel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/AbstractColorChooserPanel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/AbstractColorChooserPanel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,193 @@
+/* AbstractColorChooserPanel.java --
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.colorchooser;
+
+import java.awt.Color;
+import java.awt.Graphics;
+
+import javax.swing.Icon;
+import javax.swing.JColorChooser;
+import javax.swing.JPanel;
+
+/**
+ * AbstractColorChooserPanel
+ *
+ * @author Andrew Selkirk
+ * @version 1.0
+ */
+public abstract class AbstractColorChooserPanel extends JPanel
+{
+ /** DOCUMENT ME! */
+ private static final long serialVersionUID = -977469671210173863L;
+
+ /** The chooser associated with this panel. */
+ private JColorChooser chooser;
+
+ /**
+ * This is the constructor for the AbstractColorChooserPanel.
+ */
+ public AbstractColorChooserPanel()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * This method returns the name displayed in the tab for this chooser panel.
+ *
+ * @return The name displayed in the JTabbedPane's tabs.
+ */
+ public abstract String getDisplayName();
+
+ /**
+ * Returns the key code for the mnemonic for this panel. This method returns
+ * zero to indicate no mnemonic, subclasses can override this.
+ *
+ * @return <code>0</code>, to indicate no mnemonic key code.
+ *
+ * @see #getDisplayedMnemonicIndex()
+ * @since 1.4
+ */
+ public int getMnemonic()
+ {
+ return 0;
+ }
+
+ /**
+ * Returns the index of the character in the display name that is the
+ * mnemonic. This method returns <code>-1</code> to indicate no mnemonic,
+ * subclasses can override.
+ *
+ * @return <code>-1</code>, to indicate no mnemonic.
+ *
+ * @see #getDisplayName()
+ * @see #getMnemonic()
+ * @since 1.4
+ */
+ public int getDisplayedMnemonicIndex()
+ {
+ return -1;
+ }
+
+ /**
+ * This method updates the chooser panel when the JColorChooser's color has
+ * changed.
+ */
+ public abstract void updateChooser();
+
+ /**
+ * This method constructs and does any initialization necessary for the
+ * chooser panel.
+ */
+ protected abstract void buildChooser();
+
+ /**
+ * This method sets the small icon used in the JTabbedPane for this chooser
+ * panel.
+ *
+ * @return The small icon used in the JTabbedPane.
+ */
+ public abstract Icon getSmallDisplayIcon();
+
+ /**
+ * This method sets the large icon useed in the jTabbedPane for this chooser
+ * panel.
+ *
+ * @return The large icon.
+ */
+ public abstract Icon getLargeDisplayIcon();
+
+ /**
+ * This method installs the chooser panel for the given JColorChooser.
+ *
+ * @param chooser The JColorChooser that will have this panel installed.
+ */
+ public void installChooserPanel(JColorChooser chooser)
+ {
+ this.chooser = chooser;
+ buildChooser();
+ } // installChooserPanel()
+
+ /**
+ * This method removes the chooser panel from the given JColorChooser and
+ * does any necessary clean up for the chooser panel.
+ *
+ * @param chooser The JColorChooser that is having this panel removed.
+ */
+ public void uninstallChooserPanel(JColorChooser chooser)
+ {
+ this.chooser = null;
+ } // uninstallChooserPanel()
+
+ /**
+ * This method returns the ColorSelectionModel for the JColorChooser
+ * associated with this chooser panel.
+ *
+ * @return The ColorSelectionModel for the JColorChooser associated with
+ * this chooser panel.
+ */
+ public ColorSelectionModel getColorSelectionModel()
+ {
+ if (chooser != null)
+ return chooser.getSelectionModel();
+ return null;
+ } // getColorSelectionModel()
+
+ /**
+ * This method returns the current color stored in the model for this
+ * chooser panel.
+ *
+ * @return The current color.
+ */
+ protected Color getColorFromModel()
+ {
+ if (chooser != null)
+ return chooser.getColor();
+ return null;
+ } // getColorFromModel()
+
+ /**
+ * This method paints the chooser panel.
+ *
+ * @param graphics The Graphics object to paint with.
+ */
+ public void paint(Graphics graphics)
+ {
+ super.paint(graphics);
+ } // paint()
+} // AbstractColorChooserPanel
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/ColorChooserComponentFactory.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/ColorChooserComponentFactory.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/ColorChooserComponentFactory.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/ColorChooserComponentFactory.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,86 @@
+/* ColorChooserComponentFactory.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.colorchooser;
+
+import javax.swing.JComponent;
+
+
+/**
+ * ColorChooserComponentFactory
+ *
+ * @author Andrew Selkirk
+ * @version 1.0
+ */
+public class ColorChooserComponentFactory
+{
+ /**
+ * Constructor ColorChooserComponentFactory
+ */
+ private ColorChooserComponentFactory()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * This method returns the three default chooser panels to be used in
+ * JColorChooser.
+ *
+ * @return The default chooser panels.
+ */
+ public static AbstractColorChooserPanel[] getDefaultChooserPanels()
+ {
+ AbstractColorChooserPanel[] values =
+ {
+ new DefaultSwatchChooserPanel(),
+ new DefaultHSBChooserPanel(),
+ new DefaultRGBChooserPanel()
+ };
+ return values;
+ }
+
+ /**
+ * This method returns the default preview panel to be used with
+ * JColorChoosers.
+ *
+ * @return The default preview panel.
+ */
+ public static JComponent getPreviewPanel()
+ {
+ return new DefaultPreviewPanel();
+ } // getPreviewPanel()
+} // ColorChooserComponentFactory
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/ColorSelectionModel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/ColorSelectionModel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/ColorSelectionModel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/ColorSelectionModel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,86 @@
+/* ColorSelectionModel.java --
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.colorchooser;
+
+import java.awt.Color;
+
+import javax.swing.JColorChooser;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+/**
+ * A model that is used by the {@link JColorChooser} component to represent the
+ * selected color.
+ *
+ * @author Andrew Selkirk
+ */
+public interface ColorSelectionModel
+{
+
+ /**
+ * Returns the selected color.
+ *
+ * @return The selected color.
+ */
+ Color getSelectedColor();
+
+ /**
+ * Sets the selected color.
+ *
+ * @param color the selected color.
+ */
+ void setSelectedColor(Color color);
+
+ /**
+ * Registers a listener to receive {@link ChangeEvent} notifications
+ * from this model.
+ *
+ * @param listener the listener.
+ */
+ void addChangeListener(ChangeListener listener);
+
+ /**
+ * Deregisters a listener so that it no longer receives {@link ChangeEvent}
+ * notifications from this action.
+ *
+ * @param listener the listener.
+ */
+ void removeChangeListener(ChangeListener listener);
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultColorSelectionModel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultColorSelectionModel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultColorSelectionModel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultColorSelectionModel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,163 @@
+/* DefaultColorSelectionModel.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.colorchooser;
+
+import java.awt.Color;
+import java.io.Serializable;
+
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.EventListenerList;
+
+/**
+ * This is the default implementation of the ColorSelectionModel interface
+ * that JColorChoosers use.
+ *
+ * @author Andrew Selkirk
+ * @version 1.0
+ */
+public class DefaultColorSelectionModel implements ColorSelectionModel,
+ Serializable
+{
+ /** DOCUMENT ME! */
+ private static final long serialVersionUID = -8117143602864778804L;
+
+ /** The currently selected color. */
+ private Color selectedColor;
+
+ /** The ChangeEvent fired to all ChangeListeners. */
+ protected transient ChangeEvent changeEvent = new ChangeEvent(this);
+
+ /** The list of listeners. */
+ protected EventListenerList listenerList = new EventListenerList();
+
+ /**
+ * Creates a new color selection model with the default white color.
+ */
+ public DefaultColorSelectionModel()
+ {
+ this(Color.white);
+ }
+
+ /**
+ * Creates a new color selection model with a given selected color.
+ *
+ * @param color The initial color.
+ *
+ * @throws Error If the color is null.
+ */
+ public DefaultColorSelectionModel(Color color)
+ {
+ super();
+ if (color == null)
+ throw new Error("ColorSelectionModel cannot be set to have null color.");
+ this.selectedColor = color;
+ }
+
+ /**
+ * Returns the selected color.
+ *
+ * @return The selected color.
+ */
+ public Color getSelectedColor()
+ {
+ return selectedColor;
+ }
+
+ /**
+ * This method sets the color.
+ *
+ * @param color The color to set.
+ *
+ * @throws Error If the color is set.
+ */
+ public void setSelectedColor(Color color)
+ {
+ if (color == null)
+ throw new Error("ColorSelectionModel cannot be set to have null color.");
+ if (color != selectedColor)
+ {
+ this.selectedColor = color;
+ fireStateChanged();
+ }
+ }
+
+ /**
+ * Adds a listener to this model.
+ *
+ * @param listener The listener to add.
+ */
+ public void addChangeListener(ChangeListener listener)
+ {
+ listenerList.add(ChangeListener.class, listener);
+ }
+
+ /**
+ * Removes a listener from this model.
+ *
+ * @param listener The listener to remove.
+ */
+ public void removeChangeListener(ChangeListener listener)
+ {
+ listenerList.remove(ChangeListener.class, listener);
+ }
+
+ /**
+ * Returns all currently added <code>ChangeListener</code> objects.
+ *
+ * @return Array of <code>ChangeListener</code> objects.
+ */
+ public ChangeListener[] getChangeListeners()
+ {
+ return (ChangeListener[]) listenerList.getListeners(ChangeListener.class);
+ }
+
+ /**
+ * Calls all the <code>stateChanged()</code> method of all added
+ * <code>ChangeListener</code> objects with <code>changeEvent</code> as
+ * argument.
+ */
+ protected void fireStateChanged()
+ {
+ ChangeListener[] listeners = getChangeListeners();
+
+ for (int i = 0; i < listeners.length; i++)
+ listeners[i].stateChanged(changeEvent);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultHSBChooserPanel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultHSBChooserPanel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultHSBChooserPanel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultHSBChooserPanel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,891 @@
+/* DefaultHSBChooserPanel.java --
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.colorchooser;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.GridLayout;
+import java.awt.Image;
+import java.awt.Point;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionListener;
+import java.awt.image.MemoryImageSource;
+
+import javax.swing.AbstractButton;
+import javax.swing.ButtonGroup;
+import javax.swing.Icon;
+import javax.swing.JColorChooser;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+import javax.swing.JSlider;
+import javax.swing.JSpinner;
+import javax.swing.SpinnerNumberModel;
+import javax.swing.SwingConstants;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+/**
+ * This is the Default HSB Panel displayed in the JColorChooser.
+ */
+class DefaultHSBChooserPanel extends AbstractColorChooserPanel
+{
+ /** The gradient image displayed.
+ * This is package-private to avoid an accessor method. */
+ transient Image gradientImage;
+
+ /** The Panel that holds the gradient image. */
+ private transient JPanel gradientPanel;
+
+ /** The track gradient image.
+ * This is package-private to avoid an accessor method. */
+ transient Image trackImage;
+
+ /** The panel that holds the track. */
+ private transient JPanel trackPanel;
+
+ /** The slider for the locked HSB value.
+ * This is package-private to avoid an accessor method. */
+ transient JSlider slider;
+
+ /** The RadioButton that controls the Hue.
+ * This is package-private to avoid an accessor method. */
+ transient JRadioButton hRadio;
+
+ /** The RadioButton that controls the Saturation.
+ * This is package-private to avoid an accessor method. */
+ transient JRadioButton sRadio;
+
+ /** The RadioButton that controls the Brightness.
+ * This is package-private to avoid an accessor method. */
+ transient JRadioButton bRadio;
+
+ /** The JSpinner that controls the Hue.
+ * This is package-private to avoid an accessor method. */
+ transient JSpinner hSpinner;
+
+ /** The JSpinner that controls the Saturation.
+ * This is package-private to avoid an accessor method. */
+ transient JSpinner sSpinner;
+
+ /** The JSpinner that controls the Brightness.
+ * This is package-private to avoid an accessor method. */
+ transient JSpinner bSpinner;
+
+ /** The default width of the gradient image. */
+ private static final int imgWidth = 200;
+
+ /** The default height of the gradient image. */
+ private static final int imgHeight = 200;
+
+ /** The default width of the track gradient. */
+ private static final int trackWidth = 30;
+
+ /** The JLabel for Red. */
+ private static final JLabel R = new JLabel("R");
+
+ /** The JLabel for Green. */
+ private static final JLabel G = new JLabel("G");
+
+ /** The JLabel for Blue. */
+ private static final JLabel B = new JLabel("B");
+
+ // FIXME: Should be textfields.
+
+ /** The JLabel that displays the value of Red. */
+ private transient JLabel rFull;
+
+ /** The JLabel that displays the value of Green. */
+ private transient JLabel gFull;
+
+ /** The JLabel that displays the value of Blue. */
+ private transient JLabel bFull;
+
+ /** The point that is displayed in the gradient image.
+ * Package-private to avoid an accessor method.
+ */
+ transient Point gradientPoint = new Point();
+
+ /**
+ * This indicates that the change to the slider or point is triggered
+ * internally.
+ * This is package-private to avoid an accessor method.
+ */
+ transient boolean internalChange = false;
+
+ /** This indicates that the change to the spinner is triggered
+ * internally.
+ * This is package-private to avoid an accessor method. */
+ transient boolean spinnerTrigger = false;
+
+ /** This int identifies which spinner is currently locked.
+ * This is package-private to avoid an accessor method. */
+ transient int locked = -1;
+
+ /** This value indicates that the Hue spinner is locked. */
+ static final int HLOCKED = 0;
+
+ /** This value indicates that the Saturation spinner is locked. */
+ static final int SLOCKED = 1;
+
+ /** This value indicates that the Brightness spinner is locked. */
+ static final int BLOCKED = 2;
+
+ /**
+ * This method indicates that the mouse event is in the process of being
+ * handled.
+ * This is package-private to avoid an accessor method.
+ */
+ transient boolean handlingMouse;
+
+ /**
+ * This helper class handles mouse events on the gradient image.
+ */
+ class MainGradientMouseListener extends MouseAdapter
+ implements MouseMotionListener
+ {
+ /**
+ * This method is called when the mouse is pressed over the gradient
+ * image. The JColorChooser is then updated with new HSB values.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mousePressed(MouseEvent e)
+ {
+ gradientPoint = e.getPoint();
+ update(e.getPoint());
+ }
+
+ /**
+ * This method is called when the mouse is dragged over the gradient
+ * image. The JColorChooser is then updated with the new HSB values.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseDragged(MouseEvent e)
+ {
+ Point p = e.getPoint();
+ if (p.x < 0 || p.y < 0 || p.y > imgHeight || p.x > imgWidth)
+ return;
+
+ gradientPoint = p;
+ update(p);
+ }
+
+ /**
+ * This method is called when the mouse is moved over the gradient image.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseMoved(MouseEvent e)
+ {
+ // Do nothing.
+ }
+
+ /**
+ * This method updates the JColorChooser with the new values.
+ *
+ * @param p The Point where the MouseEvent occurred.
+ */
+ private void update(Point p)
+ {
+ handlingMouse = true;
+ if (hSpinner.isEnabled())
+ updateH(p);
+ else if (sSpinner.isEnabled())
+ updateS(p);
+ else
+ updateB(p);
+ handlingMouse = false;
+ }
+
+ /**
+ * This method updates the SB values if Hue is locked.
+ *
+ * @param p The point where the MouseEvent occurred.
+ */
+ private void updateH(Point p)
+ {
+ float s = (imgWidth - p.x * 1f) / imgWidth;
+ float b = (imgHeight - p.y * 1f) / imgHeight;
+
+ // Avoid two changes to the model by changing internalChange to true.
+ internalChange = true;
+ sSpinner.setValue(new Integer((int) (s * 100)));
+ internalChange = false;
+ bSpinner.setValue(new Integer((int) (b * 100)));
+
+ revalidate();
+ }
+
+ /**
+ * This method updates the HB values if Saturation is locked.
+ *
+ * @param p The point where the MouseEvent occurred.
+ */
+ private void updateS(Point p)
+ {
+ float h = p.x * 1f / imgWidth;
+ float b = (imgHeight - p.y * 1f) / imgHeight;
+
+ internalChange = true;
+ hSpinner.setValue(new Integer((int) (h * 365)));
+ internalChange = false;
+ bSpinner.setValue(new Integer((int) (b * 100)));
+
+ revalidate();
+ }
+
+ /**
+ * This method updates the HS values if Brightness is locked.
+ *
+ * @param p The point where the MouseEvent occurred.
+ */
+ private void updateB(Point p)
+ {
+ float h = p.x * 1f / imgWidth;
+ float s = (imgHeight - p.y * 1f) / imgHeight;
+
+ internalChange = true;
+ hSpinner.setValue(new Integer((int) (h * 365)));
+ internalChange = false;
+ sSpinner.setValue(new Integer((int) (s * 100)));
+
+ revalidate();
+ }
+ }
+
+ /**
+ * This method listens for slider value changes.
+ */
+ class SliderChangeListener implements ChangeListener
+ {
+ /**
+ * This method is called when the slider value changes. It should change
+ * the color of the JColorChooser.
+ *
+ * @param e The ChangeEvent.
+ */
+ public void stateChanged(ChangeEvent e)
+ {
+ if (internalChange)
+ return;
+
+ Integer value = new Integer(slider.getValue());
+
+ switch (locked)
+ {
+ case HLOCKED:
+ hSpinner.setValue(value);
+ break;
+ case SLOCKED:
+ sSpinner.setValue(value);
+ break;
+ case BLOCKED:
+ bSpinner.setValue(value);
+ break;
+ }
+ }
+ }
+
+ /**
+ * This helper class determines the active JSpinner.
+ */
+ class RadioStateListener implements ChangeListener
+ {
+ /**
+ * This method is called when there is a new JRadioButton that was
+ * selected. As a result, it should activate the associated JSpinner.
+ *
+ * @param e The ChangeEvent.
+ */
+ public void stateChanged(ChangeEvent e)
+ {
+ JSpinner change;
+ if (e.getSource() == hRadio)
+ {
+ locked = HLOCKED;
+ change = hSpinner;
+ }
+ else if (e.getSource() == sRadio)
+ {
+ locked = SLOCKED;
+ change = sSpinner;
+ }
+ else
+ {
+ locked = BLOCKED;
+ change = bSpinner;
+ }
+
+ change.setEnabled(((AbstractButton) e.getSource()).isSelected());
+ updateSlider();
+ updateTrack();
+ updateImage();
+ repaint();
+ }
+ }
+
+ /**
+ * This class listens to the JSpinners for changes.
+ */
+ class ImageScrollListener implements ChangeListener
+ {
+ /**
+ * This method is called whenever one of the JSpinner values change. The
+ * JColorChooser should be updated with the new HSB values.
+ *
+ * @param e The ChangeEvent.
+ */
+ public void stateChanged(ChangeEvent e)
+ {
+ if (internalChange)
+ return;
+
+ float h = ((Number) hSpinner.getValue()).intValue() / 360f;
+ float s = ((Number) sSpinner.getValue()).intValue() / 100f;
+ float b = ((Number) bSpinner.getValue()).intValue() / 100f;
+
+ spinnerTrigger = true;
+ getColorSelectionModel().setSelectedColor(new Color(Color.HSBtoRGB(h, s,
+ b)));
+ spinnerTrigger = false;
+
+ if (! handlingMouse && slider != null && ! slider.getValueIsAdjusting())
+ {
+ updateImage();
+ updateTrack();
+ }
+ repaint();
+ }
+ }
+
+ /**
+ * Creates a new DefaultHSBChooserPanel object.
+ */
+ DefaultHSBChooserPanel()
+ {
+ super();
+ }
+
+ /**
+ * This method returns the name displayed by the JColorChooser tab that
+ * holds this panel.
+ *
+ * @return The name displayed in the JColorChooser tab.
+ */
+ public String getDisplayName()
+ {
+ return "HSB";
+ }
+
+ /**
+ * This method updates the various components inside the HSBPanel (the
+ * JSpinners, the JSlider, and the gradient image point) with updated
+ * values when the JColorChooser color value changes.
+ */
+ public void updateChooser()
+ {
+ Color c = getColorSelectionModel().getSelectedColor();
+
+ float[] hsbVals = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(),
+ null);
+
+ internalChange = true;
+
+ if (! spinnerTrigger)
+ {
+ hSpinner.setValue(new Integer((int) (hsbVals[0] * 360)));
+ sSpinner.setValue(new Integer((int) (hsbVals[1] * 100)));
+ bSpinner.setValue(new Integer((int) (hsbVals[2] * 100)));
+ }
+
+ switch (locked)
+ {
+ case HLOCKED:
+ if (slider != null)
+ slider.setValue(((Number) hSpinner.getValue()).intValue());
+ if (! handlingMouse)
+ {
+ gradientPoint.x = (int) ((1
+ - ((Number) sSpinner.getValue()).intValue() / 100f) * imgWidth);
+ gradientPoint.y = (int) ((1
+ - ((Number) bSpinner.getValue()).intValue() / 100f) * imgHeight);
+ }
+ break;
+ case SLOCKED:
+ if (slider != null)
+ slider.setValue(((Number) sSpinner.getValue()).intValue());
+ if (! handlingMouse)
+ {
+ gradientPoint.x = (int) (((Number) hSpinner.getValue()).intValue() / 360f * imgWidth);
+ gradientPoint.y = (int) ((1
+ - ((Number) bSpinner.getValue()).intValue() / 100f) * imgHeight);
+ }
+ break;
+ case BLOCKED:
+ if (slider != null)
+ slider.setValue(((Number) bSpinner.getValue()).intValue());
+ if (! handlingMouse)
+ {
+ gradientPoint.x = (int) (((Number) hSpinner.getValue()).intValue() / 360f * imgWidth);
+ gradientPoint.y = (int) ((1
+ - ((Number) sSpinner.getValue()).intValue() / 100f) * imgHeight);
+ }
+ break;
+ }
+ internalChange = false;
+
+ if (! handlingMouse && slider != null && ! slider.getValueIsAdjusting())
+ updateImage();
+
+ if (! handlingMouse || locked != HLOCKED)
+ updateTrack();
+ updateTextFields();
+ }
+
+ /**
+ * This method builds the DefaultHSBChooserPanel.
+ */
+ protected void buildChooser()
+ {
+ setLayout(new BorderLayout());
+
+ add(buildRightPanel(), BorderLayout.EAST);
+
+ JPanel container = new JPanel();
+ container.setLayout(new BorderLayout());
+
+ gradientPanel = new JPanel()
+ {
+ public Dimension getPreferredSize()
+ {
+ return new Dimension(imgWidth, imgHeight);
+ }
+
+ public void paint(Graphics g)
+ {
+ if (gradientImage != null)
+ g.drawImage(gradientImage, 0, 0, this);
+
+ Color saved = g.getColor();
+ g.setColor(Color.WHITE);
+ g.drawOval(gradientPoint.x - 3, gradientPoint.y - 3, 6, 6);
+ g.setColor(saved);
+ }
+ };
+
+ MouseAdapter ml = new MainGradientMouseListener();
+ gradientPanel.addMouseListener(ml);
+ gradientPanel.addMouseMotionListener((MouseMotionListener) ml);
+
+ trackPanel = new JPanel()
+ {
+ public Dimension getPreferredSize()
+ {
+ return new Dimension(trackWidth, imgHeight);
+ }
+
+ public void paint(Graphics g)
+ {
+ if (trackImage != null)
+ g.drawImage(trackImage, 0, 0, this);
+ }
+ };
+
+ slider = new JSlider();
+ slider.setPaintTrack(false);
+ slider.setPaintTicks(false);
+
+ slider.setOrientation(SwingConstants.VERTICAL);
+
+ updateSlider();
+
+ container.add(gradientPanel, BorderLayout.WEST);
+ container.add(slider, BorderLayout.CENTER);
+ container.add(trackPanel, BorderLayout.EAST);
+
+ add(container, BorderLayout.WEST);
+ slider.addChangeListener(new SliderChangeListener());
+ repaint();
+ }
+
+ /**
+ * This method uninstalls the DefaultHSBPanel.
+ *
+ * @param chooser The JColorChooser to remove this panel from.
+ */
+ public void uninstallChooserPanel(JColorChooser chooser)
+ {
+ trackImage = null;
+ gradientImage = null;
+ gradientPanel = null;
+ slider = null;
+
+ hSpinner = null;
+ sSpinner = null;
+ bSpinner = null;
+
+ hRadio = null;
+ sRadio = null;
+ bRadio = null;
+
+ removeAll();
+ super.uninstallChooserPanel(chooser);
+ }
+
+ /**
+ * This helper method creates the right side panel (the panel with the
+ * Spinners and TextFields).
+ *
+ * @return The right side panel.
+ */
+ private Container buildRightPanel()
+ {
+ JPanel container = new JPanel();
+ container.setLayout(new GridLayout(6, 2));
+
+ hRadio = new JRadioButton("H");
+ sRadio = new JRadioButton("S");
+ bRadio = new JRadioButton("B");
+
+ ButtonGroup group = new ButtonGroup();
+ group.add(hRadio);
+ group.add(sRadio);
+ group.add(bRadio);
+
+ hSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 359, 1));
+ sSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 100, 1));
+ bSpinner = new JSpinner(new SpinnerNumberModel(100, 0, 100, 1));
+
+ hSpinner.setEnabled(false);
+ sSpinner.setEnabled(false);
+ bSpinner.setEnabled(false);
+
+ ChangeListener cl = new RadioStateListener();
+ ChangeListener scroll = new ImageScrollListener();
+
+ hRadio.addChangeListener(cl);
+ sRadio.addChangeListener(cl);
+ bRadio.addChangeListener(cl);
+
+ hSpinner.addChangeListener(scroll);
+ sSpinner.addChangeListener(scroll);
+ bSpinner.addChangeListener(scroll);
+
+ hRadio.setSelected(true);
+
+ container.add(hRadio);
+ container.add(hSpinner);
+
+ container.add(sRadio);
+ container.add(sSpinner);
+
+ container.add(bRadio);
+ container.add(bSpinner);
+
+ rFull = new JLabel("red full");
+ gFull = new JLabel("green full");
+ bFull = new JLabel("blue full");
+
+ container.add(R);
+ container.add(rFull);
+
+ container.add(G);
+ container.add(gFull);
+
+ container.add(B);
+ container.add(bFull);
+
+ return container;
+ }
+
+ /**
+ * This method returns the small display icon.
+ *
+ * @return The small display icon.
+ */
+ public Icon getSmallDisplayIcon()
+ {
+ return null;
+ }
+
+ /**
+ * This method returns the large display icon.
+ *
+ * @return The large display icon.
+ */
+ public Icon getLargeDisplayIcon()
+ {
+ return null;
+ }
+
+ /**
+ * This method paints the chooser panel.
+ *
+ * @param g The graphics object to paint with.
+ */
+ public void paint(Graphics g)
+ {
+ super.paint(g);
+ }
+
+ /**
+ * This method updates the gradient image with a new one taking the Hue
+ * value as the constant.
+ */
+ private void updateHLockImage()
+ {
+ int index = 0;
+ int[] pix = new int[imgWidth * imgHeight];
+ float hValue = ((Number) hSpinner.getValue()).intValue() / 360f;
+
+ for (int j = 0; j < imgHeight; j++)
+ for (int i = 0; i < imgWidth; i++)
+ pix[index++] = Color.HSBtoRGB(hValue, (imgWidth - i * 1f) / imgWidth,
+ (imgHeight - j * 1f) / imgHeight)
+ | (255 << 24);
+
+ gradientImage = createImage(new MemoryImageSource(imgWidth, imgHeight,
+ pix, 0, imgWidth));
+ }
+
+ /**
+ * This method updates the gradient image with a new one taking the
+ * Brightness value as the constant.
+ */
+ private void updateBLockImage()
+ {
+ int[] pix = new int[imgWidth * imgHeight];
+ float bValue = ((Number) bSpinner.getValue()).intValue() / 100f;
+
+ int index = 0;
+ for (int j = 0; j < imgHeight; j++)
+ for (int i = 0; i < imgWidth; i++)
+ pix[index++] = Color.HSBtoRGB(i * 1f / imgWidth,
+ (imgHeight - j * 1f) / imgHeight, bValue)
+ | (255 << 24);
+
+ gradientImage = createImage(new MemoryImageSource(imgWidth, imgHeight,
+ pix, 0, imgWidth));
+ }
+
+ /**
+ * This method updates the gradient image with a new one taking the
+ * Saturation value as the constant.
+ */
+ private void updateSLockImage()
+ {
+ int[] pix = new int[imgWidth * imgHeight];
+ float sValue = ((Number) sSpinner.getValue()).intValue() / 100f;
+
+ int index = 0;
+ for (int j = 0; j < imgHeight; j++)
+ for (int i = 0; i < imgWidth; i++)
+ pix[index++] = Color.HSBtoRGB(i * 1f / imgWidth, sValue,
+ (imgHeight - j * 1f) / imgHeight)
+ | (255 << 24);
+ gradientImage = createImage(new MemoryImageSource(imgWidth, imgHeight,
+ pix, 0, imgWidth));
+ }
+
+ /**
+ * This method calls the appropriate method to update the gradient image
+ * depending on which HSB value is constant.
+ * This is package-private to avoid an accessor method.
+ */
+ void updateImage()
+ {
+ switch (locked)
+ {
+ case HLOCKED:
+ updateHLockImage();
+ break;
+ case SLOCKED:
+ updateSLockImage();
+ break;
+ case BLOCKED:
+ updateBLockImage();
+ break;
+ }
+ }
+
+ /**
+ * This method updates the TextFields with the correct RGB values.
+ */
+ private void updateTextFields()
+ {
+ int c = getColorSelectionModel().getSelectedColor().getRGB();
+
+ rFull.setText("" + (c >> 16 & 0xff));
+ gFull.setText("" + (c >> 8 & 0xff));
+ bFull.setText("" + (c & 0xff));
+
+ repaint();
+ }
+
+ /**
+ * This method updates the slider in response to making a different HSB
+ * property the constant.
+ * This is package-private to avoid an accessor method.
+ */
+ void updateSlider()
+ {
+ if (slider == null)
+ return;
+
+ slider.setMinimum(0);
+ if (locked == HLOCKED)
+ {
+ slider.setMaximum(359);
+ ;
+ slider.setValue(((Number) hSpinner.getValue()).intValue());
+ slider.setInverted(true);
+ }
+ else
+ {
+ slider.setMaximum(100);
+ slider.setInverted(false);
+ if (sRadio.isSelected())
+ slider.setValue(((Number) sSpinner.getValue()).intValue());
+ else
+ slider.setValue(((Number) bSpinner.getValue()).intValue());
+ }
+ repaint();
+ }
+
+ /**
+ * This method updates the track gradient image depending on which HSB
+ * property is constant.
+ * This is package-private to avoid an accessor method.
+ */
+ void updateTrack()
+ {
+ switch (locked)
+ {
+ case HLOCKED:
+ updateHTrack();
+ break;
+ case SLOCKED:
+ updateSTrack();
+ break;
+ case BLOCKED:
+ updateBTrack();
+ break;
+ }
+ }
+
+ /**
+ * This method updates the track gradient image if the Hue value is allowed
+ * to change (according to the JRadioButtons).
+ */
+ private void updateHTrack()
+ {
+ int trackIndex = 0;
+ int[] trackPix = new int[trackWidth * imgHeight];
+
+ for (int j = 0; j < imgHeight; j++)
+ for (int i = 0; i < trackWidth; i++)
+ trackPix[trackIndex++] = Color.HSBtoRGB(j * 1f / imgHeight, 1f, 1f)
+ | (255 << 24);
+
+ trackImage = createImage(new MemoryImageSource(trackWidth, imgHeight,
+ trackPix, 0, trackWidth));
+ }
+
+ /**
+ * This method updates the track gradient image if the Saturation value is
+ * allowed to change (according to the JRadioButtons).
+ */
+ private void updateSTrack()
+ {
+ int[] trackPix = new int[trackWidth * imgHeight];
+
+ float hValue = ((Number) hSpinner.getValue()).intValue() / 360f;
+ float bValue = ((Number) bSpinner.getValue()).intValue() / 100f;
+
+ int trackIndex = 0;
+ for (int j = 0; j < imgHeight; j++)
+ for (int i = 0; i < trackWidth; i++)
+ trackPix[trackIndex++] = Color.HSBtoRGB(hValue,
+ (imgHeight - j * 1f) / imgHeight,
+ bValue) | (255 << 24);
+
+ trackImage = createImage(new MemoryImageSource(trackWidth, imgHeight,
+ trackPix, 0, trackWidth));
+ }
+
+ /**
+ * This method updates the track gradient image if the Brightness value is
+ * allowed to change (according to the JRadioButtons).
+ */
+ private void updateBTrack()
+ {
+ int[] trackPix = new int[trackWidth * imgHeight];
+
+ float hValue = ((Number) hSpinner.getValue()).intValue() / 360f;
+ float sValue = ((Number) sSpinner.getValue()).intValue() / 100f;
+
+ int trackIndex = 0;
+ for (int j = 0; j < imgHeight; j++)
+ for (int i = 0; i < trackWidth; i++)
+ trackPix[trackIndex++] = Color.HSBtoRGB(hValue, sValue,
+ (imgHeight - j * 1f) / imgHeight)
+ | (255 << 24);
+
+ trackImage = createImage(new MemoryImageSource(trackWidth, imgHeight,
+ trackPix, 0, trackWidth));
+ }
+
+ /**
+ * This method returns the HSB values for the currently selected color.
+ *
+ * @return The HSB values for the currently selected color.
+ */
+ private float[] getHSBValues()
+ {
+ Color c = getColorFromModel();
+ float[] f = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null);
+ return f;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultPreviewPanel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultPreviewPanel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultPreviewPanel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultPreviewPanel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,318 @@
+/* DefaultPreviewPanel.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.colorchooser;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Insets;
+
+import javax.swing.JColorChooser;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+import javax.swing.border.Border;
+
+/**
+ * This is the default preview panel for the JColorChooser. The default
+ * preview panel is responsible for displaying the currently selected color
+ * of the JColorChooser.
+ */
+class DefaultPreviewPanel extends JPanel
+{
+ /**
+ * This is the border around the preview panel.
+ */
+ class PreviewBorder implements Border
+ {
+ /** This is the value of the top, bottom, top, and right inset. */
+ private static final int edge = 20;
+
+ /**
+ * This is the distance from the top left corner of the border to the
+ * text.
+ */
+ private static final int lead = 5;
+
+ /** This is the horizontal gap between the text and the border. */
+ private static final int gap = 3;
+
+ /**
+ * This method returns the border insets for the given Component.
+ *
+ * @param c The Component to retrieve insets for.
+ *
+ * @return The insets for the given Component.
+ */
+ public Insets getBorderInsets(Component c)
+ {
+ return new Insets(edge, edge, edge, edge);
+ }
+
+ /**
+ * This method returns whether the border is responsible for painting its
+ * own background.
+ *
+ * @return Whether the border is responsible for painting its own
+ * background.
+ */
+ public boolean isBorderOpaque()
+ {
+ return true;
+ }
+
+ /**
+ * This method paints the border for the given component with the graphics
+ * object using the given properties.
+ *
+ * @param c The Component to paint the border for.
+ * @param g The Graphics object to paint with.
+ * @param x The x location to paint at.
+ * @param y The y location to paint at.
+ * @param width The width of the component.
+ * @param height The height of the component.
+ */
+ public void paintBorder(Component c, Graphics g, int x, int y, int width,
+ int height)
+ {
+ Color saved = g.getColor();
+ FontMetrics fm = g.getFontMetrics();
+
+ g.setColor(Color.BLACK);
+ g.drawLine(x + edge / 2, y + edge / 2, x + edge / 2,
+ y + height - edge / 2);
+ g.drawLine(x + edge / 2, y + height - edge / 2, x + width - edge / 2,
+ y + height - edge / 2);
+ g.drawLine(x + width - edge / 2, y + edge / 2, x + width - edge / 2,
+ y + height - edge / 2);
+ g.drawLine(x + edge / 2, y + edge / 2, x + edge / 2 + lead, y + edge / 2);
+
+ int strwidth = fm.stringWidth("Preview");
+
+ g.drawString("Preview", x + edge / 2 + lead + gap,
+ y + edge / 2 + fm.getAscent() / 2);
+
+ g.drawLine(x + lead + edge / 2 + strwidth + gap * 2, y + edge / 2,
+ x + width - edge / 2, y + edge / 2);
+
+ g.setColor(saved);
+ }
+ }
+
+ /** A standard large gap size. */
+ private static int largeGap = 6;
+
+ /** A standard small gap size. */
+ private static int smallGap = 2;
+
+ /** The size of each side of the square. */
+ private static int squareSize = 36;
+
+ /** This padding between the text and the edge of its box. */
+ private static int textPadding = 4;
+
+ /** The width of the right most rectangles. */
+ private static int rightSideRectWidth = 60;
+
+ /** The sample text. */
+ private static String sample = "Sample Text Sample Text";
+
+ /**
+ * Creates a new DefaultPreviewPanel object.
+ */
+ DefaultPreviewPanel()
+ {
+ super();
+ setBorder(new PreviewBorder());
+ }
+
+ /**
+ * This method paints the default preview panel with the given Graphics
+ * object.
+ *
+ * @param g The Graphics object.
+ */
+ public void paint(Graphics g)
+ {
+ super.paint(g);
+ Color currentColor = null;
+ JColorChooser chooser = (JColorChooser) SwingUtilities.getAncestorOfClass(JColorChooser.class,
+ this);
+ if (chooser != null)
+ currentColor = chooser.getColor();
+
+ Color saved = g.getColor();
+ Insets insets = getInsets();
+
+ int down = insets.top + squareSize + largeGap;
+ int currX = insets.left;
+
+ paintSquare(g, currX, insets.top, Color.WHITE, currentColor, Color.WHITE,
+ -1, -1, -1);
+ paintSquare(g, currX, down, currentColor, null, null, -1, -1, -1);
+
+ currX += squareSize + largeGap;
+
+ paintSquare(g, currX, insets.top, Color.BLACK, currentColor, Color.WHITE,
+ -1, -1, -1);
+ paintSquare(g, currX, down, Color.WHITE, currentColor, null, -1, -1, -1);
+
+ currX += squareSize + largeGap;
+
+ paintSquare(g, currX, insets.top, Color.WHITE, currentColor, Color.BLACK,
+ -1, -1, -1);
+ paintSquare(g, currX, down, Color.BLACK, currentColor, null, -1, -1, -1);
+
+ FontMetrics fm = g.getFontMetrics();
+ int strWidth = fm.stringWidth(sample);
+ int strHeight = fm.getHeight();
+
+ currX += squareSize + largeGap;
+
+ int boxWidth = 2 * textPadding + strWidth;
+ int boxHeight = 2 * textPadding + strHeight;
+
+ int first = insets.top + textPadding;
+ int second = insets.top + boxHeight + smallGap;
+ int third = insets.top + 2 * (boxHeight + smallGap);
+
+ g.setColor(Color.WHITE);
+ g.fillRect(currX, third, boxWidth, boxHeight);
+
+ g.setColor(currentColor);
+ g.drawString(sample, currX + textPadding,
+ first + textPadding + fm.getAscent());
+
+ g.fillRect(currX, second, boxWidth, boxHeight);
+
+ g.drawString(sample, currX + textPadding,
+ third + textPadding + fm.getAscent());
+
+ g.setColor(Color.BLACK);
+ g.drawString(sample, currX + textPadding,
+ second + textPadding + fm.getAscent());
+
+ currX += boxWidth + largeGap;
+
+ g.setColor(Color.WHITE);
+ g.fillRect(currX, insets.top, rightSideRectWidth, squareSize
+ + largeGap / 2);
+
+ g.setColor(currentColor);
+ g.fillRect(currX, insets.top + squareSize + largeGap / 2,
+ rightSideRectWidth, squareSize + largeGap / 2);
+
+ g.setColor(saved);
+ }
+
+ /**
+ * This method creates and paints a square. The square has two smaller
+ * squares inside of it. Each of the three squares has their sizes
+ * determined by the size arguments. If the size is not given (by passing
+ * in -1), then the size is determined automatically.
+ *
+ * @param g The Graphics object to paint with.
+ * @param x The x location to paint at.
+ * @param y The y location to paint at.
+ * @param first The color of the first square.
+ * @param second The color of the second square.
+ * @param third The color of the third square.
+ * @param firstSize The size of the first square.
+ * @param secondSize The size of the second square.
+ * @param thirdSize The size of the third square.
+ */
+ private void paintSquare(Graphics g, int x, int y, Color first,
+ Color second, Color third, int firstSize,
+ int secondSize, int thirdSize)
+ {
+ Color saved = g.getColor();
+ if (firstSize == -1)
+ firstSize = squareSize;
+ if (secondSize == -1)
+ secondSize = squareSize * 2 / 3;
+ if (thirdSize == -1)
+ thirdSize = squareSize / 3;
+ int secondOffset = (firstSize - secondSize) / 2;
+ int thirdOffset = (firstSize - thirdSize) / 2;
+
+ if (first == null)
+ return;
+ g.setColor(first);
+ g.fillRect(x, y, firstSize, firstSize);
+ if (second == null)
+ return;
+ g.setColor(second);
+ g.fillRect(x + secondOffset, y + secondOffset, secondSize, secondSize);
+ if (third == null)
+ return;
+ g.setColor(third);
+ g.fillRect(x + thirdOffset, y + thirdOffset, thirdSize, thirdSize);
+
+ g.setColor(saved);
+ }
+
+ /**
+ * This method returns the preferred size of the default preview panel.
+ *
+ * @return The preferred size of the default preview panel.
+ */
+ public Dimension getPreferredSize()
+ {
+ Graphics g = getGraphics();
+ FontMetrics fm = g.getFontMetrics();
+ g.dispose();
+
+ int strWidth = fm.stringWidth(sample);
+ int strHeight = fm.getHeight();
+
+ int h1 = (strHeight + 2 * textPadding) * 3 + 2 * smallGap;
+ int h2 = 2 * squareSize + largeGap;
+
+ int height = Math.max(h1, h2);
+
+ int width = 3 * (squareSize + largeGap) + strWidth + 2 * textPadding
+ + largeGap + rightSideRectWidth;
+
+ Insets insets = getInsets();
+
+ return new Dimension(width + insets.right + insets.left,
+ height + insets.top + insets.bottom);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultRGBChooserPanel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultRGBChooserPanel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultRGBChooserPanel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultRGBChooserPanel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,402 @@
+/* DefaultRGHChooserPanel.java --
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.colorchooser;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+
+import javax.swing.Icon;
+import javax.swing.JColorChooser;
+import javax.swing.JLabel;
+import javax.swing.JSlider;
+import javax.swing.JSpinner;
+import javax.swing.SpinnerNumberModel;
+import javax.swing.SwingConstants;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+/**
+ * This is the default RGB panel for the JColorChooser. The color is selected
+ * using three sliders that represent the RGB values.
+ */
+class DefaultRGBChooserPanel extends AbstractColorChooserPanel
+{
+ /**
+ * This class handles the slider value changes for all three sliders.
+ */
+ class SliderHandler implements ChangeListener
+ {
+ /**
+ * This method is called whenever any of the slider values change.
+ *
+ * @param e The ChangeEvent.
+ */
+ public void stateChanged(ChangeEvent e)
+ {
+ if (updateChange)
+ return;
+
+ int color = R.getValue() << 16 | G.getValue() << 8 | B.getValue();
+
+ sliderChange = true;
+ getColorSelectionModel().setSelectedColor(new Color(color));
+ sliderChange = false;
+ }
+ }
+
+ /**
+ * This class handles the Spinner values changing.
+ */
+ class SpinnerHandler implements ChangeListener
+ {
+ /**
+ * This method is called whenever any of the JSpinners change values.
+ *
+ * @param e The ChangeEvent.
+ */
+ public void stateChanged(ChangeEvent e)
+ {
+ if (updateChange)
+ return;
+
+ int red = ((Number) RSpinner.getValue()).intValue();
+ int green = ((Number) GSpinner.getValue()).intValue();
+ int blue = ((Number) BSpinner.getValue()).intValue();
+
+ int color = red << 16 | green << 8 | blue;
+
+ spinnerChange = true;
+ getColorSelectionModel().setSelectedColor(new Color(color));
+ spinnerChange = false;
+ }
+ }
+
+ /** Whether the color change was initiated by the spinners.
+ * This is package-private to avoid an accessor method. */
+ transient boolean spinnerChange = false;
+
+ /** Whether the color change was initiated by the sliders.
+ * This is package-private to avoid an accessor method. */
+ transient boolean sliderChange = false;
+
+ /**
+ * Whether the change was forced by the chooser (meaning the color has
+ * already been changed).
+ * This is package-private to avoid an accessor method.
+ */
+ transient boolean updateChange = false;
+
+ /** The ChangeListener for the sliders. */
+ private transient ChangeListener colorChanger;
+
+ /** The ChangeListener for the spinners. */
+ private transient ChangeListener spinnerHandler;
+
+ /** The slider that handles the red values.
+ * This is package-private to avoid an accessor method. */
+ transient JSlider R;
+
+ /** The slider that handles the green values.
+ * This is package-private to avoid an accessor method. */
+ transient JSlider G;
+
+ /** The slider that handles the blue values.
+ * This is package-private to avoid an accessor method. */
+ transient JSlider B;
+
+ /** The label for the red slider. */
+ private transient JLabel RLabel;
+
+ /** The label for the green slider. */
+ private transient JLabel GLabel;
+
+ /** The label for the blue slider. */
+ private transient JLabel BLabel;
+
+ /** The spinner that handles the red values.
+ * This is package-private to avoid an accessor method. */
+ transient JSpinner RSpinner;
+
+ /** The spinner that handles the green values.
+ * This is package-private to avoid an accessor method. */
+ transient JSpinner GSpinner;
+
+ /** The spinner that handles the blue values.
+ * This is package-private to avoid an accessor method. */
+ transient JSpinner BSpinner;
+
+ /**
+ * Creates a new DefaultRGBChooserPanel object.
+ */
+ public DefaultRGBChooserPanel()
+ {
+ super();
+ }
+
+ /**
+ * This method returns the name displayed in the JTabbedPane.
+ *
+ * @return The name displayed in the JTabbedPane.
+ */
+ public String getDisplayName()
+ {
+ return "RGB";
+ }
+
+ /**
+ * This method updates the chooser panel with the new color chosen in the
+ * JColorChooser.
+ */
+ public void updateChooser()
+ {
+ Color c = getColorFromModel();
+ int rgb = c.getRGB();
+
+ int red = rgb >> 16 & 0xff;
+ int green = rgb >> 8 & 0xff;
+ int blue = rgb & 0xff;
+
+ updateChange = true;
+
+ if (! sliderChange)
+ {
+ if (R != null)
+ R.setValue(red);
+ if (G != null)
+ G.setValue(green);
+ if (B != null)
+ B.setValue(blue);
+ }
+ if (! spinnerChange)
+ {
+ if (GSpinner != null)
+ GSpinner.setValue(new Integer(green));
+ if (RSpinner != null)
+ RSpinner.setValue(new Integer(red));
+ if (BSpinner != null)
+ BSpinner.setValue(new Integer(blue));
+ }
+
+ updateChange = false;
+
+ revalidate();
+ repaint();
+ }
+
+ /**
+ * This method builds the chooser panel.
+ */
+ protected void buildChooser()
+ {
+ setLayout(new GridBagLayout());
+
+ RLabel = new JLabel("Red");
+ RLabel.setDisplayedMnemonic('d');
+ GLabel = new JLabel("Green");
+ GLabel.setDisplayedMnemonic('n');
+ BLabel = new JLabel("Blue");
+ BLabel.setDisplayedMnemonic('B');
+
+ R = new JSlider(SwingConstants.HORIZONTAL, 0, 255, 255);
+ G = new JSlider(SwingConstants.HORIZONTAL, 0, 255, 255);
+ B = new JSlider(SwingConstants.HORIZONTAL, 0, 255, 255);
+
+ R.setPaintTicks(true);
+ R.setSnapToTicks(false);
+ G.setPaintTicks(true);
+ G.setSnapToTicks(false);
+ B.setPaintTicks(true);
+ B.setSnapToTicks(false);
+
+ R.setLabelTable(R.createStandardLabels(85));
+ R.setPaintLabels(true);
+ G.setLabelTable(G.createStandardLabels(85));
+ G.setPaintLabels(true);
+ B.setLabelTable(B.createStandardLabels(85));
+ B.setPaintLabels(true);
+
+ R.setMajorTickSpacing(85);
+ G.setMajorTickSpacing(85);
+ B.setMajorTickSpacing(85);
+
+ R.setMinorTickSpacing(17);
+ G.setMinorTickSpacing(17);
+ B.setMinorTickSpacing(17);
+
+ RSpinner = new JSpinner(new SpinnerNumberModel(R.getValue(),
+ R.getMinimum(),
+ R.getMaximum(), 1));
+ GSpinner = new JSpinner(new SpinnerNumberModel(G.getValue(),
+ G.getMinimum(),
+ G.getMaximum(), 1));
+ BSpinner = new JSpinner(new SpinnerNumberModel(B.getValue(),
+ B.getMinimum(),
+ B.getMaximum(), 1));
+
+ RLabel.setLabelFor(R);
+ GLabel.setLabelFor(G);
+ BLabel.setLabelFor(B);
+
+ GridBagConstraints bag = new GridBagConstraints();
+ bag.fill = GridBagConstraints.VERTICAL;
+
+ bag.gridx = 0;
+ bag.gridy = 0;
+ add(RLabel, bag);
+
+ bag.gridx = 1;
+ add(R, bag);
+
+ bag.gridx = 2;
+ add(RSpinner, bag);
+
+ bag.gridx = 0;
+ bag.gridy = 1;
+ add(GLabel, bag);
+
+ bag.gridx = 1;
+ add(G, bag);
+
+ bag.gridx = 2;
+ add(GSpinner, bag);
+
+ bag.gridx = 0;
+ bag.gridy = 2;
+ add(BLabel, bag);
+
+ bag.gridx = 1;
+ add(B, bag);
+
+ bag.gridx = 2;
+ add(BSpinner, bag);
+
+ installListeners();
+ }
+
+ /**
+ * This method uninstalls the chooser panel from the JColorChooser.
+ *
+ * @param chooser The JColorChooser to remove this chooser panel from.
+ */
+ public void uninstallChooserPanel(JColorChooser chooser)
+ {
+ uninstallListeners();
+ removeAll();
+
+ R = null;
+ G = null;
+ B = null;
+
+ RSpinner = null;
+ GSpinner = null;
+ BSpinner = null;
+
+ super.uninstallChooserPanel(chooser);
+ }
+
+ /**
+ * This method uninstalls any listeners that were added by the chooser
+ * panel.
+ */
+ private void uninstallListeners()
+ {
+ R.removeChangeListener(colorChanger);
+ G.removeChangeListener(colorChanger);
+ B.removeChangeListener(colorChanger);
+
+ colorChanger = null;
+
+ RSpinner.removeChangeListener(spinnerHandler);
+ GSpinner.removeChangeListener(spinnerHandler);
+ BSpinner.removeChangeListener(spinnerHandler);
+
+ spinnerHandler = null;
+ }
+
+ /**
+ * This method installs any listeners that the chooser panel needs to
+ * operate.
+ */
+ private void installListeners()
+ {
+ colorChanger = new SliderHandler();
+
+ R.addChangeListener(colorChanger);
+ G.addChangeListener(colorChanger);
+ B.addChangeListener(colorChanger);
+
+ spinnerHandler = new SpinnerHandler();
+
+ RSpinner.addChangeListener(spinnerHandler);
+ GSpinner.addChangeListener(spinnerHandler);
+ BSpinner.addChangeListener(spinnerHandler);
+ }
+
+ /**
+ * This method returns the small display icon.
+ *
+ * @return The small display icon.
+ */
+ public Icon getSmallDisplayIcon()
+ {
+ return null;
+ }
+
+ /**
+ * This method returns the large display icon.
+ *
+ * @return The large display icon.
+ */
+ public Icon getLargeDisplayIcon()
+ {
+ return null;
+ }
+
+ /**
+ * This method paints the default RGB chooser panel.
+ *
+ * @param g The Graphics object to paint with.
+ */
+ public void paint(Graphics g)
+ {
+ super.paint(g);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultSwatchChooserPanel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultSwatchChooserPanel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultSwatchChooserPanel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/DefaultSwatchChooserPanel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,896 @@
+/* DefaultSwatchChooserPanel.java --
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.colorchooser;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.LayoutManager;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+
+import javax.swing.Icon;
+import javax.swing.JColorChooser;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+/**
+ * This class is the DefaultSwatchChooserPanel. This chooser panel displays a
+ * set of colors that can be picked. Recently picked items will go into a
+ * side panel so the user can see the history of the chosen colors.
+ */
+class DefaultSwatchChooserPanel extends AbstractColorChooserPanel
+{
+ /** The main panel that holds the set of choosable colors. */
+ MainSwatchPanel mainPalette;
+
+ /** A panel that holds the recent colors. */
+ RecentSwatchPanel recentPalette;
+
+ /** The mouse handlers for the panels. */
+ MouseListener mouseHandler;
+
+ /**
+ * This the base class for all swatch panels. Swatch panels are panels that
+ * hold a set of blocks where colors are displayed.
+ */
+ abstract static class SwatchPanel extends JPanel
+ {
+ /** The width of each block. */
+ protected int cellWidth = 10;
+
+ /** The height of each block. */
+ protected int cellHeight = 10;
+
+ /** The gap between blocks. */
+ protected int gap = 1;
+
+ /** The number of rows in the swatch panel. */
+ protected int numRows;
+
+ /** The number of columns in the swatch panel. */
+ protected int numCols;
+
+ /**
+ * Creates a new SwatchPanel object.
+ */
+ SwatchPanel()
+ {
+ super();
+ setBackground(Color.WHITE);
+ }
+
+ /**
+ * This method returns the preferred size of the swatch panel based on the
+ * number of rows and columns and the size of each cell.
+ *
+ * @return The preferred size of the swatch panel.
+ */
+ public Dimension getPreferredSize()
+ {
+ int height = numRows * cellHeight + (numRows - 1) * gap;
+ int width = numCols * cellWidth + (numCols - 1) * gap;
+ Insets insets = getInsets();
+
+ return new Dimension(width + insets.left + insets.right,
+ height + insets.top + insets.bottom);
+ }
+
+ /**
+ * This method returns the color for the given position.
+ *
+ * @param x The x coordinate of the position.
+ * @param y The y coordinate of the position.
+ *
+ * @return The color at the given position.
+ */
+ public abstract Color getColorForPosition(int x, int y);
+
+ /**
+ * This method initializes the colors for the swatch panel.
+ */
+ protected abstract void initializeColors();
+ }
+
+ /**
+ * This is the main swatch panel. This panel sits in the middle and allows a
+ * set of colors to be picked which will move to the recent swatch panel.
+ */
+ static class MainSwatchPanel extends SwatchPanel
+ {
+ /** The color describing (204, 255, 255) */
+ public static final Color C204255255 = new Color(204, 204, 255);
+
+ /** The color describing (255, 204, 204) */
+ public static final Color C255204204 = new Color(255, 204, 204);
+
+ /** The color describing (204, 255, 204) */
+ public static final Color C204255204 = new Color(204, 255, 204);
+
+ /** The color describing (204, 204, 204) */
+ public static final Color C204204204 = new Color(204, 204, 204);
+
+ /** The color (153, 153, 255). */
+ public static final Color C153153255 = new Color(153, 153, 255);
+
+ /** The color (51, 51, 255). */
+ public static final Color C051051255 = new Color(51, 51, 255);
+
+ /** The color (153, 0, 153). */
+ public static final Color C153000153 = new Color(153, 0, 153);
+
+ /** The color (0, 51, 51). */
+ public static final Color C000051051 = new Color(0, 51, 51);
+
+ /** The color (51, 0, 51). */
+ public static final Color C051000051 = new Color(51, 0, 51);
+
+ /** The color (51, 51, 0). */
+ public static final Color C051051000 = new Color(51, 51, 0);
+
+ /** The color (102, 102, 0). */
+ public static final Color C102102000 = new Color(102, 102, 0);
+
+ /** The color (153, 255, 153). */
+ public static final Color C153255153 = new Color(153, 255, 153);
+
+ /** The color (102, 255, 102). */
+ public static final Color C102255102 = new Color(102, 255, 102);
+
+ /** The color (0, 102, 102). */
+ public static final Color C000102102 = new Color(0, 102, 102);
+
+ /** The color (102, 0, 102). */
+ public static final Color C102000102 = new Color(102, 0, 102);
+
+ /** The color (0, 153, 153). */
+ public static final Color C000153153 = new Color(0, 153, 153);
+
+ /** The color (153, 153, 0). */
+ public static final Color C153153000 = new Color(153, 153, 0);
+
+ /** The color (204, 204, 0). */
+ public static final Color C204204000 = new Color(204, 204, 0);
+
+ /** The color (204, 0, 204). */
+ public static final Color C204000204 = new Color(204, 0, 204);
+
+ /** The color (0, 204, 204). */
+ public static final Color C000204204 = new Color(0, 204, 204);
+
+ /** The color (51, 255, 51). */
+ public static final Color C051255051 = new Color(51, 255, 51);
+
+ /** The color (255, 51, 51). */
+ public static final Color C255051051 = new Color(255, 51, 51);
+
+ /** The color (255, 102, 102). */
+ public static final Color C255102102 = new Color(255, 102, 102);
+
+ /** The color (102, 102, 255). */
+ public static final Color C102102255 = new Color(102, 102, 255);
+
+ /** The color (255, 153, 153). */
+ public static final Color C255153153 = new Color(255, 153, 153);
+ static Color[] colors =
+ {
+ // Row 1
+ Color.WHITE, new Color(204, 255, 255), C204255255, C204255255, C204255255,
+ C204255255, C204255255, C204255255, C204255255,
+ C204255255, C204255255, new Color(255, 204, 255),
+ C255204204, C255204204, C255204204, C255204204,
+ C255204204, C255204204, C255204204, C255204204,
+ C255204204, new Color(255, 255, 204), C204255204,
+ C204255204, C204255204, C204255204, C204255204,
+ C204255204, C204255204, C204255204, C204255204,
+
+ // Row 2
+ C204204204, new Color(153, 255, 255), new Color(153, 204, 255), C153153255,
+ C153153255, C153153255, C153153255, C153153255,
+ C153153255, C153153255, new Color(204, 153, 255),
+ new Color(255, 153, 255),
+ new Color(255, 153, 204), C255153153, C255153153,
+ C255153153, C255153153, C255153153, C255153153,
+ C255153153, new Color(255, 204, 153),
+ new Color(255, 255, 153),
+ new Color(204, 255, 153), C153255153, C153255153,
+ C153255153, C153255153, C153255153, C153255153,
+ C153255153, new Color(153, 255, 204),
+
+ // Row 3
+ C204204204, new Color(102, 255, 255), new Color(102, 204, 255),
+ new Color(102, 153, 255), C102102255, C102102255,
+ C102102255, C102102255, C102102255,
+ new Color(153, 102, 255),
+ new Color(204, 102, 255),
+ new Color(255, 102, 255),
+ new Color(255, 102, 204),
+ new Color(255, 102, 153), C255102102, C255102102,
+ C255102102, C255102102, C255102102,
+ new Color(255, 153, 102),
+ new Color(255, 204, 102),
+ new Color(255, 255, 102),
+ new Color(204, 255, 102),
+ new Color(153, 255, 102), C102255102, C102255102,
+ C102255102, C102255102, C102255102,
+ new Color(102, 255, 153),
+ new Color(102, 255, 204),
+
+ // Row 4
+ new Color(153, 153, 153), new Color(51, 255, 255), new Color(51, 204, 255),
+ new Color(51, 153, 255), new Color(51, 102, 255),
+ C051051255, C051051255, C051051255,
+ new Color(102, 51, 255), new Color(153, 51, 255),
+ new Color(204, 51, 255), new Color(255, 51, 255),
+ new Color(255, 51, 204), new Color(255, 51, 153),
+ new Color(255, 51, 102), C255051051, C255051051,
+ C255051051, new Color(255, 102, 51),
+ new Color(255, 153, 51), new Color(255, 204, 51),
+ new Color(255, 255, 51), new Color(204, 255, 51),
+ new Color(153, 255, 51), new Color(102, 255, 51),
+ C051255051, C051255051, C051255051,
+ new Color(51, 255, 102), new Color(51, 255, 153),
+ new Color(51, 255, 204),
+
+ // Row 5
+ new Color(153, 153, 153), new Color(0, 255, 255), new Color(0, 204, 255),
+ new Color(0, 153, 255), new Color(0, 102, 255),
+ new Color(0, 51, 255), new Color(0, 0, 255),
+ new Color(51, 0, 255), new Color(102, 0, 255),
+ new Color(153, 0, 255), new Color(204, 0, 255),
+ new Color(255, 0, 255), new Color(255, 0, 204),
+ new Color(255, 0, 153), new Color(255, 0, 102),
+ new Color(255, 0, 51), new Color(255, 0, 0),
+ new Color(255, 51, 0), new Color(255, 102, 0),
+ new Color(255, 153, 0), new Color(255, 204, 0),
+ new Color(255, 255, 0), new Color(204, 255, 0),
+ new Color(153, 255, 0), new Color(102, 255, 0),
+ new Color(51, 255, 0), new Color(0, 255, 0),
+ new Color(0, 255, 51), new Color(0, 255, 102),
+ new Color(0, 255, 153), new Color(0, 255, 204),
+
+ // Row 6
+ new Color(102, 102, 102), C000204204, C000204204, new Color(0, 153, 204),
+ new Color(0, 102, 204), new Color(0, 51, 204),
+ new Color(0, 0, 204), new Color(51, 0, 204),
+ new Color(102, 0, 204), new Color(153, 0, 204),
+ C204000204, C204000204, C204000204,
+ new Color(204, 0, 153), new Color(204, 0, 102),
+ new Color(204, 0, 51), new Color(204, 0, 0),
+ new Color(204, 51, 0), new Color(204, 102, 0),
+ new Color(204, 153, 0), C204204000, C204204000,
+ C204204000, new Color(153, 204, 0),
+ new Color(102, 204, 0), new Color(51, 204, 0),
+ new Color(0, 204, 0), new Color(0, 204, 51),
+ new Color(0, 204, 102), new Color(0, 204, 153),
+ new Color(0, 204, 204),
+
+ // Row 7
+ new Color(102, 102, 102), C000153153, C000153153, C000153153,
+ new Color(0, 102, 153), new Color(0, 51, 153),
+ new Color(0, 0, 153), new Color(51, 0, 153),
+ new Color(102, 0, 153), C153000153, C153000153,
+ C153000153, C153000153, C153000153,
+ new Color(153, 0, 102), new Color(153, 0, 51),
+ new Color(153, 0, 0), new Color(153, 51, 0),
+ new Color(153, 102, 0), C153153000, C153153000,
+ C153153000, C153153000, C153153000,
+ new Color(102, 153, 0), new Color(51, 153, 0),
+ new Color(0, 153, 0), new Color(0, 153, 51),
+ new Color(0, 153, 102), C000153153, C000153153,
+
+ // Row 8
+ new Color(51, 51, 51), C000102102, C000102102, C000102102, C000102102,
+ new Color(0, 51, 102), new Color(0, 0, 102),
+ new Color(51, 0, 102), C102000102, C102000102,
+ C102000102, C102000102, C102000102, C102000102,
+ C102000102, new Color(102, 0, 51),
+ new Color(102, 0, 0), new Color(102, 51, 0),
+ C102102000, C102102000, C102102000, C102102000,
+ C102102000, C102102000, C102102000,
+ new Color(51, 102, 0), new Color(0, 102, 0),
+ new Color(0, 102, 51), C000102102, C000102102,
+ C000102102,
+
+ // Row 9.
+ Color.BLACK, C000051051, C000051051, C000051051, C000051051, C000051051,
+ new Color(0, 0, 51), C051000051, C051000051,
+ C051000051, C051000051, C051000051, C051000051,
+ C051000051, C051000051, C051000051,
+ new Color(51, 0, 0), C051051000, C051051000,
+ C051051000, C051051000, C051051000, C051051000,
+ C051051000, C051051000, new Color(0, 51, 0),
+ C000051051, C000051051, C000051051, C000051051,
+ new Color(51, 51, 51)
+ };
+
+ /**
+ * Creates a new MainSwatchPanel object.
+ */
+ MainSwatchPanel()
+ {
+ super();
+ numCols = 31;
+ numRows = 9;
+ initializeColors();
+ revalidate();
+ }
+
+ /**
+ * This method returns the color for the given position.
+ *
+ * @param x The x location for the position.
+ * @param y The y location for the position.
+ *
+ * @return The color for the given position.
+ */
+ public Color getColorForPosition(int x, int y)
+ {
+ if (x % (cellWidth + gap) > cellWidth
+ || y % (cellHeight + gap) > cellHeight)
+ // position is located in gap.
+ return null;
+
+ int row = y / (cellHeight + gap);
+ int col = x / (cellWidth + gap);
+ return colors[row * numCols + col];
+ }
+
+ /**
+ * This method initializes the colors for the main swatch panel.
+ */
+ protected void initializeColors()
+ {
+ // Unnecessary
+ }
+
+ /**
+ * This method paints the main graphics panel with the given Graphics
+ * object.
+ *
+ * @param graphics The Graphics object to paint with.
+ */
+ public void paint(Graphics graphics)
+ {
+ int index = 0;
+ Insets insets = getInsets();
+ int currX = insets.left;
+ int currY = insets.top;
+ Color saved = graphics.getColor();
+
+ for (int i = 0; i < numRows; i++)
+ {
+ for (int j = 0; j < numCols; j++)
+ {
+ graphics.setColor(colors[index++]);
+ graphics.fill3DRect(currX, currY, cellWidth, cellHeight, true);
+ currX += gap + cellWidth;
+ }
+ currX = insets.left;
+ currY += gap + cellHeight;
+ }
+ graphics.setColor(saved);
+ }
+
+ /**
+ * This method returns the tooltip text for the given MouseEvent.
+ *
+ * @param e The MouseEvent to find tooltip text for.
+ *
+ * @return The tooltip text.
+ */
+ public String getToolTipText(MouseEvent e)
+ {
+ Color c = getColorForPosition(e.getX(), e.getY());
+ if (c == null)
+ return null;
+ return (c.getRed() + "," + c.getGreen() + "," + c.getBlue());
+ }
+ }
+
+ /**
+ * This class is the recent swatch panel. It holds recently selected colors.
+ */
+ static class RecentSwatchPanel extends SwatchPanel
+ {
+ /** The array for storing recently stored colors. */
+ Color[] colors;
+
+ /** The default color. */
+ public static final Color defaultColor = Color.GRAY;
+
+ /** The index of the array that is the start. */
+ int start = 0;
+
+ /**
+ * Creates a new RecentSwatchPanel object.
+ */
+ RecentSwatchPanel()
+ {
+ super();
+ numCols = 5;
+ numRows = 7;
+ initializeColors();
+ revalidate();
+ }
+
+ /**
+ * This method returns the color for the given position.
+ *
+ * @param x The x coordinate of the position.
+ * @param y The y coordinate of the position.
+ *
+ * @return The color for the given position.
+ */
+ public Color getColorForPosition(int x, int y)
+ {
+ if (x % (cellWidth + gap) > cellWidth
+ || y % (cellHeight + gap) > cellHeight)
+ // position is located in gap.
+ return null;
+
+ int row = y / (cellHeight + gap);
+ int col = x / (cellWidth + gap);
+
+ return colors[getIndexForCell(row, col)];
+ }
+
+ /**
+ * This method initializes the colors for the recent swatch panel.
+ */
+ protected void initializeColors()
+ {
+ colors = new Color[numRows * numCols];
+ for (int i = 0; i < colors.length; i++)
+ colors[i] = defaultColor;
+ }
+
+ /**
+ * This method returns the array index for the given row and column.
+ *
+ * @param row The row.
+ * @param col The column.
+ *
+ * @return The array index for the given row and column.
+ */
+ private int getIndexForCell(int row, int col)
+ {
+ return ((row * numCols) + col + start) % (numRows * numCols);
+ }
+
+ /**
+ * This method adds the given color to the beginning of the swatch panel.
+ * Package-private to avoid an accessor method.
+ *
+ * @param c The color to add.
+ */
+ void addColorToQueue(Color c)
+ {
+ if (--start == -1)
+ start = numRows * numCols - 1;
+
+ colors[start] = c;
+ }
+
+ /**
+ * This method paints the panel with the given Graphics object.
+ *
+ * @param g The Graphics object to paint with.
+ */
+ public void paint(Graphics g)
+ {
+ Color saved = g.getColor();
+ Insets insets = getInsets();
+ int currX = insets.left;
+ int currY = insets.top;
+
+ for (int i = 0; i < numRows; i++)
+ {
+ for (int j = 0; j < numCols; j++)
+ {
+ g.setColor(colors[getIndexForCell(i, j)]);
+ g.fill3DRect(currX, currY, cellWidth, cellHeight, true);
+ currX += cellWidth + gap;
+ }
+ currX = insets.left;
+ currY += cellWidth + gap;
+ }
+ }
+
+ /**
+ * This method returns the tooltip text for the given MouseEvent.
+ *
+ * @param e The MouseEvent.
+ *
+ * @return The tooltip text.
+ */
+ public String getToolTipText(MouseEvent e)
+ {
+ Color c = getColorForPosition(e.getX(), e.getY());
+ if (c == null)
+ return null;
+ return c.getRed() + "," + c.getGreen() + "," + c.getBlue();
+ }
+ }
+
+ /**
+ * This class handles mouse events for the two swatch panels.
+ */
+ class MouseHandler extends MouseAdapter
+ {
+ /**
+ * This method is called whenever the mouse is pressed.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mousePressed(MouseEvent e)
+ {
+ SwatchPanel panel = (SwatchPanel) e.getSource();
+ Color c = panel.getColorForPosition(e.getX(), e.getY());
+ recentPalette.addColorToQueue(c);
+ DefaultSwatchChooserPanel.this.getColorSelectionModel().setSelectedColor(c);
+ DefaultSwatchChooserPanel.this.repaint();
+ }
+ }
+
+ /**
+ * This is the layout manager for the main panel.
+ */
+ static class MainPanelLayout implements LayoutManager
+ {
+ /**
+ * This method is called when a new component is added to the container.
+ *
+ * @param name The name of the component.
+ * @param comp The added component.
+ */
+ public void addLayoutComponent(String name, Component comp)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * This method is called to set the size and position of the child
+ * components for the given container.
+ *
+ * @param parent The container to lay out.
+ */
+ public void layoutContainer(Container parent)
+ {
+ Component[] comps = parent.getComponents();
+ Insets insets = parent.getInsets();
+ Dimension[] pref = new Dimension[comps.length];
+
+ int xpos = 0;
+ int ypos = 0;
+ int maxHeight = 0;
+ int totalWidth = 0;
+
+ for (int i = 0; i < comps.length; i++)
+ {
+ pref[i] = comps[i].getPreferredSize();
+ if (pref[i] == null)
+ return;
+ maxHeight = Math.max(maxHeight, pref[i].height);
+ totalWidth += pref[i].width;
+ }
+
+ ypos = (parent.getSize().height - maxHeight) / 2 + insets.top;
+ xpos = insets.left + (parent.getSize().width - totalWidth) / 2;
+
+ for (int i = 0; i < comps.length; i++)
+ {
+ if (pref[i] == null)
+ continue;
+ comps[i].setBounds(xpos, ypos, pref[i].width, pref[i].height);
+ xpos += pref[i].width;
+ }
+ }
+
+ /**
+ * This method is called when a component is removed from the container.
+ *
+ * @param comp The component that was removed.
+ */
+ public void removeLayoutComponent(Component comp)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * This methods calculates the minimum layout size for the container.
+ *
+ * @param parent The container.
+ *
+ * @return The minimum layout size.
+ */
+ public Dimension minimumLayoutSize(Container parent)
+ {
+ return preferredLayoutSize(parent);
+ }
+
+ /**
+ * This method returns the preferred layout size for the given container.
+ *
+ * @param parent The container.
+ *
+ * @return The preferred layout size.
+ */
+ public Dimension preferredLayoutSize(Container parent)
+ {
+ int xmax = 0;
+ int ymax = 0;
+
+ Component[] comps = parent.getComponents();
+ Dimension pref;
+
+ for (int i = 0; i < comps.length; i++)
+ {
+ pref = comps[i].getPreferredSize();
+ if (pref == null)
+ continue;
+ xmax += pref.width;
+ ymax = Math.max(ymax, pref.height);
+ }
+
+ Insets insets = parent.getInsets();
+
+ return new Dimension(insets.left + insets.right + xmax,
+ insets.top + insets.bottom + ymax);
+ }
+ }
+
+ /**
+ * This is the layout manager for the recent swatch panel.
+ */
+ static class RecentPanelLayout implements LayoutManager
+ {
+ /**
+ * This method is called when a component is added to the container.
+ *
+ * @param name The name of the component.
+ * @param comp The added component.
+ */
+ public void addLayoutComponent(String name, Component comp)
+ {
+ // Nothing needs to be done.
+ }
+
+ /**
+ * This method sets the size and position of the child components of the
+ * given container.
+ *
+ * @param parent The container to lay out.
+ */
+ public void layoutContainer(Container parent)
+ {
+ Component[] comps = parent.getComponents();
+ Dimension parentSize = parent.getSize();
+ Insets insets = parent.getInsets();
+ int currY = insets.top;
+ Dimension pref;
+
+ for (int i = 0; i < comps.length; i++)
+ {
+ pref = comps[i].getPreferredSize();
+ if (pref == null)
+ continue;
+ comps[i].setBounds(insets.left, currY, pref.width, pref.height);
+ currY += pref.height;
+ }
+ }
+
+ /**
+ * This method calculates the minimum layout size for the given container.
+ *
+ * @param parent The container.
+ *
+ * @return The minimum layout size.
+ */
+ public Dimension minimumLayoutSize(Container parent)
+ {
+ return preferredLayoutSize(parent);
+ }
+
+ /**
+ * This method calculates the preferred layout size for the given
+ * container.
+ *
+ * @param parent The container.
+ *
+ * @return The preferred layout size.
+ */
+ public Dimension preferredLayoutSize(Container parent)
+ {
+ int width = 0;
+ int height = 0;
+ Insets insets = parent.getInsets();
+ Component[] comps = parent.getComponents();
+ Dimension pref;
+ for (int i = 0; i < comps.length; i++)
+ {
+ pref = comps[i].getPreferredSize();
+ if (pref != null)
+ {
+ width = Math.max(width, pref.width);
+ height += pref.height;
+ }
+ }
+
+ return new Dimension(width + insets.left + insets.right,
+ height + insets.top + insets.bottom);
+ }
+
+ /**
+ * This method is called whenever a component is removed from the
+ * container.
+ *
+ * @param comp The removed component.
+ */
+ public void removeLayoutComponent(Component comp)
+ {
+ // Nothing needs to be done.
+ }
+ }
+
+ /**
+ * Creates a new DefaultSwatchChooserPanel object.
+ */
+ DefaultSwatchChooserPanel()
+ {
+ super();
+ }
+
+ /**
+ * This method updates the chooser panel with the new value from the
+ * JColorChooser.
+ */
+ public void updateChooser()
+ {
+ // Nothing to do here yet.
+ }
+
+ /**
+ * This method builds the chooser panel.
+ */
+ protected void buildChooser()
+ {
+ // The structure of the swatch panel is:
+ // One large panel (minus the insets).
+ // Inside that panel, there are two panels, one holds the palette.
+ // The other holds the label and the recent colors palette.
+ // The two palettes are two custom swatch panels.
+ setLayout(new MainPanelLayout());
+
+ JPanel mainPaletteHolder = new JPanel();
+ JPanel recentPaletteHolder = new JPanel();
+
+ mainPalette = new MainSwatchPanel();
+ recentPalette = new RecentSwatchPanel();
+ JLabel label = new JLabel("Recent:");
+
+ mouseHandler = new MouseHandler();
+ mainPalette.addMouseListener(mouseHandler);
+ recentPalette.addMouseListener(mouseHandler);
+
+ mainPaletteHolder.setLayout(new BorderLayout());
+ mainPaletteHolder.add(mainPalette, BorderLayout.CENTER);
+
+ recentPaletteHolder.setLayout(new RecentPanelLayout());
+ recentPaletteHolder.add(label);
+ recentPaletteHolder.add(recentPalette);
+
+ JPanel main = new JPanel();
+ main.add(mainPaletteHolder);
+ main.add(recentPaletteHolder);
+
+ this.add(main);
+ }
+
+ /**
+ * This method removes the chooser panel from the JColorChooser.
+ *
+ * @param chooser The JColorChooser this panel is being removed from.
+ */
+ public void uninstallChooserPanel(JColorChooser chooser)
+ {
+ recentPalette = null;
+ mainPalette = null;
+
+ removeAll();
+ super.uninstallChooserPanel(chooser);
+ }
+
+ /**
+ * This method returns the JTabbedPane displayed name.
+ *
+ * @return The name displayed in the JTabbedPane.
+ */
+ public String getDisplayName()
+ {
+ return "Swatches";
+ }
+
+ /**
+ * This method returns the small display icon.
+ *
+ * @return The small display icon.
+ */
+ public Icon getSmallDisplayIcon()
+ {
+ return null;
+ }
+
+ /**
+ * This method returns the large display icon.
+ *
+ * @return The large display icon.
+ */
+ public Icon getLargeDisplayIcon()
+ {
+ return null;
+ }
+
+ /**
+ * This method paints the chooser panel with the given Graphics object.
+ *
+ * @param g The Graphics object to paint with.
+ */
+ public void paint(Graphics g)
+ {
+ super.paint(g);
+ }
+
+ /**
+ * This method returns the tooltip text for the given MouseEvent.
+ *
+ * @param e The MouseEvent.
+ *
+ * @return The tooltip text.
+ */
+ public String getToolTipText(MouseEvent e)
+ {
+ return null;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/colorchooser/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,47 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in javax.swing.event package.
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. -->
+
+<html>
+<head><title>GNU Classpath - javax.swing.colorchooser</title></head>
+
+<body>
+<p>Provides support classes for the {@link javax.swing.JColorChooser}
+component.</p>
+
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/AncestorEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/AncestorEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/AncestorEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/AncestorEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,100 @@
+/* AncestorEvent.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.event;
+
+import java.awt.AWTEvent;
+import java.awt.Container;
+
+import javax.swing.JComponent;
+
+/**
+ * @author Andrew Selkirk
+ * @author Ronald Veldema
+ */
+public class AncestorEvent extends AWTEvent
+{
+ private static final long serialVersionUID = -8079801679695605002L;
+
+ public static final int ANCESTOR_ADDED = 1;
+ public static final int ANCESTOR_REMOVED = 2;
+ public static final int ANCESTOR_MOVED = 3;
+
+ private JComponent sourceComponent;
+ private Container ancestor;
+ private Container ancestorParent;
+
+ /**
+ * @param source Source component
+ * @param id ID
+ * @param ancestor ancestor
+ * @param ancestorParent parent ancestor
+ */
+ public AncestorEvent(JComponent source, int id, Container ancestor,
+ Container ancestorParent)
+ {
+ super(source, id);
+ this.sourceComponent = source;
+ this.ancestor = ancestor;
+ this.ancestorParent = ancestorParent;
+ }
+
+ /**
+ * Returns the ancestor of this event.
+ */
+ public Container getAncestor()
+ {
+ return ancestor;
+ }
+
+ /**
+ * Returns the ancester parent of this event.
+ */
+ public Container getAncestorParent()
+ {
+ return ancestorParent;
+ }
+
+ /**
+ * Returns the source of this event.
+ */
+ public JComponent getComponent()
+ {
+ return sourceComponent;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/AncestorListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/AncestorListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/AncestorListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/AncestorListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,69 @@
+/* AncestorListener.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+// Imports
+import java.util.EventListener;
+
+/**
+ * AncestorListener Interface
+ * @author Andrew Selkirk
+ * @author Ronald Veldema
+ */
+public interface AncestorListener extends EventListener {
+
+ /**
+ * Ancestor Added
+ * @param event Ancestor Event
+ */
+ void ancestorAdded(AncestorEvent event);
+
+ /**
+ * Ancestor Removed
+ * @param event Ancestor Event
+ */
+ void ancestorRemoved(AncestorEvent event);
+
+ /**
+ * Ancestor Moved
+ * @param event Ancestor Event
+ */
+ void ancestorMoved(AncestorEvent event);
+
+
+} // AncestorListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/CaretEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/CaretEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/CaretEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/CaretEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,70 @@
+/* CaretEvent.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+import java.util.EventObject;
+
+/**
+ * CaretEvent
+ * @author Andrew Selkirk
+ */
+public abstract class CaretEvent extends EventObject
+{
+
+ /**
+ * CaretEvent constructor
+ * @param source Source object
+ */
+ public CaretEvent(Object source)
+ {
+ super(source);
+ }
+
+ /**
+ * Get caret location
+ * @return the dot
+ */
+ public abstract int getDot();
+
+ /**
+ * Get mark
+ * @return the mark
+ */
+ public abstract int getMark();
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/CaretListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/CaretListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/CaretListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/CaretListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,56 @@
+/* CaretListener.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+// Imports
+import java.util.EventListener;
+
+/**
+ * CaretListener public interface
+ * @author Andrew Selkirk
+ */
+public interface CaretListener extends EventListener {
+
+ /**
+ * Caret position has been updated
+ * @param event Caret Event
+ */
+ void caretUpdate(CaretEvent event);
+
+
+} // CaretListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/CellEditorListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/CellEditorListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/CellEditorListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/CellEditorListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,62 @@
+/* CellEditorListener.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+// Imports
+import java.util.EventListener;
+
+/**
+ * CellEditorListener public interface
+ * @author Andrew Selkirk
+ */
+public interface CellEditorListener extends EventListener {
+
+ /**
+ * Editing has been canceled
+ * @param event Change Event
+ */
+ void editingCanceled(ChangeEvent event);
+
+ /**
+ * Editing has been stopped
+ * @param event Change Event
+ */
+ void editingStopped(ChangeEvent event);
+
+
+} // CellEditorListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ChangeEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ChangeEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ChangeEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ChangeEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,66 @@
+/* ChangeEvent.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+import java.util.EventObject;
+
+/**
+ * An event used to signal a state change for an object.
+ *
+ * @see ChangeListener
+ * @see CellEditorListener
+ * @see TableColumnModelListener
+ *
+ * @author Andrew Selkirk
+ * @author Ronald Veldema
+ */
+public class ChangeEvent
+ extends EventObject
+{
+
+ /**
+ * Creates a new <code>ChangeEvent</code> instance for the specified source.
+ *
+ * @param source the source for the event (<code>null</code> not permitted).
+ */
+ public ChangeEvent(Object source)
+ {
+ super(source);
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ChangeListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ChangeListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ChangeListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ChangeListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,63 @@
+/* ChangeListener.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+import java.util.EventListener;
+
+/**
+ * A <code>ChangeListener</code> can register with an object to receive
+ * notification of state changes (for objects that support this mechanism).
+ *
+ * @author Andrew Selkirk
+ * @author Ronald Veldema
+ */
+public interface ChangeListener
+ extends EventListener
+{
+
+ /**
+ * Called by an object to notify the listener that the object's state has
+ * changed. The incoming <code>event</code> identifies the
+ * <code>source</code> of the event, allowing the listener to differentiate
+ * when it is listening for changes in multiple sources.
+ *
+ * @param event the change event.
+ */
+ void stateChanged(ChangeEvent event);
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/DocumentEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/DocumentEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/DocumentEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/DocumentEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,156 @@
+/* DocumentEvent.java --
+ Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+import javax.swing.text.Document;
+import javax.swing.text.Element;
+
+/**
+ * DocumentEvent public interface
+ * @author Andrew Selkirk
+ * @author Ronald Veldema
+ */
+public interface DocumentEvent
+{
+ /**
+ * ElementChange public interface
+ */
+ public static interface ElementChange
+ {
+ /**
+ * getIndex
+ * @return int
+ */
+ int getIndex();
+
+ /**
+ * getElement
+ * @return Element
+ */
+ Element getElement();
+
+ /**
+ * getChildrenRemoved
+ * @return Element[]
+ */
+ Element[] getChildrenRemoved();
+
+ /**
+ * getChildrenAdded
+ * @return Element[]
+ */
+ Element[] getChildrenAdded();
+
+ }
+
+ /**
+ * EventType
+ */
+ final class EventType
+ {
+ /**
+ * INSERT
+ */
+ public static final EventType INSERT = new EventType("INSERT"); // TODO
+
+ /**
+ * REMOVE
+ */
+ public static final EventType REMOVE = new EventType("REMOVE"); // TODO
+
+ /**
+ * CHANGE
+ */
+ public static final EventType CHANGE = new EventType("CHANGE"); // TODO
+
+ /**
+ * typeString
+ */
+ private String type;
+
+ /**
+ * Constructor EventType
+ * @param type TODO
+ */
+ private EventType(String type)
+ {
+ this.type = type;
+ }
+
+ /**
+ * toString
+ * @return String
+ */
+ public String toString()
+ {
+ return type;
+ }
+ }
+
+ /**
+ * getType
+ * @return EventType
+ */
+ EventType getType();
+
+ /**
+ * getOffset
+ * @return int
+ */
+ int getOffset();
+
+ /**
+ * getLength
+ * @return int
+ */
+ int getLength();
+
+ /**
+ * getDocument
+ * @return Document
+ */
+ Document getDocument();
+
+ /**
+ * getChange
+ * @param element TODO
+ * @return ElementChange
+ */
+ ElementChange getChange(Element element);
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/DocumentListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/DocumentListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/DocumentListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/DocumentListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,68 @@
+/* DocumentListener.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+import java.util.EventListener;
+
+/**
+ * DocumentListener public interface
+ * @author Andrew Selkirk
+ * @author Ronald Veldema
+ */
+public interface DocumentListener extends EventListener {
+
+ /**
+ * Changed update
+ * @param event Document Event
+ */
+ void changedUpdate(DocumentEvent event);
+
+ /**
+ * Insert update
+ * @param event Document Event
+ */
+ void insertUpdate(DocumentEvent event);
+
+ /**
+ * Remove update
+ * @param event Document Event
+ */
+ void removeUpdate(DocumentEvent event);
+
+
+} // DocumentListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/EventListenerList.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/EventListenerList.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/EventListenerList.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/EventListenerList.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,307 @@
+/* EventListenerList.java --
+ Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+import java.io.Serializable;
+import java.lang.reflect.Array;
+import java.util.EventListener;
+
+
+/**
+ * A utility class for keeping track of {@link EventListener}s.
+ *
+ * <p><b>Example for using this class:</b>
+ *
+ * <blockquote><pre> import java.util.EventListener;
+ * import javax.swing.event.EventListenerList;
+ *
+ * class Foo
+ * {
+ * protected final EventListenerList listeners = new EventListenerList();
+ * protected BarClosedEvent barClosedEvent = null;
+ *
+ * public void addBarListener(BarListener l)
+ * {
+ * listeners.<a href="#add(java.lang.Class, java.util.EventListener)"
+ * >add</a>(BarListener.class, l);
+ * }
+ *
+ * public void removeBarListener(BarListener l)
+ * {
+ * listeners.<a href="#remove(java.lang.Class, java.util.EventListener)"
+ * >remove</a>(BarListener.class, l);
+ * }
+ *
+ * protected void fireBarClosedEvent()
+ * {
+ * Object[] l = listeners.<a href="#getListenerList()"
+ * >getListenerList()</a>;
+ *
+ * for (int i = l.length - 2; i >= 0; i -= 2)
+ * if (l[i] == BarListener.class)
+ * {
+ * // Create the event on demand, when it is needed the first time.
+ * if (barClosedEvent == null)
+ * barClosedEvent = new BarClosedEvent(this);
+ *
+ * ((BarClosedListener) l[i + 1]).barClosed(barClosedEvent);
+ * }
+ * }
+ * }</pre></blockquote>
+ *
+ * @author Andrew Selkirk (aselkirk at sympatico.ca)
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class EventListenerList
+ implements Serializable
+{
+ /**
+ * An ID for serializing instances of this class; verified with the
+ * serialver tool of Sun J2SE 1.4.1_01.
+ */
+ static final long serialVersionUID = -5677132037850737084L;
+
+
+ /**
+ * An empty array that is shared by all instances of this class that
+ * have no listeners.
+ */
+ private static final Object[] NO_LISTENERS = new Object[0];
+
+
+ /**
+ * An array with all currently registered listeners. The array has
+ * twice as many elements as there are listeners. For an even
+ * integer <code>i</code>, <code>listenerList[i]</code> indicates
+ * the registered class, and <code>listenerList[i + 1]</code> is the
+ * listener.
+ */
+ protected transient Object[] listenerList = NO_LISTENERS;
+
+
+ /**
+ * EventListenerList constructor
+ */
+ public EventListenerList()
+ {
+ // Nothing to do here.
+ }
+
+
+ /**
+ * Registers a listener of a specific type.
+ *
+ * @param t the type of the listener.
+ *
+ * @param listener the listener to add, which must be an instance of
+ * <code>t</code>, or of a subclass of <code>t</code>.
+ *
+ * @throws IllegalArgumentException if <code>listener</code> is not
+ * an instance of <code>t</code> (or a subclass thereof).
+ *
+ * @throws NullPointerException if <code>t</code> is <code>null</code>.
+ */
+ public void add(Class t, EventListener listener)
+ {
+ int oldLength;
+ Object[] newList;
+
+ if (listener == null)
+ return;
+
+ if (!t.isInstance(listener))
+ throw new IllegalArgumentException();
+
+ oldLength = listenerList.length;
+ newList = new Object[oldLength + 2];
+ if (oldLength > 0)
+ System.arraycopy(listenerList, 0, newList, 0, oldLength);
+
+ newList[oldLength] = t;
+ newList[oldLength + 1] = listener;
+ listenerList = newList;
+ }
+
+
+ /**
+ * Determines the number of listeners.
+ */
+ public int getListenerCount()
+ {
+ return listenerList.length / 2;
+ }
+
+
+ /**
+ * Determines the number of listeners of a particular class.
+ *
+ * @param t the type of listeners to be counted. In order to get
+ * counted, a subscribed listener must be exactly of class
+ * <code>t</code>. Thus, subclasses of <code>t</code> will not be
+ * counted.
+ */
+ public int getListenerCount(Class t)
+ {
+ int result = 0;
+ for (int i = 0; i < listenerList.length; i += 2)
+ if (t == listenerList[i])
+ ++result;
+
+ return result;
+ }
+
+
+ /**
+ * Returns an array containing a sequence of listenerType/listener pairs, one
+ * for each listener.
+ *
+ * @return An array containing the listener types and references.
+ */
+ public Object[] getListenerList()
+ {
+ // returning the internal storage is a bad idea, but tests show that the
+ // reference implementation does this...
+ return listenerList;
+ }
+
+
+ /**
+ * Retrieves the currently subscribed listeners of a particular
+ * type. For a listener to be returned, it must have been
+ * registered with exactly the type <code>c</code>; subclasses are
+ * not considered equal.
+ *
+ * <p>The returned array can always be cast to <code>c[]</code>.
+ * Since it is a newly allocated copy, the caller may arbitrarily
+ * modify the array.
+ *
+ * @param c the class which was passed to {@link #add}.
+ *
+ * @throws ClassCastException if <code>c</code> does not implement
+ * the {@link EventListener} interface.
+ *
+ * @throws NullPointerException if <code>c</code> is
+ * <code>null</code>.
+ *
+ * @return an array of <code>c</code> whose elements are the
+ * currently subscribed listeners of the specified type. If there
+ * are no such listeners, an empty array is returned.
+ *
+ * @since 1.3
+ */
+ public EventListener[] getListeners(Class c)
+ {
+ int count, f;
+ EventListener[] result;
+
+ count = getListenerCount(c);
+ result = (EventListener[]) Array.newInstance(c, count);
+ f = 0;
+ for (int i = listenerList.length - 2; i >= 0; i -= 2)
+ if (listenerList[i] == c)
+ result[f++] = (EventListener) listenerList[i + 1];
+
+ return result;
+ }
+
+
+ /**
+ * Removes a listener of a specific type.
+ *
+ * @param t the type of the listener.
+ *
+ * @param listener the listener to remove, which must be an instance
+ * of <code>t</code>, or of a subclass of <code>t</code>.
+ *
+ * @throws IllegalArgumentException if <code>listener</code> is not
+ * an instance of <code>t</code> (or a subclass thereof).
+ *
+ * @throws NullPointerException if <code>t</code> is <code>null</code>.
+ */
+ public void remove(Class t, EventListener listener)
+ {
+ Object[] oldList, newList;
+ int oldLength;
+
+ if (listener == null)
+ return;
+
+ if (!t.isInstance(listener))
+ throw new IllegalArgumentException();
+
+ oldList = listenerList;
+ oldLength = oldList.length;
+ for (int i = 0; i < oldLength; i += 2)
+ if (oldList[i] == t && oldList[i + 1] == listener)
+ {
+ if (oldLength == 2)
+ newList = NO_LISTENERS;
+ else
+ {
+ newList = new Object[oldLength - 2];
+ if (i > 0)
+ System.arraycopy(oldList, 0, newList, 0, i);
+ if (i < oldLength - 2)
+ System.arraycopy(oldList, i + 2, newList, i,
+ oldLength - 2 - i);
+ }
+ listenerList = newList;
+ return;
+ }
+ }
+
+
+ /**
+ * Returns a string representation of this object that may be useful
+ * for debugging purposes.
+ */
+ public String toString()
+ {
+ StringBuffer buf = new StringBuffer("EventListenerList: ");
+ buf.append(listenerList.length / 2);
+ buf.append(" listeners: ");
+ for (int i = 0; i < listenerList.length; i += 2)
+ {
+ buf.append(" type ");
+ buf.append(((Class) listenerList[i]).getName());
+ buf.append(" listener ");
+ buf.append(listenerList[i + 1]);
+ }
+ return buf.toString();
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/HyperlinkEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/HyperlinkEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/HyperlinkEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/HyperlinkEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,162 @@
+/* HyperlinkEvent.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.event;
+
+import java.net.URL;
+import java.util.EventObject;
+
+import javax.swing.text.Element;
+
+/**
+ * @author Andrew Selkirk
+ * @author Ronald Veldema
+ */
+public class HyperlinkEvent extends EventObject
+{
+ public static final class EventType
+ {
+ public static final EventType ENTERED = new EventType("ENTERED"); // TODO
+ public static final EventType EXITED = new EventType("EXITED"); // TODO
+ public static final EventType ACTIVATED = new EventType("ACTIVATED"); // TODO
+
+ private String type;
+
+ /**
+ * Creates a new Event type.
+ *
+ * @param type String representing the event type.
+ */
+ private EventType(String type)
+ {
+ this.type = type;
+ }
+
+ /**
+ * Returns a <code>String</code> of this object.
+ */
+ public String toString()
+ {
+ return type;
+ }
+ }
+
+ private static final long serialVersionUID = -2054640811732867012L;
+
+ private EventType type;
+ private URL url;
+ private String description;
+ private Element element;
+
+ /**
+ * Creates a new <code>HyperlinkEvent</code> with the given arguments.
+ *
+ * @param source The object this link is associated to.
+ * @param type The type of event.
+ * @param url The URL this link pointing too.
+ */
+ public HyperlinkEvent(Object source, EventType type, URL url)
+ {
+ this (source, type, url, null, null);
+ }
+
+ /**
+ * Creates a new <code>HyperlinkEvent</code> with the given arguments.
+ *
+ * @param source The object this link is associated to.
+ * @param type The type of event.
+ * @param url The URL this link pointing too.
+ * @param description The description for this link.
+ */
+ public HyperlinkEvent(Object source, EventType type, URL url,
+ String description)
+ {
+ this (source, type, url, description, null);
+ }
+
+ /**
+ * Creates a new <code>HyperlinkEvent</code> with the given arguments.
+ *
+ * @param source The object this link is associated to.
+ * @param type The type of event.
+ * @param url The URL this link pointing too.
+ * @param description The description for this link.
+ * @param element The element in the document representing the anchor.
+ */
+ public HyperlinkEvent(Object source, EventType type, URL url,
+ String description, Element element)
+ {
+ super(source);
+ this.type = type;
+ this.url = url;
+ this.description = description;
+ this.element = element;
+ }
+
+ /**
+ * Returns the element of the document repesenting this anchor.
+ */
+ public Element getSourceElement()
+ {
+ return element;
+ }
+
+ /**
+ * Returns the URL of this event.
+ */
+ public URL getURL()
+ {
+ return url;
+ }
+
+ /**
+ * Returns the type of this event.
+ */
+ public EventType getEventType()
+ {
+ return type;
+ }
+
+ /**
+ * Returns the description of this event.
+ */
+ public String getDescription()
+ {
+ return description;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/HyperlinkListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/HyperlinkListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/HyperlinkListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/HyperlinkListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,57 @@
+/* HyperlinkListener.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+// Imports
+import java.util.EventListener;
+
+/**
+ * HyperlinkListener
+ * @author Andrew Selkirk
+ * @author Ronald Veldema
+ */
+public interface HyperlinkListener extends EventListener {
+
+ /**
+ * Hyperlink updated
+ * @param event Hyperlink Event
+ */
+ void hyperlinkUpdate(HyperlinkEvent event);
+
+
+} // HyperlinkListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/InternalFrameAdapter.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/InternalFrameAdapter.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/InternalFrameAdapter.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/InternalFrameAdapter.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,126 @@
+/* InternalFrameAdapter.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.event;
+
+/**
+ * InternalFrameAdapter.
+ *
+ * @author Andrew Selkirk
+ */
+public abstract class InternalFrameAdapter implements InternalFrameListener
+{
+ /**
+ * InternalFrameAdapter constructor.
+ */
+ public InternalFrameAdapter()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Internal frame activated.
+ *
+ * @param event internal frame event
+ */
+ public void internalFrameActivated(InternalFrameEvent event)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Internal frame closed.
+ *
+ * @param event internal frame event
+ */
+ public void internalFrameClosed(InternalFrameEvent event)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Internal frame closing.
+ *
+ * @param event internal frame event
+ */
+ public void internalFrameClosing(InternalFrameEvent event)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Internal frame deactivated.
+ *
+ * @param event internal frame event
+ */
+ public void internalFrameDeactivated(InternalFrameEvent event)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Internal frame deiconified.
+ *
+ * @param event internal frame event
+ */
+ public void internalFrameDeiconified(InternalFrameEvent event)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Internal frame iconified.
+ *
+ * @param event internal frame event
+ */
+ public void internalFrameIconified(InternalFrameEvent event)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Internal frame opened.
+ *
+ * @param event internal frame event
+ */
+ public void internalFrameOpened(InternalFrameEvent event)
+ {
+ // Nothing to do here.
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/InternalFrameEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/InternalFrameEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/InternalFrameEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/InternalFrameEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,154 @@
+/* InternalFrameEvent.java --
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.event;
+
+import java.awt.AWTEvent;
+
+import javax.swing.JInternalFrame;
+
+/**
+ * An event that indicates a change to a {@link JInternalFrame} component.
+ *
+ * @author Andrew Selkirk
+ */
+public class InternalFrameEvent extends AWTEvent
+{
+ private static final long serialVersionUID = -5204823611874873183L;
+
+ /**
+ * Internal frame activated event.
+ */
+ public static final int INTERNAL_FRAME_ACTIVATED = 25554;
+
+ /**
+ * Internal frame closed event.
+ */
+ public static final int INTERNAL_FRAME_CLOSED = 25551;
+
+ /**
+ * Internal frame closing event.
+ */
+ public static final int INTERNAL_FRAME_CLOSING = 25550;
+
+ /**
+ * Internal frame deactivated event.
+ */
+ public static final int INTERNAL_FRAME_DEACTIVATED = 25555;
+
+ /**
+ * Internal frame deiconifed event.
+ */
+ public static final int INTERNAL_FRAME_DEICONIFIED = 25553;
+
+ /**
+ * Internal frame frame first event.
+ */
+ public static final int INTERNAL_FRAME_FIRST = 25549;
+
+ /**
+ * Internal frame iconified event.
+ */
+ public static final int INTERNAL_FRAME_ICONIFIED = 25552;
+
+ /**
+ * Internal frame last event.
+ */
+ public static final int INTERNAL_FRAME_LAST = 25555;
+
+ /**
+ * Internal frame opened event.
+ */
+ public static final int INTERNAL_FRAME_OPENED = 25549;
+
+ /**
+ * Creates a new <code>JInternalFrameEvent</code> instance.
+ *
+ * @param source the source of this event (<code>null</code> not permitted).
+ * @param id the event ID of this event (see the constants defined by this
+ * class).
+ *
+ * @throws IllegalArgumentException if <code>source</code> is
+ * <code>null</code>.
+ */
+ public InternalFrameEvent(JInternalFrame source, int id)
+ {
+ super(source, id);
+ }
+
+ /**
+ * Returns the <code>JInternalFrame</code> component that is the source for
+ * this event.
+ *
+ * @return The source.
+ *
+ * @since 1.3
+ */
+ public JInternalFrame getInternalFrame()
+ {
+ return (JInternalFrame) source;
+ }
+
+ /**
+ * Returns a string that indicates the event id. This is used by the
+ * {@link #toString()} method.
+ *
+ * @return A string that indicates the event id.
+ */
+ public String paramString()
+ {
+ switch (id) {
+ case INTERNAL_FRAME_ACTIVATED:
+ return "INTERNAL_FRAME_ACTIVATED";
+ case INTERNAL_FRAME_CLOSED:
+ return "INTERNAL_FRAME_CLOSED";
+ case INTERNAL_FRAME_CLOSING:
+ return "INTERNAL_FRAME_CLOSING";
+ case INTERNAL_FRAME_DEACTIVATED:
+ return "INTERNAL_FRAME_DEACTIVATED";
+ case INTERNAL_FRAME_DEICONIFIED:
+ return "INTERNAL_FRAME_DEICONIFIED";
+ case INTERNAL_FRAME_ICONIFIED:
+ return "INTERNAL_FRAME_ICONIFIED";
+ case INTERNAL_FRAME_OPENED:
+ return "INTERNAL_FRAME_OPENED";
+ default:
+ return "unknown type";
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/InternalFrameListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/InternalFrameListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/InternalFrameListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/InternalFrameListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,92 @@
+/* InternalFrameListener.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+// Imports
+import java.util.EventListener;
+
+/**
+ * InternalFrameListener public interface
+ * @author Andrew Selkirk
+ */
+public interface InternalFrameListener extends EventListener {
+
+ /**
+ * Internal frame activated
+ * @param event Internal Frame Event
+ */
+ void internalFrameActivated(InternalFrameEvent event);
+
+ /**
+ * Internal frame closed
+ * @param event Internal Frame Event
+ */
+ void internalFrameClosed(InternalFrameEvent event);
+
+ /**
+ * Internal frame closing
+ * @param event Internal Frame Event
+ */
+ void internalFrameClosing(InternalFrameEvent event);
+
+ /**
+ * Internal frame deactivated
+ * @param event Internal Frame Event
+ */
+ void internalFrameDeactivated(InternalFrameEvent event);
+
+ /**
+ * Internal frame deiconified
+ * @param event Internal Frame Event
+ */
+ void internalFrameDeiconified(InternalFrameEvent event);
+
+ /**
+ * Internal frame iconified
+ * @param event Internal Frame Event
+ */
+ void internalFrameIconified(InternalFrameEvent event);
+
+ /**
+ * Internal frame opened
+ * @param event Internal Frame Event
+ */
+ void internalFrameOpened(InternalFrameEvent event);
+
+
+} // InternalFrameListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ListDataEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ListDataEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ListDataEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ListDataEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,132 @@
+/* ListDataEvent.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.event;
+
+import java.util.EventObject;
+
+/**
+ * An event that contains information about a modification to the content of
+ * a list.
+ *
+ * @author Andrew Selkirk
+ * @author Ronald Veldema
+ */
+public class ListDataEvent extends EventObject
+{
+ private static final long serialVersionUID = 2510353260071004774L;
+
+ /** An event type indicating that the list content has been modified. */
+ public static final int CONTENTS_CHANGED = 0;
+
+ /** An event type indicating that an interval has been added to the list. */
+ public static final int INTERVAL_ADDED = 1;
+
+ /**
+ * An event type indicating that an interval has been removed from the
+ * list.
+ */
+ public static final int INTERVAL_REMOVED = 2;
+
+ private int type;
+ private int index0;
+ private int index1;
+
+ /**
+ * Creates a <code>ListDataEvent</code> object.
+ *
+ * @param source the source of the event (<code>null</code> not permitted).
+ * @param type the type of the event (should be one of
+ * {@link #CONTENTS_CHANGED}, {@link #INTERVAL_ADDED} or
+ * {@link #INTERVAL_REMOVED}, although this is not enforced).
+ * @param index0 the index for one end of the modified range of list
+ * elements.
+ * @param index1 the index for the other end of the modified range of list
+ * elements.
+ */
+ public ListDataEvent(Object source, int type, int index0, int index1)
+ {
+ super(source);
+ this.type = type;
+ this.index0 = Math.min(index0, index1);
+ this.index1 = Math.max(index0, index1);
+ }
+
+ /**
+ * Returns the index of the first item in the range of modified list items.
+ *
+ * @return The index of the first item in the range of modified list items.
+ */
+ public int getIndex0()
+ {
+ return index0;
+ }
+
+ /**
+ * Returns the index of the last item in the range of modified list items.
+ *
+ * @return The index of the last item in the range of modified list items.
+ */
+ public int getIndex1()
+ {
+ return index1;
+ }
+
+ /**
+ * Returns a code representing the type of this event, which is usually one
+ * of {@link #CONTENTS_CHANGED}, {@link #INTERVAL_ADDED} or
+ * {@link #INTERVAL_REMOVED}.
+ *
+ * @return The event type.
+ */
+ public int getType()
+ {
+ return type;
+ }
+
+ /**
+ * Returns a string representing the state of this event.
+ *
+ * @return A string.
+ */
+ public String toString()
+ {
+ return getClass().getName() + "[type=" + type + ",index0=" + index0
+ + ",index1=" + index1 + "]";
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ListDataListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ListDataListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ListDataListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ListDataListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,82 @@
+/* ListDataListener.java --
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+import java.util.EventListener;
+
+import javax.swing.ListModel;
+
+/**
+ * A <code>ListDataListener</code> can register with a {@link ListModel} and
+ * receive notification of updates to the model.
+ *
+ * @author Andrew Selkirk
+ * @author Ronald Veldema
+ */
+public interface ListDataListener extends EventListener
+{
+
+ /**
+ * Notifies the listener that the contents of the list have changed
+ * in some way. This method will be called if the change cannot be
+ * notified via the {@link #intervalAdded(ListDataEvent)} or the
+ * {@link #intervalRemoved(ListDataEvent)} methods.
+ *
+ * @param event the event.
+ */
+ void contentsChanged(ListDataEvent event);
+
+ /**
+ * Notifies the listener that one or more items have been added to the
+ * list. The <code>event</code> argument can supply the indices for the
+ * range of items added.
+ *
+ * @param event the event.
+ */
+ void intervalAdded(ListDataEvent event);
+
+ /**
+ * Notifies the listener that one or more items have been removed from
+ * the list. The <code>event</code> argument can supply the indices for
+ * the range of items removed.
+ *
+ * @param event the event.
+ */
+ void intervalRemoved(ListDataEvent event);
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ListSelectionEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ListSelectionEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ListSelectionEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ListSelectionEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,135 @@
+/* ListSelectionEvent.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+import java.util.EventObject;
+
+import javax.swing.ListSelectionModel;
+
+/**
+ * An event that indicates a change to a list selection, including the source
+ * of the change (a {@link ListSelectionModel}) and the range of items in the
+ * list that have potentially changed their selection status.
+ *
+ * @author Andrew Selkirk
+ * @author Ronald Veldema
+ */
+public class ListSelectionEvent extends EventObject
+{
+
+ /**
+ * The index of the first list item in the range of items that has
+ * potentially had its selection status modified.
+ */
+ private int firstIndex = 0;
+
+ /**
+ * The index of the last list item in the range of items that has
+ * potentially had its selection status modified.
+ */
+ private int lastIndex = 0;
+
+ /** A flag that indicates that this event is one in a series of events. */
+ private boolean isAdjusting = false;
+
+ /**
+ * Creates a new <code>ListSelectionEvent</code>.
+ *
+ * @param source the event source (<code>null</code> not permitted).
+ * @param firstIndex the first index.
+ * @param lastIndex the last index.
+ * @param isAdjusting a flag indicating that this event is one in a series
+ * of events updating a selection.
+ *
+ * @throws IllegalArgumentException if <code>source</code> is
+ * <code>null</code>.
+ */
+ public ListSelectionEvent(Object source, int firstIndex,
+ int lastIndex, boolean isAdjusting)
+ {
+ super(source);
+ this.firstIndex = firstIndex;
+ this.lastIndex = lastIndex;
+ this.isAdjusting = isAdjusting;
+ }
+
+ /**
+ * Returns the first index.
+ *
+ * @return The first index.
+ */
+ public int getFirstIndex()
+ {
+ return firstIndex;
+ }
+
+ /**
+ * Returns the last index.
+ *
+ * @return The last index.
+ */
+ public int getLastIndex()
+ {
+ return lastIndex;
+ }
+
+ /**
+ * Returns the flag that indicates that this event is one in a series of
+ * events updating a selection.
+ *
+ * @return A boolean.
+ */
+ public boolean getValueIsAdjusting()
+ {
+ return isAdjusting;
+ }
+
+ /**
+ * Returns a string representation of the event, typically used for debugging
+ * purposes.
+ *
+ * @return A string representation of the event.
+ */
+ public String toString()
+ {
+ return this.getClass().toString() + "[ source=" + source.toString()
+ + " firstIndex= " + firstIndex + " lastIndex= " + lastIndex
+ + " isAdjusting= " + isAdjusting + " ]";
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ListSelectionListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ListSelectionListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ListSelectionListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/ListSelectionListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,61 @@
+/* ListSelectionListener.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+import java.util.EventListener;
+
+import javax.swing.ListSelectionModel;
+
+/**
+ * A listener that receives {@link ListSelectionEvent} notifications,
+ * typically from a {@link ListSelectionModel} when it is modified.
+ *
+ * @author Andrew Selkirk
+ * @author Ronald Veldema
+ */
+public interface ListSelectionListener extends EventListener
+{
+
+ /**
+ * Receives notification of a {@link ListSelectionEvent}.
+ *
+ * @param event the event.
+ */
+ void valueChanged(ListSelectionEvent event);
+
+}
\ No newline at end of file
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuDragMouseEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuDragMouseEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuDragMouseEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuDragMouseEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,104 @@
+/* MenuDragMouseEvent.java --
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.event;
+
+import java.awt.Component;
+import java.awt.event.MouseEvent;
+
+import javax.swing.MenuElement;
+import javax.swing.MenuSelectionManager;
+
+/**
+ * MenuDragMouseEvent
+ * @author Andrew Selkirk
+ */
+public class MenuDragMouseEvent extends MouseEvent
+{
+
+ /**
+ * path
+ */
+ private MenuElement[] path = null;
+
+ /**
+ * manager
+ */
+ private MenuSelectionManager manager = null;
+
+ /**
+ * Constructor MenuDragMouseEvent
+ * @param source Source
+ * @param id MouseEvent type
+ * @param when Time
+ * @param modifiers Key modifiers
+ * @param x Horizontal position
+ * @param y Vertical position
+ * @param clickCount Click count
+ * @param popupTrigger Popup trigger?
+ * @param path Path
+ * @param manager MenuSelectionManager
+ */
+ public MenuDragMouseEvent(Component source, int id, long when, int modifiers,
+ int x, int y, int clickCount, boolean popupTrigger,
+ MenuElement[] path, MenuSelectionManager manager)
+ {
+ super(source, id, when, modifiers, x, y, clickCount, popupTrigger);
+ this.path = path;
+ this.manager = manager;
+ }
+
+ /**
+ * Get path
+ * @return path
+ */
+ public MenuElement[] getPath()
+ {
+ return path;
+ }
+
+ /**
+ * Get menu selection manager
+ * @return manager
+ */
+ public MenuSelectionManager getMenuSelectionManager()
+ {
+ return manager;
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuDragMouseListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuDragMouseListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuDragMouseListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuDragMouseListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,74 @@
+/* MenuDragMouseListener.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+// Imports
+import java.util.EventListener;
+
+/**
+ * MenuDragMouseListener public interface
+ * @author Andrew Selkirk
+ */
+public interface MenuDragMouseListener extends EventListener {
+
+ /**
+ * Menu drag mouse dragged
+ * @param event Menu Drag Mouse Event
+ */
+ void menuDragMouseDragged(MenuDragMouseEvent event);
+
+ /**
+ * Menu drag mouse entered
+ * @param event Menu Drag Mouse Event
+ */
+ void menuDragMouseEntered(MenuDragMouseEvent event);
+
+ /**
+ * Menu drag mouse exited
+ * @param event Menu Drag Mouse Event
+ */
+ void menuDragMouseExited(MenuDragMouseEvent event);
+
+ /**
+ * Menu drag mouse released
+ * @param event Menu Drag Mouse Event
+ */
+ void menuDragMouseReleased(MenuDragMouseEvent event);
+
+
+} // MenuDragMouseListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,59 @@
+/* MenuEvent.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+import java.util.EventObject;
+
+/**
+ * MenuEvent
+ * @author Andrew Selkirk
+ * @author Ronald Veldema
+ */
+public class MenuEvent extends EventObject
+{
+
+ /**
+ * Constructor MenuEvent
+ * @param source Source object
+ */
+ public MenuEvent(Object source)
+ {
+ super(source);
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuKeyEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuKeyEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuKeyEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuKeyEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,102 @@
+/* MenuKeyEvent.java --
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.event;
+
+import java.awt.Component;
+import java.awt.event.KeyEvent;
+
+import javax.swing.MenuElement;
+import javax.swing.MenuSelectionManager;
+
+/**
+ * MenuKeyEvent
+ * @author Andrew Selkirk
+ */
+public class MenuKeyEvent extends KeyEvent
+{
+
+ /**
+ * path
+ */
+ private MenuElement[] path = null;
+
+ /**
+ * manager
+ */
+ private MenuSelectionManager manager = null;
+
+ /**
+ * Constructor MenuKeyEvent
+ * @param source Source
+ * @param id KeyEvent ID
+ * @param when Time
+ * @param modifiers Modifier keys
+ * @param keyCode Key code
+ * @param keyChar Key char
+ * @param path Path
+ * @param manager MenuSelectionManager
+ */
+ public MenuKeyEvent(Component source, int id, long when, int modifiers,
+ int keyCode, char keyChar, MenuElement[] path,
+ MenuSelectionManager manager)
+ {
+ super(source, id, when, modifiers, keyCode, keyChar);
+ this.path = path;
+ this.manager = manager;
+ }
+
+ /**
+ * getPath
+ * @return path
+ */
+ public MenuElement[] getPath()
+ {
+ return path;
+ }
+
+ /**
+ * getMenuSelectionManager
+ * @return MenuSelectionManager
+ */
+ public MenuSelectionManager getMenuSelectionManager()
+ {
+ return manager;
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuKeyListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuKeyListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuKeyListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuKeyListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,68 @@
+/* MenuKeyListener.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+// Imports
+import java.util.EventListener;
+
+/**
+ * MenuKeyListener public interface
+ * @author Andrew Selkirk
+ */
+public interface MenuKeyListener extends EventListener {
+
+ /**
+ * Menu key pressed
+ * @param event Menu Key Event
+ */
+ void menuKeyPressed(MenuKeyEvent event);
+
+ /**
+ * Menu key released
+ * @param event Menu Key Event
+ */
+ void menuKeyReleased(MenuKeyEvent event);
+
+ /**
+ * Menu key typed
+ * @param event Menu Key Event
+ */
+ void menuKeyTyped(MenuKeyEvent event);
+
+
+} // MenuKeyListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MenuListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,68 @@
+/* MenuListener.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+// Imports
+import java.util.EventListener;
+
+/**
+ * MenuListener public interface
+ * @author Andrew Selkirk
+ */
+public interface MenuListener extends EventListener {
+
+ /**
+ * Menu canceled
+ * @param event Menu Event
+ */
+ void menuCanceled(MenuEvent event);
+
+ /**
+ * Menu deselected
+ * @param event Menu Event
+ */
+ void menuDeselected(MenuEvent event);
+
+ /**
+ * Menu selected
+ * @param event Menu Event
+ */
+ void menuSelected(MenuEvent event);
+
+
+} // MenuListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MouseInputAdapter.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MouseInputAdapter.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MouseInputAdapter.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MouseInputAdapter.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,119 @@
+/* MouseInputAdapter.java --
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.event;
+
+import java.awt.event.MouseEvent;
+
+/**
+ * MouseInputAdapter
+ * @author Andrew Selkirk
+ */
+public abstract class MouseInputAdapter implements MouseInputListener
+{
+ /**
+ * Constructor MouseInputAdapter
+ */
+ public MouseInputAdapter()
+ {
+ // Do nothing here.
+ }
+
+ /**
+ * Mouse clicked
+ * @param event Mouse event
+ */
+ public void mouseClicked(MouseEvent event)
+ {
+ // Do nothing by default.
+ }
+
+ /**
+ * Mouse dragged
+ * @param event Mouse event
+ */
+ public void mouseDragged(MouseEvent event)
+ {
+ // Do nothing by default.
+ }
+
+ /**
+ * Mouse entered
+ * @param event Mouse event
+ */
+ public void mouseEntered(MouseEvent event)
+ {
+ // Do nothing by default.
+ }
+
+ /**
+ * Mouse exited
+ * @param event Mouse event
+ */
+ public void mouseExited(MouseEvent event)
+ {
+ // Do nothing by default.
+ }
+
+ /**
+ * Mouse moved
+ * @param event Mouse event
+ */
+ public void mouseMoved(MouseEvent event)
+ {
+ // Do nothing by default.
+ }
+
+ /**
+ * Mouse pressed
+ * @param event Mouse event
+ */
+ public void mousePressed(MouseEvent event)
+ {
+ // Do nothing by default.
+ }
+
+ /**
+ * Mouse released
+ * @param event Mouse event
+ */
+ public void mouseReleased(MouseEvent event)
+ {
+ // Do nothing by default.
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MouseInputListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MouseInputListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MouseInputListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/MouseInputListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,53 @@
+/* MouseInputListener.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+
+/**
+ * MouseInputListener public interface.
+ *
+ * @author Andrew Selkirk
+ */
+public interface MouseInputListener extends MouseListener,
+ MouseMotionListener
+{
+ // This interface only pulls together MouseListener and MouseMotionListener
+ // without adding any methods on its own.
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/PopupMenuEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/PopupMenuEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/PopupMenuEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/PopupMenuEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,58 @@
+/* PopupMenuEvent.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+// Imports
+import java.util.EventObject;
+
+/**
+ * PopupMenuEvent
+ * @author Andrew Selkirk
+ */
+public class PopupMenuEvent extends EventObject {
+
+ /**
+ * Constructor PopupMenuEvent
+ * @param source Source
+ */
+ public PopupMenuEvent(Object source) {
+ super(source);
+ } // PopupMenuEvent()
+
+
+} // PopupMenuEvent
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/PopupMenuListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/PopupMenuListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/PopupMenuListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/PopupMenuListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,68 @@
+/* PopupMenuListener.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+// Imports
+import java.util.EventListener;
+
+/**
+ * PopupMenuListener public interface
+ * @author Andrew Selkirk
+ */
+public interface PopupMenuListener extends EventListener {
+
+ /**
+ * Popup Menu Canceled
+ * @param event Popup Menu Event
+ */
+ void popupMenuCanceled(PopupMenuEvent event);
+
+ /**
+ * Popup Menu will become invisible
+ * @param event Popup Menu Event
+ */
+ void popupMenuWillBecomeInvisible(PopupMenuEvent event);
+
+ /**
+ * Popup Menu will become visible
+ * @param event Popup Menu Event
+ */
+ void popupMenuWillBecomeVisible(PopupMenuEvent event);
+
+
+} // PopupMenuListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/SwingPropertyChangeSupport.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/SwingPropertyChangeSupport.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/SwingPropertyChangeSupport.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/SwingPropertyChangeSupport.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,70 @@
+/* SwingPropertyChangeSupport.java --
+ Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+
+/**
+ * Provides a mechanism for registering {@link PropertyChangeListener}s and
+ * forwarding {@link PropertyChangeEvent}s to those listeners.
+ *
+ * As of JDK1.5 this class is no longer in use. Use
+ * {@link PropertyChangeSupport} instead.
+ *
+ * @author Andrew Selkirk
+ */
+public final class SwingPropertyChangeSupport
+ extends PropertyChangeSupport
+{
+
+ private static final long serialVersionUID = 7162625831330845068L;
+
+ /**
+ * Creates a new instance.
+ *
+ * @param source the source (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if <code>source</code> is <code>null</code>.
+ */
+ public SwingPropertyChangeSupport(Object source)
+ {
+ super(source);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TableColumnModelEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TableColumnModelEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TableColumnModelEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TableColumnModelEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,93 @@
+/* TableColumnModelEvent.java --
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.event;
+
+import java.util.EventObject;
+
+import javax.swing.table.TableColumnModel;
+
+/**
+ * TableColumnModelEvent
+ * @author Andrew Selkirk
+ */
+public class TableColumnModelEvent extends EventObject
+{
+
+ /**
+ * fromIndex
+ */
+ protected int fromIndex = 0;
+
+ /**
+ * toIndex
+ */
+ protected int toIndex = 0;
+
+ /**
+ * Constructor TableColumnModelEvent
+ * @param source Source TableColumnModel
+ * @param from From index
+ * @param to To index
+ */
+ public TableColumnModelEvent(TableColumnModel source, int from, int to)
+ {
+ super(source);
+ fromIndex = from;
+ toIndex = to;
+ }
+
+ /**
+ * getFromIndex.
+ * @return From index
+ */
+ public int getFromIndex()
+ {
+ return fromIndex;
+ }
+
+ /**
+ * getToIndex.
+ * @return To index
+ */
+ public int getToIndex()
+ {
+ return toIndex;
+ }
+
+}
\ No newline at end of file
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TableColumnModelListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TableColumnModelListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TableColumnModelListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TableColumnModelListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,94 @@
+/* TableColumnModelListener.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+import java.util.EventListener;
+
+import javax.swing.table.TableColumnModel;
+
+/**
+ * A <code>TableColumnModelListener</code> can register with a
+ * {@link TableColumnModel} to receive notification of changes to the model.
+ *
+ * @author Andrew Selkirk
+ */
+public interface TableColumnModelListener
+ extends EventListener
+{
+
+ /**
+ * Called by the {@link TableColumnModel} to indicate that a column has been
+ * added to the model.
+ *
+ * @param event information about the column addition.
+ */
+ void columnAdded(TableColumnModelEvent event);
+
+ /**
+ * Called by the {@link TableColumnModel} to indicate that the model's
+ * column margin has changed.
+ *
+ * @param event the event (identifies the source).
+ */
+ void columnMarginChanged(ChangeEvent event);
+
+ /**
+ * Called by the {@link TableColumnModel} to indicate that a column has been
+ * moved.
+ *
+ * @param event information about the column move.
+ */
+ void columnMoved(TableColumnModelEvent event);
+
+ /**
+ * Called by the {@link TableColumnModel} to indicate that a column has been
+ * removed from the model.
+ *
+ * @param event information about the column removal.
+ */
+ void columnRemoved(TableColumnModelEvent event);
+
+ /**
+ * Called by the {@link TableColumnModel} to indicate that the column
+ * selection state has changed.
+ *
+ * @param event information about the column selection state.
+ */
+ void columnSelectionChanged(ListSelectionEvent event);
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TableModelEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TableModelEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TableModelEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TableModelEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,220 @@
+/* TableModelEvent.java --
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.event;
+
+import java.util.EventObject;
+
+import javax.swing.table.TableModel;
+
+/**
+ * An event that describes changes to a {@link TableModel}.
+ *
+ * @see javax.swing.event.TableModelListener
+ *
+ * @author Andrew Selkirk
+ */
+public class TableModelEvent extends EventObject
+{
+ private static final long serialVersionUID = -7849342674552212824L;
+
+ /** A column index representing all columns. */
+ public static final int ALL_COLUMNS = -1;
+
+ /**
+ * An event type indicating that one or more rows have been deleted from the
+ * model.
+ */
+ public static final int DELETE = -1;
+
+ /** A row index representing the header row. */
+ public static final int HEADER_ROW = -1;
+
+ /**
+ * An event type indicating that one or more rows have been inserted into the
+ * model.
+ */
+ public static final int INSERT = 1;
+
+ /** An event type indicating that data has been updated in the model. */
+ public static final int UPDATE = 0;
+
+ /** The column in the table model that the event relates to. */
+ protected int column = 0;
+
+ /** The first row in the table model that the event relates to. */
+ protected int firstRow = 0;
+
+ /** The last row in the table model that the event relates to. */
+ protected int lastRow = 0;
+
+ /**
+ * The event type (one of {@link #UPDATE}, {@link #INSERT}, {@link #DELETE}).
+ */
+ protected int type = 0;
+
+ /**
+ * Creates a new <code>TableModelEvent</code> indicating an {@link #UPDATE}
+ * to the data in all columns and rows.
+ *
+ * @param source the source object (<code>null</code> not permitted).
+ *
+ * @throws IllegalArgumentException if <code>source</code> is
+ * <code>null</code>.
+ */
+ public TableModelEvent(TableModel source)
+ {
+ this(source, 0, Integer.MAX_VALUE, ALL_COLUMNS, UPDATE);
+ }
+
+ /**
+ * Creates a new <code>TableModelEvent</code> indicating an {@link #UPDATE}
+ * to the data in a single row across all columns.
+ *
+ * @param source the source object (<code>null</code> not permitted).
+ * @param row the updated row.
+ *
+ * @throws IllegalArgumentException if <code>source</code> is
+ * <code>null</code>.
+ */
+ public TableModelEvent(TableModel source, int row)
+ {
+ this(source, row, row, ALL_COLUMNS, UPDATE);
+ }
+
+ /**
+ * Creates a new <code>TableModelEvent</code> indicating an {@link #UPDATE}
+ * to the data in the specified rows across all columns.
+ *
+ * @param source the source object (<code>null</code> not permitted).
+ * @param firstRow the first row of update.
+ * @param lastRow the last row of update.
+ *
+ * @throws IllegalArgumentException if <code>source</code> is
+ * <code>null</code>.
+ */
+ public TableModelEvent(TableModel source, int firstRow, int lastRow)
+ {
+ this(source, firstRow, lastRow, ALL_COLUMNS, UPDATE);
+ }
+
+ /**
+ * Creates a new <code>TableModelEvent</code> indicating an {@link #UPDATE}
+ * to the data in the specified rows and column. Use {@link #ALL_COLUMNS}
+ * for the <code>column</code> argument to indicate all columns.
+ *
+ * @param source the source object (<code>null</code> not permitted).
+ * @param firstRow the first row of update.
+ * @param lastRow the last row of update.
+ * @param column the affected column.
+ *
+ * @throws IllegalArgumentException if <code>source</code> is
+ * <code>null</code>.
+ */
+ public TableModelEvent(TableModel source, int firstRow, int lastRow,
+ int column)
+ {
+ this(source, firstRow, lastRow, column, UPDATE);
+ }
+
+ /**
+ * Creates a new <code>TableModelEvent</code> indicating an operation of
+ * the specified <code>type</code> on the data in the specified rows and
+ * column. The event type is usually one of {@link #UPDATE}, {@link #INSERT},
+ * and {@link #DELETE}.
+ *
+ * @param source the source object (<code>null</code> not permitted).
+ * @param firstRow the first row of update.
+ * @param lastRow the last row of update.
+ * @param column the affected column.
+ * @param type the type of change.
+ *
+ * @throws IllegalArgumentException if <code>source</code> is
+ * <code>null</code>.
+ */
+ public TableModelEvent(TableModel source, int firstRow, int lastRow,
+ int column, int type)
+ {
+ super(source);
+ this.firstRow = firstRow;
+ this.lastRow = lastRow;
+ this.column = column;
+ this.type = type;
+ }
+
+ /**
+ * Returns the affected column of this event.
+ *
+ * @return The column index.
+ */
+ public int getColumn()
+ {
+ return column;
+ }
+
+ /**
+ * Returns the first affected row of this event.
+ *
+ * @return The row index.
+ */
+ public int getFirstRow()
+ {
+ return firstRow;
+ }
+
+ /**
+ * Returns the last affected row of this event.
+ *
+ * @return The row index.
+ */
+ public int getLastRow()
+ {
+ return lastRow;
+ }
+
+ /**
+ * Returns the type of change indicated by this event (usually one of
+ * {@link #UPDATE}, {@link #INSERT}, {@link #DELETE}).
+ *
+ * @return The type.
+ */
+ public int getType()
+ {
+ return type;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TableModelListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TableModelListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TableModelListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TableModelListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,60 @@
+/* TableModelListener.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+import java.util.EventListener;
+
+/**
+ * A <code>TableModelListener</code> can register with a
+ * {@link javax.swing.table.TableModel} and receive notification of updates to
+ * the model.
+ *
+ * @author Andrew Selkirk
+ */
+public interface TableModelListener extends EventListener
+{
+
+ /**
+ * Called to notify the listener that the
+ * {@link javax.swing.table.TableModel} has been updated.
+ *
+ * @param event contains details of the update.
+ */
+ void tableChanged(TableModelEvent event);
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeExpansionEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeExpansionEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeExpansionEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeExpansionEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,77 @@
+/* TreeExpansionEvent.java --
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.event;
+
+import java.util.EventObject;
+
+import javax.swing.tree.TreePath;
+
+/**
+ * TreeExpansionEvent
+ * @author Andrew Selkirk
+ */
+public class TreeExpansionEvent extends EventObject
+{
+
+ /**
+ * path
+ */
+ protected TreePath path = null;
+
+ /**
+ * Constructor TreeExpansionEvent
+ * @param source Source object
+ * @param path Path
+ */
+ public TreeExpansionEvent(Object source, TreePath path)
+ {
+ super(source);
+ this.path = path;
+ }
+
+ /**
+ * getPath
+ * @return Tree path
+ */
+ public TreePath getPath()
+ {
+ return path;
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeExpansionListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeExpansionListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeExpansionListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeExpansionListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,62 @@
+/* TreeExpansionListener.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+import java.util.EventListener;
+
+/**
+ * TreeExpansionListener public interface
+ * @author Andrew Selkirk
+ */
+public interface TreeExpansionListener extends EventListener
+{
+
+ /**
+ * Tree collapsed
+ * @param event Tree Expansion Event
+ */
+ void treeCollapsed(TreeExpansionEvent event);
+
+ /**
+ * Tree expanded
+ * @param event Tree Expansion Event
+ */
+ void treeExpanded(TreeExpansionEvent event);
+
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeModelEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeModelEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeModelEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeModelEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,168 @@
+/* TreeModelEvent.java --
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.event;
+
+import java.util.EventObject;
+
+import javax.swing.tree.TreePath;
+
+/**
+ * TreeModelEvent
+ * @author Andrew Selkirk
+ */
+public class TreeModelEvent extends EventObject
+{
+
+ /**
+ * childIndices
+ */
+ protected int[] childIndices = null;
+
+ /**
+ * children
+ */
+ protected Object[] children = null;
+
+ /**
+ * path
+ */
+ protected TreePath path = null;
+
+ /**
+ * Constructor TreeModelEvent
+ * @param source Source object
+ * @param path
+ */
+ public TreeModelEvent(Object source, Object[] path)
+ {
+ super(source);
+ this.path = new TreePath(path);
+ }
+
+ /**
+ * Constructor TreeModelEvent
+ * @param source Source object
+ * @param path path
+ * @param childIndices Child indices
+ * @param children Children
+ */
+ public TreeModelEvent(Object source, Object[] path,
+ int[] childIndices, Object[] children)
+ {
+ super(source);
+ this.path = new TreePath(path);
+ this.childIndices = childIndices;
+ this.children = children;
+ }
+
+ /**
+ * Constructor TreeModelEvent
+ * @param source Source object
+ * @param path Path
+ */
+ public TreeModelEvent(Object source, TreePath path)
+ {
+ super(source);
+ this.path = path;
+ }
+
+ /**
+ * Constructor TreeModelEvent
+ * @param source Source object
+ * @param path Path
+ * @param childIndices Child indices
+ * @param children Children
+ */
+ public TreeModelEvent(Object source, TreePath path,
+ int[] childIndices, Object[] children)
+ {
+ super(source);
+ this.path = path;
+ this.childIndices = childIndices;
+ this.children = children;
+ }
+
+ /**
+ * getChildIndices
+ * @return child indices
+ */
+ public int[] getChildIndices()
+ {
+ return childIndices;
+ }
+
+ /**
+ * getChildren
+ * @return children
+ */
+ public Object[] getChildren()
+ {
+ return children;
+ }
+
+ /**
+ * getPath
+ * @return path
+ */
+ public Object[] getPath()
+ {
+ return path.getPath();
+ }
+
+ /**
+ * getTreePath
+ * @return TreePath
+ */
+ public TreePath getTreePath()
+ {
+ return path;
+ }
+
+ /**
+ * String representation
+ * @return String representation
+ */
+ public String toString()
+ {
+ return getClass() + " [Source: " + getSource() + ", TreePath: "
+ + getTreePath() + ", Child Indicies: " + getChildIndices()
+ + ", Children: " + getChildren() + ", Path: " + getPath() +"]";
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeModelListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeModelListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeModelListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeModelListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,74 @@
+/* TreeModelListener.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+// Imports
+import java.util.EventListener;
+
+/**
+ * TreeModelListener public interface
+ * @author Andrew Selkirk
+ */
+public interface TreeModelListener extends EventListener {
+
+ /**
+ * Tree nodes changed
+ * @param event Tree Model Event
+ */
+ void treeNodesChanged(TreeModelEvent event);
+
+ /**
+ * Tree nodes inserted
+ * @param event Tree Model Event
+ */
+ void treeNodesInserted(TreeModelEvent event);
+
+ /**
+ * Tree nodes removed
+ * @param event Tree Model Event
+ */
+ void treeNodesRemoved(TreeModelEvent event);
+
+ /**
+ * Tree structured changed
+ * @param event Tree Model Event
+ */
+ void treeStructureChanged(TreeModelEvent event);
+
+
+} // TreeModelListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeSelectionEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeSelectionEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeSelectionEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeSelectionEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,257 @@
+/* TreeSelectionEvent.java --
+ Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.event;
+
+import java.util.EventObject;
+
+import javax.swing.tree.TreePath;
+import javax.swing.tree.TreeSelectionModel;
+
+/**
+ * An event that carries information about a change to a
+ * {@link TreeSelectionModel}.
+ *
+ * @see TreeSelectionListener
+ *
+ * @author Andrew Selkirk
+ */
+public class TreeSelectionEvent extends EventObject
+{
+
+ /**
+ * The paths that have been added or removed from the selection.
+ */
+ protected TreePath[] paths;
+
+ /**
+ * Flags indicating if the paths were added (<code>true</code>) or removed
+ * (<code>false</code>) from the selection.
+ */
+ protected boolean[] areNew;
+
+ /**
+ * The old lead selection path (may be <code>null</code>).
+ */
+ protected TreePath oldLeadSelectionPath;
+
+ /**
+ * The new lead selection path (may be <code>null</code>).
+ */
+ protected TreePath newLeadSelectionPath;
+
+ /**
+ * Creates a new <code>TreeSelectionEvent</code>.
+ *
+ * @param source the source (usually a {@link TreeSelectionModel},
+ * <code>null</code> not permitted).
+ * @param paths an array of the paths that have been added to or removed
+ * from the selection.
+ * @param areNew a flag for each path where <code>true</code> indicates the
+ * corresponding path has been added to the selection and
+ * <code>false</code> indicates the path has been removed.
+ * @param oldLeadSelectionPath the old lead selection path (<code>null</code>
+ * permitted).
+ * @param newLeadSelectionPath the new lead selection path (<code>null</code>
+ * permitted).
+ *
+ * @throws IllegalArgumentException if <code>source</code> is
+ * <code>null</code>.
+ */
+ public TreeSelectionEvent(Object source, TreePath[] paths,
+ boolean[] areNew, TreePath oldLeadSelectionPath,
+ TreePath newLeadSelectionPath)
+ {
+ super(source);
+ this.paths = paths;
+ this.areNew = areNew;
+ this.oldLeadSelectionPath = oldLeadSelectionPath;
+ this.newLeadSelectionPath = newLeadSelectionPath;
+ }
+
+ /**
+ * Creates a new <code>TreeSelectionEvent</code>.
+ *
+ * @param source the event source (usually a {@link TreeSelectionModel},
+ * <code>null</code> not permitted).
+ * @param path the path.
+ * @param isNew <code>true</code> indicates that <code>path</code> has been
+ * added to the selection, and <code>false</code> indicates that it has
+ * been removed.
+ * @param oldLeadSelectionPath the old lead selection path (<code>null</code>
+ * permitted).
+ * @param newLeadSelectionPath the new lead selection path (<code>null</code>
+ * permitted).
+ *
+ * @throws IllegalArgumentException if <code>source</code> is
+ * <code>null</code>.
+ */
+ public TreeSelectionEvent(Object source, TreePath path,
+ boolean isNew, TreePath oldLeadSelectionPath,
+ TreePath newLeadSelectionPath)
+ {
+ super(source);
+ this.paths = new TreePath[]{path};
+ this.areNew = new boolean[]{isNew};
+ this.oldLeadSelectionPath = oldLeadSelectionPath;
+ this.newLeadSelectionPath = newLeadSelectionPath;
+ }
+
+ /**
+ * Returns the first path element.
+ *
+ * @return The first path element.
+ *
+ * @see #getPaths()
+ */
+ public TreePath getPath()
+ {
+ return paths[0];
+ }
+
+ /**
+ * Returns an array of the paths that changed in the selection.
+ *
+ * @return The paths that changed in the selection.
+ *
+ * @see #isAddedPath(TreePath)
+ */
+ public TreePath[] getPaths()
+ {
+ return (TreePath[]) paths.clone();
+ }
+
+ /**
+ * Returns <code>true</code> if the path returned by {@link #getPath()} has
+ * been added to the selection, and <code>false</code> if it has been
+ * removed.
+ *
+ * @return A boolean.
+ *
+ * @see #isAddedPath(int)
+ */
+ public boolean isAddedPath()
+ {
+ return areNew[0];
+ }
+
+ /**
+ * Returns <code>true</code> if <code>path</code> has been added to the
+ * selection, and <code>false</code> if the path has been removed from the
+ * selection.
+ *
+ * @param path the path to check.
+ *
+ * @return A flag indicating whether the path has been added to, or removed
+ * from, the selection.
+ *
+ * @throw IllegalArgumentException if <code>path</code> is not one of the
+ * paths in {@link #getPaths()}.
+ *
+ * @see #isAddedPath(int)
+ */
+ public boolean isAddedPath(TreePath path)
+ {
+ for (int i = paths.length - 1; i >= 0; i--)
+ if (paths[i].equals(path))
+ return areNew[i];
+
+ throw new IllegalArgumentException("Unknown 'path' argument.");
+ }
+
+ /**
+ * Returns <code>true</code> if the path at the specified index has been
+ * added to the selection, and <code>false</code> if the path has been
+ * removed from the selection.
+ *
+ * @param index the path index.
+ *
+ * @return A flag indicating whether the path has been added to, or removed
+ * from, the selection.
+ *
+ * @since 1.3
+ *
+ * @see #isAddedPath(TreePath)
+ */
+ public boolean isAddedPath(int index)
+ {
+ return areNew[index];
+ }
+
+ /**
+ * Returns the old lead selection path.
+ *
+ * @return The old lead selection path (possibly <code>null</code>).
+ *
+ * @see #getNewLeadSelectionPath()
+ */
+ public TreePath getOldLeadSelectionPath()
+ {
+ return oldLeadSelectionPath;
+ }
+
+ /**
+ * Returns the new lead selection path.
+ *
+ * @return The new lead selection path (possibly <code>null</code>).
+ *
+ * @see #getOldLeadSelectionPath()
+ */
+ public TreePath getNewLeadSelectionPath()
+ {
+ return newLeadSelectionPath;
+ }
+
+ /**
+ * Creates a shallow copy of this <code>TreeSelectionEvent</code>, replacing
+ * the source with <code>source</code>.
+ *
+ * @param source the new event source (<code>null</code> not permitted).
+ *
+ * @return A cloned event with another event source.
+ *
+ * @throws IllegalArgumentException if <code>source</code> is
+ * <code>null</code>.
+ */
+ public Object cloneWithSource(Object source)
+ {
+ return new TreeSelectionEvent (source, paths, areNew, oldLeadSelectionPath,
+ newLeadSelectionPath);
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeSelectionListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeSelectionListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeSelectionListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeSelectionListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,60 @@
+/* TreeSelectionListener.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.event;
+
+import java.util.EventListener;
+
+import javax.swing.tree.TreeSelectionModel;
+
+/**
+ * A listener that receives {@link TreeSelectionEvent} notifications from a
+ * source (such as a {@link TreeSelectionModel}).
+ *
+ * @author Andrew Selkirk
+ */
+public interface TreeSelectionListener extends EventListener
+{
+
+ /**
+ * Receives notification of a change to a tree selection model.
+ *
+ * @param event information about the event.
+ */
+ void valueChanged(TreeSelectionEvent event);
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeWillExpandListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeWillExpandListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeWillExpandListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/TreeWillExpandListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,65 @@
+/* TreeWillExpandListener.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.event;
+
+import java.util.EventListener;
+
+import javax.swing.tree.ExpandVetoException;
+
+/**
+ * @author Andrew Selkirk
+ */
+public interface TreeWillExpandListener extends EventListener
+{
+ /**
+ * Invoked whenever a node in the tree is about to be collapsed.
+ *
+ * @param event The tree expansion Event
+ */
+ void treeWillCollapse(TreeExpansionEvent event)
+ throws ExpandVetoException;
+
+ /**
+ * Invoked whenever a node in the tree is about to be expanded.
+ *
+ * @param event The tree expansion Event
+ */
+ void treeWillExpand(TreeExpansionEvent event)
+ throws ExpandVetoException;
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/UndoableEditEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/UndoableEditEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/UndoableEditEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/event/UndoableEditEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,80 @@
+/* UndoableEditEvent.java --
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.event;
+
+import java.util.EventObject;
+
+import javax.swing.undo.UndoableEdit;
+
+/**
+ * UndoableEditEvent
+ * @author Andrew Selkirk
+ * @author Ronald Veldema
+ */
+public class UndoableEditEvent extends EventObject
+{
+
+ private static final long serialVersionUID = 4418044561759134484L;
+
+ /**
+ * edit
+ */
+ private UndoableEdit edit;
+
+ /**
+ * Constructor UndoableEditEvent
+ * @param source TODO
+ * @param edit TODO
+ */
+ public UndoableEditEvent(Object source, UndoableEdit edit)
+ {
+ super(source);
+ this.edit = edit;
+ }
+
+ /**
+ * getEdit
+ * @return UndoableEdit
+ */
+ public UndoableEdit getEdit()
+ {
+ return edit;
+ }
+
+}
More information about the llvm-commits
mailing list