use of edu.mit.csail.sdg.alloy4.Listener 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.Listener in project org.alloytools.alloy by AlloyTools.
the class VizCustomizationPanel method remakeAll.
// =============================================================================================================//
/**
* Regenerate all the customization widgets based on the latest settings.
*/
public void remakeAll() {
// Make the tree
final OurTree tree = new OurTree(12) {
private static final long serialVersionUID = 0;
private final AlloyModel old = vizState.getOriginalModel(), now = vizState.getCurrentModel();
private final boolean hidePrivate = vizState.hidePrivate(), hideMeta = vizState.hideMeta();
{
do_start();
setRootVisible(false);
setShowsRootHandles(false);
listeners.add(new Listener() {
@Override
public Object do_action(Object sender, Event event) {
return null;
}
@Override
public Object do_action(Object sender, Event event, Object arg) {
zoom(arg);
return null;
}
});
}
@Override
public String convertValueToText(Object value, boolean sel, boolean expand, boolean leaf, int i, boolean focus) {
if (value == GENERAL)
return "<html><b>general graph settings</b></html>";
if (value == NODES)
return "<html><b>types and sets</b></html>";
if (value == EDGES)
return "<html><b>relations</b></html>";
if (value instanceof AlloyType) {
AlloyType x = (AlloyType) value;
if (vizState.getCurrentModel().hasType(x))
return "<html><b>sig</b> " + typename(x) + "</html>";
return "<html><b>sig</b> " + typename(x) + " <font color=\"#808080\">(projected)</font></html>";
}
if (value instanceof AlloySet)
return "<html><b>set</b> " + ((AlloySet) value).getName() + "</html>";
if (value instanceof AlloyRelation)
return value.toString();
else
return "";
}
@Override
public List<?> do_ask(Object parent) {
ArrayList<Object> ans = new ArrayList<Object>();
if (parent == ROOT) {
ans.add(GENERAL);
ans.add(NODES);
ans.add(EDGES);
} else if (parent == NODES) {
ans.add(AlloyType.UNIV);
} else if (parent == EDGES) {
for (AlloyRelation rel : vizState.getCurrentModel().getRelations()) if (!(hidePrivate && rel.isPrivate) && !(hideMeta && rel.isMeta))
ans.add(rel);
} else if (parent instanceof AlloyType) {
AlloyType type = (AlloyType) parent;
for (AlloySet s : now.getSets()) if (!(hidePrivate && s.isPrivate) && !(hideMeta && s.isMeta) && s.getType().equals(type))
ans.add(s);
if (!type.isEnum)
for (AlloyType t : old.getDirectSubTypes(type)) if (!(hidePrivate && t.isPrivate) && !(hideMeta && t.isMeta))
if (now.hasType(t) || vizState.canProject(t))
ans.add(t);
}
return ans;
}
@Override
public boolean do_isDouble(Object object) {
return object == NODES || object == EDGES;
}
@Override
public Object do_root() {
return ROOT;
}
};
// Pre-expand the entire tree.
TreePath last = null;
for (int i = 0; i < tree.getRowCount(); i++) {
tree.expandRow(i);
if (lastElement != null && last == null) {
last = tree.getPathForRow(i);
if (lastElement != last.getLastPathComponent())
last = null;
}
}
// Show the current element if found, else show the GENERAL OPTIONS
if (last != null) {
zoom(lastElement);
} else {
last = tree.getPathForRow(0);
zoom(GENERAL);
}
tree.scrollPathToVisible(last);
tree.setSelectionPath(last);
JScrollPane scroll = OurUtil.scrollpane(tree, Color.BLACK, Color.WHITE, new OurBorder(false, false, false, Util.onMac()));
scroll.setAlignmentX(0f);
scroll.getVerticalScrollBar().setUnitIncrement(50);
removeAll();
add(zoomPane);
add(scroll);
validate();
}
Aggregations