use of edu.mit.csail.sdg.alloy4.A4Preferences.Pref in project org.alloytools.alloy by AlloyTools.
the class SimpleGUI method addToMenu.
/**
* Creates a menu item for each choice preference (from <code>prefs</code>) and
* adds it to a given parent menu (<code>parent</code>).
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private JMenu addToMenu(JMenu parent, ChoicePref... prefs) {
JMenu last = null;
for (ChoicePref pref : prefs) {
last = new JMenu(pref.title + ": " + pref.renderValueShort(pref.get()));
addSubmenuItems(last, pref);
parent.add(last);
}
return last;
}
use of edu.mit.csail.sdg.alloy4.A4Preferences.Pref in project org.alloytools.alloy by AlloyTools.
the class SimpleGUI method finishInit.
private void finishInit(String[] args, int width) {
// Add the listeners
try {
wrap = true;
frame.addWindowListener(doQuit());
} finally {
wrap = false;
}
frame.addComponentListener(this);
// initialize the "allowed memory sizes" array
// allowedMemorySizes = new
// ArrayList<Integer>(initialAllowedMemorySizes);
// int newmem = SubMemory.get();
// if (!allowedMemorySizes.contains(newmem)) {
// int newmemlen = allowedMemorySizes.size();
// if (allowedMemorySizes.contains(768) || newmemlen==0)
// SubMemory.set(768); // a nice default value
// else
// SubMemory.set(allowedMemorySizes.get(newmemlen-1));
// }
// Choose the appropriate font
int fontSize = FontSize.get();
String fontName = OurDialog.getProperFontName(FontName.get(), "Courier New", "Lucidia", "Courier", "Monospaced");
FontName.set(fontName);
// Copy required files from the JAR
copyFromJAR();
final String binary = alloyHome() + fs + "binary";
// Create the menu bar
JMenuBar bar = new JMenuBar();
try {
wrap = true;
filemenu = menu(bar, "&File", doRefreshFile());
editmenu = menu(bar, "&Edit", doRefreshEdit());
runmenu = menu(bar, "E&xecute", doRefreshRun());
optmenu = menu(bar, "&Options", doRefreshOption());
windowmenu = menu(bar, "&Window", doRefreshWindow(false));
windowmenu2 = menu(null, "&Window", doRefreshWindow(true));
helpmenu = menu(bar, "&Help", null);
if (!Util.onMac())
menuItem(helpmenu, "About Alloy...", 'A', doAbout());
menuItem(helpmenu, "Quick Guide", 'Q', doHelp());
menuItem(helpmenu, "See the Copyright Notices...", 'L', doLicense());
} finally {
wrap = false;
}
// Pre-load the visualizer
viz = new VizGUI(false, "", windowmenu2, enumerator, evaluator);
viz.doSetFontSize(FontSize.get());
// Create the toolbar
try {
wrap = true;
toolbar = new JToolBar();
toolbar.setFloatable(false);
if (!Util.onMac())
toolbar.setBackground(background);
toolbar.add(OurUtil.button("New", "Starts a new blank model", "images/24_new.gif", doNew()));
toolbar.add(OurUtil.button("Open", "Opens an existing model", "images/24_open.gif", doOpen()));
toolbar.add(OurUtil.button("Reload", "Reload all the models from disk", "images/24_reload.gif", doReloadAll()));
toolbar.add(OurUtil.button("Save", "Saves the current model", "images/24_save.gif", doSave()));
toolbar.add(runbutton = OurUtil.button("Execute", "Executes the latest command", "images/24_execute.gif", doExecuteLatest()));
toolbar.add(stopbutton = OurUtil.button("Stop", "Stops the current analysis", "images/24_execute_abort2.gif", doStop(2)));
stopbutton.setVisible(false);
toolbar.add(showbutton = OurUtil.button("Show", "Shows the latest instance", "images/24_graph.gif", doShowLatest()));
toolbar.add(Box.createHorizontalGlue());
toolbar.setBorder(new OurBorder(false, false, false, false));
} finally {
wrap = false;
}
// Choose the antiAlias setting
OurAntiAlias.enableAntiAlias(AntiAlias.get());
// Create the message area
logpane = OurUtil.scrollpane(null);
log = new SwingLogPanel(logpane, fontName, fontSize, background, Color.BLACK, new Color(.7f, .2f, .2f), this);
// Create loggers for preference changes
PreferencesDialog.logOnChange(log, A4Preferences.allUserPrefs().toArray(new Pref<?>[0]));
// Create the text area
text = new OurTabbedSyntaxWidget(fontName, fontSize, TabSize.get());
text.listeners.add(this);
text.enableSyntax(!SyntaxDisabled.get());
// Add everything to the frame, then display the frame
Container all = frame.getContentPane();
all.setLayout(new BorderLayout());
all.removeAll();
JPanel lefthalf = new JPanel();
lefthalf.setLayout(new BorderLayout());
lefthalf.add(toolbar, BorderLayout.NORTH);
text.addTo(lefthalf, BorderLayout.CENTER);
splitpane = OurUtil.splitpane(JSplitPane.HORIZONTAL_SPLIT, lefthalf, logpane, width / 2);
splitpane.setResizeWeight(0.5D);
status = OurUtil.make(OurAntiAlias.label(" "), new Font(fontName, Font.PLAIN, fontSize), Color.BLACK, background);
status.setBorder(new OurBorder(true, false, false, false));
all.add(splitpane, BorderLayout.CENTER);
all.add(status, BorderLayout.SOUTH);
// Generate some informative log messages
log.logBold("Alloy Analyzer " + Version.version() + " (build date: " + Version.buildDate() + " git " + Version.commit + ")\n\n");
// If on Mac, then register an application listener
try {
wrap = true;
if (Util.onMac()) {
macUtil.registerApplicationListener(doShow(), doAbout(), doOpenFile(""), doQuit());
}
} catch (Throwable t) {
System.out.println("Mac classes not there");
} finally {
wrap = false;
}
// Add the new JNI location to the java.library.path
try {
System.setProperty("java.library.path", binary);
// The above line is actually useless on Sun JDK/JRE (see Sun's bug
// ID 4280189)
// The following 4 lines should work for Sun's JDK/JRE (though they
// probably won't work for others)
String[] newarray = new String[] { binary };
java.lang.reflect.Field old = ClassLoader.class.getDeclaredField("usr_paths");
old.setAccessible(true);
old.set(null, newarray);
} catch (Throwable ex) {
}
// Pre-load the preferences dialog
prefDialog = new PreferencesDialog(log, binary);
prefDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
try {
wrap = true;
prefDialog.addChangeListener(wrapToChangeListener(doOptRefreshFont()), FontName, FontSize, TabSize);
prefDialog.addChangeListener(wrapToChangeListener(doOptAntiAlias()), AntiAlias);
prefDialog.addChangeListener(wrapToChangeListener(doOptSyntaxHighlighting()), SyntaxDisabled);
prefDialog.addChangeListener(wrapToChangeListener(doLookAndFeel()), LAF);
} finally {
wrap = false;
}
// If the temporary directory has become too big, then tell the user
// they can "clear temporary directory".
long space = computeTemporarySpaceUsed();
if (space < 0 || space >= 20 * 1024768) {
if (space < 0)
log.logBold("Warning: Alloy4's temporary directory has exceeded 1024M.\n");
else
log.logBold("Warning: Alloy4's temporary directory now uses " + (space / 1024768) + "M.\n");
log.log("To clear the temporary directory,\n" + "go to the File menu and click \"Clear Temporary Directory\"\n");
log.logDivider();
log.flush();
}
// Refreshes all the menu items
doRefreshFile();
OurUtil.enableAll(filemenu);
doRefreshEdit();
OurUtil.enableAll(editmenu);
doRefreshRun();
OurUtil.enableAll(runmenu);
doRefreshOption();
doRefreshWindow(false);
OurUtil.enableAll(windowmenu);
frame.setJMenuBar(bar);
// Open the given file, if a filename is given in the command line
for (String f : args) if (f.toLowerCase(Locale.US).endsWith(".als")) {
File file = new File(f);
if (file.exists() && file.isFile())
doOpenFile(file.getPath());
}
// Update the title and status bar
notifyChange();
text.get().requestFocusInWindow();
// Launch the welcome screen if needed
if (!AlloyCore.isDebug() && Welcome.get()) {
JCheckBox again = new JCheckBox("Show this message every time you start the Alloy Analyzer");
again.setSelected(true);
OurDialog.showmsg("Welcome", "Thank you for using the Alloy Analyzer " + Version.version(), " ", "Version 4 of the Alloy Analyzer is a complete rewrite,", "offering improvements in robustness, performance and usability.", "Models written in Alloy 3 will require some small alterations to run in Alloy 4.", " ", "Here are some quick tips:", " ", "* Function calls now use [ ] instead of ( )", " For more details, please see http://alloy.mit.edu/alloy4/quickguide/", " ", "* The Execute button always executes the latest command.", " To choose which command to execute, go to the Execute menu.", " ", "* The Alloy Analyzer comes with a variety of sample models.", " To see them, go to the File menu and click Open Sample Models.", " ", again);
doShow();
Welcome.set(again.isSelected());
}
// Periodically ask the MailBug thread to see if there is a newer
// version or not
final long now = System.currentTimeMillis();
final Timer t = new Timer(800, null);
t.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int n = MailBug.latestBuildNumber();
// message may run into other user messages
if (System.currentTimeMillis() - now >= 3000 || n <= Version.buildNumber()) {
t.stop();
return;
}
latestAlloyVersion = n;
latestAlloyVersionName = MailBug.latestBuildName();
log.logBold("An updated version of the Alloy Analyzer has been released.\n");
log.log("Please visit alloy.mit.edu to download the latest version:\nVersion " + latestAlloyVersionName + "\n");
log.logDivider();
log.flush();
t.stop();
}
});
t.start();
}
use of edu.mit.csail.sdg.alloy4.A4Preferences.Pref in project org.alloytools.alloy by AlloyTools.
the class SimpleGUI method addToMenu.
/**
* Creates menu items from boolean preferences (<code>prefs</code>) and adds
* them to a given parent menu (<code>parent</code>).
*/
private void addToMenu(JMenu parent, BooleanPref... prefs) {
for (BooleanPref pref : prefs) {
Action action = pref.getTitleAction();
Object name = action.getValue(Action.NAME);
menuItem(parent, name + ": " + (pref.get() ? "Yes" : "No"), action);
}
}
Aggregations