1 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 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"); private final Image fFailureIcon= TestRunnerViewPart.createImage("ovr16/failed_ovr.gif"); 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 "); fNumberOfErrors= createLabel(JUnitMessages.CounterPanel_label_errors, fErrorIcon, " 0 "); fNumberOfFailures= createLabel(JUnitMessages.CounterPanel_label_failures, fFailureIcon, " 0 "); 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 name, Image image, String 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 76 Text value= new Text(this, SWT.READ_ONLY); 77 value.setText(init); 78 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 runString; 101 if (ignoredCount == 0) 102 runString= Messages.format(JUnitMessages.CounterPanel_runcount, new String [] { Integer.toString(value), Integer.toString(fTotal) }); 103 else 104 runString= Messages.format(JUnitMessages.CounterPanel_runcount_ignored, new String [] { 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 |