aboutsummaryrefslogtreecommitdiff
path: root/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SwtDrawingStyle.java
blob: 93a33283cfeaf99af740ba86828434ed42e38d27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.eclipse.org/org/documents/epl-v10.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.ide.eclipse.adt.internal.editors.layout.gle2;

import com.android.ide.common.api.DrawingStyle;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;

/**
 * Description of the drawing styles with specific color, line style and alpha
 * definitions. This class corresponds to the more generic {@link DrawingStyle}
 * class which defines the drawing styles but does not introduce any specific
 * SWT values to the API clients.
 * <p>
 * TODO: This class should eventually be replaced by a scheme where the color
 * constants are instead coming from the theme.
 */
public enum SwtDrawingStyle {
    /**
     * The style definition corresponding to {@link DrawingStyle#SELECTION}
     */
    SELECTION(new RGB(0x00, 0x99, 0xFF), 192, new RGB(0x00, 0x99, 0xFF), 192, 1, SWT.LINE_SOLID),

    /**
     * The style definition corresponding to {@link DrawingStyle#GUIDELINE}
     */
    GUIDELINE(new RGB(0x00, 0xAA, 0x00), 192, SWT.LINE_SOLID),

    /**
     * The style definition corresponding to {@link DrawingStyle#GUIDELINE}
     */
    GUIDELINE_SHADOW(new RGB(0x00, 0xAA, 0x00), 192, SWT.LINE_SOLID),

    /**
     * The style definition corresponding to {@link DrawingStyle#GUIDELINE_DASHED}
     */
    GUIDELINE_DASHED(new RGB(0x00, 0xAA, 0x00), 192, SWT.LINE_CUSTOM),

    /**
     * The style definition corresponding to {@link DrawingStyle#DISTANCE}
     */
    DISTANCE(new RGB(0xFF, 0x00, 0x00), 192 - 32, SWT.LINE_SOLID),

    /**
     * The style definition corresponding to {@link DrawingStyle#GRID}
     */
    GRID(new RGB(0xAA, 0xAA, 0xAA), 128, SWT.LINE_SOLID),

    /**
     * The style definition corresponding to {@link DrawingStyle#HOVER}
     */
    HOVER(null, 0, new RGB(0xFF, 0xFF, 0xFF), 40, 1, SWT.LINE_DOT),

    /**
     * The style definition corresponding to {@link DrawingStyle#HOVER}
     */
    HOVER_SELECTION(null, 0, new RGB(0xFF, 0xFF, 0xFF), 10, 1, SWT.LINE_DOT),

    /**
     * The style definition corresponding to {@link DrawingStyle#ANCHOR}
     */
    ANCHOR(new RGB(0x00, 0x99, 0xFF), 96, SWT.LINE_SOLID),

    /**
     * The style definition corresponding to {@link DrawingStyle#OUTLINE}
     */
    OUTLINE(new RGB(0x88, 0xFF, 0x88), 160, SWT.LINE_SOLID),

    /**
     * The style definition corresponding to {@link DrawingStyle#DROP_RECIPIENT}
     */
    DROP_RECIPIENT(new RGB(0xFF, 0x99, 0x00), 255, new RGB(0xFF, 0x99, 0x00), 160, 2,
            SWT.LINE_SOLID),

    /**
     * The style definition corresponding to {@link DrawingStyle#DROP_ZONE}
     */
    DROP_ZONE(new RGB(0x00, 0xAA, 0x00), 220, new RGB(0x55, 0xAA, 0x00), 200, 1, SWT.LINE_SOLID),

    /**
     * The style definition corresponding to
     * {@link DrawingStyle#DROP_ZONE_ACTIVE}
     */
    DROP_ZONE_ACTIVE(new RGB(0x00, 0xAA, 0x00), 220, new RGB(0x00, 0xAA, 0x00), 128, 2,
            SWT.LINE_SOLID),

