mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-28 07:28:20 -04:00
added InsertHistory as a LibraryListener
This commit is contained in:
parent
83a97053d4
commit
10d5e48520
@ -304,6 +304,7 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
|
||||
*/
|
||||
public void addListener(LibraryListener listener) {
|
||||
listeners.add(listener);
|
||||
LOGGER.debug("added library listener "+listener.getClass().getSimpleName()+", listeners: "+listeners.size());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -313,6 +314,7 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
|
||||
*/
|
||||
public void removeListener(LibraryListener listener) {
|
||||
listeners.remove(listener);
|
||||
LOGGER.debug("removed library listener "+listener.getClass().getSimpleName()+", listeners: "+listeners.size());
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.neemann.digital.gui;
|
||||
|
||||
import de.neemann.digital.draw.library.ElementLibrary;
|
||||
import de.neemann.digital.draw.library.LibraryListener;
|
||||
import de.neemann.digital.draw.library.LibraryNode;
|
||||
|
||||
@ -25,13 +24,11 @@ public class InsertHistory implements LibraryListener {
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param library the library
|
||||
* @param bar the toolbar to put the elements to
|
||||
*/
|
||||
public InsertHistory(ElementLibrary library, JToolBar bar) {
|
||||
public InsertHistory(JToolBar bar) {
|
||||
this.bar = bar;
|
||||
wrappers = new ArrayList<>();
|
||||
library.addListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,10 +79,16 @@ public class InsertHistory implements LibraryListener {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void libraryChanged(LibraryNode node) {
|
||||
removeAllCustomComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* remove custom components
|
||||
* remove all custom components
|
||||
*/
|
||||
public void removeCustom() {
|
||||
private void removeAllCustomComponents() {
|
||||
Iterator<WrapperAction> it = wrappers.iterator();
|
||||
while (it.hasNext()) {
|
||||
WrapperAction w = it.next();
|
||||
@ -97,11 +100,6 @@ public class InsertHistory implements LibraryListener {
|
||||
bar.revalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void libraryChanged(LibraryNode node) {
|
||||
|
||||
}
|
||||
|
||||
private final class WrapperAction extends AbstractAction {
|
||||
private final InsertAction action;
|
||||
private int componentPosition;
|
||||
|
@ -35,7 +35,6 @@ public class LibrarySelector implements LibraryListener {
|
||||
*/
|
||||
public LibrarySelector(ElementLibrary library, ShapeFactory shapeFactory) {
|
||||
this.library = library;
|
||||
library.addListener(this);
|
||||
this.shapeFactory = shapeFactory;
|
||||
}
|
||||
|
||||
|
@ -222,8 +222,10 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
|
||||
|
||||
toolBar.addSeparator();
|
||||
|
||||
insertHistory = new InsertHistory(library, toolBar);
|
||||
insertHistory = new InsertHistory(toolBar);
|
||||
library.addListener(insertHistory);
|
||||
final LibrarySelector librarySelector = new LibrarySelector(library, shapeFactory);
|
||||
library.addListener(librarySelector);
|
||||
menuBar.add(librarySelector.buildMenu(insertHistory, circuitComponent));
|
||||
|
||||
addWindowListener(new ClosingWindowListener(this, this));
|
||||
|
@ -37,7 +37,7 @@ public abstract class ToolTipAction extends AbstractAction {
|
||||
* @param icon the icon to set
|
||||
*/
|
||||
public void setIcon(Icon icon) {
|
||||
putValue("SmallIcon", icon);
|
||||
putValue(Action.SMALL_ICON, icon);
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user