Esempio n. 1
0
    /** @see prefuse.render.AbstractShapeRenderer#getRawShape(prefuse.visual.VisualItem) */
    @Override
    protected Shape getRawShape(VisualItem item) {
      double x1 = item.getDouble(VisualItem.X);
      double y1 = item.getDouble(VisualItem.Y);
      double x2 = item.getDouble(VisualItem.X2);
      double y2 = item.getDouble(VisualItem.Y2);
      boolean isX = item.getBoolean(DocumentGridAxisLayout.IS_X);
      double midPoint = item.getDouble(DocumentGridAxisLayout.MID_POINT);
      // horizontal or vertical coords should be manually held constant so that fisheye works
      // properly
      if (isX) {
        // vertical line
        m_line.setLine(x1, y1, x1, y2);
      } else {
        // horizontal line
        m_line.setLine(x1, y1, x2, y1);
      }

      if (!item.canGetString(VisualItem.LABEL)) {
        return m_line;
      }

      String label = item.getString(VisualItem.LABEL);
      if (label == null) {
        return m_line;
      }

      FontMetrics fm = DEFAULT_GRAPHICS.getFontMetrics(item.getFont());
      m_ascent = fm.getAscent();
      int h = fm.getHeight();
      int w = fm.stringWidth(label);

      double tx, ty;

      int labelOffset = 10;
      if (isX) {
        // vertical axis
        // get text x-coord, center at midPoint
        //            tx = x1 + (x2-x1)/2 - w/2;
        //            tx = midPoint + (x1+midPoint)/2 - w/2;
        //            tx = x1 + midPoint/2 - w/2;
        // simpler approach: just add a fixed distance
        tx = x1 + labelOffset;
        // get text y-coord
        ty = y2 - h;
      } else {
        // horiz axis
        // get text x-coord
        tx = x1 - w - 2;
        // get text y-coord, center at midPoint
        //            ty = y1 + (y2-y1)/2 - h/2;
        //            ty = y1 + midPoint/2 - h/2;
        // simpler approach: just add a fixed distance
        ty = y1 + labelOffset;
      }

      m_box.setFrame(tx, ty, w, h);
      return m_box;
    }
Esempio n. 2
0
    public void run(double frac) {
      // counters for population and urban centres
      double totalPopulation = 0;
      int urbanCentreCount = 0;

      // iterate through all the visual items that are visible
      VisualItem item = null;
      Iterator items = g_vis.visibleItems("canUrban");
      while (items.hasNext()) {
        item = (VisualItem) items.next();
        // add the population data
        totalPopulation += item.getDouble("2006 Population");
        // increment the counter
        urbanCentreCount++;
      }

      // if there is only one urban centre being displayed, show its information
      // in the counter display; otherwise show the number of urban centres and
      // the total population
      if (urbanCentreCount == 1) {
        g_totalStr = item.getString("label");
      } else {

        g_totalStr =
            NumberFormat.getIntegerInstance().format(urbanCentreCount)
                + " Cities, Total Population: "
                + NumberFormat.getIntegerInstance().format(totalPopulation);
      }
      // set the text in the interface element
      g_total.setText(g_totalStr);
    }
