import java.applet.Applet;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
public class WallViewer {
static final int BEZEL = 10;
static int rows, cols;
static double scale;
// Adjustable parameters to center and align preview grid...
final private static int EDGING = 30;
final private static float WALL_SCALE = 0.85f;
public static void main(String args[]) {
String name;
name = args[0];
if (args.length == 1) {
rows = 4;
cols = 4;
scale = WALL_SCALE / Math.max(rows, cols);
for (int row = 1; row <= rows; row++)
for (int col = 1; col <= cols; col++) {
Applet applet = createInstance(name, row, col);
makeFrameForApplet(applet, row, col, scale);
}
} else {
rows = Integer.valueOf(args[1]);
cols = Integer.valueOf(args[2]);
int row = Integer.valueOf(args[3]);
int col = Integer.valueOf(args[4]);
if (args.length == 6)
scale = Float.valueOf(args[5]);
else
scale = 1.0f;
Applet applet = createInstance(name, row, col);
makeFrameForApplet(applet, row, col, scale);
}
}
@SuppressWarnings("rawtypes")
static Applet createInstance(String name, int row, int col) {
Class appletClass = null;
WallApplet wallApplet = null;
try {
appletClass = Class.forName(name);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
wallApplet = (WallApplet) appletClass.newInstance();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wallApplet.setRowCol(rows, cols, row, col, scale);
return (Applet) wallApplet;
}
static int getX(int col) {
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int width = (int) (d.width * scale);
int x = (col - 1) * (BEZEL + width);
return x + (scale < 1.0f ? EDGING : 0);
}
static int getY(int row) {
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int height = (int) (d.height * scale);
int y = (row - 1) * (BEZEL + height);
return y + (scale < 1.0f ? EDGING : 0);
}
static void makeFrameForApplet(Applet applet, int row, int col, double scale) {
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int height = (int) (d.height * scale);
int width = (int) (d.width * scale);
Frame frame = new Frame();
frame.add(applet);
frame.setUndecorated(true);
int x = getX(col);
int y = getY(row);
if (scale == 1.0f)
frame.setBounds(0, 0, d.width, d.height);
else
frame.setBounds(x, y, width, height);
// frame.pack();
frame.setVisible(true);
applet.init();
System.out.printf("row = %d, col = %d\n", row, col);
System.out.printf("x = %d, y = %d, width = %d, height = %d\n", x, y, width, height);
}
}