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.event.ActionEvent;
022: import java.awt.event.ActionListener;
023:
024: import com.jeta.forms.gui.form.GridComponent;
025: import com.jeta.forms.gui.form.GridView;
026: import com.jeta.forms.store.properties.effects.PaintProperty;
027: import com.jeta.open.gui.framework.JETAController;
028: import com.jeta.open.gui.framework.JETADialog;
029: import com.jeta.open.gui.utils.JETAToolbox;
030: import com.jeta.open.i18n.I18N;
031: import com.jeta.swingbuilder.gui.commands.CommandUtils;
032: import com.jeta.swingbuilder.gui.commands.SetCellBackgroundCommand;
033: import com.jeta.swingbuilder.gui.commands.SetConstraintsCommand;
034: import com.jeta.swingbuilder.gui.editor.FormEditor;
035: import com.jeta.swingbuilder.gui.effects.PaintAssignmentView;
036: import com.jeta.swingbuilder.gui.utils.FormDesignerUtils;
037:
038: /**
039: * Controller for CellConstraintsView
040: *
041: * @author Jeff Tassin
042: */
043: public class CellConstraintsController extends JETAController {
044: /**
045: * The view we are handling events for
046: */
047: private CellConstraintsView m_view;
048:
049: /**
050: * ctor
051: */
052: public CellConstraintsController(CellConstraintsView view) {
053: super (view);
054: m_view = view;
055: assignAction(CellConstraintsNames.ID_COLUMN_SPAN,
056: new SpanAction());
057: assignAction(CellConstraintsNames.ID_ROW_SPAN, new SpanAction());
058: assignAction(CellConstraintsNames.ID_INSETS_TOP,
059: new ConstraintsAction());
060: assignAction(CellConstraintsNames.ID_INSETS_LEFT,
061: new ConstraintsAction());
062: assignAction(CellConstraintsNames.ID_INSETS_BOTTOM,
063: new ConstraintsAction());
064: assignAction(CellConstraintsNames.ID_INSETS_RIGHT,
065: new ConstraintsAction());
066: assignAction(CellConstraintsNames.ID_FILL_BUTTON,
067: new FillAction());
068: assignAction(CellConstraintsNames.ID_HORIZONTAL_ALIGNMENT,
069: new ConstraintsAction());
070: assignAction(CellConstraintsNames.ID_VERTICAL_ALIGNMENT,
071: new ConstraintsAction());
072: }
073:
074: public class ConstraintsAction implements ActionListener {
075: public void actionPerformed(ActionEvent evt) {
076: GridComponent gc = m_view.getGridComponent();
077: if (gc != null) {
078: GridView parentview = gc.getParentView();
079: SetConstraintsCommand cmd = new SetConstraintsCommand(
080: parentview.getParentForm(), gc, m_view
081: .getComponentConstraints());
082: CommandUtils.invoke(cmd, FormEditor.getEditor(gc));
083: m_view.update(gc);
084: }
085: }
086: }
087:
088: /**
089: * Sets the fill property for the currently selected cell in the view.
090: */
091: public class FillAction implements ActionListener {
092: public void actionPerformed(ActionEvent evt) {
093: GridComponent gc = m_view.getGridComponent();
094: if (gc != null) {
095: GridView parentview = gc.getParentView();
096: int row = gc.getRow();
097: int col = gc.getColumn();
098:
099: PaintAssignmentView view = new PaintAssignmentView(
100: parentview.getPaintProperty(col, row));
101: JETADialog dlg = (JETADialog) JETAToolbox.createDialog(
102: JETADialog.class, m_view, true);
103: dlg.setPrimaryPanel(view);
104: dlg.setSize(dlg.getPreferredSize());
105: dlg.setTitle(I18N.getLocalizedMessage("Edit Fill"));
106: dlg.showCenter();
107: if (dlg.isOk()) {
108: PaintProperty pp = view.getPaintProperty();
109: PaintProperty oldpaint = parentview
110: .getPaintProperty(col, row);
111: SetCellBackgroundCommand cmd = new SetCellBackgroundCommand(
112: parentview.getParentForm(), col, row, pp,
113: oldpaint);
114: CommandUtils.invoke(cmd, FormEditor
115: .getEditor(parentview));
116: }
117: }
118: }
119: }
120:
121: public class SpanAction implements ActionListener {
122: public void actionPerformed(ActionEvent evt) {
123: GridComponent gc = m_view.getGridComponent();
124: if (gc != null) {
125: FormDesignerUtils.setSpan(gc, m_view.getColumnSpan(),
126: m_view.getRowSpan());
127: }
128: }
129: }
130:
131: }
|