Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / beans / canvas / DrawableElement.java @ 19361

History | View | Annotate | Download (3.28 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (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, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.raster.beans.canvas;
20

    
21
import java.awt.Color;
22
import java.awt.Graphics;
23
import java.awt.event.MouseEvent;
24

    
25

    
26
/**
27
 * Clase base para los gr?ficos a dibujar sobre el canvas
28
 *
29
 * 14-oct-2007
30
 * @author Nacho Brodin (nachobrodin@gmail.com)
31
 */
32
public abstract class DrawableElement {
33

    
34
        protected Color             color           = Color.BLACK;
35
        /**
36
         * Entorno donde se dibuja
37
         */
38
        protected GCanvas           canvas          = null;
39
        private boolean             firstDraw       = true;
40
        
41
        /**
42
         * Dibujado del elemento gr?fico desde el GCanvas. Llamar? antes de dibujar a la funci?n firstDrawActions
43
         * @param g
44
         */
45
        public void draw(Graphics g) {
46
                if(firstDraw) {
47
                        firstDrawActions();
48
                        firstDraw = false;
49
                }
50
                paint(g);
51
        }
52
        /**
53
         * Dibujado del elemento gr?fico
54
         * @param g
55
         */
56
        protected abstract void paint(Graphics g);
57
        
58
        /**
59
         * Acciones a ejecutar antes del primer dibujado
60
         */
61
        public abstract void firstDrawActions();
62
        
63
        /**
64
         * Asigna el objeto JComponent donde se pintan los elementos.
65
         * @param canvas
66
         */
67
        public void setCanvas(GCanvas canvas) {
68
                this.canvas = canvas;
69
        }
70
        
71
        /**
72
         * Asigna el color de la l?nea
73
         * @param c Color
74
         */
75
        public void setColor(Color c) {
76
                this.color = c;
77
        }
78

    
79
        /**
80
         * Metodo que se ejecuta cuando se suelta el raton en el canvas
81
         * @param e
82
         * @return Si no se desea propagar el evento a otros drawables, devolver false.
83
         */
84
        public boolean mouseReleased(MouseEvent e) {
85
                return true;
86
        }
87

    
88
        /**
89
         * Metodo que se ejecuta cuando se presiona el raton en el canvas
90
         * @param e
91
         * @return Si no se desea propagar el evento a otros drawables, devolver false.
92
         */
93
        public boolean mousePressed(MouseEvent e) {
94
                return true;
95
        }
96
        
97
        /**
98
         * Metodo que se ejecuta cuando se esta dibujando con el raton en el canvas
99
         * @param e
100
         * @return Si no se desea propagar el evento a otros drawables, devolver false.
101
         */
102
        public boolean mouseDragged(MouseEvent e) {
103
                return true;
104
        }
105
        
106
        /**
107
         * Metodo que se ejecuta cuando se esta moviendo el raton sobre el canvas
108
         * @param e
109
         * @return Si no se desea propagar el evento a otros drawables, devolver false.
110
         */
111
        public boolean mouseMoved(MouseEvent e) {
112
                return true;
113
        }
114
        
115
        /**
116
         * Metodo que se ejecuta cuando entra el raton al canvas
117
         * @param e
118
         * @return
119
         */
120
        public boolean mouseEntered(MouseEvent e) {
121
                return true;
122
        }
123

    
124
        /**
125
         * Metodo que se ejecuta cuando sale el raton del canvas
126
         * @param e
127
         * @return
128
         */
129
        public boolean mouseExited(MouseEvent e) {
130
                return true;
131
        }
132
}