Skip to content

Commit

Permalink
*) Banner features a logo now. It does not look nice, but at least it…
Browse files Browse the repository at this point in the history
… works. Banner is not finished yet.

Which path do I have to set for IMAGE (htroot/env/grafics/yacy.gi) if I want to load it through the file system and not via HTTP?


git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4244 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
low012 committed Dec 2, 2007
1 parent 39d0f10 commit 72698fc
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 13 deletions.
41 changes: 31 additions & 10 deletions htroot/Banner.java
Expand Up @@ -46,17 +46,29 @@

import de.anomic.http.httpHeader;
import de.anomic.plasma.plasmaGrafics;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverCore;
import de.anomic.server.serverDomains;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.ymage.ymageMatrix;
import de.anomic.yacy.yacyCore;
import de.anomic.yacy.yacySeed;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;

/** draw a banner with information about the peer */
public class Banner {

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

final String IMAGE = "env/grafics/yacy.gif";
int width = 468;
int height = 60;
String bgcolor = plasmaGrafics.COL_BACKGROUND;
Expand Down Expand Up @@ -84,16 +96,16 @@ public static ymageMatrix respond(httpHeader header, serverObjects post, serverS

yacySeed seed = yacyCore.seedDB.mySeed();
if (seed != null){
name = seed.get(yacySeed.NAME, "-").toUpperCase();
links = Long.parseLong(seed.get(yacySeed.LCOUNT, "0"));
words = Long.parseLong(seed.get(yacySeed.ICOUNT, "0"));
myppm = seed.getPPM();
myqph = 60d * seed.getQPM();
name = seed.get(yacySeed.NAME, "-").toUpperCase();
links = Long.parseLong(seed.get(yacySeed.LCOUNT, "0"));
words = Long.parseLong(seed.get(yacySeed.ICOUNT, "0"));
myppm = seed.getPPM();
myqph = 60d * seed.getQPM();
network = env.getConfig("network.unit.name", "unspecified").toUpperCase();
nlinks = yacyCore.seedDB.countActiveURL();
nwords = yacyCore.seedDB.countActiveRWI();
nqpm = yacyCore.seedDB.countActiveQPM();
nppm = yacyCore.seedDB.countActivePPM();
nlinks = yacyCore.seedDB.countActiveURL();
nwords = yacyCore.seedDB.countActiveRWI();
nqpm = yacyCore.seedDB.countActiveQPM();
nppm = yacyCore.seedDB.countActivePPM();

if (yacyCore.seedDB.mySeed().isVirgin()) {
type = "VIRGIN";
Expand All @@ -116,6 +128,15 @@ public static ymageMatrix respond(httpHeader header, serverObjects post, serverS
}
}

if (!plasmaGrafics.logoIsLoaded()) {
plasmaSwitchboard switchboard = (plasmaSwitchboard)env;
int port = serverCore.getPortNr(switchboard.getConfig("port", "8080"));
String host = serverDomains.myPublicLocalIP().getHostAddress();
BufferedImage logo = ImageIO.read(new URL("http://"+host+":"+port+"/"+IMAGE));
//BufferedImage logo = ImageIO.read(new File(IMAGE));
return plasmaGrafics.getBannerPicture(1000, width, height, bgcolor, textcolor, bordercolor, name, links, words, type, myppm, network, nlinks, nwords, nqph, nppm, logo);
}

return plasmaGrafics.getBannerPicture(1000, width, height, bgcolor, textcolor, bordercolor, name, links, words, type, myppm, network, nlinks, nwords, nqph, nppm);
}

Expand Down
29 changes: 26 additions & 3 deletions source/de/anomic/plasma/plasmaGrafics.java
Expand Up @@ -49,6 +49,7 @@

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.util.Date;
Expand Down Expand Up @@ -122,6 +123,7 @@ public void setFraction(long totalBusyTime) {
private static long peerloadPictureDate = 0;

private static ymageMatrix bannerPicture = null; // [MN]
private static BufferedImage logo = null; // [MN]
private static long bannerPictureDate = 0; // [MN]

public static ymageMatrix getSearchEventPicture(String eventID) {
Expand Down Expand Up @@ -363,16 +365,26 @@ private static void drawLegendLine(Graphics2D g, int x, int y, String caption, C
//[MN]
public static ymageMatrix getBannerPicture(long maxAge, int width, int height, String bgcolor, String textcolor, String bordercolor, String name, long links, long words, String type, int ppm, String network, long nlinks, long nwords, double nqph, long nppm) {
if ((bannerPicture == null) || ((System.currentTimeMillis() - bannerPictureDate) > maxAge)) {
drawBannerPicture(width, height, bgcolor, textcolor, bordercolor, name, links, words, type, ppm, network, nlinks, nwords, nqph, nppm);
drawBannerPicture(width, height, bgcolor, textcolor, bordercolor, name, links, words, type, ppm, network, nlinks, nwords, nqph, nppm, logo);
}
return bannerPicture;
}

//[MN]
public static ymageMatrix getBannerPicture(long maxAge, int width, int height, String bgcolor, String textcolor, String bordercolor, String name, long links, long words, String type, int ppm, String network, long nlinks, long nwords, double nqph, long nppm, BufferedImage newLogo) {
if ((bannerPicture == null) || ((System.currentTimeMillis() - bannerPictureDate) > maxAge)) {
drawBannerPicture(width, height, bgcolor, textcolor, bordercolor, name, links, words, type, ppm, network, nlinks, nwords, nqph, nppm, newLogo);
}
return bannerPicture;
}

//[MN]
private static void drawBannerPicture(int width, int height, String bgcolor, String textcolor, String bordercolor, String name, long links, long words, String type, int ppm, String network, long nlinks, long nwords, double nqph, long nppm) {
private static void drawBannerPicture(int width, int height, String bgcolor, String textcolor, String bordercolor, String name, long links, long words, String type, int ppm, String network, long nlinks, long nwords, double nqph, long nppm, BufferedImage newLogo) {

int exprlength = 19;

logo = newLogo;

bannerPicture = new ymageMatrix(width, height, bgcolor);
bannerPicture.setMode(ymageMatrix.MODE_SUB);

Expand All @@ -390,17 +402,28 @@ private static void drawBannerPicture(int width, int height, String bgcolor, Str
ymageToolPrint.print(bannerPicture, 285, 42, 0, "QUERIES: " + addTrailingBlanks(nqph + " QUERIES/HOUR", exprlength), -1);
ymageToolPrint.print(bannerPicture, 285, 52, 0, "SPEED: " + addTrailingBlanks(nppm + " PAGES/MINUTE", exprlength), -1);

if (logo != null) {
bannerPicture.insertBitmap(logo, 2, 2);
}

if (!bordercolor.equals("")) {
bannerPicture.setColor(bordercolor);
bannerPicture.line(0,0,0,height-1);
bannerPicture.line(0,0,width-1,0);
bannerPicture.line(width-1,0,width-1,height-1);
bannerPicture.line(0,height-1,width-1,height-1);
}

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

public static boolean logoIsLoaded() {
if (logo == null) {
return false;
}
return true;
}

//[MN]
/* quoted method because it is not used anywhere (and creates a warning in eclipse)
Expand Down
21 changes: 21 additions & 0 deletions source/de/anomic/ymage/ymageMatrix.java
Expand Up @@ -265,6 +265,27 @@ public void arcArc(int cx, int cy, int arcRadius, int angle, int innerRadius, in
arc(x, y, innerRadius, outerRadius, fromArc, toArc);
}

/**
* inserts an image into the ymageMatrix
* @param bitmap the bitmap to be inserted
* @param x the x value of the upper left coordinate in the ymageMatrix where the bitmap will be placed
* @param y the y value of the upper left coordinate in the ymageMatrix where the bitmap will be placed
*
* @author Marc Nause
*/
public void insertBitmap(BufferedImage bitmap, int x, int y) {
int heightSrc = bitmap.getHeight();
int widthSrc = bitmap.getWidth();
int heightTgt = image.getHeight();
int widthTgt = image.getWidth();

for (int i = y; i < heightSrc && i < heightTgt - y; i++) {
for (int j = x; j < widthSrc && j < widthTgt - x; j++) {
image.setRGB(j, i, bitmap.getRGB(j, i));
}
}
}

public static void demoPaint(ymageMatrix m) {
m.setMode(MODE_SUB);
m.setColor(SUBTRACTIVE_CYAN);
Expand Down

0 comments on commit 72698fc

Please sign in to comment.