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  package org.devaki.nextobjects.workspace.models.graphics;
21  import java.awt.Graphics;
22  import java.awt.Font;
23  import java.awt.Point;
24  import javax.swing.UIManager;
25  import org.devaki.nextobjects.constants.CstGraphics;
26  import org.devaki.nextobjects.workspace.models.objects.ModelTitle;
27  import org.devaki.nextobjects.workspace.models.ConceptualModel;
28  import org.devaki.nextobjects.workspace.models.PhysicalModel;
29  /***
30   * This class is responsible for drawing a "cartouche"
31   * around the graphic.
32   * 
33   * @author eflorent
34   *
35   */
36  public class ModelTitleView extends ClassView
37  {
38      String modelKind = "";
39      Font font =
40          new Font(
41              ((Font) UIManager.get("Label.font")).getName(),
42              Font.PLAIN,
43              ((Font) UIManager.get("Label.font")).getSize());
44      int ascent = font.getSize() + 2;
45      /***
46       * Constructor
47       * @param pObject the model title
48       */
49      public ModelTitleView(ModelTitle pObject)
50      {
51          super(pObject);
52          if (pObject.getMyModel() instanceof ConceptualModel)
53          {
54              modelKind = "<<Conceptual Model>>";
55          }
56          else
57              if (pObject.getMyModel() instanceof PhysicalModel)
58              {
59                  modelKind = "<<Physical Model>>";
60              }
61          this.setSize(CstGraphics.DEFAULT_MODELTITLE_SIZE);
62          Point p = new Point(CstGraphics.MODEL_INITIAL_POSITION);
63          this.setLocation(p);
64  
65          oldRectangle.setSize(rectangle.getSize());
66          oldRectangle.setLocation(rectangle.getLocation());
67      }
68      /*** 
69       * Paint the "cartouche"
70       * @param g the graphic context
71       */
72      public void paint(Graphics g)
73      {
74          /*
75           * final :
76           *   ________
77           * I_________|
78           * I____|__ __|
79           * 
80           * 1/_______
81           * I                |
82           * I________|
83           */
84          g.setColor(CstGraphics.MODEL_BACKGROUND_COLOR);
85          g.fillRect(0, 0, this.getSize().width, this.getSize().height);
86          g.setColor(CstGraphics.DEFAULT_MODELTITLE_COLOR);
87          g.drawRect(0, 0, this.getSize().width - 1, this.getSize().height - 1);
88          /*
89           *  2/_ _ _ _ _ 
90           * I____.        |
91           * I____|_ _ _|
92           * 
93           */
94          g.drawRect(
95              0,
96              (this.getMiddlePoint().y - this.getLocation().y),
97              this.getSize().width / 2,
98              this.getSize().height / 2);
99          /*
100          *  3/   _ _  _
101          * I      . ____|
102          * I_ _ |__ __|
103          * 
104          */
105         g.drawRect(
106             (this.getMiddlePoint().x - this.getLocation().x),
107             (this.getMiddlePoint().y - this.getLocation().y),
108             this.getSize().width / 2,
109             this.getSize().height / 2);
110         printText(g);
111     }
112     /***
113      * Draw the texts
114      * @param g the graphic context
115      */
116     public void printText(Graphics g)
117     {
118         g.drawString(this.myObject.getMyModel().getName(), 4, ascent);
119         g.drawString(modelKind, 4, ascent + this.getSize().height / 2);
120         g.drawString(
121             this.myObject.getMyModel().getAuthorEmail(),
122             4 + this.getSize().width / 2,
123             ascent + this.getSize().height / 2);
124     }
125 }