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.BorderLayout;
025: import java.awt.Component;
026: import java.awt.LayoutManager;
027:
028: import javax.swing.BorderFactory;
029: import javax.swing.JPanel;
030:
031: import org.beryl.gui.GUIException;
032: import org.beryl.gui.Widget;
033: import org.beryl.gui.WidgetInfo;
034:
035: import cz.autel.dmi.HIGLayout;
036:
037: public class Panel extends Widget {
038: protected static WidgetInfo panelInfo = null;
039: protected JPanel panel = null;
040:
041: static {
042: panelInfo = new WidgetInfo(Panel.class, widgetInfo);
043: panelInfo.addProperty("border", "border", BorderFactory
044: .createEmptyBorder());
045: panelInfo.addProperty("layout", "layout", new BorderLayout());
046: };
047:
048: public Panel(Widget parent, String name) throws GUIException {
049: super (parent, name);
050: panel = new JPanel(new BorderLayout());
051: }
052:
053: public void addChild(Widget widget, Object constraint)
054: throws GUIException {
055: Component component = widget.getWidget();
056: if (constraint == null)
057: constraint = BorderLayout.CENTER;
058: panel.add(component, constraint);
059: addChild(widget);
060: }
061:
062: public void setProperty(String name, Object value)
063: throws GUIException {
064: if ("spacing".equals(name)) {
065: int border = ((Integer) value).intValue();
066: panel.setBorder(BorderFactory.createEmptyBorder(border,
067: border, border, border));
068: } else {
069: super .setProperty(name, value);
070: }
071: }
072:
073: public void recreateLayout() throws GUIException {
074: LayoutManager manager = panel.getLayout();
075: if (manager instanceof HIGLayout && !(this instanceof Group)) {
076: /* Recreate the hig layout. Why is this needed? */
077: HIGLayout layout = (HIGLayout) manager;
078: HIGLayout newLayout = new HIGLayout(layout.getWidths(),
079: layout.getHeights());
080: for (int i = 1; i < layout.getColumnWeights().length; i++)
081: newLayout.setColumnWeight(i,
082: layout.getColumnWeights()[i]);
083: for (int i = 1; i < layout.getRowWeights().length; i++)
084: newLayout.setRowWeight(i, layout.getRowWeights()[i]);
085: panel.setLayout(newLayout);
086: }
087: revalidate();
088: }
089:
090: public void removeChildWidget(Widget widget) throws GUIException {
091: panel.remove(widget.getWidget());
092: super .removeChildWidget(widget);
093: }
094:
095: public Component getWidget() {
096: return panel;
097: }
098:
099: public WidgetInfo getWidgetInfo() {
100: return panelInfo;
101: }
102: }
|