/** * 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; }
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(); }
@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(); }
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); } }
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); }
/** @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; }
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); } }
/** * 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 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); }
/** * collapses nodes between a start node and a finish node when the start node is clicked expand * nodes between a start and finish node when the step connecting them is clicked * * @param item */ public String collapseExpand(VisualItem item) { if (item instanceof TableNodeItem && item.getString(TYPE).equals(START)) { TableNodeItem nodeItem = (TableNodeItem) item; if (finishNode(nodeItem) != null && getChild(finishNode(nodeItem)) != null) { setNodesAndEdgesInvisible(nodeItem, finishNode(nodeItem)); setStepVisible(nodeItem); setIsolatedNodesInvisible(nodeItem.getGraph()); Visualization vis = item.getVisualization(); vis.run("layout"); } return START; } if (item instanceof TableNodeItem && item.getString(TYPE).equals(STEP)) { TableNodeItem nodeItem = (TableNodeItem) item; TableNodeItem startNode = getStepParent(nodeItem); startId = (getChild(startNode)).getInt(ID); TableNodeItem finishNode = getStepChild(nodeItem); setStepInvisible(nodeItem); setNodesAndEdgesVisible(startNode, finishNode, true); setIsolatedNodesVisible(nodeItem.getGraph()); Visualization vis = item.getVisualization(); vis.run("layout"); return STEP; } return "Other"; }
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); }
@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(); }
/** @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); } } } } }
public Font getFont(VisualItem item) { int nc = item.getInt(NODECOUNT); // if (nc==1) // return defaultTreeFont; // int cc = item.getInt(ROWCOUNT); // float smin = 1f/cc; float s = (float) nc / rowCount; float fs = defaultTreeFont.getSize(); if (s > 1) fs = fs * 2f; if (s > minFreqRatio * 60) fs = fs * 3f; else if (s > minFreqRatio * 40) fs = fs * 3f; else if (s > minFreqRatio * 20) fs = fs * 2.8f; else if (s > minFreqRatio * 15) fs = fs * 2.5f; else if (s > minFreqRatio * 10) fs = fs * 2f; else if (s > minFreqRatio * 6) fs = fs * 1.8f; else if (s > minFreqRatio * 3) fs = fs * 1.6f; else if (s > minFreqRatio * 2) fs = fs * 1.4f; else if (s > minFreqRatio * 1.4) fs = fs * 1.2f; else if (s <= minFreqRatio) fs = fs * 0.5f; Font font = defaultTreeFont.deriveFont(fs); System.err.println( "w=" + item.getString(NAME) + " fs=" + fs + " rc=" + rowCount + " s=" + s + " minFreqRatio=" + minFreqRatio + " fn=" + font); return font; // } // return defaultFont; }
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); }
/** * expands one level at a time when step node is clicked * * @param item */ public void expandOneLevel(VisualItem item) { Visualization vis = item.getVisualization(); TableNodeItem stepItem = (TableNodeItem) item; TableNodeItem stepParent = getStepParent(stepItem); TableNodeItem stepChild = getStepChild(stepItem); int finishNodeId = 0; Iterator visualItems = vis.visibleItems(); VisualItem node; while (visualItems.hasNext()) { node = (VisualItem) visualItems.next(); if (node instanceof TableNodeItem && node.getInt(ID) > (stepParent.getInt(ID) + 1) && node.getInt(ID) < stepChild.getInt(ID) && node.getString(TYPE).equals(START) && node.getInt(ID) > finishNodeId) { collapseExpand(node); finishNodeId = finishNode((TableNodeItem) node).getInt(ID); } } }
@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); } } }