1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.eclipse.org/org/documents/epl-v10.php
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ide.eclipse.adt.internal.editors.layout.gle2;
18 
19 import com.android.ide.common.api.DrawingStyle;
20 
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.graphics.RGB;
23 
24 /**
25  * Description of the drawing styles with specific color, line style and alpha
26  * definitions. This class corresponds to the more generic {@link DrawingStyle}
27  * class which defines the drawing styles but does not introduce any specific
28  * SWT values to the API clients.
29  * <p>
30  * TODO: This class should eventually be replaced by a scheme where the color
31  * constants are instead coming from the theme.
32  */
33 public enum SwtDrawingStyle {
34     /**
35      * The style definition corresponding to {@link DrawingStyle#SELECTION}
36      */
37     SELECTION(new RGB(0x00, 0x99, 0xFF), 192, new RGB(0x00, 0x99, 0xFF), 192, 1, SWT.LINE_SOLID),
38 
39     /**
40      * The style definition corresponding to {@link DrawingStyle#GUIDELINE}
41      */
42     GUIDELINE(new RGB(0x00, 0xAA, 0x00), 192, SWT.LINE_SOLID),
43 
44     /**
45      * The style definition corresponding to {@link DrawingStyle#GUIDELINE}
46      */
47     GUIDELINE_SHADOW(new RGB(0x00, 0xAA, 0x00), 192, SWT.LINE_SOLID),
48 
49     /**
50      * The style definition corresponding to {@link DrawingStyle#GUIDELINE_DASHED}
51      */
52     GUIDELINE_DASHED(new RGB(0x00, 0xAA, 0x00), 192, SWT.LINE_CUSTOM),
53 
54     /**
55      * The style definition corresponding to {@link DrawingStyle#DISTANCE}
56      */
57     DISTANCE(new RGB(0xFF, 0x00, 0x00), 192 - 32, SWT.LINE_SOLID),
58 
59     /**
60      * The style definition corresponding to {@link DrawingStyle#GRID}
61      */
62     GRID(new RGB(0xAA, 0xAA, 0xAA), 128, SWT.LINE_SOLID),
63 
64     /**
65      * The style definition corresponding to {@link DrawingStyle#HOVER}
66      */
67     HOVER(null, 0, new RGB(0xFF, 0xFF, 0xFF), 40, 1, SWT.LINE_DOT),
68 
69     /**
70      * The style definition corresponding to {@link DrawingStyle#HOVER}
71      */
72     HOVER_SELECTION(null, 0, new RGB(0xFF, 0xFF, 0xFF), 10, 1, SWT.LINE_DOT),
73 
74     /**
75      * The style definition corresponding to {@link DrawingStyle#ANCHOR}
76      */
77     ANCHOR(new RGB(0x00, 0x99, 0xFF), 96, SWT.LINE_SOLID),
78 
79     /**
80      * The style definition corresponding to {@link DrawingStyle#OUTLINE}
81      */
82     OUTLINE(new RGB(0x88, 0xFF, 0x88), 160, SWT.LINE_SOLID),
83 
84     /**
85      * The style definition corresponding to {@link DrawingStyle#DROP_RECIPIENT}
86      */
87     DROP_RECIPIENT(new RGB(0xFF, 0x99, 0x00), 255, new RGB(0xFF, 0x99, 0x00), 160, 2,
88             SWT.LINE_SOLID),
89 
90     /**
91      * The style definition corresponding to {@link DrawingStyle#DROP_ZONE}
92      */
93     DROP_ZONE(new RGB(0x00, 0xAA, 0x00), 220, new RGB(0x55, 0xAA, 0x00), 200, 1, SWT.LINE_SOLID),
94 
95     /**
96      * The style definition corresponding to
97      * {@link DrawingStyle#DROP_ZONE_ACTIVE}
98      */
99     DROP_ZONE_ACTIVE(new RGB(0x00, 0xAA, 0x00), 220, new RGB(0x00, 0xAA, 0x00), 128, 2,
100             SWT.LINE_SOLID),
101 
102     /**
103      * The style definition corresponding to {@link DrawingStyle#DROP_PREVIEW}
104      */
105     DROP_PREVIEW(new RGB(0xFF, 0x99, 0x00), 255, null, 0, 2, SWT.LINE_CUSTOM),
106 
107     /**
108      * The style definition corresponding to {@link DrawingStyle#RESIZE_PREVIEW}
109      */
110     RESIZE_PREVIEW(new RGB(0xFF, 0x99, 0x00), 255, null, 0, 2, SWT.LINE_SOLID),
111 
112     /**
113      * The style used to show a proposed resize bound which is being rejected (for example,
114      * because there is no near edge to attach to in a RelativeLayout).
115      */
116     RESIZE_FAIL(new RGB(0xFF, 0x99, 0x00), 255, null, 0, 2, SWT.LINE_CUSTOM),
117 
118     /**
119      * The style definition corresponding to {@link DrawingStyle#HELP}
120      */
121     HELP(new RGB(0xFF, 0xFF, 0xFF), 255, new RGB(0x00, 0x00, 0x00), 128, 1, SWT.LINE_SOLID),
122 
123     /**
124      * The style definition corresponding to {@link DrawingStyle#INVALID}
125      */
126     INVALID(new RGB(0xFF, 0xFF, 0xFF), 255, new RGB(0xFF, 0x00, 0x00), 64, 2, SWT.LINE_SOLID),
127 
128     /**
129      * The style definition corresponding to {@link DrawingStyle#DEPENDENCY}
130      */
131     DEPENDENCY(new RGB(0xFF, 0xFF, 0xFF), 255, new RGB(0xFF, 0xFF, 0x00), 24, 2, SWT.LINE_SOLID),
132 
133     /**
134      * The style definition corresponding to {@link DrawingStyle#CYCLE}
135      */
136     CYCLE(new RGB(0xFF, 0x00, 0x00), 192, null, 0, 1, SWT.LINE_SOLID),
137 
138     /**
139      * The style definition corresponding to {@link DrawingStyle#DRAGGED}
140      */
141     DRAGGED(new RGB(0xFF, 0xFF, 0xFF), 255, new RGB(0x00, 0xFF, 0x00), 16, 2, SWT.LINE_SOLID),
142 
143     /**
144      * The style definition corresponding to {@link DrawingStyle#EMPTY}
145      */
146     EMPTY(new RGB(0xFF, 0xFF, 0x55), 255, new RGB(0xFF, 0xFF, 0x55), 255, 1, SWT.LINE_DASH),
147 
148     /**
149      * The style definition corresponding to {@link DrawingStyle#CUSTOM1}
150      */
151     CUSTOM1(new RGB(0xFF, 0x00, 0xFF), 255, null, 0, 1, SWT.LINE_SOLID),
152 
153     /**
154      * The style definition corresponding to {@link DrawingStyle#CUSTOM2}
155      */
156     CUSTOM2(new RGB(0x00, 0xFF, 0xFF), 255, null, 0, 1, SWT.LINE_DOT);
157 
158     /**
159      * Construct a new style value with the given foreground, background, width,
160      * linestyle and transparency.
161      *
162      * @param stroke A color descriptor for the foreground color, or null if no
163      *            foreground color should be set
164      * @param fill A color descriptor for the background color, or null if no
165      *            foreground color should be set
166      * @param lineWidth The line width, in pixels, or 0 if no line width should
167      *            be set
168      * @param lineStyle The SWT line style - such as {@link SWT#LINE_SOLID}.
169      * @param strokeAlpha The alpha value of the stroke, an integer in the range 0 to 255
170      *            where 0 is fully transparent and 255 is fully opaque.
171      * @param fillAlpha The alpha value of the fill, an integer in the range 0 to 255
172      *            where 0 is fully transparent and 255 is fully opaque.
173      */
SwtDrawingStyle(RGB stroke, int strokeAlpha, RGB fill, int fillAlpha, int lineWidth, int lineStyle)174     private SwtDrawingStyle(RGB stroke, int strokeAlpha, RGB fill, int fillAlpha, int lineWidth,
175             int lineStyle) {
176         mStroke = stroke;
177         mFill = fill;
178         mLineWidth = lineWidth;
179         mLineStyle = lineStyle;
180         mStrokeAlpha = strokeAlpha;
181         mFillAlpha = fillAlpha;
182     }
183 
184     /**
185      * Convenience constructor for typical drawing styles, which do not specify
186      * a fill and use a standard thickness line
187      *
188      * @param stroke Stroke color to be used (e.g. for the border/foreground)
189      * @param strokeAlpha Transparency to use for the stroke; 0 is transparent
190      *            and 255 is fully opaque.
191      * @param lineStyle The SWT line style - such as {@link SWT#LINE_SOLID}.
192      */
SwtDrawingStyle(RGB stroke, int strokeAlpha, int lineStyle)193     private SwtDrawingStyle(RGB stroke, int strokeAlpha, int lineStyle) {
194         this(stroke, strokeAlpha, null, 255, 1, lineStyle);
195     }
196 
197     /**
198      * Return the stroke/foreground/border RGB color description to be used for
199      * this style, or null if none
200      */
getStrokeColor()201     public RGB getStrokeColor() {
202         return mStroke;
203     }
204 
205     /**
206      * Return the fill/background/interior RGB color description to be used for
207      * this style, or null if none
208      */
getFillColor()209     public RGB getFillColor() {
210         return mFill;
211     }
212 
213     /** Return the line width to be used for this style */
getLineWidth()214     public int getLineWidth() {
215         return mLineWidth;
216     }
217 
218     /** Return the SWT line style to be used for this style */
getLineStyle()219     public int getLineStyle() {
220         return mLineStyle;
221     }
222 
223     /**
224      * Return the stroke alpha value (in the range 0,255) to be used for this
225      * style
226      */
getStrokeAlpha()227     public int getStrokeAlpha() {
228         return mStrokeAlpha;
229     }
230 
231     /**
232      * Return the fill alpha value (in the range 0,255) to be used for this
233      * style
234      */
getFillAlpha()235     public int getFillAlpha() {
236         return mFillAlpha;
237     }
238 
239     /**
240      * Return the corresponding SwtDrawingStyle for the given
241      * {@link DrawingStyle}
242      * @param style The style to convert from a {@link DrawingStyle} to a {@link SwtDrawingStyle}.
243      * @return A corresponding {@link SwtDrawingStyle}.
244      */
of(DrawingStyle style)245     public static SwtDrawingStyle of(DrawingStyle style) {
246         switch (style) {
247             case SELECTION:
248                 return SELECTION;
249             case GUIDELINE:
250                 return GUIDELINE;
251             case GUIDELINE_SHADOW:
252                 return GUIDELINE_SHADOW;
253             case GUIDELINE_DASHED:
254                 return GUIDELINE_DASHED;
255             case DISTANCE:
256                 return DISTANCE;
257             case GRID:
258                 return GRID;
259             case HOVER:
260                 return HOVER;
261             case HOVER_SELECTION:
262                 return HOVER_SELECTION;
263             case ANCHOR:
264                 return ANCHOR;
265             case OUTLINE:
266                 return OUTLINE;
267             case DROP_ZONE:
268                 return DROP_ZONE;
269             case DROP_ZONE_ACTIVE:
270                 return DROP_ZONE_ACTIVE;
271             case DROP_RECIPIENT:
272                 return DROP_RECIPIENT;
273             case DROP_PREVIEW:
274                 return DROP_PREVIEW;
275             case RESIZE_PREVIEW:
276                 return RESIZE_PREVIEW;
277             case RESIZE_FAIL:
278                 return RESIZE_FAIL;
279             case HELP:
280                 return HELP;
281             case INVALID:
282                 return INVALID;
283             case DEPENDENCY:
284                 return DEPENDENCY;
285             case CYCLE:
286                 return CYCLE;
287             case DRAGGED:
288                 return DRAGGED;
289             case EMPTY:
290                 return EMPTY;
291             case CUSTOM1:
292                 return CUSTOM1;
293             case CUSTOM2:
294                 return CUSTOM2;
295 
296                 // Internal error
297             default:
298                 throw new IllegalArgumentException("Unknown style " + style);
299         }
300     }
301 
302     /** RGB description of the stroke/foreground/border color */
303     private final RGB mStroke;
304 
305     /** RGB description of the fill/foreground/interior color */
306     private final RGB mFill;
307 
308     /** Pixel thickness of the stroke/border */
309     private final int mLineWidth;
310 
311     /** SWT line style of the border/stroke */
312     private final int mLineStyle;
313 
314     /** Alpha (in the range 0-255) of the stroke/border */
315     private final int mStrokeAlpha;
316 
317     /** Alpha (in the range 0-255) of the fill/interior */
318     private final int mFillAlpha;
319 }
320