Fixed some JList selection problems, and implemented/fixed a few things
in the FileChooser code. It is not yet completed.

2005-11-25  Lillian Angel  <[EMAIL PROTECTED]>

        * javax/swing/JList.java
        (JList): Set default selection mode.
        * javax/swing/plaf/basic/BasicFileChooserUI.java
        (DoubleClickListener): No need for timer here.
        (mouseClicked): Removed timer code, and added check for double 
        click. Problems with opening wrong directory is now fixed.
        * javax/swing/plaf/basic/BasicListUI.java
        (mouseDragged): Implemented.
        * javax/swing/plaf/metal/MetalFileChooserUI.java
        (propertyChange): Implemented 
        MULTI_SELECTION_ENABLED_CHANGED_PROPERTY
        property change.
        (getListCellRendererComponent): Set opaque property, so 
        background color on cell is painted.
        (SingleClickListener.init): Implemented.
        (installStrings): Fixed tooltip text strings.

Index: javax/swing/JList.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JList.java,v
retrieving revision 1.40
diff -u -r1.40 JList.java
--- javax/swing/JList.java	17 Nov 2005 12:08:31 -0000	1.40
+++ javax/swing/JList.java	25 Nov 2005 16:26:12 -0000
@@ -1077,6 +1077,7 @@
 
     setModel(new DefaultListModel());
     setSelectionModel(createSelectionModel());
+    setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 
     updateUI();
   }
