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