⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicfilechooserui.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* BasicFileChooserUI.java --   Copyright (C) 2005  Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.swing.plaf.basic;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Component;import java.awt.Dimension;import java.awt.Graphics;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Point;import java.awt.Polygon;import java.awt.Window;import java.awt.event.ActionEvent;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.io.File;import java.io.IOException;import java.util.ArrayList;import java.util.Hashtable;import javax.swing.AbstractAction;import javax.swing.Action;import javax.swing.ButtonGroup;import javax.swing.Icon;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JComponent;import javax.swing.JDialog;import javax.swing.JFileChooser;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextField;import javax.swing.JToggleButton;import javax.swing.ListCellRenderer;import javax.swing.SwingConstants;import javax.swing.SwingUtilities;import javax.swing.Timer;import javax.swing.UIManager;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import javax.swing.filechooser.FileFilter;import javax.swing.filechooser.FileSystemView;import javax.swing.filechooser.FileView;import javax.swing.plaf.ComponentUI;import javax.swing.plaf.FileChooserUI;/** * A UI delegate for the {@link JFileChooser} component under the  * {@link BasicLookAndFeel}. */public class BasicFileChooserUI extends FileChooserUI{  /**   * A file filter that accepts all files.   */  protected class AcceptAllFileFilter extends FileFilter  {    /**     * Creates a new instance.     */    public AcceptAllFileFilter()    {      // Nothing to do here.    }        /**     * Returns <code>true</code> always, as all files are accepted by this     * filter.     *     * @param f  the file.     *     * @return Always <code>true</code>.     */    public boolean accept(File f)    {      return true;    }    /**     * Returns a description for this filter.     *     * @return A description for the file filter.     */    public String getDescription()    {      return acceptAllFileFilterText;    }  }  /**   * Handles a user action to approve the dialog selection.   *    * @see BasicFileChooserUI#getApproveSelectionAction()   */  protected class ApproveSelectionAction extends AbstractAction  {    /**     * Creates a new ApproveSelectionAction object.     */    protected ApproveSelectionAction()    {      // Nothing to do here.    }    /**     * Sets the current selection and closes the dialog.     *      * @param e  the action event.     */    public void actionPerformed(ActionEvent e)    {      Object obj = new String(parentPath + entry.getText());      if (obj != null)        {          File f = filechooser.getFileSystemView().createFileObject(                                                                    obj.toString());          if (filechooser.isTraversable(f)              && filechooser.isDirectorySelectionEnabled())            filechooser.setCurrentDirectory(f);          else            {              filechooser.setSelectedFile(f);              filechooser.approveSelection();              closeDialog();            }        }    }  }  /**   * Provides presentation information about files and directories.   */  protected class BasicFileView extends FileView  {    /** Storage for cached icons. */    protected Hashtable iconCache = new Hashtable();    /**     * Creates a new instance.     */    public BasicFileView()    {      // Nothing to do here.    }    /**     * Adds an icon to the cache, associating it with the given file/directory.     *     * @param f  the file/directory.     * @param i  the icon.     */    public void cacheIcon(File f, Icon i)    {      iconCache.put(f, i);    }    /**     * Clears the icon cache.     */    public void clearIconCache()    {      iconCache.clear();    }    /**     * Retrieves the icon associated with the specified file/directory, if      * there is one.     *     * @param f  the file/directory.     *     * @return The cached icon (or <code>null</code>).     */    public Icon getCachedIcon(File f)    {      return (Icon) iconCache.get(f);    }    /**     * Returns a description of the given file/directory.  In this      * implementation, the description is the same as the name returned by      * {@link #getName(File)}.     *     * @param f  the file/directory.     *     * @return A description of the given file/directory.     */    public String getDescription(File f)    {      return getName(f);    }    /**     * Returns an icon appropriate for the given file or directory.     *     * @param f  the file/directory.     *     * @return An icon.     */    public Icon getIcon(File f)    {      Icon val = getCachedIcon(f);      if (val != null)	return val;      if (filechooser.isTraversable(f))	val = directoryIcon;      else	val = fileIcon;      cacheIcon(f, val);      return val;    }    /**     * Returns the name for the given file/directory.     *     * @param f  the file/directory.     *     * @return The name of the file/directory.     */    public String getName(File f)    {      return f.getName();    }    /**     * Returns a localised description for the type of file/directory.     *     * @param f  the file/directory.     *     * @return A type description for the given file/directory.     */    public String getTypeDescription(File f)    {      if (filechooser.isTraversable(f))	return dirDescText;      else	return fileDescText;    }    /**     * Returns {@link Boolean#TRUE} if the given file/directory is hidden,     * and {@link Boolean#FALSE} otherwise.     *     * @param f  the file/directory.     *     * @return {@link Boolean#TRUE} or {@link Boolean#FALSE}.     */    public Boolean isHidden(File f)    {      return Boolean.valueOf(filechooser.getFileSystemView().isHiddenFile(f));    }  }  /**   * Handles an action to cancel the file chooser.   *    * @see BasicFileChooserUI#getCancelSelectionAction()   */  protected class CancelSelectionAction extends AbstractAction  {    /**     * Creates a new <code>CancelSelectionAction</code> object.     */    protected CancelSelectionAction()    {      // Nothing to do here.    }    /**     * Cancels the selection and closes the dialog.     *     * @param e  the action event (ignored).     */    public void actionPerformed(ActionEvent e)    {      filechooser.cancelSelection();      closeDialog();    }  }  /**   * An action to handle changes to the parent directory (for example, via   * a click on the "up folder" button).   *    * @see BasicFileChooserUI#getChangeToParentDirectoryAction()   */  protected class ChangeToParentDirectoryAction extends AbstractAction  {    /**     * Creates a new <code>ChangeToParentDirectoryAction</code> object.     */    protected ChangeToParentDirectoryAction()    {      // Nothing to do here.    }    /**     * Handles the action event.     *     * @param e  the action event.     */    public void actionPerformed(ActionEvent e)    {      filechooser.changeToParentDirectory();      filechooser.revalidate();      filechooser.repaint();    }  }  /**   * A mouse listener that handles double-click events.   *    * @see BasicFileChooserUI#createDoubleClickListener(JFileChooser, JList)   */  protected class DoubleClickListener extends MouseAdapter  {    /** A timer. */    private Timer timer = null;    /** DOCUMENT ME! */    private Object lastSelected = null;    /** DOCUMENT ME! */    private JList list = null;    /**     * Creates a new DoubleClickListener object.     *     * @param list DOCUMENT ME!     */    public DoubleClickListener(JList list)    {      this.list = list;      timer = new Timer(1000, null);      timer.setRepeats(false);      lastSelected = list.getSelectedValue();      setDirectorySelected(false);    }    /**     * Handles a mouse click event.     *      * @param e  the event.     */    public void mouseClicked(MouseEvent e)    {      if (list.getSelectedValue() == null)        return;      FileSystemView fsv = filechooser.getFileSystemView();      if (timer.isRunning()          && list.getSelectedValue().toString().equals(lastSelected.toString()))        {          File f = fsv.createFileObject(lastSelected.toString());          timer.stop();          if (filechooser.isTraversable(f))            {              filechooser.setCurrentDirectory(f);              filechooser.rescanCurrentDirectory();            }          else            {              filechooser.setSelectedFile(f);              filechooser.approveSelection();              closeDialog();            }        }      else        {          String path = list.getSelectedValue().toString();          File f = fsv.createFileObject(path);          if (filechooser.isTraversable(f))            {              setDirectorySelected(true);              setDirectory(f);            }          else            {              setDirectorySelected(false);              setDirectory(null);            }          lastSelected = path;          parentPath = path.substring(0, path.lastIndexOf("/") + 1);          entry.setText(path.substring(path.lastIndexOf("/") + 1));          timer.restart();        }    }    /**     * Handles a mouse entered event (NOT IMPLEMENTED).     *      * @param e  the mouse event.     */    public void mouseEntered(MouseEvent e)    {      // FIXME: Implement    }  }  /**   * An action that changes the file chooser to display the user's home    * directory.    *    * @see BasicFileChooserUI#getGoHomeAction()   */  protected class GoHomeAction extends AbstractAction  {    /**     * Creates a new <code>GoHomeAction</code> object.     */    protected GoHomeAction()    {      // Nothing to do here.    }    /**     * 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()    {      // Nothing to do here.    }    /**     * Handles the event by creating a new folder.     *     * @param e  the action event (ignored).     */    public void actionPerformed(ActionEvent e)    {      try

⌨️ 快捷键说明

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