/*
This file is part of JLoom
Copyright (C) 2006 Gereon Fassbender
Homepage: jloom.sourceforge.net
JLoom is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You can find a copy of the GNU General Public License along with this program
in a file called COPYING. Information can also be found at www.fsf.org or
www.gnu.org or write to the Free Software Foundation, Inc., 51 Franklin Street,
Fifth Floor, Boston, MA 02110-1301, USA
*/
/*
created: 09.03.2006 Gereon Fassbender
$Revision$
$Date$
$Log$
*/
package net.gereon.jloom.util;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Iterator;
import javax.imageio.*;
import javax.imageio.stream.ImageOutputStream;
public class JLoomLogo
{
private final static Color COLOR_BLUE = new Color( 70, 70, 255);
private final static Color COLOR_GREEN = new Color( 0, 180, 60);
//private final static Color COLOR_RED = new Color(200, 60, 60);
private final static int H_BLOCKS = 3;
private final static int V_BLOCKS = 3;
private static void drawRect(Graphics2D g, int xLeft, int yTop, int xRight, int yBottom,
Color color,
int blockSize, int boundSize)
{
assert xLeft >= 1;
assert yTop >= 1;
assert xLeft <= xRight;
assert yTop <= yBottom;
int x = xLeft * boundSize + (xLeft - 1) * blockSize;
int y = yTop * boundSize + (yTop - 1) * blockSize;
int width = (xRight - xLeft) * boundSize + (xRight - xLeft + 1) * blockSize;
int height = (yBottom - yTop) * boundSize + (yBottom - yTop + 1) * blockSize;
//System.out.println("width=" + width + " height=" + height);
g.setColor(color);
g.setBackground(color);
g.fillRect(x, y, width, height);
}
public static BufferedImage createImage(int blockSize, int boundSize)
{
int width = blockSize * H_BLOCKS + boundSize * (H_BLOCKS + 1);
int height = blockSize * V_BLOCKS + boundSize * (V_BLOCKS + 1);
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) img.getGraphics();
drawRect(g, 1, 1, 1, 1, COLOR_GREEN, blockSize, boundSize);
drawRect(g, 1, 3, 1, 3, COLOR_GREEN, blockSize, boundSize);
drawRect(g, 3, 1, 3, 2, COLOR_GREEN, blockSize, boundSize);
drawRect(g, 2, 1, 2, 1, COLOR_BLUE, blockSize, boundSize);
drawRect(g, 1, 2, 2, 2, COLOR_BLUE, blockSize, boundSize);
drawRect(g, 2, 3, 3, 3, COLOR_BLUE, blockSize, boundSize);
return img;
}
public static BufferedImage createImage(int sizeFactor)
{
return createImage(sizeFactor * 6, sizeFactor);
}
public static void saveImage(BufferedImage image, String path) throws IOException
{
ImageOutputStream out = null;
try {
Iterator writers = ImageIO.getImageWritersByFormatName("png");
ImageWriter writer = (ImageWriter) writers.next();
File f = new File(path);
out = ImageIO.createImageOutputStream(f);
writer.setOutput(out);
writer.write(image);
}
finally {
if (out != null) { out.close(); }
}
}
/**
* Creates a set of logo images and saves them in "images/".
*/
public static void main(String[] args) throws Exception
{
String prefix = "images/jloom_";
for (int i=1; i<=9; i++) {
BufferedImage img = createImage(i);
saveImage(img, prefix + i + ".png");
}
BufferedImage img = createImage(4, 1);
saveImage(img, prefix + "mini.png");
img = createImage(3, 1);
saveImage(img, prefix + "milli.png");
img = createImage(2, 1);
saveImage(img, prefix + "micro.png");
img = createImage(3, 0);
saveImage(img, prefix + "nano.png");
img = createImage(2, 0);
saveImage(img, prefix + "pico.png");
img = createImage(15);
saveImage(img, prefix + "l.png");
img = createImage(20);
saveImage(img, prefix + "xl.png");
img = createImage(30);
saveImage(img, prefix + "xxl.png");
new ImageViewer("JLoom Logo").setImage(img);
}
}