Back to index

wims  3.65+svn20090927
MyGraphicsEPS.java
Go to the documentation of this file.
00001 package rene.zirkel.graphics;
00002 
00003 import java.awt.*;
00004 import java.awt.image.*;
00005 import java.io.*;
00006 
00007 import rene.gui.*;
00008 import rene.zirkel.ZirkelFrame;
00009 import rene.zirkel.objects.*;
00010 
00011 public class MyGraphicsEPS extends MyGraphics
00012 {      EPSGraphics G;
00013        static public int MaxR=1000000;
00014        double LineWidth=1;
00015 
00016        public MyGraphicsEPS (OutputStream out, int w, int h)
00017        {      G=new EPSGraphics(out,w,h,EPSGraphics.PORTRAIT,true);
00018        }
00019 
00020        public void setLineWidth (double w)
00021        {      LineWidth=w;
00022               G.setLineWidth(w);
00023        }
00024        
00025        public void clearRect (int x, int y, int w, int h, Color c)
00026        {      G.setColor(c);
00027               G.fillRect(x,y,w,h);
00028        }
00029 
00030        public void setColor (Color c)
00031        {      G.setColor(c);
00032        }
00033 
00034        public void setColor (ConstructionObject o)
00035        {      if (o.isJobTarget()) setColor(ZirkelFrame.TargetColor);
00036               else if (o.selected()) setColor(ZirkelFrame.SelectColor);
00037               else if (o.getColorType()==ConstructionObject.THIN)
00038               {      int i=o.getColorIndex();
00039                      if (o.isHidden()) setColor(ZirkelFrame.BrighterLightColors[i]);
00040                      else setColor(ZirkelFrame.LightColors[i]);                     
00041               }             
00042               else
00043               {      int i=o.getColorIndex();
00044                      if (o.isHidden()) setColor(ZirkelFrame.BrighterColors[i]);
00045                      else setColor(ZirkelFrame.Colors[i]);                   
00046               }
00047        }
00048 
00049        public void setFillColor (ConstructionObject o)
00050        {      if (o.isJobTarget()) setColor(ZirkelFrame.TargetColor);
00051               else if (o.getColorType()!=ConstructionObject.THICK)
00052               {      int i=o.getColorIndex();
00053                      if (o.isHidden()) setColor(ZirkelFrame.BrighterLightColors[i]);
00054                      else setColor(ZirkelFrame.LightColors[i]);                     
00055               }             
00056               else
00057               {      int i=o.getColorIndex();
00058                      if (o.isHidden()) setColor(ZirkelFrame.BrighterColors[i]);
00059                      else setColor(ZirkelFrame.Colors[i]);                   
00060               }
00061        }
00062 
00063        public void setLabelColor (ConstructionObject o)
00064        {      if (o.labelSelected()) setColor(ZirkelFrame.SelectColor);
00065               else if (o.isFilled())
00066               {      int type=o.getColorType();
00067                      o.setColorType(ConstructionObject.NORMAL);
00068                      setColor(o);
00069                      o.setColorType(type);
00070               }
00071               else setColor(o);
00072        }
00073 
00074        public void drawRect (double x, double y, double w, double h)
00075        {      G.drawRect(x,y,w,h);
00076        }
00077        
00078        public void drawLine (double x, double y, double x1, double y1, ConstructionObject o)
00079        {      if (o.getColorType()==ConstructionObject.THICK)
00080                      drawThickLine(x,y,x1,y1);
00081               else if (o.getColorType()==ConstructionObject.THIN)
00082                      drawThinLine(x,y,x1,y1);
00083               else
00084                      drawLine(x,y,x1,y1);
00085        }
00086 
00087        public void drawLine (double x, double y, double x1, double y1)
00088        {      G.drawLine(x,y,x1,y1);
00089        }
00090 
00091        public void drawThickLine (double c1, double r1, double c2, double r2)
00092        {      G.setLineWidth(3*LineWidth);
00093               G.drawLine(c1,r1,c2,r2);
00094               G.setLineWidth(LineWidth);
00095        }
00096 
00097        public void drawThinLine (double c1, double r1, double c2, double r2)
00098        {      G.setDash(4,4);
00099               G.drawLine(c1,r1,c2,r2);
00100               G.clearDash();
00101        }
00102 
00103        public void drawArc (double x, double y, double w, double h, double a, double b)
00104        {      G.drawArc(x,y,w,h,a,b);
00105        }
00106 
00107        public void drawThickArc (double x, double y, double w, double h, double a, double b)
00108        {      G.setLineWidth(3*LineWidth);
00109               drawArc(x+1,y+1,w-2,w-2,a,b);
00110               G.setLineWidth(LineWidth);
00111        }
00112 
00113        public void drawThinArc (double x, double y, double w, double h, double a, double b)
00114        {      G.setDash(4,4);
00115               drawArc(x+1,y+1,w-2,w-2,a,b);
00116               G.clearDash();
00117        }
00118 
00119        public void drawArc (double x, double y, double w, double h, double a, double b,
00120               ConstructionObject o)
00121        {      if (o.getColorType()==ConstructionObject.THICK)
00122                      drawThickArc(x,y,w,h,a,b);
00123               else if (o.getColorType()==ConstructionObject.THIN)
00124                      drawThinArc(x,y,w,h,a,b);
00125               else
00126                      drawArc(x,y,w,h,a,b);
00127        }
00128 
00129        public void drawString (String s, double x, double y)
00130        {      G.drawString(s,x,y);
00131        }
00132 
00133        public void drawOval (double x, double y, double w, double h)
00134        {      if (w<MaxR) G.drawOval(x,y,w,h);
00135        }
00136 
00137        public void drawThickOval (double x, double y, double w, double h)
00138        {      drawOval(x,y,w,h);
00139               drawOval(x-1,y-1,w+2,h+2);
00140               drawOval(x+1,y+1,w-2,h-2);
00141        }
00142 
00143        public void drawOval (double x, double y, double w, double h,
00144               ConstructionObject o)
00145        {      setColor(o);
00146               if (o.getColorType()==ConstructionObject.THICK)
00147                      drawThickOval(x,y,w,h);
00148               else
00149                      drawOval(x,y,w,h);
00150        }
00151 
00152        public void fillRect (double x, double y, double w, double h,
00153               boolean outline, boolean transparent, ConstructionObject o)
00154        {      setFillColor(o);
00155               G.fillRect(x,y,w,h);
00156               if (outline)
00157               {      setColor(o);
00158                      G.drawRect(x,y,w,h);
00159               }
00160        }
00161 
00162        public void fillArc (double x, double y, double w, double h, double a, double b,
00163               boolean outline, boolean transparent, boolean arc, ConstructionObject o)
00164        {      setFillColor(o);
00165               if (arc)
00166                      G.fillArc(x,y,w,h,a,b);
00167               else
00168                      G.fillChord(x,y,w,h,a,b);          
00169               if (outline)
00170               {      setColor(o);
00171                      G.drawArc(x,y,w,h,a,b);
00172               }
00173        }
00174 
00175        public void fillOval (double x, double y, double w, double h,
00176               boolean outline, boolean transparent, ConstructionObject o)
00177        {      if (w>=MaxR) return;
00178               setFillColor(o);
00179               G.fillOval(x,y,w,h);
00180               if (outline)
00181               {      setColor(o);
00182                      G.drawOval(x,y,w,h);
00183               }
00184        }
00185 
00186               public void fillPolygon (double x[], double y[], int n,
00187               boolean outline, boolean transparent, ConstructionObject o)
00188        {      if (o.getColorType()!=ConstructionObject.INVISIBLE)
00189               {      setFillColor(o);
00190                      G.fillPolygon(x,y,n);
00191               }
00192               if (outline)
00193               {      setColor(o);
00194                      G.drawPolygon(x,y,n);
00195               }
00196        }
00197 
00198        public void drawImage (Image i, int x, int y, ImageObserver o)
00199        {
00200        }      
00201 
00202        public void drawImage (Image i, int x, int y, int w, int h,
00203               ImageObserver o)
00204        {
00205        }      
00206 
00207        public void close ()
00208               throws IOException
00209        {      G.close();
00210        }
00211        
00212        int fsize;
00213        boolean flarge,fbold;
00214        int ffactor=Global.getParameter("ffactor",130);
00215        
00216        public void setDefaultFont (int h, boolean large, boolean bold)
00217        {      fsize=h; flarge=large; fbold=bold;
00218               setFont(large,bold);
00219        }
00220        
00221        public void setFont (boolean large, boolean bold)
00222        {      int size=fsize;
00223               if (large) size=size*ffactor/100;
00224               if (flarge) size=size*ffactor/100;
00225               setFont(size,bold || fbold);
00226        }
00227 
00228        public void setFont (int h, boolean bold)
00229        {      G.setFont(new Font(
00230                      Global.getParameter("font.name","dialog"),
00231                      bold?Font.BOLD:Font.PLAIN,
00232                      h));
00233        }
00234        
00235        public FontMetrics getFontMetrics ()
00236        {      return G.getFontMetrics();
00237        }
00238 
00239        public void drawImage (Image i, double x, double y, double x1, double y1, 
00240                      double x2, double y2, ImageObserver o)
00241        {
00242        }
00243 
00244        public Graphics getGraphics() {
00245               return null;
00246        }
00247 
00248        public int stringWidth(String s) 
00249        {      return getFontMetrics().stringWidth(s);
00250        }
00251 
00252        public int stringHeight(String s) 
00253        {      return getFontMetrics().getHeight();
00254        }
00255 
00256        public int drawStringExtended(String s, double x, double y) 
00257        {      drawString(s,x,y+getFontMetrics().getAscent());
00258               return getFontMetrics().getHeight(); 
00259        }
00260 
00261        public int stringAscent(String s) 
00262        {      return getFontMetrics().getAscent();
00263        }
00264 
00265 }