gtkfilechooserui.java
来自「JAVA 所有包」· Java 代码 · 共 1,363 行 · 第 1/4 页
JAVA
1,363 行
/* * @(#)GTKFileChooserUI.java 1.41 06/11/30 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.java.swing.plaf.gtk;import java.awt.*;import java.awt.event.*;import java.beans.*;import java.io.File;import java.io.FileNotFoundException;import java.io.IOException;import java.text.MessageFormat;import java.util.*;import javax.swing.plaf.synth.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.filechooser.*;import javax.swing.event.*;import javax.swing.plaf.*;import javax.swing.plaf.basic.BasicDirectoryModel;import javax.swing.table.*;import javax.accessibility.*;import sun.swing.SwingUtilities2;import sun.swing.plaf.synth.*;import sun.swing.FilePane;import sun.swing.DefaultLookup;import sun.awt.shell.ShellFolder;/** * GTK FileChooserUI. * * @version 1.36 08/21/02 * @author Leif Samuelsson * @author Jeff Dinkins */class GTKFileChooserUI extends SynthFileChooserUI { // The accessoryPanel is a container to place the JFileChooser accessory component private JPanel accessoryPanel = null; private String newFolderButtonText = null; private String newFolderErrorSeparator = null; private String newFolderErrorText = null; private String newFolderDialogText = null; private String deleteFileButtonText = null; private String renameFileButtonText = null; private String newFolderButtonToolTipText = null; private String deleteFileButtonToolTipText = null; private String renameFileButtonToolTipText = null; private int newFolderButtonMnemonic = 0; private int deleteFileButtonMnemonic = 0; private int renameFileButtonMnemonic = 0; private int foldersLabelMnemonic = 0; private int filesLabelMnemonic = 0; private String renameFileDialogText = null; private String renameFileErrorTitle = null; private String renameFileErrorText = null; private JComboBox filterComboBox; private FilterComboBoxModel filterComboBoxModel; // From Motif private JPanel rightPanel; private JList directoryList; private JList fileList; private JLabel pathField; private JTextField fileNameTextField; private static final Dimension hstrut3 = new Dimension(3, 1); private static final Dimension vstrut10 = new Dimension(1, 10); private static final Insets insets = new Insets(10, 10, 10, 10); private static Dimension prefListSize = new Dimension(75, 150); private static Dimension PREF_SIZE = new Dimension(435, 360); private static Dimension MIN_SIZE = new Dimension(200, 300); private static Dimension PREF_ACC_SIZE = new Dimension(10, 10); private static Dimension ZERO_ACC_SIZE = new Dimension(1, 1); private static Dimension MAX_SIZE = new Dimension(Short.MAX_VALUE, Short.MAX_VALUE); private static final Insets buttonMargin = new Insets(3, 3, 3, 3); private String filesLabelText = null; private String foldersLabelText = null; private String pathLabelText = null; private String filterLabelText = null; private int pathLabelMnemonic = 0; private int filterLabelMnemonic = 0; private JComboBox directoryComboBox; private DirectoryComboBoxModel directoryComboBoxModel; private Action directoryComboBoxAction = new DirectoryComboBoxAction(); private JPanel bottomButtonPanel; private GTKDirectoryModel model = null; private Action newFolderAction; private JPanel interior; private boolean readOnly; private boolean showDirectoryIcons; private boolean showFileIcons; private GTKFileView fileView = new GTKFileView(); private PropertyChangeListener gtkFCPropertyChangeListener; private Action approveSelectionAction = new GTKApproveSelectionAction(); private GTKDirectoryListModel directoryListModel; public GTKFileChooserUI(JFileChooser filechooser) { super(filechooser); } public String getFileName() { JFileChooser fc = getFileChooser(); String typedInName = fileNameTextField != null ? fileNameTextField.getText() : null; if (!fc.isMultiSelectionEnabled()) { return typedInName; } int mode = fc.getFileSelectionMode(); JList list = mode == JFileChooser.DIRECTORIES_ONLY ? directoryList : fileList; Object[] files = list.getSelectedValues(); int len = files.length; Vector result = new Vector(len + 1); // we return all selected file names for (int i = 0; i < len; i++) { File file = (File)files[i]; result.add(file.getName()); } // plus the file name typed into the text field, if not already there if (typedInName != null && !result.contains(typedInName)) { result.add(typedInName); } StringBuffer buf = new StringBuffer(); len = result.size(); // construct the resulting string for (int i=0; i<len; i++) { if (len > 1) { buf.append(" \""); } buf.append(result.get(i)); if (len > 1) { buf.append("\""); } } return buf.toString(); } public void setFileName(String fileName) { if (fileNameTextField != null) { fileNameTextField.setText(fileName); } }// public String getDirectoryName() {// return pathField.getText();// } public void setDirectoryName(String dirname) { pathField.setText(dirname); } public void ensureFileIsVisible(JFileChooser fc, File f) { // PENDING } public void rescanCurrentDirectory(JFileChooser fc) { getModel().validateFileCache(); } public JPanel getAccessoryPanel() { return accessoryPanel; } // *********************** // * FileView operations * // *********************** public FileView getFileView(JFileChooser fc) { return fileView; } private class GTKFileView extends BasicFileView { public GTKFileView() { iconCache = null; } public void clearIconCache() { } public Icon getCachedIcon(File f) { return null; } public void cacheIcon(File f, Icon i) { } public Icon getIcon(File f) { return (f != null && f.isDirectory()) ? directoryIcon : fileIcon; } } private void updateDefaultButton() { JFileChooser filechooser = getFileChooser(); JRootPane root = SwingUtilities.getRootPane(filechooser); if (root == null) { return; } if (filechooser.getControlButtonsAreShown()) { if (root.getDefaultButton() == null) { root.setDefaultButton(getApproveButton(filechooser)); getCancelButton(filechooser).setDefaultCapable(false); } } else { if (root.getDefaultButton() == getApproveButton(filechooser)) { root.setDefaultButton(null); } } } protected void doSelectedFileChanged(PropertyChangeEvent e) { super.doSelectedFileChanged(e); File f = (File) e.getNewValue(); if (f != null) { setFileName(getFileChooser().getName(f)); } } protected void doDirectoryChanged(PropertyChangeEvent e) { directoryList.clearSelection(); ListSelectionModel sm = directoryList.getSelectionModel(); if (sm instanceof DefaultListSelectionModel) { ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0); ((DefaultListSelectionModel)sm).setAnchorSelectionIndex(0); } fileList.clearSelection(); sm = fileList.getSelectionModel(); if (sm instanceof DefaultListSelectionModel) { ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0); ((DefaultListSelectionModel)sm).setAnchorSelectionIndex(0); } File currentDirectory = getFileChooser().getCurrentDirectory(); if (currentDirectory != null) { try { setDirectoryName(ShellFolder.getNormalizedFile((File)e.getNewValue()).getPath()); } catch (IOException ioe) { setDirectoryName(((File)e.getNewValue()).getAbsolutePath()); } if ((getFileChooser().getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) && !getFileChooser().isMultiSelectionEnabled()) { setFileName(pathField.getText()); } directoryComboBoxModel.addItem(currentDirectory); directoryListModel.directoryChanged(); } super.doDirectoryChanged(e); } protected 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); getAccessoryPanel().setPreferredSize(accessory.getPreferredSize()); getAccessoryPanel().setMaximumSize(MAX_SIZE); } else { getAccessoryPanel().setPreferredSize(ZERO_ACC_SIZE); getAccessoryPanel().setMaximumSize(ZERO_ACC_SIZE); } } } protected void doFileSelectionModeChanged(PropertyChangeEvent e) { directoryList.clearSelection(); rightPanel.setVisible(((Integer)e.getNewValue()).intValue() != JFileChooser.DIRECTORIES_ONLY); super.doFileSelectionModeChanged(e); } protected void doMultiSelectionChanged(PropertyChangeEvent e) { if (getFileChooser().isMultiSelectionEnabled()) { fileList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } else { fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fileList.clearSelection(); } super.doMultiSelectionChanged(e); } protected void doControlButtonsChanged(PropertyChangeEvent e) { super.doControlButtonsChanged(e); JFileChooser filechooser = getFileChooser(); if (filechooser.getControlButtonsAreShown()) { filechooser.add(bottomButtonPanel, BorderLayout.SOUTH); } else { filechooser.remove(bottomButtonPanel); } updateDefaultButton(); } protected void doAncestorChanged(PropertyChangeEvent e) { if (e.getOldValue() == null && e.getNewValue() != null) { // Ancestor was added, set initial focus fileNameTextField.selectAll(); fileNameTextField.requestFocus(); updateDefaultButton(); } super.doAncestorChanged(e); } // ******************************************** // ************ Create Listeners ************** // ********************************************
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?