Font font = new Font("Dialog", Font.PLAIN, 12);
// create a rectangle with lable and rotate it
Rectangle2D.Double r1 = new Rectangle2D.Double(30., 30., 30., 40.);
CanvasFigure fig = g.makeLabeledRectangle(r1, CoordinateConverter.USER, null, Color.blue, 2.0F,
"Test1", SwingConstants.CENTER, Color.blue, font, si);
// rotate the rectangle by 30 degrees
fig.transform(AffineTransform.getRotateInstance(Math.toRadians(30.), 25, 25));
g.add(fig);
// create another labeled rectangle. This one using the fixed selection interactor
Rectangle2D.Double r2 = new Rectangle2D.Double(70., 70., 50., 50.);
g.add(g.makeLabeledRectangle(r2, CoordinateConverter.USER, null, Color.white, 2.0F,
"Test2", SwingConstants.CENTER, Color.blue, font, fsi));
// create a rotatable, nonresizable ellipse
Ellipse2D.Double e1 = new Ellipse2D.Double(150., 150., 50., 50.);
RotatableCanvasFigure imageFig = g.makeEllipse(e1, CoordinateConverter.USER, Color.red, Color.white, 2.0F, rsi);
imageFig.setResizable(false);
g.add(imageFig);
// create a nonrotatable rectangle
Rectangle2D.Double r4 = new Rectangle2D.Double(120., 180., 20., 60.);
g.add(g.makeRectangle(r4, CoordinateConverter.USER, Color.green, Color.yellow, 2.0F, si));
// create a nonrotatable ellipse
Ellipse2D.Double e3 = new Ellipse2D.Double(20., 220., 50., 20.);
g.add(g.makeEllipse(e3, CoordinateConverter.USER, null, Color.white, 2.0F, si));
// this ellipse can only be dragged
Ellipse2D.Double e4 = new Ellipse2D.Double(55., 200., 10., 40.);
g.add(g.makeEllipse(e4, CoordinateConverter.USER, Color.white, Color.yellow, 2.0F, di));
// create a test label with no interactor
Point2D.Double pos = new Point2D.Double(10., 150.);
g.add(g.makeLabel(pos, "Test Label", Color.yellow, font));
// test figure listener to demonstrate event handling
CanvasFigureListener listener = new CanvasFigureListener() {
public void figureSelected(CanvasFigureEvent e) {
System.out.println("Figure selected");
}
public void figureDeselected(CanvasFigureEvent e) {
System.out.println("Figure deselected");
}
public void figureResized(CanvasFigureEvent e) {
System.out.println("Figure resized: " + e.getFigure().getShape());
}
public void figureMoved(CanvasFigureEvent e) {
System.out.println("Figure moved: " + e.getFigure().getShape());
}
public void figureRotated(CanvasFigureEvent e) {
RotatableCanvasFigure rfig = (RotatableCanvasFigure)e.getFigure();
System.out.println("Figure rotated: " + Math.toDegrees(rfig.getGeometry().getRotateAngle()) + " deg");
}
};
// create a rotatable figure group (call setResizable(false) to disable resizing)
Rectangle2D.Double r3 = new Rectangle2D.Double(150., 100., 60., 40.);
CanvasFigure f1 = g.makeRectangle(r3, CoordinateConverter.USER, null, Color.yellow, 2.0F, null);
Ellipse2D.Double e5 = new Ellipse2D.Double(150., 100., 60., 40.);
CanvasFigure f2 = g.makeEllipse(e5, CoordinateConverter.USER, null, Color.yellow, 2.0F, null);
pos = new Point2D.Double(r3.x + 10, r3.y + 25);
CanvasFigure f3 = g.makeLabel(pos, CoordinateConverter.USER, "Group", Color.yellow, new JLabel().getFont(), null);
CanvasFigureGroup group = g.makeFigureGroup(rsi);
// group.setResizable(false);
// rotate the group by -25 deg
group.transform(AffineTransform.getRotateInstance(Math.toRadians(-25.), 25, 25));
group.add(f1);