basicfilechooserui.java

来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 1,414 行 · 第 1/3 页

JAVA
1,414
字号
    /**     * Sets the directory to the user's home directory, and repaints the     * file chooser component.     *     * @param e  the action event (ignored).     */    public void actionPerformed(ActionEvent e)    {      filechooser.setCurrentDirectory(filechooser.getFileSystemView()                                                 .getHomeDirectory());      filechooser.revalidate();      filechooser.repaint();    }  }  /**   * An action that handles the creation of a new folder/directory.   *    * @see BasicFileChooserUI#getNewFolderAction()   */  protected class NewFolderAction extends AbstractAction  {    /**     * Creates a new <code>NewFolderAction</code> object.     */    protected NewFolderAction()    {      super("New Folder");    }    /**     * Handles the event by creating a new folder.     *     * @param e  the action event (ignored).     */    public void actionPerformed(ActionEvent e)    {      try        {	  filechooser.getFileSystemView().createNewFolder(filechooser	                                                  .getCurrentDirectory());        }      catch (IOException ioe)        {	  return;        }      filechooser.rescanCurrentDirectory();      filechooser.repaint();    }  }  /**   * A listener for selection events in the file list.   *    * @see BasicFileChooserUI#createListSelectionListener(JFileChooser)   */  protected class SelectionListener implements ListSelectionListener  {    /**     * Creates a new <code>SelectionListener</code> object.     */    protected SelectionListener()    {      // Nothing to do here.    }    /**     * DOCUMENT ME!     *     * @param e DOCUMENT ME!     */    public void valueChanged(ListSelectionEvent e)    {      JList list = (JList) e.getSource();      Object f = list.getSelectedValue();      if (f == null)	return;      File file = filechooser.getFileSystemView().createFileObject(f.toString());      if (! filechooser.isTraversable(file))	filechooser.setSelectedFile(file);      else	filechooser.setSelectedFile(null);    }  }  /**   * DOCUMENT ME!   *    * @see BasicFileChooserUI#getUpdateAction()   */  protected class UpdateAction extends AbstractAction  {    /**     * Creates a new UpdateAction object.     */    protected UpdateAction()    {      super(null);    }    /**     * NOT YET IMPLEMENTED.     *     * @param e  the action event.     */    public void actionPerformed(ActionEvent e)    {      // FIXME: implement this    }  }  /** The localised mnemonic for the cancel button. */  protected int cancelButtonMnemonic;  /** The localised text for the cancel button. */  protected String cancelButtonText;  /** The localised tool tip text for the cancel button. */  protected String cancelButtonToolTipText;  /** An icon representing a computer. */  protected Icon computerIcon;  /** An icon for the "details view" button. */  protected Icon detailsViewIcon;  /** An icon representing a directory. */  protected Icon directoryIcon;  /** The localised Mnemonic for the open button. */  protected int directoryOpenButtonMnemonic;  /** The localised text for the open button. */  protected String directoryOpenButtonText;  /** The localised tool tip text for the open button. */  protected String directoryOpenButtonToolTipText;  /** An icon representing a file. */  protected Icon fileIcon;  /** An icon representing a floppy drive. */  protected Icon floppyDriveIcon;  /** An icon representing a hard drive. */  protected Icon hardDriveIcon;  /** The localised mnemonic for the "help" button. */  protected int helpButtonMnemonic;  /** The localised text for the "help" button. */  protected String helpButtonText;  /** The localised tool tip text for the help button. */  protected String helpButtonToolTipText;  /** An icon representing the user's home folder. */  protected Icon homeFolderIcon;  /** An icon for the "list view" button. */  protected Icon listViewIcon;  /** An icon for the "new folder" button. */  protected Icon newFolderIcon = directoryIcon;  /** The localised mnemonic for the "open" button. */  protected int openButtonMnemonic;  /** The localised text for the "open" button. */  protected String openButtonText;  /** The localised tool tip text for the "open" button. */  protected String openButtonToolTipText;  /** The localised mnemonic for the "save" button. */  protected int saveButtonMnemonic;  /** The localised text for the "save" button. */  protected String saveButtonText;  /** The localised tool tip text for the save button. */  protected String saveButtonToolTipText;  /** The localised mnemonic for the "update" button. */  protected int updateButtonMnemonic;  /** The localised text for the "update" button. */  protected String updateButtonText;  /** The localised tool tip text for the "update" button. */  protected String updateButtonToolTipText;  /** An icon for the "up folder" button. */  protected Icon upFolderIcon;  // -- begin private, but package local since used in inner classes --  /** The file chooser component represented by this UI delegate. */  JFileChooser filechooser;  /** The model for the directory list. */  BasicDirectoryModel model;  /** The file filter for all files. */  FileFilter acceptAll = new AcceptAllFileFilter();  /** The default file view. */  FileView fv = new BasicFileView();  /** The accept (open/save) button. */  JButton accept;  /** An optional accessory panel. */  JPanel accessoryPanel = new JPanel();  /** A property change listener. */  PropertyChangeListener propertyChangeListener;  /** The text describing the filter for "all files". */  String acceptAllFileFilterText;  /** The text describing a directory type. */  String dirDescText;  /** The text describing a file type. */  String fileDescText;  /** Is a directory selected? */  boolean dirSelected = false;  /** The current directory. */  File currDir = null;  // FIXME: describe what is contained in the bottom panel  /** The bottom panel. */  JPanel bottomPanel;    /** The close panel. */  JPanel closePanel;  /** Text box that displays file name */  JTextField entry;      /** Current parent path */  String parentPath;    /**   * The action for the 'approve' button.   * @see #getApproveSelectionAction()   */  private ApproveSelectionAction approveSelectionAction;    /**   * The action for the 'cancel' button.   * @see #getCancelSelectionAction()   */  private CancelSelectionAction cancelSelectionAction;    /**   * The action for the 'go home' control button.   * @see #getGoHomeAction()   */  private GoHomeAction goHomeAction;    /**   * The action for the 'up folder' control button.   * @see #getChangeToParentDirectoryAction()   */  private ChangeToParentDirectoryAction changeToParentDirectoryAction;    /**   * The action for the 'new folder' control button.   * @see #getNewFolderAction()   */  private NewFolderAction newFolderAction;    /**   * The action for ???.  // FIXME: what is this?   * @see #getUpdateAction()   */  private UpdateAction updateAction;    // -- end private --  /**   * Closes the dialog.   */  void closeDialog()  {    Window owner = SwingUtilities.windowForComponent(filechooser);    if (owner instanceof JDialog)      ((JDialog) owner).dispose();  }  /**   * Creates a new <code>BasicFileChooserUI</code> object.   *   * @param b  the file chooser component.   */  public BasicFileChooserUI(JFileChooser b)  {  }  /**   * Returns a UI delegate for the given component.   *   * @param c  the component (should be a {@link JFileChooser}).   *   * @return A new UI delegate.   */  public static ComponentUI createUI(JComponent c)  {    return new BasicFileChooserUI((JFileChooser) c);  }  /**   * Installs the UI for the specified component.   *    * @param c  the component (should be a {@link JFileChooser}).   */  public void installUI(JComponent c)  {    if (c instanceof JFileChooser)      {        JFileChooser fc = (JFileChooser) c;        this.filechooser = fc;        fc.resetChoosableFileFilters();        createModel();        clearIconCache();        installDefaults(fc);        installComponents(fc);        installListeners(fc);                Object path = filechooser.getCurrentDirectory();        if (path != null)          parentPath = path.toString().substring(path.toString().lastIndexOf("/"));      }  }  /**   * Uninstalls this UI from the given component.   *    * @param c  the component (should be a {@link JFileChooser}).   */  public void uninstallUI(JComponent c)  {    model = null;    uninstallListeners(filechooser);    uninstallComponents(filechooser);    uninstallDefaults(filechooser);    filechooser = null;  }  // FIXME: Indent the entries in the combobox  // Made this method package private to access it from within inner classes  // with better performance  void boxEntries()  {    ArrayList parentFiles = new ArrayList();    File parent = filechooser.getCurrentDirectory();    if (parent == null)      parent = filechooser.getFileSystemView().getDefaultDirectory();    while (parent != null)      {        String name = parent.getName();        if (name.equals(""))          name = parent.getAbsolutePath();        parentFiles.add(parentFiles.size(), name);        parent = parent.getParentFile();      }    if (parentFiles.size() == 0)      return;  }    /**   * Creates and install the subcomponents for the file chooser.   *   * @param fc  the file chooser.   */  public void installComponents(JFileChooser fc)  {  }  /**   * Uninstalls the components from the file chooser.   *   * @param fc  the file chooser.   */  public void uninstallComponents(JFileChooser fc)  {  }  /**   * Installs the listeners required by this UI delegate.   *   * @param fc  the file chooser.   */  protected void installListeners(JFileChooser fc)  {    propertyChangeListener = createPropertyChangeListener(filechooser);    filechooser.addPropertyChangeListener(propertyChangeListener);  }  /**   * Uninstalls the listeners previously installed by this UI delegate.   *   * @param fc  the file chooser.   */  protected void uninstallListeners(JFileChooser fc)  {    filechooser.removePropertyChangeListener(propertyChangeListener);    propertyChangeListener = null;  }  /**   * Installs the defaults for this UI delegate.   *   * @param fc  the file chooser.   */  protected void installDefaults(JFileChooser fc)  {    installIcons(fc);    installStrings(fc);  }  /**   * Uninstalls the defaults previously added by this UI delegate.   *   * @param fc  the file chooser.   */  protected void uninstallDefaults(JFileChooser fc)  {    uninstallStrings(fc);    uninstallIcons(fc);  }  /**   * Installs the icons for this UI delegate.   *   * @param fc  the file chooser (ignored).   */  protected void installIcons(JFileChooser fc)  {    UIDefaults defaults = UIManager.getLookAndFeelDefaults();    computerIcon = MetalIconFactory.getTreeComputerIcon();    detailsViewIcon = defaults.getIcon("FileChooser.detailsViewIcon");    directoryIcon = new MetalIconFactory.TreeFolderIcon();    fileIcon = new MetalIconFactory.TreeLeafIcon();    floppyDriveIcon = MetalIconFactory.getTreeFloppyDriveIcon();    hardDriveIcon = MetalIconFactory.getTreeHardDriveIcon();    homeFolderIcon = defaults.getIcon("FileChooser.homeFolderIcon");    listViewIcon = defaults.getIcon("FileChooser.listViewIcon");    newFolderIcon = defaults.getIcon("FileChooser.newFolderIcon");    upFolderIcon = defaults.getIcon("FileChooser.upFolderIcon");  }  /**   * Uninstalls the icons previously added by this UI delegate.   *   * @param fc  the file chooser.   */  protected void uninstallIcons(JFileChooser fc)  {    computerIcon = null;    detailsViewIcon = null;    directoryIcon = null;    fileIcon = null;    floppyDriveIcon = null;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?