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
;
17 import org
.eclipse
.jface
.dialogs
.Dialog
;
18 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
19 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TmfTimeAnalysisProvider
;
20 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITmfTimeAnalysisEntry
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TraceColorScheme
;
23 import org
.eclipse
.swt
.SWT
;
24 import org
.eclipse
.swt
.events
.MouseAdapter
;
25 import org
.eclipse
.swt
.events
.MouseEvent
;
26 import org
.eclipse
.swt
.events
.PaintEvent
;
27 import org
.eclipse
.swt
.events
.PaintListener
;
28 import org
.eclipse
.swt
.graphics
.Color
;
29 import org
.eclipse
.swt
.graphics
.GC
;
30 import org
.eclipse
.swt
.graphics
.Point
;
31 import org
.eclipse
.swt
.graphics
.Rectangle
;
32 import org
.eclipse
.swt
.layout
.GridData
;
33 import org
.eclipse
.swt
.layout
.GridLayout
;
34 import org
.eclipse
.swt
.widgets
.Canvas
;
35 import org
.eclipse
.swt
.widgets
.Composite
;
36 import org
.eclipse
.swt
.widgets
.Control
;
37 import org
.eclipse
.swt
.widgets
.Display
;
38 import org
.eclipse
.swt
.widgets
.Shell
;
40 public class TickColorDialog
extends Dialog
{
42 int selectedIndex
= 0;
43 Composite colorComposite
;
45 TraceColorScheme traceColorScheme
= new TraceColorScheme();
46 private TmfTimeAnalysisProvider timeAnalysisProvider
= new TmfTimeAnalysisProvider() {
48 public StateColor
getEventColor(ITimeEvent event
) {
52 public String
getTraceClassName(ITmfTimeAnalysisEntry trace
) {
56 public String
getEventName(ITimeEvent event
, boolean upper
, boolean extInfo
) {
60 public Map
<String
, String
> getEventHoverToolTipInfo(ITimeEvent event
) {
64 public String
getStateName(StateColor color
) {
68 protected TickColorDialog(Shell shell
) {
70 setShellStyle(getShellStyle() | SWT
.MAX
);
74 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
77 protected Control
createDialogArea(Composite parent
) {
78 getShell().setText(Messages
.TickColorDialog_TickColorDialogTitle
);
79 //getShell().setMinimumSize(getShell().computeSize(500, 200));
80 Composite composite
= (Composite
) super.createDialogArea(parent
);
81 colorComposite
= new Composite(composite
, SWT
.NONE
);
82 colorComposite
.setLayout(new GridLayout(4, false));
84 for (int i
= 0; i
< 16; i
++) {
85 TickColorCanvas tickColorCanvas
= new TickColorCanvas(colorComposite
, SWT
.NONE
);
86 tickColorCanvas
.setColorIndex(i
);
92 public void setColorIndex(int colorIndex
) {
93 selectedIndex
= colorIndex
;
96 public int getColorIndex() {
100 private class TickColorCanvas
extends Canvas
{
103 public TickColorCanvas(Composite parent
, int style
) {
104 super(parent
, style
);
106 GridData gd
= new GridData(SWT
.CENTER
, SWT
.FILL
, true, false);
110 setBackground(traceColorScheme
.getBkColor(false, false, false));
112 addPaintListener(new PaintListener() {
114 public void paintControl(PaintEvent e
) {
115 e
.gc
.setForeground(traceColorScheme
.getColor(TraceColorScheme
.MID_LINE
));
116 int midy
= e
.y
+ e
.height
/ 2;
117 e
.gc
.drawLine(e
.x
, midy
, e
.x
+ e
.width
, midy
);
118 int midx
= e
.x
+ e
.width
/ 2;
119 Rectangle rect
= new Rectangle(midx
- 10, e
.y
+ 3, 0, e
.height
- 6);
120 for (int i
= 1; i
<= 3; i
++) {
123 timeAnalysisProvider
.drawState(traceColorScheme
, colorIndex
, rect
, e
.gc
, false, false, false);
125 for (int i
= 3; i
> 0; i
--) {
128 timeAnalysisProvider
.drawState(traceColorScheme
, colorIndex
, rect
, e
.gc
, false, false, false);
130 if (selectedIndex
== colorIndex
) {
131 Color borderColor
= Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
);
132 Point p
= TickColorCanvas
.this.getSize();
133 rect
= new Rectangle(0, 0, p
.x
- 1, p
.y
- 1);
135 gc
.setForeground(borderColor
);
136 gc
.drawRectangle(rect
);
140 addMouseListener(new MouseAdapter() {
142 public void mouseUp(MouseEvent e
) {
143 selectedIndex
= colorIndex
;
144 colorComposite
.redraw(0, 0, colorComposite
.getBounds().width
, colorComposite
.getBounds().height
, true);
148 public void setColorIndex(int index
) {