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