0001: /*
0002: * Copyright (C) 2005 Jeff Tassin
0003: *
0004: * This library is free software; you can redistribute it and/or
0005: * modify it under the terms of the GNU Lesser General Public
0006: * License as published by the Free Software Foundation; either
0007: * version 2.1 of the License, or (at your option) any later version.
0008: *
0009: * This library is distributed in the hope that it will be useful,
0010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0012: * Lesser General Public License for more details.
0013: *
0014: * You should have received a copy of the GNU Lesser General Public
0015: * License along with this library; if not, write to the Free Software
0016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0017: */
0018:
0019: package com.jeta.swingbuilder.gui.main;
0020:
0021: import java.awt.BorderLayout;
0022: import java.awt.Component;
0023: import java.awt.Container;
0024: import java.awt.Dimension;
0025: import java.awt.Rectangle;
0026: import java.awt.event.ActionEvent;
0027: import java.awt.event.ActionListener;
0028: import java.awt.event.InputEvent;
0029: import java.awt.event.KeyEvent;
0030: import java.awt.event.WindowAdapter;
0031: import java.awt.event.WindowEvent;
0032: import java.util.Collection;
0033: import java.util.Iterator;
0034: import java.util.LinkedList;
0035:
0036: import javax.swing.BorderFactory;
0037: import javax.swing.JButton;
0038: import javax.swing.JFrame;
0039: import javax.swing.JMenu;
0040: import javax.swing.JMenuBar;
0041: import javax.swing.JMenuItem;
0042: import javax.swing.JPanel;
0043: import javax.swing.JScrollPane;
0044: import javax.swing.JSplitPane;
0045: import javax.swing.JTabbedPane;
0046: import javax.swing.JToggleButton;
0047: import javax.swing.JToolBar;
0048: import javax.swing.KeyStroke;
0049: import javax.swing.LookAndFeel;
0050:
0051: import com.jeta.forms.components.panel.FormPanel;
0052: import com.jeta.forms.gui.common.FormUtils;
0053: import com.jeta.forms.gui.components.ComponentFactory;
0054: import com.jeta.forms.gui.components.ComponentSource;
0055: import com.jeta.forms.gui.form.FormAccessor;
0056: import com.jeta.forms.gui.form.FormComponent;
0057: import com.jeta.forms.gui.form.GridComponent;
0058: import com.jeta.forms.gui.form.GridViewEvent;
0059: import com.jeta.forms.gui.form.GridViewListener;
0060: import com.jeta.forms.gui.formmgr.FormManager;
0061: import com.jeta.forms.logger.FormsLogger;
0062: import com.jeta.forms.support.AbeilleForms;
0063: import com.jeta.open.gui.framework.JETAContainer;
0064: import com.jeta.open.gui.framework.JETAPanel;
0065: import com.jeta.open.gui.framework.UIDirector;
0066: import com.jeta.open.gui.utils.JETAToolbox;
0067: import com.jeta.open.i18n.I18N;
0068: import com.jeta.open.registry.JETARegistry;
0069: import com.jeta.open.support.CompositeComponentFinder;
0070: import com.jeta.swingbuilder.common.ComponentNames;
0071: import com.jeta.swingbuilder.gui.components.TSButtonBar;
0072: import com.jeta.swingbuilder.gui.components.TSCell;
0073: import com.jeta.swingbuilder.gui.components.TSComponentNames;
0074: import com.jeta.swingbuilder.gui.editor.FormEditor;
0075: import com.jeta.swingbuilder.gui.formmgr.EditorManager;
0076: import com.jeta.swingbuilder.gui.handler.AbstractMouseHandler;
0077: import com.jeta.swingbuilder.gui.lookandfeel.DefaultLookAndFeelManager;
0078: import com.jeta.swingbuilder.gui.lookandfeel.LookAndFeelInfo;
0079: import com.jeta.swingbuilder.gui.properties.PropertyPaneContainer;
0080: import com.jeta.swingbuilder.gui.utils.FormDesignerUtils;
0081: import com.jeta.swingbuilder.interfaces.app.ObjectStore;
0082: import com.jeta.swingbuilder.project.DefaultProjectManager;
0083: import com.jeta.swingbuilder.resources.Icons;
0084: import com.jeta.swingbuilder.store.ProjectModel;
0085: import com.jeta.swingbuilder.support.DesignTimeComponentFinder;
0086: import com.jgoodies.forms.layout.CellConstraints;
0087: import com.jgoodies.forms.layout.FormLayout;
0088:
0089: /**
0090: * The main frame window for the application
0091: *
0092: * @author Jeff Tassin
0093: */
0094: public class MainFrame extends JFrame implements ComponentSource,
0095: GridViewListener, ActionListener, JETAContainer, EditorManager {
0096: /**
0097: * The buttonbar that contains the property pane, FormSpec views, and
0098: * CellConstaint view
0099: */
0100: private TSButtonBar m_buttonbar;
0101:
0102: /**
0103: * Frame window that displays the properties for a selected Java Bean
0104: */
0105: private PropertyPaneContainer m_propsview;
0106:
0107: /**
0108: * Panels that show the RowSpec and ColumnSpec for the selected row/column
0109: * in the current form
0110: */
0111: private SpecView m_col_spec_panel;
0112:
0113: private SpecView m_row_spec_panel;
0114:
0115: /**
0116: * View that displays the CellConstraints for the selected cell
0117: */
0118: private CellConstraintsView m_cc_view;
0119:
0120: /**
0121: * Split pane.
0122: */
0123: private JSplitPane m_split = new JSplitPane(
0124: JSplitPane.HORIZONTAL_SPLIT);
0125:
0126: /**
0127: * The controller for this frame
0128: */
0129: private MainFrameController m_controller;
0130:
0131: /**
0132: * The component finder for this frame. Component finders are used to
0133: * implement getComponentByName methods.
0134: */
0135: private CompositeComponentFinder m_composite_finder = new CompositeComponentFinder();
0136:
0137: /**
0138: * Tab pane that contains the forms
0139: */
0140: private JTabbedPane m_forms_tab = new JTabbedPane(
0141: JTabbedPane.BOTTOM);
0142:
0143: /**
0144: * Listener for tab change events on m_forms_tab
0145: */
0146: private TabListener m_tab_listener;
0147:
0148: /**
0149: * The toolbar that displays the components that we can place on a frame
0150: */
0151: private ComponentsToolBar m_component_tools;
0152:
0153: /**
0154: * The form manager for the application.
0155: */
0156: private MainFormManager m_formmgr;
0157:
0158: /**
0159: * Handles enabling/disabling
0160: */
0161: private MainFrameUIDirector m_uidirector;
0162:
0163: /**
0164: * The look and feel menu. This is updated dynamically.
0165: */
0166: private JMenu m_lfmenu;
0167:
0168: /**
0169: * Popup menu for right-context mouse clicks
0170: */
0171: FormEditorPopupMenu m_form_popup = new FormEditorPopupMenu();
0172:
0173: /**
0174: * The toolbar for this frame.
0175: */
0176: private JToolBar m_toolbar;
0177:
0178: /**
0179: * The status bar cell for this frame. Shows current project information.
0180: */
0181: private TSCell m_status_cell;
0182:
0183: /**
0184: * The properties view
0185: */
0186: private FormPanel m_properties_view;
0187:
0188: /**
0189: * The main container the contains the tool palette, form editor, and
0190: * optionally the properties window
0191: */
0192: private JPanel m_main_panel;
0193:
0194: /**
0195: * Responsible for handling dock behavior for the properties window
0196: */
0197: private FrameDocker m_docker;
0198:
0199: public static final String ID_FRAME_BOUNDS = "main.frame.bounds";
0200:
0201: /**
0202: * ctor
0203: */
0204: public MainFrame() {
0205: super ("Abeille Forms Designer "
0206: + AbeilleForms.getVersionTitle());
0207: FormsLogger.debug("Creating MainFrame");
0208:
0209: setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
0210: try {
0211: m_component_tools = new ComponentsToolBar();
0212:
0213: m_formmgr = new MainFormManager(this );
0214:
0215: JETARegistry.rebind(FormManager.COMPONENT_ID, m_formmgr);
0216: JETARegistry.rebind(EditorManager.COMPONENT_ID, this );
0217: JETARegistry.rebind(ComponentSource.COMPONENT_ID, this );
0218: JETARegistry.rebind(JETAToolbox.APPLICATION_FRAME, this );
0219:
0220: getContentPane().setLayout(new BorderLayout());
0221:
0222: createMenu();
0223: createToolBar();
0224: createStatusBar();
0225:
0226: addWindowListener(new WindowAdapter() {
0227: public void windowClosing(WindowEvent e) {
0228: shutDown();
0229: }
0230: });
0231:
0232: /**
0233: * create the main panel
0234: */
0235: m_split.setResizeWeight(1.0);
0236: m_main_panel = new JPanel();
0237: m_main_panel.setLayout(new BorderLayout());
0238: m_main_panel.add(m_split, BorderLayout.CENTER);
0239:
0240: JPanel editor_panel = new JPanel(new BorderLayout());
0241: editor_panel.add(m_component_tools, BorderLayout.WEST);
0242: editor_panel.add(m_forms_tab, BorderLayout.CENTER);
0243:
0244: JPanel controls_panel = (JPanel) createControlsView();
0245: controls_panel.setPreferredSize(FormDesignerUtils
0246: .getWindowDimension(controls_panel, 150, 200));
0247:
0248: m_docker = new FrameDocker(m_main_panel, editor_panel,
0249: m_split, m_properties_view);
0250:
0251: m_composite_finder.add(new DesignTimeComponentFinder(
0252: m_component_tools));
0253: m_composite_finder.add(new DesignTimeComponentFinder(
0254: m_forms_tab));
0255: m_composite_finder.add(new DesignTimeComponentFinder(
0256: m_form_popup));
0257:
0258: getContentPane().add(m_main_panel);
0259:
0260: m_tab_listener = new TabListener();
0261: m_forms_tab.addChangeListener(m_tab_listener);
0262:
0263: FormUtils.setDesignMode(true);
0264:
0265: initializeFrameBounds();
0266:
0267: m_split.add(editor_panel);
0268: m_split.add(controls_panel);
0269:
0270: m_uidirector = new MainFrameUIDirector(this );
0271: m_controller = new MainFrameController(this );
0272: m_controller.openLastProject();
0273:
0274: javax.swing.ImageIcon icon = FormDesignerUtils
0275: .loadImage(Icons.LINKED_FORM_16);
0276: if (icon != null)
0277: setIconImage(icon.getImage());
0278:
0279: createLookAndFeelMenu();
0280:
0281: updateComponents();
0282: } catch (Exception e) {
0283: FormsLogger.debug(e);
0284: }
0285: }
0286:
0287: /**
0288: * Called when the button bar is updated
0289: */
0290: public void actionPerformed(ActionEvent evt) {
0291: Component comp = m_buttonbar.getCurrentView();
0292: if (comp instanceof ControlsScrollPane) {
0293: /** loads the view if it is not already loaded */
0294: ((ControlsScrollPane) comp).initialize();
0295: }
0296:
0297: FormEditor editor = getCurrentEditor();
0298: if (editor != null) {
0299: GridComponent gc = editor.getSelectedComponent();
0300: Component view = getCurrentControlsView();
0301: if (view == null)
0302: return;
0303:
0304: if (view == m_propsview) {
0305: m_propsview.update(gc);
0306: } else if (view == m_col_spec_panel) {
0307: m_col_spec_panel.update(gc);
0308: } else if (view == m_row_spec_panel) {
0309: m_row_spec_panel.update(gc);
0310: } else if (view == m_cc_view) {
0311: m_cc_view.update(gc);
0312: }
0313: }
0314: }
0315:
0316: /**
0317: * Adds the tab listener to the forms tab
0318: */
0319: private void addTabListener() {
0320: m_forms_tab.removeChangeListener(m_tab_listener);
0321: m_forms_tab.addChangeListener(m_tab_listener);
0322: }
0323:
0324: /**
0325: * Adds the given form to the tab window
0326: */
0327: public void addForm(FormEditor editor) {
0328: editor.addListener(this );
0329: m_controller.installHandlers(editor);
0330:
0331: removeTabListener();
0332: deactivateAllForms();
0333:
0334: if (editor.isLinked()) {
0335: String filename = editor.getForm().getFileName();
0336: if (filename == null)
0337: filename = I18N.getLocalizedMessage("New Form");
0338:
0339: m_forms_tab.addTab(filename, FormDesignerUtils
0340: .loadImage(Icons.LINKED_FORM_16), editor);
0341: } else {
0342: m_forms_tab
0343: .addTab(editor.getForm().getName(),
0344: FormDesignerUtils
0345: .loadImage(Icons.EMBEDDED_FORM_16),
0346: editor);
0347: }
0348:
0349: m_forms_tab.setSelectedIndex(m_forms_tab.getTabCount() - 1);
0350: m_formmgr.activateForm(editor.getTopParent().getId());
0351: addTabListener();
0352: }
0353:
0354: /**
0355: * Creates the panel to the right of the design window. This panel contains
0356: * the properties and grid controls.
0357: */
0358: private Container createControlsView() {
0359: m_propsview = new PropertyPaneContainer();
0360:
0361: m_buttonbar = new TSButtonBar();
0362: m_buttonbar.addListener(this );
0363:
0364: m_buttonbar.addView(I18N.getLocalizedMessage("Component"),
0365: m_propsview, FormDesignerUtils
0366: .loadImage(Icons.COMPONENT_16));
0367:
0368: /**
0369: * lazily load the views to speed up application startup.
0370: */
0371: JScrollPane scroll = new ControlsScrollPane() {
0372: protected Component loadView() {
0373: m_col_spec_panel = new SpecView(
0374: "com/jeta/swingbuilder/gui/main/columnSpec.frm",
0375: false);
0376: return m_col_spec_panel;
0377: }
0378: };
0379: m_buttonbar.addView(I18N.getLocalizedMessage("Column"), scroll,
0380: FormDesignerUtils.loadImage(Icons.COLUMN_16));
0381:
0382: scroll = new ControlsScrollPane() {
0383: protected Component loadView() {
0384: m_row_spec_panel = new SpecView(
0385: "com/jeta/swingbuilder/gui/main/rowSpec.frm",
0386: true);
0387: return m_row_spec_panel;
0388: }
0389: };
0390: m_buttonbar.addView(I18N.getLocalizedMessage("Row"), scroll,
0391: FormDesignerUtils.loadImage(Icons.ROW_16));
0392:
0393: scroll = new ControlsScrollPane() {
0394: protected Component loadView() {
0395: m_cc_view = new CellConstraintsView();
0396: return m_cc_view;
0397: }
0398: };
0399: m_buttonbar.addView(I18N.getLocalizedMessage("Cell"), scroll,
0400: FormDesignerUtils.loadImage(Icons.CELL_16));
0401: m_buttonbar.updateView();
0402:
0403: m_properties_view = new FormPanel(
0404: "com/jeta/swingbuilder/gui/main/formProperties.jfrm");
0405: FormAccessor fa = m_properties_view
0406: .getFormAccessor(FormPropertiesNames.ID_MAIN_FORM);
0407: fa.replaceBean(FormPropertiesNames.ID_PROPERTIES_BAR,
0408: m_buttonbar);
0409: m_composite_finder.add(new DesignTimeComponentFinder(
0410: m_properties_view));
0411: return m_properties_view;
0412: }
0413:
0414: /**
0415: * Creates the look and feel submenu.
0416: */
0417: private JMenu createLookAndFeelMenu() {
0418: m_lfmenu.removeAll();
0419:
0420: DefaultLookAndFeelManager lfm = (DefaultLookAndFeelManager) JETARegistry
0421: .lookup(DefaultLookAndFeelManager.COMPONENT_ID);
0422: Iterator iter = lfm.getDefaultLookAndFeels().iterator();
0423: while (iter.hasNext()) {
0424: LookAndFeelInfo lf = (LookAndFeelInfo) iter.next();
0425: createLookAndFeelMenuItem(lfm, lf);
0426: }
0427: return m_lfmenu;
0428: }
0429:
0430: /**
0431: * Creates a menu item for the given look and feel information
0432: */
0433: private JMenuItem createLookAndFeelMenuItem(
0434: DefaultLookAndFeelManager lfm, LookAndFeelInfo lfinfo) {
0435: String desc = lfinfo.getName();
0436: String class_name = lfinfo.getLookAndFeelClassName();
0437: if (desc == null || desc.length() == 0)
0438: desc = class_name;
0439:
0440: /**
0441: * add a counter to the description to make sure the action command for
0442: * the menu is unique. it is possible to get the same description for a
0443: * look and feel
0444: */
0445: String actioncmd = lfinfo.getId();
0446: assert (actioncmd != null);
0447:
0448: JMenuItem item = i18n_createMenuItem(desc, actioncmd, null);
0449: m_lfmenu.add(item);
0450:
0451: assert (getComponentByName(actioncmd) == item);
0452: LookAndFeel lf = lfinfo.getLookAndFeel();
0453: if (lf == null || !lf.isSupportedLookAndFeel()) {
0454: item.setEnabled(false);
0455: }
0456: m_controller.assignAction(actioncmd, m_controller.m_lfaction);
0457: return item;
0458: }
0459:
0460: /**
0461: * @return the current view in the button bar
0462: */
0463: Component getCurrentControlsView() {
0464: Component view = m_buttonbar.getCurrentView();
0465: if (view instanceof JScrollPane) {
0466: view = ((JScrollPane) view).getViewport().getView();
0467: }
0468: return view;
0469: }
0470:
0471: public JMenuItem i18n_createMenuItem(String itemText,
0472: String actionCmd, KeyStroke keyAccelerator) {
0473: JMenuItem item = new JMenuItem(I18N
0474: .getLocalizedMessage(itemText));
0475: item.setName(actionCmd);
0476: item.setActionCommand(actionCmd);
0477: if (keyAccelerator != null)
0478: item.setAccelerator(keyAccelerator);
0479: return item;
0480: }
0481:
0482: public JButton i18n_createToolBarButton(String cmd,
0483: String imageFile, String toolTip) {
0484: JButton button = new JButton(FormDesignerUtils
0485: .loadImage(imageFile)) {
0486: public boolean isFocusTraversable() {
0487: return false;
0488: }
0489: };
0490:
0491: button.setMargin(new java.awt.Insets(1, 0, 1, 0));
0492: button.setName(cmd);
0493: button.setActionCommand(cmd);
0494: if (toolTip != null)
0495: button.setToolTipText(I18N.getLocalizedMessage(toolTip));
0496:
0497: if (!JETAToolbox.isOSX()) {
0498: button.setBorderPainted(false);
0499: button.setFocusPainted(false);
0500: }
0501: return button;
0502: }
0503:
0504: public javax.swing.AbstractButton i18n_createToolBarToggleButton(
0505: String cmd, String unselImage, String selImage,
0506: String toolTip) {
0507:
0508: JToggleButton button = new JToggleButton(FormDesignerUtils
0509: .loadImage(unselImage)) {
0510: public boolean isFocusTraversable() {
0511: return false;
0512: }
0513: };
0514: button.setSelectedIcon(FormDesignerUtils.loadImage(selImage));
0515: button.setName(cmd);
0516: button.setActionCommand(cmd);
0517: button.setMargin(new java.awt.Insets(1, 1, 1, 1));
0518:
0519: if (toolTip != null)
0520: button.setToolTipText(I18N.getLocalizedMessage(toolTip));
0521:
0522: return button;
0523: }
0524:
0525: /**
0526: * Creates the menus for this frame window.
0527: */
0528: private void createMenu() {
0529: JMenuBar menuBar = new JMenuBar();
0530: setJMenuBar(menuBar);
0531:
0532: DesignTimeComponentFinder menu_finder = new DesignTimeComponentFinder(
0533: menuBar);
0534: m_composite_finder.add(menu_finder);
0535:
0536: JMenu menu = new JMenu(I18N.getLocalizedMessage("File"));
0537: menu.add(i18n_createMenuItem("New Form",
0538: MainFrameNames.ID_CREATE_FORM, KeyStroke.getKeyStroke(
0539: KeyEvent.VK_N, InputEvent.CTRL_MASK, false)));
0540: menu.add(i18n_createMenuItem("Open Form",
0541: MainFrameNames.ID_OPEN_FORM, KeyStroke.getKeyStroke(
0542: KeyEvent.VK_O, InputEvent.CTRL_MASK, false)));
0543: menu.add(i18n_createMenuItem("Save",
0544: MainFrameNames.ID_SAVE_FORM, KeyStroke.getKeyStroke(
0545: KeyEvent.VK_S, InputEvent.CTRL_MASK, false)));
0546: menu.add(i18n_createMenuItem("Save As",
0547: MainFrameNames.ID_SAVE_FORM_AS, null));
0548: menu.add(i18n_createMenuItem("Close Form",
0549: MainFrameNames.ID_CLOSE_FORM, null));
0550:
0551: menu.addSeparator();
0552: menu.add(i18n_createMenuItem("New Project",
0553: MainFrameNames.ID_CREATE_PROJECT, null));
0554: menu.add(i18n_createMenuItem("Open Project",
0555: MainFrameNames.ID_OPEN_PROJECT, null));
0556: menu.add(i18n_createMenuItem("Close Project",
0557: MainFrameNames.ID_CLOSE_PROJECT, null));
0558: menu.addSeparator();
0559:
0560: menu.add(i18n_createMenuItem("Exit", MainFrameNames.ID_EXIT,
0561: null));
0562: menuBar.add(menu);
0563:
0564: assert (menu_finder
0565: .getComponentByName(MainFrameNames.ID_SAVE_FORM_AS) != null);
0566:
0567: menu = new JMenu(I18N.getLocalizedMessage("Edit"));
0568: menu.add(i18n_createMenuItem("Cut", TSComponentNames.ID_CUT,
0569: KeyStroke.getKeyStroke(KeyEvent.VK_X,
0570: InputEvent.CTRL_MASK, false)));
0571: menu.add(i18n_createMenuItem("Copy", TSComponentNames.ID_COPY,
0572: KeyStroke.getKeyStroke(KeyEvent.VK_C,
0573: InputEvent.CTRL_MASK, false)));
0574: menu.add(i18n_createMenuItem("Paste",
0575: TSComponentNames.ID_PASTE, KeyStroke.getKeyStroke(
0576: KeyEvent.VK_V, InputEvent.CTRL_MASK, false)));
0577: menu.addSeparator();
0578: menu.add(i18n_createMenuItem("Undo", TSComponentNames.ID_UNDO,
0579: KeyStroke.getKeyStroke(KeyEvent.VK_Z,
0580: InputEvent.CTRL_MASK, false)));
0581: menu.add(i18n_createMenuItem("Redo", TSComponentNames.ID_REDO,
0582: KeyStroke.getKeyStroke(KeyEvent.VK_Y,
0583: InputEvent.CTRL_MASK, false)));
0584: menuBar.add(menu);
0585:
0586: JMenu submenu = new JMenu(I18N.getLocalizedMessage("Column"));
0587: submenu.add(i18n_createMenuItem("Insert Left",
0588: FormEditorNames.ID_INSERT_COLUMN_LEFT, KeyStroke
0589: .getKeyStroke(KeyEvent.VK_L,
0590: InputEvent.CTRL_MASK, false)));
0591: submenu.add(i18n_createMenuItem("Insert Right",
0592: FormEditorNames.ID_INSERT_COLUMN_RIGHT, KeyStroke
0593: .getKeyStroke(KeyEvent.VK_R,
0594: InputEvent.CTRL_MASK, false)));
0595: submenu.add(i18n_createMenuItem("Set As Separator",
0596: FormEditorNames.ID_SET_AS_COLUMN_SEPARATOR, KeyStroke
0597: .getKeyStroke(KeyEvent.VK_P,
0598: InputEvent.CTRL_MASK, false)));
0599: submenu.add(i18n_createMenuItem("Set As Large Separator",
0600: FormEditorNames.ID_SET_AS_BIG_COLUMN_SEPARATOR, null));
0601:
0602: submenu.add(i18n_createMenuItem("Delete Column",
0603: FormEditorNames.ID_DELETE_COLUMN, KeyStroke
0604: .getKeyStroke(KeyEvent.VK_D,
0605: InputEvent.CTRL_MASK, false)));
0606: submenu.add(i18n_createMenuItem("Trim",
0607: FormEditorNames.ID_TRIM_COLUMNS, null));
0608:
0609: submenu.addSeparator();
0610:
0611: submenu.add(i18n_createMenuItem("Size: Preferred",
0612: FormEditorNames.ID_COLUMN_PREFERRED_SIZE, KeyStroke
0613: .getKeyStroke(KeyEvent.VK_W,
0614: InputEvent.CTRL_MASK, false)));
0615: submenu.add(i18n_createMenuItem("Resize: Grow",
0616: FormEditorNames.ID_COLUMN_RESIZE_GROW, KeyStroke
0617: .getKeyStroke(KeyEvent.VK_G,
0618: InputEvent.CTRL_MASK, false)));
0619: submenu.add(i18n_createMenuItem("Resize: None",
0620: FormEditorNames.ID_COLUMN_RESIZE_NONE, KeyStroke
0621: .getKeyStroke(KeyEvent.VK_G,
0622: InputEvent.SHIFT_MASK, false)));
0623:
0624: submenu.addSeparator();
0625: submenu.add(i18n_createMenuItem("Increase Column Span",
0626: FormEditorNames.ID_COLUMN_INCREASE_SPAN, KeyStroke
0627: .getKeyStroke(KeyEvent.VK_RIGHT,
0628: InputEvent.SHIFT_MASK, false)));
0629: submenu.add(i18n_createMenuItem("Decrease Column Span",
0630: FormEditorNames.ID_COLUMN_DECREASE_SPAN, KeyStroke
0631: .getKeyStroke(KeyEvent.VK_LEFT,
0632: InputEvent.SHIFT_MASK, false)));
0633:
0634: menuBar.add(submenu);
0635:
0636: submenu = new JMenu(I18N.getLocalizedMessage("Row"));
0637: submenu.add(i18n_createMenuItem("Insert Above",
0638: FormEditorNames.ID_INSERT_ROW_ABOVE, KeyStroke
0639: .getKeyStroke(KeyEvent.VK_A,
0640: InputEvent.CTRL_MASK, false)));
0641: submenu.add(i18n_createMenuItem("Insert Below",
0642: FormEditorNames.ID_INSERT_ROW_BELOW, KeyStroke
0643: .getKeyStroke(KeyEvent.VK_B,
0644: InputEvent.CTRL_MASK, false)));
0645: submenu.add(i18n_createMenuItem("Set As Separator",
0646: FormEditorNames.ID_SET_AS_ROW_SEPARATOR, KeyStroke
0647: .getKeyStroke(KeyEvent.VK_E,
0648: InputEvent.CTRL_MASK, false)));
0649: submenu.add(i18n_createMenuItem("Set As Large Separator",
0650: FormEditorNames.ID_SET_AS_BIG_ROW_SEPARATOR, null));
0651:
0652: submenu.add(i18n_createMenuItem("Delete Row",
0653: FormEditorNames.ID_DELETE_ROW, KeyStroke.getKeyStroke(
0654: KeyEvent.VK_K, InputEvent.CTRL_MASK, false)));
0655: submenu.add(i18n_createMenuItem("Trim",
0656: FormEditorNames.ID_TRIM_ROWS, null));
0657:
0658: submenu.addSeparator();
0659: submenu.add(i18n_createMenuItem("Size: Preferred",
0660: FormEditorNames.ID_ROW_PREFERRED_SIZE, KeyStroke
0661: .getKeyStroke(KeyEvent.VK_H,
0662: InputEvent.CTRL_MASK, false)));
0663: submenu.add(i18n_createMenuItem("Resize: Grow",
0664: FormEditorNames.ID_ROW_RESIZE_GROW, KeyStroke
0665: .getKeyStroke(KeyEvent.VK_U,
0666: InputEvent.CTRL_MASK, false)));
0667: submenu.add(i18n_createMenuItem("Resize: None",
0668: FormEditorNames.ID_ROW_RESIZE_NONE, KeyStroke
0669: .getKeyStroke(KeyEvent.VK_U,
0670: InputEvent.SHIFT_MASK, false)));
0671: submenu.addSeparator();
0672: submenu.add(i18n_createMenuItem("Increase Row Span",
0673: FormEditorNames.ID_ROW_INCREASE_SPAN, KeyStroke
0674: .getKeyStroke(KeyEvent.VK_DOWN,
0675: InputEvent.SHIFT_MASK, false)));
0676: submenu.add(i18n_createMenuItem("Decrease Row Span",
0677: FormEditorNames.ID_ROW_DECREASE_SPAN, KeyStroke
0678: .getKeyStroke(KeyEvent.VK_UP,
0679: InputEvent.SHIFT_MASK, false)));
0680:
0681: menuBar.add(submenu);
0682:
0683: menu = new JMenu(I18N.getLocalizedMessage("Form"));
0684: menu.add(i18n_createMenuItem("Show Form",
0685: MainFrameNames.ID_SHOW_FORM, KeyStroke.getKeyStroke(
0686: KeyEvent.VK_F, InputEvent.CTRL_MASK, false)));
0687: menu.add(i18n_createMenuItem("Toggle Grid",
0688: FormEditorNames.ID_SHOW_GRID, KeyStroke.getKeyStroke(
0689: KeyEvent.VK_G, InputEvent.CTRL_MASK, false)));
0690: menu.add(i18n_createMenuItem("Export Names",
0691: FormEditorNames.ID_EXPORT_COMPONENT_NAMES, null));
0692: menuBar.add(menu);
0693:
0694: m_lfmenu = new JMenu(I18N.getLocalizedMessage("Look and Feel"));
0695: m_lfmenu.setName("Look and Feel Menu");
0696: menuBar.add(m_lfmenu);
0697:
0698: menu = new JMenu(I18N.getLocalizedMessage("Tools"));
0699: menu.add(i18n_createMenuItem("Form Properties",
0700: MainFrameNames.ID_FORM_PROPERTIES, KeyStroke
0701: .getKeyStroke(KeyEvent.VK_F4, 0, false)));
0702: menu.add(i18n_createMenuItem("Code Generation",
0703: MainFrameNames.ID_FORWARD_ENGINEER, null));
0704: menu.add(i18n_createMenuItem("Project Settings",
0705: MainFrameNames.ID_PROJECT_SETTINGS, null));
0706: menu.add(i18n_createMenuItem("Java Bean Manager",
0707: MainFrameNames.ID_BEAN_MANAGER, null));
0708: menu.add(i18n_createMenuItem("Preferences",
0709: MainFrameNames.ID_ENV_SETTINGS, null));
0710: menu.add(i18n_createMenuItem("System Properties",
0711: MainFrameNames.ID_SYSTEM_PROPERTIES, null));
0712:
0713: if (FormDesignerUtils.isDebug()) {
0714: menu.addSeparator();
0715: menu.add(i18n_createMenuItem("Form Manager",
0716: MainFrameNames.ID_SHOW_FORM_MANAGER, null));
0717: menu.add(i18n_createMenuItem("Undo Manager",
0718: MainFrameNames.ID_SHOW_UNDO_MANAGER, null));
0719: }
0720: menuBar.add(menu);
0721:
0722: menu = new JMenu(I18N.getLocalizedMessage("Help"));
0723: javax.swing.JMenuItem hitem = i18n_createMenuItem(
0724: "Help Topics", MainFrameNames.ID_HELP, null);
0725: com.jeta.swingbuilder.help.HelpUtils.enableHelpOnButton(hitem,
0726: MainFrameNames.ID_HELP);
0727: menu.add(hitem);
0728: menu.add(i18n_createMenuItem("About", MainFrameNames.ID_ABOUT,
0729: null));
0730: menuBar.add(menu);
0731:
0732: }
0733:
0734: /**
0735: * Creates the status bar the application. Shows current project.
0736: */
0737: private void createStatusBar() {
0738: JETAPanel panel = new JETAPanel();
0739: FormLayout layout = new FormLayout("pref:grow", "pref");
0740: panel.setLayout(layout);
0741:
0742: m_status_cell = new TSCell("formcell", "left:pref:nogrow");
0743: m_status_cell.setFont(javax.swing.UIManager
0744: .getFont("Table.font"));
0745: m_status_cell
0746: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
0747: m_status_cell.setIcon(FormDesignerUtils
0748: .loadImage(Icons.APPLICATION_16));
0749: m_status_cell.setBorder(BorderFactory.createCompoundBorder(
0750: m_status_cell.getBorder(), BorderFactory
0751: .createEmptyBorder(1, 0, 0, 0)));
0752: CellConstraints cc = new CellConstraints();
0753: panel.add(m_status_cell, cc.xy(1, 1));
0754: getContentPane().add(panel, BorderLayout.SOUTH);
0755: }
0756:
0757: /**
0758: * Creates the toolbar for this frame window.
0759: */
0760: private void createToolBar() {
0761: JToolBar toolbar = new JToolBar();
0762: m_toolbar = toolbar;
0763:
0764: m_composite_finder.add(new DesignTimeComponentFinder(toolbar));
0765:
0766: toolbar.setFloatable(false);
0767:
0768: JPanel panel = new JPanel(new BorderLayout());
0769: panel.add(toolbar, BorderLayout.CENTER);
0770: getContentPane().add(panel, BorderLayout.NORTH);
0771:
0772: toolbar.add(i18n_createToolBarButton(
0773: MainFrameNames.ID_CREATE_PROJECT, Icons.NEW_PROJECT_24,
0774: "Create Project"));
0775: toolbar.add(i18n_createToolBarButton(
0776: MainFrameNames.ID_OPEN_PROJECT, Icons.OPEN_PROJECT_24,
0777: "Open Project"));
0778:
0779: toolbar
0780: .add(i18n_createToolBarButton(
0781: MainFrameNames.ID_OPEN_FORM, Icons.OPEN_24,
0782: "Open Form"));
0783: toolbar
0784: .add(i18n_createToolBarButton(
0785: MainFrameNames.ID_SAVE_FORM, Icons.SAVE_24,
0786: "Save Form"));
0787: toolbar.add(i18n_createToolBarButton(
0788: MainFrameNames.ID_CREATE_FORM, Icons.ADD_24,
0789: "Create Form"));
0790:
0791: toolbar.addSeparator();
0792:
0793: toolbar.add(i18n_createToolBarButton(TSComponentNames.ID_CUT,
0794: Icons.CUT_24, "Cut"));
0795: toolbar.add(i18n_createToolBarButton(TSComponentNames.ID_COPY,
0796: Icons.COPY_24, "Copy"));
0797: toolbar.add(i18n_createToolBarButton(TSComponentNames.ID_PASTE,
0798: Icons.PASTE_24, "Paste"));
0799:
0800: toolbar.add(i18n_createToolBarButton(TSComponentNames.ID_UNDO,
0801: Icons.UNDO_24, "Undo"));
0802: toolbar.add(i18n_createToolBarButton(TSComponentNames.ID_REDO,
0803: Icons.REDO_24, "Redo"));
0804:
0805: toolbar.addSeparator();
0806: toolbar
0807: .add(i18n_createToolBarButton(
0808: MainFrameNames.ID_SHOW_FORM, Icons.PLAY_24,
0809: "Show Form"));
0810: toolbar.addSeparator();
0811:
0812: toolbar.add(i18n_createToolBarButton(
0813: FormEditorNames.ID_INSERT_COLUMN_LEFT,
0814: Icons.COLUMN_INSERT_24, "Insert Column"));
0815: toolbar.add(i18n_createToolBarButton(
0816: FormEditorNames.ID_DELETE_COLUMN,
0817: Icons.COLUMN_DELETE_24, "Delete Column"));
0818:
0819: toolbar.add(i18n_createToolBarButton(
0820: FormEditorNames.ID_SET_AS_COLUMN_SEPARATOR,
0821: Icons.COLUMN_SEP_SMALL_24, "Set As Column Separator"));
0822: toolbar.add(i18n_createToolBarButton(
0823: FormEditorNames.ID_SET_AS_BIG_COLUMN_SEPARATOR,
0824: Icons.COLUMN_SEP_LARGE_24,
0825: "Set As Large Column Separator"));
0826: toolbar.add(i18n_createToolBarButton(
0827: FormEditorNames.ID_COLUMN_RESIZE_GROW,
0828: Icons.COLUMN_GROW_24, "Column Resize: Grow"));
0829: toolbar.add(i18n_createToolBarButton(
0830: FormEditorNames.ID_COLUMN_RESIZE_NONE,
0831: Icons.COLUMN_NOGROW_24, "Column Resize: None"));
0832: toolbar.add(i18n_createToolBarButton(
0833: FormEditorNames.ID_COLUMN_INCREASE_SPAN,
0834: Icons.COLUMN_INCREASE_SPAN_24, "Increase Column Span"));
0835: toolbar.add(i18n_createToolBarButton(
0836: FormEditorNames.ID_COLUMN_DECREASE_SPAN,
0837: Icons.COLUMN_DECREASE_SPAN_24, "Decrease Column Span"));
0838:
0839: toolbar.addSeparator();
0840: toolbar.add(i18n_createToolBarButton(
0841: FormEditorNames.ID_INSERT_ROW_ABOVE,
0842: Icons.ROW_INSERT_24, "Insert Row"));
0843:
0844: toolbar.add(i18n_createToolBarButton(
0845: FormEditorNames.ID_DELETE_ROW, Icons.ROW_DELETE_24,
0846: "Delete Row"));
0847: toolbar.add(i18n_createToolBarButton(
0848: FormEditorNames.ID_SET_AS_ROW_SEPARATOR,
0849: Icons.ROW_SEP_SMALL_24, "Set As Row Separator"));
0850: toolbar.add(i18n_createToolBarButton(
0851: FormEditorNames.ID_SET_AS_BIG_ROW_SEPARATOR,
0852: Icons.ROW_SEP_LARGE_24, "Set As Large Row Separator"));
0853:
0854: toolbar.add(i18n_createToolBarButton(
0855: FormEditorNames.ID_ROW_RESIZE_GROW, Icons.ROW_GROW_24,
0856: "Row Resize: Grow"));
0857: toolbar.add(i18n_createToolBarButton(
0858: FormEditorNames.ID_ROW_RESIZE_NONE,
0859: Icons.ROW_NOGROW_24, "Row Resize: None"));
0860: toolbar.add(i18n_createToolBarButton(
0861: FormEditorNames.ID_ROW_INCREASE_SPAN,
0862: Icons.ROW_INCREASE_SPAN_24, "Increase Row Span"));
0863: toolbar.add(i18n_createToolBarButton(
0864: FormEditorNames.ID_ROW_DECREASE_SPAN,
0865: Icons.ROW_DECREASE_SPAN_24, "Decrease Row Span"));
0866:
0867: /*
0868: * Need a better help icon toolbar.addSeparator(); javax.swing.JButton
0869: * btn = i18n_createToolBarButton( MainFrameNames.ID_HELP,
0870: * "general/Help24.gif", "Help" );
0871: * com.jeta.swingbuilder.help.HelpUtils.enableHelpOnButton( btn,
0872: * MainFrameNames.ID_HELP ); toolbar.add( btn );
0873: */
0874: }
0875:
0876: /**
0877: * Deactivates all forms in the frame
0878: */
0879: private void deactivateAllForms() {
0880: for (int index = 0; index < m_forms_tab.getTabCount(); index++) {
0881: FormEditor other_ed = (FormEditor) m_forms_tab
0882: .getComponentAt(index);
0883: other_ed.deactivate();
0884: m_formmgr.deactivateForms(other_ed);
0885: }
0886: }
0887:
0888: /**
0889: * Enables/Disables the menu/toolbar button associated with the commandid
0890: *
0891: * @param commandId
0892: * the id of the command whose button to enable/disable
0893: * @param bEnable
0894: * true/false to enable/disable
0895: */
0896: public void enableComponent(String commandId, boolean bEnable) {
0897: m_composite_finder.enableComponent(commandId, bEnable);
0898: }
0899:
0900: /**
0901: * JETAContainer implementation
0902: */
0903: public UIDirector getUIDirector() {
0904: return m_uidirector;
0905: }
0906:
0907: /**
0908: * Called when the form component's path has changed. We update the tab
0909: * label in this case.
0910: */
0911: void formNameChanged(FormComponent fc) {
0912: for (int index = 0; index < m_forms_tab.getTabCount(); index++) {
0913: FormEditor editor = (FormEditor) m_forms_tab
0914: .getComponentAt(index);
0915: if (editor.getForm() == fc) {
0916: String filename = fc.getFileName();
0917: assert (filename != null);
0918: m_forms_tab.setTitleAt(index, filename);
0919: if (fc.isEmbedded())
0920: m_forms_tab.setIconAt(index, FormDesignerUtils
0921: .loadImage(Icons.EMBEDDED_FORM_16));
0922: else
0923: m_forms_tab.setIconAt(index, FormDesignerUtils
0924: .loadImage(Icons.LINKED_FORM_16));
0925:
0926: break;
0927: }
0928: }
0929: }
0930:
0931: /**
0932: * @return the buttonbar that contains the property pane, FormSpec views,
0933: * and CellConstaint view
0934: */
0935: public TSButtonBar getButtonBar() {
0936: return m_buttonbar;
0937: }
0938:
0939: /**
0940: * JETAContainer implementation
0941: *
0942: * @return the component that is NOT a JMenuItem that has the given name
0943: */
0944: public Component getComponentByName(String compName) {
0945: return m_composite_finder.getComponentByName(compName);
0946: }
0947:
0948: /**
0949: * JETAContainer implementation
0950: *
0951: * @return all components in this frame with the given name.
0952: */
0953: public Collection getComponentsByName(String compName) {
0954: return m_composite_finder.getComponentsByName(compName);
0955: }
0956:
0957: /**
0958: * @return the editor that is currently active in the frame. Null is
0959: * returned if no editors are opened.
0960: */
0961: public FormEditor getCurrentEditor() {
0962: FormEditor editor = (FormEditor) m_forms_tab
0963: .getSelectedComponent();
0964: return editor;
0965: }
0966:
0967: /**
0968: * ComponentSource imlementation
0969: */
0970: public ComponentFactory getComponentFactory() {
0971: return m_component_tools.getComponentFactory();
0972: }
0973:
0974: public ComponentsToolBar getComponentsToolBar() {
0975: return m_component_tools;
0976: }
0977:
0978: /**
0979: * Returns the object responsible for handling dock behavior for the
0980: * properties window
0981: */
0982: FrameDocker getDocker() {
0983: return m_docker;
0984: }
0985:
0986: /**
0987: * @return the editor whose main form is the given form. If the given form
0988: * is not opened in its own editor, null is returned.
0989: */
0990: public FormEditor getEditor(FormComponent form) {
0991: for (int index = 0; index < m_forms_tab.getTabCount(); index++) {
0992: FormEditor editor = (FormEditor) m_forms_tab
0993: .getComponentAt(index);
0994: if (editor.getForm() == form)
0995: return editor;
0996: }
0997: return null;
0998: }
0999:
1000: /**
1001: * @return a collection of currently opened FormEditors
1002: */
1003: public Collection getEditors() {
1004: LinkedList editors = new LinkedList();
1005: for (int index = 0; index < m_forms_tab.getTabCount(); index++) {
1006: FormEditor editor = (FormEditor) m_forms_tab
1007: .getComponentAt(index);
1008: editors.add(editor);
1009: }
1010: return editors;
1011: }
1012:
1013: /**
1014: * @return the current project.
1015: */
1016: public ProjectModel getProject() {
1017: DefaultProjectManager pmgr = (DefaultProjectManager) JETARegistry
1018: .lookup(DefaultProjectManager.COMPONENT_ID);
1019: return pmgr.getProject();
1020: }
1021:
1022: /**
1023: * @return the property frame
1024: */
1025: public PropertyPaneContainer getPropertyContainer() {
1026: return m_propsview;
1027: }
1028:
1029: /**
1030: * @return the form that has the given id *if* it is opened in the frame.
1031: */
1032: public FormComponent getForm(String formId) {
1033: for (int index = 0; index < m_forms_tab.getTabCount(); index++) {
1034: FormEditor editor = (FormEditor) m_forms_tab
1035: .getComponentAt(index);
1036: if (formId.equals(editor.getId())) {
1037: return editor.getFormComponent();
1038: }
1039: }
1040: return null;
1041: }
1042:
1043: /** GridViewListener implementation */
1044: public void gridChanged(GridViewEvent evt) {
1045: if (evt != null) {
1046: if ((!isSelectionTool() || AbstractMouseHandler
1047: .isDragging())
1048: && evt.getId() == GridViewEvent.CELL_SELECTED) {
1049: return;
1050: }
1051:
1052: if (evt.getId() == GridViewEvent.EDIT_COMPONENT) {
1053: m_buttonbar.setCurrentView(m_propsview);
1054: }
1055: }
1056:
1057: Object obj = getCurrentControlsView();
1058: if (obj instanceof GridViewListener) {
1059: ((GridViewListener) obj).gridChanged(evt);
1060: } else {
1061: assert (false);
1062: }
1063:
1064: updateComponents();
1065:
1066: }
1067:
1068: /**
1069: * @return true if the focus manager is currently active
1070: */
1071: public void setFocusSelected(boolean focus_sel) {
1072: /*
1073: * Collection comps = getComponentsByName(
1074: * MainFrameNames.ID_FOCUS_MANAGER ); Iterator iter = comps.iterator();
1075: * while( iter.hasNext() ) { Component comp = (Component)iter.next(); if (
1076: * comp instanceof javax.swing.AbstractButton ) {
1077: * ((javax.swing.AbstractButton)comp).setSelected( focus_sel ); } }
1078: */
1079: }
1080:
1081: /**
1082: * ComponentSource imlementation
1083: */
1084: public boolean isSelectionTool() {
1085: return m_component_tools.isSelectionTool();
1086: }
1087:
1088: /**
1089: * Reloads the components toolbar because it may have changed
1090: */
1091: public void reloadComponentsToolbar() {
1092: m_component_tools.reload();
1093: m_split.revalidate();
1094: }
1095:
1096: /**
1097: * Removes the given form from the tabbed pane.
1098: */
1099: public void removeForm(String formId) {
1100: try {
1101: removeTabListener();
1102: deactivateAllForms();
1103:
1104: for (int index = 0; index < m_forms_tab.getTabCount(); index++) {
1105: FormEditor editor = (FormEditor) m_forms_tab
1106: .getComponentAt(index);
1107: if (formId.equals(editor.getForm().getId())) {
1108: m_forms_tab.remove(index);
1109: break;
1110: }
1111: }
1112: FormEditor editor = getCurrentEditor();
1113: if (editor != null) {
1114: m_formmgr.activateForm(editor.getTopParent().getId());
1115: editor.activate();
1116: }
1117: } finally {
1118: addTabListener();
1119: }
1120:
1121: if (m_forms_tab.getTabCount() == 0) {
1122: Object obj = getCurrentControlsView();
1123: if (obj instanceof GridViewListener) {
1124: ((GridViewListener) obj).gridChanged(new GridViewEvent(
1125: null, GridViewEvent.CELL_SELECTED));
1126: }
1127: } else {
1128: FormEditor editor = getCurrentEditor();
1129: gridChanged(new GridViewEvent(null,
1130: GridViewEvent.CELL_SELECTED, editor
1131: .getSelectedComponent()));
1132: }
1133: }
1134:
1135: /**
1136: * Adds the tab listener to the forms tab
1137: */
1138: private void removeTabListener() {
1139: m_forms_tab.removeChangeListener(m_tab_listener);
1140: }
1141:
1142: /**
1143: * Sets the frame location and size to the last know position.
1144: */
1145: private void initializeFrameBounds() {
1146: try {
1147: Dimension screensz = java.awt.Toolkit.getDefaultToolkit()
1148: .getScreenSize();
1149:
1150: int x = 40;
1151: int y = 40;
1152: int width = screensz.width - 80;
1153: int height = screensz.height - 80;
1154:
1155: ObjectStore os = (ObjectStore) JETARegistry
1156: .lookup(ComponentNames.APPLICATION_STATE_STORE);
1157: Rectangle rect = (Rectangle) os
1158: .load(MainFrame.ID_FRAME_BOUNDS);
1159: if (rect != null) {
1160: x = Math.max(rect.x, 20);
1161: y = Math.max(rect.y, 20);
1162: width = rect.width;
1163: height = rect.height;
1164:
1165: if ((x + width) > screensz.width)
1166: width = screensz.width - x - 40;
1167:
1168: if ((y + height) > screensz.height)
1169: height = screensz.height - y - 40;
1170:
1171: if (width < 100 || height < 100) {
1172: x = 10;
1173: y = 10;
1174: width = 700;
1175: height = 600;
1176: }
1177: }
1178: setSize(width, height);
1179: setLocation(x, y);
1180:
1181: m_docker.initializeFrameBounds();
1182: } catch (Exception e) {
1183: e.printStackTrace();
1184: setSize(700, 600);
1185: setLocation(10, 10);
1186: }
1187: }
1188:
1189: /**
1190: * Sets the current project.
1191: */
1192: public void setProject(ProjectModel pmodel) {
1193: DefaultProjectManager pmgr = (DefaultProjectManager) JETARegistry
1194: .lookup(DefaultProjectManager.COMPONENT_ID);
1195: pmgr.setProject(pmodel);
1196: if (pmodel == null)
1197: m_status_cell.setText("");
1198: else
1199: m_status_cell.setText(pmodel.getProjectPath());
1200:
1201: }
1202:
1203: /**
1204: * Sets the active component factory to the selection tool
1205: */
1206: public void setSelectionTool() {
1207: m_component_tools.setSelectionTool();
1208: }
1209:
1210: /**
1211: * Selects the form in the frame. If the form is not currently in the tab
1212: * window, a new tab is added.
1213: */
1214: public void showForm(FormComponent fc) {
1215: assert (fc != null);
1216: removeTabListener();
1217:
1218: deactivateAllForms();
1219:
1220: for (int index = 0; index < m_forms_tab.getTabCount(); index++) {
1221: FormEditor editor = (FormEditor) m_forms_tab
1222: .getComponentAt(index);
1223: assert (editor != null);
1224: if (editor.getId().equals(fc.getId())) {
1225: m_forms_tab.setSelectedIndex(index);
1226: m_formmgr.activateForm(getCurrentEditor()
1227: .getTopParent().getId());
1228: addTabListener();
1229: editor = getCurrentEditor();
1230: editor.activate();
1231: gridChanged(new GridViewEvent(null,
1232: GridViewEvent.CELL_SELECTED, editor
1233: .getSelectedComponent()));
1234: return;
1235: }
1236: }
1237:
1238: FormEditor editor = new FormEditor(this , fc);
1239: /** add form resets the tab listener */
1240: addForm(editor);
1241: editor = getCurrentEditor();
1242: editor.activate();
1243: gridChanged(new GridViewEvent(null,
1244: GridViewEvent.CELL_SELECTED, editor
1245: .getSelectedComponent()));
1246:
1247: }
1248:
1249: /**
1250: * Shuts down this frame. Saves the frame state to the object store and
1251: * Closes all open windows.
1252: */
1253: void shutDown() {
1254: try {
1255: ObjectStore os = (ObjectStore) JETARegistry
1256: .lookup(ComponentNames.APPLICATION_STATE_STORE);
1257: os.store(MainFrame.ID_FRAME_BOUNDS, getBounds());
1258:
1259: m_docker.shutDown();
1260: } catch (Exception e) {
1261: // ignore
1262: }
1263:
1264: if (m_controller.closeProject() == MainFrameController.CLOSE_OK) {
1265: dispose(); // close all open frame windows. this allows them to
1266: // save
1267: // their state
1268: com.jeta.swingbuilder.main.AbeilleForms.shutdown();
1269: }
1270: }
1271:
1272: /**
1273: * EditorManager implementation. Called when a form or forms have changed.
1274: * This tells the EditorManager to update any modified indicators on the GUI
1275: * if a form is modified/unmodified.
1276: */
1277: public void updateModifiedStatus() {
1278: for (int index = 0; index < m_forms_tab.getTabCount(); index++) {
1279: FormEditor editor = (FormEditor) m_forms_tab
1280: .getComponentAt(index);
1281: String filename = editor.getForm().getFileName();
1282: StringBuffer tab_label = new StringBuffer();
1283: if (editor.isLinked()) {
1284: filename = editor.getForm().getFileName();
1285: if (filename == null)
1286: filename = I18N.getLocalizedMessage("New Form");
1287: } else {
1288: filename = I18N.getLocalizedMessage("embedded form");
1289: }
1290:
1291: tab_label.append(filename);
1292: if (editor.isModified()) {
1293: tab_label.append('*');
1294: }
1295: m_forms_tab.setTitleAt(index, tab_label.toString());
1296: }
1297: }
1298:
1299: /**
1300: * Updates all child components when the look and feel has changed
1301: */
1302: public void updateUI() {
1303: /** first update all editors */
1304: Collection editors = getEditors();
1305: Iterator iter = editors.iterator();
1306: while (iter.hasNext()) {
1307: FormUtils.updateLookAndFeel((Component) iter.next());
1308: }
1309:
1310: Collection forms = m_formmgr.getForms();
1311: iter = forms.iterator();
1312: while (iter.hasNext()) {
1313: String formid = (String) iter.next();
1314: FormUtils.updateLookAndFeel((Component) m_formmgr
1315: .getForm(formid));
1316: }
1317:
1318: m_docker.updateUI();
1319: FormUtils.updateLookAndFeel(m_form_popup);
1320: }
1321:
1322: /**
1323: * Runs unit test routines on this Frame.
1324: */
1325: void unitTest() {
1326: if (FormDesignerUtils.isTest()) {
1327: // com.jeta.swingbuilder.test.JETATestFactory.runTest(
1328: // "test.jeta.swingbuilder.gui.main.MainFrameValidator", this );
1329: m_formmgr.unitTest();
1330: }
1331: }
1332:
1333: private void updateComponents() {
1334: UIDirector uidirector = getUIDirector();
1335: if (uidirector != null)
1336: uidirector.updateComponents(null);
1337: }
1338:
1339: /**
1340: * Listener for the Forms tab. When we get the tab changed event, we
1341: * deactivat all other forms.
1342: */
1343: private class TabListener implements
1344: javax.swing.event.ChangeListener {
1345: public void stateChanged(javax.swing.event.ChangeEvent e) {
1346: deactivateAllForms();
1347: m_formmgr.activateForm(getCurrentEditor().getTopParent()
1348: .getId());
1349: FormEditor editor = getCurrentEditor();
1350: editor.activate();
1351: unitTest();
1352: gridChanged(new GridViewEvent(null,
1353: GridViewEvent.CELL_SELECTED, editor
1354: .getSelectedComponent()));
1355: }
1356: }
1357:
1358: /**
1359: * Specialization of JScrollPane for Row/Column Spec and CellConstraints
1360: * views to help improve application startup time.
1361: */
1362: private abstract class ControlsScrollPane extends JScrollPane {
1363: private Component m_viewport_view;
1364:
1365: ControlsScrollPane() {
1366: super (JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
1367: JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
1368: }
1369:
1370: void initialize() {
1371: if (m_viewport_view == null) {
1372: m_viewport_view = loadView();
1373: setViewportView(m_viewport_view);
1374: }
1375: }
1376:
1377: protected abstract Component loadView();
1378: }
1379:
1380: }
|