@Override
    public int getColor(VisualItem item) {

      // highlight border of glyphs for which search is true
      // TODO: thicker borders? more outstanding highlighting?
      // do (inefficient) manual comparison (for now)
      Iterator itemsInGroup = m_vis.getGroup(Visualization.SEARCH_ITEMS).tuples();
      while (itemsInGroup.hasNext()) {
        Tuple itemInGroup = (Tuple) itemsInGroup.next();
        if (item.getString(DocumentGridTable.NODE_NAME)
            .equals(itemInGroup.getString(DocumentGridTable.NODE_NAME))) {
          // debug
          //                    System.out.println("debug: "+this.getClass().getName()+": item in
          // group! "+item.toString());
          return ColorLib.rgb(191, 99, 130);
        }
      }

      if (item.isHover()) {
        return Color.LIGHT_GRAY.getRGB();
      }

      // default border color
      //            return ColorLib.gray(50);
      return Color.DARK_GRAY.getRGB();
    }
Example #2
0
  @Override
  public void itemClicked(VisualItem item, MouseEvent e) {

    Visualization vis = item.getVisualization();
    DDGDisplay d = (DDGDisplay) vis.getDisplay(0);

    // revalidates the display by finding the item with the same position as
    // the mouse pointer
    if (revalidated) {
      String state = collapseExpand(item);
      if (state.equals(START)) {
        updateFocusGroup(stepId, item.getVisualization());
        vis.run("color");
        vis.run("repaint");
      }
      if (state.equals(STEP)) {
        expandOneLevel(item);
        updateFocusGroup(startId, item.getVisualization());
        vis.run("color");
        vis.run("repaint");
      }
      revalidated = false;
    } else {
      revalidated = true;
      VisualItem myItem = d.findItem(e.getPoint());
      itemClicked(myItem, e);
    }
  }
 public void itemEntered(VisualItem item, MouseEvent e) {
   DisplayComponent d = (DisplayComponent) e.getSource();
   d.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
   d.setToolTipText(item.getString("id"));
   activeItem = item;
   wasFixed = item.isFixed();
 }
 public void run(double frac) {
   TupleSet ts = m_vis.getFocusGroup(Visualization.FOCUS_ITEMS);
   // System.err.println("auto-panning"+frac);
   if (ts.getTupleCount() == 0) return;
   if (frac == 0.0) {
     int xbias = 0, ybias = 0;
     switch (m_orientation) {
       case Constants.ORIENT_LEFT_RIGHT:
         xbias = m_bias;
         break;
       case Constants.ORIENT_RIGHT_LEFT:
         xbias = -m_bias;
         break;
       case Constants.ORIENT_TOP_BOTTOM:
         ybias = m_bias;
         break;
       case Constants.ORIENT_BOTTOM_TOP:
         ybias = -m_bias;
         break;
     }
     VisualItem vi = (VisualItem) ts.tuples().next();
     m_cur.setLocation(getWidth() / 2, getHeight() / 2);
     getAbsoluteCoordinate(m_cur, m_start);
     m_end.setLocation(vi.getX() + xbias, vi.getY() + ybias);
   } else {
     m_cur.setLocation(
         m_start.getX() + frac * (m_end.getX() - m_start.getX()),
         m_start.getY() + frac * (m_end.getY() - m_start.getY()));
     panToAbs(m_cur);
   }
 }
Example #5
0
  /**
   * Converts the prefuse graph data into the jung graph data.
   *
   * @param vg the prefuse visual graph
   * @return graph the jung graph data
   */
  public static edu.uci.ics.jung.graph.Graph<String, String> convertJungGraph(VisualGraph vg) {

    edu.uci.ics.jung.graph.Graph<String, String> graph =
        new UndirectedSparseGraph<String, String>();

    if (vg != null) {
      Iterator<?> nodeIter = vg.nodes();
      while (nodeIter.hasNext()) {
        VisualItem node = (VisualItem) nodeIter.next();
        String nodeId = node.getString("id");
        // System.out.println("node id == " + nodeId);
        graph.addVertex(nodeId);
      }

      Iterator<?> edgeIter = vg.edges();
      while (edgeIter.hasNext()) {
        VisualItem edge = (VisualItem) edgeIter.next();
        String node1 = edge.getString("node1");
        String node2 = edge.getString("node2");
        String edgeId = node1 + node2;
        // System.out.println("edge id == " + edgeId);
        graph.addEdge(edgeId, node1, node2, EdgeType.UNDIRECTED);
      }
    }
    return graph;
  }
