Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 40604 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/internal/junit/ui/IJUnitPreferencesConstants.java (+9 lines)
Lines 38-41 Link Here
38
	 */				
38
	 */				
39
	public static final String PREF_INACTIVE_FILTERS_LIST = JUnitPlugin.PLUGIN_ID + ".inactive_filters"; //$NON-NLS-1$	
39
	public static final String PREF_INACTIVE_FILTERS_LIST = JUnitPlugin.PLUGIN_ID + ".inactive_filters"; //$NON-NLS-1$	
40
40
41
	/**
42
	 * OK color for the progress bar.
43
	 */	
44
	public static final String PREF_COLOR_OK= JUnitPlugin.PLUGIN_ID + ".ok_color"; //$NON-NLS-1$	
45
46
	/**
47
	 * Failure color for the progress bar.
48
	 */	
49
	public static final String PREF_COLOR_FAILURE= JUnitPlugin.PLUGIN_ID + ".failure_color"; //$NON-NLS-1$	
41
}
50
}
(-)src/org/eclipse/jdt/internal/junit/ui/JUnitMessages.properties (+2 lines)
Lines 167-169 Link Here
167
ExpandAllAction.tooltip=Expand All Nodes
167
ExpandAllAction.tooltip=Expand All Nodes
168
JUnitAddLibraryProposal.info=Add the JUnit library to the project\'s build class path
168
JUnitAddLibraryProposal.info=Add the JUnit library to the project\'s build class path
169
JUnitAddLibraryProposal.label=Add JUnit libraries
169
JUnitAddLibraryProposal.label=Add JUnit libraries
170
JUnitPreferencePage.ok.color=OK &status color:
171
JUnitPreferencePage.failure.color=Fail&ure status color:
(-)src/org/eclipse/jdt/internal/junit/ui/JUnitPreferencePage.java (-1 / +58 lines)
Lines 21-26 Link Here
21
import org.eclipse.jdt.core.IType;
21
import org.eclipse.jdt.core.IType;
22
import org.eclipse.jdt.core.JavaModelException;
22
import org.eclipse.jdt.core.JavaModelException;
23
import org.eclipse.jdt.core.search.SearchEngine;
23
import org.eclipse.jdt.core.search.SearchEngine;
24
25
import org.eclipse.jdt.internal.junit.util.ColorEditor;
24
import org.eclipse.jdt.internal.junit.util.ExceptionHandler;
26
import org.eclipse.jdt.internal.junit.util.ExceptionHandler;
25
import org.eclipse.jdt.internal.junit.util.SWTUtil;
27
import org.eclipse.jdt.internal.junit.util.SWTUtil;
26
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
28
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
Lines 31-36 Link Here
31
import org.eclipse.jface.dialogs.IDialogConstants;
33
import org.eclipse.jface.dialogs.IDialogConstants;
32
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
34
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
33
import org.eclipse.jface.preference.IPreferenceStore;
35
import org.eclipse.jface.preference.IPreferenceStore;
36
import org.eclipse.jface.preference.PreferenceConverter;
34
import org.eclipse.jface.preference.PreferencePage;
37
import org.eclipse.jface.preference.PreferencePage;
35
import org.eclipse.jface.viewers.CheckStateChangedEvent;
38
import org.eclipse.jface.viewers.CheckStateChangedEvent;
36
import org.eclipse.jface.viewers.CheckboxTableViewer;
39
import org.eclipse.jface.viewers.CheckboxTableViewer;
Lines 55-66 Link Here
55
import org.eclipse.swt.events.KeyAdapter;
58
import org.eclipse.swt.events.KeyAdapter;
56
import org.eclipse.swt.events.KeyEvent;
59
import org.eclipse.swt.events.KeyEvent;
57
import org.eclipse.swt.graphics.Image;
60
import org.eclipse.swt.graphics.Image;
61
import org.eclipse.swt.graphics.RGB;
58
import org.eclipse.swt.layout.GridData;
62
import org.eclipse.swt.layout.GridData;
59
import org.eclipse.swt.layout.GridLayout;
63
import org.eclipse.swt.layout.GridLayout;
60
import org.eclipse.swt.widgets.Button;
64
import org.eclipse.swt.widgets.Button;
61
import org.eclipse.swt.widgets.Composite;
65
import org.eclipse.swt.widgets.Composite;
62
import org.eclipse.swt.widgets.Control;
66
import org.eclipse.swt.widgets.Control;
63
import org.eclipse.swt.widgets.Event;
67
import org.eclipse.swt.widgets.Event;
68
import org.eclipse.swt.widgets.Group;
64
import org.eclipse.swt.widgets.Label;
69
import org.eclipse.swt.widgets.Label;
65
import org.eclipse.swt.widgets.Listener;
70
import org.eclipse.swt.widgets.Listener;
66
import org.eclipse.swt.widgets.Shell;
71
import org.eclipse.swt.widgets.Shell;
Lines 93-98 Link Here
93
		"junit.framework.Assert", //$NON-NLS-1$
