Back to index

wims  3.65+svn20090927
Info.java
Go to the documentation of this file.
00001 package rene.zirkel.help;
00002 
00003 import java.awt.*;
00004 import java.awt.event.*;
00005 import java.io.*;
00006 import java.util.*;
00007 
00008 import rene.gui.*;
00009 import rene.dialogs.*;
00010 import rene.viewer.*;
00011 import rene.zirkel.Zirkel;
00012 import rene.zirkel.ZirkelFrame;
00013 
00036 public class Info extends CloseDialog
00037        implements ItemListener
00038 {      ExtendedViewer V;
00039        Button Close,Back;
00040        public static String Subject="start";
00041        String Search=null;
00042 
00043        MyChoice L;
00044        Vector Other=null;
00045        Vector History=new Vector();
00046        
00047        Frame F;
00048 
00049        public Info (Frame f)
00050        {      this(f,false);
00051        }
00052        
00053        public Info (Frame f, boolean modal)
00054        {      super(f,Zirkel.name("info.title"),modal);
00055               F=f;
00056               V=new ExtendedViewer();
00057               if (Global.Background!=null) V.setBackground(Global.Background);
00058               V.setFont(Global.NormalFont);
00059               setLayout(new BorderLayout());
00060               Panel north=new MyPanel();
00061               north.setLayout(new GridLayout(0,2));
00062               north.add(new MyLabel(Zirkel.name("info.related")));
00063               L=new MyChoice();
00064               fill();
00065               north.add(L);
00066               add("North",north);
00067               add("Center",V);
00068               Panel p=new MyPanel();
00069               p.add(new ButtonAction(this,Zirkel.name("info.start"),"Start"));
00070               p.add(new ButtonAction(this,Zirkel.name("info.search"),"Search"));
00071               p.add(new ButtonAction(this,Zirkel.name("info.back"),"Back"));
00072               p.add(new MyLabel(""));
00073               p.add(new ButtonAction(this,Zirkel.name("close","Close"),"Close"));
00074               add("South",new Panel3D(p));
00075               // seticon("rene/zirkel/icon.png");
00076               L.addItemListener(this);
00077               pack();
00078               // setLocation(0,70);
00079               centerOut(f);
00080               setPosition("info");
00081               setVisible(true);
00082        }
00083        
00084        public void fill ()
00085        {      L.removeAll();
00086               V.setText("");
00087               V.setVisible(false);
00088               boolean Found=false,Appending=false;
00089               Vector Related=null;
00090               Other=new Vector();
00091               String pair[]=null,lastpair[]=null;
00092               String lang=Global.name("language","");
00093               Vector SearchResults=new Vector();
00094               String SearchResult="";
00095               String FoundTopic=null;
00096               boolean FirstRun=true,FoundHeader=false;
00097 
00098               String Search1=Search;
00099               if (Search!=null && Search.length()>0)
00100               {      Search1=Search.substring(0,1).toUpperCase()+Search.substring(1);
00101               }
00102 
00103               read: while (true)
00104               {      try
00105                      {      String cp=Global.name("codepage.help","");
00106                             BufferedReader in=null;
00107                             if (cp.equals(""))
00108                                    in=new BufferedReader(new InputStreamReader(
00109                                           getClass().getResourceAsStream("/rene/zirkel/docs/"+lang+"info.txt")));
00110                             else
00111                             {      try
00112                                    {      in=new BufferedReader(new InputStreamReader(
00113                                                  getClass().getResourceAsStream("/rene/zirkel/docs/"+lang+"info.txt"),cp));
00114                                    }
00115                                    catch (Exception ex)
00116                                    {      in=new BufferedReader(new InputStreamReader(
00117                                                  getClass().getResourceAsStream("/rene/zirkel/docs/"+lang+"info.txt")));
00118                                    }
00119                             }
00120                             boolean newline=false;
00121                             newline: while (true)
00122                             {      String s=in.readLine();
00123                                    if (s==null) break newline;
00124                                    if (s.startsWith("//")) continue;
00125                                    s=clear(s);
00126                                    if (!s.startsWith(".") && Search!=null && 
00127                                           (s.indexOf(Search)>=0 || s.indexOf(Search1)>=0))
00128                                    {      if (lastpair!=null && pair==null &&
00129                                                  !SearchResult.equals(lastpair[0]))
00130                                           {      SearchResults.addElement(lastpair);
00131                                                  SearchResult=lastpair[0];
00132                                                  if (FoundTopic==null) FoundTopic=lastpair[0];
00133                                           }
00134                                    }
00135                                    interpret: while (true)
00136                                    {      if (!Appending && s.startsWith(".") && 
00137                                                  !s.startsWith(".related"))
00138                                           {      if (!Found)
00139                                                  {      if (s.startsWith("."+Subject))
00140                                                         {      Found=true; Appending=true;
00141                                                                continue newline;
00142                                                         }
00143                                                         StringTokenizer t=new StringTokenizer(s);
00144                                                         while (t.hasMoreElements())
00145                                                         {      String name=t.nextToken();
00146                                                                if (name.equals(Subject))
00147                                                                {      Found=true; Appending=true;
00148                                                                       continue newline;
00149                                                                }
00150                                                         }
00151                                                  }
00152                                                  pair=new String[2];
00153                                                  s=s.substring(1);
00154                                                  int n=s.indexOf(' ');
00155                                                  if (n>0) s=s.substring(0,n);
00156                                                  pair[0]=s;
00157                                                  continue newline;
00158                                           }
00159                                           if (Appending)
00160                                           {      if (s.startsWith(".related"))
00161                                                  {      s=s.substring(".related".length());
00162                                                         Related=new Vector();
00163                                                         StringTokenizer t=new StringTokenizer(s);
00164                                                         while (t.hasMoreElements())
00165                                                         {      Related.addElement(t.nextToken());
00166                                                         }
00167                                                         continue newline;
00168                                                  }
00169                                                  if (s.startsWith("."))
00170                                                  {      Appending=false; 
00171                                                         continue interpret;
00172                                                  }
00173                                                  if (s.trim().equals(""))
00174                                                  {      if (!newline)
00175                                                         {      V.newLine();
00176                                                                V.appendLine("");
00177                                                         }
00178                                                         newline=true;
00179                                                  }
00180                                                  else 
00181                                                  {      newline=false;
00182                                                         if (s.startsWith(" "))
00183                                                                V.newLine();
00184                                                         V.append(s+" ");
00185                                                  }
00186                                           }
00187                                           else if (pair!=null && !s.startsWith("."))
00188                                           {      pair[1]=s;
00189                                                  Other.addElement(pair);
00190                                                  lastpair=pair;
00191                                                  pair=null;
00192                                                  if (Search!=null && 
00193                                                         (s.indexOf(Search)>=0 || s.indexOf(Search1)>=0))
00194                                                  {      if (!SearchResult.equals(lastpair[0]))
00195                                                         {      SearchResults.addElement(lastpair);
00196                                                                SearchResult=lastpair[0];
00197                                                                if (!FoundHeader) FoundTopic=lastpair[0];
00198                                                                FoundHeader=true;
00199                                                         }
00200                                                  }
00201                                           }
00202                                           continue newline;
00203                                    }
00204                             }
00205                             V.newLine();
00206                             in.close();
00207                      }
00208                      catch (Exception e)
00209                      {      if (!lang.equals(""))
00210                             {      lang=""; continue read;
00211                             }
00212                             else
00213                             {      V.appendLine(
00214                                           Zirkel.name("help.error","Could not find the help file!"));
00215                             }
00216                      }
00217                      if (FoundTopic!=null && FirstRun)
00218                      {      Subject=FoundTopic;
00219                             SearchResults=new Vector();
00220                             SearchResult="";
00221                             pair=null; lastpair=null;
00222                             Found=false;
00223                             V.setText("");
00224                             FirstRun=false;
00225                             continue read;
00226                      }
00227                      else break read;
00228               }
00229 
00230               if (!Found) V.appendLine(Zirkel.name("info.notfound","Topic not found!"));
00231 
00232               if (Search!=null)
00233               {      if (SearchResults.size()>0) L.add(Zirkel.name("info.searchresults"));
00234                      else L.add(Zirkel.name("info.noresults"));
00235               }
00236               else L.add(Zirkel.name("info.select"));
00237 
00238               if (Search==null && Related!=null)
00239               {      Enumeration e=Related.elements();
00240                      while (e.hasMoreElements())
00241                      {      String topic=(String)e.nextElement();
00242                             Enumeration ev=Other.elements();
00243                             while (ev.hasMoreElements())
00244                             {      String s[]=(String[])ev.nextElement();
00245                                    if (s[0].equals(topic)) 
00246                                    {      L.add(s[1]); break;
00247                                    }
00248                             }
00249                      }
00250               }
00251               
00252               if (Search!=null)
00253               {      Enumeration e=SearchResults.elements();
00254                      while (e.hasMoreElements())
00255                      {      String s[]=(String[])e.nextElement();
00256                             L.add(s[1]);
00257                      }
00258               }
00259               
00260               History.addElement(Subject);
00261               V.update();
00262               V.setVisible(true);
00263               V.showFirst();
00264        }
00265        
00266        public String clear (String s)
00267        {      s=s.replace('',' ');
00268               s=s.replaceAll("__","");
00269               return s;
00270        }
00271 
00272        public void doAction (String o)
00273        {      if (o.equals("Close"))
00274               {      notePosition("info");
00275                      super.doAction("Close");
00276               }
00277               else if (o.equals("Back"))
00278               {      int n=History.size();
00279                      if (n<2) return;
00280                      History.removeElementAt(n-1);
00281                      Subject=(String)History.elementAt(n-2);
00282                      History.removeElementAt(n-2);
00283                      fill();
00284               }
00285               else if (o.equals("Start"))
00286               {      Subject="start";
00287                      fill();
00288               }
00289               else if (o.equals("Search"))
00290               {      GetParameter.InputLength=50;
00291                      GetParameter g=new GetParameter(F,
00292                             Zirkel.name("info.title"),
00293                             Zirkel.name("info.search"),
00294                             Zirkel.name("info.search","ok"));
00295                      // g.center(this);
00296                      g.setVisible(true);
00297                      if (!g.aborted())
00298                             Search=g.getResult();
00299                      fill();
00300                      Search=null;
00301               }
00302               else super.doAction(o);
00303        }
00304        
00305        public void itemStateChanged (ItemEvent e)
00306        {      String s=L.getSelectedItem();
00307               Enumeration ev=Other.elements();
00308               while (ev.hasMoreElements())
00309               {      String p[]=(String[])ev.nextElement();
00310                      if (p[1].equals(s))
00311                      {      Subject=p[0];
00312                             fill();
00313                             break;
00314                      }
00315               }
00316        }
00317        
00318        public void doclose ()
00319        {      if (F instanceof ZirkelFrame) ((ZirkelFrame)F).removeInfo();
00320               notePosition("info");
00321               super.doclose();
00322        }
00323 }