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  
22  import java.io.Serializable;
23  import java.awt.Dimension;
24  import java.awt.Graphics;
25  import java.awt.Point;
26  import java.awt.Polygon;
27  import org.devaki.nextobjects.workspace.models.objects.BaseObject;
28  
29  /***
30   *  This class is responsible of drawing an object
31   * @author <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
32   */
33  public abstract class ObjectView implements Serializable
34  {
35   /***
36    *  the context objects
37    */
38   protected BaseObject myObject;
39  
40   /***
41    * selections points
42    */
43   protected SelectionPoint[] selectionPoints;
44   
45   /***
46   * Action point : the point where the object is to be moved.
47   */
48   protected Point actionPoint=new Point(0,0);
49  
50   /***
51    * Construct a new 'ObjectView' object
52    * @param pObject the object
53    */
54   public ObjectView(BaseObject pObject)
55   {
56    this.myObject = pObject;
57   }
58   
59   /***
60    * Construct a new 'ObjectView' object
61    */
62   public ObjectView()
63   {
64    this.myObject =null;
65   }
66   
67   public void setActionLocation (int pX,int pY) 
68   {
69    this.actionPoint=new Point(pX,pY);
70   }
71   
72   public void resetActionLocation () 
73   {
74    this.actionPoint=null;
75   } 
76   
77   /***
78    * Paint object
79    * @param g Graphic axis of the object
80    */
81   //public abstract void paint(Graphics g);
82  
83   /***
84    * Paint selection around the object
85    * @param g Graphic axis of the main view
86    */
87   public void renderSelected(Graphics g)
88   {
89    for (int i = 0; i < getSelectionPoints().length; i++)
90    {
91     this.getSelectionPoint(i).paint(g);
92    }
93    if (actionPoint!=null) 
94    {
95    g.drawRect(this.actionPoint.x,
96     this.actionPoint.y,
97     this.getSize().width,
98     this.getSize().height);
99    }
100  }
101 
102  /***
103    * Get the surface on which the user can click to select the object
104    * @return the surface shape
105    */
106  public abstract Polygon getSurface();
107 
108  /***
109   * Return the Selection Points Array
110   * @return selections points
111   */
112  public SelectionPoint[] getSelectionPoints()
113  {
114   return this.selectionPoints;
115  }
116  /***
117   * Return the Selection Point
118   * @param i index
119   * @return selectionPoint
120   */
121  public SelectionPoint getSelectionPoint(int i)
122  {
123   return this.selectionPoints[i];
124  }
125 
126  /***
127   * Set the location
128   * @param p the location
129   */
130  public abstract void setLocation(Point p);
131  
132  /***
133   * The parent function needs to be overriden because of a bug in the program.
134   * @return the location
135   */
136  public  abstract Point getLocation() ;
137  
138  /***
139   * Define the dimension
140   * @param pDimension the dimension
141   */
142  public abstract void setSize(Dimension pDimension);
143 
144  /***
145   * Define the dimension
146   * @return the dimension
147   */
148  public Dimension getSize()
149  {
150   return new Dimension(1, 1);
151  }
152 
153  /***
154   * Set the object represented by this view
155   * @param pBaseObject the context object
156   */
157  public void setBaseObject(BaseObject pBaseObject)
158  {
159   this.myObject = pBaseObject;
160  }
161  /***
162   * Get the object represented by this view
163   * @return the object
164   */
165  public BaseObject getBaseObject()
166  {
167   return this.myObject;
168  }
169  
170  /***
171   *Reset Selection points
172   *do nothing
173   */
174  public abstract void resetSelectionPoint();
175  /***
176   *  paint
177   * @param g the graphics context
178   */ 
179  public abstract void paint(Graphics g);
180 }