diff --git a/diylc/diylc-core/src/org/diylc/common/DefaultComponentTransformer.java b/diylc/diylc-core/src/org/diylc/common/DefaultComponentTransformer.java new file mode 100644 index 00000000..6fb4e290 --- /dev/null +++ b/diylc/diylc-core/src/org/diylc/common/DefaultComponentTransformer.java @@ -0,0 +1,116 @@ +package org.diylc.common; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; +import java.lang.reflect.InvocationTargetException; +import java.util.List; +import org.apache.log4j.Logger; +import org.diylc.core.Angle; +import org.diylc.core.IDIYComponent; +import org.diylc.presenter.ComponentProcessor; + +public class DefaultComponentTransformer implements IComponentTransformer { + + private static final Logger LOG = Logger.getLogger(DefaultComponentTransformer.class); + + @Override + public boolean canRotate(IDIYComponent component) { + List properties = + ComponentProcessor.getInstance().extractProperties(component.getClass()); + + for (PropertyWrapper property : properties) { + if (property.getType().isAssignableFrom(Orientation.class) + || property.getType().isAssignableFrom(OrientationHV.class) + || property.getType().isAssignableFrom(Angle.class)) + return true; + } + return false; + } + + @Override + public boolean canMirror(IDIYComponent component) { + return false; + } + + @Override + public boolean mirroringChangesCircuit() { + return false; + } + + @Override + public void rotate(IDIYComponent component, Point2D center, int direction) { + boolean canRotate = false; + List properties = + ComponentProcessor.getInstance().extractProperties(component.getClass()); + + for (PropertyWrapper property : properties) { + try { + property.readFrom(component); + } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException + | SecurityException | NoSuchMethodException e) { + LOG.warn("Error while rotating component " + component.getName(), e); + } + + try { + if (property.getType().isAssignableFrom(Orientation.class)) { + canRotate = true; + + Orientation o = (Orientation) property.getValue(); + int oValue = o.ordinal(); + oValue += direction; + if (oValue < 0) + oValue = Orientation.values().length - 1; + if (oValue >= Orientation.values().length) + oValue = 0; + o = Orientation.values()[oValue]; + property.setValue(o); + } + + if (property.getType().isAssignableFrom(OrientationHV.class)) { + canRotate = true; + + OrientationHV o = (OrientationHV) property.getValue(); + int oValue = o.ordinal(); + oValue += direction; + if (oValue < 0) + oValue = OrientationHV.values().length - 1; + if (oValue >= OrientationHV.values().length) + oValue = 0; + o = OrientationHV.values()[oValue]; + property.setValue(o); + } + + if (property.getType().isAssignableFrom(Angle.class)) { + canRotate = true; + + Angle angle = (Angle) property.getValue(); + Angle newAngle = angle.rotate(direction); + property.setValue(newAngle); + } + } catch (Exception e) { + LOG.warn("Error while rotating component " + component.getName(), e); + } + + if (canRotate) { + AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2 * direction, + center.getX(), center.getY()); + for (int index = 0; index < component.getControlPointCount(); index++) { + Point2D p = new Point2D.Double(); + rotate.transform(component.getControlPoint(index), p); + component.setControlPoint(p, index); + } + + try { + property.writeTo(component); + } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException + | SecurityException | NoSuchMethodException e) { + LOG.warn("Error while rotating component " + component.getName(), e); + } + break; + } + } + } + + @Override + public void mirror(IDIYComponent component, Point2D center, int direction) {} +} diff --git a/diylc/diylc-core/src/org/diylc/common/DefaultTransformer.java b/diylc/diylc-core/src/org/diylc/common/DefaultTransformer.java deleted file mode 100644 index 045df00d..00000000 --- a/diylc/diylc-core/src/org/diylc/common/DefaultTransformer.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - - DIY Layout Creator (DIYLC). - Copyright (c) 2009-2018 held jointly by the individual authors. - - This file is part of DIYLC. - - DIYLC is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - DIYLC is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DIYLC. If not, see . - -*/ -package org.diylc.common; - -import java.awt.geom.Point2D; -import org.diylc.core.IDIYComponent; - -public class DefaultTransformer implements IComponentTransformer { - - @Override - public boolean canRotate(IDIYComponent component) { - return false; - } - - @Override - public boolean canMirror(IDIYComponent component) { - return false; - } - - @Override - public boolean mirroringChangesCircuit() { - return false; - } - - @Override - public void rotate(IDIYComponent component, Point2D center, int direction) { - } - - @Override - public void mirror(IDIYComponent component, Point2D center, int direction) { - } - -} diff --git a/diylc/diylc-core/src/org/diylc/core/annotations/ComponentDescriptor.java b/diylc/diylc-core/src/org/diylc/core/annotations/ComponentDescriptor.java index 707c9c24..960c8e93 100644 --- a/diylc/diylc-core/src/org/diylc/core/annotations/ComponentDescriptor.java +++ b/diylc/diylc-core/src/org/diylc/core/annotations/ComponentDescriptor.java @@ -23,7 +23,7 @@ package org.diylc.core.annotations; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.diylc.common.DefaultTransformer; +import org.diylc.common.DefaultComponentTransformer; import org.diylc.common.IComponentTransformer; import org.diylc.core.CreationMethod; import org.diylc.core.IDIYComponent; @@ -94,7 +94,7 @@ public @interface ComponentDescriptor { /** * @return if the component can be rotated and/or mirrored, returns a class of the transformer that can do it */ - Class transformer() default DefaultTransformer.class; + Class transformer() default DefaultComponentTransformer.class; /** * Defines if and how a component should appear in auto-generated project keywords. See diff --git a/diylc/diylc-core/src/org/diylc/presenter/update.xml b/diylc/diylc-core/src/org/diylc/presenter/update.xml index 90776870..ac95f912 100644 --- a/diylc/diylc-core/src/org/diylc/presenter/update.xml +++ b/diylc/diylc-core/src/org/diylc/presenter/update.xml @@ -4349,5 +4349,25 @@ https://github.com/bancika/diy-layout-creator/releases + + + 4 + 37 + 0 + + 2023-03-30 00:00:00.000 CET + + + + NEW_FEATURE + 'Proto Board 780 Holes' added with two variations (sponsored by Pete Olivier) + + + IMPROVEMENT + Ability to rotate (almost) all components using keyboard shortcuts and 'Transform Selection' menu + + + https://github.com/bancika/diy-layout-creator/releases + diff --git a/diylc/diylc-library/src/org/diylc/components/electromechanical/DIPSwitch.java b/diylc/diylc-library/src/org/diylc/components/electromechanical/DIPSwitch.java index 7baa52d8..81fb49f2 100644 --- a/diylc/diylc-library/src/org/diylc/components/electromechanical/DIPSwitch.java +++ b/diylc/diylc-library/src/org/diylc/components/electromechanical/DIPSwitch.java @@ -1,26 +1,23 @@ /* + * + * DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors. + * + * This file is part of DIYLC. + * + * DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * DIYLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with DIYLC. If not, see + * . + * + */ +package org.diylc.components.electromechanical; - DIY Layout Creator (DIYLC). - Copyright (c) 2009-2018 held jointly by the individual authors. - - This file is part of DIYLC. - - DIYLC is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - DIYLC is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DIYLC. If not, see . - -*/ -package org.diylc.components.electromechanical; - import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Composite; @@ -38,7 +35,6 @@ import org.diylc.common.IPlugInPort; import org.diylc.common.ObjectCache; import org.diylc.common.Orientation; import org.diylc.components.AbstractTransparentComponent; -import org.diylc.components.transform.DIL_ICTransformer; import org.diylc.core.ComponentState; import org.diylc.core.IDIYComponent; import org.diylc.core.IDrawingObserver; @@ -53,467 +49,497 @@ import org.diylc.core.annotations.PositiveNonZeroMeasureValidator; import org.diylc.core.measures.Size; import org.diylc.core.measures.SizeUnit; import org.diylc.utils.Constants; - -@ComponentDescriptor(name = "DIP Switch", author = "Branislav Stojkovic", category = "Electro-Mechanical", - instanceNamePrefix = "SW", description = "Dual-in-line package switch", - zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class, - enableCache = true) -public class DIPSwitch extends AbstractTransparentComponent implements ISwitch { - - private static final long serialVersionUID = 1L; - - public static Color BODY_COLOR = Color.decode("#E84E46"); - public static Color BORDER_COLOR = BODY_COLOR.darker(); - public static Color PIN_COLOR = Color.decode("#00B2EE"); - public static Color PIN_BORDER_COLOR = PIN_COLOR.darker(); - public static Color TICK_COLOR = Color.white; - public static Color LABEL_COLOR = Color.white; - public static int EDGE_RADIUS = 2; + +@ComponentDescriptor(name = "DIP Switch", author = "Branislav Stojkovic", + category = "Electro-Mechanical", instanceNamePrefix = "SW", + description = "Dual-in-line package switch", zOrder = IDIYComponent.COMPONENT, + keywordPolicy = KeywordPolicy.SHOW_VALUE, enableCache = true) +public class DIPSwitch extends AbstractTransparentComponent implements ISwitch { + + private static final long serialVersionUID = 1L; + + public static Color BODY_COLOR = Color.decode("#E84E46"); + public static Color BORDER_COLOR = BODY_COLOR.darker(); + public static Color PIN_COLOR = Color.decode("#00B2EE"); + public static Color PIN_BORDER_COLOR = PIN_COLOR.darker(); + public static Color TICK_COLOR = Color.white; + public static Color LABEL_COLOR = Color.white; + public static int EDGE_RADIUS = 2; public static Size PIN_SIZE = new Size(0.04d, SizeUnit.in); - public static Size DEFAULT_WIDTH = new Size(0.4d, SizeUnit.in); - public static Size INDENT_SIZE = new Size(0.07d, SizeUnit.in); - - private String value = ""; - private Orientation orientation = Orientation.DEFAULT; - private SwitchCount switchCount = SwitchCount._8; - private Size pinSpacing = new Size(0.1d, SizeUnit.in); - private Size rowSpacing = new Size(0.3d, SizeUnit.in); - private Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0)}; - protected Display display = Display.NONE; - private Color bodyColor = BODY_COLOR; - private Color borderColor = BORDER_COLOR; - private Color labelColor = LABEL_COLOR; + public static Size DEFAULT_WIDTH = new Size(0.4d, SizeUnit.in); + public static Size INDENT_SIZE = new Size(0.07d, SizeUnit.in); + + private String value = ""; + private Orientation orientation = Orientation.DEFAULT; + private SwitchCount switchCount = SwitchCount._8; + private Size pinSpacing = new Size(0.1d, SizeUnit.in); + private Size rowSpacing = new Size(0.3d, SizeUnit.in); + private Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0)}; + protected Display display = Display.NONE; + private Color bodyColor = BODY_COLOR; + private Color borderColor = BORDER_COLOR; + private Color labelColor = LABEL_COLOR; private Color tickColor = TICK_COLOR; - private Size width = DEFAULT_WIDTH; - // new Point(0, pinSpacing.convertToPixels()), - // new Point(0, 2 * pinSpacing.convertToPixels()), - // new Point(0, 3 * pinSpacing.convertToPixels()), - // new Point(3 * pinSpacing.convertToPixels(), 0), - // new Point(3 * pinSpacing.convertToPixels(), - // pinSpacing.convertToPixels()), - // new Point(3 * pinSpacing.convertToPixels(), 2 * - // pinSpacing.convertToPixels()), - // new Point(3 * pinSpacing.convertToPixels(), 3 * - // pinSpacing.convertToPixels()) }; - transient private Area[] body; - - public DIPSwitch() { - super(); + private Size width = DEFAULT_WIDTH; + // new Point(0, pinSpacing.convertToPixels()), + // new Point(0, 2 * pinSpacing.convertToPixels()), + // new Point(0, 3 * pinSpacing.convertToPixels()), + // new Point(3 * pinSpacing.convertToPixels(), 0), + // new Point(3 * pinSpacing.convertToPixels(), + // pinSpacing.convertToPixels()), + // new Point(3 * pinSpacing.convertToPixels(), 2 * + // pinSpacing.convertToPixels()), + // new Point(3 * pinSpacing.convertToPixels(), 3 * + // pinSpacing.convertToPixels()) }; + transient private Area[] body; + + public DIPSwitch() { + super(); updateControlPoints(); - alpha = (byte) 100; - } - - @EditableProperty - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - @EditableProperty - public Orientation getOrientation() { - return orientation; - } - - public void setOrientation(Orientation orientation) { - this.orientation = orientation; - updateControlPoints(); - // Reset body shape. - body = null; - } - - @EditableProperty(name = "Switches") - public SwitchCount getSwitchCount() { - return switchCount; - } - - public void setSwitchCount(SwitchCount switchCount) { - this.switchCount = switchCount; - updateControlPoints(); - // Reset body shape; - body = null; - } - - @EditableProperty(name = "Pin Spacing", validatorClass = PositiveNonZeroMeasureValidator.class) - public Size getPinSpacing() { - return pinSpacing; - } - - public void setPinSpacing(Size pinSpacing) { - this.pinSpacing = pinSpacing; - updateControlPoints(); - // Reset body shape; - body = null; - } - - @EditableProperty(name = "Row Spacing", validatorClass = PositiveNonZeroMeasureValidator.class) - public Size getRowSpacing() { - return rowSpacing; - } - - public void setRowSpacing(Size rowSpacing) { - this.rowSpacing = rowSpacing; - updateControlPoints(); - // Reset body shape; - body = null; - } - - @EditableProperty - public Display getDisplay() { - if (display == null) { - display = Display.VALUE; - } - return display; - } - - public void setDisplay(Display display) { - this.display = display; - } - - @Override - public int getControlPointCount() { - return controlPoints.length; - } - - @Override - public Point2D getControlPoint(int index) { - return controlPoints[index]; - } - - @Override - public boolean isControlPointSticky(int index) { - return true; - } - - @Override - public VisibilityPolicy getControlPointVisibilityPolicy(int index) { - return VisibilityPolicy.NEVER; - } - - @Override - public void setControlPoint(Point2D point, int index) { - controlPoints[index].setLocation(point); - body = null; - } - - private void updateControlPoints() { - Point2D firstPoint = controlPoints[0]; - controlPoints = new Point2D[switchCount.getValue() * 2]; - controlPoints[0] = firstPoint; - double pinSpacing = this.pinSpacing.convertToPixels(); - double rowSpacing = this.rowSpacing.convertToPixels(); - // Update control points. - double dx1; - double dy1; - double dx2; - double dy2; - for (int i = 0; i < switchCount.getValue(); i++) { - switch (orientation) { - case DEFAULT: - dx1 = 0; - dy1 = i * pinSpacing; - dx2 = rowSpacing; - dy2 = i * pinSpacing; - break; - case _90: - dx1 = -i * pinSpacing; - dy1 = 0; - dx2 = -i * pinSpacing; - dy2 = rowSpacing; - break; - case _180: - dx1 = 0; - dy1 = -i * pinSpacing; - dx2 = -rowSpacing; - dy2 = -i * pinSpacing; - break; - case _270: - dx1 = i * pinSpacing; - dy1 = 0; - dx2 = i * pinSpacing; - dy2 = -rowSpacing; - break; - default: - throw new RuntimeException("Unexpected orientation: " + orientation); - } - controlPoints[i] = new Point2D.Double(firstPoint.getX() + dx1, firstPoint.getY() + dy1); - controlPoints[i + switchCount.getValue()] = new Point2D.Double(firstPoint.getX() + dx2, firstPoint.getY() + dy2); - } - } - - public Area[] getBody() { - if (body == null) { - body = new Area[3]; - double x = controlPoints[0].getX(); - double y = controlPoints[0].getY(); - double width; - double height; - double pinSpacing = this.pinSpacing.convertToPixels(); - double rowSpacing = this.rowSpacing.convertToPixels(); + alpha = (byte) 100; + } + + @EditableProperty + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @EditableProperty + public Orientation getOrientation() { + return orientation; + } + + public void setOrientation(Orientation orientation) { + this.orientation = orientation; + updateControlPoints(); + // Reset body shape. + body = null; + } + + @EditableProperty(name = "Switches") + public SwitchCount getSwitchCount() { + return switchCount; + } + + public void setSwitchCount(SwitchCount switchCount) { + this.switchCount = switchCount; + updateControlPoints(); + // Reset body shape; + body = null; + } + + @EditableProperty(name = "Pin Spacing", validatorClass = PositiveNonZeroMeasureValidator.class) + public Size getPinSpacing() { + return pinSpacing; + } + + public void setPinSpacing(Size pinSpacing) { + this.pinSpacing = pinSpacing; + updateControlPoints(); + // Reset body shape; + body = null; + } + + @EditableProperty(name = "Row Spacing", validatorClass = PositiveNonZeroMeasureValidator.class) + public Size getRowSpacing() { + return rowSpacing; + } + + public void setRowSpacing(Size rowSpacing) { + this.rowSpacing = rowSpacing; + updateControlPoints(); + // Reset body shape; + body = null; + } + + @EditableProperty + public Display getDisplay() { + if (display == null) { + display = Display.VALUE; + } + return display; + } + + public void setDisplay(Display display) { + this.display = display; + } + + @Override + public int getControlPointCount() { + return controlPoints.length; + } + + @Override + public Point2D getControlPoint(int index) { + return controlPoints[index]; + } + + @Override + public boolean isControlPointSticky(int index) { + return true; + } + + @Override + public VisibilityPolicy getControlPointVisibilityPolicy(int index) { + return VisibilityPolicy.NEVER; + } + + @Override + public void setControlPoint(Point2D point, int index) { + controlPoints[index].setLocation(point); + body = null; + } + + private void updateControlPoints() { + Point2D firstPoint = controlPoints[0]; + controlPoints = new Point2D[switchCount.getValue() * 2]; + controlPoints[0] = firstPoint; + double pinSpacing = this.pinSpacing.convertToPixels(); + double rowSpacing = this.rowSpacing.convertToPixels(); + // Update control points. + double dx1; + double dy1; + double dx2; + double dy2; + for (int i = 0; i < switchCount.getValue(); i++) { + switch (orientation) { + case DEFAULT: + dx1 = 0; + dy1 = i * pinSpacing; + dx2 = rowSpacing; + dy2 = i * pinSpacing; + break; + case _90: + dx1 = -i * pinSpacing; + dy1 = 0; + dx2 = -i * pinSpacing; + dy2 = rowSpacing; + break; + case _180: + dx1 = 0; + dy1 = -i * pinSpacing; + dx2 = -rowSpacing; + dy2 = -i * pinSpacing; + break; + case _270: + dx1 = i * pinSpacing; + dy1 = 0; + dx2 = i * pinSpacing; + dy2 = -rowSpacing; + break; + default: + throw new RuntimeException("Unexpected orientation: " + orientation); + } + controlPoints[i] = new Point2D.Double(firstPoint.getX() + dx1, firstPoint.getY() + dy1); + controlPoints[i + switchCount.getValue()] = + new Point2D.Double(firstPoint.getX() + dx2, firstPoint.getY() + dy2); + } + } + + public Area[] getBody() { + if (body == null) { + body = new Area[3]; + double x = controlPoints[0].getX(); + double y = controlPoints[0].getY(); + double width; + double height; + double pinSpacing = this.pinSpacing.convertToPixels(); + double rowSpacing = this.rowSpacing.convertToPixels(); double bodyWidth = getClosestOdd(getWidth().convertToPixels()); double tickHoleLength = rowSpacing * 2 / 3; double tickSize = PIN_SIZE.convertToPixels(); Area tickArea = new Area(); - Area tickHoleArea = new Area(); - switch (orientation) { - case DEFAULT: - width = bodyWidth; - height = switchCount.getValue() * pinSpacing; - x -= (bodyWidth - rowSpacing) / 2; + Area tickHoleArea = new Area(); + switch (orientation) { + case DEFAULT: + width = bodyWidth; + height = switchCount.getValue() * pinSpacing; + x -= (bodyWidth - rowSpacing) / 2; y -= pinSpacing / 2; for (int i = 0; i < getSwitchCount().getValue(); i++) { - tickHoleArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() + (rowSpacing - tickHoleLength) / 2, controlPoints[i].getY() - tickSize / 2, tickHoleLength, tickSize))); - tickArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() + (rowSpacing - tickHoleLength) / 2, controlPoints[i].getY() - tickSize / 2, tickSize, tickSize))); - } - break; - case _90: - width = switchCount.getValue() * pinSpacing; - height = bodyWidth; - x -= (pinSpacing / 2) + width - pinSpacing; + tickHoleArea.add(new Area( + new Rectangle2D.Double(controlPoints[i].getX() + (rowSpacing - tickHoleLength) / 2, + controlPoints[i].getY() - tickSize / 2, tickHoleLength, tickSize))); + tickArea.add(new Area( + new Rectangle2D.Double(controlPoints[i].getX() + (rowSpacing - tickHoleLength) / 2, + controlPoints[i].getY() - tickSize / 2, tickSize, tickSize))); + } + break; + case _90: + width = switchCount.getValue() * pinSpacing; + height = bodyWidth; + x -= (pinSpacing / 2) + width - pinSpacing; y -= (bodyWidth - rowSpacing) / 2; for (int i = 0; i < getSwitchCount().getValue(); i++) { - tickHoleArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() - tickSize / 2, controlPoints[i].getY() + (rowSpacing - tickHoleLength) / 2, tickSize, tickHoleLength))); - tickArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() - tickSize / 2, controlPoints[i].getY() + (rowSpacing - tickHoleLength) / 2, tickSize, tickSize))); - } - break; - case _180: - width = bodyWidth; - height = switchCount.getValue() * pinSpacing; - x -= rowSpacing + (bodyWidth - rowSpacing) / 2; + tickHoleArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() - tickSize / 2, + controlPoints[i].getY() + (rowSpacing - tickHoleLength) / 2, tickSize, + tickHoleLength))); + tickArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() - tickSize / 2, + controlPoints[i].getY() + (rowSpacing - tickHoleLength) / 2, tickSize, tickSize))); + } + break; + case _180: + width = bodyWidth; + height = switchCount.getValue() * pinSpacing; + x -= rowSpacing + (bodyWidth - rowSpacing) / 2; y -= (pinSpacing / 2) + height - pinSpacing; for (int i = getSwitchCount().getValue(); i < controlPoints.length; i++) { - tickHoleArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() + (rowSpacing - tickHoleLength) / 2, controlPoints[i].getY() - tickSize / 2, tickHoleLength, tickSize))); - tickArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() + (rowSpacing + tickHoleLength) / 2 - tickSize, controlPoints[i].getY() - tickSize / 2, tickSize, tickSize))); - } - break; - case _270: - width = (switchCount.getValue()) * pinSpacing; - height = bodyWidth; - x -= pinSpacing / 2; + tickHoleArea.add(new Area( + new Rectangle2D.Double(controlPoints[i].getX() + (rowSpacing - tickHoleLength) / 2, + controlPoints[i].getY() - tickSize / 2, tickHoleLength, tickSize))); + tickArea.add(new Area(new Rectangle2D.Double( + controlPoints[i].getX() + (rowSpacing + tickHoleLength) / 2 - tickSize, + controlPoints[i].getY() - tickSize / 2, tickSize, tickSize))); + } + break; + case _270: + width = (switchCount.getValue()) * pinSpacing; + height = bodyWidth; + x -= pinSpacing / 2; y -= rowSpacing + (bodyWidth - rowSpacing) / 2; for (int i = getSwitchCount().getValue(); i < controlPoints.length; i++) { - tickHoleArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() - tickSize / 2, controlPoints[i].getY() + (rowSpacing - tickHoleLength) / 2, tickSize, tickHoleLength))); - tickArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() - tickSize / 2, controlPoints[i].getY() + (rowSpacing - tickHoleLength) / 2 + tickHoleLength - tickSize, tickSize, tickSize))); - } - break; - default: - throw new RuntimeException("Unexpected orientation: " + orientation); - } - body[0] = new Area(new RoundRectangle2D.Double(x, y, width, height, EDGE_RADIUS, EDGE_RADIUS)); + tickHoleArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() - tickSize / 2, + controlPoints[i].getY() + (rowSpacing - tickHoleLength) / 2, tickSize, + tickHoleLength))); + tickArea.add(new Area(new Rectangle2D.Double( + controlPoints[i].getX() - tickSize / 2, controlPoints[i].getY() + + (rowSpacing - tickHoleLength) / 2 + tickHoleLength - tickSize, + tickSize, tickSize))); + } + break; + default: + throw new RuntimeException("Unexpected orientation: " + orientation); + } + body[0] = + new Area(new RoundRectangle2D.Double(x, y, width, height, EDGE_RADIUS, EDGE_RADIUS)); body[1] = tickHoleArea; - body[2] = tickArea; - } - return body; - } - - @Override - public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project, - IDrawingObserver drawingObserver) { - if (checkPointsClipped(g2d.getClip())) { - return; + body[2] = tickArea; } - g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); - Area mainArea = getBody()[0]; - if (!outlineMode) { - int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2; - for (Point2D point : controlPoints) { + return body; + } + + @Override + public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, + Project project, IDrawingObserver drawingObserver) { + if (checkPointsClipped(g2d.getClip())) { + return; + } + g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); + Area mainArea = getBody()[0]; + if (!outlineMode) { + int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2; + for (Point2D point : controlPoints) { g2d.setColor(PIN_COLOR); - int pinWidth = getClosestOdd(pinSize / (getOrientation() == Orientation.DEFAULT || getOrientation() == Orientation._180 ? 2f : 1f)); - int pinHeight = getClosestOdd(pinSize / (getOrientation() == Orientation.DEFAULT || getOrientation() == Orientation._180 ? 1f : 2f)); - g2d.fillRect((int)(point.getX() - pinWidth / 2), (int)(point.getY() - pinHeight / 2), pinWidth, pinHeight); - g2d.setColor(PIN_BORDER_COLOR); - g2d.drawRect((int)(point.getX() - pinWidth / 2), (int)(point.getY() - pinHeight / 2), pinWidth, pinHeight); - } - } - Composite oldComposite = g2d.getComposite(); - if (alpha < MAX_ALPHA) { - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA)); - } - g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : getBodyColor()); - g2d.fill(mainArea); - g2d.setComposite(oldComposite); - - Color finalBorderColor; - if (outlineMode) { - Theme theme = - (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); - finalBorderColor = - componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR - : theme.getOutlineColor(); - } else { - finalBorderColor = - componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR - : getBorderColor(); - } - g2d.setColor(finalBorderColor); - g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); - if (outlineMode) { - Area area = new Area(mainArea); - area.subtract(getBody()[1]); + int pinWidth = getClosestOdd(pinSize + / (getOrientation() == Orientation.DEFAULT || getOrientation() == Orientation._180 ? 2f + : 1f)); + int pinHeight = getClosestOdd(pinSize + / (getOrientation() == Orientation.DEFAULT || getOrientation() == Orientation._180 ? 1f + : 2f)); + g2d.fillRect((int) (point.getX() - pinWidth / 2), (int) (point.getY() - pinHeight / 2), + pinWidth, pinHeight); + g2d.setColor(PIN_BORDER_COLOR); + g2d.drawRect((int) (point.getX() - pinWidth / 2), (int) (point.getY() - pinHeight / 2), + pinWidth, pinHeight); + } + } + Composite oldComposite = g2d.getComposite(); + if (alpha < MAX_ALPHA) { + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA)); + } + g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : getBodyColor()); + g2d.fill(mainArea); + g2d.setComposite(oldComposite); + + Color finalBorderColor; + if (outlineMode) { + Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, + Constants.DEFAULT_THEME); + finalBorderColor = + componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING + ? SELECTION_COLOR + : theme.getOutlineColor(); + } else { + finalBorderColor = + componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING + ? SELECTION_COLOR + : getBorderColor(); + } + g2d.setColor(finalBorderColor); + g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); + if (outlineMode) { + Area area = new Area(mainArea); + area.subtract(getBody()[1]); g2d.draw(area); if (getBody()[1] != null) g2d.draw(getBody()[1]); if (getBody()[2] != null) - g2d.draw(getBody()[2]); - } else { - g2d.draw(mainArea); - if (getBody()[1] != null) { - g2d.setColor(getTickColor().darker()); - g2d.fill(getBody()[1]); + g2d.draw(getBody()[2]); + } else { + g2d.draw(mainArea); + if (getBody()[1] != null) { + g2d.setColor(getTickColor().darker()); + g2d.fill(getBody()[1]); } if (getBody()[2] != null) { g2d.setColor(getTickColor()); g2d.fill(getBody()[2]); - } - } - - drawingObserver.stopTracking(); - - // Draw label. - g2d.setFont(project.getFont()); - 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 - : getLabelColor(); - } - g2d.setColor(finalLabelColor); - FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont()); - String[] label = null; - - if (getDisplay() == Display.NAME) { - label = new String[] {getName()}; - } else if (getDisplay() == Display.VALUE) { - label = new String[] {getValue().toString()}; - } else if (getDisplay() == Display.BOTH) { - String value = getValue().toString(); - label = value.isEmpty() ? new String[] {getName()} : new String[] {getName(), value}; - } - - if (label != null) { - for (int i = 0; i < label.length; i++) { - String l = label[i]; - Rectangle2D rect = fontMetrics.getStringBounds(l, g2d); - int textHeight = (int) (rect.getHeight()); - int textWidth = (int) (rect.getWidth()); - // Center text horizontally and vertically - Rectangle bounds = mainArea.getBounds(); - double x = bounds.getX() + (bounds.width - textWidth) / 2; - double y = bounds.getY() + (bounds.height - textHeight) / 2 + fontMetrics.getAscent(); - - AffineTransform oldTransform = g2d.getTransform(); - - if (getOrientation() == Orientation.DEFAULT || getOrientation() == Orientation._180) { - double centerX = bounds.getX() + bounds.width / 2; - double centerY = bounds.getY() + bounds.height / 2; - g2d.rotate(-Math.PI / 2, centerX, centerY); - } - - if (label.length == 2) { - if (i == 0) - g2d.translate(0, -textHeight / 2); - else if (i == 1) - g2d.translate(0, textHeight / 2); - } - - g2d.drawString(l, (int)x, (int)y); - - g2d.setTransform(oldTransform); - } - } - } - - @Override - public void drawIcon(Graphics2D g2d, int width, int height) { - g2d.setColor(BODY_COLOR); - g2d.fillRect(width / 6, 1, 4 * width / 6, height - 4); - g2d.setColor(BORDER_COLOR); - g2d.drawRect(width / 6, 1, 4 * width / 6, height - 4); + } + } + + drawingObserver.stopTracking(); + + // Draw label. + g2d.setFont(project.getFont()); + 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 + : getLabelColor(); + } + g2d.setColor(finalLabelColor); + FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont()); + String[] label = null; + + if (getDisplay() == Display.NAME) { + label = new String[] {getName()}; + } else if (getDisplay() == Display.VALUE) { + label = new String[] {getValue().toString()}; + } else if (getDisplay() == Display.BOTH) { + String value = getValue().toString(); + label = value.isEmpty() ? new String[] {getName()} : new String[] {getName(), value}; + } + + if (label != null) { + for (int i = 0; i < label.length; i++) { + String l = label[i]; + Rectangle2D rect = fontMetrics.getStringBounds(l, g2d); + int textHeight = (int) (rect.getHeight()); + int textWidth = (int) (rect.getWidth()); + // Center text horizontally and vertically + Rectangle bounds = mainArea.getBounds(); + double x = bounds.getX() + (bounds.width - textWidth) / 2; + double y = bounds.getY() + (bounds.height - textHeight) / 2 + fontMetrics.getAscent(); + + AffineTransform oldTransform = g2d.getTransform(); + + if (getOrientation() == Orientation.DEFAULT || getOrientation() == Orientation._180) { + double centerX = bounds.getX() + bounds.width / 2; + double centerY = bounds.getY() + bounds.height / 2; + g2d.rotate(-Math.PI / 2, centerX, centerY); + } + + if (label.length == 2) { + if (i == 0) + g2d.translate(0, -textHeight / 2); + else if (i == 1) + g2d.translate(0, textHeight / 2); + } + + g2d.drawString(l, (int) x, (int) y); + + g2d.setTransform(oldTransform); + } + } + } + + @Override + public void drawIcon(Graphics2D g2d, int width, int height) { + g2d.setColor(BODY_COLOR); + g2d.fillRect(width / 6, 1, 4 * width / 6, height - 4); + g2d.setColor(BORDER_COLOR); + g2d.drawRect(width / 6, 1, 4 * width / 6, height - 4); int tickSize = (int) (2f * width / 32); - int tickHoleLength = (int) (width * 0.4); + int tickHoleLength = (int) (width * 0.4); for (int i = 0; i < 4; i++) { - g2d.setColor(TICK_COLOR.darker()); - g2d.fillRect((width - tickHoleLength) / 2, (height / 5) * (i + 1) - tickSize / 2, tickHoleLength, tickSize); + g2d.setColor(TICK_COLOR.darker()); + g2d.fillRect((width - tickHoleLength) / 2, (height / 5) * (i + 1) - tickSize / 2, + tickHoleLength, tickSize); g2d.setColor(TICK_COLOR); - g2d.fillRect((width - tickHoleLength) / 2, (height / 5) * (i + 1) - tickSize / 2, tickSize, tickSize); - } - } - - @EditableProperty(name = "Body") - public Color getBodyColor() { - if (bodyColor == null) { - bodyColor = BODY_COLOR; - } - return bodyColor; - } - - public void setBodyColor(Color bodyColor) { - this.bodyColor = bodyColor; - } - - @EditableProperty(name = "Border") - public Color getBorderColor() { - if (borderColor == null) { - borderColor = BORDER_COLOR; - } - return borderColor; - } - - public void setBorderColor(Color borderColor) { - this.borderColor = borderColor; - } - - @EditableProperty(name = "Label") - public Color getLabelColor() { - if (labelColor == null) { - labelColor = LABEL_COLOR; - } - return labelColor; - } - - public void setLabelColor(Color labelColor) { - this.labelColor = labelColor; - } - - @EditableProperty(name = "Tick") + g2d.fillRect((width - tickHoleLength) / 2, (height / 5) * (i + 1) - tickSize / 2, tickSize, + tickSize); + } + } + + @EditableProperty(name = "Body") + public Color getBodyColor() { + if (bodyColor == null) { + bodyColor = BODY_COLOR; + } + return bodyColor; + } + + public void setBodyColor(Color bodyColor) { + this.bodyColor = bodyColor; + } + + @EditableProperty(name = "Border") + public Color getBorderColor() { + if (borderColor == null) { + borderColor = BORDER_COLOR; + } + return borderColor; + } + + public void setBorderColor(Color borderColor) { + this.borderColor = borderColor; + } + + @EditableProperty(name = "Label") + public Color getLabelColor() { + if (labelColor == null) { + labelColor = LABEL_COLOR; + } + return labelColor; + } + + public void setLabelColor(Color labelColor) { + this.labelColor = labelColor; + } + + @EditableProperty(name = "Tick") public Color getTickColor() { return tickColor; } - + public void setTickColor(Color tickColor) { this.tickColor = tickColor; } - + @EditableProperty(validatorClass = PositiveNonZeroMeasureValidator.class) public Size getWidth() { return width; } - + public void setWidth(Size width) { this.width = width; body = null; - } - - public static enum SwitchCount { - - _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12; - - @Override - public String toString() { - return name().replace("_", ""); - } - - public int getValue() { - return Integer.parseInt(toString()); - } + } + + public static enum SwitchCount { + + _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12; + + @Override + public String toString() { + return name().replace("_", ""); + } + + public int getValue() { + return Integer.parseInt(toString()); + } } @Override @@ -529,36 +555,38 @@ public class DIPSwitch extends AbstractTransparentComponent implements I if (sb.length() > 0) sb.append("-"); sb.append(binary.charAt(i) == '0' ? "OFF" : "ON"); - } + } return sb.toString(); } @Override public boolean arePointsConnected(int index1, int index2, int position) { String binary = toBinary(position); - return Math.abs(index1 - index2) == getSwitchCount().getValue() && binary.charAt(index1 < index2 ? index1 : index2) == '1'; + return Math.abs(index1 - index2) == getSwitchCount().getValue() + && binary.charAt(index1 < index2 ? index1 : index2) == '1'; } - + @Override public boolean canPointMoveFreely(int pointIndex) { return false; } - + @Override public Rectangle2D getCachingBounds() { int margin = 20; Rectangle2D bounds = getBody()[0].getBounds2D(); - return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin); + return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, + bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin); } - + private String toBinary(int n) { StringBuilder builder = new StringBuilder(); do { - builder.append(n % 2); - n = n / 2; + builder.append(n % 2); + n = n / 2; } while (n > 0); while (builder.length() < getSwitchCount().getValue()) builder.append("0"); return builder.toString(); - } -} + } +} diff --git a/diylc/diylc-library/src/org/diylc/components/electromechanical/TactileMicroSwitch.java b/diylc/diylc-library/src/org/diylc/components/electromechanical/TactileMicroSwitch.java index 51d80c68..9826de61 100644 --- a/diylc/diylc-library/src/org/diylc/components/electromechanical/TactileMicroSwitch.java +++ b/diylc/diylc-library/src/org/diylc/components/electromechanical/TactileMicroSwitch.java @@ -1,26 +1,23 @@ /* + * + * DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors. + * + * This file is part of DIYLC. + * + * DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * DIYLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with DIYLC. If not, see + * . + * + */ +package org.diylc.components.electromechanical; - DIY Layout Creator (DIYLC). - Copyright (c) 2009-2018 held jointly by the individual authors. - - This file is part of DIYLC. - - DIYLC is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - DIYLC is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DIYLC. If not, see . - -*/ -package org.diylc.components.electromechanical; - import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Composite; @@ -50,343 +47,350 @@ import org.diylc.core.annotations.KeywordPolicy; import org.diylc.core.measures.Size; import org.diylc.core.measures.SizeUnit; import org.diylc.utils.Constants; - -@ComponentDescriptor(name = "Tactile Micro-Switch", author = "Branislav Stojkovic", category = "Electro-Mechanical", - instanceNamePrefix = "SW", description = "4-pin tactile momentary switch", - zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class, - enableCache = true) -public class TactileMicroSwitch extends AbstractLabeledComponent { - - private static final long serialVersionUID = 1L; - - public static Color BODY_COLOR = Color.lightGray; - public static Color BORDER_COLOR = Color.gray.darker(); - public static Color PIN_COLOR = METAL_COLOR; - public static Color PIN_BORDER_COLOR = PIN_COLOR.darker(); - public static Color INDENT_COLOR = Color.gray.darker(); - public static Color LABEL_COLOR = Color.white; + +@ComponentDescriptor(name = "Tactile Micro-Switch", author = "Branislav Stojkovic", + category = "Electro-Mechanical", instanceNamePrefix = "SW", + description = "4-pin tactile momentary switch", zOrder = IDIYComponent.COMPONENT, + keywordPolicy = KeywordPolicy.SHOW_VALUE, enableCache = true) +public class TactileMicroSwitch extends AbstractLabeledComponent { + + private static final long serialVersionUID = 1L; + + public static Color BODY_COLOR = Color.lightGray; + public static Color BORDER_COLOR = Color.gray.darker(); + public static Color PIN_COLOR = METAL_COLOR; + public static Color PIN_BORDER_COLOR = PIN_COLOR.darker(); + public static Color INDENT_COLOR = Color.gray.darker(); + public static Color LABEL_COLOR = Color.white; public static Size PIN_SIZE = new Size(0.04d, SizeUnit.in); public static int PIN_COUNT = 4; public static Size CASE_SIZE = new Size(6d, SizeUnit.mm); public static Size INDENT_SIZE = new Size(3d, SizeUnit.mm); private static Size PIN_SPACING = new Size(4.5d, SizeUnit.mm); - private static Size ROW_SPACING = new Size(6.5d, SizeUnit.mm); - - private String value = ""; - private Orientation orientation = Orientation.DEFAULT; - - private Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0)}; - protected Display display = Display.BOTH; - private Color bodyColor = BODY_COLOR; - private Color borderColor = BORDER_COLOR; - private Color labelColor = LABEL_COLOR; - transient private Area[] body; - - public TactileMicroSwitch() { - super(); - updateControlPoints(); - } - - @EditableProperty - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - @EditableProperty - public Orientation getOrientation() { - return orientation; - } - - public void setOrientation(Orientation orientation) { - this.orientation = orientation; - updateControlPoints(); - // Reset body shape. - body = null; - } - - @EditableProperty - public Display getDisplay() { - if (display == null) { - display = Display.VALUE; - } - return display; - } - - public void setDisplay(Display display) { - this.display = display; - } - - @Override - public int getControlPointCount() { - return controlPoints.length; - } - - @Override - public Point2D getControlPoint(int index) { - return controlPoints[index]; - } - - @Override - public boolean isControlPointSticky(int index) { - return true; - } - - @Override - public VisibilityPolicy getControlPointVisibilityPolicy(int index) { - return VisibilityPolicy.NEVER; - } - - @Override - public void setControlPoint(Point2D point, int index) { - controlPoints[index].setLocation(point); - body = null; - } - - private void updateControlPoints() { - Point2D firstPoint = controlPoints[0]; - controlPoints = new Point2D[PIN_COUNT]; - controlPoints[0] = firstPoint; - double pinSpacing = PIN_SPACING.convertToPixels(); - double rowSpacing = ROW_SPACING.convertToPixels(); - // Update control points. - double dx1; - double dy1; - double dx2; - double dy2; - for (int i = 0; i < PIN_COUNT / 2; i++) { - switch (orientation) { - case DEFAULT: - dx1 = 0; - dy1 = i * pinSpacing; - dx2 = rowSpacing; - dy2 = i * pinSpacing; - break; - case _90: - dx1 = -i * pinSpacing; - dy1 = 0; - dx2 = -i * pinSpacing; - dy2 = rowSpacing; - break; - case _180: - dx1 = 0; - dy1 = -i * pinSpacing; - dx2 = -rowSpacing; - dy2 = -i * pinSpacing; - break; - case _270: - dx1 = i * pinSpacing; - dy1 = 0; - dx2 = i * pinSpacing; - dy2 = -rowSpacing; - break; - default: - throw new RuntimeException("Unexpected orientation: " + orientation); - } - controlPoints[i] = new Point2D.Double((int) (firstPoint.getX() + dx1), (int) (firstPoint.getY() + dy1)); - controlPoints[i + PIN_COUNT / 2] = new Point2D.Double((int) (firstPoint.getX() + dx2), (int) (firstPoint.getY() + dy2)); - } - } - - public Area[] getBody() { - if (body == null) { - body = new Area[2]; - double x = controlPoints[0].getX(); - double y = controlPoints[0].getY(); - double width; - double height; + private static Size ROW_SPACING = new Size(6.5d, SizeUnit.mm); + + private String value = ""; + private Orientation orientation = Orientation.DEFAULT; + + private Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0)}; + protected Display display = Display.BOTH; + private Color bodyColor = BODY_COLOR; + private Color borderColor = BORDER_COLOR; + private Color labelColor = LABEL_COLOR; + transient private Area[] body; + + public TactileMicroSwitch() { + super(); + updateControlPoints(); + } + + @EditableProperty + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @EditableProperty + public Orientation getOrientation() { + return orientation; + } + + public void setOrientation(Orientation orientation) { + this.orientation = orientation; + updateControlPoints(); + // Reset body shape. + body = null; + } + + @EditableProperty + public Display getDisplay() { + if (display == null) { + display = Display.VALUE; + } + return display; + } + + public void setDisplay(Display display) { + this.display = display; + } + + @Override + public int getControlPointCount() { + return controlPoints.length; + } + + @Override + public Point2D getControlPoint(int index) { + return controlPoints[index]; + } + + @Override + public boolean isControlPointSticky(int index) { + return true; + } + + @Override + public VisibilityPolicy getControlPointVisibilityPolicy(int index) { + return VisibilityPolicy.NEVER; + } + + @Override + public void setControlPoint(Point2D point, int index) { + controlPoints[index].setLocation(point); + body = null; + } + + private void updateControlPoints() { + Point2D firstPoint = controlPoints[0]; + controlPoints = new Point2D[PIN_COUNT]; + controlPoints[0] = firstPoint; + double pinSpacing = PIN_SPACING.convertToPixels(); + double rowSpacing = ROW_SPACING.convertToPixels(); + // Update control points. + double dx1; + double dy1; + double dx2; + double dy2; + for (int i = 0; i < PIN_COUNT / 2; i++) { + switch (orientation) { + case DEFAULT: + dx1 = 0; + dy1 = i * pinSpacing; + dx2 = rowSpacing; + dy2 = i * pinSpacing; + break; + case _90: + dx1 = -i * pinSpacing; + dy1 = 0; + dx2 = -i * pinSpacing; + dy2 = rowSpacing; + break; + case _180: + dx1 = 0; + dy1 = -i * pinSpacing; + dx2 = -rowSpacing; + dy2 = -i * pinSpacing; + break; + case _270: + dx1 = i * pinSpacing; + dy1 = 0; + dx2 = i * pinSpacing; + dy2 = -rowSpacing; + break; + default: + throw new RuntimeException("Unexpected orientation: " + orientation); + } + controlPoints[i] = + new Point2D.Double((int) (firstPoint.getX() + dx1), (int) (firstPoint.getY() + dy1)); + controlPoints[i + PIN_COUNT / 2] = + new Point2D.Double((int) (firstPoint.getX() + dx2), (int) (firstPoint.getY() + dy2)); + } + } + + public Area[] getBody() { + if (body == null) { + body = new Area[2]; + double x = controlPoints[0].getX(); + double y = controlPoints[0].getY(); + double width; + double height; double caseSize = CASE_SIZE.convertToPixels(); - double indentSize = INDENT_SIZE.convertToPixels(); - - width = height = caseSize; - x = (controlPoints[0].getX() + controlPoints[3].getX() - width) / 2; - y = (controlPoints[0].getY() + controlPoints[3].getY() - height) / 2; - - body[0] = new Area(new Rectangle2D.Double(x, y, width, height)); - - width = height = indentSize; + double indentSize = INDENT_SIZE.convertToPixels(); + + width = height = caseSize; x = (controlPoints[0].getX() + controlPoints[3].getX() - width) / 2; y = (controlPoints[0].getY() + controlPoints[3].getY() - height) / 2; - - body[1] = new Area(new Ellipse2D.Double(x, y, width, height)); - } - return body; - } - - @Override - public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project, - IDrawingObserver drawingObserver) { - if (checkPointsClipped(g2d.getClip())) { - return; + + body[0] = new Area(new Rectangle2D.Double(x, y, width, height)); + + width = height = indentSize; + x = (controlPoints[0].getX() + controlPoints[3].getX() - width) / 2; + y = (controlPoints[0].getY() + controlPoints[3].getY() - height) / 2; + + body[1] = new Area(new Ellipse2D.Double(x, y, width, height)); } - Area[] body = getBody(); + return body; + } + + @Override + public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, + Project project, IDrawingObserver drawingObserver) { + if (checkPointsClipped(g2d.getClip())) { + return; + } + Area[] body = getBody(); Area mainArea = body[0]; Area indentArea = body[1]; - g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1f)); - if (!outlineMode) { - int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2; + g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1f)); + if (!outlineMode) { + int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2; for (Point2D point : controlPoints) { - Rectangle2D rect = new Rectangle2D.Double(point.getX() - pinSize / 2, point.getY() - pinSize / 2, pinSize, pinSize); - g2d.setColor(PIN_COLOR); - g2d.fill(rect); - g2d.setColor(PIN_BORDER_COLOR); - g2d.draw(rect); - } - } - Composite oldComposite = g2d.getComposite(); - if (alpha < MAX_ALPHA) { - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA)); - } - g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : getBodyColor()); + Rectangle2D rect = new Rectangle2D.Double(point.getX() - pinSize / 2, + point.getY() - pinSize / 2, pinSize, pinSize); + g2d.setColor(PIN_COLOR); + g2d.fill(rect); + g2d.setColor(PIN_BORDER_COLOR); + g2d.draw(rect); + } + } + Composite oldComposite = g2d.getComposite(); + if (alpha < MAX_ALPHA) { + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA)); + } + g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : getBodyColor()); g2d.fill(mainArea); - + g2d.setColor(INDENT_COLOR); g2d.fill(indentArea); g2d.setColor(INDENT_COLOR.darker()); g2d.draw(indentArea); - - g2d.setComposite(oldComposite); - - Color finalBorderColor; - if (outlineMode) { - Theme theme = - (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); - finalBorderColor = - componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR - : theme.getOutlineColor(); - } else { - finalBorderColor = - componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR - : getBorderColor(); - } - g2d.setColor(finalBorderColor); - g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); - - g2d.draw(mainArea); - - drawingObserver.stopTracking(); - - // Draw label. + + g2d.setComposite(oldComposite); + + Color finalBorderColor; + if (outlineMode) { + Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, + Constants.DEFAULT_THEME); + finalBorderColor = + componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING + ? SELECTION_COLOR + : theme.getOutlineColor(); + } else { + finalBorderColor = + componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING + ? SELECTION_COLOR + : getBorderColor(); + } + g2d.setColor(finalBorderColor); + g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); + + g2d.draw(mainArea); + + drawingObserver.stopTracking(); + + // Draw label. g2d.setFont(project.getFont()); - + // Override font size if (getFontSizeOverride() != null) g2d.setFont(g2d.getFont().deriveFont(1f * getFontSizeOverride())); - - 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 - : getLabelColor(); - } - g2d.setColor(finalLabelColor); - FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont()); - String[] label = null; - - if (getDisplay() == Display.NAME) { - label = new String[] {getName()}; - } else if (getDisplay() == Display.VALUE) { - label = new String[] {getValue().toString()}; - } else if (getDisplay() == Display.BOTH) { - String value = getValue().toString(); - label = value.isEmpty() ? new String[] {getName()} : new String[] {getName(), value}; - } - - if (label != null) { - for (int i = 0; i < label.length; i++) { - String l = label[i]; - Rectangle2D rect = fontMetrics.getStringBounds(l, g2d); - int textHeight = (int) (rect.getHeight()); - int textWidth = (int) (rect.getWidth()); - // Center text horizontally and vertically - Rectangle bounds = mainArea.getBounds(); - double x = bounds.getX() + (bounds.width - textWidth) / 2; - double y = bounds.getY() + (bounds.height - textHeight) / 2 + fontMetrics.getAscent(); - - if (label.length == 2) { - if (i == 0) - g2d.translate(0, -textHeight / 2); - else if (i == 1) - g2d.translate(0, textHeight / 2); - } - - g2d.drawString(l, (int)x, (int)y); - } - } - } - - @Override + + 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 + : getLabelColor(); + } + g2d.setColor(finalLabelColor); + FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont()); + String[] label = null; + + if (getDisplay() == Display.NAME) { + label = new String[] {getName()}; + } else if (getDisplay() == Display.VALUE) { + label = new String[] {getValue().toString()}; + } else if (getDisplay() == Display.BOTH) { + String value = getValue().toString(); + label = value.isEmpty() ? new String[] {getName()} : new String[] {getName(), value}; + } + + if (label != null) { + for (int i = 0; i < label.length; i++) { + String l = label[i]; + Rectangle2D rect = fontMetrics.getStringBounds(l, g2d); + int textHeight = (int) (rect.getHeight()); + int textWidth = (int) (rect.getWidth()); + // Center text horizontally and vertically + Rectangle bounds = mainArea.getBounds(); + double x = bounds.getX() + (bounds.width - textWidth) / 2; + double y = bounds.getY() + (bounds.height - textHeight) / 2 + fontMetrics.getAscent(); + + if (label.length == 2) { + if (i == 0) + g2d.translate(0, -textHeight / 2); + else if (i == 1) + g2d.translate(0, textHeight / 2); + } + + g2d.drawString(l, (int) x, (int) y); + } + } + } + + @Override public void drawIcon(Graphics2D g2d, int width, int height) { int pinSize = 4 * width / 32; g2d.setColor(PIN_COLOR); g2d.fillRect(width / 6 - pinSize + 1, height / 6 + 1, pinSize, pinSize); g2d.fillRect(5 * width / 6, height / 6 + 1, pinSize, pinSize); - + g2d.fillRect(width / 6 - pinSize + 1, 5 * height / 6 - pinSize - 1, pinSize, pinSize); g2d.fillRect(5 * width / 6, 5 * height / 6 - pinSize - 1, pinSize, pinSize); - - g2d.setColor(BODY_COLOR); - g2d.fillRect(width / 6, width / 6, 4 * width / 6, 4 * width / 6); - g2d.setColor(BORDER_COLOR); - g2d.drawRect(width / 6, width / 6, 4 * width / 6, 4 * width / 6); - + g2d.setColor(BODY_COLOR); + g2d.fillRect(width / 6, width / 6, 4 * width / 6, 4 * width / 6); + g2d.setColor(BORDER_COLOR); + g2d.drawRect(width / 6, width / 6, 4 * width / 6, 4 * width / 6); + + g2d.setColor(INDENT_COLOR); int indentSize = 9 * width / 32; - g2d.fillOval(width / 2 - indentSize / 2, height / 2 - indentSize / 2, indentSize, indentSize); - } - - @EditableProperty(name = "Body") - public Color getBodyColor() { - if (bodyColor == null) { - bodyColor = BODY_COLOR; - } - return bodyColor; - } - - public void setBodyColor(Color bodyColor) { - this.bodyColor = bodyColor; - } - - @EditableProperty(name = "Border") - public Color getBorderColor() { - if (borderColor == null) { - borderColor = BORDER_COLOR; - } - return borderColor; - } - - public void setBorderColor(Color borderColor) { - this.borderColor = borderColor; - } - - @EditableProperty(name = "Label") - public Color getLabelColor() { - if (labelColor == null) { - labelColor = LABEL_COLOR; - } - return labelColor; - } - - public void setLabelColor(Color labelColor) { - this.labelColor = labelColor; + g2d.fillOval(width / 2 - indentSize / 2, height / 2 - indentSize / 2, indentSize, indentSize); } - + + @EditableProperty(name = "Body") + public Color getBodyColor() { + if (bodyColor == null) { + bodyColor = BODY_COLOR; + } + return bodyColor; + } + + public void setBodyColor(Color bodyColor) { + this.bodyColor = bodyColor; + } + + @EditableProperty(name = "Border") + public Color getBorderColor() { + if (borderColor == null) { + borderColor = BORDER_COLOR; + } + return borderColor; + } + + public void setBorderColor(Color borderColor) { + this.borderColor = borderColor; + } + + @EditableProperty(name = "Label") + public Color getLabelColor() { + if (labelColor == null) { + labelColor = LABEL_COLOR; + } + return labelColor; + } + + public void setLabelColor(Color labelColor) { + this.labelColor = labelColor; + } + @Override public boolean canPointMoveFreely(int pointIndex) { return false; } - + @Override public Rectangle2D getCachingBounds() { double minX = Integer.MAX_VALUE; @@ -405,7 +409,8 @@ public class TactileMicroSwitch extends AbstractLabeledComponent { if (p.getY() > maxY) maxY = p.getY(); } - - return new Rectangle2D.Double(minX - margin, minY - margin, maxX - minX + 2 * margin, maxY - minY + 2 * margin); - } -} + + return new Rectangle2D.Double(minX - margin, minY - margin, maxX - minX + 2 * margin, + maxY - minY + 2 * margin); + } +} diff --git a/diylc/diylc-library/src/org/diylc/components/passive/AudioTransformer.java b/diylc/diylc-library/src/org/diylc/components/passive/AudioTransformer.java index a6f3cdbe..8c69f3a1 100644 --- a/diylc/diylc-library/src/org/diylc/components/passive/AudioTransformer.java +++ b/diylc/diylc-library/src/org/diylc/components/passive/AudioTransformer.java @@ -58,7 +58,7 @@ import org.diylc.utils.Constants; @ComponentDescriptor(name = "Mini Signal Transformer", author = "Branislav Stojkovic", category = "Passive", instanceNamePrefix = "TR", description = "Miniature PCB-mount signal transformer with EI core", - zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class) + zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE) public class AudioTransformer extends AbstractMultiPartComponent { private static final long serialVersionUID = 1L; diff --git a/diylc/diylc-library/src/org/diylc/components/semiconductors/BridgeRectifier.java b/diylc/diylc-library/src/org/diylc/components/semiconductors/BridgeRectifier.java index 109e8996..036b2fac 100644 --- a/diylc/diylc-library/src/org/diylc/components/semiconductors/BridgeRectifier.java +++ b/diylc/diylc-library/src/org/diylc/components/semiconductors/BridgeRectifier.java @@ -1,26 +1,23 @@ /* + * + * DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors. + * + * This file is part of DIYLC. + * + * DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * DIYLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with DIYLC. If not, see + * . + * + */ +package org.diylc.components.semiconductors; - DIY Layout Creator (DIYLC). - Copyright (c) 2009-2018 held jointly by the individual authors. - - This file is part of DIYLC. - - DIYLC is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - DIYLC is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DIYLC. If not, see . - -*/ -package org.diylc.components.semiconductors; - import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Composite; @@ -45,7 +42,6 @@ import org.diylc.common.VerticalAlignment; import org.diylc.components.AbstractLabeledComponent; import org.diylc.components.AbstractLeadedComponent.LabelOriantation; import org.diylc.components.RoundedPolygon; -import org.diylc.components.transform.DIL_ICTransformer; import org.diylc.core.ComponentState; import org.diylc.core.IDIYComponent; import org.diylc.core.IDrawingObserver; @@ -60,139 +56,140 @@ import org.diylc.core.measures.Size; import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.Voltage; import org.diylc.utils.Constants; - -@ComponentDescriptor(name = "Bridge Rectifier", author = "Branislav Stojkovic", category = "Semiconductors", - instanceNamePrefix = "BR", description = "Few variations of bridge rectifier chips", - zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class, - enableCache = true) -public class BridgeRectifier extends AbstractLabeledComponent { - + +@ComponentDescriptor(name = "Bridge Rectifier", author = "Branislav Stojkovic", + category = "Semiconductors", instanceNamePrefix = "BR", + description = "Few variations of bridge rectifier chips", zOrder = IDIYComponent.COMPONENT, + keywordPolicy = KeywordPolicy.SHOW_VALUE, enableCache = true) +public class BridgeRectifier extends AbstractLabeledComponent { + private static final long serialVersionUID = 1L; - + private static Size MINI_LENGTH = new Size(6.7d, SizeUnit.mm); private static Size MINI_WIDTH = new Size(8.3d, SizeUnit.mm); private static Size MINI_HORIZONTAL_SPACING = new Size(0.3d, SizeUnit.in); private static Size MINI_VERTICAL_SPACING = new Size(0.2d, SizeUnit.in); - - private static int[] MINI1_LABEL_SPACING_X = new int[] { 1, -1, -1, 1 }; - private static int[] MINI2_LABEL_SPACING_X = new int[] { 1, -1, 1, -1 }; - + + private static int[] MINI1_LABEL_SPACING_X = new int[] {1, -1, -1, 1}; + private static int[] MINI2_LABEL_SPACING_X = new int[] {1, -1, 1, -1}; + private static Size MINI_ROUND_DIAMETER = new Size(9.1d, SizeUnit.mm); - private static Size MINI_ROUND_SPACING = new Size(0.2d, SizeUnit.in); - private static int[] MINI_ROUND_LABEL_SPACING_Y = new int[] { 1, 1, -1, -1 }; - + private static Size MINI_ROUND_SPACING = new Size(0.2d, SizeUnit.in); + private static int[] MINI_ROUND_LABEL_SPACING_Y = new int[] {1, 1, -1, -1}; + private static Size INLINE_LENGTH = new Size(23.2d, SizeUnit.mm); private static Size INLINE_WIDTH = new Size(2.7d, SizeUnit.mm); private static Size INLINE_SPACING = new Size(0.2d, SizeUnit.in); - private static int[] INLINE_LABEL_SPACING_Y = new int[] { -1, -1, 1, 1 }; - + private static int[] INLINE_LABEL_SPACING_Y = new int[] {-1, -1, 1, 1}; + private static Size BR3_LENGTH = new Size(0.6d, SizeUnit.in); private static Size BR3_SPACING = new Size(0.425d, SizeUnit.in); private static Size BR3_HOLE_SIZE = new Size(3d, SizeUnit.mm); - private static int[] BR3_LABEL_SPACING_Y = new int[] { 1, 1, -1, -1 }; - - public static Color BODY_COLOR = Color.gray; - public static Color BORDER_COLOR = Color.gray.darker(); - public static Color PIN_COLOR = METAL_COLOR; - public static Color PIN_BORDER_COLOR = PIN_COLOR.darker(); - public static Color LABEL_COLOR = Color.white; - public static int EDGE_RADIUS = 6; + private static int[] BR3_LABEL_SPACING_Y = new int[] {1, 1, -1, -1}; + + public static Color BODY_COLOR = Color.gray; + public static Color BORDER_COLOR = Color.gray.darker(); + public static Color PIN_COLOR = METAL_COLOR; + public static Color PIN_BORDER_COLOR = PIN_COLOR.darker(); + public static Color LABEL_COLOR = Color.white; + public static int EDGE_RADIUS = 6; public static Size SQUARE_PIN_SIZE = new Size(0.04d, SizeUnit.in); - public static Size ROUND_PIN_SIZE = new Size(0.032d, SizeUnit.in); - public static Size INDENT_SIZE = new Size(0.07d, SizeUnit.in); - - private String value = ""; - private Orientation orientation = Orientation.DEFAULT; - private Point2D[] controlPoints = new Point2D[] { new Point2D.Double(0, 0), new Point2D.Double(0, 0), new Point2D.Double(0, 0), new Point2D.Double(0, 0) }; - private String[] pointLabels = new String[] { "+", "~", "~", "-" }; - protected Display display = Display.BOTH; - private Color bodyColor = BODY_COLOR; - private Color borderColor = BORDER_COLOR; - private Color labelColor = LABEL_COLOR; + public static Size ROUND_PIN_SIZE = new Size(0.032d, SizeUnit.in); + public static Size INDENT_SIZE = new Size(0.07d, SizeUnit.in); + + private String value = ""; + private Orientation orientation = Orientation.DEFAULT; + private Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0), + new Point2D.Double(0, 0), new Point2D.Double(0, 0), new Point2D.Double(0, 0)}; + private String[] pointLabels = new String[] {"+", "~", "~", "-"}; + protected Display display = Display.BOTH; + private Color bodyColor = BODY_COLOR; + private Color borderColor = BORDER_COLOR; + private Color labelColor = LABEL_COLOR; private RectifierType rectifierType = RectifierType.MiniDIP1; private Voltage voltage; - private Current current; + private Current current; transient private Area[] body; - private LabelOriantation labelOriantation = LabelOriantation.Directional; - - public BridgeRectifier() { - super(); + private LabelOriantation labelOriantation = LabelOriantation.Directional; + + public BridgeRectifier() { + super(); updateControlPoints(); - alpha = 100; - } - - @EditableProperty - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - @EditableProperty - public Orientation getOrientation() { - return orientation; - } - - public void setOrientation(Orientation orientation) { - this.orientation = orientation; - updateControlPoints(); - // Reset body shape. - body = null; - } - - @EditableProperty - public Display getDisplay() { - if (display == null) { - display = Display.VALUE; - } - return display; - } - - public void setDisplay(Display display) { - this.display = display; - } - - @Override - public int getControlPointCount() { - return controlPoints.length; - } - - @Override - public Point2D getControlPoint(int index) { - return controlPoints[index]; - } - - @Override - public boolean isControlPointSticky(int index) { - return true; - } - - @Override - public VisibilityPolicy getControlPointVisibilityPolicy(int index) { - return VisibilityPolicy.NEVER; - } - - @Override - public void setControlPoint(Point2D point, int index) { - controlPoints[index].setLocation(point); - body = null; - } - + alpha = 100; + } + + @EditableProperty + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @EditableProperty + public Orientation getOrientation() { + return orientation; + } + + public void setOrientation(Orientation orientation) { + this.orientation = orientation; + updateControlPoints(); + // Reset body shape. + body = null; + } + + @EditableProperty + public Display getDisplay() { + if (display == null) { + display = Display.VALUE; + } + return display; + } + + public void setDisplay(Display display) { + this.display = display; + } + + @Override + public int getControlPointCount() { + return controlPoints.length; + } + + @Override + public Point2D getControlPoint(int index) { + return controlPoints[index]; + } + + @Override + public boolean isControlPointSticky(int index) { + return true; + } + + @Override + public VisibilityPolicy getControlPointVisibilityPolicy(int index) { + return VisibilityPolicy.NEVER; + } + + @Override + public void setControlPoint(Point2D point, int index) { + controlPoints[index].setLocation(point); + body = null; + } + @SuppressWarnings("incomplete-switch") - private void updateControlPoints() { + private void updateControlPoints() { Point2D firstPoint = controlPoints[0]; - + int hSpacing; int vSpacing; - + switch (rectifierType) { case MiniDIP1: hSpacing = (int) MINI_HORIZONTAL_SPACING.convertToPixels(); vSpacing = (int) MINI_VERTICAL_SPACING.convertToPixels(); controlPoints[1].setLocation(firstPoint.getX() + hSpacing, firstPoint.getY()); - controlPoints[2].setLocation(firstPoint.getX() + hSpacing, firstPoint.getY() + vSpacing); + controlPoints[2].setLocation(firstPoint.getX() + hSpacing, firstPoint.getY() + vSpacing); controlPoints[3].setLocation(firstPoint.getX(), firstPoint.getY() + vSpacing); break; case MiniDIP2: @@ -200,19 +197,19 @@ public class BridgeRectifier extends AbstractLabeledComponent { vSpacing = (int) MINI_VERTICAL_SPACING.convertToPixels(); controlPoints[1].setLocation(firstPoint.getX() + hSpacing, firstPoint.getY()); controlPoints[2].setLocation(firstPoint.getX(), firstPoint.getY() + vSpacing); - controlPoints[3].setLocation(firstPoint.getX() + hSpacing, firstPoint.getY() + vSpacing); + controlPoints[3].setLocation(firstPoint.getX() + hSpacing, firstPoint.getY() + vSpacing); break; case MiniRound1: hSpacing = vSpacing = (int) MINI_ROUND_SPACING.convertToPixels(); controlPoints[1].setLocation(firstPoint.getX() + hSpacing, firstPoint.getY()); - controlPoints[2].setLocation(firstPoint.getX() + hSpacing, firstPoint.getY() + vSpacing); + controlPoints[2].setLocation(firstPoint.getX() + hSpacing, firstPoint.getY() + vSpacing); controlPoints[3].setLocation(firstPoint.getX(), firstPoint.getY() + vSpacing); break; case MiniRound2: hSpacing = vSpacing = (int) MINI_ROUND_SPACING.convertToPixels(); controlPoints[1].setLocation(firstPoint.getX() + hSpacing, firstPoint.getY()); controlPoints[2].setLocation(firstPoint.getX(), firstPoint.getY() + vSpacing); - controlPoints[3].setLocation(firstPoint.getX() + hSpacing, firstPoint.getY() + vSpacing); + controlPoints[3].setLocation(firstPoint.getX() + hSpacing, firstPoint.getY() + vSpacing); break; case InLine: vSpacing = (int) INLINE_SPACING.convertToPixels(); @@ -221,13 +218,13 @@ public class BridgeRectifier extends AbstractLabeledComponent { controlPoints[3].setLocation(firstPoint.getX(), firstPoint.getY() + 3 * vSpacing); break; case SquareBR3: - hSpacing = vSpacing = (int) BR3_SPACING.convertToPixels(); + hSpacing = vSpacing = (int) BR3_SPACING.convertToPixels(); controlPoints[1].setLocation(firstPoint.getX() + hSpacing, firstPoint.getY()); controlPoints[2].setLocation(firstPoint.getX(), firstPoint.getY() + vSpacing); controlPoints[3].setLocation(firstPoint.getX() + hSpacing, firstPoint.getY() + vSpacing); break; - } - + } + if (orientation != Orientation.DEFAULT) { double theta = 0; switch (orientation) { @@ -241,25 +238,28 @@ public class BridgeRectifier extends AbstractLabeledComponent { theta = Math.PI * 3 / 2; break; } - AffineTransform rotation = AffineTransform.getRotateInstance(theta, firstPoint.getX(), firstPoint.getY()); + AffineTransform rotation = + AffineTransform.getRotateInstance(theta, firstPoint.getX(), firstPoint.getY()); for (int i = 1; i < controlPoints.length; i++) { rotation.transform(controlPoints[i], controlPoints[i]); - } - } - } - + } + } + } + @SuppressWarnings("incomplete-switch") - public Area[] getBody() { - if (body == null) { + public Area[] getBody() { + if (body == null) { body = new Area[2]; - - double centerX = (controlPoints[0].getX() + controlPoints[1].getX() + controlPoints[2].getX() + controlPoints[3].getX()) / 4; - double centerY = (controlPoints[0].getY() + controlPoints[1].getY() + controlPoints[2].getY() + controlPoints[3].getY()) / 4; - + + double centerX = (controlPoints[0].getX() + controlPoints[1].getX() + controlPoints[2].getX() + + controlPoints[3].getX()) / 4; + double centerY = (controlPoints[0].getY() + controlPoints[1].getY() + controlPoints[2].getY() + + controlPoints[3].getY()) / 4; + int width = 0; int length = 0; - + switch (rectifierType) { case MiniDIP1: case MiniDIP2: @@ -278,48 +278,52 @@ public class BridgeRectifier extends AbstractLabeledComponent { length = width = (int) BR3_LENGTH.convertToPixels(); break; } - + if (orientation == Orientation._90 || orientation == Orientation._270) { int p = length; length = width; width = p; - } - + } + switch (rectifierType) { case MiniDIP1: case MiniDIP2: case InLine: - body[0] = new Area(new RoundRectangle2D.Double(centerX - length / 2, centerY - width / 2, length, width, EDGE_RADIUS, EDGE_RADIUS)); + body[0] = new Area(new RoundRectangle2D.Double(centerX - length / 2, centerY - width / 2, + length, width, EDGE_RADIUS, EDGE_RADIUS)); break; case MiniRound1: case MiniRound2: - body[0] = new Area(new Ellipse2D.Double(centerX - length / 2, centerY - width / 2, length, width)); + body[0] = new Area( + new Ellipse2D.Double(centerX - length / 2, centerY - width / 2, length, width)); break; case SquareBR3: double margin = (BR3_LENGTH.convertToPixels() - BR3_SPACING.convertToPixels()) / 2; double holeSize = BR3_HOLE_SIZE.convertToPixels(); -// -// Path2D path = new Path2D.Double(); -// path.moveTo(centerX - width / 2 + margin, centerY - width / 2); -// path.lineTo(centerX + width / 2, centerY - width / 2); -// path.lineTo(centerX + width / 2, centerY + width / 2); -// path.lineTo(centerX - width / 2, centerY + width / 2); -// path.lineTo(centerX - width / 2, centerY - width / 2 + margin); -// path.closePath(); - - RoundedPolygon poly = new RoundedPolygon(new Point2D[] { - new Point2D.Double(centerX, centerY - width / 2), - new Point2D.Double(centerX + width / 2, centerY - width / 2), - new Point2D.Double(centerX + width / 2, centerY + width / 2), - new Point2D.Double(centerX - width / 2, centerY + width / 2), - new Point2D.Double(centerX - width / 2, (int) (centerY - width / 2 + margin)), - new Point2D.Double((int) (centerX - width / 2 + margin), centerY - width / 2), - - }, new double[] { EDGE_RADIUS, EDGE_RADIUS, EDGE_RADIUS, EDGE_RADIUS / 2 , EDGE_RADIUS / 2}); - + // + // Path2D path = new Path2D.Double(); + // path.moveTo(centerX - width / 2 + margin, centerY - width / 2); + // path.lineTo(centerX + width / 2, centerY - width / 2); + // path.lineTo(centerX + width / 2, centerY + width / 2); + // path.lineTo(centerX - width / 2, centerY + width / 2); + // path.lineTo(centerX - width / 2, centerY - width / 2 + margin); + // path.closePath(); + + RoundedPolygon poly = + new RoundedPolygon(new Point2D[] {new Point2D.Double(centerX, centerY - width / 2), + new Point2D.Double(centerX + width / 2, centerY - width / 2), + new Point2D.Double(centerX + width / 2, centerY + width / 2), + new Point2D.Double(centerX - width / 2, centerY + width / 2), + new Point2D.Double(centerX - width / 2, (int) (centerY - width / 2 + margin)), + new Point2D.Double((int) (centerX - width / 2 + margin), centerY - width / 2), + + }, new double[] {EDGE_RADIUS, EDGE_RADIUS, EDGE_RADIUS, EDGE_RADIUS / 2, + EDGE_RADIUS / 2}); + body[0] = new Area(poly); - body[0].subtract(new Area(new Ellipse2D.Double(centerX - holeSize / 2, centerY - holeSize / 2, holeSize, holeSize))); - + body[0].subtract(new Area(new Ellipse2D.Double(centerX - holeSize / 2, + centerY - holeSize / 2, holeSize, holeSize))); + if (orientation != Orientation.DEFAULT) { double theta = 0; switch (orientation) { @@ -337,152 +341,160 @@ public class BridgeRectifier extends AbstractLabeledComponent { body[0].transform(rotation); } - + break; - } - } - return body; - } - + } + } + return body; + } + @SuppressWarnings("incomplete-switch") - @Override - public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project, - IDrawingObserver drawingObserver) { - if (checkPointsClipped(g2d.getClip())) { - return; - } + @Override + public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, + Project project, IDrawingObserver drawingObserver) { + if (checkPointsClipped(g2d.getClip())) { + return; + } Area mainArea = getBody()[0]; - + PinShape pinShape = rectifierType.getPinShape(); - int pinSize = (int) (pinShape == PinShape.Round ? ROUND_PIN_SIZE.convertToPixels() : SQUARE_PIN_SIZE.convertToPixels()) / 2 * 2; - - g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1f)); - if (!outlineMode) { - for (Point2D point : controlPoints) { + int pinSize = (int) (pinShape == PinShape.Round ? ROUND_PIN_SIZE.convertToPixels() + : SQUARE_PIN_SIZE.convertToPixels()) / 2 * 2; + + g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1f)); + if (!outlineMode) { + for (Point2D point : controlPoints) { g2d.setColor(PIN_COLOR); Shape shape; if (pinShape == PinShape.Round) - shape = new Ellipse2D.Double(point.getX() - pinSize / 2, point.getY() - pinSize / 2, pinSize, pinSize); - else - shape = new Rectangle2D.Double(point.getX() - pinSize / 2, point.getY() - pinSize / 2, pinSize, pinSize); - g2d.fill(shape); + shape = new Ellipse2D.Double(point.getX() - pinSize / 2, point.getY() - pinSize / 2, + pinSize, pinSize); + else + shape = new Rectangle2D.Double(point.getX() - pinSize / 2, point.getY() - pinSize / 2, + pinSize, pinSize); + g2d.fill(shape); g2d.setColor(PIN_BORDER_COLOR); - g2d.draw(shape); - } + g2d.draw(shape); + } } - - Composite oldComposite = g2d.getComposite(); - if (alpha < MAX_ALPHA) { - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA)); - } - g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : getBodyColor()); - g2d.fill(mainArea); - g2d.setComposite(oldComposite); - - Color finalBorderColor; - if (outlineMode) { - Theme theme = - (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); - finalBorderColor = - componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR - : theme.getOutlineColor(); - } else { - finalBorderColor = - componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR - : getBorderColor(); - } - g2d.setColor(finalBorderColor); - g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); - if (outlineMode) { - Area area = new Area(mainArea); - area.subtract(getBody()[1]); - g2d.draw(area); - } else { - g2d.draw(mainArea); -// if (getBody()[1] != null) { -// g2d.setColor(getIndentColor()); -// g2d.fill(getBody()[1]); -// } - } - - drawingObserver.stopTracking(); - - // Draw label. + + Composite oldComposite = g2d.getComposite(); + if (alpha < MAX_ALPHA) { + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA)); + } + g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : getBodyColor()); + g2d.fill(mainArea); + g2d.setComposite(oldComposite); + + Color finalBorderColor; + if (outlineMode) { + Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, + Constants.DEFAULT_THEME); + finalBorderColor = + componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING + ? SELECTION_COLOR + : theme.getOutlineColor(); + } else { + finalBorderColor = + componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING + ? SELECTION_COLOR + : getBorderColor(); + } + g2d.setColor(finalBorderColor); + g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); + if (outlineMode) { + Area area = new Area(mainArea); + area.subtract(getBody()[1]); + g2d.draw(area); + } else { + g2d.draw(mainArea); + // if (getBody()[1] != null) { + // g2d.setColor(getIndentColor()); + // g2d.fill(getBody()[1]); + // } + } + + drawingObserver.stopTracking(); + + // Draw label. g2d.setFont(project.getFont()); - + // Override font size if (getFontSizeOverride() != null) g2d.setFont(g2d.getFont().deriveFont(1f * getFontSizeOverride())); - - 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 - : getLabelColor(); - } - g2d.setColor(finalLabelColor); - FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont()); - String[] label = null; - - if (getDisplay() == Display.NAME) { - label = new String[] {getName()}; - } else if (getDisplay() == Display.VALUE) { - label = new String[] {getValue().toString()}; - } else if (getDisplay() == Display.BOTH) { - String value = getValue().toString(); - label = value.isEmpty() ? new String[] {getName()} : new String[] {getName(), value}; - } - - if (label != null) { - for (int i = 0; i < label.length; i++) { - String l = label[i]; - Rectangle2D rect = fontMetrics.getStringBounds(l, g2d); - int textHeight = (int) (rect.getHeight()); - int textWidth = (int) (rect.getWidth()); - // Center text horizontally and vertically - Rectangle bounds = mainArea.getBounds(); - double x = bounds.getX() + (bounds.width - textWidth) / 2; - double y = bounds.getY() + (bounds.height - textHeight) / 2 + fontMetrics.getAscent(); - - AffineTransform oldTransform = g2d.getTransform(); - - if (getLabelOriantation() == LabelOriantation.Directional && (getOrientation() == Orientation.DEFAULT || getOrientation() == Orientation._180)) { - double centerX = bounds.getX() + bounds.width / 2; - double centerY = bounds.getY() + bounds.height / 2; - g2d.rotate(-Math.PI / 2, centerX, centerY); - } - - if (label.length == 2) { - if (i == 0) - g2d.translate(0, -textHeight / 2); - else if (i == 1) - g2d.translate(0, textHeight / 2); + + 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 + : getLabelColor(); + } + g2d.setColor(finalLabelColor); + FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont()); + String[] label = null; + + if (getDisplay() == Display.NAME) { + label = new String[] {getName()}; + } else if (getDisplay() == Display.VALUE) { + label = new String[] {getValue().toString()}; + } else if (getDisplay() == Display.BOTH) { + String value = getValue().toString(); + label = value.isEmpty() ? new String[] {getName()} : new String[] {getName(), value}; + } + + if (label != null) { + for (int i = 0; i < label.length; i++) { + String l = label[i]; + Rectangle2D rect = fontMetrics.getStringBounds(l, g2d); + int textHeight = (int) (rect.getHeight()); + int textWidth = (int) (rect.getWidth()); + // Center text horizontally and vertically + Rectangle bounds = mainArea.getBounds(); + double x = bounds.getX() + (bounds.width - textWidth) / 2; + double y = bounds.getY() + (bounds.height - textHeight) / 2 + fontMetrics.getAscent(); + + AffineTransform oldTransform = g2d.getTransform(); + + if (getLabelOriantation() == LabelOriantation.Directional + && (getOrientation() == Orientation.DEFAULT || getOrientation() == Orientation._180)) { + double centerX = bounds.getX() + bounds.width / 2; + double centerY = bounds.getY() + bounds.height / 2; + g2d.rotate(-Math.PI / 2, centerX, centerY); } - + + if (label.length == 2) { + if (i == 0) + g2d.translate(0, -textHeight / 2); + else if (i == 1) + g2d.translate(0, textHeight / 2); + } + if (rectifierType == RectifierType.SquareBR3) - y -= BR3_HOLE_SIZE.convertToPixels(); - - g2d.drawString(l, (int)x, (int)y); - - g2d.setTransform(oldTransform); - } - } - - // draw pin numbers + y -= BR3_HOLE_SIZE.convertToPixels(); + + g2d.drawString(l, (int) x, (int) y); + + g2d.setTransform(oldTransform); + } + } + + // draw pin numbers g2d.setFont(project.getFont().deriveFont((float) (project.getFont().getSize2D() * 0.8))); - g2d.setColor(finalLabelColor); - for (int i = 0; i { break; case MiniDIP2: dx = pinSize * MINI2_LABEL_SPACING_X[i]; - break; + break; case MiniRound1: case MiniRound2: dy = pinSize * MINI_ROUND_LABEL_SPACING_Y[i]; @@ -502,23 +514,23 @@ public class BridgeRectifier extends AbstractLabeledComponent { dy = pinSize * BR3_LABEL_SPACING_Y[i]; break; } - + dx = (int) (1.5 * dx); dy = (int) (1.5 * dy); - + // now apply the correct rotation switch (rectifierType) { - case MiniDIP1: + case MiniDIP1: case MiniDIP2: switch (orientation) { - case _90: + case _90: int p1 = dx; dx = dy; dy = p1; break; case _180: - dx = - dx; - dy = - dy; + dx = -dx; + dy = -dy; break; case _270: int p2 = dx; @@ -526,30 +538,12 @@ public class BridgeRectifier extends AbstractLabeledComponent { dy = -p2; break; } - break; + break; case MiniRound1: case MiniRound2: case SquareBR3: switch (orientation) { - case _90: - int p1 = dx; - dx = -dy; - dy = -p1; - break; - case _180: - dx = - dx; - dy = - dy; - break; - case _270: - int p2 = dx; - dx = dy; - dy = p2; - break; - } - break; - case InLine: - switch (orientation) { - case _90: + case _90: int p1 = dx; dx = -dy; dy = -p1; @@ -565,139 +559,161 @@ public class BridgeRectifier extends AbstractLabeledComponent { break; } break; - } - - StringUtils.drawCenteredText(g2d, pointLabels[i], point.getX() + dx, point.getY() + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); - } - } - - @Override - public void drawIcon(Graphics2D g2d, int width, int height) { + case InLine: + switch (orientation) { + case _90: + int p1 = dx; + dx = -dy; + dy = -p1; + break; + case _180: + dx = -dx; + dy = -dy; + break; + case _270: + int p2 = dx; + dx = dy; + dy = p2; + break; + } + break; + } + + StringUtils.drawCenteredText(g2d, pointLabels[i], point.getX() + dx, point.getY() + dy, + HorizontalAlignment.CENTER, VerticalAlignment.CENTER); + } + } + + @Override + public void drawIcon(Graphics2D g2d, int width, int height) { int margin = (int) (2f * width / 32); - Area area = new Area(new Ellipse2D.Double(margin / 2, margin, width - 2 * margin, width - 2 * margin)); + Area area = + new Area(new Ellipse2D.Double(margin / 2, margin, width - 2 * margin, width - 2 * margin)); g2d.setColor(BODY_COLOR); g2d.fill(area); g2d.setColor(BORDER_COLOR); g2d.draw(area); g2d.setColor(PIN_COLOR); - int pinSize = 2 * width / 32; + int pinSize = 2 * width / 32; g2d.fillOval(width * 2 / 8, height * 2 / 8, pinSize, pinSize); g2d.fillOval(width * 6 / 8 - pinSize, height * 2 / 8, pinSize, pinSize); g2d.fillOval(width * 6 / 8 - pinSize, height * 6 / 8 - pinSize, pinSize, pinSize); g2d.fillOval(width * 2 / 8, height * 6 / 8 - pinSize, pinSize, pinSize); g2d.setColor(LABEL_COLOR); g2d.setFont(LABEL_FONT.deriveFont(8f * width / 32)); - StringUtils.drawCenteredText(g2d, "+", width * 2 / 8 + 1, height * 2 / 8 + 4 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); - StringUtils.drawCenteredText(g2d, "-", width * 2 / 8 + 1, height * 6 / 8 - 5 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); - StringUtils.drawCenteredText(g2d, "~", width * 6 / 8 - 2 * width / 32, height * 2 / 8 + 5 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); - StringUtils.drawCenteredText(g2d, "~", width * 6 / 8 - 2 * width / 32, height * 6 / 8 - 5 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); - } - - @EditableProperty(name = "Body") - public Color getBodyColor() { - if (bodyColor == null) { - bodyColor = BODY_COLOR; - } - return bodyColor; - } - - public void setBodyColor(Color bodyColor) { - this.bodyColor = bodyColor; - } - - @EditableProperty(name = "Border") - public Color getBorderColor() { - if (borderColor == null) { - borderColor = BORDER_COLOR; - } - return borderColor; - } - - public void setBorderColor(Color borderColor) { - this.borderColor = borderColor; - } - - @EditableProperty(name = "Label") - public Color getLabelColor() { - if (labelColor == null) { - labelColor = LABEL_COLOR; - } - return labelColor; - } - - public void setLabelColor(Color labelColor) { - this.labelColor = labelColor; - } + StringUtils.drawCenteredText(g2d, "+", width * 2 / 8 + 1, height * 2 / 8 + 4 * width / 32, + HorizontalAlignment.CENTER, VerticalAlignment.CENTER); + StringUtils.drawCenteredText(g2d, "-", width * 2 / 8 + 1, height * 6 / 8 - 5 * width / 32, + HorizontalAlignment.CENTER, VerticalAlignment.CENTER); + StringUtils.drawCenteredText(g2d, "~", width * 6 / 8 - 2 * width / 32, + height * 2 / 8 + 5 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); + StringUtils.drawCenteredText(g2d, "~", width * 6 / 8 - 2 * width / 32, + height * 6 / 8 - 5 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); + } + + @EditableProperty(name = "Body") + public Color getBodyColor() { + if (bodyColor == null) { + bodyColor = BODY_COLOR; + } + return bodyColor; + } + + public void setBodyColor(Color bodyColor) { + this.bodyColor = bodyColor; + } + + @EditableProperty(name = "Border") + public Color getBorderColor() { + if (borderColor == null) { + borderColor = BORDER_COLOR; + } + return borderColor; + } + + public void setBorderColor(Color borderColor) { + this.borderColor = borderColor; + } + + @EditableProperty(name = "Label") + public Color getLabelColor() { + if (labelColor == null) { + labelColor = LABEL_COLOR; + } + return labelColor; + } + + public void setLabelColor(Color labelColor) { + this.labelColor = labelColor; + } @EditableProperty(name = "Type") public RectifierType getRectifierType() { return rectifierType; } - + public void setRectifierType(RectifierType rectifierType) { this.rectifierType = rectifierType; updateControlPoints(); body = null; } - + @EditableProperty public Current getCurrent() { return current; } - + public void setCurrent(Current current) { this.current = current; } - + @EditableProperty public Voltage getVoltage() { return voltage; } - + public void setVoltage(Voltage voltage) { this.voltage = voltage; } - + @EditableProperty(name = "Label Orientation") public LabelOriantation getLabelOriantation() { if (labelOriantation == null) labelOriantation = LabelOriantation.Directional; return labelOriantation; } - + public void setLabelOriantation(LabelOriantation labelOriantation) { this.labelOriantation = labelOriantation; } - + @Override public boolean canPointMoveFreely(int pointIndex) { return false; } - + @Override - public Rectangle2D getCachingBounds() { - int margin = 20; + public Rectangle2D getCachingBounds() { + int margin = 20; Rectangle2D bounds = getBody()[0].getBounds2D(); - return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin); - } - + return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, + bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin); + } + public static enum RectifierType { - - MiniDIP1("DFM A", PinShape.Square), - MiniDIP2("DFM B", PinShape.Square), - MiniRound1("Round WOG A", PinShape.Round), - MiniRound2("Round WOG B", PinShape.Round), - InLine("In-Line D-44", PinShape.Round), - SquareBR3("Square BR-3", PinShape.Round); - + + MiniDIP1("DFM A", PinShape.Square), MiniDIP2("DFM B", PinShape.Square), MiniRound1( + "Round WOG A", PinShape.Round), MiniRound2("Round WOG B", PinShape.Round), InLine( + "In-Line D-44", PinShape.Round), SquareBR3("Square BR-3", PinShape.Round); + private String label; private PinShape pinShape; - + private RectifierType(String label, PinShape pinShape) { this.label = label; this.pinShape = pinShape; } - + @Override public String toString() { return label; @@ -707,8 +723,8 @@ public class BridgeRectifier extends AbstractLabeledComponent { return pinShape; } } - + private static enum PinShape { Square, Round - } -} + } +} diff --git a/diylc/diylc-swing/dict.txt b/diylc/diylc-swing/dict.txt index 156caab5..401b792f 100644 --- a/diylc/diylc-swing/dict.txt +++ b/diylc/diylc-swing/dict.txt @@ -49,6 +49,7 @@ AWG Alternate And Angle Offset +Apply Model B-C-E BJT Background Box @@ -103,6 +104,7 @@ I-G-O REGULATOR Italiano Lin Log +MPJA Markers Maximum number of switching combinations exceeded. Allowed: %s, actual: %s NPN @@ -126,6 +128,8 @@ PCB PNP Poles Português +RS +RY1 Rectangle Rev log S-G-D JFET