View Javadoc

1   package org.devaki.nextobjects.workspace.models.graphics;
2   /*
3   
4   nextobjects Copyright (C) 2001-2005 Emmanuel Florent
5   
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by the
8   Free Software Foundation; either version 2 of the License, or (at your
9   option) any later version.
10  
11  This program is distributed in the hope that it will
12  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13  of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the GNU General Public License for more details.
15  
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc., 59
18  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  
20  */
21  import java.io.Serializable;
22  import java.awt.Cursor;
23  import java.awt.Graphics;
24  import java.awt.Point;
25  import java.awt.Rectangle;
26  import org.devaki.nextobjects.constants.CstGraphics;
27  /***
28   * SelectionPoint
29   * @author <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
30   */
31  public class SelectionPoint implements Serializable
32  {
33      /*** X Location */
34      private int X;
35      /*** Y Location */
36      private int Y;
37      /*** X Size */
38      private final int width = 6;
39      /*** Y Size */
40      private final int height = 6;
41      /*** Positions */
42      public static final int NORTH_WEST = Cursor.NW_RESIZE_CURSOR;
43      /*** Positions */
44      public static final int NORTH = Cursor.N_RESIZE_CURSOR;
45      /*** Positions */
46      public static final int NORTH_EAST = Cursor.NE_RESIZE_CURSOR;
47      /*** Positions */
48      public static final int WEST = Cursor.W_RESIZE_CURSOR;
49      /*** Positions */
50      public static final int EAST = Cursor.E_RESIZE_CURSOR;
51      /*** Positions */
52      public static final int SOUTH_WEST = Cursor.SW_RESIZE_CURSOR;
53      /*** Positions */
54      public static final int SOUTH = Cursor.S_RESIZE_CURSOR;
55      /*** Positions */
56      public static final int SOUTH_EAST = Cursor.SE_RESIZE_CURSOR;
57      /***
58       * Construct a new 'SelectionPoint' object
59       * @param pX the initial x location
60       * @param pY the initial y location
61       */
62      public SelectionPoint(final int pX, final int pY)
63      {
64          this.X = pX;
65          this.Y = pY;
66      }
67      /***
68       * Paint
69       * @param g graphics
70       */
71      public final void paint(final Graphics g)
72      {
73          g.setColor(CstGraphics.SELECTION_COLOR);
74          g.fillRect(this.X - 3, this.Y - 3, this.width, this.height);
75      }
76      /***
77       * Get the location
78       * @return the location
79       */
80      public final Point getPoint()
81      {
82          Point tmp = new Point(X, Y);
83          return tmp;
84      }
85      /***
86       * Set the location
87       * @param p the new location
88       */
89      public final void setLocation(final Point p)
90      {
91          X = (int) p.getX();
92          Y = (int) p.getY();
93      }
94      /***
95       * Returns a Rectangle from the current object
96       * Grow square by 8 pixels for each side in order to facilitate
97       * the resize click
98       * @return the surface.
99       */
100     public final Rectangle getSurface()
101     {
102         return new Rectangle(
103             this.X - 7,
104             this.Y - 7,
105             this.width + 8,
106             this.height + 8);
107     }
108 }