Back to index

wims  3.65+svn20090927
ConstructionDisplayPanel.java
Go to the documentation of this file.
00001 /*
00002  * Created on 14.01.2006
00003  *
00004  */
00005 package rene.zirkel.construction;
00006 
00007 import java.awt.*;
00008 import java.awt.datatransfer.Clipboard;
00009 import java.awt.datatransfer.ClipboardOwner;
00010 import java.awt.datatransfer.StringSelection;
00011 import java.awt.datatransfer.Transferable;
00012 import java.awt.event.*;
00013 import java.io.ByteArrayOutputStream;
00014 import java.io.OutputStreamWriter;
00015 import java.io.PrintWriter;
00016 import java.util.*;
00017 
00018 import rene.gui.*;
00019 import rene.lister.*;
00020 import rene.zirkel.*;
00021 import rene.zirkel.dialogs.EditConditionals;
00022 import rene.zirkel.dialogs.ObjectsEditDialog;
00023 import rene.zirkel.objects.*;
00024 
00025 public class ConstructionDisplayPanel 
00026        extends MyPanel 
00027               implements DoActionListener, ActionListener, ClipboardOwner
00028 {      Lister V;
00029        Vector W;
00030        Construction C;
00031        ZirkelCanvas ZC;
00032 
00033        Choice Ch;
00034        CheckboxMenuItemAction Visible;
00035        boolean ShowVisible=true;
00036        CheckboxMenuItemAction Sort,Description,Size,Formula;
00037        public static String Choices[]=
00038               {"all","points","lines","circles","angles","expressions","other"};
00039        int State=0;
00040        PopupMenu PM;
00041        Button Menu;
00042        
00043        public ConstructionDisplayPanel (ZirkelCanvas zc)
00044        {      ZC=zc;
00045               C=ZC.getConstruction();
00046               V=new Lister();
00047               V.setMode(true,false,true,true);
00048               V.addActionListener(this);
00049 
00050               if (Global.Background!=null) V.setBackground(Global.Background);
00051               V.setFont(Global.FixedFont);
00052               State=Global.getParameter("constructiondisplay.state",0);
00053               
00054               setLayout(new BorderLayout());
00055               
00056               Panel north=new MyPanel();
00057               north.setLayout(new BorderLayout());
00058               Ch=new ChoiceAction(this,"choices");
00059               for (int i=0; i<Choices.length; i++)
00060               {      Ch.add(Zirkel.name("constructiondisplay."+Choices[i]));
00061               }
00062               north.add("Center",Ch);
00063               Ch.select(State);
00064               Menu=new ButtonAction(this,"?","Menu");
00065               north.add("East",Menu);
00066               
00067               add("North",new Panel3D(north));
00068               
00069               setListerState();
00070               
00071               makePopup();
00072               
00073               add("Center",V);
00074        }
00075        
00076        public void reload ()
00077        {      V.clear();
00078               C=ZC.getConstruction();
00079               Enumeration e=null;
00080               if (Global.getParameter("constructiondisplay.sort",true)) e=C.getSortedElements();
00081               else e=C.elements();
00082               W=new Vector();
00083               outer: while (e.hasMoreElements())
00084               {      ConstructionObject o=(ConstructionObject)e.nextElement();
00085                      if (ShowVisible && o.mustHide(ZC)) continue outer;
00086                      if (Global.getParameter("restricted",false) &&
00087                                    o.isSuperHidden()) continue outer;
00088                      switch (State)
00089                      {      case 0 :
00090                                    break;
00091                             case 1 :
00092                                    if (!(o instanceof PointObject))
00093                                                                continue outer;
00094                                    break;
00095                             case 2 :
00096                                    if (!(o instanceof PrimitiveLineObject) ||
00097                                                  (o instanceof FixedAngleObject))
00098                                                                continue outer;
00099                                    break;
00100                             case 3 :
00101                                    if (!(o instanceof PrimitiveCircleObject))
00102                                                                continue outer;
00103                                    break;
00104                             case 4 :
00105                                    if (!(o instanceof AngleObject || 
00106                                                  o instanceof FixedAngleObject))
00107                                                                continue outer;
00108                                    break;
00109                             case 5 :
00110                                    if (!(o instanceof ExpressionObject || 
00111                                                  o instanceof FunctionObject))
00112                                                                continue outer;
00113                                    break;
00114                             case 6 :
00115                                    if (o instanceof PointObject || 
00116                                                  o instanceof PrimitiveLineObject ||
00117                                                  o instanceof PrimitiveCircleObject ||
00118                                                  o instanceof AngleObject ||
00119                                                  o instanceof ExpressionObject ||
00120                                                  o instanceof FunctionObject)
00121                                                                continue outer;
00122                                    break; 
00123                      }
00124                      V.addElement(o);
00125                      W.addElement(o);
00126               }
00127               V.showLast();
00128               updateDisplay();
00129        }
00130        
00131        public void updateDisplay ()
00132        {      V.updateDisplay();
00133        }
00134 
00135        public void doAction (String o) 
00136        {      if (o.equals("Edit"))
00137               {      int selected[]=V.getSelectedIndices();
00138                      if (selected.length==0) return;
00139                      if (selected.length==1)
00140                      {      ((ConstructionObject)W.elementAt(selected[0])).edit(ZC);
00141                      }      
00142                      else
00143                      {      Vector v=new Vector();
00144                             for (int i=0; i<selected.length; i++)
00145                                    v.addElement(W.elementAt(selected[i]));
00146                             ObjectsEditDialog d=new ObjectsEditDialog(ZC.getFrame(),v);
00147                             d.setVisible(true);
00148                             ZC.validate();
00149                      }
00150                      ZC.repaint();
00151                      reload();
00152               }
00153               else if (o.equals("EditConditions"))
00154               {      int selected[]=V.getSelectedIndices();
00155                      if (selected.length==0) return;
00156                      if (selected.length==1)
00157                      {      new EditConditionals(ZC.getFrame(),
00158                                           (ConstructionObject)W.elementAt(selected[0]));
00159                      }      
00160                      else
00161                      {      Vector v=new Vector();
00162                             for (int i=0; i<selected.length; i++)
00163                                    v.addElement(W.elementAt(selected[i]));
00164                             new EditConditionals(ZC.getFrame(),v);
00165                      }
00166                      ZC.repaint();
00167                      updateDisplay();
00168               }
00169               else if (o.equals("Copy"))
00170               {      try
00171                      {      ByteArrayOutputStream ba=new ByteArrayOutputStream(50000);
00172                             PrintWriter po=new PrintWriter(
00173                                    new OutputStreamWriter(ba),true);
00174                             V.save(po);
00175                             po.close();
00176                             String S=ba.toString();
00177                             Clipboard clip=getToolkit().getSystemClipboard();
00178                             StringSelection sel=new StringSelection(S);
00179                             clip.setContents(sel,this);
00180                      }
00181                      catch (Exception e) {       }
00182               }
00183               else if (o.equals("Delete"))
00184               {      int selected[]=V.getSelectedIndices();
00185                      if (selected.length==0) return;
00186                      Vector v=new Vector();
00187                      for (int i=0; i<selected.length; i++)
00188                             v.addElement(W.elementAt(selected[i]));
00189                      ZC.delete(v);
00190                      ZC.repaint();
00191                      ZC.reset();
00192                      reload();
00193               }
00194               else if (o.equals("Hide"))
00195               {      int selected[]=V.getSelectedIndices();
00196                      if (selected.length==0) return;
00197                      for (int i=0; i<selected.length; i++)
00198                      {      ConstructionObject oc=(ConstructionObject)W.elementAt(selected[i]);
00199                             oc.setHidden(!oc.isHidden());
00200                      }
00201                      ZC.repaint();
00202                      updateDisplay();
00203               }
00204               else if (o.equals("SuperHide"))
00205               {      int selected[]=V.getSelectedIndices();
00206                      if (selected.length==0) return;
00207                      for (int i=0; i<selected.length; i++)
00208                      {      ConstructionObject oc=(ConstructionObject)W.elementAt(selected[i]);
00209                             oc.setSuperHidden(true);
00210                      }
00211                      ZC.repaint();
00212                      updateDisplay();
00213               }
00214               else if (o.equals("HighLight"))
00215               {      int selected[]=V.getSelectedIndices();
00216                      if (selected.length==0) return;
00217                      for (int i=0; i<selected.length; i++)
00218                      {      ConstructionObject oc=(ConstructionObject)W.elementAt(selected[i]);
00219                             oc.setStrongSelected(true);
00220                      }
00221                      Graphics g=ZC.getGraphics();
00222                      if (g!=null)
00223                      {      ZC.paint(g);
00224                             g.dispose();
00225                             try
00226                             {      Thread.sleep(400);
00227                             }
00228                             catch (Exception e) {}
00229                      }
00230                      for (int i=0; i<selected.length; i++)
00231                      {      ConstructionObject oc=(ConstructionObject)W.elementAt(selected[i]);
00232                             oc.setStrongSelected(false);
00233                      }
00234                      ZC.repaint();
00235               }
00236               else if (o.equals("Menu"))
00237               {      displayPopup(V.L,10,10);
00238               }
00239               ZC.requestFocus();
00240        }
00241 
00242        public void itemToggleAction (String o)
00243        {      if (o.equals("Sort"))
00244               {      Sort.setState(!Sort.getState());
00245                      itemAction("Sort",Sort.getState());
00246               }
00247               else if (o.equals("Visible"))
00248               {      Visible.setState(!Visible.getState());
00249                      itemAction("Visible",Visible.getState());
00250               }
00251        }
00252        
00253        public void itemAction (String o, boolean flag)
00254        {      if (o.equals("Sort"))
00255               {      Global.setParameter("constructiondisplay.sort",Sort.getState());
00256                      reload();
00257               }
00258               else if (o.equals("Visible"))
00259               {      ShowVisible=Visible.getState();
00260                      reload();
00261               }
00262               else if (o.equals("Description"))
00263               {      Global.setParameter("constructiondisplay.listerstate",
00264                             ConstructionObject.DescriptionState);
00265                      setListerState();
00266                      updateDisplay();
00267               }
00268               else if (o.equals("Size"))
00269               {      Global.setParameter("constructiondisplay.listerstate",
00270                             ConstructionObject.SizeState);
00271                      setListerState();
00272                      updateDisplay();
00273               }
00274               else if (o.equals("Formula"))
00275               {      Global.setParameter("constructiondisplay.listerstate",
00276                             ConstructionObject.FormulaState);
00277                      setListerState();
00278                      updateDisplay();
00279               }
00280               else if (flag)
00281               {      State=Ch.getSelectedIndex();
00282                      Global.setParameter("constructiondisplay.state",State);
00283                      reload();
00284               }
00285        }
00286        
00287        public void setListerState ()
00288        {      int state=Global.getParameter("constructiondisplay.listerstate",ConstructionObject.SizeState);
00289               V.setState(state);
00290               if (PM!=null)
00291               {      Description.setState(state==ConstructionObject.DescriptionState);
00292                      Size.setState(state==ConstructionObject.SizeState);
00293                      Formula.setState(state==ConstructionObject.FormulaState);
00294               }
00295        }
00296 
00297        public Dimension getPreferredSize ()
00298        {      return new Dimension(Global.getParameter("options.constructiondisplay.width",200),
00299                      400);
00300        }
00301 
00305        public void actionPerformed (ActionEvent e) 
00306        {      if (e.getSource()==V && (e instanceof ListerMouseEvent))
00307               {      ListerMouseEvent em=(ListerMouseEvent)e;
00308                      if (em.rightMouse())
00309                             displayPopup(em.getEvent().getComponent(),
00310                                           em.getEvent().getX(),em.getEvent().getY());
00311                      else
00312                      {      if (em.clickCount()>=2)
00313                                    doAction("Edit");
00314                             else
00315                                    doAction("HighLight");
00316                      }
00317               }
00318        }
00319        
00324        public void displayPopup (Component c, int x, int y)
00325        {      PM.show(c,x,y);
00326        }
00327        
00328        public void makePopup ()
00329        {      PM=new PopupMenu();
00330               PM.add(new MenuItemAction(this,Zirkel.name("constructiondisplay.edit"),"Edit"));
00331               PM.add(new MenuItemAction(this,Zirkel.name("constructiondisplay.editconditions"),"EditConditions"));
00332               PM.addSeparator();
00333               PM.add(new MenuItemAction(this,Zirkel.name("constructiondisplay.hide"),"Hide"));
00334               PM.add(new MenuItemAction(this,Zirkel.name("constructiondisplay.superhide"),
00335                             "SuperHide"));
00336               PM.addSeparator();
00337               PM.add(new MenuItemAction(this,Zirkel.name("constructiondisplay.delete"),
00338                             "Delete"));
00339               PM.addSeparator();
00340               Description=new CheckboxMenuItemAction(this,
00341                             Zirkel.name("constructiondisplay.description"),"Description");
00342               Description.setState(Global.getParameter("constructiondisplay.description",false));
00343               PM.add(Description);
00344               Size=new CheckboxMenuItemAction(this,
00345                             Zirkel.name("constructiondisplay.size"),"Size");
00346               Description.setState(Global.getParameter("constructiondisplay.size",true));
00347               PM.add(Size);
00348               Formula=new CheckboxMenuItemAction(this,
00349                             Zirkel.name("constructiondisplay.formula"),"Formula");
00350               Description.setState(Global.getParameter("constructiondisplay.formula",false));
00351               PM.add(Formula);
00352               PM.addSeparator();
00353               PM.add(new MenuItemAction(this,Zirkel.name("constructiondisplay.copy"),
00354                             "Copy"));
00355               V.L.add(PM);
00356               PM.addSeparator();
00357               Visible=new CheckboxMenuItemAction(this,
00358                      Zirkel.name("constructiondisplay.visible"),"Visible");
00359               Visible.setState(true);
00360               PM.add(Visible);
00361               Sort=new CheckboxMenuItemAction(this,
00362                      Zirkel.name("constructiondisplay.sorted"),"Sort");
00363               Sort.setState(Global.getParameter("constructiondisplay.sort",true));
00364               PM.add(Sort);
00365               setListerState();
00366        }
00367        
00371        public void showLast ()
00372        {      V.showLast();
00373        }
00374 
00375        public void lostOwnership(Clipboard clipboard, Transferable contents) {
00376        }
00377 
00378        public void setListingBackground (Color c)
00379        {      V.setListingBackground(c);
00380        }
00381 }