Example usage for java.awt.event ItemEvent toString

List of usage examples for java.awt.event ItemEvent toString

Introduction

In this page you can find the example usage for java.awt.event ItemEvent toString.

Prototype

public String toString() 

Source Link

Document

Returns a String representation of this object.

Usage

From source file:com.ibm.bluej.commonutil.visualization.PrintableVisualizationViewer.java

protected void setStandardOptions() {
    PluggableRenderer r = (PluggableRenderer) this.getRenderer();
    r.setVertexStringer(new StringVertexStringer());
    r.setEdgeStringer(new StringEdgeStringer());
    r.setEdgeShapeFunction(new SpacedCurve());
    r.setVertexPaintFunction(new SmartVertexPaintFunction(r, callbacks));
    r.setEdgeLabelClosenessFunction(new ConstantEdgeValue(.5));
    r.setEdgePaintFunction(new SmartEdgePaintFunction(r, callbacks));
    r.setEdgeFontFunction(new FontHandler());

    this.setDoubleBuffered(true);
    DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();
    this.setGraphMouse(graphMouse);
    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);
    this.getPickedState().addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getItem() instanceof LabeledDirectedSparseVertex) {
                LabeledDirectedSparseVertex v = (LabeledDirectedSparseVertex) e.getItem();
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    callbacks.picked((T) v.marked);
                    return;
                }/*  w ww.j a  v a 2  s.  c o m*/
                if (e.getStateChange() == ItemEvent.DESELECTED) {
                    callbacks.unpicked((T) v.marked);
                    return;
                }
                System.err.println(e.toString());
                System.err.println(e.getItem().toString());
            } else {
                LabeledDirectedSparseEdge edge = (LabeledDirectedSparseEdge) e.getItem();
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    callbacks.picked((T) edge.getFrom(), edge.getLabel(), (T) edge.getTo());
                    return;
                }
                if (e.getStateChange() == ItemEvent.DESELECTED) {
                    callbacks.unpicked((T) edge.getFrom(), edge.getLabel(), (T) edge.getTo());
                    return;
                }
                System.out.println("Edge pick");
                System.out.println(e.getItem().getClass().getName());
                System.out.println(e.getStateChange());
            }
        }
    });
    setToolTipFunction(new DefaultToolTipFunction() {
        public String getToolTipText(Vertex v) {
            return callbacks.getToolTip((T) ((LabeledDirectedSparseVertex) v).marked);
        }
        /*
        public String getToolTipText(Edge edge) {
           edu.uci.ics.jung.utils.Pair accts = edge.getEndpoints();
           Vertex v1 = (Vertex) accts.getFirst();
           Vertex v2 = (Vertex) accts.getSecond();
           return v1 + " -- " + v2;
        }
        */
    });
    Predicate p = new Predicate() {
        public boolean evaluate(Object arg0) {
            if (!(arg0 instanceof LabeledDirectedSparseEdge)) {
                System.err.println("Unexpected: " + arg0);
                return false;
            }
            LabeledDirectedSparseEdge edge = (LabeledDirectedSparseEdge) arg0;
            return callbacks.shouldShowEdge((T) edge.getFrom(), edge.getLabel(), (T) edge.getTo());
        }
    };
    r.setEdgeIncludePredicate(p);
    this.setPickSupport(new ShapePickSupport(4));

    //System.out.println(getPickSupport().getClass().getName());
}