00001
00002
00003
00004 package org.math.plot.render;
00005
00006 import java.awt.*;
00007
00008 import org.math.plot.canvas.*;
00009 import org.math.plot.plotObjects.Label;
00010 import org.math.plot.utils.*;
00011
00012 public abstract class AbstractDrawer {
00013
00014
00015
00016 public PlotCanvas canvas;
00017
00018 protected Graphics2D comp2D;
00019
00020 public final static int ROUND_DOT = 1;
00021
00022 public final static int CROSS_DOT = 2;
00023
00024 public final static int PATTERN_DOT = 0;
00025
00026 public final static int CONTINOUS_LINE = 1;
00027
00028 public final static int DOTTED_LINE = 2;
00029
00030 public final static int DEFAULT_DOT_RADIUS = 2;
00031
00032 public final static int DEFAULT_LINE_WIDTH = 1;
00033
00034 public final static boolean[][] DOT_TRIANGLE_PATTERN = stringToPattern("_", "___#___", "__#_#__", "__#_#__", "_#___#_", "_#___#_", "#######");
00035
00036 public final static boolean[][] DOT_SQUARE_PATTERN = stringToPattern("_", "######", "#____#", "#____#", "#____#", "#____#", "######");
00037
00038 public final static Font DEFAULT_FONT = new Font("BitStream Vera Sans", Font.PLAIN, 12);
00039
00040 public final static Color DEFAULT_COLOR = Color.BLACK;
00041
00042 protected Font font = DEFAULT_FONT;
00043
00044 protected double text_Eastoffset, text_Northoffset;
00045
00046 protected double text_angle;
00047
00048 protected Color color = DEFAULT_COLOR;
00049
00050 protected double[] base_offset;
00051
00052 protected int[] screen_offset;
00053
00054
00055
00056 protected int dot_type = ROUND_DOT;
00057
00058 protected int dot_radius = DEFAULT_DOT_RADIUS;
00059
00060 protected boolean[][] dot_pattern = DOT_TRIANGLE_PATTERN;
00061
00062 protected int line_type = CONTINOUS_LINE;
00063
00064 protected int line_width = DEFAULT_LINE_WIDTH;
00065
00066
00067
00068 public AbstractDrawer(PlotCanvas _canvas) {
00069 canvas = _canvas;
00070 }
00071
00075 public void initGraphics(Graphics2D _comp2D) {
00076 comp2D = _comp2D;
00077 }
00078
00083 public abstract void resetBaseProjection();
00084
00085 public void setColor(Color c) {
00086 color = c;
00087 }
00088
00089 public abstract void setGradient(double[] xy0, Color c0, double[] xy1, Color c1);
00090
00091 public void resetGradient() {
00092 comp2D.setPaint(color);
00093 }
00094
00095
00096 public void setFont(Font f) {
00097 font = f;
00098 }
00099
00100 public void setTextOffset(double _cornerEast, double _cornerNorth) {
00101 text_Eastoffset = _cornerEast;
00102 text_Northoffset = _cornerNorth;
00103 }
00104
00105 public void setTextAngle(double _angle) {
00106 text_angle = _angle;
00107 }
00108
00109 public void setDotType(int _dot_type) {
00110 dot_type = _dot_type;
00111 }
00112
00113 public void setDotRadius(int _dot_radius) {
00114 dot_radius = _dot_radius;
00115 }
00116
00117 public void setDotPattern(boolean[][] _dot_pattern) {
00118 dot_pattern = _dot_pattern;
00119 }
00120
00121 public void setLineType(int _line_type) {
00122 line_type = _line_type;
00123 }
00124
00125 public void setLineWidth(int _line_width) {
00126 line_width = _line_width;
00127 }
00128
00129 public void setBaseOffset(double... _boffset) {
00130 base_offset = _boffset;
00131 }
00132
00133 public void setScreenOffset(int... _soffset) {
00134 screen_offset = _soffset;
00135 }
00136
00137
00138
00139
00140
00141 public Color getColor() {
00142 return color;
00143 }
00144
00145 public Font getFont() {
00146 return font;
00147 }
00148
00149 public double[] getTextOffset() {
00150 return new double[] { text_Eastoffset, text_Northoffset };
00151 }
00152
00153 public double getTextAngle() {
00154 return text_angle;
00155 }
00156
00157 public int getDotType() {
00158 return dot_type;
00159 }
00160
00161 public int getDotRadius() {
00162 return dot_radius;
00163 }
00164
00165 public boolean[][] getDotPattern() {
00166 return dot_pattern;
00167 }
00168
00169 public double[] getBaseOffset() {
00170 return base_offset;
00171 }
00172
00173 public int[] getScreenOffset() {
00174 return screen_offset;
00175 }
00176
00185 public abstract int[] project(double... pC);
00186
00195 public abstract int[] projectBase(double... rC);
00196
00203 public abstract void translate(int... t);
00204
00213 public abstract void dilate(int[] screenOrigin, double[] screenRatio);
00214
00215 public void drawCoordinate(double[] pC) {
00216 for (int i = 0; i < pC.length; i++) {
00217 double[] axeprojection = Array.copy(pC);
00218 axeprojection[i] = canvas.base.baseCoords[0][i];
00219 drawLine(pC, axeprojection);
00220 }
00221 setTextAngle(0);
00222 setTextOffset(0, 0);
00223
00224 }
00225
00226 public abstract void drawText(String label, double... pC);
00227
00228 public abstract void drawTextBase(String label, double... rC);
00229
00230 public abstract void drawLineBase(double[]... rC);
00231
00232 public abstract void drawLine(double[]... pC);
00233
00234 public abstract void drawDot(double... pC);
00235
00236 public abstract void drawPolygon(double[]... pC);
00237
00238 public abstract void fillPolygon(float alpha,double[]... pC);
00239
00240 public abstract void drawImage(Image img, float alpha,double[] _xyzSW, double[] _xyzSE,double[] _xyzNW);
00241
00242
00243
00244
00245 public static boolean[][] stringToPattern(String empty, String... c) {
00246 boolean[][] p = new boolean[c.length][];
00247 for (int i = 0; i < p.length; i++)
00248 p[i] = stringToPattern(empty, c[i]);
00249 return p;
00250 }
00251
00252 public static boolean[] stringToPattern(String empty, String c) {
00253 boolean[] p = new boolean[c.length()];
00254 for (int i = 0; i < p.length; i++)
00255 p[i] = !(c.substring(i, i + 1).equals(empty));
00256 return p;
00257 }
00258 }