98
		"junit.framework.Assert", //$NON-NLS-1$
94
		"java.lang.reflect.Method.invoke" //$NON-NLS-1$
99
		"java.lang.reflect.Method.invoke" //$NON-NLS-1$
95
	};
100
	};
101
	
102
	private static final RGB DEFAULT_OK_COLOR= new RGB(63, 127, 63);
103
	private static final RGB DEFAULT_FAILURE_COLOR= new RGB(223, 63, 63);
96
104
97
	// Step filter widgets
105
	// Step filter widgets
98
	private CheckboxTableViewer fFilterViewer;
106
	private CheckboxTableViewer fFilterViewer;
Lines 115-120 Link Here
115
	private Label fTableLabel;
123
	private Label fTableLabel;
116
124
117
	private StackFilterContentProvider fStackFilterContentProvider;
125
	private StackFilterContentProvider fStackFilterContentProvider;
126
	private ColorEditor fOkColorButton;
127
	private ColorEditor fFailureColorButton;
118
128
119
	/**
129
	/**
120
	 * Model object that represents a single entry in the filter table.
130
	 * Model object that represents a single entry in the filter table.
Lines 329-340 Link Here
329
		data.verticalAlignment= GridData.FILL;
339
		data.verticalAlignment= GridData.FILL;
330
		data.horizontalAlignment= GridData.FILL;
340
		data.horizontalAlignment= GridData.FILL;
331
		composite.setLayoutData(data);
341
		composite.setLayoutData(data);
332
342
		
343
		createColorPickers(composite);
333
		createStackFilterPreferences(composite);
344
		createStackFilterPreferences(composite);
334
		Dialog.applyDialogFont(composite);
345
		Dialog.applyDialogFont(composite);
335
		return composite;
346
		return composite;
336
	}
347
	}
337
348
349
	private void createColorPickers(Composite composite) {
350
		Composite colorPickerComposite= new Composite(composite, SWT.NONE);
351
		colorPickerComposite.setLayoutData(new GridData());
352
		GridLayout gl= new GridLayout();
353
		gl.numColumns= 2;
354
		gl.marginHeight= 0;
355
		gl.marginWidth= 0;
356
		colorPickerComposite.setLayout(gl);
357
		
358
		Label okLabel= new Label(colorPickerComposite, SWT.NONE);
359
		okLabel.setText(JUnitMessages.getString("JUnitPreferencePage.ok.color")); //$NON-NLS-1$
360
		okLabel.setLayoutData(new GridData());
361
		
362
		fOkColorButton= new ColorEditor(colorPickerComposite);
363
		fOkColorButton.setColorValue(getOKColor());
364
		fOkColorButton.getButton().setLayoutData(new GridData());
365
		
366
		Label failureLabel= new Label(colorPickerComposite, SWT.NONE);
367
		failureLabel.setText(JUnitMessages.getString("JUnitPreferencePage.failure.color")); //$NON-NLS-1$
368
		failureLabel.setLayoutData(new GridData());
369
		
370
		fFailureColorButton= new ColorEditor(colorPickerComposite);
371
		fFailureColorButton.setColorValue(getFailureColor());
372
		fFailureColorButton.getButton().setLayoutData(new GridData());
373
	}
374
338
	/**
375
	/**
339
	 * Create a group to contain the step filter related widgetry
376
	 * Create a group to contain the step filter related widgetry
340
	 */
377
	 */
Lines 732-737 Link Here
732
		IPreferenceStore store= getPreferenceStore();
769
		IPreferenceStore store= getPreferenceStore();
733
		store.setValue(IJUnitPreferencesConstants.SHOW_ON_ERROR_ONLY, fShowOnErrorCheck.getSelection());
770
		store.setValue(IJUnitPreferencesConstants.SHOW_ON_ERROR_ONLY, fShowOnErrorCheck.getSelection());
734
		fStackFilterContentProvider.saveFilters();
771
		fStackFilterContentProvider.saveFilters();
772
		PreferenceConverter.setValue(store, IJUnitPreferencesConstants.PREF_COLOR_OK, fOkColorButton.getColorValue());
773
		PreferenceConverter.setValue(store, IJUnitPreferencesConstants.PREF_COLOR_FAILURE, fFailureColorButton.getColorValue());
735
		return true;
774
		return true;
736
	}
775
	}
737
776
Lines 742-747 Link Here
742
781
743
	private void setDefaultValues() {
782
	private void setDefaultValues() {
744
		fStackFilterContentProvider.setDefaults();
783
		fStackFilterContentProvider.setDefaults();
784
		fOkColorButton.setColorValue(DEFAULT_OK_COLOR);
785
		fFailureColorButton.setColorValue(DEFAULT_FAILURE_COLOR);
745
	}
786
	}
