10 package com.generalrobotix.ui.view.graph;
15 import java.awt.image.ImageObserver;
16 import java.text.AttributedCharacterIterator;
29 private static final String
HEADER =
"%!PS-Adobe-3.0 EPSF-3.0";
31 private static final String
DEF =
"/";
32 private static final String
BIND_DEF =
" bind def";
33 private static final String
EOF =
"%%EOF";
51 = DEF + SET_COLOR_WHITE +
" {0.3 setlinewidth 0 setgray [] 0 setdash}" +
BIND_DEF;
53 = DEF + SET_COLOR_LIGHTGRAY +
" {0.3 setlinewidth 0.2 setgray [] 0 setdash}" +
BIND_DEF;
55 = DEF + SET_COLOR_GRAY +
" {0.3 setlinewidth 0.5 setgray [] 0 setdash}" +
BIND_DEF;
57 = DEF + SET_COLOR_DARKGRAY +
" {0.3 setlinewidth 0.7 setgray [] 0 setdash}" +
BIND_DEF;
59 = DEF + SET_COLOR_BLACK +
" {0.3 setlinewidth 1 setgray [] 0 setdash}" +
BIND_DEF;
61 = DEF + SET_COLOR_OTHERS +
" {0.3 setlinewidth 0 setgray [] 0 setdash}" +
BIND_DEF;
63 = DEF + SET_COLOR_GREEN +
" {0.3 setlinewidth 0 setgray [] 0 setdash}" +
BIND_DEF;
65 = DEF + SET_COLOR_YELLOW +
" {0.3 setlinewidth 0.4 setgray [] 0 setdash}" +
BIND_DEF;
67 = DEF + SET_COLOR_PINK +
" {0.3 setlinewidth 0.7 setgray [] 0 setdash}" +
BIND_DEF;
69 = DEF + SET_COLOR_CYAN +
" {0.6 setlinewidth 0.7 setgray [] 0 setdash}" +
BIND_DEF;
71 = DEF + SET_COLOR_MAGENTA +
" {0.9 setlinewidth 0 setgray [] 0 setdash}" +
BIND_DEF;
73 = DEF + SET_COLOR_RED +
" {0.9 setlinewidth 0.7 setgray [] 0 setdash}" +
BIND_DEF;
75 = DEF + SET_COLOR_ORANGE +
" {0.9 setlinewidth 0 setgray [6 2 2 2] 0 setdash}" +
BIND_DEF;
77 = DEF + SET_COLOR_BLUE +
" {0.9 setlinewidth 0.7 setgray [6 2 2 2] 0 setdash}" +
BIND_DEF;
81 private static final String
SET_FONT =
"setFont";
83 private static final String
SET_CLIP =
"setClip";
85 private static final String
NEWPATH =
"N";
86 private static final String
MOVETO =
"M";
87 private static final String
LINETO =
"L";
88 private static final String
STROKE =
"S";
91 = DEF + DRAW_LINE +
" {newpath moveto lineto stroke}" +
BIND_DEF;
93 = DEF + SET_FONT +
" {exch findfont exch scalefont setfont}" +
BIND_DEF;
95 = DEF + DRAW_STRING +
" {moveto show}" +
BIND_DEF;
98 +
" {gsave newpath 3 index 3 index moveto dup 0 exch" 99 +
" rlineto exch 0 rlineto 0 exch sub 0 exch" 100 +
" rlineto pop pop closepath clip}" 114 private PrintWriter
pw;
146 colorList_ =
new ArrayList<Color>();
147 colorList_.add(Color.white);
148 colorList_.add(Color.lightGray);
149 colorList_.add(Color.gray);
150 colorList_.add(Color.darkGray);
151 colorList_.add(Color.black);
152 colorList_.add(Color.green);
153 colorList_.add(Color.yellow);
154 colorList_.add(Color.pink);
155 colorList_.add(Color.cyan);
156 colorList_.add(Color.magenta);
157 colorList_.add(Color.red);
158 colorList_.add(Color.orange);
159 colorList_.add(Color.blue);
160 colorOps_ =
new ArrayList<String>();
161 colorOps_.add(SET_COLOR_WHITE);
162 colorOps_.add(SET_COLOR_LIGHTGRAY);
163 colorOps_.add(SET_COLOR_GRAY);
164 colorOps_.add(SET_COLOR_DARKGRAY);
165 colorOps_.add(SET_COLOR_BLACK);
166 colorOps_.add(SET_COLOR_GREEN);
167 colorOps_.add(SET_COLOR_YELLOW);
168 colorOps_.add(SET_COLOR_PINK);
169 colorOps_.add(SET_COLOR_CYAN);
170 colorOps_.add(SET_COLOR_MAGENTA);
171 colorOps_.add(SET_COLOR_RED);
172 colorOps_.add(SET_COLOR_ORANGE);
173 colorOps_.add(SET_COLOR_BLUE);
180 pw =
new PrintWriter(writer);
221 pw.println(
"" + width +
" setlinewidth");
243 int ind = colorList_.indexOf(c);
246 col = (String)colorOps_.get(ind);
273 public void drawLine(
int x1,
int y1,
int x2,
int y2) {
276 if (prevX_ == x1 && prevY_ == y1) {
278 sb =
new StringBuffer();
279 sb.append(x2 / scale_ + xOfs_);
280 sb.append(
' '); sb.append(PAGE_HEIGHT - y2 / scale_ - yOfs_);
281 sb.append(
' '); sb.append(LINETO);
282 pw.println(sb.toString());
288 sb =
new StringBuffer(STROKE);
289 sb.append(
' '); sb.append(NEWPATH);
290 sb.append(
' '); sb.append(x1 / scale_ + xOfs_);
291 sb.append(
' '); sb.append(PAGE_HEIGHT - y1 / scale_ - yOfs_);
292 sb.append(
' '); sb.append(MOVETO);
293 sb.append(
'\n'); sb.append(x2 / scale_ + xOfs_);
294 sb.append(
' '); sb.append(PAGE_HEIGHT - y2 / scale_ - yOfs_);
295 sb.append(
' '); sb.append(LINETO);
296 pw.println(sb.toString());
302 sb =
new StringBuffer(NEWPATH);
303 sb.append(
' '); sb.append(x1 / scale_ + xOfs_);
304 sb.append(
' '); sb.append(PAGE_HEIGHT - y1 / scale_ - yOfs_);
305 sb.append(
' '); sb.append(MOVETO);
306 sb.append(
'\n'); sb.append(x2 / scale_ + xOfs_);
307 sb.append(
' '); sb.append(PAGE_HEIGHT - y2 / scale_ - yOfs_);
308 sb.append(
' '); sb.append(LINETO);
309 pw.println(sb.toString());
312 prevX_ = x2; prevY_ = y2;
332 StringBuffer sb =
new StringBuffer(
"/");
336 String fname = font.getName();
338 if (fname.equals(
"dialog")) {
340 }
else if (fname.equals(
"monospaced")) {
347 sb.append(
' '); sb.append(font.getSize());
348 sb.append(
' '); sb.append(SET_FONT);
349 pw.println(sb.toString());
361 StringBuffer sb =
new StringBuffer(
"(");
362 int len = str.length();
363 for (
int i = 0;
i < len;
i++) {
364 char c = str.charAt(
i);
365 if (c ==
'(' || c ==
')') {
370 sb.append(
") "); sb.append(x / scale_ + xOfs_);
371 sb.append(
' '); sb.append(PAGE_HEIGHT - y / scale_ - yOfs_);
372 sb.append(
' '); sb.append(DRAW_STRING);
373 pw.println(sb.toString());
384 pw.println(SET_CLIP_NULL);
398 StringBuffer sb =
new StringBuffer();
399 sb.append(x / scale_ + xOfs_);
400 sb.append(
' '); sb.append(PAGE_HEIGHT - (y + height) / scale_ - yOfs_);
401 sb.append(
' '); sb.append(width / scale_);
402 sb.append(
' '); sb.append(height / scale_);
403 sb.append(
' '); sb.append(SET_CLIP);
404 pw.println(sb.toString());
451 int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight
454 int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight
459 int x,
int y,
int width,
int height,
int startAngle,
int arcAngle
462 int x,
int y,
int width,
int height,
int startAngle,
int arcAngle
464 public void drawPolyline(
int xPoints[],
int yPoints[],
int nPoints) { }
465 public void drawPolygon(
int xPoints[],
int yPoints[],
int nPoints) { }
466 public void fillPolygon(
int xPoints[],
int yPoints[],
int nPoints) { }
468 AttributedCharacterIterator iterator,
int x,
int y 471 Image img,
int x,
int y, ImageObserver observer
476 Image img,
int x,
int y,
int width,
int height, ImageObserver observer
481 Image img,
int x,
int y, Color bgcolor, ImageObserver observer
487 Color bgcolor, ImageObserver observer
492 Image img,
int dx1,
int dy1,
int dx2,
int dy2,
493 int sx1,
int sy1,
int sx2,
int sy2, ImageObserver observer
498 Image img,
int dx1,
int dy1,
int dx2,
int dy2,
499 int sx1,
int sy1,
int sx2,
int sy2, Color bgcolor, ImageObserver observer
526 int bb = PAGE_HEIGHT - (top +
height);
527 int br = left +
width;
528 int bt = PAGE_HEIGHT - top;
532 StringBuffer sb =
new StringBuffer(BOUNDING_BOX);
533 sb.append(
' '); sb.append(bl);
534 sb.append(
' '); sb.append(bb);
535 sb.append(
' '); sb.append(br);
536 sb.append(
' '); sb.append(bt);
537 pw.println(sb.toString());
541 pw.println(
"% Color definition");
543 for (
int i = 0;
i < colorList_.size();
i++) {
544 Color col = (Color)colorList_.get(
i);
545 StringBuffer sbuf =
new StringBuffer(DEF);
546 sbuf.append((String)colorOps_.get(
i));
547 sbuf.append(
" {0.3 setlinewidth 0 setgray [] 0 setdash ");
548 sbuf.append((255 - col.getRed()) / 255.0
f);
550 sbuf.append((255 - col.getGreen()) / 255.0
f);
552 sbuf.append((255 - col.getBlue()) / 255.0
f);
553 sbuf.append(
" setrgbcolor}");
554 sbuf.append(BIND_DEF);
555 pw.println(sbuf.toString());
577 pw.println(
"% Method definition");
583 pw.println(DEF_NEWPATH);
584 pw.println(DEF_MOVETO);
585 pw.println(DEF_LINETO);
586 pw.println(DEF_STROKE);
590 pw.println(
"% end of header");
594 pw.println(
"newpath");
595 pw.println(
"" + bl +
" " + bb +
" moveto");
596 pw.println(
"" + br +
" " + bb +
" lineto");
597 pw.println(
"" + br +
" " + bt +
" lineto");
598 pw.println(
"" + bl +
" " + bt +
" lineto");
599 pw.println(
"closepath");
600 pw.println(
"stroke");
static final String DEF_SET_FONT
static final String HEADER
static final String MOVETO
static final String DEF_COLOR_MAGENTA
void drawOval(int x, int y, int width, int height)
void drawString(AttributedCharacterIterator iterator, int x, int y)
static final String DEF_SET_CLIP
static final String DEF_COLOR_GREEN
static final String SET_COLOR_MAGENTA
#define null
our own NULL pointer
void setLineWidth(double width)
void fillRect(int x, int y, int width, int height)
FontMetrics getFontMetrics(Font f)
static final String SET_COLOR_CYAN
static final String SET_COLOR_LIGHTGRAY
static final String DEF_COLOR_BLUE
static final String BIND_DEF
static final String SET_COLOR_YELLOW
static final String DEF_NEWPATH
static final int PAGE_HEIGHT
boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
void fillPolygon(int xPoints[], int yPoints[], int nPoints)
static final String DEF_COLOR_WHITE
static final String SET_COLOR_BLACK
static final String SET_COLOR_OTHERS
static final String SET_COLOR_BLUE
void fillOval(int x, int y, int width, int height)
static final String DEF_COLOR_BLACK
static final String DEF_COLOR_LIGHTGRAY
static final String DEF_COLOR_RED
png_infop png_uint_32 * width
static final String DEF_COLOR_YELLOW
static final String SET_CLIP_NULL
void drawLine(int x1, int y1, int x2, int y2)
static final String DEF_COLOR_CYAN
static final String DEF_COLOR_OTHERS
static final String SET_COLOR_RED
void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
static final String DEF_DRAW_LINE
void drawPolyline(int xPoints[], int yPoints[], int nPoints)
static final String DEF_MOVETO
void setXOffset(int xofs)
static final String SET_COLOR_WHITE
static final String SET_CLIP
static final String LINETO
void drawString(String str, int x, int y)
static final String SET_COLOR_DARKGRAY
EPSGraphics(Writer writer, int top, int left, int width, int height, boolean color)
static final String DEF_LINETO
static final String BOUNDING_BOX
static final String SET_COLOR_GREEN
static final String DEF_SET_CLIP_NULL
png_infop png_uint_32 png_uint_32 * height
void _writeHeader(int top, int left, int width, int height, boolean color)
void drawPolygon(int xPoints[], int yPoints[], int nPoints)
static final String SET_COLOR_ORANGE
ArrayList< Color > colorList_
static final String SET_COLOR_PINK
void setScale(double scale)
static final String DEF_COLOR_GRAY
void copyArea(int x, int y, int width, int height, int dx, int dy)
void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
static final String SET_FONT
boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
void clearRect(int x, int y, int width, int height)
boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
static final String DEF_COLOR_DARKGRAY
static final String STROKE
ArrayList< String > colorOps_
static final String DEF_COLOR_ORANGE
static final String DEF_STROKE
void setYOffset(int yofs)
void translate(int x, int y)
static final String DRAW_STRING
boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
void setClip(int x, int y, int width, int height)
static final String NEWPATH
Rectangle getClipBounds()
boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
static final String DEF_DRAW_STRING
static final String SET_COLOR_GRAY
static final String DEF_COLOR_PINK
void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
boolean drawImage(Image img, int x, int y, ImageObserver observer)
void clipRect(int x, int y, int width, int height)
static final String DRAW_LINE