Source Code Cross Referenced for FormEditor.java in  » Swing-Library » abeille-forms-designer » com » jeta » swingbuilder » gui » editor » 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.editor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2005 Jeff Tassin
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */
018:
019:        package com.jeta.swingbuilder.gui.editor;
020:
021:        import java.awt.BorderLayout;
022:        import java.awt.Component;
023:        import java.awt.Container;
024:        import java.awt.Dimension;
025:        import java.awt.Insets;
026:        import java.awt.LayoutManager;
027:        import java.awt.event.AdjustmentEvent;
028:        import java.awt.event.AdjustmentListener;
029:        import java.util.Iterator;
030:        import java.util.LinkedList;
031:
032:        import javax.swing.BorderFactory;
033:        import javax.swing.ImageIcon;
034:        import javax.swing.JPanel;
035:        import javax.swing.JScrollPane;
036:
037:        import com.jeta.forms.gui.common.FormException;
038:        import com.jeta.forms.gui.components.ComponentSource;
039:        import com.jeta.forms.gui.components.ContainedFormFactory;
040:        import com.jeta.forms.gui.form.FormComponent;
041:        import com.jeta.forms.gui.form.GridComponent;
042:        import com.jeta.forms.gui.form.GridOverlay;
043:        import com.jeta.forms.gui.form.GridView;
044:        import com.jeta.forms.gui.form.GridViewEvent;
045:        import com.jeta.forms.gui.form.GridViewListener;
046:        import com.jeta.open.gui.framework.JETAPanel;
047:        import com.jeta.open.i18n.I18N;
048:        import com.jeta.open.registry.JETARegistry;
049:        import com.jeta.swingbuilder.gui.commands.FormUndoableEdit;
050:        import com.jeta.swingbuilder.gui.components.LinkedFormComponentFactory;
051:        import com.jeta.swingbuilder.gui.components.TSCell;
052:        import com.jeta.swingbuilder.gui.focus.FocusView;
053:        import com.jeta.swingbuilder.gui.formmgr.AbstractFormManager;
054:        import com.jeta.swingbuilder.gui.formmgr.FormManagerDesignUtils;
055:        import com.jeta.swingbuilder.gui.handler.GridMouseListener;
056:        import com.jeta.swingbuilder.gui.project.UserPreferencesNames;
057:        import com.jeta.swingbuilder.gui.undo.EditorUndoManager;
058:        import com.jeta.swingbuilder.gui.utils.FormDesignerUtils;
059:        import com.jeta.swingbuilder.interfaces.userprops.TSUserPropertiesUtils;
060:        import com.jgoodies.forms.layout.CellConstraints;
061:        import com.jgoodies.forms.layout.ColumnSpec;
062:        import com.jgoodies.forms.layout.FormLayout;
063:        import com.jgoodies.forms.layout.RowSpec;
064:
065:        /**
066:         * Displays a form and an editor grid.
067:         * 
068:         * @author Jeff Tassin
069:         */
070:        public class FormEditor extends JETAPanel implements  GridViewListener {
071:            /**
072:             * The margin at the top of the view for selecting/editing/resizing column
073:             * settings
074:             */
075:            private Margin m_colmargin;
076:
077:            /**
078:             * The margin at the left of the view for selecting/editing/resizing row
079:             * settings
080:             */
081:            private Margin m_rowmargin;
082:            private static int COLUMN_MARGIN_HEIGHT = 24;
083:            private static int ROW_MARGIN_WIDTH = 24;
084:
085:            /** @directed */
086:            private DesignFormComponent m_form;
087:
088:            /**
089:             * The 1x1 topmost parent the contains the form we are editing.
090:             */
091:            private FormComponent m_topparent;
092:
093:            /** @directed */
094:            private GridView m_gridview;
095:
096:            /**
097:             * Displays the focus order for the form in this editor
098:             */
099:            private FocusView m_focus_view;
100:
101:            /**
102:             * The object that determines the currently selected component to create
103:             * when adding a component to the form.
104:             */
105:            private ComponentSource m_compsrc;
106:
107:            /**
108:             * The scroll pane that contains the form.
109:             */
110:            private JScrollPane m_scroll;
111:
112:            /**
113:             * Flag that indicates if this editor is currently active.
114:             */
115:            private boolean m_active = true;
116:
117:            /**
118:             * The row/column cells on the status bar. Displays the row/column specs for
119:             * the selected component
120:             */
121:            private TSCell m_formtype_cell;
122:            private TSCell m_colcell;
123:            private TSCell m_rowcell;
124:
125:            /**
126:             * The row/column specs cells. Display the row and column specs for the
127:             * selected form.
128:             */
129:            private TSCell m_colspec_cell;
130:            private TSCell m_rowspec_cell;
131:
132:            /**
133:             * For debugging only Displays the form id for the current parent and form
134:             * components.
135:             */
136:            private TSCell m_formcell;
137:            private TSCell m_parentcell;
138:
139:            /**
140:             * Undo/Redo support for this editor
141:             */
142:            private EditorUndoManager m_undomanager;
143:
144:            /**
145:             * A list of GridViewListeners who are interested in GridViewEvents for the
146:             * forms in this editor. We keep track of this list in case the form changes
147:             * such as during a Save As operation. In this situation, we can re-register
148:             * the listeners on the new form.
149:             */
150:            private LinkedList m_grid_listeners = new LinkedList();
151:
152:            /** icons for status bar */
153:            private static ImageIcon m_linked_icon = FormDesignerUtils
154:                    .loadImage("forms/form_control_linked.gif");
155:            private static ImageIcon m_embedded_icon = FormDesignerUtils
156:                    .loadImage("forms/form_control_embedded.gif");
157:
158:            /**
159:             * ctor
160:             * 
161:             */
162:            public FormEditor(ComponentSource compsrc, FormComponent comp) {
163:                try {
164:                    assert (compsrc != null);
165:                    assert (comp != null);
166:
167:                    m_compsrc = compsrc;
168:                    initialize(createTopParent(comp));
169:                } catch (Exception e) {
170:                    e.printStackTrace();
171:                }
172:            }
173:
174:            /**
175:             * ctor
176:             * 
177:             * @param gmodel
178:             */
179:            public FormEditor(ComponentSource compsrc, int cols, int rows) {
180:                try {
181:                    m_compsrc = compsrc;
182:
183:                    LinkedFormComponentFactory factory = new LinkedFormComponentFactory(
184:                            m_compsrc);
185:                    m_form = (DesignFormComponent) factory.create(m_compsrc,
186:                            "", null, cols, rows, false);
187:
188:                    m_gridview = m_form.getChildView();
189:                    GridView.fillCells(m_gridview, m_compsrc);
190:                    initialize(createTopParent(m_form));
191:                } catch (Exception e) {
192:                    e.printStackTrace();
193:                }
194:            }
195:
196:            /**
197:             * Sets this editor as the currently active editor
198:             */
199:            public void activate() {
200:                m_active = true;
201:                getForm().setGridViewVisible(true);
202:                getForm().setControlButtonsVisible(false);
203:                getForm().getChildView().refreshView();
204:                if (m_focus_view != null) {
205:                    javax.swing.SwingUtilities.invokeLater(new Runnable() {
206:                        public void run() {
207:                            m_focus_view.showFocusBoxes();
208:                            getForm().getChildView().repaint();
209:                        }
210:                    });
211:                }
212:                unitTest();
213:            }
214:
215:            /**
216:             * Adds GridListeners to the form in this editor
217:             */
218:            public void addListener(GridViewListener listener) {
219:                m_topparent.getChildView().addListener(listener);
220:                m_grid_listeners.add(listener);
221:            }
222:
223:            /**
224:             * Clears all undo/redo edits for this editor. This is typically performed
225:             * after the editor has been saved.
226:             */
227:            public void clearUndoableEdits() {
228:                m_undomanager.discardAllEdits();
229:            }
230:
231:            /**
232:             * Creates the status bar for this editor
233:             */
234:            private JETAPanel createStatusBar() {
235:                if (FormDesignerUtils.isDebug()) {
236:                    JETAPanel panel = new JETAPanel(new FormLayout("pref:grow",
237:                            "pref,pref"));
238:                    CellConstraints cc = new CellConstraints();
239:
240:                    panel.add(createStandardStatusBar(), cc.xy(1, 1));
241:                    panel.add(createDebugStatusBar(), cc.xy(1, 2));
242:                    return panel;
243:                } else {
244:                    return createStandardStatusBar();
245:                }
246:            }
247:
248:            /**
249:             * Creates a debug bar for this editor. Shows extra information such as form
250:             * id.
251:             */
252:            private JETAPanel createDebugStatusBar() {
253:                JETAPanel panel = new JETAPanel();
254:                FormLayout layout = new FormLayout("pref:grow", "pref,pref");
255:                panel.setLayout(layout);
256:
257:                m_formcell = new TSCell("formcell", "left:pref:nogrow");
258:                m_formcell.setFont(javax.swing.UIManager.getFont("Table.font"));
259:                m_formcell
260:                        .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
261:
262:                m_parentcell = new TSCell("parentcell", "left:pref:nogrow");
263:                m_parentcell.setFont(javax.swing.UIManager
264:                        .getFont("Table.font"));
265:                m_parentcell
266:                        .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
267:
268:                CellConstraints cc = new CellConstraints();
269:                panel.add(m_formcell, cc.xy(1, 1));
270:                panel.add(m_parentcell, cc.xy(1, 2));
271:                return panel;
272:            }
273:
274:            /**
275:             * Creates the status bar for this editor
276:             */
277:            private JETAPanel createStandardStatusBar() {
278:                JETAPanel panel = new JETAPanel();
279:                FormLayout layout = new FormLayout(
280:                        "20px:nogrow,2px,pref:grow(0.5),2px,pref:grow(0.5)",
281:                        "pref");
282:                panel.setLayout(layout);
283:
284:                m_formtype_cell = new TSCell("formtypecell",
285:                        "center:pref:nogrow");
286:
287:                m_rowcell = new TSCell("rowcell", "center:pref:nogrow");
288:                m_rowcell.setFont(javax.swing.UIManager.getFont("Table.font"));
289:                m_rowcell
290:                        .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
291:
292:                m_colcell = new TSCell("colcell", "center:pref:nogrow");
293:                m_colcell.setFont(javax.swing.UIManager.getFont("Table.font"));
294:                m_colcell
295:                        .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
296:
297:                CellConstraints cc = new CellConstraints();
298:                panel.add(m_formtype_cell, cc.xy(1, 1));
299:                panel.add(m_colcell, cc.xy(3, 1));
300:                panel.add(m_rowcell, cc.xy(5, 1));
301:                return panel;
302:            }
303:
304:            /**
305:             * Creates a top level form cell
306:             */
307:            private FormComponent createTopParent(FormComponent form)
308:                    throws FormException {
309:                m_form = (DesignFormComponent) form;
310:                m_gridview = form.getChildView();
311:
312:                // **** now make sure that any empty cells are properly filled
313:                m_gridview.enableEvents(true);
314:
315:                ContainedFormFactory factory = (ContainedFormFactory) JETARegistry
316:                        .lookup(ContainedFormFactory.COMPONENT_ID);
317:                m_topparent = factory.createTopParent(this , m_compsrc, form);
318:                GridView view = m_topparent.getChildView();
319:                view.enableEvents(true);
320:
321:                /**
322:                 * you must call setOpaque here or there will be some color artifacts
323:                 * visible when look and feel changes
324:                 */
325:                m_topparent.setOpaque(true);
326:
327:                /**
328:                 * Re-add any listeners to the top parent. This is needed when doing a
329:                 * Save As on a form. The editor does not change but the form does.
330:                 */
331:                Iterator iter = m_grid_listeners.iterator();
332:                while (iter.hasNext()) {
333:                    view.addListener((GridViewListener) iter.next());
334:                }
335:
336:                m_topparent.setBorder(BorderFactory.createEmptyBorder(0, 0, 0,
337:                        0));
338:                return m_topparent;
339:            }
340:
341:            /**
342:             * Deactivates this editor.
343:             */
344:            public void deactivate() {
345:                m_active = false;
346:            }
347:
348:            /**
349:             * Invokes the given command and registers it with the UndoSupport
350:             */
351:            public void editHappened(FormUndoableEdit edit) {
352:                m_undomanager.addEdit(edit);
353:            }
354:
355:            /**
356:             * @return the component source
357:             */
358:            public ComponentSource getComponentSource() {
359:                return m_compsrc;
360:            }
361:
362:            /**
363:             * @return the editor that is an ancestor of the given component. If the
364:             *         comp is not in a FormEditor hierarchy, null is returned.
365:             */
366:            public static FormEditor getEditor(Component comp) {
367:                if (comp instanceof  FormEditor)
368:                    return (FormEditor) comp;
369:
370:                java.awt.Container parent = comp.getParent();
371:                while (parent != null) {
372:                    if (parent instanceof  FormEditor)
373:                        return (FormEditor) parent;
374:
375:                    parent = parent.getParent();
376:                }
377:                return null;
378:            }
379:
380:            /**
381:             * @return the formcomponent that is this form
382:             */
383:            public DesignFormComponent getForm() {
384:                return (DesignFormComponent) m_form;
385:            }
386:
387:            /**
388:             * @return the formcomponent that is this form
389:             */
390:            public DesignFormComponent getFormComponent() {
391:                return (DesignFormComponent) m_form;
392:            }
393:
394:            /**
395:             * @return the overlay for the main form
396:             */
397:            public GridOverlay getGridOverlay() {
398:                return m_gridview.getOverlay();
399:            }
400:
401:            /**
402:             * @return the id of the form we are editing.
403:             */
404:            public String getId() {
405:                return m_form.getId();
406:            }
407:
408:            /**
409:             * @return the top most overlay on the form. This is the 1x1 form that is
410:             *         the parent for the main form we are editing.
411:             */
412:            public GridOverlay getTopOverlay() {
413:                assert (m_topparent != null);
414:                assert (m_topparent.getChildView() != null);
415:                return m_topparent.getChildView().getOverlay();
416:            }
417:
418:            /**
419:             * @return the top most parent FormComponent. This is the 1x1 form that is
420:             *         the parent for the main form we are editing.
421:             */
422:            public FormComponent getTopParent() {
423:                return m_topparent;
424:            }
425:
426:            /**
427:             * @return the UndoManager for this editor
428:             */
429:            public EditorUndoManager getUndoManager() {
430:                return m_undomanager;
431:            }
432:
433:            /** GridViewListener implementation */
434:            public void gridChanged(GridViewEvent evt) {
435:                updateStatusBar();
436:                if (evt.getId() != GridViewEvent.EDIT_COMPONENT
437:                        && evt.getId() != GridViewEvent.CELL_SELECTED) {
438:                    revalidate();
439:                    m_gridview.revalidate();
440:                    m_gridview.doLayout();
441:                    m_gridview.repaint();
442:                    m_form.revalidate();
443:                    m_form.doLayout();
444:                    m_form.repaint();
445:                    doLayout();
446:                    repaint();
447:                }
448:
449:                if (m_colmargin != null) {
450:                    if (evt.getId() == GridViewEvent.CELL_SELECTED) {
451:                        GridComponent gc = getSelectedComponent();
452:                        m_colmargin.update(gc);
453:                        m_rowmargin.update(gc);
454:                    } else {
455:                        javax.swing.SwingUtilities.invokeLater(new Runnable() {
456:                            public void run() {
457:                                GridComponent gc = getSelectedComponent();
458:                                m_colmargin.update(gc);
459:                                m_rowmargin.update(gc);
460:                            }
461:                        });
462:                    }
463:                }
464:
465:                // if ( m_active && m_focus_view != null)
466:                // {
467:                // m_focus_view.gridChanged( evt );
468:                // }
469:            }
470:
471:            /**
472:             * @returns the first selected component it finds in the component hierarhcy
473:             *          of this container.
474:             */
475:            public GridComponent getSelectedComponent() {
476:                GridComponent comp = m_gridview.getSelectedComponent();
477:                if (comp == null) {
478:                    if (m_form.isSelected())
479:                        comp = m_form;
480:                }
481:                return comp;
482:            }
483:
484:            /**
485:             * Initializes the form
486:             */
487:            private void initialize(FormComponent formcell)
488:                    throws FormException {
489:                m_undomanager = new EditorUndoManager(
490:                        (AbstractFormManager) JETARegistry
491:                                .lookup(AbstractFormManager.COMPONENT_ID), this );
492:
493:                m_form.setControlButtonsVisible(false);
494:                GridView gridview = formcell.getChildView();
495:
496:                setLayout(new BorderLayout());
497:
498:                m_scroll = new JScrollPane(formcell);
499:                m_scroll.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
500:
501:                m_colmargin = new ColumnMargin(m_form, gridview, m_compsrc,
502:                        m_scroll.getViewport(), showMargins());
503:                m_rowmargin = new RowMargin(m_form, gridview, m_compsrc,
504:                        m_scroll.getViewport(), showMargins());
505:
506:                m_scroll.getHorizontalScrollBar().addAdjustmentListener(
507:                        new AdjustmentListener() {
508:                            public void adjustmentValueChanged(
509:                                    AdjustmentEvent evt) {
510:                                m_colmargin.update();
511:                            }
512:                        });
513:
514:                m_scroll.getVerticalScrollBar().addAdjustmentListener(
515:                        new AdjustmentListener() {
516:                            public void adjustmentValueChanged(
517:                                    AdjustmentEvent evt) {
518:                                m_rowmargin.update();
519:                            }
520:                        });
521:
522:                JPanel content = new JPanel(new FormEditorLayout(m_colmargin,
523:                        m_rowmargin, m_scroll, formcell));
524:
525:                content.add(m_colmargin);
526:                content.add(m_rowmargin);
527:                content.add(m_scroll);
528:                add(content, BorderLayout.CENTER);
529:
530:                add(createStatusBar(), BorderLayout.SOUTH);
531:                gridview.addListener(this );
532:
533:                final DesignGridOverlay overlay = (DesignGridOverlay) gridview
534:                        .getOverlay();
535:                final GridMouseListener mlistener = new GridMouseListener(
536:                        gridview.getOverlay(), formcell.getMouseHandler());
537:                overlay.setFocusable(true);
538:
539:                /**
540:                 * we need to delay adding the listeners because the form component
541:                 * might not be fully initialized yet
542:                 */
543:                Runnable gui_update = new Runnable() {
544:                    public void run() {
545:                        overlay.addMouseListener(mlistener);
546:                        overlay.addMouseMotionListener(mlistener);
547:                    }
548:                };
549:                javax.swing.SwingUtilities.invokeLater(gui_update);
550:
551:                /**
552:                 * This mouse listener is for clicks in the border around the main form.
553:                 * It gives the user a little room to select the main form
554:                 */
555:                formcell.addMouseListener(new java.awt.event.MouseAdapter() {
556:                    public void mousePressed(java.awt.event.MouseEvent evt) {
557:                        FormManagerDesignUtils.deselectAll(m_form);
558:                        m_form.setSelected(true);
559:                        repaint();
560:                    }
561:                });
562:
563:                unitTest();
564:            }
565:
566:            /**
567:             * @return true if this form is an embedded form. An embedded form is stored
568:             *         within the parent form.
569:             */
570:            public boolean isEmbedded() {
571:                return m_form.isEmbedded();
572:            }
573:
574:            /**
575:             * @return true if the focus view is visible
576:             */
577:            public boolean isFocusViewVisible() {
578:                return (m_focus_view != null);
579:            }
580:
581:            /**
582:             * @return true if this form is a linked form. A linked form is one that is
583:             *         actually stored in a file.
584:             */
585:            public boolean isLinked() {
586:                return m_form.isLinked();
587:            }
588:
589:            /**
590:             * @return true if this form has been modified.
591:             */
592:            public boolean isModified() {
593:                return (m_undomanager.size() > 0 && m_undomanager
594:                        .getIndexOfNextAdd() > 0);
595:            }
596:
597:            /**
598:             * Removes the given GridListener from this editor.
599:             */
600:            public void removeListener(GridViewListener listener) {
601:                m_topparent.getChildView().removeListener(listener);
602:                m_grid_listeners.remove(listener);
603:            }
604:
605:            /**
606:             * Saves the current focus policy
607:             */
608:            public void saveFocusPolicy() {
609:                if (m_focus_view != null) {
610:                    m_form.setFocusPolicy(m_focus_view.getFocusPolicyMemento());
611:                }
612:            }
613:
614:            /**
615:             * Sets the focus view visible
616:             */
617:            public void setFocusViewVisible(boolean bvisible) {
618:                GridView gridview = m_topparent.getChildView();
619:                /*
620:                 * JLayeredPane layeredpane = gridview.getLayeredPane(); if ( bvisible ) {
621:                 * if ( m_focus_view != null ) { layeredpane.remove( m_focus_view ); }
622:                 * m_focus_view = new FocusView( m_form ); layeredpane.add(
623:                 * m_focus_view, GridView.FOCUS_LAYER ); } else { if ( m_focus_view !=
624:                 * null ) { if ( layeredpane.isAncestorOf( m_focus_view ) ) {
625:                 * layeredpane.remove( m_focus_view ); } m_form.setFocusPolicy(
626:                 * m_focus_view.getFocusPolicyMemento() ); m_focus_view = null; } }
627:                 */
628:            }
629:
630:            /**
631:             * Sets the formcomponent that is this form. This call is made when the user
632:             * performs a Save As.
633:             */
634:            public void setFormComponent(FormComponent fc) throws FormException {
635:                removeAll();
636:                initialize(createTopParent(fc));
637:                revalidate();
638:            }
639:
640:            /**
641:             * Returns true if the resize margins are visible (user set property)
642:             */
643:            boolean showMargins() {
644:                return TSUserPropertiesUtils.getBoolean(
645:                        UserPreferencesNames.ID_SHOW_RESIZE_HANDLES, true);
646:            }
647:
648:            /**
649:             * Override updateUI so we can update the scrollpane viewport background.
650:             */
651:            public void updateUI() {
652:                super .updateUI();
653:            }
654:
655:            /**
656:             * Runs unit test routines on this editor.
657:             */
658:            public void unitTest() {
659:                if (FormDesignerUtils.isTest()) {
660:                    // com.jeta.swingbuilder.test.JETATestFactory.runTest(
661:                    // "test.jeta.swingbuilder.gui.editor.EditorValidator", this );
662:                }
663:            }
664:
665:            /**
666:             * Updates the display based on user preferences.
667:             */
668:            public void updatePreferences() {
669:                if (showMargins() != m_colmargin.isPaintMargin()) {
670:                    m_colmargin.setPaintMargins(showMargins());
671:                    m_rowmargin.setPaintMargins(showMargins());
672:                    revalidate();
673:                    repaint();
674:                    GridComponent gc = getSelectedComponent();
675:                    m_colmargin.update(gc);
676:                    m_rowmargin.update(gc);
677:                }
678:            }
679:
680:            /**
681:             * Updates the status bar to display the column and row specs for the given
682:             * component.
683:             */
684:            private void updateStatusBar() {
685:                m_colcell.setText("");
686:                m_rowcell.setText("");
687:                if (m_formcell != null) {
688:                    m_formcell.setText("");
689:                    m_parentcell.setText("");
690:                }
691:
692:                GridComponent gc = getSelectedComponent();
693:
694:                if (gc != null) {
695:                    GridView view = gc.getParentView();
696:                    if (view != null) {
697:                        ColumnSpec cspec = view.getColumnSpec(gc.getColumn());
698:                        m_colcell.setText(I18N.format("column_spec_2",
699:                                new Integer(gc.getColumn()), cspec.toString()));
700:                        RowSpec rspec = view.getRowSpec(gc.getRow());
701:                        m_rowcell.setText(I18N.format("row_spec_2",
702:                                new Integer(gc.getRow()), rspec.toString()));
703:
704:                    }
705:
706:                    if (gc instanceof  FormComponent) {
707:                        FormComponent fc = (FormComponent) gc;
708:                        if (fc.isLinked()) {
709:                            m_formtype_cell.setIcon(m_linked_icon);
710:                        } else {
711:                            m_formtype_cell.setIcon(m_embedded_icon);
712:                        }
713:
714:                        if (m_formcell != null) {
715:                            m_formcell.setText("Form: " + gc.getId());
716:                            FormComponent parent = fc.getParentForm();
717:                            if (parent != null) {
718:                                m_parentcell.setText("Parent Form: "
719:                                        + parent.getId());
720:                            }
721:                        }
722:                    } else {
723:                        m_formtype_cell.setIcon(null);
724:                    }
725:                    // gc.print();
726:                }
727:            }
728:
729:            /**
730:             * LayoutManager for this view. It lays out the Margins and the main scroll
731:             * pane
732:             */
733:            public static class FormEditorLayout implements  LayoutManager {
734:                private Margin m_colmargin;
735:                private Margin m_rowmargin;
736:                private JScrollPane m_scroll;
737:                private FormComponent m_topparent;
738:
739:                public FormEditorLayout(Margin colMargin, Margin rowMargin,
740:                        JScrollPane scroll, FormComponent topparent) {
741:                    m_colmargin = colMargin;
742:                    m_rowmargin = rowMargin;
743:                    m_scroll = scroll;
744:                    m_topparent = topparent;
745:                }
746:
747:                /**
748:                 * @param name
749:                 * @param comp
750:                 */
751:                public void addLayoutComponent(String name, Component comp) {
752:                }
753:
754:                /** @param parent */
755:                public void layoutContainer(Container parent) {
756:                    Dimension margin_sz = m_colmargin.getPreferredSize();
757:
758:                    Insets insets = parent.getInsets();
759:                    int colm_x = insets.left + margin_sz.width;
760:                    int colm_y = insets.top;
761:                    int colm_width = parent.getWidth() - insets.right - colm_x;
762:                    int colm_height = margin_sz.height;
763:
764:                    int rowm_x = insets.left;
765:                    int rowm_y = insets.top + margin_sz.height;
766:                    int rowm_width = margin_sz.width;
767:                    int rowm_height = parent.getHeight() - insets.bottom
768:                            - rowm_y;
769:
770:                    m_scroll.setLocation(colm_x, rowm_y);
771:                    m_scroll.setSize(colm_width, rowm_height);
772:
773:                    m_colmargin.setLocation(colm_x, colm_y);
774:                    m_colmargin.setSize(colm_width, colm_height);
775:
776:                    m_rowmargin.setLocation(rowm_x, rowm_y);
777:                    m_rowmargin.setSize(rowm_width, rowm_height);
778:                }
779:
780:                /**
781:                 * @param parent
782:                 * @return
783:                 */
784:                public Dimension minimumLayoutSize(Container parent) {
785:                    return new Dimension(100, 100);
786:                }
787:
788:                /**
789:                 * @param parent
790:                 * @return
791:                 */
792:                public Dimension preferredLayoutSize(Container parent) {
793:                    return new Dimension(600, 400);
794:                }
795:
796:                /** @param comp */
797:                public void removeLayoutComponent(Component comp) {
798:                }
799:            }
800:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.