gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.swing / org.gvsig.raster.swing.api / src / main / java / org / gvsig / raster / swing / gcanvas / DrawableElement.java @ 2443
History | View | Annotate | Download (3.85 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.swing.gcanvas; |
23 |
|
24 |
import java.awt.Color; |
25 |
import java.awt.Graphics; |
26 |
import java.awt.event.MouseEvent; |
27 |
/**
|
28 |
* Clase base para los gr?ficos a dibujar sobre el canvas
|
29 |
*
|
30 |
* 14-oct-2007
|
31 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
32 |
*/
|
33 |
public abstract class DrawableElement { |
34 |
protected Color color = Color.BLACK; |
35 |
private boolean firstDraw = true; |
36 |
private boolean drawing = true; |
37 |
|
38 |
/**
|
39 |
* Entorno donde se dibuja
|
40 |
*/
|
41 |
protected GCanvas canvas = null; |
42 |
|
43 |
/**
|
44 |
* Dibujado del elemento gr?fico desde el GCanvas. Llamar? antes de dibujar a
|
45 |
* la funci?n firstDrawActions
|
46 |
* @param g
|
47 |
*/
|
48 |
public void draw(Graphics g) { |
49 |
if(!drawing)
|
50 |
return;
|
51 |
if (firstDraw) {
|
52 |
firstDrawActions(); |
53 |
firstDraw = false;
|
54 |
} |
55 |
paint(g); |
56 |
} |
57 |
|
58 |
/**
|
59 |
* Asigna el flag de dibujado del elemento gr?fico
|
60 |
* @param draw
|
61 |
*/
|
62 |
public void setDrawing(boolean drawing) { |
63 |
this.drawing = drawing;
|
64 |
} |
65 |
|
66 |
/**
|
67 |
* Obtiene el flag que informa si el elemento gr?fico est? dibujandose
|
68 |
* o no.
|
69 |
* @return
|
70 |
*/
|
71 |
public boolean isDrawing() { |
72 |
return this.drawing; |
73 |
} |
74 |
|
75 |
/**
|
76 |
* Dibujado del elemento gr?fico
|
77 |
* @param g
|
78 |
*/
|
79 |
protected abstract void paint(Graphics g); |
80 |
|
81 |
/**
|
82 |
* Acciones a ejecutar al asignar el canvas
|
83 |
*/
|
84 |
public abstract void firstActions(); |
85 |
|
86 |
/**
|
87 |
* Acciones a ejecutar antes del primer dibujado
|
88 |
*/
|
89 |
public abstract void firstDrawActions(); |
90 |
|
91 |
/**
|
92 |
* Asigna el objeto JComponent donde se pintan los elementos.
|
93 |
* @param canvas
|
94 |
*/
|
95 |
public void setCanvas(GCanvas canvas) { |
96 |
this.canvas = canvas;
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* Asigna el color de la l?nea
|
101 |
* @param c Color
|
102 |
*/
|
103 |
public void setColor(Color c) { |
104 |
this.color = c;
|
105 |
} |
106 |
|
107 |
/**
|
108 |
* Obtiene el color de la l?nea
|
109 |
* @param c Color
|
110 |
*/
|
111 |
public Color getColor() { |
112 |
return this.color; |
113 |
} |
114 |
|
115 |
/**
|
116 |
* Metodo que se ejecuta cuando se suelta el raton en el canvas
|
117 |
* @param e
|
118 |
* @return Si no se desea propagar el evento a otros drawables, devolver false.
|
119 |
*/
|
120 |
public boolean mouseReleased(MouseEvent e) { |
121 |
return true; |
122 |
} |
123 |
|
124 |
/**
|
125 |
* Metodo que se ejecuta cuando se presiona el raton en el canvas
|
126 |
* @param e
|
127 |
* @return Si no se desea propagar el evento a otros drawables, devolver false.
|
128 |
*/
|
129 |
public boolean mousePressed(MouseEvent e) { |
130 |
return true; |
131 |
} |
132 |
|
133 |
/**
|
134 |
* Metodo que se ejecuta cuando se esta dibujando con el raton en el canvas
|
135 |
* @param e
|
136 |
* @return Si no se desea propagar el evento a otros drawables, devolver false.
|
137 |
*/
|
138 |
public boolean mouseDragged(MouseEvent e) { |
139 |
return true; |
140 |
} |
141 |
|
142 |
/**
|
143 |
* Metodo que se ejecuta cuando se esta moviendo el raton sobre el canvas
|
144 |
* @param e
|
145 |
* @return Si no se desea propagar el evento a otros drawables, devolver false.
|
146 |
*/
|
147 |
public boolean mouseMoved(MouseEvent e) { |
148 |
return true; |
149 |
} |
150 |
|
151 |
/**
|
152 |
* Metodo que se ejecuta cuando entra el raton al canvas
|
153 |
* @param e
|
154 |
* @return
|
155 |
*/
|
156 |
public boolean mouseEntered(MouseEvent e) { |
157 |
return true; |
158 |
} |
159 |
|
160 |
/**
|
161 |
* Metodo que se ejecuta cuando sale el raton del canvas
|
162 |
* @param e
|
163 |
* @return
|
164 |
*/
|
165 |
public boolean mouseExited(MouseEvent e) { |
166 |
return true; |
167 |
} |
168 |
} |