changeset 825:8b842701af50

6776856: Code with useShellFolder field shuold be simplify Reviewed-by: peterz
author rupashka
date Wed, 26 Nov 2008 19:38:46 +0300
parents be2b6b030a79
children 5784f5dfe3ac
files src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java src/share/classes/sun/swing/FilePane.java src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java
diffstat 4 files changed, 9 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java	Wed Nov 26 19:08:41 2008 +0300
+++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java	Wed Nov 26 19:38:46 2008 +0300
@@ -70,7 +70,6 @@
     private JTextField filenameTextField;
     private FilePane filePane;
     private WindowsPlacesBar placesBar;
-    private boolean useShellFolder;
 
     private JButton approveButton;
     private JButton cancelButton;
@@ -210,10 +209,6 @@
         public ListSelectionListener createListSelectionListener() {
             return WindowsFileChooserUI.this.createListSelectionListener(getFileChooser());
         }
-
-        public boolean usesShellFolder() {
-            return useShellFolder;
-        }
     }
 
     public void installComponents(JFileChooser fc) {
@@ -625,15 +620,8 @@
         // Decide whether to use the ShellFolder class to populate shortcut
         // panel and combobox.
         JFileChooser fc = getFileChooser();
-        Boolean prop =
-            (Boolean)fc.getClientProperty("FileChooser.useShellFolder");
-        if (prop != null) {
-            useShellFolder = prop.booleanValue();
-        } else {
-            useShellFolder = fc.getFileSystemView().equals(FileSystemView.getFileSystemView());
-        }
         if (OS_VERSION.compareTo(OSInfo.WINDOWS_ME) >= 0) {
-            if (useShellFolder) {
+            if (FilePane.usesShellFolder(fc)) {
                 if (placesBar == null && !UIManager.getBoolean("FileChooser.noPlacesBar")) {
                     placesBar = new WindowsPlacesBar(fc, XPStyle.getXP() != null);
                     fc.add(placesBar, BorderLayout.BEFORE_LINE_BEGINS);
@@ -1149,6 +1137,8 @@
                 return;
             }
 
+            boolean useShellFolder = FilePane.usesShellFolder(chooser);
+
             directories.clear();
 
             File[] baseFolders;
--- a/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java	Wed Nov 26 19:08:41 2008 +0300
+++ b/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java	Wed Nov 26 19:38:46 2008 +0300
@@ -68,8 +68,6 @@
     private JToggleButton listViewButton;
     private JToggleButton detailsViewButton;
 
-    private boolean useShellFolder;
-
     private JButton approveButton;
     private JButton cancelButton;
 
@@ -204,10 +202,6 @@
         public ListSelectionListener createListSelectionListener() {
             return MetalFileChooserUI.this.createListSelectionListener(getFileChooser());
         }
-
-        public boolean usesShellFolder() {
-            return useShellFolder;
-        }
     }
 
     public void installComponents(JFileChooser fc) {
@@ -219,8 +213,6 @@
         filePane = new FilePane(new MetalFileChooserUIAccessor());
         fc.addPropertyChangeListener(filePane);
 
-        updateUseShellFolder();
-
         // ********************************* //
         // **** Construct the top panel **** //
         // ********************************* //
@@ -448,19 +440,6 @@
         groupLabels(new AlignedLabel[] { fileNameLabel, filesOfTypeLabel });
     }
 
-    private void updateUseShellFolder() {
-        // Decide whether to use the ShellFolder class to populate shortcut
-        // panel and combobox.
-        JFileChooser fc = getFileChooser();
-        Boolean prop =
-            (Boolean)fc.getClientProperty("FileChooser.useShellFolder");
-        if (prop != null) {
-            useShellFolder = prop.booleanValue();
-        } else {
-            useShellFolder = fc.getFileSystemView().equals(FileSystemView.getFileSystemView());
-        }
-    }
-
     protected JPanel getButtonPanel() {
         if (buttonPanel == null) {
             buttonPanel = new JPanel();
@@ -786,7 +765,6 @@
                         cc.applyComponentOrientation(o);
                     }
                 } else if (s == "FileChooser.useShellFolder") {
-                    updateUseShellFolder();
                     doDirectoryChanged(e);
                 } else if (s.equals("ancestor")) {
                     if (e.getOldValue() == null && e.getNewValue() != null) {
@@ -953,6 +931,8 @@
                 return;
             }
 
+            boolean useShellFolder = FilePane.usesShellFolder(chooser);
+
             directories.clear();
 
             File[] baseFolders;
--- a/src/share/classes/sun/swing/FilePane.java	Wed Nov 26 19:08:41 2008 +0300
+++ b/src/share/classes/sun/swing/FilePane.java	Wed Nov 26 19:38:46 2008 +0300
@@ -689,7 +689,7 @@
 
         void updateColumnInfo() {
             File dir = chooser.getCurrentDirectory();
-            if (dir != null && fileChooserUIAccessor.usesShellFolder()) {
+            if (dir != null && usesShellFolder(chooser)) {
                 try {
                     dir = ShellFolder.getShellFolder(dir);
                 } catch (FileNotFoundException e) {
@@ -1947,7 +1947,7 @@
         if (f instanceof ShellFolder) {
             return ((ShellFolder) f).isFileSystem();
         } else {
-            if (fileChooserUIAccessor.usesShellFolder()) {
+            if (usesShellFolder(getFileChooser())) {
                 try {
                     return ShellFolder.getShellFolder(f).isFileSystem();
                 } catch (FileNotFoundException ex) {
@@ -1985,6 +1985,5 @@
         public Action getNewFolderAction();
         public MouseListener createDoubleClickListener(JList list);
         public ListSelectionListener createListSelectionListener();
-        public boolean usesShellFolder();
     }
 }
--- a/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java	Wed Nov 26 19:08:41 2008 +0300
+++ b/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java	Wed Nov 26 19:38:46 2008 +0300
@@ -71,8 +71,6 @@
     private JToggleButton listViewButton;
     private JToggleButton detailsViewButton;
 
-    private boolean useShellFolder;
-
     private boolean readOnly;
 
     private JPanel buttonPanel;
@@ -185,10 +183,6 @@
         public ListSelectionListener createListSelectionListener() {
             return SynthFileChooserUIImpl.this.createListSelectionListener(getFileChooser());
         }
-
-        public boolean usesShellFolder() {
-            return useShellFolder;
-        }
     }
 
     protected void installDefaults(JFileChooser fc) {
@@ -201,8 +195,6 @@
 
         SynthContext context = getContext(fc, ENABLED);
 
-        updateUseShellFolder();
-
         fc.setLayout(new BorderLayout(0, 11));
 
         // ********************************* //
@@ -432,20 +424,6 @@
         super.uninstallListeners(fc);
     }
 
-    private void updateUseShellFolder() {
-        // Decide whether to use the ShellFolder class to populate shortcut
-        // panel and combobox.
-        JFileChooser fc = getFileChooser();
-        Boolean prop =
-            (Boolean)fc.getClientProperty("FileChooser.useShellFolder");
-        if (prop != null) {
-            useShellFolder = prop.booleanValue();
-        } else {
-            useShellFolder = fc.getFileSystemView().equals(FileSystemView.getFileSystemView());
-        }
-    }
-
-
     private String fileNameString(File file) {
         if (file == null) {
             return null;
@@ -761,6 +739,8 @@
                 return;
             }
 
+            boolean useShellFolder = FilePane.usesShellFolder(chooser);
+
             int oldSize = directories.size();
             directories.clear();
             if (oldSize > 0) {