746
787
747
	/**
788
	/**
Lines 814-819 Link Here
814
	public static boolean getShowOnErrorOnly() {
855
	public static boolean getShowOnErrorOnly() {
815
		IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore();
856
		IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore();
816
		return store.getBoolean(IJUnitPreferencesConstants.SHOW_ON_ERROR_ONLY);
857
		return store.getBoolean(IJUnitPreferencesConstants.SHOW_ON_ERROR_ONLY);
858
	}
859
860
	public static RGB getOKColor() {
861
		IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore();
862
		RGB color= PreferenceConverter.getColor(store, IJUnitPreferencesConstants.PREF_COLOR_OK);
863
		if (color.equals(PreferenceConverter.COLOR_DEFAULT_DEFAULT))
864
			return DEFAULT_OK_COLOR;
865
		return color;
866
	}
867
868
	public static RGB getFailureColor() {
869
		IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore();
870
		RGB color= PreferenceConverter.getColor(store, IJUnitPreferencesConstants.PREF_COLOR_FAILURE);
871
		if (color.equals(PreferenceConverter.COLOR_DEFAULT_DEFAULT))
872
			return DEFAULT_FAILURE_COLOR;
873
		return color;
817
	}
874
	}
818
	
875
	
819
	/**
876
	/**
(-)src/org/eclipse/jdt/internal/junit/ui/JUnitProgressBar.java (-3 / +44 lines)
Lines 18-28 Link Here
18
import org.eclipse.swt.graphics.Color;
18
import org.eclipse.swt.graphics.Color;
19
import org.eclipse.swt.graphics.GC;
19
import org.eclipse.swt.graphics.GC;
20
import org.eclipse.swt.graphics.Point;
20
import org.eclipse.swt.graphics.Point;
21
import org.eclipse.swt.graphics.RGB;
21
import org.eclipse.swt.graphics.Rectangle;
22
import org.eclipse.swt.graphics.Rectangle;
22
import org.eclipse.swt.widgets.Canvas;
23
import org.eclipse.swt.widgets.Canvas;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Display;
25
import org.eclipse.swt.widgets.Display;
25
26
27
import org.eclipse.jface.util.IPropertyChangeListener;
28
import org.eclipse.jface.util.PropertyChangeEvent;
29
26
/**
30
/**
27
 * A progress bar with a red/green indication for success or failure.
31
 * A progress bar with a red/green indication for success or failure.
28
 */
32
 */
Lines 36-41 Link Here
36
	private Color fOKColor;
40
	private Color fOKColor;
37
	private Color fFailureColor;
41
	private Color fFailureColor;
38
	private boolean fError;
42
	private boolean fError;
43
	private IPropertyChangeListener fPropertyChangeListener;
39
	
44
	
40
	public JUnitProgressBar(Composite parent) {
45
	public JUnitProgressBar(Composite parent) {
41
		super(parent, SWT.NONE);
46
		super(parent, SWT.NONE);
Lines 51-59 Link Here
51
				paint(e);
56
				paint(e);
52
			}
57
			}
53
		});
58
		});
54
		Display display= parent.getDisplay();
59
		fPropertyChangeListener= createPropertyChangeListener();
55
		fFailureColor= new Color(display, 223, 63, 63);
60
		JUnitPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPropertyChangeListener);
56
		fOKColor= new Color(display, 63, 127, 63);
61
		resetColors();
62
	}
63
64
	private IPropertyChangeListener createPropertyChangeListener() {
65
		return new IPropertyChangeListener() {
66
			public void propertyChange(PropertyChangeEvent event) {
67
				JUnitProgressBar.this.handlePropertyChange(event);
68
			}
69
		};
70
	}
71
72
	private void handlePropertyChange(PropertyChangeEvent event) {
73
		if (event.getProperty().equals(IJUnitPreferencesConstants.PREF_COLOR_FAILURE) || event.getProperty().equals(IJUnitPreferencesConstants.PREF_COLOR_OK)) {
74
			resetColors();
75
		}
76
	}
77
78
	private void resetColors() {
79
		if (isDisposed())
80
			return;
81
		resetOKColorFromPreferences();
82
		resetFailureColorFromPreferences();
83
		refresh(fError);
84
	}
85
86
	private void resetOKColorFromPreferences() {
87
		if (fOKColor != null && !fOKColor.isDisposed())
88
			fOKColor.dispose();
89
		fOKColor= new Color(getDisplay(), JUnitPreferencePage.getOKColor());
90
	}
91
	
92
	private void resetFailureColorFromPreferences() {
93
		if (fFailureColor != null && !fFailureColor.isDisposed())
94
			fFailureColor.dispose();
95
		fFailureColor= new Color(getDisplay(), JUnitPreferencePage.getFailureColor());
57
	}
