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