001: /*
002: * Copyright (C) 2004 TiongHiang Lee
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: * Email: thlee@onemindsoft.org
019: */
020:
021: package org.onemind.swingweb.client.gwt.widget;
022:
023: import com.google.gwt.user.client.DOM;
024: import com.google.gwt.user.client.ui.*;
025:
026: public class CopyOfSplitPane extends AbsolutePanel implements
027: MouseListener, IContainer {
028:
029: public static final int HORIZONTAL_SPLIT = 0, VERTICAL_SPLIT = 1;
030:
031: private int _orientation;
032:
033: private ComponentLayout _layout = new ComponentLayout();
034:
035: private SimplePanel _firstContainer = new SimplePanel(),
036: _secondContainer = new SimplePanel();
037:
038: private CellPanel _dividerHalf;
039:
040: private Widget _firstComponent, _secondComponent;
041:
042: private int _dividerSize = 10, _dividerLoc = 100;
043:
044: private boolean capture = false;
045:
046: private int startX, startY;
047:
048: private class Divider extends MousePanel {
049:
050: public Divider() {
051: setStyleName("splitpane-divider");
052: }
053: }
054:
055: public CopyOfSplitPane() {
056: this (VERTICAL_SPLIT);
057: }
058:
059: private Divider _divider = new Divider();
060:
061: public CopyOfSplitPane(int orientation) {
062: _orientation = orientation;
063: _divider.addMouseListener(this );
064: DOM.setStyleAttribute(_firstContainer.getElement(), "zOrder",
065: "-1");
066: initPanels();
067: }
068:
069: private void initPanels() {
070: clear();
071: switch (_orientation) {
072: case HORIZONTAL_SPLIT:
073: add(_firstContainer, 0, 0);
074: _dividerHalf = new HorizontalPanel();
075: _dividerHalf.setHeight("100%");
076: _dividerHalf.add(_divider);
077: _dividerHalf.add(_secondContainer);
078: add(_dividerHalf, 0, 0);
079: break;
080: case VERTICAL_SPLIT:
081: add(_firstContainer, 0, 0);
082: _dividerHalf = new VerticalPanel();
083: _dividerHalf.setWidth("100%");
084: _dividerHalf.add(_divider);
085: _dividerHalf.add(_secondContainer);
086: add(_dividerHalf, 0, 0);
087: break;
088: }
089: setDividerLoc(_dividerLoc);
090: }
091:
092: public void setFirstComponent(Widget w) {
093: if (_firstComponent != w) {
094: if (_firstComponent != null) {
095: _firstContainer.remove(_firstComponent);
096: }
097: _firstComponent = w;
098: _firstContainer.setWidget(w);
099: }
100: }
101:
102: public void setOrientation(int splitStyle) {
103: if (_orientation != splitStyle) {
104: _orientation = splitStyle;
105: initPanels();
106: }
107: }
108:
109: public void setSecondComponent(Widget w) {
110: if (_secondComponent != w) {
111: if (_secondComponent != null) {
112: _secondContainer.remove(w);
113: }
114: _secondComponent = w;
115: _secondContainer.setWidget(w);
116: }
117: }
118:
119: public void setDividerLoc(int loc) {
120: _dividerLoc = loc;
121: switch (_orientation) {
122: case HORIZONTAL_SPLIT:
123: _divider.setHeight("100%");
124: _divider.setWidth(String.valueOf(_dividerSize));
125: setWidgetPosition(_dividerHalf, loc, 0);
126: //setWidgetPosition(_secondContainer, loc + _dividerSize + 3, 0);
127: break;
128: case VERTICAL_SPLIT:
129: _divider.setHeight(String.valueOf(_dividerSize));
130: _divider.setWidth("100%");
131: setWidgetPosition(_dividerHalf, 0, loc);
132: //setWidgetPosition(_secondContainer, 0, loc + _dividerSize + 3);
133: break;
134: }
135: }
136:
137: public void setDividerSize(int size) {
138: _dividerSize = size;
139: setDividerLoc(_dividerLoc);
140: }
141:
142: public void onMouseDown(Widget sender, int x, int y) {
143: capture = true;
144: DOM.setCapture(sender.getElement());
145: startX = x;
146: startY = y;
147: }
148:
149: public void onMouseEnter(Widget sender) {
150: // TODO Auto-generated method stub
151: }
152:
153: public void onMouseLeave(Widget sender) {
154: }
155:
156: public void onMouseMove(Widget sender, int x, int y) {
157: if (capture) {
158: switch (_orientation) {
159: case HORIZONTAL_SPLIT:
160: int absX = getWidgetLeft(_dividerHalf);
161: int newX = absX + (x - startX);
162: setDividerLoc(newX);
163: break;
164: case VERTICAL_SPLIT:
165: int absY = getWidgetTop(_dividerHalf);
166: int newY = absY + (y - startY);
167: setDividerLoc(newY);
168: break;
169: }
170: }
171: }
172:
173: public void onMouseUp(Widget sender, int x, int y) {
174: capture = false;
175: DOM.releaseCapture(sender.getElement());
176: }
177:
178: public void addChild(Widget widget, CellInfo info) {
179: throw new IllegalArgumentException("Shouldn't be called");
180: }
181:
182: public ComponentLayout getLayout() {
183: return _layout;
184: }
185:
186: public void removeChild(Widget child) {
187: throw new IllegalArgumentException("Shouldn't be called");
188: }
189: }
|