/[classpath]/classpath/javax/swing/plaf/metal/MetalFileChooserUI.java
ViewVC logotype

Diff of /classpath/javax/swing/plaf/metal/MetalFileChooserUI.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by langel, Fri Nov 25 16:33:24 2005 UTC revision 1.6 by langel, Fri Nov 25 21:58:39 2005 UTC
# Line 45  import java.awt.Dimension; Line 45  import java.awt.Dimension;
45  import java.awt.GridLayout;  import java.awt.GridLayout;
46  import java.awt.Insets;  import java.awt.Insets;
47  import java.awt.LayoutManager;  import java.awt.LayoutManager;
48    import java.awt.Point;
49  import java.awt.Window;  import java.awt.Window;
50  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
51  import java.awt.event.MouseAdapter;  import java.awt.event.MouseAdapter;
52  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
53    
54  import java.beans.PropertyChangeEvent;  import java.beans.PropertyChangeEvent;
55  import java.beans.PropertyChangeListener;  import java.beans.PropertyChangeListener;
56    
57  import java.io.File;  import java.io.File;
 import java.util.List;  
58    
59  import javax.swing.AbstractAction;  import javax.swing.AbstractAction;
60  import javax.swing.AbstractListModel;  import javax.swing.AbstractListModel;
# Line 83  import javax.swing.filechooser.FileView; Line 85  import javax.swing.filechooser.FileView;
85  import javax.swing.plaf.ComponentUI;  import javax.swing.plaf.ComponentUI;
86  import javax.swing.plaf.basic.BasicFileChooserUI;  import javax.swing.plaf.basic.BasicFileChooserUI;
87    
88    import java.util.List;
89    
90    
91  /**  /**
92   * A UI delegate for the {@link JFileChooser} component.  This class is only   * A UI delegate for the {@link JFileChooser} component.  This class is only
# Line 601  public class MetalFileChooserUI Line 605  public class MetalFileChooserUI
605       */       */
606      protected MetalFileChooserSelectionListener()      protected MetalFileChooserSelectionListener()
607      {      {
608          // Do nothing here.
609      }      }
610    
611      /**      /**
612       * DOCUMENT ME!       * Makes changes to different properties when
613         * a value has changed in the filechooser's selection.
614       *       *
615       * @param e DOCUMENT ME!       * @param e - the list selection event that occured.
616       */       */
617      public void valueChanged(ListSelectionEvent e)      public void valueChanged(ListSelectionEvent e)
618      {      {
# Line 623  public class MetalFileChooserUI Line 629  public class MetalFileChooserUI
629    
630    /**    /**
631     * A mouse listener for the {@link JFileChooser}.     * A mouse listener for the {@link JFileChooser}.
632       * This listener is used for editing filenames.
633     */     */
634    protected class SingleClickListener    protected class SingleClickListener
635      extends MouseAdapter      extends MouseAdapter
# Line 631  public class MetalFileChooserUI Line 638  public class MetalFileChooserUI
638      /** Stores instance of the list */      /** Stores instance of the list */
639      JList list;      JList list;
640            
641        /**
642         * Stores the current file that is being edited.
643         * It is null if nothing is currently being edited.
644         */
645        File editFile;
646        
647        /** The current file chooser. */
648        JFileChooser fc;
649        
650        /** The index of the last file selected. */
651        int lastSelected;
652        
653        /** The textfield used for editing. */
654        JTextField editField;
655        
656      /**      /**
657       * Creates a new listener.       * Creates a new listener.
658       *       *
# Line 639  public class MetalFileChooserUI Line 661  public class MetalFileChooserUI
661      public SingleClickListener(JList list)      public SingleClickListener(JList list)
662      {      {
663        this.list = list;        this.list = list;
664          editFile = null;
665          fc = getFileChooser();
666          lastSelected = -1;
667      }      }
668            
669      /**      /**
# Line 648  public class MetalFileChooserUI Line 673  public class MetalFileChooserUI
673       */       */
674      public void mouseClicked(MouseEvent e)      public void mouseClicked(MouseEvent e)
675      {      {
676        // FIXME: implement        if (e.getClickCount() == 1)
677            {
678              int index = list.locationToIndex(e.getPoint());
679              File[] sf = fc.getSelectedFiles();
680              if ((!fc.isMultiSelectionEnabled() || (sf != null && sf.length <= 1))
681                  && index >= 0 && editFile == null && list.isSelectedIndex(index))
682                {
683                  if (lastSelected == index)
684                    editFile(index);
685                  lastSelected = index;
686                }
687              else if (editFile != null)
688                {
689                  completeEditing();
690                  editFile = null;
691                  lastSelected = -1;
692                }
693            }
694        }
695        
696        /**
697         * Sets up the text editor for the current file.
698         *
699         * @param index -
700         *          the current index of the item in the list to be edited.
701         */
702        private void editFile(int index)
703        {
704          list.ensureIndexIsVisible(index);
705          editFile = (File) list.getModel().getElementAt(index);
706          if (editFile.canWrite())
707            {
708              Point p = list.indexToLocation(index);
709              editField = new JTextField(editFile.getName());
710              // FIXME: add action listener
711              list.add(editField);
712              editField.requestFocus();
713              editField.selectAll();          
714              list.revalidate();
715              list.repaint();
716            }
717          else
718            {
719              editField = null;
720              editFile = null;
721              lastSelected = -1;
722            }
723        }
724        
725        /**
726         * Completes the editing.
727         */
728        private void completeEditing()
729        {
730          if (editField != null)
731            {
732              String text = editField.getText();
733              if (text != null && !text.equals(""))
734                editFile.renameTo(new File(text));
735              list.remove(editField);
736              list.revalidate();
737              list.repaint();
738            }
739      }      }
740    }    }
741    
# Line 697  public class MetalFileChooserUI Line 784  public class MetalFileChooserUI
784        
785    /** The filter combo box model. */    /** The filter combo box model. */
786    private FilterComboBoxModel filterModel;    private FilterComboBoxModel filterModel;
787    
788      /** The action map. */
789      private ActionMap actionMap;
790        
791    /**    /**
792     * A factory method that returns a UI delegate for the specified     * A factory method that returns a UI delegate for the specified
# Line 724  public class MetalFileChooserUI Line 814  public class MetalFileChooserUI
814    
815    public void installUI(JComponent c)    public void installUI(JComponent c)
816    {    {
     // FIXME: do something here  
817      super.installUI(c);      super.installUI(c);
818        actionMap = createActionMap();
819    }    }
820        
821    public void uninstallUI(JComponent c)    public void uninstallUI(JComponent c)
822    {    {
     // FIXME: do something here  
823      super.uninstallUI(c);      super.uninstallUI(c);
824        actionMap = null;
825    }    }
826        
827    /**    /**
# Line 848  public class MetalFileChooserUI Line 938  public class MetalFileChooserUI
938    protected void installStrings(JFileChooser fc)    protected void installStrings(JFileChooser fc)
939    {    {
940       super.installStrings(fc);       super.installStrings(fc);
941       directoryLabel = "Look In: ";  // FIXME: localise       directoryLabel = "Look In: ";
942       fileLabel = "File Name: ";  // FIXME: localise       fileLabel = "File Name: ";
943       filterLabel = "Files of Type: ";  // FIXME: localise       filterLabel = "Files of Type: ";
944            
945       this.cancelButtonMnemonic = 0;       this.cancelButtonMnemonic = 0;
946       this.cancelButtonText = "Cancel";       this.cancelButtonText = "Cancel";
# Line 900  public class MetalFileChooserUI Line 990  public class MetalFileChooserUI
990        
991    protected ActionMap getActionMap()    protected ActionMap getActionMap()
992    {    {
993      // FIXME: implement this      if (actionMap == null)
994      return null;        actionMap = createActionMap();
995        return actionMap;
996    }    }
997        
998    /**    /**
# Line 929  public class MetalFileChooserUI Line 1020  public class MetalFileChooserUI
1020    {    {
1021      JPanel panel = new JPanel(new BorderLayout());      JPanel panel = new JPanel(new BorderLayout());
1022      fileList = new JList(getModel());      fileList = new JList(getModel());
1023                fileList.setLayoutOrientation(JList.VERTICAL_WRAP);
     // a bug is preventing the vertical wrap from working right now,  
     // uncomment the next line once that is fixed...  
     //fileList.setLayoutOrientation(JList.VERTICAL_WRAP);  
1024      fileList.setVisibleRowCount(0);      fileList.setVisibleRowCount(0);
1025      fileList.setCellRenderer(new FileRenderer());      fileList.setCellRenderer(new FileRenderer());
1026      panel.add(new JScrollPane(fileList));      panel.add(new JScrollPane(fileList));
# Line 1103  public class MetalFileChooserUI Line 1191  public class MetalFileChooserUI
1191        
1192    protected void removeControlButtons()    protected void removeControlButtons()
1193    {    {
1194      // FIXME: implement this      controls.removeAll();
1195    }    }
1196        
1197    public void ensureFileIsVisible(JFileChooser fc, File f)    public void ensureFileIsVisible(JFileChooser fc, File f)

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26