Back to index

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