home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.basic;
-
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.JSplitPane;
- import com.sun.java.swing.border.Border;
- import com.sun.java.swing.plaf.ComponentUI;
- import com.sun.java.swing.plaf.SplitPaneUI;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.LayoutManager;
- import java.awt.Rectangle;
- import java.awt.peer.ComponentPeer;
- import java.awt.peer.LightweightPeer;
- import java.beans.PropertyChangeEvent;
- import java.beans.PropertyChangeListener;
- import java.io.Serializable;
- import java.util.EventObject;
-
- public class BasicSplitPaneUI extends SplitPaneUI implements PropertyChangeListener, Serializable {
- protected static final String NON_CONTINUOUS_DIVIDER = "nonContinuousDivider";
- protected JSplitPane splitPane;
- private int orientation;
- protected BasicHorizontalLayoutManager layoutManager;
- private boolean continuousLayout;
- protected BasicSplitPaneDivider divider;
- private int lastDragLocation;
- protected int dividerSize;
- protected boolean createdBorder;
- protected Component nonContinuousLayoutDivider;
- protected boolean draggingHW;
- protected int beginDragDividerLocation;
-
- public int getOrientation() {
- return this.orientation;
- }
-
- public void setOrientation(int var1) {
- this.orientation = var1;
- }
-
- public boolean isContinuousLayout() {
- return this.continuousLayout;
- }
-
- public void setContinuousLayout(boolean var1) {
- this.continuousLayout = var1;
- }
-
- public int getLastDragLocation() {
- return this.lastDragLocation;
- }
-
- public void setLastDragLocation(int var1) {
- this.lastDragLocation = var1;
- }
-
- public static ComponentUI createUI(JComponent var0) {
- return new BasicSplitPaneUI();
- }
-
- public BasicSplitPaneUI() {
- this.setLastDragLocation(-1);
- }
-
- public void installUI(JComponent var1) {
- this.installDefaults(var1);
- this.installListeners(var1);
- }
-
- protected void installDefaults(JComponent var1) {
- this.splitPane = (JSplitPane)var1;
- this.setOrientation(this.splitPane.getOrientation());
- this.setContinuousLayout(this.splitPane.isContinuousLayout());
- Border var2 = this.splitPane.getBorder();
- if (var2 == null) {
- var2 = this.createDefaultBorder();
- if (var2 != null) {
- this.splitPane.setBorder(var2);
- this.createdBorder = true;
- }
- } else {
- this.createdBorder = false;
- }
-
- if (this.divider == null) {
- this.divider = this.createDefaultDivider();
- }
-
- this.divider.setBasicSplitPaneUI(this);
- this.divider.setDividerSize(this.splitPane.getDividerSize());
- this.splitPane.add(this.divider, "divider");
- this.resetLayoutManager();
- if (this.nonContinuousLayoutDivider == null) {
- this.setNonContinuousLayoutDivider(this.createDefaultNonContinuousLayoutDivider(), true);
- } else {
- this.setNonContinuousLayoutDivider(this.nonContinuousLayoutDivider, true);
- }
- }
-
- protected void installListeners(JComponent var1) {
- this.splitPane.addPropertyChangeListener(this);
- }
-
- public void uninstallUI(JComponent var1) {
- this.uninstallListeners(var1);
- this.uninstallDefaults(var1);
- }
-
- protected void uninstallListeners(JComponent var1) {
- this.splitPane.removePropertyChangeListener(this);
- }
-
- protected void uninstallDefaults(JComponent var1) {
- if (this.splitPane.getLayout() == this.layoutManager) {
- this.splitPane.setLayout((LayoutManager)null);
- }
-
- if (this.createdBorder) {
- this.splitPane.setBorder((Border)null);
- }
-
- if (this.nonContinuousLayoutDivider != null) {
- this.splitPane.remove(this.nonContinuousLayoutDivider);
- }
-
- this.splitPane.remove(this.divider);
- this.divider.setBasicSplitPaneUI((BasicSplitPaneUI)null);
- this.splitPane = null;
- this.layoutManager = null;
- this.setNonContinuousLayoutDivider((Component)null);
- }
-
- protected Border createDefaultBorder() {
- return new BasicSplitPaneBorder(this);
- }
-
- public void propertyChange(PropertyChangeEvent var1) {
- if (((EventObject)var1).getSource() == this.splitPane) {
- String var2 = var1.getPropertyName();
- if (var2.equals("orientation")) {
- this.orientation = this.splitPane.getOrientation();
- this.resetLayoutManager();
- return;
- }
-
- if (var2.equals("continuousLayout")) {
- this.setContinuousLayout(this.splitPane.isContinuousLayout());
- if (!this.isContinuousLayout()) {
- if (this.nonContinuousLayoutDivider == null) {
- this.setNonContinuousLayoutDivider(this.createDefaultNonContinuousLayoutDivider(), true);
- return;
- }
-
- if (this.nonContinuousLayoutDivider.getParent() == null) {
- this.setNonContinuousLayoutDivider(this.nonContinuousLayoutDivider, true);
- return;
- }
- }
- } else {
- if (var2.equals("border")) {
- this.createdBorder = false;
- return;
- }
-
- if (var2.equals("dividerSize")) {
- this.divider.setDividerSize(this.splitPane.getDividerSize());
- this.layoutManager.resetSizeAt(2);
- this.splitPane.invalidate();
- this.splitPane.validate();
- }
- }
- }
-
- }
-
- public void setDivider(BasicSplitPaneDivider var1) {
- if (var1 != null) {
- if (this.splitPane != null) {
- if (this.divider != null) {
- this.splitPane.remove(this.divider);
- }
-
- this.divider = var1;
- this.splitPane.add(this.divider, "divider");
- this.layoutManager.resetSizeAt(2);
- this.splitPane.invalidate();
- this.splitPane.validate();
- } else {
- this.divider = var1;
- }
-
- this.divider.setBasicSplitPaneUI(this);
- }
-
- }
-
- public BasicSplitPaneDivider getDivider() {
- return this.divider;
- }
-
- protected Component createDefaultNonContinuousLayoutDivider() {
- return new 1(this);
- }
-
- protected void setNonContinuousLayoutDivider(Component var1) {
- this.setNonContinuousLayoutDivider(var1, true);
- }
-
- protected void setNonContinuousLayoutDivider(Component var1, boolean var2) {
- if (this.nonContinuousLayoutDivider != null && this.splitPane != null) {
- this.splitPane.remove(this.nonContinuousLayoutDivider);
- }
-
- this.nonContinuousLayoutDivider = var1;
- if (this.nonContinuousLayoutDivider != null && this.splitPane != null) {
- this.nonContinuousLayoutDivider.setLocation(-1000, -1000);
- Component var3 = this.splitPane.getLeftComponent();
- Component var4 = this.splitPane.getRightComponent();
- int[] var5 = this.layoutManager.getSizes();
- if (var3 != null) {
- this.splitPane.setLeftComponent((Component)null);
- }
-
- if (var4 != null) {
- this.splitPane.setRightComponent((Component)null);
- }
-
- this.splitPane.remove(this.divider);
- this.splitPane.add(this.nonContinuousLayoutDivider, "nonContinuousDivider", this.splitPane.getComponentCount());
- this.splitPane.setLeftComponent(var3);
- this.splitPane.setRightComponent(var4);
- this.splitPane.add(this.divider, "divider");
- if (var2) {
- this.layoutManager.setSizes(var5);
- }
-
- this.splitPane.validate();
- this.splitPane.paintImmediately(this.splitPane.getX(), this.splitPane.getY(), this.splitPane.getWidth(), this.splitPane.getHeight());
- }
-
- }
-
- public Component getNonContinuousLayoutDivider() {
- return this.nonContinuousLayoutDivider;
- }
-
- public JSplitPane getSplitPane() {
- return this.splitPane;
- }
-
- public BasicSplitPaneDivider createDefaultDivider() {
- return new BasicSplitPaneDivider(this);
- }
-
- public void resetToPreferredSizes() {
- if (this.splitPane != null) {
- this.layoutManager.resetToPreferredSizes();
- this.splitPane.validate();
- this.layoutManager.layoutContainer(this.splitPane);
- }
-
- }
-
- public void setDividerLocation(int var1) {
- Component var2 = this.splitPane.getLeftComponent();
- Component var3 = this.splitPane.getRightComponent();
- if (var2 != null && var3 != null) {
- Insets var4 = this.splitPane.getInsets();
- if (var4 != null) {
- if (this.orientation == 1) {
- var2.setSize(Math.max(0, var1 - var4.left), 10);
- } else {
- var2.setSize(10, Math.max(0, var1 - var4.top));
- }
- } else if (this.orientation == 1) {
- var2.setSize(Math.max(0, var1), 10);
- } else {
- var2.setSize(10, Math.max(0, var1));
- }
-
- this.splitPane.validate();
- this.splitPane.repaint();
- }
-
- }
-
- public int getDividerLocation() {
- return this.orientation == 1 ? this.divider.getLocation().x : this.divider.getLocation().y;
- }
-
- public int getMinimumDividerLocation() {
- int var1 = 0;
- Component var2 = this.splitPane.getLeftComponent();
- if (var2 != null) {
- Insets var3 = this.splitPane.getInsets();
- Dimension var4 = var2.getMinimumSize();
- if (this.orientation == 1) {
- var1 = var4.width;
- } else {
- var1 = var4.height;
- }
-
- var1 += this.getDividerBorderSize();
- if (var3 != null) {
- if (this.orientation == 1) {
- var1 += var3.left;
- } else {
- var1 += var3.top;
- }
- }
- }
-
- return var1;
- }
-
- public int getMaximumDividerLocation() {
- Dimension var1 = this.splitPane.getSize();
- int var2 = 0;
- Component var3 = this.splitPane.getRightComponent();
- if (var3 != null) {
- Insets var4 = this.splitPane.getInsets();
- Dimension var5 = var3.getMinimumSize();
- if (this.orientation == 1) {
- var2 = var1.width - var5.width;
- } else {
- var2 = var1.height - var5.height;
- }
-
- var2 -= this.dividerSize + this.getDividerBorderSize();
- if (var4 != null) {
- if (this.orientation == 1) {
- var2 += var4.left;
- } else {
- var2 += var4.top;
- }
- }
- }
-
- return Math.max(this.getMinimumDividerLocation(), var2);
- }
-
- public void finishedPaintingChildren(JSplitPane var1, Graphics var2) {
- if (var1 == this.splitPane && this.getLastDragLocation() != -1 && !this.isContinuousLayout() && !this.draggingHW) {
- Dimension var3 = this.splitPane.getSize();
- var2.setColor(Color.darkGray);
- if (this.orientation == 1) {
- var2.fillRect(this.getLastDragLocation(), 0, this.dividerSize - 1, var3.height - 1);
- return;
- }
-
- var2.fillRect(0, this.lastDragLocation, var3.width - 1, this.dividerSize - 1);
- }
-
- }
-
- public void paint(Graphics var1, JComponent var2) {
- }
-
- public Dimension getPreferredSize(JComponent var1) {
- return this.splitPane != null ? this.layoutManager.preferredLayoutSize(this.splitPane) : new Dimension(0, 0);
- }
-
- public Dimension getMinimumSize(JComponent var1) {
- return this.splitPane != null ? this.layoutManager.minimumLayoutSize(this.splitPane) : new Dimension(0, 0);
- }
-
- public Dimension getMaximumSize(JComponent var1) {
- return this.splitPane != null ? this.layoutManager.maximumLayoutSize(this.splitPane) : new Dimension(0, 0);
- }
-
- public Insets getInsets(JComponent var1) {
- return null;
- }
-
- protected void resetLayoutManager() {
- if (this.orientation == 1) {
- this.layoutManager = new BasicHorizontalLayoutManager(this);
- } else {
- this.layoutManager = new BasicVerticalLayoutManager(this);
- }
-
- this.splitPane.setLayout(this.layoutManager);
- this.layoutManager.updateComponents();
- this.splitPane.validate();
- this.splitPane.repaint();
- }
-
- protected void startDragging() {
- Component var1 = this.splitPane.getLeftComponent();
- Component var2 = this.splitPane.getRightComponent();
- this.beginDragDividerLocation = this.getDividerLocation();
- this.draggingHW = false;
- ComponentPeer var3;
- if (var1 != null && (var3 = var1.getPeer()) != null && !(var3 instanceof LightweightPeer)) {
- this.draggingHW = true;
- } else if (var2 != null && (var3 = var2.getPeer()) != null && !(var3 instanceof LightweightPeer)) {
- this.draggingHW = true;
- }
-
- if (this.orientation == 1) {
- this.setLastDragLocation(this.divider.getBounds().x);
- this.dividerSize = this.divider.getSize().width + 2 * this.getDividerBorderSize();
- if (!this.isContinuousLayout() && this.draggingHW) {
- this.nonContinuousLayoutDivider.setBounds(this.getLastDragLocation(), 0, this.dividerSize, this.splitPane.getHeight());
- return;
- }
- } else {
- this.setLastDragLocation(this.divider.getBounds().y);
- this.dividerSize = this.divider.getSize().height + 2 * this.getDividerBorderSize();
- if (!this.isContinuousLayout() && this.draggingHW) {
- this.nonContinuousLayoutDivider.setBounds(0, this.getLastDragLocation(), this.splitPane.getWidth(), this.dividerSize);
- }
- }
-
- }
-
- protected void dragDividerTo(int var1) {
- if (this.getLastDragLocation() != var1) {
- if (this.isContinuousLayout()) {
- Component var4 = this.splitPane.getLeftComponent();
- Rectangle var6 = var4.getBounds();
- if (this.orientation == 1) {
- var4.setSize(var1 - var6.x, var6.height);
- } else {
- var4.setSize(var6.width, var1 - var6.y);
- }
-
- this.splitPane.validate();
- this.splitPane.repaint();
- this.setLastDragLocation(var1);
- return;
- }
-
- int var2 = this.getLastDragLocation();
- this.setLastDragLocation(var1);
- if (this.orientation == 1) {
- int var5 = this.splitPane.getSize().height;
- if (this.draggingHW) {
- this.nonContinuousLayoutDivider.setLocation(this.getLastDragLocation(), 0);
- return;
- }
-
- this.splitPane.repaint(var2, 0, this.dividerSize, var5);
- this.splitPane.repaint(var1, 0, this.dividerSize, var5);
- return;
- }
-
- int var3 = this.splitPane.getSize().width;
- if (this.draggingHW) {
- this.nonContinuousLayoutDivider.setLocation(0, this.getLastDragLocation());
- return;
- }
-
- this.splitPane.repaint(0, var2, var3, this.dividerSize);
- this.splitPane.repaint(0, var1, var3, this.dividerSize);
- }
-
- }
-
- protected void finishDraggingTo(int var1) {
- this.dragDividerTo(var1);
- this.setLastDragLocation(-1);
- if (!this.isContinuousLayout()) {
- Component var2 = this.splitPane.getLeftComponent();
- Rectangle var3 = var2.getBounds();
- if (this.orientation == 1) {
- int var4 = this.splitPane.getSize().height;
- var2.setSize(var1 - var3.x, var3.height);
- if (this.draggingHW) {
- this.nonContinuousLayoutDivider.setLocation(-this.dividerSize, 0);
- }
-
- this.splitPane.paintImmediately(var1, 0, this.dividerSize, var4);
- } else {
- int var5 = this.splitPane.getSize().width;
- var2.setSize(var3.width, var1 - var3.y);
- if (this.draggingHW) {
- this.nonContinuousLayoutDivider.setLocation(0, -this.dividerSize);
- }
-
- this.splitPane.paintImmediately(0, var1, var5, this.dividerSize);
- }
-
- this.splitPane.validate();
- this.splitPane.repaint();
- }
-
- this.splitPane.setLastDividerLocation(this.beginDragDividerLocation);
- }
-
- protected int getDividerBorderSize() {
- return 1;
- }
-
- // $FF: synthetic method
- static int access$0(BasicSplitPaneUI var0) {
- return var0.orientation;
- }
- }
-