classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: MetalFileChooserUI


From: David Gilbert
Subject: [cp-patches] FYI: MetalFileChooserUI
Date: Thu, 13 Oct 2005 13:53:32 +0000
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050728)

I committed some more pieces of this class, it is still not usable, but I'm making good progress. This patch shouldn't get in the way of anything and keeps the diffs between CVS and my working tree to a minimum:

2005-10-13  David Gilbert  <address@hidden>

        * javax/swing/plaf/metal/MetalFileChooserUI.java
        (DirectoryComboBoxAction): new inner class,
        (FileRenderer): new inner class,
        (directoryModel): new private field.

Regards,

Dave
Index: javax/swing/plaf/metal/MetalFileChooserUI.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalFileChooserUI.java,v
retrieving revision 1.1
diff -u -r1.1 MetalFileChooserUI.java
--- javax/swing/plaf/metal/MetalFileChooserUI.java      21 Sep 2005 10:59:46 
-0000      1.1
+++ javax/swing/plaf/metal/MetalFileChooserUI.java      13 Oct 2005 12:47:10 
-0000
@@ -39,19 +39,23 @@
 package javax.swing.plaf.metal;
 
 import java.awt.Component;
+import java.awt.event.ActionEvent;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.io.File;
 import java.util.List;
 
+import javax.swing.AbstractAction;
 import javax.swing.AbstractListModel;
 import javax.swing.ComboBoxModel;
 import javax.swing.DefaultListCellRenderer;
 import javax.swing.JComponent;
 import javax.swing.JFileChooser;
 import javax.swing.JList;
+import javax.swing.UIManager;
 import javax.swing.filechooser.FileFilter;
 import javax.swing.filechooser.FileSystemView;
+import javax.swing.filechooser.FileView;
 import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.basic.BasicFileChooserUI;
 
@@ -157,6 +161,85 @@
   }
 
   /**
+   * Handles changes to the selection in the directory combo box.
+   */
+  protected class DirectoryComboBoxAction
+    extends AbstractAction
+  {
+    /**
+     * Creates a new action.
+     */
+    protected DirectoryComboBoxAction()
+    {
+    }
+    
+    /**
+     * Handles the action event.
+     * 
+     * @param e  the event.
+     */
+    public void actionPerformed(ActionEvent e)
+    {
+      JFileChooser fc = getFileChooser();
+      fc.setCurrentDirectory((File) directoryModel.getSelectedItem());
+    }
+  }
+
+  /**
+   * A renderer for the files and directories in the file chooser.
+   */
+  protected class FileRenderer
+    extends DefaultListCellRenderer
+  {
+    
+    /**
+     * Creates a new renderer.
+     */
+    protected FileRenderer()
+    {
+    }
+    
+    /**
+     * Returns a component that can render the specified value.
+     * 
+     * @param list  the list.
+     * @param value  the value (a address@hidden File}).
+     * @param index  the index.
+     * @param isSelected  is the item selected?
+     * @param cellHasFocus  does the item have the focus?
+     * 
+     * @return The renderer.
+     */
+    public Component getListCellRendererComponent(JList list, Object value,
+        int index, boolean isSelected, boolean cellHasFocus)
+    {
+      FileView v = getFileView(getFileChooser());
+      File f = (File) value;
+      setText(v.getName(f));
+      setIcon(v.getIcon(f));
+      if (isSelected)
+        {
+          setBackground(list.getSelectionBackground());
+          setForeground(list.getSelectionForeground());
+        }
+      else
+        {
+          setBackground(list.getBackground());
+          setForeground(list.getForeground());
+        }
+
+      setEnabled(list.isEnabled());
+      setFont(list.getFont());
+
+      if (cellHasFocus)
+        setBorder(UIManager.getBorder("List.focusCellHighlightBorder"));
+      else
+        setBorder(noFocusBorder);
+      return this;
+    }
+  }
+
+  /**
    * A combo box model for the file selection filters.
    */
   protected class FilterComboBoxModel
@@ -289,6 +372,9 @@
     }
   }
 
+  /** The model for the directory combo box. */
+  private DirectoryComboBoxModel directoryModel;
+  
   /**
    * A factory method that returns a UI delegate for the specified
    * component.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]