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); } }
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(); }
/** @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()); } }
protected static void move(VisualItem item, double dx, double dy) { if (item instanceof AggregateItem) { Iterator items = ((AggregateItem) item).items(); while (items.hasNext()) { move((VisualItem) items.next(), dx, dy); } } else { double x = item.getX(); double y = item.getY(); item.setStartX(x); item.setStartY(y); item.setX(x + dx); item.setY(y + dy); item.setEndX(x + dx); item.setEndY(y + dy); } }
/** * 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; }
/** @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); return; } // GraphicsLib.setBounds(item, shape, getStroke(item)); // if (m_curArrow != null) { // Rectangle2D bbox = (Rectangle2D) item.get(VisualItem.BOUNDS); // Rectangle2D.union(bbox, m_curArrow.getBounds2D(), bbox); // } GraphicsLib.getBounds(m_tmpBounds, shape, getStroke(item)); if (m_curArrow != null) { Rectangle2D.union(m_tmpBounds, m_curArrow.getBounds2D(), m_tmpBounds); } item.setBounds( m_tmpBounds.getX(), m_tmpBounds.getY(), m_tmpBounds.getWidth(), m_tmpBounds.getHeight()); }
@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); } } }
@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); // } }
@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); } } }