From 5a8c6c3bf7b2101bca5d1a0bb601ce887f885ccc Mon Sep 17 00:00:00 2001 From: Pavel Porvatov Date: Wed, 26 Nov 2008 19:38:46 +0300 Subject: [PATCH] 6776856: Code with useShellFolder field shuold be simplify Reviewed-by: peterz --- .../plaf/windows/WindowsFileChooserUI.java | 16 +++---------- .../swing/plaf/metal/MetalFileChooserUI.java | 24 ++----------------- jdk/src/share/classes/sun/swing/FilePane.java | 5 ++-- .../plaf/synth/SynthFileChooserUIImpl.java | 24 ++----------------- 4 files changed, 9 insertions(+), 60 deletions(-) diff --git a/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java b/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java index e0fb203e0d3..6f75220d4e7 100644 --- a/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java +++ b/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java @@ -70,7 +70,6 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { private JTextField filenameTextField; private FilePane filePane; private WindowsPlacesBar placesBar; - private boolean useShellFolder; private JButton approveButton; private JButton cancelButton; @@ -210,10 +209,6 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { public ListSelectionListener createListSelectionListener() { return WindowsFileChooserUI.this.createListSelectionListener(getFileChooser()); } - - public boolean usesShellFolder() { - return useShellFolder; - } } public void installComponents(JFileChooser fc) { @@ -625,15 +620,8 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { // 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 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { return; } + boolean useShellFolder = FilePane.usesShellFolder(chooser); + directories.clear(); File[] baseFolders; diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java index fd837b9abf2..f1864614d90 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java @@ -68,8 +68,6 @@ public class MetalFileChooserUI extends BasicFileChooserUI { private JToggleButton listViewButton; private JToggleButton detailsViewButton; - private boolean useShellFolder; - private JButton approveButton; private JButton cancelButton; @@ -204,10 +202,6 @@ public class MetalFileChooserUI extends BasicFileChooserUI { public ListSelectionListener createListSelectionListener() { return MetalFileChooserUI.this.createListSelectionListener(getFileChooser()); } - - public boolean usesShellFolder() { - return useShellFolder; - } } public void installComponents(JFileChooser fc) { @@ -219,8 +213,6 @@ public class MetalFileChooserUI extends BasicFileChooserUI { filePane = new FilePane(new MetalFileChooserUIAccessor()); fc.addPropertyChangeListener(filePane); - updateUseShellFolder(); - // ********************************* // // **** Construct the top panel **** // // ********************************* // @@ -448,19 +440,6 @@ public class MetalFileChooserUI extends BasicFileChooserUI { 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 @@ public class MetalFileChooserUI extends BasicFileChooserUI { 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 @@ public class MetalFileChooserUI extends BasicFileChooserUI { return; } + boolean useShellFolder = FilePane.usesShellFolder(chooser); + directories.clear(); File[] baseFolders; diff --git a/jdk/src/share/classes/sun/swing/FilePane.java b/jdk/src/share/classes/sun/swing/FilePane.java index 2f80184c741..de5ad7c4831 100644 --- a/jdk/src/share/classes/sun/swing/FilePane.java +++ b/jdk/src/share/classes/sun/swing/FilePane.java @@ -689,7 +689,7 @@ public class FilePane extends JPanel implements PropertyChangeListener { 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 @@ public class FilePane extends JPanel implements PropertyChangeListener { 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 class FilePane extends JPanel implements PropertyChangeListener { public Action getNewFolderAction(); public MouseListener createDoubleClickListener(JList list); public ListSelectionListener createListSelectionListener(); - public boolean usesShellFolder(); } } diff --git a/jdk/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java b/jdk/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java index 2721764d1d7..a107ccca88d 100644 --- a/jdk/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java +++ b/jdk/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java @@ -71,8 +71,6 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { private JToggleButton listViewButton; private JToggleButton detailsViewButton; - private boolean useShellFolder; - private boolean readOnly; private JPanel buttonPanel; @@ -185,10 +183,6 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { public ListSelectionListener createListSelectionListener() { return SynthFileChooserUIImpl.this.createListSelectionListener(getFileChooser()); } - - public boolean usesShellFolder() { - return useShellFolder; - } } protected void installDefaults(JFileChooser fc) { @@ -201,8 +195,6 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { SynthContext context = getContext(fc, ENABLED); - updateUseShellFolder(); - fc.setLayout(new BorderLayout(0, 11)); // ********************************* // @@ -432,20 +424,6 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { 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 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { return; } + boolean useShellFolder = FilePane.usesShellFolder(chooser); + int oldSize = directories.size(); directories.clear(); if (oldSize > 0) {