Source Code Cross Referenced for ComponentBrowser.java in  » Testing » abbot-1.0.1 » abbot » 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 » Testing » abbot 1.0.1 » abbot.editor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package abbot.editor;
002:
003:        import java.awt.*;
004:        import java.awt.event.*;
005:        import java.lang.reflect.Method;
006:        import java.util.*;
007:
008:        import javax.swing.*;
009:        import javax.swing.border.*;
010:        import javax.swing.event.*;
011:        import javax.swing.tree.*;
012:        import javax.swing.table.*;
013:
014:        import abbot.*;
015:        import abbot.editor.editors.XMLEditor;
016:        import abbot.editor.widgets.*;
017:        import abbot.finder.*;
018:        import abbot.i18n.Strings;
019:        import abbot.script.*;
020:        import abbot.script.Resolver;
021:        import abbot.tester.Robot;
022:
023:        /** Browse an existing component hierarchy.  Thanks to the JFCUnit guys for
024:         * the basis for this code.
025:         */
026:        // FIXME put the component reference ID into a label, not in the status
027:        public class ComponentBrowser extends JPanel implements  ActionListener {
028:            private int TAB_HIERARCHY = 0;
029:
030:            private JButton refreshButton;
031:            private JCheckBox filterButton;
032:            private JButton addAssertButton;
033:            private JButton addSampleButton;
034:            private JCheckBox filterPropertiesCheckBox;
035:            private Resolver resolver;
036:            private ComponentTree componentTree;
037:            private JTable propTable;
038:            private ReferencesModel refModel;
039:            private JTable refTable;
040:            private ComponentPropertyModel propertyModel;
041:            private JTable attributeTable;
042:            private ReferenceAttributeModel attributeModel;
043:            private JTable inputMapTable;
044:            private JTable actionMapTable;
045:
046:            private boolean filter = true;
047:
048:            private JTabbedPane tabs;
049:            private JTabbedPane tabs2;
050:
051:            /** Currently selected component. */
052:            private Component selectedComponent = null;
053:            /** Is the currently selected component "fake"? */
054:            private boolean fakeComponent = false;
055:            /** Currently selected reference. */
056:            private ComponentReference selectedReference = null;
057:            private LocalHierarchy hierarchy;
058:
059:            /**
060:             * Default constructor
061:             */
062:            public ComponentBrowser(Resolver r, Hierarchy h) {
063:                this .resolver = r;
064:                this .hierarchy = new LocalHierarchy(h);
065:                setName("browser");
066:                equip(this );
067:                setSelectedComponent(null);
068:                setSelectedReference(null);
069:            }
070:
071:            /**
072:             * Method to create required widgets/components and populate
073:             * the content pane with them.
074:             *
075:             * @param pane   The content pane to which the created objects have to
076:             *               be added into.
077:             */
078:            private void equip(Container pane) {
079:                setLayout(new BorderLayout());
080:                JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
081:                        createLeftPanel(), createRightPanel());
082:                // prefer tree over property table
083:                split.setResizeWeight(1.0);
084:                split.setDividerSize(4);
085:                split.setBorder(null);
086:                pane.add(split, BorderLayout.CENTER);
087:            }
088:
089:            private JPanel createHierarchyView() {
090:                JPanel pane = new JPanel(new BorderLayout());
091:                componentTree = new ComponentTree(hierarchy);
092:                componentTree.setName("browser.hierarchy");
093:                componentTree
094:                        .addTreeSelectionListener(new TreeSelectionListener() {
095:                            public void valueChanged(TreeSelectionEvent e) {
096:                                if (!ignoreHierarchyChange) {
097:                                    setSelectedComponent(getSelectedComponentFromTree());
098:                                }
099:                            }
100:                        });
101:                JScrollPane scroll = new JScrollPane(componentTree);
102:                scroll.getViewport().setBackground(
103:                        componentTree.getBackground());
104:                pane.add(scroll, BorderLayout.CENTER);
105:
106:                refreshButton = new JButton(Strings
107:                        .get("browser.hierarchy.reload"));
108:                refreshButton.addActionListener(this );
109:                filterButton = new JCheckBox(Strings
110:                        .get("browser.hierarchy.concise"));
111:                filterButton.addActionListener(this );
112:                filterButton.setSelected(filter);
113:                filterButton.setToolTipText(Strings
114:                        .get("browser.hierarchy.filter.tip"));
115:                JPanel buttons = new JPanel();
116:                buttons.setBorder(new EmptyBorder(0, 0, 0, 0));
117:                buttons.add(refreshButton);
118:                buttons.add(filterButton);
119:                JPanel leftJustify = new JPanel(new BorderLayout());
120:                leftJustify.setBorder(new EmptyBorder(0, 0, 0, 0));
121:                leftJustify.add(buttons, BorderLayout.WEST);
122:                pane.add(leftJustify, BorderLayout.SOUTH);
123:                return pane;
124:            }
125:
126:            /** Set the resolver on which the references list is based. */
127:            public void setResolver(Resolver resolver) {
128:                this .resolver = resolver;
129:                refModel = new ReferencesModel(resolver);
130:                refTable.setModel(refModel);
131:            }
132:
133:            private Component createReferenceView() {
134:                // FIXME need buttons for new/delete (delete only enabled if the
135:                // reference is entirely unused
136:                refModel = new ReferencesModel(resolver);
137:                refTable = new JTable(refModel) {
138:                    public void setRowSelectionInterval(int start, int end) {
139:                        super .setRowSelectionInterval(start, end);
140:                        // Make sure the selection is always visible. 
141:                        Rectangle cellRect = getCellRect(start, 0, true);
142:                        if (cellRect != null)
143:                            super .scrollRectToVisible(cellRect);
144:                    }
145:                };
146:                refTable.setName("browser.references");
147:                refTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
148:                refTable.setDefaultEditor(ComponentReference.class,
149:                        new XMLEditor());
150:                refTable.clearSelection();
151:                ListSelectionListener lsl = new ListSelectionListener() {
152:                    public void valueChanged(ListSelectionEvent lse) {
153:                        if (!lse.getValueIsAdjusting()) {
154:                            referenceListSelectionChanged(lse);
155:                        }
156:                    }
157:                };
158:                refTable.getSelectionModel().addListSelectionListener(lsl);
159:                JScrollPane scroll = new JScrollPane(refTable);
160:                scroll.getViewport().setBackground(refTable.getBackground());
161:                return scroll;
162:            }
163:
164:            /**
165:             * Create a tabbed pane for browsing either existing components or
166:             * component references.
167:             *
168:             * @return A JPanel for the left side of the main frame
169:             */
170:            private Component createLeftPanel() {
171:                tabs = new JTabbedPane() {
172:                    public Dimension getPreferredSize() {
173:                        return new Dimension(250, 200);
174:                    }
175:                };
176:                tabs.add(Strings.get("Hierarchy"), createHierarchyView());
177:                tabs.setToolTipTextAt(0, Strings.get("browser.hierarchy.tip"));
178:                tabs.add(Strings.get("References"), createReferenceView());
179:                tabs.setToolTipTextAt(1, Strings.get("browser.references.tip"));
180:                tabs.addChangeListener(new ChangeListener() {
181:                    public void stateChanged(ChangeEvent e) {
182:                        tabChanged(e);
183:                    }
184:                });
185:                return tabs;
186:            }
187:
188:            /**
189:             * Create the property browser/selection table.
190:             *
191:             * @return A JPanel for the right side of the main frame
192:             */
193:            private Component createRightPanel() {
194:                JPanel pane = new JPanel(new BorderLayout());
195:                propertyModel = new ComponentPropertyModel();
196:                propTable = new JTable(propertyModel);
197:                propTable.setName("browser.properties");
198:                propTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
199:                propTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
200:                propTable.setDefaultRenderer(Object.class,
201:                        new PropertyRenderer());
202:                ListSelectionListener lsl = new ListSelectionListener() {
203:                    public void valueChanged(ListSelectionEvent lse) {
204:                        if (!lse.getValueIsAdjusting()) {
205:                            enableAssertSampleButtons();
206:                        }
207:                    }
208:                };
209:                propTable.getSelectionModel().addListSelectionListener(lsl);
210:
211:                addAssertButton = new JButton("");
212:                addAssertButton.addActionListener(new ActionListener() {
213:                    public void actionPerformed(ActionEvent ev) {
214:                        firePropertyCheck(false);
215:                    }
216:                });
217:                addAssertButton.setEnabled(false);
218:                updateAssertText(false, false);
219:
220:                addSampleButton = new JButton(Strings.get("SampleProperty"));
221:                addSampleButton.addActionListener(new ActionListener() {
222:                    public void actionPerformed(ActionEvent ev) {
223:                        firePropertyCheck(true);
224:                    }
225:                });
226:                addSampleButton.setEnabled(false);
227:
228:                String waitKeyName = KeyEvent.getKeyText(ScriptEditor.KC_WAIT);
229:                String invertKeyName = KeyEvent
230:                        .getKeyText(ScriptEditor.KC_INVERT);
231:                String tip = Strings.get("AssertPropertyTip", new Object[] {
232:                        invertKeyName, waitKeyName, });
233:                addAssertButton.setToolTipText(TextFormat.tooltip(tip));
234:                tip = Strings.get("SamplePropertyTip");
235:                addSampleButton.setToolTipText(TextFormat.tooltip(tip));
236:
237:                filterPropertiesCheckBox = new JCheckBox(Strings.get("Filter"));
238:                filterPropertiesCheckBox.addActionListener(this );
239:                filterPropertiesCheckBox.setEnabled(true);
240:                filterPropertiesCheckBox.setSelected(true);
241:                filterPropertiesCheckBox.setToolTipText(Strings
242:                        .get("browser.properties.filter.tip"));
243:                JPanel buttonsPanel = new JPanel();
244:                buttonsPanel.add(addAssertButton);
245:                buttonsPanel.add(addSampleButton);
246:                buttonsPanel.add(filterPropertiesCheckBox);
247:                JPanel leftJustify = new JPanel(new BorderLayout());
248:                leftJustify.setBorder(new EmptyBorder(0, 0, 0, 0));
249:                leftJustify.add(buttonsPanel, BorderLayout.WEST);
250:
251:                JScrollPane scroll = new JScrollPane(propTable);
252:                scroll.getViewport().setBackground(propTable.getBackground());
253:                scroll.setColumnHeaderView(propTable.getTableHeader());
254:                pane.add(scroll, BorderLayout.CENTER);
255:                pane.add(leftJustify, BorderLayout.SOUTH);
256:
257:                attributeModel = new ReferenceAttributeModel();
258:                attributeModel.addTableModelListener(new AttributeListener());
259:                attributeTable = new JTable(attributeModel);
260:                JScrollPane scroll1 = new JScrollPane(attributeTable);
261:                scroll1.getViewport().setBackground(
262:                        attributeTable.getBackground());
263:
264:                inputMapTable = new JTable(InputMapModel.EMPTY);
265:                JScrollPane scroll2 = new JScrollPane(inputMapTable);
266:                scroll2.getViewport().setBackground(
267:                        inputMapTable.getBackground());
268:
269:                actionMapTable = new JTable(ActionMapModel.EMPTY);
270:                JScrollPane scroll3 = new JScrollPane(actionMapTable);
271:                scroll3.getViewport().setBackground(
272:                        actionMapTable.getBackground());
273:
274:                tabs2 = new JTabbedPane() {
275:                    public Dimension getPreferredSize() {
276:                        return new Dimension(300, 150);
277:                    }
278:                };
279:                tabs2.add(Strings.get("browser.properties"), pane);
280:                tabs2
281:                        .setToolTipTextAt(0, Strings
282:                                .get("browser.properties.tip"));
283:                tabs2.add(Strings.get("browser.attributes"), scroll1);
284:                tabs2
285:                        .setToolTipTextAt(1, Strings
286:                                .get("browser.attributes.tip"));
287:                tabs2.add(Strings.get("browser.inputmap"), scroll2);
288:                tabs2.setToolTipTextAt(2, Strings.get("browser.inputmap.tip"));
289:                tabs2.add(Strings.get("browser.actionmap"), scroll3);
290:                tabs2.setToolTipTextAt(3, Strings.get("browser.actionmap.tip"));
291:
292:                return tabs2;
293:            }
294:
295:            public void updateAssertText(boolean isWait, boolean invert) {
296:                addAssertButton.setText(Strings.get(isWait ? "WaitProperty"
297:                        : "AssertProperty", new Object[] { invert ? Strings
298:                        .get("assert.not_equals") : Strings
299:                        .get("assert.equals") }));
300:            }
301:
302:            /** Select the given reference in the current view. */
303:            public void setSelectedReference(ComponentReference ref) {
304:                if (ref != selectedReference) {
305:                    selectedReference = ref;
306:                    updateReferenceSelection(ref);
307:                    Component c = ref != null ? getComponentForReference(ref)
308:                            : null;
309:                    if (c != selectedComponent) {
310:                        selectedComponent = c;
311:                        updateComponentSelection(c);
312:                    }
313:                    fireSelectionChanged();
314:                }
315:            }
316:
317:            /** Select the given component (and make it visible) in the current
318:                view.  Update the auxiliary view components appropriately.
319:                If showing component references and the given component doesn't have
320:                one, switch the view to the hierarchy.
321:             */
322:            public void setSelectedComponent(Component comp) {
323:                selectedComponent = comp;
324:                ComponentReference ref = null;
325:                if (comp != null && resolver.getHierarchy().contains(comp)) {
326:                    ref = resolver.getComponentReference(comp);
327:                }
328:                if (ref != selectedReference) {
329:                    selectedReference = ref;
330:                    updateReferenceSelection(ref);
331:                }
332:                if (ref == null && !showingHierarchy()) {
333:                    tabs.setSelectedIndex(TAB_HIERARCHY);
334:                }
335:                updateComponentSelection(comp);
336:                fireSelectionChanged();
337:            }
338:
339:            /** Return the row index of the given component reference. */
340:            private int getRow(ComponentReference ref) {
341:                if (ref != null) {
342:                    for (int i = 0; i < refTable.getRowCount(); i++) {
343:                        ComponentReference value = (ComponentReference) refTable
344:                                .getValueAt(i, 0);
345:                        if (ref == value) {
346:                            return i;
347:                        }
348:                    }
349:                }
350:                return -1;
351:            }
352:
353:            /** Flag to avoid responding to list/tree selection changes when they're
354:             * made programmatically instead of by the user.
355:             */
356:            private boolean ignoreHierarchyChange = false;
357:            private boolean ignoreReferenceChange = false;
358:
359:            /** Set the appropriate selection in the reference list. */
360:            private void updateReferenceSelection(ComponentReference ref) {
361:                if (!showingHierarchy()) {
362:                    int row = getRow(ref);
363:                    ignoreReferenceChange = true;
364:                    if (row == -1) {
365:                        refTable.clearSelection();
366:                    } else {
367:                        refTable.setRowSelectionInterval(row, row);
368:                    }
369:                    ignoreReferenceChange = false;
370:                }
371:                updateAttributesList();
372:                updatePropertyList();
373:            }
374:
375:            /** Set the appropriate selection in the component hierarchy tree. */
376:            private void updateComponentSelection(Component comp) {
377:                if (showingHierarchy()) {
378:                    ignoreHierarchyChange = true;
379:                    if (comp == null) {
380:                        componentTree.clearSelection();
381:                    } else {
382:                        TreePath path = componentTree.getPath(comp);
383:                        ComponentNode node = (ComponentNode) path
384:                                .getLastPathComponent();
385:                        if (node.getUserObject() != comp) {
386:                            setCompactDisplay(false);
387:                            path = componentTree.getPath(comp);
388:                        }
389:                        componentTree.setSelectionPath(path);
390:                    }
391:                    ignoreHierarchyChange = false;
392:                }
393:                updateAttributesList();
394:                updatePropertyList();
395:            }
396:
397:            /**
398:             * Utility method showing whether a component node has been selected or
399:             * not. 
400:             */
401:            public boolean isComponentSelected() {
402:                if (showingHierarchy()) {
403:                    return (ComponentNode) componentTree
404:                            .getLastSelectedPathComponent() != null;
405:                }
406:                return refTable.getSelectedRow() != -1;
407:            }
408:
409:            /** When re-enabled, perform a reload of the tree. */
410:            public void setEnabled(boolean state) {
411:                super .setEnabled(state);
412:                if (state)
413:                    refresh();
414:            }
415:
416:            public void refresh() {
417:                SwingUtilities.invokeLater(new Runnable() {
418:                    public void run() {
419:                        componentTree.reload(null);
420:                    }
421:                });
422:            }
423:
424:            /** Convert the component reference into an actual component, creating a
425:             * dummy one if the real one is not available.
426:             */
427:            private Component getComponentForReference(ComponentReference ref) {
428:                Component comp = null;
429:                fakeComponent = false;
430:                try {
431:                    comp = ref.getComponent();
432:                } catch (ComponentSearchException e) {
433:                    if (e instanceof  MultipleComponentsFoundException) {
434:                        // FIXME query the user to select the right one?
435:                        // the right one may not exist at this point in time.
436:                        MultipleComponentsFoundException mc = (MultipleComponentsFoundException) e;
437:                        Component[] list = mc.getComponents();
438:                        String warning = "Multiple components found for "
439:                                + ref.toXMLString() + ": ";
440:                        for (int i = 0; i < list.length; i++) {
441:                            warning += "\n"
442:                                    + Robot
443:                                            .toHierarchyPath(mc.getComponents()[i]);
444:                        }
445:                        Log.warn(warning);
446:                    }
447:                    try {
448:                        fakeComponent = true;
449:                        comp = (Component) (Class
450:                                .forName(ref.getRefClassName())).newInstance();
451:                        comp.setName(Strings.get("browser.hierarchy.proxy",
452:                                new Object[] { ref.getID() }));
453:                        if (comp instanceof  Window) {
454:                            // make sure it never appears in the hierarchy
455:                            hierarchy.filter(comp);
456:                            componentTree.reload();
457:                        }
458:                    } catch (Exception exc) {
459:                        // Not much we can do here; we require a no-args constructor
460:                        // FIXME show a warning dialog
461:                    }
462:                }
463:                return comp;
464:            }
465:
466:            public boolean showingHierarchy() {
467:                return tabs.getSelectedIndex() == TAB_HIERARCHY;
468:            }
469:
470:            /** Returns the currently selected reference. */
471:            public ComponentReference getSelectedReference() {
472:                return selectedReference;
473:            }
474:
475:            /** Returns which component is currently selected. */
476:            public Component getSelectedComponent() {
477:                return selectedComponent;
478:            }
479:
480:            /** Sets whether uninteresting components are elided from the display. */
481:            public void setCompactDisplay(boolean compact) {
482:                filter = compact;
483:                filterButton.setSelected(filter);
484:                hierarchy.setCompact(filter);
485:                componentTree.setHierarchy(hierarchy);
486:            }
487:
488:            /** Returns whether the current display mode is compact. */
489:            public boolean isCompactDisplay() {
490:                return filter;
491:            }
492:
493:            /**
494:             * Generic action handler for buttons.  
495:             */
496:            public void actionPerformed(ActionEvent e) {
497:                if (e.getSource() == refreshButton) {
498:                    refresh();
499:                } else if (e.getSource() == filterButton) {
500:                    setCompactDisplay(!filter);
501:                } else if (e.getSource() == filterPropertiesCheckBox) {
502:                    updatePropertyList();
503:                }
504:            }
505:
506:            private void updateAttributesList() {
507:                attributeModel.setReference(selectedReference);
508:            }
509:
510:            private void updatePropertyList() {
511:                int row = propTable.getSelectedRow();
512:                String savedProperty = row == -1 ? "" : (String) propTable
513:                        .getValueAt(row, ComponentPropertyModel.PROPERTY_NAME);
514:
515:                addAssertButton.setEnabled(false);
516:                addSampleButton.setEnabled(false);
517:                Component comp = showingHierarchy()
518:                        || selectedReference != null ? selectedComponent : null;
519:                propertyModel.setComponent(comp, filterPropertiesCheckBox
520:                        .isSelected());
521:                for (row = 0; row < propTable.getRowCount(); row++) {
522:                    String prop = (String) propTable.getValueAt(row,
523:                            ComponentPropertyModel.PROPERTY_NAME);
524:                    if (prop.equals(savedProperty)) {
525:                        propTable.setRowSelectionInterval(row, row);
526:                        Rectangle rect = propTable.getCellRect(row, 0, true);
527:                        propTable.scrollRectToVisible(rect);
528:                        enableAssertSampleButtons();
529:                        break;
530:                    }
531:                }
532:
533:                if (comp instanceof  JComponent) {
534:                    InputMap im = ((JComponent) comp).getInputMap();
535:                    ActionMap am = ((JComponent) comp).getActionMap();
536:                    inputMapTable.setModel(new InputMapModel(im));
537:                    actionMapTable.setModel(new ActionMapModel(am));
538:                } else {
539:                    inputMapTable.setModel(InputMapModel.EMPTY);
540:                    actionMapTable.setModel(ActionMapModel.EMPTY);
541:                }
542:                inputMapTable.repaint();
543:                actionMapTable.repaint();
544:            }
545:
546:            /** Returns the Component represented by the current tree selection. */
547:            private Component getSelectedComponentFromTree() {
548:                ComponentNode node = (ComponentNode) componentTree
549:                        .getLastSelectedPathComponent();
550:                Component comp = node != null ? node.getComponent() : null;
551:                return comp;
552:            }
553:
554:            private ComponentReference getReferenceAt(int row) {
555:                return (ComponentReference) refTable.getValueAt(row, 0);
556:            }
557:
558:            /** Returns the component reference represented by the current selection
559:             * in the reference list.
560:             */
561:            private ComponentReference getSelectedReferenceFromList() {
562:                int refrow = refTable.getSelectedRow();
563:                return refrow == -1 ? null : getReferenceAt(refrow);
564:            }
565:
566:            public void enableAssertSampleButtons() {
567:                int row = propTable.getSelectedRow();
568:                addAssertButton.setEnabled(row != -1 && isComponentSelected());
569:                addSampleButton.setEnabled(row != -1 && isComponentSelected());
570:            }
571:
572:            /** Called when a the reference list selection changes, and when the
573:                property list changes. */
574:            public void referenceListSelectionChanged(ListSelectionEvent e) {
575:                if (!ignoreReferenceChange) {
576:                    setSelectedReference(getSelectedReferenceFromList());
577:                }
578:            }
579:
580:            /** Invoked when the hierarchy/reference tab changes. */
581:            public void tabChanged(ChangeEvent e) {
582:                if (showingHierarchy()) {
583:                    // If we were viewing a fake component in the reference view,
584:                    // switch to no component selection in the hierarchy view
585:                    if (fakeComponent) {
586:                        fakeComponent = false;
587:                        setSelectedComponent(null);
588:                    } else {
589:                        updateComponentSelection(selectedComponent);
590:                    }
591:                } else {
592:                    // Bug on OSX always leaves a selection in the reference list
593:                    // Avoid it by explicitly setting the selection if we can
594:                    if (selectedReference == null && refTable.getRowCount() > 0) {
595:                        setSelectedReference(getReferenceAt(0));
596:                    } else {
597:                        updateReferenceSelection(selectedReference);
598:                    }
599:                }
600:            }
601:
602:            private ArrayList listeners = new ArrayList();
603:
604:            public void addSelectionListener(ComponentBrowserListener cbl) {
605:                ArrayList list = new ArrayList(listeners);
606:                list.add(cbl);
607:                listeners = list;
608:            }
609:
610:            public void removeSelectionListener(ComponentBrowserListener cbl) {
611:                ArrayList list = new ArrayList(listeners);
612:                list.remove(cbl);
613:                listeners = list;
614:            }
615:
616:            protected void fireSelectionChanged() {
617:                Iterator iter = listeners.iterator();
618:                while (iter.hasNext()) {
619:                    ((ComponentBrowserListener) iter.next()).selectionChanged(
620:                            this , selectedComponent, selectedReference);
621:                }
622:            }
623:
624:            protected void firePropertyCheck(boolean sample) {
625:                int row = propTable.getSelectedRow();
626:                if (row == -1 || selectedComponent == null)
627:                    return;
628:                Method m = (Method) propertyModel.getValueAt(row,
629:                        ComponentPropertyModel.METHOD_OBJECT);
630:                Object value = propertyModel.getValueAt(row,
631:                        ComponentPropertyModel.PROPERTY_VALUE);
632:                Iterator iter = listeners.iterator();
633:                while (iter.hasNext()) {
634:                    ((ComponentBrowserListener) iter.next()).propertyAction(
635:                            this , m, value, sample);
636:                }
637:            }
638:
639:            /** Provides filtering of another hierarchy to remove locally-spawned
640:             * throwaway components.  
641:             */
642:            private class LocalHierarchy extends CompactHierarchy {
643:                private Map filtered = new WeakHashMap();
644:                private Hierarchy raw = new AWTHierarchy();
645:
646:                public LocalHierarchy(Hierarchy h) {
647:                    super (h);
648:                }
649:
650:                public Collection getRoots() {
651:                    Collection roots = isCompact() ? super .getRoots() : raw
652:                            .getRoots();
653:                    roots.removeAll(filtered.keySet());
654:                    return roots;
655:                }
656:
657:                public Collection getComponents(Component c) {
658:                    Collection kids = isCompact() ? super .getComponents(c)
659:                            : raw.getComponents(c);
660:                    kids.removeAll(filtered.keySet());
661:                    return kids;
662:                }
663:
664:                public boolean contains(Component c) {
665:                    return (isCompact() ? super .contains(c) : raw.contains(c))
666:                            && !filtered.containsKey(c);
667:                }
668:
669:                public void filter(Component c) {
670:                    filtered.put(c, Boolean.TRUE);
671:                }
672:            }
673:
674:            private class AttributeListener implements  TableModelListener {
675:                private boolean messaging = false;
676:
677:                public void tableChanged(TableModelEvent e) {
678:                    // Preserve the reference table selection
679:                    // NOTE: only really need to message on ID changes, since that's
680:                    // the only thing displayed in the reference table.
681:                    // NOTE: does anything other than the Script use the cref id?
682:                    // first arg of most actions, what else? 
683:                    if (!messaging) {
684:                        messaging = true;
685:                        ComponentReference ref = selectedReference;
686:                        refModel.fireTableDataChanged();
687:                        setSelectedReference(ref);
688:                        messaging = false;
689:                    }
690:                }
691:            }
692:
693:            /** To be invoked when an underlying component reference has changed. */
694:            public void referencesChanged() {
695:                if (SwingUtilities.isEventDispatchThread())
696:                    refModel.fireTableDataChanged();
697:                else {
698:                    SwingUtilities.invokeLater(new Runnable() {
699:                        public void run() {
700:                            referencesChanged();
701:                        }
702:                    });
703:                }
704:            }
705:
706:            private class PropertyRenderer extends DefaultTableCellRenderer {
707:                public Component getTableCellRendererComponent(JTable table,
708:                        Object value, boolean isSelected, boolean hasFocus,
709:                        int row, int column) {
710:                    JComponent c = (JComponent) super 
711:                            .getTableCellRendererComponent(table, value,
712:                                    isSelected, hasFocus, row, column);
713:                    value = propertyModel.getValueAt(row,
714:                            ComponentPropertyModel.ACCESSIBLE);
715:                    if (isSelected) {
716:                        c.setBackground(table.getSelectionBackground());
717:                        c.setForeground(table.getSelectionForeground());
718:                    } else {
719:                        c.setBackground(table.getBackground());
720:                        c.setForeground(table.getForeground());
721:                    }
722:                    if ((column == 1) && Boolean.TRUE.equals(value)) {
723:                        setToolTipText(Strings.get("Inaccessible"));
724:                        c.setBackground(Color.gray);
725:                    }
726:                    /*
727:                    if (column == 1 && Boolean.TRUE.equals(value)) {
728:                        setToolTipText(Strings.get("Inaccessible"));
729:                        c.setBackground(Color.gray);
730:                    }
731:                    else {
732:                        c.setBackground(UIManager.getColor("Table.background"));
733:                    }
734:                     */
735:                    return c;
736:                }
737:
738:                protected void setValue(Object value) {
739:                    String str = ArgumentParser.toString(value);
740:                    setToolTipText(str);
741:                    super
742:                            .setValue(str == ArgumentParser.DEFAULT_TOSTRING ? value
743:                                    .toString()
744:                                    : str);
745:                }
746:            }
747:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.