Commit | Line | Data |
---|---|---|
be222f56 | 1 | /******************************************************************************* |
9b840a86 | 2 | * Copyright (c) 2010, 2015 Ericsson |
be222f56 PT |
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 | * Bernd Hufmann - Updated to use RGB for the tick color | |
12 | *******************************************************************************/ | |
13 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.tmf.ui.views.colors; |
be222f56 | 15 | |
9b840a86 PT |
16 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
17 | ||
be222f56 PT |
18 | import java.util.ArrayList; |
19 | import java.util.Arrays; | |
20 | import java.util.List; | |
21 | ||
dab5f596 | 22 | import org.eclipse.jdt.annotation.NonNull; |
be222f56 PT |
23 | import org.eclipse.jface.action.Action; |
24 | import org.eclipse.jface.action.IToolBarManager; | |
25 | import org.eclipse.jface.action.Separator; | |
26 | import org.eclipse.jface.dialogs.MessageDialog; | |
27 | import org.eclipse.jface.resource.ImageDescriptor; | |
28 | import org.eclipse.jface.window.Window; | |
be222f56 PT |
29 | import org.eclipse.swt.SWT; |
30 | import org.eclipse.swt.custom.ScrolledComposite; | |
31 | import org.eclipse.swt.events.MouseAdapter; | |
32 | import org.eclipse.swt.events.MouseEvent; | |
33 | import org.eclipse.swt.events.MouseListener; | |
34 | import org.eclipse.swt.events.PaintEvent; | |
35 | import org.eclipse.swt.events.PaintListener; | |
36 | import org.eclipse.swt.events.SelectionAdapter; | |
37 | import org.eclipse.swt.events.SelectionEvent; | |
38 | import org.eclipse.swt.graphics.Color; | |
39 | import org.eclipse.swt.graphics.GC; | |
40 | import org.eclipse.swt.graphics.Image; | |
41 | import org.eclipse.swt.graphics.Point; | |
1a98a65c | 42 | import org.eclipse.swt.graphics.RGB; |
be222f56 PT |
43 | import org.eclipse.swt.graphics.Rectangle; |
44 | import org.eclipse.swt.layout.GridData; | |
45 | import org.eclipse.swt.layout.GridLayout; | |
46 | import org.eclipse.swt.widgets.Button; | |
47 | import org.eclipse.swt.widgets.Canvas; | |
48 | import org.eclipse.swt.widgets.ColorDialog; | |
49 | import org.eclipse.swt.widgets.Composite; | |
50 | import org.eclipse.swt.widgets.Control; | |
51 | import org.eclipse.swt.widgets.Display; | |
52 | import org.eclipse.swt.widgets.FileDialog; | |
53 | import org.eclipse.swt.widgets.Label; | |
54 | import org.eclipse.swt.widgets.Shell; | |
2bdf0193 AM |
55 | import org.eclipse.tracecompass.internal.tmf.ui.Activator; |
56 | import org.eclipse.tracecompass.internal.tmf.ui.Messages; | |
9b840a86 | 57 | import org.eclipse.tracecompass.tmf.core.filter.ITmfFilter; |
674c702f | 58 | import org.eclipse.tracecompass.tmf.ui.dialog.TmfFileDialogFactory; |
2bdf0193 AM |
59 | import org.eclipse.tracecompass.tmf.ui.views.TmfView; |
60 | import org.eclipse.tracecompass.tmf.ui.views.filter.FilterDialog; | |
61 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; | |
be222f56 PT |
62 | import org.eclipse.ui.IActionBars; |
63 | ||
64 | /** | |
65 | * Color view implementation. This view provides support for managing color settings for filters. | |
66 | * | |
67 | * @version 1.0 | |
68 | * @author Patrick Tasse | |
69 | * | |
70 | */ | |
71 | public class ColorsView extends TmfView { | |
72 | ||
73 | /** ID for the color view */ | |
dab5f596 | 74 | public static final @NonNull String ID = "org.eclipse.linuxtools.tmf.ui.views.colors"; //$NON-NLS-1$ |
be222f56 PT |
75 | |
76 | private static final Image ADD_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$ | |
77 | private static final Image DELETE_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$ | |
78 | private static final Image MOVE_UP_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$ | |
79 | private static final Image MOVE_DOWN_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$ | |
80 | private static final Image IMPORT_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/import_button.gif"); //$NON-NLS-1$ | |
81 | private static final Image EXPORT_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/export_button.gif"); //$NON-NLS-1$ | |
82 | ||
83 | // ------------------------------------------------------------------------ | |
84 | // Main data structures | |
85 | // ------------------------------------------------------------------------ | |
86 | ||
87 | /** | |
88 | * The composite shell. | |
89 | */ | |
90 | protected Shell fShell; | |
91 | /** | |
92 | * The main composite (scrolled composite) | |
93 | */ | |
94 | protected ScrolledComposite fScrolledComposite; | |
95 | /** | |
96 | * The list composite. | |
97 | */ | |
98 | protected Composite fListComposite; | |
99 | /** | |
100 | * The filler composite. | |
101 | */ | |
102 | protected Composite fFillerComposite; | |
103 | /** | |
104 | * The selected color settings row | |
105 | */ | |
106 | protected ColorSettingRow fSelectedRow = null; | |
107 | /** | |
108 | * The color scheme instance for managing colors | |
109 | */ | |
110 | protected TimeGraphColorScheme traceColorScheme = new TimeGraphColorScheme(); | |
111 | /** | |
112 | * An action to add a color settings row | |
113 | */ | |
114 | protected Action fAddAction; | |
115 | /** | |
116 | * An action to delete a color settings row | |
117 | */ | |
118 | protected Action fDeleteAction; | |
119 | /** | |
120 | * An action to move up a color settings row in the list. | |
121 | */ | |
122 | protected Action fMoveUpAction; | |
123 | /** | |
124 | * An action to move down a color settings row in the list. | |
125 | */ | |
126 | protected Action fMoveDownAction; | |
127 | /** | |
128 | * An action to import color settings from file. | |
129 | */ | |
130 | protected Action fImportAction; | |
131 | /** | |
132 | * An action to export color settings from file. | |
133 | */ | |
134 | protected Action fExportAction; | |
135 | /** | |
136 | * The list of existing color settings | |
137 | */ | |
138 | protected List<ColorSetting> fColorSettings; | |
139 | ||
140 | // ------------------------------------------------------------------------ | |
141 | // Constructor | |
142 | // ------------------------------------------------------------------------ | |
143 | ||
144 | /** | |
145 | * Default Constructor | |
146 | */ | |
147 | public ColorsView() { | |
148 | super("Colors"); //$NON-NLS-1$ | |
149 | } | |
150 | ||
be222f56 PT |
151 | @Override |
152 | public void createPartControl(Composite parent) { | |
153 | fShell = parent.getShell(); | |
154 | ||
155 | fScrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL); | |
156 | fScrolledComposite.setExpandHorizontal(true); | |
157 | fScrolledComposite.setExpandVertical(true); | |
158 | fListComposite = new Composite(fScrolledComposite, SWT.NONE); | |
159 | fScrolledComposite.setContent(fListComposite); | |
160 | ||
161 | GridLayout gl = new GridLayout(); | |
162 | gl.marginHeight = 0; | |
163 | gl.marginWidth = 0; | |
164 | gl.verticalSpacing = 1; | |
165 | fListComposite.setLayout(gl); | |
166 | ||
507b1336 | 167 | fColorSettings = new ArrayList<>(Arrays.asList(ColorSettingsManager.getColorSettings())); |
be222f56 PT |
168 | for (ColorSetting colorSetting : fColorSettings) { |
169 | new ColorSettingRow(fListComposite, colorSetting); | |
170 | } | |
171 | ||
172 | fFillerComposite = new Composite(fListComposite, SWT.NONE); | |
173 | GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); | |
174 | gd.heightHint = 0; | |
175 | fFillerComposite.setLayoutData(gd); | |
176 | gl = new GridLayout(); | |
177 | gl.marginHeight = 1; | |
178 | gl.marginWidth = 1; | |
179 | fFillerComposite.setLayout(gl); | |
180 | Label fillerLabel = new Label(fFillerComposite, SWT.NONE); | |
181 | fillerLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); | |
182 | fillerLabel.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); | |
183 | ||
184 | fFillerComposite.addPaintListener(new PaintListener() { | |
185 | @Override | |
186 | public void paintControl(PaintEvent e) { | |
187 | if (fSelectedRow == null) { | |
188 | Color lineColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); | |
189 | Point p = fFillerComposite.getSize(); | |
190 | GC gc = e.gc; | |
191 | gc.setForeground(lineColor); | |
192 | gc.drawLine(0, 0, p.x - 1, 0); | |
193 | } | |
194 | } | |
195 | }); | |
196 | ||
197 | MouseListener mouseListener = new MouseAdapter() { | |
198 | @Override | |
199 | public void mouseDown(MouseEvent e) { | |
200 | fSelectedRow = null; | |
201 | refresh(); | |
202 | } | |
203 | }; | |
204 | fillerLabel.addMouseListener(mouseListener); | |
205 | ||
206 | fScrolledComposite.setMinSize(fListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); | |
207 | ||
208 | fillToolBar(); | |
209 | } | |
210 | ||
be222f56 PT |
211 | @Override |
212 | public void setFocus() { | |
213 | fScrolledComposite.setFocus(); | |
214 | } | |
215 | ||
216 | /** | |
217 | * Refreshes the view display and updates the view actions enablements. | |
218 | */ | |
219 | public void refresh() { | |
220 | fListComposite.layout(); | |
221 | fScrolledComposite.setMinSize(fListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); | |
222 | fListComposite.redraw(0, 0, fListComposite.getBounds().width, fListComposite.getBounds().height, true); | |
223 | if (fSelectedRow == null) { | |
224 | fDeleteAction.setEnabled(false); | |
225 | fMoveUpAction.setEnabled(false); | |
226 | fMoveDownAction.setEnabled(false); | |
227 | } else { | |
228 | fDeleteAction.setEnabled(true); | |
229 | fMoveUpAction.setEnabled(true); | |
230 | fMoveDownAction.setEnabled(true); | |
231 | } | |
232 | } | |
233 | ||
234 | private void fillToolBar() { | |
235 | ||
236 | fAddAction = new AddAction(); | |
237 | fAddAction.setImageDescriptor(ImageDescriptor.createFromImage(ADD_IMAGE)); | |
238 | fAddAction.setToolTipText(Messages.ColorsView_AddActionToolTipText); | |
239 | ||
240 | fDeleteAction = new DeleteAction(); | |
241 | fDeleteAction.setImageDescriptor(ImageDescriptor.createFromImage(DELETE_IMAGE)); | |
242 | fDeleteAction.setToolTipText(Messages.ColorsView_DeleteActionToolTipText); | |
243 | fDeleteAction.setEnabled(false); | |
244 | ||
245 | fMoveUpAction = new MoveUpAction(); | |
246 | fMoveUpAction.setImageDescriptor(ImageDescriptor.createFromImage(MOVE_UP_IMAGE)); | |
247 | fMoveUpAction.setToolTipText(Messages.ColorsView_MoveUpActionToolTipText); | |
248 | fMoveUpAction.setEnabled(false); | |
249 | ||
250 | fMoveDownAction = new MoveDownAction(); | |
251 | fMoveDownAction.setImageDescriptor(ImageDescriptor.createFromImage(MOVE_DOWN_IMAGE)); | |
252 | fMoveDownAction.setToolTipText(Messages.ColorsView_MoveDownActionToolTipText); | |
253 | fMoveDownAction.setEnabled(false); | |
254 | ||
255 | fExportAction = new ExportAction(); | |
256 | fExportAction.setImageDescriptor(ImageDescriptor.createFromImage(EXPORT_IMAGE)); | |
257 | fExportAction.setToolTipText(Messages.ColorsView_ExportActionToolTipText); | |
258 | ||
259 | fImportAction = new ImportAction(); | |
260 | fImportAction.setImageDescriptor(ImageDescriptor.createFromImage(IMPORT_IMAGE)); | |
261 | fImportAction.setToolTipText(Messages.ColorsView_ImportActionToolTipText); | |
262 | ||
263 | IActionBars bars = getViewSite().getActionBars(); | |
264 | IToolBarManager manager = bars.getToolBarManager(); | |
265 | manager.add(fAddAction); | |
266 | manager.add(fDeleteAction); | |
267 | manager.add(fMoveUpAction); | |
268 | manager.add(fMoveDownAction); | |
269 | manager.add(new Separator()); | |
270 | manager.add(fExportAction); | |
271 | manager.add(fImportAction); | |
272 | } | |
273 | ||
274 | private class AddAction extends Action { | |
275 | @Override | |
276 | public void run() { | |
277 | ColorSetting colorSetting = new ColorSetting( | |
9b840a86 PT |
278 | checkNotNull(Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB()), |
279 | checkNotNull(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB()), | |
280 | checkNotNull(Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB()), | |
be222f56 PT |
281 | null); |
282 | ColorSettingRow row = new ColorSettingRow(fListComposite, colorSetting); | |
283 | if (fSelectedRow == null) { | |
284 | fColorSettings.add(colorSetting); | |
285 | row.moveAbove(fFillerComposite); | |
286 | } else { | |
287 | fColorSettings.add(fColorSettings.indexOf(fSelectedRow.getColorSetting()), colorSetting); | |
288 | row.moveAbove(fSelectedRow); | |
289 | } | |
290 | fSelectedRow = row; | |
291 | refresh(); | |
292 | ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); | |
293 | } | |
294 | } | |
295 | ||
296 | private class DeleteAction extends Action { | |
297 | ||
298 | @Override | |
299 | public void run() { | |
300 | if (fSelectedRow != null) { | |
301 | int index = fColorSettings.indexOf(fSelectedRow.getColorSetting()); | |
302 | fColorSettings.remove(index); | |
303 | fSelectedRow.fColorSetting.dispose(); | |
304 | fSelectedRow.dispose(); | |
305 | if (index < fColorSettings.size()) { | |
306 | fSelectedRow = (ColorSettingRow) fListComposite.getChildren()[index]; | |
307 | } else { | |
308 | fSelectedRow = null; | |
309 | } | |
310 | refresh(); | |
311 | ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); | |
312 | } | |
313 | } | |
314 | } | |
315 | ||
316 | private class MoveUpAction extends Action { | |
317 | @Override | |
318 | public void run() { | |
319 | if (fSelectedRow != null) { | |
320 | int index = fColorSettings.indexOf(fSelectedRow.getColorSetting()); | |
321 | if (index > 0) { | |
322 | fColorSettings.add(index - 1, fColorSettings.remove(index)); | |
323 | fSelectedRow.moveAbove(fListComposite.getChildren()[index - 1]); | |
324 | refresh(); | |
325 | ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); | |
326 | } | |
327 | } | |
328 | } | |
329 | } | |
330 | ||
331 | private class MoveDownAction extends Action { | |
332 | @Override | |
333 | public void run() { | |
334 | if (fSelectedRow != null) { | |
335 | int index = fColorSettings.indexOf(fSelectedRow.getColorSetting()); | |
336 | if (index < fColorSettings.size() - 1) { | |
337 | fColorSettings.add(index + 1, fColorSettings.remove(index)); | |
338 | ||
339 | fSelectedRow.moveBelow(fListComposite.getChildren()[index + 1]); | |
340 | refresh(); | |
341 | ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); | |
342 | } | |
343 | } | |
344 | } | |
345 | } | |
346 | ||
347 | private class ExportAction extends Action { | |
348 | @Override | |
349 | public void run() { | |
674c702f | 350 | FileDialog fileDialog = TmfFileDialogFactory.create(fShell, SWT.SAVE); |
be222f56 PT |
351 | fileDialog.setFilterExtensions(new String[] {"*.xml"}); //$NON-NLS-1$ |
352 | fileDialog.setOverwrite(true); | |
353 | String pathName = fileDialog.open(); | |
354 | if (pathName != null) { | |
355 | ColorSettingsXML.save(pathName, fColorSettings.toArray(new ColorSetting[0])); | |
356 | } | |
357 | } | |
358 | } | |
359 | ||
360 | private class ImportAction extends Action { | |
361 | @Override | |
362 | public void run() { | |
674c702f | 363 | FileDialog fileDialog = TmfFileDialogFactory.create(fShell, SWT.OPEN); |
be222f56 PT |
364 | fileDialog.setFilterExtensions(new String[] {"*.xml"}); //$NON-NLS-1$ |
365 | String pathName = fileDialog.open(); | |
366 | if (pathName != null) { | |
367 | ColorSetting[] colorSettings = ColorSettingsXML.load(pathName); | |
368 | if (colorSettings.length > 0) { | |
369 | if (fColorSettings.size() > 0) { | |
370 | boolean overwrite = MessageDialog.openQuestion(fShell, | |
371 | Messages.ColorsView_ImportOverwriteDialogTitle, | |
372 | Messages.ColorsView_ImportOverwriteDialogMessage1 + | |
373 | Messages.ColorsView_ImportOverwriteDialogMessage2); | |
374 | if (overwrite) { | |
375 | for (Control control : fListComposite.getChildren()) { | |
376 | if (control instanceof ColorSettingRow) { | |
377 | ((ColorSettingRow) control).fColorSetting.dispose(); | |
378 | control.dispose(); | |
379 | } | |
380 | } | |
507b1336 | 381 | fColorSettings = new ArrayList<>(); |
be222f56 PT |
382 | fSelectedRow = null; |
383 | } | |
384 | } | |
385 | for (ColorSetting colorSetting : colorSettings) { | |
386 | ColorSettingRow row = new ColorSettingRow(fListComposite, colorSetting); | |
387 | if (fSelectedRow == null) { | |
388 | fColorSettings.add(colorSetting); | |
389 | row.moveAbove(fFillerComposite); | |
390 | } else { | |
391 | fColorSettings.add(fColorSettings.indexOf(fSelectedRow.getColorSetting()), colorSetting); | |
392 | row.moveAbove(fSelectedRow); | |
393 | } | |
394 | } | |
395 | refresh(); | |
396 | ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); | |
397 | } | |
398 | } | |
399 | } | |
400 | } | |
401 | ||
402 | private class ColorSettingRow extends Composite { | |
403 | ||
404 | ColorSetting fColorSetting; | |
405 | ||
406 | public ColorSettingRow(final Composite parent, final ColorSetting colorSetting) { | |
407 | super(parent, SWT.NONE); | |
408 | fColorSetting = colorSetting; | |
409 | ||
410 | setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); | |
411 | ||
412 | setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
413 | GridLayout gl = new GridLayout(7, false); | |
414 | gl.marginHeight = 1; | |
415 | gl.marginWidth = 1; | |
416 | gl.horizontalSpacing = 1; | |
417 | gl.verticalSpacing = 0; | |
418 | setLayout(gl); | |
419 | ||
420 | final Button fgButton = new Button(this, SWT.PUSH); | |
421 | fgButton.setText(Messages.ColorsView_ForegroundButtonText); | |
422 | fgButton.setSize(fgButton.computeSize(SWT.DEFAULT, 19)); | |
423 | fgButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); | |
424 | ||
425 | final Button bgButton = new Button(this, SWT.PUSH); | |
426 | bgButton.setText(Messages.ColorsView_BackgroundButtonText); | |
427 | bgButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); | |
428 | ||
429 | final Composite labelComposite = new Composite(this, SWT.NONE); | |
430 | labelComposite.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, false)); | |
431 | gl = new GridLayout(); | |
432 | gl.marginHeight = 0; | |
433 | gl.marginWidth = 0; | |
434 | labelComposite.setLayout(gl); | |
435 | labelComposite.setBackground(colorSetting.getBackgroundColor()); | |
436 | ||
437 | final Label label = new Label(labelComposite, SWT.NONE); | |
438 | label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, true)); | |
439 | label.setText(" Text "); //$NON-NLS-1$ | |
440 | label.setForeground(colorSetting.getForegroundColor()); | |
441 | label.setBackground(colorSetting.getBackgroundColor()); | |
442 | ||
443 | fgButton.addSelectionListener(new SelectionAdapter() { | |
444 | @Override | |
445 | public void widgetSelected(SelectionEvent e) { | |
446 | fSelectedRow = ColorSettingRow.this; | |
447 | refresh(); | |
448 | ColorDialog dialog = new ColorDialog(fShell); | |
449 | dialog.setRGB(colorSetting.getForegroundRGB()); | |
450 | dialog.setText(Messages.ColorsView_ForegroundDialogText); | |
451 | dialog.open(); | |
1a98a65c MAL |
452 | RGB rgb = dialog.getRGB(); |
453 | if (rgb != null) { | |
454 | colorSetting.setForegroundRGB(rgb); | |
455 | ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); | |
456 | label.setForeground(colorSetting.getForegroundColor()); | |
457 | } | |
be222f56 PT |
458 | }}); |
459 | ||
460 | bgButton.addSelectionListener(new SelectionAdapter() { | |
461 | @Override | |
462 | public void widgetSelected(SelectionEvent e) { | |
463 | fSelectedRow = ColorSettingRow.this; | |
464 | refresh(); | |
465 | ColorDialog dialog = new ColorDialog(fShell); | |
466 | dialog.setRGB(colorSetting.getBackgroundRGB()); | |
467 | dialog.setText(Messages.ColorsView_BackgroundDialogText); | |
468 | dialog.open(); | |
1a98a65c MAL |
469 | RGB rgb = dialog.getRGB(); |
470 | if (rgb != null) { | |
471 | colorSetting.setBackgroundRGB(rgb); | |
472 | ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); | |
473 | labelComposite.setBackground(colorSetting.getBackgroundColor()); | |
474 | label.setBackground(colorSetting.getBackgroundColor()); | |
475 | } | |
be222f56 PT |
476 | }}); |
477 | ||
478 | final Button tickButton = new Button(this, SWT.PUSH); | |
479 | tickButton.setText(Messages.ColorsView_TickButtonText); | |
480 | tickButton.setSize(tickButton.computeSize(SWT.DEFAULT, 19)); | |
481 | tickButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); | |
482 | ||
483 | final Canvas tickCanvas = new Canvas(this, SWT.NONE); | |
484 | GridData gd = new GridData(SWT.CENTER, SWT.FILL, false, false); | |
485 | gd.widthHint = 12; | |
486 | gd.heightHint = bgButton.getSize().y; | |
487 | tickCanvas.setLayoutData(gd); | |
488 | tickCanvas.setBackground(traceColorScheme.getBkColor(false, false, false)); | |
489 | tickCanvas.addPaintListener(new PaintListener() { | |
490 | @Override | |
491 | public void paintControl(PaintEvent e) { | |
492 | Rectangle bounds = tickCanvas.getBounds(); | |
493 | e.gc.setForeground(traceColorScheme.getColor(TimeGraphColorScheme.MID_LINE)); | |
494 | int midy = bounds.y + bounds.height / 2 - 1; | |
495 | //int midy = e.y + e.height / 2; | |
496 | e.gc.drawLine(e.x, midy, e.x + e.width, midy); | |
497 | Rectangle rect = new Rectangle(e.x + 1, bounds.y + 2, 0, bounds.height - 6); | |
498 | for (int i = 1; i <= 3; i++) { | |
499 | rect.x += i; | |
500 | rect.width = i; | |
501 | e.gc.setBackground(fColorSetting.getTickColor()); | |
502 | e.gc.fillRectangle(rect); | |
503 | } | |
504 | }}); | |
505 | ||
506 | tickButton.addSelectionListener(new SelectionAdapter() { | |
507 | @Override | |
508 | public void widgetSelected(SelectionEvent e) { | |
509 | fSelectedRow = ColorSettingRow.this; | |
510 | ColorDialog dialog = new ColorDialog(fShell); | |
511 | dialog.setRGB(colorSetting.getTickColorRGB()); | |
512 | dialog.setText(Messages.TickColorDialog_TickColorDialogTitle); | |
513 | dialog.open(); | |
1a98a65c MAL |
514 | RGB rgb = dialog.getRGB(); |
515 | if (rgb != null) { | |
516 | colorSetting.setTickColorRGB(rgb); | |
517 | ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); | |
518 | refresh(); | |
519 | } | |
be222f56 PT |
520 | }}); |
521 | ||
522 | final Button filterButton = new Button(this, SWT.PUSH); | |
523 | filterButton.setText(Messages.ColorsView_FilterButtonText); | |
524 | filterButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); | |
525 | ||
526 | final Label filterText = new Label(this, SWT.NONE); | |
9b840a86 PT |
527 | ITmfFilter filter = colorSetting.getFilter(); |
528 | if (filter != null) { | |
529 | filterText.setText(filter.toString()); | |
530 | filterText.setToolTipText(filter.toString()); | |
be222f56 PT |
531 | } |
532 | filterText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); | |
533 | filterText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
534 | ||
535 | filterButton.addSelectionListener(new SelectionAdapter() { | |
536 | @Override | |
537 | public void widgetSelected(SelectionEvent e) { | |
538 | fSelectedRow = ColorSettingRow.this; | |
539 | refresh(); | |
540 | FilterDialog dialog = new FilterDialog(fShell); | |
541 | dialog.setFilter(colorSetting.getFilter()); | |
542 | dialog.open(); | |
543 | if (dialog.getReturnCode() == Window.OK) { | |
544 | if (dialog.getFilter() != null) { | |
545 | colorSetting.setFilter(dialog.getFilter()); | |
546 | filterText.setText(dialog.getFilter().toString()); | |
547 | filterText.setToolTipText(dialog.getFilter().toString()); | |
548 | } else { | |
549 | colorSetting.setFilter(null); | |
550 | filterText.setText(""); //$NON-NLS-1$ | |
551 | filterText.setToolTipText(""); //$NON-NLS-1$ | |
552 | } | |
553 | ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); | |
554 | refresh(); | |
555 | } | |
556 | }}); | |
557 | ||
558 | addPaintListener(new PaintListener() { | |
559 | @Override | |
560 | public void paintControl(PaintEvent e) { | |
561 | if (fSelectedRow == ColorSettingRow.this) { | |
562 | Color borderColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); | |
563 | Point p = ColorSettingRow.this.getSize(); | |
564 | Rectangle rect = new Rectangle(0, 0, p.x - 1, p.y - 1); | |
565 | GC gc = e.gc; | |
566 | gc.setForeground(borderColor); | |
567 | gc.drawRectangle(rect); | |
568 | } | |
569 | } | |
570 | }); | |
571 | ||
572 | MouseListener mouseListener = new MouseAdapter() { | |
573 | @Override | |
574 | public void mouseDown(MouseEvent e) { | |
575 | fSelectedRow = ColorSettingRow.this; | |
576 | refresh(); | |
577 | } | |
578 | }; | |
579 | addMouseListener(mouseListener); | |
580 | label.addMouseListener(mouseListener); | |
581 | tickCanvas.addMouseListener(mouseListener); | |
582 | filterText.addMouseListener(mouseListener); | |
583 | } | |
584 | ||
585 | /** | |
586 | * @return the ColorSetting | |
587 | */ | |
588 | public ColorSetting getColorSetting() { | |
589 | return fColorSetting; | |
590 | } | |
591 | ||
592 | } | |
6e1b4486 JR |
593 | |
594 | @Override | |
595 | protected boolean canBePinned() { | |
596 | //TODO: actionPin is not defined | |
597 | return false; | |
598 | } | |
be222f56 | 599 | } |