Source Code Cross Referenced for FormEditorController.java in  » Swing-Library » abeille-forms-designer » com » jeta » swingbuilder » gui » main » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » abeille forms designer » com.jeta.swingbuilder.gui.main 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.Toolkit;
0022:        import java.awt.datatransfer.Clipboard;
0023:        import java.awt.datatransfer.Transferable;
0024:        import java.awt.event.ActionEvent;
0025:        import java.awt.event.ActionListener;
0026:        import java.awt.event.KeyEvent;
0027:        import java.awt.event.MouseAdapter;
0028:        import java.awt.event.MouseEvent;
0029:        import java.util.Collection;
0030:        import java.util.Iterator;
0031:
0032:        import javax.swing.AbstractAction;
0033:        import javax.swing.ActionMap;
0034:        import javax.swing.InputMap;
0035:        import javax.swing.JOptionPane;
0036:        import javax.swing.JPopupMenu;
0037:        import javax.swing.KeyStroke;
0038:
0039:        import com.jeta.forms.gui.common.FormUtils;
0040:        import com.jeta.forms.gui.components.EmptyComponentFactory;
0041:        import com.jeta.forms.gui.form.FormComponent;
0042:        import com.jeta.forms.gui.form.FormComponentFactory;
0043:        import com.jeta.forms.gui.form.GridCellEvent;
0044:        import com.jeta.forms.gui.form.GridComponent;
0045:        import com.jeta.forms.gui.form.GridView;
0046:        import com.jeta.forms.gui.formmgr.FormManager;
0047:        import com.jeta.forms.logger.FormsLogger;
0048:        import com.jeta.forms.store.memento.ComponentMemento;
0049:        import com.jeta.forms.store.memento.ComponentMementoProxy;
0050:        import com.jeta.forms.store.properties.effects.PaintProperty;
0051:        import com.jeta.open.gui.framework.JETAController;
0052:        import com.jeta.open.gui.framework.JETADialog;
0053:        import com.jeta.open.gui.utils.JETAToolbox;
0054:        import com.jeta.open.i18n.I18N;
0055:        import com.jeta.open.registry.JETARegistry;
0056:        import com.jeta.swingbuilder.gui.commands.CommandUtils;
0057:        import com.jeta.swingbuilder.gui.commands.CompositeCommand;
0058:        import com.jeta.swingbuilder.gui.commands.DeleteColumnCommand;
0059:        import com.jeta.swingbuilder.gui.commands.DeleteComponentCommand;
0060:        import com.jeta.swingbuilder.gui.commands.DeleteRowCommand;
0061:        import com.jeta.swingbuilder.gui.commands.EditColumnSpecCommand;
0062:        import com.jeta.swingbuilder.gui.commands.EditRowSpecCommand;
0063:        import com.jeta.swingbuilder.gui.commands.EditTextPropertyCommand;
0064:        import com.jeta.swingbuilder.gui.commands.FormUndoableEdit;
0065:        import com.jeta.swingbuilder.gui.commands.InsertColumnCommand;
0066:        import com.jeta.swingbuilder.gui.commands.InsertRowCommand;
0067:        import com.jeta.swingbuilder.gui.commands.ReplaceComponentCommand;
0068:        import com.jeta.swingbuilder.gui.commands.SetCellBackgroundCommand;
0069:        import com.jeta.swingbuilder.gui.commands.SetPropertyCommand;
0070:        import com.jeta.swingbuilder.gui.commands.TrimColumnsCommand;
0071:        import com.jeta.swingbuilder.gui.commands.TrimRowsCommand;
0072:        import com.jeta.swingbuilder.gui.components.TSComponentNames;
0073:        import com.jeta.swingbuilder.gui.dnd.ComponentTransferable;
0074:        import com.jeta.swingbuilder.gui.dnd.DesignerDragSource;
0075:        import com.jeta.swingbuilder.gui.dnd.FormObjectFlavor;
0076:        import com.jeta.swingbuilder.gui.editor.DesignGridOverlay;
0077:        import com.jeta.swingbuilder.gui.editor.FormEditor;
0078:        import com.jeta.swingbuilder.gui.formmgr.FormManagerDesignUtils;
0079:        import com.jeta.swingbuilder.gui.project.UserPreferencesNames;
0080:        import com.jeta.swingbuilder.gui.properties.PropertyPaneContainer;
0081:        import com.jeta.swingbuilder.gui.undo.UndoableEditProxy;
0082:        import com.jeta.swingbuilder.gui.utils.FormDesignerUtils;
0083:        import com.jeta.swingbuilder.interfaces.userprops.TSUserPropertiesUtils;
0084:        import com.jgoodies.forms.layout.ColumnSpec;
0085:        import com.jgoodies.forms.layout.RowSpec;
0086:        import com.jgoodies.forms.layout.Sizes;
0087:
0088:        /**
0089:         * Handles user events for the FormEditorFrame
0090:         * 
0091:         * @author Jeff Tassin
0092:         */
0093:        public abstract class FormEditorController extends JETAController {
0094:            private MainFrame m_frame;
0095:
0096:            /**
0097:             * Popup menu
0098:             */
0099:            private JPopupMenu m_popup;
0100:
0101:            /**
0102:             * ctor
0103:             */
0104:            public FormEditorController(MainFrame frame, JPopupMenu popup) {
0105:                super (frame);
0106:                m_frame = frame;
0107:                m_popup = popup;
0108:
0109:                assignAction(TSComponentNames.ID_CUT, new CutAction());
0110:                assignAction(TSComponentNames.ID_COPY, new CopyAction());
0111:                assignAction(TSComponentNames.ID_PASTE, new PasteAction());
0112:                assignAction(FormEditorNames.ID_PASTE_SPECIAL,
0113:                        new PasteSpecialAction());
0114:                assignAction(TSComponentNames.ID_UNDO, new UndoAction());
0115:                assignAction(TSComponentNames.ID_REDO, new RedoAction());
0116:
0117:                assignAction(FormEditorNames.ID_INSERT_ROW_ABOVE,
0118:                        new InsertRowAction(true));
0119:                assignAction(FormEditorNames.ID_INSERT_ROW_BELOW,
0120:                        new InsertRowAction(false));
0121:                assignAction(FormEditorNames.ID_INSERT_COLUMN_LEFT,
0122:                        new InsertColumnAction(true));
0123:                assignAction(FormEditorNames.ID_INSERT_COLUMN_RIGHT,
0124:                        new InsertColumnAction(false));
0125:                assignAction(FormEditorNames.ID_DELETE_COLUMN,
0126:                        new DeleteColumnAction());
0127:                assignAction(FormEditorNames.ID_DELETE_ROW,
0128:                        new DeleteRowAction());
0129:                assignAction(FormEditorNames.ID_SET_AS_COLUMN_SEPARATOR,
0130:                        new SetColumnSeparatorAction(true));
0131:                assignAction(FormEditorNames.ID_SET_AS_BIG_COLUMN_SEPARATOR,
0132:                        new SetColumnSeparatorAction(false));
0133:                assignAction(FormEditorNames.ID_SET_AS_ROW_SEPARATOR,
0134:                        new SetRowSeparatorAction(true));
0135:                assignAction(FormEditorNames.ID_SET_AS_BIG_ROW_SEPARATOR,
0136:                        new SetRowSeparatorAction(false));
0137:
0138:                assignAction(FormEditorNames.ID_COLUMN_DECREASE_SPAN,
0139:                        new IncrementColumnSpanAction(false));
0140:                assignAction(FormEditorNames.ID_COLUMN_INCREASE_SPAN,
0141:                        new IncrementColumnSpanAction(true));
0142:                assignAction(FormEditorNames.ID_ROW_DECREASE_SPAN,
0143:                        new IncrementRowSpanAction(false));
0144:                assignAction(FormEditorNames.ID_ROW_INCREASE_SPAN,
0145:                        new IncrementRowSpanAction(true));
0146:
0147:                assignAction(FormEditorNames.ID_COLUMN_PREFERRED_SIZE,
0148:                        new ColumnSetPreferredSizeAction());
0149:                assignAction(FormEditorNames.ID_ROW_PREFERRED_SIZE,
0150:                        new RowSetPreferredSizeAction());
0151:
0152:                assignAction(FormEditorNames.ID_SHOW_GRID, new ShowGridAction());
0153:
0154:                assignAction(FormEditorNames.ID_TRIM_ROWS, new TrimRowsAction());
0155:                assignAction(FormEditorNames.ID_TRIM_COLUMNS,
0156:                        new TrimColumnsAction());
0157:                assignAction(FormEditorNames.ID_DELETE_COMPONENT,
0158:                        new DeleteComponentAction());
0159:
0160:                assignAction(FormEditorNames.ID_COLUMN_RESIZE_GROW,
0161:                        new ColumnResizeAction(true));
0162:                assignAction(FormEditorNames.ID_COLUMN_RESIZE_NONE,
0163:                        new ColumnResizeAction(false));
0164:                assignAction(FormEditorNames.ID_ROW_RESIZE_GROW,
0165:                        new RowResizeAction(true));
0166:                assignAction(FormEditorNames.ID_ROW_RESIZE_NONE,
0167:                        new RowResizeAction(false));
0168:            }
0169:
0170:            /**
0171:             * @return the current form editor
0172:             */
0173:            public abstract FormEditor getCurrentEditor();
0174:
0175:            /**
0176:             * Installs handlers for a specific editor
0177:             */
0178:            void installHandlers(FormEditor editor) {
0179:                DesignGridOverlay overlay = (DesignGridOverlay) editor
0180:                        .getTopOverlay();
0181:                overlay.addMouseListener(new ContextMouseListener());
0182:
0183:                InputMap inputmap = overlay.getInputMap();
0184:                ActionMap actionmap = overlay.getActionMap();
0185:
0186:                inputmap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0,
0187:                        false), FormEditorNames.ID_DELETE_COMPONENT);
0188:                inputmap.put(
0189:                        KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0, false),
0190:                        FormEditorNames.ID_NAVIGATE_LEFT);
0191:                inputmap.put(KeyStroke
0192:                        .getKeyStroke(KeyEvent.VK_RIGHT, 0, false),
0193:                        FormEditorNames.ID_NAVIGATE_RIGHT);
0194:                inputmap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0, false),
0195:                        FormEditorNames.ID_NAVIGATE_UP);
0196:                inputmap.put(
0197:                        KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0, false),
0198:                        FormEditorNames.ID_NAVIGATE_DOWN);
0199:                inputmap.put(KeyStroke
0200:                        .getKeyStroke(KeyEvent.VK_ENTER, 0, false),
0201:                        FormEditorNames.ID_EDIT_COMPONENT_PROPERTIES);
0202:                inputmap.put(KeyStroke
0203:                        .getKeyStroke(KeyEvent.VK_SPACE, 0, false),
0204:                        FormEditorNames.ID_EDIT_COMPONENT_NAME);
0205:                inputmap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0,
0206:                        false), FormEditorNames.ID_CANCEL_DRAG);
0207:
0208:                actionmap.put(FormEditorNames.ID_DELETE_COMPONENT,
0209:                        new DeleteComponentAction());
0210:                actionmap.put(FormEditorNames.ID_NAVIGATE_LEFT,
0211:                        new LeftAction());
0212:                actionmap.put(FormEditorNames.ID_NAVIGATE_RIGHT,
0213:                        new RightAction());
0214:                actionmap.put(FormEditorNames.ID_NAVIGATE_UP, new UpAction());
0215:                actionmap.put(FormEditorNames.ID_NAVIGATE_DOWN,
0216:                        new DownAction());
0217:                actionmap.put(FormEditorNames.ID_EDIT_COMPONENT_PROPERTIES,
0218:                        new EditComponentAction());
0219:                actionmap.put(FormEditorNames.ID_EDIT_COMPONENT_NAME,
0220:                        new EditComponentNameAction());
0221:                actionmap.put(FormEditorNames.ID_CANCEL_DRAG,
0222:                        new EscapeAction());
0223:            }
0224:
0225:            /**
0226:             * Creates a paste command. Gets a grid component memento from the
0227:             * clipboard, instantiates a new component, sets the state and places it on
0228:             * the parent view
0229:             */
0230:            private FormUndoableEdit getPasteCommand(GridView parentView,
0231:                    Transferable transferable) {
0232:                try {
0233:                    GridComponent oldcomp = getCurrentEditor()
0234:                            .getSelectedComponent();
0235:                    if (oldcomp != null) {
0236:                        ComponentMementoProxy cmproxy = (ComponentMementoProxy) transferable
0237:                                .getTransferData(FormObjectFlavor.COMPONENT_MEMENTO);
0238:                        ComponentMemento cm = cmproxy.getComponentMemento();
0239:
0240:                        Class compclass = Class.forName(cm.getComponentClass());
0241:                        GridComponent newcomp = null;
0242:                        if (FormComponent.class.isAssignableFrom(compclass)) {
0243:                            FormComponentFactory factory = (FormComponentFactory) JETARegistry
0244:                                    .lookup(FormComponentFactory.COMPONENT_ID);
0245:                            newcomp = factory.createFormComponent();
0246:                        } else {
0247:                            newcomp = (GridComponent) compclass.newInstance();
0248:                        }
0249:                        newcomp.setParentView(parentView);
0250:                        newcomp.setState(cm);
0251:
0252:                        FormManager fmgr = (FormManager) JETARegistry
0253:                                .lookup(FormManager.COMPONENT_ID);
0254:                        if (newcomp instanceof  FormComponent) {
0255:                            FormManagerDesignUtils.registerForms(fmgr,
0256:                                    (FormComponent) newcomp);
0257:                        }
0258:                        fmgr.installHandlers(getCurrentEditor()
0259:                                .getComponentSource(), newcomp);
0260:                        ReplaceComponentCommand cmd = new ReplaceComponentCommand(
0261:                                newcomp, oldcomp, parentView.getParentForm());
0262:                        return cmd;
0263:                    }
0264:                } catch (Exception e) {
0265:                    FormsLogger.severe(e);
0266:                }
0267:                return null;
0268:            }
0269:
0270:            /**
0271:             * Gets a Grid component memento from the clipboard, instantiates a new
0272:             * component, sets the state and places it on the parent view
0273:             */
0274:            private void pasteComponent(GridView parentView,
0275:                    Transferable transferable) {
0276:                try {
0277:                    CommandUtils.invoke(getPasteCommand(parentView,
0278:                            transferable), getCurrentEditor());
0279:                } catch (Exception e) {
0280:                    FormsLogger.severe(e);
0281:                }
0282:            }
0283:
0284:            public class IncrementColumnSpanAction extends AbstractAction {
0285:                /*
0286:                 * Set to false to decrement
0287:                 */
0288:                private boolean m_increment = true;
0289:
0290:                public IncrementColumnSpanAction(boolean increase) {
0291:                    m_increment = increase;
0292:                }
0293:
0294:                public void actionPerformed(ActionEvent evt) {
0295:                    GridComponent gc = getCurrentEditor()
0296:                            .getSelectedComponent();
0297:                    if (gc != null) {
0298:                        int colspan = gc.getColumnSpan();
0299:                        if (m_increment)
0300:                            colspan++;
0301:                        else
0302:                            colspan--;
0303:
0304:                        FormDesignerUtils.setSpan(gc, colspan, gc.getRowSpan());
0305:                    }
0306:                }
0307:            }
0308:
0309:            public class IncrementRowSpanAction extends AbstractAction {
0310:                /*
0311:                 * Set to false to decrement
0312:                 */
0313:                private boolean m_increment = true;
0314:
0315:                public IncrementRowSpanAction(boolean increase) {
0316:                    m_increment = increase;
0317:                }
0318:
0319:                public void actionPerformed(ActionEvent evt) {
0320:                    GridComponent gc = getCurrentEditor()
0321:                            .getSelectedComponent();
0322:                    if (gc != null) {
0323:                        int rowspan = gc.getRowSpan();
0324:                        if (m_increment)
0325:                            rowspan++;
0326:                        else
0327:                            rowspan--;
0328:
0329:                        FormDesignerUtils.setSpan(gc, gc.getColumnSpan(),
0330:                                rowspan);
0331:                    }
0332:                }
0333:            }
0334:
0335:            /**
0336:             * Sets the size behavior to preferred for the selected column
0337:             */
0338:            public class ColumnSetPreferredSizeAction extends AbstractAction {
0339:                public void actionPerformed(ActionEvent evt) {
0340:                    GridComponent gc = getCurrentEditor()
0341:                            .getSelectedComponent();
0342:                    if (gc != null) {
0343:                        GridView view = gc.getParentView();
0344:                        int col = gc.getColumn();
0345:                        ColumnSpec oldspec = view.getFormLayout()
0346:                                .getColumnSpec(col);
0347:                        ColumnSpec newspec = new ColumnSpec(oldspec
0348:                                .getDefaultAlignment(), Sizes.PREFERRED,
0349:                                oldspec.getResizeWeight());
0350:                        EditColumnSpecCommand cmd = new EditColumnSpecCommand(
0351:                                view.getParentForm(), col, newspec, oldspec);
0352:                        CommandUtils.invoke(cmd, getCurrentEditor());
0353:                    }
0354:                }
0355:            }
0356:
0357:            /**
0358:             * Copies the selected bean and places it on the clipboard
0359:             */
0360:            public class CopyAction implements  ActionListener {
0361:                public void actionPerformed(ActionEvent evt) {
0362:                    try {
0363:                        System.out
0364:                                .println("CopyAction........................ ");
0365:                        GridComponent gc = getCurrentEditor()
0366:                                .getSelectedComponent();
0367:                        if (gc != null) {
0368:                            ComponentTransferable transferable = new ComponentTransferable(
0369:                                    gc);
0370:                            Toolkit kit = Toolkit.getDefaultToolkit();
0371:                            Clipboard clipboard = kit.getSystemClipboard();
0372:                            clipboard.setContents(transferable, null);
0373:                        }
0374:                    } catch (Exception e) {
0375:                        e.printStackTrace();
0376:                    }
0377:                }
0378:            }
0379:
0380:            /**
0381:             * Deletes the selected bean and places it on the clipboard
0382:             */
0383:            public class CutAction implements  ActionListener {
0384:                public void actionPerformed(ActionEvent evt) {
0385:                    GridComponent gc = getCurrentEditor()
0386:                            .getSelectedComponent();
0387:                    if (gc != null) {
0388:                        FormEditorController.this 
0389:                                .invokeAction(TSComponentNames.ID_COPY);
0390:                        FormEditorController.this 
0391:                                .invokeAction(FormEditorNames.ID_DELETE_COMPONENT);
0392:                    }
0393:                }
0394:            }
0395:
0396:            /**
0397:             * Deletes the selected column. Any components in the column are deleted as
0398:             * well.
0399:             */
0400:            public class DeleteColumnAction extends AbstractAction {
0401:                public void actionPerformed(ActionEvent evt) {
0402:                    GridComponent gc = getCurrentEditor()
0403:                            .getSelectedComponent();
0404:                    if (gc != null) {
0405:                        GridView view = gc.getParentView();
0406:                        if (view != null && view.getColumnCount() > 1) {
0407:                            int row = gc.getRow();
0408:                            int col = gc.getColumn();
0409:
0410:                            DeleteColumnCommand cmd = new DeleteColumnCommand(
0411:                                    view.getParentForm(), col,
0412:                                    getCurrentEditor().getComponentSource());
0413:                            CommandUtils.invoke(cmd, getCurrentEditor());
0414:                            if (col > view.getColumnCount())
0415:                                col--;
0416:
0417:                            gc = view.getGridComponent(col, row);
0418:                            if (gc != null)
0419:                                gc.setSelected(true);
0420:
0421:                            FormManagerDesignUtils.clearUnreferencedForms();
0422:
0423:                        }
0424:                    }
0425:                }
0426:            }
0427:
0428:            /**
0429:             * Deletes the selected bean from the view
0430:             */
0431:            public class DeleteComponentAction extends AbstractAction {
0432:                public void actionPerformed(ActionEvent evt) {
0433:                    GridComponent gc = getCurrentEditor()
0434:                            .getSelectedComponent();
0435:                    if (gc != null) {
0436:                        DeleteComponentCommand cmd = new DeleteComponentCommand(
0437:                                gc, getCurrentEditor().getComponentSource());
0438:                        CommandUtils.invoke(cmd, getCurrentEditor());
0439:                        FormManagerDesignUtils.clearUnreferencedForms();
0440:                    }
0441:                }
0442:            }
0443:
0444:            /**
0445:             * Deletes the selected row. Any components in the row are deleted as well.
0446:             */
0447:            public class DeleteRowAction extends AbstractAction {
0448:                public void actionPerformed(ActionEvent evt) {
0449:                    GridComponent gc = getCurrentEditor()
0450:                            .getSelectedComponent();
0451:                    if (gc != null) {
0452:                        GridView view = gc.getParentView();
0453:                        if (view != null && view.getRowCount() > 1) {
0454:                            int row = gc.getRow();
0455:                            int col = gc.getColumn();
0456:                            DeleteRowCommand cmd = new DeleteRowCommand(view
0457:                                    .getParentForm(), row, getCurrentEditor()
0458:                                    .getComponentSource());
0459:                            CommandUtils.invoke(cmd, getCurrentEditor());
0460:                            if (row > view.getRowCount())
0461:                                row--;
0462:
0463:                            gc = view.getGridComponent(col, row);
0464:                            if (gc != null)
0465:                                gc.setSelected(true);
0466:
0467:                            FormManagerDesignUtils.clearUnreferencedForms();
0468:
0469:                        }
0470:                    }
0471:                }
0472:            }
0473:
0474:            /**
0475:             * Selects the cell immediately below the current cell
0476:             */
0477:            public class DownAction extends AbstractAction {
0478:                public void actionPerformed(ActionEvent evt) {
0479:                    GridComponent gc = getCurrentEditor()
0480:                            .getSelectedComponent();
0481:                    GridView view = gc.getParentView();
0482:                    if (gc != null) {
0483:                        if (view != null) {
0484:                            int row = gc.getRow();
0485:                            int col = gc.getColumn();
0486:                            row++;
0487:                            if (row > view.getRowCount()) {
0488:                                row = 1;
0489:                                col++;
0490:                                if (col > view.getColumnCount())
0491:                                    col = 1;
0492:                            }
0493:                            GridComponent next = view
0494:                                    .getGridComponent(col, row);
0495:                            gc.setSelected(false);
0496:                            next.setSelected(true);
0497:                        }
0498:                    }
0499:                }
0500:            }
0501:
0502:            /**
0503:             * Edits the row spec for the selected row
0504:             */
0505:            public class EditColumnSpecAction implements  ActionListener {
0506:                public void actionPerformed(ActionEvent evt) {
0507:                    GridComponent gc = getCurrentEditor()
0508:                            .getSelectedComponent();
0509:                    if (gc != null) {
0510:                        GridView view = gc.getParentView();
0511:                        if (view != null) {
0512:                            int col = gc.getColumn();
0513:                            // temporary dialog
0514:
0515:                            ColumnSpec oldspec = view.getFormLayout()
0516:                                    .getColumnSpec(col);
0517:                            String newspec = javax.swing.JOptionPane
0518:                                    .showInputDialog(
0519:                                            m_frame,
0520:                                            I18N
0521:                                                    .getLocalizedMessage("Column Spec:"),
0522:                                            oldspec.toString());
0523:                            if (newspec != null) {
0524:                                EditColumnSpecCommand cmd = new EditColumnSpecCommand(
0525:                                        view.getParentForm(), col,
0526:                                        new ColumnSpec(newspec), oldspec);
0527:                                CommandUtils.invoke(cmd, getCurrentEditor());
0528:                            }
0529:                        }
0530:                    } else {
0531:                        System.out
0532:                                .println("FormEditorFrameComponent.editColumnSpec  selected comp is null");
0533:                    }
0534:                }
0535:            }
0536:
0537:            /**
0538:             * Sends a message to the property editor to show the properties for the
0539:             * selected component
0540:             */
0541:            public class EditComponentAction extends AbstractAction {
0542:                public void actionPerformed(ActionEvent evt) {
0543:                    GridComponent gc = getCurrentEditor()
0544:                            .getSelectedComponent();
0545:                    if (gc != null) {
0546:                        EditTextPropertyCommand.tryEditTextProperty(FormEditor
0547:                                .getEditor(gc),
0548:                                FormComponent.getParentForm(gc), gc);
0549:                        gc.fireGridCellEvent(new GridCellEvent(
0550:                                GridCellEvent.EDIT_COMPONENT, gc));
0551:                    }
0552:                }
0553:            }
0554:
0555:            /**
0556:             * Sends a message to the property editor to show the properties for the
0557:             * selected component
0558:             */
0559:            public class EditComponentNameAction extends AbstractAction {
0560:                public void actionPerformed(ActionEvent evt) {
0561:                    GridComponent gc = getCurrentEditor()
0562:                            .getSelectedComponent();
0563:                    if (gc != null) {
0564:                        java.awt.Component comp = gc.getBeanDelegate();
0565:                        if (comp != null) {
0566:                            String oldname = comp.getName();
0567:                            String newvalue = javax.swing.JOptionPane
0568:                                    .showInputDialog(m_frame, I18N
0569:                                            .getLocalizedMessage("Set Name"),
0570:                                            oldname);
0571:                            if (newvalue != null) {
0572:                                comp.setName(newvalue);
0573:                                gc.fireGridCellEvent(new GridCellEvent(
0574:                                        GridCellEvent.EDIT_COMPONENT, gc,
0575:                                        GridCellEvent.COMPONENT_NAME_CHANGED));
0576:                            }
0577:                        }
0578:                    }
0579:                }
0580:            }
0581:
0582:            /**
0583:             * Edits the row spec for the selected row
0584:             */
0585:            public class EditRowSpecAction implements  ActionListener {
0586:                public void actionPerformed(ActionEvent evt) {
0587:                    GridComponent gc = getCurrentEditor()
0588:                            .getSelectedComponent();
0589:                    if (gc != null) {
0590:                        GridView view = gc.getParentView();
0591:                        if (view != null) {
0592:                            int row = gc.getRow();
0593:                            // temporary dialog
0594:
0595:                            RowSpec oldspec = view.getFormLayout().getRowSpec(
0596:                                    row);
0597:                            String newspec = javax.swing.JOptionPane
0598:                                    .showInputDialog(m_frame, I18N
0599:                                            .getLocalizedMessage("Row Spec:"),
0600:                                            oldspec.toString());
0601:                            if (newspec != null) {
0602:                                EditRowSpecCommand cmd = new EditRowSpecCommand(
0603:                                        view.getParentForm(), row, new RowSpec(
0604:                                                newspec), oldspec);
0605:                                CommandUtils.invoke(cmd, getCurrentEditor());
0606:                            }
0607:                        }
0608:                    }
0609:                }
0610:            }
0611:
0612:            public class EscapeAction extends AbstractAction {
0613:                public void actionPerformed(ActionEvent evt) {
0614:                    DesignerDragSource dds = (DesignerDragSource) JETARegistry
0615:                            .lookup(DesignerDragSource.COMPONENT_ID);
0616:                    if (dds != null)
0617:                        dds.cancelDrag();
0618:                }
0619:            }
0620:
0621:            /**
0622:             * Inserts a new column into the selected view
0623:             */
0624:            public class InsertColumnAction implements  ActionListener {
0625:                /**
0626:                 * Flag that indicates if column should be inserted immediately to
0627:                 * left/right of selected column.
0628:                 */
0629:                private boolean m_left = true;
0630:
0631:                /**
0632:                 * ctor
0633:                 */
0634:                public InsertColumnAction(boolean bleft) {
0635:                    m_left = bleft;
0636:                }
0637:
0638:                public void actionPerformed(ActionEvent evt) {
0639:                    GridComponent gc = getCurrentEditor()
0640:                            .getSelectedComponent();
0641:                    if (gc != null) {
0642:                        GridView view = gc.getParentView();
0643:                        if (view != null) {
0644:                            int col = gc.getColumn();
0645:                            String colspec = "d";
0646:                            if (!m_left)
0647:                                col++;
0648:
0649:                            InsertColumnCommand cmd = new InsertColumnCommand(
0650:                                    view.getParentForm(), col, new ColumnSpec(
0651:                                            colspec),
0652:                                    new EmptyComponentFactory(
0653:                                            getCurrentEditor()
0654:                                                    .getComponentSource()));
0655:                            CommandUtils.invoke(cmd, getCurrentEditor());
0656:                        }
0657:                    }
0658:                }
0659:            }
0660:
0661:            /**
0662:             * Inserts a new row into the selected view
0663:             */
0664:            public class InsertRowAction implements  ActionListener {
0665:                private boolean m_above = true;
0666:
0667:                /**
0668:                 * ctor
0669:                 */
0670:                public InsertRowAction(boolean babove) {
0671:                    m_above = babove;
0672:                }
0673:
0674:                public void actionPerformed(ActionEvent evt) {
0675:                    GridComponent gc = getCurrentEditor()
0676:                            .getSelectedComponent();
0677:                    if (gc != null) {
0678:                        GridView view = gc.getParentView();
0679:                        if (view != null) {
0680:                            int row = gc.getRow();
0681:                            if (!m_above)
0682:                                row++;
0683:
0684:                            String rowspec = "d";
0685:                            InsertRowCommand cmd = new InsertRowCommand(view
0686:                                    .getParentForm(), row,
0687:                                    new RowSpec(rowspec),
0688:                                    new EmptyComponentFactory(
0689:                                            getCurrentEditor()
0690:                                                    .getComponentSource()));
0691:                            CommandUtils.invoke(cmd, getCurrentEditor());
0692:                        }
0693:                    }
0694:                }
0695:            }
0696:
0697:            /**
0698:             * Selects the cell to the immediate left
0699:             */
0700:            public class LeftAction extends AbstractAction {
0701:                public void actionPerformed(ActionEvent evt) {
0702:                    GridComponent gc = getCurrentEditor()
0703:                            .getSelectedComponent();
0704:                    if (gc != null) {
0705:                        GridView view = gc.getParentView();
0706:                        if (view != null) {
0707:                            int row = gc.getRow();
0708:                            int col = gc.getColumn();
0709:                            col--;
0710:                            if (col < 1) {
0711:                                col = view.getColumnCount();
0712:                                row--;
0713:                                if (row < 1)
0714:                                    row = view.getRowCount();
0715:                            }
0716:                            GridComponent next = view
0717:                                    .getGridComponent(col, row);
0718:                            gc.setSelected(false);
0719:                            next.setSelected(true);
0720:                        }
0721:                    }
0722:                }
0723:            }
0724:
0725:            /**
0726:             * Selects the cell to the immediate right
0727:             */
0728:            public class RightAction extends AbstractAction {
0729:                public void actionPerformed(ActionEvent evt) {
0730:                    GridComponent gc = getCurrentEditor()
0731:                            .getSelectedComponent();
0732:                    if (gc != null) {
0733:                        GridView view = gc.getParentView();
0734:                        if (view != null) {
0735:                            int row = gc.getRow();
0736:                            int col = gc.getColumn();
0737:                            col++;
0738:                            if (col > view.getColumnCount()) {
0739:                                col = 1;
0740:                                row++;
0741:                                if (row > view.getRowCount())
0742:                                    row = 1;
0743:                            }
0744:                            GridComponent next = view
0745:                                    .getGridComponent(col, row);
0746:                            gc.setSelected(false);
0747:                            next.setSelected(true);
0748:                        }
0749:                    }
0750:                }
0751:            }
0752:
0753:            /**
0754:             * Pastes any components from the system clipboard
0755:             */
0756:            public class PasteAction extends AbstractAction {
0757:                public void actionPerformed(ActionEvent evt) {
0758:                    try {
0759:                        GridComponent oldcomp = getCurrentEditor()
0760:                                .getSelectedComponent();
0761:                        if (oldcomp != null) {
0762:                            GridView view = oldcomp.getParentView();
0763:                            Toolkit kit = Toolkit.getDefaultToolkit();
0764:                            Clipboard clipboard = kit.getSystemClipboard();
0765:                            Transferable transferable = clipboard
0766:                                    .getContents(null);
0767:                            if (transferable
0768:                                    .isDataFlavorSupported(FormObjectFlavor.LINKED_FORM_SET)) {
0769:                                FormComponent parentform = view.getParentForm();
0770:
0771:                                Collection forms = (Collection) transferable
0772:                                        .getTransferData(FormObjectFlavor.LINKED_FORM_SET);
0773:                                Iterator iter = forms.iterator();
0774:                                while (iter.hasNext()) {
0775:                                    String form_id = (String) iter.next();
0776:                                    if (FormManagerDesignUtils.containsForm(
0777:                                            getCurrentEditor().getForm(),
0778:                                            form_id)) {
0779:                                        String msg = I18N.format(
0780:                                                "linked_form_once_per_view_1",
0781:                                                form_id);
0782:                                        String title = I18N
0783:                                                .getLocalizedMessage("Error");
0784:                                        JOptionPane.showMessageDialog(m_frame,
0785:                                                msg, title,
0786:                                                JOptionPane.ERROR_MESSAGE);
0787:                                        return;
0788:                                    }
0789:                                }
0790:
0791:                                if (transferable
0792:                                        .isDataFlavorSupported(FormObjectFlavor.LINKED_FORM)) {
0793:                                    // means we have a top level linked form
0794:                                    FormManager fmgr = (FormManager) JETARegistry
0795:                                            .lookup(FormManager.COMPONENT_ID);
0796:                                    String form_path = (String) transferable
0797:                                            .getTransferData(FormObjectFlavor.LINKED_FORM);
0798:                                    FormComponent form = fmgr
0799:                                            .openLinkedForm(form_path);
0800:                                    fmgr.activateForm(form.getId());
0801:                                    ReplaceComponentCommand cmd = new ReplaceComponentCommand(
0802:                                            form, oldcomp, view.getParentForm());
0803:                                    CommandUtils
0804:                                            .invoke(cmd, getCurrentEditor());
0805:                                } else if (transferable
0806:                                        .isDataFlavorSupported(FormObjectFlavor.COMPONENT_MEMENTO)) {
0807:                                    // means we have a top level embedded form with
0808:                                    // nested
0809:                                    // links
0810:                                    pasteComponent(view, transferable);
0811:                                }
0812:                            } else if (transferable
0813:                                    .isDataFlavorSupported(FormObjectFlavor.COMPONENT_MEMENTO)) {
0814:                                pasteComponent(view, transferable);
0815:                            } else if (transferable
0816:                                    .isDataFlavorSupported(FormObjectFlavor.CELL_BACKGROUND)) {
0817:                                int col = oldcomp.getColumn();
0818:                                int row = oldcomp.getRow();
0819:                                PaintProperty paint = (PaintProperty) transferable
0820:                                        .getTransferData(FormObjectFlavor.CELL_BACKGROUND);
0821:                                PaintProperty oldpaint = view.getPaintProperty(
0822:                                        col, row);
0823:                                SetCellBackgroundCommand cmd = new SetCellBackgroundCommand(
0824:                                        view.getParentForm(), col, row, paint,
0825:                                        oldpaint);
0826:                                CommandUtils.invoke(cmd, getCurrentEditor());
0827:                            }
0828:                        }
0829:                    } catch (Exception e) {
0830:                        e.printStackTrace();
0831:                    }
0832:                }
0833:            }
0834:
0835:            /**
0836:             * Invokes the paste special dialog
0837:             */
0838:            public class PasteSpecialAction extends AbstractAction {
0839:                public void actionPerformed(ActionEvent evt) {
0840:                    try {
0841:                        GridComponent oldcomp = getCurrentEditor()
0842:                                .getSelectedComponent();
0843:                        if (oldcomp != null) {
0844:                            GridView gridview = oldcomp.getParentView();
0845:                            Toolkit kit = Toolkit.getDefaultToolkit();
0846:                            Clipboard clipboard = kit.getSystemClipboard();
0847:                            Transferable transferable = clipboard
0848:                                    .getContents(null);
0849:                            PasteSpecialView view = new PasteSpecialView(
0850:                                    transferable);
0851:                            JETADialog dlg = JETAToolbox.invokeDialog(view,
0852:                                    gridview,
0853:                                    I18N.getLocalizedMessage("Paste Special"));
0854:                            if (dlg.isOk()) {
0855:                                int col = oldcomp.getColumn();
0856:                                int row = oldcomp.getRow();
0857:
0858:                                FormUndoableEdit cmd = null;
0859:
0860:                                if (transferable
0861:                                        .isDataFlavorSupported(FormObjectFlavor.LINKED_FORM_SET)
0862:                                        && view
0863:                                                .isSelected(PasteSpecialNames.ID_LINKED_AS_EMBEDDED)) {
0864:
0865:                                    /**
0866:                                     * if LINKED_FORM is supported, then GRID_COMPONENT
0867:                                     * must also be supported
0868:                                     */
0869:                                    if (transferable
0870:                                            .isDataFlavorSupported(FormObjectFlavor.COMPONENT_MEMENTO)) {
0871:                                        cmd = getPasteCommand(gridview,
0872:                                                transferable);
0873:                                    } else {
0874:                                        assert (false);
0875:                                    }
0876:                                } else if (transferable
0877:                                        .isDataFlavorSupported(FormObjectFlavor.COMPONENT_MEMENTO)
0878:                                        && view
0879:                                                .isSelected(PasteSpecialNames.ID_COMPONENT)) {
0880:                                    cmd = getPasteCommand(gridview,
0881:                                            transferable);
0882:                                }
0883:
0884:                                FormUndoableEdit pp_cmd = null;
0885:                                if (transferable
0886:                                        .isDataFlavorSupported(FormObjectFlavor.CELL_BACKGROUND)
0887:                                        && view
0888:                                                .isSelected(PasteSpecialNames.ID_CELL_BACKGROUND)) {
0889:                                    PaintProperty paint = (PaintProperty) transferable
0890:                                            .getTransferData(FormObjectFlavor.CELL_BACKGROUND);
0891:                                    PaintProperty oldpaint = gridview
0892:                                            .getPaintProperty(col, row);
0893:                                    pp_cmd = new SetCellBackgroundCommand(
0894:                                            gridview.getParentForm(), col, row,
0895:                                            paint, oldpaint);
0896:                                }
0897:
0898:                                CompositeCommand cc_cmd = new CompositeCommand(
0899:                                        gridview.getParentForm(), cmd, pp_cmd);
0900:                                CommandUtils.invoke(cc_cmd, getCurrentEditor());
0901:                            }
0902:                        }
0903:                    } catch (Exception e) {
0904:                        e.printStackTrace();
0905:                    }
0906:                }
0907:            }
0908:
0909:            /**
0910:             * Pastes a linked component from the clipboard as an embedded component.
0911:             */
0912:            public class PasteAsEmbeddedAction extends AbstractAction {
0913:                public void actionPerformed(ActionEvent evt) {
0914:                    try {
0915:                        GridComponent oldcomp = getCurrentEditor()
0916:                                .getSelectedComponent();
0917:                        if (oldcomp != null) {
0918:                            GridView view = oldcomp.getParentView();
0919:                            Toolkit kit = Toolkit.getDefaultToolkit();
0920:                            Clipboard clipboard = kit.getSystemClipboard();
0921:                            Transferable transferable = clipboard
0922:                                    .getContents(null);
0923:                            if (transferable
0924:                                    .isDataFlavorSupported(FormObjectFlavor.LINKED_FORM)) {
0925:                                /**
0926:                                 * if LINKED_FORM is supported, then GRID_COMPONENT must
0927:                                 * also be supported
0928:                                 */
0929:                                if (transferable
0930:                                        .isDataFlavorSupported(FormObjectFlavor.COMPONENT_MEMENTO)) {
0931:                                    pasteComponent(view, transferable);
0932:                                } else {
0933:                                    assert (false);
0934:                                }
0935:                            }
0936:                        }
0937:                    } catch (Exception e) {
0938:                        e.printStackTrace();
0939:                    }
0940:                }
0941:            }
0942:
0943:            /**
0944:             * Redoes a previous edit
0945:             */
0946:            public class RedoAction extends AbstractAction {
0947:                public void actionPerformed(ActionEvent evt) {
0948:                    CommandUtils.redoEdit(getCurrentEditor());
0949:                    FormManagerDesignUtils.deselectAll(getCurrentEditor()
0950:                            .getTopParent());
0951:                }
0952:            }
0953:
0954:            /**
0955:             * Sets the resize behavior on the selected column
0956:             */
0957:            public class ColumnResizeAction extends AbstractAction {
0958:                private boolean m_growable = false;
0959:
0960:                public ColumnResizeAction(boolean growable) {
0961:                    m_growable = growable;
0962:                }
0963:
0964:                public void actionPerformed(ActionEvent evt) {
0965:                    GridComponent gc = getCurrentEditor()
0966:                            .getSelectedComponent();
0967:                    if (gc != null) {
0968:                        GridView view = gc.getParentView();
0969:                        if (view != null) {
0970:                            int col = gc.getColumn();
0971:                            ColumnSpec oldspec = view.getFormLayout()
0972:                                    .getColumnSpec(col);
0973:
0974:                            float resize_weight = m_growable ? 1.0f : 0.0f;
0975:
0976:                            ColumnSpec newspec = new ColumnSpec(oldspec
0977:                                    .getDefaultAlignment(), oldspec.getSize(),
0978:                                    resize_weight);
0979:                            EditColumnSpecCommand cmd = new EditColumnSpecCommand(
0980:                                    view.getParentForm(), col, newspec, oldspec);
0981:                            CommandUtils.invoke(cmd, getCurrentEditor());
0982:                        }
0983:                    }
0984:                }
0985:            }
0986:
0987:            /**
0988:             * Sets the resize behavior on the selected row
0989:             */
0990:            public class RowResizeAction extends AbstractAction {
0991:                private boolean m_growable = false;
0992:
0993:                public RowResizeAction(boolean growable) {
0994:                    m_growable = growable;
0995:                }
0996:
0997:                public void actionPerformed(ActionEvent evt) {
0998:                    GridComponent gc = getCurrentEditor()
0999:                            .getSelectedComponent();
1000:                    if (gc != null) {
1001:                        GridView view = gc.getParentView();
1002:                        if (view != null) {
1003:                            int row = gc.getRow();
1004:                            RowSpec oldspec = view.getFormLayout().getRowSpec(
1005:                                    row);
1006:
1007:                            float resize_weight = m_growable ? 1.0f : 0.0f;
1008:
1009:                            RowSpec newspec = new RowSpec(RowSpec.FILL, oldspec
1010:                                    .getSize(), resize_weight);
1011:                            EditRowSpecCommand cmd = new EditRowSpecCommand(
1012:                                    view.getParentForm(), row, newspec, oldspec);
1013:                            CommandUtils.invoke(cmd, getCurrentEditor());
1014:                        }
1015:                    }
1016:                }
1017:            }
1018:
1019:            /**
1020:             * Sets the size behavior to preferred for the selected row
1021:             */
1022:            public class RowSetPreferredSizeAction extends AbstractAction {
1023:                public void actionPerformed(ActionEvent evt) {
1024:                    GridComponent gc = getCurrentEditor()
1025:                            .getSelectedComponent();
1026:                    if (gc != null) {
1027:                        GridView view = gc.getParentView();
1028:                        if (view != null) {
1029:                            int row = gc.getRow();
1030:                            RowSpec oldspec = view.getFormLayout().getRowSpec(
1031:                                    row);
1032:
1033:                            RowSpec newspec = new RowSpec(oldspec
1034:                                    .getDefaultAlignment(), Sizes.PREFERRED,
1035:                                    oldspec.getResizeWeight());
1036:                            EditRowSpecCommand cmd = new EditRowSpecCommand(
1037:                                    view.getParentForm(), row, newspec, oldspec);
1038:                            CommandUtils.invoke(cmd, getCurrentEditor());
1039:                        }
1040:                    }
1041:                }
1042:            }
1043:
1044:            /**
1045:             * Formats the selected column as a separator (e.g set its size to something
1046:             * like 4dlu )
1047:             */
1048:            public class SetColumnSeparatorAction extends AbstractAction {
1049:                /**
1050:                 * Set to false for large separator
1051:                 */
1052:                private boolean m_std_size = true;
1053:
1054:                public SetColumnSeparatorAction(boolean stdsize) {
1055:                    m_std_size = stdsize;
1056:                }
1057:
1058:                private String getSeparatorSpec() {
1059:                    String units_prop_name = m_std_size ? UserPreferencesNames.ID_COL_STD_SEP_UNITS
1060:                            : UserPreferencesNames.ID_COL_LARGE_SEP_UNITS;
1061:                    String sz_prop_name = m_std_size ? UserPreferencesNames.ID_COL_STD_SEP_SIZE
1062:                            : UserPreferencesNames.ID_COL_LARGE_SEP_SIZE;
1063:
1064:                    String units = TSUserPropertiesUtils.getString(
1065:                            units_prop_name, "dlu");
1066:                    if (!FormUtils.isValidUnits(units))
1067:                        units = "dlu";
1068:
1069:                    String sz = m_std_size ? "4" : "8";
1070:                    sz = FormDesignerUtils.fastTrim(TSUserPropertiesUtils
1071:                            .getString(sz_prop_name, sz));
1072:                    if (sz.length() == 0)
1073:                        sz = FormUtils.getReasonableSize(units);
1074:
1075:                    String spec = "";
1076:                    try {
1077:                        StringBuffer sbuff = new StringBuffer();
1078:                        sbuff.append(sz);
1079:                        sbuff.append(units);
1080:                        spec = sbuff.toString();
1081:                    } catch (Exception e) {
1082:                        spec = (m_std_size ? "4dlu" : "8dlu");
1083:                    }
1084:                    return spec;
1085:                }
1086:
1087:                public void actionPerformed(ActionEvent evt) {
1088:                    GridComponent gc = getCurrentEditor()
1089:                            .getSelectedComponent();
1090:                    GridView view = gc.getParentView();
1091:                    if (view != null) {
1092:                        int col = gc.getColumn();
1093:                        ColumnSpec oldspec = view.getColumnSpec(col);
1094:                        ColumnSpec newspec = new ColumnSpec(getSeparatorSpec());
1095:                        EditColumnSpecCommand cmd = new EditColumnSpecCommand(
1096:                                view.getParentForm(), col, newspec, oldspec);
1097:                        CommandUtils.invoke(cmd, getCurrentEditor());
1098:                    }
1099:                }
1100:            }
1101:
1102:            /**
1103:             * Formats the selected row as a separator (e.g set its size to something
1104:             * like 2dlu )
1105:             */
1106:            public class SetRowSeparatorAction extends AbstractAction {
1107:                /**
1108:                 * Set to false for large separator
1109:                 */
1110:                private boolean m_std_size = true;
1111:
1112:                public SetRowSeparatorAction(boolean stdsize) {
1113:                    m_std_size = stdsize;
1114:                }
1115:
1116:                private String getSeparatorSpec() {
1117:                    String units_prop_name = m_std_size ? UserPreferencesNames.ID_ROW_STD_SEP_UNITS
1118:                            : UserPreferencesNames.ID_ROW_LARGE_SEP_UNITS;
1119:                    String sz_prop_name = m_std_size ? UserPreferencesNames.ID_ROW_STD_SEP_SIZE
1120:                            : UserPreferencesNames.ID_ROW_LARGE_SEP_SIZE;
1121:
1122:                    String units = TSUserPropertiesUtils.getString(
1123:                            units_prop_name, "dlu");
1124:                    if (!FormUtils.isValidUnits(units))
1125:                        units = "dlu";
1126:
1127:                    String sz = m_std_size ? "2" : "4";
1128:                    sz = FormDesignerUtils.fastTrim(TSUserPropertiesUtils
1129:                            .getString(sz_prop_name, sz));
1130:                    if (sz.length() == 0)
1131:                        sz = FormUtils.getReasonableSize(units);
1132:
1133:                    String spec = "";
1134:                    try {
1135:                        StringBuffer sbuff = new StringBuffer();
1136:                        sbuff.append(sz);
1137:                        sbuff.append(units);
1138:                        spec = sbuff.toString();
1139:                    } catch (Exception e) {
1140:                        spec = (m_std_size ? "2dlu" : "4dlu");
1141:                    }
1142:                    return spec;
1143:                }
1144:
1145:                public void actionPerformed(ActionEvent evt) {
1146:                    GridComponent gc = getCurrentEditor()
1147:                            .getSelectedComponent();
1148:                    GridView view = gc.getParentView();
1149:                    if (view != null) {
1150:                        int row = gc.getRow();
1151:                        RowSpec oldspec = view.getRowSpec(row);
1152:                        RowSpec newspec = new RowSpec(getSeparatorSpec());
1153:                        EditRowSpecCommand cmd = new EditRowSpecCommand(view
1154:                                .getParentForm(), row, newspec, oldspec);
1155:                        CommandUtils.invoke(cmd, getCurrentEditor());
1156:                    }
1157:                }
1158:            }
1159:
1160:            /**
1161:             * Toggles the selected grid on/off
1162:             */
1163:            public class ShowGridAction extends AbstractAction {
1164:                public void actionPerformed(ActionEvent evt) {
1165:                    GridComponent gc = getCurrentEditor()
1166:                            .getSelectedComponent();
1167:                    GridView view = gc.getParentView();
1168:                    if (view != null) {
1169:                        view.setGridVisible(!view.isGridVisible());
1170:                    }
1171:                }
1172:            }
1173:
1174:            /**
1175:             * Trims all columns that don't have components.
1176:             */
1177:            public class TrimColumnsAction extends AbstractAction {
1178:                public void actionPerformed(ActionEvent evt) {
1179:                    GridComponent gc = getCurrentEditor()
1180:                            .getSelectedComponent();
1181:                    if (gc != null) {
1182:                        GridView view = gc.getParentView();
1183:                        if (view != null && view.getColumnCount() > 1) {
1184:                            FormManager fmgr = (FormManager) JETARegistry
1185:                                    .lookup(FormManager.COMPONENT_ID);
1186:                            TrimColumnsCommand cmd = new TrimColumnsCommand(
1187:                                    view.getParentForm(), getCurrentEditor()
1188:                                            .getComponentSource());
1189:                            CommandUtils.invoke(cmd, getCurrentEditor());
1190:                            FormManagerDesignUtils.clearUnreferencedForms();
1191:                        }
1192:                    }
1193:                }
1194:            }
1195:
1196:            /**
1197:             * Trims all rows that don't have components.
1198:             */
1199:            public class TrimRowsAction extends AbstractAction {
1200:                public void actionPerformed(ActionEvent evt) {
1201:                    GridComponent gc = getCurrentEditor()
1202:                            .getSelectedComponent();
1203:                    if (gc != null) {
1204:                        GridView view = gc.getParentView();
1205:                        if (view != null && view.getRowCount() > 1) {
1206:                            FormManager fmgr = (FormManager) JETARegistry
1207:                                    .lookup(FormManager.COMPONENT_ID);
1208:                            TrimRowsCommand cmd = new TrimRowsCommand(view
1209:                                    .getParentForm(), getCurrentEditor()
1210:                                    .getComponentSource());
1211:                            CommandUtils.invoke(cmd, getCurrentEditor());
1212:                            FormManagerDesignUtils.clearUnreferencedForms();
1213:                        }
1214:                    }
1215:                }
1216:            }
1217:
1218:            /**
1219:             * Undoes a previous edit
1220:             */
1221:            public class UndoAction extends AbstractAction {
1222:                public void actionPerformed(ActionEvent evt) {
1223:                    FormUndoableEdit cmd = CommandUtils
1224:                            .undoEdit(getCurrentEditor());
1225:                    if (cmd instanceof  UndoableEditProxy)
1226:                        cmd = ((UndoableEditProxy) cmd).getDelegate();
1227:
1228:                    if (cmd instanceof  SetPropertyCommand) {
1229:                        java.awt.Component controls_view = m_frame
1230:                                .getCurrentControlsView();
1231:                        if (controls_view instanceof  PropertyPaneContainer) {
1232:                            ((PropertyPaneContainer) controls_view)
1233:                                    .refreshView();
1234:                        }
1235:                    }
1236:                    FormManagerDesignUtils.deselectAll(getCurrentEditor()
1237:                            .getTopParent());
1238:                }
1239:            }
1240:
1241:            /**
1242:             * Selects the cell immediately above the current cell
1243:             */
1244:            public class UpAction extends AbstractAction {
1245:                public void actionPerformed(ActionEvent evt) {
1246:                    GridComponent gc = getCurrentEditor()
1247:                            .getSelectedComponent();
1248:                    if (gc != null) {
1249:                        GridView view = gc.getParentView();
1250:                        if (view != null) {
1251:                            int row = gc.getRow();
1252:                            int col = gc.getColumn();
1253:                            row--;
1254:                            if (row < 1) {
1255:                                row = view.getRowCount();
1256:                                col--;
1257:                                if (col < 1)
1258:                                    col = view.getColumnCount();
1259:                            }
1260:                            GridComponent next = view
1261:                                    .getGridComponent(col, row);
1262:                            gc.setSelected(false);
1263:                            next.setSelected(true);
1264:                        }
1265:                    }
1266:                }
1267:            }
1268:
1269:            /**
1270:             * Handles popup mouse trigger events for form.
1271:             */
1272:            public class ContextMouseListener extends MouseAdapter {
1273:                private void handlePopup(MouseEvent evt) {
1274:                    if (evt.isPopupTrigger()) {
1275:                        m_popup.show((java.awt.Component) evt.getSource(), evt
1276:                                .getX(), evt.getY());
1277:                    }
1278:                }
1279:
1280:                public void mousePressed(MouseEvent e) {
1281:                    handlePopup(e);
1282:                }
1283:
1284:                public void mouseReleased(MouseEvent e) {
1285:                    handlePopup(e);
1286:                }
1287:            }
1288:
1289:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.