KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > junit > ui > CounterPanel


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.junit.ui;
12
13
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.events.DisposeEvent;
16 import org.eclipse.swt.events.DisposeListener;
17 import org.eclipse.swt.graphics.Image;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.swt.widgets.Text;
23
24 import org.eclipse.jdt.internal.junit.Messages;
25
26 /**
27  * A panel with counters for the number of Runs, Errors and Failures.
28  */

29 public class CounterPanel extends Composite {
30     protected Text fNumberOfErrors;
31     protected Text fNumberOfFailures;
32     protected Text fNumberOfRuns;
33     protected int fTotal;
34     protected int fIgnoredCount;
35     
36     private final Image fErrorIcon= TestRunnerViewPart.createImage("ovr16/error_ovr.gif"); //$NON-NLS-1$
37
private final Image fFailureIcon= TestRunnerViewPart.createImage("ovr16/failed_ovr.gif"); //$NON-NLS-1$
38

39     public CounterPanel(Composite parent) {
40         super(parent, SWT.WRAP);
41         GridLayout gridLayout= new GridLayout();
42         gridLayout.numColumns= 9;
43         gridLayout.makeColumnsEqualWidth= false;
44         gridLayout.marginWidth= 0;
45         setLayout(gridLayout);
46         
47         fNumberOfRuns= createLabel(JUnitMessages.CounterPanel_label_runs, null, " 0/0 "); //$NON-NLS-1$
48
fNumberOfErrors= createLabel(JUnitMessages.CounterPanel_label_errors, fErrorIcon, " 0 "); //$NON-NLS-1$
49
fNumberOfFailures= createLabel(JUnitMessages.CounterPanel_label_failures, fFailureIcon, " 0 "); //$NON-NLS-1$
50

51         addDisposeListener(new DisposeListener() {
52             public void widgetDisposed(DisposeEvent e) {
53                 disposeIcons();
54             }
55         });
56     }
57  
58     private void disposeIcons() {
59         fErrorIcon.dispose();
60         fFailureIcon.dispose();
61     }
62
63     private Text createLabel(String JavaDoc name, Image image, String JavaDoc init) {
64         Label label= new Label(this, SWT.NONE);
65         if (image != null) {
66             image.setBackground(label.getBackground());
67             label.setImage(image);
68         }
69         label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
70         
71         label= new Label(this, SWT.NONE);
72         label.setText(name);
73         label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
74         //label.setFont(JFaceResources.getBannerFont());
75

76         Text value= new Text(this, SWT.READ_ONLY);
77         value.setText(init);
78         // bug: 39661 Junit test counters do not repaint correctly [JUnit]
79
value.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
80         value.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING));
81         return value;
82     }
83
84     public void reset() {
85         setErrorValue(0);
86         setFailureValue(0);
87         setRunValue(0, 0);
88         fTotal= 0;
89     }
90     
91     public void setTotal(int value) {
92         fTotal= value;
93     }
94     
95     public int getTotal(){
96         return fTotal;
97     }
98     
99     public void setRunValue(int value, int ignoredCount) {
100         String JavaDoc runString;
101         if (ignoredCount == 0)
102             runString= Messages.format(JUnitMessages.CounterPanel_runcount, new String JavaDoc[] { Integer.toString(value), Integer.toString(fTotal) });
103         else
104             runString= Messages.format(JUnitMessages.CounterPanel_runcount_ignored, new String JavaDoc[] { Integer.toString(value), Integer.toString(fTotal), Integer.toString(ignoredCount) });
105         fNumberOfRuns.setText(runString);
106
107         if (fIgnoredCount == 0 && ignoredCount > 0 || fIgnoredCount != 0 && ignoredCount == 0) {
108             layout();
109         } else {
110             fNumberOfRuns.redraw();
111             redraw();
112         }
113         fIgnoredCount= ignoredCount;
114     }
115     
116     public void setErrorValue(int value) {
117         fNumberOfErrors.setText(Integer.toString(value));
118         redraw();
119     }
120     
121     public void setFailureValue(int value) {
122         fNumberOfFailures.setText(Integer.toString(value));
123         redraw();
124     }
125 }
126
Popular Tags