View Javadoc

1   /*
2   
3   nextobjects Copyright (C) 2001-2005 Emmanuel Florent
4   
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by the
7   Free Software Foundation; either version 2 of the License, or (at your
8   option) any later version.
9   
10  This program is distributed in the hope that it will
11  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12  of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13  PURPOSE. See the GNU General Public License for more details.
14  
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc., 59
17  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  
19  */
20  
21  package org.devaki.nextobjects.workspace.models.graphics;
22  
23  import java.io.Serializable;
24  import java.awt.Graphics;
25  import java.awt.Graphics2D;
26  import java.awt.Rectangle;
27  import org.devaki.nextobjects.constants.CstGraphics;
28  import org.devaki.nextobjects.workspace.models.objects.Entity;
29  
30  
31  /***
32   * The representation of an entity
33   * @author <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
34   */
35  public class EntityView extends ClassView implements Serializable
36  {
37   /***
38    * Construct a new 'EntityView' object
39    * @param pEntity the context entity
40    */
41   public EntityView(Entity pEntity)
42   {
43    super(pEntity);
44    // Define size
45    this.setSize(CstGraphics.DEFAULT_ENTITY_SIZE);
46    this.oldRectangle.setSize(rectangle.getSize());
47    this.oldRectangle.setLocation(rectangle.getLocation());
48   }
49  
50  
51   /***
52    * Update graphics
53    * @param g the graphics
54    */
55   public void update(Graphics g)
56   {
57    Graphics2D g2 = (Graphics2D)g;
58    Rectangle rect = new Rectangle(0, 0, (int) this.getSize().getWidth() - 1,
59                    (int) this.getSize().getHeight() - 1);
60    /*** Start drawing... **/
61    /*** Background **/
62    g2.setColor(this.myStyle.getBackgroundColor());
63    g2.fill(rect);
64    /*** Border **/
65    g2.setPaint(this.myStyle.getBorderColor());
66    g2.drawRect(0, 0, (int) rect.getSize().getWidth(),
67           (int) rect.getSize().getHeight());
68    /*** Name **/
69    this.printColumns(g2, 0, 0);
70   }
71  
72  
73   /***
74    * Paint
75    * @param g the graphics
76    */
77   public void paint(Graphics g)
78   {
79    update(g);
80   }
81  }