1 /*******************************************************************************
2 * Copyright (c) 2010 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
;
15 import org
.eclipse
.jface
.dialogs
.Dialog
;
16 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
17 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphColorScheme
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.events
.MouseAdapter
;
20 import org
.eclipse
.swt
.events
.MouseEvent
;
21 import org
.eclipse
.swt
.events
.PaintEvent
;
22 import org
.eclipse
.swt
.events
.PaintListener
;
23 import org
.eclipse
.swt
.graphics
.Color
;
24 import org
.eclipse
.swt
.graphics
.GC
;
25 import org
.eclipse
.swt
.graphics
.Point
;
26 import org
.eclipse
.swt
.graphics
.Rectangle
;
27 import org
.eclipse
.swt
.layout
.GridData
;
28 import org
.eclipse
.swt
.layout
.GridLayout
;
29 import org
.eclipse
.swt
.widgets
.Canvas
;
30 import org
.eclipse
.swt
.widgets
.Composite
;
31 import org
.eclipse
.swt
.widgets
.Control
;
32 import org
.eclipse
.swt
.widgets
.Display
;
33 import org
.eclipse
.swt
.widgets
.Shell
;
35 public class TickColorDialog
extends Dialog
{
37 int selectedIndex
= 0;
38 Composite colorComposite
;
40 TimeGraphColorScheme traceColorScheme
= new TimeGraphColorScheme();
42 protected TickColorDialog(Shell shell
) {
44 setShellStyle(getShellStyle() | SWT
.MAX
);
48 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
51 protected Control
createDialogArea(Composite parent
) {
52 getShell().setText(Messages
.TickColorDialog_TickColorDialogTitle
);
53 //getShell().setMinimumSize(getShell().computeSize(500, 200));
54 Composite composite
= (Composite
) super.createDialogArea(parent
);
55 colorComposite
= new Composite(composite
, SWT
.NONE
);
56 colorComposite
.setLayout(new GridLayout(4, false));
58 for (int i
= 0; i
< 16; i
++) {
59 TickColorCanvas tickColorCanvas
= new TickColorCanvas(colorComposite
, SWT
.NONE
);
60 tickColorCanvas
.setColorIndex(i
);
66 public void setColorIndex(int colorIndex
) {
67 selectedIndex
= colorIndex
;
70 public int getColorIndex() {
74 private class TickColorCanvas
extends Canvas
{
77 public TickColorCanvas(Composite parent
, int style
) {
80 GridData gd
= new GridData(SWT
.CENTER
, SWT
.FILL
, true, false);
84 setBackground(traceColorScheme
.getBkColor(false, false, false));
86 addPaintListener(new PaintListener() {
88 public void paintControl(PaintEvent e
) {
89 e
.gc
.setForeground(traceColorScheme
.getColor(TimeGraphColorScheme
.MID_LINE
));
90 int midy
= e
.y
+ e
.height
/ 2;
91 e
.gc
.drawLine(e
.x
, midy
, e
.x
+ e
.width
, midy
);
92 int midx
= e
.x
+ e
.width
/ 2;
93 Rectangle rect
= new Rectangle(midx
- 10, e
.y
+ 3, 0, e
.height
- 6);
94 for (int i
= 1; i
<= 3; i
++) {
97 e
.gc
.setBackground(traceColorScheme
.getColor(colorIndex
));
98 e
.gc
.fillRectangle(rect
);
100 for (int i
= 3; i
> 0; i
--) {
103 e
.gc
.setBackground(traceColorScheme
.getColor(colorIndex
));
104 e
.gc
.fillRectangle(rect
);
106 if (selectedIndex
== colorIndex
) {
107 Color borderColor
= Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
);
108 Point p
= TickColorCanvas
.this.getSize();
109 rect
= new Rectangle(0, 0, p
.x
- 1, p
.y
- 1);
111 gc
.setForeground(borderColor
);
112 gc
.drawRectangle(rect
);
116 addMouseListener(new MouseAdapter() {
118 public void mouseUp(MouseEvent e
) {
119 selectedIndex
= colorIndex
;
120 colorComposite
.redraw(0, 0, colorComposite
.getBounds().width
, colorComposite
.getBounds().height
, true);
124 public void setColorIndex(int index
) {