001: /*
002: * Beryl - A web platform based on XML, XSLT and Java
003: * This file is part of the Beryl XML GUI
004: *
005: * Copyright (C) 2004 Wenzel Jakob <wazlaf@tigris.org>
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011:
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-3107 USA
020: */
021:
022: package org.beryl.gui.widgets;
023:
024: import java.awt.Component;
025:
026: import javax.swing.JSplitPane;
027:
028: import org.beryl.gui.GUIException;
029: import org.beryl.gui.Widget;
030: import org.beryl.gui.WidgetInfo;
031:
032: public class SplitPane extends Widget {
033: private static WidgetInfo splitPaneInfo = null;
034: private JSplitPane splitPane = null;
035: private Widget first = null;
036: private Widget second = null;
037:
038: static {
039: splitPaneInfo = new WidgetInfo(SplitPane.class, widgetInfo);
040: splitPaneInfo.addProperty("orientation", "string", "h");
041: splitPaneInfo.addProperty("resizeWeight", "double", new Double(
042: 0.5));
043: };
044:
045: public SplitPane(Widget parent, String name) throws GUIException {
046: super (parent, name);
047: splitPane = new JSplitPane();
048: splitPane.setOneTouchExpandable(true);
049: splitPane.setContinuousLayout(true);
050: }
051:
052: public void setProperty(String name, Object value)
053: throws GUIException {
054: if ("orientation".equals(name)) {
055: String orientation = (String) value;
056:
057: if (orientation.equals("h")) {
058: splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
059: } else if (orientation.equals("v")) {
060: splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
061: } else {
062: throw new GUIException("Invalid split pane orientation");
063: }
064: } else {
065: super .setProperty(name, value);
066: }
067: }
068:
069: public void addChild(Widget widget, Object constraint)
070: throws GUIException {
071: if (first == null) {
072: if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT)
073: splitPane.setLeftComponent(widget.getWidget());
074: else
075: splitPane.setTopComponent(widget.getWidget());
076: first = widget;
077: addChild(widget);
078: } else if (second == null) {
079: if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT)
080: splitPane.setRightComponent(widget.getWidget());
081: else
082: splitPane.setBottomComponent(widget.getWidget());
083: second = widget;
084: addChild(widget);
085: } else {
086: throw new GUIException(
087: "A SplitPane cannot have more than two children");
088: }
089: }
090:
091: public void removeChildWidget(Widget widget) throws GUIException {
092: if (widget == first)
093: first = null;
094: else if (widget == second)
095: second = null;
096: super .removeChildWidget(widget);
097: }
098:
099: public Component getWidget() {
100: return splitPane;
101: }
102:
103: public WidgetInfo getWidgetInfo() {
104: return splitPaneInfo;
105: }
106: }
|