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