Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
df0b8ff4 BH |
2 | * Copyright (c) 2005, 2008 IBM Corporation and others. |
3 | * Copyright (c) 2011, 2012 Ericsson. | |
4 | * | |
73005152 BH |
5 | * All rights reserved. This program and the accompanying materials |
6 | * are made available under the terms of the Eclipse Public License v1.0 | |
7 | * which accompanies this distribution, and is available at | |
8 | * http://www.eclipse.org/legal/epl-v10.html | |
73005152 BH |
9 | * |
10 | * Contributors: | |
11 | * IBM - Initial API and implementation | |
12 | * Bernd Hufmann - Updated for TMF | |
13 | **********************************************************************/ | |
14 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.impl; | |
15 | ||
16 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor; | |
17 | import org.eclipse.swt.graphics.Color; | |
18 | import org.eclipse.swt.widgets.Display; | |
19 | ||
20 | /** | |
df0b8ff4 BH |
21 | * Default implementation of the IColor interface. |
22 | * | |
23 | * @version 1.0 | |
73005152 BH |
24 | * @author sveyrier |
25 | * | |
26 | */ | |
27 | public class ColorImpl implements IColor { | |
28 | ||
df0b8ff4 BH |
29 | // ------------------------------------------------------------------------ |
30 | // Attributes | |
31 | // ------------------------------------------------------------------------ | |
32 | /** | |
33 | * The color object. | |
34 | */ | |
eb63f5ff | 35 | protected Color fColor = null; |
df0b8ff4 BH |
36 | /** |
37 | * Flag to indicate that this object is managing the resource. | |
38 | */ | |
eb63f5ff | 39 | protected boolean fManageColor = true; |
73005152 | 40 | |
df0b8ff4 BH |
41 | // ------------------------------------------------------------------------ |
42 | // Constructors | |
43 | // ------------------------------------------------------------------------ | |
44 | /** | |
45 | * Constructor | |
46 | * | |
47 | * @param display The display to use | |
48 | * @param r A value for red | |
49 | * @param g A value for green | |
50 | * @param b A value for blue | |
51 | */ | |
73005152 | 52 | public ColorImpl(Display display, int r, int g, int b) { |
eb63f5ff | 53 | fColor = new Color(display, r, g, b); |
73005152 BH |
54 | } |
55 | ||
df0b8ff4 BH |
56 | /** |
57 | * Copy constructor | |
58 | * | |
59 | * @param A color to copy | |
60 | */ | |
73005152 | 61 | protected ColorImpl(Color color) { |
eb63f5ff BH |
62 | fColor = color; |
63 | fManageColor = false; | |
73005152 BH |
64 | } |
65 | ||
df0b8ff4 BH |
66 | // ------------------------------------------------------------------------ |
67 | // Methods | |
68 | // ------------------------------------------------------------------------ | |
69 | ||
70 | /** | |
71 | * Returns a system color. | |
72 | * | |
73 | * @param color The color ID | |
74 | * @return a system color | |
75 | */ | |
73005152 BH |
76 | public static ColorImpl getSystemColor(int color) { |
77 | return new ColorImpl(Display.getDefault().getSystemColor(color)); | |
78 | } | |
df0b8ff4 BH |
79 | |
80 | /* | |
81 | * (non-Javadoc) | |
82 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor#getColor() | |
83 | */ | |
73005152 BH |
84 | @Override |
85 | public Object getColor() { | |
eb63f5ff | 86 | return fColor; |
73005152 BH |
87 | } |
88 | ||
df0b8ff4 BH |
89 | /* |
90 | * (non-Javadoc) | |
91 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor#dispose() | |
92 | */ | |
73005152 BH |
93 | @Override |
94 | public void dispose() { | |
eb63f5ff BH |
95 | if ((fColor != null) && (fManageColor)) { |
96 | fColor.dispose(); | |
df0b8ff4 | 97 | } |
73005152 BH |
98 | } |
99 | ||
100 | } |