added dashed style

This commit is contained in:
hneemann 2016-04-01 16:10:36 +02:00
parent 45a6ea8e51
commit b858d72fd5
2 changed files with 22 additions and 14 deletions

View File

@ -15,28 +15,33 @@ public class Style {
public static final Style WIRE_HIGHZ = new Style(2, true, Color.GRAY);
public static final Style WIRE_OUT = new Style(2, true, Color.RED.darker());
public static final Style FILLED = new Style(2, true, Color.BLACK);
public static final Style THIN = new Style(1, false, Color.BLACK);
public static final Style DASH = new Style(1, false, Color.BLACK);
public static final Style SHAPE_PIN = new Style(2, false, Color.GRAY, 9);
public static final Style DASH = new Style(0, false, Color.BLACK, new float[]{2, 2});
public static final Style SHAPE_PIN = new Style(2, false, Color.GRAY, 9, null);
public static final Style HIGHLIGHT = new Style(2, false, Color.CYAN);
private final int thickness;
private final boolean filled;
private final Color color;
private final int fontsize;
private final float[] dash;
private final Stroke stroke;
private final Font font;
public Style(int thickness, boolean filled, Color color) {
this(thickness, filled, color, 12);
public Style(int thickness, boolean filled, Color color, float[] dash) {
this(thickness, filled, color, 12, dash);
}
private Style(int thickness, boolean filled, Color color, int fontsize) {
public Style(int thickness, boolean filled, Color color) {
this(thickness, filled, color, 12, null);
}
private Style(int thickness, boolean filled, Color color, int fontsize, float[] dash) {
this.thickness = thickness;
this.filled = filled;
this.color = color;
this.fontsize = fontsize;
stroke = new BasicStroke(thickness);
this.dash = dash;
stroke = new BasicStroke(thickness, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10f, dash, 0f);
font = new Font("Arial", Font.PLAIN, fontsize);
}
@ -65,6 +70,10 @@ public class Style {
return font;
}
public float[] getDash() {
return dash;
}
public static Style getWireStyle(ObservableValue value) {
if (value == null || value.getBits() > 1) return WIRE;
if (value.isHighZIgnoreBurn()) return WIRE_HIGHZ;

View File

@ -9,7 +9,6 @@ import de.neemann.digital.draw.elements.Moveable;
import de.neemann.digital.draw.elements.VisualElement;
import de.neemann.digital.draw.elements.Wire;
import de.neemann.digital.draw.graphics.*;
import de.neemann.digital.draw.graphics.Polygon;
import de.neemann.digital.draw.library.ElementLibrary;
import de.neemann.digital.draw.shapes.Drawable;
import de.neemann.digital.draw.shapes.GenericShape;
@ -457,12 +456,12 @@ public class CircuitComponent extends JComponent {
@Override
public void drawTo(Graphic gr) {
if (corner1 != null && corner2 != null) {
Polygon p = new Polygon(true)
.add(corner1)
.add(new Vector(corner1.x, corner2.y))
.add(corner2)
.add(new Vector(corner2.x, corner1.y));
gr.drawPolygon(p, Style.DASH);
Vector p1 = new Vector(corner1.x, corner2.y);
Vector p2 = new Vector(corner2.x, corner1.y);
gr.drawLine(corner1, p1, Style.DASH);
gr.drawLine(p1, corner2, Style.DASH);
gr.drawLine(corner2, p2, Style.DASH);
gr.drawLine(p2, corner1, Style.DASH);
}
if (state == State.COPY && elements != null)
for (Moveable m : elements)