001: /*
002: * FlatSplitPane.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package org.underworldlabs.swing;
023:
024: import java.awt.Component;
025:
026: import javax.swing.BorderFactory;
027: import javax.swing.JButton;
028: import javax.swing.JComponent;
029: import javax.swing.JScrollPane;
030: import javax.swing.JSplitPane;
031: import javax.swing.UIManager;
032:
033: import javax.swing.border.Border;
034:
035: import org.underworldlabs.swing.plaf.FlatSplitPaneUI;
036:
037: /* ----------------------------------------------------------
038: * CVS NOTE: Changes to the CVS repository prior to the
039: * release of version 3.0.0beta1 has meant a
040: * resetting of CVS revision numbers.
041: * ----------------------------------------------------------
042: */
043:
044: /**
045: * Simple JSplitPane with line borders.
046: * This is achieved simply by 'nulling' all borders, including the divider itself.
047: *
048: * @author Takis Diakoumis
049: * @version $Revision: 1.5 $
050: * @date $Date: 2006/06/03 01:23:36 $
051: */
052: public class FlatSplitPane extends JSplitPane {
053:
054: private int storedDividerLocation;
055:
056: protected static Border lineBorder;
057:
058: static {
059: lineBorder = BorderFactory.createLineBorder(UIManager
060: .getColor("controlShadow"));
061: }
062:
063: public FlatSplitPane() {
064: this (JSplitPane.HORIZONTAL_SPLIT, false, new JButton(UIManager
065: .getString("SplitPane.leftButtonText")), new JButton(
066: UIManager.getString("SplitPane.rightButtonText")));
067: }
068:
069: public FlatSplitPane(int newOrientation) {
070: this (newOrientation, false);
071: }
072:
073: public FlatSplitPane(int newOrientation, boolean newContinuousLayout) {
074: this (newOrientation, newContinuousLayout, null, null);
075: }
076:
077: public FlatSplitPane(int newOrientation,
078: Component newLeftComponent, Component newRightComponent) {
079: this (newOrientation, false, newLeftComponent, newRightComponent);
080: }
081:
082: public FlatSplitPane(int newOrientation,
083: boolean newContinuousLayout, Component newLeftComponent,
084: Component newRightComponent) {
085:
086: super (newOrientation, false, newLeftComponent,
087: newRightComponent);
088: }
089:
090: public Border getBorder() {
091: return null;
092: }
093:
094: public void updateUI() {
095: setUI(new FlatSplitPaneUI());
096: }
097:
098: public void storeDividerLocation() {
099: storedDividerLocation = getDividerLocation();
100: }
101:
102: public void storeDividerLocation(int location) {
103: storedDividerLocation = location;
104: }
105:
106: public void restoreDividerLocation() {
107: if (storedDividerLocation > 0) {
108: setDividerLocation(storedDividerLocation);
109: } else {
110: resetToPreferredSizes();
111: }
112: }
113:
114: /*
115: public void setTopComponent(Component comp) {
116: setComponentBorder(comp);
117: super.setTopComponent(comp);
118: }
119:
120: public void setLeftComponent(Component comp) {
121: setComponentBorder(comp);
122: super.setLeftComponent(comp);
123: }
124:
125: public void setRightComponent(Component comp) {
126: setComponentBorder(comp);
127: super.setRightComponent(comp);
128: }
129:
130: public void setBottomComponent(Component comp) {
131: setComponentBorder(comp);
132: super.setBottomComponent(comp);
133: }
134: */
135: protected void setComponentBorder(Component comp) {
136:
137: // TODO: FIX ME!!! ???
138:
139: // this is a little untidy
140:
141: boolean hasScroller = false;
142:
143: if (comp instanceof JComponent) {
144:
145: JComponent jComponent = (JComponent) comp;
146: Component[] components = jComponent.getComponents();
147:
148: for (int i = 0; i < components.length; i++) {
149:
150: if (components[i] instanceof JScrollPane) {
151: hasScroller = true;
152: JScrollPane scroller = (JScrollPane) components[i];
153: scroller.setBorder(lineBorder);
154: break;
155: }
156:
157: }
158:
159: if (!hasScroller) {
160: jComponent.setBorder(lineBorder);
161: }
162:
163: }
164:
165: }
166:
167: public int getStoredDividerLocation() {
168: return storedDividerLocation;
169: }
170:
171: }
|