Back to index

wims  3.65+svn20090927
ConstructionDisplay.java
Go to the documentation of this file.
00001 package rene.zirkel.construction;
00002 
00003 import java.awt.*;
00004 import java.awt.datatransfer.*;
00005 import java.util.*;
00006 import java.io.*;
00007 
00008 import rene.gui.*;
00009 import rene.lister.*;
00010 import rene.zirkel.Zirkel;
00011 import rene.zirkel.ZirkelCanvas;
00012 import rene.zirkel.dialogs.HelpCloseDialog;
00013 import rene.zirkel.objects.*;
00014 
00023 public class ConstructionDisplay extends HelpCloseDialog
00024        implements ClipboardOwner
00025 {      Lister V;
00026        Vector W;
00027        Construction C;
00028        ZirkelCanvas ZC;
00029        // display the help from subject.txt
00030        
00031        Choice Ch;
00032        Checkbox Sort;
00033        public static String Choices[]=
00034               {"all","visible","expressions",
00035                      "points","lines","circles","angles","other","invalid"};
00036        int State=0;
00037        
00038        public ConstructionDisplay (Frame f, ZirkelCanvas zc)
00039        {      super(f,Zirkel.name("constructiondisplay.title","Construction"),true);
00040               C=zc.getConstruction();
00041               ZC=zc;
00042               V=new Lister()
00043                      {      public Dimension getPreferredSize ()
00044                             {      return new Dimension(500,400);
00045                             }
00046                      };
00047               V.setMode(true,false,false,false);
00048               if (Global.Background!=null) V.setBackground(Global.Background);
00049               V.setFont(Global.FixedFont);
00050               State=Global.getParameter("constructiondisplay.state",1);
00051               
00052               setLayout(new BorderLayout());
00053               
00054               Panel north=new MyPanel();
00055               north.setLayout(new GridLayout(0,2));
00056               north.add(new MyLabel(Zirkel.name("constructiondisplay.select")));
00057               Ch=new ChoiceAction(this,"choices");
00058               for (int i=0; i<Choices.length; i++)
00059               {      Ch.add(Zirkel.name("constructiondisplay."+Choices[i]));
00060               }
00061               north.add(Ch);
00062               Ch.select(State);
00063               north.add(new MyLabel(Zirkel.name("constructiondisplay.sorted")));
00064               Sort=new CheckboxAction(this,"","Sort");
00065               Sort.setState(Global.getParameter("constructiondisplay.sort",true));
00066               north.add(Sort);
00067               add("North",new Panel3D(north));
00068               
00069               add("Center",V);
00070               
00071               Panel p=new MyPanel();
00072               p.add(new ButtonAction(this,Zirkel.name("constructiondisplay.copy"),"Copy"));
00073               p.add(new ButtonAction(this,Zirkel.name("constructiondisplay.edit"),"Edit"));
00074               p.add(new ButtonAction(this,Zirkel.name("close","Close"),"Close"));
00075               addHelp(p,"construction");
00076               add("South",p);
00077               
00078               pack();
00079               setSize("constructiondialog");
00080               center(f);
00081               reload();
00082               setVisible(true);
00083        }
00084        
00085        public void reload ()
00086        {      V.clear();
00087               Enumeration e=null;
00088               if (Sort.getState()) e=C.getSortedElements();
00089               else e=C.elements();
00090               W=new Vector();
00091               outer: while (e.hasMoreElements())
00092               {      ConstructionObject o=(ConstructionObject)e.nextElement();
00093                      switch (State)
00094                      {      
00095                             case 1 : 
00096                                    if (o.mustHide(ZC)) continue outer;
00097                                    break;
00098                             case 2 :
00099                                    if (o.mustHide(ZC)) continue outer;
00100                                    if (!(o instanceof ExpressionObject ||
00101                                                         o instanceof FunctionObject))
00102                                                                continue outer;
00103                                    break;
00104                             case 3 :
00105                                    if (o.mustHide(ZC)) continue outer;
00106                                    if (!(o instanceof PointObject))
00107                                                                continue outer;
00108                                    break;
00109                             case 4 :
00110                                    if (o.mustHide(ZC)) continue outer;
00111                                    if (!(o instanceof PrimitiveLineObject) ||
00112                                                  (o instanceof FixedAngleObject))
00113                                                                continue outer;
00114                                    break;
00115                             case 5 :
00116                                    if (o.mustHide(ZC)) continue outer;
00117                                    if (!(o instanceof PrimitiveCircleObject))
00118                                                                continue outer;
00119                                    break;
00120                             case 6 :
00121                                    if (o.mustHide(ZC)) continue outer;
00122                                    if (!(o instanceof AngleObject || 
00123                                                  o instanceof FixedAngleObject))
00124                                                                continue outer;
00125                                    break;
00126                             case 7 :
00127                                    if (o.mustHide(ZC)) continue outer;
00128                                    if (o instanceof PointObject || 
00129                                                  o instanceof PrimitiveLineObject ||
00130                                                  o instanceof PrimitiveCircleObject ||
00131                                                  o instanceof AngleObject ||
00132                                                  o instanceof ExpressionObject ||
00133                                                  o instanceof FunctionObject)
00134                                                                continue outer;
00135                                    break; 
00136                             case 8 :
00137                                    if (o.valid()) continue outer;
00138                                    break;
00139                      }
00140                      V.addElement(o);
00141                      W.addElement(o);
00142               }
00143               V.showLast();
00144               V.updateDisplay();
00145        }
00146        
00147        public void doAction (String o)
00148        {      noteSize("constructiondialog");
00149               Global.setParameter("constructiondisplay.sort",Sort.getState());
00150               if (o.equals("Edit"))
00151               {      super.doAction("Close");
00152                      int selected=V.getSelectedIndex();
00153                      if (selected>=0)
00154                      {      Enumeration e=W.elements();
00155                             int i=0;
00156                             while (e.hasMoreElements())
00157                             {      ConstructionObject O=(ConstructionObject)e.nextElement();
00158                                    if (i==selected)
00159                                    {      O.edit(ZC);
00160                                           return;
00161                                    }
00162                                    i++;
00163                             }
00164                      }                    
00165               }
00166               else if (o.equals("Copy"))
00167               {      try
00168                      {      ByteArrayOutputStream ba=new ByteArrayOutputStream(50000);
00169                             PrintWriter po=new PrintWriter(
00170                                    new OutputStreamWriter(ba),true);
00171                             V.save(po);
00172                             po.close();
00173                             String S=ba.toString();
00174                             Clipboard clip=getToolkit().getSystemClipboard();
00175                             StringSelection sel=new StringSelection(S);
00176                             clip.setContents(sel,this);
00177                      }
00178                      catch (Exception e) {       }
00179               }
00180               super.doAction(o);
00181        }
00182        
00183        public void itemAction (String o, boolean flag)
00184        {      if (o.equals("Sort"))
00185               {      reload();
00186               }
00187               else if (flag)
00188               {      State=Ch.getSelectedIndex();
00189                      Global.setParameter("constructiondisplay.state",State);
00190                      reload();
00191               }
00192        }
00193        
00194        public void lostOwnership (Clipboard b, Transferable s) {}
00195        
00196 }