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;
}
}
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());
}
}
}
}
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;
}
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);
}
}
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);
}
}
Aggregations