[kaffe] CVS kaffe (robilad): resynced with gnu classpath: swing fixes
Kaffe CVS
cvs-commits at kaffe.org
Wed May 18 15:21:03 PDT 2005
PatchSet 6550
Date: 2005/05/18 22:13:27
Author: robilad
Branch: HEAD
Tag: (none)
Log:
resynced with gnu classpath: swing fixes
Members:
ChangeLog:1.4076->1.4077
libraries/javalib/javax/swing/JComponent.java:1.17->1.18
libraries/javalib/javax/swing/JTree.java:1.14->1.15
libraries/javalib/javax/swing/SwingUtilities.java:1.11->1.12
libraries/javalib/javax/swing/UIManager.java:1.7->1.8
libraries/javalib/javax/swing/table/DefaultTableCellRenderer.java:1.5->1.6
libraries/javalib/javax/swing/text/JTextComponent.java:1.15->1.16
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4076 kaffe/ChangeLog:1.4077
--- kaffe/ChangeLog:1.4076 Wed May 18 22:08:44 2005
+++ kaffe/ChangeLog Wed May 18 22:13:27 2005
@@ -2,6 +2,57 @@
Resynced with GNU Classpath.
+ 2005-05-18 Roman Kennke <roman at kennke.org>
+
+ * javax/swing/text/JTextComponent.java
+ (constructor): Make text components editable by default.
+
+ 2005-05-18 Roman Kennke <roman at kennke.org>
+
+ * javax/swing/UIManager.java
+ (toString): Added method.
+
+ 2005-05-18 Roman Kennke <roman at kennke.org>
+
+ * javax/swing/SwingUtilities.java
+ (getUIInputMap): Added method.
+ (getUIActionMap): Added method.
+
+ 2005-05-18 Roman Kennke <roman at kennke.org>
+
+ * javax/swing/JComponent.java
+ (constructor): Make component requestFocusEnabled by default.
+ (requestFocusInWindow): Added method.
+
+ 2005-05-18 Sven de Marothy <sven at physto.se>
+
+ * javax/swing/table/DefaultTableCellRenderer.java
+ (getTableCellRendererComponent): Allow table parameter to be null.
+
+ 2005-05-17 Jan Roehrich <jan at roehrich.info>
+
+ * javax/swing/JTree.java
+ (getExpandedDescendants): Added method.
+
+ 2005-05-17 Roman Kennke <roman at kennke.org>
+
+ * javax/swing/JTree.java
+ (TreeModelHandler): Added inner class.
+ (TreeSelectionRedirector): Added inner class.
+ (EmptySelectionModel): Added inner class.
+ (DynamicUtilTreeNode.getChildAt): Added method.
+ (constructor(model)): Sets up a model and a selection model.
+ (setModel): Set up the JTree treeModelListener on newly set
+ models.
+ (createModelListener): Added method.
+ (getDefaultTreeModel): Added method.
+ (convertValueToText): Added method.
+ (paramString): Added method.
+
+2005-05-18 Dalibor Topic <robilad at kaffe.org>
+
+ Resynced with GNU Classpath.
+
2005-05-18 Audrius Meskauskas, <AudriusA at Bioinformatics.org>
* org/omg/CORBA/DynAny.java,
Index: kaffe/libraries/javalib/javax/swing/JComponent.java
diff -u kaffe/libraries/javalib/javax/swing/JComponent.java:1.17 kaffe/libraries/javalib/javax/swing/JComponent.java:1.18
--- kaffe/libraries/javalib/javax/swing/JComponent.java:1.17 Sun May 15 19:32:02 2005
+++ kaffe/libraries/javalib/javax/swing/JComponent.java Wed May 18 22:13:35 2005
@@ -400,6 +400,7 @@
setDropTarget(new DropTarget());
defaultLocale = Locale.getDefault();
debugGraphicsOptions = DebugGraphics.NONE_OPTION;
+ setRequestFocusEnabled(true);
}
/**
@@ -2321,6 +2322,33 @@
public boolean requestFocus(boolean temporary)
{
return super.requestFocus(temporary);
+ }
+
+ /**
+ * Requests that this component gets the input focus if the top level
+ * window that contains this component has the focus and the
+ * requestFocusEnabled property is set to <code>true</code>.
+ *
+ * The preconditions that have to be met to become a focus owner is that
+ * the component must be displayable, visible and focusable.
+ *
+ * Note that this signals only a request for becoming focused. There are
+ * situations in which it is not possible to get the focus. So developers
+ * should not assume that the component has the focus until it receives
+ * a {@link java.awt.event.FocusEvent} with a value of
+ * {@link java.awt.event.FocusEvent.FOCUS_GAINED}.
+ *
+ * @return <code>false</code> if the focus change request will definitly
+ * fail, <code>true</code> if it will likely succeed
+ *
+ * @see {@link Component#requestFocusInWindow()}
+ */
+ public boolean requestFocusInWindow()
+ {
+ if (isRequestFocusEnabled())
+ return super.requestFocusInWindow();
+ else
+ return false;
}
/**
Index: kaffe/libraries/javalib/javax/swing/JTree.java
diff -u kaffe/libraries/javalib/javax/swing/JTree.java:1.14 kaffe/libraries/javalib/javax/swing/JTree.java:1.15
--- kaffe/libraries/javalib/javax/swing/JTree.java:1.14 Sat Feb 19 15:23:41 2005
+++ kaffe/libraries/javalib/javax/swing/JTree.java Wed May 18 22:13:35 2005
@@ -40,6 +40,7 @@
import java.awt.Dimension;
import java.awt.Rectangle;
+import java.io.Serializable;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
@@ -49,6 +50,8 @@
import javax.accessibility.AccessibleContext;
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;
@@ -56,6 +59,7 @@
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
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;
@@ -68,6 +72,172 @@
public class JTree extends JComponent
implements Scrollable, Accessible
{
+ /**
+ * 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()
+ {
+ }
+
+ /**
+ * 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));
+ }
+ } // TreeModelHandler
+
+ /**
+ * 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()
+ {
+ }
+
+ /**
+ * 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);
+ }
+ } // TreeSelectionRedirector
+
+ /**
+ * 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()
+ {
+ }
+
+ /**
+ * 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
+ }
+ }// EmptySelectionModel
+
private static final long serialVersionUID = 7559816092864483649L;
public static final String CELL_EDITOR_PROPERTY = "cellEditor";
@@ -121,6 +291,17 @@
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();
+
+ /**
* Creates a new <code>JTree</code> object.
*/
public JTree()
@@ -155,7 +336,9 @@
*/
public JTree(TreeModel model)
{
- treeModel = model;
+ setModel(model);
+ setSelectionModel(EmptySelectionModel.sharedInstance());
+ selectionModel.addTreeSelectionListener(selectionRedirector);
setCellRenderer(new DefaultTreeCellRenderer());
updateUI();
}
@@ -233,6 +416,20 @@
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 ||
@@ -582,6 +779,11 @@
TreeModel oldValue = treeModel;
treeModel = model;
firePropertyChange(TREE_MODEL_PROPERTY, oldValue, model);
+
+ // add treeModelListener to the new model
+ if (treeModelListener == null)
+ treeModelListener = createTreeModelListener();
+ model.addTreeModelListener(treeModelListener);
}
/**
@@ -1388,5 +1590,118 @@
public boolean isPathEditable(TreePath path)
{
return isEditable();
+ }
+
+ /**
+ * Creates and returns an instance of {@link TreeModelHandler}.
+ *
+ * @returns 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
+ */
+ public 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();
}
}
Index: kaffe/libraries/javalib/javax/swing/SwingUtilities.java
diff -u kaffe/libraries/javalib/javax/swing/SwingUtilities.java:1.11 kaffe/libraries/javalib/javax/swing/SwingUtilities.java:1.12
--- kaffe/libraries/javalib/javax/swing/SwingUtilities.java:1.11 Mon Feb 14 20:49:40 2005
+++ kaffe/libraries/javalib/javax/swing/SwingUtilities.java Wed May 18 22:13:35 2005
@@ -1319,4 +1319,33 @@
&& 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
+ */
+ public static InputMap getUIInputMap(JComponent component, int cond)
+ {
+ return component.getInputMap(cond);
+ }
+
+ /**
+ * 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 InputMap getUIActionMap(JComponent component)
+ {
+ return component.getInputMap();
+ }
}
Index: kaffe/libraries/javalib/javax/swing/UIManager.java
diff -u kaffe/libraries/javalib/javax/swing/UIManager.java:1.7 kaffe/libraries/javalib/javax/swing/UIManager.java:1.8
--- kaffe/libraries/javalib/javax/swing/UIManager.java:1.7 Sun May 15 10:13:28 2005
+++ kaffe/libraries/javalib/javax/swing/UIManager.java Wed May 18 22:13:36 2005
@@ -72,6 +72,23 @@
{
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();
+ }
}
private static final long serialVersionUID = -5547433830339189365L;
Index: kaffe/libraries/javalib/javax/swing/table/DefaultTableCellRenderer.java
diff -u kaffe/libraries/javalib/javax/swing/table/DefaultTableCellRenderer.java:1.5 kaffe/libraries/javalib/javax/swing/table/DefaultTableCellRenderer.java:1.6
--- kaffe/libraries/javalib/javax/swing/table/DefaultTableCellRenderer.java:1.5 Wed Jan 26 13:40:06 2005
+++ kaffe/libraries/javalib/javax/swing/table/DefaultTableCellRenderer.java Wed May 18 22:13:36 2005
@@ -122,10 +122,14 @@
boolean hasFocus,
int row, int column)
{
- if (value!=null)
+ if (value != null)
super.setText(value.toString());
setOpaque(true);
+
+ if (table == null)
+ return this;
+
if (isSelected)
{
setBackground(table.getSelectionBackground());
Index: kaffe/libraries/javalib/javax/swing/text/JTextComponent.java
diff -u kaffe/libraries/javalib/javax/swing/text/JTextComponent.java:1.15 kaffe/libraries/javalib/javax/swing/text/JTextComponent.java:1.16
--- kaffe/libraries/javalib/javax/swing/text/JTextComponent.java:1.15 Sun May 15 18:03:47 2005
+++ kaffe/libraries/javalib/javax/swing/text/JTextComponent.java Wed May 18 22:13:37 2005
@@ -910,6 +910,7 @@
}
setFocusable(true);
+ setEditable(true);
enableEvents(AWTEvent.KEY_EVENT_MASK);
updateUI();
More information about the kaffe
mailing list