Better parenthesis button behavior
This commit is contained in:
parent
b57ae900e5
commit
bd5260e0f3
@ -639,7 +639,7 @@ public class Keyboard {
|
||||
{ "", null, null } /* 1,7 */
|
||||
}, { /* ROW 2 */
|
||||
{ "", null, null }, /* 2,0 */
|
||||
{ "√", null, null }, /* 2,1 */
|
||||
{ "√▯", null, null }, /* 2,1 */
|
||||
{ "", null, null }, /* 2,2 */
|
||||
{ "⇩", null, null }, /* 2,3 */
|
||||
{ "↶", null, null }, /* 2,4 */
|
||||
@ -649,8 +649,8 @@ public class Keyboard {
|
||||
}, { /* ROW 3 */
|
||||
{ "", null, null }, /* 3,0 */
|
||||
{ "", null, null }, /* 3,1 */
|
||||
{ "^x", null, null }, /* 3,2 */
|
||||
{ "^2", null, null }, /* 3,3 */
|
||||
{ "▯^▯", null, null }, /* 3,2 */
|
||||
{ "▯^2", null, null }, /* 3,3 */
|
||||
{ "", null, null }, /* 3,4 */
|
||||
{ "", null, null }, /* 3,5 */
|
||||
{ "", null, null }, /* 3,6 */
|
||||
@ -658,7 +658,7 @@ public class Keyboard {
|
||||
}, { /* ROW 4 */
|
||||
{ "", null, null }, /* 4,0 */
|
||||
{ "", null, null }, /* 4,1 */
|
||||
{ "(", null, null }, /* 4,2 */
|
||||
{ "(▯)", null, null }, /* 4,2 */
|
||||
{ ")", null, null }, /* 4,3 */
|
||||
{ "", null, null }, /* 4,4 */
|
||||
{ "S⇔D", null, null }, /* 4,5 */
|
||||
|
@ -9,12 +9,13 @@ import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.parser.features.interfaces.Feature;
|
||||
import it.cavallium.warppi.util.Error;
|
||||
|
||||
public abstract class Block implements GraphicalElement {
|
||||
public abstract class Block implements TreeBlock, GraphicalElement {
|
||||
|
||||
protected boolean small;
|
||||
protected int width;
|
||||
protected int height;
|
||||
protected int line;
|
||||
protected TreeContainer parent;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -69,4 +70,18 @@ public abstract class Block implements GraphicalElement {
|
||||
}
|
||||
|
||||
public abstract Feature toFeature(MathContext context) throws Error;
|
||||
|
||||
@Override
|
||||
public TreeContainer getParentContainer() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasParent() {
|
||||
return parent != null;
|
||||
}
|
||||
|
||||
public void setParent(TreeContainer parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import it.cavallium.warppi.util.Error;
|
||||
import it.cavallium.warppi.util.Errors;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
public class BlockContainer implements GraphicalElement {
|
||||
public class BlockContainer implements TreeContainer, GraphicalElement {
|
||||
|
||||
private static boolean initialized = false;
|
||||
|
||||
@ -28,33 +28,35 @@ public class BlockContainer implements GraphicalElement {
|
||||
private int line;
|
||||
public final boolean withBorder;
|
||||
private boolean autoMinimums;
|
||||
private TreeBlock parent;
|
||||
|
||||
public BlockContainer() {
|
||||
this(false, BlockContainer.getDefaultCharWidth(false), BlockContainer.getDefaultCharHeight(false), true);
|
||||
public BlockContainer(TreeBlock parent) {
|
||||
this(parent, false, BlockContainer.getDefaultCharWidth(false), BlockContainer.getDefaultCharHeight(false), true);
|
||||
autoMinimums = true;
|
||||
}
|
||||
|
||||
public BlockContainer(final boolean small) {
|
||||
this(small, BlockContainer.getDefaultCharWidth(small), BlockContainer.getDefaultCharHeight(small), true);
|
||||
public BlockContainer(TreeBlock parent, final boolean small) {
|
||||
this(parent, small, BlockContainer.getDefaultCharWidth(small), BlockContainer.getDefaultCharHeight(small), true);
|
||||
autoMinimums = true;
|
||||
}
|
||||
|
||||
public BlockContainer(final boolean small, final ObjectArrayList<Block> content) {
|
||||
this(small, BlockContainer.getDefaultCharWidth(small), BlockContainer.getDefaultCharHeight(small), content, true);
|
||||
public BlockContainer(TreeBlock parent, final boolean small, final ObjectArrayList<Block> content) {
|
||||
this(parent, small, BlockContainer.getDefaultCharWidth(small), BlockContainer.getDefaultCharHeight(small), content, true);
|
||||
autoMinimums = true;
|
||||
}
|
||||
|
||||
public BlockContainer(final boolean small, final boolean withBorder) {
|
||||
this(small, BlockContainer.getDefaultCharWidth(small), BlockContainer.getDefaultCharHeight(small), withBorder);
|
||||
public BlockContainer(TreeBlock parent, final boolean small, final boolean withBorder) {
|
||||
this(parent, small, BlockContainer.getDefaultCharWidth(small), BlockContainer.getDefaultCharHeight(small), withBorder);
|
||||
autoMinimums = true;
|
||||
}
|
||||
|
||||
public BlockContainer(final boolean small, final int minWidth, final int minHeight, final boolean withBorder) {
|
||||
this(small, minWidth, minHeight, new ObjectArrayList<>(), withBorder);
|
||||
public BlockContainer(TreeBlock parent, final boolean small, final int minWidth, final int minHeight, final boolean withBorder) {
|
||||
this(parent, small, minWidth, minHeight, new ObjectArrayList<>(), withBorder);
|
||||
autoMinimums = false;
|
||||
}
|
||||
|
||||
public BlockContainer(final boolean small, final int minWidth, final int minHeight, final ObjectArrayList<Block> content, final boolean withBorder) {
|
||||
public BlockContainer(TreeBlock parent, final boolean small, final int minWidth, final int minHeight, final ObjectArrayList<Block> content, final boolean withBorder) {
|
||||
this.parent = parent;
|
||||
this.small = small;
|
||||
this.minWidth = minWidth;
|
||||
this.minHeight = minHeight;
|
||||
@ -66,12 +68,23 @@ public class BlockContainer implements GraphicalElement {
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeBlock getParentBlock() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasParent() {
|
||||
return parent != null;
|
||||
}
|
||||
|
||||
public void addBlock(final int position, final Block b) {
|
||||
addBlockUnsafe(position, b);
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
public void addBlockUnsafe(final int position, final Block b) {
|
||||
b.setParent(this);
|
||||
if (b.isSmall() != small)
|
||||
b.setSmall(small);
|
||||
if (position >= content.size())
|
||||
@ -86,6 +99,7 @@ public class BlockContainer implements GraphicalElement {
|
||||
}
|
||||
|
||||
public void appendBlockUnsafe(final Block b) {
|
||||
b.setParent(this);
|
||||
if (b.isSmall() != small)
|
||||
b.setSmall(small);
|
||||
content.add(b);
|
||||
@ -97,11 +111,12 @@ public class BlockContainer implements GraphicalElement {
|
||||
}
|
||||
|
||||
public void removeBlockUnsafe(final Block b) {
|
||||
b.setParent(null);
|
||||
content.remove(b);
|
||||
}
|
||||
|
||||
public void removeAt(final int i) {
|
||||
content.remove(i);
|
||||
content.remove(i).setParent(null);
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,8 @@ public class BlockDivision extends Block {
|
||||
private int h1;
|
||||
|
||||
public BlockDivision() {
|
||||
containerUp = new BlockContainer(false);
|
||||
containerDown = new BlockContainer(false);
|
||||
containerUp = new BlockContainer(this, false);
|
||||
containerDown = new BlockContainer(this, false);
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import it.cavallium.warppi.math.parser.features.interfaces.Feature;
|
||||
import it.cavallium.warppi.util.Error;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
public class BlockLogarithm extends Block {
|
||||
public class BlockLogarithm extends Block implements IParenthesis {
|
||||
|
||||
private final BlockContainer containerBase;
|
||||
private final BlockContainer containerNumber;
|
||||
@ -28,14 +28,14 @@ public class BlockLogarithm extends Block {
|
||||
private int toph;
|
||||
|
||||
public BlockLogarithm() {
|
||||
containerBase = new BlockContainer(true);
|
||||
containerNumber = new BlockContainer(false);
|
||||
containerBase = new BlockContainer(this, true);
|
||||
containerNumber = new BlockContainer(this, false);
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
public BlockLogarithm(final ObjectArrayList<Block> blocks) {
|
||||
containerBase = new BlockContainer(true);
|
||||
containerNumber = new BlockContainer(false, blocks);
|
||||
containerBase = new BlockContainer(this, true);
|
||||
containerNumber = new BlockContainer(this, false, blocks);
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
public class BlockParenthesis extends BlockParenthesisAbstract {
|
||||
public BlockParenthesis() {
|
||||
super();
|
||||
}
|
||||
|
||||
public BlockParenthesis(final ObjectArrayList<Block> blocks) {
|
||||
|
@ -8,7 +8,7 @@ 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 BlockParenthesisAbstract extends Block {
|
||||
public abstract class BlockParenthesisAbstract extends Block implements IParenthesis {
|
||||
|
||||
private final BlockContainer containerNumber;
|
||||
|
||||
@ -18,20 +18,20 @@ public abstract class BlockParenthesisAbstract extends Block {
|
||||
private int chh;
|
||||
|
||||
protected BlockParenthesisAbstract(final String prefix) {
|
||||
containerNumber = new BlockContainer(false);
|
||||
containerNumber = new BlockContainer(this, false);
|
||||
this.prefix = prefix;
|
||||
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
public BlockParenthesisAbstract() {
|
||||
containerNumber = new BlockContainer(false);
|
||||
containerNumber = new BlockContainer(this, false);
|
||||
prefix = null;
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
public BlockParenthesisAbstract(final ObjectArrayList<Block> blocks) {
|
||||
containerNumber = new BlockContainer(false, blocks);
|
||||
containerNumber = new BlockContainer(this, false, blocks);
|
||||
prefix = null;
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class BlockPower extends Block {
|
||||
private final BlockContainer containerExponent;
|
||||
|
||||
public BlockPower() {
|
||||
containerExponent = new BlockContainer(true);
|
||||
containerExponent = new BlockContainer(this, true);
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ public class BlockPower2 extends Block {
|
||||
private final BlockContainer containerExponent;
|
||||
|
||||
public BlockPower2() {
|
||||
containerExponent = new BlockContainer(true);
|
||||
containerExponent = new BlockContainer(this, true);
|
||||
containerExponent.addBlock(0, new BlockNumericChar('2'));
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ public class BlockSquareRoot extends Block {
|
||||
private int h1;
|
||||
|
||||
public BlockSquareRoot() {
|
||||
containerNumber = new BlockContainer(false);
|
||||
containerNumber = new BlockContainer(this, false);
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,5 @@
|
||||
package it.cavallium.warppi.gui.expression.blocks;
|
||||
|
||||
public interface IParenthesis {
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package it.cavallium.warppi.gui.expression.blocks;
|
||||
|
||||
public interface TreeBlock {
|
||||
public TreeContainer getParentContainer();
|
||||
public boolean hasParent();
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package it.cavallium.warppi.gui.expression.blocks;
|
||||
|
||||
public interface TreeContainer {
|
||||
public TreeBlock getParentBlock();
|
||||
public boolean hasParent();
|
||||
}
|
@ -1,8 +1,15 @@
|
||||
package it.cavallium.warppi.gui.expression.containers;
|
||||
|
||||
import it.cavallium.warppi.gui.expression.Caret;
|
||||
import it.cavallium.warppi.gui.expression.InputContext;
|
||||
import it.cavallium.warppi.gui.expression.blocks.Block;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockChar;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockReference;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
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;
|
||||
|
||||
public class InlineInputContainer extends InputContainer {
|
||||
|
||||
|
@ -11,6 +11,8 @@ import it.cavallium.warppi.gui.expression.InputContext;
|
||||
import it.cavallium.warppi.gui.expression.blocks.Block;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockContainer;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockReference;
|
||||
import it.cavallium.warppi.gui.expression.blocks.TreeContainer;
|
||||
import it.cavallium.warppi.gui.expression.blocks.TreeBlock;
|
||||
import it.cavallium.warppi.gui.expression.layouts.InputLayout;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
@ -21,8 +23,8 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
public abstract class InputContainer implements GraphicalElement, InputLayout, Serializable {
|
||||
private static final long serialVersionUID = 923589369317765667L;
|
||||
private final BlockContainer root;
|
||||
private Caret caret;
|
||||
protected final BlockContainer root;
|
||||
protected Caret caret;
|
||||
private static final float CARET_DURATION = 0.5f;
|
||||
private float caretTime;
|
||||
private int maxPosition = 0;
|
||||
@ -53,7 +55,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S
|
||||
public InputContainer(final InputContext ic, final boolean small, final int minWidth, final int minHeight) {
|
||||
inputContext = ic;
|
||||
caret = new Caret(CaretState.VISIBLE_ON, 0);
|
||||
root = new BlockContainer(small, false);
|
||||
root = new BlockContainer(null, small, false);
|
||||
}
|
||||
|
||||
public void typeChar(final char c) {
|
||||
@ -69,10 +71,10 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S
|
||||
maxPosition = root.computeCaretMaxBound();
|
||||
root.recomputeDimensions();
|
||||
}
|
||||
closeExtra();
|
||||
}
|
||||
caretTime = 0;
|
||||
caret.turnOn();
|
||||
closeExtra();
|
||||
}
|
||||
|
||||
public void typeChar(final String c) {
|
||||
@ -98,6 +100,11 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S
|
||||
return selectedBlock;
|
||||
}
|
||||
|
||||
public BlockReference<?> getBlockAtCaretPosition(int i) {
|
||||
final BlockReference<?> selectedBlock = root.getBlock(new Caret(CaretState.HIDDEN, i));
|
||||
return selectedBlock;
|
||||
}
|
||||
|
||||
public void moveLeft() {
|
||||
final int curPos = caret.getPosition();
|
||||
if (curPos > 0)
|
||||
@ -109,10 +116,10 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S
|
||||
closeExtra();
|
||||
}
|
||||
|
||||
public void moveRight() {
|
||||
public void moveRight(int delta) {
|
||||
final int curPos = caret.getPosition();
|
||||
if (curPos + 1 < maxPosition)
|
||||
caret.setPosition(curPos + 1);
|
||||
if (curPos + delta < maxPosition)
|
||||
caret.setPosition(curPos + delta);
|
||||
else
|
||||
caret.setPosition(0);
|
||||
caret.turnOn();
|
||||
@ -120,6 +127,20 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S
|
||||
closeExtra();
|
||||
}
|
||||
|
||||
public void moveTo(int position) {
|
||||
if (position < maxPosition)
|
||||
caret.setPosition(position);
|
||||
else
|
||||
caret.setPosition(0);
|
||||
caret.turnOn();
|
||||
caretTime = 0;
|
||||
closeExtra();
|
||||
}
|
||||
|
||||
public void moveRight() {
|
||||
moveRight(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recomputeDimensions() {
|
||||
root.recomputeDimensions();
|
||||
|
@ -1,5 +1,7 @@
|
||||
package it.cavallium.warppi.gui.expression.containers;
|
||||
|
||||
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.expression.blocks.Block;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockChar;
|
||||
@ -8,12 +10,16 @@ import it.cavallium.warppi.gui.expression.blocks.BlockDivision;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockLogarithm;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockNumericChar;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockParenthesis;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockParenthesisAbstract;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockPower;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockPower2;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockReference;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockSine;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockSquareRoot;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockVariable;
|
||||
import it.cavallium.warppi.gui.expression.blocks.IParenthesis;
|
||||
import it.cavallium.warppi.gui.expression.blocks.TreeBlock;
|
||||
import it.cavallium.warppi.gui.expression.blocks.TreeContainer;
|
||||
import it.cavallium.warppi.math.MathematicalSymbols;
|
||||
|
||||
public class NormalInputContainer extends InputContainer {
|
||||
@ -92,9 +98,33 @@ public class NormalInputContainer extends InputContainer {
|
||||
public void typeChar(final char c) {
|
||||
super.typeChar(c);
|
||||
switch (c) {
|
||||
case MathematicalSymbols.PARENTHESIS_CLOSE:
|
||||
moveRight();
|
||||
case MathematicalSymbols.DIVISION:
|
||||
case MathematicalSymbols.PARENTHESIS_CLOSE: {
|
||||
BlockReference<?> ref = getSelectedBlock();
|
||||
if (ref == null) {
|
||||
break;
|
||||
} else {
|
||||
Caret newCaret = new Caret(CaretState.HIDDEN, caret.getPosition());
|
||||
BlockContainer currentContainer;
|
||||
BlockReference<?> newRef = ref;
|
||||
int safeExit = 0;
|
||||
do {
|
||||
currentContainer = (BlockContainer) newRef.get().getParentContainer();
|
||||
int initialRelativeIndex = currentContainer.getContent().indexOf(newRef.get());
|
||||
int newIndex = newCaret.getPosition() + (currentContainer.getContent().size() - initialRelativeIndex);
|
||||
newRef = getBlockAtCaretPosition(newIndex);
|
||||
newCaret.setPosition(newIndex);
|
||||
safeExit++;
|
||||
} while (newRef != null && newRef.get() instanceof IParenthesis == false && currentContainer != null && safeExit < 100000);
|
||||
if (safeExit >= 100000) {
|
||||
System.err.println("Error 0x001030: Infinite loop");
|
||||
}
|
||||
if (newRef != null) {
|
||||
moveTo(newCaret.getPosition());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MathematicalSymbols.DIVISION: {
|
||||
@SuppressWarnings("unchecked")
|
||||
final BlockReference<BlockDivision> ref = (BlockReference<BlockDivision>) getSelectedBlock();
|
||||
@SuppressWarnings("unused")
|
||||
@ -128,7 +158,8 @@ public class NormalInputContainer extends InputContainer {
|
||||
moveRight();
|
||||
moveRight();// Move to the divisor
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,22 +19,22 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
|
||||
|
||||
public OutputContainer() {
|
||||
roots = new ObjectArrayList<>();
|
||||
roots.add(new BlockContainer());
|
||||
roots.add(new BlockContainer(null));
|
||||
}
|
||||
|
||||
public OutputContainer(final boolean small) {
|
||||
roots = new ObjectArrayList<>();
|
||||
roots.add(new BlockContainer(small));
|
||||
roots.add(new BlockContainer(null, small));
|
||||
}
|
||||
|
||||
public OutputContainer(final boolean small, final int minWidth, final int minHeight) {
|
||||
roots = new ObjectArrayList<>();
|
||||
roots.add(new BlockContainer(small));
|
||||
roots.add(new BlockContainer(null, small));
|
||||
}
|
||||
|
||||
public void setContentAsSingleGroup(final ObjectArrayList<Block> blocks) {
|
||||
roots.clear();
|
||||
final BlockContainer bcnt = new BlockContainer();
|
||||
final BlockContainer bcnt = new BlockContainer(null);
|
||||
for (final Block block : blocks)
|
||||
bcnt.appendBlockUnsafe(block);
|
||||
roots.add(bcnt);
|
||||
@ -44,7 +44,7 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
|
||||
public void setContentAsMultipleGroups(final ObjectArrayList<ObjectArrayList<Block>> roots) {
|
||||
this.roots.clear();
|
||||
for (final ObjectArrayList<Block> blocks : roots) {
|
||||
final BlockContainer bcnt = new BlockContainer();
|
||||
final BlockContainer bcnt = new BlockContainer(null);
|
||||
for (final Block block : blocks)
|
||||
bcnt.appendBlockUnsafe(block);
|
||||
this.roots.add(bcnt);
|
||||
@ -55,7 +55,7 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
|
||||
public void setContentAsMultipleElements(final ObjectArrayList<Block> elems) {
|
||||
roots.clear();
|
||||
for (final Block block : elems) {
|
||||
final BlockContainer bcnt = new BlockContainer();
|
||||
final BlockContainer bcnt = new BlockContainer(null);
|
||||
bcnt.appendBlockUnsafe(block);
|
||||
roots.add(bcnt);
|
||||
}
|
||||
@ -125,7 +125,7 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
|
||||
|
||||
public void clear() {
|
||||
roots.clear();
|
||||
roots.add(new BlockContainer());
|
||||
roots.add(new BlockContainer(null));
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,7 @@ public class Utils {
|
||||
|
||||
public static final int scaleMode = BigDecimal.ROUND_HALF_UP;
|
||||
public static final RoundingMode scaleMode2 = RoundingMode.HALF_UP;
|
||||
public static final int maxAutoFractionDigits = 5;
|
||||
|
||||
public static boolean newtMode = true;
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -5,6 +5,7 @@
|
||||
package it.cavallium.warppi.gui.graphicengine.impl.swing;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
@ -26,6 +27,8 @@ public class SwingAdvancedButton extends JButton {
|
||||
public boolean drawColor = false;
|
||||
public boolean drawDefaultComponent = false;
|
||||
public int state;
|
||||
protected boolean hover;
|
||||
public Color basicForeground;
|
||||
|
||||
public SwingAdvancedButton() {
|
||||
setOpaque(false);
|
||||
@ -69,10 +72,14 @@ public class SwingAdvancedButton extends JButton {
|
||||
final AlphaComposite acomp = AlphaComposite.getInstance(3, 1.0f);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
|
||||
g2d.setComposite(acomp);
|
||||
g2d.drawImage(backgroundImage, 0, (int) backgroundSize.getHeight() * -state, (int) backgroundSize.getWidth(), (int) (backgroundSize.getHeight() * 3), null);
|
||||
g2d.drawImage(backgroundImage, 0, (int) backgroundSize.getHeight() * -(hover ? state+1 : state), (int) backgroundSize.getWidth(), (int) (backgroundSize.getHeight() * 4), null);
|
||||
g2d.setFont(g.getFont());
|
||||
g2d.setColor(super.getForeground());
|
||||
g2d.drawString(getText(), super.getWidth() / 2 - g.getFontMetrics().stringWidth(getText()) / 2, super.getHeight() / 2 + g.getFontMetrics().getHeight() / 4);
|
||||
int y = super.getHeight() / 2 + g.getFontMetrics().getHeight() / 4;
|
||||
if (state == 2) {
|
||||
y += 8;
|
||||
}
|
||||
g2d.drawString(getText(), super.getWidth() / 2 - g.getFontMetrics().stringWidth(getText()) / 2, y);
|
||||
g2d.dispose();
|
||||
}
|
||||
if (drawDefaultComponent)
|
||||
@ -102,4 +109,9 @@ public class SwingAdvancedButton extends JButton {
|
||||
public boolean getCanClick() {
|
||||
return canclick;
|
||||
}
|
||||
|
||||
public void setBasicForeground(Color color) {
|
||||
basicForeground = color;
|
||||
super.setForeground(basicForeground);
|
||||
}
|
||||
}
|
||||
|
@ -203,12 +203,16 @@ public class SwingWindow extends JFrame {
|
||||
buttonsPanel = new JPanel();
|
||||
buttonsPanelContainer.add(buttonsPanel, BorderLayout.CENTER);
|
||||
buttonsPanel.setLayout(new GridLayout(9, 7));
|
||||
buttonsPanel.setBackground(Color.GRAY);
|
||||
buttonsPanel.setBackground(Color.BLACK);
|
||||
buttonsPanel.setDoubleBuffered(false);
|
||||
buttonsPanel.setVisible(true);
|
||||
for (int row = 0; row < 5; row++)
|
||||
for (int col = 0; col < 7; col++)
|
||||
if (row == 0 && col == 2 || row == 0 && col == 4 || row == 2 && col == 2) {
|
||||
createBlankBox();
|
||||
} else {
|
||||
createBtn(row, col);
|
||||
}
|
||||
for (int row = 5; row < 8; row++) {
|
||||
createBlankBox();
|
||||
for (int col = 0; col < 5; col++)
|
||||
@ -234,7 +238,7 @@ public class SwingWindow extends JFrame {
|
||||
final SwingAdvancedButton b = new SwingAdvancedButton(img, new Dimension((int) (BTN_SIZE * 1.5), BTN_SIZE));
|
||||
b.drawDefaultComponent = false;
|
||||
b.setText(Keyboard.getKeyName(row, col));
|
||||
b.setForeground(Color.BLACK);
|
||||
b.setBasicForeground(Color.BLACK);
|
||||
Font f = b.getFont();
|
||||
f = f.deriveFont(Font.BOLD, BTN_SIZE / 3);
|
||||
b.setFont(f);
|
||||
@ -245,6 +249,43 @@ public class SwingWindow extends JFrame {
|
||||
Keyboard.keyReleasedRaw(row, col);
|
||||
c.grabFocus();
|
||||
});
|
||||
b.addMouseListener(new MouseListener() {
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
if (b.state == 2) {
|
||||
b.setForeground(b.basicForeground.darker());
|
||||
} else {
|
||||
b.setForeground(b.basicForeground);
|
||||
}
|
||||
b.hover = false;
|
||||
b.repaint();
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
if (b.state == 2) {
|
||||
b.setForeground(b.basicForeground);
|
||||
} else {
|
||||
b.setForeground(b.basicForeground.brighter());
|
||||
}
|
||||
b.hover = true;
|
||||
b.repaint();
|
||||
}
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
});
|
||||
buttons[row][col] = b;
|
||||
buttonsPanel.add(b);
|
||||
}
|
||||
@ -261,9 +302,9 @@ public class SwingWindow extends JFrame {
|
||||
else
|
||||
btn.state = 0;
|
||||
if (val && Keyboard.hasKeyName(row, col))
|
||||
btn.setForeground(Color.RED);
|
||||
btn.setBasicForeground(Color.RED);
|
||||
else
|
||||
btn.setForeground(Color.BLACK);
|
||||
btn.setBasicForeground(Color.BLACK);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -280,9 +321,9 @@ public class SwingWindow extends JFrame {
|
||||
else
|
||||
btn.state = 0;
|
||||
if (val && Keyboard.hasKeyName(row, col))
|
||||
btn.setForeground(new Color(255, 120, 0));
|
||||
btn.setBasicForeground(new Color(255, 120, 0));
|
||||
else
|
||||
btn.setForeground(Color.BLACK);
|
||||
btn.setBasicForeground(Color.BLACK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 600 B After Width: | Height: | Size: 767 B |
Binary file not shown.
@ -12,6 +12,7 @@ import it.cavallium.warppi.math.functions.Division;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.cavallium.warppi.util.Utils;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
@ -46,13 +47,17 @@ public class NumberRule implements Rule {
|
||||
final MathContext mathContext = f.getMathContext();
|
||||
if (mathContext.exactMode)
|
||||
if (((Number) f).isInteger() == false) {
|
||||
final Number divisor = new Number(mathContext, BigInteger.TEN.pow(((Number) f).getNumberOfDecimalPlaces()));
|
||||
final int decimalPlaces = ((Number) f).getNumberOfDecimalPlaces();
|
||||
final int decimalDigits = decimalPlaces + 1;
|
||||
if (decimalDigits < Utils.maxAutoFractionDigits) {
|
||||
final Number divisor = new Number(mathContext, BigInteger.TEN.pow(decimalPlaces));
|
||||
final Function number = new Number(mathContext, ((Number) f).getTerm().multiply(divisor.getTerm()));
|
||||
final Function div = new Division(mathContext, number, divisor);
|
||||
result.add(div);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user