001: /* SwingML
002: * Copyright (C) 2002 Robert Morris.
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 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
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: *
019: * Authors:
020: * Robert Morris <robertj@morris.net>
021: *
022: */
023:
024: package org.swingml.component;
025:
026: import java.awt.Component;
027: import java.awt.Container;
028: import java.awt.GridBagLayout;
029: import java.util.Vector;
030:
031: import javax.swing.JPanel;
032: import javax.swing.border.BevelBorder;
033: import javax.swing.border.EtchedBorder;
034: import javax.swing.border.TitledBorder;
035:
036: import org.swingml.Constants;
037: import org.swingml.RenderingThread;
038: import org.swingml.SubmittingThread;
039: import org.swingml.event.EventHandler;
040: import org.swingml.model.GridBagPanelModel;
041:
042: /**
043: * This class provides the actual instantiation and management of the
044: * <GRIDBAG-PANEL> tag on the rendered form. This class operates
045: * essentially as a SwingML-style wrapper around a standard JPanel
046: * that lays out its child components using GridBagLayout.
047: * The overridden add() method accepts GridBagRowComponents that in
048: * turn contain GridBagCell components which themselves contain the actual
049: * references to the component to display within the GridBagPanelComponent
050: * instance. The detailed parameters regarding the layout settings for each
051: * component are hierarchically stored within the GridBagRowModel and GridBagCellModel
052: * components passed in during the add() invocation.
053: */
054: public class GridBagPanelComponent extends JPanel {
055: private EventHandler eventHandler = EventHandler.getInstance();
056: private GridBagPanelModel m_model = null;
057: private Vector m_rows = new Vector();
058:
059: /**
060: * This overridden method handles the addition of GridBagRow components.
061: * It is also important to note that after rendering is complete, it is possible
062: * for InvokableEvent instances to call add() with other component instances.
063: *
064: * @param component The component to add to the current GridBagPanelComponent instance.
065: *
066: * @return The component that was added to the GridBagPanelComponent.
067: *
068: * @see org.swingml.component.GridBagRowComponent
069: *
070: */
071: public Component add(Component aComponent) {
072: if (aComponent instanceof GridBagRowComponent) {
073: GridBagRowComponent theComponent = (GridBagRowComponent) aComponent;
074: theComponent.setParentPanel(this );
075: this .m_rows.add(aComponent);
076: } else {
077: super .add(aComponent);
078: }
079: return aComponent;
080: }
081:
082: /**
083: * @see javax.swing.JPanel#add(Component, Object)
084: */
085: public void add(Component aComponent, Object aConstraints) {
086: super .add(aComponent, aConstraints);
087: }
088:
089: public void submit(String anAddress) {
090: SubmittingThread theThread = new SubmittingThread(anAddress,
091: this , this , true);
092: theThread.start();
093: }
094:
095: public void submit(String anAddress, String aTargetContainer,
096: boolean aRepaint) {
097: Component theTargetContainer = this .eventHandler
098: .findActionTarget(super .getTopLevelAncestor(),
099: aTargetContainer);
100: SubmittingThread theThread = new SubmittingThread(anAddress,
101: this , (Container) theTargetContainer, aRepaint);
102: theThread.start();
103: }
104:
105: public void render(String aUrl, String aParent) {
106: Component theParentComponent = this .eventHandler
107: .findActionTarget(super .getTopLevelAncestor(), aParent);
108: RenderingThread theThread = new RenderingThread(aUrl,
109: (Container) theParentComponent);
110: theThread.start();
111: }
112:
113: /**
114: * Constructor for GridBagPanelComponent. This
115: * constructor essentially sets the layout to GridBagLayout
116: * and assigns the necessary model information to properties
117: * of this component.
118: *
119: * @param model A valid reference to an instance of the GridBagPanelModel class.
120: *
121: * @see org.swingml.model.GridBagPanelModel
122: */
123: public GridBagPanelComponent(GridBagPanelModel aModel) {
124: this .m_model = aModel;
125: super .setLayout(new GridBagLayout());
126: super .setName(this .m_model.getName());
127: String theBorder = this .m_model.getBorder();
128: String theTitle = this .m_model.getTitle();
129: int theBevelType = this .m_model.getBevelType();
130:
131: if (theBorder.equalsIgnoreCase(Constants.ETCHEDBORDER)) {
132: if (theTitle == null) {
133: super .setBorder(new EtchedBorder());
134: } else {
135: super .setBorder(new TitledBorder(new EtchedBorder(),
136: theTitle));
137: }
138: }
139: if (theBorder.equalsIgnoreCase(Constants.BEVELBORDER)) {
140: if (theTitle == null) {
141: super .setBorder(new BevelBorder(theBevelType));
142: } else {
143: super .setBorder(new TitledBorder(new BevelBorder(
144: theBevelType), theTitle));
145: }
146: }
147: }
148: }
|