< prev index next >
src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java
Print this page
*** 20,109 ****
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
-
package com.sun.java.swing.plaf.windows;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.filechooser.*;
import javax.swing.event.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.beans.*;
import java.io.File;
! import java.io.FileNotFoundException;
! import java.io.IOException;
import java.util.*;
- import java.security.AccessController;
- import java.security.PrivilegedAction;
-
- import sun.awt.shell.ShellFolder;
import sun.swing.*;
import javax.accessibility.*;
/**
! * Windows {@literal L&F} implementation of a FileChooser.
*
* @author Jeff Dinkins
*/
public class WindowsFileChooserUI extends BasicFileChooserUI {
! // The following are private because the implementation of the
! // Windows FileChooser L&F is not complete yet.
!
! private JPanel centerPanel;
!
! private JLabel lookInLabel;
! private JComboBox<File> directoryComboBox;
! private DirectoryComboBoxModel directoryComboBoxModel;
! private ActionListener directoryComboBoxAction = new DirectoryComboBoxAction();
private FilterComboBoxModel filterComboBoxModel;
private JTextField filenameTextField;
private FilePane filePane;
! private WindowsPlacesBar placesBar;
private JButton approveButton;
private JButton cancelButton;
! private JPanel buttonPanel;
private JPanel bottomPanel;
private JComboBox<FileFilter> filterComboBox;
private static final Dimension hstrut10 = new Dimension(10, 1);
private static final Dimension vstrut4 = new Dimension(1, 4);
private static final Dimension vstrut6 = new Dimension(1, 6);
private static final Dimension vstrut8 = new Dimension(1, 8);
! private static final Insets shrinkwrap = new Insets(0,0,0,0);
// Preferred and Minimum sizes for the dialog box
private static int PREF_WIDTH = 425;
private static int PREF_HEIGHT = 245;
private static Dimension PREF_SIZE = new Dimension(PREF_WIDTH, PREF_HEIGHT);
private static int MIN_WIDTH = 425;
private static int MIN_HEIGHT = 245;
! private static int LIST_PREF_WIDTH = 444;
! private static int LIST_PREF_HEIGHT = 138;
private static Dimension LIST_PREF_SIZE = new Dimension(LIST_PREF_WIDTH, LIST_PREF_HEIGHT);
! // Labels, mnemonics, and tooltips (oh my!)
! private int lookInLabelMnemonic = 0;
! private String lookInLabelText = null;
! private String saveInLabelText = null;
private int fileNameLabelMnemonic = 0;
private String fileNameLabelText = null;
private int folderNameLabelMnemonic = 0;
private String folderNameLabelText = null;
--- 20,130 ----
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.java.swing.plaf.windows;
+ import static com.sun.java.swing.plaf.windows.WindowsFileChooserUI.WindowsFileListUI.HOVER_CELL_PROPERTY;
+ import static com.sun.java.swing.plaf.windows.WindowsFileChooserUI.WindowsFileListUI.ITEM_SELECTED_BORDER_COLOR;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.filechooser.*;
import javax.swing.event.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;
import java.awt.*;
+ import static java.awt.Color.WHITE;
import java.awt.event.*;
+ import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.beans.*;
import java.io.File;
! import static java.lang.Boolean.TRUE;
import java.util.*;
import sun.swing.*;
import javax.accessibility.*;
+ import static javax.swing.Action.NAME;
+ import static javax.swing.DefaultButtonModel.ARMED;
+ import static javax.swing.DefaultButtonModel.PRESSED;
+ import static javax.swing.SwingConstants.RIGHT;
+ import sun.awt.OSInfo;
+ import sun.awt.Win32GraphicsEnvironment;
+ import sun.swing.FilePane.ViewType;
/**
! * Windows L&F implementation of a FileChooser.
*
* @author Jeff Dinkins
*/
public class WindowsFileChooserUI extends BasicFileChooserUI {
! private WindowsAddressBar addressBar;
private FilterComboBoxModel filterComboBoxModel;
private JTextField filenameTextField;
private FilePane filePane;
! private WindowsNavigationTree navTree;
private JButton approveButton;
private JButton cancelButton;
! private JToolBar bottomToolbar;
private JPanel bottomPanel;
+ private final JPanel centerSplitPaneContainer = new JPanel(new BorderLayout());
+ private final JSplitPane centerSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true) {{
+ setUI(new BasicSplitPaneUI(){
+ @Override
+ public BasicSplitPaneDivider createDefaultDivider() {
+ return new BasicSplitPaneDivider(this){
+
+ @Override
+ public void paint(Graphics g) {
+ Color color = new Color(214, 229, 245);
+ if(OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_7)>0)
+ color = SystemColor.control;
+
+ g.setColor(WHITE);
+ g.fillRect(0, 0, getWidth(), getHeight());
+
+ g.setColor(color);
+ int lineX = Math.max(getWidth() / 2, 0);
+ g.drawLine(lineX, 0, lineX, getHeight());
+ }
+ };
+ }
+
+ });
+ }};
+
private JComboBox<FileFilter> filterComboBox;
private static final Dimension hstrut10 = new Dimension(10, 1);
private static final Dimension vstrut4 = new Dimension(1, 4);
private static final Dimension vstrut6 = new Dimension(1, 6);
private static final Dimension vstrut8 = new Dimension(1, 8);
! private static final Insets shrinkwrap = new Insets(0, 0, 0, 0);
// Preferred and Minimum sizes for the dialog box
private static int PREF_WIDTH = 425;
private static int PREF_HEIGHT = 245;
private static Dimension PREF_SIZE = new Dimension(PREF_WIDTH, PREF_HEIGHT);
private static int MIN_WIDTH = 425;
private static int MIN_HEIGHT = 245;
! // Windows 10 values
! private static int LIST_PREF_WIDTH = 638;
! private static int LIST_PREF_HEIGHT = 590;
private static Dimension LIST_PREF_SIZE = new Dimension(LIST_PREF_WIDTH, LIST_PREF_HEIGHT);
! private static final Insets UTILITY_TOOLBAR_BUTTON_MARGIN = new Insets(7, 11, 7, 11);
private int fileNameLabelMnemonic = 0;
private String fileNameLabelText = null;
private int folderNameLabelMnemonic = 0;
private String folderNameLabelText = null;
*** 118,128 ****
private String newFolderAccessibleName = null;
private String viewMenuButtonToolTipText = null;
private String viewMenuButtonAccessibleName = null;
! private BasicFileView fileView = new WindowsFileView();
private JLabel fileNameLabel;
private void populateFileNameLabel() {
if (getFileChooser().getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) {
--- 139,149 ----
private String newFolderAccessibleName = null;
private String viewMenuButtonToolTipText = null;
private String viewMenuButtonAccessibleName = null;
! private BasicFileChooserUI.BasicFileView fileView = new WindowsFileView();
private JLabel fileNameLabel;
private void populateFileNameLabel() {
if (getFileChooser().getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) {
*** 150,161 ****
--- 171,225 ----
}
public void uninstallComponents(JFileChooser fc) {
fc.removeAll();
}
+ private Deque<File> historyBack = new LinkedList<>();
+ private Deque<File> historyForward = new LinkedList<>();
+ private boolean isInBack;
+ private final Action backAction = new AbstractAction() {
+ {
+ putValue(NAME, "Back");
+ setEnabled(false);
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ File dir = historyBack.pop();
+ historyForward.push(getFileChooser().getCurrentDirectory());
+
+ isInBack = true;
+ getFileChooser().setCurrentDirectory(dir);
+ isInBack = false;
+ }
+ };
+ private final Action forwardAction = new AbstractAction() {
+
+ {
+ putValue(NAME, "Forward");
+ setEnabled(false);
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ assert isEnabled();
+
+ File dir = historyForward.peek();
+ getFileChooser().setCurrentDirectory(dir);
+ }
+ };
+
+ private Action getBackAction() {
+ return backAction;
+ }
+
+ private Action getForwardAction() {
+ return forwardAction;
+ }
private class WindowsFileChooserUIAccessor implements FilePane.FileChooserUIAccessor {
+
public JFileChooser getFileChooser() {
return WindowsFileChooserUI.this.getFileChooser();
}
public BasicDirectoryModel getModel() {
*** 188,198 ****
public Action getNewFolderAction() {
return WindowsFileChooserUI.this.getNewFolderAction();
}
! public MouseListener createDoubleClickListener(JList<?> list) {
return WindowsFileChooserUI.this.createDoubleClickListener(getFileChooser(),
list);
}
public ListSelectionListener createListSelectionListener() {
--- 252,262 ----
public Action getNewFolderAction() {
return WindowsFileChooserUI.this.getNewFolderAction();
}
! public MouseListener createDoubleClickListener(JList list) {
return WindowsFileChooserUI.this.createDoubleClickListener(getFileChooser(),
list);
}
public ListSelectionListener createListSelectionListener() {
*** 202,582 ****
public void installComponents(JFileChooser fc) {
filePane = new FilePane(new WindowsFileChooserUIAccessor());
fc.addPropertyChangeListener(filePane);
! FileSystemView fsv = fc.getFileSystemView();
! fc.setBorder(new EmptyBorder(4, 10, 10, 10));
! fc.setLayout(new BorderLayout(8, 8));
! updateUseShellFolder();
// ********************************* //
// **** Construct the top panel **** //
// ********************************* //
- // Directory manipulation buttons
- JToolBar topPanel = new JToolBar();
- topPanel.setFloatable(false);
- topPanel.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
-
// Add the top panel to the fileChooser
! fc.add(topPanel, BorderLayout.NORTH);
! // ComboBox Label
! @SuppressWarnings("serial") // anonymous class
! JLabel tmp1 = new JLabel(lookInLabelText, JLabel.TRAILING) {
! public Dimension getPreferredSize() {
! return getMinimumSize();
! }
!
! public Dimension getMinimumSize() {
! Dimension d = super.getPreferredSize();
! if (placesBar != null) {
! d.width = Math.max(d.width, placesBar.getWidth());
! }
! return d;
}
! };
! lookInLabel = tmp1;
! lookInLabel.setDisplayedMnemonic(lookInLabelMnemonic);
! lookInLabel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
! lookInLabel.setAlignmentY(JComponent.CENTER_ALIGNMENT);
! topPanel.add(lookInLabel);
! topPanel.add(Box.createRigidArea(new Dimension(8,0)));
!
! // CurrentDir ComboBox
! @SuppressWarnings("serial") // anonymous class
! JComboBox<File> tmp2 = new JComboBox<File>() {
! public Dimension getMinimumSize() {
! Dimension d = super.getMinimumSize();
! d.width = 60;
! return d;
! }
!
! public Dimension getPreferredSize() {
! Dimension d = super.getPreferredSize();
! // Must be small enough to not affect total width.
! d.width = 150;
! return d;
}
- };
- directoryComboBox = tmp2;
- directoryComboBox.putClientProperty( "JComboBox.lightweightKeyboardNavigation", "Lightweight" );
- lookInLabel.setLabelFor(directoryComboBox);
- directoryComboBoxModel = createDirectoryComboBoxModel(fc);
- directoryComboBox.setModel(directoryComboBoxModel);
- directoryComboBox.addActionListener(directoryComboBoxAction);
- directoryComboBox.setRenderer(createDirectoryComboBoxRenderer(fc));
- directoryComboBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
- directoryComboBox.setAlignmentY(JComponent.CENTER_ALIGNMENT);
- directoryComboBox.setMaximumRowCount(8);
! topPanel.add(directoryComboBox);
! topPanel.add(Box.createRigidArea(hstrut10));
! // Up Button
! JButton upFolderButton = createToolButton(getChangeToParentDirectoryAction(), upFolderIcon,
! upFolderToolTipText, upFolderAccessibleName);
! topPanel.add(upFolderButton);
! // New Directory Button
! if (!UIManager.getBoolean("FileChooser.readOnly")) {
! JButton newFolderButton = createToolButton(filePane.getNewFolderAction(), newFolderIcon,
! newFolderToolTipText, newFolderAccessibleName);
! topPanel.add(newFolderButton);
! }
! // View button group
! ButtonGroup viewButtonGroup = new ButtonGroup();
! // Popup Menu
! final JPopupMenu viewTypePopupMenu = new JPopupMenu();
! final JRadioButtonMenuItem listViewMenuItem = new JRadioButtonMenuItem(
! filePane.getViewTypeAction(FilePane.VIEWTYPE_LIST));
! listViewMenuItem.setSelected(filePane.getViewType() == FilePane.VIEWTYPE_LIST);
! viewTypePopupMenu.add(listViewMenuItem);
! viewButtonGroup.add(listViewMenuItem);
!
! final JRadioButtonMenuItem detailsViewMenuItem = new JRadioButtonMenuItem(
! filePane.getViewTypeAction(FilePane.VIEWTYPE_DETAILS));
! detailsViewMenuItem.setSelected(filePane.getViewType() == FilePane.VIEWTYPE_DETAILS);
! viewTypePopupMenu.add(detailsViewMenuItem);
! viewButtonGroup.add(detailsViewMenuItem);
! // Create icon for viewMenuButton
! BufferedImage image = new BufferedImage(viewMenuIcon.getIconWidth() + 7, viewMenuIcon.getIconHeight(),
! BufferedImage.TYPE_INT_ARGB);
! Graphics graphics = image.getGraphics();
! viewMenuIcon.paintIcon(filePane, graphics, 0, 0);
! int x = image.getWidth() - 5;
! int y = image.getHeight() / 2 - 1;
! graphics.setColor(Color.BLACK);
! graphics.fillPolygon(new int[]{x, x + 5, x + 2}, new int[]{y, y, y + 3}, 3);
! // Details Button
! final JButton viewMenuButton = createToolButton(null, new ImageIcon(image), viewMenuButtonToolTipText,
! viewMenuButtonAccessibleName);
! viewMenuButton.addMouseListener(new MouseAdapter() {
! public void mousePressed(MouseEvent e) {
! if (SwingUtilities.isLeftMouseButton(e) && !viewMenuButton.isSelected()) {
! viewMenuButton.setSelected(true);
! viewTypePopupMenu.show(viewMenuButton, 0, viewMenuButton.getHeight());
! }
}
- });
- viewMenuButton.addKeyListener(new KeyAdapter() {
- public void keyPressed(KeyEvent e) {
- // Forbid keyboard actions if the button is not in rollover state
- if (e.getKeyCode() == KeyEvent.VK_SPACE && viewMenuButton.getModel().isRollover()) {
- viewMenuButton.setSelected(true);
! viewTypePopupMenu.show(viewMenuButton, 0, viewMenuButton.getHeight());
! }
! }
! });
! viewTypePopupMenu.addPopupMenuListener(new PopupMenuListener() {
! public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
! }
! public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
! SwingUtilities.invokeLater(new Runnable() {
! public void run() {
! viewMenuButton.setSelected(false);
! }
! });
! }
! public void popupMenuCanceled(PopupMenuEvent e) {
! }
! });
! topPanel.add(viewMenuButton);
! topPanel.add(Box.createRigidArea(new Dimension(80, 0)));
! filePane.addPropertyChangeListener(new PropertyChangeListener() {
! public void propertyChange(PropertyChangeEvent e) {
! if ("viewType".equals(e.getPropertyName())) {
! switch (filePane.getViewType()) {
! case FilePane.VIEWTYPE_LIST:
! listViewMenuItem.setSelected(true);
! break;
! case FilePane.VIEWTYPE_DETAILS:
! detailsViewMenuItem.setSelected(true);
! break;
! }
}
}
- });
! // ************************************** //
! // ******* Add the directory pane ******* //
! // ************************************** //
! centerPanel = new JPanel(new BorderLayout());
! centerPanel.add(getAccessoryPanel(), BorderLayout.AFTER_LINE_ENDS);
! JComponent accessory = fc.getAccessory();
! if(accessory != null) {
! getAccessoryPanel().add(accessory);
}
! filePane.setPreferredSize(LIST_PREF_SIZE);
! centerPanel.add(filePane, BorderLayout.CENTER);
! fc.add(centerPanel, BorderLayout.CENTER);
! // ********************************** //
! // **** Construct the bottom panel ** //
! // ********************************** //
! getBottomPanel().setLayout(new BoxLayout(getBottomPanel(), BoxLayout.LINE_AXIS));
! // Add the bottom panel to file chooser
! centerPanel.add(getBottomPanel(), BorderLayout.SOUTH);
! // labels
! JPanel labelPanel = new JPanel();
! labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.PAGE_AXIS));
! labelPanel.add(Box.createRigidArea(vstrut4));
! fileNameLabel = new JLabel();
! populateFileNameLabel();
! fileNameLabel.setAlignmentY(0);
! labelPanel.add(fileNameLabel);
! labelPanel.add(Box.createRigidArea(new Dimension(1,12)));
JLabel ftl = new JLabel(filesOfTypeLabelText);
ftl.setDisplayedMnemonic(filesOfTypeLabelMnemonic);
! labelPanel.add(ftl);
!
! getBottomPanel().add(labelPanel);
! getBottomPanel().add(Box.createRigidArea(new Dimension(15, 0)));
// file entry and filters
! JPanel fileAndFilterPanel = new JPanel();
! fileAndFilterPanel.add(Box.createRigidArea(vstrut8));
! fileAndFilterPanel.setLayout(new BoxLayout(fileAndFilterPanel, BoxLayout.Y_AXIS));
!
! @SuppressWarnings("serial") // anonymous class
! JTextField tmp3 = new JTextField(35) {
public Dimension getMaximumSize() {
return new Dimension(Short.MAX_VALUE, super.getPreferredSize().height);
}
};
- filenameTextField = tmp3;
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()));
}
! fileAndFilterPanel.add(filenameTextField);
! fileAndFilterPanel.add(Box.createRigidArea(vstrut8));
! filterComboBoxModel = createFilterComboBoxModel();
! fc.addPropertyChangeListener(filterComboBoxModel);
! filterComboBox = new JComboBox<FileFilter>(filterComboBoxModel);
! ftl.setLabelFor(filterComboBox);
! filterComboBox.setRenderer(createFilterComboBoxRenderer());
! fileAndFilterPanel.add(filterComboBox);
! getBottomPanel().add(fileAndFilterPanel);
! getBottomPanel().add(Box.createRigidArea(new Dimension(30, 0)));
! // buttons
! getButtonPanel().setLayout(new BoxLayout(getButtonPanel(), BoxLayout.Y_AXIS));
! @SuppressWarnings("serial") // anonymous class
! JButton tmp4 = new JButton(getApproveButtonText(fc)) {
! public Dimension getMaximumSize() {
! return approveButton.getPreferredSize().width > cancelButton.getPreferredSize().width ?
! approveButton.getPreferredSize() : cancelButton.getPreferredSize();
}
};
! approveButton = tmp4;
! Insets buttonMargin = approveButton.getMargin();
! buttonMargin = new InsetsUIResource(buttonMargin.top, buttonMargin.left + 5,
! buttonMargin.bottom, buttonMargin.right + 5);
! approveButton.setMargin(buttonMargin);
! approveButton.setMnemonic(getApproveButtonMnemonic(fc));
! approveButton.addActionListener(getApproveSelectionAction());
! approveButton.setToolTipText(getApproveButtonToolTipText(fc));
! getButtonPanel().add(Box.createRigidArea(vstrut6));
! getButtonPanel().add(approveButton);
! getButtonPanel().add(Box.createRigidArea(vstrut4));
! @SuppressWarnings("serial") // anonymous class
! JButton tmp5 = new JButton(cancelButtonText) {
! public Dimension getMaximumSize() {
! return approveButton.getPreferredSize().width > cancelButton.getPreferredSize().width ?
! approveButton.getPreferredSize() : cancelButton.getPreferredSize();
}
};
! cancelButton = tmp5;
! cancelButton.setMargin(buttonMargin);
! cancelButton.setToolTipText(cancelButtonToolTipText);
! cancelButton.addActionListener(getCancelSelectionAction());
! getButtonPanel().add(cancelButton);
! if(fc.getControlButtonsAreShown()) {
! addControlButtons();
}
}
! private void updateUseShellFolder() {
! // Decide whether to use the ShellFolder class to populate shortcut
! // panel and combobox.
! JFileChooser fc = getFileChooser();
! if (FilePane.usesShellFolder(fc)) {
! if (placesBar == null && !UIManager.getBoolean("FileChooser.noPlacesBar")) {
! placesBar = new WindowsPlacesBar(fc, XPStyle.getXP() != null);
! fc.add(placesBar, BorderLayout.BEFORE_LINE_BEGINS);
! fc.addPropertyChangeListener(placesBar);
}
! } else {
! if (placesBar != null) {
! fc.remove(placesBar);
! fc.removePropertyChangeListener(placesBar);
! placesBar = null;
}
}
}
! protected JPanel getButtonPanel() {
! if(buttonPanel == null) {
! buttonPanel = new JPanel();
}
! return buttonPanel;
}
protected JPanel getBottomPanel() {
! if(bottomPanel == null) {
bottomPanel = new JPanel();
}
return bottomPanel;
}
protected void installStrings(JFileChooser fc) {
super.installStrings(fc);
Locale l = fc.getLocale();
- lookInLabelMnemonic = getMnemonic("FileChooser.lookInLabelMnemonic", l);
- lookInLabelText = UIManager.getString("FileChooser.lookInLabelText",l);
- saveInLabelText = UIManager.getString("FileChooser.saveInLabelText",l);
-
fileNameLabelMnemonic = getMnemonic("FileChooser.fileNameLabelMnemonic", l);
! fileNameLabelText = UIManager.getString("FileChooser.fileNameLabelText",l);
! folderNameLabelMnemonic = getMnemonic("FileChooser.folderNameLabelMnemonic", l);
! folderNameLabelText = UIManager.getString("FileChooser.folderNameLabelText",l);
filesOfTypeLabelMnemonic = getMnemonic("FileChooser.filesOfTypeLabelMnemonic", l);
! filesOfTypeLabelText = UIManager.getString("FileChooser.filesOfTypeLabelText",l);
! upFolderToolTipText = UIManager.getString("FileChooser.upFolderToolTipText",l);
! upFolderAccessibleName = UIManager.getString("FileChooser.upFolderAccessibleName",l);
! newFolderToolTipText = UIManager.getString("FileChooser.newFolderToolTipText",l);
! newFolderAccessibleName = UIManager.getString("FileChooser.newFolderAccessibleName",l);
! viewMenuButtonToolTipText = UIManager.getString("FileChooser.viewMenuButtonToolTipText",l);
! viewMenuButtonAccessibleName = UIManager.getString("FileChooser.viewMenuButtonAccessibleName",l);
}
private Integer getMnemonic(String key, Locale l) {
return SwingUtilities2.getUIDefaultsInt(key, l);
}
protected void installListeners(JFileChooser fc) {
super.installListeners(fc);
ActionMap actionMap = getActionMap();
SwingUtilities.replaceUIActionMap(fc, actionMap);
}
protected ActionMap getActionMap() {
return createActionMap();
}
protected ActionMap createActionMap() {
ActionMap map = new ActionMapUIResource();
FilePane.addActionsToMap(map, filePane.getActions());
return map;
}
protected JPanel createList(JFileChooser fc) {
return filePane.createList();
--- 266,804 ----
public void installComponents(JFileChooser fc) {
filePane = new FilePane(new WindowsFileChooserUIAccessor());
fc.addPropertyChangeListener(filePane);
! fc.setLayout(new BorderLayout());
! centerSplitPane.setBorder(null);
! centerSplitPaneContainer.add(centerSplitPane, BorderLayout.CENTER);
! fc.add(centerSplitPaneContainer, BorderLayout.CENTER);
!
! if (!UIManager.getBoolean("FileChooser.noPlacesBar")) {
! navTree = new WindowsNavigationTree(this);
! navTreeScrollPane = new JScrollPane(navTree);
! navTreeScrollPane.setBorder(null);
! centerSplitPane.add(navTreeScrollPane, JSplitPane.LEFT);
! fc.addPropertyChangeListener(navTree);
! }
// ********************************* //
// **** Construct the top panel **** //
// ********************************* //
// Add the top panel to the fileChooser
! fc.add(createTopContainer(fc), BorderLayout.NORTH);
! // ************************************** //
! // ******* Add the directory pane ******* //
! // ************************************** //
! JComponent accessory = fc.getAccessory();
! if (accessory != null) {
! getAccessoryPanel().add(accessory);
}
! filePane.setPreferredSize(LIST_PREF_SIZE);
! centerSplitPane.add(filePane, JSplitPane.RIGHT);
! // Add the bottom panel to file chooser
! fc.add(getBottomPanel(), BorderLayout.SOUTH);
! setupBottomPanel(fc);
}
! private void setupBottomPanel(JFileChooser fc) {
! getBottomPanel().setLayout(new BorderLayout());
! getBottomPanel().setBorder(new EmptyBorder(5, 5, 5, 5));
! getBottomPanel().setFont(Font.decode("Segoe UI-PLAIN-12.5"));
! // labels
! JPanel labelPanel = new JPanel();
! labelPanel.setOpaque(false);
! labelPanel.setLayout(new GridBagLayout());
! GridBagConstraints cons = new GridBagConstraints();
! cons.insets = new Insets(0, 0, 0, 5);
! cons.fill = GridBagConstraints.HORIZONTAL;
! cons.weightx = 1;
! cons.gridx = 0;
! setupFileNameLabel();
! labelPanel.add(fileNameLabel, cons);
! labelPanel.add(new JPanel(null), cons);
! JLabel ftl = createFileTypeLabel();
! labelPanel.add(ftl, cons);
! cons.gridx = 1;
! cons.insets = new Insets(0, 0, 0, 2);
! getBottomPanel().add(labelPanel);
! setupFileNameTextField();
! if (fc.isMultiSelectionEnabled()) {
! setFileName(fileNameString(fc.getSelectedFiles()));
! } else {
! setFileName(fileNameString(fc.getSelectedFile()));
}
! labelPanel.add(filenameTextField, cons);
! JPanel spacer = new JPanel(null);
! spacer.setPreferredSize(new Dimension(0, 3));
! labelPanel.add(spacer, cons);
! createFilterComboBox(fc, ftl);
! labelPanel.add(filterComboBox, cons);
! getBottomToolbar().setBorder(new EmptyBorder(20, 4, 4, 4));
! getBottomToolbar().setFloatable(false);
! getBottomToolbar().add(Box.createHorizontalGlue());
! getBottomToolbar().add(new JPanel() {
! {
! GroupLayout buttonPanelLayout = new GroupLayout(this);
! setLayout(buttonPanelLayout);
!
! setupApproveButton();
! setupCancelButton();
!
! add(approveButton);
! add(cancelButton);
!
! buttonPanelLayout.setHorizontalGroup(
! buttonPanelLayout.createSequentialGroup().
! addComponent(approveButton).
! addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).
! addComponent(cancelButton)
! );
! buttonPanelLayout.setVerticalGroup(
! buttonPanelLayout.createParallelGroup().
! addComponent(approveButton).
! addComponent(cancelButton)
! );
! buttonPanelLayout.linkSize(approveButton, cancelButton);
}
+
+ private void setupApproveButton() {
+ approveButton = new JButton(getApproveButtonText(fc));
+ approveButton.setMnemonic(getApproveButtonMnemonic(fc));
+ approveButton.addActionListener(getApproveSelectionAction());
+ approveButton.setToolTipText(getApproveButtonToolTipText(fc));
+ approveButton.setMargin(new Insets(3, 15, 3, 15));
+ approveButton.setFont(getFont());
}
! private Insets setupCancelButton() {
! cancelButton = new JButton(cancelButtonText) {
! public Dimension getMaximumSize() {
! return approveButton.getPreferredSize().width > cancelButton.getPreferredSize().width
! ? approveButton.getPreferredSize() : cancelButton.getPreferredSize();
}
! };
! Insets buttonMargin = approveButton.getMargin();
! cancelButton.setFont(getFont());
! cancelButton.setMargin(buttonMargin);
! cancelButton.setToolTipText(cancelButtonToolTipText);
! cancelButton.addActionListener(getCancelSelectionAction());
! return buttonMargin;
! }
! });
! if (fc.getControlButtonsAreShown()) {
! addControlButtons();
! }
! }
! private void createFilterComboBox(JFileChooser fc, JLabel ftl) {
! filterComboBoxModel = createFilterComboBoxModel();
! fc.addPropertyChangeListener(filterComboBoxModel);
! filterComboBox = new JComboBox<FileFilter>(filterComboBoxModel);
! ftl.setLabelFor(filterComboBox);
! filterComboBox.setRenderer(createFilterComboBoxRenderer());
! filterComboBox.setFont(bottomPanel.getFont());
! }
+ private JLabel createFileTypeLabel() {
JLabel ftl = new JLabel(filesOfTypeLabelText);
ftl.setDisplayedMnemonic(filesOfTypeLabelMnemonic);
! ftl.setHorizontalAlignment(RIGHT);
! ftl.setFont(getBottomPanel().getFont());
! return ftl;
! }
+ private void setupFileNameTextField() {
// file entry and filters
! filenameTextField = new JTextField(35) {
public Dimension getMaximumSize() {
return new Dimension(Short.MAX_VALUE, super.getPreferredSize().height);
}
};
fileNameLabel.setLabelFor(filenameTextField);
filenameTextField.addFocusListener(
new FocusAdapter() {
+ @Override
public void focusGained(FocusEvent e) {
if (!getFileChooser().isMultiSelectionEnabled()) {
filePane.clearSelection();
}
}
+ });
+
+ filenameTextField.setFont(bottomPanel.getFont());
+ filenameTextField.setMargin(new Insets(2, 4, 2, 4));
}
! private void setupFileNameLabel() {
! fileNameLabel = new JLabel();
! populateFileNameLabel();
! fileNameLabel.setHorizontalAlignment(RIGHT);
! fileNameLabel.setAlignmentY(0);
! fileNameLabel.setFont(getBottomPanel().getFont());
}
! private JPanel createTopContainer(JFileChooser fc) {
! JPanel topContainer = new JPanel(new BorderLayout());
! JToolBar topPanel = new JToolBar() {
! private boolean isWin7GradientBackground = false;
! {
! setOpaque(true);
! /* switch (getType()) {
! case WIN7:
! isWin7GradientBackground
! = Win32GraphicsEnvironment.isDWMCompositionEnabled();
! setBackground(new Color(185, 209, 234));
! // TODO: ablak unfókuszálásakor más szín kell
! Win32GraphicsEnvironment.addDwmCompositionChangeListener(() -> {
! isWin7GradientBackground
! = Win32GraphicsEnvironment.isDWMCompositionEnabled();
! repaint();
! });
!
! //setBackground(new Color(230, 240, 250));
! break;
! case WIN10:*/
! setBackground(WHITE);/*
! break;
! case CLASSIC:
! setBackground(SystemColor.control);
! break;
! default:
! throw new UnsupportedOperationException();
! }*/
}
+
+ @Override
+ protected void paintComponent(Graphics g) {
+ if (!isWin7GradientBackground) {
+ super.paintComponent(g);
+ return;
+ }
+
+ Graphics2D g2d = (Graphics2D) g;
+
+ g2d.setPaint(new GradientPaint(
+ 0, 0,
+ new Color(250, 252, 253),
+ 0, getHeight() / 2,
+ new Color(230, 240, 250)
+ ));
+ g2d.fillRect(0, 0, getWidth(), getHeight());
+ }
+
};
! topPanel.setBorder(new EmptyBorder(0, 4, 0, 0));
! topPanel.setFloatable(false);
! topPanel.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
! topPanel.setMaximumSize(new Dimension(0, 12));
! topContainer.add(topPanel, BorderLayout.NORTH);
! JToolBar utilityToolBar = new JToolBar() {
!
! private boolean isWin7Background;
!
! {
! /* switch (getType()) {
! case WIN7:
! isWin7Background = true;
! break;
! case WIN10:*/
! setBackground(new Color(245, 246, 247));/*
! break;
! }*/
! }
!
! @Override
! protected void paintComponent(Graphics g) {
! if (!isWin7Background) {
! super.paintComponent(g);
! return;
! }
!
! Graphics2D g2d = (Graphics2D) g;
!
! g2d.setPaint(new LinearGradientPaint(
! new Point2D.Double(0, 0),
! new Point2D.Double(0, getHeight() / 2),
! new float[]{0, 1},
! new Color[]{new Color(250, 252, 253), new Color(230, 240, 250)}
! ));
! g2d.fillRect(0, 0, getWidth(), getHeight() / 2);
!
! g2d.setPaint(new LinearGradientPaint(
! new Point2D.Double(0, 0),
! new Point2D.Double(0, getHeight() / 2),
! new float[]{0, 1},
! new Color[]{new Color(220, 230, 244), new Color(221, 233, 247)}
! ));
! g2d.fillRect(0, getHeight() / 2, getWidth(), getHeight() / 2);
}
+
+ @Override
+ protected void addImpl(Component comp, Object constraints, int index) {
+ super.addImpl(comp, constraints, index);
+ if(comp instanceof JButton) {
+ JButton btn = (JButton) comp;
+ btn.setBorder(new EmptyBorder(btn.getInsets()));
+ }
+ }
+
};
! utilityToolBar.setForeground(new Color(30, 57, 91));
! utilityToolBar.setFloatable(false);
! utilityToolBar.setOpaque(true);
! utilityToolBar.setBorder(new MatteBorder(0, 0, 1, 0, new Color(232, 233, 234)));
! topContainer.add(utilityToolBar, BorderLayout.CENTER);
!
! // Back Button
! JButton backFolderButton = createToolButton(getBackAction(),
! new ImageIcon(initBackArrowImage()),
! "BACKBUTTON TOOLTIP", "BACKBUTTON ACCESSIBLENAME");
! topPanel.add(backFolderButton);
!
! // Forward Button
! JButton forwardFolderButton = createToolButton(getForwardAction(),
! new ImageIcon(initForwardArrowImage()),
! "FWBUTTON TOOLTIP", "FWBUTTON ACCESSIBLENAME");
! topPanel.add(forwardFolderButton);
! // Up Button
! JButton upFolderButton = createToolButton(getChangeToParentDirectoryAction(),
! new ImageIcon(initUpArrowImage()),
! upFolderToolTipText, upFolderAccessibleName);
! topPanel.add(upFolderButton);
!
! // Refresh Button
! JButton refreshButton = new JButton(getUpdateAction());
! refreshButton.putClientProperty("WindowsButtonUI.displayAsInToolbar", TRUE);
! refreshButton.putClientProperty("WindowsButtonUI.animateStateChange", TRUE);
! refreshButton.setBackground(WHITE);
! refreshButton.setPreferredSize(new Dimension(20, 22));
! refreshButton.setBorder(new MatteBorder(1, 0, 1, 1,
! new Color(217, 217, 217)));
!
! // AddressBar
! addressBar = new WindowsAddressBar(fc);
!
! JPanel addressBarContainer = new JPanel(new BorderLayout());
! addressBarContainer.setBorder(new EmptyBorder(5, 3, 7, 4));
! addressBarContainer.setOpaque(false);
! addressBarContainer.add(newSpaceFiller(), BorderLayout.NORTH);
! addressBarContainer.add(addressBar, BorderLayout.CENTER);
! addressBarContainer.add(newSpaceFiller(), BorderLayout.SOUTH);
! addressBarContainer.add(refreshButton, BorderLayout.EAST);
! topPanel.add(addressBarContainer);
! topPanel.add(Box.createRigidArea(hstrut10));
!
! // New Directory Button
! if (!UIManager.getBoolean("FileChooser.readOnly")) {
! JButton newFolderButton = new JButton(filePane.getNewFolderAction());
! newFolderButton.setForeground(utilityToolBar.getForeground());
! newFolderButton.setOpaque(false);
! newFolderButton.setMargin(UTILITY_TOOLBAR_BUTTON_MARGIN);
! newFolderButton.setToolTipText(newFolderToolTipText);
! newFolderButton.getAccessibleContext().setAccessibleName(newFolderAccessibleName);
! utilityToolBar.add(newFolderButton);
}
+
+ JPanel filler = new JPanel();
+ filler.setOpaque(false);
+ utilityToolBar.add(filler);
+
+ JButton viewMenuButton = createDetailsButton(createViewTypePopupMenu());
+ viewMenuButton.setForeground(utilityToolBar.getForeground());
+ viewMenuButton.setMargin(UTILITY_TOOLBAR_BUTTON_MARGIN);
+ utilityToolBar.add(viewMenuButton);
+
+ initViewTypeMenuIcon();
+
+ return topContainer;
}
! private static JPanel newSpaceFiller() {
! JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
! panel.setOpaque(false);
! return panel;
! }
! private void initViewTypeMenuIcon() {
! // Create icon for viewMenuButton
! BufferedImage image = new BufferedImage(viewMenuIcon.getIconWidth() + 7, viewMenuIcon.getIconHeight(),
! BufferedImage.TYPE_INT_ARGB);
! Graphics graphics = image.getGraphics();
! viewMenuIcon.paintIcon(filePane, graphics, 0, 0);
! int x = image.getWidth() - 5;
! int y = image.getHeight() / 2 - 1;
! graphics.setColor(Color.BLACK);
! graphics.fillPolygon(new int[]{x, x + 5, x + 2}, new int[]{y, y, y + 3}, 3);
}
!
! private JPopupMenu createViewTypePopupMenu() {
! // View button group
! ButtonGroup viewButtonGroup = new ButtonGroup();
!
! // Popup Menu
! final JPopupMenu viewTypePopupMenu = new JPopupMenu();
!
! Map<ViewType, JRadioButtonMenuItem> viewTypeMenuItems
! = new EnumMap<>(ViewType.class);
!
! for (ViewType viewType : ViewType.values()) {
! final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(
! filePane.getViewTypeAction(viewType));
! menuItem.setSelected(filePane.getViewType() == viewType);
! viewTypePopupMenu.add(menuItem);
! viewButtonGroup.add(menuItem);
!
! viewTypeMenuItems.put(viewType, menuItem);
! }
!
! filePane.addPropertyChangeListener(evt -> {
! if ("viewType".equals(evt.getPropertyName())) {
! viewTypeMenuItems.get(filePane.getViewType()).setSelected(true);
}
+ });
+
+ return viewTypePopupMenu;
+ }
+
+ private JButton createDetailsButton(final JPopupMenu viewTypePopupMenu) {
+ // Details Button
+ final JButton viewMenuButton = createToolButton(new AbstractAction("Rendezés"){
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ }
+ }, null, viewMenuButtonToolTipText,
+ viewMenuButtonAccessibleName);
+ viewMenuButton.addActionListener(evt->{
+ viewTypePopupMenu.show(viewMenuButton, 0, viewMenuButton.getHeight());
+ });
+ viewMenuButton.setOpaque(false);
+ viewMenuButton.setMargin(UTILITY_TOOLBAR_BUTTON_MARGIN);
+ viewTypePopupMenu.addPopupMenuListener(new PopupMenuListener() {
+ public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
+ viewMenuButton.setSelected(true);
+ }
+
+ public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ viewMenuButton.setSelected(false);
+ }
+ });
+ }
+
+ public void popupMenuCanceled(PopupMenuEvent e) {
}
+ });
+ return viewMenuButton;
}
! private JScrollPane navTreeScrollPane;
!
! protected JToolBar getBottomToolbar() {
! if (bottomToolbar == null) {
! bottomToolbar = new JToolBar();
}
! return bottomToolbar;
}
protected JPanel getBottomPanel() {
! if (bottomPanel == null) {
bottomPanel = new JPanel();
}
return bottomPanel;
}
protected void installStrings(JFileChooser fc) {
super.installStrings(fc);
Locale l = fc.getLocale();
fileNameLabelMnemonic = getMnemonic("FileChooser.fileNameLabelMnemonic", l);
! fileNameLabelText = UIManager.getString("FileChooser.fileNameLabelText", l);
filesOfTypeLabelMnemonic = getMnemonic("FileChooser.filesOfTypeLabelMnemonic", l);
! filesOfTypeLabelText = UIManager.getString("FileChooser.filesOfTypeLabelText", l);
! upFolderToolTipText = UIManager.getString("FileChooser.upFolderToolTipText", l);
! upFolderAccessibleName = UIManager.getString("FileChooser.upFolderAccessibleName", l);
! newFolderToolTipText = UIManager.getString("FileChooser.newFolderToolTipText", l);
! newFolderAccessibleName = UIManager.getString("FileChooser.newFolderAccessibleName", l);
! viewMenuButtonToolTipText = UIManager.getString("FileChooser.viewMenuButtonToolTipText", l);
! viewMenuButtonAccessibleName = UIManager.getString("FileChooser.viewMenuButtonAccessibleName", l);
}
private Integer getMnemonic(String key, Locale l) {
return SwingUtilities2.getUIDefaultsInt(key, l);
}
protected void installListeners(JFileChooser fc) {
super.installListeners(fc);
ActionMap actionMap = getActionMap();
SwingUtilities.replaceUIActionMap(fc, actionMap);
+
+ fc.addPropertyChangeListener(JFileChooser.DIRECTORY_CHANGED_PROPERTY, evt -> {
+ if (!isInBack) {
+ if (!historyForward.isEmpty()) {
+ if (historyForward.peek().equals(evt.getNewValue())) {
+ historyForward.pop();
+ } else {
+ historyForward.clear();
+ }
+ }
+
+ if (evt.getOldValue() != null) {
+ historyBack.push((File) evt.getOldValue());
+ }
+ }
+
+ getBackAction().setEnabled(!historyBack.isEmpty());
+ getForwardAction().setEnabled(!historyForward.isEmpty());
+ });
}
protected ActionMap getActionMap() {
return createActionMap();
}
protected ActionMap createActionMap() {
ActionMap map = new ActionMapUIResource();
FilePane.addActionsToMap(map, filePane.getActions());
+ FilePane.addActionsToMap(map, new Action[]{getChangeToParentDirectoryAction()});
return map;
}
protected JPanel createList(JFileChooser fc) {
return filePane.createList();
*** 594,623 ****
*/
public ListSelectionListener createListSelectionListener(JFileChooser fc) {
return super.createListSelectionListener(fc);
}
- // Obsolete class, not used in this version.
- @SuppressWarnings("serial")
- protected class WindowsNewFolderAction extends NewFolderAction {
- }
-
- // Obsolete class, not used in this version.
- protected class SingleClickListener extends MouseAdapter {
- }
-
- // Obsolete class, not used in this version.
- @SuppressWarnings("serial") // Superclass is not serializable across versions
- protected class FileRenderer extends DefaultListCellRenderer {
- }
-
public void uninstallUI(JComponent c) {
// Remove listeners
c.removePropertyChangeListener(filterComboBoxModel);
c.removePropertyChangeListener(filePane);
! if (placesBar != null) {
! c.removePropertyChangeListener(placesBar);
}
cancelButton.removeActionListener(getCancelSelectionAction());
approveButton.removeActionListener(getApproveSelectionAction());
filenameTextField.removeActionListener(getApproveSelectionAction());
--- 816,831 ----
*/
public ListSelectionListener createListSelectionListener(JFileChooser fc) {
return super.createListSelectionListener(fc);
}
public void uninstallUI(JComponent c) {
// Remove listeners
c.removePropertyChangeListener(filterComboBoxModel);
c.removePropertyChangeListener(filePane);
! if (navTree != null) {
! c.removePropertyChangeListener(navTree);
}
cancelButton.removeActionListener(getCancelSelectionAction());
approveButton.removeActionListener(getApproveSelectionAction());
filenameTextField.removeActionListener(getApproveSelectionAction());
*** 628,647 ****
super.uninstallUI(c);
}
/**
! * Returns the preferred size of the specified
! * <code>JFileChooser</code>.
! * 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.
*
* @param c a <code>JFileChooser</code>
! * @return a <code>Dimension</code> specifying the preferred
! * width and height of the file chooser
*/
@Override
public Dimension getPreferredSize(JComponent c) {
int prefWidth = PREF_SIZE.width;
Dimension d = c.getLayout().preferredLayoutSize(c);
--- 836,852 ----
super.uninstallUI(c);
}
/**
! * Returns the preferred size of the specified <code>JFileChooser</code>.
! * 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.
*
* @param c a <code>JFileChooser</code>
! * @return a <code>Dimension</code> specifying the preferred width and
! * height of the file chooser
*/
@Override
public Dimension getPreferredSize(JComponent c) {
int prefWidth = PREF_SIZE.width;
Dimension d = c.getLayout().preferredLayoutSize(c);
*** 655,678 ****
/**
* Returns the minimum size of the <code>JFileChooser</code>.
*
* @param c a <code>JFileChooser</code>
! * @return a <code>Dimension</code> specifying the minimum
! * width and height of the file chooser
*/
@Override
public Dimension getMinimumSize(JComponent c) {
return new Dimension(MIN_WIDTH, MIN_HEIGHT);
}
/**
* Returns the maximum size of the <code>JFileChooser</code>.
*
* @param c a <code>JFileChooser</code>
! * @return a <code>Dimension</code> specifying the maximum
! * width and height of the file chooser
*/
@Override
public Dimension getMaximumSize(JComponent c) {
return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
}
--- 860,883 ----
/**
* Returns the minimum size of the <code>JFileChooser</code>.
*
* @param c a <code>JFileChooser</code>
! * @return a <code>Dimension</code> specifying the minimum width and height
! * of the file chooser
*/
@Override
public Dimension getMinimumSize(JComponent c) {
return new Dimension(MIN_WIDTH, MIN_HEIGHT);
}
/**
* Returns the maximum size of the <code>JFileChooser</code>.
*
* @param c a <code>JFileChooser</code>
! * @return a <code>Dimension</code> specifying the maximum width and height
! * of the file chooser
*/
@Override
public Dimension getMaximumSize(JComponent c) {
return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
}
*** 680,700 ****
private String fileNameString(File file) {
if (file == null) {
return null;
} else {
JFileChooser fc = getFileChooser();
! if ((fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) ||
! (fc.isDirectorySelectionEnabled() && fc.isFileSelectionEnabled() && fc.getFileSystemView().isFileSystemRoot(file))){
return file.getPath();
} else {
return file.getName();
}
}
}
private String fileNameString(File[] files) {
! StringBuilder buf = new StringBuilder();
for (int i = 0; files != null && i < files.length; i++) {
if (i > 0) {
buf.append(" ");
}
if (files.length > 1) {
--- 885,905 ----
private String fileNameString(File file) {
if (file == null) {
return null;
} else {
JFileChooser fc = getFileChooser();
! if ((fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled())
! || (fc.isDirectorySelectionEnabled() && fc.isFileSelectionEnabled() && fc.getFileSystemView().isFileSystemRoot(file))) {
return file.getPath();
} else {
return file.getName();
}
}
}
private String fileNameString(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) {
*** 707,717 ****
}
return buf.toString();
}
/* The following methods are used by the PropertyChange Listener */
-
private void doSelectedFileChanged(PropertyChangeEvent e) {
File f = (File) e.getNewValue();
JFileChooser fc = getFileChooser();
if (f != null
&& ((fc.isFileSelectionEnabled() && !f.isDirectory())
--- 912,921 ----
*** 735,747 ****
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);
--- 939,949 ----
JFileChooser fc = getFileChooser();
FileSystemView fsv = fc.getFileSystemView();
clearIconCache();
File currentDirectory = fc.getCurrentDirectory();
! if (currentDirectory != null) {
if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) {
if (fsv.isFileSystem(currentDirectory)) {
setFileName(currentDirectory.getPath());
} else {
setFileName(null);
*** 772,787 ****
setFileName(null);
}
}
private void doAccessoryChanged(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);
}
}
}
--- 974,989 ----
setFileName(null);
}
}
private void doAccessoryChanged(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);
}
}
}
*** 795,817 ****
private void doDialogTypeChanged(PropertyChangeEvent e) {
JFileChooser chooser = getFileChooser();
approveButton.setText(getApproveButtonText(chooser));
approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
approveButton.setMnemonic(getApproveButtonMnemonic(chooser));
- if (chooser.getDialogType() == JFileChooser.SAVE_DIALOG) {
- lookInLabel.setText(saveInLabelText);
- } else {
- lookInLabel.setText(lookInLabelText);
- }
}
private void doApproveButtonMnemonicChanged(PropertyChangeEvent e) {
approveButton.setMnemonic(getApproveButtonMnemonic(getFileChooser()));
}
private void doControlButtonsChanged(PropertyChangeEvent e) {
! if(getFileChooser().getControlButtonsAreShown()) {
addControlButtons();
} else {
removeControlButtons();
}
}
--- 997,1014 ----
private void doDialogTypeChanged(PropertyChangeEvent e) {
JFileChooser chooser = getFileChooser();
approveButton.setText(getApproveButtonText(chooser));
approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
approveButton.setMnemonic(getApproveButtonMnemonic(chooser));
}
private void doApproveButtonMnemonicChanged(PropertyChangeEvent e) {
approveButton.setMnemonic(getApproveButtonMnemonic(getFileChooser()));
}
private void doControlButtonsChanged(PropertyChangeEvent e) {
! if (getFileChooser().getControlButtonsAreShown()) {
addControlButtons();
} else {
removeControlButtons();
}
}
*** 819,879 ****
/*
* Listen for filechooser property changes, such as
* the selected file changing, or the type of the dialog changing.
*/
public PropertyChangeListener createPropertyChangeListener(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 == "FileChooser.useShellFolder") {
! updateUseShellFolder();
doDirectoryChanged(e);
! } else if (s.equals("componentOrientation")) {
! ComponentOrientation o = (ComponentOrientation)e.getNewValue();
! JFileChooser cc = (JFileChooser)e.getSource();
if (o != e.getOldValue()) {
cc.applyComponentOrientation(o);
}
! } else if (s.equals("ancestor")) {
if (e.getOldValue() == null && e.getNewValue() != null) {
// Ancestor was added, set initial focus
filenameTextField.selectAll();
filenameTextField.requestFocus();
}
! }
}
};
}
-
protected void removeControlButtons() {
! getBottomPanel().remove(getButtonPanel());
}
protected void addControlButtons() {
! getBottomPanel().add(getButtonPanel());
}
public void ensureFileIsVisible(JFileChooser fc, File f) {
filePane.ensureFileIsVisible(fc, f);
}
--- 1016,1086 ----
/*
* Listen for filechooser property changes, such as
* the selected file changing, or the type of the dialog changing.
*/
public PropertyChangeListener createPropertyChangeListener(JFileChooser fc) {
! return (PropertyChangeEvent e) -> {
String s = e.getPropertyName();
! switch (s) {
! case JFileChooser.SELECTED_FILE_CHANGED_PROPERTY:
doSelectedFileChanged(e);
! break;
! case JFileChooser.SELECTED_FILES_CHANGED_PROPERTY:
doSelectedFilesChanged(e);
! break;
! case JFileChooser.DIRECTORY_CHANGED_PROPERTY:
doDirectoryChanged(e);
! break;
! case JFileChooser.FILE_FILTER_CHANGED_PROPERTY:
doFilterChanged(e);
! break;
! case JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY:
doFileSelectionModeChanged(e);
! break;
! case JFileChooser.ACCESSORY_CHANGED_PROPERTY:
doAccessoryChanged(e);
! break;
! case JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY:
! case JFileChooser.APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY:
doApproveButtonTextChanged(e);
! break;
! case JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY:
doDialogTypeChanged(e);
! break;
! case JFileChooser.APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY:
doApproveButtonMnemonicChanged(e);
! break;
! case JFileChooser.CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY:
doControlButtonsChanged(e);
! break;
! case "FileChooser.useShellFolder":
doDirectoryChanged(e);
! break;
! case "componentOrientation":
! ComponentOrientation o = (ComponentOrientation) e.getNewValue();
! JFileChooser cc = (JFileChooser) e.getSource();
if (o != e.getOldValue()) {
cc.applyComponentOrientation(o);
}
! break;
! case "ancestor":
if (e.getOldValue() == null && e.getNewValue() != null) {
// Ancestor was added, set initial focus
filenameTextField.selectAll();
filenameTextField.requestFocus();
}
! break;
}
};
}
protected void removeControlButtons() {
! getBottomPanel().remove(getBottomToolbar());
}
protected void addControlButtons() {
! getBottomPanel().add(getBottomToolbar(), BorderLayout.SOUTH);
}
public void ensureFileIsVisible(JFileChooser fc, File f) {
filePane.ensureFileIsVisible(fc, f);
}
*** 881,899 ****
public void rescanCurrentDirectory(JFileChooser fc) {
filePane.rescanCurrentDirectory();
}
public String getFileName() {
! if(filenameTextField != null) {
return filenameTextField.getText();
} else {
return null;
}
}
public void setFileName(String filename) {
! if(filenameTextField != null) {
filenameTextField.setText(filename);
}
}
/**
--- 1088,1107 ----
public void rescanCurrentDirectory(JFileChooser fc) {
filePane.rescanCurrentDirectory();
}
public String getFileName() {
! if (filenameTextField != null) {
return filenameTextField.getText();
} else {
return null;
}
}
+ @Override
public void setFileName(String filename) {
! if (filenameTextField != null) {
filenameTextField.setText(filename);
}
}
/**
*** 901,960 ****
* This is normally called by the UI on a selection event.
*
* @param directorySelected if a directory is currently selected.
* @since 1.4
*/
protected void setDirectorySelected(boolean directorySelected) {
super.setDirectorySelected(directorySelected);
JFileChooser chooser = getFileChooser();
! if(directorySelected) {
approveButton.setText(directoryOpenButtonText);
approveButton.setToolTipText(directoryOpenButtonToolTipText);
approveButton.setMnemonic(directoryOpenButtonMnemonic);
} else {
approveButton.setText(getApproveButtonText(chooser));
approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
approveButton.setMnemonic(getApproveButtonMnemonic(chooser));
}
}
public String getDirectoryName() {
! // PENDING(jeff) - get the name from the directory combobox
! return null;
}
public void setDirectoryName(String dirname) {
// PENDING(jeff) - set the name in the directory combobox
}
- protected DirectoryComboBoxRenderer createDirectoryComboBoxRenderer(JFileChooser fc) {
- return new DirectoryComboBoxRenderer();
- }
-
- @SuppressWarnings("serial") // anonymous class
private static JButton createToolButton(Action a, Icon defaultIcon, String toolTipText, String accessibleName) {
final JButton result = new JButton(a);
result.setText(null);
result.setIcon(defaultIcon);
result.setToolTipText(toolTipText);
result.setRequestFocusEnabled(false);
result.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, accessibleName);
result.putClientProperty(WindowsLookAndFeel.HI_RES_DISABLED_ICON_CLIENT_KEY, Boolean.TRUE);
result.setAlignmentX(JComponent.LEFT_ALIGNMENT);
result.setAlignmentY(JComponent.CENTER_ALIGNMENT);
! result.setMargin(shrinkwrap);
result.setFocusPainted(false);
result.setModel(new DefaultButtonModel() {
public void setPressed(boolean b) {
// Forbid keyboard actions if the button is not in rollover state
if (!b || isRollover()) {
super.setPressed(b);
}
}
public void setRollover(boolean b) {
if (b && !isRollover()) {
// Reset other buttons
for (Component component : result.getParent().getComponents()) {
if (component instanceof JButton && component != result) {
--- 1109,1186 ----
* This is normally called by the UI on a selection event.
*
* @param directorySelected if a directory is currently selected.
* @since 1.4
*/
+ @Override
protected void setDirectorySelected(boolean directorySelected) {
super.setDirectorySelected(directorySelected);
JFileChooser chooser = getFileChooser();
! if (directorySelected) {
approveButton.setText(directoryOpenButtonText);
approveButton.setToolTipText(directoryOpenButtonToolTipText);
approveButton.setMnemonic(directoryOpenButtonMnemonic);
} else {
approveButton.setText(getApproveButtonText(chooser));
approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
approveButton.setMnemonic(getApproveButtonMnemonic(chooser));
}
}
+ @Override
+ public Action getUpdateAction() {
+ return new UpdateAction() {
+
+ {
+ putValue(Action.SMALL_ICON, new ImageIcon(initRefreshImage()));
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ rescanCurrentDirectory(getFileChooser());
+ }
+
+ };
+ }
+
+
public String getDirectoryName() {
! System.out.println(getFileChooser().getCurrentDirectory().getPath());
! return getFileChooser().getCurrentDirectory().getPath();
}
public void setDirectoryName(String dirname) {
// PENDING(jeff) - set the name in the directory combobox
}
private static JButton createToolButton(Action a, Icon defaultIcon, String toolTipText, String accessibleName) {
final JButton result = new JButton(a);
+ if (defaultIcon != null) {
result.setText(null);
result.setIcon(defaultIcon);
+ }
result.setToolTipText(toolTipText);
result.setRequestFocusEnabled(false);
result.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, accessibleName);
result.putClientProperty(WindowsLookAndFeel.HI_RES_DISABLED_ICON_CLIENT_KEY, Boolean.TRUE);
result.setAlignmentX(JComponent.LEFT_ALIGNMENT);
result.setAlignmentY(JComponent.CENTER_ALIGNMENT);
! result.setMargin(new Insets(5, 5, 5, 5));
! result.setOpaque(false);
result.setFocusPainted(false);
result.setModel(new DefaultButtonModel() {
+ @Override
public void setPressed(boolean b) {
// Forbid keyboard actions if the button is not in rollover state
if (!b || isRollover()) {
super.setPressed(b);
}
}
+ @Override
public void setRollover(boolean b) {
if (b && !isRollover()) {
// Reset other buttons
for (Component component : result.getParent().getComponents()) {
if (component instanceof JButton && component != result) {
*** 974,983 ****
--- 1200,1210 ----
} else {
stateMask &= ~(PRESSED | ARMED);
}
}
});
+ result.getModel().setEnabled(a.isEnabled());
result.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
result.getModel().setRollover(true);
}
*** 989,1185 ****
return result;
}
//
- // Renderer for DirectoryComboBox
- //
- @SuppressWarnings("serial") // Superclass is not serializable across versions
- class DirectoryComboBoxRenderer extends DefaultListCellRenderer {
- IndentIcon ii = new IndentIcon();
- public Component getListCellRendererComponent(JList<?> list, Object value,
- int index, boolean isSelected,
- boolean cellHasFocus) {
-
- super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
-
- if (value == null) {
- setText("");
- return this;
- }
- File directory = (File)value;
- setText(getFileChooser().getName(directory));
- Icon icon = getFileChooser().getIcon(directory);
- ii.icon = icon;
- ii.depth = directoryComboBoxModel.getDepth(index);
- setIcon(ii);
-
- return this;
- }
- }
-
- static final int space = 10;
- class IndentIcon implements Icon {
-
- Icon icon = null;
- int depth = 0;
-
- public void paintIcon(Component c, Graphics g, int x, int y) {
- if (c.getComponentOrientation().isLeftToRight()) {
- icon.paintIcon(c, g, x+depth*space, y);
- } else {
- icon.paintIcon(c, g, x, y);
- }
- }
-
- public int getIconWidth() {
- return icon.getIconWidth() + depth*space;
- }
-
- public int getIconHeight() {
- return icon.getIconHeight();
- }
-
- }
-
- //
- // DataModel for DirectoryComboxbox
- //
- protected DirectoryComboBoxModel createDirectoryComboBoxModel(JFileChooser fc) {
- return new DirectoryComboBoxModel();
- }
-
- /**
- * Data model for a type-face selection combo-box.
- */
- @SuppressWarnings("serial") // Superclass is not serializable across versions
- protected class DirectoryComboBoxModel extends AbstractListModel<File> implements ComboBoxModel<File> {
- Vector<File> directories = new Vector<File>();
- int[] depths = null;
- File selectedDirectory = null;
- JFileChooser chooser = getFileChooser();
- FileSystemView fsv = chooser.getFileSystemView();
-
- public DirectoryComboBoxModel() {
- // Add the current directory to the model, and make it the
- // selectedDirectory
- File dir = getFileChooser().getCurrentDirectory();
- if(dir != null) {
- addItem(dir);
- }
- }
-
- /**
- * Adds the directory to the model and sets it to be selected,
- * additionally clears out the previous selected directory and
- * the paths leading up to it, if any.
- */
- private void addItem(File directory) {
-
- if(directory == null) {
- return;
- }
-
- boolean useShellFolder = FilePane.usesShellFolder(chooser);
-
- directories.clear();
-
- File[] baseFolders = (useShellFolder)
- ? (File[]) ShellFolder.get("fileChooserComboBoxFolders")
- : fsv.getRoots();
- directories.addAll(Arrays.asList(baseFolders));
-
- // Get the canonical (full) path. This has the side
- // benefit of removing extraneous chars from the path,
- // for example /foo/bar/ becomes /foo/bar
- File canonical;
- try {
- canonical = directory.getCanonicalFile();
- } catch (IOException e) {
- // Maybe drive is not ready. Can't abort here.
- canonical = directory;
- }
-
- // create File instances of each directory leading up to the top
- try {
- File sf = useShellFolder ? ShellFolder.getShellFolder(canonical)
- : canonical;
- File f = sf;
- Vector<File> path = new Vector<File>(10);
- do {
- path.addElement(f);
- } while ((f = f.getParentFile()) != null);
-
- int pathCount = path.size();
- // Insert chain at appropriate place in vector
- for (int i = 0; i < pathCount; i++) {
- f = path.get(i);
- if (directories.contains(f)) {
- int topIndex = directories.indexOf(f);
- for (int j = i-1; j >= 0; j--) {
- directories.insertElementAt(path.get(j), topIndex+i-j);
- }
- break;
- }
- }
- calculateDepths();
- setSelectedItem(sf);
- } catch (FileNotFoundException ex) {
- calculateDepths();
- }
- }
-
- private void calculateDepths() {
- depths = new int[directories.size()];
- for (int i = 0; i < depths.length; i++) {
- File dir = directories.get(i);
- File parent = dir.getParentFile();
- depths[i] = 0;
- if (parent != null) {
- for (int j = i-1; j >= 0; j--) {
- if (parent.equals(directories.get(j))) {
- depths[i] = depths[j] + 1;
- break;
- }
- }
- }
- }
- }
-
- public int getDepth(int i) {
- return (depths != null && i >= 0 && i < depths.length) ? depths[i] : 0;
- }
-
- public void setSelectedItem(Object selectedDirectory) {
- this.selectedDirectory = (File)selectedDirectory;
- fireContentsChanged(this, -1, -1);
- }
-
- public Object getSelectedItem() {
- return selectedDirectory;
- }
-
- public int getSize() {
- return directories.size();
- }
-
- public File getElementAt(int index) {
- return directories.elementAt(index);
- }
- }
-
- //
// Renderer for Types ComboBox
//
protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
return new FilterComboBoxRenderer();
}
/**
* Render different type sizes and styles.
*/
- @SuppressWarnings("serial") // Superclass is not serializable across versions
public class FilterComboBoxRenderer extends DefaultListCellRenderer {
public Component getListCellRendererComponent(JList<?> list,
Object value, int index, boolean isSelected,
boolean cellHasFocus) {
--- 1216,1234 ----
*** 1277,1300 ****
if (!e.getValueIsAdjusting() && f != null && !getFileChooser().isTraversable(f)) {
setFileName(fileNameString(f));
}
}
- /**
- * Acts when DirectoryComboBox has changed the selected item.
- */
- protected class DirectoryComboBoxAction implements ActionListener {
-
-
-
-
- public void actionPerformed(ActionEvent e) {
- File f = (File)directoryComboBox.getSelectedItem();
- getFileChooser().setCurrentDirectory(f);
- }
- }
-
protected JButton getApproveButton(JFileChooser fc) {
return approveButton;
}
public FileView getFileView(JFileChooser fc) {
--- 1326,1335 ----
*** 1320,1325 ****
--- 1355,1920 ----
}
cacheIcon(f, icon);
return icon;
}
}
+
+ public static class WindowsFileListUI extends BasicListUI {
+
+ public static final Color ITEM_SELECTED_COLOR = new Color(204, 232, 255);
+ public static final Color ITEM_HOVERED_COLOR = new Color(229, 243, 255);
+ public static final Color ITEM_SELECTED_UNFOCUSED_COLOR = new Color(217, 217, 217);
+ public static final Color ITEM_SELECTED_BORDER_COLOR = new Color(153, 209, 255);
+ public static final Border ITEM_SELECTED_BORDER
+ = new LineBorder(ITEM_SELECTED_BORDER_COLOR);
+
+ public static final String HOVER_CELL_PROPERTY = "WindowsFileListUI.hoverCell";
+ public static final String CELL_WIDTH_PROPERTY = "WindowsFileListUI.cellWidth";
+
+ private Rectangle selectionRectangle;
+ private final JFileChooser fileChooser;
+
+ public WindowsFileListUI(JFileChooser fileChooser) {
+ this.fileChooser = fileChooser;
+ }
+
+ @Override
+ protected void installListeners() {
+ super.installListeners();
+
+ MouseAdapter mouseListener = new MouseAdapter() {
+ @Override
+ public void mouseExited(MouseEvent e) {
+ setHoverCell(-1);
+ }
+
+ @Override
+ public void mouseMoved(MouseEvent e) {
+ int hoverCell = list.locationToIndex(e.getPoint());
+ if (hoverCell != -1 && !list.getCellBounds(
+ hoverCell, hoverCell).contains(e.getPoint())) {
+ hoverCell = -1;
+ }
+ setHoverCell(hoverCell);
+ }
+
+ private void setHoverCell(int hoverCell) {
+ list.putClientProperty(HOVER_CELL_PROPERTY, hoverCell);
+ list.repaint();
+ }
+ private Point press;
+
+ @Override
+ public void mousePressed(MouseEvent e) {
+ press = e.getPoint();
+ }
+
+ @Override
+ public void mouseDragged(MouseEvent e) {
+ if (!fileChooser.isMultiSelectionEnabled()) {
+ return;
+ }
+
+ int x = press.x, y = press.y, w, h;
+
+ if (e.getX() < x) {
+ w = x - e.getX();
+ x -= w;
+ } else {
+ w = e.getX() - x;
+ }
+
+ if (e.getY() < y) {
+ h = y - e.getY();
+ y -= h;
+ } else {
+ h = e.getY() - y;
+ }
+
+ selectionRectangle = new Rectangle(x, y, w, h);
+
+ Set<Integer> toBeSelected = new HashSet<>();
+ for (int i = 0; i < list.getModel().getSize(); i++) {
+ if (list.getCellBounds(i, i).intersects(selectionRectangle)) {
+ toBeSelected.add(i);
+ }
+ }
+ list.getSelectionModel().clearSelection();
+ for (Integer cell : toBeSelected) {
+ list.getSelectionModel().addSelectionInterval(cell, cell);
+ }
+ list.repaint();
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ selectionRectangle = null;
+ list.repaint();
+ }
+
+ };
+
+ list.addMouseListener(mouseListener);
+ list.addMouseMotionListener(mouseListener);
+
+ list.addFocusListener(new FocusListener() {
+ @Override
+ public void focusGained(FocusEvent e) {
+ list.repaint();
+ }
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ list.repaint();
+ }
+
+ });
+ }
+
+ @Override
+ protected void updateLayoutState() {
+ super.updateLayoutState();
+ list.putClientProperty(CELL_WIDTH_PROPERTY, cellWidth);
+ }
+
+ @Override
+ public void paint(Graphics g, JComponent c) {
+ super.paint(g, c);
+
+ if (selectionRectangle != null) {
+ g.setColor(new Color(0, 102, 204, 85));
+ g.fillRect(selectionRectangle.x, selectionRectangle.y,
+ selectionRectangle.width, selectionRectangle.height);
+
+ g.setColor(new Color(0, 128, 255, 204));
+ g.drawRect(selectionRectangle.x, selectionRectangle.y,
+ selectionRectangle.width, selectionRectangle.height);
+ }
+ }
+
+ }
+
+ public static class WindowsFileTableUI extends BasicTableUI {
+
+ public static final Border ITEM_SELECTED_BORDER_LEFT_CELL
+ = new CompoundBorder(
+ new MatteBorder(1, 1, 1, 0, ITEM_SELECTED_BORDER_COLOR),
+ new EmptyBorder(0, 0, 0, 1)
+ );
+
+ public static final Border ITEM_SELECTED_BORDER_MID_CELL
+ = new CompoundBorder(
+ new MatteBorder(1, 0, 1, 0, ITEM_SELECTED_BORDER_COLOR),
+ new EmptyBorder(0, 1, 0, 1)
+ );
+
+
+ public static final Border ITEM_SELECTED_BORDER_RIGHT_CELL
+ = new CompoundBorder(
+ new MatteBorder(1, 0, 1, 1, ITEM_SELECTED_BORDER_COLOR),
+ new EmptyBorder(0, 1, 0, 0)
+ );
+
+ private Rectangle selectionRectangle;
+ private final JFileChooser fileChooser;
+
+ public WindowsFileTableUI(JFileChooser fileChooser) {
+ this.fileChooser = fileChooser;
+ }
+
+ @Override
+ protected void installListeners() {
+ super.installListeners();
+
+ MouseAdapter mouseListener = new MouseAdapter() {
+ @Override
+ public void mouseExited(MouseEvent e) {
+ setHoverCell(-1);
+ }
+
+ @Override
+ public void mouseMoved(MouseEvent e) {
+ int hoverRow = table.rowAtPoint(e.getPoint());
+ if (hoverRow != -1 && !containsIgnoreX(
+ table.getCellRect(hoverRow, 0, true),
+ e.getPoint())) {
+ hoverRow = -1; // outside any row
+ }
+ setHoverCell(hoverRow);
+ }
+
+ private boolean containsIgnoreX(Rectangle rect, Point p) {
+ return p.y >= rect.y && p.y < rect.y + rect.height;
+ }
+
+ private void setHoverCell(int hoverCell) {
+ table.putClientProperty(HOVER_CELL_PROPERTY, hoverCell);
+ table.repaint();
+ }
+
+ private Point press;
+
+ @Override
+ public void mousePressed(MouseEvent e) {
+ press = e.getPoint();
+ }
+
+ @Override
+ public void mouseDragged(MouseEvent e) {
+ if (!fileChooser.isMultiSelectionEnabled()) {
+ return;
+ }
+
+ int x = press.x, y = press.y, w, h;
+
+ if (e.getX() < x) {
+ w = x - e.getX();
+ x -= w;
+ } else {
+ w = e.getX() - x;
+ }
+
+ if (e.getY() < y) {
+ h = y - e.getY();
+ y -= h;
+ } else {
+ h = e.getY() - y;
+ }
+
+ Rectangle rect = selectionRectangle == null ? new Rectangle()
+ : new Rectangle(selectionRectangle);
+ selectionRectangle = new Rectangle(x, y, w, h);
+
+ Rectangle union = selectionRectangle.union(rect);
+ union.x--;
+ union.y--;
+ union.width += 2;
+ union.height += 2;
+ table.paintImmediately(union);
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ selectionRectangle = null;
+ table.repaint();
+ }
+
+ };
+ table.addMouseListener(mouseListener);
+ table.addMouseMotionListener(mouseListener);
+
+ table.putClientProperty("FileChooser.supportsFileDrop", TRUE);
+ table.putClientProperty("FileChooser.instance", fileChooser);
+ table.putClientProperty("Table.noOutsideChecking", TRUE);
+ table.putClientProperty("Table.showWholeRowAsDropTarget", TRUE);
+ table.putClientProperty("BasicTableUI.cellWidthHack", Boolean.TRUE);
+
+ table.setDropMode(DropMode.ON);
+ }
+
+ @Override
+ public void paint(Graphics g, JComponent c) {
+ super.paint(g, c);
+
+ if (selectionRectangle != null) {
+ g.setColor(new Color(0, 102, 204, 85));
+ g.fillRect(selectionRectangle.x, selectionRectangle.y,
+ selectionRectangle.width, selectionRectangle.height);
+
+ g.setColor(new Color(0, 128, 255, 204));
+ g.drawRect(selectionRectangle.x, selectionRectangle.y,
+ selectionRectangle.width, selectionRectangle.height);
+ }
+ }
+ }
+
+ private static Image initBackArrowImage() {
+ BufferedImage img = new BufferedImage(12, 12, 6);
+ img.setRGB(0, 4, 16777216);
+ img.setRGB(0, 5, 1476395008);
+ img.setRGB(0, 6, 1409286144);
+ img.setRGB(0, 7, 16777216);
+ img.setRGB(1, 3, 16777216);
+ img.setRGB(1, 4, 1476395008);
+ img.setRGB(1, 5, 2130706432);
+ img.setRGB(1, 6, 2130706432);
+ img.setRGB(1, 7, 1409286144);
+ img.setRGB(1, 8, 16777216);
+ img.setRGB(2, 2, 16777216);
+ img.setRGB(2, 3, 1476395008);
+ img.setRGB(2, 4, 2130706432);
+ img.setRGB(2, 5, 2130706432);
+ img.setRGB(2, 6, 2130706432);
+ img.setRGB(2, 7, 2130706432);
+ img.setRGB(2, 8, 1409286144);
+ img.setRGB(2, 9, 16777216);
+ img.setRGB(3, 1, 16777216);
+ img.setRGB(3, 2, 1476395008);
+ img.setRGB(3, 3, 2130706432);
+ img.setRGB(3, 4, 1459617792);
+ img.setRGB(3, 5, 2130706432);
+ img.setRGB(3, 6, 2130706432);
+ img.setRGB(3, 7, 1509949440);
+ img.setRGB(3, 8, 2130706432);
+ img.setRGB(3, 9, 1409286144);
+ img.setRGB(3, 10, 16777216);
+ img.setRGB(4, 0, 16777216);
+ img.setRGB(4, 1, 1476395008);
+ img.setRGB(4, 2, 2130706432);
+ img.setRGB(4, 3, 1459617792);
+ img.setRGB(4, 4, 16777216);
+ img.setRGB(4, 5, 2130706432);
+ img.setRGB(4, 6, 2130706432);
+ img.setRGB(4, 7, 16777216);
+ img.setRGB(4, 8, 1509949440);
+ img.setRGB(4, 9, 2130706432);
+ img.setRGB(4, 10, 1409286144);
+ img.setRGB(4, 11, 16777216);
+ img.setRGB(5, 0, 452984832);
+ img.setRGB(5, 1, 2130706432);
+ img.setRGB(5, 2, 1459617792);
+ img.setRGB(5, 3, 16777216);
+ img.setRGB(5, 5, 2130706432);
+ img.setRGB(5, 6, 2130706432);
+ img.setRGB(5, 8, 16777216);
+ img.setRGB(5, 9, 1509949440);
+ img.setRGB(5, 10, 2130706432);
+ img.setRGB(5, 11, 402653184);
+ img.setRGB(6, 1, 469762048);
+ img.setRGB(6, 2, 16777216);
+ img.setRGB(6, 5, 2130706432);
+ img.setRGB(6, 6, 2130706432);
+ img.setRGB(6, 9, 16777216);
+ img.setRGB(6, 10, 419430400);
+ img.setRGB(7, 5, 2130706432);
+ img.setRGB(7, 6, 2130706432);
+ img.setRGB(8, 5, 2130706432);
+ img.setRGB(8, 6, 2130706432);
+ img.setRGB(9, 5, 2130706432);
+ img.setRGB(9, 6, 2130706432);
+ img.setRGB(10, 5, 2130706432);
+ img.setRGB(10, 6, 2130706432);
+ img.setRGB(11, 5, 2130706432);
+ img.setRGB(11, 6, 2130706432);
+ return img;
+ }
+
+ private static Image initForwardArrowImage() {
+ BufferedImage img = new BufferedImage(12, 12, 6);
+ img.setRGB(0, 5, 2130706432);
+ img.setRGB(0, 6, 2130706432);
+ img.setRGB(1, 5, 2130706432);
+ img.setRGB(1, 6, 2130706432);
+ img.setRGB(2, 5, 2130706432);
+ img.setRGB(2, 6, 2130706432);
+ img.setRGB(3, 5, 2130706432);
+ img.setRGB(3, 6, 2130706432);
+ img.setRGB(4, 5, 2130706432);
+ img.setRGB(4, 6, 2130706432);
+ img.setRGB(5, 1, 452984832);
+ img.setRGB(5, 2, 16777216);
+ img.setRGB(5, 5, 2130706432);
+ img.setRGB(5, 6, 2130706432);
+ img.setRGB(5, 9, 16777216);
+ img.setRGB(5, 10, 419430400);
+ img.setRGB(6, 0, 452984832);
+ img.setRGB(6, 1, 2130706432);
+ img.setRGB(6, 2, 1442840576);
+ img.setRGB(6, 3, 16777216);
+ img.setRGB(6, 5, 2130706432);
+ img.setRGB(6, 6, 2130706432);
+ img.setRGB(6, 8, 16777216);
+ img.setRGB(6, 9, 1509949440);
+ img.setRGB(6, 10, 2130706432);
+ img.setRGB(6, 11, 402653184);
+ img.setRGB(7, 0, 16777216);
+ img.setRGB(7, 1, 1476395008);
+ img.setRGB(7, 2, 2130706432);
+ img.setRGB(7, 3, 1442840576);
+ img.setRGB(7, 4, 16777216);
+ img.setRGB(7, 5, 2130706432);
+ img.setRGB(7, 6, 2130706432);
+ img.setRGB(7, 7, 16777216);
+ img.setRGB(7, 8, 1509949440);
+ img.setRGB(7, 9, 2130706432);
+ img.setRGB(7, 10, 1392508928);
+ img.setRGB(7, 11, 16777216);
+ img.setRGB(8, 1, 16777216);
+ img.setRGB(8, 2, 1476395008);
+ img.setRGB(8, 3, 2130706432);
+ img.setRGB(8, 4, 1442840576);
+ img.setRGB(8, 5, 2130706432);
+ img.setRGB(8, 6, 2130706432);
+ img.setRGB(8, 7, 1509949440);
+ img.setRGB(8, 8, 2130706432);
+ img.setRGB(8, 9, 1409286144);
+ img.setRGB(8, 10, 16777216);
+ img.setRGB(9, 2, 16777216);
+ img.setRGB(9, 3, 1476395008);
+ img.setRGB(9, 4, 2130706432);
+ img.setRGB(9, 5, 2130706432);
+ img.setRGB(9, 6, 2130706432);
+ img.setRGB(9, 7, 2130706432);
+ img.setRGB(9, 8, 1409286144);
+ img.setRGB(9, 9, 16777216);
+ img.setRGB(10, 3, 16777216);
+ img.setRGB(10, 4, 1476395008);
+ img.setRGB(10, 5, 2130706432);
+ img.setRGB(10, 6, 2130706432);
+ img.setRGB(10, 7, 1409286144);
+ img.setRGB(10, 8, 16777216);
+ img.setRGB(11, 4, 16777216);
+ img.setRGB(11, 5, 1476395008);
+ img.setRGB(11, 6, 1409286144);
+ img.setRGB(11, 7, 16777216);
+ return img;
+ }
+
+ private static Image initUpArrowImage() {
+ BufferedImage img = new BufferedImage(12, 13, 6);
+ img.setRGB(0, 5, 167772160);
+ img.setRGB(0, 6, 1325400064);
+ img.setRGB(0, 7, 117440512);
+ img.setRGB(1, 4, 167772160);
+ img.setRGB(1, 5, 1778384896);
+ img.setRGB(1, 6, 2130706432);
+ img.setRGB(1, 7, 1308622848);
+ img.setRGB(2, 3, 167772160);
+ img.setRGB(2, 4, 1778384896);
+ img.setRGB(2, 5, 2130706432);
+ img.setRGB(2, 6, 1778384896);
+ img.setRGB(2, 7, 167772160);
+ img.setRGB(3, 2, 167772160);
+ img.setRGB(3, 3, 1778384896);
+ img.setRGB(3, 4, 2130706432);
+ img.setRGB(3, 5, 1778384896);
+ img.setRGB(3, 6, 167772160);
+ img.setRGB(4, 1, 167772160);
+ img.setRGB(4, 2, 1778384896);
+ img.setRGB(4, 3, 2130706432);
+ img.setRGB(4, 4, 1778384896);
+ img.setRGB(4, 5, 167772160);
+ img.setRGB(5, 0, 167772160);
+ img.setRGB(5, 1, 1778384896);
+ img.setRGB(5, 2, 2130706432);
+ img.setRGB(5, 3, 2130706432);
+ img.setRGB(5, 4, 2130706432);
+ img.setRGB(5, 5, 2130706432);
+ img.setRGB(5, 6, 2130706432);
+ img.setRGB(5, 7, 2130706432);
+ img.setRGB(5, 8, 2130706432);
+ img.setRGB(5, 9, 2130706432);
+ img.setRGB(5, 10, 2130706432);
+ img.setRGB(5, 11, 2130706432);
+ img.setRGB(5, 12, 2130706432);
+ img.setRGB(6, 0, 167772160);
+ img.setRGB(6, 1, 1778384896);
+ img.setRGB(6, 2, 2130706432);
+ img.setRGB(6, 3, 2130706432);
+ img.setRGB(6, 4, 2130706432);
+ img.setRGB(6, 5, 2130706432);
+ img.setRGB(6, 6, 2130706432);
+ img.setRGB(6, 7, 2130706432);
+ img.setRGB(6, 8, 2130706432);
+ img.setRGB(6, 9, 2130706432);
+ img.setRGB(6, 10, 2130706432);
+ img.setRGB(6, 11, 2130706432);
+ img.setRGB(6, 12, 2130706432);
+ img.setRGB(7, 1, 184549376);
+ img.setRGB(7, 2, 1778384896);
+ img.setRGB(7, 3, 2130706432);
+ img.setRGB(7, 4, 1761607680);
+ img.setRGB(7, 5, 167772160);
+ img.setRGB(8, 2, 184549376);
+ img.setRGB(8, 3, 1778384896);
+ img.setRGB(8, 4, 2130706432);
+ img.setRGB(8, 5, 1744830464);
+ img.setRGB(8, 6, 167772160);
+ img.setRGB(9, 3, 184549376);
+ img.setRGB(9, 4, 1795162112);
+ img.setRGB(9, 5, 2130706432);
+ img.setRGB(9, 6, 1728053248);
+ img.setRGB(9, 7, 150994944);
+ img.setRGB(10, 4, 201326592);
+ img.setRGB(10, 5, 1795162112);
+ img.setRGB(10, 6, 2130706432);
+ img.setRGB(10, 7, 1258291200);
+ img.setRGB(11, 5, 201326592);
+ img.setRGB(11, 6, 1308622848);
+ img.setRGB(11, 7, 83886080);
+ return img;
+ }
+
+ private static Image initRefreshImage() {
+ BufferedImage img = new BufferedImage(10, 11, 6);
+ img.setRGB(0, 3, 385875968);
+ img.setRGB(0, 4, 1325400064);
+ img.setRGB(0, 5, 1778384896);
+ img.setRGB(0, 6, 1761607680);
+ img.setRGB(0, 7, 1308622848);
+ img.setRGB(0, 8, 369098752);
+ img.setRGB(1, 0, 2130706432);
+ img.setRGB(1, 1, 989855744);
+ img.setRGB(1, 2, 805306368);
+ img.setRGB(1, 3, 2097152000);
+ img.setRGB(1, 4, 2130706432);
+ img.setRGB(1, 5, 2013265920);
+ img.setRGB(1, 6, 1996488704);
+ img.setRGB(1, 7, 2130706432);
+ img.setRGB(1, 8, 2080374784);
+ img.setRGB(1, 9, 788529152);
+ img.setRGB(2, 0, 2130706432);
+ img.setRGB(2, 1, 1191182336);
+ img.setRGB(2, 2, 2097152000);
+ img.setRGB(2, 3, 1962934272);
+ img.setRGB(2, 4, 620756992);
+ img.setRGB(2, 7, 603979776);
+ img.setRGB(2, 8, 1979711488);
+ img.setRGB(2, 9, 2097152000);
+ img.setRGB(2, 10, 352321536);
+ img.setRGB(3, 0, 2130706432);
+ img.setRGB(3, 1, 1660944384);
+ img.setRGB(3, 2, 2130706432);
+ img.setRGB(3, 3, 637534208);
+ img.setRGB(3, 8, 687865856);
+ img.setRGB(3, 9, 2130706432);
+ img.setRGB(3, 10, 1308622848);
+ img.setRGB(4, 0, 2130706432);
+ img.setRGB(4, 1, 2097152000);
+ img.setRGB(4, 2, 1996488704);
+ img.setRGB(4, 3, 1006632960);
+ img.setRGB(4, 4, 1006632960);
+ img.setRGB(4, 9, 1996488704);
+ img.setRGB(4, 10, 1761607680);
+ img.setRGB(5, 0, 2130706432);
+ img.setRGB(5, 1, 2130706432);
+ img.setRGB(5, 2, 2130706432);
+ img.setRGB(5, 3, 2130706432);
+ img.setRGB(5, 4, 2130706432);
+ img.setRGB(5, 9, 1996488704);
+ img.setRGB(5, 10, 1761607680);
+ img.setRGB(6, 8, 687865856);
+ img.setRGB(6, 9, 2130706432);
+ img.setRGB(6, 10, 1308622848);
+ img.setRGB(7, 3, 587202560);
+ img.setRGB(7, 4, 603979776);
+ img.setRGB(7, 7, 603979776);
+ img.setRGB(7, 8, 1979711488);
+ img.setRGB(7, 9, 2097152000);
+ img.setRGB(7, 10, 369098752);
+ img.setRGB(8, 2, 150994944);
+ img.setRGB(8, 3, 1996488704);
+ img.setRGB(8, 4, 2130706432);
+ img.setRGB(8, 5, 1996488704);
+ img.setRGB(8, 6, 1996488704);
+ img.setRGB(8, 7, 2130706432);
+ img.setRGB(8, 8, 2080374784);
+ img.setRGB(8, 9, 788529152);
+ img.setRGB(9, 3, 369098752);
+ img.setRGB(9, 4, 1325400064);
+ img.setRGB(9, 5, 1778384896);
+ img.setRGB(9, 6, 1761607680);
+ img.setRGB(9, 7, 1308622848);
+ img.setRGB(9, 8, 369098752);
+ return img;
+ }
}
< prev index next >