Back to index

wims  3.65+svn20090927
ExportScaler.java
Go to the documentation of this file.
00001 /*
00002  * Created on 07.10.2004
00003  *
00004  */
00005 package rene.zirkel.dialogs;
00006 
00007 import java.awt.*;
00008 import java.awt.event.*;
00009 
00010 import rene.gui.*;
00011 import rene.zirkel.Zirkel;
00012 import rene.zirkel.ZirkelFrame;
00013 
00018 public class ExportScaler
00019        extends HelpCloseDialog implements ItemListener
00020 {      TextFieldAction W,H,Scale,Width,Height,DPI,LineWidth,TextSize,PointSize;
00021        Checkbox Middle,Sizes,Aspect,Latex;
00022        ZirkelFrame F;
00023        boolean AbsCoord;
00024        MyChoice Presets;
00025        
00026        String Pres[]={
00027               "printscaler.preset",
00028               "printscaler.preset.300dpi",
00029               "printscaler.preset.300dpi12",
00030               "printscaler.preset.window",
00031               "printscaler.preset.clip50",
00032               "printscaler.preset.latex10"
00033        };
00034        
00035        String PresVect[]={
00036               "printscaler.preset",
00037               "printscaler.preset.300dpi",
00038               "printscaler.preset.300dpi12",
00039        };
00040        
00041        public ExportScaler (ZirkelFrame f, boolean abscoord)
00042        {      super(f,Global.name("printscaler.title"),true);
00043               F=f;
00044               AbsCoord=abscoord;
00045               setLayout(new BorderLayout());
00046               
00047               Panel panel0=new MyPanel();
00048               panel0.setLayout(new GridLayout(1,2));
00049               
00050               panel0.add(new MyLabel(Zirkel.name("printscaler.presets")));
00051               panel0.add(Presets=new MyChoice());
00052               if (abscoord)
00053                      for (int i=0; i<Pres.length; i++)
00054                             Presets.add(Zirkel.name(Pres[i]));
00055               else
00056                      for (int i=0; i<PresVect.length; i++)
00057                             Presets.add(Zirkel.name(PresVect[i]));
00058               Presets.addItemListener(this);
00059               
00060               add("North",new Panel3D(panel0));
00061               
00062               Panel panel1=new MyPanel();
00063               panel1.setLayout(new BorderLayout());
00064               
00065               Panel north1=new MyPanel();
00066               north1.setLayout(new BorderLayout());
00067               
00068               Panel north=new MyPanel();
00069               north.setLayout(new GridLayout(0,2));
00070               
00071               double scale=Global.getParameter("printscale.scale",1.0);
00072               int w=(int)(F.ZC.IW*scale);
00073               int h=(int)(F.ZC.IH*scale);
00074               north.add(new MyLabel(Zirkel.name("printscaler.w")));
00075               north.add(W=new TextFieldAction(this,"w"));
00076               W.setText(""+Global.getParameter("printscale.w",w));
00077               north.add(new MyLabel(Zirkel.name("printscaler.h")));
00078               north.add(H=new TextFieldAction(this,"h"));
00079               H.setText(""+Global.getParameter("printscale.h",h));
00080               north.add(new MyLabel(Zirkel.name("printscaler.scale")));
00081               north.add(Scale=new TextFieldAction(this,"scale"));
00082               Scale.setText(""+Global.getParameter("printscale.scale",1.0));
00083               north.add(new MyLabel(Zirkel.name("printscaler.aspect")));
00084               north.add(Aspect=new CheckboxAction(this,"","aspect"));
00085               Aspect.setState(Global.getParameter("printscale.aspect",false));
00086               north.add(new MyLabel(Zirkel.name("printscaler.middle")));
00087               north.add(Middle=new CheckboxAction(this,"","middle"));
00088               Middle.setState(Global.getParameter("printscale.middle",false));
00089               if (abscoord) panel1.add("North",new Panel3D(north));
00090               
00091               north1.add("Center",new Panel3D(north));
00092               
00093               Panel north2=new MyPanel();
00094               north2.setLayout(new GridLayout(0,2));
00095               
00096               north2.add(new MyLabel(Zirkel.name("printscaler.latex")));
00097               north2.add(Latex=new CheckboxAction(this,"","latex"));
00098               Latex.setState(Global.getParameter("printscale.latex",false));
00099               
00100               north1.add("South",new Panel3D(north2));
00101               
00102               if (abscoord) panel1.add("North",north1);
00103               
00104               Panel middle=new MyPanel();
00105               middle.setLayout(new GridLayout(0,2));
00106               middle.add(new MyLabel(Zirkel.name("printscaler.width")));
00107               middle.add(Width=new TextFieldAction(this,"width"));
00108               Width.setText(""+Global.getParameter("printscale.width",5.0));
00109               middle.add(new MyLabel(Zirkel.name("printscaler.height")));
00110               middle.add(Height=new TextFieldAction(this,"height"));
00111               Height.setText(""+Global.getParameter("printscale.height",5.0));
00112               middle.add(new MyLabel(Zirkel.name("printscaler.dpi")));
00113               middle.add(DPI=new TextFieldAction(this,"dpi"));
00114               DPI.setText(""+Global.getParameter("printscale.dpi",300));
00115               panel1.add("Center",new Panel3D(middle));
00116               
00117               Panel south=new MyPanel();
00118               south.setLayout(new GridLayout(0,2));
00119               
00120               south.add(new MyLabel(Zirkel.name("printscaler.sizes")));
00121               south.add(Sizes=new CheckboxAction(this,"","sizes"));
00122               Sizes.setState(Global.getParameter("printscale.sizes",true));
00123               south.add(new MyLabel(Zirkel.name("printscaler.linewidth")));
00124               south.add(LineWidth=new TextFieldAction(this,"linewidth"));
00125               LineWidth.setText(""+Global.getParameter("printscale.linewidth",0.02));
00126               south.add(new MyLabel(Zirkel.name("printscaler.pointsize")));
00127               south.add(PointSize=new TextFieldAction(this,"pointsize"));
00128               PointSize.setText(""+Global.getParameter("printscale.pointsize",0.07));
00129               south.add(new MyLabel(Zirkel.name("printscaler.textsize")));
00130               south.add(TextSize=new TextFieldAction(this,"textsize"));
00131               TextSize.setText(""+Global.getParameter("printscale.textsize",0.3));
00132               panel1.add("South",new Panel3D(south));
00133                             
00134               add("Center",panel1);
00135               
00136               Panel panel2=new MyPanel();
00137               panel2.add(new ButtonAction(this,Zirkel.name("ok"),"OK"));
00138               panel2.add(new ButtonAction(this,Zirkel.name("cancel"),"Close"));
00139               addHelp(panel2,"print");
00140               
00141               add("South",new Panel3D(panel2));
00142               
00143               String last=Global.getParameter("printscaler.changed","");
00144               if (last.equals("scale")) doAction("scale");
00145               else if (last.equals("widthheight")) doAction("width");
00146               else doAction("w");
00147               
00148               if (Middle.getState()) Sizes.setState(false);
00149               
00150               pack();
00151               center(f);
00152               setVisible(true);
00153        }
00154        
00155        public double round (double x)
00156        {      return Math.round(x*100)/100.0;
00157        }
00158        
00159        public void doAction (String o)
00160        {      if (o.equals("width") || o.equals("height"))
00161               {      double w=getValue(Width,5,1,100);
00162                      double h=getValue(Height,5,1,100);
00163                      Width.setText(""+round(w));
00164                      Height.setText(""+round(h));
00165                      if (Aspect.getState())
00166                      {      if (o.equals("width"))
00167                                    Height.setText(""+round(w*F.ZC.IH/F.ZC.IW));
00168                             else if (o.equals("height"))
00169                                    Width.setText(""+round(h*F.ZC.IW/F.ZC.IH));
00170                      }
00171                      setWHS();
00172                      Global.setParameter("printscaler.changed","widthheight");
00173               }
00174               else if (o.equals("dpi"))
00175               {      String last=Global.getParameter("printscaler.changed","");
00176                      if (last.equals("wh") || last.equals("scale"))
00177                             doAction("w");
00178                      else
00179                             doAction("width");
00180                      return;
00181               }
00182               else if (o.equals("w") || o.equals("h"))
00183               {      double w=getValue(W,F.ZC.IW,50,5000);
00184                      double h=getValue(H,F.ZC.IW,50,5000);
00185                      W.setText(""+(int)w);
00186                      H.setText(""+(int)h);
00187                      if (Aspect.getState())
00188                      {      if (o.equals("w"))
00189                                    H.setText(""+(int)(w*F.ZC.IH/F.ZC.IW));
00190                             else if (o.equals("h"))
00191                                    W.setText(""+(int)(h*F.ZC.IW/F.ZC.IH));
00192                      }
00193                      Scale.setText(""+(w/F.ZC.IW));
00194                      Global.setParameter("printscaler.changed","wh");
00195                      setWidthHeight();
00196               }
00197               else if (o.equals("scale"))
00198               {      double scale=getValue(Scale,1.0,0.1,100);
00199                      W.setText(""+(int)(F.ZC.IW*scale));
00200                      H.setText(""+(int)(F.ZC.IH*scale));
00201                      if (Global.getParameter("printscaler.changed","").equals("scaled"))
00202                      {      double dpi=getValue(W,F.ZC.IW,50,5000)/
00203                                    (getValue(Width,5,1,100)/2.54);
00204                             DPI.setText(""+round(dpi));
00205                             System.out.println(dpi);
00206                      }
00207                      Global.setParameter("printscaler.changed","scale");
00208                      setWidthHeight();
00209               }
00210               else if (o.equals("OK"))
00211               {      if (Width.isChanged() || Height.isChanged() || DPI.isChanged())
00212                      {      setWHS();
00213                             Global.setParameter("printscaler.changed","widthheight");
00214                      }
00215                      else if (W.isChanged() || H.isChanged())
00216                      {      setWidthHeight();
00217                             Global.setParameter("printscaler.changed","wh");
00218                      }
00219                      else if (Scale.isChanged())
00220                      {      double scale=getValue(Scale,1.0,0.1,100);
00221                             W.setText(""+(int)(F.ZC.IW*scale));
00222                             H.setText(""+(int)(F.ZC.IH*scale));
00223                             Global.setParameter("printscaler.changed","scale");
00224                             setWidthHeight();    
00225                      }
00226                      Global.setParameter("printscale.w",
00227                             getValue(W,F.ZC.IW,50,5000));
00228                      Global.setParameter("printscale.h",
00229                             getValue(H,F.ZC.IW,50,5000));
00230                      Global.setParameter("printscale.scale",
00231                             getValue(Scale,1,0.1,100));
00232                      Global.setParameter("printscale.width",
00233                             getValue(Width,5,1,100));
00234                      Global.setParameter("printscale.height",
00235                             getValue(Height,5,1,100));
00236                      Global.setParameter("printscale.dpi",
00237                             getValue(DPI,300,50,1200));
00238                      Global.setParameter("printscale.linewidth",
00239                             getValue(LineWidth,0.02,0.005,0.5));
00240                      Global.setParameter("printscale.pointsize",
00241                             getValue(PointSize,0.07,0.01,2));
00242                      Global.setParameter("printscale.textsize",
00243                             getValue(TextSize,0.3,0.05,2));
00244                      Global.setParameter("printscale.middle",Middle.getState());
00245                      Global.setParameter("printscale.sizes",Sizes.getState());
00246                      Global.setParameter("printscale.aspect",Aspect.getState());
00247                      Global.setParameter("printscale.latex",Latex.getState());
00248                      doclose();                  
00249               }
00250               else super.doAction(o);
00251        }
00252        
00253        public void itemAction (String o, boolean flag)
00254        {      if (o.equals("middle"))
00255               {      Sizes.setState(false);
00256               }
00257               else if (o.equals("sizes"))
00258               {      Middle.setState(false);
00259               }
00260        }
00261        
00262        public void setWHS ()
00263        {      double width=getValue(Width,5,1,100);
00264               double height=getValue(Height,5,1,100);
00265               double dpi=getValue(DPI,300,50,4800);
00266               W.setText(""+(int)(width/2.54*dpi));
00267               H.setText(""+(int)(height/2.54*dpi));
00268               Scale.setText(""+(width/2.54*dpi/F.ZC.IW));
00269        }
00270        
00271        public void setWidthHeight ()
00272        {      int w=(int)getValue(W,F.ZC.IW,50,5000);
00273               int h=(int)getValue(H,F.ZC.IW,50,5000);
00274               double dpi=getValue(DPI,300,50,4800);
00275               Width.setText(""+round(w/dpi*2.54));
00276               Height.setText(""+round(h/dpi*2.54));
00277        }
00278        
00279        double getValue (TextField f, double def, double min, double max)
00280        {      try
00281               {      String s=f.getText();
00282                      double factor=1;
00283                      if (s.endsWith("pt"))
00284                      {      factor=0.035; s=s.substring(0,s.length()-2);
00285                      }
00286                      else if (s.endsWith("cm"))
00287                      {      factor=1; s=s.substring(0,s.length()-2);
00288                      }
00289                      else if (s.endsWith("mm"))
00290                      {      factor=0.1; s=s.substring(0,s.length()-2);
00291                      }
00292                      else if (s.endsWith("cm"))
00293                      {      factor=1; s=s.substring(0,s.length()-2);
00294                      }
00295                      else if (s.endsWith("''"))
00296                      {      factor=1/2.54; s=s.substring(0,s.length()-2);
00297                      }
00298                      else if (s.endsWith("cm"))
00299                      {      factor=1; s=s.substring(0,s.length()-2);
00300                      }
00301                      else if (s.endsWith("in"))
00302                      {      factor=1/2.54; s=s.substring(0,s.length()-2);
00303                      }
00304                      double x=new Double(s).doubleValue()*factor;
00305                      if (x>max) x=max;
00306                      if (x<min) x=min;
00307                      return x;
00308               }
00309               catch (Exception e) { return def; }
00310        }
00311 
00312        public void itemStateChanged (ItemEvent e)
00313        {      switch (Presets.getSelectedIndex())
00314               {      case 1 :
00315                             DPI.setText("300");
00316                             Width.setText(""+round(F.ZC.DX));
00317                             Middle.setState(false);
00318                             Aspect.setState(true);
00319                             Sizes.setState(true);
00320                             LineWidth.setText(""+0.02);
00321                             PointSize.setText(""+0.07);
00322                             TextSize.setText(""+0.3);
00323                             Latex.setState(false);
00324                             doAction("width");
00325                             Global.setParameter("printscaler.changed","scaled");
00326                             break;
00327                      case 2 :
00328                             DPI.setText("300");
00329                             Width.setText("12.0");
00330                             Middle.setState(false);
00331                             Aspect.setState(true);
00332                             Sizes.setState(true);
00333                             LineWidth.setText(""+0.02);
00334                             PointSize.setText(""+0.07);
00335                             TextSize.setText(""+0.3);
00336                             Latex.setState(false);
00337                             doAction("width");
00338                             break;
00339                      case 3 :
00340                             Scale.setText("1.0");
00341                             DPI.setText("100");
00342                             Middle.setState(false);
00343                             Aspect.setState(true);
00344                             Sizes.setState(false);
00345                             Latex.setState(false);
00346                             doAction("scale");
00347                             break;
00348                      case 4 :
00349                             Scale.setText("0.5");
00350                             DPI.setText("100");
00351                             Middle.setState(true);
00352                             Aspect.setState(false);
00353                             Sizes.setState(false);
00354                             Latex.setState(false);
00355                             doAction("scale");
00356                             break;
00357                      case 5 :
00358                             DPI.setText("300");
00359                             Width.setText("12.0");
00360                             Middle.setState(false);
00361                             Aspect.setState(true);
00362                             Sizes.setState(true);
00363                             LineWidth.setText(""+0.02);
00364                             PointSize.setText(""+0.07);
00365                             TextSize.setText(""+0.35);
00366                             Latex.setState(true);
00367                             doAction("width");
00368                             break;
00369               }
00370        }
00371        
00372 }