Example #1
0
 public void repaint() {
   if (frame == null) return;
   Dimension dim = component.getPreferredSize();
   if (dim.getWidth() > component.getWidth() || dim.getHeight() > component.getHeight()) {
     frame.pack();
   } else {
     frame.repaint();
   }
 }
 public void draw(int initialOffset, Graphics g) {
   int offset = initialOffset;
   for (int i = 0; i < this.components.size(); i++) {
     CanvasComponent c = (CanvasComponent) components.elementAt(i);
     c.draw(offset, g);
     offset = c.getDescent();
     g.setColor(Graphics.getColorOfName(Graphics.SILVER));
   }
   this.descent = offset;
   this.height = this.descent - initialOffset;
 }
Example #3
0
 /**
  * Return the transform context of the figure. This default implementation assumes that the figure
  * does not implement a transform context, so just calls the same method on its parent. If it has
  * no parent, return null.
  */
 public TransformContext getTransformContext() {
   if (_parent == null) {
     return null;
   } else {
     return _parent.getTransformContext();
   }
 }
Example #4
0
 public void saveToDisk(String fileName) {
   Dimension dim = component.getPreferredSize();
   java.awt.Rectangle rect = new java.awt.Rectangle(0, 0, dim.width, dim.height);
   BufferedImage image = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_RGB);
   Graphics2D g = (Graphics2D) image.getGraphics();
   g.setColor(java.awt.Color.WHITE);
   g.fill(rect);
   g.setColor(java.awt.Color.BLACK);
   component.paintComponent(g);
   String extension = fileName.substring(fileName.lastIndexOf('.') + 1);
   try {
     ImageIO.write(image, extension, new File(fileName));
   } catch (IOException e) {
     System.err.println("Was unable to save the image to " + fileName);
   }
   g.dispose();
 }
Example #5
0
 /**
  * Schedule a repaint of the figure within the given damage region. This default implementation
  * forwards the damage region to this figure's parent. See the nullary version of this method.
  */
 public void repaint(DamageRegion d) {
   if (_parent != null) {
     _parent.repaint(d);
   }
 }
Example #6
0
 /**
  * Schedule a repaint of the figure. This should be called after performing modifications on the
  * figure, so that the figure is scheduled for redrawing. This default implementation creates a
  * damage region that is the same size as this figure's bounding box, and forwards that to the
  * parent. Subclasses only need to override this method if they need to damage a region that is
  * different from the bounding box.
  */
 public void repaint() {
   if (_parent != null) {
     repaint(DamageRegion.createDamageRegion(_parent.getTransformContext(), getBounds()));
   }
 }