Esempio n. 3
0
    /**
     * Given a MouseEvent, finds the VisualItem (if any) on which the event occurred.
     *
     * @param e
     * @return item on which the MouseEvent occurred, or null if it did not occur on any item.
     */
    public VisualItem findClickedItem(MouseEvent e) {

      // get click coordinates
      int x = e.getX();
      int y = e.getY();
      // translate coordinates to Prefuse region
      int xOffset = 0;
      int yOffset = 0;
      JComponent component = display;
      // recursively go through this Component's ancestors, summing offset information in order to
      // get the absolute position relative to window
      do {
        Point visLocation = component.getLocation();
        xOffset += visLocation.x;
        yOffset += visLocation.y;
      } while ((!component.getParent().getClass().equals(JRootPane.class))
          && (component = (JComponent) component.getParent()) != null);
      x -= xOffset;
      y -= yOffset;

      // debug
      //            System.out.println("debug: "+this.getClass().getName()+": mouse click at ("+x+",
      // "+y+")");

      // search each item, determining which was clicked on
      Iterator items = m_vis.getGroup(DATA_GROUP).tuples();
      while (items.hasNext()) {
        VisualItem item = (VisualItem) items.next();
        double itemX = item.getX();
        double itemY = item.getY();
        double itemW = item.getDouble(WIDTH);
        double itemH = item.getDouble(HEIGHT);
        if (x >= itemX && x <= (itemX + itemW) && y >= itemY && y <= (itemY + itemH)) {
          // debug
          //                    System.out.println("debug: "+this.getClass().getName()+": match:
          // ("+itemX+", "+itemY+", "+itemW+", "+itemH+")");
          return item;
        } else {
          // debug
          //                    System.out.println("debug: "+this.getClass().getName()+": no-match:
          // ("+itemX+", "+itemY+", "+itemW+", "+itemH+")");
        }
      }
      return null;
    }
Esempio n. 4
0
    @Override
    public void itemDragged(VisualItem item, MouseEvent e) {
      if (!SwingUtilities.isRightMouseButton(e)) {
        return;
      }
      if (item.getGroup().equals(m_group)) {
        dragged = true;
        //            Display d = (Display) e.getComponent();
        Display d = controller.getDocumentGrid();
        d.getAbsoluteCoordinate(e.getPoint(), temp);
        double dx = temp.getX() - down.getX();
        double dy = temp.getY() - down.getY();
        double x = item.getX();
        double y = item.getY();
        double w = item.getDouble(WIDTH);
        double h = item.getDouble(HEIGHT);

        item.setStartX(x);
        item.setStartY(y);
        item.setX(x + dx);
        item.setY(y + dy);
        item.setEndX(x + dx);
        item.setEndY(y + dy);

        item.setBounds(x + dx, y + dy, w, h);

        if (repaint) {
          item.getVisualization().repaint();
        }

        down.setLocation(temp);
        if (action != null) {
          d.getVisualization().run(action);
        }
      }
    }
    public void run(double frac) {
      double total = 0;
      int count = 0;
      VisualItem item = null;
      Iterator items = m_vis.visibleItems(m_group);
      while (items.hasNext()) {
        item = (VisualItem) items.next();
        total += item.getDouble("Total Receipts");
        ++count;
      }
      m_totalMoney = total;
      m_totalPeople = count;

      if (count == 1) {
        m_totalStr = item.getString("label");
      } else {
        m_totalStr =
            count + " Candidates receiving " + NumberFormat.getCurrencyInstance().format(total);
      }
      m_total.setText(m_totalStr);
    }
