Source Code Cross Referenced for JFilterDialog.java in  » IDE-Netbeans » uml » org » netbeans » modules » uml » ui » swing » projecttree » 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 » IDE Netbeans » uml » org.netbeans.modules.uml.ui.swing.projecttree 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.uml.ui.swing.projecttree;
043:
044:        import java.awt.Color;
045:        import java.awt.event.ActionListener;
046:        import java.awt.event.FocusEvent;
047:        import java.awt.event.FocusListener;
048:        import java.awt.event.MouseAdapter;
049:        import java.awt.event.MouseEvent;
050:        import javax.swing.tree.TreePath;
051:        import org.netbeans.modules.uml.core.eventframework.IEventPayload;
052:        import org.netbeans.modules.uml.ui.controls.filter.FilterItem;
053:        import org.netbeans.modules.uml.ui.controls.filter.IFilterDialog;
054:        import org.netbeans.modules.uml.ui.controls.filter.IFilterItem;
055:        import org.netbeans.modules.uml.ui.controls.filter.IFilterNode;
056:        import org.netbeans.modules.uml.ui.controls.filter.IProjectTreeFilterDialogEventDispatcher;
057:        import org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeModel;
058:        import org.netbeans.modules.uml.ui.support.DispatchHelper;
059:        import org.netbeans.modules.uml.ui.swing.SelectableLabel;
060:        import org.netbeans.modules.uml.ui.swing.commondialogs.JCenterDialog;
061:        import java.awt.Component;
062:        import java.awt.Dialog;
063:        import java.awt.Dimension;
064:        import java.awt.Frame;
065:        import java.awt.GridBagConstraints;
066:        import java.awt.GridBagLayout;
067:        import java.awt.Insets;
068:        import java.awt.event.ActionEvent;
069:        import java.awt.event.KeyEvent;
070:        import java.awt.event.WindowAdapter;
071:        import java.awt.event.WindowEvent;
072:        import javax.swing.AbstractAction;
073:        import javax.swing.Icon;
074:        import javax.swing.JButton;
075:        import javax.swing.JCheckBox;
076:        import javax.swing.JComponent;
077:        import javax.swing.JLabel;
078:        import javax.swing.JPanel;
079:        import javax.swing.JScrollPane;
080:        import javax.swing.JTree;
081:        import javax.swing.KeyStroke;
082:        import javax.swing.UIManager;
083:        import javax.swing.border.EmptyBorder;
084:        import javax.swing.plaf.ColorUIResource;
085:        import javax.swing.tree.DefaultMutableTreeNode;
086:        import javax.swing.tree.DefaultTreeModel;
087:        import javax.swing.tree.TreeCellRenderer;
088:        import javax.swing.tree.TreeModel;
089:
090:        /**
091:         * The JFilterDialog allows users to specified the items should be filtered
092:         * and the items that should not be filtered.  The dialog will present the user
093:         * with a tree control that has a checkbox by each of it's nodes.  When the
094:         * checkbox is checked then the item should not be filtered.  When the item is
095:         * not check the item should be filtered out.
096:         * <p>
097:         * The OnProjectTreeFilterDialogInit is sent to all registered
098:         * IProjectTreeFilterDialogEventsSink objects.  The
099:         * IProjectTreeFilterDialogEventsSink objects are responsible for filling
100:         * in the filter items by using the the methods createRootNode, and
101:         * addFilterItem.
102:         * <p>
103:         * JFilterDialog is the swing implementation of the IProjectTreeFilterDialog
104:         * interface.
105:         *
106:         * @author Trey Spiva
107:         * @see IProjectTreeFilterDialog
108:         * @see #createRootNode(org.netbeans.modules.uml.ui.controls.projecttree.IFilterItem)
109:         * @see #createRootNode(java.lang.String)
110:         * @see #addFilterItem
111:         */
112:        public class JFilterDialog extends JCenterDialog implements 
113:                IFilterDialog {
114:            private JTree m_FilterTree = new JTree();
115:            private JButton m_OKBtn = null;
116:            private JButton m_CancelBtn = null;
117:            private DefaultTreeModel m_Model = null;
118:            private DefaultMutableTreeNode m_Root = new DefaultMutableTreeNode();
119:            private DispatchHelper m_Helper = new DispatchHelper();
120:            private IProjectTreeModel m_ProjectTreeModel = null;
121:            private JLabel spacer = new JLabel();
122:
123:            /**
124:             * Initialize the filter dialog.
125:             * @param model The project tree model that will be filtered.
126:             */
127:            public JFilterDialog(IProjectTreeModel model) {
128:                super ();
129:                initialize();
130:                pack();
131:                setProjectTreeModel(model);
132:            }
133:
134:            /**
135:             * Initialize the filter dialog.
136:             * @param parent The owner of the dialog.
137:             * @param model The project tree model that will be filtered.
138:             */
139:            public JFilterDialog(Frame parent, IProjectTreeModel model) {
140:                super (parent, true);
141:                initialize();
142:                pack(); // pack() should be called before center(parent)
143:                center(parent);
144:                setProjectTreeModel(model);
145:            }
146:
147:            /**
148:             * Initialize the filter dialog.
149:             * @param parent The owner of the dialog.
150:             * @param model The project tree model that will be filtered.
151:             */
152:            public JFilterDialog(Dialog parent, IProjectTreeModel model) {
153:                super (parent, true);
154:                initialize();
155:                pack(); // pack() should be called before center(parent)
156:                center(parent);
157:                setProjectTreeModel(model);
158:            }
159:
160:            /**
161:             * Initalizes the dialog.  The controls are created and the renders and
162:             * editor are setup.
163:             *
164:             */
165:            protected void initialize() {
166:                setTitle(ProjectTreeResources
167:                        .getString("JFilterDialog.Filter_Dialog_Title")); //$NON-NLS-1$
168:                initializeControls();
169:
170:                //setSize(400, 500);
171:                //setResizable(false);
172:                setPreferredSize(new java.awt.Dimension(400, 500));
173:                setResizable(true);
174:                CheckBoxTreeRenderEditor renderEditor = new CheckBoxTreeRenderEditor();
175:                m_FilterTree.setCellRenderer(renderEditor);
176:                m_FilterTree.setShowsRootHandles(true);
177:
178:                m_FilterTree.addMouseListener(new NodeSelectionListener(
179:                        m_FilterTree));
180:
181:                // Add accelerator
182:                ActionListener action = new ActionListener() {
183:                    public void actionPerformed(ActionEvent e) {
184:                        int selectedRows[] = m_FilterTree.getSelectionRows();
185:                        if (selectedRows == null || selectedRows.length == 0)
186:                            return;
187:
188:                        // get the path of the 1st selected row
189:                        int row = selectedRows[0];
190:                        TreePath path = m_FilterTree.getPathForRow(row);
191:                        if (path != null) {
192:                            FilterNode node = (FilterNode) path
193:                                    .getLastPathComponent();
194:                            boolean isSelected = !(node.isOn());
195:
196:                            int state = IFilterItem.FILTER_STATE_OFF;
197:                            if (isSelected == true) {
198:                                state = IFilterItem.FILTER_STATE_ON;
199:                            }
200:                            setItemState(node, state);
201:
202:                            ((DefaultTreeModel) m_FilterTree.getModel())
203:                                    .nodeChanged(node);
204:                            if (row == 0) {
205:                                m_FilterTree.revalidate();
206:                                m_FilterTree.repaint();
207:                            }
208:                        }
209:                    }
210:                };
211:
212:                // use SPACE bar to select/deselect the m_Tree node
213:                m_FilterTree.registerKeyboardAction(action, KeyStroke
214:                        .getKeyStroke(KeyEvent.VK_SPACE, 0),
215:                        JComponent.WHEN_FOCUSED);
216:                m_FilterTree.addFocusListener(new TreeFocusListerner());
217:                m_FilterTree.setEditable(true);
218:
219:                m_FilterTree.setRootVisible(false);
220:                m_FilterTree.setShowsRootHandles(true);
221:
222:                //      m_Model = new DefaultTreeModel(m_Root);
223:            }
224:
225:            /**
226:             * Initilalize the control for the filter dialog.
227:             */
228:            protected void initializeControls() {
229:                m_OKBtn = new JButton(new OKAction(this ));
230:                getRootPane().setDefaultButton(m_OKBtn);
231:
232:                m_CancelBtn = new JButton(new CancelAction());
233:
234:                JPanel panel = new JPanel();
235:                panel.setBorder(new EmptyBorder(10, 10, 5, 10));
236:
237:                panel.setLayout(new GridBagLayout());
238:                JScrollPane scrollPane = new JScrollPane(m_FilterTree);
239:                scrollPane
240:                        .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
241:                scrollPane
242:                        .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
243:                panel.add(scrollPane, new GridBagConstraints(0, 0, 3, 1, 1.0,
244:                        0.9, GridBagConstraints.CENTER,
245:                        GridBagConstraints.BOTH, new Insets(3, 3, 3, 3), 0, 0));
246:                panel.add(spacer, new GridBagConstraints(0, 1, 1, 1, 0.3, 0.1,
247:                        GridBagConstraints.CENTER,
248:                        GridBagConstraints.HORIZONTAL, new Insets(0, 3, 0, 0),
249:                        0, 0));
250:                panel.add(m_OKBtn, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
251:                        GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL,
252:                        new Insets(0, 0, 0, 3), 0, 0));
253:                panel.add(m_CancelBtn, new GridBagConstraints(2, 1, 1, 1, 0.0,
254:                        0.0, GridBagConstraints.EAST,
255:                        GridBagConstraints.HORIZONTAL, new Insets(0, 3, 0, 3),
256:                        0, 0));
257:
258:                // reset the buttons' size to the larger size. This applies to all locales
259:                Dimension okSize = m_OKBtn.getPreferredSize();
260:                Dimension cancelSize = m_CancelBtn.getPreferredSize();
261:                if (cancelSize.width > okSize.width) {
262:                    m_OKBtn.setPreferredSize(cancelSize);
263:                } else {
264:                    m_CancelBtn.setPreferredSize(okSize);
265:                }
266:
267:                getContentPane().add(panel);
268:
269:            }
270:
271:            /**
272:             * Creates a top level filter tree node that is not associated to a filtered
273:             * item.
274:             *
275:             * @param name The name of the user to be displayed to the user.    *
276:             * @return The top level node.
277:             */
278:            public IFilterNode createRootNode(String name) {
279:                FilterItem item = new FilterItem(name);
280:                return createRootNode(item);
281:            }
282:
283:            /**
284:             * Creates a top level filter tree node that represent the filtered item.
285:             *
286:             * @param item The filter item to add to the FilterNode.
287:             * @return The FilterNode that represents the filter item.
288:             */
289:            public IFilterNode createRootNode(IFilterItem item) {
290:                FilterNode retVal = null;
291:                // We were getting into a situation where this was being called from both the project tree
292:                // and the design center tree, so we had 4 root nodes
293:                // There are two root nodes (Model Elements and Diagrams), so before we add anymore root nodes,
294:                // check the count and don't add if there are already too
295:                // We will ASSUME that it is the correct two nodes
296:                if (m_Root.getChildCount() < 2) {
297:                    retVal = new FilterNode(item);
298:                    m_Root.add(retVal);
299:                }
300:                return retVal;
301:            }
302:
303:            /**
304:             * Adds a new filter item to the specified FilterNode.  The FilterNode that
305:             * is created to represent the IFilterItem is returned.
306:             *
307:             * @param parent The parent of the filter item.  If the parent is
308:             *               <code>null</code> then the filter item is not added.
309:             * @param item The filter item to add to the FilterNode.
310:             * @return The FilterNode that represents the filter item.
311:             */
312:            public IFilterNode addFilterItem(IFilterNode parent,
313:                    IFilterItem item) {
314:                IFilterNode retVal = null;
315:
316:                if (parent != null) {
317:                    retVal = new FilterNode(item);
318:                    parent.add(retVal);
319:                }
320:                return retVal;
321:            }
322:
323:            /**
324:             * Shows the dialog to the user.  The OnProjectTreeFilterDialogInit is sent
325:             * to all registered IProjectTreeFilterDialogEventsSink objects.  The
326:             * IProjectTreeFilterDialogEventsSink objects are responsible for filling
327:             * in the filter items by using the the methods createRootNode, and
328:             * addFilterItem.
329:             *
330:             * @see #createRootNode(org.netbeans.modules.uml.ui.controls.projecttree.IFilterItem)
331:             * @see #createRootNode(java.lang.String)
332:             * @see #addFilterItem
333:             */
334:            public void show() {
335:                // cvc - CR 6271328
336:                // this method is called the first time a filter is applied to
337:                // the Model root node. 2+ times, the show(TreeModel) will be called
338:
339:                TreeModel model = getModel();
340:                initializeModel(model);
341:                m_FilterTree.setModel(model);
342:
343:                super .show();
344:
345:                // cvc - CR 6271328
346:                // clearing the model defeates the purpose of caching it to reuse
347:                // the settings when the filter dialog is used again	   // clearModel();
348:            }
349:
350:            // cvc - CR 6271328
351:            // the filter tree model is being passed in from the action which gets it
352:            // from the UMLModelRootNode where it is cached to preserve the
353:            // filter settings
354:            public void show(DefaultTreeModel model) {
355:                initializeModel(model);
356:                m_FilterTree.setModel(model);
357:                setModel(model);
358:
359:                super .show();
360:            }
361:
362:            /**
363:             * Clears the filter dialog.
364:             */
365:            protected void clearModel() {
366:                m_Root.removeAllChildren();
367:                m_Model = null;
368:            }
369:
370:            /**
371:             * Initalizes the model.  The onProjectTreeFilterDialogInit event is sent
372:             * to all registered IProjectTreeFilterDialogEventsSink.
373:             *
374:             * @param model
375:             * @see IProjectTreeFilterDialogEventsSink#onProjectTreeFilterDialogInit
376:             */
377:            protected void initializeModel(TreeModel model) {
378:
379:                IProjectTreeFilterDialogEventDispatcher dispatcher = null;
380:                dispatcher = m_Helper.getProjectTreeFilterDialogDispatcher();
381:
382:                IEventPayload payLoad = dispatcher
383:                        .createPayload("ProjectTreeFilterDialogInit"); //$NON-NLS-1$
384:                dispatcher.fireProjectTreeFilterDialogInit(this , payLoad);
385:
386:            }
387:
388:            /**
389:             * Retrieves the tree model that contains the filter item data.
390:             *
391:             * @return The tree model.
392:             */
393:            protected TreeModel getModel() {
394:                if (m_Model == null) {
395:                    m_Root.removeAllChildren();
396:                    m_Model = new DefaultTreeModel(m_Root);
397:                }
398:
399:                return m_Model;
400:            }
401:
402:            protected void setModel(DefaultTreeModel val) {
403:                m_Model = val;
404:                m_Root = (DefaultMutableTreeNode) val.getRoot();
405:                m_Model.setRoot(m_Root);
406:            }
407:
408:            // cvc - CR 6271328
409:            // need public access to the tree model to cache in UMLModelRootNode
410:            public DefaultTreeModel getTreeModel() {
411:                return (DefaultTreeModel) getModel();
412:            }
413:
414:            /**
415:             * Retrieves the root nodes of the tree.
416:             *
417:             * @return The root nodes.
418:             *
419:             */
420:            public IFilterNode[] getRootNodes() {
421:                IFilterNode[] retVal = new FilterNode[m_Root.getChildCount()];
422:
423:                for (int index = 0; index < retVal.length; index++) {
424:                    retVal[index] = (IFilterNode) m_Root.getChildAt(index);
425:                }
426:
427:                return retVal;
428:            }
429:
430:            /**
431:             * Sets the items state.  All of the items children will be set to the
432:             * same state.
433:             *
434:             * @param item The item to process.
435:             * @param state The state value.
436:             */
437:            protected void setItemState(IFilterNode item, int state) {
438:                item.setState(state);
439:
440:                int childrenCount = item.getChildCount();
441:                for (int index = 0; index < childrenCount; index++) {
442:                    FilterNode curItem = (FilterNode) m_Model.getChild(item,
443:                            index);
444:
445:                    if (curItem != null) {
446:                        curItem.setState(state);
447:                    }
448:                }
449:            }
450:
451:            class CheckBoxTreeRenderEditor extends JPanel implements 
452:                    TreeCellRenderer {
453:                protected JCheckBox check;
454:                protected SelectableLabel strLabel;
455:
456:                public CheckBoxTreeRenderEditor() {
457:                    setLayout(null);
458:                    add(check = new JCheckBox());
459:                    add(strLabel = new SelectableLabel());
460:                    check.setLocation(50, 0);
461:                    check.setBackground(UIManager
462:                            .getColor("Tree.textBackground"));
463:                    setOpaque(false);
464:
465:                    check.requestFocus();
466:
467:                }
468:
469:                public Component getTreeCellRendererComponent(JTree tree,
470:                        Object value, boolean isSelected, boolean expanded,
471:                        boolean leaf, int row, boolean hasFocus) {
472:
473:                    initializeControl(value, tree, isSelected, hasFocus);
474:                    return this ;
475:                }
476:
477:                /**
478:                 * Initilazes the control with the FilterNode details.
479:                 * @param value
480:                 */
481:                protected void initializeControl(Object value, JTree tree,
482:                        boolean isSelected, boolean hasFocus) {
483:                    if (value instanceof  IFilterNode) {
484:                        IFilterNode cNode = (IFilterNode) value;
485:                        String stringValue = cNode.getDispalyName();
486:
487:                        setEnabled(tree.isEnabled());
488:
489:                        if (cNode != null) {
490:                            check.setSelected(cNode.isOn());
491:                        }
492:
493:                        strLabel.setFont(tree.getFont());
494:                        strLabel.setText(stringValue);
495:                        strLabel.setIcon(cNode.getIcon());
496:                        strLabel.setSelected(isSelected);
497:                        strLabel.setFocus(hasFocus);
498:
499:                        if (isSelected) {
500:                            strLabel.setSelectedBackground(UIManager
501:                                    .getColor("Tree.selectionBackground"));
502:                            strLabel.setForeground(UIManager
503:                                    .getColor("Tree.selectionForeground"));
504:                        } else {
505:                            strLabel.setForeground(UIManager
506:                                    .getColor("Tree.textForeground"));
507:                        }
508:
509:                    } else {
510:                        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
511:                        if (node.getUserObject() != null) {
512:                            strLabel.setText("  "
513:                                    + node.getUserObject().toString());
514:                        }
515:                    }
516:
517:                }
518:
519:                public Dimension getPreferredSize() {
520:                    Dimension d_check = check.getPreferredSize();
521:                    Dimension d_label = strLabel.getPreferredSize();
522:
523:                    return new Dimension(d_check.width + d_label.width,
524:                            d_check.height < d_label.height ? d_label.height
525:                                    : d_check.height);
526:                }
527:
528:                public void doLayout() {
529:                    Dimension d_check = check.getPreferredSize();
530:                    Dimension d_label = strLabel.getPreferredSize();
531:                    int y_check = 0;
532:                    int y_label = 0;
533:
534:                    if (d_check.height > d_label.height) {
535:                        y_check = (d_label.height - d_check.height) / 2;
536:                    }
537:
538:                    else {
539:                        y_label = (d_check.height - d_label.height) / 2;
540:                    }
541:
542:                    check.setLocation(0, y_check);
543:                    check.setBounds(0, y_check, d_check.width, d_check.height);
544:                    strLabel.setLocation(d_check.width, y_label);
545:                    strLabel.setBounds(d_check.width, y_label, d_label.width,
546:                            d_label.height);
547:                }
548:
549:                public void setBackground(Color color) {
550:                    if (color instanceof  ColorUIResource)
551:                        color = null;
552:                    super .setBackground(color);
553:                }
554:            }
555:
556:            //**************************NodeSelectionListener***************************
557:            class NodeSelectionListener extends MouseAdapter {
558:                JTree tree;
559:
560:                NodeSelectionListener(JTree tree) {
561:                    this .tree = tree;
562:                }
563:
564:                public void mouseClicked(MouseEvent e) {
565:                    int x = e.getX();
566:                    int y = e.getY();
567:                    int row = tree.getRowForLocation(x, y);
568:                    TreePath path = tree.getPathForRow(row);
569:
570:                    if (path != null) {
571:                        Object obj = path.getLastPathComponent();
572:
573:                        if (obj instanceof  FilterNode) {
574:                            FilterNode node = (FilterNode) obj;
575:                            boolean isSelected = !(node.isOn());
576:
577:                            int state = IFilterItem.FILTER_STATE_OFF;
578:                            if (isSelected == true) {
579:                                state = IFilterItem.FILTER_STATE_ON;
580:                            }
581:
582:                            setItemState(node, state);
583:
584:                            ((DefaultTreeModel) tree.getModel())
585:                                    .nodeChanged(node);
586:                            if (row == 0) {
587:                                tree.revalidate();
588:                                tree.repaint();
589:                            }
590:                        }
591:                    }
592:                }
593:            }
594:
595:            //************************* TreeFocusListener **************************
596:            class TreeFocusListerner implements  FocusListener {
597:                JTree tree;
598:
599:                public void focusGained(FocusEvent e) {
600:                    Component comp = e.getComponent();
601:                    if (comp instanceof  JTree) {
602:                        tree = (JTree) comp;
603:                        TreePath path = tree.getPathForRow(0);
604:                        tree.setSelectionPath(path);
605:                    }
606:                }
607:
608:                public void focusLost(FocusEvent e) {
609:                    Component comp = e.getComponent();
610:                    if (comp instanceof  JTree) {
611:                        tree = (JTree) comp;
612:                        tree.clearSelection();
613:                    }
614:                }
615:            }
616:
617:            /**
618:             * The FilterNode is used to wrap the IFilterItem.  The FilterNode is used
619:             * to isolate the users changes until they press the OK button.  Once the
620:             * OK button is pressed the IFilterItem will be updated with the users
621:             * changes.  If the user did not change the value of the IFilterItem then
622:             * the item will not be updated.
623:             *
624:             * @author Trey Spiva
625:             * @see IFilterItem
626:             */
627:            protected class FilterNode extends DefaultMutableTreeNode implements 
628:                    IFilterNode {
629:                private int m_State = IFilterItem.FILTER_STATE_ON;
630:                private IFilterItem m_Item = null;
631:                private Icon m_Icon = null;
632:
633:                /**
634:                 * Initializes the filter node.
635:                 * @param item The filter item represented by the node.
636:                 */
637:                public FilterNode(IFilterItem item) {
638:                    setItem(item);
639:                }
640:
641:                /**
642:                 * Initializes the filter node.
643:                 * @param item The filter item represented by the node.
644:                 * @param icon The Icon to display.
645:                 */
646:                public FilterNode(IFilterItem item, Icon icon) {
647:                    setIcon(icon);
648:                    setItem(item);
649:                }
650:
651:                /**
652:                 * Specifies if the checkbox for the filter item is on or off.
653:                 *
654:                 * @return <b>true</b> if the item is checked, <b>false</b> if the item is
655:                 *         off.
656:                 */
657:                public boolean isOn() {
658:                    return m_State == IFilterItem.FILTER_STATE_ON;
659:                }
660:
661:                /**
662:                 * Sets the state of the filter item.
663:                 *
664:                 * @param value <b>true</b> if the item is checked, <b>false</b> if the
665:                 *              item is off.
666:                 * @param dialog The dialog that set the state.
667:                 */
668:                public void setState(int value) {
669:                    m_State = value;
670:                }
671:
672:                /**
673:                 * Retrieves the filter item associated with this node.
674:                 *
675:                 * @return The filter item.
676:                 */
677:                public IFilterItem getItem() {
678:                    return m_Item;
679:                }
680:
681:                /**
682:                 * Sets the filter item associated with this node.
683:                 *
684:                 * @param item The filter item.
685:                 */
686:                public void setItem(IFilterItem item) {
687:                    m_Item = item;
688:                    setState(item.getState());
689:                }
690:
691:                /**
692:                 * Retrieves the name that is to be displayed to the user.
693:                 *
694:                 * @return The display name.
695:                 */
696:                public String getDispalyName() {
697:                    String retVal = ""; //$NON-NLS-1$
698:                    if (m_Item != null) {
699:                        retVal = m_Item.getName();
700:                    }
701:
702:                    return retVal;
703:                }
704:
705:                /**
706:                 * Retrieves the icon that represent the filter item.
707:                 *
708:                 * @return The icon to display.
709:                 */
710:                public Icon getIcon() {
711:                    Icon retVal = null;
712:
713:                    if (getItem() != null) {
714:                        retVal = getItem().getIcon();
715:                    }
716:
717:                    if (retVal == null) {
718:                        retVal = m_Icon;
719:                    }
720:
721:                    return retVal;
722:                }
723:
724:                /**
725:                 * Sets the icon that represent the filter item.
726:                 *
727:                 * @param value The icon to display.
728:                 */
729:                public void setIcon(Icon value) {
730:                    m_Icon = value;
731:                }
732:
733:                /**
734:                 * Saves the nodes contents to the associated IFilterItem.  The children
735:                 * of the node is also saved.
736:                 */
737:                public void save(IFilterDialog dialog) {
738:                    IFilterItem item = getItem();
739:                    if ((item != null) && (m_State != item.getState())) {
740:                        item.setState(m_State, dialog);
741:                    }
742:
743:                    int childrenCount = getChildCount();
744:                    for (int index = 0; index < childrenCount; index++) {
745:                        Object child = getChildAt(index);
746:
747:                        if (child instanceof  IFilterNode) {
748:                            IFilterNode curNode = (IFilterNode) child;
749:                            if (curNode != null) {
750:                                curNode.save(dialog);
751:                            }
752:                        }
753:                    }
754:                }
755:
756:                /* (non-Javadoc)
757:                 * @see org.netbeans.modules.uml.ui.controls.filter.IFilterNode#add(org.netbeans.modules.uml.ui.controls.filter.IFilterNode)
758:                 */
759:                public void add(IFilterNode newChild)
760:                        throws IllegalArgumentException {
761:                    if (newChild instanceof  FilterNode) {
762:                        FilterNode node = (FilterNode) newChild;
763:                        super .add(node);
764:                    }
765:                }
766:
767:            }
768:
769:            /**
770:             * The action that performs the OK button action.  The users changes will
771:             * be saved.
772:             */
773:            protected class OKAction extends AbstractAction {
774:                private JFilterDialog m_Dialog = null;
775:
776:                public OKAction(JFilterDialog dialog) {
777:                    super (ProjectTreeResources
778:                            .getString("JFilterDialog.OK_Btn_Title")); //$NON-NLS-1$
779:                    m_Dialog = dialog;
780:                }
781:
782:                /**
783:                 * Saves the users changes and closes the window.
784:                 *
785:                 * @param e The event data.
786:                 */
787:                public void actionPerformed(ActionEvent e) {
788:                    IFilterNode[] roots = getRootNodes();
789:
790:                    if (roots != null) {
791:                        for (int index = 0; index < roots.length; index++) {
792:                            roots[index].save(m_Dialog);
793:                        }
794:                    }
795:
796:                    IProjectTreeFilterDialogEventDispatcher dispatcher = null;
797:                    dispatcher = m_Helper
798:                            .getProjectTreeFilterDialogDispatcher();
799:
800:                    IEventPayload payLoad = dispatcher
801:                            .createPayload("ProjectTreeFilterDialogOKActivated"); //$NON-NLS-1$
802:                    dispatcher.fireProjectTreeFilterDialogOKActivated(m_Dialog,
803:                            payLoad);
804:
805:                    hide();
806:                    dispose();
807:                }
808:            }
809:
810:            /**
811:             * The action that performs the cancel button action.  The users changes will
812:             * be discarded.
813:             */
814:            public class CancelAction extends AbstractAction {
815:                public CancelAction() {
816:                    super (ProjectTreeResources
817:                            .getString("JFilterDialog.Cancel_Btn_Title")); //$NON-NLS-1$
818:                }
819:
820:                /**
821:                 * Saves the users changes and closes the window.
822:                 *
823:                 * @param e The event data.
824:                 */
825:                public void actionPerformed(ActionEvent e) {
826:                    hide();
827:                    dispose();
828:                }
829:            }
830:
831:            /**
832:             * Retrieves the project tree model that will be filtered.
833:             * @return The model that will be affectd.
834:             */
835:            public IProjectTreeModel getProjectTreeModel() {
836:                return m_ProjectTreeModel;
837:            }
838:
839:            /**
840:             * Sest the project tree model that will be filted.
841:             * @param model The model that will be affected.
842:             */
843:            protected void setProjectTreeModel(IProjectTreeModel model) {
844:                m_ProjectTreeModel = model;
845:            }
846:
847:            public static void main(String[] args) {
848:                final JFilterDialog dialog = new JFilterDialog(null);
849:
850:                dialog.addWindowListener(new WindowAdapter() {
851:                    public void windowClosed(WindowEvent e) {
852:                        System.exit(0);
853:                    }
854:
855:                    public void windowClosing(WindowEvent e) {
856:                        dialog.dispose();
857:                    }
858:                });
859:
860:                IFilterNode elementsItem = dialog
861:                        .createRootNode(ProjectTreeResources
862:                                .getString("JFilterDialog.Root_Node_Name")); //$NON-NLS-1$
863:                dialog.addFilterItem(elementsItem, new FilterItem(
864:                        ProjectTreeResources
865:                                .getString("JFilterDialog.Class_Node_Name"))); //$NON-NLS-1$
866:                dialog
867:                        .addFilterItem(
868:                                elementsItem,
869:                                new FilterItem(
870:                                        ProjectTreeResources
871:                                                .getString("JFilterDialog.Interface_Node_Name"))); //$NON-NLS-1$
872:                dialog
873:                        .addFilterItem(
874:                                elementsItem,
875:                                new FilterItem(
876:                                        ProjectTreeResources
877:                                                .getString("JFilterDialog.SourceFileArtifact_Node_Name"))); //$NON-NLS-1$
878:
879:                dialog.show();
880:                //System.exit(0);
881:            }
882:        }
w_w___w_.___j__a___v__a___2s.___c_o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.