home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &… the Search for Life CD 3 / 0_CD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / plaf / basic / BasicSplitPaneDivider.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  5.2 KB  |  184 lines

  1. package javax.swing.plaf.basic;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Cursor;
  6. import java.awt.Dimension;
  7. import java.awt.Graphics;
  8. import java.awt.Insets;
  9. import java.beans.PropertyChangeEvent;
  10. import java.beans.PropertyChangeListener;
  11. import java.util.EventObject;
  12. import javax.swing.AbstractButton;
  13. import javax.swing.JButton;
  14. import javax.swing.JSplitPane;
  15. import javax.swing.UIManager;
  16. import javax.swing.border.Border;
  17.  
  18. public class BasicSplitPaneDivider extends Container implements PropertyChangeListener {
  19.    protected static final int ONE_TOUCH_SIZE = 6;
  20.    protected static final int ONE_TOUCH_OFFSET = 2;
  21.    protected DragController dragger;
  22.    protected BasicSplitPaneUI splitPaneUI;
  23.    protected int dividerSize = 0;
  24.    protected Component hiddenDivider;
  25.    protected JSplitPane splitPane;
  26.    protected MouseHandler mouseHandler;
  27.    protected int orientation;
  28.    protected JButton leftButton;
  29.    protected JButton rightButton;
  30.    static final Cursor horizontalCursor = Cursor.getPredefinedCursor(11);
  31.    static final Cursor verticalCursor = Cursor.getPredefinedCursor(9);
  32.    static final Cursor defaultCursor = Cursor.getPredefinedCursor(0);
  33.    private Border border;
  34.  
  35.    public BasicSplitPaneDivider(BasicSplitPaneUI var1) {
  36.       ((Container)this).setLayout(new DividerLayout(this));
  37.       this.setBasicSplitPaneUI(var1);
  38.       this.orientation = this.splitPane.getOrientation();
  39.       ((Component)this).setBackground(UIManager.getColor("SplitPane.background"));
  40.    }
  41.  
  42.    public void setBasicSplitPaneUI(BasicSplitPaneUI var1) {
  43.       if (this.splitPane != null) {
  44.          this.splitPane.removePropertyChangeListener(this);
  45.          if (this.mouseHandler != null) {
  46.             this.splitPane.removeMouseListener(this.mouseHandler);
  47.             this.splitPane.removeMouseMotionListener(this.mouseHandler);
  48.             ((Component)this).removeMouseListener(this.mouseHandler);
  49.             ((Component)this).removeMouseMotionListener(this.mouseHandler);
  50.             this.mouseHandler = null;
  51.          }
  52.       }
  53.  
  54.       this.splitPaneUI = var1;
  55.       if (var1 != null) {
  56.          this.splitPane = var1.getSplitPane();
  57.          if (this.splitPane != null) {
  58.             if (this.mouseHandler == null) {
  59.                this.mouseHandler = new MouseHandler(this);
  60.             }
  61.  
  62.             this.splitPane.addMouseListener(this.mouseHandler);
  63.             this.splitPane.addMouseMotionListener(this.mouseHandler);
  64.             ((Component)this).addMouseListener(this.mouseHandler);
  65.             ((Component)this).addMouseMotionListener(this.mouseHandler);
  66.             this.splitPane.addPropertyChangeListener(this);
  67.             if (this.splitPane.isOneTouchExpandable()) {
  68.                this.oneTouchExpandableChanged();
  69.             }
  70.          }
  71.       } else {
  72.          this.splitPane = null;
  73.       }
  74.  
  75.    }
  76.  
  77.    public BasicSplitPaneUI getBasicSplitPaneUI() {
  78.       return this.splitPaneUI;
  79.    }
  80.  
  81.    public void setDividerSize(int var1) {
  82.       this.dividerSize = var1;
  83.    }
  84.  
  85.    public int getDividerSize() {
  86.       return this.dividerSize;
  87.    }
  88.  
  89.    public void setBorder(Border var1) {
  90.       Border var2 = this.border;
  91.       this.border = var1;
  92.    }
  93.  
  94.    public Border getBorder() {
  95.       return this.border;
  96.    }
  97.  
  98.    public Insets getInsets() {
  99.       Border var1 = this.getBorder();
  100.       return var1 != null ? var1.getBorderInsets(this) : super.getInsets();
  101.    }
  102.  
  103.    public Dimension getPreferredSize() {
  104.       return new Dimension(this.getDividerSize(), this.getDividerSize());
  105.    }
  106.  
  107.    public Dimension getMinimumSize() {
  108.       return this.getPreferredSize();
  109.    }
  110.  
  111.    public void propertyChange(PropertyChangeEvent var1) {
  112.       if (((EventObject)var1).getSource() == this.splitPane) {
  113.          if (var1.getPropertyName().equals("orientation")) {
  114.             this.orientation = this.splitPane.getOrientation();
  115.             ((Container)this).invalidate();
  116.             ((Container)this).validate();
  117.          } else if (var1.getPropertyName().equals("oneTouchExpandable")) {
  118.             this.oneTouchExpandableChanged();
  119.          }
  120.       }
  121.  
  122.    }
  123.  
  124.    public void paint(Graphics var1) {
  125.       super.paint(var1);
  126.       Border var2 = this.getBorder();
  127.       if (var2 != null) {
  128.          Dimension var3 = ((Component)this).getSize();
  129.          var2.paintBorder(this, var1, 0, 0, var3.width, var3.height);
  130.       }
  131.  
  132.    }
  133.  
  134.    protected void oneTouchExpandableChanged() {
  135.       if (this.splitPane.isOneTouchExpandable() && this.leftButton == null && this.rightButton == null) {
  136.          this.leftButton = this.createLeftOneTouchButton();
  137.          if (this.leftButton != null) {
  138.             this.leftButton.addActionListener(new OneTouchActionHandler(this, true));
  139.          }
  140.  
  141.          this.rightButton = this.createRightOneTouchButton();
  142.          if (this.rightButton != null) {
  143.             this.rightButton.addActionListener(new OneTouchActionHandler(this, false));
  144.          }
  145.  
  146.          if (this.leftButton != null && this.rightButton != null) {
  147.             ((Container)this).add(this.leftButton);
  148.             ((Container)this).add(this.rightButton);
  149.          }
  150.       }
  151.  
  152.       ((Container)this).invalidate();
  153.       ((Container)this).validate();
  154.    }
  155.  
  156.    protected JButton createLeftOneTouchButton() {
  157.       1 var1 = new 1(this);
  158.       ((Component)var1).setCursor(defaultCursor);
  159.       ((AbstractButton)var1).setFocusPainted(false);
  160.       ((AbstractButton)var1).setBorderPainted(false);
  161.       return var1;
  162.    }
  163.  
  164.    protected JButton createRightOneTouchButton() {
  165.       2 var1 = new 2(this);
  166.       ((Component)var1).setCursor(defaultCursor);
  167.       ((AbstractButton)var1).setFocusPainted(false);
  168.       ((AbstractButton)var1).setBorderPainted(false);
  169.       return var1;
  170.    }
  171.  
  172.    protected void prepareForDragging() {
  173.       this.splitPaneUI.startDragging();
  174.    }
  175.  
  176.    protected void dragDividerTo(int var1) {
  177.       this.splitPaneUI.dragDividerTo(var1);
  178.    }
  179.  
  180.    protected void finishDraggingTo(int var1) {
  181.       this.splitPaneUI.finishDraggingTo(var1);
  182.    }
  183. }
  184.