1 package devisor2.grid.GUI.framework;
2 
3 import java.awt.*;
4 import java.awt.image.*;
5 import java.awt.geom.*;
6 import java.awt.event.*;
7 import java.io.*;
8 import java.text.*;
9 import java.util.*;
10 import javax.swing.*;
11 import devisor2.grid.GUI.event.*;
12 import devisor2.grid.options.*;
13 import devisor2.grid.backend.*;
14 
15 /**
16  *  This class DrawingArea represent the place where the domains
17  *  are to be drawn. It is part of the MainFrame and connected to
18  *  the rest of the application via the centerfold reference.
19  *  <br>
20  *  It does not have any real functionality, this is left to the
21  *  GridListener instance responsible attached to it. See there for
22  *  details. the only thing supported is managing the horizontal and
23  *  vertival scrollbars. <br>
24  *
25  *  @author Christian Becker, Dominik Goeddeke
26  *  @version beta
27  */
28 public class PSGraphics extends Graphics
29 {
30   /**
31    * stream object for the postscript output
32    */
33   DataOutputStream out;
34 
35   int FW,FH;
36 
37   int PSX;
38   int PSY;
39 
40   double kx,ky;
41 
42   boolean landscape;
43 
PSGraphics()44    public PSGraphics()
45    {
46    }
47 
PSGraphics(String file,int ufw, int ufh, boolean ls)48    public PSGraphics(String file,int ufw, int ufh, boolean ls)
49    {
50 
51      FW=ufw;
52      FH=ufh;
53      landscape=ls;
54 
55      int rw=210;
56      int rh=297;
57 
58    try
59     {
60       FileOutputStream writeFile = new FileOutputStream(file);
61       out = new DataOutputStream( writeFile );
62 
63       out.writeBytes("%!PS-Adobe-2.0\n");  // write PS header
64 
65       out.writeBytes("%%Title: "+file+"\n");
66       out.writeBytes("%%Creator: DeViSoRGrid2\n");
67 
68 
69       if (landscape)
70       {
71         kx=(0.8*rh)/FW;
72 	ky=kx;
73 
74 	PSY=(int)0.1*rh;
75 	PSX=(int)(rh-(kx*FH))/2;
76 
77         out.writeBytes("%%BoundingBox: "+(PSX/25.4*72)+" "
78           +(PSY/25.4*72)+" "+(PSX+kx*FH)/25.4*72+" "+(PSY+ky*FW)/25.4*72+"\n");
79       }
80       else
81       {
82         kx=(0.8*rw)/FW;
83 	ky=kx;
84 
85 	PSX=(int)0.1*rw;
86 	PSY=(int)(rh-(kx*FH))/2;
87 
88         out.writeBytes("%%BoundingBox: "+(PSX/25.4*72)+" "
89           +(PSY/25.4*72)+" "+(PSX+kx*FW)/25.4*72+" "+(PSY+ky*FH)/25.4*72+"\n");
90       }
91 
92       out.writeBytes("%%Pages: 1\n");
93       out.writeBytes("%%DocumentFonts:\n");
94       out.writeBytes("%%EndComments\n");
95       out.writeBytes("%%EndProlog\n");
96       out.writeBytes("\n");
97 
98 //      out.writeBytes("newpath "+(PSX/25.4*72)+" "+(PSY/25.4*72)+" moveto\n");
99 //      out.writeBytes(((PSX+kx*FW)/25.4*72)+" "+(PSY/25.4*72)+" lineto\n");
100 //      out.writeBytes(((PSX+kx*FW)/25.4*72)+" "+(PSY+ky*FH)/25.4*72+" lineto\n");
101 //      out.writeBytes(((PSX)/25.4*72)+" "+(PSY+ky*FH)/25.4*72+" lineto\n");
102 //      out.writeBytes(((PSX)/25.4*72)+" "+(PSY)/25.4*72+" lineto\n");
103 //      out.writeBytes("clip closepath stroke\n");
104 
105       out.writeBytes("72 25.4 div dup scale\n");
106       out.writeBytes("0.15 setlinewidth\n");
107       out.writeBytes("/DeviceRGB setcolorspace\n");
108           out.writeBytes("/Times-Roman findfont 2 scalefont setfont \n");
109 
110 
111 //drawLine(0,0,FW,FH);
112 //drawLine(0,FH,FW,0);
113 //drawLine(0,0,FW,0);
114 //drawLine(FW,0,FW,FH);
115 //drawLine(FW,FH,0,FH);
116 //drawLine(0,FH,0,0);
117 
118     }
119     catch(IOException exp)
120     {
121       System.out.println("ERROR:Metagraph:constructor "+exp);
122     }
123 
124 
125    }
126 
127 
128 
129  /**
130    * closes an output
131    */
close()132    public void close()
133    {
134      if (out!=null)
135      {
136       try
137       {
138         out.writeBytes("showpage");
139 
140         out.close();
141       }
142       catch(IOException exp)
143       {
144         System.err.println("ERROR:Metagraph:close "+exp);
145       }
146 
147      }
148    }
149 
drawLine(int x1, int y1, int x2, int y2)150    public void drawLine(int x1, int y1, int x2, int y2)
151    {
152       try
153       {
154         out.writeBytes("newpath \n");
155 	if (landscape)
156          out.writeBytes(""+(PSX+y1*kx)+" "+(x1*ky+PSY)+" moveto "
157           +(PSX+y2*kx)+" "+(x2*ky+PSY)+" lineto \n");
158 	else
159 	 out.writeBytes(""+(PSX+x1*kx)+" "+((FH-y1)*ky+PSY)+" moveto "
160           +(PSX+x2*kx)+" "+((FH-y2)*ky+PSY)+" lineto \n");
161         out.writeBytes("stroke \n");
162 
163       }
164       catch(IOException exp)
165       {
166         System.err.println("ERROR:Metagraph:drawLineM "+exp);
167       }
168    }
169 
dispose()170    public void dispose()
171    {
172    }
173 
drawImage(Image img, int x, int y, ImageObserver observer)174   public boolean drawImage(Image img, int x, int y,
175                            ImageObserver observer)
176   {
177     return false;
178   }
179 
drawImage(Image img, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, ImageObserver observer)180   public boolean drawImage(Image img, int x1, int y1,
181                            int x2, int y2,
182                            int x3, int y3, int x4, int y4,
183                            ImageObserver observer)
184   {
185     return false;
186   }
187 
drawImage(Image img, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, Color c, ImageObserver observer)188   public boolean drawImage(Image img, int x1, int y1,
189                            int x2, int y2,
190                            int x3, int y3, int x4, int y4,
191                            Color c,
192                            ImageObserver observer)
193   {
194     return false;
195   }
196 
drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)197   public boolean drawImage(Image img, int x, int y,
198                            int width, int height,
199                            ImageObserver observer)
200   {
201     return false;
202   }
203 
drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)204   public boolean drawImage(Image img, int x, int y, Color bgcolor,
205                            ImageObserver observer)
206   {
207     return false;
208   }
209 
drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)210   public boolean drawImage(Image img, int x, int y,
211                            int width, int height, Color bgcolor,
212                            ImageObserver observer)
213   {
214     return false;
215   }
216 
drawString(String str, int x, int y)217   public void drawString(String str, int x, int y)
218   {
219      try
220       {
221         if (landscape)
222         out.writeBytes(""+(PSX+y*kx)+" "+(PSY+x*ky)+" moveto 90 rotate ("+str+") show -90 rotate\n");
223 	else
224         out.writeBytes(""+(PSX+x*kx)+" "+(PSY+(FH-y)*ky)+" moveto ("+str+") show \n");
225       }
226       catch(IOException exp)
227       {
228         System.err.println("ERROR:Metagraph:drawStringM "+exp);
229       }
230   }
231 
drawString(AttributedCharacterIterator str, int x, int y)232   public void drawString(AttributedCharacterIterator str, int x, int y)
233   {
234   }
235 
fillPolygon(int xPoints[], int yPoints[], int nPoints)236   public void fillPolygon(int xPoints[], int yPoints[], int nPoints)
237   {
238   }
239 
fillPolygon(Polygon p)240   public void fillPolygon(Polygon p)
241   {
242        try
243        {
244         if (landscape)
245         System.err.println("ERROR:yet not implemented");
246  //       out.writeBytes(""+(PSX+y*kx)+" "+(PSY+x*kx)
247    //       +" "+height*kx+" "+width*ky+" rectfill \n");
248 	else
249 	{
250 	out.writeBytes("newpath \n");
251 	out.writeBytes((PSX+p.xpoints[0]*kx)+" "+(PSY+(FH-p.ypoints[0])*ky)+" moveto\n");
252         for (int i=1;i<p.npoints;i++)
253 	  out.writeBytes((PSX+p.xpoints[i]*kx)+" "+(PSY+(FH-p.ypoints[i])*ky)+" lineto\n");
254 	}
255 //	  out.writeBytes((PSX+p.xpoints[0]*kx)+" "+(PSY+(FH-p.ypoints[0])*ky)+" rlineto\n");
256 	out.writeBytes("closepath fill\n");
257       }
258       catch(IOException exp)
259       {
260         System.err.println("ERROR:Metagraph:drawStringM "+exp);
261       }
262     }
263 
drawPolygon(int xPoints[], int yPoints[], int nPoints)264   public void drawPolygon(int xPoints[], int yPoints[], int nPoints)
265   {
266   }
267 
drawPolygon(Polygon p)268   public void drawPolygon(Polygon p)
269   {
270   }
271 
drawPolyline(int xPoints[], int yPoints[], int nPoints)272   public void drawPolyline(int xPoints[], int yPoints[], int nPoints)
273   {
274   }
275 
fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)276   public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
277   {
278   }
279 
drawArc(int x, int y, int width, int height, int sstartAngle, int sarcAngle)280   public void drawArc(int x, int y, int width, int height,
281                       int sstartAngle, int sarcAngle)
282   {
283       int startAngle,arcAngle;
284 
285       if (sstartAngle<0) startAngle=sstartAngle+360; else startAngle=sstartAngle;
286       if (sarcAngle<0) arcAngle=sarcAngle+360; else arcAngle=sarcAngle;
287 
288      if (startAngle>360) startAngle=startAngle-360;
289       if (arcAngle>360) arcAngle=arcAngle-360;
290 
291 	    if ((startAngle+arcAngle)==startAngle) arcAngle=arcAngle-1;
292       try
293       {
294         out.writeBytes("newpath \n");
295 	if (landscape)
296          out.writeBytes(""+((PSX+y*kx)+(width*kx)/2)+" "+((x*ky+PSY)+(width*kx)/2)+" "
297           +(width*kx)/2+" "+startAngle+" "+(startAngle+arcAngle)+" arc \n");
298 	else
299 	 out.writeBytes(""+((PSX+x*kx)+(width*kx)/2)+" "+(((FH-y)*ky+PSY)-(width*kx)/2)+" "
300           +(width*kx)/2+" "+startAngle+" "+(startAngle+arcAngle)+" arc \n");
301         out.writeBytes("stroke \n");
302 
303       }
304       catch(IOException exp)
305       {
306         System.err.println("ERROR:Metagraph:drawLineM "+exp);
307       }
308 
309   }
310 
fillOval(int x, int y, int width, int height)311   public void fillOval(int x, int y, int width, int height)
312   {
313   }
314 
drawOval(int x, int y, int width, int height)315   public void drawOval(int x, int y, int width, int height)
316   {
317   }
318 
fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)319   public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
320   {
321   }
322 
drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)323   public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
324   {
325   }
326 
clearRect(int x, int y, int width, int height)327   public void clearRect(int x, int y, int width, int height)
328   {
329   }
330 
fillRect(int x, int y, int width, int height)331   public void fillRect(int x, int y, int width, int height)
332   {
333       try
334       {
335         if (landscape)
336         out.writeBytes(""+(PSX+y*kx)+" "+(PSY+x*kx)
337           +" "+height*kx+" "+width*ky+" rectfill \n");
338 	else
339         out.writeBytes(""+(PSX+x*kx)+" "+(PSY+(FH-y)*kx)
340           +" "+width*kx+" "+height*ky+" rectfill \n");
341       }
342       catch(IOException exp)
343       {
344         System.err.println("ERROR:Metagraph:fillRectM "+exp);
345       }
346   }
347 
copyArea(int x, int y, int width, int height, int dx, int dy)348   public void copyArea(int x, int y, int width, int height, int dx, int dy)
349   {
350   }
351 
setClip(Shape s)352   public void setClip(Shape s)
353   {
354   }
355 
setClip(int x, int y, int width, int height)356   public void setClip(int x, int y, int width, int height)
357   {
358   }
359 
getClipBounds()360   public Rectangle getClipBounds()
361   {
362     return null;
363   }
364 
getClip()365   public Shape getClip()
366   {
367     return null;
368   }
369 
clipRect(int x, int y, int width, int height)370   public void clipRect(int x, int y, int width, int height)
371   {
372   }
373 
getFontMetrics()374   public FontMetrics getFontMetrics()
375   {
376     return null;
377   }
378 
getFontMetrics(Font f)379   public FontMetrics getFontMetrics(Font f)
380   {
381     return null;
382   }
383 
setFont(Font f)384   public void setFont(Font f)
385   {
386   }
387 
getFont()388   public Font getFont()
389   {
390     return null;
391   }
392 
setXORMode(Color c1)393   public void setXORMode(Color c1)
394   {
395   }
396 
setPaintMode()397   public void setPaintMode()
398   {
399   }
400 
getColor()401   public Color getColor()
402   {
403     return null;
404   }
405 
setColor(Color c)406   public void setColor(Color c)
407   {
408 
409       try
410       {
411 /**        if (c.equals(Color.white))
412           out.writeBytes("1 1 1 setcolor \n");
413         else if (c.equals(Color.red))
414           out.writeBytes("1 0 0 setcolor \n");
415         else if (c.equals(Color.blue))
416           out.writeBytes("0 0 1 setcolor \n");
417         else if (c.equals(Color.green))
418           out.writeBytes("0 1 0 setcolor \n");
419         else if (c.equals(Color.cyan))
420           out.writeBytes("1 1 0 setcolor \n");
421         else if (c.equals(Color.darkGray))
422           out.writeBytes("0.8 0.8 0.8 setcolor \n");
423         else if (c.equals(Color.gray))
424           out.writeBytes("0.4 0.4 0.4 setcolor \n");
425         else if (c.equals(Color.magenta))
426           out.writeBytes("1 0 1 setcolor \n");
427         else if (c.equals(Color.orange))
428           out.writeBytes("0.5 0 0.2 setcolor \n");
429         else if (c.equals(Color.yellow))
430           out.writeBytes("0 1 1 setcolor \n");
431         else **/
432 
433           out.writeBytes((c.getRed()/255.0)+" "+(c.getGreen()/255.0)+" "+
434 	  (c.getBlue()/255.0)+" setcolor \n");
435 
436       }
437       catch(IOException exp)
438       {
439         System.err.println("ERROR:Metagraph:setColorM "+exp);
440       }
441 
442   }
443 
translate(int x, int y)444   public void translate(int x, int y)
445   {
446   }
447 
create()448   public Graphics create()
449   {
450     return null;
451   }
452 
453 
454 }
455 
456 
457