01: /* SwingML
02: * Copyright (C) 2002 Robert Morris.
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the
16: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17: * Boston, MA 02111-1307, USA.
18: *
19: * Authors:
20: * Robert Morris <robertj@morris.net>
21: *
22: */
23: package org.swingml.component;
24:
25: import java.awt.*;
26:
27: import org.swingml.model.*;
28:
29: /**
30: * This class simply contains necessary GridBagLayout formatting instructions as
31: * well as a list of references to 0 or more GridBagCellComponent instances. As
32: * the components contained within this hierarchy are added to the enclosing
33: * GridBagPanelComponent instance, the formatting instructions are
34: * hierarchically applied to the layout.
35: *
36: * @see org.swingml.component.GridBagPanelComponent
37: * @see org.swingml.component.GridBagCellComponent
38: */
39: public class GridBagRowComponent extends Container {
40:
41: private int m_cols = 0;
42: private GridBagPanelComponent m_parentPanel = null;
43: private GridBagRowModel model = null;
44:
45: /**
46: * Creates a GridBagRowComponent instance.
47: */
48: public GridBagRowComponent(GridBagRowModel aModel) {
49: this .model = aModel;
50: }
51:
52: /**
53: * This add() method override, assumes that the class of the supplied
54: * component argument will resolve to an instance of the
55: * GridBagCellComponent class. This way the addition of components to the
56: * enclosing GridBagPanelComponent instance are laid out properly. A
57: * reference to any other class will simply return the referenced component,
58: * but not add it to the enclosing GridBagPanelComponent instance.
59: *
60: * @param component
61: * A valid reference to an instance of the GridBagCellComponent
62: * class.
63: *
64: * @see org.swingml.component.GridBagPanelComponent
65: * @see org.swingml.component.GridBagCellComponent
66: */
67: public Component add(Component aComponent) {
68: if (aComponent instanceof GridBagCellComponent) {
69: GridBagCellComponent theComponent = (GridBagCellComponent) aComponent;
70: theComponent.setParentPanel(this .m_parentPanel);
71: theComponent.setColumn(this .m_cols);
72: this .m_cols++;
73: }
74: return aComponent;
75: }
76:
77: public GridBagRowModel getModel() {
78: return model;
79: }
80:
81: public void setModel(GridBagRowModel model) {
82: this .model = model;
83: }
84:
85: /**
86: * This method sets the parent panel property to the one specified by the
87: * parentPanel parameter. This allows the current GridBagRowComponent
88: * instance to add forward this reference to contained instances of the
89: * GridBagCellComponent class.
90: *
91: * @param parentPanel
92: * A valid reference to a GridBagPanelComponent instance.
93: *
94: * @see org.swingml.component.GridBagPanelComponent
95: */
96: public void setParentPanel(GridBagPanelComponent aParentPanel) {
97: this.m_parentPanel = aParentPanel;
98: }
99: }
|