KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > junit > output > StatisticsPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.junit.output;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.event.ItemEvent JavaDoc;
24 import java.awt.event.ItemListener JavaDoc;
25 import java.util.List JavaDoc;
26 import javax.swing.Box JavaDoc;
27 import javax.swing.BoxLayout JavaDoc;
28 import javax.swing.ImageIcon JavaDoc;
29 import javax.swing.JComponent JavaDoc;
30 import javax.swing.JPanel JavaDoc;
31 import javax.swing.JToggleButton JavaDoc;
32 import javax.swing.JToolBar JavaDoc;
33 import javax.swing.SwingConstants JavaDoc;
34 import org.openide.util.NbBundle;
35 import org.openide.util.Utilities;
36
37 /**
38  * Panel containing the toolbar and the tree of test results.
39  *
40  * @author Marian Petras
41  */

42 public final class StatisticsPanel extends JPanel JavaDoc implements ItemListener JavaDoc {
43     
44     /** */
45     private final ResultPanelTree treePanel;
46     /** */
47     private JToggleButton JavaDoc btnFilter;
48     /** */
49     private String JavaDoc tooltipShowAll;
50     /** */
51     private String JavaDoc tooltipShowFailures;
52
53     /**
54      */

55     public StatisticsPanel(final ResultDisplayHandler displayHandler) {
56         super(new BorderLayout JavaDoc(0, 0));
57
58         JComponent JavaDoc toolbar = createToolbar();
59         treePanel = new ResultPanelTree(displayHandler);
60         treePanel.setFiltered(btnFilter.isSelected());
61
62         add(toolbar, BorderLayout.WEST);
63         add(treePanel, BorderLayout.CENTER);
64     }
65
66     /**
67      */

68     private JComponent JavaDoc createToolbar() {
69         createFilterButton();
70
71         JToolBar JavaDoc toolbar = new JToolBar JavaDoc(SwingConstants.VERTICAL);
72         toolbar.setLayout(new BoxLayout JavaDoc(toolbar, BoxLayout.Y_AXIS));
73         toolbar.add(btnFilter);
74         toolbar.add(Box.createHorizontalGlue());
75         
76         toolbar.setFocusable(false);
77         toolbar.setFloatable(false);
78         toolbar.setBorderPainted(false);
79         
80         return toolbar;
81     }
82     
83     /**
84      */

85     private void createFilterButton() {
86         btnFilter = new JToggleButton JavaDoc(new ImageIcon JavaDoc(
87                 Utilities.loadImage(
88                     "org/netbeans/modules/junit/output/res/filter.png", //NOI18N
89
true)));
90         btnFilter.getAccessibleContext().setAccessibleName(
91                 NbBundle.getMessage(getClass(), "ACSN_FilterButton")); //NOI18N
92
btnFilter.addItemListener(this);
93         
94         updateFilterButtonLabel();
95     }
96     
97     /**
98      */

99     private void updateFilterButtonLabel() {
100         if (tooltipShowAll == null) {
101             tooltipShowAll = NbBundle.getMessage(
102                     getClass(),
103                     "MultiviewPanel.btnFilter.showAll.tooltip"); //NOI18N
104
tooltipShowFailures = NbBundle.getMessage(
105                     getClass(),
106                     "MultiviewPanel.btnFilter.showFailures.tooltip"); //NOI18N
107
}
108         btnFilter.setToolTipText(btnFilter.isSelected() ? tooltipShowAll
109                                                         : tooltipShowFailures);
110     }
111     
112     /**
113      */

114     public void itemStateChanged(ItemEvent JavaDoc e) {
115         /* called when the Filter button is toggled. */
116         treePanel.setFiltered(btnFilter.isSelected());
117         updateFilterButtonLabel();
118     }
119     
120     /**
121      */

122     void displayReport(final Report report) {
123         treePanel.displayReport(report);
124         
125         btnFilter.setEnabled(
126             treePanel.getSuccessDisplayedLevel() != RootNode.ALL_PASSED_ABSENT);
127     }
128     
129     /**
130      */

131     void displayReports(final List JavaDoc<Report> reports) {
132         if (reports.isEmpty()) {
133             return;
134         }
135         
136         treePanel.displayReports(reports);
137         
138         btnFilter.setEnabled(
139             treePanel.getSuccessDisplayedLevel() != RootNode.ALL_PASSED_ABSENT);
140     }
141     
142     /**
143      * Displays a message about a running suite.
144      *
145      * @param suiteName name of the running suite,
146      * or {@code ANONYMOUS_SUITE} for anonymous suites
147      * @see ResultDisplayHandler#ANONYMOUS_SUITE
148      */

149     void displaySuiteRunning(final String JavaDoc suiteName) {
150         treePanel.displaySuiteRunning(suiteName);
151     }
152     
153     /**
154      */

155     void displayMsg(final String JavaDoc msg) {
156         treePanel.displayMsg(msg);
157     }
158     
159 }
160
Popular Tags