mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Triode symbol
This commit is contained in:
+1
-1
@@ -49,7 +49,7 @@ public abstract class AbstractTransistorSymbol extends AbstractComponent<String>
|
||||
}
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
Color finalColor;
|
||||
if (componentState == ComponentState.SELECTED) {
|
||||
if (componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING) {
|
||||
finalColor = SELECTION_COLOR;
|
||||
} else if (outlineMode) {
|
||||
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
|
||||
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
package org.diylc.components.tube;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Shape;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.VerticalAlignment;
|
||||
import org.diylc.components.AbstractComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
public abstract class AbstractTubeSymbol extends AbstractComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Size PIN_SPACING = new Size(0.1d, SizeUnit.in);
|
||||
public static Color COLOR = Color.black;
|
||||
|
||||
protected String value = "";
|
||||
|
||||
protected Color color = COLOR;
|
||||
protected Display display = Display.NAME;
|
||||
transient protected Shape[] body;
|
||||
protected boolean showHeaters;
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState,
|
||||
boolean outlineMode, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
if (checkPointsClipped(g2d.getClip())) {
|
||||
return;
|
||||
}
|
||||
Color finalColor;
|
||||
if (componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING) {
|
||||
finalColor = SELECTION_COLOR;
|
||||
} else if (outlineMode) {
|
||||
Theme theme = (Theme) ConfigurationManager.getInstance()
|
||||
.readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
|
||||
finalColor = theme.getOutlineColor();
|
||||
} else {
|
||||
finalColor = color;
|
||||
}
|
||||
g2d.setColor(finalColor);
|
||||
|
||||
// Draw tube
|
||||
|
||||
Shape[] body = getBody();
|
||||
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
|
||||
g2d.draw(body[0]);
|
||||
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
g2d.draw(body[1]);
|
||||
|
||||
if (body[2] != null) {
|
||||
g2d.draw(body[2]);
|
||||
}
|
||||
|
||||
// Draw label
|
||||
g2d.setFont(LABEL_FONT);
|
||||
Color finalLabelColor;
|
||||
if (outlineMode) {
|
||||
Theme theme = (Theme) ConfigurationManager.getInstance()
|
||||
.readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
|
||||
finalLabelColor = componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||
: theme.getOutlineColor();
|
||||
} else {
|
||||
finalLabelColor = componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||
: LABEL_COLOR;
|
||||
}
|
||||
g2d.setColor(finalLabelColor);
|
||||
Point p = getTextLocation();
|
||||
drawCenteredText(g2d,
|
||||
display == Display.VALUE ? getValue() : getName(), p.x, p.y,
|
||||
HorizontalAlignment.LEFT, VerticalAlignment.TOP);
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
@Override
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Display getDisplay() {
|
||||
return display;
|
||||
}
|
||||
|
||||
public void setDisplay(Display display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Show heaters")
|
||||
public boolean getShowHeaters() {
|
||||
return showHeaters;
|
||||
}
|
||||
|
||||
public void setShowHeaters(boolean showHeaters) {
|
||||
this.showHeaters = showHeaters;
|
||||
// Invalidate body
|
||||
body = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns transistor shape consisting of 3 parts, in this order:
|
||||
* electrodes, connectors, bulb.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract Shape[] getBody();
|
||||
|
||||
protected abstract Point getTextLocation();
|
||||
}
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
package org.diylc.components.tube;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.GeneralPath;
|
||||
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
|
||||
@ComponentDescriptor(name = "Triode Symbol", author = "Branislav Stojkovic", category = "Tubes", instanceNamePrefix = "V", description = "Triode tube section", stretchable = false, zOrder = IDIYComponent.COMPONENT)
|
||||
public class TriodeSymbol extends AbstractTubeSymbol {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected Point[] controlPoints = new Point[] { new Point(0, 0),
|
||||
new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0) };
|
||||
|
||||
public TriodeSymbol() {
|
||||
super();
|
||||
updateControlPoints();
|
||||
}
|
||||
|
||||
public Shape[] getBody() {
|
||||
if (body == null) {
|
||||
body = new Shape[3];
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
|
||||
// electrodes
|
||||
GeneralPath polyline = new GeneralPath();
|
||||
|
||||
// grid
|
||||
polyline.moveTo(x + pinSpacing * 5 / 4, y);
|
||||
polyline.lineTo(x + pinSpacing * 7 / 4, y);
|
||||
polyline.moveTo(x + pinSpacing * 9 / 4, y);
|
||||
polyline.lineTo(x + pinSpacing * 11 / 4, y);
|
||||
polyline.moveTo(x + pinSpacing * 13 / 4, y);
|
||||
polyline.lineTo(x + pinSpacing * 15 / 4, y);
|
||||
polyline.moveTo(x + pinSpacing * 17 / 4, y);
|
||||
polyline.lineTo(x + pinSpacing * 19 / 4, y);
|
||||
|
||||
// plate
|
||||
polyline.moveTo(x + pinSpacing * 3 / 2, y - pinSpacing);
|
||||
polyline.lineTo(x + pinSpacing * 9 / 2, y - pinSpacing);
|
||||
|
||||
// cathode
|
||||
polyline.moveTo(x + pinSpacing * 2, y + pinSpacing);
|
||||
polyline.lineTo(x + pinSpacing * 4, y + pinSpacing);
|
||||
|
||||
body[0] = polyline;
|
||||
|
||||
// connectors
|
||||
polyline = new GeneralPath();
|
||||
|
||||
// grid
|
||||
polyline.moveTo(x, y);
|
||||
polyline.lineTo(x + pinSpacing, y);
|
||||
|
||||
// plate
|
||||
polyline.moveTo(controlPoints[1].x, controlPoints[1].y);
|
||||
polyline.lineTo(x + pinSpacing * 3, y - pinSpacing);
|
||||
|
||||
// cathode
|
||||
polyline.moveTo(controlPoints[2].x, controlPoints[2].y);
|
||||
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing);
|
||||
|
||||
if (showHeaters) {
|
||||
polyline.moveTo(controlPoints[3].x, controlPoints[3].y);
|
||||
polyline.lineTo(controlPoints[3].x, controlPoints[3].y
|
||||
- pinSpacing);
|
||||
polyline.lineTo(controlPoints[3].x + pinSpacing / 2,
|
||||
controlPoints[3].y - 3 * pinSpacing / 2);
|
||||
|
||||
polyline.moveTo(controlPoints[4].x, controlPoints[4].y);
|
||||
polyline.lineTo(controlPoints[4].x, controlPoints[4].y
|
||||
- pinSpacing);
|
||||
polyline.lineTo(controlPoints[4].x - pinSpacing / 2,
|
||||
controlPoints[4].y - 3 * pinSpacing / 2);
|
||||
}
|
||||
|
||||
body[1] = polyline;
|
||||
|
||||
// bulb
|
||||
body[2] = new Ellipse2D.Double(x + pinSpacing / 2, y - pinSpacing
|
||||
* 5 / 2, pinSpacing * 5, pinSpacing * 5);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.setColor(COLOR);
|
||||
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
|
||||
g2d.drawLine(width / 4, height / 4, width * 3 / 4, height / 4);
|
||||
g2d.drawLine(width / 2, height / 4, width / 2, 0);
|
||||
|
||||
g2d.drawLine(width / 4 + 2 * width / 32, height * 3 / 4, width * 3 / 4
|
||||
- 4 * width / 32, height * 3 / 4);
|
||||
g2d.drawLine(width / 4 + 2 * width / 32, height * 3 / 4, width / 4 + 2
|
||||
* width / 32, height - 1);
|
||||
|
||||
g2d.drawOval(1, 1, width - 1 - 2 * width / 32, height - 1 - 2 * width
|
||||
/ 32);
|
||||
|
||||
g2d.drawLine(0, height / 2, width / 8, height / 2);
|
||||
g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_ROUND,
|
||||
BasicStroke.JOIN_BEVEL, 0, new float[] { 3f }, 6f));
|
||||
g2d.drawLine(width / 8, height / 2, width * 7 / 8, height / 2);
|
||||
|
||||
// g2d.drawLine(width * 3 / 4, 1, width * 3 / 4, height / 4);
|
||||
// g2d.drawLine(width / 3, height / 3 + 1, width * 3 / 4, height / 4);
|
||||
//
|
||||
// g2d.drawLine(width * 3 / 4, height - 1, width * 3 / 4, height * 3 /
|
||||
// 4);
|
||||
// g2d.drawLine(width / 3, height * 2 / 3 - 1, width * 3 / 4,
|
||||
// height * 3 / 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return controlPoints[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return controlPoints.length;
|
||||
}
|
||||
|
||||
protected void updateControlPoints() {
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
// Update control points.
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
|
||||
controlPoints[1].x = x + pinSpacing * 3;
|
||||
controlPoints[1].y = y - pinSpacing * 3;
|
||||
|
||||
controlPoints[2].x = x + pinSpacing * 2;
|
||||
controlPoints[2].y = y + pinSpacing * 3;
|
||||
|
||||
controlPoints[3].x = x + pinSpacing * 3;
|
||||
controlPoints[3].y = y + pinSpacing * 3;
|
||||
|
||||
controlPoints[4].x = x + pinSpacing * 4;
|
||||
controlPoints[4].y = y + pinSpacing * 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
controlPoints[index].setLocation(point);
|
||||
// Invalidate body
|
||||
body = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
if (showHeaters) {
|
||||
return VisibilityPolicy.WHEN_SELECTED;
|
||||
} else {
|
||||
return index < 3 ? VisibilityPolicy.WHEN_SELECTED
|
||||
: VisibilityPolicy.NEVER;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
if (showHeaters) {
|
||||
return index < 5;
|
||||
} else {
|
||||
return index < 3;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Point getTextLocation() {
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
return new Point(controlPoints[0].x + pinSpacing * 5,
|
||||
controlPoints[0].y + pinSpacing * 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user