Esempio n. 6
0
    @Override
    public void itemReleased(VisualItem item, MouseEvent e) {
      // when right-mouse released, release the dragged document glyph
      if (!SwingUtilities.isRightMouseButton(e)) {
        return;
      }
      // debug
      System.out.println("debug: " + this.getClass().getName() + ": item released");
      if (dragged) {
        activeItem = null;
        item.setFixed(wasFixed);
        dragged = false;
      }
      // clear the focus
      Visualization vis = item.getVisualization();
      vis.getFocusGroup(Visualization.FOCUS_ITEMS).clear();

      // determine whether item is in same region or new region;
      //  if new region, call controller to update attr vals
      double x = item.getX();
      double y = item.getY();
      double w = item.getDouble(WIDTH);
      double h = item.getDouble(HEIGHT);
      int newRegionX = -1;
      int newRegionY = -1;
      String xAttrName = docGridLayout.getXAttr();
      String yAttrName = docGridLayout.getYAttr();
      List<String> xCats = docGridLayout.getXCats();
      List<String> yCats = docGridLayout.getYCats();
      List<Integer> xCatRegionSizes = docGridLayout.getXCatRegionSizes();
      List<Integer> yCatRegionSizes = docGridLayout.getYCatRegionSizes();
      List<Integer> xCatPositions = docGridLayout.getXCatPositions();
      List<Integer> yCatPositions = docGridLayout.getYCatPositions();
      // for each region, get start and range;
      for (int i = 0; i < xCats.size(); i++) {
        int xRegionStart = xCatPositions.get(i);
        int xRegionEnd = xRegionStart + xCatRegionSizes.get(i);
        if (xRegionStart < x + (w / 2.) && x + (w / 2.) < xRegionEnd) {
          newRegionX = i;
        }
      }
      for (int i = 0; i < yCats.size(); i++) {
        int yRegionStart = yCatPositions.get(i);
        int yRegionEnd = yRegionStart + yCatRegionSizes.get(i);
        if (yRegionStart < y + (h / 2.) && y + (h / 2.) < yRegionEnd) {
          newRegionY = i;
        }
      }

      int docID = item.getInt(DocumentGridTable.NODE_ID);

      // debug
      //            System.out.println("debug: item moved:
      // docID="+docID+"xOrig="+xCats.get(origRegionX)+", xNew="+xCats.get(newRegionX)+",
      // yOrig="+yCats.get(origRegionY)+", yNew="+yCats.get(newRegionY));

      // update for x and y separately
      //            if (origRegionX != newRegionX && newRegionX != -1) {
      String newCatX = xCats.get(newRegionX);
      controller.updateDocumentAttr(docID, xAttrName, newCatX);
      controller.documentAttributesUpdated(docID);
      //            }
      //            if (origRegionY != newRegionY && newRegionY != -1) {
      String newCatY = yCats.get(newRegionY);
      controller.updateDocumentAttr(docID, yAttrName, newCatY);
      controller.documentAttributesUpdated(docID);
      //            }

    }
Esempio n. 7
0
    @Override
    //        public void itemPressed(VisualItem item, MouseEvent e) {
    public void itemClicked(VisualItem item, MouseEvent e) {
      // load (or unload) marked-up text into glasspane on rightclick
      // glasspane text is now loaded on mouseover instead

      // temp: zoom on selection
      if (SwingUtilities.isLeftMouseButton(e)) {
        if (item.canGetInt(DocumentGridTable.NODE_ID)) {
          int nodeId = item.getInt(DocumentGridTable.NODE_ID);
          boolean hasSelectFocus = item.getBoolean(SELECT_FOCUS);
          boolean hasWidthFocus = item.getBoolean(WIDTH_FOCUS);
          boolean hasHeightFocus = item.getBoolean(HEIGHT_FOCUS);
          if (hasSelectFocus) {
            // simply deselect the node
            resetGlyphFocus();
          } else {
            // clear all other node selections
            resetGlyphFocus();
            // select this node
            item.setBoolean(SELECT_FOCUS, true);
            item.setBoolean(WIDTH_FOCUS, true);
            item.setBoolean(HEIGHT_FOCUS, true);
          }

          // ensure that the layout has been reprocessed before loading glasspane
          documentGridLayout.categoricalLayout();

          m_vis.run(
              "init"); // init is needed to run here, since sizing is tightly-bound with our
                       // faux-fisheye zooming
          //                    m_vis.run("repaint");

          // appear the glasspane at appropriate size & location
          // get relative location of Visualization
          int xOffset = 0;
          int yOffset = 0;
          JComponent component = display;
          // recursively go through this Component's ancestors, summing offset information in order
          // to get the absolute position relative to window
          do {
            Point visLocation = component.getLocation();
            xOffset += visLocation.x;
            yOffset += visLocation.y;
          } while ((!component.getParent().getClass().equals(JRootPane.class))
              && (component = (JComponent) component.getParent()) != null);
          // debug
          //                    System.out.println("debug: " + this.getClass().getName() + ":
          // offsets: " + xOffset + ", " + yOffset);

          String attrIdStr =
              colorAttrName; // TODO make highlighting more general, not just based on color!

          // make sure that the clicked item is not temporarily ``disabled'' (ie, zoom state was not
          // immediately toggled by a glasspane-oriented class)
          if (disableNextZoomItem == null || disableNextZoomItem != item) {
            disableNextZoomItem = null;
            int x = (int) item.getEndX() + bufferPx + xOffset;
            int y = (int) item.getEndY() + bufferPx + yOffset;
            int w = (int) item.getDouble(WIDTH_END) - 2 * bufferPx;
            int h = (int) item.getDouble(HEIGHT_END) - 2 * bufferPx;
            // debug
            System.out.println(
                "debug: "
                    + this.getClass().getName()
                    + ": displaying sized glasspane at x="
                    + x
                    + ", y="
                    + y
                    + ", w="
                    + w
                    + ", h="
                    + h);
            glassPane.displaySizedPane((int) x, (int) y, (int) w, (int) h, item);

            AbstractDocument doc = glassPane.getAbstDoc();
            controller.writeDocTextWithHighlights(doc, nodeId, attrIdStr);

            glassPane.setBackgroundColor(new Color(docColorAction.getColor(item)));
          } else {
            disableNextZoomItem = null;
          }
        }
      }
    }
