Search in sources :

Example 1 with OurCheckbox

use of edu.mit.csail.sdg.alloy4.OurCheckbox in project org.alloytools.alloy by AlloyTools.

the class VizCustomizationPanel method createGeneralWidget.

// =============================================================================================================//
/**
 * Generates the "general graph settings" widgets, and add them to "parent".
 */
private void createGeneralWidget(JPanel parent) {
    final List<Integer> fontSizes = Util.asList(9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 32, 36, 40, 44, 48, 54, 60, 66, 72);
    JLabel nLabel = OurUtil.label("Node Color Palette:");
    JLabel eLabel = OurUtil.label("Edge Color Palette:");
    JLabel aLabel = OurUtil.label("Use original atom names:");
    JLabel pLabel = OurUtil.label("Hide private sigs/relations:");
    JLabel mLabel = OurUtil.label("Hide meta sigs/relations:");
    JLabel fLabel = OurUtil.label("Font Size:");
    JComboBox fontSize = new OurCombobox(false, fontSizes.toArray(), 60, 32, vizState.getFontSize()) {

        private static final long serialVersionUID = 0;

        @Override
        public void do_changed(Object value) {
            if (fontSizes.contains(value))
                vizState.setFontSize((Integer) value);
        }
    };
    JComboBox nodepal = new OurCombobox(false, DotPalette.values(), 100, 32, vizState.getNodePalette()) {

        private static final long serialVersionUID = 0;

        @Override
        public String do_getText(Object value) {
            return ((DotPalette) value).getDisplayedText();
        }

        @Override
        public void do_changed(Object value) {
            vizState.setNodePalette((DotPalette) value);
        }
    };
    JComboBox edgepal = new OurCombobox(false, DotPalette.values(), 100, 32, vizState.getEdgePalette()) {

        private static final long serialVersionUID = 0;

        @Override
        public String do_getText(Object value) {
            return ((DotPalette) value).getDisplayedText();
        }

        @Override
        public void do_changed(Object value) {
            vizState.setEdgePalette((DotPalette) value);
        }
    };
    JPanel name = new OurCheckbox("", "Whether the visualizer should use the original atom names as-is.", vizState.useOriginalName() ? OurCheckbox.ON : OurCheckbox.OFF) {

        private static final long serialVersionUID = 0;

        @Override
        public Icon do_action() {
            boolean x = vizState.useOriginalName();
            vizState.useOriginalName(!x);
            return (!x ? ON : OFF);
        }
    };
    JPanel priv = new OurCheckbox("", "Whether the visualizer should hide private sigs, sets, and relations by default.", vizState.hidePrivate() ? OurCheckbox.ON : OurCheckbox.OFF) {

        private static final long serialVersionUID = 0;

        @Override
        public Icon do_action() {
            boolean x = vizState.hidePrivate();
            vizState.hidePrivate(!x);
            remakeAll();
            return (!x ? ON : OFF);
        }
    };
    JPanel meta = new OurCheckbox("", "Whether the visualizer should hide meta sigs, sets, and relations by default.", vizState.hideMeta() ? OurCheckbox.ON : OurCheckbox.OFF) {

        private static final long serialVersionUID = 0;

        @Override
        public Icon do_action() {
            boolean x = vizState.hideMeta();
            vizState.hideMeta(!x);
            remakeAll();
            return (!x ? ON : OFF);
        }
    };
    parent.add(makelabel(" General Graph Settings:"));
    parent.add(OurUtil.makeH(wcolor, new Dimension(6, 6)));
    parent.add(OurUtil.makeH(wcolor, 25, nLabel, 5, nodepal, 8, aLabel, 5, name, 2, null));
    parent.add(OurUtil.makeH(wcolor, 25, eLabel, 5, edgepal, 8, fLabel, 5, fontSize, 2, null));
    parent.add(OurUtil.makeH(wcolor, 25, pLabel, 5, priv, 2, null));
    parent.add(OurUtil.makeH(wcolor, 25, mLabel, 5, meta, 2, null));
}
Also used : OurCombobox(edu.mit.csail.sdg.alloy4.OurCombobox) JPanel(javax.swing.JPanel) DotPalette(edu.mit.csail.sdg.alloy4graph.DotPalette) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) OurCheckbox(edu.mit.csail.sdg.alloy4.OurCheckbox)

Example 2 with OurCheckbox

use of edu.mit.csail.sdg.alloy4.OurCheckbox in project org.alloytools.alloy by AlloyTools.

the class VizCustomizationPanel method makeNodeOptionsPanel.

// =============================================================================================================//
/**
 * Generates the node settings widgets for the given type or set, and add them
 * to "parent".
 */
