use of de.neemann.digital.draw.library.LibraryNode in project Digital by hneemann.
the class LibrarySelector method libraryChanged.
@Override
public void libraryChanged(LibraryNode node) {
componentsMenu.removeAll();
for (LibraryNode n : library.getRoot()) addComponents(componentsMenu, n);
if (library.getCustomNode() != null) {
JMenuItem m = componentsMenu.getItem(componentsMenu.getItemCount() - 1);
if (m instanceof JMenu) {
JMenu menu = (JMenu) m;
menu.addSeparator();
menu.add(new ToolTipAction(Lang.get("menu_update")) {
@Override
public void actionPerformed(ActionEvent e) {
try {
library.updateEntries();
} catch (IOException ex) {
SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorUpdatingLibrary")).addCause(ex));
}
}
}.setToolTip(Lang.get("menu_update_tt")).createJMenuItem());
}
}
}
use of de.neemann.digital.draw.library.LibraryNode in project Digital by hneemann.
the class InsertHistory method updateCustomComponents.
/**
* Updates all custom components.
* If the component no longer exists, it is deleted from the history toolbar.
*/
private void updateCustomComponents() {
Iterator<WrapperAction> it = wrappers.iterator();
while (it.hasNext()) {
WrapperAction w = it.next();
if (w.action.isCustom()) {
LibraryNode n = library.getElementNodeOrNull(w.action.getName());
if (n == null) {
// is'nt there, so delete
removeWrapperFromToolBar(w);
it.remove();
} else
w.update(n);
}
}
bar.revalidate();
}
use of de.neemann.digital.draw.library.LibraryNode in project Digital by hneemann.
the class DocuTest method write74xx.
private void write74xx(File file) throws IOException {
TreeMap<String, String> map = new TreeMap<>(NumStringComparator.getInstance());
ElementLibrary library = new ElementLibrary();
LibraryNode node = library.getRoot().getChild(Lang.get("menu_library"));
if (node != null) {
node.traverse(libraryNode -> {
if (libraryNode.isLeaf()) {
try {
String key = libraryNode.getName();
if (key.endsWith(".dig"))
key = key.substring(0, key.length() - 4);
if (!key.endsWith("-inc")) {
String value = libraryNode.getDescription().getDescription(new ElementAttributes());
map.put(key, value);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
try (Writer w = new OutputStreamWriter(new FileOutputStream(file), "UTF-8")) {
w.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
w.append("<icRoot>\n");
for (Map.Entry<String, String> e : map.entrySet()) {
w.append(" <ic name=\"");
w.append(e.getKey());
w.append("\">");
w.append(e.getValue());
w.append("</ic>\n");
}
w.append("</icRoot>");
}
}
}
use of de.neemann.digital.draw.library.LibraryNode in project Digital by hneemann.
the class LibrarySelector method addComponents.
private void addComponents(JMenu parts, LibraryNode node) {
if (node.isLeaf()) {
if (!node.isHidden())
parts.add(new InsertAction(node, insertHistory, circuitComponent, shapeFactory).createJMenuItem());
} else {
JMenu subMenu = new JMenu(node.getName());
for (LibraryNode child : node) addComponents(subMenu, child);
parts.add(subMenu);
}
}
Aggregations