Back to index

wims  3.65+svn20090927
EditConditionals.java
Go to the documentation of this file.
00001 package rene.zirkel.dialogs;
00002 
00003 // file: ZirkelFrame.java
00004 
00005 import java.awt.*;
00006 import java.awt.event.*;
00007 import java.util.Enumeration;
00008 import java.util.Vector;
00009 
00010 import rene.zirkel.*;
00011 import rene.zirkel.objects.*;
00012 import rene.zirkel.expression.*;
00013 import rene.zirkel.construction.*;
00014 import rene.gui.*;
00015 import rene.dialogs.Warning;
00016 
00017 public class EditConditionals extends HelpCloseDialog 
00018     implements ActionListener
00019 {      TextField Colors[]=new TextField[ColorStrings.length];
00020        TextField ColorTypes[]=new TextField[ColorTypeStrings.length];
00021        TextField Hidden,SuperHidden;
00022        TextField ShowName,ShowValue;
00023        TextField Background,Solid;
00024        TextField Z;
00025        ConstructionObject O; // Single Object
00026        Vector V; // Vector of Objects
00027        Frame F;
00028        
00029        public static String ColorTypeStrings[]=
00030        {      "normal","thick","thin","invisible"
00031        }; 
00032        public static String ColorStrings[]=
00033        {      "black","green","blue","brown","cyan","red"
00034        }; 
00035        
00036        public EditConditionals (Frame f, ConstructionObject o, Vector v)
00037        {      super(f,
00038                      o==null?Zirkel.name("editconditionals.title"):
00039                             Zirkel.name("editconditionals.title")+" : "+o.getName(),true);
00040               O=o; F=f;
00041               if (O==null) O=o=(ConstructionObject)v.elementAt(0);
00042               if (v==null)
00043               {      V=new Vector(); V.addElement(o);
00044               }
00045               else 
00046                      V=v;
00047               
00048               setLayout(new BorderLayout());
00049               
00050               MyPanel north=new MyPanel();
00051               north.setLayout(new GridLayout(0,2));
00052               for (int i=0; i<ColorStrings.length; i++)
00053               {      north.add(new MyLabel(
00054                             Zirkel.name("colors."+ColorStrings[i])));
00055                      Colors[i]=new MyTextField("",32);
00056                      Expression ex=o.getConditional(ColorStrings[i]);
00057                      if (ex!=null) Colors[i].setText(ex.toString());
00058                      north.add(Colors[i]);
00059               }
00060               for (int i=0; i<ColorTypeStrings.length; i++)
00061               {      north.add(new MyLabel(
00062                             Zirkel.name("color.type."+ColorTypeStrings[i])));
00063                      ColorTypes[i]=new MyTextField("",32);
00064                      Expression ex=o.getConditional(ColorTypeStrings[i]);
00065                      if (ex!=null) ColorTypes[i].setText(ex.toString());
00066                      north.add(ColorTypes[i]);
00067               }
00068 
00069               Hidden=addConditional(north,"hidden");
00070               SuperHidden=addConditional(north,"superhidden");
00071 
00072               ShowName=addConditional(north,"showname");
00073               ShowValue=addConditional(north,"showvalue");
00074               Background=addConditional(north,"background");
00075               Solid=addConditional(north,"solid");
00076               Z=addConditional(north,"z");
00077               
00078               add("North",new Panel3D(north));
00079               
00080               MyPanel south=new MyPanel();
00081               
00082               south.add(new ButtonAction(this,Zirkel.name("cancel"),"Close"));
00083               south.add(new ButtonAction(this,Zirkel.name("ok"),"OK"));
00084               addHelp(south,"conditions");
00085               
00086               add("South",new Panel3D(south));
00087               
00088               pack();
00089               center(f);
00090               setVisible(true);
00091        }
00092        
00093        public EditConditionals (Frame f, Vector v)
00094        {      this(f,null,v);
00095        }
00096        
00097        public EditConditionals (Frame f, ConstructionObject o)
00098        {      this(f,o,null);
00099        }
00100        
00101        public TextField addConditional (Panel north, String tag)
00102        {      north.add(new MyLabel(Zirkel.name("editconditionals."+tag)));
00103               TextField H=new MyTextField("",32);
00104               Expression ex=O.getConditional(tag);
00105               if (ex!=null) H.setText(ex.toString());
00106               north.add(H);
00107               return H;
00108        }
00109        
00110        public void doAction (String o)
00111        {      if (o.equals("OK"))
00112               {      Enumeration en=V.elements();
00113                      while (en.hasMoreElements())
00114                      {      O=(ConstructionObject)en.nextElement();
00115                             O.clearConditionals();
00116                             for (int i=0; i<ColorStrings.length; i++)
00117                             {      setConditional(ColorStrings[i],Colors[i]);
00118                             }
00119                             for (int i=0; i<ColorTypeStrings.length; i++)
00120                             {      setConditional(ColorTypeStrings[i],ColorTypes[i]);
00121                             }
00122                             setConditional("hidden",Hidden);
00123                             setConditional("superhidden",SuperHidden);
00124                             
00125                             setConditional("showname",ShowName);
00126                             setConditional("showvalue",ShowValue);
00127                             setConditional("background",Background);
00128                             setConditional("solid",Solid);
00129                             setConditional("z",Z);
00130                             try
00131                             {      O.checkConditionals();
00132                             }
00133                             catch (ConstructionException e)
00134                             {      Warning w=new Warning(F,e.getDescription(),
00135                                           Zirkel.name("warning"),true);
00136                                    w.center(F);
00137                                    w.setVisible(true);
00138                                    return;
00139                             }
00140                      }
00141                      doclose();
00142               }
00143               else super.doAction(o);
00144        }
00145        
00146        public void setConditional (String tag, TextField t)
00147        {      if (!t.getText().trim().equals(""))
00148               {      O.addConditional(tag,
00149                             new Expression(t.getText().trim(),O.getConstruction(),O,null,false));
00150               }
00151        }
00152 }
00153