Methods Summary |
---|
protected java.awt.Checkbox | createCheckbox(java.lang.String label, int item)
Checkbox check = new Checkbox(label);
check.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ie) {
setSwitch(item, (ie.getStateChange() == ie.SELECTED));
}
});
return check;
|
public static void | main(java.lang.String[] args)
String filename = "knudsen.gif";
if (args.length > 0) filename = args[0];
Image image = Utilities.blockingLoad(filename);
final ImageBouncer bouncer = new ImageBouncer(image);
Frame f = new AnimationFrame(bouncer);
f.setFont(new Font("Serif", Font.PLAIN, 12));
Panel controls = new Panel();
controls.add(bouncer.createCheckbox("Bilinear", ImageBouncer.BILINEAR));
controls.add(bouncer.createCheckbox("Transform",ImageBouncer.TRANSFORM));
final Choice typeChoice = new Choice();
typeChoice.add("TYPE_INT_RGB");
typeChoice.add("TYPE_INT_ARGB");
typeChoice.add("TYPE_INT_ARGB_PRE");
typeChoice.add("TYPE_3BYTE_BGR");
typeChoice.add("TYPE_BYTE_GRAY");
typeChoice.add("TYPE_USHORT_GRAY");
typeChoice.add("TYPE_USHORT_555_RGB");
typeChoice.add("TYPE_USHORT_565_RGB");
controls.add(typeChoice);
f.add(controls, BorderLayout.NORTH);
typeChoice.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ie) {
String type = typeChoice.getSelectedItem();
bouncer.setImageType(type);
}
});
f.setVisible(true);
|
public void | paint(java.awt.Graphics g)
Graphics2D g2 = (Graphics2D)g;
setTransform(g2);
setBilinear(g2);
// Draw the image.
g2.drawImage(mImage, AffineTransform.getTranslateInstance(mX, mY), null);
|
protected void | setBilinear(java.awt.Graphics2D g2)
if (mBilinear == false) return;
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
public void | setImageType(java.lang.String s)
int type = BufferedImage.TYPE_CUSTOM;
if (s.equals("TYPE_INT_RGB"))
type = BufferedImage.TYPE_INT_RGB;
else if (s.equals("TYPE_INT_ARGB"))
type = BufferedImage.TYPE_INT_ARGB;
else if (s.equals("TYPE_INT_ARGB_PRE"))
type = BufferedImage.TYPE_INT_ARGB_PRE;
else if (s.equals("TYPE_3BYTE_BGR"))
type = BufferedImage.TYPE_3BYTE_BGR;
else if (s.equals("TYPE_BYTE_GRAY"))
type = BufferedImage.TYPE_BYTE_GRAY;
else if (s.equals("TYPE_USHORT_GRAY"))
type = BufferedImage.TYPE_USHORT_GRAY;
else if (s.equals("TYPE_USHORT_555_RGB"))
type = BufferedImage.TYPE_USHORT_565_RGB;
else if (s.equals("TYPE_USHORT_565_RGB"))
type = BufferedImage.TYPE_USHORT_565_RGB;
else {
System.out.println("Unrecognized type.");
return;
}
mImage = Utilities.makeBufferedImage(mOriginalImage, type);
|
public void | setSwitch(int item, boolean value)
switch(item) {
case BILINEAR: mBilinear = value; break;
case TRANSFORM: mTransform = value; break;
default: break;
}
|
protected void | setTransform(java.awt.Graphics2D g2)
if (mTransform == false) return;
float cx = mX + mWidth / 2;
float cy = mY + mHeight / 2;
g2.rotate(mTheta, cx, cy);
|
public void | timeStep()
Dimension d = getSize();
if (mX + mDeltaX < 0) mDeltaX = -mDeltaX;
else if (mX + mWidth + mDeltaX >= d.width) mDeltaX = -mDeltaX;
if (mY + mDeltaY < 0) mDeltaY = -mDeltaY;
else if (mY + mHeight + mDeltaY >= d.height) mDeltaY = -mDeltaY;
mX += mDeltaX;
mY += mDeltaY;
mTheta += Math.PI / 192;
if (mTheta > (2 * Math.PI)) mTheta -= (2 * Math.PI);
|