    /**
     * The style definition corresponding to {@link DrawingStyle#DROP_PREVIEW}
     */
    DROP_PREVIEW(new RGB(0xFF, 0x99, 0x00), 255, null, 0, 2, SWT.LINE_CUSTOM),

    /**
     * The style definition corresponding to {@link DrawingStyle#RESIZE_PREVIEW}
     */
    RESIZE_PREVIEW(new RGB(0xFF, 0x99, 0x00), 255, null, 0, 2, SWT.LINE_SOLID),

    /**
     * The style used to show a proposed resize bound which is being rejected (for example,
     * because there is no near edge to attach to in a RelativeLayout).
     */
    RESIZE_FAIL(new RGB(0xFF, 0x99, 0x00), 255, null, 0, 2, SWT.LINE_CUSTOM),

    /**
     * The style definition corresponding to {@link DrawingStyle#HELP}
     */
    HELP(new RGB(0xFF, 0xFF, 0xFF), 255, new RGB(0x00, 0x00, 0x00), 128, 1, SWT.LINE_SOLID),

    /**
     * The style definition corresponding to {@link DrawingStyle#INVALID}
     */
    INVALID(new RGB(0xFF, 0xFF, 0xFF), 255, new RGB(0xFF, 0x00, 0x00), 64, 2, SWT.LINE_SOLID),

    /**
     * The style definition corresponding to {@link DrawingStyle#DEPENDENCY}
     */
    DEPENDENCY(new RGB(0xFF, 0xFF, 0xFF), 255, new RGB(0xFF, 0xFF, 0x00), 24, 2, SWT.LINE_SOLID),

    /**
     * The style definition corresponding to {@link DrawingStyle#CYCLE}
     */
    CYCLE(new RGB(0xFF, 0x00, 0x00), 192, null, 0, 1, SWT.LINE_SOLID),

    /**
     * The style definition corresponding to {@link DrawingStyle#DRAGGED}
     */
    DRAGGED(new RGB(0xFF, 0xFF, 0xFF), 255, new RGB(0x00, 0xFF, 0x00), 16, 2, SWT.LINE_SOLID),

    /**
     * The style definition corresponding to {@link DrawingStyle#EMPTY}
     */
    EMPTY(new RGB(0xFF, 0xFF, 0x55), 255, new RGB(0xFF, 0xFF, 0x55), 255, 1, SWT.LINE_DASH),

    /**
     * The style definition corresponding to {@link DrawingStyle#CUSTOM1}
     */
    CUSTOM1(new RGB(0xFF, 0x00, 0xFF), 255, null, 0, 1, SWT.LINE_SOLID),

    /**
     * The style definition corresponding to {@link DrawingStyle#CUSTOM2}
     */
    CUSTOM2(new RGB(0x00, 0xFF, 0xFF), 255, null, 0, 1, SWT.LINE_DOT);

    /**
     * Construct a new style value with the given foreground, background, width,
     * linestyle and transparency.
     *
     * @param stroke A color descriptor for the foreground color, or null if no
     *            foreground color should be set
     * @param fill A color descriptor for the background color, or null if no
     *            foreground color should be set
     * @param lineWidth The line width, in pixels, or 0 if no line width should
     *            be set
     * @param lineStyle The SWT line style - such as {@link SWT#LINE_SOLID}.
     * @param strokeAlpha The alpha value of the stroke, an integer in the range 0 to 255
     *            where 0 is fully transparent and 255 is fully opaque.
     * @param fillAlpha The alpha value of the fill, an integer in the range 0 to 255
     *            where 0 is fully transparent and 255 is fully opaque.
     */
    private SwtDrawingStyle(RGB stroke, int strokeAlpha, RGB fill, int fillAlpha, int lineWidth,
            int lineStyle) {
        mStroke = stroke;
        mFill = fill;
        mLineWidth = lineWidth;
        mLineStyle = lineStyle;
        mStrokeAlpha = strokeAlpha;
        mFillAlpha = fillAlpha;
    }

