001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Sergey Burlak
020: * @version $Revision$
021: */package javax.swing.plaf.basic;
022:
023: import java.awt.BorderLayout;
024: import java.awt.ComponentOrientation;
025: import java.awt.datatransfer.DataFlavor;
026: import java.awt.datatransfer.Transferable;
027: import java.awt.datatransfer.UnsupportedFlavorException;
028: import java.awt.event.ActionEvent;
029: import java.awt.event.MouseAdapter;
030: import java.awt.event.MouseEvent;
031: import java.awt.event.MouseListener;
032: import java.beans.PropertyChangeEvent;
033: import java.beans.PropertyChangeListener;
034: import java.io.File;
035: import java.io.IOException;
036: import java.io.StringBufferInputStream;
037: import java.util.ArrayList;
038: import java.util.Hashtable;
039: import java.util.LinkedList;
040: import java.util.List;
041:
042: import javax.swing.AbstractAction;
043: import javax.swing.Action;
044: import javax.swing.Icon;
045: import javax.swing.JButton;
046: import javax.swing.JComponent;
047: import javax.swing.JFileChooser;
048: import javax.swing.JList;
049: import javax.swing.JPanel;
050: import javax.swing.TransferHandler;
051: import javax.swing.UIManager;
052: import javax.swing.event.ListSelectionEvent;
053: import javax.swing.event.ListSelectionListener;
054: import javax.swing.filechooser.FileFilter;
055: import javax.swing.filechooser.FileSystemView;
056: import javax.swing.filechooser.FileView;
057: import javax.swing.plaf.FileChooserUI;
058:
059: import org.apache.harmony.x.swing.StringConstants;
060: import org.apache.harmony.x.swing.Utilities;
061:
062: public class BasicFileChooserUI extends FileChooserUI {
063:
064: protected class AcceptAllFileFilter extends FileFilter {
065: public AcceptAllFileFilter() {
066: }
067:
068: public boolean accept(final File f) {
069: return true;
070: }
071:
072: public String getDescription() {
073: return UIManager
074: .getString("FileChooser.acceptAllFileFilterText");
075: }
076: }
077:
078: protected class BasicFileView extends FileView {
079: protected Hashtable<java.io.File, javax.swing.Icon> iconCache = new Hashtable<java.io.File, javax.swing.Icon>();
080:
081: public BasicFileView() {
082: }
083:
084: public void clearIconCache() {
085: iconCache.clear();
086: }
087:
088: public String getName(final File f) {
089: return fileChooser.getFileSystemView()
090: .getSystemDisplayName(f);
091: }
092:
093: public String getDescription(final File f) {
094: return getName(f);
095: }
096:
097: public String getTypeDescription(final File f) {
098: return fileChooser.getFileSystemView()
099: .getSystemTypeDescription(f);
100: }
101:
102: public Icon getCachedIcon(final File f) {
103: return f == null ? null : (Icon) iconCache.get(f);
104: }
105:
106: public void cacheIcon(final File f, final Icon i) {
107: if (f == null || i == null) {
108: return;
109: }
110: iconCache.put(f, i);
111: }
112:
113: public Icon getIcon(final File f) {
114: Icon result = getCachedIcon(f);
115: if (result == null) {
116: result = getIconForFile(f);
117: cacheIcon(f, result);
118: }
119:
120: return result;
121: }
122:
123: public Boolean isHidden(final File f) {
124: return f.isHidden() ? Boolean.TRUE : Boolean.FALSE;
125: }
126:
127: private Icon getIconForFile(final File file) {
128: FileSystemView view = getFileChooser().getFileSystemView();
129: if (file == null) {
130: return null;
131: } else if (view.isComputerNode(file)) {
132: return computerIcon;
133: } else if (view.isFloppyDrive(file)) {
134: return floppyDriveIcon;
135: } else if (view.isDrive(file)) {
136: return hardDriveIcon;
137: } else if (file.isFile()) {
138: return fileIcon;
139: } else if (file.isDirectory()) {
140: return directoryIcon;
141: } else {
142: return null;
143: }
144: }
145: }
146:
147: protected class ApproveSelectionAction extends AbstractAction {
148: protected ApproveSelectionAction() {
149: putValue(Action.NAME, approveButtonText);
150: putValue(Action.SHORT_DESCRIPTION, approveButtonToolTipText);
151: putValue(Action.MNEMONIC_KEY, new Integer(
152: approveButtonMnemonic));
153: }
154:
155: public void actionPerformed(final ActionEvent e) {
156: String fileName = getFileName();
157: if (Utilities.isEmptyString(fileName)) {
158: return;
159: }
160: if (fileChooser.isMultiSelectionEnabled()) {
161: List selectedFiles = new ArrayList();
162: String[] fileNames = splitFileNames(fileName);
163: for (int i = 0; i < fileNames.length; i++) {
164: selectedFiles.add(translateFile(fileNames[i]));
165: }
166: fileChooser.setSelectedFiles((File[]) selectedFiles
167: .toArray(new File[selectedFiles.size()]));
168: } else {
169: fileChooser.setSelectedFile(translateFile(fileName));
170: }
171:
172: fileChooser.approveSelection();
173: }
174:
175: private File translateFile(final String fileName) {
176: if (Utilities.isEmptyString(fileName)) {
177: return null;
178: }
179:
180: File candidateFile = new File(fileName);
181: if (candidateFile.isAbsolute()) {
182: return candidateFile;
183: }
184:
185: if (fileName.startsWith("\"")) {
186: String nakedFileName = fileName.endsWith("\"") ? fileName
187: .substring(1, fileName.length() - 1)
188: : fileName.substring(1);
189:
190: File fileInCurrentDir = fileChooser.getFileSystemView()
191: .getChild(fileChooser.getCurrentDirectory(),
192: nakedFileName);
193: if (fileInCurrentDir != null
194: && fileInCurrentDir.exists()
195: && fileChooser.getFileSystemView()
196: .isFileSystem(fileInCurrentDir)) {
197:
198: return fileInCurrentDir;
199: } else {
200: return fileChooser.getFileSystemView()
201: .createFileObject(nakedFileName);
202: }
203: } else {
204: return fileChooser.getFileSystemView()
205: .createFileObject(
206: fileChooser.getCurrentDirectory(),
207: fileName);
208: }
209: }
210:
211: private String[] splitFileNames(final String fileNames) {
212: if (fileNames == null) {
213: return new String[0];
214: }
215:
216: List result = new LinkedList();
217: int wordBegin = 0;
218: boolean insideWord = false;
219: for (int i = 0; i < fileNames.length(); i++) {
220: char curChar = fileNames.charAt(i);
221: if (Character.isWhitespace(curChar) && !insideWord) {
222: continue;
223: }
224:
225: if (curChar == '\"') {
226: if (!insideWord) {
227: insideWord = true;
228: wordBegin = i;
229: } else {
230: result.add(fileNames
231: .substring(wordBegin, i + 1));
232: insideWord = false;
233: }
234: }
235: }
236: if (insideWord || result.isEmpty()) {
237: return new String[] { fileNames };
238: } else {
239: return (String[]) result.toArray(new String[result
240: .size()]);
241: }
242: }
243: }
244:
245: protected class CancelSelectionAction extends AbstractAction {
246: protected CancelSelectionAction() {
247: putValue(AbstractAction.NAME, cancelButtonText);
248: putValue(AbstractAction.SHORT_DESCRIPTION,
249: cancelButtonToolTipText);
250: }
251:
252: public void actionPerformed(final ActionEvent e) {
253: fileChooser.cancelSelection();
254: }
255: }
256:
257: protected class ChangeToParentDirectoryAction extends
258: AbstractAction {
259: protected ChangeToParentDirectoryAction() {
260: putValue(AbstractAction.NAME, upFolderButtonText);
261: putValue(AbstractAction.SHORT_DESCRIPTION,
262: upFolderButtonToolTipText);
263: putValue(AbstractAction.SMALL_ICON, upFolderIcon);
264: }
265:
266: public void actionPerformed(final ActionEvent e) {
267: fileChooser.changeToParentDirectory();
268: }
269: }
270:
271: protected class GoHomeAction extends AbstractAction {
272: protected GoHomeAction() {
273: putValue(AbstractAction.NAME, homeFolderButtonText);
274: putValue(AbstractAction.SHORT_DESCRIPTION,
275: homeFolderButtonToolTipText);
276: putValue(AbstractAction.SMALL_ICON, homeFolderIcon);
277: }
278:
279: public void actionPerformed(final ActionEvent e) {
280: fileChooser.setCurrentDirectory(fileChooser
281: .getFileSystemView().getHomeDirectory());
282: }
283: }
284:
285: protected class NewFolderAction extends AbstractAction {
286: protected NewFolderAction() {
287: putValue(AbstractAction.NAME, newFolderButtonText);
288: putValue(AbstractAction.SHORT_DESCRIPTION,
289: newFolderButtonToolTipText);
290: putValue(AbstractAction.SMALL_ICON, newFolderIcon);
291: }
292:
293: public void actionPerformed(final ActionEvent e) {
294: try {
295: File newFolder = fileChooser.getFileSystemView()
296: .createNewFolder(
297: fileChooser.getCurrentDirectory());
298: fileChooser.rescanCurrentDirectory();
299: fileChooser.setSelectedFile(newFolder);
300: } catch (IOException ioe) {
301: }
302: }
303: }
304:
305: protected class UpdateAction extends AbstractAction {
306: protected UpdateAction() {
307: putValue(AbstractAction.NAME, updateButtonText);
308: putValue(AbstractAction.SHORT_DESCRIPTION,
309: updateButtonToolTipText);
310: }
311:
312: public void actionPerformed(final ActionEvent e) {
313: fileChooser.rescanCurrentDirectory();
314: }
315: }
316:
317: protected class DoubleClickListener extends MouseAdapter {
318: private JList list;
319:
320: public DoubleClickListener(final JList list) {
321: this .list = list;
322: }
323:
324: public void mouseClicked(final MouseEvent e) {
325: if (e.getButton() != MouseEvent.BUTTON1) {
326: return;
327: }
328:
329: if (e.getClickCount() != 2) {
330: return;
331: }
332: File file = (File) list.getSelectedValue();
333: if (file != null && file.isDirectory()) {
334: getFileChooser().setCurrentDirectory(file);
335: return;
336: }
337:
338: approveSelectionAction.actionPerformed(null);
339: }
340: }
341:
342: //Never used by Metal L&F
343: protected class SelectionListener implements ListSelectionListener {
344: public void valueChanged(final ListSelectionEvent e) {
345: }
346: }
347:
348: private class PropertyChangeHandler implements
349: PropertyChangeListener {
350: public void propertyChange(final PropertyChangeEvent event) {
351: String changedProperty = event.getPropertyName();
352: if (JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY
353: .equals(changedProperty)) {
354: final int type = ((Integer) event.getNewValue())
355: .intValue();
356: setButtonsAttrs(type);
357: } else if (JFileChooser.DIALOG_TITLE_CHANGED_PROPERTY
358: .equals(changedProperty)) {
359: dialogTitleText = (String) event.getNewValue();
360: } else if (JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY
361: .equals(changedProperty)) {
362: if (event.getNewValue() == null) {
363: setButtonsAttrs(fileChooser.getDialogType());
364: } else {
365: approveButtonText = (String) event.getNewValue();
366: }
367: } else if (StringConstants.COMPONENT_ORIENTATION
368: .equals(changedProperty)) {
369: ComponentOrientation co = (ComponentOrientation) event
370: .getNewValue();
371: fileChooser.applyComponentOrientation(co);
372: }
373: }
374: }
375:
376: // TODO: file flavor should also be supported
377: private class FileChooserTransferHandler extends TransferHandler {
378: private final String lineSeparator = System
379: .getProperty("line.separator");
380:
381: public int getSourceActions(final JComponent c) {
382: return COPY;
383: }
384:
385: protected Transferable createTransferable(final JComponent c) {
386: File[] selectedFiles;
387: if (fileChooser.isMultiSelectionEnabled()) {
388: selectedFiles = fileChooser.getSelectedFiles();
389: } else {
390: selectedFiles = fileChooser.getSelectedFile() != null ? new File[] { fileChooser
391: .getSelectedFile() }
392: : null;
393: }
394:
395: if (selectedFiles == null || selectedFiles.length == 0) {
396: if (isDirectorySelected()) {
397: selectedFiles = new File[] { getDirectory() };
398: } else {
399: return null;
400: }
401: }
402:
403: final File[] transferingFiles = selectedFiles;
404: return new Transferable() {
405: public Object getTransferData(final DataFlavor flavor)
406: throws UnsupportedFlavorException, IOException {
407: if (flavor.equals(DataFlavor.stringFlavor)
408: || flavor
409: .equals(DataFlavor.plainTextFlavor)) {
410:
411: StringBuffer content = new StringBuffer();
412: for (int i = 0; i < transferingFiles.length; i++) {
413: content.append(transferingFiles[i]
414: .getAbsolutePath());
415: if (i < transferingFiles.length - 1) {
416: content.append(lineSeparator);
417: }
418: }
419:
420: return flavor.equals(DataFlavor.stringFlavor) ? (Object) content
421: .toString()
422: : new StringBufferInputStream(content
423: .toString());
424: }
425:
426: throw new UnsupportedFlavorException(flavor);
427: }
428:
429: public boolean isDataFlavorSupported(
430: final DataFlavor flavor) {
431: return flavor.equals(DataFlavor.stringFlavor)
432: || flavor
433: .equals(DataFlavor.plainTextFlavor);
434: }
435:
436: public DataFlavor[] getTransferDataFlavors() {
437: return new DataFlavor[] { DataFlavor.stringFlavor,
438: DataFlavor.plainTextFlavor };
439: }
440: };
441: }
442: }
443:
444: protected Icon directoryIcon;
445: protected Icon fileIcon;
446: protected Icon computerIcon;
447: protected Icon hardDriveIcon;
448: protected Icon floppyDriveIcon;
449: protected Icon newFolderIcon;
450: protected Icon upFolderIcon;
451: protected Icon homeFolderIcon;
452: protected Icon listViewIcon;
453: protected Icon detailsViewIcon;
454: protected int saveButtonMnemonic;
455: protected int openButtonMnemonic;
456: protected int cancelButtonMnemonic;
457: protected int updateButtonMnemonic;
458: protected int helpButtonMnemonic;
459: protected int directoryOpenButtonMnemonic;
460: protected String saveButtonText;
461: protected String openButtonText;
462: protected String cancelButtonText;
463: protected String updateButtonText;
464: protected String helpButtonText;
465: protected String directoryOpenButtonText;
466: protected String saveButtonToolTipText;
467: protected String openButtonToolTipText;
468: protected String cancelButtonToolTipText;
469: protected String updateButtonToolTipText;
470: protected String helpButtonToolTipText;
471: protected String directoryOpenButtonToolTipText;
472: private String newFolderButtonText;
473: private String newFolderButtonToolTipText;
474: private String upFolderButtonText;
475: private String upFolderButtonToolTipText;
476: private String homeFolderButtonText;
477: private String homeFolderButtonToolTipText;
478:
479: private JFileChooser fileChooser;
480: private BasicDirectoryModel model;
481: private FileView fileView;
482: private JPanel accessoryPanel;
483:
484: private String openDialogTitleText;
485: private String saveDialogTitleText;
486:
487: private String dialogTitleText;
488: private String approveButtonText;
489: private String approveButtonToolTipText;
490: private int approveButtonMnemonic;
491: private boolean isDirectorySelected;
492:
493: private PropertyChangeListener propertyChangeHandler;
494: private AcceptAllFileFilter acceptAllFileFilter = new AcceptAllFileFilter();
495: private String fileName;
496: private File directory;
497:
498: private Action approveSelectionAction;
499: private Action updateAction;
500: private Action cancelSelectionAction;
501: private Action changeToParentDirAction;
502: private Action goHomeAction;
503: private Action newFolderAction;
504:
505: public BasicFileChooserUI(final JFileChooser fc) {
506: this .fileChooser = fc;
507: }
508:
509: public void installUI(final JComponent c) {
510: fileChooser = (JFileChooser) c;
511:
512: fileView = new BasicFileView();
513: createModel();
514:
515: installDefaults(fileChooser);
516: installIcons(fileChooser);
517: installStrings(fileChooser);
518: installComponents(fileChooser);
519: installListeners(fileChooser);
520:
521: fileChooser
522: .setTransferHandler(new FileChooserTransferHandler());
523: }
524:
525: public void uninstallUI(final JComponent c) {
526: uninstallListeners(fileChooser);
527: uninstallComponents(fileChooser);
528: uninstallDefaults(fileChooser);
529: uninstallIcons(fileChooser);
530: uninstallStrings(fileChooser);
531: model = null;
532: accessoryPanel = null;
533: }
534:
535: public void installComponents(final JFileChooser fc) {
536: accessoryPanel = new JPanel(new BorderLayout());
537:
538: approveSelectionAction = new ApproveSelectionAction();
539: updateAction = new UpdateAction();
540: cancelSelectionAction = new CancelSelectionAction();
541: changeToParentDirAction = new ChangeToParentDirectoryAction();
542: goHomeAction = new GoHomeAction();
543: newFolderAction = new NewFolderAction();
544: }
545:
546: public void uninstallComponents(final JFileChooser fc) {
547: accessoryPanel = null;
548: }
549:
550: protected void installListeners(final JFileChooser fc) {
551: propertyChangeHandler = new PropertyChangeHandler();
552: fileChooser.addPropertyChangeListener(propertyChangeHandler);
553:
554: Utilities.installKeyboardActions(fc,
555: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
556: "FileChooser.ancestorInputMap", null);
557: fc.getActionMap().put("cancelSelection", cancelSelectionAction);
558: }
559:
560: protected void uninstallListeners(final JFileChooser fc) {
561: fileChooser.removePropertyChangeListener(propertyChangeHandler);
562:
563: Utilities.uninstallKeyboardActions(fc,
564: JComponent.WHEN_IN_FOCUSED_WINDOW);
565: }
566:
567: protected void installDefaults(final JFileChooser fc) {
568: if (fc == null) {
569: throw new NullPointerException();
570: }
571:
572: helpButtonMnemonic = UIManager
573: .getInt("FileChooser.helpButtonMnemonic");
574: directoryOpenButtonMnemonic = UIManager
575: .getInt("FileChooser.directoryOpenButtonMnemonic");
576:
577: openDialogTitleText = UIManager
578: .getString("FileChooser.openDialogTitleText");
579: saveDialogTitleText = UIManager
580: .getString("FileChooser.saveDialogTitleText");
581: }
582:
583: protected void installIcons(final JFileChooser fc) {
584: directoryIcon = UIManager.getIcon("FileView.directoryIcon");
585: fileIcon = UIManager.getIcon("FileView.fileIcon");
586: computerIcon = UIManager.getIcon("FileView.computerIcon");
587: hardDriveIcon = UIManager.getIcon("FileView.hardDriveIcon");
588: floppyDriveIcon = UIManager.getIcon("FileView.floppyDriveIcon");
589: newFolderIcon = UIManager.getIcon("FileChooser.newFolderIcon");
590: upFolderIcon = UIManager.getIcon("FileChooser.upFolderIcon");
591: homeFolderIcon = UIManager
592: .getIcon("FileChooser.homeFolderIcon");
593: listViewIcon = UIManager.getIcon("FileChooser.listViewIcon");
594: detailsViewIcon = UIManager
595: .getIcon("FileChooser.detailsViewIcon");
596:
597: clearIconCache();
598:
599: }
600:
601: protected void installStrings(final JFileChooser fc) {
602: saveButtonText = UIManager
603: .getString("FileChooser.saveButtonText");
604: openButtonText = UIManager
605: .getString("FileChooser.openButtonText");
606: cancelButtonText = UIManager
607: .getString("FileChooser.cancelButtonText");
608: updateButtonText = UIManager
609: .getString("FileChooser.updateButtonText");
610: helpButtonText = UIManager
611: .getString("FileChooser.helpButtonText");
612: directoryOpenButtonText = UIManager
613: .getString("FileChooser.directoryOpenButtonText");
614: newFolderButtonText = UIManager
615: .getString("FileChooser.newFolderAccessibleName");
616: upFolderButtonText = UIManager
617: .getString("FileChooser.upFolderAccessibleName");
618: homeFolderButtonText = UIManager
619: .getString("FileChooser.homeFolderAccessibleName");
620:
621: saveButtonToolTipText = UIManager
622: .getString("FileChooser.saveButtonToolTipText");
623: openButtonToolTipText = UIManager
624: .getString("FileChooser.openButtonToolTipText");
625: cancelButtonToolTipText = UIManager
626: .getString("FileChooser.cancelButtonToolTipText");
627: updateButtonToolTipText = UIManager
628: .getString("FileChooser.updateButtonToolTipText");
629: helpButtonToolTipText = UIManager
630: .getString("FileChooser.helpButtonToolTipText");
631: directoryOpenButtonToolTipText = UIManager
632: .getString("FileChooser.directoryOpenButtonToolTipText");
633: newFolderButtonToolTipText = UIManager
634: .getString("FileChooser.newFolderToolTipText");
635: upFolderButtonToolTipText = UIManager
636: .getString("FileChooser.upFolderToolTipText");
637: homeFolderButtonToolTipText = UIManager
638: .getString("FileChooser.homeFolderToolTipText");
639:
640: setButtonsAttrs(fileChooser.getDialogType());
641: }
642:
643: protected void uninstallDefaults(final JFileChooser fc) {
644: fileChooser.setTransferHandler(null);
645: }
646:
647: protected void uninstallIcons(final JFileChooser fc) {
648: clearIconCache();
649: }
650:
651: protected void uninstallStrings(final JFileChooser fc) {
652: }
653:
654: protected void createModel() {
655: model = new BasicDirectoryModel(fileChooser);
656: }
657:
658: public BasicDirectoryModel getModel() {
659: return model;
660: }
661:
662: public PropertyChangeListener createPropertyChangeListener(
663: final JFileChooser fc) {
664: return null;
665: }
666:
667: public String getFileName() {
668: return fileName;
669: }
670:
671: public String getDirectoryName() {
672: return null;
673: }
674:
675: public void setFileName(final String filename) {
676: fileName = filename;
677: }
678:
679: public void setDirectoryName(final String dirname) {
680: }
681:
682: public void rescanCurrentDirectory(final JFileChooser fc) {
683: }
684:
685: public void ensureFileIsVisible(final JFileChooser fc, final File f) {
686: if (fileChooser != null) {
687: fileChooser.ensureFileIsVisible(f);
688: }
689: }
690:
691: public JFileChooser getFileChooser() {
692: return fileChooser;
693: }
694:
695: public JPanel getAccessoryPanel() {
696: return accessoryPanel;
697: }
698:
699: public void clearIconCache() {
700: if (fileView instanceof BasicFileView) {
701: ((BasicFileView) fileView).clearIconCache();
702: }
703: }
704:
705: protected MouseListener createDoubleClickListener(
706: final JFileChooser fc, final JList list) {
707: return new DoubleClickListener(list);
708: }
709:
710: public ListSelectionListener createListSelectionListener(
711: final JFileChooser fc) {
712: return new SelectionListener();
713: }
714:
715: protected boolean isDirectorySelected() {
716: return isDirectorySelected;
717: }
718:
719: protected void setDirectorySelected(final boolean b) {
720: isDirectorySelected = b;
721: }
722:
723: protected File getDirectory() {
724: return directory;
725: }
726:
727: protected void setDirectory(final File f) {
728: directory = f;
729: }
730:
731: public FileFilter getAcceptAllFileFilter(final JFileChooser fc) {
732: return acceptAllFileFilter;
733: }
734:
735: public FileView getFileView(final JFileChooser fc) {
736: return fileView;
737: }
738:
739: public String getDialogTitle(final JFileChooser fc) {
740: return dialogTitleText;
741: }
742:
743: protected JButton getApproveButton(final JFileChooser fc) {
744: return null;
745: }
746:
747: public String getApproveButtonToolTipText(final JFileChooser fc) {
748: if (fc == null) {
749: throw new NullPointerException();
750: }
751:
752: return approveButtonToolTipText;
753: }
754:
755: public int getApproveButtonMnemonic(final JFileChooser fc) {
756: return approveButtonMnemonic;
757: }
758:
759: public String getApproveButtonText(final JFileChooser fc) {
760: return approveButtonText;
761: }
762:
763: public Action getNewFolderAction() {
764: return newFolderAction;
765: }
766:
767: public Action getGoHomeAction() {
768: return goHomeAction;
769: }
770:
771: public Action getChangeToParentDirectoryAction() {
772: return changeToParentDirAction;
773: }
774:
775: public Action getApproveSelectionAction() {
776: return approveSelectionAction;
777: }
778:
779: public Action getCancelSelectionAction() {
780: return cancelSelectionAction;
781: }
782:
783: public Action getUpdateAction() {
784: return updateAction;
785: }
786:
787: private void setButtonsAttrs(final int type) {
788: if (type == JFileChooser.OPEN_DIALOG) {
789: dialogTitleText = openDialogTitleText;
790: approveButtonText = openButtonText;
791: approveButtonToolTipText = openButtonToolTipText;
792: } else if (type == JFileChooser.SAVE_DIALOG) {
793: dialogTitleText = saveDialogTitleText;
794: approveButtonText = saveButtonText;
795: approveButtonToolTipText = saveButtonToolTipText;
796: } else {
797: dialogTitleText = null;
798: approveButtonText = fileChooser.getApproveButtonText();
799: approveButtonToolTipText = null;
800: approveButtonMnemonic = 0;
801: }
802:
803: if (approveSelectionAction != null) {
804: approveSelectionAction.putValue(Action.NAME,
805: approveButtonText);
806: approveSelectionAction.putValue(Action.SHORT_DESCRIPTION,
807: approveButtonToolTipText);
808: approveSelectionAction.putValue(Action.MNEMONIC_KEY,
809: new Integer(approveButtonMnemonic));
810: }
811: }
812: }
|