Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / LayoutEvents.java @ 37873

History | View | Annotate | Download (7.03 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.app.project.documents.layout;
23

    
24
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionListener;
26
import java.awt.event.ComponentEvent;
27
import java.awt.event.ComponentListener;
28
import java.awt.event.MouseEvent;
29
import java.awt.event.MouseListener;
30
import java.awt.event.MouseMotionListener;
31

    
32
import org.gvsig.app.project.documents.layout.gui.FPopupMenu;
33
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
34
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
35
import org.gvsig.utils.exceptionHandling.ExceptionHandlingSupport;
36
import org.gvsig.utils.exceptionHandling.ExceptionListener;
37

    
38
/**
39
 * Eventos que se realizan sobre el Layout.
40
 * 
41
 * @author Vicente Caballero Navarro
42
 */
43
public class LayoutEvents implements ActionListener, ComponentListener,
44
    MouseMotionListener, MouseListener {
45

    
46
    private LayoutPanel layout = null;
47
    private ExceptionHandlingSupport exceptionHandlingSupport =
48
        new ExceptionHandlingSupport();
49

    
50
    /**
51
     * Crea un nuevo EventsHandler.
52
     * 
53
     * @param l
54
     *            Referencia al Layout.
55
     */
56
    public LayoutEvents(LayoutPanel l) {
57
        layout = l;
58
    }
59

    
60
    /**
61
     * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
62
     */
63
    public void componentHidden(ComponentEvent arg0) {
64
    }
65

    
66
    /**
67
     * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
68
     */
69
    public void componentMoved(ComponentEvent arg0) {
70
    }
71

    
72
    /**
73
     * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
74
     */
75
    public void componentResized(ComponentEvent arg0) {
76
        layout.getLayoutControl().fullRect();
77
    }
78

    
79
    /**
80
     * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
81
     */
82
    public void componentShown(ComponentEvent arg0) {
83
    }
84

    
85
    /**
86
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
87
     */
88
    public void actionPerformed(ActionEvent arg0) {
89
        layout.repaint();
90
    }
91

    
92
    /**
93
     * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
94
     */
95
    public void mouseDragged(MouseEvent e) {
96
        if (e.getButton() != MouseEvent.BUTTON3) {
97
            layout.getLayoutControl().setLastPoint();
98
            layout.repaint();
99
        }
100
        try {
101
            layout.getLayoutControl().getCurrentLayoutTool().mouseDragged(e);
102
        } catch (BehaviorException t) {
103
            throwException(t);
104
        }
105
        layout.getLayoutControl().setPosition(e.getPoint());
106
    }
107

    
108
    /**
109
     * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
110
     */
111
    public void mouseMoved(MouseEvent e) {
112
        layout.getLayoutControl().setPosition(e.getPoint());
113
        try {
114
            layout.getLayoutControl().getCurrentLayoutTool().mouseMoved(e);
115
        } catch (BehaviorException t) {
116
            throwException(t);
117
        }       
118
        layout.repaint();
119
    }
120

    
121
    /**
122
     * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
123
     */
124
    public void mouseClicked(MouseEvent e) {
125
        try {
126
            layout.getLayoutControl().getCurrentLayoutTool().mouseClicked(e);
127
        } catch (BehaviorException t) {
128
            throwException(t);
129
        }
130
    }
131

    
132
    /**
133
     * A?ade un listener de tipo ExceptionListener.
134
     * 
135
     * @param o
136
     *            ExceptionListener.
137
     */
138
    public void addExceptionListener(ExceptionListener o) {
139
        exceptionHandlingSupport.addExceptionListener(o);
140
    }
141

    
142
    /**
143
     * Borra la ExceptioListener que se pasa como par?metro.
144
     * 
145
     * @param o
146
     *            ExceptionListener.
147
     * 
148
     * @return True si se borra correctamente.
149
     */
150
    public boolean removeExceptionListener(ExceptionListener o) {
151
        return exceptionHandlingSupport.removeExceptionListener(o);
152
    }
153

    
154
    /**
155
     * Lanza una Excepci?n.
156
     * 
157
     * @param t
158
     *            Excepci?n.
159
     */
160
    protected void throwException(Throwable t) {
161
        exceptionHandlingSupport.throwException(t);
162
    }
163

    
164
    /**
165
     * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
166
     */
167
    public void mouseEntered(MouseEvent e) {
168
        layout.getLayoutControl().clearMouseImage();
169
        try {
170
            layout.getLayoutControl().getCurrentLayoutTool().mouseEntered(e);
171
        } catch (BehaviorException t) {
172
            throwException(t);
173
        }
174
    }
175

    
176
    /**
177
     * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
178
     */
179
    public void mouseExited(MouseEvent e) {
180
        try {
181
            layout.getLayoutControl().getCurrentLayoutTool().mouseExited(e);
182
        } catch (BehaviorException t) {
183
            throwException(t);
184
        }
185
    }
186

    
187
    /**
188
     * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
189
     */
190
    public void mousePressed(MouseEvent e) {
191
        if (e.getButton() == MouseEvent.BUTTON1) {
192
            layout.getLayoutControl().setPointAnt();
193
            layout.getLayoutControl().setFirstPoint();
194
            try {
195
                layout.getLayoutControl().getCurrentLayoutTool()
196
                    .mousePressed(e);
197
            } catch (BehaviorException t) {
198
                throwException(t);
199
            }
200
        } else
201
            if (e.getButton() == MouseEvent.BUTTON3) {
202
                FPopupMenu popmenu = new FPopupMenu(layout);
203
                layout.add(popmenu);
204
                popmenu.show(e.getComponent(), e.getX(), e.getY());
205
            }
206
    }
207

    
208
    /**
209
     * @see java.awt.event.MouseListener#mouseReleassed(java.awt.event.MouseEvent)
210
     */
211
    public void mouseReleased(MouseEvent e) {
212
        if (e.getButton() != MouseEvent.BUTTON3) {
213
            layout.getLayoutControl().setLastPoint();
214
        }
215

    
216
        if (e.getButton() == MouseEvent.BUTTON1) {
217
            try {
218
                layout.getLayoutControl().getCurrentLayoutTool()
219
                    .mouseReleased(e);
220
            } catch (BehaviorException t) {
221
                throwException(t);
222
            }
223
            layout.getLayoutControl().setCancelDrawing(false);
224
        } else
225
            if (e.getButton() == MouseEvent.BUTTON3) {
226
            }
227

    
228
    }
229
}