Commit | Line | Data |
---|---|---|
ca13a91c FC |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2010 Ericsson\r | |
3 | * \r | |
4 | * All rights reserved. This program and the accompanying materials are\r | |
5 | * made available under the terms of the Eclipse Public License v1.0 which\r | |
6 | * accompanies this distribution, and is available at\r | |
7 | * http://www.eclipse.org/legal/epl-v10.html\r | |
8 | * \r | |
9 | * Contributors:\r | |
10 | * Patrick Tasse - Initial API and implementation\r | |
11 | *******************************************************************************/\r | |
12 | \r | |
13 | package org.eclipse.linuxtools.tmf.ui.views.colors;\r | |
14 | \r | |
15 | import java.util.Map;\r | |
16 | \r | |
17 | import org.eclipse.jface.dialogs.Dialog;\r | |
18 | import org.eclipse.linuxtools.tmf.ui.internal.Messages;\r | |
19 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider;\r | |
20 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent;\r | |
21 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry;\r | |
22 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.TraceColorScheme;\r | |
23 | import org.eclipse.swt.SWT;\r | |
24 | import org.eclipse.swt.events.MouseAdapter;\r | |
25 | import org.eclipse.swt.events.MouseEvent;\r | |
26 | import org.eclipse.swt.events.PaintEvent;\r | |
27 | import org.eclipse.swt.events.PaintListener;\r | |
28 | import org.eclipse.swt.graphics.Color;\r | |
29 | import org.eclipse.swt.graphics.GC;\r | |
30 | import org.eclipse.swt.graphics.Point;\r | |
31 | import org.eclipse.swt.graphics.Rectangle;\r | |
32 | import org.eclipse.swt.layout.GridData;\r | |
33 | import org.eclipse.swt.layout.GridLayout;\r | |
34 | import org.eclipse.swt.widgets.Canvas;\r | |
35 | import org.eclipse.swt.widgets.Composite;\r | |
36 | import org.eclipse.swt.widgets.Control;\r | |
37 | import org.eclipse.swt.widgets.Display;\r | |
38 | import org.eclipse.swt.widgets.Shell;\r | |
39 | \r | |
40 | public class TickColorDialog extends Dialog {\r | |
41 | \r | |
42 | int selectedIndex = 0;\r | |
43 | Composite colorComposite;\r | |
44 | \r | |
45 | TraceColorScheme traceColorScheme = new TraceColorScheme();\r | |
46 | private TmfTimeAnalysisProvider timeAnalysisProvider = new TmfTimeAnalysisProvider() {\r | |
47 | @Override\r | |
48 | public StateColor getEventColor(ITimeEvent event) {\r | |
49 | return null;\r | |
50 | }\r | |
51 | @Override\r | |
52 | public String getTraceClassName(ITmfTimeAnalysisEntry trace) {\r | |
53 | return null;\r | |
54 | }\r | |
55 | @Override\r | |
56 | public String getEventName(ITimeEvent event, boolean upper, boolean extInfo) {\r | |
57 | return null;\r | |
58 | }\r | |
59 | @Override\r | |
60 | public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event) {\r | |
61 | return null;\r | |
62 | }\r | |
63 | @Override\r | |
64 | public String getStateName(StateColor color) {\r | |
65 | return null;\r | |
66 | }};\r | |
67 | \r | |
68 | protected TickColorDialog(Shell shell) {\r | |
69 | super(shell);\r | |
70 | setShellStyle(getShellStyle() | SWT.MAX);\r | |
71 | }\r | |
72 | \r | |
73 | /* (non-Javadoc)\r | |
74 | * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)\r | |
75 | */\r | |
76 | @Override\r | |
77 | protected Control createDialogArea(Composite parent) {\r | |
78 | getShell().setText(Messages.TickColorDialog_TickColorDialogTitle);\r | |
79 | //getShell().setMinimumSize(getShell().computeSize(500, 200));\r | |
80 | Composite composite = (Composite) super.createDialogArea(parent);\r | |
81 | colorComposite = new Composite(composite, SWT.NONE);\r | |
82 | colorComposite.setLayout(new GridLayout(4, false));\r | |
83 | \r | |
84 | for (int i = 0; i < 16; i++) {\r | |
85 | TickColorCanvas tickColorCanvas = new TickColorCanvas(colorComposite, SWT.NONE);\r | |
86 | tickColorCanvas.setColorIndex(i);\r | |
87 | }\r | |
88 | \r | |
89 | return composite;\r | |
90 | }\r | |
91 | \r | |
92 | public void setColorIndex(int colorIndex) {\r | |
93 | selectedIndex = colorIndex;\r | |
94 | }\r | |
95 | \r | |
96 | public int getColorIndex() {\r | |
97 | return selectedIndex;\r | |
98 | }\r | |
99 | \r | |
100 | private class TickColorCanvas extends Canvas {\r | |
101 | int colorIndex;\r | |
102 | \r | |
103 | public TickColorCanvas(Composite parent, int style) {\r | |
104 | super(parent, style);\r | |
105 | \r | |
106 | GridData gd = new GridData(SWT.CENTER, SWT.FILL, true, false);\r | |
107 | gd.widthHint = 40;\r | |
108 | gd.heightHint = 25;\r | |
109 | setLayoutData(gd);\r | |
110 | setBackground(traceColorScheme.getBkColor(false, false, false));\r | |
111 | \r | |
112 | addPaintListener(new PaintListener() {\r | |
113 | @Override\r | |
114 | public void paintControl(PaintEvent e) {\r | |
115 | e.gc.setForeground(traceColorScheme.getColor(TraceColorScheme.MID_LINE));\r | |
116 | int midy = e.y + e.height / 2;\r | |
117 | e.gc.drawLine(e.x, midy, e.x + e.width, midy);\r | |
118 | int midx = e.x + e.width / 2;\r | |
119 | Rectangle rect = new Rectangle(midx - 10, e.y + 3, 0, e.height - 6);\r | |
120 | for (int i = 1; i <= 3; i++) {\r | |
121 | rect.x += i;\r | |
122 | rect.width = i;\r | |
123 | timeAnalysisProvider.drawState(traceColorScheme, colorIndex, rect, e.gc, false, false, false);\r | |
124 | }\r | |
125 | for (int i = 3; i > 0; i--) {\r | |
126 | rect.x += i + 2;\r | |
127 | rect.width = i;\r | |
128 | timeAnalysisProvider.drawState(traceColorScheme, colorIndex, rect, e.gc, false, false, false);\r | |
129 | }\r | |
130 | if (selectedIndex == colorIndex) {\r | |
131 | Color borderColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);\r | |
132 | Point p = TickColorCanvas.this.getSize();\r | |
133 | rect = new Rectangle(0, 0, p.x - 1, p.y - 1);\r | |
134 | GC gc = e.gc;\r | |
135 | gc.setForeground(borderColor);\r | |
136 | gc.drawRectangle(rect);\r | |
137 | }\r | |
138 | }});\r | |
139 | \r | |
140 | addMouseListener(new MouseAdapter() {\r | |
141 | @Override\r | |
142 | public void mouseUp(MouseEvent e) {\r | |
143 | selectedIndex = colorIndex;\r | |
144 | colorComposite.redraw(0, 0, colorComposite.getBounds().width, colorComposite.getBounds().height, true);\r | |
145 | }});\r | |
146 | }\r | |
147 | \r | |
148 | public void setColorIndex(int index) {\r | |
149 | colorIndex = index;\r | |
150 | }\r | |
151 | }\r | |
152 | \r | |
153 | \r | |
154 | }\r |