Back to index

wims  3.65+svn20090927
ObjectEditDialog.java
Go to the documentation of this file.
00001 package rene.zirkel.dialogs;
00002 
00003 // file: PointObject.java
00004 
00005 import java.awt.*;
00006 import java.awt.event.*;
00007 
00008 import rene.gui.*;
00009 import rene.zirkel.*;
00010 import rene.zirkel.objects.*;
00011 
00020 public class ObjectEditDialog extends HelpCloseDialog
00021        implements IconBarListener
00022 {      protected MyTextField Text,Unit,Equation;
00023        protected TextFieldAction Name,Alias;
00024        protected ConstructionObject O;
00025        protected IconBar ColorIB,ThicknessIB,IB;
00026        protected Frame F;
00027        protected boolean More;
00028        protected ButtonAction OK;
00029        protected boolean SuperHide=false,HideChanged=false,
00030               HidingBreak=false,BreakChanged=false,OKControlDown=false;
00031        
00032        public ObjectEditDialog (Frame f, String title, ConstructionObject o)
00033        {      this(f,title,o,"properties");
00034        }
00035 
00036        public ObjectEditDialog (Frame f, String title, ConstructionObject o,
00037               String subject)
00038        {      super(f,title,true);
00039               F=f;
00040               O=o;
00041               o.getConstruction().changed(true);
00042               setLayout(new BorderLayout());
00043               
00044               // edit options:
00045               Panel center=new MyPanel();
00046               center.setLayout(new BorderLayout());
00047               Panel P=new MyPanel();
00048               Name=new TextFieldAction(this,"Name",o.getName(),32);
00049               if (O.canDisplayName())
00050                      Alias=new TextFieldAction(this,"Alias",o.getAlias(),32);
00051               Text=new MyTextField(o.getText(),32);
00052               Unit=new MyTextField(o.getUnit(),32);
00053               P.setLayout(new GridLayout(0,2));
00054               P.add(new MyLabel(Zirkel.name("edit.name"))); P.add(Name);
00055               if (Alias!=null)
00056               {      P.add(new MyLabel(Zirkel.name("edit.alias"))); P.add(Alias);
00057               }
00058               P.add(new MyLabel(Zirkel.name("edit.text"))); P.add(Text);
00059               if (o.hasUnit())
00060               {      P.add(new MyLabel(Zirkel.name("edit.unit"))); P.add(Unit);
00061               }
00062               String eq=o.getEquation();
00063               if (!eq.equals(""))
00064               {      P.add(new MyLabel(Zirkel.name("edit.equation"))); 
00065                      Equation=new MyTextField(o.getName(),32);
00066                      Equation.setEditable(false);
00067                      Equation.setText(eq);
00068                      P.add(Equation);
00069               }
00070 
00071               addFirst(P);
00072 
00073               center.add("Center",P);
00074               Panel cs=new MyPanel();
00075               cs.setLayout(new GridLayout(0,2));
00076 
00077               ColorIB=new IconBar(f);
00078               ColorIB.addToggleGroupLeft("color",6);
00079               ColorIB.toggle("color",O.getColorIndex(true));
00080               cs.add(new MyLabel("")); cs.add(ColorIB);
00081 
00082               ThicknessIB=new IconBar(f);
00083               ThicknessIB.addToggleGroupLeft("thickness",4);
00084               ThicknessIB.toggle("thickness",O.getColorType(true));
00085               if (o.maybeTransparent())
00086               {      ThicknessIB.addSeparatorLeft();
00087                      ThicknessIB.addOnOffLeft("solid");
00088                      ThicknessIB.setState("solid",o.isSolid(true));
00089                      if (!o.isFilled())
00090                             ThicknessIB.setEnabled("solid",false);
00091               }
00092               cs.add(new MyLabel("")); cs.add(ThicknessIB);
00093 
00094               IB=new IconBar(f);
00095               IB.setIconBarListener(this);
00096               IB.addOnOffLeft("hide");
00097               IB.setState("hide",O.isHidden(true));
00098               IB.addSeparatorLeft();
00099               if (O.canDisplayName())
00100               {      IB.addOnOffLeft("showname");
00101                      IB.setState("showname",O.showName(true));
00102                      if (showsValue())
00103                      {      IB.addOnOffLeft("showvalue");
00104                             IB.setState("showvalue",O.showValue(true));
00105                      }
00106                      IB.addSeparatorLeft();
00107                      IB.addOnOffLeft("bold");
00108                      IB.setState("bold",O.isBold());
00109                      IB.addOnOffLeft("large");
00110                      IB.setState("large",O.isLarge());
00111                      IB.addSeparatorLeft();
00112               }
00113               IB.addOnOffLeft("isback");
00114               IB.setState("isback",O.isBack(true));
00115               IB.addOnOffLeft("setbreak");
00116               IB.setState("setbreak",O.isBreak());
00117               cs.add(new MyLabel("")); cs.add(IB);
00118               
00119               addSecond(cs);
00120 
00121               center.add("South",cs);
00122               add("Center",new Panel3D(center));
00123               
00124               // button panel:
00125               Panel p=new MyPanel();
00126               addButton(p);
00127               if (Global.getParameter("options.more",false))
00128               {      p.add(new ButtonAction(this,Zirkel.name("edit.more"),"More"));
00129               }
00130               p.add(OK=new ButtonAction(this,Zirkel.name("edit.ok"),"OK"));
00131               OK.addMouseListener(new MouseAdapter ()
00132                      {      public void mousePressed (MouseEvent e)
00133                             {      OKControlDown=e.isControlDown();
00134                             }
00135                      }
00136               );
00137               OKControlDown=false;
00138               Button b=new ButtonAction(this,Zirkel.name("edit.cancel"),"Close");
00139               p.add(b);
00140               addHelp(p,subject);
00141               add("South",new Panel3D(p));
00142               
00143               More=false;
00144               pack();
00145               center(f);
00146        }
00147        
00148        public void doAction (String o)
00149        {      if (o.equals("OK") || o.equals("Name") || o.equals("Alias") || o.equals("More"))
00150               {      More=(o.equals("More") || OKControlDown);
00151                      O.setName(Name.getText());
00152                      if (Alias!=null)
00153                      {      if (!Alias.getText().equals(""))
00154                             {      if (O.getAlias()==null || !O.getAlias().equals(Alias.getText()))
00155                                           O.setShowName(true);
00156                                    O.setAlias(Alias.getText());
00157                             }
00158                             else O.setAlias(null);
00159                      }
00160                      if (o.equals("Name")) IB.setState("showname",true);
00161                      String text=Text.getText();
00162                      if (text.equals(""))
00163                      {      O.setText("",true);
00164                             O.updateText();
00165                      }
00166                      else if (!O.getText().equals(text))
00167                      {      if (!text.endsWith(" ")) text=text+" ";
00168                             O.setText(text,true);
00169                      }
00170                      O.setUnit(Unit.getText());
00171                      if (HideChanged)
00172                      {      O.setHidden(IB.getState("hide"));
00173                             if (SuperHide && IB.getState("hide")) O.setSuperHidden(true);
00174                             else O.setSuperHidden(false);
00175                      }
00176                      O.setColor(ColorIB.getToggleState("color"));
00177                      O.setColorType(ThicknessIB.getToggleState("thickness"));
00178                      O.setShowName(o.equals("Name") || o.equals("Alias") || IB.getState("showname"));
00179                      O.setBold(IB.getState("bold"));
00180                      O.setLarge(IB.getState("large"));
00181                      O.setBack(IB.getState("isback"));
00182                      if (showsValue()) O.setShowValue(IB.getState("showvalue"));
00183                      if (O.maybeTransparent())
00184                      {      O.setSolid(ThicknessIB.getState("solid"));
00185                      }
00186                      if (BreakChanged)
00187                      {      if (IB.getState("setbreak"))
00188                             {      if (HidingBreak) O.setHideBreak(true);
00189                                    else O.setBreak(true);
00190                             }
00191                             else O.setBreak(false);
00192                      }
00193                      doclose();
00194                      setAction();
00195               }
00196               else super.doAction(o);
00197        }
00198        public void addFirst (Panel P) {}
00199        public void addSecond (Panel P) {}
00200        public void addButton (Panel p) {}
00201 
00202        public void setAction () {}
00203        public void iconPressed (String o)
00204        {      if (o.equals("hide"))
00205               {      HideChanged=true;
00206                      if (IB.isShiftPressed()) SuperHide=IB.getState("hide");
00207                      else SuperHide=false;
00208               }
00209               else if (o.equals("setbreak"))
00210               {      BreakChanged=true;
00211                      if (IB.isShiftPressed()) HidingBreak=IB.getState("setbreak");
00212                      else HidingBreak=false;
00213               }
00214        }
00215        public void showValue ()
00216        {      if (showsValue()) IB.setState("showvalue",true);
00217        }
00218        public boolean showsValue ()
00219        {      return true;
00220        }
00221 
00222        public boolean wantsMore ()
00223        {      return More;
00224        }
00225 
00226 }