buttonPanel = null;
}
public void installComponents(JFileChooser fc)
{
FileSystemView fsv = fc.getFileSystemView();
fc.setBorder(new EmptyBorder(12, 12, 11, 11));
fc.setLayout(new BorderLayout(0, 11));
// ********************************* //
// **** Construct the top panel **** //
// ********************************* //
// Directory manipulation buttons
JToolBar bar = new JToolBar();
// Add the top panel to the fileChooser
fc.add(bar, BorderLayout.NORTH);
// ComboBox Label
lookInLabel = new JLabel(lookInLabelText);
lookInLabel.setDisplayedMnemonic(lookInLabelMnemonic);
bar.add(lookInLabel, BorderLayout.BEFORE_LINE_BEGINS);
// CurrentDir ComboBox
directoryComboBox = new JComboBox();
directoryComboBox.putClientProperty("JComboBox.lightweightKeyboardNavigation", "Lightweight");
lookInLabel.setLabelFor(directoryComboBox);
directoryComboBoxModel = createDirectoryComboBoxModel(fc);
directoryComboBox.setModel(directoryComboBoxModel);
directoryComboBox.addActionListener(directoryComboBoxAction);
directoryComboBox.setRenderer(createDirectoryComboBoxRenderer(fc));
directoryComboBox.setMaximumRowCount(8);
bar.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);
bar.add(upFolderButton);
bar.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());
bar.add(b);
bar.add(Box.createRigidArea(hstrut5));
// New Directory Button
b = new JButton(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);
bar.add(b);
bar.add(Box.createRigidArea(hstrut5));
// View button group
ButtonGroup viewButtonGroup = new ButtonGroup();
class ViewButtonListener
implements ActionListener
{
JFileChooser chooser;
ViewButtonListener(JFileChooser chooser)
{
this.chooser = chooser;
}
public void actionPerformed(ActionEvent e)
{
JToggleButton b = (JToggleButton) e.getSource();
JPanel oldViewPanel = currentViewPanel;
if (b == detailsViewButton)
{
if (detailsViewPanel == null)
{
detailsViewPanel = createDetailsView(chooser);
detailsViewPanel.setPreferredSize(LIST_PREF_SIZE);
}
currentViewPanel = detailsViewPanel;
}
else
{
currentViewPanel = listViewPanel;
}
if (currentViewPanel != oldViewPanel)
{
centerPanel.remove(oldViewPanel);
centerPanel.add(currentViewPanel, BorderLayout.CENTER);
centerPanel.revalidate();
centerPanel.repaint();
}
}
}
ViewButtonListener viewButtonListener = new ViewButtonListener(fc);
// 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(viewButtonListener);
bar.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(viewButtonListener);
bar.add(detailsViewButton);
viewButtonGroup.add(detailsViewButton);
// Use ShellFolder class to populate combobox only if
// FileSystemView.getRoots() returns one folder and that is
// the same as the first item in the ShellFolder combobox list.
{
useShellFolder = false;
File [] roots = fsv.getRoots();
if (roots != null && roots.length == 1)
{
File [] cbFolders = (File []) ShellFolder.get("fileChooserComboBoxFolders");
if (cbFolders != null && cbFolders.length > 0 && roots [0] == cbFolders [0])
{