home *** CD-ROM | disk | FTP | other *** search
- package com.maplesoft;
-
- import java.applet.Applet;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.Toolkit;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.PrintStream;
- 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.fonts.FontBroker;
- import webeq3.parser.Parser;
- import webeq3.parser.mathml.mathml;
- import webeq3.schema.Box;
- import webeq3.schema.ContentBox;
- import webeq3.util.ErrorHandler;
-
- public class mathmlviewer extends Applet {
- // $FF: renamed from: eq webeq3.app.PEquation
- public PEquation field_0 = null;
- ErrorHandler err = new ErrorHandler();
- Handler handler = new Handler();
- boolean controls = false;
- boolean allow_cut = false;
- boolean linebreak = false;
- String equation = null;
- String src_file = null;
- // $FF: renamed from: in java.lang.String
- String field_1 = null;
- URL src_URL = null;
- int pointsize = 18;
- String align = "center";
- String valign = "baseline";
- int padding = 1;
- PrintStream out;
- public boolean isBehavior;
- public boolean readyToFire;
- public boolean sizingDone;
- private Vector m_listeners;
-
- public mathmlviewer() {
- this.out = System.out;
- this.isBehavior = false;
- this.readyToFire = false;
- this.sizingDone = false;
- }
-
- public boolean handleEvent(Event var1) {
- return this.field_0 != null ? this.field_0.handleEvent(var1) : false;
- }
-
- public void init() {
- this.m_listeners = new Vector();
- this.isBehavior = "true".equals(((Applet)this).getParameter("FiresScriptEvents"));
- this.handler.setDefaultStatus("");
- this.handler.setParameters(this);
- this.equation = ((Applet)this).getParameter("eq");
- 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);
- Toolkit var2 = ((Component)this).getToolkit();
- int var3 = var2.getScreenResolution();
- this.pointsize = (int)((double)(var3 * this.pointsize) / (double)72.0F);
- }
-
- var1 = ((Applet)this).getParameter("background");
- if (var1 == null) {
- var1 = ((Applet)this).getParameter("color");
- }
-
- if (var1 == null) {
- var1 = "white";
- }
-
- Color var17 = this.resolveColor(var1);
- if (var17 != null) {
- ((Component)this).setBackground(var17);
- }
-
- var1 = ((Applet)this).getParameter("foreground");
- if (var1 == null) {
- var1 = "black";
- }
-
- var17 = this.resolveColor(var1);
- if (var17 != null) {
- ((Component)this).setForeground(var17);
- }
-
- if (this.equation != null && !this.equation.equals("")) {
- this.field_1 = this.equation;
- } else if (this.src_file == null) {
- this.out.println("WebEQ Error: A WebEQ Applet call must include either an EQ or an SRC parameter.");
- this.field_1 = "<math><mi>error</mi></math>";
- } else {
- try {
- this.src_URL = new URL(((Applet)this).getDocumentBase(), this.src_file);
- } catch (MalformedURLException var8) {
- this.out.println("Bad URL for equation source: " + var8);
- }
-
- this.field_1 = this.convertToString(this.src_URL);
- }
-
- this.field_0 = new PEquation(this.handler);
- this.field_0.setBackground(((Component)this).getBackground());
- this.field_0.setForeground(((Component)this).getForeground());
- this.field_0.initBG(((Component)this).getBackground());
- this.field_0.initFG(((Component)this).getForeground());
- 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.setSelection(this.allow_cut);
- this.field_0.setControls(this.controls);
- this.field_0.setAlign(this.align);
- this.field_0.setVAlign(this.valign);
- FontBroker.initialize(true);
- mathml var19 = new mathml();
- ((Parser)var19).init(this.handler);
-
- try {
- ((Parser)var19).parse(this.field_1, (String)null, this.field_0.markupRoot, this.err);
- } catch (Exception var7) {
- System.out.println(var7);
- }
-
- this.field_0.registerActions();
- if (this.isBehavior) {
- try {
- this.field_0.root.layout();
- this.readyToFire = true;
- this.fireEvent();
- } catch (Exception var6) {
- System.out.println("layout errors -- rendering failed\n" + var6);
- }
- } else {
- try {
- this.field_0.redraw();
- } catch (Exception var5) {
- }
- }
-
- }
-
- public void paint(Graphics var1) {
- if (!this.isBehavior || this.readyToFire) {
- this.field_0.setSize(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 synchronized void setSizeNoRefresh(int var1) {
- this.field_0.setPointSize(var1);
- }
-
- public synchronized void setSize(int var1) {
- this.field_0.setPointSize(var1);
- this.field_0.redraw();
- ((Component)this).repaint();
- }
-
- public void setAllSizes(int var1) {
- this.field_0.controls.setAllSizes(var1);
- }
-
- public synchronized int preferredHeight() {
- try {
- return this.field_0.getPreferredHeight();
- } catch (Exception var2) {
- return 0;
- }
- }
-
- public synchronized int preferredWidth() {
- try {
- return this.field_0.getPreferredWidth();
- } catch (Exception var2) {
- return 0;
- }
- }
-
- public synchronized int preferredAscent() {
- try {
- return this.field_0.getPreferredAscent();
- } catch (Exception var2) {
- return 0;
- }
- }
-
- public synchronized void setColorNoRefresh(String var1) {
- Color var2 = this.resolveColor(var1);
- ((Component)this).setBackground(var2);
- this.field_0.initBG(var2);
- }
-
- public synchronized 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 synchronized void setEquation(String var1) {
- this.field_0.setRoot(new Box(this.field_0), new ContentBox(this.field_0));
- this.field_0.initBG();
- mathml var2 = new mathml();
- ((Parser)var2).init(this.handler);
-
- try {
- ((Parser)var2).parse(var1, (String)null, this.field_0.markupRoot, this.err);
- } catch (Exception var4) {
- System.out.println(var4);
- ((Throwable)var4).printStackTrace();
- }
-
- this.field_0.registerActions();
- this.field_0.redraw();
- ((Component)this).repaint();
- }
-
- public void refresh() {
- this.field_0.redraw();
- ((Component)this).repaint();
- }
-
- public void addmathmlviewerListener(mathmlviewerListener var1) {
- if (this.m_listeners == null) {
- this.m_listeners = new Vector();
- }
-
- this.m_listeners.addElement(var1);
- if (this.readyToFire) {
- this.fireEvent();
- }
-
- }
-
- public void removemathmlviewerListener(mathmlviewerListener var1) {
- this.m_listeners.removeElement(var1);
- }
-
- private void fireEvent() {
- Vector var2 = this.m_listeners;
- mathmlviewerListener[] var1;
- synchronized(var2) {
- var1 = new mathmlviewerListener[this.m_listeners.size()];
- this.m_listeners.copyInto(var1);
- }
-
- for(int var3 = 0; var3 < var1.length; ++var3) {
- var1[var3].mathmlviewerResize(((Applet)this).getParameter("id"));
- }
-
- }
-
- 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;
- }
- }
-
- private String convertToString(URL var1) {
- String var2 = "";
- byte[] var4 = new byte[1024];
- InputStream var5 = null;
-
- try {
- var5 = var1.openStream();
- } catch (IOException var7) {
- this.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) {
- this.out.println("Error reading " + var1);
- }
- }
- }
- }
-