- added more options to access grid picture, web structure picture and network graphics

- remove test class


git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7770 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent efcd21e0ed
commit 2683162ec5

@ -11,7 +11,7 @@
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
imagestub = "AccessPicture_p.png?width=1024&height=576&bgcolor=FFFFFF&ct=5000&coronaangle="; imagestub = "AccessPicture_p.png?width=1024&height=576&colorback=FFFFFF&amp;colortext=AAAAAA&amp;colorgrid=333333&amp;colordot=33CC33&amp;colorline=555555&ct=5000&coronaangle=";
imageanimindex = 0; imageanimindex = 0;
imageloadindex = 0; imageloadindex = 0;
imagecycles = 0; imagecycles = 0;
@ -53,7 +53,7 @@
<p>This images shows incoming connections to your YaCy peer and outgoing connections from your peer to other peers and web servers</p> <p>This images shows incoming connections to your YaCy peer and outgoing connections from your peer to other peers and web servers</p>
<div class="left"> <div class="left">
<p> <p>
<a href="AccessPicture_p.png?width=1024&amp;height=576&amp;bgcolor=FFFFFF"><img id="AccessPicture" src="AccessPicture_p.png?width=1024&amp;height=576&amp;bgcolor=FFFFFF&amp;coronaangle=0" alt="YaCy Access Grid" width="1024" height="576" /></a> <a href="AccessPicture_p.png?width=1024&amp;height=576&amp;colorback=FFFFFF&amp;colortext=AAAAAA&amp;colorgrid=333333&amp;colordot=33CC33&amp;colorline=555555"><img id="AccessPicture" src="AccessPicture_p.png?width=1024&amp;height=576&amp;bgcolor=FFFFFF&amp;coronaangle=0" alt="YaCy Access Grid" width="1024" height="576" /></a>
</p> </p>
</div> </div>

@ -2,7 +2,7 @@
* AccessPicture_p * AccessPicture_p
* Copyright 2011 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany * Copyright 2011 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
* First released 18.02.2010 at http://yacy.net * First released 18.02.2010 at http://yacy.net
* *
* $LastChangedDate: 2010-06-16 17:11:21 +0200 (Mi, 16 Jun 2010) $ * $LastChangedDate: 2010-06-16 17:11:21 +0200 (Mi, 16 Jun 2010) $
* $LastChangedRevision: 6922 $ * $LastChangedRevision: 6922 $
* $LastChangedBy: orbiter $ * $LastChangedBy: orbiter $
@ -11,12 +11,12 @@
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version. * version 2.1 of the License, or (at your option) any later version.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this program in the file lgpl21.txt * along with this program in the file lgpl21.txt
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
@ -32,7 +32,6 @@ import net.yacy.cora.protocol.RequestHeader;
import net.yacy.visualization.HexGridPlotter; import net.yacy.visualization.HexGridPlotter;
import net.yacy.visualization.PrintTool; import net.yacy.visualization.PrintTool;
import net.yacy.visualization.RasterPlotter; import net.yacy.visualization.RasterPlotter;
import net.yacy.visualization.RasterPlotter.DrawMode;
import de.anomic.search.Switchboard; import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects; import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch; import de.anomic.server.serverSwitch;
@ -40,22 +39,22 @@ import de.anomic.server.serverSwitch;
public class AccessPicture_p { public class AccessPicture_p {
private static int[] times = new int[]{60000, 50000, 40000, 30000, 20000, 10000, 1000}; private static int[] times = new int[]{60000, 50000, 40000, 30000, 20000, 10000, 1000};
public static RasterPlotter respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { public static RasterPlotter respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
final Switchboard sb = (Switchboard) env; final Switchboard sb = (Switchboard) env;
String color_text = "AAAAAA"; String color_text = "AAAAAA";
String color_back = "FFFFFF"; String color_back = "FFFFFF";
String color_grid = "333333"; String color_grid = "333333";
String color_dot = "33CC33"; String color_dot = "33CC33";
String color_line = "555555"; String color_line = "555555";
int width = 1024; int width = 1024;
int height = 576; int height = 576;
int cellsize = 18; int cellsize = 18;
boolean corona = false; boolean corona = false;
int coronaangle = 0; int coronaangle = 0;
if (post != null) { if (post != null) {
width = post.getInt("width", 1024); width = post.getInt("width", 1024);
height = post.getInt("height", 576); height = post.getInt("height", 576);
@ -69,24 +68,25 @@ public class AccessPicture_p {
coronaangle = (corona) ? post.getInt("coronaangle", 0) : -1; coronaangle = (corona) ? post.getInt("coronaangle", 0) : -1;
} }
if (coronaangle < 0) corona = false; if (coronaangle < 0) corona = false;
// too small values lead to an error, too big to huge CPU/memory consumption, resulting in possible DOS. // too small values lead to an error, too big to huge CPU/memory consumption, resulting in possible DOS.
if (width < 32 ) width = 32; if (width < 32 ) width = 32;
if (width > 10000) width = 10000; if (width > 10000) width = 10000;
if (height < 24) height = 24; if (height < 24) height = 24;
if (height > 10000) height = 10000; if (height > 10000) height = 10000;
final HexGridPlotter picture = new HexGridPlotter(width, height, DrawMode.MODE_SUB, color_back, cellsize); final RasterPlotter.DrawMode drawMode = (RasterPlotter.darkColor(color_back)) ? RasterPlotter.DrawMode.MODE_ADD : RasterPlotter.DrawMode.MODE_SUB;
final HexGridPlotter picture = new HexGridPlotter(width, height, drawMode, color_back, cellsize);
picture.drawGrid(color_grid); picture.drawGrid(color_grid);
// calculate dimensions for left and right column // calculate dimensions for left and right column
int gridLeft = 0; final int gridLeft = 0;
int gridRight = picture.gridWidth() - 2; int gridRight = picture.gridWidth() - 2;
if ((gridRight & 1) == 0) gridRight--; if ((gridRight & 1) == 0) gridRight--;
// draw home peer // draw home peer
int centerx = (picture.gridWidth() >> 1) - 1; final int centerx = (picture.gridWidth() >> 1) - 1;
int centery = picture.gridHeight() >> 1; final int centery = picture.gridHeight() >> 1;
picture.setColor(color_dot); picture.setColor(color_dot);
picture.gridDot(centerx, centery, 5, true, 100); picture.gridDot(centerx, centery, 5, true, 100);
if (corona) { if (corona) {
@ -99,32 +99,32 @@ public class AccessPicture_p {
//picture.gridDot(centerx, centery, 31, false); //picture.gridDot(centerx, centery, 31, false);
picture.setColor(color_text); picture.setColor(color_text);
picture.gridPrint(centerx, centery, 5, "THIS YACY PEER", "\"" + sb.peers.myName().toUpperCase() + "\"", 0); picture.gridPrint(centerx, centery, 5, "THIS YACY PEER", "\"" + sb.peers.myName().toUpperCase() + "\"", 0);
// left column: collect data for access from outside // left column: collect data for access from outside
int verticalSlots = (picture.gridHeight() >> 1) - 1; final int verticalSlots = (picture.gridHeight() >> 1) - 1;
String[] hosts = new String[verticalSlots]; final String[] hosts = new String[verticalSlots];
int[] time = new int[verticalSlots]; final int[] time = new int[verticalSlots];
int[] count = new int[verticalSlots]; final int[] count = new int[verticalSlots];
for (int i = 0; i < verticalSlots; i++) {hosts[i] = null; time[i] = 0; count[i] = 0;} for (int i = 0; i < verticalSlots; i++) {hosts[i] = null; time[i] = 0; count[i] = 0;}
String host; String host;
int c, h; int c, h;
for (int j = 0; j < times.length; j++) { for (final int time2 : times) {
Iterator<String> i = sb.accessHosts(); final Iterator<String> i = sb.accessHosts();
try { try {
while (i.hasNext()) { while (i.hasNext()) {
host = i.next(); host = i.next();
c = sb.latestAccessCount(host, times[j]); c = sb.latestAccessCount(host, time2);
if (c > 0) { if (c > 0) {
h = (Math.abs(host.hashCode())) % hosts.length; h = (Math.abs(host.hashCode())) % hosts.length;
hosts[h] = host; hosts[h] = host;
count[h] = c; count[h] = c;
time[h] = times[j]; time[h] = time2;
} }
} }
} catch (final ConcurrentModificationException e) {} // we don't want to synchronize this } catch (final ConcurrentModificationException e) {} // we don't want to synchronize this
} }
// draw left column: access from outside // draw left column: access from outside
for (int i = 0; i < hosts.length; i++) { for (int i = 0; i < hosts.length; i++) {
if (hosts[i] != null) { if (hosts[i] != null) {
@ -145,7 +145,7 @@ public class AccessPicture_p {
} }
} }
} }
// right column: collect data for access to outside // right column: collect data for access to outside
for (int i = 0; i < verticalSlots; i++) {hosts[i] = null; time[i] = 0; count[i] = 0;} for (int i = 0; i < verticalSlots; i++) {hosts[i] = null; time[i] = 0; count[i] = 0;}
final Set<ConnectionInfo> allConnections = ConnectionInfo.getAllConnections(); final Set<ConnectionInfo> allConnections = ConnectionInfo.getAllConnections();
@ -159,7 +159,7 @@ public class AccessPicture_p {
time[h] = (int) conInfo.getLifetime(); time[h] = (int) conInfo.getLifetime();
} }
} }
// draw right column: access to outside // draw right column: access to outside
for (int i = 0; i < hosts.length; i++) { for (int i = 0; i < hosts.length; i++) {
if (hosts[i] != null) { if (hosts[i] != null) {
@ -180,7 +180,7 @@ public class AccessPicture_p {
} }
} }
} }
// print headline // print headline
picture.setColor(color_text); picture.setColor(color_text);
PrintTool.print(picture, 2, 6, 0, "YACY NODE ACCESS GRID", -1); PrintTool.print(picture, 2, 6, 0, "YACY NODE ACCESS GRID", -1);
@ -202,8 +202,8 @@ public class AccessPicture_p {
picture.setColor(color_dot); picture.setColor(color_dot);
picture.gridLine(centerx + 3, picture.gridHeight() - 1, gridRight, picture.gridHeight() - 1); picture.gridLine(centerx + 3, picture.gridHeight() - 1, gridRight, picture.gridHeight() - 1);
picture.gridPrint(gridRight, picture.gridHeight() - 1, 8, "", "OUTGOING CONNECTIONS", 1); picture.gridPrint(gridRight, picture.gridHeight() - 1, 8, "", "OUTGOING CONNECTIONS", 1);
return picture; return picture;
} }
} }

