Bug 378401: Implementation of time graph widget.
[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 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;
34
35 public class TickColorDialog extends Dialog {
36
37 int selectedIndex = 0;
38 Composite colorComposite;
39
40 TimeGraphColorScheme traceColorScheme = new TimeGraphColorScheme();
41
42 protected TickColorDialog(Shell shell) {
43 super(shell);
44 setShellStyle(getShellStyle() | SWT.MAX);
45 }
46
47 /* (non-Javadoc)
48 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
49 */
50 @Override
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));
57
58 for (int i = 0; i < 16; i++) {
59 TickColorCanvas tickColorCanvas = new TickColorCanvas(colorComposite, SWT.NONE);
60 tickColorCanvas.setColorIndex(i);
61 }
62
63 return composite;
64 }
65
66 public void setColorIndex(int colorIndex) {
67 selectedIndex = colorIndex;
68 }
69
70 public int getColorIndex() {
71 return selectedIndex;
72 }
73
74 private class TickColorCanvas extends Canvas {
75 int colorIndex;
76
77 public TickColorCanvas(Composite parent, int style) {
78 super(parent, style);
79
80 GridData gd = new GridData(SWT.CENTER, SWT.FILL, true, false);
81 gd.widthHint = 40;
82 gd.heightHint = 25;
83 setLayoutData(gd);
84 setBackground(traceColorScheme.getBkColor(false, false, false));
85
86 addPaintListener(new PaintListener() {
87 @Override
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++) {
95 rect.x += i;
96 rect.width = i;
97 e.gc.setBackground(traceColorScheme.getColor(colorIndex));
98 e.gc.fillRectangle(rect);
99 }
100 for (int i = 3; i > 0; i--) {
101 rect.x += i + 2;
102 rect.width = i;
103 e.gc.setBackground(traceColorScheme.getColor(colorIndex));
104 e.gc.fillRectangle(rect);
105 }
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);
110 GC gc = e.gc;
111 gc.setForeground(borderColor);
112 gc.drawRectangle(rect);
113 }
114 }});
115
116 addMouseListener(new MouseAdapter() {
117 @Override
118 public void mouseUp(MouseEvent e) {
119 selectedIndex = colorIndex;
120 colorComposite.redraw(0, 0, colorComposite.getBounds().width, colorComposite.getBounds().height, true);
121 }});
122 }
123
124 public void setColorIndex(int index) {
125 colorIndex = index;
126 }
127 }
128
129
130 }
This page took 0.036447 seconds and 6 git commands to generate.