/** * Draws the image and the grid. * * @param panel * @param g */ public void draw(DrawingPanel panel, Graphics g) { if (scaleFactor < 1) { g.drawImage( image.getScaledInstance( (int) (scaleFactor * image.getWidth()), (int) (scaleFactor * image.getHeight()), java.awt.Image.SCALE_REPLICATE), panel.getLeftGutter(), panel.getTopGutter(), panel); } else { // g.drawImage(image, 1+panel.xToPix(xmin), 1+panel.yToPix(ymax), panel); g.drawImage(image, panel.getLeftGutter(), panel.getTopGutter(), panel); } }
/** * Gets the dimension of the lattice in pixel units. * * @param panel * @return the dimension */ public Dimension getInterior(DrawingPanel panel) { float availableWidth = panel.getWidth() - panel.getLeftGutter() - panel.getRightGutter() - 1; float availableHeight = panel.getHeight() - panel.getTopGutter() - panel.getBottomGutter() - 1; scaleFactor = Math.min(availableWidth / dimension.width, availableHeight / dimension.height); if (scaleFactor > 1) { scaleFactor = 1; return dimension; } return new Dimension((int) (scaleFactor * ncol), (int) (scaleFactor * nrow)); }