public Congress(Table t) {
    super(new BorderLayout());

    // --------------------------------------------------------------------
    // STEP 1: setup the visualized data

    final Visualization vis = new Visualization();
    m_vis = vis;

    final String group = "by_state";

    // filter to show only candidates receiving more than $100,000
    Predicate p = (Predicate) ExpressionParser.parse("[" + TOTAL_RECEIPTS + "] >= 100000");
    VisualTable vt = vis.addTable(group, t, p);

    // add a new column containing a label string showing
    // candidate name, party, state, year, and total receipts
    vt.addColumn(
        "label",
        "CONCAT(CAP(Candidate), ' (', "
            + "CAP([Party Designation]), '-', [State Code], "
            + "') ', Year, ': $', FORMAT([Total Receipts],2))");

    // add calculation for senators
    vt.addColumn("Senate", "District <= 0");

    vis.setRendererFactory(
        new RendererFactory() {
          AbstractShapeRenderer sr = new ShapeRenderer();
          Renderer arY = new AxisRenderer(Constants.RIGHT, Constants.TOP);
          Renderer arX = new AxisRenderer(Constants.CENTER, Constants.FAR_BOTTOM);

          public Renderer getRenderer(VisualItem item) {
            return item.isInGroup("ylab") ? arY : item.isInGroup("xlab") ? arX : sr;
          }
        });

    // --------------------------------------------------------------------
    // STEP 2: create actions to process the visual data

    // set up dynamic queries, search set
    RangeQueryBinding receiptsQ = new RangeQueryBinding(vt, RECEIPTS);
    ListQueryBinding yearsQ = new ListQueryBinding(vt, "Year");
    SearchQueryBinding searchQ = new SearchQueryBinding(vt, "Candidate");

    // construct the filtering predicate
    AndPredicate filter = new AndPredicate(searchQ.getPredicate());
    filter.add(yearsQ.getPredicate());
    filter.add(receiptsQ.getPredicate());

    // set up the actions
    AxisLayout xaxis = new AxisLayout(group, "State Code", Constants.X_AXIS, VisiblePredicate.TRUE);
    AxisLayout yaxis = new AxisLayout(group, RECEIPTS, Constants.Y_AXIS, VisiblePredicate.TRUE);
    // yaxis.setScale(Constants.LOG_SCALE);
    yaxis.setRangeModel(receiptsQ.getModel());
    receiptsQ.getNumberModel().setValueRange(0, 65000000, 0, 65000000);

    xaxis.setLayoutBounds(m_dataB);
    yaxis.setLayoutBounds(m_dataB);

    AxisLabelLayout ylabels = new AxisLabelLayout("ylab", yaxis, m_ylabB);
    NumberFormat nf = NumberFormat.getCurrencyInstance();
    nf.setMaximumFractionDigits(0);
    ylabels.setNumberFormat(nf);

    AxisLabelLayout xlabels = new AxisLabelLayout("xlab", xaxis, m_xlabB, 15);
    vis.putAction("xlabels", xlabels);

    // dems = blue, reps = red, other = gray
    int[] palette =
        new int[] {
          ColorLib.rgb(150, 150, 255), ColorLib.rgb(255, 150, 150), ColorLib.rgb(180, 180, 180)
        };
    DataColorAction color =
        new DataColorAction(group, "Party", Constants.ORDINAL, VisualItem.STROKECOLOR, palette);

    int[] shapes = new int[] {Constants.SHAPE_RECTANGLE, Constants.SHAPE_DIAMOND};
    DataShapeAction shape = new DataShapeAction(group, "Senate", shapes);

    Counter cntr = new Counter(group);

    ActionList draw = new ActionList();
    draw.add(cntr);
    draw.add(color);
    draw.add(shape);
    draw.add(xaxis);
    draw.add(yaxis);
    draw.add(ylabels);
    draw.add(new ColorAction(group, VisualItem.FILLCOLOR, 0));
    draw.add(new RepaintAction());
    vis.putAction("draw", draw);

    ActionList update = new ActionList();
    update.add(new VisibilityFilter(group, filter));
    update.add(cntr);
    update.add(xaxis);
    update.add(yaxis);
    update.add(ylabels);
    update.add(new RepaintAction());
    vis.putAction("update", update);

    UpdateListener lstnr =
        new UpdateListener() {
          public void update(Object src) {
            vis.run("update");
          }
        };
    filter.addExpressionListener(lstnr);

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

    m_display = new Display(vis);
    m_display.setItemSorter(
        new ItemSorter() {
          public int score(VisualItem item) {
            int score = super.score(item);
            if (item.isInGroup(group)) score += item.getInt(TOTAL_RECEIPTS);
            return score;
          }
        });
    m_display.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    m_display.setSize(700, 450);
    m_display.setHighQuality(true);
    m_display.addComponentListener(
        new ComponentAdapter() {
          public void componentResized(ComponentEvent e) {
            displayLayout();
          }
        });
    displayLayout();

    m_details = new JFastLabel(m_title);
    m_details.setPreferredSize(new Dimension(75, 20));
    m_details.setVerticalAlignment(SwingConstants.BOTTOM);

    m_total.setPreferredSize(new Dimension(500, 20));
    m_total.setHorizontalAlignment(SwingConstants.RIGHT);
    m_total.setVerticalAlignment(SwingConstants.BOTTOM);

    ToolTipControl ttc = new ToolTipControl("label");
    Control hoverc =
        new ControlAdapter() {
          public void itemEntered(VisualItem item, MouseEvent evt) {
            if (item.isInGroup(group)) {
              m_total.setText(item.getString("label"));
              item.setFillColor(item.getStrokeColor());
              item.setStrokeColor(ColorLib.rgb(0, 0, 0));
              item.getVisualization().repaint();
            }
          }

          public void itemExited(VisualItem item, MouseEvent evt) {
            if (item.isInGroup(group)) {
              m_total.setText(m_totalStr);
              item.setFillColor(item.getEndFillColor());
              item.setStrokeColor(item.getEndStrokeColor());
              item.getVisualization().repaint();
            }
          }
        };
    m_display.addControlListener(ttc);
    m_display.addControlListener(hoverc);

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

    this.addComponentListener(lstnr);

    // details
    Box infoBox = new Box(BoxLayout.X_AXIS);
    infoBox.add(Box.createHorizontalStrut(5));
    infoBox.add(m_details);
    infoBox.add(Box.createHorizontalGlue());
    infoBox.add(Box.createHorizontalStrut(5));
    infoBox.add(m_total);
    infoBox.add(Box.createHorizontalStrut(5));

    // set up search box
    JSearchPanel searcher = searchQ.createSearchPanel();
    searcher.setLabelText("Candidate: ");
    searcher.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0));

    // create dynamic queries
    Box radioBox = new Box(BoxLayout.X_AXIS);
    radioBox.add(Box.createHorizontalStrut(5));
    radioBox.add(searcher);
    radioBox.add(Box.createHorizontalGlue());
    radioBox.add(Box.createHorizontalStrut(5));
    radioBox.add(yearsQ.createRadioGroup());
    radioBox.add(Box.createHorizontalStrut(16));

    JRangeSlider slider = receiptsQ.createVerticalRangeSlider();
    slider.setThumbColor(null);
    slider.setMinExtent(150000);
    slider.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            m_display.setHighQuality(false);
          }

          public void mouseReleased(MouseEvent e) {
            m_display.setHighQuality(true);
            m_display.repaint();
          }
        });

    vis.run("draw");
    vis.run("xlabels");

    add(infoBox, BorderLayout.NORTH);
    add(m_display, BorderLayout.CENTER);
    add(slider, BorderLayout.EAST);
    add(radioBox, BorderLayout.SOUTH);
    UILib.setColor(this, ColorLib.getColor(255, 255, 255), Color.GRAY);
    slider.setForeground(Color.LIGHT_GRAY);
    UILib.setFont(radioBox, FontLib.getFont("Tahoma", 15));
    m_details.setFont(FontLib.getFont("Tahoma", 18));
    m_total.setFont(FontLib.getFont("Tahoma", 16));
  }
