View Javadoc

1   /* $Id: Room.java 22 2008-12-30 17:33:44Z mihlon $ */
2   
3   //////////////////////////////////////////////////////////////////////////////
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   //
7   //   the Free Software Foundation, either version 3 of the License, or      //
8   //   at your option any later version.                                      //
9   //                                                                          //
10  //   This program is distributed in the hope that it will be useful,        //
11  //   but WITHOUT ANY WARRANTY; without even the implied warranty of         //
12  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          //
13  //   GNU General Public License for more details.                           //
14  //                                                                          //
15  //   You should have received a copy of the GNU General Public License      //
16  //   along with this program.  If not, see <http://www.gnu.org/licenses/>.  //
17  //                                                                          //
18  //////////////////////////////////////////////////////////////////////////////
19  
20  package cs.pancava.caltha.worlds;
21  
22  import cs.pancava.caltha.Editor;
23  import java.awt.Color;
24  import java.awt.Font;
25  import java.awt.Graphics2D;
26  import java.awt.font.TextLayout;
27  import java.awt.geom.Ellipse2D;
28  
29  /**
30   * <p><b>Tato trida definuje vlastnosti mistnosti ve vytvorenem svete.</b></p>
31   *
32   * @author Milan Vaclavik<br />
33   * @version $Revision: 22 $<br />
34   * $LastChangedBy: mihlon $<br />
35   */
36  public class Room extends GameEntity
37  {
38      /**
39       * Graficka reprezentace mistnosti v editoru.
40       */
41      private Ellipse2D graphicsObject;
42  
43      /**
44       * Prumer mistnosti (kruznice).
45       */
46      private int diameter;
47  
48      /**
49       * Barva mistnosti.
50       */
51      private final Color ROOM_COLOR = Color.BLUE;
52  
53      /**
54       * Barva vybrane mistnosti.
55       */
56      private final Color ROOM_SELECTED_COLOR = Color.CYAN;
57  
58      /**
59       * Barva popisku - textu.
60       */
61      private final Color TEXT_COLOR = Color.WHITE;
62  
63      /**
64       * Konstruktor - nastavuje souradnice umisteni dane mistnosti v editoru.
65       * @param x int : X-ova souradnice mistnosti.
66       * @param y int : Y-ova souradnice mistnosti.
67       * @param r int : Polomer kruznice - urcuje velikost mistnosti.
68       */
69      public Room(final int x, final int y, final int r)
70      {
71          super(x, y, World.WORLD_ROOM, Editor.getEditorDesktop().getWorld().getWorldRoomsAL().size());
72  
73          this.diameter = r;
74  
75          this.graphicsObject = new Ellipse2D.Double(x, y, this.diameter, this.diameter);
76      }
77  
78      /**
79       * Vraci stred objektu v ose X.
80       * @return int : Stred objektu v ose X.
81       */
82      @Override
83      public final int getCenterX()
84      {
85          return this.getLocationX() + this.diameter / 2;
86      }
87  
88      /**
89       * Vraci stred objektu v ose Y.
90       * @return int : Stred objektu v ose Y.
91       */
92      @Override
93      public final int getCenterY()
94      {
95          return this.getLocationY() + this.diameter / 2;
96      }
97  
98      /**
99       * Vraci grafickou reprezentaci mistnosti v editoru.
100      * @return RectangularShape : Graficka reprezentace mistnosti v editoru.
101      */
102     @Override
103     public final Object getGraphicsObject()
104     {
105         return this.graphicsObject;
106     }
107 
108     /**
109      * Zobrazi danou mistnost v editoru.
110      * @param g2 Graphics2D : Graficky kontext, do ktereho se bude kreslit.
111      */
112     @Override
113     public final void showGraphicsObject(final Graphics2D g2)
114     {
115         final TextLayout textID = new TextLayout(String.valueOf(this.getId()),
116                                            new Font("Helvetica", 0, this.diameter / 2),
117                                            g2.getFontRenderContext());
118 
119         // Nastaveni grafickeho objektu na novou (aktualni) pozici.
120         this.graphicsObject.setFrame(this.getLocationX(), this.getLocationY(), this.diameter, this.diameter);
121 
122         if (this.isSeleted())
123         {
124             g2.setColor(this.ROOM_SELECTED_COLOR);
125         }
126         else
127         {
128             g2.setColor(this.ROOM_COLOR);
129         }
130 
131         g2.fill(this.graphicsObject);
132 
133         g2.setColor(this.TEXT_COLOR);
134         textID.draw(g2,
135                     this.getLocationX() + (int) ((this.diameter - textID.getBounds().getWidth()) / 2),
136                     this.getLocationY() + (int)  (this.diameter - textID.getBounds().getHeight()));
137     }
138 
139     /**
140      * V teto tride nepotrebuji tuto vlastnost, proto vratime null.
141      * @return gameEntity : Vratime null, protoze je tato vlastnost v tomto kontextu k nicemu.
142      */
143     @Override
144     public final GameEntity getFirstRoom()
145     {
146         return null;
147     }
148 
149     /**
150      * V teto tride nepotrebuji tuto vlastnost, proto vratime null.
151      * @return gameEntity : Vratime null, protoze je tato vlastnost v tomto kontextu k nicemu.
152      */
153     @Override
154     public final GameEntity getSecondRoom()
155     {
156         throw new UnsupportedOperationException("Not supported yet.");
157     }
158 }