Esempio n. 8
0
    @Override
    public void render(Graphics2D g, VisualItem item) {

      if (item.isVisible()) {
        item.setShape(Constants.SHAPE_RECTANGLE);
        RectangularShape shape = (RectangularShape) getShape(item);
        if (shape != null) {

          shape
              .getBounds2D()
              .setRect(
                  (double) item.get(VisualItem.X),
                  (double) item.get(VisualItem.Y),
                  item.getSize(),
                  item.getSize());

          // draw basic glyph
          Color strokeColor = ColorLib.getColor(item.getStrokeColor());
          Color fillColor = ColorLib.getColor(item.getFillColor());

          //                    int size = (int)item.getSize();
          int x = (int) item.getX() + bufferPx;
          int y = (int) item.getY() + bufferPx;
          int w = (int) item.getDouble(WIDTH) - 2 * bufferPx;
          int h = (int) item.getDouble(HEIGHT) - 2 * bufferPx;
          g.setPaint(fillColor);
          g.fillRect(x, y, w, h);

          // draw string on-top of glyph, filling the glyph's area

          //                    String s = "doc=" + item.getString(NODE_NAME) + "\n";
          String s = "";

          // set text: full document if no search term, else excerpts containing the search term
          String queryStr = searchQ.getSearchSet().getQuery();
          String focusText = item.getString(DocumentGridTable.NODE_FOCUS_TEXT);
          if (queryStr != null
              && !queryStr.isEmpty()
              && focusText != null
              && !focusText.equals("null")
              && !focusText.equals("")) {
            // if search query and terms present in document, use term-containing spans
            s += focusText;
          } else if (queryStr != null
              && !queryStr.isEmpty()
              && focusText.equals(FOCUS_SENT_SPLITTER)) {
            // if search query but no terms present in document, use blank
            s += "";
          } else if ((queryStr == null || queryStr.isEmpty()) && item.canGetInt(NODE_ID)) {
            // if no search query, build feature-oriented summary based on color attribute
            s = controller.getDocumentSummary(item.getInt(NODE_ID), colorAttrName);
          }

          // TODO : idea: set font size dynamically based on number of active nodes? based on size
          // of rect?
          int fontSize = 10;

          item.setFont(FontLib.getFont("Tahoma", Font.PLAIN, fontSize));

          Font f = item.getFont();

          // compute width, height for the given text
          // NOTE: this logic has been moved into drawStringMultiline
          //                    int[] textDims = getTextDims(g, f, s);

          // debug
          //                    System.out.println("debug: "+this.getClass().getName()+":
          // drawStringMultiline at x="+x1+", y="+y1+", w="+w+", h="+h);
          drawStringMultiline(g, f, s, x, y, w, h);
        }
      }
    }