Search in sources :

Example 1 with LibraryNode

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());
        }
    }
}
Also used : ToolTipAction(de.neemann.gui.ToolTipAction) ActionEvent(java.awt.event.ActionEvent) IOException(java.io.IOException) ErrorMessage(de.neemann.gui.ErrorMessage) LibraryNode(de.neemann.digital.draw.library.LibraryNode)

Example 2 with LibraryNode

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();
}
Also used : LibraryNode(de.neemann.digital.draw.library.LibraryNode)

Example 3 with LibraryNode

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>");
        }
    }
}
Also used : TreeMap(java.util.TreeMap) LibraryNode(de.neemann.digital.draw.library.LibraryNode) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 4 with LibraryNode

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);
    }
}
Also used : LibraryNode(de.neemann.digital.draw.library.LibraryNode)

Aggregations

LibraryNode (de.neemann.digital.draw.library.LibraryNode)4 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)1 ErrorMessage (de.neemann.gui.ErrorMessage)1 ToolTipAction (de.neemann.gui.ToolTipAction)1 ActionEvent (java.awt.event.ActionEvent)1 IOException (java.io.IOException)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1