Back to index

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