diff --git a/source/net/yacy/search/Switchboard.java b/source/net/yacy/search/Switchboard.java index 566ba979b..2fe0affdf 100644 --- a/source/net/yacy/search/Switchboard.java +++ b/source/net/yacy/search/Switchboard.java @@ -2885,8 +2885,8 @@ public final class Switchboard extends serverSwitch { while (t-- > 0 && this.index.exists(ids).size() > 0) { try {Thread.sleep(100);} catch (final InterruptedException e) {} ConcurrentLog.fine("Switchboard", "STACKURL: waiting for deletion, t=" + t); - if (t == 20) this.index.fulltext().commit(true); - if (t == 40) this.index.fulltext().commit(false); + //if (t == 20) this.index.fulltext().commit(true); + if (t == 1) this.index.fulltext().commit(false); } // special handling of ftp protocol diff --git a/source/net/yacy/visualization/AnimationPlotter.java b/source/net/yacy/visualization/AnimationPlotter.java new file mode 100644 index 000000000..4cf21c023 --- /dev/null +++ b/source/net/yacy/visualization/AnimationPlotter.java @@ -0,0 +1,97 @@ +/** + * AnimationPlotter + * Copyright 2013 by Michael Christen + * First released 9.9.2010 at http://yacy.net + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * 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, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program in the file lgpl21.txt + * If not, see . + */ + +package net.yacy.visualization; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.imageio.ImageIO; +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; + +public class AnimationPlotter { + + public static class Frame { + BufferedImage image; + int delayMillis; + public Frame(BufferedImage image, int delayMillis) { + this.image = image; + this.delayMillis = delayMillis; + } + } + + private final List frames; + + + public AnimationPlotter() { + this.frames = new ArrayList(); + } + + public void addFrame(final BufferedImage image, final int delayMillis) { + this.frames.add(new Frame(image, delayMillis)); + } + + + public void save(final File path, final String filestub, final String type) throws IOException { + assert path.isDirectory(); + for (int i = 0; i < this.frames.size(); i++) { + Frame frame = this.frames.get(i); + File file = new File(path, filestub + "_" + intformat(i) + '.' + type); + final FileOutputStream fos = new FileOutputStream(file); + ImageIO.write(frame.image, type, fos); + fos.close(); + } + } + + private String intformat(final int i) { + String n = Integer.toString(i); + while (n.length() < 6) n = '0' + n; + return n; + } + + /** + * show the images as stream of JFrame on desktop + */ + public void show() { + JFrame f = new JFrame(); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.setVisible(true); + JLabel label = null; + while (true) { + for (int i = 0; i < this.frames.size(); i++) { + Frame frame = this.frames.get(i); + if (label == null) { + label = new JLabel(new ImageIcon(frame.image)); + f.getContentPane().add(label); + f.pack(); + } else { + label.getGraphics().drawImage(frame.image,0,0, label); + } + try {Thread.sleep(frame.delayMillis);} catch (InterruptedException e) {} + } + } + } +} diff --git a/source/net/yacy/visualization/HexGridPlotter.java b/source/net/yacy/visualization/HexGridPlotter.java index 274c34b21..cc808708b 100644 --- a/source/net/yacy/visualization/HexGridPlotter.java +++ b/source/net/yacy/visualization/HexGridPlotter.java @@ -25,10 +25,8 @@ package net.yacy.visualization; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; - -import javax.imageio.ImageIO; +import net.yacy.cora.util.ConcurrentLog; /* * hexagonal grid plotter @@ -151,23 +149,21 @@ public class HexGridPlotter extends RasterPlotter { } } - public static void main(final String[] args) { - // go into headless awt mode - System.setProperty("java.awt.headless", "true"); - - final HexGridPlotter picture = new HexGridPlotter(640, 480, DrawMode.MODE_SUB, "FFFFFF", 18); - picture.drawGrid("555555"); - picture.setColor(Long.parseLong("33ff33", 16)); + private static HexGridPlotter testImage0(int width, int height, String bgcolor, String gridcolor, String dotcolor) { + final HexGridPlotter picture = new HexGridPlotter(width, height, bgcolor.equals("000000") ? DrawMode.MODE_ADD : DrawMode.MODE_SUB, bgcolor, 18); + picture.drawGrid(gridcolor); + long dotcolori = Long.parseLong(dotcolor, 16); + picture.setColor(dotcolori); picture.gridDot(0, 0, 5, true, 100); picture.gridPrint(0, 0, 5, "", "0,0", -1); for (int i = 1; i < picture.gridHeight() -1; i++) { - picture.setColor(Long.parseLong("33ff33", 16));picture.gridDot(0, i, 3, true, 100); - picture.setColor(Long.parseLong("334433", 16));picture.gridPrint(0, i, 3, "", "0," + i, -1); + picture.setColor(dotcolori);picture.gridDot(0, i, 3, true, 100); + picture.setColor(dotcolori);picture.gridPrint(0, i, 3, "", "0," + i, -1); } for (int i = 1; i < picture.gridWidth() -1; i++) { - picture.setColor(Long.parseLong("33ff33", 16));picture.gridDot(i, 0, 3, true, 100); - picture.setColor(Long.parseLong("334433", 16));picture.gridPrint315(i, 0, 3, i + ",0"); + picture.setColor(dotcolori);picture.gridDot(i, 0, 3, true, 100); + picture.setColor(dotcolori);picture.gridPrint315(i, 0, 3, i + ",0"); } - picture.setColor(Long.parseLong("33ff33", 16)); + picture.setColor(dotcolori); picture.gridDot(0, picture.gheight - 1, 5, true, 100); picture.gridPrint(0, picture.gheight - 1, 5, "0, grid.gheight - 1", "", -1); picture.gridDot(picture.gwidth - 1, 0, 5, true, 100); picture.gridPrint(picture.gwidth - 1, 0, 5, "", "grid.gwidth - 1, 0", -1); picture.gridDot(picture.gwidth - 1, picture.gheight - 1, 5, true, 100); picture.gridPrint(picture.gwidth - 1, picture.gheight - 1, 5, "grid.gwidth - 1, grid.gheight - 1", "", 1); @@ -191,13 +187,23 @@ public class HexGridPlotter extends RasterPlotter { picture.gridPrint(picture.gwidth / 2, picture.gheight / 2, 5, "HOME PEER", "ANON_23", 0); //grid.gridLine(grid.gwidth - 2, grid.gheight - 2, grid.gwidth / 2, grid.gheight / 2); picture.gridLine(picture.gwidth / 2, picture.gheight / 2, picture.gwidth - 1, picture.gheight - 4); + return picture; + } + + public static void main(final String[] args) { + // go into headless awt mode + //System.setProperty("java.awt.headless", "true"); + AnimationPlotter animation = new AnimationPlotter(); + for (int i = 640; i < 700; i++) { + animation.addFrame(testImage0(i, 480, "000000", "555555", "33ff33").getImage(), 10); + } + animation.show(); + HexGridPlotter picture = testImage0(640, 480, "FFFFFF", "555555", "33ff33"); final File file = new File("/Users/admin/Desktop/testimage.png"); - try { - final FileOutputStream fos = new FileOutputStream(file); - ImageIO.write(picture.getImage(), "png", fos); - fos.close(); - } catch (final IOException e) {} + try {picture.save(file, "png");} catch (final IOException e) {} + ConcurrentLog.shutdown(); + if (!System.getProperty("java.awt.headless", "false").equals("true")) picture.show(); } } diff --git a/source/net/yacy/visualization/RasterPlotter.java b/source/net/yacy/visualization/RasterPlotter.java index e4689d6f7..106f86c06 100644 --- a/source/net/yacy/visualization/RasterPlotter.java +++ b/source/net/yacy/visualization/RasterPlotter.java @@ -54,6 +54,9 @@ import java.util.zip.Deflater; import java.util.zip.DeflaterOutputStream; import javax.imageio.ImageIO; +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; import net.yacy.cora.util.ByteBuffer; import net.yacy.cora.util.ConcurrentLog; @@ -92,7 +95,11 @@ public class RasterPlotter { private DrawMode defaultMode; private byte[] frame; - public RasterPlotter(final int width, final int height, final long backgroundColor) { + public RasterPlotter(final int width, final int height, final DrawMode drawMode, final String backgroundColor) { + this(width, height, drawMode, Long.parseLong(backgroundColor, 16)); + } + + public RasterPlotter(final int width, final int height, final DrawMode drawMode, final long backgroundColor) { this.cc = new int[3]; this.width = width; this.height = height; @@ -100,14 +107,6 @@ public class RasterPlotter { this.defaultColR = 0xFF; this.defaultColG = 0xFF; this.defaultColB = 0xFF; - } - - public RasterPlotter(final int width, final int height, final DrawMode drawMode, final String backgroundColor) { - this(width, height, drawMode, Long.parseLong(backgroundColor, 16)); - } - - public RasterPlotter(final int width, final int height, final DrawMode drawMode, final long backgroundColor) { - this(width, height, backgroundColor); this.defaultMode = drawMode; try { // we need our own frame buffer to get a very, very fast transformation to png because we can omit the PixedGrabber, which is up to 800 times slower @@ -941,6 +940,30 @@ public class RasterPlotter { } } + /** + * save the image to a file + * @param file the storage file + * @param type the file type, may be i.e. 'png' or 'gif' + * @throws IOException + */ + public void save(File file, String type) throws IOException { + final FileOutputStream fos = new FileOutputStream(file); + ImageIO.write(this.image, type, fos); + fos.close(); + } + + /** + * show the image as JFrame on desktop + */ + public void show() { + JLabel label = new JLabel(new ImageIcon(this.image)); + JFrame f = new JFrame(); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.getContentPane().add(label); + f.pack(); + f.setVisible(true); + } + /* * The following code was transformed from a library, coded by J. David Eisenberg, version 1.5, 19 Oct 2003 (C) LGPL * This code was very strongly transformed into the following very short method for an ultra-fast png generation.