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

  1. package com.sun.java.swing;
  2.  
  3. import com.sun.java.accessibility.Accessible;
  4. import com.sun.java.accessibility.AccessibleContext;
  5. import com.sun.java.swing.plaf.SplitPaneUI;
  6. import java.awt.Component;
  7. import java.awt.Container;
  8. import java.awt.Graphics;
  9. import java.awt.LayoutManager;
  10.  
  11. public class JSplitPane extends JComponent implements Accessible {
  12.    public static final int VERTICAL_SPLIT = 0;
  13.    public static final int HORIZONTAL_SPLIT = 1;
  14.    public static final String LEFT = "left";
  15.    public static final String RIGHT = "right";
  16.    public static final String TOP = "top";
  17.    public static final String BOTTOM = "bottom";
  18.    public static final String DIVIDER = "divider";
  19.    public static final String ORIENTATION_PROPERTY = "orientation";
  20.    public static final String CONTINUOUS_LAYOUT_PROPERTY = "continuousLayout";
  21.    public static final String DIVIDER_SIZE_PROPERTY = "dividerSize";
  22.    public static final String ONE_TOUCH_EXPANDABLE_PROPERTY = "oneTouchExpandable";
  23.    public static final String LAST_DIVIDER_LOCATION_PROPERTY = "lastDividerLocation";
  24.    protected int orientation;
  25.    protected boolean continuousLayout;
  26.    protected Component leftComponent;
  27.    protected Component rightComponent;
  28.    protected int dividerSize;
  29.    protected boolean oneTouchExpandable;
  30.    protected int lastDividerLocation;
  31.  
  32.    public JSplitPane() {
  33.       this(1, false, new JButton("left button"), new JButton("right button"));
  34.    }
  35.  
  36.    public JSplitPane(int var1) {
  37.       this(var1, false);
  38.    }
  39.  
  40.    public JSplitPane(int var1, boolean var2) {
  41.       this(var1, var2, (Component)null, (Component)null);
  42.    }
  43.  
  44.    public JSplitPane(int var1, Component var2, Component var3) {
  45.       this(var1, false, var2, var3);
  46.    }
  47.  
  48.    public JSplitPane(int var1, boolean var2, Component var3, Component var4) {
  49.       this.dividerSize = 5;
  50.       ((Container)this).setLayout((LayoutManager)null);
  51.       this.orientation = var1;
  52.       if (this.orientation != 1 && this.orientation != 0) {
  53.          throw new IllegalArgumentException("cannot create JSplitPane, orientation must be one of JSplitPane.HORIZONTAL_SPLIT or JSplitPane.VERTICAL_SPLIT");
  54.       } else {
  55.          this.continuousLayout = var2;
  56.          if (var3 != null) {
  57.             this.setLeftComponent(var3);
  58.          }
  59.  
  60.          if (var4 != null) {
  61.             this.setRightComponent(var4);
  62.          }
  63.  
  64.          this.updateUI();
  65.       }
  66.    }
  67.  
  68.    public void setUI(SplitPaneUI var1) {
  69.       if ((SplitPaneUI)super.ui != var1) {
  70.          super.setUI(var1);
  71.          ((Container)this).invalidate();
  72.       }
  73.  
  74.    }
  75.  
  76.    public SplitPaneUI getUI() {
  77.       return (SplitPaneUI)super.ui;
  78.    }
  79.  
  80.    public void updateUI() {
  81.       this.setUI((SplitPaneUI)UIManager.getUI(this));
  82.       ((Container)this).invalidate();
  83.    }
  84.  
  85.    public String getUIClassID() {
  86.       return "SplitPaneUI";
  87.    }
  88.  
  89.    public void setDividerSize(int var1) {
  90.       int var2 = this.dividerSize;
  91.       if (var2 != var1) {
  92.          this.dividerSize = var1;
  93.          ((JComponent)this).firePropertyChange("dividerSize", var2, var1);
  94.       }
  95.  
  96.    }
  97.  
  98.    public int getDividerSize() {
  99.       return this.dividerSize;
  100.    }
  101.  
  102.    public void setLeftComponent(Component var1) {
  103.       if (var1 == null) {
  104.          if (this.leftComponent != null) {
  105.             this.remove(this.leftComponent);
  106.             this.leftComponent = null;
  107.             return;
  108.          }
  109.       } else {
  110.          ((Container)this).add(var1, "left");
  111.       }
  112.  
  113.    }
  114.  
  115.    public Component getLeftComponent() {
  116.       return this.leftComponent;
  117.    }
  118.  
  119.    public void setTopComponent(Component var1) {
  120.       this.setLeftComponent(var1);
  121.    }
  122.  
  123.    public Component getTopComponent() {
  124.       return this.leftComponent;
  125.    }
  126.  
  127.    public void setRightComponent(Component var1) {
  128.       if (var1 == null) {
  129.          if (this.rightComponent != null) {
  130.             this.remove(this.rightComponent);
  131.             this.rightComponent = null;
  132.             return;
  133.          }
  134.       } else {
  135.          ((Container)this).add(var1, "right");
  136.       }
  137.  
  138.    }
  139.  
  140.    public Component getRightComponent() {
  141.       return this.rightComponent;
  142.    }
  143.  
  144.    public void setBottomComponent(Component var1) {
  145.       this.setRightComponent(var1);
  146.    }
  147.  
  148.    public Component getBottomComponent() {
  149.       return this.rightComponent;
  150.    }
  151.  
  152.    public void setOneTouchExpandable(boolean var1) {
  153.       boolean var2 = this.oneTouchExpandable;
  154.       this.oneTouchExpandable = var1;
  155.       ((JComponent)this).firePropertyChange("oneTouchExpandable", var2, var1);
  156.       ((Component)this).repaint();
  157.    }
  158.  
  159.    public boolean isOneTouchExpandable() {
  160.       return this.oneTouchExpandable;
  161.    }
  162.  
  163.    public void setLastDividerLocation(int var1) {
  164.       int var2 = this.lastDividerLocation;
  165.       this.lastDividerLocation = var1;
  166.       ((JComponent)this).firePropertyChange("lastDividerLocation", var2, var1);
  167.    }
  168.  
  169.    public int getLastDividerLocation() {
  170.       return this.lastDividerLocation;
  171.    }
  172.  
  173.    public void setOrientation(int var1) {
  174.       if (var1 != 0 && var1 != 1) {
  175.          throw new IllegalArgumentException("JSplitPane: orientation must be one of JSplitPane.VERTICAL_SPLIT or JSplitPane.HORIZONTAL_SPLIT");
  176.       } else {
  177.          int var2 = this.orientation;
  178.          this.orientation = var1;
  179.          ((JComponent)this).firePropertyChange("orientation", var2, var1);
  180.       }
  181.    }
  182.  
  183.    public int getOrientation() {
  184.       return this.orientation;
  185.    }
  186.  
  187.    public void setContinuousLayout(boolean var1) {
  188.       boolean var2 = this.continuousLayout;
  189.       this.continuousLayout = var1;
  190.       ((JComponent)this).firePropertyChange("continuousLayout", var2, var1);
  191.    }
  192.  
  193.    public boolean isContinuousLayout() {
  194.       return this.continuousLayout;
  195.    }
  196.  
  197.    public void resetToPreferredSizes() {
  198.       SplitPaneUI var1 = this.getUI();
  199.       if (var1 != null) {
  200.          var1.resetToPreferredSizes();
  201.       }
  202.  
  203.    }
  204.  
  205.    public void setDividerLocation(double var1) {
  206.       if (!(var1 < (double)0.0F) && !(var1 > (double)1.0F)) {
  207.          if (this.getOrientation() == 0) {
  208.             this.setDividerLocation((int)((double)(((JComponent)this).getHeight() - this.getDividerSize()) * var1));
  209.          } else {
  210.             this.setDividerLocation((int)((double)(((JComponent)this).getWidth() - this.getDividerSize()) * var1));
  211.          }
  212.       } else {
  213.          throw new IllegalArgumentException("proportional location must be between 0.0 and 1.0.");
  214.       }
  215.    }
  216.  
  217.    public void setDividerLocation(int var1) {
  218.       SplitPaneUI var2 = this.getUI();
  219.       if (var2 != null) {
  220.          var2.setDividerLocation(var1);
  221.       }
  222.  
  223.    }
  224.  
  225.    public int getDividerLocation() {
  226.       SplitPaneUI var1 = this.getUI();
  227.       return var1 != null ? var1.getDividerLocation() : -1;
  228.    }
  229.  
  230.    public int getMinimumDividerLocation() {
  231.       SplitPaneUI var1 = this.getUI();
  232.       return var1 != null ? var1.getMinimumDividerLocation() : -1;
  233.    }
  234.  
  235.    public int getMaximumDividerLocation() {
  236.       SplitPaneUI var1 = this.getUI();
  237.       return var1 != null ? var1.getMaximumDividerLocation() : -1;
  238.    }
  239.  
  240.    public void remove(Component var1) {
  241.       if (var1 == this.leftComponent) {
  242.          this.leftComponent = null;
  243.       } else if (var1 == this.rightComponent) {
  244.          this.rightComponent = null;
  245.       }
  246.  
  247.       super.remove(var1);
  248.    }
  249.  
  250.    public void remove(int var1) {
  251.       Component var2 = ((Container)this).getComponent(var1);
  252.       if (var2 == this.leftComponent) {
  253.          this.leftComponent = null;
  254.       } else if (var2 == this.rightComponent) {
  255.          this.rightComponent = null;
  256.       }
  257.  
  258.       super.remove(var1);
  259.    }
  260.  
  261.    public void removeAll() {
  262.       this.leftComponent = this.rightComponent = null;
  263.       super.removeAll();
  264.    }
  265.  
  266.    protected void addImpl(Component var1, Object var2, int var3) {
  267.       if (var2 != null && !(var2 instanceof String)) {
  268.          throw new IllegalArgumentException("cannot add to layout: constraint must be a string (or null)");
  269.       } else {
  270.          if (var2 == null) {
  271.             if (this.getLeftComponent() == null) {
  272.                var2 = "left";
  273.             } else if (this.getRightComponent() == null) {
  274.                var2 = "right";
  275.             }
  276.          }
  277.  
  278.          if (var2 == null || !var2.equals("left") && !var2.equals("top")) {
  279.             if (var2 != null && (var2.equals("right") || var2.equals("bottom"))) {
  280.                Component var5 = this.getRightComponent();
  281.                if (var5 != null) {
  282.                   this.remove(var5);
  283.                }
  284.  
  285.                this.rightComponent = var1;
  286.                var3 = -1;
  287.             } else if (var2 != null && var2.equals("divider")) {
  288.                var3 = -1;
  289.             }
  290.          } else {
  291.             Component var4 = this.getLeftComponent();
  292.             if (var4 != null) {
  293.                this.remove(var4);
  294.             }
  295.  
  296.             this.leftComponent = var1;
  297.             var3 = -1;
  298.          }
  299.  
  300.          super.addImpl(var1, var2, var3);
  301.       }
  302.    }
  303.  
  304.    protected void paintChildren(Graphics var1) {
  305.       super.paintChildren(var1);
  306.       SplitPaneUI var2 = this.getUI();
  307.       if (var2 != null) {
  308.          Graphics var3 = var1.create();
  309.          var2.finishedPaintingChildren(this, var3);
  310.          var3.dispose();
  311.       }
  312.  
  313.    }
  314.  
  315.    public AccessibleContext getAccessibleContext() {
  316.       if (super.accessibleContext == null) {
  317.          super.accessibleContext = new AccessibleJSplitPane(this);
  318.       }
  319.  
  320.       return super.accessibleContext;
  321.    }
  322. }
  323.