mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 00:44:40 -04:00
Added a refresh to library.
This commit is contained in:
parent
6e947da74f
commit
194da3351e
@ -1,8 +1,5 @@
|
|||||||
package de.neemann.digital.gui;
|
package de.neemann.digital.gui;
|
||||||
|
|
||||||
import de.neemann.digital.core.element.Element;
|
|
||||||
import de.neemann.digital.core.element.ElementAttributes;
|
|
||||||
import de.neemann.digital.core.element.ElementFactory;
|
|
||||||
import de.neemann.digital.core.element.ElementTypeDescription;
|
import de.neemann.digital.core.element.ElementTypeDescription;
|
||||||
import de.neemann.digital.gui.components.CircuitComponent;
|
import de.neemann.digital.gui.components.CircuitComponent;
|
||||||
import de.neemann.digital.gui.draw.elements.Circuit;
|
import de.neemann.digital.gui.draw.elements.Circuit;
|
||||||
@ -17,6 +14,7 @@ import de.process.utils.gui.ToolTipAction;
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
@ -28,10 +26,12 @@ public class LibrarySelector implements ElementNotFoundNotification {
|
|||||||
private JMenu customMenu;
|
private JMenu customMenu;
|
||||||
private InsertHistory insertHistory;
|
private InsertHistory insertHistory;
|
||||||
private CircuitComponent circuitComponent;
|
private CircuitComponent circuitComponent;
|
||||||
|
private ArrayList<String> importedElements;
|
||||||
|
|
||||||
public LibrarySelector(ElementLibrary library) {
|
public LibrarySelector(ElementLibrary library) {
|
||||||
this.library = library;
|
this.library = library;
|
||||||
library.setElementNotFoundNotification(this);
|
library.setElementNotFoundNotification(this);
|
||||||
|
importedElements = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JMenu buildMenu(InsertHistory insertHistory, CircuitComponent circuitComponent) {
|
public JMenu buildMenu(InsertHistory insertHistory, CircuitComponent circuitComponent) {
|
||||||
@ -42,7 +42,7 @@ public class LibrarySelector implements ElementNotFoundNotification {
|
|||||||
customMenu = new JMenu("Custom");
|
customMenu = new JMenu("Custom");
|
||||||
parts.add(customMenu);
|
parts.add(customMenu);
|
||||||
|
|
||||||
ToolTipAction importAction = new ToolTipAction("Import") {
|
customMenu.add(new ToolTipAction("Import") {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JFileChooser fc = Main.getjFileChooser(lastFile);
|
JFileChooser fc = Main.getjFileChooser(lastFile);
|
||||||
@ -50,8 +50,15 @@ public class LibrarySelector implements ElementNotFoundNotification {
|
|||||||
importElement(fc.getSelectedFile());
|
importElement(fc.getSelectedFile());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.setToolTip("Imports a model as a useable Element!");
|
}.setToolTip("Imports a model as a useable Element!"));
|
||||||
customMenu.add(importAction.createJMenuItem());
|
|
||||||
|
customMenu.add(new ToolTipAction("Refresh") {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
for (String name : importedElements)
|
||||||
|
library.removeElement(name);
|
||||||
|
}
|
||||||
|
}.setToolTip("Imports a model as a useable Element!"));
|
||||||
|
|
||||||
|
|
||||||
JMenu subMenu = null;
|
JMenu subMenu = null;
|
||||||
@ -105,15 +112,16 @@ public class LibrarySelector implements ElementNotFoundNotification {
|
|||||||
|
|
||||||
private ElementTypeDescription importElement(File file) {
|
private ElementTypeDescription importElement(File file) {
|
||||||
try {
|
try {
|
||||||
|
System.out.println("load element " + file);
|
||||||
Circuit circuit = Circuit.loadCircuit(file);
|
Circuit circuit = Circuit.loadCircuit(file);
|
||||||
ElementTypeDescription description = new ElementTypeDescription(file.getName(), new ElementFactory() {
|
ElementTypeDescription description =
|
||||||
@Override
|
new ElementTypeDescription(file.getName(),
|
||||||
public Element create(ElementAttributes attributes) {
|
attributes -> new CustomElement(circuit, library),
|
||||||
return new CustomElement(circuit, library);
|
circuit.getInputNames(library))
|
||||||
}
|
.setShortName(createShortName(file));
|
||||||
}, circuit.getInputNames(library)).setShortName(createShortName(file));
|
|
||||||
library.addDescription(description);
|
library.addDescription(description);
|
||||||
customMenu.add(new InsertAction(description.getName(), insertHistory, circuitComponent));
|
customMenu.add(new InsertAction(description.getName(), insertHistory, circuitComponent));
|
||||||
|
importedElements.add(description.getName());
|
||||||
return description;
|
return description;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
new ErrorMessage("error importing model").addCause(e).show();
|
new ErrorMessage("error importing model").addCause(e).show();
|
||||||
|
@ -82,10 +82,6 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
|
|||||||
return pd;
|
return pd;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ElementTypeDescription loadPart(String elementName) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<ElementContainer> iterator() {
|
public Iterator<ElementContainer> iterator() {
|
||||||
return list.iterator();
|
return list.iterator();
|
||||||
@ -95,6 +91,10 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
|
|||||||
this.elementNotFoundNotification = elementNotFoundNotification;
|
this.elementNotFoundNotification = elementNotFoundNotification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeElement(String name) {
|
||||||
|
map.remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
public static class ElementContainer {
|
public static class ElementContainer {
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String treePath;
|
private final String treePath;
|
||||||
|
@ -93,7 +93,7 @@ public class ModelDescription implements Iterable<ModelEntry> {
|
|||||||
thisNet.removePin(p);
|
thisNet.removePin(p);
|
||||||
// and connect it to the nested inner net!
|
// and connect it to the nested inner net!
|
||||||
thisNet.addAll(childNet.getPins());
|
thisNet.addAll(childNet.getPins());
|
||||||
// remove connecte net form child
|
// remove connected net form child
|
||||||
child.remove(childNet);
|
child.remove(childNet);
|
||||||
}
|
}
|
||||||
it.remove();
|
it.remove();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user