Updated block deletion handling

This commit is contained in:
Cavallium 2018-10-04 08:49:11 +02:00
parent 9f6eb9e549
commit 658c5669f0
16 changed files with 86 additions and 2 deletions

2
Flow

@ -1 +1 @@
Subproject commit aa1984f1d386324712f2562f95620679ea5dde6c
Subproject commit c58460e49af4036df9eecb8cac7be38717cbb29e

View File

@ -8,6 +8,7 @@ import it.cavallium.warppi.gui.graphicengine.Renderer;
import it.cavallium.warppi.math.MathContext;
import it.cavallium.warppi.math.parser.features.interfaces.Feature;
import it.cavallium.warppi.util.Error;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public abstract class Block implements TreeBlock, GraphicalElement {
@ -34,6 +35,12 @@ public abstract class Block implements TreeBlock, GraphicalElement {
public abstract boolean delBlock(Caret caret);
public abstract BlockReference<?> getBlock(Caret caret);
/**
* Used only to get inner blocks when deleting the parent block.
* @return every block of every inner container, or null if empty
*/
public abstract ObjectArrayList<Block> getAllInnerBlocks();
@Override
public abstract void recomputeDimensions();

View File

@ -6,6 +6,7 @@ import it.cavallium.warppi.gui.graphicengine.Renderer;
import it.cavallium.warppi.math.MathContext;
import it.cavallium.warppi.math.parser.features.FeatureChar;
import it.cavallium.warppi.math.parser.features.interfaces.Feature;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public class BlockChar extends Block {
@ -65,4 +66,9 @@ public class BlockChar extends Block {
return new FeatureChar(getChar());
}
@Override
public ObjectArrayList<Block> getAllInnerBlocks() {
return null;
}
}

View File

@ -14,6 +14,7 @@ import it.cavallium.warppi.math.parser.features.interfaces.Feature;
import it.cavallium.warppi.util.Error;
import it.cavallium.warppi.util.Errors;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectListIterator;
public class BlockContainer implements TreeContainer, GraphicalElement {
@ -218,8 +219,18 @@ public class BlockContainer implements TreeContainer, GraphicalElement {
final int deltaCaret = caret.getRemaining();
removed = removed | b.delBlock(caret);
if (caret.getRemaining() == 0 || removed == false && deltaCaret >= 0 && caret.getRemaining() < 0) {
ObjectArrayList<Block> blocks = this.getBlockAt(pos - 1).get().getAllInnerBlocks();
removeAt(pos - 1);
caret.setPosition(caret.getPosition() - deltaCaret);
if (blocks != null) {
ObjectListIterator<Block> blocksIterator = blocks.iterator();
int blockNum = 0;
while (blocksIterator.hasNext()) {
Block block = blocksIterator.next();
addBlockUnsafe(pos - 1+blockNum, block);
blockNum++;
}
}
removed = true;
}
}

View File

@ -8,6 +8,8 @@ import it.cavallium.warppi.math.MathContext;
import it.cavallium.warppi.math.parser.features.FeatureDivision;
import it.cavallium.warppi.math.parser.features.interfaces.Feature;
import it.cavallium.warppi.util.Error;
import it.unimi.dsi.fastutil.objects.AbstractObjectList;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public class BlockDivision extends Block {
@ -118,4 +120,11 @@ public class BlockDivision extends Block {
final Function lower = getLowerContainer().toFunction(context);
return new FeatureDivision(upper, lower);
}
@Override
public ObjectArrayList<Block> getAllInnerBlocks() {
ObjectArrayList<Block> output = containerUp.getContent();
output.addAll(containerDown.getContent());
return output;
}
}

View File

@ -160,4 +160,11 @@ public class BlockLogarithm extends Block implements IParenthesis {
return new FeatureLogarithm(base, number);
}
@Override
public ObjectArrayList<Block> getAllInnerBlocks() {
ObjectArrayList<Block> output = containerBase.getContent();
output.addAll(containerNumber.getContent());
return output;
}
}

View File

@ -20,4 +20,9 @@ public class BlockParenthesis extends BlockParenthesisAbstract {
return new FeatureParenthesis(cont);
}
@Override
public ObjectArrayList<Block> getAllInnerBlocks() {
return getNumberContainer().getContent();
}
}

View File

@ -115,4 +115,10 @@ public abstract class BlockParenthesisAbstract extends Block implements IParenth
@Override
public abstract Feature toFeature(MathContext context) throws Error;
@Override
public ObjectArrayList<Block> getAllInnerBlocks() {
return containerNumber.getContent();
}
}

