mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
Added ability to lock and unlock individual components from the context
menu
This commit is contained in:
@@ -383,5 +383,10 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
|
||||
*
|
||||
* @param editor
|
||||
*/
|
||||
void applyEditor(IProjectEditor editor);
|
||||
void applyEditor(IProjectEditor editor);
|
||||
|
||||
/**
|
||||
* Locks or unlocks a single component.
|
||||
*/
|
||||
void lockComponent(IDIYComponent<?> c, boolean locked);
|
||||
}
|
||||
|
||||
@@ -51,10 +51,11 @@ public interface ISelectionProcessor {
|
||||
* Finds all components at the specified location, sorted by z-index from top to bottom. Location
|
||||
* depends on the current zoom level.
|
||||
*
|
||||
* @param point
|
||||
* @param point
|
||||
* @param includeLocked
|
||||
* @return
|
||||
*/
|
||||
List<IDIYComponent<?>> findComponentsAt(Point point);
|
||||
List<IDIYComponent<?>> findComponentsAt(Point point, boolean includeLocked);
|
||||
|
||||
/**
|
||||
* Expands the current selection to include surrounding components. Options are controlled with
|
||||
|
||||
@@ -67,7 +67,8 @@ public class Project implements Serializable, Cloneable {
|
||||
private Integer dotSpacing;
|
||||
private List<IDIYComponent<?>> components;
|
||||
private Set<Set<IDIYComponent<?>>> groups;
|
||||
private Set<Integer> lockedLayers;
|
||||
private Set<Integer> lockedLayers;
|
||||
private Set<IDIYComponent<?>> lockedComponents;
|
||||
private Set<Integer> hiddenLayers;
|
||||
private Font font = DEFAULT_FONT;
|
||||
|
||||
@@ -75,7 +76,8 @@ public class Project implements Serializable, Cloneable {
|
||||
components = new ArrayList<IDIYComponent<?>>();
|
||||
groups = new HashSet<Set<IDIYComponent<?>>>();
|
||||
lockedLayers = new HashSet<Integer>();
|
||||
hiddenLayers = new HashSet<Integer>();
|
||||
hiddenLayers = new HashSet<Integer>();
|
||||
lockedComponents = new HashSet<IDIYComponent<?>>();
|
||||
title = DEFAULT_TITLE;
|
||||
author = System.getProperty("user.name");
|
||||
width = DEFAULT_WIDTH;
|
||||
@@ -165,6 +167,12 @@ public class Project implements Serializable, Cloneable {
|
||||
*/
|
||||
public Set<Set<IDIYComponent<?>>> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
public Set<IDIYComponent<?>> getLockedComponents() {
|
||||
if (lockedComponents == null)
|
||||
lockedComponents = new HashSet<IDIYComponent<?>>();
|
||||
return lockedComponents;
|
||||
}
|
||||
|
||||
public Set<Integer> getLockedLayers() {
|
||||
@@ -289,6 +297,11 @@ public class Project implements Serializable, Cloneable {
|
||||
return false;
|
||||
} else if (!lockedLayers.equals(other.lockedLayers))
|
||||
return false;
|
||||
if (getLockedComponents() == null) {
|
||||
if (other.lockedComponents != null)
|
||||
return false;
|
||||
} else if (!getLockedComponents().equals(other.lockedComponents))
|
||||
return false;
|
||||
if (hiddenLayers == null) {
|
||||
if (other.hiddenLayers != null)
|
||||
return false;
|
||||
@@ -328,14 +341,14 @@ public class Project implements Serializable, Cloneable {
|
||||
project.setHeight(this.getHeight());
|
||||
project.setWidth(this.getWidth());
|
||||
project.getLockedLayers().addAll(this.getLockedLayers());
|
||||
project.getHiddenLayers().addAll(this.getHiddenLayers());
|
||||
project.getHiddenLayers().addAll(this.getHiddenLayers());
|
||||
project.setFont(this.getFont());
|
||||
|
||||
Map<IDIYComponent<?>, IDIYComponent<?>> cloneMap = new HashMap<IDIYComponent<?>, IDIYComponent<?>>();
|
||||
|
||||
for (IDIYComponent<?> component : this.components) {
|
||||
try {
|
||||
IDIYComponent<?> clone = component.clone();
|
||||
IDIYComponent<?> clone = component.clone();
|
||||
project.getComponents().add(clone);
|
||||
cloneMap.put(component, clone);
|
||||
} catch (CloneNotSupportedException e) {
|
||||
@@ -349,6 +362,10 @@ public class Project implements Serializable, Cloneable {
|
||||
cloneGroup.add(cloneMap.get(component));
|
||||
}
|
||||
project.groups.add(cloneGroup);
|
||||
}
|
||||
|
||||
for (IDIYComponent<?> component : this.getLockedComponents()) {
|
||||
project.lockedComponents.add(cloneMap.get(component));
|
||||
}
|
||||
return project;
|
||||
}
|
||||
|
||||
@@ -529,12 +529,12 @@ public class Presenter implements IPlugInPort {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<IDIYComponent<?>> findComponentsAtScaled(Point point) {
|
||||
public List<IDIYComponent<?>> findComponentsAtScaled(Point point, boolean includeLocked) {
|
||||
List<IDIYComponent<?>> components = drawingManager.findComponentsAt(point, currentProject);
|
||||
Iterator<IDIYComponent<?>> iterator = components.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
IDIYComponent<?> component = iterator.next();
|
||||
if (isComponentLocked(component) || !isComponentVisible(component)) {
|
||||
if ((includeLocked ? isComponentLayerLocked(component) : isComponentLocked(component)) || !isComponentVisible(component)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
@@ -542,9 +542,9 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IDIYComponent<?>> findComponentsAt(Point point) {
|
||||
public List<IDIYComponent<?>> findComponentsAt(Point point, boolean includeLocked) {
|
||||
Point scaledPoint = scalePoint(point);
|
||||
List<IDIYComponent<?>> components = findComponentsAtScaled(scaledPoint);
|
||||
List<IDIYComponent<?>> components = findComponentsAtScaled(scaledPoint, includeLocked);
|
||||
return components;
|
||||
}
|
||||
|
||||
@@ -654,7 +654,7 @@ public class Presenter implements IPlugInPort {
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
} else {
|
||||
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>(selectedComponents);
|
||||
List<IDIYComponent<?>> components = findComponentsAtScaled(scaledPoint);
|
||||
List<IDIYComponent<?>> components = findComponentsAtScaled(scaledPoint, false);
|
||||
// If there's nothing under mouse cursor deselect all.
|
||||
if (components.isEmpty()) {
|
||||
if (!ctrlDown) {
|
||||
@@ -1087,7 +1087,7 @@ public class Presenter implements IPlugInPort {
|
||||
this.preDragProject = currentProject.clone();
|
||||
Point scaledPoint = scalePoint(point);
|
||||
this.previousDragPoint = scaledPoint;
|
||||
List<IDIYComponent<?>> components = forceSelectionRect ? null : findComponentsAtScaled(scaledPoint);
|
||||
List<IDIYComponent<?>> components = forceSelectionRect ? null : findComponentsAtScaled(scaledPoint, false);
|
||||
if (controlPointMap != null && !this.controlPointMap.isEmpty()) {
|
||||
// If we're dragging control points reset selection.
|
||||
updateSelection(new ArrayList<IDIYComponent<?>>(this.controlPointMap.keySet()));
|
||||
@@ -2765,9 +2765,41 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
return lockedComponents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lockComponent(IDIYComponent<?> c, boolean locked) {
|
||||
LOG.debug(String.format("lockComponent(%s, %s)", c.getName(), locked));
|
||||
Project oldProject = currentProject.clone();
|
||||
try {
|
||||
if (locked) {
|
||||
currentProject.getLockedComponents().add(c);
|
||||
selectedComponents.remove(c);
|
||||
} else {
|
||||
currentProject.getLockedComponents().remove(c);
|
||||
}
|
||||
} finally {
|
||||
// Notify the listeners.
|
||||
if (!oldProject.equals(currentProject)) {
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, currentProject.clone(),
|
||||
locked ? "Lock Component" : "Unlock Component");
|
||||
projectFileManager.notifyFileChange();
|
||||
}
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
if (locked)
|
||||
updateSelection(selectedComponents);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private boolean isComponentLocked(IDIYComponent<?> component) {
|
||||
ComponentType componentType =
|
||||
ComponentProcessor.getInstance().extractComponentTypeFrom(
|
||||
(Class<? extends IDIYComponent<?>>) component.getClass());
|
||||
return currentProject.getLockedLayers().contains((int) Math.round(componentType.getZOrder())) || currentProject.getLockedComponents().contains(component);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private boolean isComponentLayerLocked(IDIYComponent<?> component) {
|
||||
ComponentType componentType =
|
||||
ComponentProcessor.getInstance().extractComponentTypeFrom(
|
||||
(Class<? extends IDIYComponent<?>>) component.getClass());
|
||||
|
||||
@@ -3002,9 +3002,17 @@
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>"Add Flexible Leads" action added in the context menu that replaces straight leads of leaded components with flexible leads and adds leds to some components that do not have them (e.g. Transistors, Tube Sockets, Potentiometers, etc)</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added ability to lock and unlock individual components from the context menu</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added "Rotary Selector Switch" component</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added support for automated regression testing of core functionalities which should reduce regression bugs in the long run</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
|
||||
@@ -65,7 +65,8 @@ public enum IconLoader {
|
||||
"splash_electrolytic.png"), SplashFilm("splash_film.png"), Splash("splash.png"), Help("help2.png"), ScrollInformation("scroll_information.png"),
|
||||
Node("node.png"), Web("web.png"), Guitar("guitar.png"), Scientist("scientist.png"), StarGrey("star_grey.png"), StarBlue("star_blue.png"),
|
||||
JarBeanInto("jar_bean_into.png"), GraphEdgeDirected("graph_edge_directed.png"), LaserPointer("laserpointer.png"), TapeMeasure("tape_measure1.png"),
|
||||
Elements("elements1.png"), GraphNodes("graph_nodes.png"), User("user1.png"), FlexibleLeads("flexible_leads.png"), Pads("pads.png");
|
||||
Elements("elements1.png"), GraphNodes("graph_nodes.png"), User("user1.png"), FlexibleLeads("flexible_leads.png"), Pads("pads.png"), Lock("lock.png"),
|
||||
Unlock("lock_open.png");
|
||||
|
||||
protected String name;
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 764 B |
Binary file not shown.
|
After Width: | Height: | Size: 815 B |
@@ -40,6 +40,7 @@ import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPopupMenu;
|
||||
@@ -82,6 +83,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
private JMenu expandMenu;
|
||||
private JMenu transformMenu;
|
||||
private JMenu applyTemplateMenu;
|
||||
private JMenu lockMenu;
|
||||
private JMenu unlockMenu;
|
||||
|
||||
private ActionFactory.CutAction cutAction;
|
||||
private ActionFactory.CopyAction copyAction;
|
||||
@@ -210,21 +213,23 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
updateZeroLocation();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.RULER_IN_SUBDIVISION_KEY,
|
||||
new IConfigListener() {
|
||||
|
||||
@Override
|
||||
public void valueChanged(String key, Object value) {
|
||||
getScrollPane().setInSubdivision(IPlugInPort.RULER_IN_SUBDIVISION_10.equalsIgnoreCase(value == null ? null : value.toString()) ? InchSubdivision.BASE_10 : InchSubdivision.BASE_2);
|
||||
public void valueChanged(String key, Object value) {
|
||||
getScrollPane().setInSubdivision(IPlugInPort.RULER_IN_SUBDIVISION_10
|
||||
.equalsIgnoreCase(value == null ? null : value.toString()) ? InchSubdivision.BASE_10
|
||||
: InchSubdivision.BASE_2);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA,
|
||||
new IConfigListener() {
|
||||
|
||||
@Override
|
||||
public void valueChanged(String key, Object value) {
|
||||
public void valueChanged(String key, Object value) {
|
||||
canvasPanel.repaint();
|
||||
}
|
||||
});
|
||||
@@ -331,18 +336,21 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
private RulerScrollPane getScrollPane() {
|
||||
if (scrollPane == null) {
|
||||
String subdivision = ConfigurationManager.getInstance().readString(IPlugInPort.RULER_IN_SUBDIVISION_KEY, IPlugInPort.RULER_IN_SUBDIVISION_DEFAULT);
|
||||
|
||||
String subdivision = ConfigurationManager.getInstance().readString(
|
||||
IPlugInPort.RULER_IN_SUBDIVISION_KEY, IPlugInPort.RULER_IN_SUBDIVISION_DEFAULT);
|
||||
|
||||
scrollPane = new RulerScrollPane(getCanvasPanel(),
|
||||
new ProjectDrawingProvider(plugInPort, true, false, true),
|
||||
new Size(1d, SizeUnit.cm).convertToPixels(), new Size(1d, SizeUnit.in).convertToPixels(),
|
||||
IPlugInPort.RULER_IN_SUBDIVISION_10.equalsIgnoreCase(subdivision) ? InchSubdivision.BASE_10 : InchSubdivision.BASE_2);
|
||||
IPlugInPort.RULER_IN_SUBDIVISION_10.equalsIgnoreCase(subdivision)
|
||||
? InchSubdivision.BASE_10
|
||||
: InchSubdivision.BASE_2);
|
||||
boolean metric = ConfigurationManager.getInstance().readBoolean(IPlugInPort.METRIC_KEY, true);
|
||||
|
||||
boolean useHardwareAcceleration =
|
||||
ConfigurationManager.getInstance().readBoolean(IPlugInPort.HARDWARE_ACCELERATION, false);
|
||||
scrollPane.setUseHardwareAcceleration(useHardwareAcceleration);
|
||||
scrollPane.setMetric(metric);
|
||||
scrollPane.setMetric(metric);
|
||||
scrollPane.setWheelScrollingEnabled(true);
|
||||
scrollPane.addUnitListener(new IRulerListener() {
|
||||
|
||||
@@ -434,6 +442,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
private void showPopupAt(int x, int y) {
|
||||
updateSelectionMenu(x, y);
|
||||
updateApplyTemplateMenu();
|
||||
updateLock(x, y);
|
||||
getPopupMenu().show(canvasPanel, x, y);
|
||||
}
|
||||
|
||||
@@ -455,6 +464,9 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
popupMenu.add(getSaveAsBlockAction());
|
||||
popupMenu.add(getExpandMenu());
|
||||
popupMenu.addSeparator();
|
||||
popupMenu.add(getLockMenu());
|
||||
popupMenu.add(getUnlockMenu());
|
||||
popupMenu.addSeparator();
|
||||
popupMenu.add(getFlexibleLeadsAction());
|
||||
popupMenu.addSeparator();
|
||||
popupMenu.add(ActionFactory.getInstance().createEditProjectAction(plugInPort));
|
||||
@@ -481,6 +493,22 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
return expandMenu;
|
||||
}
|
||||
|
||||
public JMenu getLockMenu() {
|
||||
if (lockMenu == null) {
|
||||
lockMenu = new JMenu("Lock");
|
||||
lockMenu.setIcon(IconLoader.Lock.getIcon());
|
||||
}
|
||||
return lockMenu;
|
||||
}
|
||||
|
||||
public JMenu getUnlockMenu() {
|
||||
if (unlockMenu == null) {
|
||||
unlockMenu = new JMenu("Unlock");
|
||||
unlockMenu.setIcon(IconLoader.Unlock.getIcon());
|
||||
}
|
||||
return unlockMenu;
|
||||
}
|
||||
|
||||
public JMenu getTransformMenu() {
|
||||
if (transformMenu == null) {
|
||||
transformMenu = new JMenu("Transform Selection");
|
||||
@@ -512,7 +540,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
private void updateSelectionMenu(int x, int y) {
|
||||
getSelectionMenu().removeAll();
|
||||
for (IDIYComponent<?> component : plugInPort.findComponentsAt(new Point(x, y))) {
|
||||
for (IDIYComponent<?> component : plugInPort.findComponentsAt(new Point(x, y), false)) {
|
||||
JMenuItem item = new JMenuItem(component.getName());
|
||||
final IDIYComponent<?> finalComponent = component;
|
||||
item.addActionListener(new ActionListener() {
|
||||
@@ -529,6 +557,30 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLock(int x, int y) {
|
||||
getLockMenu().removeAll();
|
||||
getUnlockMenu().removeAll();
|
||||
List<IDIYComponent<?>> componentsAt = plugInPort.findComponentsAt(new Point(x, y), true);
|
||||
if (componentsAt.size() == 0) {
|
||||
getLockMenu().setEnabled(false);
|
||||
getUnlockMenu().setEnabled(false);
|
||||
} else {
|
||||
boolean hasLocked = false;
|
||||
boolean hasUnlocked = false;
|
||||
for (IDIYComponent<?> c : componentsAt) {
|
||||
if (plugInPort.getCurrentProject().getLockedComponents().contains(c)) {
|
||||
getUnlockMenu().add(new LockAction(c, false));
|
||||
hasLocked = true;
|
||||
} else {
|
||||
getLockMenu().add(new LockAction(c, true));
|
||||
hasUnlocked = true;
|
||||
}
|
||||
}
|
||||
getLockMenu().setEnabled(hasUnlocked);
|
||||
getUnlockMenu().setEnabled(hasLocked);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateApplyTemplateMenu() {
|
||||
getApplyTemplateMenu().removeAll();
|
||||
List<Template> templates = null;
|
||||
@@ -634,7 +686,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
}
|
||||
return mirrorVerticallyAction;
|
||||
}
|
||||
|
||||
|
||||
public ActionFactory.FlexibleLeadsAction getFlexibleLeadsAction() {
|
||||
if (flexibleLeadsAction == null)
|
||||
flexibleLeadsAction = ActionFactory.getInstance().createFlexibleLeadsAction(plugInPort);
|
||||
@@ -716,7 +768,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
@Override
|
||||
public EnumSet<EventType> getSubscribedEventTypes() {
|
||||
return EnumSet.of(EventType.PROJECT_LOADED, EventType.ZOOM_CHANGED, EventType.REPAINT, EventType.SCROLL_TO);
|
||||
return EnumSet.of(EventType.PROJECT_LOADED, EventType.ZOOM_CHANGED, EventType.REPAINT,
|
||||
EventType.SCROLL_TO);
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@@ -773,8 +826,10 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
Rectangle visibleRect2 = canvasPanel.getVisibleRect();
|
||||
Rectangle2D targetRect = (Rectangle2D) params[0];
|
||||
if (targetRect != null)
|
||||
canvasPanel.scrollRectToVisible(new Rectangle((int)(targetRect.getCenterX() - visibleRect2.width / 2),
|
||||
(int)(targetRect.getCenterY() - visibleRect2.height / 2), visibleRect2.width, visibleRect2.height));
|
||||
canvasPanel.scrollRectToVisible(
|
||||
new Rectangle((int) (targetRect.getCenterX() - visibleRect2.width / 2),
|
||||
(int) (targetRect.getCenterY() - visibleRect2.height / 2), visibleRect2.width,
|
||||
visibleRect2.height));
|
||||
break;
|
||||
}
|
||||
// }
|
||||
@@ -812,4 +867,25 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
double extraSpace = CanvasPlugin.this.plugInPort.getExtraSpace();
|
||||
getScrollPane().setZeroLocation(new Point2D.Double(extraSpace, extraSpace));
|
||||
}
|
||||
|
||||
class LockAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private IDIYComponent<?> component;
|
||||
private boolean locked;
|
||||
|
||||
public LockAction(IDIYComponent<?> component, boolean locked) {
|
||||
super();
|
||||
this.locked = locked;
|
||||
this.component = component;
|
||||
putValue(AbstractAction.NAME, component.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
plugInPort.lockComponent(component, locked);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user