added some documentation

This commit is contained in:
hneemann 2016-04-17 11:30:51 +02:00
parent abcb49b2c7
commit 4c75bfd745
6 changed files with 117 additions and 69 deletions

View File

@ -158,9 +158,7 @@ public class VisualElement implements Drawable, Moveable, AttributeListener {
// draw circle around element
if (highLight) {
GraphicMinMax mm = getMinMax();
Vector delta = mm.getMax().sub(mm.getMin());
int rad = (int) Math.sqrt(delta.x * delta.x + delta.y * delta.y) / 2;
delta = new Vector(rad, rad);
Vector delta = mm.getMax().sub(mm.getMin()).mul(3).div(5);
Vector pos = mm.getMax().add(mm.getMin()).div(2);
graphic.drawCircle(pos.sub(delta), pos.add(delta), Style.HIGHLIGHT);
}

View File

@ -15,9 +15,9 @@ public class GraphicSVG implements Graphic, Closeable {
/**
* Creates a new instance.
*
* @param out the stream
* @param min upper left corner
* @param max lower right corner
* @param out the stream
* @param min upper left corner
* @param max lower right corner
* @throws IOException IOException
*/
public GraphicSVG(OutputStream out, Vector min, Vector max) throws IOException {
@ -79,38 +79,36 @@ public class GraphicSVG implements Graphic, Closeable {
@Override
public void drawLine(Vector p1, Vector p2, Style style) {
if (style != Style.INVISIBLE)
try {
w.write("<line x1=\"" + p1.x + "\" y1=\"" + p1.y + "\" x2=\"" + p2.x + "\" y2=\"" + p2.y + "\" stroke=\"" + getColor(style) + "\" stroke-linecap=\"square\" stroke-width=\"" + getStrokeWidth(style) + "\"");
try {
w.write("<line x1=\"" + p1.x + "\" y1=\"" + p1.y + "\" x2=\"" + p2.x + "\" y2=\"" + p2.y + "\" stroke=\"" + getColor(style) + "\" stroke-linecap=\"square\" stroke-width=\"" + getStrokeWidth(style) + "\"");
// if (style.isDashed())
// addStrokeDash(w, style.getDashArray());
w.write(" />\n");
} catch (IOException e) {
throw new RuntimeException(e);
}
w.write(" />\n");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void drawPolygon(Polygon p, Style style) {
if (style != Style.INVISIBLE)
try {
w.write("<path d=\"M " + str(p.get(0)));
for (int i = 1; i < p.size(); i++)
w.write(" L " + str(p.get(i)));
try {
w.write("<path d=\"M " + str(p.get(0)));
for (int i = 1; i < p.size(); i++)
w.write(" L " + str(p.get(i)));
if (p.isClosed())
w.write(" Z");
if (p.isClosed())
w.write(" Z");
w.write("\"");
w.write("\"");
// if (style.isDashed())
// addStrokeDash(w, style.getDashArray());
if (style.isFilled() && p.isClosed())
w.write(" stroke=\"" + getColor(style) + "\" stroke-width=\"" + getStrokeWidth(style) + "\" fill=\"" + getColor(style) + "\"/>\n");
else
w.write(" stroke=\"" + getColor(style) + "\" stroke-width=\"" + getStrokeWidth(style) + "\" fill=\"none\"/>\n");
} catch (IOException e) {
throw new RuntimeException(e);
}
if (style.isFilled() && p.isClosed())
w.write(" stroke=\"" + getColor(style) + "\" stroke-width=\"" + getStrokeWidth(style) + "\" fill=\"" + getColor(style) + "\"/>\n");
else
w.write(" stroke=\"" + getColor(style) + "\" stroke-width=\"" + getStrokeWidth(style) + "\" fill=\"none\"/>\n");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static double getStrokeWidth(Style style) {
@ -119,21 +117,20 @@ public class GraphicSVG implements Graphic, Closeable {
@Override
public void drawCircle(Vector p1, Vector p2, Style style) {
if (style != Style.INVISIBLE)
try {
Vector c = p1.add(p2).div(2);
double r = Math.abs(p2.sub(p1).x) / 2.0;
if (style.isFilled())
w.write("<circle cx=\"" + c.x + "\" cy=\"" + c.y + "\" r=\"" + r + "\" stroke=\"" + getColor(style) + "\" stroke-width=\"" + getStrokeWidth(style) + "\" fill=\"" + getColor(style) + "\" />\n");
else {
w.write("<circle cx=\"" + c.x + "\" cy=\"" + c.y + "\" r=\"" + r + "\" stroke=\"" + getColor(style) + "\" stroke-width=\"" + getStrokeWidth(style) + "\" fill=\"none\"");
try {
Vector c = p1.add(p2).div(2);
double r = Math.abs(p2.sub(p1).x) / 2.0;
if (style.isFilled())
w.write("<circle cx=\"" + c.x + "\" cy=\"" + c.y + "\" r=\"" + r + "\" stroke=\"" + getColor(style) + "\" stroke-width=\"" + getStrokeWidth(style) + "\" fill=\"" + getColor(style) + "\" />\n");
else {
w.write("<circle cx=\"" + c.x + "\" cy=\"" + c.y + "\" r=\"" + r + "\" stroke=\"" + getColor(style) + "\" stroke-width=\"" + getStrokeWidth(style) + "\" fill=\"none\"");
// if (style.isDashed())
// addStrokeDash(w, style.getDashArray());
w.write(" />\n");
}
} catch (IOException e) {
throw new RuntimeException(e);
w.write(" />\n");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override

View File

@ -27,32 +27,28 @@ public class GraphicSwing implements Graphic {
@Override
public void drawLine(Vector p1, Vector p2, Style style) {
if (style != Style.INVISIBLE) {
applyStyle(style);
gr.drawLine(p1.x, p1.y, p2.x, p2.y);
}
applyStyle(style);
gr.drawLine(p1.x, p1.y, p2.x, p2.y);
}
@Override
public void drawPolygon(Polygon p, Style style) {
if (style != Style.INVISIBLE) {
applyStyle(style);
Path2D path = new GeneralPath();
boolean first = true;
for (Vector v : p)
if (first) {
first = false;
path.moveTo(v.x, v.y);
} else
path.lineTo(v.x, v.y);
applyStyle(style);
Path2D path = new GeneralPath();
boolean first = true;
for (Vector v : p)
if (first) {
first = false;
path.moveTo(v.x, v.y);
} else
path.lineTo(v.x, v.y);
if (p.isClosed())
path.closePath();
if (p.isClosed())
path.closePath();
if (style.isFilled() && p.isClosed())
gr.fill(path);
gr.draw(path);
}
if (style.isFilled() && p.isClosed())
gr.fill(path);
gr.draw(path);
}
@Override

View File

@ -1,17 +1,46 @@
package de.neemann.digital.draw.graphics;
/**
* The text orientation
*
* @author hneemann
*/
public enum Orientation {
/**
* the anchor point is at the left side of the text at the bottom line
*/
LEFTBOTTOM(0, 0),
/**
* the anchor point is at the center of the text at the bottom line
*/
CENTERBOTTOM(1, 0),
/**
* the anchor point is at the right side of the text at the bottom line
*/
RIGHTBOTTOM(2, 0),
/**
* the anchor point is at the right side of the text in middle height
*/
RIGHTCENTER(2, 1),
/**
* the anchor point is at the right side of the text at the top of the text
*/
RIGHTTOP(2, 2),
/**
* the anchor point is at the center of the text at the top of the text
*/
CENTERTOP(1, 2),
/**
* the anchor point is at the left side of the text at the top of the text
*/
LEFTTOP(0, 2),
/**
* the anchor point is at the left side of the text in middle height
*/
LEFTCENTER(0, 1),
/**
* the anchor point is in the center of the text
*/
CENTERCENTER(1, 1);

View File

@ -8,18 +8,50 @@ import java.awt.*;
* @author hneemann
*/
public class Style {
/**
* used for all lines to draw the shapes itself
*/
public static final Style NORMAL = new Style(4, false, Color.BLACK);
/**
* thin line used for the graphic in the clock or delay shape
*/
public static final Style THIN = new Style(2, false, Color.BLACK);
/**
* Used for wires in editing mode
*/
public static final Style WIRE = new Style(4, true, Color.BLUE.darker());
/**
* Used for low wires in running mode
*/
public static final Style WIRE_LOW = new Style(4, true, new Color(0, 112, 0));
/**
* Used for high wires in running mode
*/
public static final Style WIRE_HIGH = new Style(4, true, new Color(102, 255, 102));
/**
* Used for wires in high Z state
*/
public static final Style WIRE_HIGHZ = new Style(4, true, Color.GRAY);
/**
* used to draw the output dots
*/
public static final Style WIRE_OUT = new Style(4, true, Color.RED.darker());
/**
* filld style used to fill the splitter or the dark LEDs
*/
public static final Style FILLED = new Style(4, true, Color.BLACK);
/**
* Used to draw the grid in the graph
*/
public static final Style DASH = new Style(1, false, Color.BLACK, new float[]{4, 4});
/**
* Used todraw the pin description text
*/
public static final Style SHAPE_PIN = new Style(4, false, Color.GRAY, 18, null);
/**
* highlight color used for the circles to mark an element
*/
public static final Style HIGHLIGHT = new Style(4, false, Color.CYAN);
public static final Style INVISIBLE = new Style(0, false, Color.WHITE);
private final int thickness;
private final boolean filled;

View File

@ -5,7 +5,10 @@ import de.neemann.digital.core.element.ElementAttributes;
import de.neemann.digital.core.element.PinDescription;
import de.neemann.digital.draw.elements.IOState;
import de.neemann.digital.draw.elements.Pins;
import de.neemann.digital.draw.graphics.*;
import de.neemann.digital.draw.graphics.Graphic;
import de.neemann.digital.draw.graphics.Orientation;
import de.neemann.digital.draw.graphics.Style;
import de.neemann.digital.draw.graphics.Vector;
import de.neemann.digital.lang.Lang;
/**
@ -41,13 +44,6 @@ public class TextShape implements Shape {
@Override
public void drawTo(Graphic graphic, boolean highLight) {
int size = Style.NORMAL.getFontSize();
graphic.drawPolygon(
new Polygon(true)
.add(0, 0)
.add(size * 2, 0)
.add(size * 2, size)
.add(0, size), Style.INVISIBLE);
graphic.drawText(new Vector(0, 0), new Vector(1, 0), label, Orientation.LEFTTOP, Style.NORMAL);
}
}