use red when selected

This commit is contained in:
bancika
2011-01-11 21:48:38 +00:00
parent 19d561d35d
commit 5d22d282fa
5 changed files with 23 additions and 12 deletions
@@ -20,8 +20,8 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
public static Color GUIDELINE_COLOR = Color.blue; public static Color GUIDELINE_COLOR = Color.blue;
protected Point[] controlPoints = new Point[] { protected Point[] controlPoints = new Point[] {
new Point(-5 * Constants.GRID, -5 * Constants.GRID), new Point(0, -3 * Constants.GRID), new Point(-5 * Constants.GRID, -5 * Constants.GRID), new Point(0, -5 * Constants.GRID),
new Point(0, 3 * Constants.GRID), new Point(5 * Constants.GRID, 5 * Constants.GRID) }; new Point(0, 5 * Constants.GRID), new Point(5 * Constants.GRID, 5 * Constants.GRID) };
protected Color color = getDefaultColor(); protected Color color = getDefaultColor();
@@ -30,9 +30,14 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
* *
* @param curve * @param curve
* @param g2d * @param g2d
* @param componentState
*/ */
protected abstract void drawCurve(CubicCurve2D curve, Graphics2D g2d); protected abstract void drawCurve(CubicCurve2D curve, Graphics2D g2d,
ComponentState componentState);
/**
* @return default color.
*/
protected abstract Color getDefaultColor(); protected abstract Color getDefaultColor();
@Override @Override
@@ -75,7 +80,7 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
// g2d.setColor(color); // g2d.setColor(color);
// g2d.setStroke(new BasicStroke(thickness - 2)); // g2d.setStroke(new BasicStroke(thickness - 2));
// g2d.draw(path); // g2d.draw(path);
drawCurve(curve, g2d); drawCurve(curve, g2d, componentState);
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
} }
@@ -6,6 +6,7 @@ import java.awt.Graphics2D;
import java.awt.geom.CubicCurve2D; import java.awt.geom.CubicCurve2D;
import org.diylc.components.AbstractCurvedComponent; import org.diylc.components.AbstractCurvedComponent;
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;
@@ -28,10 +29,11 @@ public class CurvedTrace extends AbstractCurvedComponent<Size> {
} }
@Override @Override
protected void drawCurve(CubicCurve2D curve, Graphics2D g2d) { protected void drawCurve(CubicCurve2D curve, Graphics2D g2d, ComponentState componentState) {
int thickness = size.convertToPixels(); int thickness = size.convertToPixels();
g2d.setStroke(new BasicStroke(thickness)); g2d.setStroke(new BasicStroke(thickness));
g2d.setColor(color); g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color);
g2d.draw(curve); g2d.draw(curve);
} }
@@ -6,6 +6,7 @@ import java.awt.Graphics2D;
import java.awt.geom.CubicCurve2D; import java.awt.geom.CubicCurve2D;
import org.diylc.components.AbstractCurvedComponent; import org.diylc.components.AbstractCurvedComponent;
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;
@@ -27,16 +28,19 @@ public class HookupWire extends AbstractCurvedComponent<AWG> {
} }
@Override @Override
protected void drawCurve(CubicCurve2D curve, Graphics2D g2d) { protected void drawCurve(CubicCurve2D curve, Graphics2D g2d, ComponentState componentState) {
int thickness = (int) (Math.pow(Math.E, -1.12436 - 0.11594 * value.getValue()) int thickness = (int) (Math.pow(Math.E, -1.12436 - 0.11594 * value.getValue())
* Constants.GRID * Constants.GRIDS_PER_INCH * (1 + 2 * INSULATION_THICKNESS_PCT)); * Constants.GRID * Constants.GRIDS_PER_INCH * (1 + 2 * INSULATION_THICKNESS_PCT));
g2d.setColor(color.darker()); g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color.darker());
g2d.setStroke(new BasicStroke(thickness)); g2d.setStroke(new BasicStroke(thickness));
g2d.draw(curve); g2d.draw(curve);
if (componentState == ComponentState.NORMAL) {
g2d.setColor(color); g2d.setColor(color);
g2d.setStroke(new BasicStroke(thickness - 2)); g2d.setStroke(new BasicStroke(thickness - 2));
g2d.draw(curve); g2d.draw(curve);
} }
}
@EditableProperty(name = "AWG") @EditableProperty(name = "AWG")
@Override @Override