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
    @Override
    public int getColor(VisualItem item) {

      // get value for target attr in item
      if (item.canGetString(colorAttrName)) {
        String attrVal = item.getString(colorAttrName);
        Color attrValColor = catToColorMap.get(attrVal);
        if (attrValColor == null) {
          return Color.CYAN.getRGB();
        }
        return attrValColor.getRGB();
      }

      Color white = Color.WHITE;
      return white.getRGB();
    }
Esempio n. 3
0
    /** @see prefuse.render.Renderer#render(java.awt.Graphics2D, prefuse.visual.VisualItem) */
    @Override
    public void render(Graphics2D g, VisualItem item) {
      Shape s = getShape(item);
      GraphicsLib.paint(g, item, m_line, getStroke(item), getRenderType(item));

      // check if we have a text label, if so, render it
      String str;
      if (item.canGetString(VisualItem.LABEL)) {
        str = (String) item.getString(VisualItem.LABEL);
        if (str != null && !str.equals("")) {
          float x = (float) m_box.getMinX();
          float y = (float) m_box.getMinY() + m_ascent;

          // draw label background
          GraphicsLib.paint(g, item, s, null, RENDER_TYPE_FILL);

          AffineTransform origTransform = g.getTransform();
          AffineTransform transform = this.getTransform(item);
          if (transform != null) {
            g.setTransform(transform);
          }

          g.setFont(item.getFont());
          g.setColor(ColorLib.getColor(item.getTextColor()));

          if (!(str.length() > 5
              && str.substring(str.length() - 5, str.length()).equals("_last"))) {

            g.setColor(Color.WHITE);
            // TODO properly hunt down source of null str! for now, triage
            if (str != null) {
              // bump y down by appropriate amount
              FontMetrics fm = g.getFontMetrics(item.getFont());
              int strHeight = fm.getAscent();
              //                        g.drawString(str, x, y);
              g.drawString(str, x, y + strHeight);
            }

            if (transform != null) {
              g.setTransform(origTransform);
            }
          }
        }
      }
    }