Statistics
| Revision:

svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / LayoutEvents.java @ 308

History | View | Annotate | Download (7.1 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().getComponent().requestFocusInWindow();
127
            layout.getLayoutControl().getCurrentLayoutTool().mouseClicked(e);
128
        } catch (BehaviorException t) {
129
            throwException(t);
130
        }
131
    }
132

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

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

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

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

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

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

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

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

    
229
    }
230
}