Search in sources :

Example 6 with ToStringLabeller

use of edu.uci.ics.jung.visualization.decorators.ToStringLabeller in project fql by CategoricalData.

the class Signature method doView.

@SuppressWarnings("unchecked")
private JComponent doView(Color clr, /* final Environment env, */
Graph<String, String> sgv) {
    try {
        Class<?> c = Class.forName(FqlOptions.layout_prefix + DefunctGlobalOptions.debug.fql.schema_graph);
        Constructor<?> x = c.getConstructor(Graph.class);
        Layout<String, String> layout = (Layout<String, String>) x.newInstance(sgv);
        layout.setSize(new Dimension(600, 400));
        VisualizationViewer<String, String> vv = new VisualizationViewer<>(layout);
        Function<String, Paint> vertexPaints = (String name) -> isAttribute(name) ? UIManager.getColor("Panel.background") : clr;
        DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
        gm.setMode(Mode.TRANSFORMING);
        vv.setGraphMouse(gm);
        gm.setMode(Mode.PICKING);
        float[] dash = { 1.0f };
        Stroke edgeStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 10.0f);
        Stroke bs = new BasicStroke();
        Function<String, Stroke> edgeStrokeTransformer = (String name) -> (isAttribute(name)) ? edgeStroke : bs;
        vv.getRenderContext().setVertexFillPaintTransformer(vertexPaints);
        vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
        vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
        vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
        vv.getRenderContext().setVertexLabelTransformer((String t) -> (isAttribute(t)) ? getTypeLabel(t) : t);
        GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
        JPanel ret = new JPanel(new GridLayout(1, 1));
        ret.add(zzz);
        ret.setBorder(BorderFactory.createEtchedBorder());
        return ret;
    } catch (Throwable cnf) {
        cnf.printStackTrace();
        throw new RuntimeException();
    }
}
Also used : BasicStroke(java.awt.BasicStroke) JPanel(javax.swing.JPanel) BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) ToStringLabeller(edu.uci.ics.jung.visualization.decorators.ToStringLabeller) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) GridLayout(java.awt.GridLayout) Layout(edu.uci.ics.jung.algorithms.layout.Layout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer)

Example 7 with ToStringLabeller

use of edu.uci.ics.jung.visualization.decorators.ToStringLabeller in project dwoss by gg-net.

the class Grapher method showFull.

/**
 * Show the full StateMachine with a special formater.
 * <p/>
 * @param <T>          type of state machine
 * @param stateMachine the statemachine to show
 * @param formater     an optional formater
 */
public static <T> void showFull(final StateMachine<T> stateMachine, final StateFormater<T> formater) {
    DirectedGraph<State<T>, String> g = new DirectedSparseMultigraph<>();
    int i = 0;
    for (Link<T> link : stateMachine.getLinks()) {
        // TODO: A Graph needs for each transition a unique id. A StateMachine not. So we build it here.
        g.addEdge("[" + (i++) + "] " + link.getTransition().toString(), link.getSource(), link.getDestination());
    }
    FRLayout<State<T>, String> layout = new FRLayout<>(g);
    // layout.setRepulsionMultiplier(2);
    // layout.setMaxIterations(20);
    // sets the initial size of the space
    layout.setSize(new Dimension(1100, 950));
    VisualizationViewer<State<T>, String> vv = new VisualizationViewer<>(layout);
    // Sets the viewing area size
    vv.setPreferredSize(new Dimension(1280, 1024));
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);
    // final VisualizationModel<String,Number> visualizationModel =
    // new DefaultVisualizationModel<String,Number>(layout, preferredSize);
    // this class will provide both label drawing and vertex shapes
    VertexLabelAsShapeRenderer<State<T>, String> vlasr = new VertexLabelAsShapeRenderer<>(vv.getRenderContext());
    // // customize the render context
    if (formater != null) {
        vv.getRenderContext().setVertexLabelTransformer((state) -> {
            return formater.toHtml(state);
        });
        vv.setVertexToolTipTransformer((state) -> {
            return formater.toToolTipHtml(state);
        });
    }
    vv.getRenderContext().setVertexShapeTransformer(vlasr);
    vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.RED));
    vv.getRenderContext().setEdgeDrawPaintTransformer((input) -> {
        return Color.DARK_GRAY;
    });
    vv.getRenderContext().setEdgeStrokeTransformer((input) -> {
        return new BasicStroke(2.5f);
    });
    // customize the renderer
    vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<State<T>, String>(Color.LIGHT_GRAY, Color.WHITE, true));
    vv.getRenderer().setVertexLabelRenderer(vlasr);
    DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
    gm.setMode(ModalGraphMouse.Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    vv.addKeyListener(gm.getModeKeyListener());
    JFrame frame = new JFrame("Simple Graph View");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(vv, BorderLayout.CENTER);
    frame.getContentPane().add(gm.getModeComboBox(), BorderLayout.SOUTH);
    frame.pack();
    frame.setVisible(true);
}
Also used : DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) ToStringLabeller(edu.uci.ics.jung.visualization.decorators.ToStringLabeller) JFrame(javax.swing.JFrame) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer)

Example 8 with ToStringLabeller

use of edu.uci.ics.jung.visualization.decorators.ToStringLabeller in project fql by CategoricalData.

the class TransformEditor method doView.

@SuppressWarnings({ "unchecked", "rawtypes" })
private JComponent doView(Color clr, /* final Color color */
Graph<String, String> sgv) {
    try {
        Class<?> c = Class.forName(FqlOptions.layout_prefix + DefunctGlobalOptions.debug.fql.inst_graph);
        Constructor<?> x = c.getConstructor(Graph.class);
        Layout<String, String> layout = (Layout<String, String>) x.newInstance(sgv);
        layout.setSize(new Dimension(500, 340));
        VisualizationViewer<String, String> vv = new VisualizationViewer<>(layout);
        Function<String, Paint> vertexPaint = (String i) -> thesig.isAttribute(i) ? UIManager.getColor("Panel.background") : clr;
        DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
        // gm.setMode(ModalGraphMouse.Mode.TRANSFORMING);
        vv.setGraphMouse(gm);
        gm.setMode(Mode.PICKING);
        vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
        vv.getRenderContext().setVertexLabelTransformer((String str) -> {
            if (thesig.isAttribute(str)) {
                str = thesig.getTypeLabel(str);
            }
            return str;
        });
        vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
            if (e.getStateChange() != ItemEvent.SELECTED) {
                return;
            }
            vv.getPickedEdgeState().clear();
            String str = ((String) e.getItem());
            if (thesig.isNode(str)) {
                cards.show(vwr, str);
                card = str;
            }
        });
        vv.getRenderContext().setLabelOffset(20);
        vv.getRenderContext().setEdgeLabelTransformer((String s) -> {
            if (thesig.isAttribute(s)) {
                return "";
            }
            return s;
        });
        float[] dash = { 1.0f };
        Stroke edgeStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 10.0f);
        Stroke bs = new BasicStroke();
        Function<String, Stroke> edgeStrokeTransformer = (String s) -> {
            if (thesig.isAttribute(s)) {
                return edgeStroke;
            }
            return bs;
        };
        vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
        vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
        GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
        zzz.setPreferredSize(new Dimension(600, 400));
        vwr.setPreferredSize(new Dimension(600, 200));
        // JPanel newthing = new JPanel(new GridLayout(2,1));
        JSplitPane newthing = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        newthing.setResizeWeight(.5d);
        newthing.setDividerLocation(.5d);
        // setDividerLocation(.9d);
        newthing.add(zzz);
        JPanel yyy = new JPanel(new FlowLayout(FlowLayout.LEFT));
        JButton ar = new JButton("Add Row");
        JButton dr = new JButton("Delete Rows");
        ar.setPreferredSize(dr.getPreferredSize());
        yyy.add(ar);
        yyy.add(dr);
        JPanel xxx = new JPanel(new BorderLayout());
        xxx.add(vwr, BorderLayout.CENTER);
        xxx.add(yyy, BorderLayout.SOUTH);
        newthing.add(xxx);
        newthing.resetToPreferredSizes();
        dr.addActionListener((ActionEvent e) -> {
            JTable t = tj.get(card);
            int[] i = t.getSelectedRows();
            int j = 0;
            DefaultTableModel dtm = (DefaultTableModel) t.getModel();
            for (int x1 : i) {
                dtm.removeRow(x1 - (j++));
            }
            tjx.get(card).setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), name + "." + card + " (" + dtm.getRowCount() + " rows)"));
        });
        ar.addActionListener((ActionEvent e) -> {
            JTable t = tj.get(card);
            DefaultTableModel dtm = (DefaultTableModel) t.getModel();
            dtm.addRow((Vector) null);
            tjx.get(card).setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), name + "." + card + " (" + dtm.getRowCount() + " rows)"));
        });
        return newthing;
    } catch (Throwable t) {
        t.printStackTrace();
        throw new RuntimeException();
    }
}
Also used : BasicStroke(java.awt.BasicStroke) JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) DefaultTableModel(javax.swing.table.DefaultTableModel) JButton(javax.swing.JButton) ToStringLabeller(edu.uci.ics.jung.visualization.decorators.ToStringLabeller) BorderLayout(java.awt.BorderLayout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) Paint(java.awt.Paint) CardLayout(java.awt.CardLayout) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) FlowLayout(java.awt.FlowLayout) Layout(edu.uci.ics.jung.algorithms.layout.Layout) JTable(javax.swing.JTable) JSplitPane(javax.swing.JSplitPane)