96
	}
58
97
59
	public void setMaximum(int max) {
98
	public void setMaximum(int max) {
Lines 66-71 Link Here
66
		fColorBarWidth= 0;
105
		fColorBarWidth= 0;
67
		fMaxTickCount= 0;
106
		fMaxTickCount= 0;
68
		redraw();
107
		redraw();
108
		resetColors();
69
	}
109
	}
70
	
110
	
71
	private void paintStep(int startX, int endX) {
111
	private void paintStep(int startX, int endX) {
Lines 81-86 Link Here
81
		super.dispose();
121
		super.dispose();
82
		fFailureColor.dispose();
122
		fFailureColor.dispose();
83
		fOKColor.dispose();
123
		fOKColor.dispose();
124
		JUnitPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
84
	}
125
	}
85
	
126
	
86
	private void setStatusColor(GC gc) {
127
	private void setStatusColor(GC gc) {
(-)src/org/eclipse/jdt/internal/junit/util/ColorEditor.java (+123 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.junit.util;
12
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.events.DisposeEvent;
15
import org.eclipse.swt.events.DisposeListener;
16
import org.eclipse.swt.events.SelectionAdapter;
17
import org.eclipse.swt.events.SelectionEvent;
18
import org.eclipse.swt.graphics.Color;
19
import org.eclipse.swt.graphics.Font;
20
import org.eclipse.swt.graphics.GC;
21
import org.eclipse.swt.graphics.Image;
22
import org.eclipse.swt.graphics.Point;
23
import org.eclipse.swt.graphics.RGB;
24
import org.eclipse.swt.widgets.Button;
25
import org.eclipse.swt.widgets.ColorDialog;
26
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Control;
28
import org.eclipse.swt.widgets.Display;
29
30
import org.eclipse.jface.resource.JFaceResources;
31
32
/**
33
 * A "button" of a certain color determined by the color picker.
34
 * (copied from jdt ui)
35
 */
36
public class ColorEditor {
37
	
38
	private Point fExtent;
39
	private Image fImage;
40
	private RGB fColorValue;
41
	private Color fColor;
42
	private Button fButton;
43
	
44
	public ColorEditor(Composite parent) {
45
		
46
		fButton= new Button(parent, SWT.PUSH);
47
		fExtent= computeImageSize(parent);
48
		fImage= new Image(parent.getDisplay(), fExtent.x, fExtent.y);
49
		
50
		GC gc= new GC(fImage);
51
		gc.setBackground(fButton.getBackground());
52
		gc.fillRectangle(0, 0, fExtent.x, fExtent.y);
53
		gc.dispose();
54
		
55
		fButton.setImage(fImage);
56
		fButton.addSelectionListener(new SelectionAdapter() {
57
			public void widgetSelected(SelectionEvent event) {
58
				ColorDialog colorDialog= new ColorDialog(fButton.getShell());
59
				colorDialog.setRGB(fColorValue);
60
				RGB newColor = colorDialog.open();
61
				if (newColor != null) {
62
					fColorValue= newColor;
63
					updateColorImage();
64
				}
65
			}
66
		});
67
		
68
		fButton.addDisposeListener(new DisposeListener() {
69
			public void widgetDisposed(DisposeEvent event) {
70
				if (fImage != null)  {
71
					fImage.dispose();
72
					fImage= null;
73
				}
74
				if (fColor != null) {
75
					fColor.dispose();
76
					fColor= null;
77
				}
78
			}
79
		});
80
	}
81
	
82
	public RGB getColorValue() {
83
		return fColorValue;
84
	}
85
	
86
	public void setColorValue(RGB rgb) {
87
		fColorValue= rgb;
88
		updateColorImage();
89
	}
90
	
91
	public Button getButton() {
92
		return fButton;
93
	}
94
	
95
	protected void updateColorImage() {
96
		
97
		Display display= fButton.getDisplay();
98
		
99
		GC gc= new GC(fImage);
100
		gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
101
		gc.drawRectangle(0, 2, fExtent.x - 1, fExtent.y - 4);
102
		
103
		if (fColor != null)
104
			fColor.dispose();
105
			
106
		fColor= new Color(display, fColorValue);
107
		gc.setBackground(fColor);
108
		gc.fillRectangle(1, 3, fExtent.x - 2, fExtent.y - 5);
109
		gc.dispose();
110
		
111
		fButton.setImage(fImage);
112
	}
113
	
114
	protected Point computeImageSize(Control window) {
115
		GC gc= new GC(window);
116
		Font f= JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT);
117
		gc.setFont(f);
118
		int height= gc.getFontMetrics().getHeight();
119
		gc.dispose();
120
		Point p= new Point(height * 3 - 6, height);
121
		return p;
122
	}
123
}

Return to bug 40604