mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
added capacitor
This commit is contained in:
Binary file not shown.
+6
-1
@@ -31,6 +31,7 @@ public abstract class AbstractLeadedDIYComponent implements IDIYComponent {
|
|||||||
|
|
||||||
public static Color LEAD_COLOR = Color.black;
|
public static Color LEAD_COLOR = Color.black;
|
||||||
public static Color LABEL_COLOR = Color.black;
|
public static Color LABEL_COLOR = Color.black;
|
||||||
|
public static Color LABEL_COLOR_SELECTED = Color.red;
|
||||||
public static Font LABEL_FONT = new Font("Tahoma", Font.BOLD, 11);
|
public static Font LABEL_FONT = new Font("Tahoma", Font.BOLD, 11);
|
||||||
|
|
||||||
protected Size width;
|
protected Size width;
|
||||||
@@ -98,13 +99,17 @@ public abstract class AbstractLeadedDIYComponent implements IDIYComponent {
|
|||||||
(point1.y + point2.y - shapeRect.height) / 2);
|
(point1.y + point2.y - shapeRect.height) / 2);
|
||||||
g2d.rotate(theta, shapeRect.width / 2, shapeRect.height / 2);
|
g2d.rotate(theta, shapeRect.width / 2, shapeRect.height / 2);
|
||||||
// Draw body.
|
// Draw body.
|
||||||
|
if (componentState != ComponentState.DRAGGING) {
|
||||||
g2d.setColor(getBodyColor());
|
g2d.setColor(getBodyColor());
|
||||||
g2d.fill(shape);
|
g2d.fill(shape);
|
||||||
|
}
|
||||||
g2d.setColor(getBorderColor());
|
g2d.setColor(getBorderColor());
|
||||||
g2d.draw(shape);
|
g2d.draw(shape);
|
||||||
// Draw label.
|
// Draw label.
|
||||||
g2d.setFont(LABEL_FONT);
|
g2d.setFont(LABEL_FONT);
|
||||||
g2d.setColor(LABEL_COLOR);
|
g2d
|
||||||
|
.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED
|
||||||
|
: LABEL_COLOR);
|
||||||
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
|
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
|
||||||
java.awt.geom.Rectangle2D textRect = fontMetrics.getStringBounds(getComponentName(), g2d);
|
java.awt.geom.Rectangle2D textRect = fontMetrics.getStringBounds(getComponentName(), g2d);
|
||||||
g2d.drawString(getComponentName(), (int) (shapeRect.width - textRect.getWidth()) / 2,
|
g2d.drawString(getComponentName(), (int) (shapeRect.width - textRect.getWidth()) / 2,
|
||||||
|
|||||||
+71
@@ -0,0 +1,71 @@
|
|||||||
|
package org.diylc.components;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Shape;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
|
||||||
|
import org.diylc.core.annotations.ComponentDescriptor;
|
||||||
|
import org.diylc.core.annotations.ComponentValue;
|
||||||
|
import org.diylc.core.annotations.EditableProperty;
|
||||||
|
import org.diylc.core.measures.Capacitance;
|
||||||
|
import org.diylc.core.measures.CapacitanceUnit;
|
||||||
|
import org.diylc.core.measures.Size;
|
||||||
|
import org.diylc.core.measures.SizeUnit;
|
||||||
|
|
||||||
|
@ComponentDescriptor(name = "Axial Film Capacitor", author = "bancika", category = "Passive", instanceNamePrefix = "C", desciption = "test")
|
||||||
|
public class Capacitor extends AbstractLeadedDIYComponent {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public static Size DEFAULT_WIDTH = new Size(1d / 2, SizeUnit.in);
|
||||||
|
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
|
||||||
|
public static Color BODY_COLOR = Color.decode("#FFE303");
|
||||||
|
public static Color BORDER_COLOR = Color.decode("#B8860B");
|
||||||
|
|
||||||
|
private Capacitance value = new Capacitance(123d, CapacitanceUnit.nF);
|
||||||
|
|
||||||
|
public Capacitor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ComponentValue
|
||||||
|
@EditableProperty
|
||||||
|
public Capacitance getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(Capacitance value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||||
|
g2d.drawString("C", 10, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Size getDefaultHeight() {
|
||||||
|
return DEFAULT_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Size getDefaultWidth() {
|
||||||
|
return DEFAULT_WIDTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Color getBodyColor() {
|
||||||
|
return BODY_COLOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Color getBorderColor() {
|
||||||
|
return BORDER_COLOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Shape getComponentShape() {
|
||||||
|
return new Rectangle2D.Double(0f, 0f, getWidth().convertToPixels(), getHeight()
|
||||||
|
.convertToPixels());
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
-3
@@ -6,6 +6,7 @@ import java.awt.Shape;
|
|||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
|
|
||||||
import org.diylc.core.annotations.ComponentDescriptor;
|
import org.diylc.core.annotations.ComponentDescriptor;
|
||||||
|
import org.diylc.core.annotations.ComponentValue;
|
||||||
import org.diylc.core.annotations.EditableProperty;
|
import org.diylc.core.annotations.EditableProperty;
|
||||||
import org.diylc.core.measures.Resistance;
|
import org.diylc.core.measures.Resistance;
|
||||||
import org.diylc.core.measures.ResistanceUnit;
|
import org.diylc.core.measures.ResistanceUnit;
|
||||||
@@ -22,15 +23,20 @@ public class Resistor extends AbstractLeadedDIYComponent {
|
|||||||
public static Color BODY_COLOR = Color.decode("#82CFFD");
|
public static Color BODY_COLOR = Color.decode("#82CFFD");
|
||||||
public static Color BORDER_COLOR = Color.decode("#5D92B1");
|
public static Color BORDER_COLOR = Color.decode("#5D92B1");
|
||||||
|
|
||||||
private Resistance r = new Resistance(123d, ResistanceUnit.K);
|
private Resistance value = new Resistance(123d, ResistanceUnit.K);
|
||||||
|
|
||||||
public Resistor() {
|
public Resistor() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ComponentValue
|
||||||
@EditableProperty
|
@EditableProperty
|
||||||
public Resistance getR() {
|
public Resistance getValue() {
|
||||||
return r;
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(Resistance value) {
|
||||||
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||||
|
|||||||
+19
-27
@@ -6,6 +6,7 @@ import java.awt.GridBagLayout;
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -23,6 +24,7 @@ import org.diylc.common.EventType;
|
|||||||
import org.diylc.common.IPlugIn;
|
import org.diylc.common.IPlugIn;
|
||||||
import org.diylc.common.IPlugInPort;
|
import org.diylc.common.IPlugInPort;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
|
import org.diylc.presenter.ComparatorFactory;
|
||||||
import org.diylc.presenter.ComponentProcessor;
|
import org.diylc.presenter.ComponentProcessor;
|
||||||
|
|
||||||
import com.diyfever.gui.MemoryBar;
|
import com.diyfever.gui.MemoryBar;
|
||||||
@@ -166,6 +168,8 @@ public class StatusBar extends JPanel implements IPlugIn {
|
|||||||
case AVAILABLE_CTRL_POINTS_CHANGED:
|
case AVAILABLE_CTRL_POINTS_CHANGED:
|
||||||
componentsUnderCursor = new ArrayList<IDIYComponent>(
|
componentsUnderCursor = new ArrayList<IDIYComponent>(
|
||||||
((Map<IDIYComponent, ControlPointWrapper>) params[0]).keySet());
|
((Map<IDIYComponent, ControlPointWrapper>) params[0]).keySet());
|
||||||
|
Collections.sort(componentsUnderCursor, ComparatorFactory.getInstance()
|
||||||
|
.getComponentNameComparator());
|
||||||
refreshStatusText();
|
refreshStatusText();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -176,34 +180,22 @@ public class StatusBar extends JPanel implements IPlugIn {
|
|||||||
if ((componentsUnderCursor == null) || (componentsUnderCursor.isEmpty())) {
|
if ((componentsUnderCursor == null) || (componentsUnderCursor.isEmpty())) {
|
||||||
getStatusLabel().setText("");
|
getStatusLabel().setText("");
|
||||||
} else {
|
} else {
|
||||||
// String formattedNames = "";
|
String formattedNames = "";
|
||||||
// int n = 1;
|
int n = 1;
|
||||||
// for (IDIYComponent component : componentsUnderCursor) {
|
for (IDIYComponent component : componentsUnderCursor) {
|
||||||
// if (n > 1) {
|
if (n > 1) {
|
||||||
// formattedNames += ", ";
|
formattedNames += ", ";
|
||||||
// }
|
|
||||||
// formattedNames +=
|
|
||||||
// ComponentProcessor.getInstance().extractBomName(component);//
|
|
||||||
// +
|
|
||||||
// // " (<b><font color=\"blue\">"
|
|
||||||
// // +
|
|
||||||
// // n++
|
|
||||||
// // +
|
|
||||||
// // "</font></b>)";
|
|
||||||
// }
|
|
||||||
if (componentsUnderCursor.size() == 1) {
|
|
||||||
getStatusLabel().setText(
|
|
||||||
"Drag \""
|
|
||||||
+ ComponentProcessor.getInstance().extractComponentName(
|
|
||||||
componentsUnderCursor.get(0)) + "\"");
|
|
||||||
} else {
|
|
||||||
getStatusLabel().setText(
|
|
||||||
"Hold CTRL key to drag all "
|
|
||||||
+ componentsUnderCursor.size()
|
|
||||||
+ " components under the cursor or drag only \""
|
|
||||||
+ ComponentProcessor.getInstance().extractComponentName(
|
|
||||||
componentsUnderCursor.get(0)) + "\"");
|
|
||||||
}
|
}
|
||||||
|
formattedNames += ComponentProcessor.getInstance().extractComponentName(
|
||||||
|
component);//
|
||||||
|
// +
|
||||||
|
// " (<b><font color=\"blue\">"
|
||||||
|
// +
|
||||||
|
n++;
|
||||||
|
// +
|
||||||
|
// "</font></b>)";
|
||||||
|
}
|
||||||
|
getStatusLabel().setText("Drag " + formattedNames + "");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getStatusLabel().setText(
|
getStatusLabel().setText(
|
||||||
|
|||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
package org.diylc.presenter;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import org.diylc.core.IDIYComponent;
|
||||||
|
|
||||||
|
public class ComparatorFactory {
|
||||||
|
|
||||||
|
private static ComparatorFactory instance;
|
||||||
|
|
||||||
|
private Comparator<IDIYComponent> componentNameComparator;
|
||||||
|
|
||||||
|
public static ComparatorFactory getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new ComparatorFactory();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Comparator<IDIYComponent> getComponentNameComparator() {
|
||||||
|
if (componentNameComparator == null) {
|
||||||
|
componentNameComparator = new Comparator<IDIYComponent>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(IDIYComponent o1, IDIYComponent o2) {
|
||||||
|
String name1 = ComponentProcessor.getInstance().extractComponentName(o1);
|
||||||
|
String name2 = ComponentProcessor.getInstance().extractComponentName(o2);
|
||||||
|
if (name1 == null || name2 == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return name1.compareToIgnoreCase(name2);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return componentNameComparator;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user