}
}
}
public static void doLoadJarLibrary(Project proj) {
Loader loader = proj.getLogisimFile().getLoader();
JFileChooser chooser = loader.createChooser();
chooser.setDialogTitle(Strings.get("loadJarDialogTitle"));
chooser.setFileFilter(Loader.JAR_FILTER);
int check = chooser.showOpenDialog(proj.getFrame());
if (check == JFileChooser.APPROVE_OPTION) {
File f = chooser.getSelectedFile();
String className = null;
// try to retrieve the class name from the "Library-Class"
// attribute in the manifest. This section of code was contributed
// by Christophe Jacquet (Request Tracker #2024431).
JarFile jarFile = null;
try {
jarFile = new JarFile(f);
Manifest manifest = jarFile.getManifest();
className = manifest.getMainAttributes().getValue("Library-Class");
} catch (IOException e) {
// if opening the JAR file failed, do nothing
} finally {
if (jarFile != null) {
try { jarFile.close(); } catch (IOException e) { }
}
}
// if the class name was not found, go back to the good old dialog
if (className == null) {
className = JOptionPane.showInputDialog(proj.getFrame(),
Strings.get("jarClassNamePrompt"),
Strings.get("jarClassNameTitle"),
JOptionPane.QUESTION_MESSAGE);
// if user canceled selection, abort
if (className == null) return;
}
Library lib = loader.loadJarLibrary(f, className);
if (lib != null) {
proj.doAction(LogisimFileActions.loadLibrary(lib));
}
}
}