< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java

Print this page

        

*** 48,105 **** --- 48,133 ---- * @author Jeff Dinkins */ public class BasicFileChooserUI extends FileChooserUI { /* FileView icons */ + /** Directory icon */ protected Icon directoryIcon = null; + /** File icon */ protected Icon fileIcon = null; + /** Computer icon */ protected Icon computerIcon = null; + /** Hard drive icon */ protected Icon hardDriveIcon = null; + /** Floppy drive icon */ protected Icon floppyDriveIcon = null; + /** New folder icon */ protected Icon newFolderIcon = null; + /** Up folder icon */ protected Icon upFolderIcon = null; + /** Home folder icon */ protected Icon homeFolderIcon = null; + /** List view icon */ protected Icon listViewIcon = null; + /** Details view icon */ protected Icon detailsViewIcon = null; + /** View menu icon */ protected Icon viewMenuIcon = null; + /** Save button mnemonic */ protected int saveButtonMnemonic = 0; + /** Open button mnemonic */ protected int openButtonMnemonic = 0; + /** Cancel button mnemonic */ protected int cancelButtonMnemonic = 0; + /** Update button mnemonic */ protected int updateButtonMnemonic = 0; + /** Help button mnemonic */ protected int helpButtonMnemonic = 0; /** * The mnemonic keycode used for the approve button when a directory * is selected and the current selection mode is FILES_ONLY. * * @since 1.4 */ protected int directoryOpenButtonMnemonic = 0; + /** Save button text */ protected String saveButtonText = null; + /** Open button text */ protected String openButtonText = null; + /** Cancel button text */ protected String cancelButtonText = null; + /** Update button text */ protected String updateButtonText = null; + /** Help button text */ protected String helpButtonText = null; /** * The label text displayed on the approve button when a directory * is selected and the current selection mode is FILES_ONLY. * * @since 1.4 */ protected String directoryOpenButtonText = null; + /** Open dialog text */ private String openDialogTitleText = null; + /** Save dialog text */ private String saveDialogTitleText = null; + /** Save button tool tip text */ protected String saveButtonToolTipText = null; + /** Open button tool tip text */ protected String openButtonToolTipText = null; + /** Cancel button tool tip text */ protected String cancelButtonToolTipText = null; + /** Update button tool tip text */ protected String updateButtonToolTipText = null; + /** Help button tool tip text */ protected String helpButtonToolTipText = null; /** * The tooltip text displayed on the approve button when a directory * is selected and the current selection mode is FILES_ONLY.
*** 156,168 **** --- 184,204 ---- */ public static ComponentUI createUI(JComponent c) { return new BasicFileChooserUI((JFileChooser) c); } + /** + * Constructs a {@code BasicFileChooserUI}. + * @param b file chooser + */ public BasicFileChooserUI(JFileChooser b) { } + /** + * Installs the UI. + * @param c the component + */ public void installUI(JComponent c) { accessoryPanel = new JPanel(new BorderLayout()); filechooser = (JFileChooser) c; createModel();
*** 173,182 **** --- 209,222 ---- installComponents(filechooser); installListeners(filechooser); filechooser.applyComponentOrientation(filechooser.getComponentOrientation()); } + /** + * Uninstalls the UI. + * @param c the component + */ public void uninstallUI(JComponent c) { uninstallListeners(filechooser); uninstallComponents(filechooser); uninstallDefaults(filechooser);
*** 188,203 **** --- 228,255 ---- getFileChooser().removeAll(); handler = null; } + /** + * Installs the components. + * @param fc the file chooser + */ public void installComponents(JFileChooser fc) { } + /** + * Uninstalls the components. + * @param fc the file chooser + */ public void uninstallComponents(JFileChooser fc) { } + /** + * Installs the listeners. + * @param fc the file chooser + */ protected void installListeners(JFileChooser fc) { propertyChangeListener = createPropertyChangeListener(fc); if(propertyChangeListener != null) { fc.addPropertyChangeListener(propertyChangeListener); }
*** 239,248 **** --- 291,304 ---- getChangeToParentDirectoryAction()); return map; } + /** + * Uninstalls the listeners. + * @param fc the file chooser + */ protected void uninstallListeners(JFileChooser fc) { if(propertyChangeListener != null) { fc.removePropertyChangeListener(propertyChangeListener); } fc.removePropertyChangeListener(getModel());
*** 250,259 **** --- 306,319 ---- WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null); SwingUtilities.replaceUIActionMap(fc, null); } + /** + * Installs the defaults. + * @param fc the file chooser + */ protected void installDefaults(JFileChooser fc) { installIcons(fc); installStrings(fc); usesSingleFilePane = UIManager.getBoolean("FileChooser.usesSingleFilePane"); readOnly = UIManager.getBoolean("FileChooser.readOnly");
*** 262,271 **** --- 322,335 ---- fc.setTransferHandler(defaultTransferHandler); } LookAndFeel.installProperty(fc, "opaque", Boolean.FALSE); } + /** + * Installs the icons. + * @param fc the file chooser + */ protected void installIcons(JFileChooser fc) { directoryIcon = UIManager.getIcon("FileView.directoryIcon"); fileIcon = UIManager.getIcon("FileView.fileIcon"); computerIcon = UIManager.getIcon("FileView.computerIcon"); hardDriveIcon = UIManager.getIcon("FileView.hardDriveIcon");
*** 277,286 **** --- 341,354 ---- detailsViewIcon = UIManager.getIcon("FileChooser.detailsViewIcon"); listViewIcon = UIManager.getIcon("FileChooser.listViewIcon"); viewMenuIcon = UIManager.getIcon("FileChooser.viewMenuIcon"); } + /** + * Installs the strings. + * @param fc the file chooser + */ protected void installStrings(JFileChooser fc) { Locale l = fc.getLocale(); newFolderErrorText = UIManager.getString("FileChooser.newFolderErrorText",l); newFolderErrorSeparator = UIManager.getString("FileChooser.newFolderErrorSeparator",l);
*** 313,330 **** --- 381,406 ---- updateButtonToolTipText = UIManager.getString("FileChooser.updateButtonToolTipText",l); helpButtonToolTipText = UIManager.getString("FileChooser.helpButtonToolTipText",l); directoryOpenButtonToolTipText = UIManager.getString("FileChooser.directoryOpenButtonToolTipText",l); } + /** + * Uninstalls the defaults. + * @param fc the file chooser + */ protected void uninstallDefaults(JFileChooser fc) { uninstallIcons(fc); uninstallStrings(fc); if (fc.getTransferHandler() instanceof UIResource) { fc.setTransferHandler(null); } } + /** + * Uninstalls the icons. + * @param fc the file chooser + */ protected void uninstallIcons(JFileChooser fc) { directoryIcon = null; fileIcon = null; computerIcon = null; hardDriveIcon = null;
*** 336,345 **** --- 412,425 ---- detailsViewIcon = null; listViewIcon = null; viewMenuIcon = null; } + /** + * Uninstalls the strings. + * @param fc the file chooser + */ protected void uninstallStrings(JFileChooser fc) { saveButtonText = null; openButtonText = null; cancelButtonText = null; updateButtonText = null;
*** 352,412 **** --- 432,547 ---- updateButtonToolTipText = null; helpButtonToolTipText = null; directoryOpenButtonToolTipText = null; } + /** + * Creates the model. + */ protected void createModel() { if (model != null) { model.invalidateFileCache(); } model = new BasicDirectoryModel(getFileChooser()); } + /** + * Returns the model. + * @return the model + */ public BasicDirectoryModel getModel() { return model; } + /** + * Creates the property change listener. + * @param fc the file chooser + * @return the property change listener + */ public PropertyChangeListener createPropertyChangeListener(JFileChooser fc) { return null; } + /** + * Returns the file name. + * @return the file name + */ public String getFileName() { return null; } + /** + * Returns the directory name. + * @return the directory name + */ public String getDirectoryName() { return null; } + /** + * Sets the file name. + * @param filename the file name + */ public void setFileName(String filename) { } + /** + * Sets the directory name. + * @param dirname the file name + */ public void setDirectoryName(String dirname) { } + /** + * {@inheritDoc} + */ public void rescanCurrentDirectory(JFileChooser fc) { } + /** + * {@inheritDoc} + */ public void ensureFileIsVisible(JFileChooser fc, File f) { } + /** + * Returns the file chooser. + * @return the file chooser + */ public JFileChooser getFileChooser() { return filechooser; } + /** + * Returns the accessory panel. + * @return the accessory panel + */ public JPanel getAccessoryPanel() { return accessoryPanel; } + /** + * Returns the approve button. + * @param fc the file chooser + * @return the approve button + */ protected JButton getApproveButton(JFileChooser fc) { return null; } + /** + * {@inheritDoc} + */ public JButton getDefaultButton(JFileChooser fc) { return getApproveButton(fc); } + /** + * Returns the approve button tool tip. + * @param fc the file chooser + * @return the approve button tool tip + */ public String getApproveButtonToolTipText(JFileChooser fc) { String tooltipText = fc.getApproveButtonToolTipText(); if(tooltipText != null) { return tooltipText; }
*** 417,426 **** --- 552,564 ---- return saveButtonToolTipText; } return null; } + /** + * Clears the icon cache. + */ public void clearIconCache() { fileView.clearIconCache(); }
*** 433,447 **** --- 571,596 ---- handler = new Handler(); } return handler; } + /** + * Creates a double click listener. + * @param fc the file chooser + * @param list the list + * @return a double click listener + */ protected MouseListener createDoubleClickListener(JFileChooser fc, JList<?> list) { return new Handler(list); } + /** + * Creates a list selection listener. + * @param fc the file chooser + * @return a list selection listener + */ public ListSelectionListener createListSelectionListener(JFileChooser fc) { return getHandler(); } private class Handler implements MouseListener, ListSelectionListener {
*** 564,579 **** --- 713,735 ---- } } } } + /** + * A double click listener. + */ protected class DoubleClickListener extends MouseAdapter { // NOTE: This class exists only for backward compatibility. All // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. Handler handler; + /** + * Constucts a {@code DoubleClickListener}. + * @param list the lsit + */ public DoubleClickListener(JList<?> list) { handler = new Handler(list); } /**
*** 585,604 **** --- 741,765 ---- */ public void mouseEntered(MouseEvent e) { handler.mouseEntered(e); } + /** {@inheritDoc} */ public void mouseClicked(MouseEvent e) { handler.mouseClicked(e); } } + /** + * A selection listener. + */ protected class SelectionListener implements ListSelectionListener { // NOTE: This class exists only for backward compatibility. All // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** {@inheritDoc} */ public void valueChanged(ListSelectionEvent e) { getHandler().valueChanged(e); } }
*** 670,679 **** --- 831,842 ---- } /** * Returns the title of this dialog + * @param fc the file chooser + * @return the title of this dialog */ public String getDialogTitle(JFileChooser fc) { String dialogTitle = fc.getDialogTitle(); if (dialogTitle != null) { return dialogTitle;
*** 684,694 **** } else { return getApproveButtonText(fc); } } ! public int getApproveButtonMnemonic(JFileChooser fc) { int mnemonic = fc.getApproveButtonMnemonic(); if (mnemonic > 0) { return mnemonic; } else if (fc.getDialogType() == JFileChooser.OPEN_DIALOG) { --- 847,861 ---- } else { return getApproveButtonText(fc); } } ! /** ! * Returns the approve button mnemonic. ! * @param fc the file chooser ! * @return the approve button mnemonic ! */ public int getApproveButtonMnemonic(JFileChooser fc) { int mnemonic = fc.getApproveButtonMnemonic(); if (mnemonic > 0) { return mnemonic; } else if (fc.getDialogType() == JFileChooser.OPEN_DIALOG) {
*** 698,707 **** --- 865,875 ---- } else { return mnemonic; } } + /** {@inheritDoc} */ public String getApproveButtonText(JFileChooser fc) { String buttonText = fc.getApproveButtonText(); if (buttonText != null) { return buttonText; } else if (fc.getDialogType() == JFileChooser.OPEN_DIALOG) {
*** 716,725 **** --- 884,897 ---- // ***************************** // ***** Directory Actions ***** // ***************************** + /** + * Returns a new folder action. + * @return a new folder action + */ public Action getNewFolderAction() { if (newFolderAction == null) { newFolderAction = new NewFolderAction(); // Note: Don't return null for readOnly, it might // break older apps.
*** 728,766 **** --- 900,960 ---- } } return newFolderAction; } + /** + * Returns a go home action. + * @return a go home action + */ public Action getGoHomeAction() { return goHomeAction; } + /** + * Returns a change to parent directory action. + * @return a change to parent directory action + */ public Action getChangeToParentDirectoryAction() { return changeToParentDirectoryAction; } + /** + * Returns an approve selection action. + * @return an approve selection action + */ public Action getApproveSelectionAction() { return approveSelectionAction; } + /** + * Returns a cancel selection action. + * @return a cancel selection action + */ public Action getCancelSelectionAction() { return cancelSelectionAction; } + /** + * Returns an update action. + * @return an update action + */ public Action getUpdateAction() { return updateAction; } /** * Creates a new folder. */ @SuppressWarnings("serial") // Superclass is not serializable across versions protected class NewFolderAction extends AbstractAction { + /** Constructs a {@code NewFolderAction}. */ protected NewFolderAction() { super(FilePane.ACTION_NEW_FOLDER); } + /** {@inheritDoc} */ public void actionPerformed(ActionEvent e) { if (readOnly) { return; } JFileChooser fc = getFileChooser();
*** 797,834 **** --- 991,1036 ---- /** * Acts on the "home" key event or equivalent event. */ @SuppressWarnings("serial") // Superclass is not serializable across versions protected class GoHomeAction extends AbstractAction { + /** Constructs a {@code GoHomeAction}. */ protected GoHomeAction() { super("Go Home"); } public void actionPerformed(ActionEvent e) { JFileChooser fc = getFileChooser(); changeDirectory(fc.getFileSystemView().getHomeDirectory()); } } + /** + * Change to parent directory action. + */ @SuppressWarnings("serial") // Superclass is not serializable across versions protected class ChangeToParentDirectoryAction extends AbstractAction { + /** Constructs a {@code ChangeToParentDirectoryAction}. */ protected ChangeToParentDirectoryAction() { super("Go Up"); putValue(Action.ACTION_COMMAND_KEY, FilePane.ACTION_CHANGE_TO_PARENT_DIRECTORY); } + /** {@inheritDoc} */ public void actionPerformed(ActionEvent e) { getFileChooser().changeToParentDirectory(); } } /** * Responds to an Open or Save request */ @SuppressWarnings("serial") // Superclass is not serializable across versions protected class ApproveSelectionAction extends AbstractAction { + /** Constructs an {@code ApproveSelectionAction}. */ protected ApproveSelectionAction() { super(FilePane.ACTION_APPROVE_SELECTION); } + /** {@inheritDoc} */ public void actionPerformed(ActionEvent e) { if (isDirectorySelected()) { File dir = getDirectory(); if (dir != null) { try {
*** 1131,1150 **** --- 1333,1354 ---- /** * Responds to a cancel request. */ @SuppressWarnings("serial") // Superclass is not serializable across versions protected class CancelSelectionAction extends AbstractAction { + /** {@inheritDoc} */ public void actionPerformed(ActionEvent e) { getFileChooser().cancelSelection(); } } /** * Rescans the files in the current directory */ @SuppressWarnings("serial") // Superclass is not serializable across versions protected class UpdateAction extends AbstractAction { + /** {@inheritDoc} */ public void actionPerformed(ActionEvent e) { JFileChooser fc = getFileChooser(); fc.setCurrentDirectory(fc.getFileSystemView().createFileObject(getDirectoryName())); fc.rescanCurrentDirectory(); }
*** 1186,1239 **** // ***************************************** // ***** default AcceptAll file filter ***** // ***************************************** protected class AcceptAllFileFilter extends FileFilter { public AcceptAllFileFilter() { } public boolean accept(File f) { return true; } public String getDescription() { return UIManager.getString("FileChooser.acceptAllFileFilterText"); } } // *********************** // * FileView operations * // *********************** protected class BasicFileView extends FileView { /* FileView type descriptions */ ! // PENDING(jeff) - pass in the icon cache size protected Hashtable<File,Icon> iconCache = new Hashtable<File,Icon>(); public BasicFileView() { } public void clearIconCache() { iconCache = new Hashtable<File,Icon>(); } public String getName(File f) { // Note: Returns display name rather than file name String fileName = null; if(f != null) { fileName = getFileChooser().getFileSystemView().getSystemDisplayName(f); } return fileName; } ! public String getDescription(File f) { return f.getName(); } public String getTypeDescription(File f) { String type = getFileChooser().getFileSystemView().getSystemTypeDescription(f); if (type == null) { if (f.isDirectory()) { type = directoryDescriptionText; --- 1390,1464 ---- // ***************************************** // ***** default AcceptAll file filter ***** // ***************************************** + /** + * Accept all file filter. + */ protected class AcceptAllFileFilter extends FileFilter { + /** Constructs an {@code AcceptAllFileFilter}. */ public AcceptAllFileFilter() { } + /** + * Returns true. + * @param f the file + * @return true + */ public boolean accept(File f) { return true; } + /** + * {@inheritDoc} + */ public String getDescription() { return UIManager.getString("FileChooser.acceptAllFileFilterText"); } } // *********************** // * FileView operations * // *********************** + /** + * A basic file view. + */ protected class BasicFileView extends FileView { /* FileView type descriptions */ ! /** The icon cache */ protected Hashtable<File,Icon> iconCache = new Hashtable<File,Icon>(); + /** Constructs a {@code BasicFileView}. */ public BasicFileView() { } + /** + * Clears the icon cache. + */ public void clearIconCache() { iconCache = new Hashtable<File,Icon>(); } + /** {@inheritDoc} */ public String getName(File f) { // Note: Returns display name rather than file name String fileName = null; if(f != null) { fileName = getFileChooser().getFileSystemView().getSystemDisplayName(f); } return fileName; } ! /** {@inheritDoc} */ public String getDescription(File f) { return f.getName(); } + /** {@inheritDoc} */ public String getTypeDescription(File f) { String type = getFileChooser().getFileSystemView().getSystemTypeDescription(f); if (type == null) { if (f.isDirectory()) { type = directoryDescriptionText;
*** 1242,1262 **** --- 1467,1498 ---- } } return type; } + /** + * Returns the cached icon for the file. + * @param f the file + * @return the cached icon for the file + */ public Icon getCachedIcon(File f) { return iconCache.get(f); } + /** + * Caches an icon for a file. + * @param f the file + * @param i the icon + */ public void cacheIcon(File f, Icon i) { if(f == null || i == null) { return; } iconCache.put(f, i); } + /** {@inheritDoc} */ public Icon getIcon(File f) { Icon icon = getCachedIcon(f); if(icon != null) { return icon; }
*** 1276,1285 **** --- 1512,1526 ---- } cacheIcon(f, icon); return icon; } + /** + * Returns whether or not a file is hidden. + * @param f the file + * @return whether or not a file is hidden + */ public Boolean isHidden(File f) { String name = f.getName(); if(name != null && name.charAt(0) == '.') { return Boolean.TRUE; } else {
< prev index next >