Search in sources :

Example 1 with OurConsole

use of edu.mit.csail.sdg.alloy4.OurConsole 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();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) OurBorder(edu.mit.csail.sdg.alloy4.OurBorder) JButton(javax.swing.JButton) JComponent(javax.swing.JComponent) Box(javax.swing.Box) Dimension(java.awt.Dimension) FocusEvent(java.awt.event.FocusEvent) OurConsole(edu.mit.csail.sdg.alloy4.OurConsole) IOException(java.io.IOException) BorderLayout(java.awt.BorderLayout) FocusListener(java.awt.event.FocusListener) File(java.io.File)

Aggregations

OurBorder (edu.mit.csail.sdg.alloy4.OurBorder)1 OurConsole (edu.mit.csail.sdg.alloy4.OurConsole)1 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 FocusEvent (java.awt.event.FocusEvent)1 FocusListener (java.awt.event.FocusListener)1 File (java.io.File)1 IOException (java.io.IOException)1 Box (javax.swing.Box)1 JButton (javax.swing.JButton)1 JComponent (javax.swing.JComponent)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1