jdk/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java
changeset 25178 dbab904451e9
parent 24969 afa6934dd8e8
child 25565 ce603b34c98d
equal deleted inserted replaced
25177:487a5e71f6dd 25178:dbab904451e9
   136             fileNameLabel.setText(fileNameLabelText);
   136             fileNameLabel.setText(fileNameLabelText);
   137             fileNameLabel.setDisplayedMnemonic(fileNameLabelMnemonic);
   137             fileNameLabel.setDisplayedMnemonic(fileNameLabelMnemonic);
   138         }
   138         }
   139     }
   139     }
   140 
   140 
   141     //
   141     /**
   142     // ComponentUI Interface Implementation methods
   142      * Constructs a new instance of {@code MetalFileChooserUI}.
   143     //
   143      *
       
   144      * @param c a component
       
   145      * @return a new instance of {@code MetalFileChooserUI}
       
   146      */
   144     public static ComponentUI createUI(JComponent c) {
   147     public static ComponentUI createUI(JComponent c) {
   145         return new MetalFileChooserUI((JFileChooser) c);
   148         return new MetalFileChooserUI((JFileChooser) c);
   146     }
   149     }
   147 
   150 
       
   151     /**
       
   152      * Constructs a new instance of {@code MetalFileChooserUI}.
       
   153      *
       
   154      * @param filechooser a {@code JFileChooser}
       
   155      */
   148     public MetalFileChooserUI(JFileChooser filechooser) {
   156     public MetalFileChooserUI(JFileChooser filechooser) {
   149         super(filechooser);
   157         super(filechooser);
   150     }
   158     }
   151 
   159 
   152     public void installUI(JComponent c) {
   160     public void installUI(JComponent c) {
   444         }
   452         }
   445 
   453 
   446         groupLabels(new AlignedLabel[] { fileNameLabel, filesOfTypeLabel });
   454         groupLabels(new AlignedLabel[] { fileNameLabel, filesOfTypeLabel });
   447     }
   455     }
   448 
   456 
       
   457     /**
       
   458      * Returns the button panel.
       
   459      *
       
   460      * @return the button panel
       
   461      */
   449     protected JPanel getButtonPanel() {
   462     protected JPanel getButtonPanel() {
   450         if (buttonPanel == null) {
   463         if (buttonPanel == null) {
   451             buttonPanel = new JPanel();
   464             buttonPanel = new JPanel();
   452         }
   465         }
   453         return buttonPanel;
   466         return buttonPanel;
   454     }
   467     }
   455 
   468 
       
   469     /**
       
   470      * Returns the bottom panel.
       
   471      *
       
   472      * @return the bottom panel
       
   473      */
   456     protected JPanel getBottomPanel() {
   474     protected JPanel getBottomPanel() {
   457         if(bottomPanel == null) {
   475         if(bottomPanel == null) {
   458             bottomPanel = new JPanel();
   476             bottomPanel = new JPanel();
   459         }
   477         }
   460         return bottomPanel;
   478         return bottomPanel;
   501         super.installListeners(fc);
   519         super.installListeners(fc);
   502         ActionMap actionMap = getActionMap();
   520         ActionMap actionMap = getActionMap();
   503         SwingUtilities.replaceUIActionMap(fc, actionMap);
   521         SwingUtilities.replaceUIActionMap(fc, actionMap);
   504     }
   522     }
   505 
   523 
       
   524     /**
       
   525      * Returns an instance of {@code ActionMap}.
       
   526      *
       
   527      * @return an instance of {@code ActionMap}
       
   528      */
   506     protected ActionMap getActionMap() {
   529     protected ActionMap getActionMap() {
   507         return createActionMap();
   530         return createActionMap();
   508     }
   531     }
   509 
   532 
       
   533     /**
       
   534      * Constructs an instance of {@code ActionMap}.
       
   535      *
       
   536      * @return an instance of {@code ActionMap}
       
   537      */
   510     protected ActionMap createActionMap() {
   538     protected ActionMap createActionMap() {
   511         ActionMap map = new ActionMapUIResource();
   539         ActionMap map = new ActionMapUIResource();
   512         FilePane.addActionsToMap(map, filePane.getActions());
   540         FilePane.addActionsToMap(map, filePane.getActions());
   513         return map;
   541         return map;
   514     }
   542     }
   515 
   543 
       
   544     /**
       
   545      * Constructs a details view.
       
   546      *
       
   547      * @param fc a {@code JFileChooser}
       
   548      * @return the list
       
   549      */
   516     protected JPanel createList(JFileChooser fc) {
   550     protected JPanel createList(JFileChooser fc) {
   517         return filePane.createList();
   551         return filePane.createList();
   518     }
   552     }
   519 
   553 
       
   554     /**
       
   555      * Constructs a details view.
       
   556      *
       
   557      * @param fc a {@code JFileChooser}
       
   558      * @return the details view
       
   559      */
   520     protected JPanel createDetailsView(JFileChooser fc) {
   560     protected JPanel createDetailsView(JFileChooser fc) {
   521         return filePane.createDetailsView();
   561         return filePane.createDetailsView();
   522     }
   562     }
   523 
   563 
   524     /**
   564     /**
   531         return super.createListSelectionListener(fc);
   571         return super.createListSelectionListener(fc);
   532     }
   572     }
   533 
   573 
   534     // Obsolete class, not used in this version.
   574     // Obsolete class, not used in this version.
   535     protected class SingleClickListener extends MouseAdapter {
   575     protected class SingleClickListener extends MouseAdapter {
   536         public  SingleClickListener(JList list) {
   576         /**
       
   577          * Constructs an instance of {@code SingleClickListener}.
       
   578          *
       
   579          * @param list an instance of {@code JList}
       
   580          */
       
   581         public SingleClickListener(JList list) {
   537         }
   582         }
   538     }
   583     }
   539 
   584 
   540     // Obsolete class, not used in this version.
   585     // Obsolete class, not used in this version.
   541     @SuppressWarnings("serial") // Superclass is not serializable across versions
   586     @SuppressWarnings("serial") // Superclass is not serializable across versions
   786                 }
   831                 }
   787             }
   832             }
   788         };
   833         };
   789     }
   834     }
   790 
   835 
   791 
   836     /**
       
   837      * Removes control buttons from bottom panel.
       
   838      */
   792     protected void removeControlButtons() {
   839     protected void removeControlButtons() {
   793         getBottomPanel().remove(getButtonPanel());
   840         getBottomPanel().remove(getButtonPanel());
   794     }
   841     }
   795 
   842 
       
   843     /**
       
   844      * Adds control buttons to bottom panel.
       
   845      */
   796     protected void addControlButtons() {
   846     protected void addControlButtons() {
   797         getBottomPanel().add(getButtonPanel());
   847         getBottomPanel().add(getButtonPanel());
   798     }
   848     }
   799 
   849 
   800     public void ensureFileIsVisible(JFileChooser fc, File f) {
   850     public void ensureFileIsVisible(JFileChooser fc, File f) {
   840                 approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
   890                 approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
   841             }
   891             }
   842         }
   892         }
   843     }
   893     }
   844 
   894 
       
   895     /**
       
   896      * Returns the directory name.
       
   897      *
       
   898      * @return the directory name
       
   899      */
   845     public String getDirectoryName() {
   900     public String getDirectoryName() {
   846         // PENDING(jeff) - get the name from the directory combobox
   901         // PENDING(jeff) - get the name from the directory combobox
   847         return null;
   902         return null;
   848     }
   903     }
   849 
   904 
       
   905     /**
       
   906      * Sets the directory name.
       
   907      *
       
   908      * @param dirname the directory name
       
   909      */
   850     public void setDirectoryName(String dirname) {
   910     public void setDirectoryName(String dirname) {
   851         // PENDING(jeff) - set the name in the directory combobox
   911         // PENDING(jeff) - set the name in the directory combobox
   852     }
   912     }
   853 
   913 
       
   914     /**
       
   915      * Constructs a new instance of {@code DirectoryComboBoxRenderer}.
       
   916      *
       
   917      * @param fc a {@code JFileChooser}
       
   918      * @return a new instance of {@code DirectoryComboBoxRenderer}
       
   919      */
   854     protected DirectoryComboBoxRenderer createDirectoryComboBoxRenderer(JFileChooser fc) {
   920     protected DirectoryComboBoxRenderer createDirectoryComboBoxRenderer(JFileChooser fc) {
   855         return new DirectoryComboBoxRenderer();
   921         return new DirectoryComboBoxRenderer();
   856     }
   922     }
   857 
   923 
   858     //
   924     //
   904             return icon.getIconHeight();
   970             return icon.getIconHeight();
   905         }
   971         }
   906 
   972 
   907     }
   973     }
   908 
   974 
   909     //
   975     /**
   910     // DataModel for DirectoryComboxbox
   976      * Constructs a new instance of {@code DataModel} for {@code DirectoryComboBox}.
   911     //
   977      *
       
   978      * @param fc a {@code JFileChooser}
       
   979      * @return a new instance of {@code DataModel} for {@code DirectoryComboBox}
       
   980      */
   912     protected DirectoryComboBoxModel createDirectoryComboBoxModel(JFileChooser fc) {
   981     protected DirectoryComboBoxModel createDirectoryComboBoxModel(JFileChooser fc) {
   913         return new DirectoryComboBoxModel();
   982         return new DirectoryComboBoxModel();
   914     }
   983     }
   915 
   984 
   916     /**
   985     /**
   922         int[] depths = null;
   991         int[] depths = null;
   923         File selectedDirectory = null;
   992         File selectedDirectory = null;
   924         JFileChooser chooser = getFileChooser();
   993         JFileChooser chooser = getFileChooser();
   925         FileSystemView fsv = chooser.getFileSystemView();
   994         FileSystemView fsv = chooser.getFileSystemView();
   926 
   995 
       
   996         /**
       
   997          * Constructs an instance of {@code DirectoryComboBoxModel}.
       
   998          */
   927         public DirectoryComboBoxModel() {
   999         public DirectoryComboBoxModel() {
   928             // Add the current directory to the model, and make it the
  1000             // Add the current directory to the model, and make it the
   929             // selectedDirectory
  1001             // selectedDirectory
   930             File dir = getFileChooser().getCurrentDirectory();
  1002             File dir = getFileChooser().getCurrentDirectory();
   931             if(dir != null) {
  1003             if(dir != null) {
  1015                     }
  1087                     }
  1016                 }
  1088                 }
  1017             }
  1089             }
  1018         }
  1090         }
  1019 
  1091 
       
  1092         /**
       
  1093          * Returns the depth of {@code i}-th file.
       
  1094          *
       
  1095          * @param i an index
       
  1096          * @return the depth of {@code i}-th file
       
  1097          */
  1020         public int getDepth(int i) {
  1098         public int getDepth(int i) {
  1021             return (depths != null && i >= 0 && i < depths.length) ? depths[i] : 0;
  1099             return (depths != null && i >= 0 && i < depths.length) ? depths[i] : 0;
  1022         }
  1100         }
  1023 
  1101 
  1024         public void setSelectedItem(Object selectedDirectory) {
  1102         public void setSelectedItem(Object selectedDirectory) {
  1037         public Object getElementAt(int index) {
  1115         public Object getElementAt(int index) {
  1038             return directories.elementAt(index);
  1116             return directories.elementAt(index);
  1039         }
  1117         }
  1040     }
  1118     }
  1041 
  1119 
  1042     //
  1120     /**
  1043     // Renderer for Types ComboBox
  1121      * Constructs a {@code Renderer} for types {@code ComboBox}.
  1044     //
  1122      *
       
  1123      * @return a {@code Renderer} for types {@code ComboBox}
       
  1124      */
  1045     protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
  1125     protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
  1046         return new FilterComboBoxRenderer();
  1126         return new FilterComboBoxRenderer();
  1047     }
  1127     }
  1048 
  1128 
  1049     /**
  1129     /**
  1063 
  1143 
  1064             return this;
  1144             return this;
  1065         }
  1145         }
  1066     }
  1146     }
  1067 
  1147 
  1068     //
  1148     /**
  1069     // DataModel for Types Comboxbox
  1149      * Constructs a {@code DataModel} for types {@code ComboBox}.
  1070     //
  1150      *
       
  1151      * @return a {@code DataModel} for types {@code ComboBox}
       
  1152      */
  1071     protected FilterComboBoxModel createFilterComboBoxModel() {
  1153     protected FilterComboBoxModel createFilterComboBoxModel() {
  1072         return new FilterComboBoxModel();
  1154         return new FilterComboBoxModel();
  1073     }
  1155     }
  1074 
  1156 
  1075     /**
  1157     /**
  1076      * Data model for a type-face selection combo-box.
  1158      * Data model for a type-face selection combo-box.
  1077      */
  1159      */
  1078     @SuppressWarnings("serial") // Same-version serialization only
  1160     @SuppressWarnings("serial") // Same-version serialization only
  1079     protected class FilterComboBoxModel extends AbstractListModel<Object> implements ComboBoxModel<Object>, PropertyChangeListener {
  1161     protected class FilterComboBoxModel extends AbstractListModel<Object> implements ComboBoxModel<Object>, PropertyChangeListener {
       
  1162 
       
  1163         /**
       
  1164          * An array of file filters.
       
  1165          */
  1080         protected FileFilter[] filters;
  1166         protected FileFilter[] filters;
       
  1167 
       
  1168         /**
       
  1169          * Constructs an instance of {@code FilterComboBoxModel}.
       
  1170          */
  1081         protected FilterComboBoxModel() {
  1171         protected FilterComboBoxModel() {
  1082             super();
  1172             super();
  1083             filters = getFileChooser().getChoosableFileFilters();
  1173             filters = getFileChooser().getChoosableFileFilters();
  1084         }
  1174         }
  1085 
  1175 
  1140                 return null;
  1230                 return null;
  1141             }
  1231             }
  1142         }
  1232         }
  1143     }
  1233     }
  1144 
  1234 
       
  1235     /**
       
  1236      * Invokes when {@code ListSelectionEvent} occurs.
       
  1237      *
       
  1238      * @param e an instance of {@code ListSelectionEvent}
       
  1239      */
  1145     public void valueChanged(ListSelectionEvent e) {
  1240     public void valueChanged(ListSelectionEvent e) {
  1146         JFileChooser fc = getFileChooser();
  1241         JFileChooser fc = getFileChooser();
  1147         File f = fc.getSelectedFile();
  1242         File f = fc.getSelectedFile();
  1148         if (!e.getValueIsAdjusting() && f != null && !getFileChooser().isTraversable(f)) {
  1243         if (!e.getValueIsAdjusting() && f != null && !getFileChooser().isTraversable(f)) {
  1149             setFileName(fileNameString(f));
  1244             setFileName(fileNameString(f));
  1153     /**
  1248     /**
  1154      * Acts when DirectoryComboBox has changed the selected item.
  1249      * Acts when DirectoryComboBox has changed the selected item.
  1155      */
  1250      */
  1156     @SuppressWarnings("serial") // Superclass is not serializable across versions
  1251     @SuppressWarnings("serial") // Superclass is not serializable across versions
  1157     protected class DirectoryComboBoxAction extends AbstractAction {
  1252     protected class DirectoryComboBoxAction extends AbstractAction {
       
  1253 
       
  1254         /**
       
  1255          * Constructs a new instance of {@code DirectoryComboBoxAction}.
       
  1256          */
  1158         protected DirectoryComboBoxAction() {
  1257         protected DirectoryComboBoxAction() {
  1159             super("DirectoryComboBoxAction");
  1258             super("DirectoryComboBoxAction");
  1160         }
  1259         }
  1161 
  1260 
  1162         public void actionPerformed(ActionEvent e) {
  1261         public void actionPerformed(ActionEvent e) {