Example 9 with ToStringLabeller

use of edu.uci.ics.jung.visualization.decorators.ToStringLabeller in project abstools by abstools.

the class JungObjectGraph method begin.

@Override
public void begin() {
    graph = new DirectedSparseGraph<String, Integer>();
    layout = new FRLayout<String, Integer>(graph);
    layout.setSize(new Dimension(600, 600));
    vv = new VisualizationViewer<String, Integer>(layout, new Dimension(600, 600));
    vv.setBackground(Color.white);
    startAnimator();
    VertexLabelAsShapeRenderer<String, Integer> vlasr = new VertexLabelAsShapeRenderer<String, Integer>(vv.getRenderContext());
    // vv.getRenderContext().setVertexShapeTransformer(arg0)
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    vv.getRenderContext().setVertexShapeTransformer(vlasr);
    try {
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                JFrame frame = new JFrame("Simple Graph View");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                JPanel pane = new JPanel();
                pane.setLayout(new BorderLayout());
                pane.add(vv, BorderLayout.CENTER);
                frame.getContentPane().add(pane);
                pane.setBorder(BorderFactory.createEmptyBorder(50, 50, 50, 50));
                frame.pack();
                frame.setVisible(true);
            }
        });
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}
Also used : JPanel(javax.swing.JPanel) Dimension(java.awt.Dimension) ToStringLabeller(edu.uci.ics.jung.visualization.decorators.ToStringLabeller) InvocationTargetException(java.lang.reflect.InvocationTargetException) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) VertexLabelAsShapeRenderer(edu.uci.ics.jung.visualization.renderers.VertexLabelAsShapeRenderer)

Aggregations

ToStringLabeller (edu.uci.ics.jung.visualization.decorators.ToStringLabeller)9 VisualizationViewer (edu.uci.ics.jung.visualization.VisualizationViewer)8 DefaultModalGraphMouse (edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse)8 Dimension (java.awt.Dimension)8 JPanel (javax.swing.JPanel)7 Layout (edu.uci.ics.jung.algorithms.layout.Layout)6 GraphZoomScrollPane (edu.uci.ics.jung.visualization.GraphZoomScrollPane)6 GridLayout (java.awt.GridLayout)6 Paint (java.awt.Paint)6 CardLayout (java.awt.CardLayout)5 ItemEvent (java.awt.event.ItemEvent)5 BasicStroke (java.awt.BasicStroke)4 BorderLayout (java.awt.BorderLayout)4 Stroke (java.awt.Stroke)4 JSplitPane (javax.swing.JSplitPane)3 JTable (javax.swing.JTable)3 Pair (catdata.Pair)2 DirectedSparseMultigraph (edu.uci.ics.jung.graph.DirectedSparseMultigraph)2 IntRef (catdata.IntRef)1 Quad (catdata.Quad)1