• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.common.layout;
18 
19 import com.android.annotations.NonNull;
20 import com.android.ide.common.api.DrawingStyle;
21 import com.android.ide.common.api.IColor;
22 import com.android.ide.common.api.IGraphics;
23 import com.android.ide.common.api.Point;
24 import com.android.ide.common.api.Rect;
25 
26 import java.util.ArrayList;
27 import java.util.Collections;
28 import java.util.List;
29 
30 // TODO: Create box of ascii art
31 
32 public class TestGraphics implements IGraphics {
33     /** List of things we have drawn */
34     private List<String> mDrawn = new ArrayList<String>();
35 
36     private IColor mBackground = new TestColor(0x000000);
37 
38     private IColor mForeground = new TestColor(0xFFFFFF);
39 
40     private int mAlpha = 128;
41 
42     /** Return log of graphics calls */
getDrawn()43     public List<String> getDrawn() {
44         return Collections.unmodifiableList(mDrawn);
45     }
46 
47     /** Wipe out log of graphics calls */
clear()48     public void clear() {
49         mDrawn.clear();
50     }
51 
52     // ==== IGraphics ====
53 
54     @Override
drawBoxedStrings(int x, int y, @NonNull List<?> strings)55     public void drawBoxedStrings(int x, int y, @NonNull List<?> strings) {
56         mDrawn.add("drawBoxedStrings(" + x + "," + y + "," + strings + ")");
57     }
58 
59     @Override
drawLine(int x1, int y1, int x2, int y2)60     public void drawLine(int x1, int y1, int x2, int y2) {
61         mDrawn.add("drawLine(" + x1 + "," + y1 + "," + x2 + "," + y2 + ")");
62     }
63 
64     @Override
drawLine(@onNull Point p1, @NonNull Point p2)65     public void drawLine(@NonNull Point p1, @NonNull Point p2) {
66         mDrawn.add("drawLine(" + p1 + "," + p2 + ")");
67     }
68 
69     @Override
drawRect(int x1, int y1, int x2, int y2)70     public void drawRect(int x1, int y1, int x2, int y2) {
71         mDrawn.add("drawRect(" + x1 + "," + y1 + "," + x2 + "," + y2 + ")");
72     }
73 
74     @Override
drawRect(@onNull Point p1, @NonNull Point p2)75     public void drawRect(@NonNull Point p1, @NonNull Point p2) {
76         mDrawn.add("drawRect(" + p1 + "," + p2 + ")");
77     }
78 
79     @Override
drawRect(@onNull Rect r)80     public void drawRect(@NonNull Rect r) {
81         mDrawn.add("drawRect(" + rectToString(r) + ")");
82     }
83 
84     @Override
drawString(@onNull String string, int x, int y)85     public void drawString(@NonNull String string, int x, int y) {
86         mDrawn.add("drawString(" + x + "," + y + "," + string + ")");
87     }
88 
89     @Override
drawString(@onNull String string, @NonNull Point topLeft)90     public void drawString(@NonNull String string, @NonNull Point topLeft) {
91         mDrawn.add("drawString(" + string + "," + topLeft + ")");
92     }
93 
94     @Override
fillRect(int x1, int y1, int x2, int y2)95     public void fillRect(int x1, int y1, int x2, int y2) {
96         mDrawn.add("fillRect(" + x1 + "," + y1 + "," + x2 + "," + y2 + ")");
97     }
98 
99     @Override
fillRect(@onNull Point p1, @NonNull Point p2)100     public void fillRect(@NonNull Point p1, @NonNull Point p2) {
101         mDrawn.add("fillRect(" + p1 + "," + p2 + ")");
102     }
103 
104     @Override
fillRect(@onNull Rect r)105     public void fillRect(@NonNull Rect r) {
106         mDrawn.add("fillRect(" + rectToString(r) + ")");
107     }
108 
109     @Override
getAlpha()110     public int getAlpha() {
111         return mAlpha;
112     }
113 
114     @Override
getBackground()115     public @NonNull IColor getBackground() {
116         return mBackground;
117     }
118 
119     @Override
getFontHeight()120     public int getFontHeight() {
121         return 12;
122     }
123 
124     @Override
getForeground()125     public @NonNull IColor getForeground() {
126         return mForeground;
127     }
128 
129     @Override
registerColor(int rgb)130     public @NonNull IColor registerColor(int rgb) {
131         mDrawn.add("registerColor(" + Integer.toHexString(rgb) + ")");
132         return new TestColor(rgb);
133     }
134 
135     @Override
setAlpha(int alpha)136     public void setAlpha(int alpha) {
137         mAlpha = alpha;
138         mDrawn.add("setAlpha(" + alpha + ")");
139     }
140 
141     @Override
setBackground(@onNull IColor color)142     public void setBackground(@NonNull IColor color) {
143         mDrawn.add("setBackground(" + color + ")");
144         mBackground = color;
145     }
146 
147     @Override
setForeground(@onNull IColor color)148     public void setForeground(@NonNull IColor color) {
149         mDrawn.add("setForeground(" + color + ")");
150         mForeground = color;
151     }
152 
153     @Override
setLineStyle(@onNull LineStyle style)154     public void setLineStyle(@NonNull LineStyle style) {
155         mDrawn.add("setLineStyle(" + style + ")");
156     }
157 
158     @Override
setLineWidth(int width)159     public void setLineWidth(int width) {
160         mDrawn.add("setLineWidth(" + width + ")");
161     }
162 
163     @Override
useStyle(@onNull DrawingStyle style)164     public void useStyle(@NonNull DrawingStyle style) {
165         mDrawn.add("useStyle(" + style + ")");
166     }
167 
168     @Override
drawArrow(int x1, int y1, int x2, int y2, int size)169     public void drawArrow(int x1, int y1, int x2, int y2, int size) {
170         mDrawn.add("drawArrow(" + x1 + "," + y1 + "," + x2 + "," + y2 + ")");
171     }
172 
173     @Override
drawPoint(int x, int y)174     public void drawPoint(int x, int y) {
175         mDrawn.add("drawPoint(" + x + "," + y + ")");
176     }
177 
rectToString(Rect rect)178     private static String rectToString(Rect rect) {
179         return "Rect[" + rect.x + "," + rect.y + "," + rect.w + "," + rect.h + "]";
180     }
181 }
182