Methods Summary |
---|
protected void | addControlButtons()
getBottomPanel().add(getButtonPanel());
|
protected javax.swing.ActionMap | createActionMap()
ActionMap map = new ActionMapUIResource();
FilePane.addActionsToMap(map, filePane.getActions());
return map;
|
protected javax.swing.JPanel | createDetailsView(javax.swing.JFileChooser fc)
return filePane.createDetailsView();
|
protected javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxModel | createDirectoryComboBoxModel(javax.swing.JFileChooser fc)
return new DirectoryComboBoxModel();
|
protected javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxRenderer | createDirectoryComboBoxRenderer(javax.swing.JFileChooser fc)
return new DirectoryComboBoxRenderer();
|
protected javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel | createFilterComboBoxModel()
return new FilterComboBoxModel();
|
protected javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxRenderer | createFilterComboBoxRenderer()
return new FilterComboBoxRenderer();
|
protected javax.swing.JPanel | createList(javax.swing.JFileChooser fc)
return filePane.createList();
|
public javax.swing.event.ListSelectionListener | createListSelectionListener(javax.swing.JFileChooser fc)Creates a selection listener for the list of files and directories.
return super.createListSelectionListener(fc);
|
public java.beans.PropertyChangeListener | createPropertyChangeListener(javax.swing.JFileChooser fc)
return new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
String s = e.getPropertyName();
if(s.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) {
doSelectedFileChanged(e);
} else if (s.equals(JFileChooser.SELECTED_FILES_CHANGED_PROPERTY)) {
doSelectedFilesChanged(e);
} else if(s.equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) {
doDirectoryChanged(e);
} else if(s.equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY)) {
doFilterChanged(e);
} else if(s.equals(JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY)) {
doFileSelectionModeChanged(e);
} else if(s.equals(JFileChooser.ACCESSORY_CHANGED_PROPERTY)) {
doAccessoryChanged(e);
} else if (s.equals(JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY) ||
s.equals(JFileChooser.APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY)) {
doApproveButtonTextChanged(e);
} else if(s.equals(JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY)) {
doDialogTypeChanged(e);
} else if(s.equals(JFileChooser.APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY)) {
doApproveButtonMnemonicChanged(e);
} else if(s.equals(JFileChooser.CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY)) {
doControlButtonsChanged(e);
} else if (s.equals("componentOrientation")) {
ComponentOrientation o = (ComponentOrientation)e.getNewValue();
JFileChooser cc = (JFileChooser)e.getSource();
if (o != (ComponentOrientation)e.getOldValue()) {
cc.applyComponentOrientation(o);
}
} else if (s == "FileChooser.useShellFolder") {
updateUseShellFolder();
doDirectoryChanged(e);
} else if (s.equals("ancestor")) {
if (e.getOldValue() == null && e.getNewValue() != null) {
// Ancestor was added, set initial focus
fileNameTextField.selectAll();
fileNameTextField.requestFocus();
}
}
}
};
|
public static javax.swing.plaf.ComponentUI | createUI(javax.swing.JComponent c)
//
// ComponentUI Interface Implementation methods
//
return new MetalFileChooserUI((JFileChooser) c);
|
private void | doAccessoryChanged(java.beans.PropertyChangeEvent e)
if(getAccessoryPanel() != null) {
if(e.getOldValue() != null) {
getAccessoryPanel().remove((JComponent) e.getOldValue());
}
JComponent accessory = (JComponent) e.getNewValue();
if(accessory != null) {
getAccessoryPanel().add(accessory, BorderLayout.CENTER);
}
}
|
private void | doApproveButtonMnemonicChanged(java.beans.PropertyChangeEvent e)
// Note: Metal does not use mnemonics for approve and cancel
|
private void | doApproveButtonTextChanged(java.beans.PropertyChangeEvent e)
JFileChooser chooser = getFileChooser();
approveButton.setText(getApproveButtonText(chooser));
approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
|
private void | doControlButtonsChanged(java.beans.PropertyChangeEvent e)
if(getFileChooser().getControlButtonsAreShown()) {
addControlButtons();
} else {
removeControlButtons();
}
|
private void | doDialogTypeChanged(java.beans.PropertyChangeEvent e)
JFileChooser chooser = getFileChooser();
approveButton.setText(getApproveButtonText(chooser));
approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
if (chooser.getDialogType() == JFileChooser.SAVE_DIALOG) {
lookInLabel.setText(saveInLabelText);
} else {
lookInLabel.setText(lookInLabelText);
}
|
private void | doDirectoryChanged(java.beans.PropertyChangeEvent e)
JFileChooser fc = getFileChooser();
FileSystemView fsv = fc.getFileSystemView();
clearIconCache();
File currentDirectory = fc.getCurrentDirectory();
if(currentDirectory != null) {
directoryComboBoxModel.addItem(currentDirectory);
if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) {
if (fsv.isFileSystem(currentDirectory)) {
setFileName(currentDirectory.getPath());
} else {
setFileName(null);
}
}
}
|
private void | doFileSelectionModeChanged(java.beans.PropertyChangeEvent e)
clearIconCache();
JFileChooser fc = getFileChooser();
File currentDirectory = fc.getCurrentDirectory();
if (currentDirectory != null
&& fc.isDirectorySelectionEnabled()
&& !fc.isFileSelectionEnabled()
&& fc.getFileSystemView().isFileSystem(currentDirectory)) {
setFileName(currentDirectory.getPath());
} else {
setFileName(null);
}
|
private void | doFilterChanged(java.beans.PropertyChangeEvent e)
clearIconCache();
|
private void | doSelectedFileChanged(java.beans.PropertyChangeEvent e)
File f = (File) e.getNewValue();
JFileChooser fc = getFileChooser();
if (f != null
&& ((fc.isFileSelectionEnabled() && !f.isDirectory())
|| (f.isDirectory() && fc.isDirectorySelectionEnabled()))) {
setFileName(fileNameString(f));
}
|
private void | doSelectedFilesChanged(java.beans.PropertyChangeEvent e)
File[] files = (File[]) e.getNewValue();
JFileChooser fc = getFileChooser();
if (files != null
&& files.length > 0
&& (files.length > 1 || fc.isDirectorySelectionEnabled() || !files[0].isDirectory())) {
setFileName(fileNameString(files));
}
|
public void | ensureFileIsVisible(javax.swing.JFileChooser fc, java.io.File f)
filePane.ensureFileIsVisible(fc, f);
|
private java.lang.String | fileNameString(java.io.File file)
if (file == null) {
return null;
} else {
JFileChooser fc = getFileChooser();
if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) {
return file.getPath();
} else {
return file.getName();
}
}
|
private java.lang.String | fileNameString(java.io.File[] files)
StringBuffer buf = new StringBuffer();
for (int i = 0; files != null && i < files.length; i++) {
if (i > 0) {
buf.append(" ");
}
if (files.length > 1) {
buf.append("\"");
}
buf.append(fileNameString(files[i]));
if (files.length > 1) {
buf.append("\"");
}
}
return buf.toString();
|
protected javax.swing.ActionMap | getActionMap()
return createActionMap();
|
protected javax.swing.JButton | getApproveButton(javax.swing.JFileChooser fc)
return approveButton;
|
protected javax.swing.JPanel | getBottomPanel()
if(bottomPanel == null) {
bottomPanel = new JPanel();
}
return bottomPanel;
|
protected javax.swing.JPanel | getButtonPanel()
if (buttonPanel == null) {
buttonPanel = new JPanel();
}
return buttonPanel;
|
public java.lang.String | getDirectoryName()
// PENDING(jeff) - get the name from the directory combobox
return null;
|
public java.lang.String | getFileName()
if (fileNameTextField != null) {
return fileNameTextField.getText();
} else {
return null;
}
|
public java.awt.Dimension | getMaximumSize(javax.swing.JComponent c)Returns the maximum size of the JFileChooser .
return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
public java.awt.Dimension | getMinimumSize(javax.swing.JComponent c)Returns the minimum size of the JFileChooser .
return MIN_SIZE;
|
public java.awt.Dimension | getPreferredSize(javax.swing.JComponent c)Returns the preferred size of the specified
JFileChooser .
The preferred size is at least as large,
in both height and width,
as the preferred size recommended
by the file chooser's layout manager.
int prefWidth = PREF_SIZE.width;
Dimension d = c.getLayout().preferredLayoutSize(c);
if (d != null) {
return new Dimension(d.width < prefWidth ? prefWidth : d.width,
d.height < PREF_SIZE.height ? PREF_SIZE.height : d.height);
} else {
return new Dimension(prefWidth, PREF_SIZE.height);
}
|
private static void | groupLabels(javax.swing.plaf.metal.MetalFileChooserUI$AlignedLabel[] group)
for (int i = 0; i < group.length; i++) {
group[i].group = group;
}
|
public void | installComponents(javax.swing.JFileChooser fc)
FileSystemView fsv = fc.getFileSystemView();
fc.setBorder(new EmptyBorder(12, 12, 11, 11));
fc.setLayout(new BorderLayout(0, 11));
filePane = new FilePane(new MetalFileChooserUIAccessor());
fc.addPropertyChangeListener(filePane);
updateUseShellFolder();
// ********************************* //
// **** Construct the top panel **** //
// ********************************* //
// Directory manipulation buttons
JPanel topPanel = new JPanel(new BorderLayout(11, 0));
JPanel topButtonPanel = new JPanel();
topButtonPanel.setLayout(new BoxLayout(topButtonPanel, BoxLayout.LINE_AXIS));
topPanel.add(topButtonPanel, BorderLayout.AFTER_LINE_ENDS);
// Add the top panel to the fileChooser
fc.add(topPanel, BorderLayout.NORTH);
// ComboBox Label
lookInLabel = new JLabel(lookInLabelText);
lookInLabel.setDisplayedMnemonic(lookInLabelMnemonic);
topPanel.add(lookInLabel, BorderLayout.BEFORE_LINE_BEGINS);
// CurrentDir ComboBox
directoryComboBox = new JComboBox() {
public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
// Must be small enough to not affect total width.
d.width = 150;
return d;
}
};
directoryComboBox.getAccessibleContext().setAccessibleDescription(lookInLabelText);
directoryComboBox.putClientProperty( "JComboBox.isTableCellEditor", Boolean.TRUE );
lookInLabel.setLabelFor(directoryComboBox);
directoryComboBoxModel = createDirectoryComboBoxModel(fc);
directoryComboBox.setModel(directoryComboBoxModel);
directoryComboBox.addActionListener(directoryComboBoxAction);
directoryComboBox.setRenderer(createDirectoryComboBoxRenderer(fc));
directoryComboBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
directoryComboBox.setAlignmentY(JComponent.TOP_ALIGNMENT);
directoryComboBox.setMaximumRowCount(8);
topPanel.add(directoryComboBox, BorderLayout.CENTER);
// Up Button
JButton upFolderButton = new JButton(getChangeToParentDirectoryAction());
upFolderButton.setText(null);
upFolderButton.setIcon(upFolderIcon);
upFolderButton.setToolTipText(upFolderToolTipText);
upFolderButton.getAccessibleContext().setAccessibleName(upFolderAccessibleName);
upFolderButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
upFolderButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
upFolderButton.setMargin(shrinkwrap);
topButtonPanel.add(upFolderButton);
topButtonPanel.add(Box.createRigidArea(hstrut5));
// Home Button
File homeDir = fsv.getHomeDirectory();
String toolTipText = homeFolderToolTipText;
if (fsv.isRoot(homeDir)) {
toolTipText = getFileView(fc).getName(homeDir); // Probably "Desktop".
}
JButton b = new JButton(homeFolderIcon);
b.setToolTipText(toolTipText);
b.getAccessibleContext().setAccessibleName(homeFolderAccessibleName);
b.setAlignmentX(JComponent.LEFT_ALIGNMENT);
b.setAlignmentY(JComponent.CENTER_ALIGNMENT);
b.setMargin(shrinkwrap);
b.addActionListener(getGoHomeAction());
topButtonPanel.add(b);
topButtonPanel.add(Box.createRigidArea(hstrut5));
// New Directory Button
if (!UIManager.getBoolean("FileChooser.readOnly")) {
b = new JButton(filePane.getNewFolderAction());
b.setText(null);
b.setIcon(newFolderIcon);
b.setToolTipText(newFolderToolTipText);
b.getAccessibleContext().setAccessibleName(newFolderAccessibleName);
b.setAlignmentX(JComponent.LEFT_ALIGNMENT);
b.setAlignmentY(JComponent.CENTER_ALIGNMENT);
b.setMargin(shrinkwrap);
}
topButtonPanel.add(b);
topButtonPanel.add(Box.createRigidArea(hstrut5));
// View button group
ButtonGroup viewButtonGroup = new ButtonGroup();
// List Button
listViewButton = new JToggleButton(listViewIcon);
listViewButton.setToolTipText(listViewButtonToolTipText);
listViewButton.getAccessibleContext().setAccessibleName(listViewButtonAccessibleName);
listViewButton.setSelected(true);
listViewButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
listViewButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
listViewButton.setMargin(shrinkwrap);
listViewButton.addActionListener(filePane.getViewTypeAction(FilePane.VIEWTYPE_LIST));
topButtonPanel.add(listViewButton);
viewButtonGroup.add(listViewButton);
// Details Button
detailsViewButton = new JToggleButton(detailsViewIcon);
detailsViewButton.setToolTipText(detailsViewButtonToolTipText);
detailsViewButton.getAccessibleContext().setAccessibleName(detailsViewButtonAccessibleName);
detailsViewButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
detailsViewButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
detailsViewButton.setMargin(shrinkwrap);
detailsViewButton.addActionListener(filePane.getViewTypeAction(FilePane.VIEWTYPE_DETAILS));
topButtonPanel.add(detailsViewButton);
viewButtonGroup.add(detailsViewButton);
filePane.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
if ("viewType".equals(e.getPropertyName())) {
int viewType = filePane.getViewType();
switch (viewType) {
case FilePane.VIEWTYPE_LIST:
listViewButton.setSelected(true);
break;
case FilePane.VIEWTYPE_DETAILS:
detailsViewButton.setSelected(true);
break;
}
}
}
});
// ************************************** //
// ******* Add the directory pane ******* //
// ************************************** //
fc.add(getAccessoryPanel(), BorderLayout.AFTER_LINE_ENDS);
JComponent accessory = fc.getAccessory();
if(accessory != null) {
getAccessoryPanel().add(accessory);
}
filePane.setPreferredSize(LIST_PREF_SIZE);
fc.add(filePane, BorderLayout.CENTER);
// ********************************** //
// **** Construct the bottom panel ** //
// ********************************** //
JPanel bottomPanel = getBottomPanel();
bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.Y_AXIS));
fc.add(bottomPanel, BorderLayout.SOUTH);
// FileName label and textfield
JPanel fileNamePanel = new JPanel();
fileNamePanel.setLayout(new BoxLayout(fileNamePanel, BoxLayout.LINE_AXIS));
bottomPanel.add(fileNamePanel);
bottomPanel.add(Box.createRigidArea(vstrut5));
AlignedLabel fileNameLabel = new AlignedLabel(fileNameLabelText);
fileNameLabel.setDisplayedMnemonic(fileNameLabelMnemonic);
fileNamePanel.add(fileNameLabel);
fileNameTextField = new JTextField(35) {
public Dimension getMaximumSize() {
return new Dimension(Short.MAX_VALUE, super.getPreferredSize().height);
}
};
fileNamePanel.add(fileNameTextField);
fileNameLabel.setLabelFor(fileNameTextField);
fileNameTextField.addFocusListener(
new FocusAdapter() {
public void focusGained(FocusEvent e) {
if (!getFileChooser().isMultiSelectionEnabled()) {
filePane.clearSelection();
}
}
}
);
if (fc.isMultiSelectionEnabled()) {
setFileName(fileNameString(fc.getSelectedFiles()));
} else {
setFileName(fileNameString(fc.getSelectedFile()));
}
// Filetype label and combobox
JPanel filesOfTypePanel = new JPanel();
filesOfTypePanel.setLayout(new BoxLayout(filesOfTypePanel, BoxLayout.LINE_AXIS));
bottomPanel.add(filesOfTypePanel);
AlignedLabel filesOfTypeLabel = new AlignedLabel(filesOfTypeLabelText);
filesOfTypeLabel.setDisplayedMnemonic(filesOfTypeLabelMnemonic);
filesOfTypePanel.add(filesOfTypeLabel);
filterComboBoxModel = createFilterComboBoxModel();
fc.addPropertyChangeListener(filterComboBoxModel);
filterComboBox = new JComboBox(filterComboBoxModel);
filterComboBox.getAccessibleContext().setAccessibleDescription(filesOfTypeLabelText);
filesOfTypeLabel.setLabelFor(filterComboBox);
filterComboBox.setRenderer(createFilterComboBoxRenderer());
filesOfTypePanel.add(filterComboBox);
// buttons
getButtonPanel().setLayout(new ButtonAreaLayout());
approveButton = new JButton(getApproveButtonText(fc));
// Note: Metal does not use mnemonics for approve and cancel
approveButton.addActionListener(getApproveSelectionAction());
approveButton.setToolTipText(getApproveButtonToolTipText(fc));
getButtonPanel().add(approveButton);
cancelButton = new JButton(cancelButtonText);
cancelButton.setToolTipText(cancelButtonToolTipText);
cancelButton.addActionListener(getCancelSelectionAction());
getButtonPanel().add(cancelButton);
if(fc.getControlButtonsAreShown()) {
addControlButtons();
}
groupLabels(new AlignedLabel[] { fileNameLabel, filesOfTypeLabel });
|
protected void | installListeners(javax.swing.JFileChooser fc)
super.installListeners(fc);
ActionMap actionMap = getActionMap();
SwingUtilities.replaceUIActionMap(fc, actionMap);
|
protected void | installStrings(javax.swing.JFileChooser fc)
super.installStrings(fc);
Locale l = fc.getLocale();
lookInLabelMnemonic = UIManager.getInt("FileChooser.lookInLabelMnemonic");
lookInLabelText = UIManager.getString("FileChooser.lookInLabelText",l);
saveInLabelText = UIManager.getString("FileChooser.saveInLabelText",l);
fileNameLabelMnemonic = UIManager.getInt("FileChooser.fileNameLabelMnemonic");
fileNameLabelText = UIManager.getString("FileChooser.fileNameLabelText",l);
filesOfTypeLabelMnemonic = UIManager.getInt("FileChooser.filesOfTypeLabelMnemonic");
filesOfTypeLabelText = UIManager.getString("FileChooser.filesOfTypeLabelText",l);
upFolderToolTipText = UIManager.getString("FileChooser.upFolderToolTipText",l);
upFolderAccessibleName = UIManager.getString("FileChooser.upFolderAccessibleName",l);
homeFolderToolTipText = UIManager.getString("FileChooser.homeFolderToolTipText",l);
homeFolderAccessibleName = UIManager.getString("FileChooser.homeFolderAccessibleName",l);
newFolderToolTipText = UIManager.getString("FileChooser.newFolderToolTipText",l);
newFolderAccessibleName = UIManager.getString("FileChooser.newFolderAccessibleName",l);
listViewButtonToolTipText = UIManager.getString("FileChooser.listViewButtonToolTipText",l);
listViewButtonAccessibleName = UIManager.getString("FileChooser.listViewButtonAccessibleName",l);
detailsViewButtonToolTipText = UIManager.getString("FileChooser.detailsViewButtonToolTipText",l);
detailsViewButtonAccessibleName = UIManager.getString("FileChooser.detailsViewButtonAccessibleName",l);
|
public void | installUI(javax.swing.JComponent c)
super.installUI(c);
|
protected void | removeControlButtons()
getBottomPanel().remove(getButtonPanel());
|
public void | rescanCurrentDirectory(javax.swing.JFileChooser fc)
filePane.rescanCurrentDirectory();
|
public void | setDirectoryName(java.lang.String dirname)
// PENDING(jeff) - set the name in the directory combobox
|
protected void | setDirectorySelected(boolean directorySelected)Property to remember whether a directory is currently selected in the UI.
This is normally called by the UI on a selection event.
super.setDirectorySelected(directorySelected);
JFileChooser chooser = getFileChooser();
if(directorySelected) {
if (approveButton != null) {
approveButton.setText(directoryOpenButtonText);
approveButton.setToolTipText(directoryOpenButtonToolTipText);
}
} else {
if (approveButton != null) {
approveButton.setText(getApproveButtonText(chooser));
approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
}
}
|
public void | setFileName(java.lang.String filename)
if (fileNameTextField != null) {
fileNameTextField.setText(filename);
}
|
public void | uninstallComponents(javax.swing.JFileChooser fc)
fc.removeAll();
bottomPanel = null;
buttonPanel = null;
|
public void | uninstallUI(javax.swing.JComponent c)
// Remove listeners
c.removePropertyChangeListener(filterComboBoxModel);
c.removePropertyChangeListener(filePane);
cancelButton.removeActionListener(getCancelSelectionAction());
approveButton.removeActionListener(getApproveSelectionAction());
fileNameTextField.removeActionListener(getApproveSelectionAction());
super.uninstallUI(c);
|
private void | updateUseShellFolder()
// Decide whether to use the ShellFolder class to populate shortcut
// panel and combobox.
JFileChooser fc = getFileChooser();
Boolean prop =
(Boolean)fc.getClientProperty("FileChooser.useShellFolder");
if (prop != null) {
useShellFolder = prop.booleanValue();
} else {
// See if FileSystemView.getRoots() returns the desktop folder,
// i.e. the normal Windows hierarchy.
useShellFolder = false;
File[] roots = fc.getFileSystemView().getRoots();
if (roots != null && roots.length == 1) {
File[] cbFolders = (File[])ShellFolder.get("fileChooserComboBoxFolders");
if (cbFolders != null && cbFolders.length > 0 && roots[0] == cbFolders[0]) {
useShellFolder = true;
}
}
}
|
public void | valueChanged(javax.swing.event.ListSelectionEvent e)
JFileChooser fc = getFileChooser();
File f = fc.getSelectedFile();
if (!e.getValueIsAdjusting() && f != null && !getFileChooser().isTraversable(f)) {
setFileName(fileNameString(f));
}
|