Example #6
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);
    }
    public int getColor(VisualItem item) {
      if (item.getInt("searchDepth") == 1) return ColorScheme.searchColor;

      if (item.canGetInt("senseIndex"))
        return ColorScheme.sensesPalette[
            item.getInt("senseIndex") % ColorScheme.sensesPalette.length];
      else return ColorScheme.resultsColor;
    }
 @Override
 public void tupleSetChanged(TupleSet ts, Tuple[] added, Tuple[] removed) {
   for (Tuple t : removed) {
     ((VisualItem) t).setFixed(false);
   }
   for (Tuple t : added) {
     ((VisualItem) t).setFixed(false);
     ((VisualItem) t).setFixed(true);
   }
 }
Example #9
0
 /**
  * Finds a node by node id.
  *
  * @param vg
  * @param nodeId
  * @return VisualItem the node
  */
 public static VisualItem findNode(VisualGraph vg, String nodeId) {
   if (vg != null) {
     Iterator<?> nodeIter = vg.nodes();
     while (nodeIter.hasNext()) {
       VisualItem node = (VisualItem) nodeIter.next();
       if (node.getString("id").equals(nodeId)) {
         return node;
       }
     }
   }
   return null;
 }
 public void reset() {
   Iterator iter = m_vis.visibleItems(m_nodeGroup);
   while (iter.hasNext()) {
     VisualItem item = (VisualItem) iter.next();
     ForceItem aitem = (ForceItem) item.get(ANCHORITEM);
     if (aitem != null) {
       aitem.location[0] = (float) item.getEndX();
       aitem.location[1] = (float) item.getEndY();
     }
   }
   super.reset();
 }
    public int getColor(VisualItem item) {
      if (ENTROPY_COLOR) return entropyColor(item);
      // test
      //			if (item.getBoolean("cut")){
      //				return new Color(222,13,107).getRGB();
      //			}
      // color is fixed, what changes as a function of the value is the transparency (alpha)
      int color = sca.getColor(item);

      // lemmas and senses in the pathToRoot
      if (item.isInGroup("pathToRoot")
          && ((item.getInt("type") == 1) || (item.getInt("type") == 4)))
        color = ColorScheme.pathToRootColor;

      // count off -- just return color
      if (NodeColorAction.this.docuBurstActionList.countType.equals(DocuBurstActionList.NOCOUNT))
        return color;

      float total =
          (float)
              (item.getFloat(
                  DocuBurstActionList.CACHECOUNT
                      + NodeColorAction.this.docuBurstActionList.countType));
      float maxTotal =
          NodeColorAction.this.docuBurstActionList.getMaxTotal(
              NodeColorAction.this.docuBurstActionList.countType);

      if (total < 0) color = ColorScheme.negativeColor;

      if (total == 0) {
        if (color != ColorScheme.pathToRootColor)
          // zero senses get grey, zero lemmas and words get clear
          return ColorLib.setAlpha(ColorScheme.zeroOccurrenceSenseColor, ColorScheme.zeroAlpha);
        else
          // modulate path to root color
          return ColorLib.setAlpha(color, ColorScheme.zeroAlpha);
      }

      // initial alpha for zero and one count
      int alpha = ColorScheme.zeroAlpha;

      alpha += (int) (((float) total / (float) maxTotal) * (float) (255 - alpha));

      if (total < 0)
        System.err.println(
            "total: " + total + " node: " + item.getString("label") + " alpha: " + alpha);

      // this should not occur except for rounding errors
      if (alpha > 255) alpha = 255;

      return ColorLib.setAlpha(color, alpha);
    }
    public void itemDragged(VisualItem item, MouseEvent e) {
      if (!SwingUtilities.isLeftMouseButton(e)) return;
      dragged = true;
      Display d = (Display) e.getComponent();
      tmp = d.getAbsoluteCoordinate(e.getPoint(), tmp);
      double dx = tmp.getX() - down.getX();
      double dy = tmp.getY() - down.getY();

      PrefuseLib.setX(item, null, item.getX() + dx);
      PrefuseLib.setY(item, null, item.getY() + dy);
      down.setLocation(tmp);
      if (repaint) item.getVisualization().repaint();
    }
    public void itemReleased(VisualItem item, MouseEvent e) {
      if (!SwingUtilities.isLeftMouseButton(e)) return;
      if (dragged) {
        activeItem = null;
        item.setFixed(wasFixed);
        dragged = false;
      }
      // clear the focus
      Visualization vis = item.getVisualization();
      vis.getFocusGroup(Visualization.FOCUS_ITEMS).clear();

      vis.cancel("forces");
    }
    public void itemPressed(VisualItem item, MouseEvent e) {
      if (!SwingUtilities.isLeftMouseButton(e)) return;

      // set the focus to the current node
      Visualization vis = item.getVisualization();
      vis.getFocusGroup(Visualization.FOCUS_ITEMS).setTuple(item);

      item.setFixed(true);
      dragged = false;
      Display d = (Display) e.getComponent();
      down = d.getAbsoluteCoordinate(e.getPoint(), down);

      vis.run("forces");
    }
