home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.basic;
-
- import com.sun.java.swing.AbstractButton;
- import com.sun.java.swing.Action;
- import com.sun.java.swing.Box;
- import com.sun.java.swing.BoxLayout;
- import com.sun.java.swing.Icon;
- import com.sun.java.swing.JButton;
- import com.sun.java.swing.JComboBox;
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.JLabel;
- import com.sun.java.swing.JPanel;
- import com.sun.java.swing.JTextField;
- import com.sun.java.swing.JToggleButton;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.plaf.ComponentUI;
- import com.sun.java.swing.plaf.FileChooserUI;
- import com.sun.java.swing.preview.DirectoryModel;
- import com.sun.java.swing.preview.JDirectoryPane;
- import com.sun.java.swing.preview.JFileChooser;
- import java.awt.BorderLayout;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.IllegalComponentStateException;
- import java.awt.Insets;
- import java.io.File;
-
- public class BasicFileChooserUI extends FileChooserUI {
- protected BasicDirectoryPaneUI directoryPaneUI;
- protected JPanel centerPanel;
- protected JFileChooser fileChooser;
- protected JDirectoryPane directoryPane;
- protected Component accessory;
- protected Listener listener;
- protected Action goHomeAction = new GoHomeAction(this);
- protected Action mkdirAction = new MkdirAction(this);
- protected Action cancelAction = new CancelAction(this);
- protected Action okayAction = new OkayAction(this);
- protected TypesComboBoxModel typesComboBoxModel;
- private static Dimension PREF_SIZE = new Dimension(500, 300);
- private static Dimension MIN_SIZE = new Dimension(300, 200);
- private JComboBox currentDir;
- private JButton okayButton;
- private JButton cancelButton;
- private JTextField filename;
- private JComboBox types;
- private JPanel bodyPanel;
- private Icon newFolderIcon;
- private Icon upFolderIcon;
- private Icon homeFolderIcon;
- private Icon listViewIcon;
- private Icon detailsViewIcon;
- private static final Dimension hstrut10 = new Dimension(10, 1);
- private static final Dimension hstrut25 = new Dimension(25, 1);
- private static final Dimension vstrut10 = new Dimension(1, 10);
- private static final Insets shrinkwrap = new Insets(0, 0, 0, 0);
-
- public static ComponentUI createUI(JComponent var0) {
- return new BasicFileChooserUI((JFileChooser)var0);
- }
-
- public BasicFileChooserUI(JFileChooser var1) {
- if (this.newFolderIcon == null) {
- this.newFolderIcon = UIManager.getIcon("FileChooser.newFolder");
- this.upFolderIcon = UIManager.getIcon("FileChooser.upFolder");
- this.homeFolderIcon = UIManager.getIcon("FileChooser.homeFolder");
- this.detailsViewIcon = UIManager.getIcon("FileChooser.detailsView");
- this.listViewIcon = UIManager.getIcon("FileChooser.listView");
- }
-
- }
-
- public void installUI(JComponent var1) {
- this.fileChooser = (JFileChooser)var1;
- this.directoryPane = this.fileChooser.getDirectoryPane();
- this.accessory = this.fileChooser.getAccessory();
- this.fileChooser.setLayout(new BoxLayout(this.fileChooser, 1));
- this.fileChooser.add(Box.createRigidArea(vstrut10));
- JPanel var2 = new JPanel();
- ((Container)var2).setLayout(new BoxLayout(var2, 0));
- this.fileChooser.add(var2);
- this.fileChooser.add(Box.createRigidArea(vstrut10));
- JLabel var3 = new JLabel("Look in:");
- ((JComponent)var3).setAlignmentX(0.0F);
- ((JComponent)var3).setAlignmentY(0.5F);
- ((Container)var2).add(Box.createRigidArea(hstrut10));
- ((Container)var2).add(var3);
- ((Container)var2).add(Box.createRigidArea(hstrut25));
- this.currentDir = new JComboBox();
- this.currentDir.setAlignmentX(0.0F);
- this.currentDir.setAlignmentY(0.5F);
- ((Container)var2).add(this.currentDir);
- ((Container)var2).add(Box.createRigidArea(hstrut10));
- NoFocusButton var4 = new NoFocusButton(this, this.upFolderIcon);
- ((JComponent)var4).setToolTipText("Up One Level");
- ((JComponent)var4).setAlignmentX(0.0F);
- ((JComponent)var4).setAlignmentY(0.5F);
- ((AbstractButton)var4).setMargin(shrinkwrap);
- ((AbstractButton)var4).setFocusPainted(false);
- ((AbstractButton)var4).addActionListener(this.directoryPane.getGoUpAction());
- ((Container)var2).add(var4);
- ((Container)var2).add(Box.createRigidArea(hstrut10));
- var4 = new NoFocusButton(this, this.homeFolderIcon);
- ((JComponent)var4).setToolTipText("Home");
- ((JComponent)var4).setAlignmentX(0.0F);
- ((JComponent)var4).setAlignmentY(0.5F);
- ((AbstractButton)var4).setMargin(shrinkwrap);
- ((AbstractButton)var4).setFocusPainted(false);
- ((AbstractButton)var4).addActionListener(this.goHomeAction);
- ((Container)var2).add(var4);
- ((Container)var2).add(Box.createRigidArea(hstrut10));
- var4 = new NoFocusButton(this, this.newFolderIcon);
- ((JComponent)var4).setToolTipText("Create New Folder");
- ((JComponent)var4).setAlignmentX(0.0F);
- ((JComponent)var4).setAlignmentY(0.5F);
- ((AbstractButton)var4).setMargin(shrinkwrap);
- ((AbstractButton)var4).setFocusPainted(false);
- ((AbstractButton)var4).addActionListener(this.mkdirAction);
- ((Container)var2).add(var4);
- ((Container)var2).add(Box.createRigidArea(hstrut10));
- JToggleButton var5 = new JToggleButton(this.listViewIcon);
- ((JComponent)var5).setToolTipText("List");
- ((AbstractButton)var5).setEnabled(false);
- ((AbstractButton)var5).setFocusPainted(false);
- ((JComponent)var5).setAlignmentX(0.0F);
- ((JComponent)var5).setAlignmentY(0.5F);
- ((AbstractButton)var5).setMargin(shrinkwrap);
- ((Container)var2).add(var5);
- var5 = new JToggleButton(this.detailsViewIcon);
- ((JComponent)var5).setToolTipText("Details");
- ((AbstractButton)var5).setFocusPainted(false);
- ((AbstractButton)var5).setSelected(true);
- ((AbstractButton)var5).setEnabled(false);
- ((JComponent)var5).setAlignmentX(0.0F);
- ((JComponent)var5).setAlignmentY(0.5F);
- ((AbstractButton)var5).setMargin(shrinkwrap);
- ((Container)var2).add(var5);
- ((Container)var2).add(Box.createRigidArea(hstrut10));
- this.centerPanel = new JPanel(new BorderLayout());
- this.centerPanel.add(this.directoryPane, "Center");
- if (this.accessory != null) {
- this.centerPanel.add(this.accessory, "East");
- }
-
- this.fileChooser.add(this.centerPanel);
- JPanel var6 = new JPanel();
- ((Container)var6).setLayout(new BoxLayout(var6, 0));
- ((Container)var6).add(Box.createRigidArea(hstrut10));
- this.fileChooser.add(Box.createRigidArea(vstrut10));
- this.fileChooser.add(var6);
- this.fileChooser.add(Box.createRigidArea(vstrut10));
- JPanel var7 = new JPanel();
- ((Container)var7).setLayout(new BoxLayout(var7, 1));
- var3 = new JLabel("File name:");
- ((Container)var7).add(var3);
- ((Container)var7).add(Box.createRigidArea(vstrut10));
- var3 = new JLabel("Files of type:");
- ((Container)var7).add(var3);
- ((Container)var6).add(var7);
- ((Container)var6).add(Box.createRigidArea(hstrut25));
- JPanel var8 = new JPanel();
- ((Container)var8).setLayout(new BoxLayout(var8, 1));
- this.filename = new JTextField();
- this.filename.addActionListener(this.okayAction);
- ((Container)var8).add(this.filename);
- ((Container)var8).add(Box.createRigidArea(vstrut10));
- this.typesComboBoxModel = this.createTypesComboBoxModel();
- this.types = new JComboBox(this.typesComboBoxModel);
- this.types.setRenderer(this.createTypeRenderer());
- ((Container)var8).add(this.types);
- ((Container)var6).add(var8);
- ((Container)var6).add(Box.createRigidArea(hstrut10));
- JPanel var9 = new JPanel();
- ((Container)var9).setLayout(new BoxLayout(var9, 1));
- this.okayButton = new 1("Open");
- this.okayButton.addActionListener(this.okayAction);
- this.okayButton.setToolTipText("Open");
- ((Container)var9).add(this.okayButton);
- ((Container)var9).add(Box.createRigidArea(vstrut10));
- this.cancelButton = new 2("Cancel");
- this.cancelButton.setToolTipText("Cancel");
- this.cancelButton.addActionListener(this.cancelAction);
- ((Container)var9).add(this.cancelButton);
- ((Container)var6).add(var9);
- ((Container)var6).add(Box.createRigidArea(hstrut10));
- this.listener = this.createListener();
- this.directoryPane.addPropertyChangeListener(this.listener);
- this.directoryPane.getListSelectionModel().addListSelectionListener(this.listener);
- }
-
- public void uninstallUI(JComponent var1) {
- if (var1 != this.fileChooser) {
- throw new IllegalComponentStateException(this + " was asked to deinstall() " + var1 + " when it only knows about " + this.fileChooser + ".");
- } else {
- this.directoryPane.getModel().removePropertyChangeListener(this.listener);
- this.directoryPane.getListSelectionModel().removeListSelectionListener(this.listener);
- this.listener = null;
- this.centerPanel = null;
- this.directoryPane = null;
- this.fileChooser = null;
- this.accessory = null;
- this.fileChooser.removeAll();
- this.fileChooser = null;
- }
- }
-
- public Dimension getPreferredSize(JComponent var1) {
- return PREF_SIZE;
- }
-
- public Dimension getMinimumSize(JComponent var1) {
- return MIN_SIZE;
- }
-
- public Dimension getMaximumSize(JComponent var1) {
- return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
- }
-
- public void update() {
- DirectoryModel var1 = this.directoryPane.getModel();
- File var2 = var1.getCurrentDirectory();
- this.currentDir.removeAllItems();
- this.currentDir.addItem(var2.getName());
- this.mkdirAction.setEnabled(var2.canWrite());
- this.typesComboBoxModel.setTypes(this.fileChooser.getChoosableFileTypes());
- }
-
- protected TypeRenderer createTypeRenderer() {
- return new TypeRenderer(this);
- }
-
- protected TypesComboBoxModel createTypesComboBoxModel() {
- return new TypesComboBoxModel(this);
- }
-
- protected Listener createListener() {
- return new Listener(this);
- }
-
- protected File mkdir(String var1) {
- String var2 = this.directoryPane.getModel().getCurrentDirectory().getPath();
- File var3 = new File(var2, var1);
-
- for(int var4 = 1; (var3.exists() || !var3.mkdirs()) && var4 < 100; ++var4) {
- var3 = new File(var2, var1 + " " + var4);
- }
-
- return var3;
- }
-
- // $FF: synthetic method
- static JTextField access$0(BasicFileChooserUI var0) {
- return var0.filename;
- }
- }
-