Search in sources :

Example 11 with Tool

use of com.cburch.logisim.tools.Tool in project logisim-evolution by reds-heig.

the class ToolboxManip method menuRequested.

public JPopupMenu menuRequested(ProjectExplorerEvent event) {
    Object clicked = event.getTarget();
    if (clicked instanceof ProjectExplorerToolNode) {
        Tool baseTool = ((ProjectExplorerToolNode) clicked).getValue();
        if (baseTool instanceof AddTool) {
            AddTool tool = (AddTool) baseTool;
            ComponentFactory source = tool.getFactory();
            if (source instanceof SubcircuitFactory) {
                Circuit circ = ((SubcircuitFactory) source).getSubcircuit();
                return Popups.forCircuit(proj, tool, circ);
            } else {
                return null;
            }
        } else {
            return null;
        }
    } else if (clicked instanceof ProjectExplorerLibraryNode) {
        Library lib = ((ProjectExplorerLibraryNode) clicked).getValue();
        if (lib == proj.getLogisimFile()) {
            return Popups.forProject(proj);
        } else {
            boolean is_top = event.getTreePath().getPathCount() <= 2;
            return Popups.forLibrary(proj, lib, is_top);
        }
    } else {
        return null;
    }
}
Also used : ProjectExplorerToolNode(com.cburch.logisim.gui.generic.ProjectExplorerToolNode) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) Circuit(com.cburch.logisim.circuit.Circuit) AddTool(com.cburch.logisim.tools.AddTool) ProjectExplorerLibraryNode(com.cburch.logisim.gui.generic.ProjectExplorerLibraryNode) Library(com.cburch.logisim.tools.Library) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool)

Example 12 with Tool

use of com.cburch.logisim.tools.Tool in project logisim-evolution by reds-heig.

the class ToolboxManip method deleteRequested.

public void deleteRequested(ProjectExplorerEvent event) {
    Object request = event.getTarget();
    if (request instanceof ProjectExplorerLibraryNode) {
        Library lib = ((ProjectExplorerLibraryNode) request).getValue();
        ProjectLibraryActions.doUnloadLibrary(proj, lib);
    } else if (request instanceof ProjectExplorerToolNode) {
        Tool tool = ((ProjectExplorerToolNode) request).getValue();
        if (tool instanceof AddTool) {
            ComponentFactory factory = ((AddTool) tool).getFactory();
            if (factory instanceof SubcircuitFactory) {
                SubcircuitFactory circFact = (SubcircuitFactory) factory;
                ProjectCircuitActions.doRemoveCircuit(proj, circFact.getSubcircuit());
            }
        }
    }
}
Also used : ProjectExplorerToolNode(com.cburch.logisim.gui.generic.ProjectExplorerToolNode) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) ProjectExplorerLibraryNode(com.cburch.logisim.gui.generic.ProjectExplorerLibraryNode) Library(com.cburch.logisim.tools.Library) AddTool(com.cburch.logisim.tools.AddTool) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool)

Example 13 with Tool

use of com.cburch.logisim.tools.Tool in project logisim-evolution by reds-heig.

the class FileStatistics method sortCounts.

private static List<Count> sortCounts(Map<ComponentFactory, Count> counts, LogisimFile file) {
    List<Count> ret = new ArrayList<Count>();
    for (AddTool tool : file.getTools()) {
        ComponentFactory factory = tool.getFactory();
        Count count = counts.get(factory);
        if (count != null) {
            count.library = file;
            ret.add(count);
        }
    }
    for (Library lib : file.getLibraries()) {
        for (Tool tool : lib.getTools()) {
            if (tool instanceof AddTool) {
                ComponentFactory factory = ((AddTool) tool).getFactory();
                Count count = counts.get(factory);
                if (count != null) {
                    count.library = lib;
                    ret.add(count);
                }
            }
        }
    }
    return ret;
}
Also used : ComponentFactory(com.cburch.logisim.comp.ComponentFactory) ArrayList(java.util.ArrayList) AddTool(com.cburch.logisim.tools.AddTool) Library(com.cburch.logisim.tools.Library) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool)

Example 14 with Tool

use of com.cburch.logisim.tools.Tool in project logisim-evolution by reds-heig.

the class LoadedLibrary method replaceAll.