Example #15
0
 @Override
 public void itemPressed(VisualItem item, MouseEvent e) {
   // on right-mouse press, start dragging the document
   if (SwingUtilities.isRightMouseButton(e)) {
     // debug
     System.out.println("debug: " + this.getClass().getName() + ": item pressed w/ right mouse");
     // drag, set the focus to the current node
     Visualization vis = item.getVisualization();
     vis.getFocusGroup(Visualization.FOCUS_ITEMS).setTuple(item);
     item.setFixed(true);
     dragged = false;
     Display d = controller.getDocumentGrid();
     down = d.getAbsoluteCoordinate(e.getPoint(), down);
   }
 }
    public int entropyColor(VisualItem item) {
      // color is fixed, what changes as a function of the value is the transparency (alpha)
      int color = sca.getColor(item);

      // lemmas and senses in the pathToRoot
      if (item.isInGroup("pathToRoot")
          && ((item.getInt("type") == 1) || (item.getInt("type") == 4)))
        color = ColorScheme.pathToRootColor;

      // count off -- just return color
      if (NodeColorAction.this.docuBurstActionList.countType.equals(DocuBurstActionList.NOCOUNT))
        return color;

      // float total = item.getFloat(DocuBurstActionList.CONDENTROPY);
      float total = item.getFloat(DocuBurstActionList.CONDENTROPY);
      float maxTotal =
          NodeColorAction.this.docuBurstActionList.getMaxTotal(DocuBurstActionList.CONDENTROPY);

      if (total < 0) color = ColorScheme.negativeColor;

      if (total == 0) {
        if (color != ColorScheme.pathToRootColor)
          // zero senses get grey, zero lemmas and words get clear
          return ColorLib.setAlpha(color, 255);
        else
          // modulate path to root color
          return ColorLib.setAlpha(color, ColorScheme.zeroAlpha);
      }

      // initial alpha for zero and one count
      int alpha = 10;

      float condEntropyMin = NodeColorAction.this.docuBurstActionList.getCondEntropyMinTotal();

      // alpha += (int) ( (1 - Math.log(total/maxTotal)/Math.log(condEntropyMin)) * (float) (255 -
      // alpha));
      alpha +=
          (int) ((Math.log(total / maxTotal) / Math.log(condEntropyMin)) * (float) (255 - alpha));

      if (total < 0)
        System.err.println(
            "total: " + total + " node: " + item.getString("label") + " alpha: " + alpha);

      // this should not occur except for rounding errors
      if (alpha > 255) alpha = 255;

      return ColorLib.setAlpha(color, alpha);
    }
