Home | History | Annotate | Download | only in layout
      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     public void drawBoxedStrings(int x, int y, List<?> strings) {
     54         mDrawn.add("drawBoxedStrings(" + x + "," + y + "," + strings + ")");
     55     }
     56 
     57     public void drawLine(int x1, int y1, int x2, int y2) {
     58         mDrawn.add("drawLine(" + x1 + "," + y1 + "," + x2 + "," + y2 + ")");
     59     }
     60 
     61     public void drawLine(Point p1, Point p2) {
     62         mDrawn.add("drawLine(" + p1 + "," + p2 + ")");
     63     }
     64 
     65     public void drawRect(int x1, int y1, int x2, int y2) {
     66         mDrawn.add("drawRect(" + x1 + "," + y1 + "," + x2 + "," + y2 + ")");
     67     }
     68 
     69     public void drawRect(Point p1, Point p2) {
     70         mDrawn.add("drawRect(" + p1 + "," + p2 + ")");
     71     }
     72 
     73     public void drawRect(Rect r) {
     74         mDrawn.add("drawRect(" + rectToString(r) + ")");
     75     }
     76 
     77     public void drawString(String string, int x, int y) {
     78         mDrawn.add("drawString(" + x + "," + y + "," + string + ")");
     79     }
     80 
     81     public void drawString(String string, Point topLeft) {
     82         mDrawn.add("drawString(" + string + "," + topLeft + ")");
     83     }
     84 
     85     public void fillRect(int x1, int y1, int x2, int y2) {
     86         mDrawn.add("fillRect(" + x1 + "," + y1 + "," + x2 + "," + y2 + ")");
     87     }
     88 
     89     public void fillRect(Point p1, Point p2) {
     90         mDrawn.add("fillRect(" + p1 + "," + p2 + ")");
     91     }
     92 
     93     public void fillRect(Rect r) {
     94         mDrawn.add("fillRect(" + rectToString(r) + ")");
     95     }
     96 
     97     public int getAlpha() {
     98         return mAlpha;
     99     }
    100 
    101     public IColor getBackground() {
    102         return mBackground;
    103     }
    104 
    105     public int getFontHeight() {
    106         return 12;
    107     }
    108 
    109     public IColor getForeground() {
    110         return mForeground;
    111     }
    112 
    113     public IColor registerColor(int rgb) {
    114         mDrawn.add("registerColor(" + Integer.toHexString(rgb) + ")");
    115         return new TestColor(rgb);
    116     }
    117 
    118     public void setAlpha(int alpha) {
    119         mAlpha = alpha;
    120         mDrawn.add("setAlpha(" + alpha + ")");
    121     }
    122 
    123     public void setBackground(IColor color) {
    124         mDrawn.add("setBackground(" + color + ")");
    125         mBackground = color;
    126     }
    127 
    128     public void setForeground(IColor color) {
    129         mDrawn.add("setForeground(" + color + ")");
    130         mForeground = color;
    131     }
    132 
    133     public void setLineStyle(LineStyle style) {
    134         mDrawn.add("setLineStyle(" + style + ")");
    135     }
    136 
    137     public void setLineWidth(int width) {
    138         mDrawn.add("setLineWidth(" + width + ")");
    139     }
    140 
    141     public void useStyle(DrawingStyle style) {
    142         mDrawn.add("useStyle(" + style + ")");
    143     }
    144 
    145     public void drawArrow(int x1, int y1, int x2, int y2, int size) {
    146         mDrawn.add("drawArrow(" + x1 + "," + y1 + "," + x2 + "," + y2 + ")");
    147     }
    148 
    149     public void drawPoint(int x, int y) {
    150         mDrawn.add("drawPoint(" + x + "," + y + ")");
    151     }
    152 
    153     private static String rectToString(Rect rect) {
    154         return "Rect[" + rect.x + "," + rect.y + "," + rect.w + "," + rect.h + "]";
    155     }
    156 }
    157