Skip to content

Commit

Permalink
redesign of ymage classes
Browse files Browse the repository at this point in the history
- less memory usage
- better usage of awt classes
- drawing abstractions: preparations for movable objects for animation class
- test applet for animations
- known bugs: wrong colours for network picture

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3214 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Jan 15, 2007
1 parent c82f494 commit 5515571
Show file tree
Hide file tree
Showing 15 changed files with 461 additions and 572 deletions.
4 changes: 2 additions & 2 deletions htroot/NetworkPicture.java
Expand Up @@ -48,13 +48,13 @@
import de.anomic.plasma.plasmaGrafics;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.ymage.ymagePainter;
import de.anomic.ymage.ymageMatrix;

// draw a picture of the yacy network

public class NetworkPicture {

public static ymagePainter respond(httpHeader header, serverObjects post, serverSwitch env) {
public static ymageMatrix respond(httpHeader header, serverObjects post, serverSwitch env) {

int width = 640;
int height = 480;
Expand Down
9 changes: 4 additions & 5 deletions htroot/SearchEventPicture.java
Expand Up @@ -48,17 +48,16 @@
import de.anomic.plasma.plasmaGrafics;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.ymage.ymageMatrixPainter;
import de.anomic.ymage.ymagePainter;
import de.anomic.ymage.ymageMatrix;

// draw a picture of the yacy network

public class SearchEventPicture {

public static ymagePainter respond(httpHeader header, serverObjects post, serverSwitch env) {
public static ymageMatrix respond(httpHeader header, serverObjects post, serverSwitch env) {

ymagePainter yp = plasmaGrafics.getSearchEventPicture();
if (yp == null) return new ymageMatrixPainter(1, 1, "000000"); // empty image
ymageMatrix yp = plasmaGrafics.getSearchEventPicture();
if (yp == null) return new ymageMatrix(1, 1, "000000"); // empty image

return yp;
}
Expand Down
36 changes: 17 additions & 19 deletions htroot/imagetest.java
Expand Up @@ -47,14 +47,12 @@
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.ymage.ymageMatrix;
import de.anomic.ymage.ymageMatrixPainter;
import de.anomic.ymage.ymagePainter;

import de.anomic.ymage.ymageToolPrint;

public class imagetest {


public static ymagePainter respond(httpHeader header, serverObjects post, serverSwitch env) {
public static ymageMatrix respond(httpHeader header, serverObjects post, serverSwitch env) {
/*
BufferedImage bi = new BufferedImage(640, 400, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();
Expand Down Expand Up @@ -86,27 +84,27 @@ public static ymagePainter respond(httpHeader header, serverObjects post, server
for (int i = 20; i < 100; i++) r.setPixel(i, 34, new int[]{0, 0, 255});
return bi;
*/
ymagePainter img = new ymageMatrixPainter(800, 600, "000000");
ymageMatrix img = new ymageMatrix(800, 600, "000000");

img.setMode(ymageMatrix.MODE_ADD);
img.setColor(ymageMatrix.ADDITIVE_BLACK);
for (int y = 0; y < 600; y = y + 50) img.print(0, 6 + y, 0, "" + y, true);
for (int x = 0; x < 800; x = x + 50) img.print(x, 6 , 0, "" + x, true);
img.setColor(ymageMatrix.ADDITIVE_RED);
img.setMode(ymageMatrix.MODE_SUB);
img.setColor(ymageMatrix.SUBTRACTIVE_BLACK);
for (int y = 0; y < 600; y = y + 50) ymageToolPrint.print(img, 0, 6 + y, 0, "" + y, true);
for (int x = 0; x < 800; x = x + 50) ymageToolPrint.print(img, x, 6 , 0, "" + x, true);
img.setColor(ymageMatrix.SUBTRACTIVE_RED);
img.dot(550, 110, 90, true);
img.setColor(ymageMatrix.ADDITIVE_GREEN);
img.setColor(ymageMatrix.SUBTRACTIVE_GREEN);
img.dot(480, 200, 90, true);
img.setColor(ymageMatrix.ADDITIVE_BLUE);
img.setColor(ymageMatrix.SUBTRACTIVE_BLUE);
img.dot(620, 200, 90, true);
img.setColor(ymageMatrix.ADDITIVE_RED);
img.setColor(ymageMatrix.SUBTRACTIVE_RED);
img.arc(300, 270, 30, 70, 0, 360);
img.setColor("330000");
img.arc(220, 110, 50, 90, 30, 110);
img.arc(210, 120, 50, 90, 30, 110);
img.setColor(ymageMatrix.ADDITIVE_BLACK);
img.print(50, 110, 0, "BROADCAST MESSAGE #772: NODE %882 BLACK abcefghijklmnopqrstuvwxyz", true);
img.setColor(ymageMatrix.ADDITIVE_GREEN);
img.print(50, 120, 0, "BROADCAST MESSAGE #772: NODE %882 GREEN abcefghijklmnopqrstuvwxyz", true);
img.setColor(ymageMatrix.SUBTRACTIVE_BLACK);
ymageToolPrint.print(img, 50, 110, 0, "BROADCAST MESSAGE #772: NODE %882 BLACK abcefghijklmnopqrstuvwxyz", true);
img.setColor(ymageMatrix.SUBTRACTIVE_GREEN);
ymageToolPrint.print(img, 50, 120, 0, "BROADCAST MESSAGE #772: NODE %882 GREEN abcefghijklmnopqrstuvwxyz", true);
for (long i = 0; i < 256; i++) {
img.setColor(i);
img.dot(10 + 14 * (int) (i / 16), 200 + 14 * (int) (i % 16), 6, true);
Expand All @@ -128,12 +126,12 @@ public static ymagePainter respond(httpHeader header, serverObjects post, server
for (int i = 0; i <= 360; i++) {
img.arc(550, 400, 40, 41 + i/9, 0, i);
}
img.setColor(ymageMatrix.ADDITIVE_BLACK);
img.setColor(ymageMatrix.SUBTRACTIVE_BLACK);
int angle;
for (byte c = (byte) 'A'; c <= 'Z'; c++) {
angle = (c - (byte) 'A') * 360 / ((byte) 'Z' - (byte) 'A');
img.arcLine(550, 400, 81, 100, angle);
img.arcPrint(550, 400, 100, angle, "ANGLE" + angle + ":" + (char) c);
ymageToolPrint.arcPrint(img, 550, 400, 100, angle, "ANGLE" + angle + ":" + (char) c);
}
return img;

Expand Down
5 changes: 3 additions & 2 deletions source/dbtest.java
Expand Up @@ -12,6 +12,8 @@
import java.util.Iterator;
import java.util.Random;

import javax.imageio.ImageIO;

import de.anomic.kelondro.kelondroBase64Order;
import de.anomic.kelondro.kelondroCache;
import de.anomic.kelondro.kelondroFlexSplitTable;
Expand All @@ -26,7 +28,6 @@
import de.anomic.server.serverInstantThread;
import de.anomic.server.serverMemory;
import de.anomic.ymage.ymageChart;
import de.anomic.ymage.ymagePNGEncoderAWT;

public class dbtest {

Expand Down Expand Up @@ -673,7 +674,7 @@ public void run() {
try {Thread.sleep(100);} catch (InterruptedException e) {}
}
try {
ymagePNGEncoderAWT.toPNG(memChart, true, outputFile);
ImageIO.write(memChart.getImage(), "png", outputFile);
} catch (IOException e) {}
}

Expand Down
12 changes: 4 additions & 8 deletions source/de/anomic/http/httpdFileHandler.java
Expand Up @@ -115,9 +115,7 @@ public static java.util.Hashtable respond(java.util.HashMap, serverSwitch)
import de.anomic.server.serverSwitch;
import de.anomic.server.servletProperties;
import de.anomic.server.logging.serverLog;
import de.anomic.ymage.ymageMatrixPainter;
import de.anomic.ymage.ymagePNGEncoderAWT;
import de.anomic.ymage.ymagePainter;
import de.anomic.ymage.ymageMatrix;

public final class httpdFileHandler extends httpdAbstractHandler implements httpdHandler {

Expand Down Expand Up @@ -514,8 +512,8 @@ public void doResponse(Properties conProp, httpHeader requestHeader, OutputStrea
// error with image generation; send file-not-found
httpd.sendRespondError(this.connectionProperties,out,3,404,"File not Found",null,null);
} else {
if (img instanceof ymagePainter) {
ymagePainter yp = (ymagePainter) img;
if (img instanceof ymageMatrix) {
ymageMatrix yp = (ymageMatrix) img;
// send an image to client
targetDate = new Date(System.currentTimeMillis());
nocache = true;
Expand All @@ -527,9 +525,7 @@ public void doResponse(Properties conProp, httpHeader requestHeader, OutputStrea
// ymagePNGEncoderJDE((ymageMatrixPainter) yp,
// ymagePNGEncoderJDE.FILTER_NONE, 0);
// byte[] result = jde.pngEncode();
ImageIO.write(ymagePNGEncoderAWT.toImage(
(ymageMatrixPainter) yp, true),
targetExt, baos);
ImageIO.write(yp.getImage(), targetExt, baos);
byte[] result = baos.toByteArray();
baos.close();
baos = null;
Expand Down
54 changes: 27 additions & 27 deletions source/de/anomic/plasma/plasmaGrafics.java
Expand Up @@ -53,27 +53,27 @@
import de.anomic.yacy.yacySearch;
import de.anomic.yacy.yacySeed;
import de.anomic.ymage.ymageMatrix;
import de.anomic.ymage.ymageMatrixPainter;
import de.anomic.ymage.ymagePainter;
import de.anomic.ymage.ymageToolPrint;

public class plasmaGrafics {

private static int shortestName = 10;
private static int longestName = 12;

private static ymagePainter networkPicture = null;
private static ymageMatrix networkPicture = null;
private static long networkPictureDate = 0;

public static ymagePainter getSearchEventPicture() {
public static ymageMatrix getSearchEventPicture() {
if (plasmaSearchEvent.lastEvent == null) return null;
yacySearch[] primarySearches = plasmaSearchEvent.lastEvent.getPrimarySearchThreads();
yacySearch[] secondarySearches = plasmaSearchEvent.lastEvent.getSecondarySearchThreads();
if (primarySearches == null) return null; // this was a local search and there are no threads

// get a copy of a recent network picture
ymagePainter eventPicture = getNetworkPicture(120000);
if (eventPicture instanceof ymageMatrixPainter) eventPicture = new ymageMatrixPainter((ymageMatrix) eventPicture);

ymageMatrix eventPicture = getNetworkPicture(120000);
if (eventPicture instanceof ymageMatrix) eventPicture = (ymageMatrix) eventPicture; //new ymageMatrix((ymageMatrix) eventPicture);
// TODO: fix cloning of ymageMatrix pictures

// get dimensions
int cr = Math.min(eventPicture.getWidth(), eventPicture.getHeight()) / 5 - 20;
int cx = eventPicture.getWidth() / 2;
Expand All @@ -84,7 +84,7 @@ public static ymagePainter getSearchEventPicture() {

// draw in the primary search peers
for (int j = 0; j < primarySearches.length; j++) {
eventPicture.setColor((primarySearches[j].isAlive()) ? ymageMatrix.ADDITIVE_RED : ymageMatrix.ADDITIVE_GREEN);
eventPicture.setColor((primarySearches[j].isAlive()) ? ymageMatrix.SUBTRACTIVE_RED : ymageMatrix.SUBTRACTIVE_GREEN);
hash = primarySearches[j].target().hash;
angle = (int) ((long) 360 * (yacySeed.dhtPosition(hash) / (yacySeed.maxDHTDistance / (long) 10000)) / (long) 10000);
eventPicture.arcLine(cx, cy, cr - 20, cr, angle);
Expand All @@ -93,7 +93,7 @@ public static ymagePainter getSearchEventPicture() {
// draw in the secondary search peers
if (secondarySearches != null) {
for (int j = 0; j < secondarySearches.length; j++) {
eventPicture.setColor((secondarySearches[j].isAlive()) ? ymageMatrix.ADDITIVE_RED : ymageMatrix.ADDITIVE_GREEN);
eventPicture.setColor((secondarySearches[j].isAlive()) ? ymageMatrix.SUBTRACTIVE_RED : ymageMatrix.SUBTRACTIVE_GREEN);
hash = secondarySearches[j].target().hash;
angle = (int) ((long) 360 * (yacySeed.dhtPosition(hash) / (yacySeed.maxDHTDistance / (long) 10000)) / (long) 10000);
eventPicture.arcLine(cx, cy, cr - 10, cr, angle - 1);
Expand All @@ -104,8 +104,8 @@ public static ymagePainter getSearchEventPicture() {
// draw in the search target
plasmaSearchQuery query = plasmaSearchEvent.lastEvent.getQuery();
Iterator i = query.queryHashes.iterator();
eventPicture.setMode(ymageMatrix.MODE_ADD);
eventPicture.setColor(ymageMatrix.ADDITIVE_BLACK);
eventPicture.setMode(ymageMatrix.MODE_SUB);
eventPicture.setColor(ymageMatrix.SUBTRACTIVE_BLACK);
while (i.hasNext()) {
hash = (String) i.next();
angle = (int) ((long) 360 * (yacySeed.dhtPosition(hash) / (yacySeed.maxDHTDistance / (long) 10000)) / (long) 10000);
Expand All @@ -115,11 +115,11 @@ public static ymagePainter getSearchEventPicture() {
return eventPicture;
}

public static ymagePainter getNetworkPicture(long maxAge) {
public static ymageMatrix getNetworkPicture(long maxAge) {
return getNetworkPicture(maxAge, 640, 480, 300, 300, 1000, true);
}

public static ymagePainter getNetworkPicture(long maxAge, int width, int height, int passiveLimit, int potentialLimit, int maxCount, boolean corona) {
public static ymageMatrix getNetworkPicture(long maxAge, int width, int height, int passiveLimit, int potentialLimit, int maxCount, boolean corona) {
if ((networkPicture == null) || ((System.currentTimeMillis() - networkPictureDate) > maxAge)) {
drawNetworkPicture(width, height, passiveLimit, potentialLimit, maxCount, corona);
}
Expand All @@ -134,11 +134,11 @@ private static void drawNetworkPicture(int width, int height, int passiveLimit,

if (yacyCore.seedDB == null) return; // no other peers known

networkPicture = new ymageMatrixPainter(width, height, "000010");
networkPicture.setMode(ymageMatrix.MODE_ADD);
networkPicture = new ymageMatrix(width, height, "101010" /*"FFFFE0"*/);
networkPicture.setMode(ymageMatrix.MODE_SUB);

// draw network circle
networkPicture.setColor("008020");
networkPicture.setColor("A02080" /*"008020"*/);
networkPicture.arc(width / 2, height / 2, innerradius - 20, innerradius + 20, 0, 360);

//System.out.println("Seed Maximum distance is " + yacySeed.maxDHTDistance);
Expand All @@ -154,7 +154,7 @@ private static void drawNetworkPicture(int width, int height, int passiveLimit,
while (e.hasMoreElements() && count < maxCount) {
seed = (yacySeed) e.nextElement();
if (seed != null) {
drawNetworkPicturePeer(networkPicture, width / 2, height / 2, innerradius, outerradius, seed, "000040", "608860", "B0FFB0", corona);
drawNetworkPicturePeer(networkPicture, width / 2, height / 2, innerradius, outerradius, seed, "404000", "E8C0E8", "B0FFB0", corona);
count++;
}
}
Expand Down Expand Up @@ -182,27 +182,27 @@ private static void drawNetworkPicture(int width, int height, int passiveLimit,
if (seed != null) {
lastseen = Math.abs((System.currentTimeMillis() - seed.getLastSeenTime()) / 1000 / 60);
if (lastseen > potentialLimit) break; // we have enough, this list is sorted so we don't miss anything
drawNetworkPicturePeer(networkPicture, width / 2, height / 2, innerradius, outerradius, seed, "202000", "505000", "A0A000", corona);
drawNetworkPicturePeer(networkPicture, width / 2, height / 2, innerradius, outerradius, seed, "202040", "5050A0", "A0A0FF", corona);
count++;
}
}
totalCount += count;

// draw my own peer
drawNetworkPicturePeer(networkPicture, width / 2, height / 2, innerradius, outerradius, yacyCore.seedDB.mySeed, "800000", "AAAAAA", "FFFFFF", corona);
drawNetworkPicturePeer(networkPicture, width / 2, height / 2, innerradius, outerradius, yacyCore.seedDB.mySeed, "008080", "AAAAAA", "FFFFFF", corona);

// draw description
networkPicture.setColor("FFFFFF");
networkPicture.setMode(ymageMatrix.MODE_ADD);
networkPicture.print(2, 8, 0, "THE YACY NETWORK", true);
networkPicture.print(2, 16, 0, "DRAWING OF " + totalCount + " SELECTED PEERS", true);
networkPicture.print(width - 2, 8, 0, "SNAPSHOT FROM " + new Date().toString().toUpperCase(), false);
networkPicture.setColor(ymageMatrix.SUBTRACTIVE_BLACK);
networkPicture.setMode(ymageMatrix.MODE_SUB);
ymageToolPrint.print(networkPicture, 2, 8, 0, "THE YACY NETWORK", true);
ymageToolPrint.print(networkPicture, 2, 16, 0, "DRAWING OF " + totalCount + " SELECTED PEERS", true);
ymageToolPrint.print(networkPicture, width - 2, 8, 0, "SNAPSHOT FROM " + new Date().toString().toUpperCase(), false);

// set timestamp
networkPictureDate = System.currentTimeMillis();
}

private static void drawNetworkPicturePeer(ymagePainter img, int x, int y, int innerradius, int outerradius, yacySeed seed, String colorDot, String colorLine, String colorText, boolean corona) {
private static void drawNetworkPicturePeer(ymageMatrix img, int x, int y, int innerradius, int outerradius, yacySeed seed, String colorDot, String colorLine, String colorText, boolean corona) {
String name = seed.getName().toUpperCase();
if (name.length() < shortestName) shortestName = name.length();
if (name.length() > longestName) longestName = name.length();
Expand All @@ -212,7 +212,7 @@ private static void drawNetworkPicturePeer(ymagePainter img, int x, int y, int i
if (linelength > outerradius) linelength = outerradius;
int dotsize = 6 + 2 * (int) (seed.getLinkCount() / 500000L);
if (dotsize > 18) dotsize = 18;
img.setMode(ymageMatrix.MODE_ADD);
img.setMode(ymageMatrix.MODE_SUB);
// draw dot
img.setColor(colorDot);
img.arcDot(x, y, innerradius, angle, dotsize);
Expand All @@ -221,7 +221,7 @@ private static void drawNetworkPicturePeer(ymagePainter img, int x, int y, int i
img.arcLine(x, y, innerradius + 18, innerradius + linelength, angle);
// draw text
img.setColor(colorText);
img.arcPrint(x, y, innerradius + linelength, angle, name);
ymageToolPrint.arcPrint(img, x, y, innerradius + linelength, angle, name);

// draw corona around dot for crawling activity
int ppm10 = seed.getPPM() / 10;
Expand Down
12 changes: 6 additions & 6 deletions source/de/anomic/ymage/ymageChart.java
Expand Up @@ -41,7 +41,7 @@

package de.anomic.ymage;

public class ymageChart extends ymageMatrixPainter {
public class ymageChart extends ymageMatrix {

public static final int DIMENSION_RIGHT = 0;
public static final int DIMENSION_TOP = 1;
Expand All @@ -67,7 +67,7 @@ public ymageChart(int width, int height, String backgroundColor,
this.topborder = topborder;
this.bottomborder = bottomborder;
if (name != null) {
print(width / 2 - name.length() * 3, 6, 0, name, true);
ymageToolPrint.print(this, width / 2 - name.length() * 3, 6, 0, name, true);
}
}

Expand Down Expand Up @@ -111,12 +111,12 @@ private void drawHorizontalScale(boolean top, int scale, int pixelperscale, Stri
}
setColor(colorNaming);
line(x, y - 3, x, y + 3);
print(x, (top) ? y - 3 : y + 9, 0, Integer.toString(s), true);
ymageToolPrint.print(this, x, (top) ? y - 3 : y + 9, 0, Integer.toString(s), true);
x += pixelperscale;
s += scale;
}
setColor(colorNaming);
print(width - rightborder, (top) ? y - 9 : y + 15, 0, name, false);
ymageToolPrint.print(this, width - rightborder, (top) ? y - 9 : y + 15, 0, name, false);
line(leftborder - 4, y, width - rightborder + 4, y);
}

Expand All @@ -135,12 +135,12 @@ private void drawVerticalScale(boolean left, int scale, int pixelperscale, Strin
line(x - 3, y, x + 3, y);
s1 = Integer.toString(s);
if (s1.length() > s1max) s1max = s1.length();
print((left) ? leftborder - 4 : width - rightborder + 4, y, 0, s1, (!left));
ymageToolPrint.print(this, (left) ? leftborder - 4 : width - rightborder + 4, y, 0, s1, (!left));
y -= pixelperscale;
s += scale;
}
setColor(colorNaming);
print((left) ? x - s1max * 6 - 6 : x + s1max * 6 + 9, topborder, 90, name, false);
ymageToolPrint.print(this, (left) ? x - s1max * 6 - 6 : x + s1max * 6 + 9, topborder, 90, name, false);
line(x, topborder - 4, x, height - bottomborder + 4);
}

Expand Down

0 comments on commit 5515571

Please sign in to comment.