From: <Jan...@us...> - 2007-02-28 09:55:48
|
Revision: 583 http://svn.sourceforge.net/magicmap/?rev=583&view=rev Author: Jan_fride Date: 2007-02-28 01:55:47 -0800 (Wed, 28 Feb 2007) Log Message: ----------- copy all edges and vertices before painting in paintComponent to avoid concurrency problems Modified Paths: -------------- trunk/magicmapclient/src/edu/uci/ics/jung/visualization/VisualizationViewer.java Modified: trunk/magicmapclient/src/edu/uci/ics/jung/visualization/VisualizationViewer.java =================================================================== --- trunk/magicmapclient/src/edu/uci/ics/jung/visualization/VisualizationViewer.java 2007-02-27 20:56:49 UTC (rev 582) +++ trunk/magicmapclient/src/edu/uci/ics/jung/visualization/VisualizationViewer.java 2007-02-28 09:55:47 UTC (rev 583) @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, the JUNG Project and the Regents of the University + * Copyright (c) 2003, the JUNG Project and the Regents of the University * of California * All rights reserved. * @@ -157,7 +157,7 @@ repaint(); } - /** + /** * (non-Javadoc) * @see javax.swing.JComponent#setVisible(boolean) */ @@ -167,7 +167,7 @@ } /** - * Runs the visualization forward a few hundred iterations (for half a + * Runs the visualization forward a few hundred iterations (for half a * second) */ public void prerelax(){ @@ -398,7 +398,7 @@ /** * Returns a flag that says whether the visRunner thread is running. If - * it is not, then you may need to restart the thread (with + * it is not, then you may need to restart the thread (with * @return */ public boolean isVisRunnerRunning(){ @@ -447,43 +447,47 @@ } protected void paintComponent(Graphics g){ - start(); + start(); - //super.paintComponent(g); - if (image != null){ - g.drawImage(image, 0, 0, this); + //super.paintComponent(g); + if (image != null){ + g.drawImage(image, 0, 0, this); - } else{} + } else{} - Graphics2D g2d = (Graphics2D) g; - g2d.setRenderingHints(renderingHints); - AffineTransform oldXform = g2d.getTransform(); - AffineTransform newXform = new AffineTransform(oldXform); - newXform.scale(scalex, scaley); - newXform.translate(-offsetx, -offsety); - g2d.setTransform(newXform); + Graphics2D g2d = (Graphics2D) g; + g2d.setRenderingHints(renderingHints); + AffineTransform oldXform = g2d.getTransform(); + AffineTransform newXform = new AffineTransform(oldXform); + newXform.scale(scalex, scaley); + newXform.translate(-offsetx, -offsety); + g2d.setTransform(newXform); - long start = System.currentTimeMillis(); - // for all edges, paint edge - for (Iterator iter = layout.getVisibleEdges().iterator(); iter.hasNext();){ - Edge e = (Edge) iter.next(); - Vertex v1 = (Vertex) e.getEndpoints().getFirst(); - Vertex v2 = (Vertex) e.getEndpoints().getSecond(); - renderer.paintEdge(g, e, (int) layout.getX(v1), (int) layout.getY(v1), (int) layout.getX(v2), (int) layout - .getY(v2)); - } + long start = System.currentTimeMillis(); + // for all edges, paint edge + // get a copy of edges! + Object[] edges = layout.getVisibleEdges().toArray(); + Object[] vertices = layout.getVisibleVertices().toArray(); - for (Iterator iter = layout.getVisibleVertices().iterator(); iter.hasNext();){ - Vertex v = (Vertex) iter.next(); - renderer.paintVertex(g, v, (int) layout.getX(v), (int) layout.getY(v)); - } + for (Object o: edges){ + Edge e = (Edge) o; + Vertex v1 = (Vertex) e.getEndpoints().getFirst(); + Vertex v2 = (Vertex) e.getEndpoints().getSecond(); + renderer.paintEdge(g, e, (int) layout.getX(v1), (int) layout.getY(v1), (int) layout.getX(v2), (int) layout + .getY(v2)); + } - long delta = System.currentTimeMillis() - start; - paintTimes[paintIndex++] = delta; - paintIndex = paintIndex % paintTimes.length; - paintfps = average(paintTimes); + for (Object o: vertices){ + Vertex v = (Vertex)o; + renderer.paintVertex(g, v, (int) layout.getX(v), (int) layout.getY(v)); + } - g2d.setTransform(oldXform); + long delta = System.currentTimeMillis() - start; + paintTimes[paintIndex++] = delta; + paintIndex = paintIndex % paintTimes.length; + paintfps = average(paintTimes); + + g2d.setTransform(oldXform); } /** @@ -526,7 +530,7 @@ } /** - * + * */ public synchronized void stop(){ System.out.println("> stop."); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |