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