View File

@ -8,6 +8,7 @@ import it.cavallium.warppi.math.MathContext;
import it.cavallium.warppi.math.parser.features.FeaturePowerChar;
import it.cavallium.warppi.math.parser.features.interfaces.Feature;
import it.cavallium.warppi.util.Error;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public class BlockPower extends Block {
@ -80,4 +81,9 @@ public class BlockPower extends Block {
final Function exp = getExponentContainer().toFunction(context);
return new FeaturePowerChar(exp);
}
@Override
public ObjectArrayList<Block> getAllInnerBlocks() {
return this.containerExponent.getContent();
}
}

View File

@ -8,6 +8,7 @@ import it.cavallium.warppi.math.MathContext;
import it.cavallium.warppi.math.parser.features.FeaturePowerChar;
import it.cavallium.warppi.math.parser.features.interfaces.Feature;
import it.cavallium.warppi.util.Error;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public class BlockPower2 extends Block {
@ -86,4 +87,9 @@ public class BlockPower2 extends Block {
final Function exp = getExponentContainer().toFunction(context);
return new FeaturePowerChar(exp);
}
@Override
public ObjectArrayList<Block> getAllInnerBlocks() {
return containerExponent.getContent();
}
}

View File

@ -5,6 +5,7 @@ import it.cavallium.warppi.math.MathContext;
import it.cavallium.warppi.math.parser.features.FeatureSine;
import it.cavallium.warppi.math.parser.features.interfaces.Feature;
import it.cavallium.warppi.util.Error;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public class BlockSine extends BlockParenthesisAbstract {
public BlockSine() {

View File

@ -8,6 +8,7 @@ import it.cavallium.warppi.math.MathContext;
import it.cavallium.warppi.math.parser.features.FeatureSquareRoot;
import it.cavallium.warppi.math.parser.features.interfaces.Feature;
import it.cavallium.warppi.util.Error;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public class BlockSquareRoot extends Block {
@ -95,4 +96,11 @@ public class BlockSquareRoot extends Block {
final Function contnt = getNumberContainer().toFunction(context);
return new FeatureSquareRoot(contnt);
}
@Override
public ObjectArrayList<Block> getAllInnerBlocks() {
ObjectArrayList<Block> output = containerNumber.getContent();
// output.addAll();
return output;
}
}

View File

@ -7,6 +7,7 @@ import it.cavallium.warppi.math.MathContext;
import it.cavallium.warppi.math.MathematicalSymbols;
import it.cavallium.warppi.math.parser.features.FeatureChar;
import it.cavallium.warppi.math.parser.features.interfaces.Feature;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public class BlockUndefined extends Block {
@ -59,4 +60,9 @@ public class BlockUndefined extends Block {
return new FeatureChar(MathematicalSymbols.UNDEFINED);
}
@Override
public ObjectArrayList<Block> getAllInnerBlocks() {
return null;
}
}

View File

@ -14,6 +14,7 @@ import it.cavallium.warppi.math.functions.Variable.V_TYPE;
import it.cavallium.warppi.math.parser.features.FeatureVariable;
import it.cavallium.warppi.math.parser.features.interfaces.Feature;
import it.cavallium.warppi.util.Error;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public class BlockVariable extends Block {
@ -255,4 +256,9 @@ public class BlockVariable extends Block {
public Feature toFeature(final MathContext context) throws Error {
return new FeatureVariable(ch, type);
}
@Override
public ObjectArrayList<Block> getAllInnerBlocks() {
return null;
}
}

Binary file not shown.

View File

@ -104,7 +104,7 @@ public class SwingWindow extends JFrame {
@Override
public void componentResized(final ComponentEvent e) {
onResize.onNext(new Integer[] { getWidth(), getHeight() });
onResize.onNext(new Integer[] { c.getWidth(), c.getHeight() });
}
@Override