private static void replaceAll(Map<ComponentFactory, ComponentFactory> compMap, Map<Tool, Tool> toolMap) {
    for (Project proj : Projects.getOpenProjects()) {
        Tool oldTool = proj.getTool();
        Circuit oldCircuit = proj.getCurrentCircuit();
        if (toolMap.containsKey(oldTool)) {
            proj.setTool(toolMap.get(oldTool));
        }
        SubcircuitFactory oldFactory = oldCircuit.getSubcircuitFactory();
        if (compMap.containsKey(oldFactory)) {
            SubcircuitFactory newFactory;
            newFactory = (SubcircuitFactory) compMap.get(oldFactory);
            proj.setCurrentCircuit(newFactory.getSubcircuit());
        }
        replaceAll(proj.getLogisimFile(), compMap, toolMap);
    }
    for (LogisimFile file : LibraryManager.instance.getLogisimLibraries()) {
        replaceAll(file, compMap, toolMap);
    }
}
Also used : Project(com.cburch.logisim.proj.Project) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) Circuit(com.cburch.logisim.circuit.Circuit) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool)

Example 15 with Tool

use of com.cburch.logisim.tools.Tool in project logisim-evolution by reds-heig.

the class LoadedLibrary method resolveChanges.

private void resolveChanges(Library old) {
    if (listeners.isEmpty())
        return;
    if (!base.getDisplayName().equals(old.getDisplayName())) {
        fireLibraryEvent(LibraryEvent.SET_NAME, base.getDisplayName());
    }
    HashSet<Library> changes = new HashSet<Library>(old.getLibraries());
    changes.removeAll(base.getLibraries());
    for (Library lib : changes) {
        fireLibraryEvent(LibraryEvent.REMOVE_LIBRARY, lib);
    }
    changes.clear();
    changes.addAll(base.getLibraries());
    changes.removeAll(old.getLibraries());
    for (Library lib : changes) {
        fireLibraryEvent(LibraryEvent.ADD_LIBRARY, lib);
    }
    HashMap<ComponentFactory, ComponentFactory> componentMap;
    HashMap<Tool, Tool> toolMap;
    componentMap = new HashMap<ComponentFactory, ComponentFactory>();
    toolMap = new HashMap<Tool, Tool>();
    for (Tool oldTool : old.getTools()) {
        Tool newTool = base.getTool(oldTool.getName());
        toolMap.put(oldTool, newTool);
        if (oldTool instanceof AddTool) {
            ComponentFactory oldFactory = ((AddTool) oldTool).getFactory();
            if (newTool != null && newTool instanceof AddTool) {
                ComponentFactory newFactory = ((AddTool) newTool).getFactory();
                componentMap.put(oldFactory, newFactory);
            } else {
                componentMap.put(oldFactory, null);
            }
        }
    }
    replaceAll(componentMap, toolMap);
    HashSet<Tool> toolChanges = new HashSet<Tool>(old.getTools());
    toolChanges.removeAll(toolMap.keySet());
    for (Tool tool : toolChanges) {
        fireLibraryEvent(LibraryEvent.REMOVE_TOOL, tool);
    }
    toolChanges = new HashSet<Tool>(base.getTools());
    toolChanges.removeAll(toolMap.values());
    for (Tool tool : toolChanges) {
        fireLibraryEvent(LibraryEvent.ADD_TOOL, tool);
    }
}
Also used : ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Library(com.cburch.logisim.tools.Library) AddTool(com.cburch.logisim.tools.AddTool) HashSet(java.util.HashSet) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool)

Aggregations

Tool (com.cburch.logisim.tools.Tool)28 AddTool (com.cburch.logisim.tools.AddTool)16 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)9 Library (com.cburch.logisim.tools.Library)7 Circuit (com.cburch.logisim.circuit.Circuit)6 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)6 ProjectExplorerToolNode (com.cburch.logisim.gui.generic.ProjectExplorerToolNode)4 SelectTool (com.cburch.logisim.tools.SelectTool)4 Component (com.cburch.logisim.comp.Component)3 ArrayList (java.util.ArrayList)3 Element (org.w3c.dom.Element)3 AttributeSet (com.cburch.logisim.data.AttributeSet)2 ProjectExplorerLibraryNode (com.cburch.logisim.gui.generic.ProjectExplorerLibraryNode)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ToolbarItem (com.cburch.draw.toolbar.ToolbarItem)1 ToolbarSeparator (com.cburch.draw.toolbar.ToolbarSeparator)1 CircuitState (com.cburch.logisim.circuit.CircuitState)1 ComponentDrawContext (com.cburch.logisim.comp.ComponentDrawContext)1