use of edu.mit.csail.sdg.alloy4.OurBorder 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.OurBorder 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();
}
use of edu.mit.csail.sdg.alloy4.OurBorder in project org.alloytools.alloy by AlloyTools.
the class VizGUI method updateDisplay.
/**
* Helper method that refreshes the right-side visualization panel with the
* latest settings.
*/
private void updateDisplay() {
if (myState == null)
return;
// First, update the toolbar
currentMode.set();
for (JButton button : solutionButtons) button.setEnabled(settingsOpen != 1);
switch(currentMode) {
case Tree:
treeButton.setEnabled(false);
break;
case TEXT:
txtButton.setEnabled(false);
break;
case TABLE:
tableButton.setEnabled(false);
break;
// case DOT: dotButton.setEnabled(false); break;
default:
vizButton.setEnabled(false);
}
final boolean isMeta = myState.getOriginalInstance().isMetamodel;
vizButton.setVisible(frame != null);
treeButton.setVisible(frame != null);
txtButton.setVisible(frame != null);
// dotButton.setVisible(frame!=null);
// xmlButton.setVisible(frame!=null);
magicLayout.setVisible((settingsOpen == 0 || settingsOpen == 1) && currentMode == VisualizerMode.Viz);
projectionButton.setVisible((settingsOpen == 0 || settingsOpen == 1) && currentMode == VisualizerMode.Viz);
openSettingsButton.setVisible(settingsOpen == 0 && currentMode == VisualizerMode.Viz);
loadSettingsButton.setVisible(frame == null && settingsOpen == 1 && currentMode == VisualizerMode.Viz);
saveSettingsButton.setVisible(frame == null && settingsOpen == 1 && currentMode == VisualizerMode.Viz);
saveAsSettingsButton.setVisible(frame == null && settingsOpen == 1 && currentMode == VisualizerMode.Viz);
resetSettingsButton.setVisible(frame == null && settingsOpen == 1 && currentMode == VisualizerMode.Viz);
closeSettingsButton.setVisible(settingsOpen == 1 && currentMode == VisualizerMode.Viz);
updateSettingsButton.setVisible(settingsOpen == 1 && currentMode == VisualizerMode.Viz);
openEvaluatorButton.setVisible(!isMeta && settingsOpen == 0 && evaluator != null);
closeEvaluatorButton.setVisible(!isMeta && settingsOpen == 2 && evaluator != null);
enumerateMenu.setEnabled(!isMeta && settingsOpen == 0 && enumerator != null);
enumerateButton.setVisible(!isMeta && settingsOpen == 0 && enumerator != null);
toolbar.setVisible(true);
// on the right
if (frame != null)
frame.setTitle(makeVizTitle());
switch(currentMode) {
case Tree:
{
final VizTree t = new VizTree(myState.getOriginalInstance().originalA4, makeVizTitle(), fontSize);
final JScrollPane scroll = OurUtil.scrollpane(t, Color.BLACK, Color.WHITE, new OurBorder(true, false, true, false));
scroll.addFocusListener(new FocusListener() {
@Override
public final void focusGained(FocusEvent e) {
t.requestFocusInWindow();
}
@Override
public final void focusLost(FocusEvent e) {
}
});
content = scroll;
break;
}
case TEXT:
{
String textualOutput = myState.getOriginalInstance().originalA4.toString();
content = getTextComponent(textualOutput);
break;
}
case TABLE:
{
String textualOutput = myState.getOriginalInstance().originalA4.format();
content = getTextComponent(textualOutput);
break;
}
// }
default:
{
if (myGraphPanel == null) {
myGraphPanel = new VizGraphPanel(myState, false);
} else {
myGraphPanel.seeDot(false);
myGraphPanel.remakeAll();
}
}
content = myGraphPanel;
}
// Now that we've re-constructed "content", let's set its font size
if (currentMode != VisualizerMode.Tree) {
content.setFont(OurUtil.getVizFont().deriveFont((float) fontSize));
content.invalidate();
content.repaint();
content.validate();
}
// Now, display them!
final Box instanceTopBox = Box.createHorizontalBox();
instanceTopBox.add(toolbar);
final JPanel instanceArea = new JPanel(new BorderLayout());
instanceArea.add(instanceTopBox, BorderLayout.NORTH);
instanceArea.add(content, BorderLayout.CENTER);
instanceArea.setVisible(true);
if (!Util.onMac()) {
instanceTopBox.setBackground(background);
instanceArea.setBackground(background);
}
JComponent left = null;
if (settingsOpen == 1) {
if (myCustomPanel == null)
myCustomPanel = new VizCustomizationPanel(splitpane, myState);
else
myCustomPanel.remakeAll();
left = myCustomPanel;
} else if (settingsOpen > 1) {
if (myEvaluatorPanel == null)
myEvaluatorPanel = new OurConsole(evaluator, true, "The ", true, "Alloy Evaluator ", false, "allows you to type\nin Alloy expressions and see their values.\nFor example, ", true, "univ", false, " shows the list of all atoms.\n(You can press UP and DOWN to recall old inputs).\n");
try {
evaluator.compute(new File(xmlFileName));
}// exception should not happen
catch (Exception ex) {
}
left = myEvaluatorPanel;
left.setBorder(new OurBorder(false, false, false, false));
}
if (frame != null && frame.getContentPane() == splitpane)
lastDividerPosition = splitpane.getDividerLocation();
splitpane.setRightComponent(instanceArea);
splitpane.setLeftComponent(left);
if (left != null) {
Dimension dim = left.getPreferredSize();
if (lastDividerPosition < 50 && frame != null)
lastDividerPosition = frame.getWidth() / 2;
if (lastDividerPosition < dim.width)
lastDividerPosition = dim.width;
if (settingsOpen == 2 && lastDividerPosition > 400)
lastDividerPosition = 400;
splitpane.setDividerLocation(lastDividerPosition);
}
if (frame != null)
frame.setContentPane(splitpane);
if (settingsOpen != 2)
content.requestFocusInWindow();
else
myEvaluatorPanel.requestFocusInWindow();
repopulateProjectionPopup();
if (frame != null)
frame.validate();
else
splitpane.validate();
}
use of edu.mit.csail.sdg.alloy4.OurBorder in project org.alloytools.alloy by AlloyTools.
the class VizGUI method getTextComponent.
/**
* Helper method returns a JTextArea containing the given text.
*/
private JComponent getTextComponent(String text) {
final JTextArea ta = OurUtil.textarea(text, 10, 10, false, true);
final JScrollPane ans = new JScrollPane(ta, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED) {
private static final long serialVersionUID = 0;
@Override
public void setFont(Font font) {
super.setFont(font);
}
};
ans.setBorder(new OurBorder(true, false, true, false));
String fontName = OurDialog.getProperFontName("Lucida Console", "Monospaced");
Font font = new Font(fontName, Font.PLAIN, fontSize);
ans.setFont(font);
ta.setFont(font);
return ans;
}
use of edu.mit.csail.sdg.alloy4.OurBorder in project org.alloytools.alloy by AlloyTools.
the class PreferencesDialog method makeTabPane.
private Component makeTabPane(JPanel pane) {
JPanel p = new JPanel(new GridBagLayout());
// pane.setBorder(new OurBorder(true, true, true, true));
p.add(pane, gbc().pos(0, 0).fill(GridBagConstraints.BOTH).insets(new Insets(5, 5, 5, 5)).anchor(GridBagConstraints.NORTH).make());
p.add(new JLabel(), gbc().pos(0, 1).weighty(1).fill(GridBagConstraints.BOTH).make());
JPanel ans = OurUtil.make(p, new OurBorder(true, true, true, true));
return ans;
}
Aggregations