Beispiel #1
0
  public trial(int st, String n) {

    // setup a visualisation
    super(new Visualization());

    System.out.println(st + "  " + n);

    // generate a graph
    initGraph(n, st);

    //  standard labelRenderer for the given label
    LabelRenderer nodeRenderer = new LabelRenderer(LABEL);
    // rendererFactory for the visualization items
    DefaultRendererFactory rendererFactory = new DefaultRendererFactory();
    // set the labelRenderer
    rendererFactory.setDefaultRenderer(nodeRenderer);
    m_vis.setRendererFactory(rendererFactory);

    // Color Actions
    ColorAction nodeText = new ColorAction(NODES, VisualItem.TEXTCOLOR);
    nodeText.setDefaultColor(ColorLib.gray(0));
    ColorAction nodeStroke = new ColorAction(NODES, VisualItem.STROKECOLOR);
    nodeStroke.setDefaultColor(ColorLib.gray(100));
    ColorAction nodeFill = new ColorAction(NODES, VisualItem.FILLCOLOR);
    nodeFill.setDefaultColor(ColorLib.gray(255));
    ColorAction edgeStrokes = new ColorAction(EDGES, VisualItem.STROKECOLOR);
    edgeStrokes.setDefaultColor(ColorLib.gray(100));

    // ColorAction fill = new ColorAction(NODES, VisualItem.FILLCOLOR,
    ColorLib.rgb(200, 200, 255);
    // fill.add(VisualItem.FIXED, ColorLib.rgb(255,100,100));
    // fill.add(VisualItem.HIGHLIGHT, ColorLib.rgb(255,200,125));

    // bundle the color actions
    ActionList draw = new ActionList();
    //    draw.add(fill);
    draw.add(new ColorAction(NODES, VisualItem.STROKECOLOR, 0));
    draw.add(new ColorAction(NODES, VisualItem.TEXTCOLOR, ColorLib.rgb(0, 0, 0)));
    draw.add(new ColorAction(EDGES, VisualItem.FILLCOLOR, ColorLib.gray(200)));
    draw.add(new ColorAction(EDGES, VisualItem.STROKECOLOR, ColorLib.gray(200)));
    draw.add(nodeText);
    draw.add(nodeStroke);
    draw.add(nodeFill);
    draw.add(edgeStrokes);

    ActionList animate = new ActionList(Activity.INFINITY);
    //   animate.add(fill);
    animate.add(new RepaintAction());

    m_nodeRenderer = new LabelRenderer(m_label);

    m_nodeRenderer.setRenderType(AbstractShapeRenderer.RENDER_TYPE_FILL);
    m_nodeRenderer.setHorizontalAlignment(Constants.LEFT);
    m_nodeRenderer.setRoundedCorner(8, 8);
    m_edgeRenderer = new EdgeRenderer(Constants.EDGE_TYPE_CURVE);

    DefaultRendererFactory rf = new DefaultRendererFactory(m_nodeRenderer);
    m_vis.setRendererFactory(rf);

    // DataSizeAction
    DataSizeAction nodeDataSizeAction = new DataSizeAction(NODES, SIZE);
    draw.add(nodeDataSizeAction);
    m_vis.putAction("draw", draw);
    m_vis.putAction("layout", animate);

    m_vis.runAfter("draw", "layout");

    // create the layout action for the graph
    NodeLinkTreeLayout treeLayout = new NodeLinkTreeLayout(GRAPH, m_orientation, 80, 5, 10);
    treeLayout.setLayoutAnchor(new Point2D.Double(250, -150));
    m_vis.putAction("treeLayout", treeLayout);
    m_vis.addFocusGroup("selected");

    CollapsedSubtreeLayout subLayout = new CollapsedSubtreeLayout(GRAPH, m_orientation);
    m_vis.putAction("subLayout", subLayout);

    m_vis.run("treeLayout");
    m_vis.run("draw");

    pan(250, 250);
    setHighQuality(true);
    addControlListener(new ZoomControl());
    addControlListener(new PanControl());
    addControlListener(new DragControl(true));
    addControlListener(new NodeClicked());
    addControlListener(new FocusControl());

    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_LEFT_RIGHT),
        "left-to-right",
        KeyStroke.getKeyStroke("ctrl 1"),
        WHEN_FOCUSED);
    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_TOP_BOTTOM),
        "top-to-bottom",
        KeyStroke.getKeyStroke("ctrl 2"),
        WHEN_FOCUSED);
    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_RIGHT_LEFT),
        "right-to-left",
        KeyStroke.getKeyStroke("ctrl 3"),
        WHEN_FOCUSED);
    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_BOTTOM_TOP),
        "bottom-to-top",
        KeyStroke.getKeyStroke("ctrl 4"),
        WHEN_FOCUSED);
    TupleSet search = new PrefixSearchTupleSet();
    m_vis.addFocusGroup(Visualization.SEARCH_ITEMS, search);
    search.addTupleSetListener(
        new TupleSetListener() {
          public void tupleSetChanged(TupleSet t, Tuple[] add, Tuple[] rem) {
            m_vis.cancel("animatePaint");
            m_vis.run("fullPaint");
            m_vis.run("animatePaint");
          }
        });
  }
  public Display getGraphDisplay(
      GraphLayoutType glType, final ExperimentPanel expPanel, String highlightName) {
    Display display = new Display();
    int X = expPanel.getDetailWidth();
    int Y = expPanel.getDetailHeight();
    display.setSize(X, Y); // set display size
    // display.setHighQuality(true);
    // display.setPreferredSize(new Dimension(600,600));
    display.addControlListener(new DragControl()); // drag items around
    display.addControlListener(new PanControl()); // pan with background left-drag
    display.addControlListener(new WheelZoomControl()); // zoom with vertical right-drag
    display.addControlListener(
        new ZoomToFitControl(Visualization.ALL_ITEMS, 50, 500, Control.MIDDLE_MOUSE_BUTTON));
    display.addControlListener(new NeighborHighlightControl());

    Visualization vis = new Visualization();
    if (clusterGraph == null) {
      clusterGraph = this.toGraph();
    }
    vis.add("graph", clusterGraph);
    LabelRenderer r = new LabelRenderer("name");
    r.setHorizontalAlignment(Constants.CENTER);
    // r.setRoundedCorner(8, 8); // round the corners

    DefaultRendererFactory rf = new DefaultRendererFactory(r);
    rf.setDefaultEdgeRenderer(new EdgeRenderer(Constants.EDGE_TYPE_CURVE));
    vis.setRendererFactory(rf);
    int[] palette = new int[] {ColorLib.rgb(255, 180, 180), ColorLib.rgb(190, 190, 255)};
    DataColorAction fill =
        new DataColorAction(
            "graph.nodes", "type", Constants.NOMINAL, VisualItem.FILLCOLOR, palette);
    fill.add(VisualItem.FIXED, ColorLib.rgb(255, 100, 100));
    fill.add(VisualItem.HIGHLIGHT, ColorLib.rgb(255, 200, 125));
    int[] text_palette = new int[] {ColorLib.gray(0), ColorLib.gray(255)};
    DataColorAction text =
        new DataColorAction(
            "graph.nodes",
            "indeterminate",
            Constants.NUMERICAL,
            VisualItem.TEXTCOLOR,
            text_palette);
    // ColorAction text = new ColorAction("graph.nodes", VisualItem.TEXTCOLOR, ColorLib.gray(0));
    ColorAction edges = new ColorAction("graph.edges", VisualItem.STROKECOLOR, ColorLib.gray(200));

    ActionList color = new ActionList(Activity.INFINITY);
    color.add(text);
    color.add(fill);
    color.add(edges);
    color.add(new RepaintAction());

    if (highlightName != null) {
      String pred = "name='" + highlightName + "'";
      Iterator iter = vis.items("graph.nodes", ExpressionParser.predicate(pred));
      while (iter.hasNext()) {
        NodeItem ni = (NodeItem) iter.next();
        highlightedItem = ni;
        ni.setFixed(true);
        Iterator iterEdge = ni.edges();
        while (iterEdge.hasNext()) {
          EdgeItem eItem = (EdgeItem) iterEdge.next();
          NodeItem nItem = eItem.getAdjacentItem(ni);
          if (eItem.isVisible()) {
            eItem.setHighlighted(true);
            nItem.setHighlighted(true);
          }
        }
      }
    }

    ActionList layout = new ActionList();
    switch (glType) {
      case BALLOON_TREE:
        layout.add(new BalloonTreeLayout("graph"));
        break;
      case FORCE_DIRECTED:
        layout = new ActionList(Activity.INFINITY);
        layout.add(new ForceDirectedLayout("graph"));
        break;
      case NODE_LINK_TREE:
        layout.add(new NodeLinkTreeLayout("graph"));
        break;
      case RADIAL_TREE:
        layout.add(new RadialTreeLayout("graph"));
        break;
    }
    // layout.add(fill);
    layout.add(new RepaintAction());

    vis.putAction("color", color);
    vis.putAction("layout", layout);
    display.setVisualization(vis);
    vis.run("color");
    vis.run("layout");
    // Rectangle2D bounds = vis.getBounds(Visualization.ALL_ITEMS);
    // GraphicsLib.expand(bounds, 50 + (int)(1/display.getScale()));
    // DisplayLib.fitViewToBounds(display,bounds,1);
    // vis.runAfter("layout",1000);

    Control shutoffHighlight =
        new HoverActionControl("color") {
          // public void itemEntered(VisualItem item, MouseEvent evt) {
          // }
          public void itemExited(VisualItem item, MouseEvent evt) {
            if (highlightedItem != null) {
              highlightedItem.setFixed(false);
              Iterator iterEdge = highlightedItem.edges();
              while (iterEdge.hasNext()) {
                EdgeItem eItem = (EdgeItem) iterEdge.next();
                NodeItem nItem = eItem.getAdjacentItem(highlightedItem);
                if (eItem.isVisible()) {
                  eItem.setHighlighted(false);
                  nItem.setHighlighted(false);
                }
              }
              highlightedItem = null;
            }
          }
        };
    display.addControlListener(shutoffHighlight);

    Control selectItem =
        new FocusControl() {

          public void itemClicked(VisualItem item, MouseEvent evt) {
            if (item.isInGroup("graph.nodes")) {
              if (item.getString("type").equals("peptide")) {
                Peptide pep = minPeptides.get(item.getString("name"));
                expPanel.showPeptide(pep, true);
              }
              if (item.getString("type").equals("protein")) {
                Protein pro = minProteins.get(item.getString("name"));
                expPanel.showProtein(pro, true);
              }
              String pred = "name='" + item.getString("name") + "'";
              Iterator iter =
                  item.getVisualization().items("graph.nodes", ExpressionParser.predicate(pred));
              while (iter.hasNext()) {
                NodeItem ni = (NodeItem) iter.next();
                highlightedItem = ni;
                ni.setFixed(true);
                Iterator iterEdge = ni.edges();
                while (iterEdge.hasNext()) {
                  EdgeItem eItem = (EdgeItem) iterEdge.next();
                  NodeItem nItem = eItem.getAdjacentItem(ni);
                  if (eItem.isVisible()) {
                    eItem.setHighlighted(true);
                    nItem.setHighlighted(true);
                  }
                }
              }
            }
          }
        };
    display.addControlListener(selectItem);

    final JPopupMenu menu = new JPopupMenu();

    // Create and add a menu item
    // JMenuItem printItem = new JMenuItem("Print This");
    // printItem.addActionListener(new java.awt.event.ActionListener() {

    //    public void actionPerformed(java.awt.event.ActionEvent evt) {
    //        PrintUtilities.printComponent(display);
    //    }
    // });
    // menu.add(printItem);

    // Set the component to show the popup menu
    display.addMouseListener(
        new MouseAdapter() {

          public void mousePressed(MouseEvent evt) {
            if (evt.isPopupTrigger()) {
              menu.show(evt.getComponent(), evt.getX(), evt.getY());
            }
          }

          public void mouseReleased(MouseEvent evt) {
            if (evt.isPopupTrigger()) {
              menu.show(evt.getComponent(), evt.getX(), evt.getY());
            }
          }
        });
    display.pan(X / 2.0, Y / 2.0);
    return display;
  }
  public DocumentGrid(
      final DocumentGridTable t, String xAxisInitName, String yAxisInitName, String colorInitName) {
    super(new Visualization());
    display = this;
    this.t = t;
    this.controller = MainController.getMainController();
    // add data to visualization (tables, ...)
    VisualTable vt = m_vis.addTable(DATA_GROUP, t);
    colorAttrName = colorInitName;

    // init actionlist: performs initial positioning of the glyphs, axes
    ActionList init = new ActionList();
    // add document layout action
    // rather than taking only the values which are present, let's pull the valid values directly
    // from the ML module, since some applicable values might not be present within the current
    // documents, but we will need these regions to be present in the visualization for dragging?
    //        List<String> xAxisInitCategories = t.getValueListForAttribute(xAxisInitName);
    List<String> xAxisInitCategories = controller.getValuesForAttribute(xAxisInitName);
    //        List<String> yAxisInitCategories = t.getValueListForAttribute(yAxisInitName);
    List<String> yAxisInitCategories = controller.getValuesForAttribute(yAxisInitName);
    documentGridLayout =
        new DocumentGridLayoutNested(
            DATA_GROUP, xAxisInitName, yAxisInitName, xAxisInitCategories, yAxisInitCategories);
    init.add(documentGridLayout);
    // add axes layout action
    docGridAxisLayout = new DocumentGridAxisLayout(ALL_LABEL, documentGridLayout);
    documentGridLayout.setAxisLayout(docGridAxisLayout);
    //        init.add(docGridAxisLayout);  // because of race conditions (DGAL requiring info from
    // DGL which it doesn't have until its layout proceedure has finished), DGAL is now called
    // directly by DGL, no longer as a separate member of the actionlist
    // add init actionlist to vis
    m_vis.putAction("init", init);

    // set up renderer for nodes, set rendererFactory
    nodeRenderer = new DocGlyphRenderer();
    // perform additional optional renderer setup here
    // add primary renderer to visualization
    DefaultRendererFactory rf = new DefaultRendererFactory();
    rf.setDefaultRenderer(nodeRenderer);
    // add auxiliary renderer for axes
    rf.add(new InGroupPredicate(ALL_LABEL), new DocumentGridAxisRenderer(documentGridLayout));
    m_vis.setRendererFactory(rf);

    // ActionList for simple repaint (for simple controls)
    ActionList repaint = new ActionList();
    repaint.add(new RepaintAction());
    m_vis.putAction("repaint", repaint);

    // update actionlist: performs coloration, sizing
    ActionList updateOnce = new ActionList();
    // size action
    // note: sizing is now controlled by the layout action
    //        SizeAction sizeActionUpdate = new DocGlyphSizeAction(DATA_GROUP);
    //        updateOnce.add(sizeActionUpdate);
    // shape action
    // note: now using a constant square shape
    ShapeAction squareShapeAction = new SquareShapeAction();
    updateOnce.add(squareShapeAction);
    // color action(s)
    List<String> colorInitCategories = t.getValueListForAttribute(colorInitName);
    docColorAction = new DocumentColorAction(DATA_GROUP, colorInitName, colorInitCategories);
    updateOnce.add(docColorAction);
    docBorderColorAction = new DocumentBorderColorAction(DATA_GROUP);
    updateOnce.add(docBorderColorAction);
    // visibility filter
    docGlyphVisiblePredicate = new InGroupPredicate(DATA_GROUP);
    docGlyphVisibleFilter = new GlyphVisibilityFilter(DATA_GROUP, docGlyphVisiblePredicate);
    updateOnce.add(docGlyphVisibleFilter);
    // repaint action
    updateOnce.add(new RepaintAction());
    // add update actionlist to vis
    m_vis.putAction("updateOnce", updateOnce);

    // TODO : enable proper animation
    //        ActionList animate = new ActionList(1250);
    //        animate.setPacingFunction(new SlowInSlowOutPacer());
    //        animate.add(new LocationAnimator(DATA_GROUP));
    //        animate.add(new SizeAction(DATA_GROUP));
    //        animate.add(new RepaintAction());
    //        m_vis.putAction("animate", animate);

    // get reference to glasspane
    glassPane = controller.getGlassPane();

    // set initial / basic properties of the display
    setSize(700, 600);
    setBackground(Color.LIGHT_GRAY);
    setBorder(BorderFactory.createEmptyBorder(30, 20, 5, 20));

    // for doc highlighting on search (partially adapted from TreeMap.java in Prefuse demo gallery)
    searchQ = new SearchQueryBinding(t, DocumentGridTable.NODE_TEXT);
    m_vis.addFocusGroup(Visualization.SEARCH_ITEMS, searchQ.getSearchSet());
    searchQ
        .getPredicate()
        .addExpressionListener(
            new UpdateListener() {
              @Override
              public void update(Object src) {
                //                // debug
                //                System.out.println("\n\ndebug: "+this.getClass().getName()+": in
                // SEARCH_ITEMS group: ");
                // update focus text for all items in visualtable, wrt. query
                // TODO : improve efficiency of this predicate updating method
                String queryStr = searchQ.getSearchSet().getQuery();
                Scanner querySplitter = new Scanner(queryStr);
                List<String> terms = new ArrayList<>();
                while (querySplitter.hasNext()) {
                  String term = querySplitter.next();
                  terms.add(term.trim());
                }

                // debug
                //                System.out.println("debug: "+this.getClass().getName()+": query
                // string: "+queryStr);
                int numRows = t.getRowCount();
                for (int i = 0; i < numRows; i++) {
                  t.setString(i, DocumentGridTable.NODE_FOCUS_TEXT, "");

                  String text = t.getString(i, DocumentGridTable.NODE_TEXT).toLowerCase();
                  boolean containsAllTerms = true;
                  for (String term : terms) {
                    if (!text.contains(term)) {
                      containsAllTerms = false;
                      break;
                    }
                  }
                  //                    if (!containsAllTerms) {
                  // TODO properly remove non-matching items from search set?
                  //                        searchQ.getSearchSet().removeTuple(t.getTuple(i));  //
                  // throws UnsupportedOperationException
                  //                    } else {
                  // set highlight text
                  // do very coarse "sentence-splitting"
                  // TODO : proper sentence parsing
                  List<String> focusSents = new ArrayList<>();
                  Scanner sentSplitter = new Scanner(text);
                  //                        sentSplitter.useDelimiter("[\\.\n]");  // split on
                  // period or newline
                  sentSplitter.useDelimiter("[\\.]"); // split on period only
                  while (sentSplitter.hasNext()) {
                    String sent = sentSplitter.next();
                    for (String term : terms) {
                      if (sent.contains(term)) {
                        focusSents.add(sent);
                      }
                    }
                  }
                  if (focusSents.size() > 0) {
                    StringBuilder focusText = new StringBuilder();
                    focusText.append(FOCUS_SENT_SPLITTER);
                    for (String focusSent : focusSents) {
                      focusText.append(focusSent);
                      focusText.append(FOCUS_SENT_SPLITTER + "\n");
                    }
                    t.setString(i, DocumentGridTable.NODE_FOCUS_TEXT, focusText.toString());
                  }
                  //                    }
                }

                // run repaint actions
                m_vis.run("updateOnce");
              }
            });

    // set up control listeners
    // zoom with wheel
    //        addControlListener(new WheelZoomControl());
    // zoom with background right-drag
    //        addControlListener(new ZoomControl(Control.RIGHT_MOUSE_BUTTON));
    // pan with background left-drag
    //        addControlListener(new PanControl(Control.RIGHT_MOUSE_BUTTON));
    // drag control for moving items to new cells
    docDragControl = new DocGridDragControl(DATA_GROUP, documentGridLayout, controller);
    addControlListener(docDragControl);
    // control for loading document details in glasspane
    docSelectControl = new DocumentSelectControl(glassPane);
    addControlListener(docSelectControl);

    // run actionlists

    m_vis.alwaysRunAfter("init", "updateOnce");

    m_vis.run("init");
  }
  public ConcordanceTree() {
    super(new Visualization());

    m_display_self = this;
    m_label = NAME;

    tree = new Tree();
    Table ntable = tree.getNodeTable();
    ntable.addColumn(NAME, String.class);
    ntable.addColumn(NODECOUNT, int.class);
    ntable.addColumn(ROWCOUNT, int.class);
    resetTree();

    m_vis.add(TREE, tree);
    // m_vis.add(TREE, t, new WordCountPredicate());

    m_nodeRenderer = new LabelRenderer(m_label);
    m_nodeRenderer.setRenderType(AbstractShapeRenderer.RENDER_TYPE_FILL);
    m_nodeRenderer.setHorizontalAlignment(Constants.LEFT);
    m_nodeRenderer.setRoundedCorner(8, 8);
    m_edgeRenderer = new EdgeRenderer(Constants.EDGE_TYPE_CURVE);

    DefaultRendererFactory rf = new DefaultRendererFactory(m_nodeRenderer);
    rf.add(new InGroupPredicate(TREEEDGES), m_edgeRenderer);
    m_vis.setRendererFactory(rf);

    // colors
    ItemAction nodeColor = new NodeColorAction(TREENODES);
    ItemAction textColor = new ColorAction(TREENODES, VisualItem.TEXTCOLOR, ColorLib.rgb(0, 0, 0));
    m_vis.putAction("textColor", textColor);

    ItemAction edgeColor =
        new ColorAction(TREEEDGES, VisualItem.STROKECOLOR, ColorLib.rgb(255, 155, 155));

    // quick repaint
    ActionList repaint = new ActionList();
    repaint.add(nodeColor);
    // WordSizeAction wsaction = new WordSizeAction(TREEEDGES);
    repaint.add(new RepaintAction());
    m_vis.putAction("repaint", repaint);

    // full paint
    ActionList fullPaint = new ActionList();
    fullPaint.add(nodeColor);
    m_vis.putAction("fullPaint", fullPaint);

    // animate paint change
    ActionList animatePaint = new ActionList(400);
    animatePaint.add(new ColorAnimator(TREENODES));
    animatePaint.add(new RepaintAction());
    m_vis.putAction("animatePaint", animatePaint);

    // create the tree layout action
    NodeLinkTreeLayout treeLayout = new NodeLinkTreeLayout(TREE, m_orientation, 10, 0, 0);

    Point2D anchor = new Point2D.Double(25, HEIGHT / 2);
    treeLayout.setLayoutAnchor(anchor);
    m_vis.putAction("treeLayout", treeLayout);

    CollapsedSubtreeLayout subLayout = new CollapsedSubtreeLayout(TREE, m_orientation);
    m_vis.putAction("subLayout", subLayout);

    AutoPanAction autoPan = new AutoPanAction();
    AutoCenterAction autocenter = new AutoCenterAction();
    AutoFitAction autofit = new AutoFitAction();

    ActionList positioning = new ActionList();
    positioning.add(autofit);
    m_vis.putAction("positioning", positioning);

    ActionList fna = new ActionList();
    fna.add(new WordFontAction(TREENODES, defaultTreeFont));
    //   fna.add(new EdgeWidthAction(TREEEDGES));
    // fna.add(new WordSizeAction(TREEEDGES));
    m_vis.putAction("fontnodeaction", fna);

    // create the filtering and layout
    ActionList filter = new ActionList();
    filter.add(fna);
    filter.add(fisheyetreefilter);
    // VisibilityFilter visibfilter = new VisibilityFilter(new WordCountPredicate());
    // filter.add(visibfilter);
    filter.add(treeLayout);
    filter.add(subLayout);
    filter.add(textColor);
    filter.add(nodeColor);
    filter.add(edgeColor);
    m_vis.putAction("filter", filter);

    // This doesn't quite work as expected; the layout is calculated
    // for the entire tree and low freq nodes are simply not shown,
    // leaving gaps in the layout
    //
    // setPredicate(new WordCountPredicate());

    // animated transition
    ActionList animate = new ActionList(1000);
    animate.setPacingFunction(new SlowInSlowOutPacer());
    // animate.add(autoPan);
    animate.add(new QualityControlAnimator());
    animate.add(new VisibilityAnimator(TREE));
    animate.add(new LocationAnimator(TREENODES));
    animate.add(new ColorAnimator(TREENODES));
    animate.add(new RepaintAction());
    m_vis.putAction("animate", animate);
    m_vis.alwaysRunAfter("filter", "animate");

    // create animator for orientation changes
    ActionList orient = new ActionList(2000);
    orient.setPacingFunction(new SlowInSlowOutPacer());
    // orient.add(autoPan);
    // orient.add(autocenter);
    orient.add(new QualityControlAnimator());
    orient.add(new LocationAnimator(TREENODES));
    orient.add(new RepaintAction());
    // orient.add(autofit);

    m_vis.putAction("orient", orient);

    // ------------------------------------------------

    // initialize the display
    setSize(WIDTH, HEIGHT);
    setItemSorter(new TreeDepthItemSorter());
    addControlListener(new ZoomToFitControl());
    addControlListener(new ZoomControl());
    addControlListener(new WheelZoomControl());
    addControlListener(new PanControl());
    addControlListener(new FocusControl(1, "filter"));
    addControlListener(new ToolTipControl(NODECOUNT));

    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_LEFT_RIGHT),
        "left-to-right",
        KeyStroke.getKeyStroke("ctrl 1"),
        WHEN_IN_FOCUSED_WINDOW);
    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_TOP_BOTTOM),
        "top-to-bottom",
        KeyStroke.getKeyStroke("ctrl 2"),
        WHEN_IN_FOCUSED_WINDOW);
    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_RIGHT_LEFT),
        "right-to-left",
        KeyStroke.getKeyStroke("ctrl 3"),
        WHEN_IN_FOCUSED_WINDOW);
    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_BOTTOM_TOP),
        "bottom-to-top",
        KeyStroke.getKeyStroke("ctrl 4"),
        WHEN_IN_FOCUSED_WINDOW);
    registerKeyboardAction(
        new FisheyeExpandAction(-1),
        "collapse-one",
        KeyStroke.getKeyStroke("ctrl 5"),
        WHEN_IN_FOCUSED_WINDOW);
    registerKeyboardAction(
        new FisheyeExpandAction(+1),
        "expand-one",
        KeyStroke.getKeyStroke("ctrl 6"),
        WHEN_IN_FOCUSED_WINDOW);

    // ------------------------------------------------

    // filter graph and perform layout
    setOrientation(m_orientation);
    m_vis.run("filter");

    /*
    TupleSet search = new PrefixSearchTupleSet();
      m_vis.addFocusGroup(Visualization.SEARCH_ITEMS, search);
      search.addTupleSetListener(new TupleSetListener() {
          public void tupleSetChanged(TupleSet t, Tuple[] add, Tuple[] rem) {
            m_vis.cancel("animatePaint");
            m_vis.run("fullPaint");
            m_vis.run("animatePaint");
          }
        });
       */

  }
  public PhysioMapRadialGraphView(
      SemGenSettings sets, Graph g, String label, SemSimModel semsimmodel) {
    super(new Visualization());
    this.semsimmodel = semsimmodel;

    // -- set up visualization --
    m_vis.add(tree, g);
    m_vis.setInteractive(treeEdges, null, false);

    // -- set up renderers --
    LabelRenderer m_nodeRenderer = new LabelRenderer(label);
    m_nodeRenderer.setRenderType(AbstractShapeRenderer.RENDER_TYPE_DRAW_AND_FILL);
    m_nodeRenderer.setHorizontalAlignment(Constants.CENTER);
    m_nodeRenderer.setRoundedCorner(8, 8);
    EdgeRenderer m_edgeRenderer =
        new EdgeRenderer(Constants.EDGE_TYPE_LINE, prefuse.Constants.EDGE_ARROW_REVERSE);
    m_edgeRenderer.setArrowType(prefuse.Constants.EDGE_ARROW_REVERSE);
    m_edgeRenderer.setArrowHeadSize(8, 8);

    // MAYBE HERE?
    DefaultRendererFactory rf = new DefaultRendererFactory(m_nodeRenderer);
    rf.add(new InGroupPredicate(treeEdges), m_edgeRenderer);
    m_vis.setRendererFactory(rf);
    // m_vis.

    // -- set up processing actions --
    // colors
    ItemAction nodeColor = new NodeColorAction(treeNodes);
    ItemAction borderColor = new BorderColorAction(treeNodes);
    m_vis.putAction("borderColor", borderColor);
    ItemAction textColor = new TextColorAction(treeNodes);
    m_vis.putAction("textColor", textColor);
    ItemAction edgeColor =
        new ColorAction(treeEdges, VisualItem.STROKECOLOR, ColorLib.rgb(0, 0, 0));
    ItemAction arrowColor = new ArrowColorAction(treeEdges);
    m_vis.putAction("arrowColor", arrowColor);

    FontAction fonts = new FontAction(treeNodes, FontLib.getFont("Verdana", 12));
    fonts.add("ingroup('_focus_')", FontLib.getFont("Verdana", 12));

    // recolor
    // When recolor, do these actions
    ActionList recolor = new ActionList();
    recolor.add(nodeColor);
    recolor.add(borderColor);
    recolor.add(textColor);
    recolor.add(arrowColor);
    m_vis.putAction("recolor", recolor);

    // repaint
    ActionList repaint = new ActionList();
    repaint.add(recolor);
    repaint.add(new RepaintAction());
    m_vis.putAction("repaint", repaint);

    // animate paint change
    ActionList animatePaint = new ActionList(400);
    animatePaint.add(new ColorAnimator(treeNodes));
    animatePaint.add(new RepaintAction());
    m_vis.putAction("animatePaint", animatePaint);

    // create the tree layout action
    RadialTreeLayout treeLayout = new RadialTreeLayout(tree);
    treeLayout.setAutoScale(true);
    m_vis.putAction("treeLayout", treeLayout);

    CollapsedSubtreeLayout subLayout = new CollapsedSubtreeLayout(tree);
    m_vis.putAction("subLayout", subLayout);

    // create the filtering and layout
    ActionList filter = new ActionList();
    filter.add(new TreeRootAction(tree));
    filter.add(fonts);
    filter.add(treeLayout);
    filter.add(borderColor);
    filter.add(subLayout);
    filter.add(textColor);
    filter.add(nodeColor);
    filter.add(edgeColor);
    filter.add(arrowColor);
    m_vis.putAction("filter", filter);

    // animated transition
    ActionList animate = new ActionList(700);
    animate.setPacingFunction(new SlowInSlowOutPacer());
    animate.add(new QualityControlAnimator());
    animate.add(new VisibilityAnimator(tree));
    animate.add(new PolarLocationAnimator(treeNodes, linear));
    animate.add(new ColorAnimator(treeNodes));
    animate.add(new RepaintAction());
    m_vis.putAction("animate", animate);
    m_vis.alwaysRunAfter("filter", "animate");
    // ------------------------------------------------

    // initialize the display

    setSize(sets.getAppWidth() - ExtractorTab.leftpanewidth - 50, sets.getAppHeight() - 235);
    setItemSorter(new TreeDepthItemSorter());
    addControlListener(new DragControl());
    addControlListener(new ZoomToFitControl());
    addControlListener(new ZoomControl());
    addControlListener(new PanControl());
    addControlListener(new FocusControl(1, "filter"));
    addControlListener(new HoverActionControl("repaint"));

    // ------------------------------------------------

    // filter graph and perform layout
    m_vis.run("filter");

    // maintain a set of items that should be interpolated linearly
    // this isn't absolutely necessary, but makes the animations nicer
    // the PolarLocationAnimator should read this set and act accordingly
    m_vis.addFocusGroup(linear, new DefaultTupleSet());
    m_vis
        .getGroup(Visualization.FOCUS_ITEMS)
        .addTupleSetListener(
            new TupleSetListener() {
              public void tupleSetChanged(TupleSet t, Tuple[] add, Tuple[] rem) {
                TupleSet linearInterp = m_vis.getGroup(linear);
                if (add.length < 1) return;
                linearInterp.clear();
                for (Node n = (Node) add[0]; n != null; n = n.getParent()) linearInterp.addTuple(n);
              }
            });

    SearchTupleSet search = new PrefixSearchTupleSet();
    m_vis.addFocusGroup(Visualization.SEARCH_ITEMS, search);
    search.addTupleSetListener(
        new TupleSetListener() {
          public void tupleSetChanged(TupleSet t, Tuple[] add, Tuple[] rem) {
            m_vis.cancel("animatePaint");
            m_vis.run("recolor");
            m_vis.run("animatePaint");
          }
        });
  }
  public AggregateDemo() {
    // initialize display and data
    super(new Visualization());
    initDataGroups();

    // set up the renderers
    // draw the nodes as basic shapes
    Renderer nodeR = new ShapeRenderer(20);
    // draw aggregates as polygons with curved edges
    Renderer polyR = new PolygonRenderer(Constants.POLY_TYPE_CURVE);
    ((PolygonRenderer) polyR).setCurveSlack(0.15f);

    // modification to try drawing edges to aggregates
    Renderer edgeR =
        new EdgeRenderer() {
          @Override
          protected Shape getRawShape(VisualItem item) {
            EdgeItem edge = (EdgeItem) item;
            VisualItem item1 = edge.getSourceItem();
            VisualItem item2 = edge.getTargetItem();
            item2 = (AggregateItem) at.getAggregates(item2).next();

            int type = m_edgeType;

            getAlignedPoint(m_tmpPoints[0], item1.getBounds(), m_xAlign1, m_yAlign1);
            getAlignedPoint(m_tmpPoints[1], item2.getBounds(), m_xAlign2, m_yAlign2);
            m_curWidth = (float) (m_width * getLineWidth(item));

            // create the arrow head, if needed
            EdgeItem e = (EdgeItem) item;
            if (e.isDirected() && m_edgeArrow != Constants.EDGE_ARROW_NONE) {
              // get starting and ending edge endpoints
              boolean forward = (m_edgeArrow == Constants.EDGE_ARROW_FORWARD);
              Point2D start = null, end = null;
              start = m_tmpPoints[forward ? 0 : 1];
              end = m_tmpPoints[forward ? 1 : 0];

              // compute the intersection with the target bounding box
              VisualItem dest = forward ? e.getTargetItem() : e.getSourceItem();
              int i =
                  GraphicsLib.intersectLineRectangle(start, end, dest.getBounds(), m_isctPoints);
              if (i > 0) end = m_isctPoints[0];

              // create the arrow head shape
              AffineTransform at = getArrowTrans(start, end, m_curWidth);
              m_curArrow = at.createTransformedShape(m_arrowHead);

              // update the endpoints for the edge shape
              // need to bias this by arrow head size
              Point2D lineEnd = m_tmpPoints[forward ? 1 : 0];
              lineEnd.setLocation(0, -m_arrowHeight);
              at.transform(lineEnd, lineEnd);
            } else {
              m_curArrow = null;
            }

            // create the edge shape
            Shape shape = null;
            double n1x = m_tmpPoints[0].getX();
            double n1y = m_tmpPoints[0].getY();
            double n2x = m_tmpPoints[1].getX();
            double n2y = m_tmpPoints[1].getY();
            switch (type) {
              case Constants.EDGE_TYPE_LINE:
                m_line.setLine(n1x, n1y, n2x, n2y);
                shape = m_line;
                break;
              case Constants.EDGE_TYPE_CURVE:
                getCurveControlPoints(edge, m_ctrlPoints, n1x, n1y, n2x, n2y);
                m_cubic.setCurve(
                    n1x,
                    n1y,
                    m_ctrlPoints[0].getX(),
                    m_ctrlPoints[0].getY(),
                    m_ctrlPoints[1].getX(),
                    m_ctrlPoints[1].getY(),
                    n2x,
                    n2y);
                shape = m_cubic;
                break;
              default:
                throw new IllegalStateException("Unknown edge type");
            }

            // return the edge shape
            return shape;
          }
        };

    DefaultRendererFactory drf = new DefaultRendererFactory(nodeR, edgeR);
    drf.add("ingroup('aggregates')", polyR);
    m_vis.setRendererFactory(drf);

    // set up the visual operators
    // first set up all the color actions
    ColorAction nStroke = new ColorAction(NODES, VisualItem.STROKECOLOR);
    nStroke.setDefaultColor(ColorLib.gray(100));
    nStroke.add("_hover", ColorLib.gray(50));

    ColorAction nFill = new ColorAction(NODES, VisualItem.FILLCOLOR);
    nFill.setDefaultColor(ColorLib.gray(255));
    nFill.add("_hover", ColorLib.gray(200));

    ColorAction nEdges = new ColorAction(EDGES, VisualItem.STROKECOLOR);
    nEdges.setDefaultColor(ColorLib.gray(100));

    ColorAction aStroke = new ColorAction(AGGR, VisualItem.STROKECOLOR);
    aStroke.setDefaultColor(ColorLib.gray(200));
    aStroke.add("_hover", ColorLib.rgb(255, 100, 100));

    int[] palette =
        new int[] {
          ColorLib.rgba(255, 200, 200, 255),
          ColorLib.rgba(200, 255, 200, 255),
          ColorLib.rgba(200, 200, 255, 255)
        };
    ColorAction aFill =
        new DataColorAction(AGGR, "id", Constants.NOMINAL, VisualItem.FILLCOLOR, palette);

    // bundle the color actions
    ActionList colors = new ActionList();
    colors.add(nStroke);
    colors.add(nFill);
    colors.add(nEdges);
    colors.add(aStroke);
    colors.add(aFill);

    // now create the main layout routine
    ActionList layout = new ActionList(Activity.INFINITY);
    layout.add(colors);
    layout.add(new ForceDirectedLayout(GRAPH, true));
    layout.add(new AggregateLayout(AGGR));
    layout.add(new RepaintAction());
    m_vis.putAction("layout", layout);

    // set up the display
    setSize(500, 500);
    pan(250, 250);
    setHighQuality(true);
    addControlListener(new AggregateDragControl());
    addControlListener(new ZoomControl());
    addControlListener(new PanControl());

    // set things running
    m_vis.run("layout");
  }
  public static JComponent demo(Graph g, String label) {

    // create a new, empty visualization for our data
    final Visualization vis = new Visualization();
    VisualGraph vg = vis.addGraph(graph, g);
    vis.setValue(edges, null, VisualItem.INTERACTIVE, Boolean.FALSE);
    int[] palette =
        new int[] {
          ColorLib.rgb(77, 175, 74),
          ColorLib.rgb(55, 126, 184),
          ColorLib.rgb(228, 26, 28),
          ColorLib.rgb(152, 78, 163),
          ColorLib.rgb(255, 127, 0)
        };

    int[] shape_palette =
        new int[] {Constants.SHAPE_ELLIPSE, Constants.SHAPE_RECTANGLE, Constants.SHAPE_TRIANGLE_UP};

    TupleSet focusGroup = vis.getGroup(Visualization.FOCUS_ITEMS);
    focusGroup.addTupleSetListener(
        new TupleSetListener() {
          public void tupleSetChanged(TupleSet ts, Tuple[] add, Tuple[] rem) {
            for (int i = 0; i < rem.length; ++i) ((VisualItem) rem[i]).setFixed(false);
            for (int i = 0; i < add.length; ++i) {
              ((VisualItem) add[i]).setFixed(false);
              ((VisualItem) add[i]).setFixed(true);
            }
            vis.run("draw");
          }
        });

    // set up the renderers

    /*      ShapeRenderer s = new ShapeRenderer();
    s.rectangle(0, 0, 30, 30);
    vis.setRendererFactory(new DefaultRendererFactory(s));*/

    MyRenderer tr = new MyRenderer(label);
    // MyRenderer tr = new MyRenderer(label);
    DefaultRendererFactory d = new DefaultRendererFactory(tr);

    EdgeRenderer MyEdgeRenderer = new EdgeRenderer();
    d.add(new InGroupPredicate(edges), MyEdgeRenderer);
    vis.setRendererFactory(d);

    // -- set up the actions ----------------------------------------------

    int maxhops = 1024, hops = 1024;
    final GraphDistanceFilter filter = new GraphDistanceFilter(graph, hops);

    ActionList draw = new ActionList();
    draw.add(filter);

    // draw.add(new ColorAction(nodes, VisualItem.FILLCOLOR, ColorLib.rgb(180,180,255)));
    draw.add(new ColorAction(nodes, VisualItem.STROKECOLOR, 0));
    draw.add(new ColorAction(nodes, VisualItem.TEXTCOLOR, ColorLib.rgb(0, 0, 0)));
    draw.add(new ColorAction(edges, VisualItem.FILLCOLOR, ColorLib.gray(100)));
    draw.add(new ColorAction(edges, VisualItem.STROKECOLOR, ColorLib.gray(170)));
    draw.add(new DataShapeAction(nodes, "type", shape_palette));

    DataColorAction fill =
        new DataColorAction(
            "graph.nodes", "type", Constants.NOMINAL, VisualItem.FILLCOLOR, palette);
    // use black for node text
    ColorAction text = new ColorAction("graph.nodes", VisualItem.TEXTCOLOR, ColorLib.gray(0));
    // use light grey for edges
    ColorAction edges = new ColorAction("graph.edges", VisualItem.STROKECOLOR, ColorLib.gray(200));

    // create an action list containing all color assignments
    ActionList color = new ActionList();
    color.add(fill);
    color.add(text);
    color.add(edges);

    //        ColorAction fill = new ColorAction(nodes,
    //                VisualItem.FILLCOLOR, ColorLib.rgb(200,200,255));
    fill.add("_fixed", ColorLib.rgb(255, 100, 100));
    fill.add("_highlight", ColorLib.rgb(255, 200, 125));

    // Instead have to use  GridLayout here - how do i create
    ForceDirectedLayout fdl = new ForceDirectedLayout(graph);
    // GridLayout fdl = new GridLayout(graph);
    ForceSimulator fsim = fdl.getForceSimulator();
    fsim.getForces()[0].setParameter(0, -5f);

    ActionList animate = new ActionList(Activity.INFINITY);
    // ActionList animate = new ActionList(vis);

    animate.add(fdl);
    animate.add(fill);
    animate.add(new RepaintAction());

    // finally, we register our ActionList with the Visualization.
    // we can later execute our Actions by invoking a method on our
    // Visualization, using the name we've chosen below.
    vis.putAction("draw", draw);
    vis.putAction("layout", animate);
    vis.runAfter("draw", "layout");
    vis.putAction("color", color);
    // vis.putAction("layout", layout);

    // --------------------------------------------------------------------
    // STEP 4: set up a display to show the visualization

    Display display = new Display(vis);
    display.setSize(2000, 2000);
    display.setForeground(Color.GRAY);
    display.setBackground(Color.WHITE);

    // main display controls
    display.addControlListener(new FocusControl(1));
    display.addControlListener(new DragControl());
    display.addControlListener(new PanControl());
    display.addControlListener(new ZoomControl());
    display.addControlListener(new WheelZoomControl());
    display.addControlListener(new ZoomToFitControl());
    display.addControlListener(new NeighborHighlightControl());

    display.setForeground(Color.GRAY);
    display.setBackground(Color.WHITE);

    // --------------------------------------------------------------------
    // STEP 5: launching the visualization

    // create a panel for editing force values
    final JForcePanel fpanel = new JForcePanel(fsim);

    final JValueSlider slider = new JValueSlider("Distance", 0, maxhops, hops);
    slider.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            filter.setDistance(slider.getValue().intValue());
            vis.run("draw");
          }
        });
    slider.setBackground(Color.WHITE);
    slider.setPreferredSize(new Dimension(300, 30));
    slider.setMaximumSize(new Dimension(300, 30));

    Box cf = new Box(BoxLayout.Y_AXIS);
    cf.add(slider);
    cf.setBorder(BorderFactory.createTitledBorder("Connectivity Filter"));
    fpanel.add(cf);

    fpanel.add(Box.createVerticalGlue());

    // create a new JSplitPane to present the interface
    JSplitPane split = new JSplitPane();
    split.setLeftComponent(display);
    split.setRightComponent(fpanel);
    split.setOneTouchExpandable(true);
    split.setContinuousLayout(false);
    split.setDividerLocation(530);
    split.setDividerLocation(800);

    // position and fix the default focus node
    NodeItem focus = (NodeItem) vg.getNode(0);
    PrefuseLib.setX(focus, null, 400);
    PrefuseLib.setY(focus, null, 250);
    focusGroup.setTuple(focus);

    // now we run our action list and return
    return split;
  }