* flatpak file updated

* add sha generator

* fix mail

* remove mail

* Mini Toggle Switch - lugs do not get rotated when changing orientation;
rotate from the context menu doesn't work

* Added 'SVG Image' component

* Fixed the issue with Perf Board, Vero Board and TriPad Board sometimes
rendering an extra row with pads when there's no space for them

* release 4.18

* Keep grouped components together when pasting

* Added 'Dial Scale' component for designing device face-plates

* dial scale updates

* dial scale tweaks

* release

* release

* release

* release
This commit is contained in:
Bane Stojkovic
2021-08-21 23:19:57 +02:00
committed by GitHub
parent 878d048040
commit 06cb3913ae
15 changed files with 461 additions and 48 deletions
@@ -0,0 +1,90 @@
/*
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.clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import java.util.Set;
import org.diylc.core.IDIYComponent;
/**
* Represents component selection as a {@link List} of {@link IDIYComponent} objects. Implements
* {@link Transferable}, so it is suitable for clipboard usage.
*
* @author Branislav Stojkovic
*/
public class ComponentTransferable implements Transferable, Serializable {
private static final long serialVersionUID = 1L;
public static final DataFlavor listFlavor = new DataFlavor(ComponentTransferable.class, "application/diylc");
private List<IDIYComponent<?>> components;
private Set<Set<IDIYComponent<?>>> groups;
public ComponentTransferable() {
super();
}
public ComponentTransferable(List<IDIYComponent<?>> components) {
super();
this.components = components;
this.groups = null;
}
public ComponentTransferable(List<IDIYComponent<?>> components, Set<Set<IDIYComponent<?>>> groups) {
super();
this.components = components;
this.groups = groups;
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (flavor.equals(listFlavor)) {
return this;
}
throw new UnsupportedFlavorException(flavor);
}
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] {listFlavor};
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor.equals(listFlavor);
}
public List<IDIYComponent<?>> getComponents() {
return components;
}
public Set<Set<IDIYComponent<?>>> getGroups() {
return groups;
}
}
@@ -0,0 +1,76 @@
/*
*
* 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.clipboard;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.log4j.Logger;
import org.diylc.core.IDIYComponent;
public class ComponentTransferableFactory {
private static final Logger LOG = Logger.getLogger(ComponentTransferableFactory.class);
private static ComponentTransferableFactory instance;
public static ComponentTransferableFactory getInstance() {
if (instance == null)
instance = new ComponentTransferableFactory();
return instance;
}
public ComponentTransferable build(Collection<IDIYComponent<?>> selectedComponents, Set<Set<IDIYComponent<?>>> groups) {
Set<IDIYComponent<?>> originalComponentSet = new HashSet<IDIYComponent<?>>(selectedComponents);
List<IDIYComponent<?>> originalComponents = new ArrayList<IDIYComponent<?>>(selectedComponents);
List<IDIYComponent<?>> clonedComponents = originalComponents.stream(
).map(x -> {
try {
return x.clone();
} catch (CloneNotSupportedException e) {
LOG.error(e);
return null;
}
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
Set<Set<IDIYComponent<?>>> clonedGroups = new HashSet<Set<IDIYComponent<?>>>();
for (Set<IDIYComponent<?>> group : groups) {
if (group.isEmpty())
continue;
if (originalComponentSet.contains(group.iterator().next())) {
Set<IDIYComponent<?>> clonedGroup = new HashSet<IDIYComponent<?>>();
clonedGroups.add(clonedGroup);
for (int i = 0; i < originalComponents.size(); i++) {
if (group.contains(originalComponents.get(i))) {
clonedGroup.add(clonedComponents.get(i));
}
}
}
}
return new ComponentTransferable(clonedComponents, clonedGroups);
}
}
@@ -28,7 +28,6 @@ import java.awt.Point;
import java.awt.geom.Area;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -37,6 +36,7 @@ import org.diylc.appframework.simplemq.IMessageListener;
import org.diylc.appframework.simplemq.MessageDispatcher;
import org.diylc.appframework.update.Version;
import org.diylc.appframework.update.VersionNumber;
import org.diylc.clipboard.ComponentTransferable;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
import org.diylc.core.Template;
@@ -242,11 +242,11 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
/**
* Adds a list of components to the project.
*
* @param components
* @param componentTransferable
* @param autoGroup
* @param assignNewNames
*/
void pasteComponents(Collection<IDIYComponent<?>> components, boolean autoGroup, boolean assignNewNames);
void pasteComponents(ComponentTransferable componentTransferable, boolean autoGroup, boolean assignNewNames);
/**
* Duplicates selected components and places them nearby.
@@ -65,7 +65,7 @@ public class ObjectCache {
}
public Stroke fetchStroke(float width, float[] dash, float phase, int cap) {
String key = width + "|" + Arrays.toString(dash) + "|" + phase + "|" + phase;
String key = width + "|" + Arrays.toString(dash) + "|" + phase + "|" + cap;
if (dashStrokeMap.containsKey(key)) {
return dashStrokeMap.get(key);
}
@@ -73,4 +73,14 @@ public class ObjectCache {
dashStrokeMap.put(key, stroke);
return stroke;
}
public Stroke fetchStroke(float width, int cap) {
String key = width + "|" + cap;
if (dashStrokeMap.containsKey(key)) {
return dashStrokeMap.get(key);
}
Stroke stroke = new BasicStroke(width, cap, BasicStroke.JOIN_ROUND);
dashStrokeMap.put(key, stroke);
return stroke;
}
}
@@ -25,7 +25,6 @@ import java.awt.geom.Point2D;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -34,6 +33,7 @@ import java.util.Set;
import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.clipboard.ComponentTransferable;
import org.diylc.common.ComponentType;
import org.diylc.common.IPlugInPort;
import org.diylc.common.Orientation;
@@ -142,7 +142,7 @@ public class InstantiationManager {
}
@SuppressWarnings("unchecked")
public void pasteComponents(Collection<IDIYComponent<?>> components, Point2D scaledPoint, boolean snapToGrid,
public void pasteComponents(ComponentTransferable componentTransferable, Point2D scaledPoint, boolean snapToGrid,
Size gridSpacing, boolean autoGroup, Project currentProject, boolean assignNewNames) {
// Adjust location of components so they are centered under the mouse
// cursor
@@ -156,6 +156,8 @@ public class InstantiationManager {
existingNames.add(c.getName());
List<IDIYComponent<?>> allComponents = new ArrayList<IDIYComponent<?>>(currentProject.getComponents());
List<IDIYComponent<?>> components = componentTransferable.getComponents();
for (IDIYComponent<?> component : components) {
// assign a new name if it already exists in the project
@@ -210,7 +212,12 @@ public class InstantiationManager {
CalcUtils.snapPointToGrid(scaledPoint, gridSpacing);
}
// Update the location according to mouse location
updateSingleClick(scaledPoint, snapToGrid, gridSpacing);
updateSingleClick(scaledPoint, snapToGrid, gridSpacing);
// copy group information if available
if (componentTransferable.getGroups() != null) {
currentProject.getGroups().addAll(componentTransferable.getGroups());
}
}
/**
@@ -57,6 +57,7 @@ import org.diylc.appframework.miscutils.Utils;
import org.diylc.appframework.simplemq.MessageDispatcher;
import org.diylc.appframework.update.Version;
import org.diylc.appframework.update.VersionNumber;
import org.diylc.clipboard.ComponentTransferable;
import org.diylc.common.BuildingBlockPackage;
import org.diylc.common.ComponentType;
import org.diylc.common.DrawOption;
@@ -1699,9 +1700,9 @@ public class Presenter implements IPlugInPort {
}
@Override
public void pasteComponents(Collection<IDIYComponent<?>> components, boolean autoGroup, boolean assignNewNames) {
LOG.info(String.format("pasteComponents(%s, %s, %s)", components, autoGroup, assignNewNames));
instantiationManager.pasteComponents(components, this.previousScaledPoint, isSnapToGrid(),
public void pasteComponents(ComponentTransferable componentTransferable, boolean autoGroup, boolean assignNewNames) {
LOG.info(String.format("pasteComponents(%s, %s, %s)", componentTransferable, autoGroup, assignNewNames));
instantiationManager.pasteComponents(componentTransferable, this.previousScaledPoint, isSnapToGrid(),
currentProject.getGridSpacing(), autoGroup, this.currentProject, assignNewNames);
messageDispatcher.dispatchMessage(EventType.REPAINT);
messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED, instantiationManager.getComponentTypeSlot(),
@@ -2975,7 +2976,7 @@ public class Presenter implements IPlugInPort {
LOG.error("Could not clone component: " + c);
}
// paste them to the project
pasteComponents(clones, true, true);
pasteComponents(new ComponentTransferable(clones), true, true);
} else
throw new InvalidBlockException();
}
@@ -3569,5 +3569,25 @@
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version>
<org.diylc.appframework.update.Version>
<versionNumber>
<major>4</major>
<minor>19</minor>
<build>0</build>
</versionNumber>
<releaseDate>2021-08-21 00:00:00.000 CET</releaseDate>
<name></name>
<changes>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Added 'Dial Scale' component for designing device face-plates</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Keep grouped components together when pasting</description>
</org.diylc.appframework.update.Change>
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version>
</a>
</java.util.Arrays_-ArrayList>