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