From 2262f8863fd554645299fbeeecebe18faad5b1f9 Mon Sep 17 00:00:00 2001 From: hneemann Date: Sat, 25 Mar 2017 23:27:53 +0100 Subject: [PATCH] fixed a bug in the insert history --- .../de/neemann/digital/gui/InsertAction.java | 7 +++++++ .../de/neemann/digital/gui/InsertHistory.java | 18 ++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/neemann/digital/gui/InsertAction.java b/src/main/java/de/neemann/digital/gui/InsertAction.java index b31d995a0..09440a455 100644 --- a/src/main/java/de/neemann/digital/gui/InsertAction.java +++ b/src/main/java/de/neemann/digital/gui/InsertAction.java @@ -62,6 +62,13 @@ public final class InsertAction extends ToolTipAction { return node.getDescriptionOrNull() instanceof ElementLibrary.ElementTypeDescriptionCustom; } + /** + * @return the name of the node to insert + */ + public String getName() { + return node.getName(); + } + private static ImageIcon createIcon(LibraryNode node, ShapeFactory shapeFactory) { // doesn't load the description if only the icon is needed // create action without an icon instead diff --git a/src/main/java/de/neemann/digital/gui/InsertHistory.java b/src/main/java/de/neemann/digital/gui/InsertHistory.java index 205d015dc..e49374874 100644 --- a/src/main/java/de/neemann/digital/gui/InsertHistory.java +++ b/src/main/java/de/neemann/digital/gui/InsertHistory.java @@ -35,7 +35,7 @@ public class InsertHistory { * * @param action the action */ - public void add(AbstractAction action) { + public void add(InsertAction action) { if (!contains(action)) { WrapperAction wrapper = new WrapperAction(action, bar.getComponentCount()); wrappers.add(wrapper); @@ -69,9 +69,9 @@ public class InsertHistory { return found; } - private boolean contains(AbstractAction action) { + private boolean contains(InsertAction action) { for (WrapperAction wrapper : wrappers) - if (wrapper.action == action) + if (wrapper.action.getName().equals(action.getName())) return true; return false; } @@ -83,22 +83,20 @@ public class InsertHistory { Iterator it = wrappers.iterator(); while (it.hasNext()) { WrapperAction w = it.next(); - if (w.action instanceof InsertAction) { - if (((InsertAction) w.action).isCustom()) { - removeWrapperFromBar(w); - it.remove(); - } + if (w.action.isCustom()) { + removeWrapperFromBar(w); + it.remove(); } } bar.revalidate(); } private final class WrapperAction extends AbstractAction { - private final AbstractAction action; + private final InsertAction action; private int componentPosition; private int time; - private WrapperAction(AbstractAction action, int componentPosition) { + private WrapperAction(InsertAction action, int componentPosition) { super(action.getValue(Action.NAME).toString(), (Icon) action.getValue(Action.SMALL_ICON)); this.action = action; this.componentPosition = componentPosition;