home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / plaf / basic / BasicFileChooserUI.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  9.5 KB  |  257 lines

  1. package com.sun.java.swing.plaf.basic;
  2.  
  3. import com.sun.java.swing.AbstractButton;
  4. import com.sun.java.swing.Action;
  5. import com.sun.java.swing.Box;
  6. import com.sun.java.swing.BoxLayout;
  7. import com.sun.java.swing.Icon;
  8. import com.sun.java.swing.JButton;
  9. import com.sun.java.swing.JComboBox;
  10. import com.sun.java.swing.JComponent;
  11. import com.sun.java.swing.JLabel;
  12. import com.sun.java.swing.JPanel;
  13. import com.sun.java.swing.JTextField;
  14. import com.sun.java.swing.JToggleButton;
  15. import com.sun.java.swing.UIManager;
  16. import com.sun.java.swing.plaf.ComponentUI;
  17. import com.sun.java.swing.plaf.FileChooserUI;
  18. import com.sun.java.swing.preview.DirectoryModel;
  19. import com.sun.java.swing.preview.JDirectoryPane;
  20. import com.sun.java.swing.preview.JFileChooser;
  21. import java.awt.BorderLayout;
  22. import java.awt.Component;
  23. import java.awt.Container;
  24. import java.awt.Dimension;
  25. import java.awt.IllegalComponentStateException;
  26. import java.awt.Insets;
  27. import java.io.File;
  28.  
  29. public class BasicFileChooserUI extends FileChooserUI {
  30.    protected BasicDirectoryPaneUI directoryPaneUI;
  31.    protected JPanel centerPanel;
  32.    protected JFileChooser fileChooser;
  33.    protected JDirectoryPane directoryPane;
  34.    protected Component accessory;
  35.    protected Listener listener;
  36.    protected Action goHomeAction = new GoHomeAction(this);
  37.    protected Action mkdirAction = new MkdirAction(this);
  38.    protected Action cancelAction = new CancelAction(this);
  39.    protected Action okayAction = new OkayAction(this);
  40.    protected TypesComboBoxModel typesComboBoxModel;
  41.    private static Dimension PREF_SIZE = new Dimension(500, 300);
  42.    private static Dimension MIN_SIZE = new Dimension(300, 200);
  43.    private JComboBox currentDir;
  44.    private JButton okayButton;
  45.    private JButton cancelButton;
  46.    private JTextField filename;
  47.    private JComboBox types;
  48.    private JPanel bodyPanel;
  49.    private Icon newFolderIcon;
  50.    private Icon upFolderIcon;
  51.    private Icon homeFolderIcon;
  52.    private Icon listViewIcon;
  53.    private Icon detailsViewIcon;
  54.    private static final Dimension hstrut10 = new Dimension(10, 1);
  55.    private static final Dimension hstrut25 = new Dimension(25, 1);
  56.    private static final Dimension vstrut10 = new Dimension(1, 10);
  57.    private static final Insets shrinkwrap = new Insets(0, 0, 0, 0);
  58.  
  59.    public static ComponentUI createUI(JComponent var0) {
  60.       return new BasicFileChooserUI((JFileChooser)var0);
  61.    }
  62.  
  63.    public BasicFileChooserUI(JFileChooser var1) {
  64.       if (this.newFolderIcon == null) {
  65.          this.newFolderIcon = UIManager.getIcon("FileChooser.newFolder");
  66.          this.upFolderIcon = UIManager.getIcon("FileChooser.upFolder");
  67.          this.homeFolderIcon = UIManager.getIcon("FileChooser.homeFolder");
  68.          this.detailsViewIcon = UIManager.getIcon("FileChooser.detailsView");
  69.          this.listViewIcon = UIManager.getIcon("FileChooser.listView");
  70.       }
  71.  
  72.    }
  73.  
  74.    public void installUI(JComponent var1) {
  75.       this.fileChooser = (JFileChooser)var1;
  76.       this.directoryPane = this.fileChooser.getDirectoryPane();
  77.       this.accessory = this.fileChooser.getAccessory();
  78.       this.fileChooser.setLayout(new BoxLayout(this.fileChooser, 1));
  79.       this.fileChooser.add(Box.createRigidArea(vstrut10));
  80.       JPanel var2 = new JPanel();
  81.       ((Container)var2).setLayout(new BoxLayout(var2, 0));
  82.       this.fileChooser.add(var2);
  83.       this.fileChooser.add(Box.createRigidArea(vstrut10));
  84.       JLabel var3 = new JLabel("Look in:");
  85.       ((JComponent)var3).setAlignmentX(0.0F);
  86.       ((JComponent)var3).setAlignmentY(0.5F);
  87.       ((Container)var2).add(Box.createRigidArea(hstrut10));
  88.       ((Container)var2).add(var3);
  89.       ((Container)var2).add(Box.createRigidArea(hstrut25));
  90.       this.currentDir = new JComboBox();
  91.       this.currentDir.setAlignmentX(0.0F);
  92.       this.currentDir.setAlignmentY(0.5F);
  93.       ((Container)var2).add(this.currentDir);
  94.       ((Container)var2).add(Box.createRigidArea(hstrut10));
  95.       NoFocusButton var4 = new NoFocusButton(this, this.upFolderIcon);
  96.       ((JComponent)var4).setToolTipText("Up One Level");
  97.       ((JComponent)var4).setAlignmentX(0.0F);
  98.       ((JComponent)var4).setAlignmentY(0.5F);
  99.       ((AbstractButton)var4).setMargin(shrinkwrap);
  100.       ((AbstractButton)var4).setFocusPainted(false);
  101.       ((AbstractButton)var4).addActionListener(this.directoryPane.getGoUpAction());
  102.       ((Container)var2).add(var4);
  103.       ((Container)var2).add(Box.createRigidArea(hstrut10));
  104.       var4 = new NoFocusButton(this, this.homeFolderIcon);
  105.       ((JComponent)var4).setToolTipText("Home");
  106.       ((JComponent)var4).setAlignmentX(0.0F);
  107.       ((JComponent)var4).setAlignmentY(0.5F);
  108.       ((AbstractButton)var4).setMargin(shrinkwrap);
  109.       ((AbstractButton)var4).setFocusPainted(false);
  110.       ((AbstractButton)var4).addActionListener(this.goHomeAction);
  111.       ((Container)var2).add(var4);
  112.       ((Container)var2).add(Box.createRigidArea(hstrut10));
  113.       var4 = new NoFocusButton(this, this.newFolderIcon);
  114.       ((JComponent)var4).setToolTipText("Create New Folder");
  115.       ((JComponent)var4).setAlignmentX(0.0F);
  116.       ((JComponent)var4).setAlignmentY(0.5F);
  117.       ((AbstractButton)var4).setMargin(shrinkwrap);
  118.       ((AbstractButton)var4).setFocusPainted(false);
  119.       ((AbstractButton)var4).addActionListener(this.mkdirAction);
  120.       ((Container)var2).add(var4);
  121.       ((Container)var2).add(Box.createRigidArea(hstrut10));
  122.       JToggleButton var5 = new JToggleButton(this.listViewIcon);
  123.       ((JComponent)var5).setToolTipText("List");
  124.       ((AbstractButton)var5).setEnabled(false);
  125.       ((AbstractButton)var5).setFocusPainted(false);
  126.       ((JComponent)var5).setAlignmentX(0.0F);
  127.       ((JComponent)var5).setAlignmentY(0.5F);
  128.       ((AbstractButton)var5).setMargin(shrinkwrap);
  129.       ((Container)var2).add(var5);
  130.       var5 = new JToggleButton(this.detailsViewIcon);
  131.       ((JComponent)var5).setToolTipText("Details");
  132.       ((AbstractButton)var5).setFocusPainted(false);
  133.       ((AbstractButton)var5).setSelected(true);
  134.       ((AbstractButton)var5).setEnabled(false);
  135.       ((JComponent)var5).setAlignmentX(0.0F);
  136.       ((JComponent)var5).setAlignmentY(0.5F);
  137.       ((AbstractButton)var5).setMargin(shrinkwrap);
  138.       ((Container)var2).add(var5);
  139.       ((Container)var2).add(Box.createRigidArea(hstrut10));
  140.       this.centerPanel = new JPanel(new BorderLayout());
  141.       this.centerPanel.add(this.directoryPane, "Center");
  142.       if (this.accessory != null) {
  143.          this.centerPanel.add(this.accessory, "East");
  144.       }
  145.  
  146.       this.fileChooser.add(this.centerPanel);
  147.       JPanel var6 = new JPanel();
  148.       ((Container)var6).setLayout(new BoxLayout(var6, 0));
  149.       ((Container)var6).add(Box.createRigidArea(hstrut10));
  150.       this.fileChooser.add(Box.createRigidArea(vstrut10));
  151.       this.fileChooser.add(var6);
  152.       this.fileChooser.add(Box.createRigidArea(vstrut10));
  153.       JPanel var7 = new JPanel();
  154.       ((Container)var7).setLayout(new BoxLayout(var7, 1));
  155.       var3 = new JLabel("File name:");
  156.       ((Container)var7).add(var3);
  157.       ((Container)var7).add(Box.createRigidArea(vstrut10));
  158.       var3 = new JLabel("Files of type:");
  159.       ((Container)var7).add(var3);
  160.       ((Container)var6).add(var7);
  161.       ((Container)var6).add(Box.createRigidArea(hstrut25));
  162.       JPanel var8 = new JPanel();
  163.       ((Container)var8).setLayout(new BoxLayout(var8, 1));
  164.       this.filename = new JTextField();
  165.       this.filename.addActionListener(this.okayAction);
  166.       ((Container)var8).add(this.filename);
  167.       ((Container)var8).add(Box.createRigidArea(vstrut10));
  168.       this.typesComboBoxModel = this.createTypesComboBoxModel();
  169.       this.types = new JComboBox(this.typesComboBoxModel);
  170.       this.types.setRenderer(this.createTypeRenderer());
  171.       ((Container)var8).add(this.types);
  172.       ((Container)var6).add(var8);
  173.       ((Container)var6).add(Box.createRigidArea(hstrut10));
  174.       JPanel var9 = new JPanel();
  175.       ((Container)var9).setLayout(new BoxLayout(var9, 1));
  176.       this.okayButton = new 1("Open");
  177.       this.okayButton.addActionListener(this.okayAction);
  178.       this.okayButton.setToolTipText("Open");
  179.       ((Container)var9).add(this.okayButton);
  180.       ((Container)var9).add(Box.createRigidArea(vstrut10));
  181.       this.cancelButton = new 2("Cancel");
  182.       this.cancelButton.setToolTipText("Cancel");
  183.       this.cancelButton.addActionListener(this.cancelAction);
  184.       ((Container)var9).add(this.cancelButton);
  185.       ((Container)var6).add(var9);
  186.       ((Container)var6).add(Box.createRigidArea(hstrut10));
  187.       this.listener = this.createListener();
  188.       this.directoryPane.addPropertyChangeListener(this.listener);
  189.       this.directoryPane.getListSelectionModel().addListSelectionListener(this.listener);
  190.    }
  191.  
  192.    public void uninstallUI(JComponent var1) {
  193.       if (var1 != this.fileChooser) {
  194.          throw new IllegalComponentStateException(this + " was asked to deinstall() " + var1 + " when it only knows about " + this.fileChooser + ".");
  195.       } else {
  196.          this.directoryPane.getModel().removePropertyChangeListener(this.listener);
  197.          this.directoryPane.getListSelectionModel().removeListSelectionListener(this.listener);
  198.          this.listener = null;
  199.          this.centerPanel = null;
  200.          this.directoryPane = null;
  201.          this.fileChooser = null;
  202.          this.accessory = null;
  203.          this.fileChooser.removeAll();
  204.          this.fileChooser = null;
  205.       }
  206.    }
  207.  
  208.    public Dimension getPreferredSize(JComponent var1) {
  209.       return PREF_SIZE;
  210.    }
  211.  
  212.    public Dimension getMinimumSize(JComponent var1) {
  213.       return MIN_SIZE;
  214.    }
  215.  
  216.    public Dimension getMaximumSize(JComponent var1) {
  217.       return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
  218.    }
  219.  
  220.    public void update() {
  221.       DirectoryModel var1 = this.directoryPane.getModel();
  222.       File var2 = var1.getCurrentDirectory();
  223.       this.currentDir.removeAllItems();
  224.       this.currentDir.addItem(var2.getName());
  225.       this.mkdirAction.setEnabled(var2.canWrite());
  226.       this.typesComboBoxModel.setTypes(this.fileChooser.getChoosableFileTypes());
  227.    }
  228.  
  229.    protected TypeRenderer createTypeRenderer() {
  230.       return new TypeRenderer(this);
  231.    }
  232.  
  233.    protected TypesComboBoxModel createTypesComboBoxModel() {
  234.       return new TypesComboBoxModel(this);
  235.    }
  236.  
  237.    protected Listener createListener() {
  238.       return new Listener(this);
  239.    }
  240.  
  241.    protected File mkdir(String var1) {
  242.       String var2 = this.directoryPane.getModel().getCurrentDirectory().getPath();
  243.       File var3 = new File(var2, var1);
  244.  
  245.       for(int var4 = 1; (var3.exists() || !var3.mkdirs()) && var4 < 100; ++var4) {
  246.          var3 = new File(var2, var1 + " " + var4);
  247.       }
  248.  
  249.       return var3;
  250.    }
  251.  
  252.    // $FF: synthetic method
  253.    static JTextField access$0(BasicFileChooserUI var0) {
  254.       return var0.filename;
  255.    }
  256. }
  257.