diff --git a/diylc/diylc-core/lib/app-framework.jar b/diylc/diylc-core/lib/app-framework.jar index 0200152e..7fed7294 100644 Binary files a/diylc/diylc-core/lib/app-framework.jar and b/diylc/diylc-core/lib/app-framework.jar differ diff --git a/diylc/diylc-core/src/org/diylc/presenter/update.xml b/diylc/diylc-core/src/org/diylc/presenter/update.xml index 4cff692e..2c3cee80 100644 --- a/diylc/diylc-core/src/org/diylc/presenter/update.xml +++ b/diylc/diylc-core/src/org/diylc/presenter/update.xml @@ -3166,6 +3166,10 @@ 2020-09-04 00:00:00.000 CET + + NEW_FEATURE + Added "Phono Jack" schematic symbol + NEW_FEATURE Added keyboard shortcuts for zoom in and out using standard Ctrl and +/- key combination and Ctrl+0 to reset to 100% diff --git a/diylc/diylc-library/lib/app-framework.jar b/diylc/diylc-library/lib/app-framework.jar index 0200152e..7fed7294 100644 Binary files a/diylc/diylc-library/lib/app-framework.jar and b/diylc/diylc-library/lib/app-framework.jar differ diff --git a/diylc/diylc-library/lib/diylc-core.jar b/diylc/diylc-library/lib/diylc-core.jar index 4ea2960f..4075de61 100644 Binary files a/diylc/diylc-library/lib/diylc-core.jar and b/diylc/diylc-library/lib/diylc-core.jar differ diff --git a/diylc/diylc-library/src/org/diylc/components/Abstract3LegSymbol.java b/diylc/diylc-library/src/org/diylc/components/Abstract3LegSymbol.java index 119d52c2..b4263533 100644 --- a/diylc/diylc-library/src/org/diylc/components/Abstract3LegSymbol.java +++ b/diylc/diylc-library/src/org/diylc/components/Abstract3LegSymbol.java @@ -122,13 +122,16 @@ public abstract class Abstract3LegSymbol extends AbstractComponent { g2d.translate(-1 * controlPoints[0].getX(), 0); } - g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2)); - g2d.draw(body[0]); + g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2)); + if (body[0] != null) + g2d.draw(body[0]); - g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); - g2d.draw(body[1]); - - g2d.fill(body[2]); + g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); + if (body[1] != null) + g2d.draw(body[1]); + + if (body[2] != null) + g2d.fill(body[2]); g2d.setTransform(old); // Draw label @@ -156,8 +159,16 @@ public abstract class Abstract3LegSymbol extends AbstractComponent { } FontMetrics fontMetrics = g2d.getFontMetrics(); - Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d); - Rectangle shapeRect = body[0].getBounds().union(body[1].getBounds()).union(body[2].getBounds()); + Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d); + Rectangle shapeRect = null;; + for (int i = 0; i < 3; i++) + if (body[i] != null) { + Rectangle bounds = body[i].getBounds(); + if (shapeRect == null) + shapeRect = bounds; + else + shapeRect = shapeRect.union(bounds); + } if (getMoveLabel()) { StringUtils.drawCenteredText(g2d, label, controlPoints[3].getX(), controlPoints[3].getY(), flip == SymbolFlipping.X ? HorizontalAlignment.RIGHT @@ -187,6 +198,12 @@ public abstract class Abstract3LegSymbol extends AbstractComponent { protected double getLabelY(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics, boolean outlineMode) { return getControlPoints()[0].getY(); + } + + protected void setDefaultPointLocations(Point2D[] controlPoints, int pinSpacing, double x, double y) { + controlPoints[1].setLocation(x + pinSpacing * 2, y - pinSpacing * 2); + controlPoints[2].setLocation(x + pinSpacing * 2, y + pinSpacing * 2); + controlPoints[3].setLocation(x + pinSpacing * 2, y); } protected void updateControlPoints() { @@ -196,12 +213,7 @@ public abstract class Abstract3LegSymbol extends AbstractComponent { double x = controlPoints[0].getX(); double y = controlPoints[0].getY(); - // set default point positions - controlPoints[1].setLocation(x + pinSpacing * 2, y - pinSpacing * 2); - - controlPoints[2].setLocation(x + pinSpacing * 2, y + pinSpacing * 2); - - controlPoints[3].setLocation(x + PIN_SPACING.convertToPixels() * 2, y); + setDefaultPointLocations(controlPoints, pinSpacing, x, y); // apply rotation if needed if (getOrientation() != Orientation.DEFAULT) diff --git a/diylc/diylc-library/src/org/diylc/components/electromechanical/PhonoJackSymbol.java b/diylc/diylc-library/src/org/diylc/components/electromechanical/PhonoJackSymbol.java new file mode 100644 index 00000000..0f996786 --- /dev/null +++ b/diylc/diylc-library/src/org/diylc/components/electromechanical/PhonoJackSymbol.java @@ -0,0 +1,182 @@ +/* + * + * 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.FontMetrics; +import java.awt.Graphics2D; +import java.awt.Shape; +import java.awt.geom.GeneralPath; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +import org.diylc.common.ObjectCache; +import org.diylc.common.Orientation; +import org.diylc.components.Abstract3LegSymbol; +import org.diylc.components.semiconductors.SymbolFlipping; +import org.diylc.components.transform.ThreeLegTransformer; +import org.diylc.core.IDIYComponent; +import org.diylc.core.VisibilityPolicy; +import org.diylc.core.annotations.ComponentDescriptor; +import org.diylc.core.annotations.EditableProperty; +import org.diylc.core.annotations.KeywordPolicy; + +@ComponentDescriptor(name = "Phono Jack", author = "Branislav Stojkovic", + category = "Schematic Symbols", instanceNamePrefix = "J", + description = "Connectors typically used for analog audio signals", zOrder = IDIYComponent.COMPONENT, + transformer = ThreeLegTransformer.class, keywordPolicy = KeywordPolicy.SHOW_TAG_AND_VALUE, + keywordTag = "Schematic") +public class PhonoJackSymbol extends Abstract3LegSymbol { + + private static final long serialVersionUID = 1L; + + protected PhonoJackType type = PhonoJackType.MONO; + + public Shape[] getBody() { + Shape[] body = new Shape[3]; + Point2D[] controlPoints = getControlPoints(); + double x; + double y; + double pinSpacing = PIN_SPACING.convertToPixels(); + + GeneralPath polyline = new GeneralPath(); + + x = controlPoints[0].getX(); + y = controlPoints[0].getY(); + polyline.moveTo(x, y); + polyline.lineTo(x - pinSpacing * 1.5, y); + polyline.lineTo(x - pinSpacing * 1.75, y + pinSpacing * 0.25); + polyline.lineTo(x - pinSpacing * 2, y); + + y += pinSpacing * 2; + polyline.moveTo(x, y); + polyline.lineTo(x - pinSpacing * 3, y); + polyline.lineTo(x - pinSpacing * 3, y - pinSpacing * 2); + polyline.lineTo(x - pinSpacing * 2.75, y - pinSpacing * 2); + polyline.lineTo(x - pinSpacing * 2.75, y); + + if (getType() == PhonoJackType.STEREO) { + y -= pinSpacing; + x = controlPoints[2].getX(); + y = controlPoints[2].getY(); + polyline.moveTo(x, y); + polyline.lineTo(x - pinSpacing, y); + polyline.lineTo(x - pinSpacing * 1.25, y - pinSpacing * 0.25); + polyline.lineTo(x - pinSpacing * 1.5, y); + } + + body[1] = polyline; + + return body; + } + + @Override + protected void setDefaultPointLocations(Point2D[] controlPoints, int pinSpacing, double x, + double y) { + controlPoints[1].setLocation(x, y + pinSpacing * 2); + controlPoints[2].setLocation(x, y + pinSpacing); + controlPoints[3].setLocation(x - pinSpacing * 4, y + pinSpacing); + } + + @Override + protected Point2D getDefaultLabelPosition(Point2D[] oldControlPoints) { + double pinSpacing = PIN_SPACING.convertToPixels(); + int f = flip == SymbolFlipping.X ? -1 : 1; + int d = 0; + return new Point2D.Double(oldControlPoints[0].getX() - f * (pinSpacing * 4 + d), oldControlPoints[0].getY() + pinSpacing); + } + + @Override + protected double getLabelX(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics, boolean outlineMode) { + if (orientation == Orientation._180 ^ flip == SymbolFlipping.X) + return shapeRect.getMaxX() + textRect.getWidth() / 2; + return shapeRect.getMinX() - textRect.getWidth() * 1.5; + } + + @Override + protected double getLabelY(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics, boolean outlineMode) { + return shapeRect.getCenterY(); + } + + @Override + public void drawIcon(Graphics2D g2d, int width, int height) { + g2d.setColor(COLOR); + + int margin = 4; + + g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); + g2d.drawLine(margin, margin, margin, height - margin); + g2d.drawLine(margin, margin, margin * 2, margin); + g2d.drawLine(margin * 2, margin, margin * 2, height - margin); + g2d.drawLine(margin, height - margin, width - margin, height - margin); + + g2d.drawLine(margin * 3, margin, margin * 4, margin * 2); + g2d.drawLine(margin * 4, margin * 2, margin * 5, margin); + g2d.drawLine(margin * 5, margin, width - margin, margin); + + int center = width / 2; + g2d.drawLine(center, center, center + margin, center - margin); + g2d.drawLine(center + margin, center - margin, center + margin * 2, center); + g2d.drawLine(center + margin * 2, center, width - margin, center); + } + + @EditableProperty(name = "Type") + public PhonoJackType getType() { + return type; + } + + public void setType(PhonoJackType type) { + this.type = type; + + body = null; + } + + @Override + public String getControlPointNodeName(int index) { + return getName() + "." + index; + } + + @Override + public VisibilityPolicy getControlPointVisibilityPolicy(int index) { + switch (index) { + case 0: + case 1: + return VisibilityPolicy.WHEN_SELECTED; + case 2: + return getType() == PhonoJackType.STEREO ? VisibilityPolicy.WHEN_SELECTED : VisibilityPolicy.NEVER; + case 3: + return getMoveLabel() ? VisibilityPolicy.WHEN_SELECTED : VisibilityPolicy.NEVER; + } + return VisibilityPolicy.NEVER; + } + + @Override + public boolean isControlPointSticky(int index) { + return index < 3 && (getType() == PhonoJackType.STEREO || index != 2); + } + + public enum PhonoJackType { + + MONO, STEREO; + + @Override + public String toString() { + return name().substring(0, 1) + name().substring(1).toLowerCase(); + } + } +} diff --git a/diylc/diylc-swing/lib/app-framework.jar b/diylc/diylc-swing/lib/app-framework.jar index 0200152e..7fed7294 100644 Binary files a/diylc/diylc-swing/lib/app-framework.jar and b/diylc/diylc-swing/lib/app-framework.jar differ diff --git a/diylc/diylc-swing/lib/diylc-core.jar b/diylc/diylc-swing/lib/diylc-core.jar index 3c2192ce..4075de61 100644 Binary files a/diylc/diylc-swing/lib/diylc-core.jar and b/diylc/diylc-swing/lib/diylc-core.jar differ diff --git a/diylc/diylc-swing/lib/swing-framework.jar b/diylc/diylc-swing/lib/swing-framework.jar index 675feb11..4d035652 100644 Binary files a/diylc/diylc-swing/lib/swing-framework.jar and b/diylc/diylc-swing/lib/swing-framework.jar differ diff --git a/diylc/diylc-swing/library/main.jar b/diylc/diylc-swing/library/main.jar index a0064055..5fec2488 100644 Binary files a/diylc/diylc-swing/library/main.jar and b/diylc/diylc-swing/library/main.jar differ