root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / tools / LayoutSelectListenerImpl.java @ 24963
History | View | Annotate | Download (7.89 KB)
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib��ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.project.documents.layout.tools; |
42 |
|
43 |
import java.awt.Image; |
44 |
import java.awt.event.MouseEvent; |
45 |
import java.awt.geom.Point2D; |
46 |
import java.util.ArrayList; |
47 |
|
48 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
49 |
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent; |
50 |
|
51 |
import com.iver.andami.PluginServices; |
52 |
import com.iver.cit.gvsig.project.documents.layout.FLayoutGraphics; |
53 |
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities; |
54 |
import com.iver.cit.gvsig.project.documents.layout.LayoutControl; |
55 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame; |
56 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameGroupSelectable; |
57 |
import com.iver.cit.gvsig.project.documents.layout.gui.Layout; |
58 |
import com.iver.cit.gvsig.project.documents.layout.tools.listener.LayoutMoveListener; |
59 |
|
60 |
|
61 |
/**
|
62 |
* Implementaci�n de la interfaz LayoutPanListener como herramienta para realizar una
|
63 |
* selecci�n.
|
64 |
*
|
65 |
* @author Vicente Caballero Navarro
|
66 |
*/
|
67 |
public class LayoutSelectListenerImpl implements LayoutMoveListener { |
68 |
public static final Image icrux = PluginServices.getIconTheme() |
69 |
.get("crux-cursor").getImage();
|
70 |
private Layout layout;
|
71 |
private Point2D m_pointSelected; |
72 |
private int index = 0; |
73 |
private ArrayList lastSelect = new ArrayList(); |
74 |
/**
|
75 |
* Crea un nuevo LayoutSelectionListenerImpl.
|
76 |
*
|
77 |
* @param l Layout.
|
78 |
*/
|
79 |
public LayoutSelectListenerImpl(Layout l) {
|
80 |
this.layout = l;
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* @see org.gvsig.fmap.mapcontrol.tools.Listeners.PanListener#move(java.awt.geom.Point2D,
|
85 |
* java.awt.geom.Point2D)
|
86 |
*/
|
87 |
public void drag(PointEvent event) { |
88 |
} |
89 |
|
90 |
/**
|
91 |
* @see org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener#getCursor()
|
92 |
*/
|
93 |
public Image getImageCursor() { |
94 |
return icrux;
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* @see org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener#cancelDrawing()
|
99 |
*/
|
100 |
public boolean cancelDrawing() { |
101 |
return true; |
102 |
} |
103 |
|
104 |
public void press(PointEvent event) throws BehaviorException { |
105 |
m_pointSelected = event.getPoint(); |
106 |
layout.getLayoutControl().setIsReSel(true);
|
107 |
IFFrame[] fframes=layout.getLayoutContext().getFFrames();
|
108 |
for (int i = 0; i < fframes.length; i++) { |
109 |
IFFrame fframe = fframes[i]; |
110 |
|
111 |
if (m_pointSelected != null) { |
112 |
if (!event.getEvent().isShiftDown()) {
|
113 |
if ((fframe.getSelected() != IFFrame.NOSELECT)) {
|
114 |
fframe.setSelected(m_pointSelected,event.getEvent()); |
115 |
} |
116 |
}else if (fframe instanceof IFFrameGroupSelectable){ |
117 |
fframe.setSelected(m_pointSelected,event.getEvent()); |
118 |
} |
119 |
} |
120 |
|
121 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
122 |
layout.getLayoutControl().setIsReSel(false);
|
123 |
} |
124 |
|
125 |
|
126 |
} |
127 |
|
128 |
if ((layout.getLayoutControl().getLastPoint() != null) && |
129 |
(layout.getLayoutControl().getFirstPoint() != null)) {
|
130 |
layout.getLayoutControl().getLastPoint().setLocation(layout.getLayoutControl().getFirstPoint()); |
131 |
} |
132 |
|
133 |
if (event.getEvent().getClickCount() < 2) { |
134 |
layout.getLayoutControl().setStatus(LayoutControl.ACTUALIZADO); |
135 |
layout.repaint(); |
136 |
} |
137 |
|
138 |
} |
139 |
|
140 |
public void release(PointEvent event) throws BehaviorException { |
141 |
layout.getLayoutControl().getLayoutFunctions().setSelect(); |
142 |
layout.getLayoutControl().refresh(); |
143 |
layout.getLayoutControl().setIsReSel(false);
|
144 |
} |
145 |
public void click(PointEvent event) { |
146 |
if (event.getEvent().getButton() == MouseEvent.BUTTON1) { |
147 |
m_pointSelected = event.getPoint(); |
148 |
IFFrame[] fframes=layout.getLayoutContext().getFFrames();
|
149 |
if (fframes.length > 0) { |
150 |
ArrayList listSelect = new ArrayList(); |
151 |
for (int j = 0; j < fframes.length; j++) { |
152 |
if (fframes[j].getContains(
|
153 |
m_pointSelected) != IFFrame.NOSELECT) { |
154 |
listSelect.add(fframes[j]); |
155 |
} |
156 |
} |
157 |
|
158 |
if (listSelect.size() > 0) { |
159 |
for (int k = 0; k < listSelect.size(); k++) { |
160 |
if (((IFFrame) listSelect.get(k)).getSelected() != IFFrame.NOSELECT) {
|
161 |
index = listSelect.size() - k; |
162 |
|
163 |
break;
|
164 |
} |
165 |
} |
166 |
|
167 |
if (!FLayoutUtilities.isEqualList(listSelect,
|
168 |
lastSelect) || |
169 |
(index > (listSelect.size() - 1))) {
|
170 |
index = 0;
|
171 |
} |
172 |
for (int j = 0; j < fframes.length; |
173 |
j++) { |
174 |
IFFrame fframe = fframes[j]; |
175 |
|
176 |
if (!event.getEvent().isShiftDown()) {
|
177 |
fframe.setSelected(false);
|
178 |
} else {
|
179 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
180 |
if (fframe.getContains(m_pointSelected) != IFFrame.NOSELECT) {
|
181 |
fframe.setSelected(false);
|
182 |
} |
183 |
} |
184 |
} |
185 |
} |
186 |
|
187 |
((IFFrame) listSelect.get((listSelect.size() - 1 -
|
188 |
index))).setSelected(true);
|
189 |
index++; |
190 |
lastSelect = listSelect; |
191 |
} |
192 |
|
193 |
layout.getLayoutControl().setStatus(LayoutControl.ACTUALIZADO); |
194 |
layout.repaint(); |
195 |
|
196 |
if (event.getEvent().getClickCount() > 1) { |
197 |
FLayoutGraphics flg = new FLayoutGraphics(layout);
|
198 |
flg.openFFrameDialog(); |
199 |
layout.getLayoutControl().setStatus(LayoutControl.ACTUALIZADO); |
200 |
layout.repaint(); |
201 |
} |
202 |
} |
203 |
|
204 |
PluginServices.getMainFrame().enableControls(); |
205 |
} |
206 |
} |
207 |
|
208 |
public void move(PointEvent event) throws BehaviorException { |
209 |
Image cursor = null; |
210 |
Point2D p = event.getPoint();
|
211 |
IFFrame[] fframes=layout.getLayoutContext().getFFrameSelected();
|
212 |
for (int i = 0; i < fframes.length; i++) { |
213 |
if (fframes[i].getContains(p)!=IFFrame.NOSELECT){
|
214 |
cursor=fframes[i].getMapCursor(p); |
215 |
} |
216 |
if (cursor != null) { |
217 |
layout.getLayoutControl().setMapCursor(cursor); |
218 |
} |
219 |
// else {
|
220 |
// layout.setMapCursor(Layout.icrux);
|
221 |
// }
|
222 |
} |
223 |
} |
224 |
|
225 |
} |