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

  1. package javax.swing.plaf.basic;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Graphics;
  7. import java.awt.Insets;
  8. import java.awt.LayoutManager;
  9. import java.awt.Rectangle;
  10. import java.awt.event.ActionListener;
  11. import java.awt.event.FocusListener;
  12. import java.awt.peer.ComponentPeer;
  13. import java.awt.peer.LightweightPeer;
  14. import java.beans.PropertyChangeListener;
  15. import javax.swing.JComponent;
  16. import javax.swing.JSplitPane;
  17. import javax.swing.KeyStroke;
  18. import javax.swing.LookAndFeel;
  19. import javax.swing.UIManager;
  20. import javax.swing.plaf.ComponentUI;
  21. import javax.swing.plaf.SplitPaneUI;
  22.  
  23. public class BasicSplitPaneUI extends SplitPaneUI {
  24.    protected static final String NON_CONTINUOUS_DIVIDER = "nonContinuousDivider";
  25.    protected static int KEYBOARD_DIVIDER_MOVE_OFFSET = 3;
  26.    protected JSplitPane splitPane;
  27.    protected BasicHorizontalLayoutManager layoutManager;
  28.    protected BasicSplitPaneDivider divider;
  29.    protected PropertyChangeListener propertyChangeListener;
  30.    protected FocusListener focusListener;
  31.    protected int dividerSize;
  32.    protected Component nonContinuousLayoutDivider;
  33.    protected boolean draggingHW;
  34.    protected int beginDragDividerLocation;
  35.    protected KeyStroke upKey;
  36.    protected KeyStroke downKey;
  37.    protected KeyStroke leftKey;
  38.    protected KeyStroke rightKey;
  39.    protected KeyStroke homeKey;
  40.    protected KeyStroke endKey;
  41.    protected KeyStroke dividerResizeToggleKey;
  42.    protected ActionListener keyboardUpLeftListener;
  43.    protected ActionListener keyboardDownRightListener;
  44.    protected ActionListener keyboardHomeListener;
  45.    protected ActionListener keyboardEndListener;
  46.    protected ActionListener keyboardResizeToggleListener;
  47.    private int orientation;
  48.    private int lastDragLocation;
  49.    private boolean continuousLayout;
  50.    private boolean dividerKeyboardResize;
  51.    private boolean dividerLocationIsSet;
  52.  
  53.    // $FF: synthetic method
  54.    static int access$0(BasicSplitPaneUI var0) {
  55.       return var0.orientation;
  56.    }
  57.  
  58.    // $FF: synthetic method
  59.    static void access$1(BasicSplitPaneUI var0, int var1) {
  60.       var0.orientation = var1;
  61.    }
  62.  
  63.    // $FF: synthetic method
  64.    static boolean access$2(BasicSplitPaneUI var0) {
  65.       return var0.dividerKeyboardResize;
  66.    }
  67.  
  68.    // $FF: synthetic method
  69.    static void access$3(BasicSplitPaneUI var0, boolean var1) {
  70.       var0.dividerKeyboardResize = var1;
  71.    }
  72.  
  73.    // $FF: synthetic method
  74.    static boolean access$4(BasicSplitPaneUI var0) {
  75.       return var0.dividerLocationIsSet;
  76.    }
  77.  
  78.    public BasicSplitPaneDivider createDefaultDivider() {
  79.       return new BasicSplitPaneDivider(this);
  80.    }
  81.  
  82.    protected Component createDefaultNonContinuousLayoutDivider() {
  83.       return new 1(this);
  84.    }
  85.  
  86.    protected FocusListener createFocusListener() {
  87.       return new FocusHandler(this);
  88.    }
  89.  
  90.    protected ActionListener createKeyboardDownRightListener() {
  91.       return new KeyboardDownRightHandler(this);
  92.    }
  93.  
  94.    protected ActionListener createKeyboardEndListener() {
  95.       return new KeyboardEndHandler(this);
  96.    }
  97.  
  98.    protected ActionListener createKeyboardHomeListener() {
  99.       return new KeyboardHomeHandler(this);
  100.    }
  101.  
  102.    protected ActionListener createKeyboardResizeToggleListener() {
  103.       return new KeyboardResizeToggleHandler(this);
  104.    }
  105.  
  106.    protected ActionListener createKeyboardUpLeftListener() {
  107.       return new KeyboardUpLeftHandler(this);
  108.    }
  109.  
  110.    protected PropertyChangeListener createPropertyChangeListener() {
  111.       return new PropertyHandler(this);
  112.    }
  113.  
  114.    public static ComponentUI createUI(JComponent var0) {
  115.       return new BasicSplitPaneUI();
  116.    }
  117.  
  118.    protected void dragDividerTo(int var1) {
  119.       if (this.getLastDragLocation() != var1) {
  120.          if (this.isContinuousLayout()) {
  121.             Component var2 = this.splitPane.getLeftComponent();
  122.             Rectangle var3 = var2.getBounds();
  123.             if (this.orientation == 1) {
  124.                var2.setSize(var1 - var3.x, var3.height);
  125.             } else {
  126.                var2.setSize(var3.width, var1 - var3.y);
  127.             }
  128.  
  129.             this.splitPane.revalidate();
  130.             this.splitPane.repaint();
  131.             this.setLastDragLocation(var1);
  132.          } else {
  133.             int var4 = this.getLastDragLocation();
  134.             this.setLastDragLocation(var1);
  135.             if (this.orientation == 1) {
  136.                int var5 = this.splitPane.getSize().height;
  137.                if (this.draggingHW) {
  138.                   this.nonContinuousLayoutDivider.setLocation(this.getLastDragLocation(), 0);
  139.                } else {
  140.                   this.splitPane.repaint(var4, 0, this.dividerSize, var5);
  141.                   this.splitPane.repaint(var1, 0, this.dividerSize, var5);
  142.                }
  143.             } else {
  144.                int var6 = this.splitPane.getSize().width;
  145.                if (this.draggingHW) {
  146.                   this.nonContinuousLayoutDivider.setLocation(0, this.getLastDragLocation());
  147.                } else {
  148.                   this.splitPane.repaint(0, var4, var6, this.dividerSize);
  149.                   this.splitPane.repaint(0, var1, var6, this.dividerSize);
  150.                }
  151.             }
  152.          }
  153.       }
  154.  
  155.    }
  156.  
  157.    protected void finishDraggingTo(int var1) {
  158.       this.dragDividerTo(var1);
  159.       this.setLastDragLocation(-1);
  160.       if (!this.isContinuousLayout()) {
  161.          Component var2 = this.splitPane.getLeftComponent();
  162.          Rectangle var3 = var2.getBounds();
  163.          if (this.orientation == 1) {
  164.             int var4 = this.splitPane.getSize().height;
  165.             var2.setSize(var1 - var3.x, var3.height);
  166.             if (this.draggingHW) {
  167.                this.nonContinuousLayoutDivider.setLocation(-this.dividerSize, 0);
  168.             }
  169.  
  170.             this.splitPane.paintImmediately(var1, 0, this.dividerSize, var4);
  171.          } else {
  172.             int var5 = this.splitPane.getSize().width;
  173.             var2.setSize(var3.width, var1 - var3.y);
  174.             if (this.draggingHW) {
  175.                this.nonContinuousLayoutDivider.setLocation(0, -this.dividerSize);
  176.             }
  177.  
  178.             this.splitPane.paintImmediately(0, var1, var5, this.dividerSize);
  179.          }
  180.  
  181.          this.splitPane.revalidate();
  182.          this.splitPane.repaint();
  183.       }
  184.  
  185.       this.splitPane.setLastDividerLocation(this.beginDragDividerLocation);
  186.    }
  187.  
  188.    public void finishedPaintingChildren(JSplitPane var1, Graphics var2) {
  189.       if (var1 == this.splitPane && this.getLastDragLocation() != -1 && !this.isContinuousLayout() && !this.draggingHW) {
  190.          Dimension var3 = this.splitPane.getSize();
  191.          var2.setColor(Color.darkGray);
  192.          if (this.orientation == 1) {
  193.             var2.fillRect(this.getLastDragLocation(), 0, this.dividerSize - 1, var3.height - 1);
  194.          } else {
  195.             var2.fillRect(0, this.lastDragLocation, var3.width - 1, this.dividerSize - 1);
  196.          }
  197.       }
  198.  
  199.    }
  200.  
  201.    public BasicSplitPaneDivider getDivider() {
  202.       return this.divider;
  203.    }
  204.  
  205.    protected int getDividerBorderSize() {
  206.       return 1;
  207.    }
  208.  
  209.    public int getDividerLocation(JSplitPane var1) {
  210.       return this.orientation == 1 ? this.divider.getLocation().x : this.divider.getLocation().y;
  211.    }
  212.  
  213.    public Insets getInsets(JComponent var1) {
  214.       return null;
  215.    }
  216.  
  217.    public int getLastDragLocation() {
  218.       return this.lastDragLocation;
  219.    }
  220.  
  221.    public int getMaximumDividerLocation(JSplitPane var1) {
  222.       Dimension var2 = this.splitPane.getSize();
  223.       int var3 = 0;
  224.       Component var4 = this.splitPane.getRightComponent();
  225.       if (var4 != null) {
  226.          Insets var5 = this.splitPane.getInsets();
  227.          Dimension var6 = var4.getMinimumSize();
  228.          if (this.orientation == 1) {
  229.             var3 = var2.width - var6.width;
  230.          } else {
  231.             var3 = var2.height - var6.height;
  232.          }
  233.  
  234.          var3 -= this.dividerSize + this.getDividerBorderSize();
  235.          if (var5 != null) {
  236.             if (this.orientation == 1) {
  237.                var3 += var5.left;
  238.             } else {
  239.                var3 += var5.top;
  240.             }
  241.          }
  242.       }
  243.  
  244.       return Math.max(this.getMinimumDividerLocation(this.splitPane), var3);
  245.    }
  246.  
  247.    public Dimension getMaximumSize(JComponent var1) {
  248.       return this.splitPane != null ? this.layoutManager.maximumLayoutSize(this.splitPane) : new Dimension(0, 0);
  249.    }
  250.  
  251.    public int getMinimumDividerLocation(JSplitPane var1) {
  252.       int var2 = 0;
  253.       Component var3 = this.splitPane.getLeftComponent();
  254.       if (var3 != null) {
  255.          Insets var4 = this.splitPane.getInsets();
  256.          Dimension var5 = var3.getMinimumSize();
  257.          if (this.orientation == 1) {
  258.             var2 = var5.width;
  259.          } else {
  260.             var2 = var5.height;
  261.          }
  262.  
  263.          var2 += this.getDividerBorderSize();
  264.          if (var4 != null) {
  265.             if (this.orientation == 1) {
  266.                var2 += var4.left;
  267.             } else {
  268.                var2 += var4.top;
  269.             }
  270.          }
  271.       }
  272.  
  273.       return var2;
  274.    }
  275.  
  276.    public Dimension getMinimumSize(JComponent var1) {
  277.       return this.splitPane != null ? this.layoutManager.minimumLayoutSize(this.splitPane) : new Dimension(0, 0);
  278.    }
  279.  
  280.    public Component getNonContinuousLayoutDivider() {
  281.       return this.nonContinuousLayoutDivider;
  282.    }
  283.  
  284.    public int getOrientation() {
  285.       return this.orientation;
  286.    }
  287.  
  288.    public Dimension getPreferredSize(JComponent var1) {
  289.       return this.splitPane != null ? this.layoutManager.preferredLayoutSize(this.splitPane) : new Dimension(0, 0);
  290.    }
  291.  
  292.    public JSplitPane getSplitPane() {
  293.       return this.splitPane;
  294.    }
  295.  
  296.    protected void installDefaults() {
  297.       LookAndFeel.installBorder(this.splitPane, "SplitPane.border");
  298.       if (this.divider == null) {
  299.          this.divider = this.createDefaultDivider();
  300.       }
  301.  
  302.       this.divider.setBasicSplitPaneUI(this);
  303.       this.splitPane.setDividerSize((Integer)UIManager.get("SplitPane.dividerSize"));
  304.       this.divider.setDividerSize(this.splitPane.getDividerSize());
  305.       this.splitPane.add(this.divider, "divider");
  306.       this.setOrientation(this.splitPane.getOrientation());
  307.       this.setContinuousLayout(this.splitPane.isContinuousLayout());
  308.       this.resetLayoutManager();
  309.       if (this.nonContinuousLayoutDivider == null) {
  310.          this.setNonContinuousLayoutDivider(this.createDefaultNonContinuousLayoutDivider(), true);
  311.       } else {
  312.          this.setNonContinuousLayoutDivider(this.nonContinuousLayoutDivider, true);
  313.       }
  314.  
  315.    }
  316.  
  317.    protected void installKeyboardActions() {
  318.       this.upKey = KeyStroke.getKeyStroke(38, 0);
  319.       this.splitPane.registerKeyboardAction(this.keyboardUpLeftListener, this.upKey, 1);
  320.       this.downKey = KeyStroke.getKeyStroke(40, 0);
  321.       this.splitPane.registerKeyboardAction(this.keyboardDownRightListener, this.downKey, 1);
  322.       this.leftKey = KeyStroke.getKeyStroke(37, 0);
  323.       this.splitPane.registerKeyboardAction(this.keyboardUpLeftListener, this.leftKey, 1);
  324.       this.rightKey = KeyStroke.getKeyStroke(39, 0);
  325.       this.splitPane.registerKeyboardAction(this.keyboardDownRightListener, this.rightKey, 1);
  326.       this.homeKey = KeyStroke.getKeyStroke(36, 0);
  327.       this.splitPane.registerKeyboardAction(this.keyboardHomeListener, this.homeKey, 1);
  328.       this.endKey = KeyStroke.getKeyStroke(35, 0);
  329.       this.splitPane.registerKeyboardAction(this.keyboardEndListener, this.endKey, 1);
  330.       this.dividerResizeToggleKey = KeyStroke.getKeyStroke(119, 0);
  331.       this.splitPane.registerKeyboardAction(this.keyboardResizeToggleListener, this.dividerResizeToggleKey, 1);
  332.    }
  333.  
  334.    protected void installListeners() {
  335.       if ((this.propertyChangeListener = this.createPropertyChangeListener()) != null) {
  336.          this.splitPane.addPropertyChangeListener(this.propertyChangeListener);
  337.       }
  338.  
  339.       if ((this.focusListener = this.createFocusListener()) != null) {
  340.          this.splitPane.addFocusListener(this.focusListener);
  341.       }
  342.  
  343.       this.keyboardUpLeftListener = this.createKeyboardUpLeftListener();
  344.       this.keyboardDownRightListener = this.createKeyboardDownRightListener();
  345.       this.keyboardHomeListener = this.createKeyboardHomeListener();
  346.       this.keyboardEndListener = this.createKeyboardEndListener();
  347.       this.keyboardResizeToggleListener = this.createKeyboardResizeToggleListener();
  348.    }
  349.  
  350.    public void installUI(JComponent var1) {
  351.       this.splitPane = (JSplitPane)var1;
  352.       this.dividerLocationIsSet = false;
  353.       this.dividerKeyboardResize = false;
  354.       this.installDefaults();
  355.       this.installListeners();
  356.       this.installKeyboardActions();
  357.       this.setLastDragLocation(-1);
  358.       this.splitPane.doLayout();
  359.    }
  360.  
  361.    public boolean isContinuousLayout() {
  362.       return this.continuousLayout;
  363.    }
  364.  
  365.    public void paint(Graphics var1, JComponent var2) {
  366.    }
  367.  
  368.    protected void resetLayoutManager() {
  369.       if (this.orientation == 1) {
  370.          this.layoutManager = new BasicHorizontalLayoutManager(this);
  371.       } else {
  372.          this.layoutManager = new BasicVerticalLayoutManager(this);
  373.       }
  374.  
  375.       this.splitPane.setLayout(this.layoutManager);
  376.       this.layoutManager.updateComponents();
  377.       this.splitPane.revalidate();
  378.       this.splitPane.repaint();
  379.    }
  380.  
  381.    public void resetToPreferredSizes(JSplitPane var1) {
  382.       if (this.splitPane != null) {
  383.          this.layoutManager.resetToPreferredSizes();
  384.          this.splitPane.revalidate();
  385.          this.layoutManager.layoutContainer(this.splitPane);
  386.       }
  387.  
  388.    }
  389.  
  390.    public void setContinuousLayout(boolean var1) {
  391.       this.continuousLayout = var1;
  392.    }
  393.  
  394.    public void setDividerLocation(JSplitPane var1, int var2) {
  395.       Component var3 = this.splitPane.getLeftComponent();
  396.       Component var4 = this.splitPane.getRightComponent();
  397.       if (var3 != null && var4 != null) {
  398.          Insets var5 = this.splitPane.getInsets();
  399.          if (var5 != null) {
  400.             if (this.orientation == 1) {
  401.                var3.setSize(Math.max(0, var2 - this.getDividerBorderSize() - var5.left), 10);
  402.             } else {
  403.                var3.setSize(10, Math.max(0, var2 - this.getDividerBorderSize() - var5.top));
  404.             }
  405.          } else if (this.orientation == 1) {
  406.             var3.setSize(Math.max(0, var2 - this.getDividerBorderSize()), 10);
  407.          } else {
  408.             var3.setSize(10, Math.max(0, var2 - this.getDividerBorderSize()));
  409.          }
  410.  
  411.          if (!this.dividerLocationIsSet) {
  412.             this.dividerLocationIsSet = true;
  413.          }
  414.  
  415.          this.splitPane.revalidate();
  416.          this.splitPane.repaint();
  417.       }
  418.  
  419.    }
  420.  
  421.    public void setLastDragLocation(int var1) {
  422.       this.lastDragLocation = var1;
  423.    }
  424.  
  425.    protected void setNonContinuousLayoutDivider(Component var1) {
  426.       this.setNonContinuousLayoutDivider(var1, true);
  427.    }
  428.  
  429.    protected void setNonContinuousLayoutDivider(Component var1, boolean var2) {
  430.       if (this.nonContinuousLayoutDivider != null && this.splitPane != null) {
  431.          this.splitPane.remove(this.nonContinuousLayoutDivider);
  432.       }
  433.  
  434.       this.nonContinuousLayoutDivider = var1;
  435.       if (this.nonContinuousLayoutDivider != null && this.splitPane != null) {
  436.          this.nonContinuousLayoutDivider.setLocation(-1000, -1000);
  437.          Component var3 = this.splitPane.getLeftComponent();
  438.          Component var4 = this.splitPane.getRightComponent();
  439.          int[] var5 = this.layoutManager.getSizes();
  440.          if (var3 != null) {
  441.             this.splitPane.setLeftComponent((Component)null);
  442.          }
  443.  
  444.          if (var4 != null) {
  445.             this.splitPane.setRightComponent((Component)null);
  446.          }
  447.  
  448.          this.splitPane.remove(this.divider);
  449.          this.splitPane.add(this.nonContinuousLayoutDivider, "nonContinuousDivider", this.splitPane.getComponentCount());
  450.          this.splitPane.setLeftComponent(var3);
  451.          this.splitPane.setRightComponent(var4);
  452.          this.splitPane.add(this.divider, "divider");
  453.          if (var2) {
  454.             this.layoutManager.setSizes(var5);
  455.          }
  456.  
  457.          this.splitPane.revalidate();
  458.          this.splitPane.paintImmediately(this.splitPane.getX(), this.splitPane.getY(), this.splitPane.getWidth(), this.splitPane.getHeight());
  459.       }
  460.  
  461.    }
  462.  
  463.    public void setOrientation(int var1) {
  464.       this.orientation = var1;
  465.    }
  466.  
  467.    protected void startDragging() {
  468.       Component var1 = this.splitPane.getLeftComponent();
  469.       Component var2 = this.splitPane.getRightComponent();
  470.       this.beginDragDividerLocation = this.getDividerLocation(this.splitPane);
  471.       this.draggingHW = false;
  472.       ComponentPeer var3;
  473.       if (var1 != null && (var3 = var1.getPeer()) != null && !(var3 instanceof LightweightPeer)) {
  474.          this.draggingHW = true;
  475.       } else if (var2 != null && (var3 = var2.getPeer()) != null && !(var3 instanceof LightweightPeer)) {
  476.          this.draggingHW = true;
  477.       }
  478.  
  479.       if (this.orientation == 1) {
  480.          this.setLastDragLocation(this.divider.getBounds().x);
  481.          this.dividerSize = this.divider.getSize().width + 2 * this.getDividerBorderSize();
  482.          if (!this.isContinuousLayout() && this.draggingHW) {
  483.             this.nonContinuousLayoutDivider.setBounds(this.getLastDragLocation(), 0, this.dividerSize, this.splitPane.getHeight());
  484.          }
  485.       } else {
  486.          this.setLastDragLocation(this.divider.getBounds().y);
  487.          this.dividerSize = this.divider.getSize().height + 2 * this.getDividerBorderSize();
  488.          if (!this.isContinuousLayout() && this.draggingHW) {
  489.             this.nonContinuousLayoutDivider.setBounds(0, this.getLastDragLocation(), this.splitPane.getWidth(), this.dividerSize);
  490.          }
  491.       }
  492.  
  493.    }
  494.  
  495.    protected void uninstallDefaults() {
  496.       if (this.splitPane.getLayout() == this.layoutManager) {
  497.          this.splitPane.setLayout((LayoutManager)null);
  498.       }
  499.  
  500.       if (this.nonContinuousLayoutDivider != null) {
  501.          this.splitPane.remove(this.nonContinuousLayoutDivider);
  502.       }
  503.  
  504.       LookAndFeel.uninstallBorder(this.splitPane);
  505.       this.splitPane.remove(this.divider);
  506.       this.divider.setBasicSplitPaneUI((BasicSplitPaneUI)null);
  507.       this.layoutManager = null;
  508.       this.divider = null;
  509.       this.nonContinuousLayoutDivider = null;
  510.       this.setNonContinuousLayoutDivider((Component)null);
  511.    }
  512.  
  513.    protected void uninstallKeyboardActions() {
  514.       this.splitPane.unregisterKeyboardAction(this.upKey);
  515.       this.splitPane.unregisterKeyboardAction(this.downKey);
  516.       this.splitPane.unregisterKeyboardAction(this.leftKey);
  517.       this.splitPane.unregisterKeyboardAction(this.rightKey);
  518.       this.splitPane.unregisterKeyboardAction(this.homeKey);
  519.       this.splitPane.unregisterKeyboardAction(this.endKey);
  520.       this.splitPane.unregisterKeyboardAction(this.dividerResizeToggleKey);
  521.       this.upKey = null;
  522.       this.downKey = null;
  523.       this.leftKey = null;
  524.       this.rightKey = null;
  525.       this.homeKey = null;
  526.       this.endKey = null;
  527.       this.dividerResizeToggleKey = null;
  528.    }
  529.  
  530.    protected void uninstallListeners() {
  531.       if (this.propertyChangeListener != null) {
  532.          this.splitPane.removePropertyChangeListener(this.propertyChangeListener);
  533.          this.propertyChangeListener = null;
  534.       }
  535.  
  536.       if (this.focusListener != null) {
  537.          this.splitPane.removeFocusListener(this.focusListener);
  538.          this.focusListener = null;
  539.       }
  540.  
  541.       this.keyboardUpLeftListener = null;
  542.       this.keyboardDownRightListener = null;
  543.       this.keyboardHomeListener = null;
  544.       this.keyboardEndListener = null;
  545.       this.keyboardResizeToggleListener = null;
  546.    }
  547.  
  548.    public void uninstallUI(JComponent var1) {
  549.       this.uninstallKeyboardActions();
  550.       this.uninstallListeners();
  551.       this.uninstallDefaults();
  552.       this.dividerLocationIsSet = false;
  553.       this.dividerKeyboardResize = false;
  554.       this.splitPane = null;
  555.    }
  556. }
  557.