Back to index

wims  3.65+svn20090927
ExportDialog.java
Go to the documentation of this file.
00001 package rene.zirkel.dialogs;
00002 
00003 import java.awt.*;
00004 import java.awt.event.ActionEvent;
00005 
00006 import rene.gui.*;
00007 import rene.util.*;
00008 import rene.zirkel.Zirkel;
00009 import rene.zirkel.ZirkelFrame;
00010 import rene.zirkel.construction.Construction;
00011 import rene.dialogs.*;
00012 
00013 public class ExportDialog extends HelpCloseDialog
00014 {      ZirkelFrame ZF;
00015        Construction C;
00016        TextField PageTitle,CFile,Jar,Width,Height,Solution,StyleSheet;
00017        Checkbox BackgroundColor,AppletColor,Job,Comment,SaveSolution,LinkSolution,
00018               JumpSolution,Digits,Colors,Background,Popup,Zoom,RestrictedMove;
00019        Panel CP;
00020        Choice Style;
00021        boolean OK=false;
00022        IconBar IBa,IBb;
00023        boolean SaveDimensions=true;
00024        boolean Restrict;
00025        double Persp=1; // Fenster Höhe / Breite
00026 
00027        static String ISb[]={"back","delete","undo","showcolor","showname","showvalue",
00028               "color","hidden","macro0","replay","arrow","obtuse","solid","grid",
00029               "thickness0","type0","partial","plines",
00030               "twolines","macrobar","qintersection","qpointon","qchoice","indicate",
00031               "draw","rename","function"};
00032        static String ISb0[]={"back","delete","undo","showcolor","showname","showvalue",
00033               "color","hidden","macro","replay","arrow","obtuse","solid","grid",
00034               "thickness","type","partial","plines",
00035               "twolines","macrobar","qintersection","qpointon","qchoice","indicate",
00036               "draw","rename","function"};
00037        
00038        static String ST[]={"plain","3D","icons","full","nonvisual","breaks"};
00039        
00040        public ExportDialog (ZirkelFrame zf, Construction c, boolean restrict)
00041        {      super(zf,Zirkel.name("export.title"),true);
00042               ZF=zf; C=c; Restrict=restrict;
00043               setLayout(new BorderLayout());
00044               
00045               Panel p=new MyPanel();
00046               p.setLayout(new GridLayout(0,2));
00047 
00048               p.add(new MyLabel(Zirkel.name("export.pagetitle")));
00049               p.add(PageTitle=new TextFieldAction(this,"export.pagetitle",32));
00050               PageTitle.setText(FileName.purefilename(zf.Filename));
00051 
00052               p.add(new MyLabel(Zirkel.name("export.stylesheet")));
00053               p.add(StyleSheet=new TextFieldAction(this,"export.stylesheet",32));
00054               StyleSheet.setText(Global.getParameter("export.stylesheet",""));
00055 
00056               p.add(new MyLabel(Zirkel.name("export.width")));
00057               p.add(Width=new TextFieldAction(this,"export.width",32));
00058               Width.setText(""+Global.getParameter("export.width",600));
00059               Width.addActionListener(this);
00060 
00061               p.add(new MyLabel(Zirkel.name("export.height")));
00062               p.add(Height=new TextFieldAction(this,"export.height",32));
00063               Height.setText(""+Global.getParameter("export.height",600));
00064               Height.addActionListener(this);
00065 
00066               p.add(new MyLabel(Zirkel.name("export.file")));
00067               p.add(CFile=new TextFieldAction(this,"export.file",32));
00068               CFile.setText(FileName.filename(zf.Filename));
00069 
00070               p.add(new MyLabel(Zirkel.name("export.jar")));
00071               p.add(Jar=new TextFieldAction(this,"export.jar",32));
00072               Jar.setText(Global.getParameter("export.jar","zirkel.jar"));
00073 
00074               if (ZF.ZC.isJob())
00075               {      p.add(new MyLabel(""));
00076                      p.add(Job=
00077                             new CheckboxAction(this,Zirkel.name("export.job")));
00078                      Job.setState(ZF.ZC.isJob());
00079               }
00080 
00081               if (ZF.ZC.isJob())
00082               {      p.add(new MyLabel(Zirkel.name("export.solution")));
00083                      p.add(Solution=new TextFieldAction(this,"export.solution",32));
00084                      Solution.setText(FileName.purefilename(zf.Filename)+"-sol.html");
00085        
00086                      p.add(JumpSolution=
00087                             new CheckboxAction(this,Zirkel.name("export.jumpsol")));
00088                      JumpSolution.setState(Global.getParameter("export.jumpsol",false));
00089        
00090                      p.add(SaveSolution=
00091                             new CheckboxAction(this,Zirkel.name("export.savesol")));
00092                      SaveSolution.setState(Global.getParameter("export.savesol",false));
00093        
00094                      p.add(LinkSolution=
00095                             new CheckboxAction(this,Zirkel.name("export.linksol")));
00096                      LinkSolution.setState(Global.getParameter("export.linksol",false));
00097                      
00098                      p.add(new MyLabel(""));
00099               }
00100 
00101               p.add(new MyLabel(Zirkel.name("export.color")));
00102               p.add(CP=new MyPanel());
00103               CP.setBackground(Global.getParameter("export.color",
00104                      ZF.ZC.getBackground()));
00105 
00106               p.add(BackgroundColor=
00107                      new CheckboxAction(this,Zirkel.name("export.backgroundcolor")));
00108               BackgroundColor.setState(Global.getParameter("export.backgroundcolor",true));
00109 
00110               p.add(AppletColor=
00111                      new CheckboxAction(this,Zirkel.name("export.appletcolor")));
00112               AppletColor.setState(Global.getParameter("export.appletcolor",true));
00113               
00114               Style=new MyChoice();
00115               for (int i=0; i<ST.length; i++)
00116                      Style.add(Global.name("export."+ST[i]));
00117               int style=Global.getParameter("export.style",0);
00118               if (style<=1 && ZF.ZC.isJob()) style=3;
00119               Style.select(style);
00120               p.add(new MyLabel(Zirkel.name("export.style")));
00121               p.add(Style);
00122               
00123               p.add(Digits=
00124                      new CheckboxAction(this,Zirkel.name("export.digits")));
00125               Digits.setState(Global.getParameter("export.digits",true));
00126               p.add(Comment=
00127                      new CheckboxAction(this,Zirkel.name("export.comment")));
00128               Comment.setState(Global.getParameter("export.comment",true));
00129 
00130               p.add(Colors=
00131                      new CheckboxAction(this,Zirkel.name("export.colors")));
00132               Colors.setState(Global.getParameter("export.colors",true));
00133               p.add(Background=
00134                      new CheckboxAction(this,Zirkel.name("export.background")));
00135               Background.setState(Global.getParameter("export.background",false));
00136 
00137               p.add(Popup=
00138                      new CheckboxAction(this,Zirkel.name("export.popup")));
00139               Popup.setState(Global.getParameter("export.popup",true));
00140               p.add(Zoom=
00141                      new CheckboxAction(this,Zirkel.name("export.zoom")));
00142               Zoom.setState(Global.getParameter("export.zoom",false));
00143 
00144               p.add(RestrictedMove=
00145                      new CheckboxAction(this,Zirkel.name("export.restrictedmove")));
00146               RestrictedMove.setState(Global.getParameter("export.restrictedmove",false));
00147               p.add(new MyLabel(""));
00148 
00149               add("North",new Panel3D(p));
00150               
00151               Panel icons=new MyPanel();
00152               icons.setLayout(new GridLayout(0,1));
00153               IBa=new IconBar(ZF);
00154               String ica;
00155               if (restrict)
00156                      ica=Global.getParameter("restrictedicons",
00157                             " point line segment ray circle circle3 fixedcircle fixedangle intersection ");            
00158               else
00159                      ica=Global.getParameter("export.icons",
00160                             " point line segment ray circle circle3 fixedcircle fixedangle intersection ");
00161               for (int i=0; i<ZirkelFrame.IconNumber; i++)
00162               {      String s=ZirkelFrame.ObjectStrings[i];
00163                      IBa.addToggleLeft(s);       
00164                      if (ica.equals("full") || ica.indexOf(" "+s+" ")>=0)
00165                             IBa.setState(s,true);
00166               }
00167               icons.add(new Panel3D(IBa));
00168               IBb=new IconBar(ZF);
00169               String icb;
00170               if (restrict)
00171                      icb=Global.getParameter("restrictedicons",
00172                             "back hidden color indicate twolines ");
00173               else
00174                      icb=Global.getParameter("export.tools",
00175                             "back hidden color indicate twolines ");
00176               for (int i=0; i<ISb.length; i++)
00177               {      String s=ISb[i];
00178                      if (s.equals("qintersection")) IBb.addSeparatorLeft();
00179                      if (s.equals("twolines")) IBb.addSeparatorLeft();
00180                      if (s.equals("draw")) IBb.addSeparatorLeft();
00181                      IBb.addToggleLeft(s);
00182                      if (icb.equals("full") || icb.indexOf(ISb0[i])>=0)
00183                             IBb.setState(s,true);
00184               }
00185               icons.add(new Panel3D(IBb));
00186               IBb.setState("qchoice",Global.getParameter("options.choice",false));
00187               IBb.setState("qintersection",Global.getParameter("options.intersection",false));
00188               IBb.setState("qpointon",Global.getParameter("options.pointon",false));
00189               IBb.setState("indicate",!Global.getParameter("options.indicate.simple",false));
00190               add("Center",icons);
00191               
00192               Panel buttons=new MyPanel();
00193               buttons.add(new ButtonAction(this,Zirkel.name("export.setsize"),"setsize"));
00194               buttons.add(new ButtonAction(this,Zirkel.name("export.setcolor"),"setcolor"));
00195               buttons.add(new MyLabel(" "));
00196               buttons.add(new ButtonAction(this,Zirkel.name("ok"),"OK"));
00197               buttons.add(new ButtonAction(this,Zirkel.name("abort"),"Close"));
00198               addHelp(buttons,"htmlexport");
00199               add("South",buttons);
00200               
00201               pack();
00202               if (getSize().width>750) setSize(750,getSize().height);
00203               
00204               Dimension d=ZF.ZC.getSize();
00205               if (d.width>0) Persp=((double)d.height)/d.width;
00206        }
00207 
00208        public void actionPerformed (ActionEvent e)
00209        {      if (e.getSource()==Width)
00210               {      int w=getWidth();
00211                      Width.setText(""+w);
00212                      Height.setText(""+(int)(w*Persp)); 
00213               }
00214               else if (e.getSource()==Height && Persp>0)
00215               {      int h=getHeight();
00216                      Height.setText(""+h);
00217                      Width.setText(""+(int)(h/Persp));
00218               }             
00219        }
00220        
00221 
00222        public void doAction (String o)
00223        {      OK=false;
00224               if (o.equals("OK"))
00225               {      OK=true;
00226                      Global.setParameter("export.stylesheet",StyleSheet.getText());
00227                      Global.setParameter("export.jar",Jar.getText());
00228                      if (SaveDimensions) try
00229                      {      Global.setParameter("export.height",
00230                                    Integer.parseInt(Height.getText()));
00231                             Global.setParameter("export.width",
00232                                    Integer.parseInt(Width.getText()));
00233                      }
00234                      catch (Exception e) {}
00235                      Global.setParameter("export.color",CP.getBackground());
00236                      Global.setParameter("export.backgroundcolor",BackgroundColor.getState());
00237                      Global.setParameter("export.appletcolor",AppletColor.getState());
00238                      if (JumpSolution!=null)
00239                             Global.setParameter("export.jumpsol",JumpSolution.getState());
00240                      if (SaveSolution!=null)
00241                             Global.setParameter("export.savesol",SaveSolution.getState());
00242                      if (LinkSolution!=null)
00243                             Global.setParameter("export.linksol",LinkSolution.getState());
00244                      Global.setParameter("export.comment",Comment.getState());
00245                      Global.setParameter("export.colors",Colors.getState());
00246                      Global.setParameter("export.background",Background.getState());
00247                      Global.setParameter("export.zoom",Zoom.getState());
00248                      Global.setParameter("export.restrictedmove",RestrictedMove.getState());
00249                      Global.setParameter("export.popup",Popup.getState());
00250                      int i=Style.getSelectedIndex();
00251                      if (i>=0) Global.setParameter("export.style",i);
00252                      Global.setParameter("export.digits",Digits.getState());
00253                      getIcons();
00254                      getTools();
00255                      doclose();
00256               }
00257               else if (o.equals("setcolor"))
00258               {      ColorEditor d=new ColorEditor(ZF,"export.color",CP.getBackground());
00259                      d.center(ZF);
00260                      d.setVisible(true);
00261                      CP.setBackground(
00262                             Global.getParameter("export.color",CP.getBackground()));
00263               }
00264               else if (o.equals("setsize"))
00265               {      Dimension d=ZF.ZC.getSize();
00266                      Height.setText(""+d.height);
00267                      Width.setText(""+d.width);
00268               }
00269               else super.doAction(o);
00270        }
00271        
00272        public boolean isAborted ()
00273        {      return !OK;
00274        }
00275        
00276        public String getPageTitle () { return PageTitle.getText(); }
00277        public String getStyleSheet () { return StyleSheet.getText(); }
00278        public String getFile () { return CFile.getText(); }
00279        public String getDezimalColor ()
00280        {      Color c=CP.getBackground();
00281               return c.getRed()+","+c.getGreen()+","+c.getBlue(); 
00282        }
00283        public String getHexColor ()
00284        {      Color c=CP.getBackground();
00285               return "#"+hex(c.getRed())+hex(c.getGreen())+hex(c.getBlue()); 
00286        }
00287        static char A[]={'0','1','2','3','4','5','6','7','8','9',
00288               'A','B','C','D','E','F'};
00289        String hex (int n)
00290        {      return ""+A[n/16]+A[n%16];
00291        }
00292 
00293        public boolean useForBackground()
00294        {      return BackgroundColor.getState(); 
00295        }
00296        public boolean useForApplet()
00297        {      return AppletColor.getState(); 
00298        }
00299 
00300        public boolean isJob()
00301        {      if (Job==null) return false;
00302               return Job.getState(); 
00303        }
00304        
00305        public String getIcons ()
00306        {      StringBuffer b=new StringBuffer();
00307               b.append(" ");
00308               for (int i=0; i<ZirkelFrame.IconNumber; i++)
00309               {      String s=ZirkelFrame.ObjectStrings[i];
00310                      if (IBa.getState(s))
00311                      {      b.append(s);
00312                             b.append(" ");
00313                      }
00314               }
00315               if (!Restrict)
00316                      Global.setParameter("export.icons",b.toString());
00317               return b.toString();
00318        }
00319 
00320        public String getTools ()
00321        {      StringBuffer b=new StringBuffer();
00322               b.append(" ");
00323               for (int i=0; i<ISb.length; i++)
00324               {      String s=ISb[i];
00325                      if (s.equals("indicate") && !IBb.getState(s))
00326                      {      b.append("noindicate ");
00327                      }
00328                      else if (IBb.getState(s))
00329                      {      b.append(ISb0[i]);
00330                             b.append(" ");
00331                      }
00332               }
00333               if (!Restrict)
00334                      Global.setParameter("export.tools",b.toString());
00335               return b.toString();
00336        }
00337        
00338        public String getStyle ()
00339        {      int n=Style.getSelectedIndex();
00340               if (n>=0) Global.setParameter("export.style",n);
00341               if (n<0) return ST[0];
00342               else return ST[n];
00343        }
00344        
00345        public String getJar ()
00346        {      return Jar.getText();
00347        }
00348        
00349        public String getSolution ()
00350        {      if (Solution==null) return "";
00351               return Solution.getText();
00352        }
00353        
00354        public boolean saveComment ()
00355        {      Global.setParameter("export.comment",Comment.getState());
00356               return Comment.getState();
00357        }
00358        
00359        public int getWidth ()
00360        {      try
00361               {      int w=Integer.parseInt(Width.getText());
00362                      return w;
00363               }
00364               catch (Exception e)
00365               {      return Global.getParameter("export.width",550);
00366               }
00367        }
00368 
00369        public int getHeight ()
00370        {      try
00371               {      int w=Integer.parseInt(Height.getText());
00372                      return w;
00373               }
00374               catch (Exception e)
00375               {      return Global.getParameter("export.height",550);
00376               }
00377        }
00378        
00379        public boolean jumpSolution ()
00380        {      if (JumpSolution==null) return false;
00381               return JumpSolution.getState();
00382        }
00383 
00384        public boolean saveSolution ()
00385        {      if (SaveSolution==null) return false;
00386               return SaveSolution.getState();
00387        }
00388 
00389        public boolean linkSolution ()
00390        {      if (LinkSolution==null) return false;
00391               return LinkSolution.getState();
00392        }
00393        
00394        public boolean saveDigits ()
00395        {      return Digits.getState();
00396        }
00397 
00398        public boolean saveColors ()
00399        {      return Colors.getState();
00400        }
00401 
00402        public boolean saveBackground ()
00403        {      return Background.getState();
00404        }
00405        
00406        public boolean allowZoom ()
00407        {      return Zoom.getState();
00408        }
00409        
00410        public boolean allowPopup ()
00411        {      return Popup.getState();
00412        }
00413 
00414        public boolean restrictedMove ()
00415        {      return RestrictedMove.getState();
00416        }
00417        
00418        public void setDimensions (int w, int h)
00419        {      Height.setText(""+h); Height.setEnabled(false);
00420               Width.setText(""+w); Width.setEnabled(false);
00421               SaveDimensions=false;
00422        }
00423 
00424 }