2018-09-02 13:36:49 +02:00
|
|
|
package it.cavallium.warppi.gui.expression.blocks;
|
2017-03-03 23:06:43 +01:00
|
|
|
|
2019-02-27 23:29:03 +01:00
|
|
|
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
2018-09-02 13:36:49 +02:00
|
|
|
import it.cavallium.warppi.gui.GraphicalElement;
|
|
|
|
import it.cavallium.warppi.gui.expression.Caret;
|
|
|
|
import it.cavallium.warppi.gui.expression.ExtraMenu;
|
2018-10-04 23:39:19 +02:00
|
|
|
import it.cavallium.warppi.gui.expression.InputContext;
|
2018-09-02 13:36:49 +02:00
|
|
|
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
|
|
|
import it.cavallium.warppi.math.MathContext;
|
|
|
|
import it.cavallium.warppi.math.parser.features.interfaces.Feature;
|
2018-09-12 22:16:33 +02:00
|
|
|
import it.cavallium.warppi.util.Error;
|
2018-10-04 08:49:11 +02:00
|
|
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
2017-03-03 23:06:43 +01:00
|
|
|
|
2018-09-22 14:10:36 +02:00
|
|
|
public abstract class Block implements TreeBlock, GraphicalElement {
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-03-03 23:06:43 +01:00
|
|
|
protected boolean small;
|
|
|
|
protected int width;
|
|
|
|
protected int height;
|
|
|
|
protected int line;
|
2018-09-22 14:10:36 +02:00
|
|
|
protected TreeContainer parent;
|
2018-10-09 23:51:42 +02:00
|
|
|
|
|
|
|
public Block() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy
|
|
|
|
* @param b
|
|
|
|
*/
|
|
|
|
public Block(TreeContainer parent, Block b) {
|
|
|
|
this.small = b.small;
|
|
|
|
this.width = b.width;
|
|
|
|
this.height = b.height;
|
|
|
|
this.line = b.line;
|
|
|
|
this.parent = parent;
|
|
|
|
}
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-03-03 23:06:43 +01:00
|
|
|
/**
|
2018-09-22 11:17:30 +02:00
|
|
|
*
|
2017-04-10 22:50:43 +02:00
|
|
|
* @param r
|
|
|
|
* Graphic Renderer class.
|
|
|
|
* @param x
|
|
|
|
* Position relative to the window.
|
|
|
|
* @param y
|
|
|
|
* Position relative to the window.
|
|
|
|
* @param small
|
2017-03-03 23:06:43 +01:00
|
|
|
*/
|
2019-02-27 23:29:03 +01:00
|
|
|
public abstract void draw(DisplayOutputDevice ge, Renderer r, int x, int y, Caret caret);
|
2017-03-03 23:06:43 +01:00
|
|
|
|
2023-08-23 12:04:27 +02:00
|
|
|
public abstract boolean appendBlock(Caret caret, Block newBlock, boolean splitAdjacent);
|
2017-03-26 22:44:09 +02:00
|
|
|
|
2023-08-23 12:04:27 +02:00
|
|
|
public abstract boolean deleteBlock(Caret caret);
|
2017-03-26 22:44:09 +02:00
|
|
|
|
2018-03-11 21:49:41 +01:00
|
|
|
public abstract BlockReference<?> getBlock(Caret caret);
|
2018-10-04 08:49:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used only to get inner blocks when deleting the parent block.
|
|
|
|
* @return every block of every inner container, or null if empty
|
|
|
|
*/
|
2018-10-04 09:52:14 +02:00
|
|
|
public abstract ObjectArrayList<Block> getInnerBlocks();
|
2017-05-05 22:27:11 +02:00
|
|
|
|
2018-10-05 22:09:54 +02:00
|
|
|
public abstract ObjectArrayList<BlockContainer> getInnerContainers();
|
2018-10-04 09:52:14 +02:00
|
|
|
|
2017-03-03 23:06:43 +01:00
|
|
|
@Override
|
|
|
|
public abstract void recomputeDimensions();
|
2017-04-09 22:01:03 +02:00
|
|
|
|
|
|
|
public abstract int computeCaretMaxBound();
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-03-03 23:06:43 +01:00
|
|
|
@Override
|
|
|
|
public int getWidth() {
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getHeight() {
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getLine() {
|
|
|
|
return line;
|
|
|
|
}
|
2018-09-22 11:17:30 +02:00
|
|
|
|
2018-09-11 19:19:24 +02:00
|
|
|
public int getCaretDeltaPositionAfterCreation() {
|
|
|
|
return 1;
|
|
|
|
}
|
2017-03-03 23:06:43 +01:00
|
|
|
|
|
|
|
public boolean isSmall() {
|
|
|
|
return small;
|
|
|
|
}
|
2017-09-24 18:47:30 +02:00
|
|
|
|
2017-03-03 23:06:43 +01:00
|
|
|
public abstract void setSmall(boolean small);
|
2017-09-24 18:47:30 +02:00
|
|
|
|
2017-05-16 22:02:44 +02:00
|
|
|
public ExtraMenu<?> getExtraMenu() {
|
2017-05-05 22:27:11 +02:00
|
|
|
return null;
|
|
|
|
}
|
2017-05-26 22:37:18 +02:00
|
|
|
|
|
|
|
public abstract Feature toFeature(MathContext context) throws Error;
|
2018-09-28 11:39:28 +02:00
|
|
|
|
2018-09-22 14:10:36 +02:00
|
|
|
@Override
|
|
|
|
public TreeContainer getParentContainer() {
|
|
|
|
return parent;
|
|
|
|
}
|
2018-09-28 11:39:28 +02:00
|
|
|
|
2018-09-22 14:10:36 +02:00
|
|
|
@Override
|
|
|
|
public boolean hasParent() {
|
|
|
|
return parent != null;
|
|
|
|
}
|
|
|
|
|
2018-09-28 11:39:28 +02:00
|
|
|
public void setParent(final TreeContainer parent) {
|
2018-09-22 14:10:36 +02:00
|
|
|
this.parent = parent;
|
|
|
|
}
|
2018-10-04 23:39:19 +02:00
|
|
|
|
2018-10-09 23:51:42 +02:00
|
|
|
public abstract Block clone(TreeContainer parent, InputContext ic);
|
2017-03-03 23:06:43 +01:00
|
|
|
}
|