use red rectangle when selected

This commit is contained in:
bancika
2011-01-11 19:21:05 +00:00
parent 37a7362d9e
commit a97f83f1ac
6 changed files with 11 additions and 11 deletions
@@ -1,5 +1,6 @@
package org.diylc.core; package org.diylc.core;
import java.awt.Color;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.io.Serializable; import java.io.Serializable;
@@ -38,6 +39,8 @@ public interface IDIYComponent<T> extends Serializable {
public static final int ABOVE_BOARD = 6; public static final int ABOVE_BOARD = 6;
public static final int COMPONENT = 7; public static final int COMPONENT = 7;
public static final int ABOVE_COMPONENT = 8; public static final int ABOVE_COMPONENT = 8;
public static Color SELECTION_COLOR = Color.red;
/** /**
* @return component instance name. * @return component instance name.
@@ -43,7 +43,8 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
- controlPoints[0].x, controlPoints[1].y - controlPoints[0].y); - controlPoints[0].x, controlPoints[1].y - controlPoints[0].y);
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
} }
g2d.setColor(borderColor); g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
g2d.drawRect(controlPoints[0].x, controlPoints[0].y, controlPoints[1].x g2d.drawRect(controlPoints[0].x, controlPoints[0].y, controlPoints[1].x
- controlPoints[0].x, controlPoints[1].y - controlPoints[0].y); - controlPoints[0].x, controlPoints[1].y - controlPoints[0].y);
} }
@@ -168,7 +168,8 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
} }
g2d.setStroke(new BasicStroke()); g2d.setStroke(new BasicStroke());
g2d.setColor(BORDER_COLOR); g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR);
g2d.draw(body); g2d.draw(body);
} }
// Draw lugs. // Draw lugs.
@@ -34,7 +34,6 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
public static Color PIN_BORDER_COLOR = PIN_COLOR.darker(); public static Color PIN_BORDER_COLOR = PIN_COLOR.darker();
public static Color INDENT_COLOR = Color.lightGray; public static Color INDENT_COLOR = Color.lightGray;
public static Color LABEL_COLOR = Color.white; public static Color LABEL_COLOR = Color.white;
public static Color LABEL_COLOR_SELECTED = Color.red;
public static int EDGE_RADIUS = 6; public static int EDGE_RADIUS = 6;
public static Size PIN_SIZE = new Size(0.04d, SizeUnit.in); public static Size PIN_SIZE = new Size(0.04d, SizeUnit.in);
public static Size INDENT_SIZE = new Size(0.15d, SizeUnit.in); public static Size INDENT_SIZE = new Size(0.15d, SizeUnit.in);
@@ -229,19 +228,15 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
g2d.fill(getBody()); g2d.fill(getBody());
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
} }
g2d.setColor(BORDER_COLOR); g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR);
g2d.setStroke(new BasicStroke()); g2d.setStroke(new BasicStroke());
g2d.draw(getBody()); g2d.draw(getBody());
// Draw label. // Draw label.
g2d.setFont(Constants.LABEL_FONT); g2d.setFont(Constants.LABEL_FONT);
switch (componentState) { if (componentState == ComponentState.DRAGGING) {
case DRAGGING:
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
break; } else {
case SELECTED:
g2d.setColor(LABEL_COLOR_SELECTED);
break;
default:
g2d.setColor(LABEL_COLOR); g2d.setColor(LABEL_COLOR);
} }
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont()); FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());