Editable lead color; changed default lead color

This commit is contained in:
bancika
2012-10-10 14:49:51 +00:00
parent 024884d85d
commit c57e5f837c
3 changed files with 28 additions and 11 deletions
@@ -38,7 +38,8 @@ public abstract class AbstractLeadedComponent<T> extends
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static Color LEAD_COLOR = Color.decode("#236B8E"); public static Color LEAD_COLOR = Color.decode("#CCCCCC");
public static Color LEAD_COLOR_ICON = LEAD_COLOR.darker().darker();
public static Size LEAD_THICKNESS = new Size(0.6d, SizeUnit.mm); public static Size LEAD_THICKNESS = new Size(0.6d, SizeUnit.mm);
public static Size DEFAULT_SIZE = new Size(1d, SizeUnit.in); public static Size DEFAULT_SIZE = new Size(1d, SizeUnit.in);
@@ -50,6 +51,7 @@ public abstract class AbstractLeadedComponent<T> extends
protected Color bodyColor = Color.white; protected Color bodyColor = Color.white;
protected Color borderColor = Color.black; protected Color borderColor = Color.black;
protected Color labelColor = LABEL_COLOR; protected Color labelColor = LABEL_COLOR;
protected Color leadColor = LEAD_COLOR;
protected Display display = Display.NAME; protected Display display = Display.NAME;
private boolean flipStanding = false; private boolean flipStanding = false;
@@ -129,8 +131,9 @@ public abstract class AbstractLeadedComponent<T> extends
/ 2 - leadThickness / 2; / 2 - leadThickness / 2;
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke( g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness)); leadThickness));
Color leadColor = shouldShadeLeads() ? getLeadColor( Color leadColor = shouldShadeLeads() ? getLeadColorForPainting(
componentState).darker() : getLeadColor(componentState); componentState).darker()
: getLeadColorForPainting(componentState);
g2d.setColor(leadColor); g2d.setColor(leadColor);
int endX = (int) (points[0].x + Math.cos(theta) * leadLength); int endX = (int) (points[0].x + Math.cos(theta) * leadLength);
int endY = (int) Math.round(points[0].y + Math.sin(theta) int endY = (int) Math.round(points[0].y + Math.sin(theta)
@@ -144,7 +147,7 @@ public abstract class AbstractLeadedComponent<T> extends
if (shouldShadeLeads()) { if (shouldShadeLeads()) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke( g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness - 2)); leadThickness - 2));
leadColor = getLeadColor(componentState); leadColor = getLeadColorForPainting(componentState);
g2d.setColor(leadColor); g2d.setColor(leadColor);
g2d.drawLine(points[0].x, points[0].y, g2d.drawLine(points[0].x, points[0].y,
(int) (points[0].x + Math.cos(theta) * leadLength), (int) (points[0].x + Math.cos(theta) * leadLength),
@@ -291,14 +294,15 @@ public abstract class AbstractLeadedComponent<T> extends
private void drawLead(Graphics2D g2d, ComponentState componentState) { private void drawLead(Graphics2D g2d, ComponentState componentState) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke( g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
getLeadThickness())); getLeadThickness()));
Color leadColor = shouldShadeLeads() ? getLeadColor(componentState) Color leadColor = shouldShadeLeads() ? getLeadColorForPainting(
.darker() : getLeadColor(componentState); componentState).darker()
: getLeadColorForPainting(componentState);
g2d.setColor(leadColor); g2d.setColor(leadColor);
g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y); g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
if (shouldShadeLeads()) { if (shouldShadeLeads()) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke( g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
getLeadThickness() - 2)); getLeadThickness() - 2));
leadColor = getLeadColor(componentState); leadColor = getLeadColorForPainting(componentState);
g2d.setColor(leadColor); g2d.setColor(leadColor);
g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y); g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
} }
@@ -367,10 +371,22 @@ public abstract class AbstractLeadedComponent<T> extends
/** /**
* @return default lead color. Override this method to change it. * @return default lead color. Override this method to change it.
*/ */
protected Color getLeadColor(ComponentState componentState) { protected Color getLeadColorForPainting(ComponentState componentState) {
return componentState == ComponentState.SELECTED return componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: LEAD_COLOR; : getLeadColor();
}
@EditableProperty(name = "Lead color")
public Color getLeadColor() {
if (leadColor == null) {
leadColor = LEAD_COLOR_ICON;
}
return leadColor;
}
public void setLeadColor(Color leadColor) {
this.leadColor = leadColor;
} }
protected int calculatePinSpacing(Rectangle shapeRect) { protected int calculatePinSpacing(Rectangle shapeRect) {
@@ -21,6 +21,7 @@ public abstract class AbstractSchematicLeadedSymbol<T> extends AbstractLeadedCom
super(); super();
// We don't want to fill the body, so use null. // We don't want to fill the body, so use null.
this.bodyColor = null; this.bodyColor = null;
this.leadColor = LEAD_COLOR;
this.borderColor = COLOR; this.borderColor = COLOR;
} }
@@ -65,8 +66,8 @@ public abstract class AbstractSchematicLeadedSymbol<T> extends AbstractLeadedCom
} }
@Override @Override
protected Color getLeadColor(ComponentState componentState) { protected Color getLeadColorForPainting(ComponentState componentState) {
return componentState == ComponentState.SELECTED return componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : LEAD_COLOR; || componentState == ComponentState.DRAGGING ? SELECTION_COLOR : getLeadColor();
} }
} }