/** @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; }
/** @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); } } } } }
@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); } } }