Пример #1
0
 /**
  * Draws the axes in the drawing panel.
  *
  * @param panel
  * @param g
  */
 public void draw(DrawingPanel panel, Graphics g) {
   if (!visible) {
     return;
   }
   if (interiorColor != null) {
     g.setColor(interiorColor);
     int gw = panel.getLeftGutter() + panel.getRightGutter();
     int gh = panel.getTopGutter() + panel.getBottomGutter();
     g.fillRect(
         panel.getLeftGutter(),
         panel.getTopGutter(),
         panel.getWidth() - gw,
         panel.getHeight() - gh);
     g.setColor(Color.lightGray);
     g.drawRect(
         panel.getLeftGutter(),
         panel.getTopGutter(),
         panel.getWidth() - gw,
         panel.getHeight() - gh);
   }
   xaxis.draw(panel, g);
   yaxis.draw(panel, g);
   titleLine.setX((panel.getXMax() + panel.getXMin()) / 2);
   if (panel.getTopGutter() > 20) {
     titleLine.setY(panel.getYMax() + 5 / panel.getYPixPerUnit());
   } else {
     titleLine.setY(panel.getYMax() - 25 / panel.getYPixPerUnit());
   }
   titleLine.draw(panel, g);
 }
Пример #2
0
 /**
  * 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));
 }
  public static void main(String[] args) {
    DrawingPanel drawing = new DrawingPanel(200, 200);
    Graphics canvas = drawing.getGraphics();

    canvas.setColor(Colors.black);
    canvas.fillRect(0, 0, drawing.getWidth(), drawing.getHeight());

    canvas.setColor(Colors.white);

    for (int i = 5; i > 0; i--) {
      canvas.fillRect(i * 20, (5 - i) * 20, 20, 20);
    }
  }