added label

This commit is contained in:
bancika
2011-01-23 18:23:34 +00:00
parent f9c08ecbaa
commit 4106d2dad5
21 changed files with 234 additions and 56 deletions
@@ -21,7 +21,6 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.plugins.file.BomEntry;
import org.diylc.plugins.file.BomMaker;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Bill of Materials", author = "Branislav Stojkovic", category = "Misc", description = "", instanceNamePrefix = "BOM", zOrder = IDIYComponent.ABOVE_COMPONENT, stretchable = false)
public class BOM extends AbstractComponent<Void> {
@@ -48,7 +47,7 @@ public class BOM extends AbstractComponent<Void> {
iterator.remove();
}
}
g2d.setFont(Constants.LABEL_FONT);
g2d.setFont(LABEL_FONT);
g2d.setColor(componentState == ComponentState.DRAGGING
|| componentState == ComponentState.SELECTED ? SELECTION_COLOR : COLOR);
// Determine maximum name length and maximum value length to calculate
@@ -99,7 +98,7 @@ public class BOM extends AbstractComponent<Void> {
g2d.fillRect(width / 8, 0, 6 * width / 8, height - 1);
g2d.setColor(Color.black);
g2d.drawRect(width / 8, 0, 6 * width / 8, height - 1);
g2d.setFont(Constants.LABEL_FONT.deriveFont(1f * 9 * width / 32).deriveFont(Font.PLAIN));
g2d.setFont(LABEL_FONT.deriveFont(1f * 9 * width / 32).deriveFont(Font.PLAIN));
FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D rect = fontMetrics.getStringBounds("BOM", g2d);
@@ -0,0 +1,124 @@
package org.diylc.components.misc;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Rectangle2D;
import org.diylc.components.AbstractComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
@ComponentDescriptor(name = "Label", author = "Branislav Stojkovic", category = "Misc", description = "User defined label", instanceNamePrefix = "L", zOrder = IDIYComponent.ABOVE_COMPONENT, stretchable = false)
public class Label extends AbstractComponent<Void> {
public static String DEFAULT_TEXT = "Double click to edit text";
private static final long serialVersionUID = 1L;
private Point point = new Point(0, 0);
private String text = DEFAULT_TEXT;
private Font font = LABEL_FONT;
private Color color = LABEL_COLOR;
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
g2d.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED : color);
g2d.setFont(font);
FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D rect = fontMetrics.getStringBounds(text, g2d);
int textHeight = (int) rect.getHeight();
int textWidth = (int) rect.getWidth();
// Center text horizontally and vertically
int x = point.x - textWidth / 2;
int y = point.y - textHeight / 2 + fontMetrics.getAscent();
g2d.drawString(text, x, y);
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(LABEL_COLOR);
g2d.setFont(LABEL_FONT.deriveFont(13f * width / 32).deriveFont(Font.PLAIN));
FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D rect = fontMetrics.getStringBounds("Abc", g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
// Center text horizontally and vertically.
int x = (width - textWidth) / 2 + 1;
int y = (height - textHeight) / 2 + fontMetrics.getAscent();
g2d.drawString("Abc", x, y);
}
@Override
public int getControlPointCount() {
return 1;
}
@Override
public Point getControlPoint(int index) {
return point;
}
@Override
public boolean isControlPointSticky(int index) {
return false;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
}
@Override
public void setControlPoint(Point point, int index) {
this.point.setLocation(point);
}
@EditableProperty(defaultable = false)
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
@EditableProperty
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
@Override
public String getName() {
return super.getName();
}
@Deprecated
@Override
public Void getValue() {
return null;
}
@Override
public void setValue(Void value) {
}
}
@@ -16,7 +16,6 @@ import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Project Information", author = "Branislav Stojkovic", category = "Misc", description = "Draws a box with general project information", instanceNamePrefix = "BOM", zOrder = IDIYComponent.ABOVE_COMPONENT, stretchable = false)
public class ProjectInformation extends AbstractComponent<Void> {
@@ -32,7 +31,7 @@ public class ProjectInformation extends AbstractComponent<Void> {
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
g2d.setFont(Constants.LABEL_FONT);
g2d.setFont(LABEL_FONT);
g2d.setColor(componentState == ComponentState.DRAGGING
|| componentState == ComponentState.SELECTED ? SELECTION_COLOR : COLOR);
// FontMetrics fontMetrics = g2d.getFontMetrics();
@@ -45,7 +44,7 @@ public class ProjectInformation extends AbstractComponent<Void> {
g2d.fillRect(width / 8, 0, 6 * width / 8, height - 1);
g2d.setColor(Color.black);
g2d.drawRect(width / 8, 0, 6 * width / 8, height - 1);
g2d.setFont(Constants.LABEL_FONT.deriveFont(1f * 9 * width / 32).deriveFont(Font.PLAIN));
g2d.setFont(LABEL_FONT.deriveFont(1f * 9 * width / 32).deriveFont(Font.PLAIN));
FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D rect = fontMetrics.getStringBounds("BOM", g2d);
@@ -17,7 +17,7 @@ public abstract class AbstractPotentiometer extends AbstractComponent<Potentiome
protected Resistance resistance = new Resistance(100d, ResistanceUnit.K);
protected Orientation orientation = Orientation.DEFAULT;
protected Taper taper;
protected Taper taper = Taper.LIN;
@Override
public int getControlPointCount() {
@@ -15,7 +15,7 @@ import org.diylc.core.measures.CapacitanceUnit;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Film Capacitor (axial)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "test", zOrder = IDIYComponent.COMPONENT)
@ComponentDescriptor(name = "Film Capacitor (axial)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "Axial film capacitor, similar to Mallory 150s", zOrder = IDIYComponent.COMPONENT)
public class AxialFilmCapacitor extends AbstractLeadedComponent<Capacitance> {
private static final long serialVersionUID = 1L;
@@ -1,6 +1,7 @@
package org.diylc.components.passive;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Area;
@@ -19,7 +20,7 @@ import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Potentiometer (panel mount)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR", description = "test", zOrder = IDIYComponent.ABOVE_COMPONENT, stretchable = false)
@ComponentDescriptor(name = "Potentiometer (panel mount)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR", description = "Panel mount potentiometer with solder lugs", zOrder = IDIYComponent.ABOVE_COMPONENT, stretchable = false)
public class PotentiometerPanel extends AbstractPotentiometer {
private static final long serialVersionUID = 1L;
@@ -32,8 +33,10 @@ public class PotentiometerPanel extends AbstractPotentiometer {
protected Size bodyDiameter = BODY_DIAMETER;
protected Size spacing = SPACING;
protected Size lugDiameter = LUG_DIAMETER;
protected Color bodyColor = BODY_COLOR;
protected Color borderColor = BORDER_COLOR;
// Array of 7 elements: 3 lug connectors, 1 pot body and 3 lugs
protected Area[] body = null;
public PotentiometerPanel() {
@@ -72,8 +75,8 @@ public class PotentiometerPanel extends AbstractPotentiometer {
body = new Area[7];
// Add lugs.
int lugDiameter = getClosestOdd(LUG_DIAMETER.convertToPixels());
int holeDiameter = getClosestOdd(LUG_DIAMETER.convertToPixels() / 2);
int lugDiameter = getClosestOdd(this.lugDiameter.convertToPixels());
int holeDiameter = getClosestOdd(this.lugDiameter.convertToPixels() / 2);
for (int i = 0; i < 3; i++) {
Area area = new Area(new Ellipse2D.Double(controlPoints[i].x - lugDiameter / 2,
controlPoints[i].y - lugDiameter / 2, lugDiameter, lugDiameter));
@@ -160,16 +163,62 @@ public class PotentiometerPanel extends AbstractPotentiometer {
if (shape != null) {
g2d.setColor(bodyColor);
g2d.fill(shape);
g2d.setColor(borderColor);
g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor);
g2d.draw(shape);
}
}
// Draw caption.
g2d.setFont(LABEL_FONT);
g2d
.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED
: LABEL_COLOR);
FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D bodyRect = getBody()[3].getBounds2D();
Rectangle2D rect = fontMetrics.getStringBounds(getName(), g2d);
int textHeight = (int) rect.getHeight();
int textWidth = (int) rect.getWidth();
int panelHeight = (int) bodyRect.getHeight();
int panelWidth = (int) bodyRect.getWidth();
int x = (panelWidth - textWidth) / 2;
int y = panelHeight / 2 - textHeight + fontMetrics.getAscent();
g2d.drawString(getName(), (int) (bodyRect.getX() + x), (int) (bodyRect.getY() + y));
// Draw value.
rect = fontMetrics.getStringBounds(getValue().toString(), g2d);
textHeight = (int) rect.getHeight();
textWidth = (int) rect.getWidth();
x = (panelWidth - textWidth) / 2;
y = panelHeight / 2 + fontMetrics.getAscent();
g2d.drawString(getValue().toString(), (int) (bodyRect.getX() + x),
(int) (bodyRect.getY() + y));
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
// TODO Auto-generated method stub
int margin = 4 * width / 32;
int spacing = width / 3;
g2d.setColor(BORDER_COLOR);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2 * width / 32));
g2d.drawLine(width / 2 - spacing, height / 2, width / 2 - spacing, height - margin);
g2d.drawLine(width / 2 + spacing, height / 2, width / 2 + spacing, height - margin);
g2d.drawLine(width / 2, height / 2, width / 2, height - margin);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(4 * width / 32));
g2d.drawLine(width / 2 - spacing, height - margin, width / 2 - spacing, height - margin);
g2d.drawLine(width / 2 + spacing, height - margin, width / 2 + spacing, height - margin);
g2d.drawLine(width / 2, height - margin, width / 2, height - margin);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.setColor(BODY_COLOR);
g2d.fillOval(margin, margin / 2, width - 2 * margin, height - 2 * margin);
g2d.setColor(BORDER_COLOR);
g2d.drawOval(margin, margin / 2, width - 2 * margin, height - 2 * margin);
}
@EditableProperty
@@ -192,6 +241,15 @@ public class PotentiometerPanel extends AbstractPotentiometer {
this.bodyDiameter = bodyDiameter;
}
@EditableProperty(name = "Lug size")
public Size getLugDiameter() {
return lugDiameter;
}
public void setLugDiameter(Size lugDiameter) {
this.lugDiameter = lugDiameter;
}
@EditableProperty(name = "Body")
public Color getBodyColor() {
return bodyColor;
@@ -23,6 +23,6 @@ public class PotentiometerValue {
@Override
public String toString() {
return resistance.toString() + taper.toString();
return resistance.toString() + " " + taper.toString();
}
}
@@ -15,7 +15,7 @@ import org.diylc.core.measures.CapacitanceUnit;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Ceramic Capacitor (radial)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "test", zOrder = IDIYComponent.COMPONENT)
@ComponentDescriptor(name = "Ceramic Capacitor (radial)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "Standard radial ceramic capacitor", zOrder = IDIYComponent.COMPONENT)
public class RadialCeramicDiskCapacitor extends AbstractLeadedComponent<Capacitance> {
private static final long serialVersionUID = 1L;
@@ -15,7 +15,7 @@ import org.diylc.core.measures.CapacitanceUnit;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Film Capacitor (radial)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "test", zOrder = IDIYComponent.COMPONENT)
@ComponentDescriptor(name = "Film Capacitor (radial)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "Radial film capacitor, similar to Sprague Orange Drop", zOrder = IDIYComponent.COMPONENT)
public class RadialFilmCapacitor extends AbstractLeadedComponent<Capacitance> {
private static final long serialVersionUID = 1L;
@@ -2,5 +2,11 @@ package org.diylc.components.passive;
public enum Taper {
LINEAR, LOG, REVERSE_LOG, W, S
LIN, LOG, REV_LOG, W, S;
@Override
public String toString() {
return name().substring(0, 1).toUpperCase()
+ name().substring(1).toLowerCase().replace("_", "");
}
}
@@ -23,7 +23,6 @@ import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "DIL IC", author = "Branislav Stojkovic", category = "Semiconductors", instanceNamePrefix = "IC", description = "test", stretchable = false, zOrder = IDIYComponent.COMPONENT)
public class DIL_IC extends AbstractTransparentComponent<String> {
@@ -125,12 +124,12 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
public Point getControlPoint(int index) {
return controlPoints[index];
}
@Override
public boolean isControlPointSticky(int index) {
return true;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
@@ -249,7 +248,7 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.draw(getBody());
// Draw label.
g2d.setFont(Constants.LABEL_FONT);
g2d.setFont(LABEL_FONT);
g2d.setColor(LABEL_COLOR);
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(getName(), g2d);
@@ -30,6 +30,7 @@ public class DiodePlastic extends AbstractLeadedComponent<String> {
public DiodePlastic() {
super();
this.labelColor = LABEL_COLOR;
}
@EditableProperty
@@ -74,11 +75,6 @@ public class DiodePlastic extends AbstractLeadedComponent<String> {
return BORDER_COLOR;
}
@Override
protected Color getLabelColor() {
return LABEL_COLOR;
}
@Override
protected Shape getBodyShape() {
return new Rectangle2D.Double(0f, 0f, getWidth().convertToPixels(),