diff --git a/diylc/diylc-library/src/org/diylc/components/misc/Label.java b/diylc/diylc-library/src/org/diylc/components/misc/Label.java index 5ab0f8f0..b7cecc42 100644 --- a/diylc/diylc-library/src/org/diylc/components/misc/Label.java +++ b/diylc/diylc-library/src/org/diylc/components/misc/Label.java @@ -27,11 +27,12 @@ import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.geom.Rectangle2D; - + import org.diylc.common.HorizontalAlignment; import org.diylc.common.Orientation; import org.diylc.common.VerticalAlignment; import org.diylc.components.AbstractComponent; +import org.diylc.components.transform.TextTransformer; import org.diylc.core.ComponentState; import org.diylc.core.IDIYComponent; import org.diylc.core.IDrawingObserver; @@ -43,7 +44,7 @@ import org.diylc.core.annotations.EditableProperty; @ComponentDescriptor(name = "Label", author = "Branislav Stojkovic", category = "Misc", description = "User defined label", instanceNamePrefix = "L", zOrder = IDIYComponent.TEXT, flexibleZOrder = true, - stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW) + stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW, transformer = TextTransformer.class) public class Label extends AbstractComponent { public static String DEFAULT_TEXT = "Double click to edit text"; diff --git a/diylc/diylc-library/src/org/diylc/components/misc/PCBText.java b/diylc/diylc-library/src/org/diylc/components/misc/PCBText.java index 364efe48..6db690fb 100644 --- a/diylc/diylc-library/src/org/diylc/components/misc/PCBText.java +++ b/diylc/diylc-library/src/org/diylc/components/misc/PCBText.java @@ -28,11 +28,12 @@ import java.awt.Graphics2D; import java.awt.Point; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; - + import org.diylc.common.HorizontalAlignment; import org.diylc.common.Orientation; import org.diylc.common.VerticalAlignment; import org.diylc.components.AbstractComponent; +import org.diylc.components.transform.TextTransformer; import org.diylc.core.ComponentState; import org.diylc.core.IDIYComponent; import org.diylc.core.IDrawingObserver; @@ -44,7 +45,7 @@ import org.diylc.core.annotations.EditableProperty; @ComponentDescriptor(name = "PCB Text", author = "Branislav Stojkovic", category = "Misc", description = "Mirrored text for PCB artwork", instanceNamePrefix = "L", zOrder = IDIYComponent.TRACE, - flexibleZOrder = false, stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW) + flexibleZOrder = false, stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW, transformer = TextTransformer.class) public class PCBText extends AbstractComponent { public static String DEFAULT_TEXT = "Double click to edit text"; diff --git a/diylc/diylc-library/src/org/diylc/components/transform/TextTransformer.java b/diylc/diylc-library/src/org/diylc/components/transform/TextTransformer.java new file mode 100644 index 00000000..812325e1 --- /dev/null +++ b/diylc/diylc-library/src/org/diylc/components/transform/TextTransformer.java @@ -0,0 +1,84 @@ +/* + * + * 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.transform; + +import java.awt.Point; +import java.awt.geom.AffineTransform; + +import org.diylc.common.IComponentTransformer; +import org.diylc.common.Orientation; +import org.diylc.components.misc.Label; +import org.diylc.components.misc.PCBText; +import org.diylc.core.IDIYComponent; + +public class TextTransformer implements IComponentTransformer { + + @Override + public boolean canRotate(IDIYComponent component) { + return component.getClass().equals(Label.class) || component.getClass().equals(PCBText.class); + } + + @Override + public boolean canMirror(IDIYComponent component) { + return false; + } + + @Override + public boolean mirroringChangesCircuit() { + return false; + } + + @Override + public void rotate(IDIYComponent component, Point center, int direction) { + AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2 * direction, center.x, center.y); + for (int index = 0; index < component.getControlPointCount(); index++) { + Point p = new Point(component.getControlPoint(index)); + rotate.transform(p, p); + component.setControlPoint(p, index); + } + + if (component instanceof Label) { + Label snap = (Label) component; + Orientation o = snap.getOrientation(); + 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]; + snap.setOrientation(o); + } else if (component instanceof PCBText) { + PCBText snap = (PCBText) component; + Orientation o = snap.getOrientation(); + 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]; + snap.setOrientation(o); + } + } + + @Override + public void mirror(IDIYComponent component, Point center, int direction) { + throw new RuntimeException("Unexpected call to mirror() in LabelTransformer"); + } +} diff --git a/diylc/diylc-swing/library/main.jar b/diylc/diylc-swing/library/main.jar index 06180036..f7929d68 100644 Binary files a/diylc/diylc-swing/library/main.jar and b/diylc/diylc-swing/library/main.jar differ diff --git a/diylc/diylc-swing/update.xml b/diylc/diylc-swing/update.xml index 8c5b52e2..0befae09 100644 --- a/diylc/diylc-swing/update.xml +++ b/diylc/diylc-swing/update.xml @@ -2040,7 +2040,7 @@ IMPROVEMENT - Vastly improve performance of selection aree calculations, especially with bigger layouts + Faster click and popup menu response due to improved performance of selection area calculations, especially with bigger layouts IMPROVEMENT @@ -2050,6 +2050,10 @@ IMPROVEMENT Better error handing in V2 file importer + + IMPROVEMENT + Rotate commands now apply to "Label" and "PCB Text" components + BUG_FIX Clicking on a building block in the component tree sometimes makes the components go back to the top-left corner of the layout