Skip to content

Commit

Permalink
Next (#663)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bancika authored Aug 21, 2021
1 parent 878d048 commit 06cb391
Show file tree
Hide file tree
Showing 15 changed files with 461 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ DIY Layout Creator (DIYLC).
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
*/
package org.diylc.swing.plugins.edit;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
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;

/**
Expand All @@ -37,18 +37,29 @@ DIY Layout Creator (DIYLC).
*
* @author Branislav Stojkovic
*/
public class ComponentTransferable extends ArrayList<IDIYComponent<?>> implements Transferable {
public class ComponentTransferable implements Transferable, Serializable {

private static final long serialVersionUID = 1L;

public static final DataFlavor listFlavor = new DataFlavor(ComponentTransferable.class, "application/diylc");
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(Collection<IDIYComponent<?>> selectedComponents) {
super(selectedComponents);
public ComponentTransferable(List<IDIYComponent<?>> components, Set<Set<IDIYComponent<?>>> groups) {
super();
this.components = components;
this.groups = groups;
}

@Override
Expand All @@ -67,5 +78,13 @@ public DataFlavor[] getTransferDataFlavors() {
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor.equals(listFlavor);
}

public List<IDIYComponent<?>> getComponents() {
return components;
}

public Set<Set<IDIYComponent<?>>> getGroups() {
return groups;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
6 changes: 3 additions & 3 deletions diylc/diylc-core/src/org/diylc/common/IPlugInPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ DIY Layout Creator (DIYLC).
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;
Expand All @@ -37,6 +36,7 @@ DIY Layout Creator (DIYLC).
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;
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 11 additions & 1 deletion diylc/diylc-core/src/org/diylc/common/ObjectCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,22 @@ public Stroke fetchZoomableStroke(float width) {
}

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);
}
Stroke stroke = new BasicStroke(width, cap, BasicStroke.JOIN_ROUND, 0, dash, phase);
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;
}
}
13 changes: 10 additions & 3 deletions diylc/diylc-core/src/org/diylc/presenter/InstantiationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ DIY Layout Creator (DIYLC).
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;
Expand All @@ -34,6 +33,7 @@ DIY Layout Creator (DIYLC).

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;
Expand Down Expand Up @@ -142,7 +142,7 @@ public boolean updatePointByPoint(Point2D scaledPoint) {
}

@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
Expand All @@ -156,6 +156,8 @@ public void pasteComponents(Collection<IDIYComponent<?>> components, Point2D sca
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
Expand Down Expand Up @@ -210,7 +212,12 @@ public void pasteComponents(Collection<IDIYComponent<?>> components, Point2D sca
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());
}
}

/**
Expand Down
9 changes: 5 additions & 4 deletions diylc/diylc-core/src/org/diylc/presenter/Presenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
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;
Expand Down Expand Up @@ -1699,9 +1700,9 @@ public void dragEnded(Point point) {
}

@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(),
Expand Down Expand Up @@ -2975,7 +2976,7 @@ public void loadBlock(String blockName) throws InvalidBlockException {
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();
}
Expand Down
20 changes: 20 additions & 0 deletions diylc/diylc-core/src/org/diylc/presenter/update.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Binary file modified diylc/diylc-library/lib/diylc-core.jar
Binary file not shown.
Loading

0 comments on commit 06cb391

Please sign in to comment.