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