introduced a separate color (red) to indicate errors

This commit is contained in:
hneemann 2017-05-29 08:33:27 +02:00
parent bcc980d321
commit 243e58fd88
52 changed files with 106 additions and 82 deletions

View File

@ -170,17 +170,18 @@ public class Circuit {
* @param graphic the graphic instance used * @param graphic the graphic instance used
*/ */
public void drawTo(Graphic graphic) { public void drawTo(Graphic graphic) {
drawTo(graphic, EMPTY_SET, NoSync.INST); drawTo(graphic, EMPTY_SET, null, NoSync.INST);
} }
/** /**
* Draws tis circuit using the given graphic instance * Draws this circuit using the given graphic instance
* *
* @param graphic the graphic instance used * @param graphic the graphic instance used
* @param highLighted a list of Drawables to highlight * @param highLighted a list of Drawables to highlight
* @param highlight style used to draw the highlighted elements
* @param modelSync sync interface to access the model. Is locked while drawing circuit * @param modelSync sync interface to access the model. Is locked while drawing circuit
*/ */
public void drawTo(Graphic graphic, Collection<Drawable> highLighted, Sync modelSync) { public void drawTo(Graphic graphic, Collection<Drawable> highLighted, Style highlight, Sync modelSync) {
if (!dotsPresent) { if (!dotsPresent) {
new DotCreator(wires).applyDots(); new DotCreator(wires).applyDots();
dotsPresent = true; dotsPresent = true;
@ -189,11 +190,11 @@ public class Circuit {
modelSync.access(() -> { modelSync.access(() -> {
graphic.openGroup(); graphic.openGroup();
for (Wire w : wires) for (Wire w : wires)
w.drawTo(graphic, highLighted.contains(w)); w.drawTo(graphic, highLighted.contains(w) ? highlight : null);
graphic.closeGroup(); graphic.closeGroup();
for (VisualElement p : visualElements) { for (VisualElement p : visualElements) {
graphic.openGroup(); graphic.openGroup();
p.drawTo(graphic, highLighted.contains(p)); p.drawTo(graphic, highLighted.contains(p) ? highlight : null);
graphic.closeGroup(); graphic.closeGroup();
} }
}); });
@ -640,9 +641,9 @@ public class Circuit {
* @param circuit the circuit to take the listeners from * @param circuit the circuit to take the listeners from
*/ */
public void getListenersFrom(Circuit circuit) { public void getListenersFrom(Circuit circuit) {
if (circuit.listeners!=null) { if (circuit.listeners != null) {
if (listeners==null) if (listeners == null)
listeners=new ArrayList<>(); listeners = new ArrayList<>();
listeners.addAll(circuit.listeners); listeners.addAll(circuit.listeners);
} }
} }

View File

@ -61,7 +61,7 @@ public class VisualElement implements Drawable, Movable, AttributeListener {
this.elementName = proto.elementName; this.elementName = proto.elementName;
this.elementAttributes = new ElementAttributes(proto.elementAttributes); this.elementAttributes = new ElementAttributes(proto.elementAttributes);
setPos(new Vector(proto.pos)); setPos(new Vector(proto.pos));
this.shapeFactory=proto.shapeFactory; this.shapeFactory = proto.shapeFactory;
} }
/** /**
@ -165,19 +165,19 @@ public class VisualElement implements Drawable, Movable, AttributeListener {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
drawShape(graphic, highLight); drawShape(graphic, highLight);
// draw circle around element // draw circle around element
if (highLight) { if (highLight != null) {
GraphicMinMax mm = getMinMax(false); GraphicMinMax mm = getMinMax(false);
Vector delta = mm.getMax().sub(mm.getMin()).add(SIZE, SIZE).div(2); Vector delta = mm.getMax().sub(mm.getMin()).add(SIZE, SIZE).div(2);
Vector pos = mm.getMax().add(mm.getMin()).div(2); Vector pos = mm.getMax().add(mm.getMin()).div(2);
graphic.drawCircle(pos.sub(delta), pos.add(delta), Style.HIGHLIGHT); graphic.drawCircle(pos.sub(delta), pos.add(delta), highLight);
} }
} }
private void drawShape(Graphic graphic, boolean highLight) { private void drawShape(Graphic graphic, Style highLight) {
Graphic gr = new GraphicTransform(graphic, createTransform()); Graphic gr = new GraphicTransform(graphic, createTransform());
Shape shape = getShape(); Shape shape = getShape();
shape.drawTo(gr, highLight); shape.drawTo(gr, highLight);
@ -205,14 +205,14 @@ public class VisualElement implements Drawable, Movable, AttributeListener {
if (includeText) { if (includeText) {
if (minMaxText == null) { if (minMaxText == null) {
GraphicMinMax mm = new GraphicMinMax(true); GraphicMinMax mm = new GraphicMinMax(true);
drawShape(mm, false); drawShape(mm, null);
minMaxText = mm; minMaxText = mm;
} }
return minMaxText; return minMaxText;
} else { } else {
if (minMax == null) { if (minMax == null) {
GraphicMinMax mm = new GraphicMinMax(false); GraphicMinMax mm = new GraphicMinMax(false);
drawShape(mm, false); drawShape(mm, null);
minMax = mm; minMax = mm;
} }
return minMax; return minMax;
@ -246,7 +246,7 @@ public class VisualElement implements Drawable, Movable, AttributeListener {
*/ */
public BufferedImage getBufferedImage(double scale, int maxHeight) { public BufferedImage getBufferedImage(double scale, int maxHeight) {
GraphicMinMax mm = new GraphicMinMax(); GraphicMinMax mm = new GraphicMinMax();
drawShape(mm, false); drawShape(mm, null);
if (mm.getMax().y - mm.getMin().y > maxHeight / scale) if (mm.getMax().y - mm.getMin().y > maxHeight / scale)
scale = (double) (maxHeight - 1) / (mm.getMax().y - mm.getMin().y + 4); scale = (double) (maxHeight - 1) / (mm.getMax().y - mm.getMin().y + 4);
@ -266,7 +266,7 @@ public class VisualElement implements Drawable, Movable, AttributeListener {
gr.scale(scale, scale); gr.scale(scale, scale);
gr.translate(2 - mm.getMin().x, 2 - mm.getMin().y); gr.translate(2 - mm.getMin().x, 2 - mm.getMin().y);
GraphicSwing grs = new GraphicSwing(gr); GraphicSwing grs = new GraphicSwing(gr);
drawTo(grs, false); drawTo(grs, null);
return bi; return bi;
} }

View File

@ -55,9 +55,9 @@ public class Wire implements Drawable, Movable {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
Style style = Style.HIGHLIGHT; Style style = highLight;
if (!highLight) if (style == null)
style = Style.getWireStyle(value); style = Style.getWireStyle(value);
graphic.drawLine(p1, p2, style); graphic.drawLine(p1, p2, style);

View File

@ -84,6 +84,11 @@ public class Style {
*/ */
public static final Style HIGHLIGHT = new Style(WIRETHICK, false, Color.CYAN); public static final Style HIGHLIGHT = new Style(WIRETHICK, false, Color.CYAN);
/**
* error color used for the circles to mark an element
*/
public static final Style ERROR = new Style(WIRETHICK, false, Color.RED.darker());
private final int thickness; private final int thickness;
private final boolean filled; private final boolean filled;
private final Color color; private final Color color;
@ -180,4 +185,5 @@ public class Style {
if (value.getValueIgnoreBurn() == 1) return WIRE_HIGH; if (value.getValueIgnoreBurn() == 1) return WIRE_HIGH;
else return WIRE_LOW; else return WIRE_LOW;
} }
} }

View File

@ -48,7 +48,7 @@ public class BreakShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
Vector center = new Vector(2 + SIZE, 0); Vector center = new Vector(2 + SIZE, 0);
graphic.drawCircle(center.sub(RAD), center.add(RAD), Style.NORMAL); graphic.drawCircle(center.sub(RAD), center.add(RAD), Style.NORMAL);
graphic.drawLine(center.sub(D1), center.add(D1), Style.NORMAL); graphic.drawLine(center.sub(D1), center.add(D1), Style.NORMAL);

View File

@ -83,7 +83,7 @@ public class ButtonShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean heighLight) { public void drawTo(Graphic graphic, Style heighLight) {
boolean down = false; boolean down = false;
if (ioState != null) down = ioState.getOutput(0).getBool(); if (ioState != null) down = ioState.getOutput(0).getBool();

View File

@ -70,7 +70,7 @@ public class ClockShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean heighLight) { public void drawTo(Graphic graphic, Style heighLight) {
graphic.drawPolygon(new Polygon(true) graphic.drawPolygon(new Polygon(true)
.add(-SIZE * 2 - 1, -SIZE) .add(-SIZE * 2 - 1, -SIZE)
.add(-1, -SIZE) .add(-1, -SIZE)

View File

@ -45,7 +45,7 @@ public class ConstShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean heighLight) { public void drawTo(Graphic graphic, Style heighLight) {
Vector textPos = new Vector(-3, 0); Vector textPos = new Vector(-3, 0);
graphic.drawText(textPos, textPos.add(1, 0), value, Orientation.RIGHTCENTER, Style.NORMAL); graphic.drawText(textPos, textPos.add(1, 0), value, Orientation.RIGHTCENTER, Style.NORMAL);
} }

View File

@ -67,7 +67,7 @@ public class DILShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
int dp = SPACING * SIZE; int dp = SPACING * SIZE;
int pin = dp / 4; int pin = dp / 4;
int x = width * SIZE; int x = width * SIZE;

View File

@ -10,6 +10,7 @@ import de.neemann.digital.core.element.PinDescriptions;
import de.neemann.digital.draw.elements.IOState; import de.neemann.digital.draw.elements.IOState;
import de.neemann.digital.draw.elements.Pins; import de.neemann.digital.draw.elements.Pins;
import de.neemann.digital.draw.graphics.Graphic; import de.neemann.digital.draw.graphics.Graphic;
import de.neemann.digital.draw.graphics.Style;
import de.neemann.digital.draw.model.ModelCreator; import de.neemann.digital.draw.model.ModelCreator;
import de.neemann.digital.draw.model.ModelEntry; import de.neemann.digital.draw.model.ModelEntry;
import de.neemann.digital.gui.components.CircuitComponent; import de.neemann.digital.gui.components.CircuitComponent;
@ -61,11 +62,11 @@ public class DataShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean heighLight) { public void drawTo(Graphic graphic, Style heighLight) {
if (dataSet == null) { if (dataSet == null) {
dataSet = new DataSet(); dataSet = new DataSet();
} }
dataSet.drawTo(graphic, false); dataSet.drawTo(graphic, null);
} }
@Override @Override

View File

@ -41,7 +41,7 @@ public class DelayShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean heighLight) { public void drawTo(Graphic graphic, Style heighLight) {
graphic.drawPolygon( graphic.drawPolygon(
new Polygon(true) new Polygon(true)
.add(1, -SIZE2) .add(1, -SIZE2)

View File

@ -65,7 +65,7 @@ public class DemuxerShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
graphic.drawPolygon(new Polygon(true) graphic.drawPolygon(new Polygon(true)
.add(1, 5) .add(1, 5)
.add(SIZE * 2 - 1, -4) .add(SIZE * 2 - 1, -4)

View File

@ -50,7 +50,7 @@ public class DiodeBackwardShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
Style style = blown ? Style.DASH : Style.NORMAL; Style style = blown ? Style.DASH : Style.NORMAL;
graphic.drawPolygon( graphic.drawPolygon(

View File

@ -50,7 +50,7 @@ public class DiodeForewardShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
Style style = blown ? Style.DASH : Style.NORMAL; Style style = blown ? Style.DASH : Style.NORMAL;
graphic.drawPolygon( graphic.drawPolygon(

View File

@ -48,7 +48,7 @@ public class DiodeShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
Style style = blown ? Style.DASH : Style.NORMAL; Style style = blown ? Style.DASH : Style.NORMAL;
graphic.drawPolygon( graphic.drawPolygon(

View File

@ -1,6 +1,7 @@
package de.neemann.digital.draw.shapes; package de.neemann.digital.draw.shapes;
import de.neemann.digital.draw.graphics.Graphic; import de.neemann.digital.draw.graphics.Graphic;
import de.neemann.digital.draw.graphics.Style;
/** /**
* Interface implemented by the elements which can draw itself to a {@link Graphic} instance. * Interface implemented by the elements which can draw itself to a {@link Graphic} instance.
@ -10,9 +11,8 @@ import de.neemann.digital.draw.graphics.Graphic;
public interface Drawable { public interface Drawable {
/** /**
* Draws an element depending on its state. * Draws an element depending on its state.
* * @param graphic interface to draw to
* @param graphic interface to draw to
* @param highLight true if a highlighted drawing is required * @param highLight true if a highlighted drawing is required
*/ */
void drawTo(Graphic graphic, boolean highLight); void drawTo(Graphic graphic, Style highLight);
} }

View File

@ -70,7 +70,7 @@ public class DriverShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
graphic.drawPolygon( graphic.drawPolygon(
new Polygon(true) new Polygon(true)
.add(-SIZE + 1, -SIZE2 - 2) .add(-SIZE + 1, -SIZE2 - 2)

View File

@ -51,7 +51,7 @@ public abstract class FETShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
final int g = SIZE2 / 2; final int g = SIZE2 / 2;
graphic.drawPolygon(new Polygon(false) graphic.drawPolygon(new Polygon(false)
.add(SIZE, 0) .add(SIZE, 0)

View File

@ -37,7 +37,7 @@ public class FETShapeN extends FETShape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
super.drawTo(graphic, highLight); super.drawTo(graphic, highLight);
// the arrow // the arrow

View File

@ -38,7 +38,7 @@ public class FETShapeP extends FETShape {
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
super.drawTo(graphic, highLight); super.drawTo(graphic, highLight);
// the arrow // the arrow

View File

@ -45,7 +45,7 @@ public class FGFETShapeN extends FETShape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
super.drawTo(graphic, highLight); super.drawTo(graphic, highLight);
if (programmed) if (programmed)

View File

@ -44,7 +44,7 @@ public class FGFETShapeP extends FETShape {
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
super.drawTo(graphic, highLight); super.drawTo(graphic, highLight);
if (programmed) if (programmed)

View File

@ -171,7 +171,7 @@ public class GenericShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
int max = Math.max(inputs.size(), outputs.size()); int max = Math.max(inputs.size(), outputs.size());
int height = (max - 1) * SIZE + SIZE2; int height = (max - 1) * SIZE + SIZE2;

View File

@ -43,7 +43,7 @@ public class GroundShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean heighLight) { public void drawTo(Graphic graphic, Style heighLight) {
graphic.drawLine(new Vector(-SIZE2, 0), new Vector(SIZE2, 0), Style.THICK); graphic.drawLine(new Vector(-SIZE2, 0), new Vector(SIZE2, 0), Style.THICK);
} }
} }

View File

@ -88,7 +88,7 @@ public class InputShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean heighLight) { public void drawTo(Graphic graphic, Style heighLight) {
Style style = Style.NORMAL; Style style = Style.NORMAL;
if (ioState != null) { if (ioState != null) {
ObservableValue value = ioState.getOutput(0); ObservableValue value = ioState.getOutput(0);

View File

@ -54,7 +54,7 @@ public class LEDShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean heighLight) { public void drawTo(Graphic graphic, Style heighLight) {
boolean fill = true; boolean fill = true;
if (ioState != null) { if (ioState != null) {
fill = false; fill = false;

View File

@ -12,8 +12,6 @@ import de.neemann.digital.draw.graphics.Graphic;
import de.neemann.digital.draw.graphics.Style; import de.neemann.digital.draw.graphics.Style;
import de.neemann.digital.draw.graphics.Vector; import de.neemann.digital.draw.graphics.Vector;
import java.awt.*;
import static de.neemann.digital.draw.shapes.GenericShape.SIZE; import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
/** /**
@ -56,7 +54,7 @@ public class LightBulbShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
if (a != null && b != null) { if (a != null && b != null) {
boolean on = !a.isHighZ() && !b.isHighZ() && (a.getBool() != b.getBool()); boolean on = !a.isHighZ() && !b.isHighZ() && (a.getBool() != b.getBool());
if (on) if (on)

View File

@ -42,7 +42,7 @@ public class MissingShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
Style style = Style.NORMAL_TEXT; Style style = Style.NORMAL_TEXT;
graphic.drawText(new Vector(4, 4), new Vector(5, 4), message, Orientation.LEFTTOP, style); graphic.drawText(new Vector(4, 4), new Vector(5, 4), message, Orientation.LEFTTOP, style);
if (cause != null && cause.length() > 0) if (cause != null && cause.length() > 0)

View File

@ -60,7 +60,7 @@ public class MuxerShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean heighLight) { public void drawTo(Graphic graphic, Style heighLight) {
graphic.drawPolygon(new Polygon(true) graphic.drawPolygon(new Polygon(true)
.add(1, -4) .add(1, -4)
.add(SIZE * 2 - 1, 5) .add(SIZE * 2 - 1, 5)

View File

@ -63,7 +63,7 @@ public class OutputShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
Style style = Style.NORMAL; Style style = Style.NORMAL;
if (ioState != null) { if (ioState != null) {
ObservableValue value = ioState.getInput(0); ObservableValue value = ioState.getInput(0);

View File

@ -58,7 +58,7 @@ public class ProbeShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
graphic.drawText(new Vector(2, -1), new Vector(3, -1), label, Orientation.LEFTBOTTOM, Style.NORMAL); graphic.drawText(new Vector(2, -1), new Vector(3, -1), label, Orientation.LEFTBOTTOM, Style.NORMAL);
if (bits > 1) { if (bits > 1) {
String v = format.format(inValue); String v = format.format(inValue);

View File

@ -53,7 +53,7 @@ public class PullDownShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
graphic.drawPolygon( graphic.drawPolygon(
new Polygon(true) new Polygon(true)
.add(-WIDTH2, 1) .add(-WIDTH2, 1)

View File

@ -47,7 +47,7 @@ public class PullUpShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
graphic.drawPolygon( graphic.drawPolygon(
new Polygon(true) new Polygon(true)
.add(-WIDTH2, -1) .add(-WIDTH2, -1)

View File

@ -56,7 +56,7 @@ public class RelayShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
int yOffs = 0; int yOffs = 0;
boolean closed = invers; boolean closed = invers;

View File

@ -44,7 +44,7 @@ public class ResetShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
graphic.drawPolygon(new Polygon(true).add(-SIZE * 2 - 2, -SIZE).add(-2, -SIZE).add(-2, SIZE).add(-SIZE * 2 - 2, SIZE), Style.NORMAL); graphic.drawPolygon(new Polygon(true).add(-SIZE * 2 - 2, -SIZE).add(-2, -SIZE).add(-2, SIZE).add(-SIZE * 2 - 2, SIZE), Style.NORMAL);
Vector textPos = new Vector(-SIZE * 2 + 2, -SIZE + 2); Vector textPos = new Vector(-SIZE * 2 + 2, -SIZE + 2);

View File

@ -106,7 +106,7 @@ public class RotEncoderShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean heighLight) { public void drawTo(Graphic graphic, Style heighLight) {
graphic.drawPolygon(new Polygon(true) graphic.drawPolygon(new Polygon(true)
.add(0, -SIZE) .add(0, -SIZE)
.add(0, SIZE * 2) .add(0, SIZE * 2)

View File

@ -74,7 +74,7 @@ public class SevenSegShape extends SevenShape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
super.drawTo(graphic, highLight); super.drawTo(graphic, highLight);
if (commonCatode) if (commonCatode)
graphic.drawLine( graphic.drawLine(

View File

@ -67,7 +67,7 @@ public abstract class SevenShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
graphic.drawPolygon(new Polygon(true) graphic.drawPolygon(new Polygon(true)
.add(-SIZE2, 1) .add(-SIZE2, 1)
.add(SIZE * 3 + SIZE2, 1) .add(SIZE * 3 + SIZE2, 1)

View File

@ -55,7 +55,7 @@ public class SplitterShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean heighLight) { public void drawTo(Graphic graphic, Style heighLight) {
for (int i = 0; i < inputs.size(); i++) { for (int i = 0; i < inputs.size(); i++) {
Vector pos = new Vector(-2, i * SIZE - 3); Vector pos = new Vector(-2, i * SIZE - 3);
graphic.drawText(pos, pos.add(2, 0), inputs.get(i).getName(), Orientation.RIGHTBOTTOM, Style.SHAPE_PIN); graphic.drawText(pos, pos.add(2, 0), inputs.get(i).getName(), Orientation.RIGHTBOTTOM, Style.SHAPE_PIN);

View File

@ -65,7 +65,7 @@ public class SwitchShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
int yOffs = 0; int yOffs = 0;
if (closed) { if (closed) {
graphic.drawLine(new Vector(0, 0), new Vector(SIZE * 2, 0), Style.NORMAL); graphic.drawLine(new Vector(0, 0), new Vector(SIZE * 2, 0), Style.NORMAL);

View File

@ -45,7 +45,7 @@ public class TestCaseShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
Polygon pol = new Polygon(true) Polygon pol = new Polygon(true)
.add(SIZE2, SIZE2) .add(SIZE2, SIZE2)
.add(SIZE2 + SIZE * 4, SIZE2) .add(SIZE2 + SIZE * 4, SIZE2)

View File

@ -45,7 +45,7 @@ public class TextShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
graphic.drawText(new Vector(0, 0), new Vector(1, 0), label, Orientation.LEFTTOP, Style.NORMAL_TEXT); graphic.drawText(new Vector(0, 0), new Vector(1, 0), label, Orientation.LEFTTOP, Style.NORMAL_TEXT);
} }
} }

View File

@ -64,7 +64,7 @@ public class TransGateShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
graphic.drawPolygon(TOP, Style.NORMAL); graphic.drawPolygon(TOP, Style.NORMAL);
graphic.drawPolygon(BOTTOM, Style.NORMAL); graphic.drawPolygon(BOTTOM, Style.NORMAL);
graphic.drawLine(new Vector(SIZE, -SIZE), new Vector(SIZE, -SIZE2), Style.NORMAL); graphic.drawLine(new Vector(SIZE, -SIZE), new Vector(SIZE, -SIZE2), Style.NORMAL);

View File

@ -48,7 +48,7 @@ public class TunnelShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic gr, boolean highLight) { public void drawTo(Graphic gr, Style highLight) {
gr.drawPolygon(new Polygon(true) gr.drawPolygon(new Polygon(true)
.add(0, 0) .add(0, 0)
.add(WIDTH, HEIGHT) .add(WIDTH, HEIGHT)

View File

@ -45,7 +45,7 @@ public class VDDShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean heighLight) { public void drawTo(Graphic graphic, Style heighLight) {
graphic.drawPolygon( graphic.drawPolygon(
new Polygon(false) new Polygon(false)
.add(-SIZE2, DOWNSHIFT) .add(-SIZE2, DOWNSHIFT)

View File

@ -54,7 +54,7 @@ public abstract class IEEEGenericShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
int offs = (inputs.size() / 2 - 1) * SIZE; int offs = (inputs.size() / 2 - 1) * SIZE;
drawIEEE(new GraphicTransform(graphic, v -> v.add(0, offs))); drawIEEE(new GraphicTransform(graphic, v -> v.add(0, offs)));

View File

@ -52,7 +52,7 @@ public class IEEENotShape implements Shape {
} }
@Override @Override
public void drawTo(Graphic graphic, boolean highLight) { public void drawTo(Graphic graphic, Style highLight) {
graphic.drawPolygon( graphic.drawPolygon(
new Polygon(true) new Polygon(true)
.add(1, -SIZE2 - 2) .add(1, -SIZE2 - 2)

View File

@ -917,6 +917,11 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
if (createAndStartModel(false, ModelEvent.MICROSTEP, null)) if (createAndStartModel(false, ModelEvent.MICROSTEP, null))
circuitComponent.setManualChangeObserver(new MicroStepObserver(model)); circuitComponent.setManualChangeObserver(new MicroStepObserver(model));
} }
@Override
public void leave() {
circuitComponent.removeHighLighted();
}
}); });
} }
@ -1009,6 +1014,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
BurnException e = (BurnException) cause; BurnException e = (BurnException) cause;
circuitComponent.addHighLightedWires(e.getValues()); circuitComponent.addHighLightedWires(e.getValues());
} }
circuitComponent.setHighLightStyle(Style.ERROR);
circuitComponent.repaintNeeded(); circuitComponent.repaintNeeded();
new ErrorMessage(message).addCause(cause).show(Main.this); new ErrorMessage(message).addCause(cause).show(Main.this);
stoppedState.enter(); stoppedState.enter();

View File

@ -107,6 +107,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
private ArrayList<Modification> modifications; private ArrayList<Modification> modifications;
private Circuit initialCircuit; private Circuit initialCircuit;
private int undoPosition; private int undoPosition;
private Style highLightStyle = Style.HIGHLIGHT;
/** /**
@ -558,8 +559,19 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
*/ */
public void removeHighLighted() { public void removeHighLighted() {
highLighted.clear(); highLighted.clear();
highLightStyle = Style.HIGHLIGHT;
} }
/**
* Sets the style used to highlight components
*
* @param highLightStyle the style to highlight components
*/
public void setHighLightStyle(Style highLightStyle) {
this.highLightStyle = highLightStyle;
}
/** /**
* Adds the given element to insert to the circuit * Adds the given element to insert to the circuit
* *
@ -624,7 +636,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
GraphicSwing gr = new GraphicSwing(gr2, (int) (2 / transform.getScaleX())); GraphicSwing gr = new GraphicSwing(gr2, (int) (2 / transform.getScaleX()));
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
circuit.drawTo(gr, highLighted, modelSync); circuit.drawTo(gr, highLighted, highLightStyle, modelSync);
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
if (time > 500) antiAlias = false; if (time > 500) antiAlias = false;
@ -1137,7 +1149,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
@Override @Override
public void drawTo(Graphic gr) { public void drawTo(Graphic gr) {
if (delta != null) if (delta != null)
element.drawTo(gr, true); element.drawTo(gr, Style.HIGHLIGHT);
} }
@Override @Override
@ -1203,7 +1215,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
@Override @Override
public void drawTo(Graphic gr) { public void drawTo(Graphic gr) {
visualElement.drawTo(gr, true); visualElement.drawTo(gr, Style.HIGHLIGHT);
} }
@Override @Override
@ -1293,7 +1305,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
@Override @Override
public void drawTo(Graphic gr) { public void drawTo(Graphic gr) {
// ensure that highlighted wire is visible by drawing it on top of other drawings. // ensure that highlighted wire is visible by drawing it on top of other drawings.
wire.drawTo(gr, true); wire.drawTo(gr, Style.HIGHLIGHT);
} }
@Override @Override
@ -1350,7 +1362,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
@Override @Override
public void drawTo(Graphic gr) { public void drawTo(Graphic gr) {
wire.drawTo(gr, true); wire.drawTo(gr, Style.HIGHLIGHT);
} }
@Override @Override
@ -1376,7 +1388,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
} }
private void activate(Vector startPos) { private void activate(Vector startPos) {
startPos=raster(startPos); startPos = raster(startPos);
activate(startPos, startPos); activate(startPos, startPos);
selectionMade = false; selectionMade = false;
} }
@ -1387,7 +1399,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
wire1 = new Wire(startPos, endPos); wire1 = new Wire(startPos, endPos);
wire2 = new Wire(startPos, endPos); wire2 = new Wire(startPos, endPos);
selectionMade = true; selectionMade = true;
lastPosition=endPos; lastPosition = endPos;
setWires(); setWires();
} }
@ -1447,8 +1459,8 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
@Override @Override
public void drawTo(Graphic gr) { public void drawTo(Graphic gr) {
wire1.drawTo(gr, true); wire1.drawTo(gr, Style.HIGHLIGHT);
wire2.drawTo(gr, true); wire2.drawTo(gr, Style.HIGHLIGHT);
} }
@Override @Override
@ -1684,7 +1696,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
if (elements != null) if (elements != null)
for (Movable m : elements) for (Movable m : elements)
if (m instanceof Drawable) if (m instanceof Drawable)
((Drawable) m).drawTo(gr, true); ((Drawable) m).drawTo(gr, Style.HIGHLIGHT);
} }
@Override @Override

View File

@ -140,7 +140,7 @@ public class DataSet implements Iterable<DataSample>, Drawable {
@Override @Override
synchronized public void drawTo(Graphic g, boolean highLight) { synchronized public void drawTo(Graphic g, Style highLight) {
int x = getTextBorder(); int x = getTextBorder();
int yOffs = SIZE / 2; int yOffs = SIZE / 2;

View File

@ -29,7 +29,7 @@ public class DataSetComponent extends JComponent {
g.setColor(Color.WHITE); g.setColor(Color.WHITE);
g.fillRect(0, 0, getWidth(), getHeight()); g.fillRect(0, 0, getWidth(), getHeight());
dataSet.drawTo(new GraphicSwing(g2), false); dataSet.drawTo(new GraphicSwing(g2), null);
} }
@Override @Override

View File

@ -117,10 +117,10 @@ public class DocuTest extends TestCase {
private void writeSVG(File imageFile, VisualElement ve) throws IOException { private void writeSVG(File imageFile, VisualElement ve) throws IOException {
GraphicMinMax minMax = new GraphicMinMax(true); GraphicMinMax minMax = new GraphicMinMax(true);
ve.drawTo(minMax, false); ve.drawTo(minMax, null);
try (FileOutputStream out = new FileOutputStream(imageFile)) { try (FileOutputStream out = new FileOutputStream(imageFile)) {
try (GraphicSVG svg = new GraphicSVG(out, minMax.getMin(), minMax.getMax(), null, 20)) { try (GraphicSVG svg = new GraphicSVG(out, minMax.getMin(), minMax.getMax(), null, 20)) {
ve.drawTo(svg, false); ve.drawTo(svg, null);
} }
} }
} }