home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 144 / DPCS0200.iso / Internet / Supanet / system / swing.jar / javax / swing / JSplitPane.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-05  |  7.7 KB  |  347 lines

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