001: /*
002: * Copyright (C) 2005 Jeff Tassin
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.1 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 Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.main;
020:
021: import java.awt.BorderLayout;
022: import java.awt.Insets;
023:
024: import com.jeta.forms.components.panel.FormPanel;
025: import com.jeta.forms.gui.common.FormUtils;
026: import com.jeta.forms.gui.form.ComponentConstraints;
027: import com.jeta.forms.gui.form.GridComponent;
028: import com.jeta.forms.gui.form.GridView;
029: import com.jeta.forms.gui.form.GridViewEvent;
030: import com.jeta.forms.gui.form.GridViewListener;
031: import com.jeta.forms.gui.form.ReadOnlyConstraints;
032: import com.jeta.open.gui.framework.JETAController;
033: import com.jeta.open.gui.framework.JETAPanel;
034: import com.jeta.swingbuilder.gui.components.IntegerDocument;
035: import com.jgoodies.forms.layout.CellConstraints;
036:
037: /**
038: * Displays the cell constraints for a cell
039: *
040: * @author Jeff Tassin
041: */
042: public class CellConstraintsView extends JETAPanel implements
043: GridViewListener {
044: /**
045: * The panel that contains the form.
046: */
047: private FormPanel m_view;
048:
049: /**
050: * The component that we are currently displaying constraints for.
051: */
052: private GridComponent m_current_comp;
053:
054: public CellConstraintsView() {
055: setLayout(new BorderLayout());
056: m_view = new FormPanel(
057: "com/jeta/swingbuilder/gui/main/cellConstraints.frm");
058: add(m_view, BorderLayout.CENTER);
059:
060: /** require all text fields to allow only numbers */
061: getTextField(CellConstraintsNames.ID_COLUMN_SPAN).setDocument(
062: new IntegerDocument(false));
063: getTextField(CellConstraintsNames.ID_ROW_SPAN).setDocument(
064: new IntegerDocument(false));
065: getTextField(CellConstraintsNames.ID_INSETS_TOP).setDocument(
066: new IntegerDocument(true));
067: getTextField(CellConstraintsNames.ID_INSETS_LEFT).setDocument(
068: new IntegerDocument(true));
069: getTextField(CellConstraintsNames.ID_INSETS_BOTTOM)
070: .setDocument(new IntegerDocument(true));
071: getTextField(CellConstraintsNames.ID_INSETS_RIGHT).setDocument(
072: new IntegerDocument(true));
073:
074: setController(new CellConstraintsController(this ));
075: }
076:
077: /**
078: * @return the column of the current component
079: */
080: public int getColumn() {
081: return m_current_comp.getColumn();
082: }
083:
084: /**
085: * @return the column span entered in the view
086: */
087: public int getColumnSpan() {
088: return getInteger(CellConstraintsNames.ID_COLUMN_SPAN, 1);
089: }
090:
091: /**
092: * @return the component constraints for this view
093: */
094: public ComponentConstraints getComponentConstraints() {
095: return new ReadOnlyConstraints(getColumn(), getRow(),
096: getColumnSpan(), getRowSpan(),
097: getHorizontalAlignment(), getVerticalAlignment(),
098: getCellInsets());
099: }
100:
101: /**
102: * @return the currently selected grid component
103: */
104: public GridComponent getGridComponent() {
105: return m_current_comp;
106: }
107:
108: /**
109: * @return the component's horizontal alignment.
110: */
111: public CellConstraints.Alignment getHorizontalAlignment() {
112: return FormUtils
113: .toAlignment((String) getSelectedItem(CellConstraintsNames.ID_HORIZONTAL_ALIGNMENT));
114: }
115:
116: /**
117: * @return the insets displayed in the view
118: */
119: public Insets getCellInsets() {
120: return new Insets(getInteger(
121: CellConstraintsNames.ID_INSETS_TOP, 0), getInteger(
122: CellConstraintsNames.ID_INSETS_LEFT, 0), getInteger(
123: CellConstraintsNames.ID_INSETS_BOTTOM, 0), getInteger(
124: CellConstraintsNames.ID_INSETS_RIGHT, 0));
125: }
126:
127: /**
128: * @return the row of the current component
129: */
130: public int getRow() {
131: return m_current_comp.getRow();
132: }
133:
134: /**
135: * @return the row span entered in the view
136: */
137: public int getRowSpan() {
138: return getInteger(CellConstraintsNames.ID_ROW_SPAN, 1);
139: }
140:
141: /**
142: * @return the component's vertical alignment.
143: */
144: public CellConstraints.Alignment getVerticalAlignment() {
145: return FormUtils
146: .toAlignment((String) getSelectedItem(CellConstraintsNames.ID_VERTICAL_ALIGNMENT));
147: }
148:
149: /**
150: * GridViewListener implementation
151: */
152: public void gridChanged(GridViewEvent evt) {
153: GridComponent comp = evt.getComponent();
154: update(comp);
155: }
156:
157: /**
158: * Updates the panel using the constraint info from the currently selected
159: * cell in the given editor
160: */
161: public void update(GridComponent gc) {
162: m_current_comp = gc;
163: JETAController controller = getController();
164: try {
165: controller.enableEvents(false);
166: if (gc == null) {
167: setEnabled(false);
168: } else {
169: setEnabled(true);
170: int row = gc.getRow();
171: int col = gc.getColumn();
172: ComponentConstraints cc = gc.getConstraints();
173:
174: setText(CellConstraintsNames.ID_COLUMN_FIELD, String
175: .valueOf(cc.getColumn()));
176: setText(CellConstraintsNames.ID_ROW_FIELD, String
177: .valueOf(cc.getRow()));
178: setText(CellConstraintsNames.ID_COLUMN_SPAN, String
179: .valueOf(cc.getColumnSpan()));
180: setText(CellConstraintsNames.ID_ROW_SPAN, String
181: .valueOf(cc.getRowSpan()));
182:
183: Insets insets = cc.getInsets();
184: setText(CellConstraintsNames.ID_INSETS_TOP, String
185: .valueOf(insets.top));
186: setText(CellConstraintsNames.ID_INSETS_LEFT, String
187: .valueOf(insets.left));
188: setText(CellConstraintsNames.ID_INSETS_BOTTOM, String
189: .valueOf(insets.bottom));
190: setText(CellConstraintsNames.ID_INSETS_RIGHT, String
191: .valueOf(insets.right));
192:
193: setSelectedItem(
194: CellConstraintsNames.ID_HORIZONTAL_ALIGNMENT,
195: cc.getHorizontalAlignment().toString()
196: .toUpperCase());
197: setSelectedItem(
198: CellConstraintsNames.ID_VERTICAL_ALIGNMENT, cc
199: .getVerticalAlignment().toString()
200: .toUpperCase());
201:
202: GridView parentview = gc.getParentView();
203: Object pp = parentview.getPaintProperty(col, row);
204: setText(CellConstraintsNames.ID_FILL_LABEL,
205: pp == null ? "No Fill" : pp.toString());
206: }
207: } finally {
208: controller.enableEvents(true);
209: }
210: }
211: }
|