001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Michael Danilov
019: * @version $Revision$
020: */package java.awt;
021:
022: import java.io.Serializable;
023:
024: import org.apache.harmony.awt.internal.nls.Messages;
025:
026: public class GridBagConstraints implements Cloneable, Serializable {
027: private static final long serialVersionUID = -1000070633030801713L;
028:
029: public static final int RELATIVE = -1;
030: public static final int REMAINDER = 0;
031:
032: public static final int NONE = 0;
033: public static final int BOTH = 1;
034: public static final int HORIZONTAL = 2;
035: public static final int VERTICAL = 3;
036:
037: public static final int CENTER = 10;
038: public static final int NORTH = 11;
039: public static final int NORTHEAST = 12;
040: public static final int EAST = 13;
041: public static final int SOUTHEAST = 14;
042: public static final int SOUTH = 15;
043: public static final int SOUTHWEST = 16;
044: public static final int WEST = 17;
045: public static final int NORTHWEST = 18;
046:
047: public static final int PAGE_START = 19;
048: public static final int PAGE_END = 20;
049: public static final int LINE_START = 21;
050: public static final int LINE_END = 22;
051: public static final int FIRST_LINE_START = 23;
052: public static final int FIRST_LINE_END = 24;
053: public static final int LAST_LINE_START = 25;
054: public static final int LAST_LINE_END = 26;
055:
056: public int gridx;
057: public int gridy;
058: public int gridwidth;
059: public int gridheight;
060:
061: public double weightx;
062: public double weighty;
063:
064: public int anchor;
065: public int fill;
066:
067: public Insets insets;
068: public int ipadx;
069: public int ipady;
070:
071: public GridBagConstraints(int gridx, int gridy, int gridwidth,
072: int gridheight, double weightx, double weighty, int anchor,
073: int fill, Insets insets, int ipadx, int ipady) {
074: this .gridx = gridx;
075: this .gridy = gridy;
076: this .gridwidth = gridwidth;
077: this .gridheight = gridheight;
078: this .weightx = weightx;
079: this .weighty = weighty;
080: this .anchor = anchor;
081: this .fill = fill;
082: this .insets = (insets == null) ? null : (Insets) insets.clone();
083: this .ipadx = ipadx;
084: this .ipady = ipady;
085: }
086:
087: public GridBagConstraints() {
088: gridx = RELATIVE;
089: gridy = RELATIVE;
090: gridwidth = 1;
091: gridheight = 1;
092: weightx = 0.;
093: weighty = 0.;
094: anchor = CENTER;
095: fill = NONE;
096: insets = new Insets(0, 0, 0, 0);
097: ipadx = 0;
098: ipady = 0;
099: }
100:
101: @Override
102: public Object clone() {
103: return new GridBagConstraints(gridx, gridy, gridwidth,
104: gridheight, weightx, weighty, anchor, fill, insets,
105: ipadx, ipady);
106: }
107:
108: void verify() throws IllegalArgumentException {
109: int maxN = GridBagLayout.MAXGRIDSIZE - 1;
110:
111: if (((gridx != RELATIVE) && (gridx < 0)) || (gridx >= maxN)) {
112: // awt.9C=wrong value of GridBagConstraints: {0}
113: throw new IllegalArgumentException(Messages.getString(
114: "awt.9C", "gridx")); //$NON-NLS-1$ //$NON-NLS-2$
115: }
116: if (((gridy != RELATIVE) && (gridy < 0)) || (gridy >= maxN)) {
117: // awt.9C=wrong value of GridBagConstraints: {0}
118: throw new IllegalArgumentException(Messages.getString(
119: "awt.9C", "gridy")); //$NON-NLS-1$ //$NON-NLS-2$
120: }
121: if (((gridwidth != RELATIVE) && (gridwidth != REMAINDER) && (gridwidth < 0))
122: || (gridwidth > maxN)) {
123: // awt.9C=wrong value of GridBagConstraints: {0}
124: throw new IllegalArgumentException(Messages.getString(
125: "awt.9C", "gridwidth")); //$NON-NLS-1$ //$NON-NLS-2$
126: }
127: if (((gridheight != RELATIVE) && (gridheight != REMAINDER) && (gridheight < 0))
128: || (gridheight > maxN)) {
129: // awt.9C=wrong value of GridBagConstraints: {0}
130: throw new IllegalArgumentException(Messages.getString(
131: "awt.9C", "gridheight")); //$NON-NLS-1$ //$NON-NLS-2$
132: }
133: if (((gridx >= 0) || (gridy >= 0))
134: && ((gridwidth <= 0) || (gridheight <= 0))) {
135: // awt.9D=relative grid size parameter goes after absolute grid coordinate
136: throw new IllegalArgumentException(Messages
137: .getString("awt.9D")); //$NON-NLS-1$
138: }
139: if ((gridx != RELATIVE) && ((gridwidth + gridx) > maxN)) {
140: // awt.9E=wrong values sum of GridBagConstraints' gridwidth and gridx
141: throw new IllegalArgumentException(Messages
142: .getString("awt.9E")); //$NON-NLS-1$
143: }
144: if ((gridy != RELATIVE) && ((gridheight + gridy) > maxN)) {
145: // awt.9F=wrong values sum of GridBagConstraints' gridheight and gridy
146: throw new IllegalArgumentException(Messages
147: .getString("awt.9F")); //$NON-NLS-1$
148: }
149: if ((gridwidth == RELATIVE) && (gridheight == RELATIVE)) {
150: // awt.100=component has RELATIVE width and height
151: throw new IllegalArgumentException(Messages
152: .getString("awt.100")); //$NON-NLS-1$
153: }
154:
155: if (weightx < 0.) {
156: // awt.9C=wrong value of GridBagConstraints: {0}
157: throw new IllegalArgumentException(Messages.getString(
158: "awt.9C", "weightx")); //$NON-NLS-1$ //$NON-NLS-2$
159: }
160: if (weighty < 0.) {
161: // awt.9C=wrong value of GridBagConstraints: {0}
162: throw new IllegalArgumentException(Messages.getString(
163: "awt.9C", "weighty")); //$NON-NLS-1$ //$NON-NLS-2$
164: }
165:
166: if ((anchor != CENTER) && (anchor != NORTH)
167: && (anchor != NORTHEAST) && (anchor != EAST)
168: && (anchor != SOUTHEAST) && (anchor != SOUTH)
169: && (anchor != SOUTHWEST) && (anchor != WEST)
170: && (anchor != NORTHWEST) && (anchor != PAGE_START)
171: && (anchor != PAGE_END) && (anchor != LINE_START)
172: && (anchor != LINE_END) && (anchor != FIRST_LINE_START)
173: && (anchor != FIRST_LINE_END)
174: && (anchor != LAST_LINE_START)
175: && (anchor != LAST_LINE_END)) {
176: // awt.9C=wrong value of GridBagConstraints: {0}
177: throw new IllegalArgumentException(Messages.getString(
178: "awt.9C", "anchor")); //$NON-NLS-1$ //$NON-NLS-2$
179: }
180: if ((fill != NONE) && (fill != HORIZONTAL)
181: && (fill != VERTICAL) && (fill != BOTH)) {
182: // awt.9C=wrong value of GridBagConstraints: {0}
183: throw new IllegalArgumentException(Messages.getString(
184: "awt.9C", "fill")); //$NON-NLS-1$ //$NON-NLS-2$
185: }
186:
187: if (ipadx < 0) {
188: // awt.9C=wrong value of GridBagConstraints: {0}
189: throw new IllegalArgumentException(Messages.getString(
190: "awt.9C", "ipadx")); //$NON-NLS-1$ //$NON-NLS-2$
191: }
192: if (ipady < 0) {
193: // awt.9C=wrong value of GridBagConstraints: {0}
194: throw new IllegalArgumentException(Messages.getString(
195: "awt.9C", "ipady")); //$NON-NLS-1$ //$NON-NLS-2$
196: }
197: if ((insets == null) || (insets.left < 0) || (insets.left < 0)
198: || (insets.left < 0) || (insets.left < 0)) {
199: // awt.9C=wrong value of GridBagConstraints: {0}
200: throw new IllegalArgumentException(Messages.getString(
201: "awt.9C", "insets")); //$NON-NLS-1$ //$NON-NLS-2$
202: }
203: }
204: }
|