// Lastly drop the canvas in the frame.
if (_canvas != null) {
_container.remove(_canvas);
}
GraphicsPane pane = new GraphicsPane();
_layer = pane.getForegroundLayer();
_overlayLayer = new OverlayLayer();
_canvas = new JCanvas(pane);
_container.add("Center", _canvas);
_canvas.setMinimumSize(new Dimension(horizontalDimension,
verticalDimension));
_canvas.setMaximumSize(new Dimension(horizontalDimension,
verticalDimension));
_canvas.setPreferredSize(new Dimension(horizontalDimension,
verticalDimension));
if (_frame != null) {
_frame.pack();
}
double upperLeftXValue = ((IntToken) upperLeftX.getToken())
.doubleValue();
double upperLeftYValue = ((IntToken) upperLeftY.getToken())
.doubleValue();
double lowerRightXValue = ((IntToken) lowerRightX.getToken())
.doubleValue();
double lowerRightYValue = ((IntToken) lowerRightY.getToken())
.doubleValue();
java.awt.geom.Rectangle2D visibleRect = new java.awt.geom.Rectangle2D.Double(
upperLeftXValue, upperLeftYValue, lowerRightXValue
- upperLeftXValue, lowerRightYValue - upperLeftYValue);
if ((visibleRect.getHeight() == 0) || (visibleRect.getWidth() == 0)) {
throw new IllegalActionException(this, "The width and height "
+ "of the visible rectangle cannot be zero.");
}
AffineTransform transform = CanvasUtilities.computeTransform(
visibleRect, _canvas.getBounds());
System.out.println("transform = " + transform);
// _origin = new Point2D.Double(
// _container.getWidth()/2, _container.getHeight()/2);
// pane.translate(_origin.x, _origin.y);
pane.setTransform(transform);
pane.setAntialiasing(true);
_crosshairX = new BasicFigure(new java.awt.geom.Line2D.Double(0, 2, 0,
-2));
_crosshairY = new BasicFigure(new java.awt.geom.Line2D.Double(2, 0, -2,
0));
_overlayLayer.add(_crosshairX.getShape());
_overlayLayer.add(_crosshairY.getShape());
_eventHandler = new ViewScreen2DListener();
_eventLayer = new EventLayer();
_eventLayer.addLayerListener(_eventHandler);
_eventLayer.addLayerMotionListener(_eventHandler);
pane.setOverlayLayer(_overlayLayer);
pane.setForegroundEventLayer(_eventLayer);
if (_frame != null) {
_frame.addKeyListener(_eventHandler);
}