optimize performance when rendering stripes

This commit is contained in:
Branislav Stojkovic
2019-02-03 10:40:55 +01:00
parent 6e9169242a
commit 8c09fe72e6
5 changed files with 42 additions and 17 deletions
Binary file not shown.
@@ -44,9 +44,13 @@ public class HookupWire extends AbstractCurvedComponent<Void> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static Color COLOR = Color.green; public static Color COLOR = Color.green;
public static Color STRIPE_COLOR = Color.yellow;
public static double INSULATION_THICKNESS_PCT = 0.3; public static double INSULATION_THICKNESS_PCT = 0.3;
protected AWG gauge = AWG._22; protected AWG gauge = AWG._22;
protected boolean striped = false;
protected Color stripeColor = STRIPE_COLOR;
@Override @Override
protected Color getDefaultColor() { protected Color getDefaultColor() {
@@ -76,22 +80,19 @@ public class HookupWire extends AbstractCurvedComponent<Void> {
} }
Shape s = stroke.createStrokedShape(curve); Shape s = stroke.createStrokedShape(curve);
g2d.fill(s); g2d.fill(s);
if (getStriped()) {
stroke = ObjectCache.getInstance().fetchStroke(thickness, new float[] { thickness / 2, thickness * 2 }, thickness * 10, BasicStroke.CAP_BUTT);
Shape stripe = stroke.createStrokedShape(curve);
g2d.setColor(getStripeColor());
drawingObserver.stopTracking();
g2d.fill(stripe);
drawingObserver.startTracking();
}
if (componentState == ComponentState.NORMAL) { if (componentState == ComponentState.NORMAL) {
g2d.setColor(color.darker()); g2d.setColor(color.darker());
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1f)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1f));
// switch (getStyle()) {
// case SOLID:
// stroke = ObjectCache.getInstance().fetchBasicStroke(thickness - 2);
// break;
// case DASHED:
// stroke =
// ObjectCache.getInstance().fetchStroke(thickness - 2, new float[] {thickness * 2, thickness * 3},
// thickness * 4);
// break;
// case DOTTED:
// stroke = ObjectCache.getInstance().fetchStroke(thickness - 2, new float[] {thickness / 4, thickness * 3}, 0);
// }
// g2d.setStroke(stroke);
g2d.draw(s); g2d.draw(s);
} }
} }
@@ -112,4 +113,24 @@ public class HookupWire extends AbstractCurvedComponent<Void> {
@Override @Override
public void setValue(Void value) {} public void setValue(Void value) {}
@EditableProperty(name = "Stripe")
public boolean getStriped() {
return striped;
}
public void setStriped(boolean striped) {
this.striped = striped;
}
@EditableProperty(name = "Stripe Color")
public Color getStripeColor() {
if (stripeColor == null)
stripeColor = STRIPE_COLOR;
return stripeColor;
}
public void setStripeColor(Color stripeColor) {
this.stripeColor = stripeColor;
}
} }
@@ -107,16 +107,20 @@ public class TwistedWire extends AbstractCurvedComponent<Void> {
g2d.fill(firstLeadArea); g2d.fill(firstLeadArea);
if (stripe1 && componentState == ComponentState.NORMAL) { if (stripe1 && componentState == ComponentState.NORMAL) {
drawingObserver.stopTracking();
g2d.setColor(stripeColor); g2d.setColor(stripeColor);
g2d.fill(firstLeadStripeArea); g2d.fill(firstLeadStripeArea);
drawingObserver.startTracking();
} }
g2d.setColor(curveColor2); g2d.setColor(curveColor2);
g2d.fill(secondLeadArea); g2d.fill(secondLeadArea);
if (stripe2 && componentState == ComponentState.NORMAL) { if (stripe2 && componentState == ComponentState.NORMAL) {
drawingObserver.stopTracking();
g2d.setColor(stripeColor2); g2d.setColor(stripeColor2);
g2d.fill(secondLeadStripeArea); g2d.fill(secondLeadStripeArea);
drawingObserver.startTracking();
} }
if (componentState == ComponentState.NORMAL) { if (componentState == ComponentState.NORMAL) {
@@ -215,7 +219,7 @@ public class TwistedWire extends AbstractCurvedComponent<Void> {
return super.getStyle(); return super.getStyle();
} }
@EditableProperty(name = "Stripe 1") @EditableProperty(name = "Stripe Color 1")
public Color getStripeColor() { public Color getStripeColor() {
return stripeColor; return stripeColor;
} }
@@ -224,7 +228,7 @@ public class TwistedWire extends AbstractCurvedComponent<Void> {
this.stripeColor = stripeColor; this.stripeColor = stripeColor;
} }
@EditableProperty(name = "Stripe 2") @EditableProperty(name = "Stripe Color 2")
public Color getStripeColor2() { public Color getStripeColor2() {
return stripeColor2; return stripeColor2;
} }
@@ -233,7 +237,7 @@ public class TwistedWire extends AbstractCurvedComponent<Void> {
this.stripeColor2 = stripeColor2; this.stripeColor2 = stripeColor2;
} }
@EditableProperty(name = "Show Stripe 1") @EditableProperty(name = "Stripe 1")
public boolean getStripe1() { public boolean getStripe1() {
return stripe1; return stripe1;
} }
@@ -250,7 +254,7 @@ public class TwistedWire extends AbstractCurvedComponent<Void> {
} }
} }
@EditableProperty(name = "Show Stripe 2") @EditableProperty(name = "Stripe 2")
public boolean getStripe2() { public boolean getStripe2() {
return stripe2; return stripe2;
} }
Binary file not shown.
Binary file not shown.