Index: javax/swing/plaf/basic/BasicFileChooserUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicFileChooserUI.java,v
retrieving revision 1.18
diff -u -r1.18 BasicFileChooserUI.java
--- javax/swing/plaf/basic/BasicFileChooserUI.java	25 Nov 2005 16:17:48 -0000	1.18
+++ javax/swing/plaf/basic/BasicFileChooserUI.java	25 Nov 2005 16:26:12 -0000
@@ -347,8 +347,6 @@
    */
   protected class DoubleClickListener extends MouseAdapter
   {
-    /** A timer. */
-    private Timer timer = null;
 
     /** DOCUMENT ME! */
     private Object lastSelected = null;
@@ -364,8 +362,6 @@
     public DoubleClickListener(JList list)
     {
       this.list = list;
-      timer = new Timer(1000, null);
-      timer.setRepeats(false);
       lastSelected = list.getSelectedValue();
       setDirectorySelected(false);
     }
@@ -380,11 +376,10 @@
       if (list.getSelectedValue() == null)
         return;
       FileSystemView fsv = filechooser.getFileSystemView();
-      if (timer.isRunning()
-          && list.getSelectedValue().toString().equals(lastSelected.toString()))
+      if (e.getClickCount() >= 2 &&
+          list.getSelectedValue().toString().equals(lastSelected.toString()))
         {
           File f = fsv.createFileObject(lastSelected.toString());
-          timer.stop();
           if (filechooser.isTraversable(f))
             {
               filechooser.setCurrentDirectory(f);
@@ -414,7 +409,6 @@
           lastSelected = path;
           parentPath = path.substring(0, path.lastIndexOf("/") + 1);
           setFileName(path.substring(path.lastIndexOf("/") + 1));
-          timer.restart();
         }
     }
 
Index: javax/swing/plaf/basic/BasicListUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicListUI.java,v
retrieving revision 1.41
diff -u -r1.41 BasicListUI.java
--- javax/swing/plaf/basic/BasicListUI.java	16 Nov 2005 15:32:22 -0000	1.41
+++ javax/swing/plaf/basic/BasicListUI.java	25 Nov 2005 16:26:12 -0000
@@ -524,7 +524,14 @@
      */
     public void mouseDragged(MouseEvent event)
     {
-      // TODO: What should be done here, if anything?
+      Point click = event.getPoint();
+      int index = locationToIndex(list, click);
+      if (index == -1)
+        return;
+      if (!event.isShiftDown() && !event.isControlDown())
+        list.setSelectedIndex(index);
+      
+      list.ensureIndexIsVisible(list.getLeadSelectionIndex());
     }
 
     /**
Index: javax/swing/plaf/metal/MetalFileChooserUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalFileChooserUI.java,v
retrieving revision 1.4
diff -u -r1.4 MetalFileChooserUI.java
--- javax/swing/plaf/metal/MetalFileChooserUI.java	25 Nov 2005 16:17:48 -0000	1.4
+++ javax/swing/plaf/metal/MetalFileChooserUI.java	25 Nov 2005 16:26:12 -0000
@@ -72,6 +72,7 @@
 import javax.swing.JScrollPane;
 import javax.swing.JTextField;
 import javax.swing.JToggleButton;
+import javax.swing.ListSelectionModel;
 import javax.swing.SwingUtilities;
 import javax.swing.UIManager;
 import javax.swing.event.ListSelectionEvent;
@@ -112,11 +113,16 @@
     public void propertyChange(PropertyChangeEvent e)
     {
       JFileChooser filechooser = getFileChooser();
-      // FIXME: Multiple file selection waiting on JList multiple selection
-      // bug.
+      
       String n = e.getPropertyName();
-
-      if (n.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY))
+      if (n.equals(JFileChooser.MULTI_SELECTION_ENABLED_CHANGED_PROPERTY))
+        {
+          if (filechooser.isMultiSelectionEnabled())
+            fileList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
+          else
+            fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+        }
+      else if (n.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY))
         {
           File file = filechooser.getSelectedFile();
           if (file == null)
@@ -144,7 +150,6 @@
           setDirectory(currentDirectory);
           boolean hasParent = (currentDirectory.getParentFile() != null);
           getChangeToParentDirectoryAction().setEnabled(hasParent);
-          //boxEntries();
         }
       
       else if (n.equals(JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY))
@@ -374,8 +379,6 @@
       setIcon(fileView.getIcon(file));
       setText(fileView.getName(file));
       
-      // FIXME: we can't go creating a new border here every time...
-      //setBorder(BorderFactory.createEmptyBorder(0, index * 8, 0, 0));
       if (isSelected)
         {
           setBackground(list.getSelectionBackground());
@@ -426,6 +429,7 @@
       File f = (File) value;
       setText(v.getName(f));
       setIcon(v.getIcon(f));
+      setOpaque(true);
       if (isSelected)
         {
           setBackground(list.getSelectionBackground());
@@ -618,12 +622,15 @@
   }
 
   /**
-   * A mouse listener for the [EMAIL PROTECTED] JFileChooser}.  This class is not yet
-   * implemented.
+   * A mouse listener for the [EMAIL PROTECTED] JFileChooser}.
    */
   protected class SingleClickListener
     extends MouseAdapter
   {
+    
+    /** Stores instance of the list */
+    JList list;
+    
     /**
      * Creates a new listener.
      * 
@@ -631,7 +638,7 @@
      */
     public SingleClickListener(JList list)
     {
-      // FIXME: implement
+      this.list = list;
     }
     
     /**
@@ -847,27 +854,27 @@
      
      this.cancelButtonMnemonic = 0;
      this.cancelButtonText = "Cancel";
-     this.cancelButtonToolTipText = "Cancel ToolTip Text";
+     this.cancelButtonToolTipText = "Abort file chooser dialog";
      
      this.directoryOpenButtonMnemonic = 0;
      this.directoryOpenButtonText = "Open";
-     this.directoryOpenButtonToolTipText = "Open ToolTip Text";
+     this.directoryOpenButtonToolTipText = "Open selected directory";
      
      this.helpButtonMnemonic = 0;
      this.helpButtonText = "Help";
-     this.helpButtonToolTipText = "Help";
+     this.helpButtonToolTipText = "Filechooser help";
      
      this.openButtonMnemonic = 0;
      this.openButtonText = "Open";
-     this.openButtonToolTipText = "Open ToolTip Text";
+     this.openButtonToolTipText = "Open selected file";
      
      this.saveButtonMnemonic = 0;
      this.saveButtonText = "Save";
-     this.saveButtonToolTipText = "Save ToolTip Text";
+     this.saveButtonToolTipText = "Save selected file";
      
      this.updateButtonMnemonic = 0;
      this.updateButtonText = "Update";
-     this.updateButtonToolTipText = "Update ToolTip Text";   
+     this.updateButtonToolTipText = "Update directory listing";   
   }
   
   /**
_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to