001: /*
002: * Copyright (c) 2004 JETA Software, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without modification,
005: * are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JETA Software nor the names of its contributors may
015: * be used to endorse or promote products derived from this software without
016: * specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
021: * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
022: * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
023: * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
024: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
025: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
026: * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: */
029:
030: package com.jeta.forms.gui.form;
031:
032: import java.awt.Insets;
033:
034: import com.jgoodies.forms.layout.CellConstraints;
035:
036: /**
037: * A read-only implementation of ComponentConstraints.
038: *
039: * @author Jeff Tassin
040: */
041: public class ReadOnlyConstraints implements ComponentConstraints {
042: private int m_col;
043: private int m_row;
044: private int m_colspan = 1;
045: private int m_rowspan = 1;
046:
047: private Insets m_insets = EMPTY_INSETS;
048:
049: private CellConstraints.Alignment m_halign = CellConstraints.DEFAULT;
050: private CellConstraints.Alignment m_valign = CellConstraints.DEFAULT;
051:
052: private static final Insets EMPTY_INSETS = new Insets(0, 0, 0, 0);
053:
054: /**
055: * Creates a <code>ReadOnlyConstraints</code> object with the specified
056: * row and column
057: */
058: public ReadOnlyConstraints(int col, int row) {
059: m_col = col;
060: m_row = row;
061: }
062:
063: /**
064: * Creates a <code>ReadOnlyConstraints</code> object with the specified
065: * row and column and span.
066: */
067: public ReadOnlyConstraints(int col, int row, int colspan,
068: int rowspan) {
069: m_col = col;
070: m_row = row;
071: m_colspan = colspan;
072: m_rowspan = rowspan;
073: }
074:
075: /**
076: * Creates a <code>ReadOnlyConstraints</code> object with the specified
077: * constraint information.
078: */
079: public ReadOnlyConstraints(int col, int row, int colspan,
080: int rowspan, CellConstraints.Alignment halign,
081: CellConstraints.Alignment valign, Insets insets) {
082: m_col = col;
083: m_row = row;
084: m_colspan = colspan;
085: m_rowspan = rowspan;
086: m_halign = halign;
087: m_valign = valign;
088: m_insets = insets;
089: }
090:
091: /**
092: * Creates a <code>ReadOnlyConstraints</code> object with the specified
093: * constraint information.
094: */
095: public ReadOnlyConstraints(ComponentConstraints cc) {
096: this (cc.getColumn(), cc.getRow(), cc.getColumnSpan(), cc
097: .getRowSpan(), cc.getHorizontalAlignment(), cc
098: .getVerticalAlignment(), cc.getInsets());
099: }
100:
101: /**
102: * Creates a CellConstraints object that can be used by the FormLayout.
103: *
104: * @returns a CellConstraints object based on this definition
105: */
106: public CellConstraints createCellConstraints() {
107: return new CellConstraints(m_col, m_row, m_colspan, m_rowspan,
108: m_halign, m_valign, m_insets);
109: }
110:
111: /**
112: * Always returns a read only copy of the cell constraints
113: */
114: public Object clone() {
115: return new ReadOnlyConstraints(getColumn(), getRow(),
116: getColumnSpan(), getRowSpan(), m_halign, m_valign,
117: m_insets);
118: }
119:
120: /**
121: * Return the first column occupied by the component associated with these
122: * constraints.
123: *
124: * @return the first column
125: */
126: public int getColumn() {
127: return m_col;
128: }
129:
130: /**
131: * Return the first row occupied by the component associated with these
132: * constraints.
133: *
134: * @return the first row
135: */
136: public int getRow() {
137: return m_row;
138: }
139:
140: /**
141: * Return the number of columns occupied by the component associated with
142: * these constraints.
143: *
144: * @return the column span
145: */
146: public int getColumnSpan() {
147: return m_colspan;
148: }
149:
150: /**
151: * Return the number of rows occupied by the component associated with these
152: * constraints.
153: *
154: * @return the column span
155: */
156: public int getRowSpan() {
157: return m_rowspan;
158: }
159:
160: /**
161: * @return the insets for this component
162: */
163: public Insets getInsets() {
164: return m_insets;
165: }
166:
167: /**
168: * @return the component's horizontal alignment.
169: */
170: public CellConstraints.Alignment getHorizontalAlignment() {
171: return m_halign;
172: }
173:
174: /**
175: * @return the component's vertical alignment.
176: */
177: public CellConstraints.Alignment getVerticalAlignment() {
178: return m_valign;
179: }
180:
181: }
|