@ -9,7 +9,7 @@
// $LastChangedBy$ // $LastChangedBy$
// //
// LICENSE // LICENSE
// //
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or // the Free Software Foundation; either version 2 of the License, or
@ -37,35 +37,36 @@ import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.data.meta.DigestURI; import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.logging.Log; import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order; import net.yacy.kelondro.order.Base64Order;
import net.yacy.visualization.GraphPlotter;
import net.yacy.visualization.PrintTool; import net.yacy.visualization.PrintTool;
import net.yacy.visualization.RasterPlotter; import net.yacy.visualization.RasterPlotter;
import net.yacy.visualization.GraphPlotter;
import de.anomic.search.Switchboard; import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects; import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch; import de.anomic.server.serverSwitch;
import de.anomic.yacy.graphics.WebStructureGraph; import de.anomic.yacy.graphics.WebStructureGraph;
public class WebStructurePicture_p { public class WebStructurePicture_p {
private static final double maxlongd = Long.MAX_VALUE; private static final double maxlongd = Long.MAX_VALUE;
public static RasterPlotter respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { public static RasterPlotter respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
final Switchboard sb = (Switchboard) env; final Switchboard sb = (Switchboard) env;
String color_text = "888888"; String color_text = "888888";
String color_back = "FFFFFF"; String color_back = "FFFFFF";
String color_dot = "11BB11"; String color_dot = "11BB11";
String color_line = "222222"; String color_line = "222222";
String color_lineend = "333333"; String color_lineend = "333333";
int width = 1024; int width = 1024;
int height = 576; int height = 576;
int depth = 3; int depth = 3;
int nodes = 100; // maximum number of host nodes that are painted int nodes = 100; // maximum number of host nodes that are painted
int time = -1; int time = -1;
String host = null; String host = null;
boolean corona = false;
int coronaangle = 0;
if (post != null) { if (post != null) {
width = post.getInt("width", 1024); width = post.getInt("width", 1024);
height = post.getInt("height", 576); height = post.getInt("height", 576);
@ -78,8 +79,10 @@ public class WebStructurePicture_p {
color_dot = post.get("colordot", color_dot); color_dot = post.get("colordot", color_dot);
color_line = post.get("colorline", color_line); color_line = post.get("colorline", color_line);
color_lineend = post.get("colorlineend", color_lineend); color_lineend = post.get("colorlineend", color_lineend);
corona = post.getBoolean("corona", true);
coronaangle = (corona) ? post.getInt("coronaangle", 0) : -1;
} }
// too small values lead to an error, too big to huge CPU/memory consumption, resulting in possible DOS. // too small values lead to an error, too big to huge CPU/memory consumption, resulting in possible DOS.
if (width < 32 ) width = 32; if (width < 32 ) width = 32;
if (width > 10000) width = 10000; if (width > 10000) width = 10000;
@ -87,10 +90,10 @@ public class WebStructurePicture_p {
if (height > 10000) height = 10000; if (height > 10000) height = 10000;
if (depth > 8) depth = 8; if (depth > 8) depth = 8;
if (depth < 0) depth = 0; if (depth < 0) depth = 0;
// calculate target time // calculate target time
final long timeout = (time < 0) ? Long.MAX_VALUE : System.currentTimeMillis() + (time * 8 / 10); final long timeout = (time < 0) ? Long.MAX_VALUE : System.currentTimeMillis() + (time * 8 / 10);
// find start point // find start point
if ((host == null) || (host.length() == 0) || (host.equals("auto"))) { if ((host == null) || (host.length() == 0) || (host.equals("auto"))) {
// find domain with most references // find domain with most references
@ -99,7 +102,8 @@ public class WebStructurePicture_p {
final RasterPlotter graphPicture; final RasterPlotter graphPicture;
if (host == null) { if (host == null) {
// probably no information available // probably no information available
graphPicture = new RasterPlotter(width, height, RasterPlotter.DrawMode.MODE_SUB, color_back); final RasterPlotter.DrawMode drawMode = (RasterPlotter.darkColor(color_back)) ? RasterPlotter.DrawMode.MODE_ADD : RasterPlotter.DrawMode.MODE_SUB;
graphPicture = new RasterPlotter(width, height, drawMode, color_back);
PrintTool.print(graphPicture, width / 2, height / 2, 0, "NO WEB STRUCTURE DATA AVAILABLE.", 0); PrintTool.print(graphPicture, width / 2, height / 2, 0, "NO WEB STRUCTURE DATA AVAILABLE.", 0);
PrintTool.print(graphPicture, width / 2, height / 2 + 16, 0, "START A WEB CRAWL TO OBTAIN STRUCTURE DATA.", 0); PrintTool.print(graphPicture, width / 2, height / 2 + 16, 0, "START A WEB CRAWL TO OBTAIN STRUCTURE DATA.", 0);
} else { } else {
@ -109,12 +113,12 @@ public class WebStructurePicture_p {
hash = ASCII.String((new DigestURI("http://" + host)).hash(), 6, 6); hash = ASCII.String((new DigestURI("http://" + host)).hash(), 6, 6);
} catch (final MalformedURLException e) {Log.logException(e);} } catch (final MalformedURLException e) {Log.logException(e);}
//assert (sb.webStructure.outgoingReferences(hash) != null); //assert (sb.webStructure.outgoingReferences(hash) != null);
// recursively find domains, up to a specific depth // recursively find domains, up to a specific depth
final GraphPlotter graph = new GraphPlotter(); final GraphPlotter graph = new GraphPlotter();
if (host != null && hash != null) place(graph, sb.webStructure, hash, host, nodes, timeout, 0.0, 0.0, 0, depth); if (host != null && hash != null) place(graph, sb.webStructure, hash, host, nodes, timeout, 0.0, 0.0, 0, depth, coronaangle);
//graph.print(); //graph.print();
graphPicture = graph.draw(width, height, 40, 40, 16, 16, color_back, color_dot, color_line, color_lineend, color_text); graphPicture = graph.draw(width, height, 40, 40, 16, 16, color_back, color_dot, color_line, color_lineend, color_text);
} }
// print headline // print headline
@ -124,13 +128,16 @@ public class WebStructurePicture_p {
PrintTool.print(graphPicture, width - 2, 8, 0, "SNAPSHOT FROM " + new Date().toString().toUpperCase(), 1); PrintTool.print(graphPicture, width - 2, 8, 0, "SNAPSHOT FROM " + new Date().toString().toUpperCase(), 1);
return graphPicture; return graphPicture;
} }
private static final int place(final GraphPlotter graph, final WebStructureGraph structure, final String centerhash, final String centerhost, int maxnodes, final long timeout, final double x, final double y, int nextlayer, final int maxlayer) { private static final int place(
final GraphPlotter graph, final WebStructureGraph structure, final String centerhash, final String centerhost,
int maxnodes, final long timeout, final double x, final double y, int nextlayer, final int maxlayer,
final int coronaangle) {
// returns the number of nodes that had been placed // returns the number of nodes that had been placed
assert centerhost != null; assert centerhost != null;
GraphPlotter.coordinate center = graph.getPoint(centerhost); final GraphPlotter.coordinate center = graph.getPoint(centerhost);
int mynodes = 0; int mynodes = 0;
if (center == null) { if (center == null) {
graph.addPoint(centerhost, x, y, nextlayer); graph.addPoint(centerhost, x, y, nextlayer);
@ -140,7 +147,7 @@ public class WebStructurePicture_p {
if (nextlayer == maxlayer) return mynodes; if (nextlayer == maxlayer) return mynodes;
nextlayer++; nextlayer++;
final double radius = 1.0 / (1 << nextlayer); final double radius = 1.0 / (1 << nextlayer);
WebStructureGraph.StructureEntry sr = structure.outgoingReferences(centerhash); final WebStructureGraph.StructureEntry sr = structure.outgoingReferences(centerhash);
final Map<String, Integer> next = (sr == null) ? new HashMap<String, Integer>() : sr.references; final Map<String, Integer> next = (sr == null) ? new HashMap<String, Integer>() : sr.references;
Map.Entry<String, Integer> entry; Map.Entry<String, Integer> entry;
String targethash, targethost; String targethash, targethost;
@ -162,7 +169,7 @@ public class WebStructurePicture_p {
targets.add(new String[] {targethash, targethost}); targets.add(new String[] {targethash, targethost});
if (graph.getPoint(targethost) != null) continue; if (graph.getPoint(targethost) != null) continue;
// set a new point. It is placed on a circle around the host point // set a new point. It is placed on a circle around the host point
final double angle = Base64Order.enhancedCoder.cardinal((targethash + "____").getBytes()) / maxlongd * 2 * Math.PI; final double angle = ((Base64Order.enhancedCoder.cardinal((targethash + "____").getBytes()) / maxlongd) + (coronaangle / 360.0d)) * 2.0d * Math.PI;
//System.out.println("ANGLE = " + angle); //System.out.println("ANGLE = " + angle);
rr = radius * 0.25 * (1 - targetrefs / (double) maxtargetrefs); rr = radius * 0.25 * (1 - targetrefs / (double) maxtargetrefs);
re = radius * 0.5 * (thisrefs / (double) maxthisrefs); re = radius * 0.5 * (thisrefs / (double) maxthisrefs);
@ -180,12 +187,12 @@ public class WebStructurePicture_p {
targethost = target[1]; targethost = target[1];
final GraphPlotter.coordinate c = graph.getPoint(targethost); final GraphPlotter.coordinate c = graph.getPoint(targethost);
assert c != null; assert c != null;
nextnodes = ((maxnodes <= 0) || (System.currentTimeMillis() >= timeout)) ? 0 : place(graph, structure, targethash, targethost, maxnodes, timeout, c.x, c.y, nextlayer, maxlayer); nextnodes = ((maxnodes <= 0) || (System.currentTimeMillis() >= timeout)) ? 0 : place(graph, structure, targethash, targethost, maxnodes, timeout, c.x, c.y, nextlayer, maxlayer, coronaangle);
mynodes += nextnodes; mynodes += nextnodes;
maxnodes -= nextnodes; maxnodes -= nextnodes;
graph.setBorder(centerhost, targethost); graph.setBorder(centerhost, targethost);
} }
return mynodes; return mynodes;
} }
} }

@ -39,7 +39,6 @@ import net.yacy.cora.document.UTF8;
import net.yacy.kelondro.logging.Log; import net.yacy.kelondro.logging.Log;
import net.yacy.visualization.PrintTool; import net.yacy.visualization.PrintTool;
import net.yacy.visualization.RasterPlotter; import net.yacy.visualization.RasterPlotter;
import de.anomic.search.QueryParams; import de.anomic.search.QueryParams;
import de.anomic.search.SearchEvent; import de.anomic.search.SearchEvent;
import de.anomic.search.SearchEventCache; import de.anomic.search.SearchEventCache;
@ -73,28 +72,28 @@ public class NetworkGraph {
private static final String COL_MYPEER_TEXT = "FFCCCC"; private static final String COL_MYPEER_TEXT = "FFCCCC";
private static final String COL_DHTOUT = "440000"; private static final String COL_DHTOUT = "440000";
private static final String COL_DHTIN = "008800"; private static final String COL_DHTIN = "008800";
private static final String COL_BORDER = "000000"; private static final String COL_BORDER = "000000";
private static final String COL_NORMAL_TEXT = "000000"; private static final String COL_NORMAL_TEXT = "000000";
private static final String COL_LOAD_BG = "F7F7F7"; private static final String COL_LOAD_BG = "F7F7F7";
public static class CircleThreadPiece { public static class CircleThreadPiece {
private final String pieceName; private final String pieceName;
private final Color color; private final Color color;
private long execTime = 0; private long execTime = 0;
private float fraction = 0; private float fraction = 0;
public CircleThreadPiece(final String pieceName, final Color color) { public CircleThreadPiece(final String pieceName, final Color color) {
this.pieceName = pieceName; this.pieceName = pieceName;
this.color = color; this.color = color;
} }
public int getAngle() { return Math.round(360f*this.fraction); } public int getAngle() { return Math.round(360f*this.fraction); }
public int getFractionPercent() { return Math.round(100f*this.fraction); } public int getFractionPercent() { return Math.round(100f*this.fraction); }
public Color getColor() { return this.color; } public Color getColor() { return this.color; }
public long getExecTime() { return this.execTime; } public long getExecTime() { return this.execTime; }
public String getPieceName() { return this.pieceName; } public String getPieceName() { return this.pieceName; }
public void addExecTime(final long execTime) { this.execTime += execTime; } public void addExecTime(final long execTime) { this.execTime += execTime; }
public void reset() { public void reset() {
this.execTime = 0; this.execTime = 0;
@ -105,9 +104,9 @@ public class NetworkGraph {
this.fraction = (float)this.execTime / (float)totalBusyTime; this.fraction = (float)this.execTime / (float)totalBusyTime;
} }
} }
private static final int LEGEND_BOX_SIZE = 10; private static final int LEGEND_BOX_SIZE = 10;
private static BufferedImage peerloadPicture = null; private static BufferedImage peerloadPicture = null;
private static long peerloadPictureDate = 0; private static long peerloadPictureDate = 0;
@ -126,7 +125,7 @@ public class NetworkGraph {
final RasterPlotter eventPicture = getNetworkPicture(seedDB, 120000, 640, 480, 300, 300, 1000, coronaangle, -1, Switchboard.getSwitchboard().getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified"), Switchboard.getSwitchboard().getConfig("network.unit.description", "unspecified"), COL_BACKGROUND); final RasterPlotter eventPicture = getNetworkPicture(seedDB, 120000, 640, 480, 300, 300, 1000, coronaangle, -1, Switchboard.getSwitchboard().getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified"), Switchboard.getSwitchboard().getConfig("network.unit.description", "unspecified"), COL_BACKGROUND);
//if (eventPicture instanceof ymageMatrix) eventPicture = (ymageMatrix) eventPicture; //new ymageMatrix((ymageMatrix) eventPicture); //if (eventPicture instanceof ymageMatrix) eventPicture = (ymageMatrix) eventPicture; //new ymageMatrix((ymageMatrix) eventPicture);
// TODO: fix cloning of ymageMatrix pictures // TODO: fix cloning of ymageMatrix pictures
// get dimensions // get dimensions
final int cr = Math.min(eventPicture.getWidth(), eventPicture.getHeight()) / 5 - 20; final int cr = Math.min(eventPicture.getWidth(), eventPicture.getHeight()) / 5 - 20;
final int cx = eventPicture.getWidth() / 2; final int cx = eventPicture.getWidth() / 2;
@ -135,32 +134,32 @@ public class NetworkGraph {
int angle; int angle;
// draw in the primary search peers // draw in the primary search peers
for (int j = 0; j < primarySearches.length; j++) { for (final yacySearch primarySearche : primarySearches) {
if (primarySearches[j] == null) continue; if (primarySearche == null) continue;
eventPicture.setColor((primarySearches[j].isAlive()) ? RasterPlotter.RED : RasterPlotter.GREEN); eventPicture.setColor((primarySearche.isAlive()) ? RasterPlotter.RED : RasterPlotter.GREEN);
angle = (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(UTF8.getBytes(primarySearches[j].target().hash), null)) / ((double) Long.MAX_VALUE))); angle = (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(UTF8.getBytes(primarySearche.target().hash), null)) / ((double) Long.MAX_VALUE)));
eventPicture.arcLine(cx, cy, cr - 20, cr, angle, true, null, null, -1, -1, -1, false); eventPicture.arcLine(cx, cy, cr - 20, cr, angle, true, null, null, -1, -1, -1, false);
} }
// draw in the secondary search peers // draw in the secondary search peers
if (secondarySearches != null) { if (secondarySearches != null) {
for (int j = 0; j < secondarySearches.length; j++) { for (final yacySearch secondarySearche : secondarySearches) {
if (secondarySearches[j] == null) continue; if (secondarySearche == null) continue;
eventPicture.setColor((secondarySearches[j].isAlive()) ? RasterPlotter.RED : RasterPlotter.GREEN); eventPicture.setColor((secondarySearche.isAlive()) ? RasterPlotter.RED : RasterPlotter.GREEN);
angle = (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(UTF8.getBytes(secondarySearches[j].target().hash), null)) / ((double) Long.MAX_VALUE))); angle = (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(UTF8.getBytes(secondarySearche.target().hash), null)) / ((double) Long.MAX_VALUE)));
eventPicture.arcLine(cx, cy, cr - 10, cr, angle - 1, true, null, null, -1, -1, -1, false); eventPicture.arcLine(cx, cy, cr - 10, cr, angle - 1, true, null, null, -1, -1, -1, false);
eventPicture.arcLine(cx, cy, cr - 10, cr, angle + 1, true, null, null, -1, -1, -1, false); eventPicture.arcLine(cx, cy, cr - 10, cr, angle + 1, true, null, null, -1, -1, -1, false);
} }
} }
// draw in the search target // draw in the search target
final QueryParams query = event.getQuery(); final QueryParams query = event.getQuery();
final Iterator<byte[]> i = query.queryHashes.iterator(); final Iterator<byte[]> i = query.queryHashes.iterator();
eventPicture.setColor(RasterPlotter.GREY); eventPicture.setColor(RasterPlotter.GREY);
while (i.hasNext()) { while (i.hasNext()) {
long[] positions = seedDB.scheme.dhtPositions(i.next()); final long[] positions = seedDB.scheme.dhtPositions(i.next());
for (int j = 0; j < positions.length; j++) { for (final long position : positions) {
angle = (int) (360.0 * (((double) positions[j]) / ((double) Long.MAX_VALUE))); angle = (int) (360.0 * (((double) position) / ((double) Long.MAX_VALUE)));
eventPicture.arcLine(cx, cy, cr - 20, cr, angle, true, null, null, -1, -1, -1, false); eventPicture.arcLine(cx, cy, cr - 20, cr, angle, true, null, null, -1, -1, -1, false);
} }
} }
@ -177,14 +176,15 @@ public class NetworkGraph {
final int passiveLimit, final int potentialLimit, final int passiveLimit, final int potentialLimit,
final int maxCount, final int coronaangle, final int maxCount, final int coronaangle,
final long communicationTimeout, final long communicationTimeout,
final String networkName, final String networkTitle, final String bgcolor) { final String networkName, final String networkTitle, final String color_back) {
RasterPlotter networkPicture = new RasterPlotter(width, height, (bgcolor.equals("000000")) ? RasterPlotter.DrawMode.MODE_ADD : RasterPlotter.DrawMode.MODE_SUB, bgcolor); final RasterPlotter.DrawMode drawMode = (RasterPlotter.darkColor(color_back)) ? RasterPlotter.DrawMode.MODE_ADD : RasterPlotter.DrawMode.MODE_SUB;
final RasterPlotter networkPicture = new RasterPlotter(width, height, drawMode, color_back);
if (seedDB == null) return networkPicture; // no other peers known if (seedDB == null) return networkPicture; // no other peers known
final int maxradius = Math.min(width, height) / 2; final int maxradius = Math.min(width, height) / 2;
final int innerradius = maxradius * 4 / 10; final int innerradius = maxradius * 4 / 10;
int outerradius = maxradius - 20; final int outerradius = maxradius - 20;
// draw network circle // draw network circle
networkPicture.setColor(COL_DHTCIRCLE); networkPicture.setColor(COL_DHTCIRCLE);
@ -253,34 +253,34 @@ public class NetworkGraph {
// draw DHT activity // draw DHT activity
if (communicationTimeout >= 0) { if (communicationTimeout >= 0) {
Date horizon = new Date(System.currentTimeMillis() - communicationTimeout); final Date horizon = new Date(System.currentTimeMillis() - communicationTimeout);
for (Hit event: yacyChannel.channels(yacyChannel.DHTRECEIVE)) { for (final Hit event: yacyChannel.channels(yacyChannel.DHTRECEIVE)) {
if (event == null || event.getPubDate() == null) continue; if (event == null || event.getPubDate() == null) continue;
if (event.getPubDate().after(horizon)) { if (event.getPubDate().after(horizon)) {
//System.out.println("*** NETWORK-DHTRECEIVE: " + event.getLink()); //System.out.println("*** NETWORK-DHTRECEIVE: " + event.getLink());
drawNetworkPictureDHT(networkPicture, width / 2, height / 2, innerradius, seedDB.mySeed(), seedDB.get(event.getLink()), COL_DHTIN, coronaangle, false); drawNetworkPictureDHT(networkPicture, width / 2, height / 2, innerradius, seedDB.mySeed(), seedDB.get(event.getLink()), COL_DHTIN, coronaangle, false);
} }
} }
for (Hit event: yacyChannel.channels(yacyChannel.DHTSEND)) { for (final Hit event: yacyChannel.channels(yacyChannel.DHTSEND)) {
if (event == null || event.getPubDate() == null) continue; if (event == null || event.getPubDate() == null) continue;
if (event.getPubDate().after(horizon)) { if (event.getPubDate().after(horizon)) {
//System.out.println("*** NETWORK-DHTSEND: " + event.getLink()); //System.out.println("*** NETWORK-DHTSEND: " + event.getLink());
drawNetworkPictureDHT(networkPicture, width / 2, height / 2, innerradius, seedDB.mySeed(), seedDB.get(event.getLink()), COL_DHTOUT, coronaangle, true); drawNetworkPictureDHT(networkPicture, width / 2, height / 2, innerradius, seedDB.mySeed(), seedDB.get(event.getLink()), COL_DHTOUT, coronaangle, true);
} }
} }
} }
// draw description // draw description
networkPicture.setColor(COL_HEADLINE); networkPicture.setColor(COL_HEADLINE);
PrintTool.print(networkPicture, 2, 6, 0, "YACY NETWORK '" + networkName.toUpperCase() + "'", -1); PrintTool.print(networkPicture, 2, 6, 0, "YACY NETWORK '" + networkName.toUpperCase() + "'", -1);
PrintTool.print(networkPicture, 2, 14, 0, networkTitle.toUpperCase(), -1); PrintTool.print(networkPicture, 2, 14, 0, networkTitle.toUpperCase(), -1);
PrintTool.print(networkPicture, width - 2, 6, 0, "SNAPSHOT FROM " + new Date().toString().toUpperCase(), 1); PrintTool.print(networkPicture, width - 2, 6, 0, "SNAPSHOT FROM " + new Date().toString().toUpperCase(), 1);
PrintTool.print(networkPicture, width - 2, 14, 0, "DRAWING OF " + totalCount + " SELECTED PEERS", 1); PrintTool.print(networkPicture, width - 2, 14, 0, "DRAWING OF " + totalCount + " SELECTED PEERS", 1);
return networkPicture; return networkPicture;
} }
private static void drawNetworkPictureDHT(final RasterPlotter img, final int centerX, final int centerY, final int innerradius, final yacySeed mySeed, final yacySeed otherSeed, final String colorLine, final int coronaangle, boolean out) { private static void drawNetworkPictureDHT(final RasterPlotter img, final int centerX, final int centerY, final int innerradius, final yacySeed mySeed, final yacySeed otherSeed, final String colorLine, final int coronaangle, final boolean out) {
final int angleMy = (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(mySeed.hash), null)) / ((double) Long.MAX_VALUE))); final int angleMy = (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(mySeed.hash), null)) / ((double) Long.MAX_VALUE)));
final int angleOther = (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(otherSeed.hash), null)) / ((double) Long.MAX_VALUE))); final int angleOther = (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(otherSeed.hash), null)) / ((double) Long.MAX_VALUE)));
// draw line // draw line
@ -291,7 +291,7 @@ public class NetworkGraph {
img.arcConnect(centerX, centerY, innerradius - 20, angleMy, angleOther, out, img.arcConnect(centerX, centerY, innerradius - 20, angleMy, angleOther, out,
colorLine, 100, null, 100, 12, (coronaangle < 0) ? -1 : coronaangle / 30, 2, true); colorLine, 100, null, 100, 12, (coronaangle < 0) ? -1 : coronaangle / 30, 2, true);
} }
private static void drawNetworkPicturePeer( private static void drawNetworkPicturePeer(
final RasterPlotter img, final int centerX, final int centerY, final RasterPlotter img, final int centerX, final int centerY,
final int innerradius, final int outerradius, final int innerradius, final int outerradius,
@ -317,31 +317,31 @@ public class NetworkGraph {
PrintTool.arcPrint(img, centerX, centerY, innerradius + linelength, angle, name); PrintTool.arcPrint(img, centerX, centerY, innerradius + linelength, angle, name);
// draw corona around dot for crawling activity // draw corona around dot for crawling activity
int ppmx = seed.getPPM() / 30; final int ppmx = seed.getPPM() / 30;
if (coronaangle >= 0 && ppmx > 0) { if (coronaangle >= 0 && ppmx > 0) {
drawCorona(img, centerX, centerY, innerradius, angle, dotsize, ppmx, coronaangle, true, false, 24, 24, 24); // color = 0..63 drawCorona(img, centerX, centerY, innerradius, angle, dotsize, ppmx, coronaangle, true, false, 24, 24, 24); // color = 0..63
} }
// draw corona around dot for query activity // draw corona around dot for query activity
int qphx = ((int) (seed.getQPM() * 4.0)); final int qphx = ((int) (seed.getQPM() * 4.0));
if (coronaangle >= 0 && qphx > 0) { if (coronaangle >= 0 && qphx > 0) {
drawCorona(img, centerX, centerY, innerradius, angle, dotsize, qphx, coronaangle, false, true, 8, 62, 8); // color = 0..63 drawCorona(img, centerX, centerY, innerradius, angle, dotsize, qphx, coronaangle, false, true, 8, 62, 8); // color = 0..63
} }
} }
private static void drawCorona(final RasterPlotter img, final int centerX, final int centerY, final int innerradius, int angle, int dotsize, int strength, int coronaangle, boolean inside, boolean split, int r, int g, int b) { private static void drawCorona(final RasterPlotter img, final int centerX, final int centerY, final int innerradius, final int angle, final int dotsize, int strength, final int coronaangle, final boolean inside, final boolean split, final int r, final int g, final int b) {
double ca = Math.PI * 2.0 * ((double) coronaangle) / 360.0; final double ca = Math.PI * 2.0 * (coronaangle) / 360.0;
if (strength > 4) strength = 4; if (strength > 4) strength = 4;
// draw a wave around crawling peers // draw a wave around crawling peers
double wave; double wave;
final int waveradius = innerradius / 2; final int waveradius = innerradius / 2;
int segments = 72; final int segments = 72;
for (int radius = 0; radius < waveradius; radius++) { for (int radius = 0; radius < waveradius; radius++) {
wave = ((double) (waveradius - radius) * strength) * (1.0 + Math.sin(Math.PI * 16 * radius / waveradius + ((inside) ? ca : -ca))) / 2.0 / (double) waveradius; wave = ((double) (waveradius - radius) * strength) * (1.0 + Math.sin(Math.PI * 16 * radius / waveradius + ((inside) ? ca : -ca))) / 2.0 / waveradius;
img.setColor(((((long) (r * wave)) & 0xff) << 16) | (((long) ((g * wave)) & 0xff) << 8) | ((((long) (b * wave))) & 0xff)); img.setColor(((((long) (r * wave)) & 0xff) << 16) | (((long) ((g * wave)) & 0xff) << 8) | ((((long) (b * wave))) & 0xff));
if (split) { if (split) {
for (int i = 0; i < segments; i++) { for (int i = 0; i < segments; i++) {
int a = (coronaangle + 360 * i) / segments; final int a = (coronaangle + 360 * i) / segments;
img.arcArc(centerX, centerY, innerradius, angle, dotsize + radius, dotsize + radius, a, a + 180/segments); img.arcArc(centerX, centerY, innerradius, angle, dotsize + radius, dotsize + radius, a, a + 180/segments);
} }
} else { } else {
@ -349,14 +349,14 @@ public class NetworkGraph {
} }
} }
} }
public static BufferedImage getPeerLoadPicture(final long maxAge, final int width, final int height, final CircleThreadPiece[] pieces, final CircleThreadPiece fillRest) { public static BufferedImage getPeerLoadPicture(final long maxAge, final int width, final int height, final CircleThreadPiece[] pieces, final CircleThreadPiece fillRest) {
if ((peerloadPicture == null) || ((System.currentTimeMillis() - peerloadPictureDate) > maxAge)) { if ((peerloadPicture == null) || ((System.currentTimeMillis() - peerloadPictureDate) > maxAge)) {
drawPeerLoadPicture(width, height, pieces, fillRest); drawPeerLoadPicture(width, height, pieces, fillRest);
} }
return peerloadPicture; return peerloadPicture;
} }
private static void drawPeerLoadPicture(final int width, final int height, final CircleThreadPiece[] pieces, final CircleThreadPiece fillRest) { private static void drawPeerLoadPicture(final int width, final int height, final CircleThreadPiece[] pieces, final CircleThreadPiece fillRest) {
//prepare image //prepare image
peerloadPicture = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB); peerloadPicture = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
@ -364,42 +364,42 @@ public class NetworkGraph {
g.setBackground(Color.decode("0x"+COL_LOAD_BG)); g.setBackground(Color.decode("0x"+COL_LOAD_BG));
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.clearRect(0,0,width,height); g.clearRect(0,0,width,height);
final int circ_w = Math.min(width,height)-20; //width of the circle (r*2) final int circ_w = Math.min(width,height)-20; //width of the circle (r*2)
final int circ_x = width-circ_w-10; //x-coordinate of circle-left final int circ_x = width-circ_w-10; //x-coordinate of circle-left
final int circ_y = 10; //y-coordinate of circle-top final int circ_y = 10; //y-coordinate of circle-top
int curr_angle = 0; //remember current angle int curr_angle = 0; //remember current angle
int i; int i;
for (i=0; i<pieces.length; i++) { for (i=0; i<pieces.length; i++) {
// draw the piece // draw the piece
g.setColor(pieces[i].getColor()); g.setColor(pieces[i].getColor());
g.fillArc(circ_x, circ_y, circ_w, circ_w, curr_angle, pieces[i].getAngle()); g.fillArc(circ_x, circ_y, circ_w, circ_w, curr_angle, pieces[i].getAngle());
curr_angle += pieces[i].getAngle(); curr_angle += pieces[i].getAngle();
// draw it's legend line // draw it's legend line
drawLegendLine(g, 5, height - 5 - 15 * i, pieces[i].getPieceName()+" ("+pieces[i].getFractionPercent()+" %)", pieces[i].getColor()); drawLegendLine(g, 5, height - 5 - 15 * i, pieces[i].getPieceName()+" ("+pieces[i].getFractionPercent()+" %)", pieces[i].getColor());
} }
// fill the rest // fill the rest
g.setColor(fillRest.getColor()); g.setColor(fillRest.getColor());
//FIXME: better method to avoid gaps on rounding-differences? //FIXME: better method to avoid gaps on rounding-differences?
g.fillArc(circ_x, circ_y, circ_w, circ_w, curr_angle, 360 - curr_angle); g.fillArc(circ_x, circ_y, circ_w, circ_w, curr_angle, 360 - curr_angle);
drawLegendLine(g, 5, height - 5 - 15 * i, fillRest.getPieceName()+" ("+fillRest.getFractionPercent()+" %)", fillRest.getColor()); drawLegendLine(g, 5, height - 5 - 15 * i, fillRest.getPieceName()+" ("+fillRest.getFractionPercent()+" %)", fillRest.getColor());
//draw border around the circle //draw border around the circle
g.setColor(Color.decode("0x"+COL_BORDER)); g.setColor(Color.decode("0x"+COL_BORDER));
g.drawArc(circ_x, circ_y, circ_w, circ_w, 0, 360); g.drawArc(circ_x, circ_y, circ_w, circ_w, 0, 360);
peerloadPictureDate = System.currentTimeMillis(); peerloadPictureDate = System.currentTimeMillis();
} }
private static void drawLegendLine(final Graphics2D g, final int x, final int y, final String caption, final Color item_color) { private static void drawLegendLine(final Graphics2D g, final int x, final int y, final String caption, final Color item_color) {
g.setColor(item_color); g.setColor(item_color);
g.fillRect(x, y-LEGEND_BOX_SIZE, LEGEND_BOX_SIZE, LEGEND_BOX_SIZE); g.fillRect(x, y-LEGEND_BOX_SIZE, LEGEND_BOX_SIZE, LEGEND_BOX_SIZE);
g.setColor(Color.decode("0x"+COL_BORDER)); g.setColor(Color.decode("0x"+COL_BORDER));
g.drawRect(x, y-LEGEND_BOX_SIZE, LEGEND_BOX_SIZE, LEGEND_BOX_SIZE); g.drawRect(x, y-LEGEND_BOX_SIZE, LEGEND_BOX_SIZE, LEGEND_BOX_SIZE);
g.setColor(Color.decode("0x"+COL_NORMAL_TEXT)); g.setColor(Color.decode("0x"+COL_NORMAL_TEXT));
g.drawChars(caption.toCharArray(), 0, caption.length(), x+LEGEND_BOX_SIZE+5,y); g.drawChars(caption.toCharArray(), 0, caption.length(), x+LEGEND_BOX_SIZE+5,y);
} }
@ -409,8 +409,8 @@ public class NetworkGraph {
drawBannerPicture(width, height, bgcolor, textcolor, bordercolor, name, links, words, type, ppm, network, peers, nlinks, nwords, nqph, nppm, logo); drawBannerPicture(width, height, bgcolor, textcolor, bordercolor, name, links, words, type, ppm, network, peers, nlinks, nwords, nqph, nppm, logo);
} }
return bannerPicture; return bannerPicture;
} }
public static RasterPlotter getBannerPicture(final long maxAge, final int width, final int height, final String bgcolor, final String textcolor, final String bordercolor, final String name, final long links, final long words, final String type, final int ppm, final String network, final int peers, final long nlinks, final long nwords, final double nqph, final long nppm, final BufferedImage newLogo) { public static RasterPlotter getBannerPicture(final long maxAge, final int width, final int height, final String bgcolor, final String textcolor, final String bordercolor, final String name, final long links, final long words, final String type, final int ppm, final String network, final int peers, final long nlinks, final long nwords, final double nqph, final long nppm, final BufferedImage newLogo) {
if ((bannerPicture == null) || ((System.currentTimeMillis() - bannerPictureDate) > maxAge)) { if ((bannerPicture == null) || ((System.currentTimeMillis() - bannerPictureDate) > maxAge)) {
drawBannerPicture(width, height, bgcolor, textcolor, bordercolor, name, links, words, type, ppm, network, peers, nlinks, nwords, nqph, nppm, newLogo); drawBannerPicture(width, height, bgcolor, textcolor, bordercolor, name, links, words, type, ppm, network, peers, nlinks, nwords, nqph, nppm, newLogo);
@ -451,11 +451,11 @@ public class NetworkGraph {
bannerPicture.line(width-1, 0, width-1, height-1, 100); bannerPicture.line(width-1, 0, width-1, height-1, 100);
bannerPicture.line(0, height-1, width-1, height-1, 100); bannerPicture.line(0, height-1, width-1, height-1, 100);
} }
// set timestamp // set timestamp
bannerPictureDate = System.currentTimeMillis(); bannerPictureDate = System.currentTimeMillis();
} }
public static boolean logoIsLoaded() { public static boolean logoIsLoaded() {
if (logo == null) { if (logo == null) {
return false; return false;

@ -1,39 +0,0 @@
package net.yacy;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class screenshot {
/*
try {
Robot robot = new Robot();
Rectangle area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage bufferedImage = robot.createScreenCapture(area);
} catch (AWTException e) {
}
*/
public static void main(final String[] args) throws Exception {
final Toolkit toolkit = Toolkit.getDefaultToolkit();
final Dimension screenSize = toolkit.getScreenSize();
final Rectangle screenRect = new Rectangle(screenSize);
// create screen shot
final Robot robot = new Robot();
final BufferedImage image = robot.createScreenCapture(screenRect);
final String outFileName = "test.png";
// save captured image to PNG file
ImageIO.write(image, "png", new File(outFileName));
// give feedback
System.out.println("Saved screen shot (" + image.getWidth() + " x " + image.getHeight() + " pixels) to file \"" + outFileName + "\".");
}
}

@ -9,7 +9,7 @@
// $LastChangedBy$ // $LastChangedBy$
// //
// LICENSE // LICENSE
// //
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or // the Free Software Foundation; either version 2 of the License, or
@ -44,24 +44,24 @@ public class GraphPlotter {
// a ymageGraph is a set of points and borders between the points // a ymageGraph is a set of points and borders between the points
// to reference the points, they must all have a nickname // to reference the points, they must all have a nickname
private Map<String, coordinate> points; private final Map<String, coordinate> points;
private Set<String> borders; private final Set<String> borders;
private double leftmost, rightmost, topmost, bottommost; private double leftmost, rightmost, topmost, bottommost;
public GraphPlotter() { public GraphPlotter() {
points = new HashMap<String, coordinate>(); this.points = new HashMap<String, coordinate>();
borders = new HashSet<String>(); this.borders = new HashSet<String>();
leftmost = 1.0; this.leftmost = 1.0;
rightmost = -1.0; this.rightmost = -1.0;
topmost = -1.0; this.topmost = -1.0;
bottommost = 1.0; this.bottommost = 1.0;
} }
public coordinate getPoint(final String name) { public coordinate getPoint(final String name) {
return points.get(name); return this.points.get(name);
} }
public coordinate[] getBorder(final String name) { public coordinate[] getBorder(final String name) {
final int p = name.indexOf("$"); final int p = name.indexOf("$");
if (p < 0) return null; if (p < 0) return null;
@ -70,28 +70,28 @@ public class GraphPlotter {
if ((from == null) || (to == null)) return null; if ((from == null) || (to == null)) return null;
return new coordinate[] {from, to}; return new coordinate[] {from, to};
} }
public coordinate addPoint(final String name, final double x, final double y, final int layer) { public coordinate addPoint(final String name, final double x, final double y, final int layer) {
final coordinate newc = new coordinate(x, y, layer); final coordinate newc = new coordinate(x, y, layer);
final coordinate oldc = points.put(name, newc); final coordinate oldc = this.points.put(name, newc);
assert oldc == null; // all add shall be unique assert oldc == null; // all add shall be unique
if (x > rightmost) rightmost = x; if (x > this.rightmost) this.rightmost = x;
if (x < leftmost) leftmost = x; if (x < this.leftmost) this.leftmost = x;
if (y > topmost) topmost = y; if (y > this.topmost) this.topmost = y;
if (y < bottommost) bottommost = y; if (y < this.bottommost) this.bottommost = y;
return newc; return newc;
} }
public boolean hasBorder(final String fromPoint, final String toPoint) { public boolean hasBorder(final String fromPoint, final String toPoint) {
return borders.contains(fromPoint + "-" + toPoint); return this.borders.contains(fromPoint + "-" + toPoint);
} }
public void setBorder(final String fromPoint, final String toPoint) { public void setBorder(final String fromPoint, final String toPoint) {
final coordinate from = points.get(fromPoint); final coordinate from = this.points.get(fromPoint);
final coordinate to = points.get(toPoint); final coordinate to = this.points.get(toPoint);
assert from != null; assert from != null;
assert to != null; assert to != null;
borders.add(fromPoint + "$" + toPoint); this.borders.add(fromPoint + "$" + toPoint);
} }
public static class coordinate { public static class coordinate {
@ -107,10 +107,10 @@ public class GraphPlotter {
this.layer = layer; this.layer = layer;
} }
} }
public void print() { public void print() {
// for debug purpose: print out all coordinates // for debug purpose: print out all coordinates
final Iterator<Map.Entry<String, coordinate>> i = points.entrySet().iterator(); final Iterator<Map.Entry<String, coordinate>> i = this.points.entrySet().iterator();
Map.Entry<String, coordinate> entry; Map.Entry<String, coordinate> entry;
String name; String name;
coordinate c; coordinate c;
@ -120,12 +120,12 @@ public class GraphPlotter {
c = entry.getValue(); c = entry.getValue();
System.out.println("point(" + c.x + ", " + c.y + ", " + c.layer + ") [" + name + "]"); System.out.println("point(" + c.x + ", " + c.y + ", " + c.layer + ") [" + name + "]");
} }
final Iterator<String> j = borders.iterator(); final Iterator<String> j = this.borders.iterator();
while (j.hasNext()) { while (j.hasNext()) {
System.out.println("border(" + j.next() + ")"); System.out.println("border(" + j.next() + ")");
} }
} }
public RasterPlotter draw( public RasterPlotter draw(
final int width, final int width,
final int height, final int height,
@ -139,15 +139,14 @@ public class GraphPlotter {
final String color_lineend, final String color_lineend,
final String color_text final String color_text
) { ) {
RasterPlotter.DrawMode drawMode = RasterPlotter.DrawMode.MODE_SUB; final RasterPlotter.DrawMode drawMode = (RasterPlotter.darkColor(color_back)) ? RasterPlotter.DrawMode.MODE_ADD : RasterPlotter.DrawMode.MODE_SUB;
if (RasterPlotter.darkColor(color_back)) drawMode = RasterPlotter.DrawMode.MODE_ADD;
final RasterPlotter image = new RasterPlotter(width, height, drawMode, color_back); final RasterPlotter image = new RasterPlotter(width, height, drawMode, color_back);
final double xfactor = ((rightmost - leftmost) == 0.0) ? 0.0 : (width - leftborder - rightborder) / (rightmost - leftmost); final double xfactor = ((this.rightmost - this.leftmost) == 0.0) ? 0.0 : (width - leftborder - rightborder) / (this.rightmost - this.leftmost);
final double yfactor = ((topmost - bottommost) == 0.0) ? 0.0 : (height - topborder - bottomborder) / (topmost - bottommost); final double yfactor = ((this.topmost - this.bottommost) == 0.0) ? 0.0 : (height - topborder - bottomborder) / (this.topmost - this.bottommost);
// draw dots and names // draw dots and names
final Iterator<Map.Entry<String, coordinate>> i = points.entrySet().iterator(); final Iterator<Map.Entry<String, coordinate>> i = this.points.entrySet().iterator();
Map.Entry<String, coordinate> entry; Map.Entry<String, coordinate> entry;
String name; String name;
coordinate c; coordinate c;
@ -156,8 +155,8 @@ public class GraphPlotter {
entry = i.next(); entry = i.next();
name = entry.getKey(); name = entry.getKey();
c = entry.getValue(); c = entry.getValue();
x = (xfactor == 0.0) ? width / 2 : (int) (leftborder + (c.x - leftmost) * xfactor); x = (xfactor == 0.0) ? width / 2 : (int) (leftborder + (c.x - this.leftmost) * xfactor);
y = (yfactor == 0.0) ? height / 2 : (int) (height - bottomborder - (c.y - bottommost) * yfactor); y = (yfactor == 0.0) ? height / 2 : (int) (height - bottomborder - (c.y - this.bottommost) * yfactor);
image.setColor(color_dot); image.setColor(color_dot);
image.dot(x, y, 6, true, 100); image.dot(x, y, 6, true, 100);
image.setColor(color_text); image.setColor(color_text);
@ -165,7 +164,7 @@ public class GraphPlotter {
} }
// draw lines // draw lines
final Iterator<String> j = borders.iterator(); final Iterator<String> j = this.borders.iterator();
coordinate[] border; coordinate[] border;
image.setColor(color_line); image.setColor(color_line);
int x0, x1, y0, y1; int x0, x1, y0, y1;
@ -176,20 +175,20 @@ public class GraphPlotter {
x0 = width / 2; x0 = width / 2;
x1 = width / 2; x1 = width / 2;
} else { } else {
x0 = (int) (leftborder + (border[0].x - leftmost) * xfactor); x0 = (int) (leftborder + (border[0].x - this.leftmost) * xfactor);
x1 = (int) (leftborder + (border[1].x - leftmost) * xfactor); x1 = (int) (leftborder + (border[1].x - this.leftmost) * xfactor);
} }
if (yfactor == 0.0) { if (yfactor == 0.0) {
y0 = height / 2; y0 = height / 2;
y1 = height / 2; y1 = height / 2;
} else { } else {
y0 = (int) (height - bottomborder - (border[0].y - bottommost) * yfactor); y0 = (int) (height - bottomborder - (border[0].y - this.bottommost) * yfactor);
y1 = (int) (height - bottomborder - (border[1].y - bottommost) * yfactor); y1 = (int) (height - bottomborder - (border[1].y - this.bottommost) * yfactor);
} }
// draw the line, with the dot at the beginning of the line // draw the line, with the dot at the beginning of the line
image.lineDot(x1, y1, x0, y0, 3, 4, color_line, color_lineend); image.lineDot(x1, y1, x0, y0, 3, 4, color_line, color_lineend);
} }
return image; return image;
} }
} }

Loading…
Cancel
Save