Example #2
0
public class NetMonitor {

  public static String ACCELX = "accelX";
  public static String ACCELY = "accelY";
  public static String ACCELZ = "accelZ";
  public static String NODEID = "NodeID";
  public static String LABEL = "Label";
  public static String PARENT = "ParentID";
  public static String COLOR = "MyColor";
  public static String LEVEL = "Level";
  public static String DATATABLE = "Datatable";
  public static String TEMP = "Temperature";
  public static String CURRENT = "Current";

  public static String EDGETYPE = "EdgeType";

  public static String TREEEDGE = "TreeEdge";
  public static Predicate treeEdgePred =
      (Predicate)
          ExpressionParser.parse(
              "ISEDGE() AND (" + NetMonitor.EDGETYPE + " = \"" + NetMonitor.TREEEDGE + "\")");
  public static String TREEEDGESTATE = "TreeEdgeState";
  public static Predicate treeEdgeStatePred =
      (Predicate)
          ExpressionParser.parse(
              "ISEDGE() AND (" + NetMonitor.EDGETYPE + " = \"" + NetMonitor.TREEEDGESTATE + "\")");
  public static String TREEEDGEALARM = "TreeEdgeAlarm";
  public static Predicate treeEdgeAlarmPred =
      (Predicate)
          ExpressionParser.parse(
              "ISEDGE() AND (" + NetMonitor.EDGETYPE + " = \"" + NetMonitor.TREEEDGEALARM + "\")");
  public static String TREEEDGETEMP = "TreeEdgeTemp";
  public static Predicate treeEdgeTempPred =
      (Predicate)
          ExpressionParser.parse(
              "ISEDGE() AND (" + NetMonitor.EDGETYPE + " = \"" + NetMonitor.TREEEDGETEMP + "\")");
  public static String TREEEDGENEIGHBOR = "TreeEdgeNeighbor";
  public static Predicate treeEdgeNeighborPred =
      (Predicate)
          ExpressionParser.parse(
              "ISEDGE() AND ("
                  + NetMonitor.EDGETYPE
                  + " = \""
                  + NetMonitor.TREEEDGENEIGHBOR
                  + "\")");

