Editing for the MetalFileChooser now works.
2005-11-28 Lillian Angel <[EMAIL PROTECTED]>
* javax/swing/JList.java
(init): Layout should not be set to FlowLayout. JDK sets it to
null.
* javax/swing/plaf/metal/MetalFileChooserUI.java
(mouseClicked): Changed to call completeEditing when
double-clicked.
(editFile): Fixed to add an action listener to the editing
field. Editing for filechooser now works.
(completeEditing): Fixed renaming to create a new file object
and rescan the directory if renaming was successful. Added code
to cancel editing as well.
(EditingActionListener): New class to listen for notify action
and to complete editing when enter is pressed. Otherwise,
editing is cancelled.
* javax/swing/plaf/metal/MetalSplitPaneDivider.java
(MetalDividerLayout): Changed to public.
(MetalDividerLayout.init): Likewise.
Index: javax/swing/JList.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JList.java,v
retrieving revision 1.41
diff -u -r1.41 JList.java
--- javax/swing/JList.java 25 Nov 2005 16:33:23 -0000 1.41
+++ javax/swing/JList.java 28 Nov 2005 18:29:12 -0000
@@ -1078,7 +1078,8 @@
setModel(new DefaultListModel());
setSelectionModel(createSelectionModel());
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
-
+ setLayout(null);
+
updateUI();
}
Index: javax/swing/plaf/metal/MetalFileChooserUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalFileChooserUI.java,v
retrieving revision 1.7
diff -u -r1.7 MetalFileChooserUI.java
--- javax/swing/plaf/metal/MetalFileChooserUI.java 25 Nov 2005 22:57:15 -0000 1.7
+++ javax/swing/plaf/metal/MetalFileChooserUI.java 28 Nov 2005 18:29:12 -0000
@@ -48,6 +48,7 @@
import java.awt.Rectangle;
import java.awt.Window;
import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@@ -686,13 +687,11 @@
editFile(index);
lastSelected = tmp;
}
- else if (editFile != null)
- {
+ else
completeEditing();
- editFile = null;
- lastSelected = null;
- }
}
+ else
+ completeEditing();
}
/**
@@ -701,47 +700,77 @@
* @param index -
* the current index of the item in the list to be edited.
*/
- private void editFile(int index)
+ void editFile(int index)
{
list.ensureIndexIsVisible(index);
editFile = (File) list.getModel().getElementAt(index);
if (editFile.canWrite())
{
- Rectangle bounds = list.getCellBounds(index, index);
- Icon icon = getFileView(fc).getIcon(editFile);
editField = new JTextField(editFile.getName());
- // FIXME: add action listener for typing
- // FIXME: painting for textfield is messed up when typing
- list.add(editField);
- editField.requestFocus();
- editField.selectAll();
+ editField.addActionListener(new EditingActionListener());
+ Rectangle bounds = list.getCellBounds(index, index);
+ Icon icon = getFileView(fc).getIcon(editFile);
if (icon != null)
bounds.x += icon.getIconWidth() + 4;
editField.setBounds(bounds);
+
+ list.add(editField);
+
+ editField.requestFocus();
+ editField.selectAll();
}
else
- {
- editField = null;
- editFile = null;
- lastSelected = null;
- }
+ completeEditing();
+ list.repaint();
}
/**
* Completes the editing.
*/
- private void completeEditing()
+ void completeEditing()
{
- if (editField != null)
+ if (editField != null && editFile != null)
{
String text = editField.getText();
- if (text != null && !text.equals(""))
- editFile.renameTo(new File(text));
+ if (text != null && text != "" && !text.equals(fc.getName(editFile)))
+ if (editFile.renameTo
+ (fc.getFileSystemView().createFileObject
+ (fc.getCurrentDirectory(), text)))
+ rescanCurrentDirectory(fc);
list.remove(editField);
- list.revalidate();
- list.repaint();
}
+ editFile = null;
+ lastSelected = null;
+ editField = null;
+ list.repaint();
+ }
+
+ /**
+ * ActionListener for the editing text field.
+ */
+ class EditingActionListener implements ActionListener
+ {
+
+ /**
+ * This method is invoked when an action occurs.
+ *
+ * @param e -
+ * the <code>ActionEvent</code> that occurred
+ */
+ public void actionPerformed(ActionEvent e)
+ {
+ if (e.getActionCommand().equals("notify-field-accept"))
+ completeEditing();
+ else if (editField != null)
+ {
+ list.remove(editField);
+ editFile = null;
+ lastSelected = null;
+ editField = null;
+ list.repaint();
+ }
+ }
}
}
Index: javax/swing/plaf/metal/MetalSplitPaneDivider.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalSplitPaneDivider.java,v
retrieving revision 1.5
diff -u -r1.5 MetalSplitPaneDivider.java
--- javax/swing/plaf/metal/MetalSplitPaneDivider.java 25 Nov 2005 23:04:53 -0000 1.5
+++ javax/swing/plaf/metal/MetalSplitPaneDivider.java 28 Nov 2005 18:29:12 -0000
@@ -105,7 +105,7 @@
/**
* This helper class acts as the Layout Manager for the divider.
*/
- protected class MetalDividerLayout implements LayoutManager
+ public class MetalDividerLayout implements LayoutManager
{
/** The right button. */
BasicArrowButton rb;
@@ -116,7 +116,7 @@
/**
* Creates a new DividerLayout object.
*/
- protected MetalDividerLayout()
+ public MetalDividerLayout()
{
// Nothing to do here
}
@@ -132,7 +132,7 @@
// Nothing to do here, constraints are set depending on
// orientation in layoutContainer
}
-
+
/**
* This method is called to lay out the container.
*
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches