FileDocCategorySizeDatePackage
BasicFileChooserUI.javaAPI DocJava SE 6 API37846Tue Jun 10 00:26:46 BST 2008javax.swing.plaf.basic

BasicFileChooserUI

public class BasicFileChooserUI extends FileChooserUI
Basic L&F implementation of a FileChooser.
version
%i% %g%
author
Jeff Dinkins

Fields Summary
protected Icon
directoryIcon
protected Icon
fileIcon
protected Icon
computerIcon
protected Icon
hardDriveIcon
protected Icon
floppyDriveIcon
protected Icon
newFolderIcon
protected Icon
upFolderIcon
protected Icon
homeFolderIcon
protected Icon
listViewIcon
protected Icon
detailsViewIcon
protected int
saveButtonMnemonic
protected int
openButtonMnemonic
protected int
cancelButtonMnemonic
protected int
updateButtonMnemonic
protected int
helpButtonMnemonic
protected int
directoryOpenButtonMnemonic
The mnemonic keycode used for the approve button when a directory is selected and the current selection mode is FILES_ONLY.
protected String
saveButtonText
protected String
openButtonText
protected String
cancelButtonText
protected String
updateButtonText
protected String
helpButtonText
protected String
directoryOpenButtonText
The label text displayed on the approve button when a directory is selected and the current selection mode is FILES_ONLY.
private String
openDialogTitleText
private String
saveDialogTitleText
protected String
saveButtonToolTipText
protected String
openButtonToolTipText
protected String
cancelButtonToolTipText
protected String
updateButtonToolTipText
protected String
helpButtonToolTipText
protected String
directoryOpenButtonToolTipText
The tooltip text displayed on the approve button when a directory is selected and the current selection mode is FILES_ONLY.
private Action
approveSelectionAction
private Action
cancelSelectionAction
private Action
updateAction
private Action
newFolderAction
private Action
goHomeAction
private Action
changeToParentDirectoryAction
private String
newFolderErrorSeparator
private String
newFolderErrorText
private String
fileDescriptionText
private String
directoryDescriptionText
private JFileChooser
filechooser
private boolean
directorySelected
private File
directory
private PropertyChangeListener
propertyChangeListener
private AcceptAllFileFilter
acceptAllFileFilter
private FileFilter
actualFileFilter
private GlobFilter
globFilter
private BasicDirectoryModel
model
private BasicFileView
fileView
private boolean
usesSingleFilePane
private boolean
readOnly
private JPanel
accessoryPanel
private Handler
handler
private static final TransferHandler
defaultTransferHandler
Constructors Summary
public BasicFileChooserUI(JFileChooser b)



       
    
Methods Summary
private voidchangeDirectory(java.io.File dir)

	JFileChooser fc = getFileChooser();
	// Traverse shortcuts on Windows
	if (dir != null) {
	    try {
                ShellFolder shellFolder = ShellFolder.getShellFolder(dir);
                if (shellFolder.isLink()) {
                    File linkedTo = shellFolder.getLinkLocation();
                    if (linkedTo != null && fc.isTraversable(linkedTo)) {
                        dir = linkedTo;
                    } else {
                        return;
                    }
                }
	    } catch (FileNotFoundException ex) {
		return;
	    }
	}
	fc.setCurrentDirectory(dir);
        if (fc.getFileSelectionMode() == JFileChooser.FILES_AND_DIRECTORIES &&
            fc.getFileSystemView().isFileSystem(dir)) {

            setFileName(dir.getAbsolutePath());
        }
    
public voidclearIconCache()

	fileView.clearIconCache();
    
javax.swing.ActionMapcreateActionMap()

	ActionMap map = new ActionMapUIResource();

	Action refreshAction = new UIAction(FilePane.ACTION_REFRESH) {
	    public void actionPerformed(ActionEvent evt) {
		getFileChooser().rescanCurrentDirectory();
	    }
	};

        map.put(FilePane.ACTION_APPROVE_SELECTION, getApproveSelectionAction());
	map.put(FilePane.ACTION_CANCEL, getCancelSelectionAction());
	map.put(FilePane.ACTION_REFRESH, refreshAction);
        map.put(FilePane.ACTION_CHANGE_TO_PARENT_DIRECTORY,
		getChangeToParentDirectoryAction());
	return map;
    
protected java.awt.event.MouseListenercreateDoubleClickListener(javax.swing.JFileChooser fc, javax.swing.JList list)

	return new Handler(list);
    
public javax.swing.event.ListSelectionListenercreateListSelectionListener(javax.swing.JFileChooser fc)

        return getHandler();
    
protected voidcreateModel()

        if (model != null) {
            model.invalidateFileCache();
        }
	model = new BasicDirectoryModel(getFileChooser());
    
public java.beans.PropertyChangeListenercreatePropertyChangeListener(javax.swing.JFileChooser fc)

	return null;
    
public voidensureFileIsVisible(javax.swing.JFileChooser fc, java.io.File f)

    
public javax.swing.filechooser.FileFiltergetAcceptAllFileFilter(javax.swing.JFileChooser fc)
Returns the default accept all file filter

	return acceptAllFileFilter;
    
public javax.swing.JPanelgetAccessoryPanel()

	return accessoryPanel;
    
javax.swing.ActionMapgetActionMap()

	return createActionMap();
    
protected javax.swing.JButtongetApproveButton(javax.swing.JFileChooser fc)

	return null;
    
public intgetApproveButtonMnemonic(javax.swing.JFileChooser fc)

	int mnemonic = fc.getApproveButtonMnemonic();
	if (mnemonic > 0) {
	    return mnemonic;
	} else if (fc.getDialogType() == JFileChooser.OPEN_DIALOG) {
	    return openButtonMnemonic;
	} else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG) {
	    return saveButtonMnemonic;
	} else {
	    return mnemonic;
	}
    
public java.lang.StringgetApproveButtonText(javax.swing.JFileChooser fc)

	String buttonText = fc.getApproveButtonText();
	if (buttonText != null) {
	    return buttonText;
	} else if (fc.getDialogType() == JFileChooser.OPEN_DIALOG) {
	    return openButtonText;
	} else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG) {
	    return saveButtonText;
	} else {
	    return null;
	}
    
public java.lang.StringgetApproveButtonToolTipText(javax.swing.JFileChooser fc)

	String tooltipText = fc.getApproveButtonToolTipText();
	if(tooltipText != null) {
	    return tooltipText;
	}

	if(fc.getDialogType() == JFileChooser.OPEN_DIALOG) {
	    return openButtonToolTipText;
	} else if(fc.getDialogType() == JFileChooser.SAVE_DIALOG) {
	    return saveButtonToolTipText;
	}
	return null;
    
public javax.swing.ActiongetApproveSelectionAction()

	return approveSelectionAction;
    
public javax.swing.ActiongetCancelSelectionAction()

	return cancelSelectionAction;
    
public javax.swing.ActiongetChangeToParentDirectoryAction()

	return changeToParentDirectoryAction;
    
public java.lang.StringgetDialogTitle(javax.swing.JFileChooser fc)
Returns the title of this dialog

	String dialogTitle = fc.getDialogTitle();
	if (dialogTitle != null) {
	    return dialogTitle;
	} else if (fc.getDialogType() == JFileChooser.OPEN_DIALOG) {
	    return openDialogTitleText;
	} else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG) {
	    return saveDialogTitleText;
	} else {
	    return getApproveButtonText(fc);
	}
    
protected java.io.FilegetDirectory()
Property to remember the directory that is currently selected in the UI.

return
the value of the directory property
see
#setDirectory
since
1.4

	return directory;
    
public java.lang.StringgetDirectoryName()

	return null;
    
public javax.swing.JFileChoosergetFileChooser()

	return filechooser;
    
public java.lang.StringgetFileName()

	return null;
    
public javax.swing.filechooser.FileViewgetFileView(javax.swing.JFileChooser fc)

	return fileView;
    
public javax.swing.ActiongetGoHomeAction()

	return goHomeAction;
    
private javax.swing.plaf.basic.BasicFileChooserUI$HandlergetHandler()

        if (handler == null) {
            handler = new Handler();
        }
        return handler;
    
javax.swing.InputMapgetInputMap(int condition)

	if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
	    return (InputMap)DefaultLookup.get(getFileChooser(), this,
                    "FileChooser.ancestorInputMap");
	}
	return null;
    
private intgetMnemonic(java.lang.String key, java.util.Locale l)
Returns the mnemonic for the given key.

        return SwingUtilities2.getUIDefaultsInt(key, l);
    
public javax.swing.plaf.basic.BasicDirectoryModelgetModel()

	return model;
    
public javax.swing.ActiongetNewFolderAction()

	if (newFolderAction == null) {
	    newFolderAction = new NewFolderAction();
	    // Note: Don't return null for readOnly, it might
	    // break older apps.
	    if (readOnly) {
		newFolderAction.setEnabled(false);
	    }
	}
	return newFolderAction;
    
public javax.swing.ActiongetUpdateAction()

	return updateAction;
    
public voidinstallComponents(javax.swing.JFileChooser fc)

    
protected voidinstallDefaults(javax.swing.JFileChooser fc)

	installIcons(fc);
	installStrings(fc);
	usesSingleFilePane = UIManager.getBoolean("FileChooser.usesSingleFilePane");
	readOnly           = UIManager.getBoolean("FileChooser.readOnly");
	TransferHandler th = fc.getTransferHandler();
	if (th == null || th instanceof UIResource) {
	    fc.setTransferHandler(defaultTransferHandler);
	}
        LookAndFeel.installProperty(fc, "opaque", Boolean.FALSE);
    
protected voidinstallIcons(javax.swing.JFileChooser fc)

	directoryIcon    = UIManager.getIcon("FileView.directoryIcon");
	fileIcon         = UIManager.getIcon("FileView.fileIcon");
	computerIcon     = UIManager.getIcon("FileView.computerIcon");
	hardDriveIcon    = UIManager.getIcon("FileView.hardDriveIcon");
	floppyDriveIcon  = UIManager.getIcon("FileView.floppyDriveIcon");

	newFolderIcon    = UIManager.getIcon("FileChooser.newFolderIcon");
	upFolderIcon     = UIManager.getIcon("FileChooser.upFolderIcon");
	homeFolderIcon   = UIManager.getIcon("FileChooser.homeFolderIcon");
	detailsViewIcon  = UIManager.getIcon("FileChooser.detailsViewIcon");
	listViewIcon     = UIManager.getIcon("FileChooser.listViewIcon");
    
protected voidinstallListeners(javax.swing.JFileChooser fc)

	propertyChangeListener = createPropertyChangeListener(fc);
	if(propertyChangeListener != null) {
	    fc.addPropertyChangeListener(propertyChangeListener);
	}
	fc.addPropertyChangeListener(getModel());

	InputMap inputMap = getInputMap(JComponent.
					WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
	SwingUtilities.replaceUIInputMap(fc, JComponent.
					 WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);
	ActionMap actionMap = getActionMap();
	SwingUtilities.replaceUIActionMap(fc, actionMap);
    
protected voidinstallStrings(javax.swing.JFileChooser fc)


        Locale l = fc.getLocale();
	newFolderErrorText = UIManager.getString("FileChooser.newFolderErrorText",l);
	newFolderErrorSeparator = UIManager.getString("FileChooser.newFolderErrorSeparator",l);

	fileDescriptionText = UIManager.getString("FileChooser.fileDescriptionText",l);
	directoryDescriptionText = UIManager.getString("FileChooser.directoryDescriptionText",l);

	saveButtonText   = UIManager.getString("FileChooser.saveButtonText",l);
	openButtonText   = UIManager.getString("FileChooser.openButtonText",l);
	saveDialogTitleText = UIManager.getString("FileChooser.saveDialogTitleText",l);
	openDialogTitleText = UIManager.getString("FileChooser.openDialogTitleText",l);
	cancelButtonText = UIManager.getString("FileChooser.cancelButtonText",l);
	updateButtonText = UIManager.getString("FileChooser.updateButtonText",l);
	helpButtonText   = UIManager.getString("FileChooser.helpButtonText",l);
	directoryOpenButtonText = UIManager.getString("FileChooser.directoryOpenButtonText",l);

	saveButtonMnemonic   = getMnemonic("FileChooser.saveButtonMnemonic", l);
	openButtonMnemonic   = getMnemonic("FileChooser.openButtonMnemonic", l);
	cancelButtonMnemonic = getMnemonic("FileChooser.cancelButtonMnemonic", l);
	updateButtonMnemonic = getMnemonic("FileChooser.updateButtonMnemonic", l);
	helpButtonMnemonic   = getMnemonic("FileChooser.helpButtonMnemonic", l);
	directoryOpenButtonMnemonic = getMnemonic("FileChooser.directoryOpenButtonMnemonic", l);

	saveButtonToolTipText   = UIManager.getString("FileChooser.saveButtonToolTipText",l);
	openButtonToolTipText   = UIManager.getString("FileChooser.openButtonToolTipText",l);
	cancelButtonToolTipText = UIManager.getString("FileChooser.cancelButtonToolTipText",l);
	updateButtonToolTipText = UIManager.getString("FileChooser.updateButtonToolTipText",l);
	helpButtonToolTipText   = UIManager.getString("FileChooser.helpButtonToolTipText",l);
	directoryOpenButtonToolTipText = UIManager.getString("FileChooser.directoryOpenButtonToolTipText",l);
    
public voidinstallUI(javax.swing.JComponent c)

	accessoryPanel = new JPanel(new BorderLayout());
	filechooser = (JFileChooser) c;

	createModel();

	clearIconCache();

	installDefaults(filechooser);
	installComponents(filechooser);
	installListeners(filechooser);
	filechooser.applyComponentOrientation(filechooser.getComponentOrientation());
    
protected booleanisDirectorySelected()
Property to remember whether a directory is currently selected in the UI.

return
true iff a directory is currently selected.
since
1.4

	return directorySelected;
    
private static booleanisGlobPattern(java.lang.String filename)

	return ((File.separatorChar == '\\" && (filename.indexOf('*") >= 0
						  || filename.indexOf('?") >= 0))
		|| (File.separatorChar == '/" && (filename.indexOf('*") >= 0
						  || filename.indexOf('?") >= 0
						  || filename.indexOf('[") >= 0)));
    
public voidrescanCurrentDirectory(javax.swing.JFileChooser fc)

    
private voidresetGlobFilter()

	if (actualFileFilter != null) {
	    JFileChooser chooser = getFileChooser();
	    FileFilter currentFilter = chooser.getFileFilter();
	    if (currentFilter != null && currentFilter.equals(globFilter)) {
		chooser.setFileFilter(actualFileFilter);
		chooser.removeChoosableFileFilter(globFilter);
	    }
	    actualFileFilter = null;
	}
    
protected voidsetDirectory(java.io.File f)
Property to remember the directory that is currently selected in the UI. This is normally called by the UI on a selection event.

param
f the File object representing the directory that is currently selected
since
1.4

	directory = f;
    
public voidsetDirectoryName(java.lang.String dirname)

    
protected voidsetDirectorySelected(boolean b)
Property to remember whether a directory is currently selected in the UI. This is normally called by the UI on a selection event.

param
b iff a directory is currently selected.
since
1.4

	directorySelected = b;
    
public voidsetFileName(java.lang.String filename)

    
public voiduninstallComponents(javax.swing.JFileChooser fc)

    
protected voiduninstallDefaults(javax.swing.JFileChooser fc)

	uninstallIcons(fc);
	uninstallStrings(fc);
	if (fc.getTransferHandler() instanceof UIResource) {
	    fc.setTransferHandler(null);
	}
    
protected voiduninstallIcons(javax.swing.JFileChooser fc)

	directoryIcon    = null;
	fileIcon         = null;
	computerIcon     = null;
	hardDriveIcon    = null;
	floppyDriveIcon  = null;

	newFolderIcon    = null;
	upFolderIcon     = null;
	homeFolderIcon   = null;
	detailsViewIcon  = null;
	listViewIcon     = null;
    
protected voiduninstallListeners(javax.swing.JFileChooser fc)

	if(propertyChangeListener != null) {
	    fc.removePropertyChangeListener(propertyChangeListener);
	}
	fc.removePropertyChangeListener(getModel());
	SwingUtilities.replaceUIInputMap(fc, JComponent.
					 WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
	SwingUtilities.replaceUIActionMap(fc, null);
    
protected voiduninstallStrings(javax.swing.JFileChooser fc)

	saveButtonText   = null;
	openButtonText   = null;
	cancelButtonText = null;
	updateButtonText = null;
	helpButtonText   = null;
	directoryOpenButtonText = null;

	saveButtonToolTipText = null;
	openButtonToolTipText = null;
	cancelButtonToolTipText = null;
	updateButtonToolTipText = null;
	helpButtonToolTipText = null;
	directoryOpenButtonToolTipText = null;
    
public voiduninstallUI(javax.swing.JComponent c)

	uninstallListeners((JFileChooser) filechooser);
	uninstallComponents((JFileChooser) filechooser);
	uninstallDefaults((JFileChooser) filechooser);

	if(accessoryPanel != null) {
	    accessoryPanel.removeAll();
	}

	accessoryPanel = null;
	getFileChooser().removeAll();

        handler = null;