don't group pasted components

fix: click twice on a building block makes components jump to top-left
various minor updates
This commit is contained in:
Branislav Stojkovic
2018-12-25 16:49:18 +01:00
parent 48a6857738
commit e9615d4d64
25 changed files with 2963 additions and 2331 deletions
@@ -203,8 +203,9 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
* Adds a list of components to the project. * Adds a list of components to the project.
* *
* @param components * @param components
* @param autoGroup
*/ */
void pasteComponents(Collection<IDIYComponent<?>> components); void pasteComponents(Collection<IDIYComponent<?>> components, boolean autoGroup);
/** /**
* Duplicates selected components and places them nearby. * Duplicates selected components and places them nearby.
@@ -117,21 +117,7 @@ public class ComponentProcessor {
keywordTag = annotation.keywordTag(); keywordTag = annotation.keywordTag();
continuity = annotation.continuity(); continuity = annotation.continuity();
} else { // default } else { // default
name = clazz.getSimpleName(); return null;
description = "";
creationMethod = CreationMethod.SINGLE_CLICK;
category = "Uncategorized";
namePrefix = "Unknown";
author = "Unknown";
zOrder = IDIYComponent.COMPONENT;
flexibleZOrder = false;
stretchable = true;
bomPolicy = BomPolicy.SHOW_ALL_NAMES;
autoEdit = true;
transformer = null;
keywordPolicy = KeywordPolicy.NEVER_SHOW;
keywordTag = null;
continuity = false;
} }
icon = null; icon = null;
// Draw component icon. // Draw component icon.
@@ -61,9 +61,12 @@ public class InstantiationManager {
private Point firstControlPoint; private Point firstControlPoint;
private Point potentialControlPoint; private Point potentialControlPoint;
private static final ComponentType clipboardType = new ComponentType("Clipboard contents", public static final ComponentType clipboardType = new ComponentType("Clipboard contents",
"Components from the clipboard", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null, "Components from the clipboard", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null,
false, null, KeywordPolicy.NEVER_SHOW, null, false); false, null, KeywordPolicy.NEVER_SHOW, null, false);
public static final ComponentType blockType = new ComponentType("Building block",
"Components from the building block", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null,
false, null, KeywordPolicy.NEVER_SHOW, null, false);
public InstantiationManager() {} public InstantiationManager() {}
@@ -87,6 +90,10 @@ public class InstantiationManager {
return potentialControlPoint; return potentialControlPoint;
} }
public void setPotentialControlPoint(Point potentialControlPoint) {
this.potentialControlPoint = potentialControlPoint;
}
public void setComponentTypeSlot(ComponentType componentTypeSlot, Template template, Project currentProject) public void setComponentTypeSlot(ComponentType componentTypeSlot, Template template, Project currentProject)
throws Exception { throws Exception {
this.componentTypeSlot = componentTypeSlot; this.componentTypeSlot = componentTypeSlot;
@@ -133,7 +140,7 @@ public class InstantiationManager {
} }
public void pasteComponents(Collection<IDIYComponent<?>> components, Point scaledPoint, boolean snapToGrid, public void pasteComponents(Collection<IDIYComponent<?>> components, Point scaledPoint, boolean snapToGrid,
Size gridSpacing) { Size gridSpacing, boolean autoGroup) {
// Adjust location of components so they are centered under the mouse // Adjust location of components so they are centered under the mouse
// cursor // cursor
int minX = Integer.MAX_VALUE; int minX = Integer.MAX_VALUE;
@@ -176,7 +183,7 @@ public class InstantiationManager {
// Update the component type slot so the app knows that something's // Update the component type slot so the app knows that something's
// being instantiated. // being instantiated.
this.componentTypeSlot = clipboardType; this.componentTypeSlot = autoGroup ? blockType : clipboardType;
if (snapToGrid) { if (snapToGrid) {
scaledPoint = new Point(scaledPoint); scaledPoint = new Point(scaledPoint);
@@ -356,6 +356,8 @@ public class Presenter implements IPlugInPort {
if (!Modifier.isAbstract(clazz.getModifiers()) && IDIYComponent.class.isAssignableFrom(clazz)) { if (!Modifier.isAbstract(clazz.getModifiers()) && IDIYComponent.class.isAssignableFrom(clazz)) {
ComponentType componentType = ComponentType componentType =
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) clazz); ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) clazz);
if (componentType == null)
continue;
List<ComponentType> nestedList; List<ComponentType> nestedList;
if (componentTypes.containsKey(componentType.getCategory())) { if (componentTypes.containsKey(componentType.getCategory())) {
nestedList = componentTypes.get(componentType.getCategory()); nestedList = componentTypes.get(componentType.getCategory());
@@ -517,8 +519,8 @@ public class Presenter implements IPlugInPort {
addComponent(component, true); addComponent(component, true);
newSelection.add(component); newSelection.add(component);
} }
// group components if there's more than one, e.g. building blocks // group components if there's more than one, e.g. building blocks, but not clipboard contents
if (componentSlot.size() > 1) { if (componentSlot.size() > 1 && !componentTypeSlot.getName().toLowerCase().contains("clipboard")) {
this.currentProject.getGroups().add(new HashSet<IDIYComponent<?>>(componentSlot)); this.currentProject.getGroups().add(new HashSet<IDIYComponent<?>>(componentSlot));
} }
// Select the new component // Select the new component
@@ -1452,10 +1454,10 @@ public class Presenter implements IPlugInPort {
} }
@Override @Override
public void pasteComponents(Collection<IDIYComponent<?>> components) { public void pasteComponents(Collection<IDIYComponent<?>> components, boolean autoGroup) {
LOG.info(String.format("pasteComponents(%s)", components)); LOG.info(String.format("pasteComponents(%s, %s)", components, autoGroup));
instantiationManager.pasteComponents(components, this.previousScaledPoint, isSnapToGrid(), instantiationManager.pasteComponents(components, this.previousScaledPoint, isSnapToGrid(),
currentProject.getGridSpacing()); currentProject.getGridSpacing(), autoGroup);
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED, instantiationManager.getComponentTypeSlot(), messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED, instantiationManager.getComponentTypeSlot(),
instantiationManager.getFirstControlPoint()); instantiationManager.getFirstControlPoint());
@@ -2327,6 +2329,8 @@ public class Presenter implements IPlugInPort {
Collection<IDIYComponent<?>> components = blocks.get(blockName); Collection<IDIYComponent<?>> components = blocks.get(blockName);
if (components == null) if (components == null)
throw new InvalidBlockException(); throw new InvalidBlockException();
// clear potential control point every time!
instantiationManager.setPotentialControlPoint(null);
// clone components // clone components
List<IDIYComponent<?>> clones = new ArrayList<IDIYComponent<?>>(); List<IDIYComponent<?>> clones = new ArrayList<IDIYComponent<?>>();
List<IDIYComponent<?>> testComponents = new ArrayList<IDIYComponent<?>>(currentProject.getComponents()); List<IDIYComponent<?>> testComponents = new ArrayList<IDIYComponent<?>>(currentProject.getComponents());
@@ -2341,7 +2345,7 @@ public class Presenter implements IPlugInPort {
LOG.error("Could not clone component: " + c); LOG.error("Could not clone component: " + c);
} }
// paste them to the project // paste them to the project
pasteComponents(clones); pasteComponents(clones, true);
} else } else
throw new InvalidBlockException(); throw new InvalidBlockException();
} }
Binary file not shown.
@@ -38,7 +38,7 @@ import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Chassis Panel", author = "Branislav Stojkovic", category = "Electromechanical", @ComponentDescriptor(name = "Chassis Panel", author = "Branislav Stojkovic", category = "Electro-Mechanical",
instanceNamePrefix = "CP", description = "One side of a chassis, with or withouth rounded edges", instanceNamePrefix = "CP", description = "One side of a chassis, with or withouth rounded edges",
zOrder = IDIYComponent.CHASSIS, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false, zOrder = IDIYComponent.CHASSIS, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false,
transformer = SimpleComponentTransformer.class) transformer = SimpleComponentTransformer.class)
@@ -31,7 +31,7 @@ import org.diylc.core.Project;
import org.diylc.core.annotations.BomPolicy; import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
@ComponentDescriptor(name = "Elliptical Cutout", author = "Branislav Stojkovic", category = "Electromechanical", @ComponentDescriptor(name = "Elliptical Cutout", author = "Branislav Stojkovic", category = "Electro-Mechanical",
instanceNamePrefix = "ELC", description = "Elliptical chassis cutout", zOrder = IDIYComponent.CHASSIS + 0.1, instanceNamePrefix = "ELC", description = "Elliptical chassis cutout", zOrder = IDIYComponent.CHASSIS + 0.1,
bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, transformer = SimpleComponentTransformer.class) bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, transformer = SimpleComponentTransformer.class)
public class EllipticalCutout extends AbstractShape { public class EllipticalCutout extends AbstractShape {
@@ -35,7 +35,7 @@ import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@ComponentDescriptor(name = "Polygonal Cutout", author = "Branislav Stojkovic", category = "Electromechanical", @ComponentDescriptor(name = "Polygonal Cutout", author = "Branislav Stojkovic", category = "Electro-Mechanical",
instanceNamePrefix = "POLYC", description = "Polygonal chassis cutout", zOrder = IDIYComponent.CHASSIS + 0.1, instanceNamePrefix = "POLYC", description = "Polygonal chassis cutout", zOrder = IDIYComponent.CHASSIS + 0.1,
bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, transformer = SimpleComponentTransformer.class) bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, transformer = SimpleComponentTransformer.class)
public class PolygonalCutout extends AbstractShape { public class PolygonalCutout extends AbstractShape {
@@ -34,7 +34,7 @@ import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Rectangular Cutout", author = "Branislav Stojkovic", category = "Electromechanical", @ComponentDescriptor(name = "Rectangular Cutout", author = "Branislav Stojkovic", category = "Electro-Mechanical",
instanceNamePrefix = "RECTC", description = "Rectangular chassis cutout, with or without rounded edges", instanceNamePrefix = "RECTC", description = "Rectangular chassis cutout, with or without rounded edges",
zOrder = IDIYComponent.CHASSIS + 0.1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, zOrder = IDIYComponent.CHASSIS + 0.1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
transformer = SimpleComponentTransformer.class) transformer = SimpleComponentTransformer.class)
@@ -51,7 +51,7 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "9V Battery Snap", category = "Electromechanical", author = "Branislav Stojkovic", @ComponentDescriptor(name = "9V Battery Snap", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "BTR", description = "", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "BTR",
autoEdit = false, transformer = BatterySnapTransformer.class) autoEdit = false, transformer = BatterySnapTransformer.class)
public class BatterySnap9V extends AbstractTransparentComponent<String> { public class BatterySnap9V extends AbstractTransparentComponent<String> {
@@ -53,7 +53,7 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Cliff 1/4\" Jack", category = "Electromechanical", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Cliff 1/4\" Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Cliff-style closed panel mount 1/4\" phono jack", stretchable = false, description = "Cliff-style closed panel mount 1/4\" phono jack", stretchable = false,
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J", autoEdit = false, transformer = CliffJackTransformer.class) zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J", autoEdit = false, transformer = CliffJackTransformer.class)
public class CliffJack1_4 extends AbstractTransparentComponent<String> { public class CliffJack1_4 extends AbstractTransparentComponent<String> {
@@ -53,7 +53,7 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Closed 1/4\" Jack", category = "Electromechanical", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Closed 1/4\" Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Enclosed panel mount 1/4\" phono jack", stretchable = false, zOrder = IDIYComponent.COMPONENT, description = "Enclosed panel mount 1/4\" phono jack", stretchable = false, zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "J", autoEdit = false, transformer = ClosedJackTransformer.class) instanceNamePrefix = "J", autoEdit = false, transformer = ClosedJackTransformer.class)
public class ClosedJack1_4 extends AbstractTransparentComponent<String> { public class ClosedJack1_4 extends AbstractTransparentComponent<String> {
@@ -52,7 +52,7 @@ import org.diylc.core.measures.Voltage;
import org.diylc.core.measures.VoltageUnit; import org.diylc.core.measures.VoltageUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Mini Relay", author = "Branislav Stojkovic", category = "Electromechanical", @ComponentDescriptor(name = "Mini Relay", author = "Branislav Stojkovic", category = "Electro-Mechanical",
instanceNamePrefix = "RY", description = "Miniature PCB mount relay, like Omron G5V-1 or G5V-2", instanceNamePrefix = "RY", description = "Miniature PCB mount relay, like Omron G5V-1 or G5V-2",
stretchable = false, zOrder = IDIYComponent.COMPONENT) stretchable = false, zOrder = IDIYComponent.COMPONENT)
public class MiniRelay extends AbstractTransparentComponent<String> { public class MiniRelay extends AbstractTransparentComponent<String> {
@@ -48,7 +48,7 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Mini Toggle Switch", category = "Electromechanical", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Mini Toggle Switch", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Panel mounted mini toggle switch", stretchable = false, zOrder = IDIYComponent.COMPONENT, description = "Panel mounted mini toggle switch", stretchable = false, zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "SW", autoEdit = false) instanceNamePrefix = "SW", autoEdit = false)
public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchType> { public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchType> {
@@ -51,7 +51,7 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Open 1/4\" Jack", category = "Electromechanical", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Open 1/4\" Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Switchcraft-style open panel mount 1/4\" phono jack, stereo and mono", stretchable = false, description = "Switchcraft-style open panel mount 1/4\" phono jack, stereo and mono", stretchable = false,
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J") zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J")
public class OpenJack1_4 extends AbstractTransparentComponent<String> { public class OpenJack1_4 extends AbstractTransparentComponent<String> {
@@ -49,7 +49,7 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Plastic DC Jack", category = "Electromechanical", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Plastic DC Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Panel mount plastic DC jack", stretchable = false, zOrder = IDIYComponent.COMPONENT, description = "Panel mount plastic DC jack", stretchable = false, zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "J", autoEdit = false) instanceNamePrefix = "J", autoEdit = false)
public class PlasticDCJack extends AbstractTransparentComponent<String> { public class PlasticDCJack extends AbstractTransparentComponent<String> {
@@ -134,7 +134,7 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
body = null; body = null;
} }
@EditableProperty(name = "Pin spacing") @EditableProperty(name = "Pin Spacing")
public Size getPinSpacing() { public Size getPinSpacing() {
return pinSpacing; return pinSpacing;
} }
@@ -146,7 +146,7 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
body = null; body = null;
} }
@EditableProperty(name = "Row spacing") @EditableProperty(name = "Row Spacing")
public Size getRowSpacing() { public Size getRowSpacing() {
return rowSpacing; return rowSpacing;
} }
@@ -527,7 +527,7 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
this.indentColor = indentColor; this.indentColor = indentColor;
} }
@EditableProperty(name = "Display pin numbers") @EditableProperty(name = "Display Pin #s")
public DisplayNumbers getDisplayNumbers() { public DisplayNumbers getDisplayNumbers() {
return displayNumbers; return displayNumbers;
} }
@@ -131,7 +131,7 @@ public class SIL_IC extends AbstractTransparentComponent<String> {
body = null; body = null;
} }
@EditableProperty(name = "Pin spacing") @EditableProperty(name = "Pin Spacing")
public Size getPinSpacing() { public Size getPinSpacing() {
return pinSpacing; return pinSpacing;
} }
@@ -463,7 +463,7 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
this.body = null; this.body = null;
} }
@EditableProperty(name = "Lead length") @EditableProperty(name = "Lead Length")
public Size getLeadLength() { public Size getLeadLength() {
if (leadLength == null) { if (leadLength == null) {
leadLength = LEAD_LENGTH; leadLength = LEAD_LENGTH;
@@ -477,7 +477,7 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
this.body = null; this.body = null;
} }
@EditableProperty(name = "Tab border") @EditableProperty(name = "Tab Border")
public Color getTabBorderColor() { public Color getTabBorderColor() {
return tabBorderColor; return tabBorderColor;
} }
@@ -0,0 +1,623 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
package org.diylc.components.tube;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.Display;
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.TO220Transformer;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
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 = "Sub-Mini Tube", author = "Branislav Stojkovic", category = "Tubes", instanceNamePrefix = "V", description = "Sub-miniature (pencil) vacuum tube", stretchable = false, zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TO220Transformer.class)
public class SubminiTube extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L;
public static Color BODY_COLOR = Color.lightGray;
public static Color BORDER_COLOR = Color.gray;
public static Color PIN_COLOR = Color.decode("#00B2EE");
public static Color PIN_BORDER_COLOR = PIN_COLOR.darker();
public static Color LABEL_COLOR = Color.white;
public static Size PIN_SIZE = new Size(0.03d, SizeUnit.in);
public static Size PIN_SPACING = new Size(0.1d, SizeUnit.in);
public static Size BODY_WIDTH = new Size(0.4d, SizeUnit.in);
public static Size BODY_THICKNESS = new Size(4.5d, SizeUnit.mm);
public static Size BODY_HEIGHT = new Size(9d, SizeUnit.mm);
public static Size DIAMETER = new Size(0.4d, SizeUnit.in);
public static Size LENGTH = new Size(1.375d, SizeUnit.in);
public static Size LEAD_LENGTH = new Size(0.2d, SizeUnit.in);
public static Size LEAD_THICKNESS = new Size(0.8d, SizeUnit.mm);
private String value = "";
private Orientation orientation = Orientation.DEFAULT;
private Point[] controlPoints = new Point[] { new Point(0, 0),
new Point(0, 0), new Point(0, 0) };
transient private Shape[] body;
private Color bodyColor = BODY_COLOR;
private Color borderColor = BORDER_COLOR;
private Display display = Display.NAME;
private boolean folded = false;
private Size leadLength = LEAD_LENGTH;
private PinArrangement leadArrangement = PinArrangement.Circular;
private boolean topLead = false;
private Size diameter = DIAMETER;
private Size length = LENGTH;
private PinCount pinCount = PinCount._8;
private Size leadSpacing = PIN_SPACING;
public SubminiTube() {
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;
}
@Override
public int getControlPointCount() {
return controlPoints.length;
}
@Override
public Point 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(Point point, int index) {
controlPoints[index].setLocation(point);
body = null;
}
private void updateControlPoints() {
int pinSpacing = (int) PIN_SPACING.convertToPixels();
// Update control points.
int x = controlPoints[0].x;
int y = controlPoints[0].y;
int newPointCount = getPinCount().getValue();
// Need a new array
if (newPointCount != controlPoints.length) {
controlPoints = new Point[newPointCount];
for (int i = 0; i < controlPoints.length; i++) {
controlPoints[i] = new Point(x, y);
}
}
int dx;
int dy;
if (folded) {
switch (orientation) {
case DEFAULT:
dx = 0;
dy = pinSpacing;
break;
case _90:
dx = -pinSpacing;
dy = 0;
break;
case _180:
dx = 0;
dy = -pinSpacing;
break;
case _270:
dx = pinSpacing;
dy = 0;
break;
default:
throw new RuntimeException("Unexpected orientation: "
+ orientation);
}
for (int i = 1; i < controlPoints.length; i++) {
controlPoints[i].setLocation(controlPoints[0].x + i * dx, controlPoints[0].y + i * dy);
}
} else {
switch (orientation) {
case DEFAULT:
controlPoints[1].setLocation(x, y + pinSpacing);
controlPoints[2].setLocation(x, y + 2 * pinSpacing);
break;
case _90:
controlPoints[1].setLocation(x - pinSpacing, y);
controlPoints[2].setLocation(x - 2 * pinSpacing, y);
break;
case _180:
controlPoints[1].setLocation(x, y - pinSpacing);
controlPoints[2].setLocation(x, y - 2 * pinSpacing);
break;
case _270:
controlPoints[1].setLocation(x + pinSpacing, y);
controlPoints[2].setLocation(x + 2 * pinSpacing, y);
break;
default:
throw new RuntimeException("Unexpected orientation: "
+ orientation);
}
}
}
public Shape[] getBody() {
if (body == null) {
body = new Shape[2];
int x = controlPoints[0].x;
int y = controlPoints[0].y;
int pinSpacing = (int) PIN_SPACING.convertToPixels();
int bodyWidth = getClosestOdd(BODY_WIDTH.convertToPixels());
int bodyThickness = getClosestOdd(BODY_THICKNESS.convertToPixels());
int bodyHeight = getClosestOdd(BODY_HEIGHT.convertToPixels());
int tabThickness = 0; // (int) TAB_THICKNESS.convertToPixels();
int tabHeight = 0;// (int) TAB_HEIGHT.convertToPixels();
int tabHoleDiameter = 0;// (int)
// TAB_HOLE_DIAMETER.convertToPixels();
double leadLength = getLeadLength().convertToPixels();
switch (orientation) {
case DEFAULT:
if (folded) {
body[0] = new Rectangle2D.Double(x + leadLength, y
+ pinSpacing - bodyWidth / 2, bodyHeight, bodyWidth);
body[1] = new Area(new Rectangle2D.Double(x + leadLength
+ bodyHeight, y + pinSpacing - bodyWidth / 2,
tabHeight, bodyWidth));
((Area) body[1]).subtract(new Area(new Ellipse2D.Double(x
+ leadLength + bodyHeight + tabHeight / 2
- tabHoleDiameter / 2, y + pinSpacing
- tabHoleDiameter / 2, tabHoleDiameter,
tabHoleDiameter)));
} else {
body[0] = new Rectangle2D.Double(x - bodyThickness / 2, y
+ pinSpacing - bodyWidth / 2, bodyThickness,
bodyWidth);
body[1] = new Rectangle2D.Double(x + bodyThickness / 2
- tabThickness, y + pinSpacing - bodyWidth / 2,
tabThickness, bodyWidth);
}
break;
case _90:
if (folded) {
body[0] = new Rectangle2D.Double(x - pinSpacing - bodyWidth
/ 2, y + leadLength, bodyWidth, bodyHeight);
body[1] = new Area(new Rectangle2D.Double(x - pinSpacing
- bodyWidth / 2, y + leadLength + bodyHeight,
bodyWidth, tabHeight));
((Area) body[1]).subtract(new Area(new Ellipse2D.Double(x
- pinSpacing - tabHoleDiameter / 2, y + leadLength
+ bodyHeight + tabHeight / 2 - tabHoleDiameter / 2,
tabHoleDiameter, tabHoleDiameter)));
} else {
body[0] = new Rectangle2D.Double(x - pinSpacing - bodyWidth
/ 2, y - bodyThickness / 2, bodyWidth,
bodyThickness);
body[1] = new Rectangle2D.Double(x - pinSpacing - bodyWidth
/ 2, y + bodyThickness / 2 - tabThickness,
bodyWidth, tabThickness);
}
break;
case _180:
if (folded) {
body[0] = new Rectangle2D.Double(x - leadLength
- bodyHeight, y - pinSpacing - bodyWidth / 2,
bodyHeight, bodyWidth);
body[1] = new Area(new Rectangle2D.Double(x - leadLength
- bodyHeight - tabHeight, y - pinSpacing
- bodyWidth / 2, tabHeight, bodyWidth));
((Area) body[1]).subtract(new Area(new Ellipse2D.Double(x
- leadLength - bodyHeight - tabHeight / 2
- tabHoleDiameter / 2, y - pinSpacing
- tabHoleDiameter / 2, tabHoleDiameter,
tabHoleDiameter)));
} else {
body[0] = new Rectangle2D.Double(x - bodyThickness / 2, y
- pinSpacing - bodyWidth / 2, bodyThickness,
bodyWidth);
body[1] = new Rectangle2D.Double(x - bodyThickness / 2, y
- pinSpacing - bodyWidth / 2, tabThickness,
bodyWidth);
}
break;
case _270:
if (folded) {
body[0] = new Rectangle2D.Double(x + pinSpacing - bodyWidth
/ 2, y - leadLength - bodyHeight, bodyWidth,
bodyHeight);
body[1] = new Area(new Rectangle2D.Double(x + pinSpacing
- bodyWidth / 2, y - leadLength - bodyHeight
- tabHeight, bodyWidth, tabHeight));
((Area) body[1]).subtract(new Area(new Ellipse2D.Double(x
+ pinSpacing - tabHoleDiameter / 2, y - leadLength
- bodyHeight - tabHeight / 2 - tabHoleDiameter / 2,
tabHoleDiameter, tabHoleDiameter)));
} else {
body[0] = new Rectangle2D.Double(x + pinSpacing - bodyWidth
/ 2, y - bodyThickness / 2, bodyWidth,
bodyThickness);
body[1] = new Rectangle2D.Double(x + pinSpacing - bodyWidth
/ 2, y - bodyThickness / 2, bodyWidth, tabThickness);
}
break;
default:
throw new RuntimeException("Unexpected orientation: "
+ orientation);
}
}
return body;
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
Shape mainArea = getBody()[0];
Shape tabArea = getBody()[1];
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 : bodyColor);
g2d.fill(mainArea);
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
// Draw pins.
if (folded) {
int leadThickness = getClosestOdd(LEAD_THICKNESS.convertToPixels());
int leadLength = (int) getLeadLength().convertToPixels();
Color finalPinColor;
Color finalPinBorderColor;
if (outlineMode) {
finalPinColor = new Color(0, 0, 0, 0);
finalPinBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: theme.getOutlineColor();
} else {
finalPinColor = METAL_COLOR;
finalPinBorderColor = METAL_COLOR.darker();
}
for (Point point : controlPoints) {
switch (orientation) {
case DEFAULT:
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness));
g2d.setColor(finalPinBorderColor);
g2d.drawLine(point.x, point.y, point.x + leadLength
- leadThickness / 2, point.y);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness - 2));
g2d.setColor(finalPinColor);
g2d.drawLine(point.x, point.y, point.x + leadLength
- leadThickness / 2, point.y);
break;
case _90:
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness));
g2d.setColor(finalPinBorderColor);
g2d.drawLine(point.x, point.y, point.x, point.y
+ leadLength - leadThickness / 2);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness - 2));
g2d.setColor(finalPinColor);
g2d.drawLine(point.x, point.y, point.x, point.y
+ leadLength - leadThickness / 2);
break;
case _180:
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness));
g2d.setColor(finalPinBorderColor);
g2d.drawLine(point.x, point.y, point.x - leadLength
- leadThickness / 2, point.y);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness - 2));
g2d.setColor(finalPinColor);
g2d.drawLine(point.x, point.y, point.x - leadLength
- leadThickness / 2, point.y);
break;
case _270:
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness));
g2d.setColor(finalPinBorderColor);
g2d.drawLine(point.x, point.y, point.x, point.y
- leadLength);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness - 2));
g2d.setColor(finalPinColor);
g2d.drawLine(point.x, point.y, point.x, point.y
- leadLength);
break;
}
}
} else {
if (!outlineMode) {
for (Point point : controlPoints) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2,
pinSize, pinSize);
g2d.setColor(outlineMode ? theme.getOutlineColor()
: PIN_BORDER_COLOR);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2,
pinSize, pinSize);
}
}
}
// Draw label.
g2d.setFont(project.getFont());
Color finalLabelColor;
if (outlineMode) {
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: theme.getOutlineColor();
} else {
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: LABEL_COLOR;
}
g2d.setColor(finalLabelColor);
String label = "";
label = (getDisplay() == Display.NAME) ? getName() : getValue();
if (getDisplay() == Display.NONE) {
label = "";
}
if (getDisplay() == Display.BOTH) {
label = getName() + " "
+ (getValue() == null ? "" : getValue().toString());
}
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(label, g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
// Center text horizontally and vertically
Rectangle bounds = mainArea.getBounds();
int x = bounds.x + (bounds.width - textWidth) / 2;
int y = bounds.y + (bounds.height - textHeight) / 2
+ fontMetrics.getAscent();
g2d.drawString(label, x, y);
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int margin = 2 * width / 32;
int bodySize = width * 5 / 10;
int tabSize = bodySize * 6 / 10;
int holeSize = 5 * width / 32;
Area a = new Area(new Rectangle2D.Double((width - bodySize) / 2,
margin, bodySize, tabSize));
a.subtract(new Area(new Ellipse2D.Double(width / 2 - holeSize / 2,
margin + tabSize / 2 - holeSize / 2, holeSize, holeSize)));
g2d.setColor(BORDER_COLOR);
g2d.draw(a);
g2d.setColor(BODY_COLOR);
g2d.fillRect((width - bodySize) / 2, margin + tabSize, bodySize,
bodySize);
g2d.setColor(BORDER_COLOR);
g2d.drawRect((width - bodySize) / 2, margin + tabSize, bodySize,
bodySize);
g2d.setColor(METAL_COLOR);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
g2d.drawLine(width / 2, margin + tabSize + bodySize, width / 2, height
- margin);
g2d.drawLine(width / 2 - bodySize / 3, margin + tabSize + bodySize,
width / 2 - bodySize / 3, height - margin);
g2d.drawLine(width / 2 + bodySize / 3, margin + tabSize + bodySize,
width / 2 + bodySize / 3, height - margin);
}
@EditableProperty(name = "Body")
public Color getBodyColor() {
return bodyColor;
}
public void setBodyColor(Color bodyColor) {
this.bodyColor = bodyColor;
}
@EditableProperty(name = "Border")
public Color getBorderColor() {
return borderColor;
}
public void setBorderColor(Color borderColor) {
this.borderColor = borderColor;
}
@EditableProperty
public boolean getFolded() {
return folded;
}
public void setFolded(boolean folded) {
this.folded = folded;
// Invalidate the body
this.body = null;
}
@EditableProperty(name = "Lead Length")
public Size getLeadLength() {
if (leadLength == null) {
leadLength = LEAD_LENGTH;
}
return leadLength;
}
public void setLeadLength(Size leadLength) {
this.leadLength = leadLength;
// Invalidate the body
this.body = null;
}
@EditableProperty
public Display getDisplay() {
if (display == null) {
display = Display.NAME;
}
return display;
}
public void setDisplay(Display display) {
this.display = display;
}
@EditableProperty(name = "Pin Arrangement")
public PinArrangement getPinArrangement() {
return leadArrangement;
}
public void setPinArrangement(PinArrangement pinArrangement) {
this.leadArrangement = pinArrangement;
}
@EditableProperty(name = "Top Lead")
public boolean getTopLead() {
return topLead;
}
public void setTopLead(boolean topLead) {
this.topLead = topLead;
updateControlPoints();
}
@EditableProperty
public Size getDiameter() {
return diameter;
}
public void setDiameter(Size diameter) {
this.diameter = diameter;
updateControlPoints();
}
@EditableProperty
public Size getLength() {
return length;
}
public void setLength(Size length) {
this.length = length;
}
@EditableProperty(name = "Lead Count")
public PinCount getPinCount() {
return pinCount;
}
public void setPinCount(PinCount pinCount) {
this.pinCount = pinCount;
updateControlPoints();
}
@EditableProperty(name = "Lead Spacing")
public Size getLeadSpacing() {
return leadSpacing;
}
public void setLeadSpacing(Size leadSpacing) {
this.leadSpacing = leadSpacing;
updateControlPoints();
}
public static enum PinArrangement {
Inline("In-line"), Circular("Circular");
private String label;
private PinArrangement(String label) {
this.label = label;
}
@Override
public String toString() {
return label;
}
}
public static enum PinCount {
_3, _4, _5, _6, _7, _8, _9, _10;
@Override
public String toString() {
return name().replace("_", "");
}
public int getValue() {
return Integer.parseInt(toString());
}
}
}
Binary file not shown.
Binary file not shown.
@@ -359,7 +359,7 @@ public class ActionFactory {
presenter.loadProjectFromFile(file.getAbsolutePath()); presenter.loadProjectFromFile(file.getAbsolutePath());
// Grab all components and paste them into the main // Grab all components and paste them into the main
// presenter // presenter
plugInPort.pasteComponents(presenter.getCurrentProject().getComponents()); plugInPort.pasteComponents(presenter.getCurrentProject().getComponents(), false);
// Cleanup components in the temp presenter, don't need // Cleanup components in the temp presenter, don't need
// them anymore // them anymore
presenter.selectAll(0); presenter.selectAll(0);
@@ -735,7 +735,7 @@ public class ActionFactory {
try { try {
List<IDIYComponent<?>> components = List<IDIYComponent<?>> components =
(List<IDIYComponent<?>>) clipboard.getData(ComponentTransferable.listFlavor); (List<IDIYComponent<?>>) clipboard.getData(ComponentTransferable.listFlavor);
plugInPort.pasteComponents(cloneComponents(components)); plugInPort.pasteComponents(cloneComponents(components), false);
} catch (Exception ex) { } catch (Exception ex) {
LOG.error("Coule not paste.", ex); LOG.error("Coule not paste.", ex);
} }
@@ -240,9 +240,12 @@ public class TreePanel extends JPanel {
for (final String block : blocks) { for (final String block : blocks) {
Payload payload = new Payload(block, new MouseAdapter() { Payload payload = new Payload(block, new MouseAdapter() {
long previousActionTime = 0;
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
if (e == null || SwingUtilities.isLeftMouseButton(e)) { if (e == null || SwingUtilities.isLeftMouseButton(e) && System.currentTimeMillis() - previousActionTime > 100) {
previousActionTime = System.currentTimeMillis();
try { try {
plugInPort.loadBlock(block); plugInPort.loadBlock(block);
} catch (InvalidBlockException e1) { } catch (InvalidBlockException e1) {
+8
View File
@@ -2042,10 +2042,18 @@
<changeType>IMPROVEMENT</changeType> <changeType>IMPROVEMENT</changeType>
<description>Vastly improve performance of selection aree calculations, especially with bigger layouts</description> <description>Vastly improve performance of selection aree calculations, especially with bigger layouts</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Do not group multiple components automatically after being pasted</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType> <changeType>IMPROVEMENT</changeType>
<description>Better error handing in V2 file importer</description> <description>Better error handing in V2 file importer</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>
<description>Clicking on a building block twice in a row inside the component tree would make the components go back to the top-left corner of the layout</description>
</org.diylc.appframework.update.Change>
</changes> </changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url> <url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version> </org.diylc.appframework.update.Version>