mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-13 06:49:36 -04:00
refactoring of graphic flags
This commit is contained in:
parent
b7c0a4e0ce
commit
c0d682eec1
@ -228,7 +228,7 @@ public class VisualElement implements Drawable, Movable, AttributeListener {
|
|||||||
Graphic gr = new GraphicTransform(graphic, getTransform());
|
Graphic gr = new GraphicTransform(graphic, getTransform());
|
||||||
Shape shape = getShape();
|
Shape shape = getShape();
|
||||||
shape.drawTo(gr, highLight);
|
shape.drawTo(gr, highLight);
|
||||||
if (!graphic.isFlagSet(GraphicSVG.NO_PIN_MARKER))
|
if (!graphic.isFlagSet(Graphic.Flag.noPinMarker))
|
||||||
for (Pin p : shape.getPins())
|
for (Pin p : shape.getPins())
|
||||||
gr.drawCircle(p.getPos().add(-PIN, -PIN), p.getPos().add(PIN, PIN),
|
gr.drawCircle(p.getPos().add(-PIN, -PIN), p.getPos().add(PIN, PIN),
|
||||||
p.getDirection() == Pin.Direction.input ? Style.WIRE : Style.WIRE_OUT);
|
p.getDirection() == Pin.Direction.input ? Style.WIRE : Style.WIRE_OUT);
|
||||||
|
@ -16,25 +16,9 @@ import java.io.IOException;
|
|||||||
public interface Graphic extends Closeable {
|
public interface Graphic extends Closeable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The shape filling flag
|
* The available flags
|
||||||
*/
|
*/
|
||||||
String NO_SHAPE_FILLING = "noShapeFilling";
|
enum Flag {noShapeFilling, smallIO, hideTest, noPinMarker, thinnerLines}
|
||||||
/**
|
|
||||||
* the small IO flag
|
|
||||||
*/
|
|
||||||
String SMALL_IO = "smallIO";
|
|
||||||
/**
|
|
||||||
* flag used to hide the test cases
|
|
||||||
*/
|
|
||||||
String HIDE_TEST = "hideTest";
|
|
||||||
/**
|
|
||||||
* flag used to hide the pin marker
|
|
||||||
*/
|
|
||||||
String NO_PIN_MARKER = "noPinMarker";
|
|
||||||
/**
|
|
||||||
* flag used to make lines thinner
|
|
||||||
*/
|
|
||||||
String THINNER_LINES = "thinnerLines";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the bounding box of the future usage of this instance
|
* Sets the bounding box of the future usage of this instance
|
||||||
@ -114,10 +98,10 @@ public interface Graphic extends Closeable {
|
|||||||
/**
|
/**
|
||||||
* Returns true if the given flag is set
|
* Returns true if the given flag is set
|
||||||
*
|
*
|
||||||
* @param name the flags name
|
* @param flag the flag
|
||||||
* @return true if the given flag is set
|
* @return true if the given flag is set
|
||||||
*/
|
*/
|
||||||
default boolean isFlagSet(String name) {
|
default boolean isFlagSet(Flag flag) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,10 +154,10 @@ public class GraphicMinMax implements Graphic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFlagSet(String name) {
|
public boolean isFlagSet(Flag flag) {
|
||||||
if (parent == null)
|
if (parent == null)
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
return parent.isFlagSet(name);
|
return parent.isFlagSet(flag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ public class GraphicSVG implements Graphic {
|
|||||||
private BufferedWriter w;
|
private BufferedWriter w;
|
||||||
private TextStyle textStyle = new TextFormatSVG();
|
private TextStyle textStyle = new TextFormatSVG();
|
||||||
private ColorStyle colorStyle = Style::getColor;
|
private ColorStyle colorStyle = Style::getColor;
|
||||||
private HashSet<String> flags = new HashSet<>();
|
private HashSet<Flag> flags = new HashSet<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance.
|
* Creates a new instance.
|
||||||
@ -39,17 +39,15 @@ public class GraphicSVG implements Graphic {
|
|||||||
if (a.get(SVGSettings.HIGH_CONTRAST))
|
if (a.get(SVGSettings.HIGH_CONTRAST))
|
||||||
setColorStyle(new ColorStyleHighContrast());
|
setColorStyle(new ColorStyleHighContrast());
|
||||||
if (a.get(SVGSettings.SMALL_IO))
|
if (a.get(SVGSettings.SMALL_IO))
|
||||||
setFlag(SMALL_IO);
|
setFlag(Flag.smallIO);
|
||||||
if (a.get(SVGSettings.HIDE_TEST))
|
if (a.get(SVGSettings.HIDE_TEST))
|
||||||
setFlag(HIDE_TEST);
|
setFlag(Flag.hideTest);
|
||||||
if (a.get(SVGSettings.NO_SHAPE_FILLING))
|
if (a.get(SVGSettings.NO_SHAPE_FILLING))
|
||||||
setFlag(NO_SHAPE_FILLING);
|
setFlag(Flag.noShapeFilling);
|
||||||
if (a.get(SVGSettings.NO_SHAPE_FILLING))
|
|
||||||
setFlag(NO_SHAPE_FILLING);
|
|
||||||
if (a.get(SVGSettings.NO_PIN_MARKER))
|
if (a.get(SVGSettings.NO_PIN_MARKER))
|
||||||
setFlag(NO_PIN_MARKER);
|
setFlag(Flag.noPinMarker);
|
||||||
if (a.get(SVGSettings.THINNER_LINES))
|
if (a.get(SVGSettings.THINNER_LINES))
|
||||||
setFlag(THINNER_LINES);
|
setFlag(Flag.thinnerLines);
|
||||||
|
|
||||||
if (a.get(SVGSettings.MONOCHROME))
|
if (a.get(SVGSettings.MONOCHROME))
|
||||||
setColorStyle(new ColorStyleMonochrome(colorStyle));
|
setColorStyle(new ColorStyleMonochrome(colorStyle));
|
||||||
@ -140,7 +138,7 @@ public class GraphicSVG implements Graphic {
|
|||||||
if (p.getEvenOdd() && style.isFilled())
|
if (p.getEvenOdd() && style.isFilled())
|
||||||
w.write(" fill-rule=\"evenodd\"");
|
w.write(" fill-rule=\"evenodd\"");
|
||||||
|
|
||||||
if (style.isFilled() && p.isClosed() && !isFlagSet(NO_SHAPE_FILLING))
|
if (style.isFilled() && p.isClosed() && !isFlagSet(Flag.noShapeFilling))
|
||||||
w.write(" stroke=\"" + getColor(style) + "\" stroke-width=\"" + getStrokeWidth(style) + "\" fill=\"" + getColor(style) + "\" fill-opacity=\"" + getOpacity(style) + "\"/>\n");
|
w.write(" stroke=\"" + getColor(style) + "\" stroke-width=\"" + getStrokeWidth(style) + "\" fill=\"" + getColor(style) + "\" fill-opacity=\"" + getOpacity(style) + "\"/>\n");
|
||||||
else {
|
else {
|
||||||
double strokeWidth = getStrokeWidth(style);
|
double strokeWidth = getStrokeWidth(style);
|
||||||
@ -154,7 +152,7 @@ public class GraphicSVG implements Graphic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private double getStrokeWidth(Style style) {
|
private double getStrokeWidth(Style style) {
|
||||||
if (isFlagSet(THINNER_LINES))
|
if (isFlagSet(Flag.thinnerLines))
|
||||||
return style.getThickness() * 0.7;
|
return style.getThickness() * 0.7;
|
||||||
else
|
else
|
||||||
return style.getThickness();
|
return style.getThickness();
|
||||||
@ -319,13 +317,13 @@ public class GraphicSVG implements Graphic {
|
|||||||
this.colorStyle = colorStyle;
|
this.colorStyle = colorStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setFlag(String flag) {
|
private void setFlag(Flag flag) {
|
||||||
flags.add(flag);
|
flags.add(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFlagSet(String name) {
|
public boolean isFlagSet(Flag flag) {
|
||||||
return flags.contains(name);
|
return flags.contains(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,7 +45,7 @@ public class GraphicTransform implements Graphic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFlagSet(String name) {
|
public boolean isFlagSet(Flag flag) {
|
||||||
return parent.isFlagSet(name);
|
return parent.isFlagSet(flag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ public class GraphicSkipLines implements Graphic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFlagSet(String name) {
|
public boolean isFlagSet(Flag flag) {
|
||||||
return delegate.isFlagSet(name);
|
return delegate.isFlagSet(flag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ public class AsyncClockShape implements Shape {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawTo(Graphic graphic, Style highLight) {
|
public void drawTo(Graphic graphic, Style highLight) {
|
||||||
if (!graphic.isFlagSet(Graphic.HIDE_TEST)) {
|
if (!graphic.isFlagSet(Graphic.Flag.hideTest)) {
|
||||||
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)
|
||||||
|
@ -74,7 +74,7 @@ public class ClockShape implements Shape {
|
|||||||
@Override
|
@Override
|
||||||
public void drawTo(Graphic graphic, Style heighLight) {
|
public void drawTo(Graphic graphic, Style heighLight) {
|
||||||
Vector wavePos;
|
Vector wavePos;
|
||||||
if (graphic.isFlagSet(Graphic.SMALL_IO)) {
|
if (graphic.isFlagSet(Graphic.Flag.smallIO)) {
|
||||||
Vector center = new Vector(-LATEX_RAD.x, 0);
|
Vector center = new Vector(-LATEX_RAD.x, 0);
|
||||||
graphic.drawCircle(center.sub(LATEX_RAD), center.add(LATEX_RAD), Style.NORMAL);
|
graphic.drawCircle(center.sub(LATEX_RAD), center.add(LATEX_RAD), Style.NORMAL);
|
||||||
Vector textPos = new Vector(-SIZE2 - LATEX_RAD.x, 0);
|
Vector textPos = new Vector(-SIZE2 - LATEX_RAD.x, 0);
|
||||||
|
@ -123,7 +123,7 @@ public class InputShape implements Shape {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawTo(Graphic graphic, Style heighLight) {
|
public void drawTo(Graphic graphic, Style heighLight) {
|
||||||
if (graphic.isFlagSet(Graphic.SMALL_IO)) {
|
if (graphic.isFlagSet(Graphic.Flag.smallIO)) {
|
||||||
Vector center = new Vector(-LATEX_RAD.x, 0);
|
Vector center = new Vector(-LATEX_RAD.x, 0);
|
||||||
graphic.drawCircle(center.sub(LATEX_RAD), center.add(LATEX_RAD), Style.NORMAL);
|
graphic.drawCircle(center.sub(LATEX_RAD), center.add(LATEX_RAD), Style.NORMAL);
|
||||||
Vector textPos = new Vector(-SIZE2 - LATEX_RAD.x, 0);
|
Vector textPos = new Vector(-SIZE2 - LATEX_RAD.x, 0);
|
||||||
|
@ -84,7 +84,7 @@ public class OutputShape implements Shape {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawTo(Graphic graphic, Style highLight) {
|
public void drawTo(Graphic graphic, Style highLight) {
|
||||||
if (graphic.isFlagSet(Graphic.SMALL_IO)) {
|
if (graphic.isFlagSet(Graphic.Flag.smallIO)) {
|
||||||
Vector center = new Vector(LATEX_RAD.x, 0);
|
Vector center = new Vector(LATEX_RAD.x, 0);
|
||||||
graphic.drawCircle(center.sub(LATEX_RAD), center.add(LATEX_RAD), Style.NORMAL);
|
graphic.drawCircle(center.sub(LATEX_RAD), center.add(LATEX_RAD), Style.NORMAL);
|
||||||
Vector textPos = new Vector(SIZE2 + LATEX_RAD.x, 0);
|
Vector textPos = new Vector(SIZE2 + LATEX_RAD.x, 0);
|
||||||
|
@ -49,7 +49,7 @@ public class TestCaseShape implements Shape {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawTo(Graphic graphic, Style highLight) {
|
public void drawTo(Graphic graphic, Style highLight) {
|
||||||
if (!graphic.isFlagSet(Graphic.HIDE_TEST)) {
|
if (!graphic.isFlagSet(Graphic.Flag.hideTest)) {
|
||||||
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)
|
||||||
|
@ -1361,7 +1361,7 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
|
|||||||
<string name="key_showTutorial_tt">Aktiviert das Tutorial.</string>
|
<string name="key_showTutorial_tt">Aktiviert das Tutorial.</string>
|
||||||
|
|
||||||
<string name="menu_exportSVGSettings">SVG Exporteinstellungen</string>
|
<string name="menu_exportSVGSettings">SVG Exporteinstellungen</string>
|
||||||
<string name="key_SVG_LaTeX">Text als LaTeX</string>
|
<string name="key_SVG_LaTeX">Text im LaTeX-Format</string>
|
||||||
<string name="key_SVG_LaTeX_tt">Text wird in LaTeX-Notation eingefügt. Inkscape ist für die Weiterverabeitung erforderlich.</string>
|
<string name="key_SVG_LaTeX_tt">Text wird in LaTeX-Notation eingefügt. Inkscape ist für die Weiterverabeitung erforderlich.</string>
|
||||||
<string name="key_SVG_hideTest">Testfälle verbergen</string>
|
<string name="key_SVG_hideTest">Testfälle verbergen</string>
|
||||||
<string name="key_SVG_hideTest__">Die Testfälle werden nicht mit exportiert.</string>
|
<string name="key_SVG_hideTest__">Die Testfälle werden nicht mit exportiert.</string>
|
||||||
@ -1373,9 +1373,9 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
|
|||||||
<string name="key_SVG_noPinMarker_tt">Die blauen und roten Pin-Marker an den Symbolen entfallen.</string>
|
<string name="key_SVG_noPinMarker_tt">Die blauen und roten Pin-Marker an den Symbolen entfallen.</string>
|
||||||
<string name="key_SVG_highContrast">hoher Kontrast</string>
|
<string name="key_SVG_highContrast">hoher Kontrast</string>
|
||||||
<string name="key_SVG_highContrast_tt">Leitungen und der Text der Pins werden in Schwarz ausgegeben.</string>
|
<string name="key_SVG_highContrast_tt">Leitungen und der Text der Pins werden in Schwarz ausgegeben.</string>
|
||||||
<string name="key_SVG_monochrome">Monochrom</string>
|
<string name="key_SVG_monochrome">monochrom</string>
|
||||||
<string name="key_SVG_monochrome_tt">Es werden nur Graustufen verwendet.</string>
|
<string name="key_SVG_monochrome_tt">Es werden nur Graustufen verwendet.</string>
|
||||||
<string name="key_SVG_thinnerLines">Dünne Linien</string>
|
<string name="key_SVG_thinnerLines">dünne Linien</string>
|
||||||
<string name="key_SVG_thinnerLines_tt">Wenn gesetzt, werden die Linen etwas dünner gezeichnet.</string>
|
<string name="key_SVG_thinnerLines_tt">Wenn gesetzt, werden die Linen etwas dünner gezeichnet.</string>
|
||||||
|
|
||||||
<string name="mod_insertWire">Leitung eingefügt.</string>
|
<string name="mod_insertWire">Leitung eingefügt.</string>
|
||||||
|
@ -1347,7 +1347,7 @@
|
|||||||
<string name="key_showTutorial_tt">Enables the tutorial.</string>
|
<string name="key_showTutorial_tt">Enables the tutorial.</string>
|
||||||
|
|
||||||
<string name="menu_exportSVGSettings">SVG Export Settings</string>
|
<string name="menu_exportSVGSettings">SVG Export Settings</string>
|
||||||
<string name="key_SVG_LaTeX">Text as LaTeX</string>
|
<string name="key_SVG_LaTeX">Text in LaTeX notation</string>
|
||||||
<string name="key_SVG_LaTeX_tt">Text is inserted in LaTeX notation. Inkscape is required for further processing.</string>
|
<string name="key_SVG_LaTeX_tt">Text is inserted in LaTeX notation. Inkscape is required for further processing.</string>
|
||||||
<string name="key_SVG_hideTest">Hide Test Cases</string>
|
<string name="key_SVG_hideTest">Hide Test Cases</string>
|
||||||
<string name="key_SVG_hideTest__">The test cases are not exported.</string>
|
<string name="key_SVG_hideTest__">The test cases are not exported.</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user