home *** CD-ROM | disk | FTP | other *** search
- package webeq3;
-
- import java.applet.Applet;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.Vector;
- import webeq3.app.Handler;
- import webeq3.app.PEquation;
- import webeq3.constants.ColorDictionary;
- import webeq3.dom.MathMLDOMApplet;
- import webeq3.fonts.FontBroker;
- import webeq3.parser.Parser;
- import webeq3.schema.Box;
- import webeq3.schema.ContentBox;
- import webeq3.util.ErrorHandler;
-
- public class Main extends MathMLDOMApplet {
- // $FF: renamed from: eq webeq3.app.PEquation
- public PEquation field_0 = null;
- ErrorHandler err = new ErrorHandler();
- Handler handler = new Handler();
- String equation = null;
- String src_file = null;
- // $FF: renamed from: in java.lang.String
- String field_1 = null;
- String macros = null;
- String macrofile = null;
- public String use_parser = "webtex";
- URL src_URL = null;
- int pointsize = 18;
- boolean controls = false;
- boolean linebreak = false;
- boolean allow_cut = false;
- String align = "center";
- String valign = "baseline";
- int padding = 1;
- public boolean isBehavior = false;
- public boolean readyToFire = false;
- public boolean sizingDone = false;
- private Vector m_listeners;
-
- public void init() {
- super.init();
- this.m_listeners = new Vector();
- this.isBehavior = "true".equals(((Applet)this).getParameter("FiresScriptEvents"));
- this.handler.setDefaultStatus(Key.getStatusLine());
- this.handler.setParameters(this);
- this.equation = ((Applet)this).getParameter("eq");
- this.macros = ((Applet)this).getParameter("macros");
- this.macrofile = ((Applet)this).getParameter("macrofile");
- this.src_file = ((Applet)this).getParameter("src");
- String var1 = ((Applet)this).getParameter("align");
- if (var1 != null) {
- this.align = var1.toLowerCase();
- }
-
- var1 = ((Applet)this).getParameter("valign");
- if (var1 != null) {
- this.valign = var1.toLowerCase();
- }
-
- var1 = ((Applet)this).getParameter("padding");
- if (var1 != null) {
- this.padding = Integer.parseInt(var1);
- }
-
- var1 = ((Applet)this).getParameter("controls");
- if (var1 != null) {
- this.controls = Boolean.valueOf(var1.toLowerCase());
- }
-
- var1 = ((Applet)this).getParameter("linebreak");
- if (var1 != null) {
- this.linebreak = Boolean.valueOf(var1.toLowerCase());
- }
-
- var1 = ((Applet)this).getParameter("selection");
- if (var1 == null) {
- var1 = ((Applet)this).getParameter("allow_cut");
- }
-
- if (var1 != null) {
- this.allow_cut = Boolean.valueOf(var1.toLowerCase());
- }
-
- var1 = ((Applet)this).getParameter("size");
- if (var1 != null) {
- this.pointsize = Integer.parseInt(var1);
- }
-
- var1 = ((Applet)this).getParameter("background");
- if (var1 == null) {
- var1 = ((Applet)this).getParameter("color");
- }
-
- if (var1 == null) {
- var1 = "white";
- }
-
- Color var2 = this.resolveColor(var1);
- if (var2 != null) {
- ((Component)this).setBackground(var2);
- }
-
- var1 = ((Applet)this).getParameter("foreground");
- if (var1 == null) {
- var1 = "black";
- }
-
- var2 = this.resolveColor(var1);
- if (var2 != null) {
- ((Component)this).setForeground(var2);
- }
-
- if (this.equation != null && !this.equation.equals("")) {
- this.field_1 = this.equation;
- } else if (this.src_file == null) {
- System.out.println("WebEQ Error: A WebEQ Applet call must include either an EQ or an SRC parameter.");
- this.field_1 = "error";
- } else {
- try {
- this.src_URL = new URL(((Applet)this).getDocumentBase(), this.src_file);
- } catch (MalformedURLException var16) {
- System.out.println("Bad URL for equation source: " + var16);
- }
-
- this.field_1 = this.convertToString(this.src_URL);
- }
-
- var1 = ((Applet)this).getParameter("parser");
- if (var1 != null) {
- this.use_parser = var1.toLowerCase();
- } else {
- String var3 = this.field_1 + " ";
- StringBuffer var4 = new StringBuffer(var3.substring(0, 20));
- StringBuffer var5 = new StringBuffer();
-
- for(int var6 = 0; var6 < var4.length(); ++var6) {
- char var7 = var4.charAt(var6);
- if (var7 != '\n' && var7 != ' ' && var7 != '\t' && var7 != 160) {
- var5.append(var7);
- }
- }
-
- var3 = var5.toString();
- if (var3.startsWith("<math")) {
- this.use_parser = "mathml";
- } else if (var3.startsWith("<")) {
- int var31 = var3.indexOf(":");
- int var8 = var3.indexOf(">");
- int var9 = var3.indexOf("math");
- if (var31 < var9 && var9 < var8) {
- this.use_parser = "mathml";
- }
- }
- }
-
- if (this.macrofile != null && !this.macrofile.equals("")) {
- URL var28 = null;
-
- try {
- var28 = new URL(((Applet)this).getDocumentBase(), this.macrofile);
- } catch (MalformedURLException var15) {
- System.out.println("Error reading macro data: " + var15);
- }
-
- this.macros = this.macros + this.convertToString(var28);
- }
-
- super.document = new PEquation(this.handler);
- super.dom_children.addNode(super.document);
- this.field_0 = (PEquation)super.document;
- this.field_0.setSize(((Component)this).size().width, ((Component)this).size().height);
- this.field_0.setPadding(this.padding);
- this.field_0.setPointSize(this.pointsize);
- this.field_0.setLinebreak(this.linebreak);
- this.field_0.setControls(this.controls);
- this.field_0.setSelection(this.allow_cut);
- this.field_0.setAlign(this.align);
- this.field_0.setVAlign(this.valign);
- this.field_0.setBackground(((Component)this).getBackground());
- this.field_0.setForeground(((Component)this).getForeground());
- this.field_0.initBG();
- this.field_0.initFG();
- FontBroker.initialize(true);
-
- try {
- Parser var29 = (Parser)Class.forName("webeq3.parser." + this.use_parser + "." + this.use_parser).newInstance();
- var29.init(this.handler);
-
- try {
- if (this.use_parser.equals("webtex")) {
- var29.parse(this.field_1, this.macros, this.field_0.root, this.err);
- } else {
- var29.parse(this.field_1, this.macros, this.field_0.markupRoot, this.err);
- }
- } catch (Exception var11) {
- System.out.println(var11);
- ((Throwable)var11).printStackTrace();
- }
-
- this.field_0.registerActions();
- } catch (InstantiationException var12) {
- System.out.println(var12);
- } catch (IllegalAccessException var13) {
- System.out.println(var13);
- } catch (ClassNotFoundException var14) {
- System.out.println(var14);
- return;
- }
-
- MathMLDOMApplet var30 = (MathMLDOMApplet)this.field_0.getParent();
- this.field_0.applet = this;
- if (this.isBehavior) {
- try {
- this.field_0.root.layout();
- this.readyToFire = true;
- this.fireEvent();
- } catch (Exception var10) {
- System.out.println("layout errors -- rendering failed\n" + var10);
- ((Throwable)var10).printStackTrace();
- }
- } else {
- this.field_0.redraw();
- }
-
- }
-
- public void paint(Graphics var1) {
- this.field_0.resize(this.handler.size().width, this.handler.size().height);
- this.field_0.paint(var1);
- }
-
- public void start() {
- this.field_0.registerControls();
- }
-
- public void stop() {
- this.field_0.unregisterControls();
- }
-
- public void destroy() {
- super.destroy();
- }
-
- public boolean handleEvent(Event var1) {
- return this.field_0 != null ? this.field_0.handleEvent(var1) : false;
- }
-
- public void refresh() {
- this.field_0.redraw();
- ((Component)this).repaint();
- }
-
- public void removeMainListener(MainListener var1) {
- this.m_listeners.removeElement(var1);
- }
-
- public void addMainListener(MainListener var1) {
- if (this.m_listeners == null) {
- this.m_listeners = new Vector();
- }
-
- this.m_listeners.addElement(var1);
- if (this.readyToFire) {
- this.fireEvent();
- }
-
- }
-
- private void fireEvent() {
- Vector var2 = this.m_listeners;
- MainListener[] var1;
- synchronized(var2) {
- var1 = new MainListener[this.m_listeners.size()];
- this.m_listeners.copyInto(var1);
- }
-
- for(int var3 = 0; var3 < var1.length; ++var3) {
- var1[var3].webeqResize(((Applet)this).getParameter("id"));
- }
-
- }
-
- private String convertToString(URL var1) {
- String var2 = "";
- byte[] var4 = new byte[1024];
- InputStream var5 = null;
-
- try {
- var5 = var1.openStream();
- } catch (IOException var7) {
- System.out.println("Error opening " + var1);
- }
-
- while(true) {
- try {
- int var3 = var5.read(var4);
- if (var3 == -1) {
- return var2;
- }
-
- var2 = var2 + new String(var4, 0, 0, var3);
- } catch (IOException var8) {
- System.out.println("Error reading " + var1);
- }
- }
- }
-
- private Color resolveColor(String var1) {
- if (var1 == null) {
- return null;
- } else {
- Color var2 = null;
-
- try {
- if (var1.length() == 7 && var1.startsWith("#")) {
- var2 = new Color(Integer.parseInt(var1.substring(1), 16));
- } else if (var1.length() == 4 && var1.startsWith("#")) {
- String var3 = var1.charAt(1) + "0" + var1.charAt(2) + "0" + var1.charAt(3) + "0";
- var2 = new Color(Integer.parseInt(var3, 16));
- } else if (ColorDictionary.ColorTable.containsKey(var1.toLowerCase())) {
- var2 = new Color(Integer.parseInt((String)ColorDictionary.ColorTable.get(var1.toLowerCase()), 16));
- }
- } catch (Exception var4) {
- System.out.println("Color Format Error: use color=#rrggbb or color=keyword");
- }
-
- return var2;
- }
- }
-
- public int preferredAscent() {
- return this.field_0.root.getAscent();
- }
-
- public int preferredHeight() {
- return this.field_0.root.getHeight();
- }
-
- public int preferredWidth() {
- return this.field_0.root.getWidth();
- }
-
- public void setAllSizes(int var1) {
- this.field_0.controls.setAllSizes(var1);
- }
-
- public void setColor(String var1) {
- Color var2 = this.resolveColor(var1);
- ((Component)this).setBackground(var2);
- this.field_0.initBG(var2);
- this.field_0.redraw();
- ((Component)this).repaint();
- }
-
- public void setEquation(String var1) {
- this.field_0.setRoot(new Box(this.field_0), new ContentBox(this.field_0));
- this.field_0.initBG();
-
- try {
- Parser var2 = (Parser)Class.forName("webeq3.parser." + this.use_parser + "." + this.use_parser).newInstance();
- var2.init(this.handler);
-
- try {
- if (this.use_parser.equals("webtex")) {
- var2.parse(this.field_1, this.macros, this.field_0.root, this.err);
- } else {
- var2.parse(this.field_1, this.macros, this.field_0.markupRoot, this.err);
- }
- } catch (Exception var5) {
- System.out.println(var5);
- ((Throwable)var5).printStackTrace();
- }
-
- this.field_0.registerActions();
- } catch (InstantiationException var6) {
- System.out.println(var6);
- } catch (IllegalAccessException var7) {
- System.out.println(var7);
- } catch (ClassNotFoundException var8) {
- System.out.println(var8);
- return;
- }
-
- this.field_0.redraw();
- ((Component)this).repaint();
- }
-
- public void setSize(int var1) {
- this.field_0.setPointSize(var1);
- this.field_0.redraw();
- ((Component)this).repaint();
- }
- }
-