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 / BasicSplitPaneDivider.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  5.2 KB  |  156 lines

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