001: /*
002: * WbSplitPane.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui.components;
013:
014: import java.awt.Component;
015: import javax.swing.JSplitPane;
016: import javax.swing.border.Border;
017: import javax.swing.plaf.ComponentUI;
018: import javax.swing.plaf.SplitPaneUI;
019: import javax.swing.plaf.basic.BasicSplitPaneDivider;
020: import javax.swing.plaf.basic.BasicSplitPaneUI;
021: import workbench.gui.WbSwingUtilities;
022:
023: /**
024: * A JSplitPane which restores the divider size after a UI Change
025: * and an updateUI()
026: *
027: * @author support@sql-workbench.net
028: */
029: public class WbSplitPane extends JSplitPane {
030: public int DEFAULT_DIVIDER_SIZE = 7;
031:
032: public WbSplitPane() {
033: super ();
034: this .initDefaults();
035: }
036:
037: public WbSplitPane(int orientation) {
038: super (orientation);
039: this .initDefaults();
040: }
041:
042: public WbSplitPane(int newOrientation, boolean newContinuousLayout) {
043: super (newOrientation, newContinuousLayout);
044: this .initDefaults();
045: }
046:
047: public WbSplitPane(int newOrientation, boolean newContinuousLayout,
048: Component newLeftComponent, Component newRightComponent) {
049: super (newOrientation, newContinuousLayout, newLeftComponent,
050: newRightComponent);
051: this .initDefaults();
052: }
053:
054: public WbSplitPane(int newOrientation, Component newLeftComponent,
055: Component newRightComponent) {
056: super (newOrientation, newLeftComponent, newRightComponent);
057: this .initDefaults();
058: }
059:
060: public void updateUI() {
061: int divider = this .getDividerSize();
062: this .setDividerSize(divider);
063: //super.updateUI();
064: if (this .getUI() == null) {
065: super .setUI(new WbSplitPaneUI());
066: }
067: revalidate();
068: }
069:
070: public void setUI(ComponentUI newUI) {
071: int divider = this .getDividerSize();
072: super .setUI(newUI);
073: this .setDividerSize(divider);
074: }
075:
076: public void setOneTouchTooltip(String tip) {
077: SplitPaneUI currentUI = getUI();
078: if (currentUI instanceof WbSplitPaneUI) {
079: ((WbSplitPaneUI) currentUI).setOneTouchTooltip(tip);
080: }
081: }
082:
083: private void initDefaults() {
084: this .setDividerSize(DEFAULT_DIVIDER_SIZE);
085: this .setBorder(WbSwingUtilities.EMPTY_BORDER);
086: //this.setDividerBorder(WbSwingUtilities.EMPTY_BORDER);
087: this .setContinuousLayout(true);
088: }
089:
090: public Border getDividerBorder() {
091: Border result = null;
092: try {
093: BasicSplitPaneUI currentUI = (BasicSplitPaneUI) this
094: .getUI();
095: BasicSplitPaneDivider div = currentUI.getDivider();
096: result = div.getBorder();
097: } catch (Exception e) {
098: result = null;
099: }
100: return result;
101: }
102:
103: public void setDividerBorder(Border newBorder) {
104: try {
105: int divider = this .getDividerSize();
106: BasicSplitPaneUI currentUI = (BasicSplitPaneUI) this
107: .getUI();
108: BasicSplitPaneDivider div = currentUI.getDivider();
109: div.setBorder(newBorder);
110: this .setDividerSize(divider);
111: } catch (Exception e) {
112: }
113: }
114: }
|