01: package org.zilonis.tool.ui;
02:
03: import java.awt.Graphics;
04: import java.awt.image.BufferedImage;
05:
06: import javax.swing.JPanel;
07:
08: public class SlidingTransition extends JPanel {
09:
10: private float fraction;
11:
12: private BufferedImage start;
13:
14: private BufferedImage end;
15:
16: private int direction;
17:
18: public SlidingTransition(JPanel startPanel, JPanel endPanel) {
19: int width = (int) startPanel.getSize().getWidth();
20: int height = (int) startPanel.getSize().getHeight();
21: start = new BufferedImage(width, height,
22: BufferedImage.TYPE_INT_RGB);
23: startPanel.paint(start.getGraphics());
24: end = new BufferedImage(width, height,
25: BufferedImage.TYPE_INT_RGB);
26: endPanel.setBounds(0, 0, width, height);
27: endPanel.paint(end.getGraphics());
28: }
29:
30: public void setFraction(int fraction) {
31: this .fraction = ((float) fraction) / 1000;
32: }
33:
34: @Override
35: public void paintComponent(Graphics g) {
36: int yCut = (int) (start.getHeight() * fraction);
37: if (yCut > 0) {
38: BufferedImage topImage = start.getSubimage(0, 0,
39: (int) start.getWidth(), yCut);
40: BufferedImage bottomImage = end.getSubimage(0, 0,
41: (int) start.getWidth(), (int) start.getHeight()
42: - yCut);
43: g.drawImage(topImage, 0, 0, (int) start.getWidth(), yCut,
44: null);
45: g.drawImage(bottomImage, 0, yCut, (int) start.getWidth(),
46: (int) start.getHeight() - yCut, null);
47: }
48: }
49:
50: }
|