Example #17
0
  /**
   * @see edu.berkeley.guir.prefuse.action.Action#run(edu.berkeley.guir.prefuse.ItemRegistry,
   *     double)
   */
  public void run(double frac) {

    AggregateTable aggr = (AggregateTable) m_vis.getGroup(m_group);
    // do we have any  to process?
    int num = aggr.getTupleCount();
    if (num == 0) return;

    // update buffers
    int maxsz = 0;
    for (Iterator aggrs = aggr.tuples(); aggrs.hasNext(); )
      maxsz = Math.max(maxsz, 4 * 2 * ((AggregateItem) aggrs.next()).getAggregateSize());
    if (m_pts == null || maxsz > m_pts.length) {
      m_pts = new double[maxsz];
    }

    // compute and assign convex hull for each aggregate
    Iterator aggrs = m_vis.visibleItems(m_group);
    while (aggrs.hasNext()) {
      AggregateItem aitem = (AggregateItem) aggrs.next();

      int idx = 0;
      if (aitem.getAggregateSize() == 0) continue;
      VisualItem item = null;
      Iterator iter = aitem.items();
      while (iter.hasNext()) {
        item = (VisualItem) iter.next();
        if (item.isVisible()) {
          addPoint(m_pts, idx, item, m_margin);
          idx += 2 * 4;
        }
      }
      // if no aggregates are visible, do nothing
      if (idx == 0) continue;

      // compute convex hull
      double[] nhull = GraphicsLib.convexHull(m_pts, idx);

      // prepare viz attribute array
      float[] fhull = (float[]) aitem.get(VisualItem.POLYGON);
      if (fhull == null || fhull.length < nhull.length) fhull = new float[nhull.length];
      else if (fhull.length > nhull.length) fhull[nhull.length] = Float.NaN;

      // copy hull values
      for (int j = 0; j < nhull.length; j++) fhull[j] = (float) nhull[j];
      aitem.set(VisualItem.POLYGON, fhull);
      aitem.setValidated(false); // force invalidation
    }
  }
Example #18
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();
    }
Example #19
0
 /*
  * Test method for 'prefuse.Visualization.getSourceTuple(VisualItem)'
  */
 @Test
 public void testGetSourceTuple() {
   Assert.assertEquals(m_t0, m_vis.getSourceTuple(m_vt0));
   Assert.assertEquals(m_n0, m_vis.getSourceTuple(m_vn0));
   Assert.assertEquals(m_t0, m_vt0.getSourceTuple());
   Assert.assertEquals(m_n0, m_vn0.getSourceTuple());
 }
Example #20
0
 /** @see prefuse.render.Renderer#setBounds(prefuse.visual.VisualItem) */
 @Override
 public void setBounds(VisualItem item) {
   if (!m_manageBounds) {
     return;
   }
   Shape shape = getShape(item);
   if (shape == null) {
     item.setBounds(item.getX(), item.getY(), 0, 0);
   } else if (shape == m_line) {
     GraphicsLib.setBounds(item, shape, getStroke(item));
   } else {
     m_box.add(m_line.getX1(), m_line.getY1());
     m_box.add(m_line.getX2(), m_line.getY2());
     item.setBounds(m_box.getMinX(), m_box.getMinY(), m_box.getWidth(), m_box.getHeight());
   }
 }
Example #21
0
  @Override
  public void itemClicked(VisualItem item, MouseEvent e) {

    if (!filterCheck(item)
        || v != item.getVisualization()
        || !UILib.isButtonPressed(e, button)
        || e.getClickCount() != ccount) {
      return;
    }

    if (e.isControlDown()) {
      if (focusedTupleSet.containsTuple(item)) {
        focusedTupleSet.removeTuple(item);
        if (item == curFocus) {
          curFocus = null;
          Iterator<VisualItem> focusedTuples = focusedTupleSet.tuples();
          while (focusedTuples.hasNext()) {
            curFocus = focusedTuples.next();
          }
        }
      } else {
        focusedTupleSet.addTuple(item);
        curFocus = item;
      }
    } else {
      focusedTupleSet.setTuple(item);
      curFocus = item;
    }

    runActivity(v);
  }
 public void itemClicked(VisualItem item, MouseEvent e) {
   if (!SwingUtilities.isLeftMouseButton(e)) return;
   if (e.getClickCount() == 2) {
     String id = item.getString("id");
     BrowserLauncher.showDocument(URL + id);
   }
 }
Example #23
0
  /**
   * updates the focus group to the step if a sequence is being collapsed or to the start node of
   * the sequence if the sequence is being expanded
   *
   * @param id
   */
  public void updateFocusGroup(int nodeId, Visualization vis) {
    Iterator visualItems = vis.items();
    VisualItem item = null;
    final String group = Visualization.FOCUS_ITEMS;

    while (visualItems.hasNext()) {
      item = (VisualItem) visualItems.next();
      if (item instanceof TableNodeItem && item.getInt(ID) == nodeId) {
        TupleSet ts = vis.getFocusGroup(group);
        ts.setTuple(item);
        break;
      }
    }

    vis.run("animate");
  }
