File: ScriptedUI.java

package info (click to toggle)
libbsf-java 1%3A2.4.0-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 2,960 kB
  • sloc: java: 5,373; xml: 224; ansic: 182; python: 57; makefile: 15
file content (59 lines) | stat: -rw-r--r-- 1,811 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* This example shows how a Java app can allow a script to customize
   a UI */

import java.awt.*;
import java.awt.event.*;
import java.io.*;

import org.apache.bsf.*;
import org.apache.bsf.util.*;

public class ScriptedUI {
  BSFManager mgr = new BSFManager ();

  public ScriptedUI (String fileName) {
    Frame f = new Frame ("Application's Main Frame");
    f.addWindowListener (new WindowAdapter () {
      public void windowClosing (WindowEvent e) {
	System.exit (0);
      }
    });

    Panel p = new Panel ();
    f.add ("Center", p);
    f.add ("North", new Button ("North Button"));
    f.add ("South", new Button ("South Button"));

    mgr.registerBean ("centerPanel", p);
    mgr.registerBean ("parentFrame", f); // --rgf, 2006-08-08: to allow Jacl to get to frame ...

    // exec script engine code to do its thing for this
    try {
      String language = BSFManager.getLangFromFilename (fileName);
      FileReader in = new FileReader (fileName);
      String script = IOUtils.getStringFromReader (in);

      mgr.exec (language, fileName, -1, -1, script);
    } catch (BSFException e) {
      System.err.println ("Ouch: " + e.getMessage ());
      e.printStackTrace ();
    } catch (IOException e) {
      System.err.println ("Ouch: " + e.getMessage ());
      e.printStackTrace ();
    }

    // now pack and show the frame
    f.pack ();
    // f.show(); // javac 1.5 warns to use f.show(), Apache build scripts abort as a result :(
    f.setVisible(true);     // available since Java 1.1
  }

  public static void main (String[] args) throws Exception {
    if (args.length != 1) {
      System.err.println ("Usage: java ScriptedUI filename");
      System.err.println ("       where filename is the name of the script");
      System.exit (1);
    }
    new ScriptedUI (args[0]);
  }
}