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.Component;
022: import java.awt.Toolkit;
023: import java.awt.datatransfer.Clipboard;
024: import java.awt.datatransfer.Transferable;
025:
026: import com.jeta.forms.gui.form.FormComponent;
027: import com.jeta.forms.gui.form.GridComponent;
028: import com.jeta.forms.gui.form.GridView;
029: import com.jeta.open.gui.framework.JETAPanel;
030: import com.jeta.open.gui.framework.UIDirector;
031: import com.jeta.swingbuilder.gui.components.TSComponentNames;
032: import com.jeta.swingbuilder.gui.dnd.FormObjectFlavor;
033: import com.jeta.swingbuilder.gui.editor.FormEditor;
034: import com.jgoodies.forms.layout.FormSpec;
035:
036: /**
037: * The UIDirector for the MainFrame
038: */
039: public class MainFrameUIDirector implements UIDirector {
040: /**
041: * The frame we are updating.
042: */
043: private MainFrame m_frame;
044:
045: /**
046: * ctor
047: */
048: public MainFrameUIDirector(MainFrame frame) {
049: m_frame = frame;
050: }
051:
052: /**
053: * Updates the components in the view
054: */
055: public void updateComponents(java.util.EventObject evt) {
056: boolean has_project = (m_frame.getProject() != null);
057:
058: m_frame.enableComponent(MainFrameNames.ID_CREATE_FORM,
059: has_project);
060: m_frame.enableComponent(MainFrameNames.ID_OPEN_FORM,
061: has_project);
062: m_frame.enableComponent(MainFrameNames.ID_PROJECT_SETTINGS,
063: has_project);
064: m_frame.enableComponent(MainFrameNames.ID_CREATE_PROJECT,
065: !has_project);
066: m_frame.enableComponent(MainFrameNames.ID_CLOSE_PROJECT,
067: has_project);
068: m_frame.enableComponent(MainFrameNames.ID_OPEN_PROJECT,
069: !has_project);
070:
071: boolean has_editor = (m_frame.getCurrentEditor() != null);
072:
073: m_frame
074: .enableComponent(MainFrameNames.ID_SHOW_FORM,
075: has_editor);
076: m_frame
077: .enableComponent(MainFrameNames.ID_SAVE_FORM,
078: has_editor);
079: m_frame.enableComponent(MainFrameNames.ID_SAVE_FORM_AS,
080: has_editor);
081: m_frame.enableComponent(MainFrameNames.ID_CLOSE_FORM,
082: has_editor);
083: m_frame.enableComponent(TSComponentNames.ID_UNDO, has_editor);
084: m_frame.enableComponent(TSComponentNames.ID_REDO, has_editor);
085:
086: m_frame.enableComponent(MainFrameNames.ID_FORWARD_ENGINEER,
087: has_editor);
088:
089: boolean can_focus = has_editor;
090:
091: FormEditor editor = m_frame.getCurrentEditor();
092:
093: GridComponent sel_gc = null;
094: boolean cell_selected = false;
095: if (editor != null) {
096: sel_gc = editor.getSelectedComponent();
097: cell_selected = (sel_gc != null);
098: }
099:
100: m_frame.enableComponent(
101: FormEditorNames.ID_EXPORT_COMPONENT_NAMES,
102: sel_gc instanceof FormComponent);
103:
104: m_frame.enableComponent(TSComponentNames.ID_CUT, cell_selected);
105: m_frame
106: .enableComponent(TSComponentNames.ID_COPY,
107: cell_selected);
108: m_frame
109: .enableComponent(
110: FormEditorNames.ID_COLUMN_PREFERRED_SIZE,
111: cell_selected);
112: m_frame.enableComponent(FormEditorNames.ID_ROW_PREFERRED_SIZE,
113: cell_selected);
114: m_frame.enableComponent(FormEditorNames.ID_INSERT_ROW_ABOVE,
115: cell_selected);
116: m_frame.enableComponent(FormEditorNames.ID_INSERT_ROW_BELOW,
117: cell_selected);
118: m_frame.enableComponent(FormEditorNames.ID_INSERT_COLUMN_LEFT,
119: cell_selected);
120: m_frame.enableComponent(FormEditorNames.ID_INSERT_COLUMN_RIGHT,
121: cell_selected);
122: m_frame.enableComponent(FormEditorNames.ID_DELETE_COLUMN,
123: cell_selected);
124: m_frame.enableComponent(FormEditorNames.ID_DELETE_ROW,
125: cell_selected);
126: m_frame.enableComponent(FormEditorNames.ID_SHOW_GRID,
127: cell_selected);
128: m_frame.enableComponent(
129: FormEditorNames.ID_SET_AS_COLUMN_SEPARATOR,
130: cell_selected);
131: m_frame.enableComponent(
132: FormEditorNames.ID_SET_AS_BIG_COLUMN_SEPARATOR,
133: cell_selected);
134: m_frame.enableComponent(
135: FormEditorNames.ID_SET_AS_ROW_SEPARATOR, cell_selected);
136: m_frame.enableComponent(
137: FormEditorNames.ID_SET_AS_BIG_ROW_SEPARATOR,
138: cell_selected);
139: m_frame.enableComponent(FormEditorNames.ID_TRIM_ROWS,
140: cell_selected);
141: m_frame.enableComponent(FormEditorNames.ID_TRIM_COLUMNS,
142: cell_selected);
143:
144: if (cell_selected) {
145: GridView view = sel_gc.getParentView();
146: if (view != null) {
147: FormSpec spec = view.getColumnSpec(sel_gc.getColumn());
148: m_frame.enableComponent(
149: FormEditorNames.ID_COLUMN_RESIZE_GROW, spec
150: .getResizeWeight() == FormSpec.NO_GROW);
151: m_frame.enableComponent(
152: FormEditorNames.ID_COLUMN_RESIZE_NONE, spec
153: .getResizeWeight() != FormSpec.NO_GROW);
154:
155: spec = view.getRowSpec(sel_gc.getRow());
156: m_frame.enableComponent(
157: FormEditorNames.ID_ROW_RESIZE_GROW, spec
158: .getResizeWeight() == FormSpec.NO_GROW);
159: m_frame.enableComponent(
160: FormEditorNames.ID_ROW_RESIZE_NONE, spec
161: .getResizeWeight() != FormSpec.NO_GROW);
162: }
163: } else {
164: m_frame.enableComponent(
165: FormEditorNames.ID_COLUMN_RESIZE_GROW, false);
166: m_frame.enableComponent(
167: FormEditorNames.ID_COLUMN_RESIZE_NONE, false);
168: m_frame.enableComponent(FormEditorNames.ID_ROW_RESIZE_GROW,
169: false);
170: m_frame.enableComponent(FormEditorNames.ID_ROW_RESIZE_NONE,
171: false);
172: }
173:
174: boolean can_span = false;
175: if (sel_gc != null) {
176: Component comp = sel_gc.getBeanDelegate();
177: if (comp != null)
178: can_span = true;
179: }
180:
181: m_frame.enableComponent(
182: FormEditorNames.ID_COLUMN_INCREASE_SPAN, can_span);
183: m_frame.enableComponent(
184: FormEditorNames.ID_COLUMN_DECREASE_SPAN, can_span);
185: m_frame.enableComponent(FormEditorNames.ID_ROW_INCREASE_SPAN,
186: can_span);
187: m_frame.enableComponent(FormEditorNames.ID_ROW_DECREASE_SPAN,
188: can_span);
189:
190: JETAPanel panel = (JETAPanel) m_frame.getCurrentControlsView();
191: if (panel != null) {
192: com.jeta.open.gui.framework.UIDirector uidirector = panel
193: .getUIDirector();
194: if (uidirector != null)
195: uidirector.updateComponents(evt);
196: }
197:
198: if (cell_selected) {
199: try {
200: Toolkit kit = Toolkit.getDefaultToolkit();
201: Clipboard clipboard = kit.getSystemClipboard();
202: Transferable transferable = clipboard.getContents(null);
203: boolean enable_paste = FormObjectFlavor
204: .isDesignerFlavorSupported(transferable);
205: m_frame.enableComponent(TSComponentNames.ID_PASTE,
206: enable_paste);
207: m_frame.enableComponent(
208: FormEditorNames.ID_PASTE_SPECIAL, enable_paste);
209: } catch (Exception e) {
210: e.printStackTrace();
211: }
212: } else {
213: m_frame.enableComponent(TSComponentNames.ID_PASTE, false);
214: m_frame.enableComponent(FormEditorNames.ID_PASTE_SPECIAL,
215: false);
216: }
217: }
218: }
|