Move legacy time analysis widget to lttng.ui and create initial copy in
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / colors / TickColorDialog.java
1 /*******************************************************************************
2 * Copyright (c) 2010 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.views.colors;
14
15 import java.util.Map;
16
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;
39
40 public class TickColorDialog extends Dialog {
41
42 int selectedIndex = 0;
43 Composite colorComposite;
44
45 TraceColorScheme traceColorScheme = new TraceColorScheme();
46 private TmfTimeAnalysisProvider timeAnalysisProvider = new TmfTimeAnalysisProvider() {
47 @Override
48 public StateColor getEventColor(ITimeEvent event) {
49 return null;
50 }
51 @Override
52 public String getTraceClassName(ITmfTimeAnalysisEntry trace) {
53 return null;
54 }
55 @Override
56 public String getEventName(ITimeEvent event, boolean upper, boolean extInfo) {
57 return null;
58 }
59 @Override
60 public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event) {
61 return null;
62 }
63 @Override
64 public String getStateName(StateColor color) {
65 return null;
66 }};
67
68 protected TickColorDialog(Shell shell) {
69 super(shell);
70 setShellStyle(getShellStyle() | SWT.MAX);
71 }
72
73 /* (non-Javadoc)
74 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
75 */
76 @Override
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));
83
84 for (int i = 0; i < 16; i++) {
85 TickColorCanvas tickColorCanvas = new TickColorCanvas(colorComposite, SWT.NONE);
86 tickColorCanvas.setColorIndex(i);
87 }
88
89 return composite;
90 }
91
92 public void setColorIndex(int colorIndex) {
93 selectedIndex = colorIndex;
94 }
95
96 public int getColorIndex() {
97 return selectedIndex;
98 }
99
100 private class TickColorCanvas extends Canvas {
101 int colorIndex;
102
103 public TickColorCanvas(Composite parent, int style) {
104 super(parent, style);
105
106 GridData gd = new GridData(SWT.CENTER, SWT.FILL, true, false);
107 gd.widthHint = 40;
108 gd.heightHint = 25;
109 setLayoutData(gd);
110 setBackground(traceColorScheme.getBkColor(false, false, false));
111
112 addPaintListener(new PaintListener() {
113 @Override
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++) {
121 rect.x += i;
122 rect.width = i;
123 timeAnalysisProvider.drawState(traceColorScheme, colorIndex, rect, e.gc, false, false, false);
124 }
125 for (int i = 3; i > 0; i--) {
126 rect.x += i + 2;
127 rect.width = i;
128 timeAnalysisProvider.drawState(traceColorScheme, colorIndex, rect, e.gc, false, false, false);
129 }
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);
134 GC gc = e.gc;
135 gc.setForeground(borderColor);
136 gc.drawRectangle(rect);
137 }
138 }});
139
140 addMouseListener(new MouseAdapter() {
141 @Override
142 public void mouseUp(MouseEvent e) {
143 selectedIndex = colorIndex;
144 colorComposite.redraw(0, 0, colorComposite.getBounds().width, colorComposite.getBounds().height, true);
145 }});
146 }
147
148 public void setColorIndex(int index) {
149 colorIndex = index;
150 }
151 }
152
153
154 }
This page took 0.033068 seconds and 5 git commands to generate.