  public static String NEIGHBOREDGEBI = "NeighborEdgeBi";
  public static Predicate neighborEdgeBiPred =
      (Predicate)
          ExpressionParser.parse(
              "ISEDGE() AND (" + NetMonitor.EDGETYPE + " = \"" + NetMonitor.NEIGHBOREDGEBI + "\")");
  public static String NEIGHBOREDGEUNI = "NeighborEdgeUni";
  public static Predicate neighborEdgeUniPred =
      (Predicate)
          ExpressionParser.parse(
              "ISEDGE() AND ("
                  + NetMonitor.EDGETYPE
                  + " = \""
                  + NetMonitor.NEIGHBOREDGEUNI
                  + "\")");

  public static String AGE = "Age";

  public static String PARENTNODE = "Parent_Node";
  public static String PARENTEDGE = "Parent_Edge";

  public static String EDGE_SOURCE = "Edge_Source";
  public static String EDGE_DESTINATION = "Edge_Destination";

  public static final String GRAPH = "graph";
  public static final String NODES = "graph.nodes";
  public static final String EDGES = "graph.edges";

  public static final String LIVEACTION = "readlineActionList";
  public static final String LAYOUTACTION = "layoutActionList";

  public static int MAXAGE = 50;
  public static int MAXDELETEAGE = 100;

  /** @param args */
  public static void main(String[] args) {
    HistoryManagement history = new HistoryManagement();

    Map nodeMap = new HashMap();

    DataFileReader fileReader = new DataFileReader(args[0], history);

    Window window = new Window(nodeMap, fileReader, history);

    fileReader.setGUI(window);
    fileReader.openDataFile();
    fileReader.setNodeMap(nodeMap);

    NodeData root = new NodeData(NodeData.ROOT, window, history);
    nodeMap.put(NodeData.ROOT, root);

    root.addTableRow(window.nodeTable);
    root.addValues(0, 0, 0, 0, 0);
    root.setLabel("root");
    root.addNode(0);

    window.graphDisplay.vis.run("color"); // assign the colors
    window.graphDisplay.vis.run(LAYOUTACTION); // start up the animated layout
    window.graphDisplay.vis.run("timesteps");

    window.graphDisplay.vis.run(LIVEACTION);
  }
}