I have started the JTree editing. There is _alot_ to implement, this is
just the beginning. :)
2005-08-18 Lillian Angel <[EMAIL PROTECTED]>
* javax/swing/DefaultCellEditor.java
(getTreeCellEditorComponent): Implemented.
* javax/swing/plaf/basic/BasicTreeUI.java
(isEditing): Implemented.
(mouseClicked): Moved code to mousePressed
(mousePressed): Code moved here from mouseClicked and
added in code to stop editing.
(selectPath): Default is changed to CONTIGUOUS_TREE_SELECTION
* javax/swing/tree/DefaultTreeSelectionModel.java
(DefaultTreeSelectionModel): Default is changed to
CONTIGUOUS_TREE_SELECTION.
Index: javax/swing/DefaultCellEditor.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/DefaultCellEditor.java,v
retrieving revision 1.11
diff -u -r1.11 DefaultCellEditor.java
--- javax/swing/DefaultCellEditor.java 9 Aug 2005 15:56:40 -0000 1.11
+++ javax/swing/DefaultCellEditor.java 18 Aug 2005 20:45:12 -0000
@@ -340,23 +340,41 @@
} // cancelCellEditing()
/**
- * getTreeCellEditorComponent
+ * Sets an initial value for the editor.
+ * This will cause the editor to stopEditing and lose any partially
+ * edited value if the editor is editing when this method is called.
+ * Returns the component that should be added to the client's Component
+ * hierarchy. Once installed in the client's hierarchy this component will
+ * then be able to draw and receive user input.
*
- * @param tree TODO
- * @param value TODO
- * @param isSelected TODO
- * @param expanded TODO
- * @param leaf TODO
- * @param row TODO
+ * @param tree - the JTree that is asking the editor to edit; this
+ * parameter can be null
+ * @param value - the value of the cell to be edited
+ * @param isSelected - true is the cell is to be renderer with selection
+ * highlighting
+ * @param expanded - true if the node is expanded
+ * @param leaf - true if the node is a leaf node
+ * @param row - the row index of the node being edited
*
- * @returns Component
+ * @returns Component the component for editing
*/
public Component getTreeCellEditorComponent(JTree tree, Object value,
boolean isSelected,
boolean expanded, boolean leaf,
int row)
{
- return null; // TODO
+ if (editorComponent instanceof JTextField)
+ {
+ ((JTextField)editorComponent).setText(value.toString());
+ delegate = new EditorDelegate();
+ ((JTextField)editorComponent).addActionListener(delegate);
+ }
+ else
+ {
+ // TODO
+ }
+
+ return editorComponent;
} // getTreeCellEditorComponent()
/**
Index: javax/swing/plaf/basic/BasicTreeUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v
retrieving revision 1.63
diff -u -r1.63 BasicTreeUI.java
--- javax/swing/plaf/basic/BasicTreeUI.java 18 Aug 2005 18:39:20 -0000 1.63
+++ javax/swing/plaf/basic/BasicTreeUI.java 18 Aug 2005 20:45:12 -0000
@@ -728,8 +728,7 @@
*/
public boolean isEditing(JTree tree)
{
- // FIXME: not implemented
- return false;
+ return getCellEditor() != null;
}
/**
@@ -1919,6 +1918,15 @@
*/
public void mouseClicked(MouseEvent e)
{
+ }
+
+ /**
+ * Invoked when a mouse button has been pressed on a component.
+ *
+ * @param e mouse event that occured
+ */
+ public void mousePressed(MouseEvent e)
+ {
Point click = e.getPoint();
int row = Math.round(click.y / BasicTreeUI.this.getRowHeight());
TreePath path = BasicTreeUI.this.getClosestPathForLocation(tree, click.x,
@@ -1938,8 +1946,8 @@
if (bounds.contains(click.x, click.y))
inBounds = true;
else if (BasicTreeUI.this.hasControlIcons()
- && (click.x < (bounds.x - rightChildIndent + 5) && click.x > (bounds.x
- - rightChildIndent - 5)))
+ && (click.x < (bounds.x - rightChildIndent + 5)
+ && click.x > (bounds.x - rightChildIndent - 5)))
cntlClick = true;
if ((inBounds || cntlClick) && BasicTreeUI.this.tree.isVisible(path))
@@ -1968,20 +1976,16 @@
}
BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, path);
+
+ // If editing, but the moved to another cell then stop editing
+ if (!path.equals(BasicTreeUI.this.tree.getLeadSelectionPath()))
+ if (BasicTreeUI.this.tree.isEditing())
+ BasicTreeUI.this.tree.stopEditing();
}
}
}
/**
- * Invoked when a mouse button has been pressed on a component.
- *
- * @param e mouse event that occured
- */
- public void mousePressed(MouseEvent e)
- {
- }
-
- /**
* Invoked when a mouse button has been released on a component.
*
* @param e mouse event that occured
@@ -2980,22 +2984,24 @@
{
if (tree.isPathSelected(path))
tree.removeSelectionPath(path);
- else if (tree.getSelectionModel().getSelectionMode() == TreeSelectionModel.SINGLE_TREE_SELECTION)
+ else if (tree.getSelectionModel().getSelectionMode() == TreeSelectionModel.
+ DISCONTIGUOUS_TREE_SELECTION)
{
- tree.getSelectionModel().clearSelection();
tree.addSelectionPath(path);
tree.setLeadSelectionPath(path);
}
- else if (tree.getSelectionModel().getSelectionMode() == TreeSelectionModel.CONTIGUOUS_TREE_SELECTION)
+ else if (tree.getSelectionModel().getSelectionMode() == TreeSelectionModel.
+ CONTIGUOUS_TREE_SELECTION)
{
// TODO
}
else
{
- tree.getSelectionModel().setSelectionMode(
- TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
- tree.addSelectionPath(path);
- tree.setLeadSelectionPath(path);
+ tree.getSelectionModel().setSelectionMode(TreeSelectionModel.
+ SINGLE_TREE_SELECTION);
+ tree.getSelectionModel().clearSelection();
+ tree.addSelectionPath(path);
+ tree.setLeadSelectionPath(path);
}
}
}
Index: javax/swing/tree/DefaultTreeSelectionModel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/tree/DefaultTreeSelectionModel.java,v
retrieving revision 1.19
diff -u -r1.19 DefaultTreeSelectionModel.java
--- javax/swing/tree/DefaultTreeSelectionModel.java 13 Jul 2005 08:37:46 -0000 1.19
+++ javax/swing/tree/DefaultTreeSelectionModel.java 18 Aug 2005 20:45:12 -0000
@@ -116,7 +116,7 @@
*/
public DefaultTreeSelectionModel()
{
- setSelectionMode(DISCONTIGUOUS_TREE_SELECTION);
+ setSelectionMode(SINGLE_TREE_SELECTION);
listenerList = new EventListenerList();
}
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches