01: package gnu.kawa.swingviews;
02:
03: import java.awt.*;
04: import java.awt.geom.*;
05: import gnu.kawa.models.*;
06: import javax.swing.*;
07:
08: /** Embeds a Paintable object in a JPanel,. */
09:
10: public class SwingPaintable extends JPanel {
11: Paintable paintable;
12: Dimension dim;
13:
14: public SwingPaintable(Paintable paintable) {
15: this .paintable = paintable;
16:
17: Rectangle2D rect = paintable.getBounds2D();
18: int h = (int) Math.ceil(rect.getHeight());
19: int w = (int) Math.ceil(rect.getWidth());
20: dim = new Dimension(w, h);
21: }
22:
23: public void paint(Graphics g) {
24: // FIXME may need to transform position
25: paintable.paint((Graphics2D) g);
26: }
27:
28: public java.awt.Dimension getPreferredSize() {
29: return dim;
30: }
31: }
|