1 package org.devaki.nextobjects.workspace.models.graphics;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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 }