home *** CD-ROM | disk | FTP | other *** search
- package webeq3.app;
-
- import java.awt.Component;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.util.Hashtable;
- import java.util.Vector;
- import webeq3.editor.Cursor;
- import webeq3.editor.InputHandler;
- import webeq3.editor.Template;
- import webeq3.schema.Box;
- import webeq3.schema.ContentBox;
- import webeq3.schema.MRow;
- import webeq3.schema.MTd;
- import webeq3.schema.MTr;
-
- public class EEquation extends Equation {
- private Cursor post_paint_box;
- public static Hashtable minChildren = new Hashtable();
- public static Hashtable maxChildren = new Hashtable();
- public static final int INSERT_MODE = 1;
- public static final int OVERWRITE_MODE = 2;
- public Cursor cursor;
- public boolean tainted = false;
- public int text_mode = 1;
- // $FF: renamed from: ih webeq3.editor.InputHandler
- public InputHandler field_0 = null;
- public Vector templates = new Vector();
- public int current_template = -1;
- public boolean atTop = false;
- Box lastRoot;
- Box lastCursor;
- boolean lastTainted;
- int lastTextMode;
- Vector lastTemplates;
- boolean lastAtTop;
- int lastCurrentTemplate;
- boolean lastCursorAtEnd;
- boolean lastCursorAtBegin;
- int lastInBox;
- boolean lastCursorAddTemplate;
- boolean lastHaveSelection;
- boolean safeToRestore;
-
- public EEquation() {
- }
-
- public EEquation(Handler var1) {
- super.handler = var1;
- ((Equation)this).setRoot(new Box(this), new ContentBox(this));
- this.tainted = false;
- this.atTop = true;
- super.padding = 3;
- }
-
- public EEquation(Handler var1, boolean var2) {
- super.handler = var1;
- ((Equation)this).setRoot(new Box(this), new ContentBox(this));
- this.tainted = false;
- this.atTop = var2;
- super.padding = 3;
- }
-
- public void postPaint(Graphics var1) {
- if (!super.haveSelection && this.post_paint_box != null) {
- this.post_paint_box.paint(var1);
- }
-
- }
-
- public Box findMatching(Box var1, Box var2, Box var3) {
- if (var3 == var1) {
- return var2;
- } else {
- for(int var7 = 0; var7 < var1.getNumChildren(); ++var7) {
- Box var5 = var1.getChild(var7);
-
- Box var6;
- try {
- var6 = var2.getChild(var7);
- } catch (NullPointerException var9) {
- var6 = null;
- }
-
- Box var4 = this.findMatching(var5, var6, var3);
- if (var4 != null) {
- return var4;
- }
- }
-
- return null;
- }
- }
-
- public boolean handleEvent(Event var1) {
- if (super.allow_cut && var1.id == 501 && super.oh != null && (var1.modifiers & 2) != 0) {
- super.root.printSelected("", super.oh);
- } else {
- if (var1.id == 501) {
- ((Component)this).requestFocus();
- super.root.clearSelection();
- if (super.allow_cut) {
- super.cutstartx = var1.x;
- super.cutstarty = var1.y;
- }
-
- int[] var5 = ((Equation)this).normalVirtualCoords(super.cutstartx, super.cutstarty);
- if (this.cursor.move(var5[0], var5[1], super.root)) {
- if (this.field_0 != null) {
- this.field_0.setState(0);
- }
-
- ((Equation)this).redraw();
- ((Component)this).repaint();
- super.handler.getComponent().repaint();
- }
-
- return true;
- }
-
- if (super.allow_cut && var1.id == 506) {
- super.cutendx = var1.x;
- super.cutendy = var1.y;
- int[] var2 = ((Equation)this).normalVirtualCoords(super.cutstartx, super.cutstarty);
- super.rectleft = var2[0];
- super.recttop = var2[1];
- var2 = ((Equation)this).normalVirtualCoords(super.cutendx, super.cutendy);
- super.rectright = var2[0];
- super.rectbottom = var2[1];
- if (super.rectright < super.rectleft) {
- int var3 = super.rectleft;
- super.rectleft = super.rectright;
- super.rectright = var3;
- }
-
- if (super.rectbottom < super.recttop) {
- int var7 = super.rectbottom;
- super.rectbottom = super.recttop;
- super.recttop = var7;
- }
-
- super.hilight_change = false;
- super.haveSelection = false;
- super.leftmostSelection = null;
- super.rightmostSelection = null;
- ((Equation)this).hilight(super.root);
- if (super.hilight_change) {
- ((Equation)this).redraw();
- ((Component)this).repaint();
- super.handler.getComponent().repaint();
- }
-
- return true;
- }
-
- if (var1.key == 9 && var1.id == 401) {
- this.tab_template_boxes();
- if (this.field_0 != null) {
- this.field_0.setState(0);
- }
-
- return true;
- }
- }
-
- boolean var6 = super.ah.handleAction(var1);
- if (!var6) {
- super.handler.showDefaultStatus();
- }
-
- return false;
- }
-
- public void InsertBox(Box var1) {
- Box var2;
- if (this.atTop) {
- var2 = this.cursor.getBox();
- } else if (this.cursor.getParent() == null) {
- var2 = this.cursor.getBox();
- } else {
- var2 = this.cursor.getParent();
- }
-
- if (var2.getClass().getName().equals("webeq3.schema.MTable") && !var1.getClass().getName().equals("webeq3.schema.MTr")) {
- MTr var3 = new MTr(var2);
- if (!var1.getClass().getName().equals("webeq3.schema.MTd")) {
- MTd var4 = new MTd(var2);
- ((Box)var4).insertChildAt((Box)var1, 0);
- ((Box)var3).insertChildAt(var4, 0);
- var1 = var3;
- } else {
- ((Box)var3).insertChildAt((Box)var1, 0);
- var1 = var3;
- }
- }
-
- if (var2.getClass().getName().equals("webeq3.schema.MTr") && !var1.getClass().getName().equals("webeq3.schema.MTd")) {
- MTd var5 = new MTd(var2);
- ((Box)var5).insertChildAt((Box)var1, 0);
- var1 = var5;
- }
-
- if (this.text_mode == 1) {
- if (!this.atTop && !this.cursor.isAtBegin()) {
- var2.insertChildAt((Box)var1, this.cursor.getBox().box_id + 1);
- this.cursor.toRight();
- } else {
- var2.insertChildAt((Box)var1, this.cursor.getBox().box_id);
- this.cursor.setBox((Box)var1);
- this.cursor.setAtBegin(false);
- }
- } else if (this.text_mode == 2) {
- Object var6 = null;
- int var8 = this.cursor.getBox().box_id;
- Box var7 = var2.removeChildAt(var8);
- var2.insertChildAt((Box)var1, var8);
- this.cursor.setBox((Box)var1);
- if (this.cursor.isAtBegin()) {
- this.cursor.setAtBegin(false);
- }
-
- if (var7 != null && var7.getClass().getName().equals("webeq3.editor.Template")) {
- if (this.templates.indexOf(var7) <= this.current_template) {
- --this.current_template;
- }
-
- this.templates.removeElement(var7);
- }
- }
-
- if (this.atTop) {
- this.atTop = false;
- }
-
- this.tainted = true;
- }
-
- public void splitBox() {
- Box var1 = this.cursor.getBox();
- int var2 = this.cursor.inBox();
- if ((var1.kind == 1 || var1.kind == 2) && var1.getDataLength() > var2 && var2 > 0) {
- Box var3 = var1.getCopy();
- Box var4 = var1.getCopy();
- int var5 = 0;
- String var7 = var1.adata;
- String var8 = var1.udata;
-
- for(int var9 = 0; var9 < var2; ++var9) {
- char var6 = var7.charAt(var5);
- if (var6 == '&') {
- var5 = var7.indexOf(59, var5);
- }
-
- ++var5;
- }
-
- var3.setAData(var7.substring(0, var5));
- var4.setAData(var7.substring(var5));
- var3.setUData(var8.substring(0, var2));
- var4.setUData(var8.substring(var2));
- var3.setData();
- var4.setData();
- Box var10 = var1.getParent();
- int var11 = var1.box_id;
- var10.removeChildAt(var11);
- var10.insertChildAt(var3, var11);
- var10.insertChildAt(var4, var11 + 1);
- this.cursor.setBox(var3);
- }
-
- }
-
- public boolean mergeBoxes() {
- Box var1 = this.cursor.getBox();
- Box var2 = var1.getParent();
- int var3 = var1.getBoxID();
- Box var4 = var2.getChild(var3 + 1);
- Box var5 = var2.getChild(var3 - 1);
- Box var6 = null;
- if (var4 != null && var1.kind == var4.kind && (var1.kind == 1 || var1.kind == 2)) {
- var6 = var1.getCopy();
- var6.addData(var4.adata);
- var6.setData();
- var2.removeChildAt(var3);
- var2.removeChildAt(var3);
- var2.insertChildAt(var6, var3);
- int var7 = this.cursor.inBox();
- this.cursor.setBox(var6);
- this.cursor.setInBox(var7);
- var1 = var6;
- }
-
- if (var5 != null && var1.kind == var5.kind && (var1.kind == 1 || var1.kind == 2)) {
- var6 = var5.getCopy();
- var6.addData(var1.adata);
- var6.setData();
- var2.removeChildAt(var3 - 1);
- var2.removeChildAt(var3 - 1);
- var2.insertChildAt(var6, var3 - 1);
- int var8 = this.cursor.inBox();
- this.cursor.setBox(var6);
- this.cursor.setInBox(var8 + var5.getDataLength());
- }
-
- if (var6 == null) {
- return false;
- } else {
- var6.layout();
- return true;
- }
- }
-
- public void gotoCurrentTemplate() {
- if (this.templates.size() != 0) {
- if (this.current_template < 0) {
- this.current_template = 0;
- }
-
- if (this.current_template >= this.templates.size()) {
- this.current_template = this.templates.size() - 1;
- }
-
- this.cursor.setBox((Box)this.templates.elementAt(this.current_template));
- this.cursor.tunnel();
- ((Equation)this).redraw();
- ((Component)this).repaint();
- }
- }
-
- private void tab_template_boxes() {
- if (this.templates.size() != 0) {
- if (this.current_template >= this.templates.size() - 1) {
- this.current_template = -1;
- }
-
- ++this.current_template;
- this.cursor.setBox((Box)this.templates.elementAt(this.current_template));
- this.cursor.tunnel();
- ((Equation)this).redraw();
- ((Component)this).repaint();
- }
- }
-
- public void recursiveRmTemplate(Box var1) {
- for(int var2 = 0; var2 < var1.getNumChildren(); ++var2) {
- Box var3 = var1.getChild(var2);
- if (var3 instanceof Template) {
- this.templates.removeElement(var3);
- }
-
- this.recursiveRmTemplate(var3);
- }
-
- }
-
- public void setCurrentTemplate(Template var1) {
- this.current_template = this.templates.indexOf(var1);
- }
-
- public void setCurrentTemplate(int var1) {
- this.current_template = var1;
- }
-
- public void removeTemplate(Template var1) {
- this.setCurrentTemplate(var1);
- this.templates.removeElement(var1);
- }
-
- public Template insertNecessaryTemplates(Box var1) {
- Template var2 = null;
- Box var3 = var1.getParent();
- String var4 = var3.getClass().getName();
- int var5 = (Integer)minChildren.get(var4);
- int var6 = var5 - var3.getNumChildren();
- if (var6 > 0) {
- if (!"webeq3.schema.Box".equals(var4) && !"webeq3.schema.MFrac".equals(var4) && !"webeq3.schema.MSqrt".equals(var4) && !"webeq3.schema.MRoot".equals(var4) && !"webeq3.schema.MSub".equals(var4) && !"webeq3.schema.MSup".equals(var4) && !"webeq3.schema.MSubsup".equals(var4) && !"webeq3.schema.MUnder".equals(var4) && !"webeq3.schema.MOver".equals(var4) && !"webeq3.schema.MUnderover".equals(var4)) {
- var2 = new Template(var3);
- var3.insertChildAt(var2, var1.box_id);
- this.addTemplate(var2);
- this.setCurrentTemplate(var2);
- } else {
- for(int var7 = 0; var7 < var6; ++var7) {
- MRow var8 = new MRow(var3);
- var3.insertChildAt(var8, var1.box_id + var7);
- var2 = new Template(var8);
- ((Box)var8).addChild(var2);
- this.addTemplate(var2);
- this.setCurrentTemplate(var2);
- }
- }
- }
-
- return var2;
- }
-
- public int getNumTemplates() {
- return this.templates.size();
- }
-
- public void addTemplate(Template var1) {
- this.templates.addElement(var1);
- this.setCurrentTemplate(var1);
- }
-
- public boolean isTainted() {
- return this.tainted;
- }
-
- public void setAllowCut(boolean var1) {
- super.allow_cut = var1;
- }
-
- public void setCursor(Cursor var1) {
- this.cursor = var1;
- this.post_paint_box = var1;
- }
-
- public void setInputHandler(InputHandler var1) {
- this.field_0 = var1;
- }
-
- public void setTainted(boolean var1) {
- this.tainted = var1;
- }
-
- public void setTextMode(int var1) {
- this.text_mode = var1;
- }
-
- public Cursor getECursor() {
- return this.cursor;
- }
-
- public int getTextMode() {
- return this.text_mode;
- }
-
- public void storeUndoInfo() {
- this.lastRoot = super.root.getCopy();
- this.lastCursor = this.findMatching(super.root, this.lastRoot, this.cursor.getBox());
- this.lastTainted = this.tainted;
- this.lastTextMode = this.text_mode;
- this.lastAtTop = this.atTop;
- this.lastHaveSelection = super.haveSelection;
- this.lastCursorAtEnd = this.cursor.isAtEnd();
- this.lastCursorAtBegin = this.cursor.isAtBegin();
- this.lastInBox = this.cursor.inBox();
- this.lastCursorAddTemplate = this.cursor.isAddTemplate();
- this.lastTemplates = new Vector();
-
- for(int var1 = 0; var1 < this.templates.size(); ++var1) {
- Box var2 = this.findMatching(super.root, this.lastRoot, (Box)this.templates.elementAt(var1));
- if (var2 != null) {
- this.lastTemplates.addElement(var2);
- }
- }
-
- this.lastCurrentTemplate = this.current_template;
- this.field_0.saveState(super.root, this.lastRoot);
- this.safeToRestore = true;
- }
-
- public void undo() {
- if (this.safeToRestore) {
- super.root = this.lastRoot;
- this.cursor = new Cursor(this.lastCursor);
- this.cursor.setEEquation(this);
- this.setCursor(this.cursor);
- this.cursor.setAtEnd(this.lastCursorAtEnd);
- this.cursor.setAtBegin(this.lastCursorAtBegin);
- this.cursor.setInBox(this.lastInBox);
- this.cursor.setAddTemplate(this.lastCursorAddTemplate);
- this.tainted = this.lastTainted;
- super.haveSelection = this.lastHaveSelection;
- this.text_mode = this.lastTextMode;
- this.templates = this.lastTemplates;
- this.current_template = this.lastCurrentTemplate;
- this.atTop = this.lastAtTop;
- this.field_0.restoreState();
- }
- }
-
- static {
- minChildren.put("webeq3.schema.MI", new Integer(1));
- minChildren.put("webeq3.schema.MN", new Integer(1));
- minChildren.put("webeq3.schema.MO", new Integer(1));
- minChildren.put("webeq3.schema.MText", new Integer(1));
- minChildren.put("webeq3.schema.MS", new Integer(1));
- minChildren.put("webeq3.schema.MFrac", new Integer(2));
- minChildren.put("webeq3.schema.MSqrt", new Integer(1));
- minChildren.put("webeq3.schema.MRoot", new Integer(2));
- minChildren.put("webeq3.schema.MRow", new Integer(1));
- minChildren.put("webeq3.schema.MStyle", new Integer(1));
- minChildren.put("webeq3.schema.MError", new Integer(1));
- minChildren.put("webeq3.schema.MPhantom", new Integer(1));
- minChildren.put("webeq3.schema.MFenced", new Integer(1));
- minChildren.put("webeq3.schema.MSub", new Integer(3));
- minChildren.put("webeq3.schema.MSup", new Integer(3));
- minChildren.put("webeq3.schema.MSubsup", new Integer(3));
- minChildren.put("webeq3.schema.MUnder", new Integer(3));
- minChildren.put("webeq3.schema.MOver", new Integer(3));
- minChildren.put("webeq3.schema.MUnderover", new Integer(3));
- minChildren.put("webeq3.schema.MMultiscripts", new Integer(1));
- minChildren.put("webeq3.schema.Box", new Integer(1));
- minChildren.put("webeq3.schema.MTable", new Integer(0));
- minChildren.put("webeq3.schema.MTr", new Integer(1));
- minChildren.put("webeq3.schema.MTd", new Integer(1));
- minChildren.put("webeq3.schema.MAction", new Integer(1));
- maxChildren.put("webeq3.schema.MI", new Integer(1));
- maxChildren.put("webeq3.schema.MN", new Integer(1));
- maxChildren.put("webeq3.schema.MO", new Integer(1));
- maxChildren.put("webeq3.schema.MText", new Integer(1));
- maxChildren.put("webeq3.schema.MS", new Integer(1));
- maxChildren.put("webeq3.schema.MFrac", new Integer(2));
- maxChildren.put("webeq3.schema.MSqrt", new Integer(1));
- maxChildren.put("webeq3.schema.MRoot", new Integer(2));
- maxChildren.put("webeq3.schema.MRow", new Integer(256));
- maxChildren.put("webeq3.schema.MStyle", new Integer(256));
- maxChildren.put("webeq3.schema.MError", new Integer(256));
- maxChildren.put("webeq3.schema.MPhantom", new Integer(256));
- maxChildren.put("webeq3.schema.MFenced", new Integer(256));
- maxChildren.put("webeq3.schema.MSub", new Integer(2));
- maxChildren.put("webeq3.schema.MSup", new Integer(2));
- maxChildren.put("webeq3.schema.MSubsup", new Integer(3));
- maxChildren.put("webeq3.schema.MUnder", new Integer(2));
- maxChildren.put("webeq3.schema.MOver", new Integer(2));
- maxChildren.put("webeq3.schema.MUnderover", new Integer(3));
- maxChildren.put("webeq3.schema.MMultiscripts", new Integer(256));
- maxChildren.put("webeq3.schema.Box", new Integer(256));
- maxChildren.put("webeq3.schema.MTable", new Integer(256));
- maxChildren.put("webeq3.schema.MTr", new Integer(256));
- maxChildren.put("webeq3.schema.MTd", new Integer(256));
- maxChildren.put("webeq3.schema.MAction", new Integer(256));
- }
- }
-