Example #24
0
    public void itemPressed(VisualItem item, java.awt.event.MouseEvent e) {
      if (e.getClickCount() == 2) {
        Node v = null;
        String pindex = "/";
        String parent = "/";
        int ind;
        String itemname = item.getString(LABEL);
        for (int i = 0; ; i++) {
          v = (getNode(i));
          String current = getName(v);
          if (current.compareTo(itemname) == 0) {
            ind = (int) v.get(Index);
            if (ind <= 9) itemname = itemname.substring(0, itemname.length() - 1);
            else itemname = itemname.substring(0, itemname.length() - 2);
            while (pindex != "Start") {
              Node h = v.getParent();
              pindex = getName(h);
              ind = (int) h.get(Index);

              if (pindex == "Start") break;

              if (ind <= 9) parent = "/" + pindex.substring(0, pindex.length() - 1) + parent;
              else parent = "/" + pindex.substring(0, pindex.length() - 2) + parent;

              v = h;
            }
            break;
          }
        }

        System.out.println(parent.substring(1) + itemname);

        // trial2 hello2 = new
        // trial2(item.getInt(Index),(item.getString(LABEL)),parent.substring(1)+itemname,100);
        urllink mainPanel =
            new urllink(
                item.getInt(Index), (item.getString(LABEL)), parent.substring(1) + itemname, 100);

        JFrame frame = new JFrame("Click any option");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(mainPanel);
        frame.pack();
        frame.setLocationByPlatform(true);
        frame.setVisible(true);
      }
    }
Example #25
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);
            }
          }
        }
      }
    }
Example #26
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;
    }
    protected void initSimulator(ForceSimulator fsim) {
      // make sure we have force items to work with
      TupleSet t = (TupleSet) m_vis.getGroup(m_group);
      t.addColumns(ANCHORITEM_SCHEMA);
      t.addColumns(FORCEITEM_SCHEMA);

      Iterator iter = m_vis.visibleItems(m_nodeGroup);
      while (iter.hasNext()) {
        VisualItem item = (VisualItem) iter.next();
        // get force item
        ForceItem fitem = (ForceItem) item.get(FORCEITEM);
        if (fitem == null) {
          fitem = new ForceItem();
          item.set(FORCEITEM, fitem);
        }
        fitem.location[0] = (float) item.getEndX();
        fitem.location[1] = (float) item.getEndY();
        fitem.mass = getMassValue(item);

        // get spring anchor
        ForceItem aitem = (ForceItem) item.get(ANCHORITEM);
        if (aitem == null) {
          aitem = new ForceItem();
          item.set(ANCHORITEM, aitem);
          aitem.location[0] = fitem.location[0];
          aitem.location[1] = fitem.location[1];
        }

        fsim.addItem(fitem);
        fsim.addSpring(fitem, aitem, 0);
      }
    }
 public void renderText(Graphics2D g, VisualItem item, Shape shape) {
   String s = getText(item);
   int textColor = item.getTextColor();
   if (s != null) {
     Rectangle2D r = shape.getBounds2D();
     g.setPaint(ColorLib.getColor(textColor));
     g.setFont(m_font);
     FontMetrics fm = g.getFontMetrics();
     double size = item.getSize();
     double x = r.getX() + size * m_horizBorder;
     double y = r.getY() + size * m_vertBorder;
     g.drawString(s, (float) x, (float) y + fm.getAscent());
     // if ( isHyperlink(item) ) {
     // int lx = (int)Math.round(x), ly = (int)Math.round(y);
     // g.drawLine(lx,ly,lx+fm.stringWidth(s),ly+fm.getHeight()-1);
     // }
   }
 }
 public void itemExited(VisualItem item, MouseEvent e) {
   if (activeItem == item) {
     activeItem = null;
     item.setFixed(wasFixed);
   }
   DisplayComponent d = (DisplayComponent) e.getSource();
   d.setToolTipText(null);
   d.setCursor(Cursor.getDefaultCursor());
 }
Example #30
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;
    }