Back to index

wims  3.65+svn20090927
DefineMacro.java
Go to the documentation of this file.
00001 package rene.zirkel.dialogs;
00002 
00003 import java.awt.*;
00004 import java.awt.event.*;
00005 import java.util.*;
00006 
00007 import rene.gui.*;
00008 import rene.zirkel.Zirkel;
00009 import rene.zirkel.ZirkelCanvas;
00010 import rene.zirkel.objects.*;
00011 
00012 public class DefineMacro extends HelpCloseDialog
00013 {      TextField Name,PromptFor;
00014        TextArea Comment;
00015        ZirkelCanvas ZC;
00016        Vector V;
00017        boolean Aborted=true;
00018        Checkbox TargetsOnly,Invisible,HideDuplicates;
00019 
00020        public DefineMacro (Frame f, ZirkelCanvas zc)
00021        {      super(f,Zirkel.name("definemacro.title"),true);
00022               ZC=zc;
00023               setLayout(new BorderLayout());
00024               
00025               Panel north=new MyPanel();
00026               north.setLayout(new GridLayout(0,2));
00027               north.add(new MyLabel(Zirkel.name("definemacro.name")));
00028               north.add(Name=new TextFieldAction(this,"",20));
00029               add("North",new Panel3D(north));
00030               
00031               Panel center=new MyPanel();
00032               center.setLayout(new BorderLayout());
00033               
00034               center.add("North",new MyLabel(Zirkel.name("definemacro.comment")));
00035               center.add("Center",Comment=new TextArea("",5,40,
00036                      TextArea.SCROLLBARS_VERTICAL_ONLY));
00037               if (Global.Background!=null) Comment.setBackground(Global.Background);
00038               Panel p=new MyPanel();
00039               p.setLayout(new GridLayout(0,1));
00040               p.add(new MyLabel(Zirkel.name("definemacro.parameters")));
00041               Enumeration e=ZC.getConstruction().getParameters().elements();
00042               V=new Vector();
00043               while (e.hasMoreElements())
00044               {      ConstructionObject o=(ConstructionObject)e.nextElement();
00045                      TextField tf=new TextFieldAction(this,"",o.getName());
00046                      V.addElement(tf);
00047                      p.add(tf);
00048               }
00049               if (zc.getConstruction().countTargets()>0)
00050               {      Panel ph=new MyPanel();
00051                      ph.setLayout(new GridLayout(1,0));
00052                      ph.add(new MyLabel(Zirkel.name("definemacro.targetsonly")));
00053                      TargetsOnly=new CheckboxAction(this,"","TargetsOnly");
00054                      TargetsOnly.setState(true);
00055                      ph.add(TargetsOnly);
00056                      p.add(ph);
00057                      ph=new MyPanel();
00058                      ph.setLayout(new GridLayout(1,0));
00059                      ph.add(new MyLabel(Zirkel.name("definemacro.invisible")));
00060                      Invisible=new CheckboxAction(this,"","Invisible");
00061                      Invisible.setState(false);
00062                      ph.add(Invisible);
00063                      p.add(ph);
00064               }
00065               Panel ph=new MyPanel();
00066               ph.setLayout(new GridLayout(1,0));
00067               ph.add(new MyLabel(Zirkel.name("menu.options.hideduplicates")));
00068               HideDuplicates=new CheckboxAction(this,"","HideDuplicates");
00069               HideDuplicates.setState(true);
00070               ph.add(HideDuplicates);
00071               p.add(ph);
00072               Panel pp=new MyPanel();
00073               pp.setLayout(new GridLayout(1,0));
00074               pp.add(new MyLabel(Zirkel.name("definemacro.promptfor")));
00075               PromptFor=new TextFieldAction(this,"","");
00076               pp.add(PromptFor);
00077               p.add(pp);
00078               center.add("South",p);
00079               
00080               add("Center",new Panel3D(center));
00081               
00082               Panel south=new MyPanel();
00083               south.add(new ButtonAction(this,Zirkel.name("ok"),"OK"));
00084               south.add(new ButtonAction(this,Zirkel.name("abort"),"Close"));
00085               addHelp(south,"macro");
00086               add("South",new Panel3D(south));
00087               
00088               center(f);
00089               pack();
00090        }
00091        public void doAction (String o)
00092        {      if (o.equals("OK"))
00093               {      Aborted=false;
00094                      doclose();
00095               }
00096               else super.doAction(o);
00097        }
00098        public void windowOpened (WindowEvent e)
00099        {      Name.requestFocus();
00100        }
00101        public boolean isAborted ()
00102        {      return Aborted;
00103        }
00104        public String[] getParams ()
00105        {      String s[]=new String[V.size()];
00106               for (int i=0; i<V.size(); i++)
00107                      s[i]=((TextField)V.elementAt(i)).getText();
00108               return s;
00109        }
00110        public String getName()
00111        {      return Name.getText();
00112        }
00113        public String getComment ()
00114        {      return Comment.getText();
00115        }
00116        public boolean targetsOnly ()
00117        {      if (TargetsOnly==null) return false;
00118               return TargetsOnly.getState();
00119        }
00120        public boolean invisible ()
00121        {      if (Invisible==null) return false;
00122               return Invisible.getState();
00123        }
00124        public boolean hideduplicates ()
00125        {      return HideDuplicates.getState();
00126        }
00127        public String[] getPromptFor ()
00128        {      StringTokenizer t=new StringTokenizer(PromptFor.getText(),",");
00129               String s[]=new String[t.countTokens()];
00130               for (int i=0; i<s.length; i++)
00131                      s[i]=t.nextToken();
00132               return s;
00133        }
00134 }