use red when selected

This commit is contained in:
bancika
2011-01-11 21:22:07 +00:00
parent e3a3dfe82e
commit 070e3edf52
7 changed files with 21 additions and 9 deletions
@@ -57,6 +57,8 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
double distance = points[0].distance(points[1]); double distance = points[0].distance(points[1]);
Shape shape = getBodyShape(); Shape shape = getBodyShape();
if (shape == null) { if (shape == null) {
g2d.setStroke(new BasicStroke(getLeadThickness().convertToPixels()));
g2d.setColor(getLeadColor(componentState));
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);
return; return;
} }
@@ -85,7 +87,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
g2d.draw(shape); g2d.draw(shape);
// Draw leads. // Draw leads.
g2d.setStroke(new BasicStroke(getLeadThickness().convertToPixels())); g2d.setStroke(new BasicStroke(getLeadThickness().convertToPixels()));
g2d.setColor(getLeadColor()); g2d.setColor(getLeadColor(componentState));
g2d.drawLine((int) (shapeRect.width - distance) / 2, (int) shapeRect.height / 2, g2d.drawLine((int) (shapeRect.width - distance) / 2, (int) shapeRect.height / 2,
(int) ((shapeRect.width - distance) / 2 + leadLenght), (int) shapeRect.height / 2); (int) ((shapeRect.width - distance) / 2 + leadLenght), (int) shapeRect.height / 2);
g2d.drawLine((int) (shapeRect.width + distance) / 2, (int) shapeRect.height / 2, g2d.drawLine((int) (shapeRect.width + distance) / 2, (int) shapeRect.height / 2,
@@ -139,8 +141,9 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
/** /**
* @return default lead color. Override this method to change it. * @return default lead color. Override this method to change it.
*/ */
protected Color getLeadColor() { protected Color getLeadColor(ComponentState componentState) {
return LEAD_COLOR; return componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : LEAD_COLOR;
} }
@Override @Override
@@ -6,6 +6,7 @@ import java.awt.Graphics2D;
import java.awt.Shape; import java.awt.Shape;
import org.diylc.components.AbstractLeadedComponent; import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@@ -32,8 +33,9 @@ public class CopperTrace extends AbstractLeadedComponent<Void> {
@Override @Override
@EditableProperty(name = "Color") @EditableProperty(name = "Color")
public Color getLeadColor() { public Color getLeadColor(ComponentState componentState) {
return leadColor; return componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : leadColor;
} }
public void setLeadColor(Color leadColor) { public void setLeadColor(Color leadColor) {
@@ -6,8 +6,10 @@ import java.awt.Graphics2D;
import java.awt.Shape; import java.awt.Shape;
import org.diylc.components.AbstractLeadedComponent; import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
@ComponentDescriptor(name = "Jumper", author = "Branislav Stojkovic", category = "Connectivity", instanceNamePrefix = "J", description = "", zOrder = IDIYComponent.ABOVE_BOARD) @ComponentDescriptor(name = "Jumper", author = "Branislav Stojkovic", category = "Connectivity", instanceNamePrefix = "J", description = "", zOrder = IDIYComponent.ABOVE_BOARD)
@@ -25,8 +27,10 @@ public class Jumper extends AbstractLeadedComponent<Void> {
} }
@Override @Override
protected Color getLeadColor() { @EditableProperty(name = "Color")
return COLOR; public Color getLeadColor(ComponentState componentState) {
return componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : COLOR;
} }
@Deprecated @Deprecated
@@ -31,7 +31,8 @@ public class SolderPad extends AbstractComponent<Color> {
public void draw(Graphics2D g2d, ComponentState componentState, Project project) { public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
int diameter = getClosestOdd(size.convertToPixels()); int diameter = getClosestOdd(size.convertToPixels());
int holeDiameter = getClosestOdd(HOLE_SIZE.convertToPixels()); int holeDiameter = getClosestOdd(HOLE_SIZE.convertToPixels());
g2d.setColor(color); g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color);
g2d.fillOval(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter); g2d.fillOval(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter);
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(point.x - holeDiameter / 2, point.y - holeDiameter / 2, holeDiameter, g2d.fillOval(point.x - holeDiameter / 2, point.y - holeDiameter / 2, holeDiameter,
@@ -21,6 +21,7 @@ public class TraceCut extends AbstractSinglePointComponent {
public static Size SIZE = new Size(0.085d, SizeUnit.in); public static Size SIZE = new Size(0.085d, SizeUnit.in);
public static Color FILL_COLOR = Color.white; public static Color FILL_COLOR = Color.white;
public static Color BORDER_COLOR = Color.red; public static Color BORDER_COLOR = Color.red;
public static Color SELECTION_COLOR = Color.blue;
private Size size = SIZE; private Size size = SIZE;
private Color fillColor = FILL_COLOR; private Color fillColor = FILL_COLOR;
@@ -32,7 +33,8 @@ public class TraceCut extends AbstractSinglePointComponent {
int dotDiameter = (size / 3 * 2) / 2 * 2 + 1; int dotDiameter = (size / 3 * 2) / 2 * 2 + 1;
g2d.setColor(fillColor); g2d.setColor(fillColor);
g2d.fillRect(point.x - size / 2, point.y - size / 2, size, size); g2d.fillRect(point.x - size / 2, point.y - size / 2, size, size);
g2d.setColor(borderColor); g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
g2d.setStroke(new BasicStroke(1)); g2d.setStroke(new BasicStroke(1));
g2d.drawRect(point.x - size / 2, point.y - size / 2, size, size); g2d.drawRect(point.x - size / 2, point.y - size / 2, size, size);
g2d g2d