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

  1. package com.sun.java.swing.preview;
  2.  
  3. import com.sun.java.accessibility.Accessible;
  4. import com.sun.java.accessibility.AccessibleContext;
  5. import com.sun.java.swing.Action;
  6. import com.sun.java.swing.DefaultListSelectionModel;
  7. import com.sun.java.swing.JComponent;
  8. import com.sun.java.swing.ListSelectionModel;
  9. import com.sun.java.swing.SwingConstants;
  10. import com.sun.java.swing.UIManager;
  11. import com.sun.java.swing.plaf.DirectoryPaneUI;
  12. import java.awt.event.ActionEvent;
  13. import java.awt.event.ActionListener;
  14. import java.io.File;
  15. import java.util.Enumeration;
  16. import java.util.Vector;
  17.  
  18. public class JDirectoryPane extends JComponent implements SwingConstants, Accessible {
  19.    protected DirectoryModel directoryModel;
  20.    protected ListSelectionModel listSelectionModel;
  21.    protected transient Redirector redirector;
  22.    protected transient SelListener selListener;
  23.    protected String command;
  24.    protected String doubleClickCommand;
  25.    protected String doubleClickContainerCommand;
  26.    GoUpAction goUpAction;
  27.    DefaultActionListener defaultActionListener;
  28.    // $FF: synthetic field
  29.    static Class class$java$awt$event$ActionListener;
  30.  
  31.    public JDirectoryPane() {
  32.       this((File)null);
  33.    }
  34.  
  35.    public JDirectoryPane(String var1) {
  36.       this(var1 == null ? null : new File(var1));
  37.    }
  38.  
  39.    public JDirectoryPane(File var1) {
  40.       this.doubleClickCommand = "doubleClick";
  41.       this.doubleClickContainerCommand = "doubleClickContainer";
  42.       this.goUpAction = new GoUpAction(this);
  43.       this.defaultActionListener = new DefaultActionListener(this);
  44.       this.setModel(this.createDirectoryModel(var1));
  45.       this.setSelectionModel(this.createSelectionModel());
  46.       this.addActionListener(this.getDefaultActionListener());
  47.       this.updateUI();
  48.    }
  49.  
  50.    protected DirectoryModel createDirectoryModel(File var1) {
  51.       return new DirectoryModel(var1);
  52.    }
  53.  
  54.    protected ListSelectionModel createSelectionModel() {
  55.       return new DefaultListSelectionModel();
  56.    }
  57.  
  58.    public Action getGoUpAction() {
  59.       return this.goUpAction;
  60.    }
  61.  
  62.    public ActionListener getDefaultActionListener() {
  63.       return this.defaultActionListener;
  64.    }
  65.  
  66.    public void performDoubleClick() {
  67.       TypedFile var1 = this.getSelectedFile();
  68.       if (var1.getType().isContainer()) {
  69.          this.fireActionPerformed(this.getDoubleClickContainerCommand());
  70.       } else {
  71.          this.fireActionPerformed(this.getDoubleClickCommand());
  72.       }
  73.    }
  74.  
  75.    public TypedFile getSelectedFile() {
  76.       int var1 = this.getListSelectionModel().getLeadSelectionIndex();
  77.       return var1 >= 0 ? (TypedFile)this.getModel().getTypedFiles().elementAt(var1) : null;
  78.    }
  79.  
  80.    public Vector getSelectedFiles() {
  81.       ListSelectionModel var1 = this.getListSelectionModel();
  82.       int var2 = var1.getAnchorSelectionIndex();
  83.       int var3 = var1.getLeadSelectionIndex();
  84.       Vector var4 = new Vector();
  85.       if (var2 >= 0 && var3 >= 0) {
  86.          Vector var5 = this.getModel().getTypedFiles();
  87.          int var6 = Math.max(var2, var3);
  88.  
  89.          for(int var7 = Math.min(var2, var3); var7 <= var6; ++var7) {
  90.             var4.addElement(var5.elementAt(var7));
  91.          }
  92.       }
  93.  
  94.       return var4;
  95.    }
  96.  
  97.    public boolean isSelectionEmpty() {
  98.       return this.getListSelectionModel().isSelectionEmpty();
  99.    }
  100.  
  101.    public void clearSelection() {
  102.       this.getListSelectionModel().clearSelection();
  103.    }
  104.  
  105.    public File getCurrentDirectory() {
  106.       return this.directoryModel.getCurrentDirectory();
  107.    }
  108.  
  109.    public void setCurrentDirectory(File var1) {
  110.       this.directoryModel.setCurrentDirectory(var1);
  111.    }
  112.  
  113.    public TypedFile getTypedFile(String var1, String var2) {
  114.       return this.directoryModel.getTypedFile(var1, var2);
  115.    }
  116.  
  117.    public TypedFile getTypedFile(String var1) {
  118.       return this.directoryModel.getTypedFile(var1);
  119.    }
  120.  
  121.    public Vector getTypedFiles() {
  122.       return this.directoryModel.getTypedFiles();
  123.    }
  124.  
  125.    public Vector getTypedFilesForDirectory(File var1) {
  126.       return this.directoryModel.getTypedFilesForDirectory(var1);
  127.    }
  128.  
  129.    public boolean canGoUp() {
  130.       return this.directoryModel.canGoUp();
  131.    }
  132.  
  133.    public void goUp() {
  134.       this.directoryModel.goUp();
  135.    }
  136.  
  137.    public void setHiddenRule(FileType var1) {
  138.       this.directoryModel.setHiddenRule(var1);
  139.    }
  140.  
  141.    public FileType getHiddenRule() {
  142.       return this.directoryModel.getHiddenRule();
  143.    }
  144.  
  145.    public void addKnownFileType(FileType var1) {
  146.       this.directoryModel.addKnownFileType(var1);
  147.    }
  148.  
  149.    public Enumeration enumerateKnownFileTypes() {
  150.       return this.directoryModel.enumerateKnownFileTypes();
  151.    }
  152.  
  153.    public Vector getKnownFileTypes() {
  154.       return this.directoryModel.getKnownFileTypes();
  155.    }
  156.  
  157.    public boolean isKnownFileType(FileType var1) {
  158.       return this.directoryModel.isKnownFileType(var1);
  159.    }
  160.  
  161.    public void setKnownFileTypes(FileType[] var1) {
  162.       this.directoryModel.setKnownFileTypes(var1);
  163.    }
  164.  
  165.    public DirectoryPaneUI getUI() {
  166.       return (DirectoryPaneUI)super.ui;
  167.    }
  168.  
  169.    public void setUI(DirectoryPaneUI var1) {
  170.       super.setUI(var1);
  171.    }
  172.  
  173.    public void updateUI() {
  174.       this.setUI((DirectoryPaneUI)UIManager.getUI(this));
  175.    }
  176.  
  177.    public String getUIClassID() {
  178.       return "DirectoryPaneUI";
  179.    }
  180.  
  181.    public DirectoryModel getModel() {
  182.       return this.directoryModel;
  183.    }
  184.  
  185.    protected void setModel(DirectoryModel var1) {
  186.       DirectoryModel var2 = this.getModel();
  187.       if (var2 != null) {
  188.          var2.removePropertyChangeListener(this.redirector);
  189.          this.redirector = null;
  190.       }
  191.  
  192.       this.directoryModel = var1;
  193.       if (var1 != null) {
  194.          this.redirector = this.createRedirector();
  195.          var1.addPropertyChangeListener(this.redirector);
  196.       }
  197.  
  198.    }
  199.  
  200.    public ListSelectionModel getListSelectionModel() {
  201.       return this.listSelectionModel;
  202.    }
  203.  
  204.    protected void setSelectionModel(ListSelectionModel var1) {
  205.       ListSelectionModel var2 = this.getListSelectionModel();
  206.       if (var2 != null) {
  207.          var2.removeListSelectionListener(this.selListener);
  208.          this.selListener = null;
  209.       }
  210.  
  211.       this.listSelectionModel = var1;
  212.       if (var1 != null) {
  213.          this.selListener = this.createSelectionListener();
  214.          var1.addListSelectionListener(this.selListener);
  215.       }
  216.  
  217.    }
  218.  
  219.    protected Redirector createRedirector() {
  220.       return new Redirector(this);
  221.    }
  222.  
  223.    protected SelListener createSelectionListener() {
  224.       return new SelListener(this);
  225.    }
  226.  
  227.    public synchronized void addActionListener(ActionListener var1) {
  228.       super.listenerList.add(class$java$awt$event$ActionListener != null ? class$java$awt$event$ActionListener : (class$java$awt$event$ActionListener = class$("java.awt.event.ActionListener")), var1);
  229.    }
  230.  
  231.    public synchronized void removeActionListener(ActionListener var1) {
  232.       super.listenerList.remove(class$java$awt$event$ActionListener != null ? class$java$awt$event$ActionListener : (class$java$awt$event$ActionListener = class$("java.awt.event.ActionListener")), var1);
  233.    }
  234.  
  235.    protected void fireActionPerformed(String var1) {
  236.       Object[] var2 = super.listenerList.getListenerList();
  237.       ActionEvent var3 = null;
  238.  
  239.       for(int var4 = var2.length - 2; var4 >= 0; var4 -= 2) {
  240.          if (var2[var4] == (class$java$awt$event$ActionListener != null ? class$java$awt$event$ActionListener : (class$java$awt$event$ActionListener = class$("java.awt.event.ActionListener")))) {
  241.             if (var3 == null) {
  242.                var3 = new ActionEvent(this, 1001, var1);
  243.             }
  244.  
  245.             ((ActionListener)var2[var4 + 1]).actionPerformed(var3);
  246.          }
  247.       }
  248.  
  249.    }
  250.  
  251.    public void setActionCommand(String var1) {
  252.       String var2 = this.command;
  253.       this.command = var1;
  254.       ((JComponent)this).firePropertyChange("actionCommand", var2, var1);
  255.    }
  256.  
  257.    public String getActionCommand() {
  258.       return this.command;
  259.    }
  260.  
  261.    public void setDoubleClickCommand(String var1) {
  262.       String var2 = this.doubleClickCommand;
  263.       this.doubleClickCommand = var1;
  264.       ((JComponent)this).firePropertyChange("doubleClickCommand", var2, var1);
  265.    }
  266.  
  267.    public String getDoubleClickCommand() {
  268.       return this.doubleClickCommand;
  269.    }
  270.  
  271.    public void setDoubleClickContainerCommand(String var1) {
  272.       String var2 = this.doubleClickContainerCommand;
  273.       this.doubleClickContainerCommand = var1;
  274.       ((JComponent)this).firePropertyChange("doubleClickContainerCommand", var2, var1);
  275.    }
  276.  
  277.    public String getDoubleClickContainerCommand() {
  278.       return this.doubleClickContainerCommand;
  279.    }
  280.  
  281.    public AccessibleContext getAccessibleContext() {
  282.       if (super.accessibleContext == null) {
  283.          super.accessibleContext = new AccessibleJDirectoryPane(this);
  284.       }
  285.  
  286.       return super.accessibleContext;
  287.    }
  288.  
  289.    // $FF: synthetic method
  290.    static Class class$(String var0) {
  291.       try {
  292.          return Class.forName(var0);
  293.       } catch (ClassNotFoundException var2) {
  294.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  295.       }
  296.    }
  297. }
  298.