Back to index

wims  3.65+svn20090927
Replay.java
Go to the documentation of this file.
00001 package rene.zirkel.dialogs;
00002 
00003 import java.awt.BorderLayout;
00004 import java.awt.Dimension;
00005 import java.awt.Frame;
00006 import java.awt.Point;
00007 import java.util.Enumeration;
00008 import java.util.Vector;
00009 
00010 import rene.gui.ButtonAction;
00011 import rene.gui.CloseDialog;
00012 import rene.gui.Global;
00013 import rene.gui.IconBar;
00014 import rene.gui.IconBarListener;
00015 import rene.gui.Panel3D;
00016 import rene.zirkel.ZirkelCanvas;
00017 import rene.zirkel.construction.Construction;
00018 import rene.zirkel.objects.*;
00019 
00020 public class Replay extends CloseDialog
00021        implements IconBarListener
00022 {      ZirkelCanvas ZC;
00023        int Last;
00024        Construction C;
00025        Vector V; // Copied vector of visible objects
00026        IconBar IB;
00027        boolean HaveBreaks;
00028 
00029        public Replay (Frame f, ZirkelCanvas zc)
00030        {      super(f,Global.name("replay.title"),true);
00031               ZC=zc;
00032               add(new ButtonAction(this,"Vor"));
00033               
00034               setLayout(new BorderLayout());
00035               
00036               IB=new IconBar(f);
00037               IB.addLeft("allback");
00038               IB.addLeft("fastback");
00039               IB.addLeft("oneback");
00040               IB.addLeft("oneforward");
00041               IB.addLeft("fastforward");
00042               IB.addLeft("allforward");
00043               IB.addSeparatorLeft();
00044               IB.addLeft("nextbreak");
00045               IB.addToggleLeft("setbreak");
00046               IB.addSeparatorLeft();
00047               IB.addLeft("close");
00048               IB.setIconBarListener(this);
00049               
00050               add("Center",new Panel3D(IB));
00051               
00052               C=zc.getConstruction();
00053               
00054               // Collect all visible Elements:
00055               V=new Vector();
00056               Enumeration e=C.elements();
00057               while (e.hasMoreElements())
00058               {      ConstructionObject o=(ConstructionObject)e.nextElement();
00059                      if (!o.mustHide(ZC) || o.isBreakHide() || 
00060                                    (o instanceof TextObject && o.valid() && !o.isSuperHidden()))
00061                      {      V.addElement(o);
00062                      }
00063               }
00064 
00065               HaveBreaks=haveBreaks();
00066 
00067               Last=0;
00068               setLast();
00069               setEnabled(true);
00070               
00071               pack();
00072               Dimension d=f.getSize();
00073               Dimension ds=getSize();
00074               Point l=f.getLocation();
00075               setLocation(l.x+d.width-ds.width-5,l.y+d.height/5);
00076        }
00077        
00078        public void iconPressed (String o)
00079        {      if (o.equals("close"))
00080               {      doclose();
00081               }
00082               else if (o.equals("allback"))
00083               {      Last=0; setLast();
00084               }
00085               else if (o.equals("allforward"))
00086               {      Last=V.size(); setLast();
00087               }
00088               else if (o.equals("fastback"))
00089               {      Last-=10; if (Last<0) Last=0;
00090                      setLast();
00091               }
00092               else if (o.equals("fastforward"))
00093               {      Last+=10; if (Last>V.size()) Last=V.size();
00094                      setLast();
00095               }
00096               else if (o.equals("oneforward"))
00097               {      Last++; if (Last>V.size()) Last=V.size();
00098                      setLast();
00099               }
00100               else if (o.equals("nextbreak"))
00101               {      while (true)
00102                      {      Last++;
00103                             if (Last>V.size()) { Last=V.size(); break; }
00104                             if (Last>=V.size() || 
00105                                    (Last>0 && ((ConstructionObject)V.elementAt(Last)).isBreak())) 
00106                                           break;
00107                      }
00108                      setLast();
00109               }
00110               else if (o.equals("setbreak"))
00111               {      if (Last>0)
00112                      {      ConstructionObject ob=(ConstructionObject)V.elementAt(Last);
00113                             ob.setBreak(!ob.isBreak());
00114                             IB.setState("setbreak",ob.isBreak());
00115                             if (ob.isBreak() && IB.isShiftPressed())
00116                                    ob.setHideBreak(true);
00117                      }
00118                      HaveBreaks=haveBreaks();
00119                      IB.setEnabled("nextbreak",HaveBreaks);
00120               }
00121               else if (o.equals("oneback"))
00122               {      Last--; if (Last<0) Last=0;
00123                      setLast();
00124               }
00125               start();
00126        }
00127 
00128        public void start ()
00129        {      if (Last==0)
00130               {      IB.setEnabled("allback",false);
00131                      IB.setEnabled("fastback",false);
00132                      IB.setEnabled("oneback",false);
00133               }
00134               else
00135               {      IB.setEnabled("allback",true);
00136                      IB.setEnabled("fastback",true);
00137                      IB.setEnabled("oneback",true);
00138               }
00139               if (Last<V.size())
00140               {      IB.setEnabled("allforward",true);
00141                      IB.setEnabled("fastforward",true);
00142                      IB.setEnabled("oneforward",true);
00143               }
00144               else
00145               {      IB.setEnabled("allforward",false);
00146                      IB.setEnabled("fastforward",false);
00147                      IB.setEnabled("oneforward",false);
00148               }
00149        }      
00150        
00151        public void doclose ()
00152        {      ZC.paintUntil(null);
00153               ZC.showStatus();
00154               Enumeration e=V.elements();
00155               while (e.hasMoreElements())
00156               {      ConstructionObject o=(ConstructionObject)e.nextElement();
00157                      if (o instanceof TextObject) ((TextObject)o).setDoShow(false);
00158               }
00159               ZC.repaint();
00160               super.doclose();
00161        }
00162        
00163        ConstructionObject O=null;
00164        
00165        public void checkLast ()
00166        {      if (O!=null) ((TextObject)O).setDoShow(false); 
00167               O=null;
00168               if (Last>V.size()-1) return;
00169               O=(ConstructionObject)V.elementAt(Last);
00170               if (O!=null && (O instanceof TextObject))
00171                      ((TextObject)O).setDoShow(true);
00172               else O=null;
00173        }
00174        
00175        public void setLast ()
00176        {      if (Last<V.size())
00177               {      ConstructionObject o=(ConstructionObject)V.elementAt(Last);
00178                      checkLast();
00179                      ZC.paintUntil(o);
00180               }
00181               else
00182               {      Last=V.size();
00183                      checkLast();
00184                      ZC.paintUntil(null);
00185               }
00186               if (Last>=0 && Last<V.size())
00187               {      ConstructionObject o=(ConstructionObject)V.elementAt(Last);
00188                      ZC.showStatus(o.getName()+" : "+o.getText());
00189                      IB.setState("setbreak",o.isBreak());
00190               }
00191               else
00192               {      IB.setState("setbreak",false);
00193               }
00194               if (Last>=V.size() || Last==0) IB.setEnabled("setbreak",false);
00195               else IB.setEnabled("setbreak",true);
00196               if (Last>=V.size() || !HaveBreaks) IB.setEnabled("nextbreak",false);
00197               else IB.setEnabled("nextbreak",true);
00198        }
00199        
00200        public boolean haveBreaks ()
00201        {      Enumeration e=V.elements();
00202               while (e.hasMoreElements())
00203               {      if (((ConstructionObject)e.nextElement()).isBreak())
00204                             return true;
00205               }
00206               return false;
00207        }
00208 }