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