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