Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2004, 2007 Mylyn project committers 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 |
|
9 |
package org.eclipse.mylyn.internal.tasks.ui.wizards; |
10 |
|
11 |
import org.eclipse.jface.layout.GridDataFactory; |
12 |
import org.eclipse.jface.layout.GridLayoutFactory; |
13 |
import org.eclipse.jface.window.Window; |
14 |
import org.eclipse.swt.SWT; |
15 |
import org.eclipse.swt.events.MouseAdapter; |
16 |
import org.eclipse.swt.events.MouseEvent; |
17 |
import org.eclipse.swt.events.SelectionAdapter; |
18 |
import org.eclipse.swt.events.SelectionEvent; |
19 |
import org.eclipse.swt.events.ShellAdapter; |
20 |
import org.eclipse.swt.events.ShellEvent; |
21 |
import org.eclipse.swt.graphics.RGB; |
22 |
import org.eclipse.swt.widgets.Button; |
23 |
import org.eclipse.swt.widgets.Composite; |
24 |
import org.eclipse.swt.widgets.Control; |
25 |
import org.eclipse.swt.widgets.Shell; |
26 |
|
27 |
/** |
28 |
* Popup window for color selection |
29 |
* |
30 |
* @author Willian Mitsuda |
31 |
*/ |
32 |
public class ColorSelectionWindow extends Window { |
33 |
|
34 |
private ColorCanvas[] colors; |
35 |
|
36 |
public ColorSelectionWindow(Shell shell) { |
37 |
super(shell); |
38 |
setShellStyle(SWT.BORDER); |
39 |
} |
40 |
|
41 |
@Override |
42 |
protected void configureShell(Shell newShell) { |
43 |
super.configureShell(newShell); |
44 |
newShell.addShellListener(new ShellAdapter() { |
45 |
|
46 |
@Override |
47 |
public void shellDeactivated(ShellEvent e) { |
48 |
close(); |
49 |
} |
50 |
|
51 |
}); |
52 |
} |
53 |
|
54 |
@Override |
55 |
protected Control createContents(Composite parent) { |
56 |
Composite colorComposite = new Composite(parent, SWT.NONE); |
57 |
colorComposite.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK)); |
58 |
colorComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); |
59 |
colorComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(8).spacing(1, 1).margins(1, 1).equalWidth( |
60 |
true).create()); |
61 |
|
62 |
// EGA classic palette |
63 |
colors = new ColorCanvas[16]; |
64 |
colors[0] = createColorCanvas(colorComposite, new RGB(0, 0, 0)); |
65 |
colors[1] = createColorCanvas(colorComposite, new RGB(0, 0, 170)); |
66 |
colors[2] = createColorCanvas(colorComposite, new RGB(0, 170, 0)); |
67 |
colors[3] = createColorCanvas(colorComposite, new RGB(0, 170, 170)); |
68 |
colors[4] = createColorCanvas(colorComposite, new RGB(170, 0, 0)); |
69 |
colors[5] = createColorCanvas(colorComposite, new RGB(170, 0, 170)); |
70 |
colors[6] = createColorCanvas(colorComposite, new RGB(170, 85, 0)); |
71 |
colors[7] = createColorCanvas(colorComposite, new RGB(170, 170, 170)); |
72 |
colors[8] = createColorCanvas(colorComposite, new RGB(85, 85, 85)); |
73 |
colors[9] = createColorCanvas(colorComposite, new RGB(85, 85, 255)); |
74 |
colors[10] = createColorCanvas(colorComposite, new RGB(85, 255, 85)); |
75 |
colors[11] = createColorCanvas(colorComposite, new RGB(85, 255, 255)); |
76 |
colors[12] = createColorCanvas(colorComposite, new RGB(255, 85, 85)); |
77 |
colors[13] = createColorCanvas(colorComposite, new RGB(255, 85, 255)); |
78 |
colors[14] = createColorCanvas(colorComposite, new RGB(255, 255, 85)); |
79 |
colors[15] = createColorCanvas(colorComposite, new RGB(255, 255, 255)); |
80 |
|
81 |
Button closeButton = new Button(parent, SWT.PUSH); |
82 |
closeButton.setText("&Close"); |
83 |
closeButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); |
84 |
closeButton.addSelectionListener(new SelectionAdapter() { |
85 |
|
86 |
@Override |
87 |
public void widgetSelected(SelectionEvent e) { |
88 |
close(); |
89 |
} |
90 |
|
91 |
}); |
92 |
return parent; |
93 |
} |
94 |
|
95 |
private ColorCanvas createColorCanvas(Composite parent, RGB rgb) { |
96 |
final ColorCanvas canvas = new ColorCanvas(parent, SWT.NONE, rgb); |
97 |
canvas.setLayoutData(GridDataFactory.fillDefaults().hint(16, 16).create()); |
98 |
canvas.addMouseListener(new MouseAdapter() { |
99 |
|
100 |
@Override |
101 |
public void mouseDown(MouseEvent e) { |
102 |
selectedRGB = canvas.getRGB(); |
103 |
close(); |
104 |
} |
105 |
|
106 |
}); |
107 |
return canvas; |
108 |
} |
109 |
|
110 |
private RGB selectedRGB; |
111 |
|
112 |
public RGB getSelectedRGB() { |
113 |
return selectedRGB; |
114 |
} |
115 |
|
116 |
} |