private void makeNodeOptionsPanel(final JPanel answer, final AlloyNodeElement elt) {
    final boolean enabled = !(elt instanceof AlloyType) || (vizState.getCurrentModel().hasType((AlloyType) elt));
    answer.add(makelabel((elt instanceof AlloyType) ? (" " + typename((AlloyType) elt)) : (" " + elt)));
    final JTextField labelText = OurUtil.textfield(vizState.label.get(elt), 10);
    labelText.setMaximumSize(new Dimension(100, 25));
    labelText.addKeyListener(new KeyAdapter() {

        @Override
        public final void keyReleased(KeyEvent e) {
            vizState.label.put(elt, labelText.getText());
        }
    });
    labelText.addActionListener(new ActionListener() {

        @Override
        public final void actionPerformed(ActionEvent e) {
            vizState.label.put(elt, labelText.getText());
        }
    });
    labelText.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            vizState.label.put(elt, labelText.getText());
        }
    });
    final AlloyModel model = vizState.getCurrentModel();
    final AlloyNodeElement elt2;
    if (elt instanceof AlloyType)
        elt2 = model.getSuperType((AlloyType) elt);
    else if (elt instanceof AlloySet)
        elt2 = ((AlloySet) elt).getType();
    else
        elt2 = null;
    JComboBox color = new OurCombobox(true, DotColor.valuesWithout(DotColor.MAGIC), 100, 35, vizState.nodeColor.get(elt)) {

        private static final long serialVersionUID = 0;

        @Override
        public String do_getText(Object value) {
            if (value == null)
                return "Inherit";
            else
                return ((DotColor) value).getDisplayedText();
        }

        @Override
        public Icon do_getIcon(Object value) {
            if (value == null)
                value = vizState.nodeColor.resolve(elt2);
            return value == null ? null : ((DotColor) value).getIcon(vizState.getNodePalette());
        }

        @Override
        public void do_changed(Object value) {
            vizState.nodeColor.put(elt, (DotColor) value);
        }
    };
    JComboBox shape = new OurCombobox(true, DotShape.values(), 125, 35, vizState.shape.get(elt)) {

        private static final long serialVersionUID = 0;

        @Override
        public String do_getText(Object value) {
            if (value == null)
                return "Inherit";
            else
                return ((DotShape) value).getDisplayedText();
        }

        @Override
        public Icon do_getIcon(Object value) {
            if (value == null)
                value = vizState.shape.resolve(elt2);
            return value == null ? null : ((DotShape) value).getIcon();
        }

        @Override
        public void do_changed(Object value) {
            vizState.shape.put(elt, (DotShape) value);
        }
    };
    JComboBox style = new OurCombobox(true, DotStyle.values(), 95, 35, vizState.nodeStyle.get(elt)) {

        private static final long serialVersionUID = 0;

        @Override
        public String do_getText(Object value) {
            if (value == null)
                return "Inherit";
            else
                return ((DotStyle) value).getDisplayedText();
        }

        @Override
        public Icon do_getIcon(Object value) {
            if (value == null)
                value = vizState.nodeStyle.resolve(elt2);
            return value == null ? null : ((DotStyle) value).getIcon();
        }

        @Override
        public void do_changed(Object value) {
            vizState.nodeStyle.put(elt, (DotStyle) value);
        }
    };
    // 
    answer.add(OurUtil.makeH(10, labelText, wcolor, color, style, shape, 2, null));
    if (elt instanceof AlloyType) {
        JPanel vis = vizState.nodeVisible.pick(elt, "Show", "Display members as nodes");
        JPanel con = vizState.hideUnconnected.pick(elt, "Hide unconnected nodes", "Hide nodes without arcs");
        JPanel num = vizState.number.pick(elt, "Number nodes", "Attach atom number to node label as suffix");
        JPanel proj = null;
        if (vizState.canProject((AlloyType) elt))
            proj = new OurCheckbox("Project over this sig", "Click here to " + (enabled ? "" : "un") + "project over this signature", enabled ? OurCheckbox.ALL_OFF : OurCheckbox.ALL_ON) {

                private static final long serialVersionUID = 0;

                @Override
                public Icon do_action() {
                    if (enabled)
                        projectAlloyType((AlloyType) elt);
                    else
                        deprojectAlloyType((AlloyType) elt);
                    lastElement = elt;
                    return enabled ? ALL_ON : ALL_OFF;
                }
            };
        labelText.setEnabled(enabled && !vizState.useOriginalName());
        color.setEnabled(enabled);
        shape.setEnabled(enabled);
        style.setEnabled(enabled);
        vis.setEnabled(enabled);
        con.setEnabled(enabled);
        num.setEnabled(enabled && !vizState.useOriginalName());
        JPanel a = OurUtil.makeVR(wcolor, vis, num), b;
        if (proj != null)
            b = OurUtil.makeVR(wcolor, con, proj);
        else
            b = OurUtil.makeVR(wcolor, con);
        answer.add(OurUtil.makeHT(wcolor, 15, a, 15, b, 2, null));
    } else {
        JPanel vis = vizState.nodeVisible.pick(elt, "Show", "Include members of set as nodes");
        JPanel attr = vizState.showAsAttr.pick(elt, "Show in relation attributes", "Show set membership in relation attributes");
        JPanel lab = vizState.showAsLabel.pick(elt, "Show as labels", "Show membership in set by labeling nodes");
        JPanel con = vizState.hideUnconnected.pick(elt, "Hide unconnected nodes", "Hide nodes without arcs");
        JPanel a = OurUtil.makeVR(wcolor, vis, lab), b = OurUtil.makeVR(wcolor, con, attr);
        answer.add(OurUtil.makeHT(wcolor, 15, a, 15, b, 2, null));
    }
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) JPanel(javax.swing.JPanel) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) FocusEvent(java.awt.event.FocusEvent) KeyEvent(java.awt.event.KeyEvent) OurCombobox(edu.mit.csail.sdg.alloy4.OurCombobox) ActionListener(java.awt.event.ActionListener) OurCheckbox(edu.mit.csail.sdg.alloy4.OurCheckbox)

Aggregations

OurCheckbox (edu.mit.csail.sdg.alloy4.OurCheckbox)2 OurCombobox (edu.mit.csail.sdg.alloy4.OurCombobox)2 Dimension (java.awt.Dimension)2 JComboBox (javax.swing.JComboBox)2 JPanel (javax.swing.JPanel)2 DotPalette (edu.mit.csail.sdg.alloy4graph.DotPalette)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 FocusAdapter (java.awt.event.FocusAdapter)1 FocusEvent (java.awt.event.FocusEvent)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 JLabel (javax.swing.JLabel)1 JTextField (javax.swing.JTextField)1