diff --git a/core/src/main/java/it/cavallium/warppi/device/Keyboard.java b/core/src/main/java/it/cavallium/warppi/device/Keyboard.java index c7cb538f..0b7be942 100644 --- a/core/src/main/java/it/cavallium/warppi/device/Keyboard.java +++ b/core/src/main/java/it/cavallium/warppi/device/Keyboard.java @@ -108,7 +108,7 @@ public class Keyboard { public static void debugKeyPressed(final int keyCode) { switch (keyCode) { case KeyEvent.VK_ESCAPE: - Keyboard.keyPressed(Key.POWEROFF); + Keyboard.keyPressed(Key.BACK); break; case KeyEvent.VK_S: if (Keyboard.shift) { diff --git a/core/src/main/java/it/cavallium/warppi/gui/CalculatorHUD.java b/core/src/main/java/it/cavallium/warppi/gui/CalculatorHUD.java index ee556815..e81a3a4f 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/CalculatorHUD.java +++ b/core/src/main/java/it/cavallium/warppi/gui/CalculatorHUD.java @@ -137,6 +137,8 @@ public class CalculatorHUD extends HUD { currentDebugLine++; } } + r.glColor(0xFF000000); + r.glDrawStringLeft(5, StaticVars.screenSize[1] - ((currentDebugLine+1) * (r.getCurrentFont().getCharacterHeight()+1)), "DEBUG ENABLED"); } } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/Caret.java b/core/src/main/java/it/cavallium/warppi/gui/expression/Caret.java index 43b32f0e..1623884f 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/Caret.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/Caret.java @@ -1,8 +1,8 @@ package it.cavallium.warppi.gui.expression; -import java.io.Serializable; +import java.util.Arrays; -public class Caret implements Serializable { +public class Caret { private int pos; private int remaining; @@ -22,6 +22,18 @@ public class Caret implements Serializable { this.lastSize = lastSize; } + /** + * Copy + * @param old + */ + public Caret(Caret old) { + this.pos = old.pos; + this.remaining = old.remaining; + this.state = old.state; + this.lastSize = Arrays.copyOf(old.lastSize, old.lastSize.length); + this.lastLocation = Arrays.copyOf(old.lastLocation, old.lastLocation.length); + } + public void skip(final int i) { remaining -= i; } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/CaretState.java b/core/src/main/java/it/cavallium/warppi/gui/expression/CaretState.java index a00d8917..c7949f42 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/CaretState.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/CaretState.java @@ -1,7 +1,5 @@ package it.cavallium.warppi.gui.expression; -import java.io.Serializable; - -public enum CaretState implements Serializable { +public enum CaretState { VISIBLE_ON, VISIBLE_OFF, HIDDEN } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/ExtraMenu.java b/core/src/main/java/it/cavallium/warppi/gui/expression/ExtraMenu.java index e2260359..e28d6c5c 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/ExtraMenu.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/ExtraMenu.java @@ -1,13 +1,14 @@ package it.cavallium.warppi.gui.expression; -import java.io.Serializable; +import java.util.Arrays; import it.cavallium.warppi.event.KeyboardEventListener; import it.cavallium.warppi.gui.expression.blocks.Block; +import it.cavallium.warppi.gui.expression.blocks.BlockVariable; import it.cavallium.warppi.gui.graphicengine.GraphicEngine; import it.cavallium.warppi.gui.graphicengine.Renderer; -public abstract class ExtraMenu implements Serializable, KeyboardEventListener { +public abstract class ExtraMenu implements KeyboardEventListener { private static final long serialVersionUID = -6944683477814944299L; @@ -18,6 +19,13 @@ public abstract class ExtraMenu implements Serializable, Keyboa this.height = 0; } + public ExtraMenu(final ExtraMenu old, final T newBlock) { + this.block = newBlock; + this.location = Arrays.copyOf(old.location, old.location.length); + this.width = old.width; + this.height = old.height; + } + public final T block; protected int width; protected int height; @@ -37,4 +45,8 @@ public abstract class ExtraMenu implements Serializable, Keyboa return false; } + public abstract ExtraMenu clone(InputContext ic); + + public abstract ExtraMenu clone(T newBlockVariable); + } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/InputContext.java b/core/src/main/java/it/cavallium/warppi/gui/expression/InputContext.java index cb6c5452..6460d22c 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/InputContext.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/InputContext.java @@ -1,13 +1,12 @@ package it.cavallium.warppi.gui.expression; -import java.io.Serializable; import java.util.HashMap; import it.cavallium.warppi.gui.expression.blocks.BlockVariable; import it.cavallium.warppi.math.MathematicalSymbols; import it.cavallium.warppi.math.functions.Variable.V_TYPE; -public class InputContext implements Serializable { +public class InputContext { public final HashMap variableTypes; public BlockVariable variableTypeDirtyID = null; @@ -20,4 +19,10 @@ public class InputContext implements Serializable { public InputContext(final HashMap variableTypes) { this.variableTypes = variableTypes; } + + public InputContext(InputContext ic) { + this.variableTypes = new HashMap<>(); + this.variableTypes.putAll(ic.variableTypes); + this.variableTypeDirtyID = ic.variableTypeDirtyID; + } } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/Block.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/Block.java index a942c7e2..a7da8269 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/Block.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/Block.java @@ -3,6 +3,7 @@ package it.cavallium.warppi.gui.expression.blocks; import it.cavallium.warppi.gui.GraphicalElement; import it.cavallium.warppi.gui.expression.Caret; import it.cavallium.warppi.gui.expression.ExtraMenu; +import it.cavallium.warppi.gui.expression.InputContext; import it.cavallium.warppi.gui.graphicengine.GraphicEngine; import it.cavallium.warppi.gui.graphicengine.Renderer; import it.cavallium.warppi.math.MathContext; @@ -93,4 +94,6 @@ public abstract class Block implements TreeBlock, GraphicalElement { public void setParent(final TreeContainer parent) { this.parent = parent; } + + public abstract Block clone(InputContext ic); } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockChar.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockChar.java index 1008e36a..badada78 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockChar.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockChar.java @@ -1,6 +1,7 @@ package it.cavallium.warppi.gui.expression.blocks; import it.cavallium.warppi.gui.expression.Caret; +import it.cavallium.warppi.gui.expression.InputContext; import it.cavallium.warppi.gui.graphicengine.GraphicEngine; import it.cavallium.warppi.gui.graphicengine.Renderer; import it.cavallium.warppi.math.MathContext; @@ -17,6 +18,11 @@ public class BlockChar extends Block { recomputeDimensions(); } + public BlockChar(final char ch, InputContext ic) { + this.ch = ch; + recomputeDimensions(); + } + @Override public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) { BlockContainer.getDefaultFont(small).use(ge); @@ -76,4 +82,9 @@ public class BlockChar extends Block { return 0; } + @Override + public BlockChar clone(InputContext ic) { + return new BlockChar(ch, ic); + } + } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockContainer.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockContainer.java index f2be80c4..a7606e7a 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockContainer.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockContainer.java @@ -1,9 +1,12 @@ package it.cavallium.warppi.gui.expression.blocks; +import java.util.Arrays; + import it.cavallium.warppi.Engine; import it.cavallium.warppi.gui.GraphicalElement; import it.cavallium.warppi.gui.expression.Caret; import it.cavallium.warppi.gui.expression.CaretState; +import it.cavallium.warppi.gui.expression.InputContext; import it.cavallium.warppi.gui.graphicengine.BinaryFont; import it.cavallium.warppi.gui.graphicengine.GraphicEngine; import it.cavallium.warppi.gui.graphicengine.Renderer; @@ -31,6 +34,11 @@ public class BlockContainer implements TreeContainer, GraphicalElement { private boolean autoMinimums; private final TreeBlock parent; + public BlockContainer() { + this(null, false, BlockContainer.getDefaultCharWidth(false), BlockContainer.getDefaultCharHeight(false), true); + autoMinimums = true; + } + public BlockContainer(final TreeBlock parent) { this(parent, false, BlockContainer.getDefaultCharWidth(false), BlockContainer.getDefaultCharHeight(false), true); autoMinimums = true; @@ -71,6 +79,26 @@ public class BlockContainer implements TreeContainer, GraphicalElement { recomputeDimensions(); } + private BlockContainer(BlockContainer old, InputContext ic) { + this.autoMinimums = old.autoMinimums; + this.content = new ObjectArrayList<>(); + for (Block b : old.content) { + this.content.add(b.clone(ic)); + } + this.height = old.height; + this.line = old.line; + this.minHeight = old.minHeight; + this.minWidth = old.minWidth; + this.parent = old.parent; + this.small = old.small; + this.width = old.width; + this.withBorder = old.withBorder; + } + + public BlockContainer clone(InputContext ic) { + return new BlockContainer(this, ic); + } + @Override public TreeBlock getParentBlock() { return parent; diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockDivision.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockDivision.java index 18e31c59..fabc7108 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockDivision.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockDivision.java @@ -1,6 +1,7 @@ package it.cavallium.warppi.gui.expression.blocks; import it.cavallium.warppi.gui.expression.Caret; +import it.cavallium.warppi.gui.expression.InputContext; import it.cavallium.warppi.gui.graphicengine.GraphicEngine; import it.cavallium.warppi.gui.graphicengine.Renderer; import it.cavallium.warppi.math.Function; @@ -26,6 +27,12 @@ public class BlockDivision extends Block { recomputeDimensions(); } + private BlockDivision(BlockDivision old, InputContext ic) { + containerUp = old.containerUp.clone(ic); + containerDown = old.containerDown.clone(ic); + recomputeDimensions(); + } + @Override public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) { BlockContainer.getDefaultFont(small).use(ge); @@ -132,4 +139,9 @@ public class BlockDivision extends Block { public int getInnerContainersCount() { return 2; } + + @Override + public BlockDivision clone(InputContext ic) { + return new BlockDivision(this, ic); + } } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockLogarithm.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockLogarithm.java index 3d99f9a8..0973b061 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockLogarithm.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockLogarithm.java @@ -1,6 +1,7 @@ package it.cavallium.warppi.gui.expression.blocks; import it.cavallium.warppi.gui.expression.Caret; +import it.cavallium.warppi.gui.expression.InputContext; import it.cavallium.warppi.gui.graphicengine.GraphicEngine; import it.cavallium.warppi.gui.graphicengine.Renderer; import it.cavallium.warppi.math.Function; @@ -39,6 +40,12 @@ public class BlockLogarithm extends Block implements IParenthesis { recomputeDimensions(); } + private BlockLogarithm(BlockLogarithm old, InputContext ic) { + containerBase = old.containerBase.clone(ic); + containerNumber = old.containerNumber.clone(ic); + recomputeDimensions(); + } + @Override public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) { BlockContainer.getDefaultFont(small).use(ge); @@ -171,4 +178,9 @@ public class BlockLogarithm extends Block implements IParenthesis { return 2; } + @Override + public BlockLogarithm clone(InputContext ic) { + return new BlockLogarithm(this, ic); + } + } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockParenthesis.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockParenthesis.java index 01f40696..5b8212d6 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockParenthesis.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockParenthesis.java @@ -1,5 +1,6 @@ package it.cavallium.warppi.gui.expression.blocks; +import it.cavallium.warppi.gui.expression.InputContext; import it.cavallium.warppi.math.Function; import it.cavallium.warppi.math.MathContext; import it.cavallium.warppi.math.parser.features.FeatureParenthesis; @@ -14,6 +15,10 @@ public class BlockParenthesis extends BlockParenthesisAbstract { super(blocks); } + private BlockParenthesis(BlockParenthesis old, InputContext ic) { + super(old, ic); + } + @Override public Feature toFeature(final MathContext context) throws Error { final Function cont = getNumberContainer().toFunction(context); @@ -30,4 +35,9 @@ public class BlockParenthesis extends BlockParenthesisAbstract { return 1; } + @Override + public BlockParenthesis clone(InputContext ic) { + return new BlockParenthesis(this, ic); + } + } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockParenthesisAbstract.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockParenthesisAbstract.java index 2f28adcd..063cd523 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockParenthesisAbstract.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockParenthesisAbstract.java @@ -1,6 +1,7 @@ package it.cavallium.warppi.gui.expression.blocks; import it.cavallium.warppi.gui.expression.Caret; +import it.cavallium.warppi.gui.expression.InputContext; import it.cavallium.warppi.gui.graphicengine.GraphicEngine; import it.cavallium.warppi.gui.graphicengine.Renderer; import it.cavallium.warppi.math.MathContext; @@ -30,6 +31,12 @@ public abstract class BlockParenthesisAbstract extends Block implements IParenth recomputeDimensions(); } + BlockParenthesisAbstract(BlockParenthesisAbstract old, InputContext ic) { + containerNumber = old.containerNumber.clone(ic); + prefix = old.prefix == null ? null : new String(old.prefix); + recomputeDimensions(); + } + public BlockParenthesisAbstract(final ObjectArrayList blocks) { containerNumber = new BlockContainer(this, false, blocks); prefix = null; diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockPower.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockPower.java index f70121a5..d3a46817 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockPower.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockPower.java @@ -1,6 +1,7 @@ package it.cavallium.warppi.gui.expression.blocks; import it.cavallium.warppi.gui.expression.Caret; +import it.cavallium.warppi.gui.expression.InputContext; import it.cavallium.warppi.gui.graphicengine.GraphicEngine; import it.cavallium.warppi.gui.graphicengine.Renderer; import it.cavallium.warppi.math.Function; @@ -19,6 +20,10 @@ public class BlockPower extends Block { recomputeDimensions(); } + private BlockPower(BlockPower old, InputContext ic) { + this.containerExponent = old.containerExponent.clone(ic); + } + @Override public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) { BlockContainer.getDefaultFont(true).use(ge); @@ -91,4 +96,9 @@ public class BlockPower extends Block { public int getInnerContainersCount() { return 1; } + + @Override + public BlockPower clone(InputContext ic) { + return new BlockPower(this, ic); + } } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockPower2.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockPower2.java index 3721281d..f0238085 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockPower2.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockPower2.java @@ -1,6 +1,7 @@ package it.cavallium.warppi.gui.expression.blocks; import it.cavallium.warppi.gui.expression.Caret; +import it.cavallium.warppi.gui.expression.InputContext; import it.cavallium.warppi.gui.graphicengine.GraphicEngine; import it.cavallium.warppi.gui.graphicengine.Renderer; import it.cavallium.warppi.math.Function; @@ -20,6 +21,10 @@ public class BlockPower2 extends Block { recomputeDimensions(); } + private BlockPower2(BlockPower2 old, InputContext ic) { + this.containerExponent = old.containerExponent.clone(ic); + } + @Override public int getCaretDeltaPositionAfterCreation() { return 3; @@ -97,4 +102,9 @@ public class BlockPower2 extends Block { public int getInnerContainersCount() { return 1; } + + @Override + public BlockPower2 clone(InputContext ic) { + return new BlockPower2(this, ic); + } } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockSine.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockSine.java index af2c2bbd..468e6736 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockSine.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockSine.java @@ -1,5 +1,6 @@ package it.cavallium.warppi.gui.expression.blocks; +import it.cavallium.warppi.gui.expression.InputContext; import it.cavallium.warppi.math.Function; import it.cavallium.warppi.math.MathContext; import it.cavallium.warppi.math.parser.features.FeatureSine; @@ -12,9 +13,18 @@ public class BlockSine extends BlockParenthesisAbstract { super("SIN"); } + private BlockSine(BlockSine old, InputContext ic) { + super(old, ic); + } + @Override public Feature toFeature(final MathContext context) throws Error { final Function cont = getNumberContainer().toFunction(context); return new FeatureSine(cont); } + + @Override + public Block clone(InputContext ic) { + return new BlockSine(this, ic); + } } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockSquareRoot.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockSquareRoot.java index 48a23396..7886c580 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockSquareRoot.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockSquareRoot.java @@ -1,6 +1,7 @@ package it.cavallium.warppi.gui.expression.blocks; import it.cavallium.warppi.gui.expression.Caret; +import it.cavallium.warppi.gui.expression.InputContext; import it.cavallium.warppi.gui.graphicengine.GraphicEngine; import it.cavallium.warppi.gui.graphicengine.Renderer; import it.cavallium.warppi.math.Function; @@ -21,6 +22,11 @@ public class BlockSquareRoot extends Block { recomputeDimensions(); } + private BlockSquareRoot(BlockSquareRoot old, InputContext ic) { + this.containerNumber = old.containerNumber.clone(ic); + recomputeDimensions(); + } + @Override public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) { BlockContainer.getDefaultFont(small).use(ge); @@ -108,4 +114,9 @@ public class BlockSquareRoot extends Block { public int getInnerContainersCount() { return 1; //2 } + + @Override + public BlockSquareRoot clone(InputContext ic) { + return new BlockSquareRoot(this, ic); + } } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockUndefined.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockUndefined.java index e6cb92de..91191390 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockUndefined.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockUndefined.java @@ -1,6 +1,7 @@ package it.cavallium.warppi.gui.expression.blocks; import it.cavallium.warppi.gui.expression.Caret; +import it.cavallium.warppi.gui.expression.InputContext; import it.cavallium.warppi.gui.graphicengine.GraphicEngine; import it.cavallium.warppi.gui.graphicengine.Renderer; import it.cavallium.warppi.math.MathContext; @@ -15,6 +16,10 @@ public class BlockUndefined extends Block { recomputeDimensions(); } + private BlockUndefined(BlockUndefined old, InputContext ic) { + recomputeDimensions(); + } + @Override public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) { BlockContainer.getDefaultFont(small).use(ge); @@ -70,4 +75,9 @@ public class BlockUndefined extends Block { return 0; } + @Override + public BlockUndefined clone(InputContext ic) { + return new BlockUndefined(this, ic); + } + } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockVariable.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockVariable.java index 4af7a821..e83ac44a 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockVariable.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockVariable.java @@ -1,5 +1,7 @@ package it.cavallium.warppi.gui.expression.blocks; +import java.util.Arrays; + import it.cavallium.warppi.Engine; import it.cavallium.warppi.event.KeyPressedEvent; import it.cavallium.warppi.event.KeyReleasedEvent; @@ -43,6 +45,18 @@ public class BlockVariable extends Block { recomputeDimensions(); } + private BlockVariable(BlockVariable old, InputContext ic) { + this.ic = ic; + this.ch = old.ch; + type = old.type; + color = old.color; + typeDirtyID = old.typeDirtyID; + this.typeLocked = old.typeLocked; + menu = old.menu == null ? null : new VariableMenu(old.menu, this); + retrieveValue(); + recomputeDimensions(); + } + private void retrieveValue() { type = ic.variableTypes.get(ch); if (type == null) { @@ -53,7 +67,6 @@ public class BlockVariable extends Block { menu.mustRefreshMenu = true; } mustRefresh = true; - System.out.println("retrieve:" + type.toString()); } public void pushValue() { @@ -145,7 +158,11 @@ public class BlockVariable extends Block { super(var); } - private static final long serialVersionUID = 3941994107852212764L; + private VariableMenu(VariableMenu old, BlockVariable newBlockVariable) { + super(old, newBlockVariable); + this.mustRefreshMenu = old.mustRefreshMenu; + this.text = new String(old.text); + } @Override public void open() { @@ -250,6 +267,16 @@ public class BlockVariable extends Block { r.glDrawStringCenter(popupX + width / 2, popupY + 2 + 5, text); } + @Override + public VariableMenu clone(BlockVariable newBlockVariable) { + return new VariableMenu(this, newBlockVariable); + } + + @Override + public VariableMenu clone(InputContext ic) { + return new VariableMenu(this, block.clone(ic)); + } + } @Override @@ -266,4 +293,9 @@ public class BlockVariable extends Block { public int getInnerContainersCount() { return 0; } + + @Override + public BlockVariable clone(InputContext ic) { + return new BlockVariable(this, ic); + } } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/TreeBlock.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/TreeBlock.java index c0d751fa..0979854d 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/TreeBlock.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/TreeBlock.java @@ -1,8 +1,6 @@ package it.cavallium.warppi.gui.expression.blocks; -import java.io.Serializable; - -public interface TreeBlock extends Serializable { +public interface TreeBlock { TreeContainer getParentContainer(); boolean hasParent(); diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/TreeContainer.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/TreeContainer.java index 4c77b148..9cb15777 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/TreeContainer.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/TreeContainer.java @@ -1,8 +1,6 @@ package it.cavallium.warppi.gui.expression.blocks; -import java.io.Serializable; - -public interface TreeContainer extends Serializable { +public interface TreeContainer { TreeBlock getParentBlock(); boolean hasParent(); diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/containers/InputContainer.java b/core/src/main/java/it/cavallium/warppi/gui/expression/containers/InputContainer.java index 6294ab80..72a88e35 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/containers/InputContainer.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/containers/InputContainer.java @@ -1,7 +1,5 @@ package it.cavallium.warppi.gui.expression.containers; -import java.io.Serializable; - import it.cavallium.warppi.event.KeyboardEventListener; import it.cavallium.warppi.gui.GraphicalElement; import it.cavallium.warppi.gui.expression.Caret; @@ -19,9 +17,9 @@ import it.cavallium.warppi.math.MathContext; import it.cavallium.warppi.util.Error; import it.unimi.dsi.fastutil.objects.ObjectArrayList; -public abstract class InputContainer implements GraphicalElement, InputLayout, Serializable { +public abstract class InputContainer implements GraphicalElement, InputLayout { private static final long serialVersionUID = 923589369317765667L; - protected final BlockContainer root; + protected BlockContainer root; protected Caret caret; private static final float CARET_DURATION = 0.5f; private float caretTime; @@ -55,6 +53,21 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S caret = new Caret(CaretState.VISIBLE_ON, 0); root = new BlockContainer(null, small, false); } + + /** + * Copy + * @param old + * @param ic + */ + protected InputContainer(InputContainer old, InputContext ic) { + this.caretTime = old.caretTime; + this.extra = old.extra == null ? null : old.extra.clone(ic); + this.maxPosition = old.maxPosition; + this.caret = old.caret == null ? null : new Caret(old.caret); + this.inputContext = ic; + this.root = old.root == null ? null : old.root.clone(ic); + this.parsed = old.parsed; + } public void typeChar(final char c) { final Block b = parseChar(c); @@ -117,6 +130,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S } public void moveRight(final int delta) { + final int curPos = caret.getPosition(); if (curPos + delta < maxPosition) { caret.setPosition(curPos + delta); diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/containers/NormalInputContainer.java b/core/src/main/java/it/cavallium/warppi/gui/expression/containers/NormalInputContainer.java index 94c8512c..1de13251 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/containers/NormalInputContainer.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/containers/NormalInputContainer.java @@ -21,8 +21,6 @@ import it.cavallium.warppi.math.MathematicalSymbols; public class NormalInputContainer extends InputContainer { - private static final long serialVersionUID = 5236564695997222322L; - @Deprecated() /** * Use NormalInputContainer(InputContext) instead @@ -43,6 +41,16 @@ public class NormalInputContainer extends InputContainer { super(ic, small, minWidth, minHeight); } + /** + * Copy + * @param userInput + * @param ic + */ + @SuppressWarnings("deprecation") + public NormalInputContainer(InputContainer old, InputContext ic) { + super(old, ic); + } + @Override public Block parseChar(final char c) { switch (c) { diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/containers/NormalOutputContainer.java b/core/src/main/java/it/cavallium/warppi/gui/expression/containers/NormalOutputContainer.java index a5c6a632..c1f1d500 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/containers/NormalOutputContainer.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/containers/NormalOutputContainer.java @@ -1,8 +1,9 @@ package it.cavallium.warppi.gui.expression.containers; -public class NormalOutputContainer extends OutputContainer { +import it.cavallium.warppi.gui.expression.blocks.BlockContainer; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; - private static final long serialVersionUID = 5087850494875415142L; +public class NormalOutputContainer extends OutputContainer { public NormalOutputContainer() { super(); @@ -15,4 +16,9 @@ public class NormalOutputContainer extends OutputContainer { public NormalOutputContainer(final boolean small, final int minWidth, final int minHeight) { super(small, minWidth, minHeight); } + + public NormalOutputContainer(OutputContainer old) { + super.roots.clear(); + super.roots.addAll(old.roots.clone()); + } } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/containers/OutputContainer.java b/core/src/main/java/it/cavallium/warppi/gui/expression/containers/OutputContainer.java index 29a451cc..b75d0bdc 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/containers/OutputContainer.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/containers/OutputContainer.java @@ -1,7 +1,5 @@ package it.cavallium.warppi.gui.expression.containers; -import java.io.Serializable; - import it.cavallium.warppi.gui.GraphicalElement; import it.cavallium.warppi.gui.expression.Caret; import it.cavallium.warppi.gui.expression.CaretState; @@ -12,14 +10,14 @@ import it.cavallium.warppi.gui.graphicengine.GraphicEngine; import it.cavallium.warppi.gui.graphicengine.Renderer; import it.unimi.dsi.fastutil.objects.ObjectArrayList; -public abstract class OutputContainer implements GraphicalElement, OutputLayout, Serializable { +public abstract class OutputContainer implements GraphicalElement, OutputLayout { private static final long serialVersionUID = -5714825964892683571L; public final ObjectArrayList roots; private final Caret caret = new Caret(CaretState.HIDDEN, 0); public OutputContainer() { roots = new ObjectArrayList<>(); - roots.add(new BlockContainer(null)); + roots.add(new BlockContainer()); } public OutputContainer(final boolean small) { @@ -34,7 +32,7 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout, public void setContentAsSingleGroup(final ObjectArrayList blocks) { roots.clear(); - final BlockContainer bcnt = new BlockContainer(null); + final BlockContainer bcnt = new BlockContainer(); for (final Block block : blocks) { bcnt.appendBlockUnsafe(block); } @@ -45,7 +43,7 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout, public void setContentAsMultipleGroups(final ObjectArrayList> roots) { this.roots.clear(); for (final ObjectArrayList blocks : roots) { - final BlockContainer bcnt = new BlockContainer(null); + final BlockContainer bcnt = new BlockContainer(); for (final Block block : blocks) { bcnt.appendBlockUnsafe(block); } @@ -57,7 +55,7 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout, public void setContentAsMultipleElements(final ObjectArrayList elems) { roots.clear(); for (final Block block : elems) { - final BlockContainer bcnt = new BlockContainer(null); + final BlockContainer bcnt = new BlockContainer(); bcnt.appendBlockUnsafe(block); roots.add(bcnt); } @@ -131,7 +129,7 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout, public void clear() { roots.clear(); - roots.add(new BlockContainer(null)); + roots.add(new BlockContainer()); recomputeDimensions(); } diff --git a/core/src/main/java/it/cavallium/warppi/gui/screens/MathInputScreen.java b/core/src/main/java/it/cavallium/warppi/gui/screens/MathInputScreen.java index dda9fa22..f87cfd1e 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/screens/MathInputScreen.java +++ b/core/src/main/java/it/cavallium/warppi/gui/screens/MathInputScreen.java @@ -63,6 +63,24 @@ public class MathInputScreen extends Screen { canBeInHistory = true; } + /** + * Create a copy of this element + * @param mathInputScreen + */ + private MathInputScreen(MathInputScreen old) { + this.calc = new MathContext(old.calc); + this.canBeInHistory = old.canBeInHistory; + this.created = old.created; + this.currentStep = old.currentStep; + this.d = old.d; + this.errorLevel = old.errorLevel; + this.ic = new InputContext(old.ic); + this.initialized = old.initialized; + this.mustRefresh = old.mustRefresh; + this.result = new NormalOutputContainer(old.result); + this.userInput = new NormalInputContainer(old.userInput, this.ic); + } + @Override public void created() throws InterruptedException { ic = new InputContext(); @@ -471,19 +489,7 @@ public class MathInputScreen extends Screen { @SuppressWarnings("unchecked") private void swapInputScreen() { - MathInputScreen mis = new MathInputScreen(); - mis.calc = SerializationUtils.clone(calc); - mis.canBeInHistory = true; - mis.currentStep = currentStep; - mis.created = created; - mis.d = d; - mis.errorLevel = errorLevel; - mis.ic = SerializationUtils.clone(ic); - mis.initialized = initialized; - mis.mustRefresh = true; - mis.result = SerializationUtils.clone(result); - mis.userInput = SerializationUtils.clone(userInput); - mis.d = d; + MathInputScreen mis = new MathInputScreen(this); Engine.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(mis); } diff --git a/core/src/main/java/it/cavallium/warppi/gui/screens/Screen.java b/core/src/main/java/it/cavallium/warppi/gui/screens/Screen.java index e006b59e..71db64fc 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/screens/Screen.java +++ b/core/src/main/java/it/cavallium/warppi/gui/screens/Screen.java @@ -1,7 +1,5 @@ package it.cavallium.warppi.gui.screens; -import java.io.Serializable; - import it.cavallium.warppi.event.KeyboardEventListener; import it.cavallium.warppi.event.TouchEventListener; import it.cavallium.warppi.gui.DisplayManager; diff --git a/core/src/main/java/it/cavallium/warppi/math/AngleMode.java b/core/src/main/java/it/cavallium/warppi/math/AngleMode.java index 26b7b73c..09625f7d 100644 --- a/core/src/main/java/it/cavallium/warppi/math/AngleMode.java +++ b/core/src/main/java/it/cavallium/warppi/math/AngleMode.java @@ -1,7 +1,5 @@ package it.cavallium.warppi.math; -import java.io.Serializable; - -public enum AngleMode implements Serializable { +public enum AngleMode { DEG, RAD, GRA } diff --git a/core/src/main/java/it/cavallium/warppi/math/Function.java b/core/src/main/java/it/cavallium/warppi/math/Function.java index 04b75ed1..43bfdc32 100644 --- a/core/src/main/java/it/cavallium/warppi/math/Function.java +++ b/core/src/main/java/it/cavallium/warppi/math/Function.java @@ -1,13 +1,11 @@ package it.cavallium.warppi.math; -import java.io.Serializable; - import it.cavallium.warppi.gui.expression.blocks.Block; import it.cavallium.warppi.math.rules.Rule; import it.cavallium.warppi.util.Error; import it.unimi.dsi.fastutil.objects.ObjectArrayList; -public interface Function extends Serializable { +public interface Function { /** * Returns this function and its children in a string form. @@ -27,6 +25,14 @@ public interface Function extends Serializable { */ Function clone(); + /** + * Deep clone this function, also change mathContext. + * + * @param mathContext new mathContext + * @return A clone of this function. + */ + Function clone(MathContext newMathContext); + /** * Generic method to change a parameter in a known position. * @@ -53,7 +59,7 @@ public interface Function extends Serializable { * @return Calculator mathContext */ MathContext getMathContext(); - + /** * Simplify the current function or it's children using the specified * rule diff --git a/core/src/main/java/it/cavallium/warppi/math/MathContext.java b/core/src/main/java/it/cavallium/warppi/math/MathContext.java index 3813b300..1e6ef4a2 100644 --- a/core/src/main/java/it/cavallium/warppi/math/MathContext.java +++ b/core/src/main/java/it/cavallium/warppi/math/MathContext.java @@ -1,9 +1,5 @@ package it.cavallium.warppi.math; -import java.io.Serializable; - -import org.apache.commons.lang3.SerializationUtils; - import it.cavallium.warppi.math.functions.Variable.VariableValue; import it.cavallium.warppi.math.rules.Rule; import it.cavallium.warppi.math.rules.RuleType; @@ -11,7 +7,7 @@ import it.cavallium.warppi.math.rules.RulesManager; import it.cavallium.warppi.util.Error; import it.unimi.dsi.fastutil.objects.ObjectArrayList; -public class MathContext implements Serializable { +public class MathContext { public AngleMode angleMode = AngleMode.DEG; public boolean exactMode = false; @@ -27,6 +23,24 @@ public class MathContext implements Serializable { resultsCount = 0; } + public MathContext(MathContext calc) { + this.f = new ObjectArrayList<>(); + this.f2 = new ObjectArrayList<>(); + for (Function f : calc.f) { + f = f.clone(this); + this.f.add(f); + } + for (Function f : calc.f2) { + f = f.clone(this); + this.f2.add(f); + } + this.variablesValues = new ObjectArrayList<>(); + for (VariableValue varVal : calc.variablesValues) { + this.variablesValues.add(new VariableValue(varVal, this)); + } + this.resultsCount = calc.resultsCount; + } + @Deprecated public Function parseString(final String string) throws Error { return null; diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/Division.java b/core/src/main/java/it/cavallium/warppi/math/functions/Division.java index 0e461070..5a052d81 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/Division.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/Division.java @@ -26,7 +26,12 @@ public class Division extends FunctionOperator { @Override public FunctionOperator clone() { - return new Division(getMathContext(), getParameter1(), getParameter2()); + return new Division(getMathContext(), getParameter1() == null ? null : getParameter1().clone(), getParameter2() == null ? null : getParameter2().clone()); + } + + @Override + public FunctionOperator clone(MathContext c) { + return new Division(c, getParameter1() == null ? null : getParameter1().clone(c), getParameter2() == null ? null : getParameter2().clone(c)); } @Override diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/EmptyNumber.java b/core/src/main/java/it/cavallium/warppi/math/functions/EmptyNumber.java index 81577b4a..7b0327f0 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/EmptyNumber.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/EmptyNumber.java @@ -35,6 +35,11 @@ public class EmptyNumber implements Function { return new EmptyNumber(root); } + @Override + public Function clone(MathContext c) { + return new EmptyNumber(c); + } + @Override public Function setParameter(final int index, final Function var) throws IndexOutOfBoundsException { throw new IndexOutOfBoundsException(); diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/Expression.java b/core/src/main/java/it/cavallium/warppi/math/functions/Expression.java index 1f4d8744..3a9cc844 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/Expression.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/Expression.java @@ -610,7 +610,12 @@ public class Expression extends FunctionSingle { @Override public Expression clone() { - return new Expression(mathContext, parameter); + return new Expression(mathContext, parameter == null ? null : parameter.clone()); + } + + @Override + public Expression clone(MathContext newContext) { + return new Expression(newContext, parameter == null ? null : parameter.clone(newContext)); } } diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/Joke.java b/core/src/main/java/it/cavallium/warppi/math/functions/Joke.java index c3776f8d..37b4de44 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/Joke.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/Joke.java @@ -40,6 +40,11 @@ public class Joke implements Function { return new Joke(root, joke); } + @Override + public Function clone(MathContext c) { + return new Joke(c, joke); + } + @Override public Function setParameter(final int index, final Function var) throws IndexOutOfBoundsException { throw new IndexOutOfBoundsException(); diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/Logarithm.java b/core/src/main/java/it/cavallium/warppi/math/functions/Logarithm.java index 8c5b2f3e..d4db8775 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/Logarithm.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/Logarithm.java @@ -26,7 +26,12 @@ public class Logarithm extends FunctionOperator { @Override public Logarithm clone() { - return new Logarithm(mathContext, parameter1, parameter2); + return new Logarithm(mathContext, parameter1 == null ? null : parameter1.clone(), parameter2 == null ? null : parameter2.clone()); + } + + @Override + public Logarithm clone(MathContext c) { + return new Logarithm(c, parameter1 == null ? null : parameter1.clone(c), parameter2 == null ? null : parameter2.clone(c)); } @Override diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/Multiplication.java b/core/src/main/java/it/cavallium/warppi/math/functions/Multiplication.java index 4dc3ef9f..b1d24858 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/Multiplication.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/Multiplication.java @@ -35,7 +35,12 @@ public class Multiplication extends FunctionOperator { @Override public Multiplication clone() { - return new Multiplication(mathContext, parameter1, parameter2); + return new Multiplication(mathContext, parameter1 == null ? null : parameter1.clone(), parameter2 == null ? null : parameter2.clone()); + } + + @Override + public Multiplication clone(MathContext c) { + return new Multiplication(c, parameter1 == null ? null : parameter1.clone(c), parameter2 == null ? null : parameter2.clone(c)); } @Override @@ -66,7 +71,7 @@ public class Multiplication extends FunctionOperator { } else { result.addAll(sub1); } - if (nearLeft instanceof BlockChar && nearRight instanceof BlockChar && !(par2 instanceof Negative) && !(par1 instanceof Number && par2 instanceof Number)) { + if (nearLeft instanceof BlockChar && nearRight instanceof BlockChar && !(par2 instanceof Negative) && !(par1 instanceof Number && par2 instanceof Number) && !(par1 instanceof Number && par2 instanceof Multiplication && ((Multiplication)par2).getParameter1() instanceof Number)) { } else { result.add(new BlockChar(MathematicalSymbols.MULTIPLICATION)); diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/Negative.java b/core/src/main/java/it/cavallium/warppi/math/functions/Negative.java index 386f4729..f963b976 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/Negative.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/Negative.java @@ -26,7 +26,12 @@ public class Negative extends FunctionSingle { @Override public Negative clone() { - return new Negative(mathContext, parameter); + return new Negative(mathContext, parameter == null ? null : parameter.clone()); + } + + @Override + public Negative clone(MathContext c) { + return new Negative(c, parameter == null ? null : parameter.clone(c)); } @Override diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/Number.java b/core/src/main/java/it/cavallium/warppi/math/functions/Number.java index 8e250d6b..dbeb3d9b 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/Number.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/Number.java @@ -49,6 +49,16 @@ public class Number implements Function { this(root, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2)); } + /** + * Copy + * @param n + * @param newContext + */ + public Number(Number old, MathContext newContext) { + this.root = newContext; + this.term = old.term; + } + public BigDecimal getTerm() { return term; } @@ -117,6 +127,11 @@ public class Number implements Function { return new Number(root, term); } + @Override + public Number clone(MathContext c) { + return new Number(c, term); + } + @Override public ObjectArrayList simplify(final Rule rule) throws Error, InterruptedException { return rule.execute(this); diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/Power.java b/core/src/main/java/it/cavallium/warppi/math/functions/Power.java index 4c801ac0..58aec371 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/Power.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/Power.java @@ -26,7 +26,12 @@ public class Power extends FunctionOperator { @Override public Power clone() { - return new Power(mathContext, parameter1, parameter2); + return new Power(mathContext, parameter1 == null ? null : parameter1.clone(), parameter2 == null ? null : parameter2.clone()); + } + + @Override + public Power clone(MathContext c) { + return new Power(c, parameter1 == null ? null : parameter1.clone(c), parameter2 == null ? null : parameter2.clone(c)); } @Override diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/Root.java b/core/src/main/java/it/cavallium/warppi/math/functions/Root.java index 47647ccb..25b118a4 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/Root.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/Root.java @@ -25,7 +25,12 @@ public class Root extends FunctionOperator { @Override public Root clone() { - return new Root(mathContext, parameter1, parameter2); + return new Root(mathContext, parameter1 == null ? null : parameter1.clone(), parameter2 == null ? null : parameter2.clone()); + } + + @Override + public Root clone(MathContext c) { + return new Root(c, parameter1 == null ? null : parameter1.clone(c), parameter2 == null ? null : parameter2.clone(c)); } @Override diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/RootSquare.java b/core/src/main/java/it/cavallium/warppi/math/functions/RootSquare.java index 200eace3..30a7351a 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/RootSquare.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/RootSquare.java @@ -26,7 +26,12 @@ public class RootSquare extends FunctionOperator { @Override public RootSquare clone() { - return new RootSquare(mathContext, parameter2); + return new RootSquare(mathContext, parameter2 == null ? null : parameter2.clone()); + } + + @Override + public RootSquare clone(MathContext c) { + return new RootSquare(c, parameter2 == null ? null : parameter2.clone(c)); } @Override diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/Subtraction.java b/core/src/main/java/it/cavallium/warppi/math/functions/Subtraction.java index 9ea9707b..daa0a77f 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/Subtraction.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/Subtraction.java @@ -26,7 +26,12 @@ public class Subtraction extends FunctionOperator { @Override public Subtraction clone() { - return new Subtraction(mathContext, parameter1, parameter2); + return new Subtraction(mathContext, parameter1 == null ? null : parameter1.clone(), parameter2 == null ? null : parameter2.clone()); + } + + @Override + public Subtraction clone(MathContext c) { + return new Subtraction(c, parameter1 == null ? null : parameter1.clone(c), parameter2 == null ? null : parameter2.clone(c)); } @Override diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/Sum.java b/core/src/main/java/it/cavallium/warppi/math/functions/Sum.java index 89ed0521..3bcff91c 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/Sum.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/Sum.java @@ -30,7 +30,12 @@ public class Sum extends FunctionOperator { @Override public Sum clone() { - return new Sum(mathContext, parameter1, parameter2); + return new Sum(mathContext, parameter1 == null ? parameter1 : parameter1.clone(), parameter2 == null ? null : parameter2.clone()); + } + + @Override + public Sum clone(MathContext c) { + return new Sum(c, parameter1 == null ? null : parameter1.clone(c), parameter2 == null ? null : parameter2.clone(c)); } @Override diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/SumSubtraction.java b/core/src/main/java/it/cavallium/warppi/math/functions/SumSubtraction.java index bcf54b12..ef5a7e47 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/SumSubtraction.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/SumSubtraction.java @@ -26,7 +26,12 @@ public class SumSubtraction extends FunctionOperator { @Override public SumSubtraction clone() { - return new SumSubtraction(mathContext, parameter1, parameter2); + return new SumSubtraction(mathContext, parameter1 == null ? null : parameter1.clone(), parameter2 == null ? null : parameter2.clone()); + } + + @Override + public SumSubtraction clone(MathContext c) { + return new SumSubtraction(c, parameter1 == null ? null : parameter1.clone(c), parameter2 == null ? null : parameter2.clone(c)); } @Override diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/Undefined.java b/core/src/main/java/it/cavallium/warppi/math/functions/Undefined.java index 23b5477b..38ecd971 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/Undefined.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/Undefined.java @@ -36,6 +36,11 @@ public class Undefined implements Function { return new Undefined(root); } + @Override + public Undefined clone(MathContext c) { + return new Undefined(c); + } + @Override public Function setParameter(final int index, final Function var) throws IndexOutOfBoundsException { throw new IndexOutOfBoundsException(); diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/Variable.java b/core/src/main/java/it/cavallium/warppi/math/functions/Variable.java index d2ef1e03..119f8631 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/Variable.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/Variable.java @@ -1,7 +1,5 @@ package it.cavallium.warppi.math.functions; -import java.io.Serializable; - import it.cavallium.warppi.gui.expression.blocks.Block; import it.cavallium.warppi.gui.expression.blocks.BlockChar; import it.cavallium.warppi.math.Function; @@ -26,6 +24,17 @@ public class Variable implements Function { this(root, s.charAt(0), type); } + /** + * Copy + * @param old + * @param root + */ + public Variable(Variable old, MathContext root) { + this.root = root; + this.type = old.type; + this.var = old.var; + } + public char getChar() { return var; } @@ -47,8 +56,7 @@ public class Variable implements Function { return "" + getChar(); } - public static class VariableValue implements Serializable { - private static final long serialVersionUID = -5656281021874324571L; + public static class VariableValue { public final Variable v; public final Number n; @@ -56,6 +64,16 @@ public class Variable implements Function { this.v = v; this.n = n; } + + /** + * Copy + * @param old + * @param newContext + */ + public VariableValue(VariableValue old, MathContext newContext) { + this.v = new Variable(old.v, newContext); + this.n = new Number(old.n, newContext); + } } @Override @@ -86,6 +104,11 @@ public class Variable implements Function { return new Variable(root, var, type); } + @Override + public Variable clone(MathContext c) { + return new Variable(c, var, type); + } + public static enum V_TYPE { CONSTANT, VARIABLE, SOLUTION } diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/equations/Equation.java b/core/src/main/java/it/cavallium/warppi/math/functions/equations/Equation.java index 70992e0d..8fbd50bf 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/equations/Equation.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/equations/Equation.java @@ -48,7 +48,12 @@ public class Equation extends FunctionOperator { @Override public Equation clone() { - return new Equation(mathContext, parameter1, parameter2); + return new Equation(mathContext, parameter1 == null ? null : parameter1.clone(), parameter2 == null ? null : parameter2.clone()); + } + + @Override + public Equation clone(MathContext c) { + return new Equation(c, parameter1 == null ? null : parameter1.clone(c), parameter2 == null ? null : parameter2.clone(c)); } @Override diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/equations/EquationsSystem.java b/core/src/main/java/it/cavallium/warppi/math/functions/equations/EquationsSystem.java index 6c50a3b8..16d238b3 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/equations/EquationsSystem.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/equations/EquationsSystem.java @@ -24,7 +24,20 @@ public class EquationsSystem extends FunctionDynamic { @Override public EquationsSystem clone() { - return new EquationsSystem(root, functions); + Function[] newFuncs = functions.clone(); + for (int i = 0; i < newFuncs.length; i++) { + newFuncs[i] = newFuncs[i].clone(); + } + return new EquationsSystem(root, newFuncs); + } + + @Override + public EquationsSystem clone(MathContext c) { + Function[] newFuncs = new Function[this.functions.length]; + for (int i = 0; i < newFuncs.length; i++) { + newFuncs[i] = this.functions[i] == null ? null : this.functions[i].clone(c); + } + return new EquationsSystem(c, newFuncs); } @Override diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/equations/EquationsSystemPart.java b/core/src/main/java/it/cavallium/warppi/math/functions/equations/EquationsSystemPart.java index c6c0da45..0d18fc46 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/equations/EquationsSystemPart.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/equations/EquationsSystemPart.java @@ -20,7 +20,12 @@ public class EquationsSystemPart extends FunctionSingle { @Override public EquationsSystemPart clone() { - return new EquationsSystemPart(mathContext, (Equation) parameter); + return new EquationsSystemPart(mathContext, (Equation) (parameter == null ? null : parameter.clone())); + } + + @Override + public EquationsSystemPart clone(MathContext c) { + return new EquationsSystemPart(c, (Equation) (parameter == null ? null : parameter.clone(c))); } @Override diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/ArcCosine.java b/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/ArcCosine.java index 5aee0115..46b244a8 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/ArcCosine.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/ArcCosine.java @@ -26,6 +26,12 @@ public class ArcCosine extends FunctionSingle { return null; } + @Override + public FunctionSingle clone(MathContext c) { + // TODO Auto-generated method stub + return null; + } + @Override public ObjectArrayList toBlock(final MathContext context) throws Error { // TODO Auto-generated method stub diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/ArcSine.java b/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/ArcSine.java index 166a81e0..87e0cb2d 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/ArcSine.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/ArcSine.java @@ -26,6 +26,12 @@ public class ArcSine extends FunctionSingle { return null; } + @Override + public FunctionSingle clone(MathContext c) { + // TODO Auto-generated method stub + return null; + } + @Override public ObjectArrayList toBlock(final MathContext context) throws Error { // TODO Auto-generated method stub diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/ArcTangent.java b/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/ArcTangent.java index e3387e74..b37af1ea 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/ArcTangent.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/ArcTangent.java @@ -26,6 +26,12 @@ public class ArcTangent extends FunctionSingle { return null; } + @Override + public FunctionSingle clone(MathContext c) { + // TODO Auto-generated method stub + return null; + } + @Override public ObjectArrayList toBlock(final MathContext context) throws Error { // TODO Auto-generated method stub diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/Cosine.java b/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/Cosine.java index 4a160fc5..4ed7ddd3 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/Cosine.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/Cosine.java @@ -26,6 +26,12 @@ public class Cosine extends FunctionSingle { return null; } + @Override + public FunctionSingle clone(MathContext c) { + // TODO Auto-generated method stub + return null; + } + @Override public ObjectArrayList toBlock(final MathContext context) throws Error { // TODO Auto-generated method stub diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/Sine.java b/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/Sine.java index 9c61543e..2fcda089 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/Sine.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/Sine.java @@ -28,7 +28,12 @@ public class Sine extends FunctionSingle { @Override public Sine clone() { - return new Sine(mathContext, parameter); + return new Sine(mathContext, parameter == null ? null : parameter.clone()); + } + + @Override + public Sine clone(MathContext c) { + return new Sine(c, parameter == null ? null : parameter.clone(c)); } @Override diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/Tangent.java b/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/Tangent.java index 100cffee..d9cca7cc 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/Tangent.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/trigonometry/Tangent.java @@ -25,6 +25,12 @@ public class Tangent extends FunctionSingle { return null; } + @Override + public FunctionSingle clone(MathContext c) { + // TODO Auto-generated method stub + return null; + } + @Override public ObjectArrayList toBlock(final MathContext context) throws Error { // TODO Auto-generated method stub