    /**
     * Convenience constructor for typical drawing styles, which do not specify
     * a fill and use a standard thickness line
     *
     * @param stroke Stroke color to be used (e.g. for the border/foreground)
     * @param strokeAlpha Transparency to use for the stroke; 0 is transparent
     *            and 255 is fully opaque.
     * @param lineStyle The SWT line style - such as {@link SWT#LINE_SOLID}.
     */
    private SwtDrawingStyle(RGB stroke, int strokeAlpha, int lineStyle) {
        this(stroke, strokeAlpha, null, 255, 1, lineStyle);
    }

    /**
     * Return the stroke/foreground/border RGB color description to be used for
     * this style, or null if none
     */
    public RGB getStrokeColor() {
        return mStroke;
    }

    /**
     * Return the fill/background/interior RGB color description to be used for
     * this style, or null if none
     */
    public RGB getFillColor() {
        return mFill;
    }

    /** Return the line width to be used for this style */
    public int getLineWidth() {
        return mLineWidth;
    }

    /** Return the SWT line style to be used for this style */
    public int getLineStyle() {
        return mLineStyle;
    }

    /**
     * Return the stroke alpha value (in the range 0,255) to be used for this
     * style
     */
    public int getStrokeAlpha() {
        return mStrokeAlpha;
    }

    /**
     * Return the fill alpha value (in the range 0,255) to be used for this
     * style
     */
    public int getFillAlpha() {
        return mFillAlpha;
    }

    /**
     * Return the corresponding SwtDrawingStyle for the given
     * {@link DrawingStyle}
     * @param style The style to convert from a {@link DrawingStyle} to a {@link SwtDrawingStyle}.
     * @return A corresponding {@link SwtDrawingStyle}.
     */
    public static SwtDrawingStyle of(DrawingStyle style) {
        switch (style) {
            case SELECTION:
                return SELECTION;
            case GUIDELINE:
                return GUIDELINE;
            case GUIDELINE_SHADOW:
                return GUIDELINE_SHADOW;
            case GUIDELINE_DASHED:
                return GUIDELINE_DASHED;
            case DISTANCE:
                return DISTANCE;
            case GRID:
                return GRID;
            case HOVER:
                return HOVER;
            case HOVER_SELECTION:
                return HOVER_SELECTION;
            case ANCHOR:
                return ANCHOR;
            case OUTLINE:
                return OUTLINE;
            case DROP_ZONE:
                return DROP_ZONE;
            case DROP_ZONE_ACTIVE:
                return DROP_ZONE_ACTIVE;
            case DROP_RECIPIENT:
                return DROP_RECIPIENT;
            case DROP_PREVIEW:
                return DROP_PREVIEW;
            case RESIZE_PREVIEW:
                return RESIZE_PREVIEW;
            case RESIZE_FAIL:
                return RESIZE_FAIL;
            case HELP:
                return HELP;
            case INVALID:
                return INVALID;
            case DEPENDENCY:
                return DEPENDENCY;
            case CYCLE:
                return CYCLE;
            case DRAGGED:
                return DRAGGED;
            case EMPTY:
                return EMPTY;
            case CUSTOM1:
                return CUSTOM1;
            case CUSTOM2:
                return CUSTOM2;

                // Internal error
            default:
                throw new IllegalArgumentException("Unknown style " + style);
        }
    }

    /** RGB description of the stroke/foreground/border color */
    private final RGB mStroke;

    /** RGB description of the fill/foreground/interior color */
    private final RGB mFill;

    /** Pixel thickness of the stroke/border */
    private final int mLineWidth;

    /** SWT line style of the border/stroke */
    private final int mLineStyle;

    /** Alpha (in the range 0-255) of the stroke/border */
    private final int mStrokeAlpha;

    /** Alpha (in the range 0-255) of the fill/interior */
    private final int mFillAlpha;
}