author | rupashka |
Mon, 18 Jul 2011 18:21:31 +0400 | |
changeset 10100 | c525c5fbb86c |
parent 5506 | 202f599c92aa |
child 10413 | 5bd4f81b6d45 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package com.sun.java.swing.plaf.windows; |
|
27 |
||
28 |
import javax.swing.*; |
|
29 |
import javax.swing.border.*; |
|
30 |
import javax.swing.filechooser.*; |
|
31 |
import javax.swing.event.*; |
|
32 |
import javax.swing.plaf.*; |
|
33 |
import javax.swing.plaf.basic.*; |
|
34 |
import java.awt.*; |
|
35 |
import java.awt.event.*; |
|
36 |
import java.awt.image.BufferedImage; |
|
37 |
import java.beans.*; |
|
38 |
import java.io.File; |
|
39 |
import java.io.FileNotFoundException; |
|
40 |
import java.io.IOException; |
|
41 |
import java.util.*; |
|
2491
123954ad0034
6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents:
1853
diff
changeset
|
42 |
import java.security.AccessController; |
123954ad0034
6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents:
1853
diff
changeset
|
43 |
import java.security.PrivilegedAction; |
2 | 44 |
|
45 |
import sun.awt.shell.ShellFolder; |
|
46 |
import sun.swing.*; |
|
47 |
||
48 |
import javax.accessibility.*; |
|
49 |
||
50 |
/** |
|
51 |
* Windows L&F implementation of a FileChooser. |
|
52 |
* |
|
53 |
* @author Jeff Dinkins |
|
54 |
*/ |
|
55 |
public class WindowsFileChooserUI extends BasicFileChooserUI { |
|
56 |
||
57 |
// The following are private because the implementation of the |
|
58 |
// Windows FileChooser L&F is not complete yet. |
|
59 |
||
60 |
private JPanel centerPanel; |
|
61 |
||
62 |
private JLabel lookInLabel; |
|
10100
c525c5fbb86c
7031941: Use generificated JComboBox and JList in core libraries
rupashka
parents:
5506
diff
changeset
|
63 |
private JComboBox<File> directoryComboBox; |
2 | 64 |
private DirectoryComboBoxModel directoryComboBoxModel; |
65 |
private ActionListener directoryComboBoxAction = new DirectoryComboBoxAction(); |
|
66 |
||
67 |
private FilterComboBoxModel filterComboBoxModel; |
|
68 |
||
69 |
private JTextField filenameTextField; |
|
70 |
private FilePane filePane; |
|
71 |
private WindowsPlacesBar placesBar; |
|
72 |
||
73 |
private JButton approveButton; |
|
74 |
private JButton cancelButton; |
|
75 |
||
76 |
private JPanel buttonPanel; |
|
77 |
private JPanel bottomPanel; |
|
78 |
||
10100
c525c5fbb86c
7031941: Use generificated JComboBox and JList in core libraries
rupashka
parents:
5506
diff
changeset
|
79 |
private JComboBox<FileFilter> filterComboBox; |
2 | 80 |
|
81 |
private static final Dimension hstrut10 = new Dimension(10, 1); |
|
82 |
||
83 |
private static final Dimension vstrut4 = new Dimension(1, 4); |
|
84 |
private static final Dimension vstrut6 = new Dimension(1, 6); |
|
85 |
private static final Dimension vstrut8 = new Dimension(1, 8); |
|
86 |
||
87 |
private static final Insets shrinkwrap = new Insets(0,0,0,0); |
|
88 |
||
89 |
// Preferred and Minimum sizes for the dialog box |
|
90 |
private static int PREF_WIDTH = 425; |
|
91 |
private static int PREF_HEIGHT = 245; |
|
92 |
private static Dimension PREF_SIZE = new Dimension(PREF_WIDTH, PREF_HEIGHT); |
|
93 |
||
94 |
private static int MIN_WIDTH = 425; |
|
95 |
private static int MIN_HEIGHT = 245; |
|
96 |
private static Dimension MIN_SIZE = new Dimension(MIN_WIDTH, MIN_HEIGHT); |
|
97 |
||
98 |
private static int LIST_PREF_WIDTH = 444; |
|
99 |
private static int LIST_PREF_HEIGHT = 138; |
|
100 |
private static Dimension LIST_PREF_SIZE = new Dimension(LIST_PREF_WIDTH, LIST_PREF_HEIGHT); |
|
101 |
||
102 |
// Labels, mnemonics, and tooltips (oh my!) |
|
103 |
private int lookInLabelMnemonic = 0; |
|
104 |
private String lookInLabelText = null; |
|
105 |
private String saveInLabelText = null; |
|
106 |
||
107 |
private int fileNameLabelMnemonic = 0; |
|
108 |
private String fileNameLabelText = null; |
|
109 |
private int folderNameLabelMnemonic = 0; |
|
110 |
private String folderNameLabelText = null; |
|
111 |
||
112 |
private int filesOfTypeLabelMnemonic = 0; |
|
113 |
private String filesOfTypeLabelText = null; |
|
114 |
||
115 |
private String upFolderToolTipText = null; |
|
116 |
private String upFolderAccessibleName = null; |
|
117 |
||
118 |
private String newFolderToolTipText = null; |
|
119 |
private String newFolderAccessibleName = null; |
|
120 |
||
121 |
private String viewMenuButtonToolTipText = null; |
|
122 |
private String viewMenuButtonAccessibleName = null; |
|
123 |
||
124 |
private BasicFileView fileView = new WindowsFileView(); |
|
125 |
||
126 |
private JLabel fileNameLabel; |
|
127 |
||
128 |
private void populateFileNameLabel() { |
|
129 |
if (getFileChooser().getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) { |
|
130 |
fileNameLabel.setText(folderNameLabelText); |
|
131 |
fileNameLabel.setDisplayedMnemonic(folderNameLabelMnemonic); |
|
132 |
} else { |
|
133 |
fileNameLabel.setText(fileNameLabelText); |
|
134 |
fileNameLabel.setDisplayedMnemonic(fileNameLabelMnemonic); |
|
135 |
} |
|
136 |
} |
|
137 |
||
138 |
// |
|
139 |
// ComponentUI Interface Implementation methods |
|
140 |
// |
|
141 |
public static ComponentUI createUI(JComponent c) { |
|
142 |
return new WindowsFileChooserUI((JFileChooser) c); |
|
143 |
} |
|
144 |
||
145 |
public WindowsFileChooserUI(JFileChooser filechooser) { |
|
146 |
super(filechooser); |
|
147 |
} |
|
148 |
||
149 |
public void installUI(JComponent c) { |
|
150 |
super.installUI(c); |
|
151 |
} |
|
152 |
||
153 |
public void uninstallComponents(JFileChooser fc) { |
|
154 |
fc.removeAll(); |
|
155 |
} |
|
156 |
||
157 |
private class WindowsFileChooserUIAccessor implements FilePane.FileChooserUIAccessor { |
|
158 |
public JFileChooser getFileChooser() { |
|
159 |
return WindowsFileChooserUI.this.getFileChooser(); |
|
160 |
} |
|
161 |
||
162 |
public BasicDirectoryModel getModel() { |
|
163 |
return WindowsFileChooserUI.this.getModel(); |
|
164 |
} |
|
165 |
||
166 |
public JPanel createList() { |
|
167 |
return WindowsFileChooserUI.this.createList(getFileChooser()); |
|
168 |
} |
|
169 |
||
170 |
public JPanel createDetailsView() { |
|
171 |
return WindowsFileChooserUI.this.createDetailsView(getFileChooser()); |
|
172 |
} |
|
173 |
||
174 |
public boolean isDirectorySelected() { |
|
175 |
return WindowsFileChooserUI.this.isDirectorySelected(); |
|
176 |
} |
|
177 |
||
178 |
public File getDirectory() { |
|
179 |
return WindowsFileChooserUI.this.getDirectory(); |
|
180 |
} |
|
181 |
||
182 |
public Action getChangeToParentDirectoryAction() { |
|
183 |
return WindowsFileChooserUI.this.getChangeToParentDirectoryAction(); |
|
184 |
} |
|
185 |
||
186 |
public Action getApproveSelectionAction() { |
|
187 |
return WindowsFileChooserUI.this.getApproveSelectionAction(); |
|
188 |
} |
|
189 |
||
190 |
public Action getNewFolderAction() { |
|
191 |
return WindowsFileChooserUI.this.getNewFolderAction(); |
|
192 |
} |
|
193 |
||
194 |
public MouseListener createDoubleClickListener(JList list) { |
|
195 |
return WindowsFileChooserUI.this.createDoubleClickListener(getFileChooser(), |
|
196 |
list); |
|
197 |
} |
|
198 |
||
199 |
public ListSelectionListener createListSelectionListener() { |
|
200 |
return WindowsFileChooserUI.this.createListSelectionListener(getFileChooser()); |
|
201 |
} |
|
202 |
} |
|
203 |
||
204 |
public void installComponents(JFileChooser fc) { |
|
205 |
filePane = new FilePane(new WindowsFileChooserUIAccessor()); |
|
206 |
fc.addPropertyChangeListener(filePane); |
|
207 |
||
208 |
FileSystemView fsv = fc.getFileSystemView(); |
|
209 |
||
210 |
fc.setBorder(new EmptyBorder(4, 10, 10, 10)); |
|
211 |
fc.setLayout(new BorderLayout(8, 8)); |
|
212 |
||
213 |
updateUseShellFolder(); |
|
214 |
||
215 |
// ********************************* // |
|
216 |
// **** Construct the top panel **** // |
|
217 |
// ********************************* // |
|
218 |
||
219 |
// Directory manipulation buttons |
|
220 |
JToolBar topPanel = new JToolBar(); |
|
221 |
topPanel.setFloatable(false); |
|
3751
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
222 |
topPanel.putClientProperty("JToolBar.isRollover", Boolean.TRUE); |
2 | 223 |
|
224 |
// Add the top panel to the fileChooser |
|
225 |
fc.add(topPanel, BorderLayout.NORTH); |
|
226 |
||
227 |
// ComboBox Label |
|
228 |
lookInLabel = new JLabel(lookInLabelText, JLabel.TRAILING) { |
|
229 |
public Dimension getPreferredSize() { |
|
230 |
return getMinimumSize(); |
|
231 |
} |
|
232 |
||
233 |
public Dimension getMinimumSize() { |
|
234 |
Dimension d = super.getPreferredSize(); |
|
235 |
if (placesBar != null) { |
|
236 |
d.width = Math.max(d.width, placesBar.getWidth()); |
|
237 |
} |
|
238 |
return d; |
|
239 |
} |
|
240 |
}; |
|
241 |
lookInLabel.setDisplayedMnemonic(lookInLabelMnemonic); |
|
242 |
lookInLabel.setAlignmentX(JComponent.LEFT_ALIGNMENT); |
|
243 |
lookInLabel.setAlignmentY(JComponent.CENTER_ALIGNMENT); |
|
244 |
topPanel.add(lookInLabel); |
|
245 |
topPanel.add(Box.createRigidArea(new Dimension(8,0))); |
|
246 |
||
247 |
// CurrentDir ComboBox |
|
10100
c525c5fbb86c
7031941: Use generificated JComboBox and JList in core libraries
rupashka
parents:
5506
diff
changeset
|
248 |
directoryComboBox = new JComboBox<File>() { |
2 | 249 |
public Dimension getMinimumSize() { |
250 |
Dimension d = super.getMinimumSize(); |
|
251 |
d.width = 60; |
|
252 |
return d; |
|
253 |
} |
|
254 |
||
255 |
public Dimension getPreferredSize() { |
|
256 |
Dimension d = super.getPreferredSize(); |
|
257 |
// Must be small enough to not affect total width. |
|
258 |
d.width = 150; |
|
259 |
return d; |
|
260 |
} |
|
261 |
}; |
|
262 |
directoryComboBox.putClientProperty( "JComboBox.lightweightKeyboardNavigation", "Lightweight" ); |
|
263 |
lookInLabel.setLabelFor(directoryComboBox); |
|
264 |
directoryComboBoxModel = createDirectoryComboBoxModel(fc); |
|
265 |
directoryComboBox.setModel(directoryComboBoxModel); |
|
266 |
directoryComboBox.addActionListener(directoryComboBoxAction); |
|
267 |
directoryComboBox.setRenderer(createDirectoryComboBoxRenderer(fc)); |
|
268 |
directoryComboBox.setAlignmentX(JComponent.LEFT_ALIGNMENT); |
|
269 |
directoryComboBox.setAlignmentY(JComponent.CENTER_ALIGNMENT); |
|
270 |
directoryComboBox.setMaximumRowCount(8); |
|
271 |
||
272 |
topPanel.add(directoryComboBox); |
|
273 |
topPanel.add(Box.createRigidArea(hstrut10)); |
|
274 |
||
275 |
// Up Button |
|
3751
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
276 |
JButton upFolderButton = createToolButton(getChangeToParentDirectoryAction(), upFolderIcon, |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
277 |
upFolderToolTipText, upFolderAccessibleName); |
2 | 278 |
topPanel.add(upFolderButton); |
279 |
||
280 |
// New Directory Button |
|
281 |
if (!UIManager.getBoolean("FileChooser.readOnly")) { |
|
3751
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
282 |
JButton newFolderButton = createToolButton(filePane.getNewFolderAction(), newFolderIcon, |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
283 |
newFolderToolTipText, newFolderAccessibleName); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
284 |
topPanel.add(newFolderButton); |
2 | 285 |
} |
3751
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
286 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
287 |
// View button group |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
288 |
ButtonGroup viewButtonGroup = new ButtonGroup(); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
289 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
290 |
// Popup Menu |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
291 |
final JPopupMenu viewTypePopupMenu = new JPopupMenu(); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
292 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
293 |
final JRadioButtonMenuItem listViewMenuItem = new JRadioButtonMenuItem( |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
294 |
filePane.getViewTypeAction(FilePane.VIEWTYPE_LIST)); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
295 |
listViewMenuItem.setSelected(filePane.getViewType() == FilePane.VIEWTYPE_LIST); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
296 |
viewTypePopupMenu.add(listViewMenuItem); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
297 |
viewButtonGroup.add(listViewMenuItem); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
298 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
299 |
final JRadioButtonMenuItem detailsViewMenuItem = new JRadioButtonMenuItem( |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
300 |
filePane.getViewTypeAction(FilePane.VIEWTYPE_DETAILS)); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
301 |
detailsViewMenuItem.setSelected(filePane.getViewType() == FilePane.VIEWTYPE_DETAILS); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
302 |
viewTypePopupMenu.add(detailsViewMenuItem); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
303 |
viewButtonGroup.add(detailsViewMenuItem); |
2 | 304 |
|
3751
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
305 |
// Create icon for viewMenuButton |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
306 |
BufferedImage image = new BufferedImage(viewMenuIcon.getIconWidth() + 7, viewMenuIcon.getIconHeight(), |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
307 |
BufferedImage.TYPE_INT_ARGB); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
308 |
Graphics graphics = image.getGraphics(); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
309 |
viewMenuIcon.paintIcon(filePane, graphics, 0, 0); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
310 |
int x = image.getWidth() - 5; |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
311 |
int y = image.getHeight() / 2 - 1; |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
312 |
graphics.setColor(Color.BLACK); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
313 |
graphics.fillPolygon(new int[]{x, x + 5, x + 2}, new int[]{y, y, y + 3}, 3); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
314 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
315 |
// Details Button |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
316 |
final JButton viewMenuButton = createToolButton(null, new ImageIcon(image), viewMenuButtonToolTipText, |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
317 |
viewMenuButtonAccessibleName); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
318 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
319 |
viewMenuButton.addMouseListener(new MouseAdapter() { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
320 |
public void mousePressed(MouseEvent e) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
321 |
if (SwingUtilities.isLeftMouseButton(e) && !viewMenuButton.isSelected()) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
322 |
viewMenuButton.setSelected(true); |
2 | 323 |
|
3751
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
324 |
viewTypePopupMenu.show(viewMenuButton, 0, viewMenuButton.getHeight()); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
325 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
326 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
327 |
}); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
328 |
viewMenuButton.addKeyListener(new KeyAdapter() { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
329 |
public void keyPressed(KeyEvent e) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
330 |
// Forbid keyboard actions if the button is not in rollover state |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
331 |
if (e.getKeyCode() == KeyEvent.VK_SPACE && viewMenuButton.getModel().isRollover()) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
332 |
viewMenuButton.setSelected(true); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
333 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
334 |
viewTypePopupMenu.show(viewMenuButton, 0, viewMenuButton.getHeight()); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
335 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
336 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
337 |
}); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
338 |
viewTypePopupMenu.addPopupMenuListener(new PopupMenuListener() { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
339 |
public void popupMenuWillBecomeVisible(PopupMenuEvent e) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
340 |
} |
2 | 341 |
|
3751
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
342 |
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
343 |
SwingUtilities.invokeLater(new Runnable() { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
344 |
public void run() { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
345 |
viewMenuButton.setSelected(false); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
346 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
347 |
}); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
348 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
349 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
350 |
public void popupMenuCanceled(PopupMenuEvent e) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
351 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
352 |
}); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
353 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
354 |
topPanel.add(viewMenuButton); |
2 | 355 |
|
3751
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
356 |
topPanel.add(Box.createRigidArea(new Dimension(80, 0))); |
2 | 357 |
|
3751
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
358 |
filePane.addPropertyChangeListener(new PropertyChangeListener() { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
359 |
public void propertyChange(PropertyChangeEvent e) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
360 |
if ("viewType".equals(e.getPropertyName())) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
361 |
switch (filePane.getViewType()) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
362 |
case FilePane.VIEWTYPE_LIST: |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
363 |
listViewMenuItem.setSelected(true); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
364 |
break; |
2 | 365 |
|
3751
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
366 |
case FilePane.VIEWTYPE_DETAILS: |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
367 |
detailsViewMenuItem.setSelected(true); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
368 |
break; |
2 | 369 |
} |
370 |
} |
|
3751
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
371 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
372 |
}); |
2 | 373 |
|
374 |
// ************************************** // |
|
375 |
// ******* Add the directory pane ******* // |
|
376 |
// ************************************** // |
|
377 |
centerPanel = new JPanel(new BorderLayout()); |
|
378 |
centerPanel.add(getAccessoryPanel(), BorderLayout.AFTER_LINE_ENDS); |
|
379 |
JComponent accessory = fc.getAccessory(); |
|
380 |
if(accessory != null) { |
|
381 |
getAccessoryPanel().add(accessory); |
|
382 |
} |
|
383 |
filePane.setPreferredSize(LIST_PREF_SIZE); |
|
384 |
centerPanel.add(filePane, BorderLayout.CENTER); |
|
385 |
fc.add(centerPanel, BorderLayout.CENTER); |
|
386 |
||
387 |
// ********************************** // |
|
388 |
// **** Construct the bottom panel ** // |
|
389 |
// ********************************** // |
|
390 |
getBottomPanel().setLayout(new BoxLayout(getBottomPanel(), BoxLayout.LINE_AXIS)); |
|
391 |
||
392 |
// Add the bottom panel to file chooser |
|
393 |
centerPanel.add(getBottomPanel(), BorderLayout.SOUTH); |
|
394 |
||
395 |
// labels |
|
396 |
JPanel labelPanel = new JPanel(); |
|
397 |
labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.PAGE_AXIS)); |
|
398 |
labelPanel.add(Box.createRigidArea(vstrut4)); |
|
399 |
||
400 |
fileNameLabel = new JLabel(); |
|
401 |
populateFileNameLabel(); |
|
402 |
fileNameLabel.setAlignmentY(0); |
|
403 |
labelPanel.add(fileNameLabel); |
|
404 |
||
405 |
labelPanel.add(Box.createRigidArea(new Dimension(1,12))); |
|
406 |
||
407 |
JLabel ftl = new JLabel(filesOfTypeLabelText); |
|
408 |
ftl.setDisplayedMnemonic(filesOfTypeLabelMnemonic); |
|
409 |
labelPanel.add(ftl); |
|
410 |
||
411 |
getBottomPanel().add(labelPanel); |
|
412 |
getBottomPanel().add(Box.createRigidArea(new Dimension(15, 0))); |
|
413 |
||
414 |
// file entry and filters |
|
415 |
JPanel fileAndFilterPanel = new JPanel(); |
|
416 |
fileAndFilterPanel.add(Box.createRigidArea(vstrut8)); |
|
417 |
fileAndFilterPanel.setLayout(new BoxLayout(fileAndFilterPanel, BoxLayout.Y_AXIS)); |
|
418 |
||
419 |
||
420 |
filenameTextField = new JTextField(35) { |
|
421 |
public Dimension getMaximumSize() { |
|
422 |
return new Dimension(Short.MAX_VALUE, super.getPreferredSize().height); |
|
423 |
} |
|
424 |
}; |
|
425 |
||
426 |
fileNameLabel.setLabelFor(filenameTextField); |
|
427 |
filenameTextField.addFocusListener( |
|
428 |
new FocusAdapter() { |
|
429 |
public void focusGained(FocusEvent e) { |
|
430 |
if (!getFileChooser().isMultiSelectionEnabled()) { |
|
431 |
filePane.clearSelection(); |
|
432 |
} |
|
433 |
} |
|
434 |
} |
|
435 |
); |
|
436 |
||
437 |
if (fc.isMultiSelectionEnabled()) { |
|
438 |
setFileName(fileNameString(fc.getSelectedFiles())); |
|
439 |
} else { |
|
440 |
setFileName(fileNameString(fc.getSelectedFile())); |
|
441 |
} |
|
442 |
||
443 |
fileAndFilterPanel.add(filenameTextField); |
|
444 |
fileAndFilterPanel.add(Box.createRigidArea(vstrut8)); |
|
445 |
||
446 |
filterComboBoxModel = createFilterComboBoxModel(); |
|
447 |
fc.addPropertyChangeListener(filterComboBoxModel); |
|
10100
c525c5fbb86c
7031941: Use generificated JComboBox and JList in core libraries
rupashka
parents:
5506
diff
changeset
|
448 |
filterComboBox = new JComboBox<FileFilter>(filterComboBoxModel); |
2 | 449 |
ftl.setLabelFor(filterComboBox); |
450 |
filterComboBox.setRenderer(createFilterComboBoxRenderer()); |
|
451 |
fileAndFilterPanel.add(filterComboBox); |
|
452 |
||
453 |
getBottomPanel().add(fileAndFilterPanel); |
|
454 |
getBottomPanel().add(Box.createRigidArea(new Dimension(30, 0))); |
|
455 |
||
456 |
// buttons |
|
457 |
getButtonPanel().setLayout(new BoxLayout(getButtonPanel(), BoxLayout.Y_AXIS)); |
|
458 |
||
459 |
approveButton = new JButton(getApproveButtonText(fc)) { |
|
460 |
public Dimension getMaximumSize() { |
|
461 |
return approveButton.getPreferredSize().width > cancelButton.getPreferredSize().width ? |
|
462 |
approveButton.getPreferredSize() : cancelButton.getPreferredSize(); |
|
463 |
} |
|
464 |
}; |
|
465 |
Insets buttonMargin = approveButton.getMargin(); |
|
466 |
buttonMargin = new InsetsUIResource(buttonMargin.top, buttonMargin.left + 5, |
|
467 |
buttonMargin.bottom, buttonMargin.right + 5); |
|
468 |
approveButton.setMargin(buttonMargin); |
|
469 |
approveButton.setMnemonic(getApproveButtonMnemonic(fc)); |
|
470 |
approveButton.addActionListener(getApproveSelectionAction()); |
|
471 |
approveButton.setToolTipText(getApproveButtonToolTipText(fc)); |
|
472 |
getButtonPanel().add(Box.createRigidArea(vstrut6)); |
|
473 |
getButtonPanel().add(approveButton); |
|
474 |
getButtonPanel().add(Box.createRigidArea(vstrut4)); |
|
475 |
||
476 |
cancelButton = new JButton(cancelButtonText) { |
|
477 |
public Dimension getMaximumSize() { |
|
478 |
return approveButton.getPreferredSize().width > cancelButton.getPreferredSize().width ? |
|
479 |
approveButton.getPreferredSize() : cancelButton.getPreferredSize(); |
|
480 |
} |
|
481 |
}; |
|
482 |
cancelButton.setMargin(buttonMargin); |
|
483 |
cancelButton.setToolTipText(cancelButtonToolTipText); |
|
484 |
cancelButton.addActionListener(getCancelSelectionAction()); |
|
485 |
getButtonPanel().add(cancelButton); |
|
486 |
||
487 |
if(fc.getControlButtonsAreShown()) { |
|
488 |
addControlButtons(); |
|
489 |
} |
|
490 |
} |
|
491 |
||
492 |
private void updateUseShellFolder() { |
|
493 |
// Decide whether to use the ShellFolder class to populate shortcut |
|
494 |
// panel and combobox. |
|
495 |
JFileChooser fc = getFileChooser(); |
|
3751
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
496 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
497 |
if (FilePane.usesShellFolder(fc)) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
498 |
if (placesBar == null && !UIManager.getBoolean("FileChooser.noPlacesBar")) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
499 |
placesBar = new WindowsPlacesBar(fc, XPStyle.getXP() != null); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
500 |
fc.add(placesBar, BorderLayout.BEFORE_LINE_BEGINS); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
501 |
fc.addPropertyChangeListener(placesBar); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
502 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
503 |
} else { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
504 |
if (placesBar != null) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
505 |
fc.remove(placesBar); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
506 |
fc.removePropertyChangeListener(placesBar); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
507 |
placesBar = null; |
2 | 508 |
} |
509 |
} |
|
510 |
} |
|
511 |
||
512 |
protected JPanel getButtonPanel() { |
|
513 |
if(buttonPanel == null) { |
|
514 |
buttonPanel = new JPanel(); |
|
515 |
} |
|
516 |
return buttonPanel; |
|
517 |
} |
|
518 |
||
519 |
protected JPanel getBottomPanel() { |
|
520 |
if(bottomPanel == null) { |
|
521 |
bottomPanel = new JPanel(); |
|
522 |
} |
|
523 |
return bottomPanel; |
|
524 |
} |
|
525 |
||
526 |
protected void installStrings(JFileChooser fc) { |
|
527 |
super.installStrings(fc); |
|
528 |
||
529 |
Locale l = fc.getLocale(); |
|
530 |
||
531 |
lookInLabelMnemonic = UIManager.getInt("FileChooser.lookInLabelMnemonic"); |
|
532 |
lookInLabelText = UIManager.getString("FileChooser.lookInLabelText",l); |
|
533 |
saveInLabelText = UIManager.getString("FileChooser.saveInLabelText",l); |
|
534 |
||
535 |
fileNameLabelMnemonic = UIManager.getInt("FileChooser.fileNameLabelMnemonic"); |
|
536 |
fileNameLabelText = UIManager.getString("FileChooser.fileNameLabelText",l); |
|
537 |
folderNameLabelMnemonic = UIManager.getInt("FileChooser.folderNameLabelMnemonic"); |
|
538 |
folderNameLabelText = UIManager.getString("FileChooser.folderNameLabelText",l); |
|
539 |
||
540 |
filesOfTypeLabelMnemonic = UIManager.getInt("FileChooser.filesOfTypeLabelMnemonic"); |
|
541 |
filesOfTypeLabelText = UIManager.getString("FileChooser.filesOfTypeLabelText",l); |
|
542 |
||
543 |
upFolderToolTipText = UIManager.getString("FileChooser.upFolderToolTipText",l); |
|
544 |
upFolderAccessibleName = UIManager.getString("FileChooser.upFolderAccessibleName",l); |
|
545 |
||
546 |
newFolderToolTipText = UIManager.getString("FileChooser.newFolderToolTipText",l); |
|
547 |
newFolderAccessibleName = UIManager.getString("FileChooser.newFolderAccessibleName",l); |
|
548 |
||
549 |
viewMenuButtonToolTipText = UIManager.getString("FileChooser.viewMenuButtonToolTipText",l); |
|
550 |
viewMenuButtonAccessibleName = UIManager.getString("FileChooser.viewMenuButtonAccessibleName",l); |
|
551 |
} |
|
552 |
||
553 |
protected void installListeners(JFileChooser fc) { |
|
554 |
super.installListeners(fc); |
|
555 |
ActionMap actionMap = getActionMap(); |
|
556 |
SwingUtilities.replaceUIActionMap(fc, actionMap); |
|
557 |
} |
|
558 |
||
559 |
protected ActionMap getActionMap() { |
|
560 |
return createActionMap(); |
|
561 |
} |
|
562 |
||
563 |
protected ActionMap createActionMap() { |
|
564 |
ActionMap map = new ActionMapUIResource(); |
|
565 |
FilePane.addActionsToMap(map, filePane.getActions()); |
|
566 |
return map; |
|
567 |
} |
|
568 |
||
569 |
protected JPanel createList(JFileChooser fc) { |
|
570 |
return filePane.createList(); |
|
571 |
} |
|
572 |
||
573 |
protected JPanel createDetailsView(JFileChooser fc) { |
|
574 |
return filePane.createDetailsView(); |
|
575 |
} |
|
576 |
||
577 |
/** |
|
578 |
* Creates a selection listener for the list of files and directories. |
|
579 |
* |
|
580 |
* @param fc a <code>JFileChooser</code> |
|
581 |
* @return a <code>ListSelectionListener</code> |
|
582 |
*/ |
|
583 |
public ListSelectionListener createListSelectionListener(JFileChooser fc) { |
|
584 |
return super.createListSelectionListener(fc); |
|
585 |
} |
|
586 |
||
587 |
// Obsolete class, not used in this version. |
|
588 |
protected class WindowsNewFolderAction extends NewFolderAction { |
|
589 |
} |
|
590 |
||
591 |
// Obsolete class, not used in this version. |
|
592 |
protected class SingleClickListener extends MouseAdapter { |
|
593 |
} |
|
594 |
||
595 |
// Obsolete class, not used in this version. |
|
596 |
protected class FileRenderer extends DefaultListCellRenderer { |
|
597 |
} |
|
598 |
||
599 |
public void uninstallUI(JComponent c) { |
|
600 |
// Remove listeners |
|
601 |
c.removePropertyChangeListener(filterComboBoxModel); |
|
602 |
c.removePropertyChangeListener(filePane); |
|
603 |
if (placesBar != null) { |
|
604 |
c.removePropertyChangeListener(placesBar); |
|
605 |
} |
|
606 |
cancelButton.removeActionListener(getCancelSelectionAction()); |
|
607 |
approveButton.removeActionListener(getApproveSelectionAction()); |
|
608 |
filenameTextField.removeActionListener(getApproveSelectionAction()); |
|
609 |
||
610 |
if (filePane != null) { |
|
611 |
filePane.uninstallUI(); |
|
612 |
filePane = null; |
|
613 |
} |
|
614 |
||
615 |
super.uninstallUI(c); |
|
616 |
} |
|
617 |
||
618 |
/** |
|
619 |
* Returns the preferred size of the specified |
|
620 |
* <code>JFileChooser</code>. |
|
621 |
* The preferred size is at least as large, |
|
622 |
* in both height and width, |
|
623 |
* as the preferred size recommended |
|
624 |
* by the file chooser's layout manager. |
|
625 |
* |
|
626 |
* @param c a <code>JFileChooser</code> |
|
627 |
* @return a <code>Dimension</code> specifying the preferred |
|
628 |
* width and height of the file chooser |
|
629 |
*/ |
|
630 |
public Dimension getPreferredSize(JComponent c) { |
|
631 |
int prefWidth = PREF_SIZE.width; |
|
632 |
Dimension d = c.getLayout().preferredLayoutSize(c); |
|
633 |
if (d != null) { |
|
634 |
return new Dimension(d.width < prefWidth ? prefWidth : d.width, |
|
635 |
d.height < PREF_SIZE.height ? PREF_SIZE.height : d.height); |
|
636 |
} else { |
|
637 |
return new Dimension(prefWidth, PREF_SIZE.height); |
|
638 |
} |
|
639 |
} |
|
640 |
||
641 |
/** |
|
642 |
* Returns the minimum size of the <code>JFileChooser</code>. |
|
643 |
* |
|
644 |
* @param c a <code>JFileChooser</code> |
|
645 |
* @return a <code>Dimension</code> specifying the minimum |
|
646 |
* width and height of the file chooser |
|
647 |
*/ |
|
648 |
public Dimension getMinimumSize(JComponent c) { |
|
649 |
return MIN_SIZE; |
|
650 |
} |
|
651 |
||
652 |
/** |
|
653 |
* Returns the maximum size of the <code>JFileChooser</code>. |
|
654 |
* |
|
655 |
* @param c a <code>JFileChooser</code> |
|
656 |
* @return a <code>Dimension</code> specifying the maximum |
|
657 |
* width and height of the file chooser |
|
658 |
*/ |
|
659 |
public Dimension getMaximumSize(JComponent c) { |
|
660 |
return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); |
|
661 |
} |
|
662 |
||
663 |
private String fileNameString(File file) { |
|
664 |
if (file == null) { |
|
665 |
return null; |
|
666 |
} else { |
|
667 |
JFileChooser fc = getFileChooser(); |
|
668 |
if ((fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) || |
|
669 |
(fc.isDirectorySelectionEnabled() && fc.isFileSelectionEnabled() && fc.getFileSystemView().isFileSystemRoot(file))){ |
|
670 |
return file.getPath(); |
|
671 |
} else { |
|
672 |
return file.getName(); |
|
673 |
} |
|
674 |
} |
|
675 |
} |
|
676 |
||
677 |
private String fileNameString(File[] files) { |
|
678 |
StringBuffer buf = new StringBuffer(); |
|
679 |
for (int i = 0; files != null && i < files.length; i++) { |
|
680 |
if (i > 0) { |
|
681 |
buf.append(" "); |
|
682 |
} |
|
683 |
if (files.length > 1) { |
|
684 |
buf.append("\""); |
|
685 |
} |
|
686 |
buf.append(fileNameString(files[i])); |
|
687 |
if (files.length > 1) { |
|
688 |
buf.append("\""); |
|
689 |
} |
|
690 |
} |
|
691 |
return buf.toString(); |
|
692 |
} |
|
693 |
||
694 |
/* The following methods are used by the PropertyChange Listener */ |
|
695 |
||
696 |
private void doSelectedFileChanged(PropertyChangeEvent e) { |
|
697 |
File f = (File) e.getNewValue(); |
|
698 |
JFileChooser fc = getFileChooser(); |
|
699 |
if (f != null |
|
700 |
&& ((fc.isFileSelectionEnabled() && !f.isDirectory()) |
|
701 |
|| (f.isDirectory() && fc.isDirectorySelectionEnabled()))) { |
|
702 |
||
703 |
setFileName(fileNameString(f)); |
|
704 |
} |
|
705 |
} |
|
706 |
||
707 |
private void doSelectedFilesChanged(PropertyChangeEvent e) { |
|
708 |
File[] files = (File[]) e.getNewValue(); |
|
709 |
JFileChooser fc = getFileChooser(); |
|
710 |
if (files != null |
|
711 |
&& files.length > 0 |
|
712 |
&& (files.length > 1 || fc.isDirectorySelectionEnabled() || !files[0].isDirectory())) { |
|
713 |
setFileName(fileNameString(files)); |
|
714 |
} |
|
715 |
} |
|
716 |
||
717 |
private void doDirectoryChanged(PropertyChangeEvent e) { |
|
718 |
JFileChooser fc = getFileChooser(); |
|
719 |
FileSystemView fsv = fc.getFileSystemView(); |
|
720 |
||
721 |
clearIconCache(); |
|
722 |
File currentDirectory = fc.getCurrentDirectory(); |
|
723 |
if(currentDirectory != null) { |
|
724 |
directoryComboBoxModel.addItem(currentDirectory); |
|
725 |
||
726 |
if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) { |
|
727 |
if (fsv.isFileSystem(currentDirectory)) { |
|
728 |
setFileName(currentDirectory.getPath()); |
|
729 |
} else { |
|
730 |
setFileName(null); |
|
731 |
} |
|
732 |
} |
|
733 |
} |
|
734 |
} |
|
735 |
||
736 |
private void doFilterChanged(PropertyChangeEvent e) { |
|
737 |
clearIconCache(); |
|
738 |
} |
|
739 |
||
740 |
private void doFileSelectionModeChanged(PropertyChangeEvent e) { |
|
741 |
if (fileNameLabel != null) { |
|
742 |
populateFileNameLabel(); |
|
743 |
} |
|
744 |
clearIconCache(); |
|
745 |
||
746 |
JFileChooser fc = getFileChooser(); |
|
747 |
File currentDirectory = fc.getCurrentDirectory(); |
|
748 |
if (currentDirectory != null |
|
749 |
&& fc.isDirectorySelectionEnabled() |
|
750 |
&& !fc.isFileSelectionEnabled() |
|
751 |
&& fc.getFileSystemView().isFileSystem(currentDirectory)) { |
|
752 |
||
753 |
setFileName(currentDirectory.getPath()); |
|
754 |
} else { |
|
755 |
setFileName(null); |
|
756 |
} |
|
757 |
} |
|
758 |
||
759 |
private void doAccessoryChanged(PropertyChangeEvent e) { |
|
760 |
if(getAccessoryPanel() != null) { |
|
761 |
if(e.getOldValue() != null) { |
|
762 |
getAccessoryPanel().remove((JComponent) e.getOldValue()); |
|
763 |
} |
|
764 |
JComponent accessory = (JComponent) e.getNewValue(); |
|
765 |
if(accessory != null) { |
|
766 |
getAccessoryPanel().add(accessory, BorderLayout.CENTER); |
|
767 |
} |
|
768 |
} |
|
769 |
} |
|
770 |
||
771 |
private void doApproveButtonTextChanged(PropertyChangeEvent e) { |
|
772 |
JFileChooser chooser = getFileChooser(); |
|
773 |
approveButton.setText(getApproveButtonText(chooser)); |
|
774 |
approveButton.setToolTipText(getApproveButtonToolTipText(chooser)); |
|
775 |
approveButton.setMnemonic(getApproveButtonMnemonic(chooser)); |
|
776 |
} |
|
777 |
||
778 |
private void doDialogTypeChanged(PropertyChangeEvent e) { |
|
779 |
JFileChooser chooser = getFileChooser(); |
|
780 |
approveButton.setText(getApproveButtonText(chooser)); |
|
781 |
approveButton.setToolTipText(getApproveButtonToolTipText(chooser)); |
|
782 |
approveButton.setMnemonic(getApproveButtonMnemonic(chooser)); |
|
783 |
if (chooser.getDialogType() == JFileChooser.SAVE_DIALOG) { |
|
784 |
lookInLabel.setText(saveInLabelText); |
|
785 |
} else { |
|
786 |
lookInLabel.setText(lookInLabelText); |
|
787 |
} |
|
788 |
} |
|
789 |
||
790 |
private void doApproveButtonMnemonicChanged(PropertyChangeEvent e) { |
|
791 |
approveButton.setMnemonic(getApproveButtonMnemonic(getFileChooser())); |
|
792 |
} |
|
793 |
||
794 |
private void doControlButtonsChanged(PropertyChangeEvent e) { |
|
795 |
if(getFileChooser().getControlButtonsAreShown()) { |
|
796 |
addControlButtons(); |
|
797 |
} else { |
|
798 |
removeControlButtons(); |
|
799 |
} |
|
800 |
} |
|
801 |
||
802 |
/* |
|
803 |
* Listen for filechooser property changes, such as |
|
804 |
* the selected file changing, or the type of the dialog changing. |
|
805 |
*/ |
|
806 |
public PropertyChangeListener createPropertyChangeListener(JFileChooser fc) { |
|
807 |
return new PropertyChangeListener() { |
|
808 |
public void propertyChange(PropertyChangeEvent e) { |
|
809 |
String s = e.getPropertyName(); |
|
810 |
if(s.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) { |
|
811 |
doSelectedFileChanged(e); |
|
812 |
} else if (s.equals(JFileChooser.SELECTED_FILES_CHANGED_PROPERTY)) { |
|
813 |
doSelectedFilesChanged(e); |
|
814 |
} else if(s.equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) { |
|
815 |
doDirectoryChanged(e); |
|
816 |
} else if(s.equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY)) { |
|
817 |
doFilterChanged(e); |
|
818 |
} else if(s.equals(JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY)) { |
|
819 |
doFileSelectionModeChanged(e); |
|
820 |
} else if(s.equals(JFileChooser.ACCESSORY_CHANGED_PROPERTY)) { |
|
821 |
doAccessoryChanged(e); |
|
822 |
} else if (s.equals(JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY) || |
|
823 |
s.equals(JFileChooser.APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY)) { |
|
824 |
doApproveButtonTextChanged(e); |
|
825 |
} else if(s.equals(JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY)) { |
|
826 |
doDialogTypeChanged(e); |
|
827 |
} else if(s.equals(JFileChooser.APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY)) { |
|
828 |
doApproveButtonMnemonicChanged(e); |
|
829 |
} else if(s.equals(JFileChooser.CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY)) { |
|
830 |
doControlButtonsChanged(e); |
|
831 |
} else if (s == "FileChooser.useShellFolder") { |
|
832 |
updateUseShellFolder(); |
|
833 |
doDirectoryChanged(e); |
|
834 |
} else if (s.equals("componentOrientation")) { |
|
835 |
ComponentOrientation o = (ComponentOrientation)e.getNewValue(); |
|
836 |
JFileChooser cc = (JFileChooser)e.getSource(); |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
2
diff
changeset
|
837 |
if (o != e.getOldValue()) { |
2 | 838 |
cc.applyComponentOrientation(o); |
839 |
} |
|
840 |
} else if (s.equals("ancestor")) { |
|
841 |
if (e.getOldValue() == null && e.getNewValue() != null) { |
|
842 |
// Ancestor was added, set initial focus |
|
843 |
filenameTextField.selectAll(); |
|
844 |
filenameTextField.requestFocus(); |
|
845 |
} |
|
846 |
} |
|
847 |
} |
|
848 |
}; |
|
849 |
} |
|
850 |
||
851 |
||
852 |
protected void removeControlButtons() { |
|
853 |
getBottomPanel().remove(getButtonPanel()); |
|
854 |
} |
|
855 |
||
856 |
protected void addControlButtons() { |
|
857 |
getBottomPanel().add(getButtonPanel()); |
|
858 |
} |
|
859 |
||
860 |
public void ensureFileIsVisible(JFileChooser fc, File f) { |
|
861 |
filePane.ensureFileIsVisible(fc, f); |
|
862 |
} |
|
863 |
||
864 |
public void rescanCurrentDirectory(JFileChooser fc) { |
|
865 |
filePane.rescanCurrentDirectory(); |
|
866 |
} |
|
867 |
||
868 |
public String getFileName() { |
|
869 |
if(filenameTextField != null) { |
|
870 |
return filenameTextField.getText(); |
|
871 |
} else { |
|
872 |
return null; |
|
873 |
} |
|
874 |
} |
|
875 |
||
876 |
public void setFileName(String filename) { |
|
877 |
if(filenameTextField != null) { |
|
878 |
filenameTextField.setText(filename); |
|
879 |
} |
|
880 |
} |
|
881 |
||
882 |
/** |
|
883 |
* Property to remember whether a directory is currently selected in the UI. |
|
884 |
* This is normally called by the UI on a selection event. |
|
885 |
* |
|
886 |
* @param directorySelected if a directory is currently selected. |
|
887 |
* @since 1.4 |
|
888 |
*/ |
|
889 |
protected void setDirectorySelected(boolean directorySelected) { |
|
890 |
super.setDirectorySelected(directorySelected); |
|
891 |
JFileChooser chooser = getFileChooser(); |
|
892 |
if(directorySelected) { |
|
893 |
approveButton.setText(directoryOpenButtonText); |
|
894 |
approveButton.setToolTipText(directoryOpenButtonToolTipText); |
|
895 |
approveButton.setMnemonic(directoryOpenButtonMnemonic); |
|
896 |
} else { |
|
897 |
approveButton.setText(getApproveButtonText(chooser)); |
|
898 |
approveButton.setToolTipText(getApproveButtonToolTipText(chooser)); |
|
899 |
approveButton.setMnemonic(getApproveButtonMnemonic(chooser)); |
|
900 |
} |
|
901 |
} |
|
902 |
||
903 |
public String getDirectoryName() { |
|
904 |
// PENDING(jeff) - get the name from the directory combobox |
|
905 |
return null; |
|
906 |
} |
|
907 |
||
908 |
public void setDirectoryName(String dirname) { |
|
909 |
// PENDING(jeff) - set the name in the directory combobox |
|
910 |
} |
|
911 |
||
912 |
protected DirectoryComboBoxRenderer createDirectoryComboBoxRenderer(JFileChooser fc) { |
|
913 |
return new DirectoryComboBoxRenderer(); |
|
914 |
} |
|
915 |
||
3751
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
916 |
private static JButton createToolButton(Action a, Icon defaultIcon, String toolTipText, String accessibleName) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
917 |
final JButton result = new JButton(a); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
918 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
919 |
result.setText(null); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
920 |
result.setIcon(defaultIcon); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
921 |
result.setToolTipText(toolTipText); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
922 |
result.setRequestFocusEnabled(false); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
923 |
result.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, accessibleName); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
924 |
result.putClientProperty(WindowsLookAndFeel.HI_RES_DISABLED_ICON_CLIENT_KEY, Boolean.TRUE); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
925 |
result.setAlignmentX(JComponent.LEFT_ALIGNMENT); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
926 |
result.setAlignmentY(JComponent.CENTER_ALIGNMENT); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
927 |
result.setMargin(shrinkwrap); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
928 |
result.setFocusPainted(false); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
929 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
930 |
result.setModel(new DefaultButtonModel() { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
931 |
public void setPressed(boolean b) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
932 |
// Forbid keyboard actions if the button is not in rollover state |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
933 |
if (!b || isRollover()) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
934 |
super.setPressed(b); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
935 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
936 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
937 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
938 |
public void setRollover(boolean b) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
939 |
if (b && !isRollover()) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
940 |
// Reset other buttons |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
941 |
for (Component component : result.getParent().getComponents()) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
942 |
if (component instanceof JButton && component != result) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
943 |
((JButton) component).getModel().setRollover(false); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
944 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
945 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
946 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
947 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
948 |
super.setRollover(b); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
949 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
950 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
951 |
public void setSelected(boolean b) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
952 |
super.setSelected(b); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
953 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
954 |
if (b) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
955 |
stateMask |= PRESSED | ARMED; |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
956 |
} else { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
957 |
stateMask &= ~(PRESSED | ARMED); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
958 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
959 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
960 |
}); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
961 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
962 |
result.addFocusListener(new FocusAdapter() { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
963 |
public void focusGained(FocusEvent e) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
964 |
result.getModel().setRollover(true); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
965 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
966 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
967 |
public void focusLost(FocusEvent e) { |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
968 |
result.getModel().setRollover(false); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
969 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
970 |
}); |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
971 |
|
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
972 |
return result; |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
973 |
} |
8b0ac086b7c0
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents:
2491
diff
changeset
|
974 |
|
2 | 975 |
// |
976 |
// Renderer for DirectoryComboBox |
|
977 |
// |
|
978 |
class DirectoryComboBoxRenderer extends DefaultListCellRenderer { |
|
979 |
IndentIcon ii = new IndentIcon(); |
|
980 |
public Component getListCellRendererComponent(JList list, Object value, |
|
981 |
int index, boolean isSelected, |
|
982 |
boolean cellHasFocus) { |
|
983 |
||
984 |
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); |
|
985 |
||
986 |
if (value == null) { |
|
987 |
setText(""); |
|
988 |
return this; |
|
989 |
} |
|
990 |
File directory = (File)value; |
|
991 |
setText(getFileChooser().getName(directory)); |
|
992 |
Icon icon = getFileChooser().getIcon(directory); |
|
993 |
ii.icon = icon; |
|
994 |
ii.depth = directoryComboBoxModel.getDepth(index); |
|
995 |
setIcon(ii); |
|
996 |
||
997 |
return this; |
|
998 |
} |
|
999 |
} |
|
1000 |
||
1001 |
final static int space = 10; |
|
1002 |
class IndentIcon implements Icon { |
|
1003 |
||
1004 |
Icon icon = null; |
|
1005 |
int depth = 0; |
|
1006 |
||
1007 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
1008 |
if (c.getComponentOrientation().isLeftToRight()) { |
|
1009 |
icon.paintIcon(c, g, x+depth*space, y); |
|
1010 |
} else { |
|
1011 |
icon.paintIcon(c, g, x, y); |
|
1012 |
} |
|
1013 |
} |
|
1014 |
||
1015 |
public int getIconWidth() { |
|
1016 |
return icon.getIconWidth() + depth*space; |
|
1017 |
} |
|
1018 |
||
1019 |
public int getIconHeight() { |
|
1020 |
return icon.getIconHeight(); |
|
1021 |
} |
|
1022 |
||
1023 |
} |
|
1024 |
||
1025 |
// |
|
1026 |
// DataModel for DirectoryComboxbox |
|
1027 |
// |
|
1028 |
protected DirectoryComboBoxModel createDirectoryComboBoxModel(JFileChooser fc) { |
|
1029 |
return new DirectoryComboBoxModel(); |
|
1030 |
} |
|
1031 |
||
1032 |
/** |
|
1033 |
* Data model for a type-face selection combo-box. |
|
1034 |
*/ |
|
10100
c525c5fbb86c
7031941: Use generificated JComboBox and JList in core libraries
rupashka
parents:
5506
diff
changeset
|
1035 |
protected class DirectoryComboBoxModel extends AbstractListModel<File> implements ComboBoxModel<File> { |
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
2
diff
changeset
|
1036 |
Vector<File> directories = new Vector<File>(); |
2 | 1037 |
int[] depths = null; |
1038 |
File selectedDirectory = null; |
|
1039 |
JFileChooser chooser = getFileChooser(); |
|
1040 |
FileSystemView fsv = chooser.getFileSystemView(); |
|
1041 |
||
1042 |
public DirectoryComboBoxModel() { |
|
1043 |
// Add the current directory to the model, and make it the |
|
1044 |
// selectedDirectory |
|
1045 |
File dir = getFileChooser().getCurrentDirectory(); |
|
1046 |
if(dir != null) { |
|
1047 |
addItem(dir); |
|
1048 |
} |
|
1049 |
} |
|
1050 |
||
1051 |
/** |
|
1052 |
* Adds the directory to the model and sets it to be selected, |
|
1053 |
* additionally clears out the previous selected directory and |
|
1054 |
* the paths leading up to it, if any. |
|
1055 |
*/ |
|
1056 |
private void addItem(File directory) { |
|
1057 |
||
1058 |
if(directory == null) { |
|
1059 |
return; |
|
1060 |
} |
|
1061 |
||
1842
824c7f885a64
6776856: Code with useShellFolder field shuold be simplify
rupashka
parents:
1290
diff
changeset
|
1062 |
boolean useShellFolder = FilePane.usesShellFolder(chooser); |
824c7f885a64
6776856: Code with useShellFolder field shuold be simplify
rupashka
parents:
1290
diff
changeset
|
1063 |
|
2 | 1064 |
directories.clear(); |
1065 |
||
1066 |
File[] baseFolders; |
|
1067 |
if (useShellFolder) { |
|
2491
123954ad0034
6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents:
1853
diff
changeset
|
1068 |
baseFolders = AccessController.doPrivileged(new PrivilegedAction<File[]>() { |
123954ad0034
6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents:
1853
diff
changeset
|
1069 |
public File[] run() { |
123954ad0034
6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents:
1853
diff
changeset
|
1070 |
return (File[]) ShellFolder.get("fileChooserComboBoxFolders"); |
123954ad0034
6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents:
1853
diff
changeset
|
1071 |
} |
123954ad0034
6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents:
1853
diff
changeset
|
1072 |
}); |
2 | 1073 |
} else { |
1074 |
baseFolders = fsv.getRoots(); |
|
1075 |
} |
|
1076 |
directories.addAll(Arrays.asList(baseFolders)); |
|
1077 |
||
1078 |
// Get the canonical (full) path. This has the side |
|
1079 |
// benefit of removing extraneous chars from the path, |
|
1080 |
// for example /foo/bar/ becomes /foo/bar |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
2
diff
changeset
|
1081 |
File canonical; |
2 | 1082 |
try { |
1083 |
canonical = directory.getCanonicalFile(); |
|
1084 |
} catch (IOException e) { |
|
1085 |
// Maybe drive is not ready. Can't abort here. |
|
1086 |
canonical = directory; |
|
1087 |
} |
|
1088 |
||
1089 |
// create File instances of each directory leading up to the top |
|
1090 |
try { |
|
1091 |
File sf = useShellFolder ? ShellFolder.getShellFolder(canonical) |
|
1092 |
: canonical; |
|
1093 |
File f = sf; |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
2
diff
changeset
|
1094 |
Vector<File> path = new Vector<File>(10); |
2 | 1095 |
do { |
1096 |
path.addElement(f); |
|
1097 |
} while ((f = f.getParentFile()) != null); |
|
1098 |
||
1099 |
int pathCount = path.size(); |
|
1100 |
// Insert chain at appropriate place in vector |
|
1101 |
for (int i = 0; i < pathCount; i++) { |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
2
diff
changeset
|
1102 |
f = path.get(i); |
2 | 1103 |
if (directories.contains(f)) { |
1104 |
int topIndex = directories.indexOf(f); |
|
1105 |
for (int j = i-1; j >= 0; j--) { |
|
1106 |
directories.insertElementAt(path.get(j), topIndex+i-j); |
|
1107 |
} |
|
1108 |
break; |
|
1109 |
} |
|
1110 |
} |
|
1111 |
calculateDepths(); |
|
1112 |
setSelectedItem(sf); |
|
1113 |
} catch (FileNotFoundException ex) { |
|
1114 |
calculateDepths(); |
|
1115 |
} |
|
1116 |
} |
|
1117 |
||
1118 |
private void calculateDepths() { |
|
1119 |
depths = new int[directories.size()]; |
|
1120 |
for (int i = 0; i < depths.length; i++) { |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
2
diff
changeset
|
1121 |
File dir = directories.get(i); |
2 | 1122 |
File parent = dir.getParentFile(); |
1123 |
depths[i] = 0; |
|
1124 |
if (parent != null) { |
|
1125 |
for (int j = i-1; j >= 0; j--) { |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
2
diff
changeset
|
1126 |
if (parent.equals(directories.get(j))) { |
2 | 1127 |
depths[i] = depths[j] + 1; |
1128 |
break; |
|
1129 |
} |
|
1130 |
} |
|
1131 |
} |
|
1132 |
} |
|
1133 |
} |
|
1134 |
||
1135 |
public int getDepth(int i) { |
|
1136 |
return (depths != null && i >= 0 && i < depths.length) ? depths[i] : 0; |
|
1137 |
} |
|
1138 |
||
1139 |
public void setSelectedItem(Object selectedDirectory) { |
|
1140 |
this.selectedDirectory = (File)selectedDirectory; |
|
1141 |
fireContentsChanged(this, -1, -1); |
|
1142 |
} |
|
1143 |
||
1144 |
public Object getSelectedItem() { |
|
1145 |
return selectedDirectory; |
|
1146 |
} |
|
1147 |
||
1148 |
public int getSize() { |
|
1149 |
return directories.size(); |
|
1150 |
} |
|
1151 |
||
10100
c525c5fbb86c
7031941: Use generificated JComboBox and JList in core libraries
rupashka
parents:
5506
diff
changeset
|
1152 |
public File getElementAt(int index) { |
2 | 1153 |
return directories.elementAt(index); |
1154 |
} |
|
1155 |
} |
|
1156 |
||
1157 |
// |
|
1158 |
// Renderer for Types ComboBox |
|
1159 |
// |
|
1160 |
protected FilterComboBoxRenderer createFilterComboBoxRenderer() { |
|
1161 |
return new FilterComboBoxRenderer(); |
|
1162 |
} |
|
1163 |
||
1164 |
/** |
|
1165 |
* Render different type sizes and styles. |
|
1166 |
*/ |
|
1167 |
public class FilterComboBoxRenderer extends DefaultListCellRenderer { |
|
1168 |
public Component getListCellRendererComponent(JList list, |
|
1169 |
Object value, int index, boolean isSelected, |
|
1170 |
boolean cellHasFocus) { |
|
1171 |
||
1172 |
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); |
|
1173 |
||
1174 |
if (value != null && value instanceof FileFilter) { |
|
1175 |
setText(((FileFilter)value).getDescription()); |
|
1176 |
} |
|
1177 |
||
1178 |
return this; |
|
1179 |
} |
|
1180 |
} |
|
1181 |
||
1182 |
// |
|
1183 |
// DataModel for Types Comboxbox |
|
1184 |
// |
|
1185 |
protected FilterComboBoxModel createFilterComboBoxModel() { |
|
1186 |
return new FilterComboBoxModel(); |
|
1187 |
} |
|
1188 |
||
1189 |
/** |
|
1190 |
* Data model for a type-face selection combo-box. |
|
1191 |
*/ |
|
10100
c525c5fbb86c
7031941: Use generificated JComboBox and JList in core libraries
rupashka
parents:
5506
diff
changeset
|
1192 |
protected class FilterComboBoxModel extends AbstractListModel<FileFilter> implements ComboBoxModel<FileFilter>, |
c525c5fbb86c
7031941: Use generificated JComboBox and JList in core libraries
rupashka
parents:
5506
diff
changeset
|
1193 |
PropertyChangeListener { |
2 | 1194 |
protected FileFilter[] filters; |
1195 |
protected FilterComboBoxModel() { |
|
1196 |
super(); |
|
1197 |
filters = getFileChooser().getChoosableFileFilters(); |
|
1198 |
} |
|
1199 |
||
1200 |
public void propertyChange(PropertyChangeEvent e) { |
|
1201 |
String prop = e.getPropertyName(); |
|
1202 |
if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) { |
|
1203 |
filters = (FileFilter[]) e.getNewValue(); |
|
1204 |
fireContentsChanged(this, -1, -1); |
|
1205 |
} else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) { |
|
1206 |
fireContentsChanged(this, -1, -1); |
|
1207 |
} |
|
1208 |
} |
|
1209 |
||
1210 |
public void setSelectedItem(Object filter) { |
|
1211 |
if(filter != null) { |
|
1212 |
getFileChooser().setFileFilter((FileFilter) filter); |
|
1213 |
fireContentsChanged(this, -1, -1); |
|
1214 |
} |
|
1215 |
} |
|
1216 |
||
1217 |
public Object getSelectedItem() { |
|
1218 |
// Ensure that the current filter is in the list. |
|
1219 |
// NOTE: we shouldnt' have to do this, since JFileChooser adds |
|
1220 |
// the filter to the choosable filters list when the filter |
|
1221 |
// is set. Lets be paranoid just in case someone overrides |
|
1222 |
// setFileFilter in JFileChooser. |
|
1223 |
FileFilter currentFilter = getFileChooser().getFileFilter(); |
|
1224 |
boolean found = false; |
|
1225 |
if(currentFilter != null) { |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
2
diff
changeset
|
1226 |
for (FileFilter filter : filters) { |
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
2
diff
changeset
|
1227 |
if (filter == currentFilter) { |
2 | 1228 |
found = true; |
1229 |
} |
|
1230 |
} |
|
1231 |
if(found == false) { |
|
1232 |
getFileChooser().addChoosableFileFilter(currentFilter); |
|
1233 |
} |
|
1234 |
} |
|
1235 |
return getFileChooser().getFileFilter(); |
|
1236 |
} |
|
1237 |
||
1238 |
public int getSize() { |
|
1239 |
if(filters != null) { |
|
1240 |
return filters.length; |
|
1241 |
} else { |
|
1242 |
return 0; |
|
1243 |
} |
|
1244 |
} |
|
1245 |
||
10100
c525c5fbb86c
7031941: Use generificated JComboBox and JList in core libraries
rupashka
parents:
5506
diff
changeset
|
1246 |
public FileFilter getElementAt(int index) { |
2 | 1247 |
if(index > getSize() - 1) { |
1248 |
// This shouldn't happen. Try to recover gracefully. |
|
1249 |
return getFileChooser().getFileFilter(); |
|
1250 |
} |
|
1251 |
if(filters != null) { |
|
1252 |
return filters[index]; |
|
1253 |
} else { |
|
1254 |
return null; |
|
1255 |
} |
|
1256 |
} |
|
1257 |
} |
|
1258 |
||
1259 |
public void valueChanged(ListSelectionEvent e) { |
|
1260 |
JFileChooser fc = getFileChooser(); |
|
1261 |
File f = fc.getSelectedFile(); |
|
1262 |
if (!e.getValueIsAdjusting() && f != null && !getFileChooser().isTraversable(f)) { |
|
1263 |
setFileName(fileNameString(f)); |
|
1264 |
} |
|
1265 |
} |
|
1266 |
||
1267 |
/** |
|
1268 |
* Acts when DirectoryComboBox has changed the selected item. |
|
1269 |
*/ |
|
1270 |
protected class DirectoryComboBoxAction implements ActionListener { |
|
1271 |
||
1272 |
||
1273 |
||
1274 |
||
1275 |
public void actionPerformed(ActionEvent e) { |
|
1276 |
File f = (File)directoryComboBox.getSelectedItem(); |
|
1277 |
getFileChooser().setCurrentDirectory(f); |
|
1278 |
} |
|
1279 |
} |
|
1280 |
||
1281 |
protected JButton getApproveButton(JFileChooser fc) { |
|
1282 |
return approveButton; |
|
1283 |
} |
|
1284 |
||
1285 |
public FileView getFileView(JFileChooser fc) { |
|
1286 |
return fileView; |
|
1287 |
} |
|
1288 |
||
1289 |
// *********************** |
|
1290 |
// * FileView operations * |
|
1291 |
// *********************** |
|
1292 |
protected class WindowsFileView extends BasicFileView { |
|
1293 |
/* FileView type descriptions */ |
|
1294 |
||
1295 |
public Icon getIcon(File f) { |
|
1296 |
Icon icon = getCachedIcon(f); |
|
1297 |
if (icon != null) { |
|
1298 |
return icon; |
|
1299 |
} |
|
1300 |
if (f != null) { |
|
1301 |
icon = getFileChooser().getFileSystemView().getSystemIcon(f); |
|
1302 |
} |
|
1303 |
if (icon == null) { |
|
1304 |
icon = super.getIcon(f); |
|
1305 |
} |
|
1306 |
cacheIcon(f, icon); |
|
1307 |
return icon; |
|
1308 |
} |
|
1309 |
} |
|
1310 |
} |