Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/diaam/lgpl/applications/ScriptsWays.java


1   /*
2    * $Log: ScriptsWays.java,v $
3    * Revision 1.1  2000/11/10 15:31:30  vonarnim
4    * - deplacement (et nouvelle version) de TerminalStandard dans ctulu
5    *
6    * Revision 1.2  1999/11/20 20:34:56  Herve_AGNOUX
7    * Pour changer le nom du fichier :
8    * ScriptWays.java -> ScriptsWays.java,
9    * pour faire comme 'Script_s_Streams.java'
10   *
11   * Revision 1.1  1999/11/20 16:02:15  Herve_AGNOUX
12   * Initial revision
13   *
14   *
15   */
16  /*
17  -- TerminalStandard v111999
18  
19  Fichier : TerminalStandard.java
20  Auteur : Hervé AGNOUX, hagnoux@mail.club-internet.fr
21  License LGPL.
22  */
23  
24  package com.diaam.lgpl.applications;
25  
26  import java.awt.*;
27  import java.awt.event.WindowAdapter;
28  import java.awt.event.WindowEvent;
29  import java.beans.BeanDescriptor;
30  import java.beans.BeanInfo;
31  import java.beans.Introspector;
32  import java.util.Enumeration;
33  import java.util.Hashtable;
34  import java.util.Properties;
35  
36  import javax.swing.JFrame;
37  import javax.swing.JScrollPane;
38  import javax.swing.SwingUtilities;
39  import javax.swing.text.Document;
40  
41  import com.diaam.lgpl.script.Interpretable;
42  import com.diaam.lgpl.script.TextWays;
43  import com.diaam.lgpl.ts.TerminalStandard;
44  import com.diaam.lgpl.ts.ShSh;
45  
46  /**
47   * Cette classe est une simple application pour montrer l'utilisation 
48   * de scripts avec ShSh, et en utilisant des Reader et des Writer.
49   * @author <a href="h_agnoux.html">Hervé AGNOUX</a>,
50   * hagnoux@mail.club-internet.fr
51   * @version 111999
52   * @see com.diaam.lgpl.ts.ShSh
53   */
54  public class ScriptsWays
55  {
56    /**
57     * Utilise la propriété système "script" pour connaitre la classe
58     * de script à lancer. Utilise le BeanInfo correspondant pour le
59     * descriptif. En cas que y'a des messages sur les flux stantards,
60     * les affiche sur un TerminalStandard.
61     * @param args non utilisé.
62     * @see com.diaam.lgpl.realscripts.ForPnuts
63     * @see com.diaam.lgpl.realscripts.ForSkij
64     * @see com.diaam.lgpl.ts.TerminalStandard
65     * @exception Exception par ce que je suis feneant.
66     */
67    public static void main(String args[]) throws Exception
68    {
69      String s;
70      TerminalStandard ts;
71      JFrame jf1, jf2;
72      BeanInfo bi;
73      BeanDescriptor bd;
74      final Class c;
75      final Interpretable i;
76      final ShSh t;
77      Container co;
78      Dimension dm;
79      TextWays tw;
80      JScrollPane jsp;
81  
82      ts = new TerminalStandard();
83      jf1 = TerminalStandard.pourAfficherLog(ts);
84      s = System.getProperty("script");
85      if (s == null)
86        {
87    jf1.addWindowListener(new WindowAdapter()
88         {
89           public void windowClosing(WindowEvent e)
90             {
91           System.exit(0);
92             }
93         });
94    System.out.println
95      ("Veuillez indiquer avec une propriete le langage de script\n"+
96       "a utiliser SVP.\n"+
97       "Ex : java -Dscript=com.diaam.lgpl.realscripts.ForPnuts\n"+
98       "\tcom.diaam.lgpl.applications.ScriptStream\n");
99    System.out.flush();
100   return;
101       }
102     c = Class.forName(s);
103     bi = Introspector.getBeanInfo(c);
104     bd = bi.getBeanDescriptor();
105     t = new ShSh();
106     tw = new TextWays();
107     tw.in = t.lecteur();
108     tw.out = t.rédacteur();
109     tw.err = t.gueulard();
110     jf2 = new JFrame();
111     if (bd == null)
112   jf2.setTitle("script avec '"+c.getName()+"'");
113     else
114   {
115       String s1, s2;
116 
117       s1 = bd.getName();
118       if (s1 == null)
119     jf2.setTitle("script avec '"+c.getName()+"'");
120       else
121     jf2.setTitle("script avec '"+s1+"'");
122       s2 = bd.getShortDescription();
123       if (s2 != null)
124     tw.out.write(s2+"\n");
125   }
126     i = (Interpretable)c.newInstance();
127     i.ajouteObjet("interpretable", i);
128     i.ajouteObjet("ts", ts);
129     co = jf2.getContentPane();
130     co.setLayout(new BorderLayout());
131     jsp = new JScrollPane(t);
132     co.add("Center", jsp);
133     dm = Toolkit.getDefaultToolkit().getScreenSize();
134     jf2.setBounds
135       (0, (dm.height * 15)/100, 
136        dm.width, (dm.height * 60)/100);
137     Thread u = new Thread(new RunScript(i, tw));
138     u.start();
139     jf2.addWindowListener(new WindowAdapter()
140         {
141             public void windowActivated(WindowEvent e)
142           {t.requestFocus();}
143             public void windowClosing(WindowEvent e)
144           {System.exit(0);}
145         });
146     jf2.show();
147   }
148 
149   private static class RunScript implements java.lang.Runnable
150   {
151     Interpretable monScript;
152     TextWays mesVoies;
153 
154     private RunScript(Interpretable script, TextWays voies)
155     {
156       monScript = script;
157       mesVoies = voies;
158     }
159 
160     public void run()
161     {
162   monScript.doDirectly(mesVoies, true);
163     }
164   }
165 }
166