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: package org.swingml.model;
024:
025: import java.awt.*;
026:
027: import org.swingml.*;
028:
029: /**
030: * This class is the parent of all GridBag model components. It contains properties
031: * that correspond to the settings contained with the GridBagConstraints class. These
032: * values are set by the GridBagBaseMapper class during the parsing of a SwingML document.
033: *
034: * @author <a href="mailto:robertj@morris.net">Robert J. Morris</a>
035: *
036: * @see org.swingml.model.GridBagCellModel
037: * @see org.swingml.model.GridBagRowModel
038: * @see org.swingml.model.GridBagPanelModel
039: * @see java.awt.GridBagConstraints
040: */
041: public class GridBagBaseModel extends SwingMLModel {
042:
043: protected int m_anchor = GridBagConstraints.CENTER;
044: protected int m_fill = GridBagConstraints.NONE;
045: protected int m_gridheight = 1;
046: protected int m_gridwidth = 1;
047: protected int m_ipadx = 0;
048: protected int m_ipady = 0;
049: protected String m_name = null;
050: protected int m_padding = 0;
051: protected double m_weightx = 0;
052: protected double m_weighty = 0;
053:
054: public GridBagBaseModel() {
055: super ();
056: }
057:
058: /**
059: * Retrieves the anchor property that corresponds to the anchor attribute of the GridBagLayout class.
060: *
061: * @return An int corresponding to one of the following anchor constants exposed
062: * by the GridBagConstraints class
063: *
064: * @see java.awt.GridBagConstraints
065: * @see java.awt.GridBagConstraints#NORTH
066: * @see java.awt.GridBagConstraints#NORTHEAST
067: * @see java.awt.GridBagConstraints#NORTHWEST
068: * @see java.awt.GridBagConstraints#EAST
069: * @see java.awt.GridBagConstraints#WEST
070: * @see java.awt.GridBagConstraints#SOUTH
071: * @see java.awt.GridBagConstraints#SOUTHEAST
072: * @see java.awt.GridBagConstraints#SOUTHWEST
073: */
074: public int getAnchor() {
075: return this .m_anchor;
076: }
077:
078: /**
079: * This method returns a valid reference to an instance of the @see java.awt.GridBagConstraints
080: * class with attribute values set according to the property values contained
081: * within the current instance.
082: *
083: * @return A valid reference to an instance of the GridBagConstraints class.
084: */
085: public GridBagConstraints getConstraints() {
086: GridBagConstraints theCon = new GridBagConstraints();
087: theCon.insets = new Insets(m_padding, m_padding, m_padding,
088: m_padding);
089: theCon.ipadx = this .getIpadx();
090: theCon.ipady = this .getIpady();
091: theCon.fill = this .getFill();
092: theCon.anchor = this .getAnchor();
093: theCon.weightx = this .getWeightx();
094: theCon.weighty = this .getWeighty();
095: theCon.gridheight = this .getGridHeight();
096: theCon.gridwidth = this .getGridWidth();
097:
098: return theCon;
099: }
100:
101: /**
102: * Retrieves the value of the Fill property.
103: *
104: * @return The value of the fill property.
105: */
106: public int getFill() {
107: return this .m_fill;
108: }
109:
110: /**
111: * Returns the GridHeight property that corresponds to the gridheight attribute of the GridBagConstraints class.
112: *
113: * @return The number of vertical spaces a component should occupy in a GridBagLayout.
114: */
115: public int getGridHeight() {
116: return this .m_gridheight;
117: }
118:
119: /**
120: * Returns the GridWidth property that corresponds to the gridwidth attribute of the GridBagConstraints class.
121: *
122: * @return The number of horizontal spaces a component should occupy in a GridBagLayout.
123: */
124: public int getGridWidth() {
125: return this .m_gridwidth;
126: }
127:
128: /**
129: * Retrieves the value of the Ipadx property.
130: *
131: * @return The value of the Ipadx property.
132: */
133: public int getIpadx() {
134: return this .m_ipadx;
135: }
136:
137: /**
138: * Retrieves the value of the Ipady property.
139: *
140: * @return An int representing the value of the Ipady property.
141: */
142: public int getIpady() {
143: return this .m_ipady;
144: }
145:
146: /**
147: * Returns the name of the current instance of the GridBagBaseModel.
148: *
149: * @return The name of the current instance of GridBagBaseModel.
150: */
151: public String getName() {
152: return this .m_name;
153: }
154:
155: /**
156: * Retrieves the value of the Padding property.
157: *
158: * @return The valud of the Padding property.
159: */
160: public int getPadding() {
161: return this .m_padding;
162: }
163:
164: /**
165: * Returns the Weightx property that corresponds to the weightx attribute of the GridBagConstraints class.
166: *
167: * @return An int representing how much the GridBagLayout should favor
168: * the current cell when rendering the horizontal space it occupies.
169: */
170: public double getWeightx() {
171: return this .m_weightx;
172: }
173:
174: /**
175: * Returns the Weighty property that corresponds to the weighty attribute of the GridBagConstraints class.
176: *
177: * @return An int representing how much the GridBagLayout should favor
178: * the current cell when rendering the vertical space it occupies.
179: */
180: public double getWeighty() {
181: return this .m_weighty;
182: }
183:
184: /**
185: * Sets the anchor property that corresponds to the anchor attribute of the GridBagLayout class.
186: *
187: * @param anchor An int corresponding to one of the following anchor constants exposed
188: * by the GridBagConstraints class. This setting indicates where a component appears
189: * within its cell in a GridBagLayout.
190: *
191: * @see java.awt.GridBagConstraints
192: * @see java.awt.GridBagConstraints#NORTH
193: * @see java.awt.GridBagConstraints#NORTHEAST
194: * @see java.awt.GridBagConstraints#NORTHWEST
195: * @see java.awt.GridBagConstraints#EAST
196: * @see java.awt.GridBagConstraints#WEST
197: * @see java.awt.GridBagConstraints#SOUTH
198: * @see java.awt.GridBagConstraints#SOUTHEAST
199: * @see java.awt.GridBagConstraints#SOUTHWEST
200: */
201: public void setAnchor(int anAnchor) {
202: this .m_anchor = anAnchor;
203: }
204:
205: /**
206: * Set the value of the fill property.
207: *
208: * @param fill An int representing the fill property.
209: */
210: public void setFill(int aFill) {
211: this .m_fill = aFill;
212: }
213:
214: /**
215: * Sets the GridHeight property that corresponds to the gridheight attribute of the GridBagConstraints class.
216: *
217: * @param gridheight An int representing how many vertical spaces a component
218: * should occupy in a GridBagLayout.
219: */
220: public void setGridHeight(int aGridheight) {
221: this .m_gridheight = aGridheight;
222: }
223:
224: /**
225: * Sets the GridWidth property that corresponds to the gridwidth attribute of the GridBagConstraints class.
226: *
227: * @param gridwidth An int representing how many horizontal spaces a component
228: * should occupy in a GridBagLayout.
229: */
230: public void setGridWidth(int aGridwidth) {
231: this .m_gridwidth = aGridwidth;
232: }
233:
234: /**
235: * Sets the value of the Ipadx property.
236: *
237: * @param padx The new value of the Ipadx property.
238: */
239: public void setIpadx(int aPadx) {
240: this .m_ipadx = aPadx;
241: }
242:
243: /**
244: * Sets the value of Ipady property.
245: *
246: * @param ipady An int representing the new value of the Ipady property.
247: */
248: public void setIpady(int anIpady) {
249: this .m_ipady = anIpady;
250: }
251:
252: /**
253: * Sets the name of the current instance of the GridBagBaseModel.
254: *
255: * @parm name The name to use.
256: */
257: public void setName(String aName) {
258: this .m_name = aName;
259: }
260:
261: /**
262: * Sets the value of the Padding property.
263: *
264: * @param padding The new value of the Padding property.
265: */
266: public void setPadding(int aPadding) {
267: this .m_padding = aPadding;
268: }
269:
270: /**
271: * This method takes the values contained within the specified baseModel parameter
272: * to set the values of the current instance.
273: *
274: * @param baseModel A reference to another GridBagBaseModel to copy.
275: */
276: public void setValues(GridBagBaseModel aBaseModel) {
277: this .setPadding(aBaseModel.getPadding());
278: this .setIpadx(aBaseModel.getIpadx());
279: this .setIpady(aBaseModel.getIpady());
280: this .setAnchor(aBaseModel.getAnchor());
281: this .setFill(aBaseModel.getFill());
282: this .setWeightx(aBaseModel.getWeightx());
283: this .setWeighty(aBaseModel.getWeighty());
284: this .setGridHeight(aBaseModel.getGridHeight());
285: this .setGridWidth(aBaseModel.getGridWidth());
286: }
287:
288: /**
289: * Sets the Weightx property that corresponds to the weightx attribute of the GridBagConstraints class.
290: *
291: * @param weightx An int representing how much the GridBagLayout should favor
292: * the current cell when rendering the horizontal space it occupies.
293: */
294: public void setWeightx(double aWeightx) {
295: this .m_weightx = aWeightx;
296: }
297:
298: /**
299: * Sets the Weighty property that corresponds to the weighty attribute of the GridBagConstraints class.
300: *
301: * @param weighty An int representing how much the GridBagLayout should favor
302: * the current cell when rendering the vertical space it occupies.
303: */
304: public void setWeighty(double aWeighty) {
305: this .m_weighty = aWeighty;
306: }
307:
308: /**
309: * @see org.swingml.SwingMLModel
310: */
311: public void validate() {
312: }
313: }
|