qse/ase/test/awk/AseAwkApplet.java

109 lines
2.2 KiB
Java
Raw Normal View History

2007-03-24 15:49:59 +00:00
/*
2007-04-11 10:49:34 +00:00
* $Id: AseAwkApplet.java,v 1.3 2007-04-11 10:49:34 bacon Exp $
2007-03-24 15:49:59 +00:00
*/
2006-11-26 16:17:51 +00:00
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
2007-03-23 07:45:22 +00:00
import java.net.URL;
2007-04-11 10:49:34 +00:00
import java.io.File;
2007-01-25 14:14:56 +00:00
2007-04-10 08:04:52 +00:00
public class AseAwkApplet extends Applet
2006-11-26 16:17:51 +00:00
{
2007-04-11 09:39:46 +00:00
private TextArea srcIn;
private TextArea srcOut;
private TextArea conIn;
private TextArea conOut;
private TextField jniLib;
2006-11-26 16:17:51 +00:00
public void init ()
{
2007-04-11 09:39:46 +00:00
jniLib = new TextField ();
srcIn = new TextArea ();
srcOut = new TextArea ();
conIn = new TextArea ();
conOut = new TextArea ();
Button runBtn = new Button ("Run Awk");
2006-11-26 16:17:51 +00:00
2007-04-11 09:39:46 +00:00
runBtn.addActionListener (new ActionListener ()
2006-11-26 16:17:51 +00:00
{
public void actionPerformed (ActionEvent e)
{
2007-04-11 10:49:34 +00:00
runAwk ();
2006-11-26 16:17:51 +00:00
}
});
2007-04-11 09:39:46 +00:00
Panel topPanel = new Panel ();
BorderLayout topPanelLayout = new BorderLayout ();
topPanel.setLayout (topPanelLayout);
topPanelLayout.setHgap (2);
topPanelLayout.setVgap (2);
topPanel.add (new Label ("JNI Library: "), BorderLayout.WEST);
topPanel.add (jniLib, BorderLayout.CENTER);
Panel centerPanel = new Panel ();
GridLayout centerPanelLayout = new GridLayout (2, 2);
centerPanel.setLayout (centerPanelLayout);
centerPanelLayout.setHgap (2);
centerPanelLayout.setVgap (2);
centerPanel.add (srcIn);
centerPanel.add (srcOut);
centerPanel.add (conIn);
centerPanel.add (conOut);
BorderLayout mainLayout = new BorderLayout ();
mainLayout.setHgap (2);
mainLayout.setVgap (2);
setLayout (mainLayout);
add (topPanel, BorderLayout.NORTH);
add (centerPanel, BorderLayout.CENTER);
add (runBtn, BorderLayout.SOUTH);
2007-04-11 10:49:34 +00:00
URL url = this.getClass().getResource ("AseAwk.class");
File file = new File (url.getFile());
jniLib.setText (file.getParentFile().getParentFile().getParent() + "/lib/.libs/libaseawk_jni.dylib");
2006-11-26 16:17:51 +00:00
}
public void stop () {}
public void paint (Graphics g) {}
2007-04-11 10:49:34 +00:00
private void runAwk ()
2006-11-26 16:17:51 +00:00
{
2007-04-10 08:04:52 +00:00
AseAwk awk = null;
2006-11-26 16:17:51 +00:00
try
{
2007-03-23 07:45:22 +00:00
try
{
2007-04-11 10:49:34 +00:00
System.load (jniLib.getText());
2007-03-23 07:45:22 +00:00
}
catch (Exception e)
{
2007-04-11 10:49:34 +00:00
System.err.println ("xxx fuck you - cannot load library: " + e.getMessage());
2007-03-23 07:45:22 +00:00
}
2007-04-10 08:04:52 +00:00
awk = new AseAwk ();
2006-11-26 16:17:51 +00:00
awk.parse ();
awk.run ();
}
catch (ase.awk.Exception e)
{
System.out.println ("ase.awk.Exception - " + e.getMessage());
}
finally
{
if (awk != null) awk.close ();
}
}
}