use of com.cburch.logisim.tools.Library 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.Library in project logisim-evolution by reds-heig.
the class LibraryManager method loadLibrary.
public Library loadLibrary(Loader loader, String desc) {
// It may already be loaded.
// Otherwise we'll have to decode it.
int sep = desc.indexOf(desc_sep);
if (sep < 0) {
loader.showError(StringUtil.format(Strings.get("fileDescriptorError"), desc));
return null;
}
String type = desc.substring(0, sep);
String name = desc.substring(sep + 1);
if (type.equals("")) {
Library ret = loader.getBuiltin().getLibrary(name);
if (ret == null) {
loader.showError(StringUtil.format(Strings.get("fileBuiltinMissingError"), name));
return null;
}
return ret;
} else if (type.equals("file")) {
File toRead = loader.getFileFor(name, Loader.LOGISIM_FILTER);
return loadLogisimLibrary(loader, toRead);
} else if (type.equals("jar")) {
int sepLoc = name.lastIndexOf(desc_sep);
String fileName = name.substring(0, sepLoc);
String className = name.substring(sepLoc + 1);
File toRead = loader.getFileFor(fileName, Loader.JAR_FILTER);
return loadJarLibrary(loader, toRead, className);
} else {
loader.showError(StringUtil.format(Strings.get("fileTypeError"), type, desc));
return null;
}
}
use of com.cburch.logisim.tools.Library in project logisim-evolution by reds-heig.
the class LoadedLibrary method setBase.
void setBase(Library value) {
if (base instanceof LibraryEventSource) {
((LibraryEventSource) base).removeLibraryListener(myListener);
}
Library old = base;
base = value;
resolveChanges(old);
if (base instanceof LibraryEventSource) {
((LibraryEventSource) base).addLibraryListener(myListener);
}
}
use of com.cburch.logisim.tools.Library 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);
}
}
use of com.cburch.logisim.tools.Library in project logisim-evolution by reds-heig.
the class Loader method save.
public boolean save(LogisimFile file, File dest) {
Library reference = LibraryManager.instance.findReference(file, dest);
if (reference != null) {
JOptionPane.showMessageDialog(parent, StringUtil.format(Strings.get("fileCircularError"), reference.getDisplayName()), Strings.get("fileSaveErrorTitle"), JOptionPane.ERROR_MESSAGE);
return false;
}
File backup = determineBackupName(dest);
boolean backupCreated = backup != null && dest.renameTo(backup);
FileOutputStream fwrite = null;
try {
try {
MacCompatibility.setFileCreatorAndType(dest, "LGSM", "circ");
} catch (IOException e) {
}
fwrite = new FileOutputStream(dest);
file.write(fwrite, this, dest);
file.setName(toProjectName(dest));
File oldFile = getMainFile();
setMainFile(dest);
LibraryManager.instance.fileSaved(this, dest, oldFile, file);
} catch (IOException e) {
if (backupCreated)
recoverBackup(backup, dest);
if (dest.exists() && dest.length() == 0)
dest.delete();
JOptionPane.showMessageDialog(parent, StringUtil.format(Strings.get("fileSaveError"), e.toString()), Strings.get("fileSaveErrorTitle"), JOptionPane.ERROR_MESSAGE);
return false;
} finally {
if (fwrite != null) {
try {
fwrite.close();
} catch (IOException e) {
if (backupCreated)
recoverBackup(backup, dest);
if (dest.exists() && dest.length() == 0)
dest.delete();
JOptionPane.showMessageDialog(parent, StringUtil.format(Strings.get("fileSaveCloseError"), e.toString()), Strings.get("fileSaveErrorTitle"), JOptionPane.ERROR_MESSAGE);
return false;
}
}
}
if (!dest.exists() || dest.length() == 0) {
if (backupCreated && backup != null && backup.exists()) {
recoverBackup(backup, dest);
} else {
dest.delete();
}
JOptionPane.showMessageDialog(parent, Strings.get("fileSaveZeroError"), Strings.get("fileSaveErrorTitle"), JOptionPane.ERROR_MESSAGE);
return false;
}
if (backupCreated && backup.exists()) {
backup.delete();
}
return true;
}
Aggregations