Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / tools / LayoutSelectListenerImpl.java @ 14821

History | View | Annotate | Download (7.94 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 javax.swing.ImageIcon;
49

    
50
import com.iver.andami.PluginServices;
51
import com.iver.cit.gvsig.AddLayer;
52
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
53
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
54
import com.iver.cit.gvsig.project.documents.layout.FLayoutGraphics;
55
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
56
import com.iver.cit.gvsig.project.documents.layout.LayoutControl;
57
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
58
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameGroupSelectable;
59
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
60
import com.iver.cit.gvsig.project.documents.layout.tools.listener.LayoutMoveListener;
61

    
62

    
63
/**
64
 * Implementaci�n de la interfaz LayoutPanListener como herramienta para realizar una
65
 * selecci�n.
66
 *
67
 * @author Vicente Caballero Navarro
68
 */
69
public class LayoutSelectListenerImpl implements LayoutMoveListener {
70
        public static final Image icrux = PluginServices.getIconTheme()
71
        .get("crux-cursor").getImage();
72
        private Layout layout;
73
        private Point2D m_pointSelected;
74
        private int index = 0;
75
         private ArrayList lastSelect = new ArrayList();
76
        /**
77
         * Crea un nuevo LayoutSelectionListenerImpl.
78
         *
79
         * @param l Layout.
80
         */
81
        public LayoutSelectListenerImpl(Layout l) {
82
                this.layout = l;
83
        }
84

    
85
        /**
86
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.PanListener#move(java.awt.geom.Point2D,
87
         *                 java.awt.geom.Point2D)
88
         */
89
        public void drag(PointEvent event) {
90
        }
91

    
92
        /**
93
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
94
         */
95
        public Image getImageCursor() {
96
                return icrux;
97
        }
98

    
99
        /**
100
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
101
         */
102
        public boolean cancelDrawing() {
103
                return true;
104
        }
105

    
106
        public void press(PointEvent event) throws BehaviorException {
107
                m_pointSelected = event.getPoint();
108
                layout.getLayoutControl().setIsReSel(true);
109
                IFFrame[] fframes=layout.getLayoutContext().getFFrames();
110
        for (int i = 0; i < fframes.length; i++) {
111
            IFFrame fframe = fframes[i];
112

    
113
            if (m_pointSelected != null) {
114
                if (!event.getEvent().isShiftDown()) {
115
                    if ((fframe.getSelected() != IFFrame.NOSELECT)) {
116
                        fframe.setSelected(m_pointSelected,event.getEvent());
117
                    }
118
                }else if (fframe instanceof IFFrameGroupSelectable){
119
                            fframe.setSelected(m_pointSelected,event.getEvent());
120
                }
121
            }
122

    
123
            if (fframe.getSelected() != IFFrame.NOSELECT) {
124
                layout.getLayoutControl().setIsReSel(false);
125
            }
126

    
127

    
128
        }
129

    
130
        if ((layout.getLayoutControl().getLastPoint() != null) &&
131
                (layout.getLayoutControl().getFirstPoint() != null)) {
132
            layout.getLayoutControl().getLastPoint().setLocation(layout.getLayoutControl().getFirstPoint());
133
        }
134

    
135
        if (event.getEvent().getClickCount() < 2) {
136
            layout.getLayoutControl().setStatus(LayoutControl.ACTUALIZADO);
137
            layout.repaint();
138
        }
139

    
140
        }
141

    
142
        public void release(PointEvent event) throws BehaviorException {
143
                layout.getLayoutControl().getLayoutFunctions().setSelect();
144
        layout.getLayoutControl().refresh();
145
        layout.getLayoutControl().setIsReSel(false);
146
        }
147
        public void click(PointEvent event) {
148
                 if (event.getEvent().getButton() == MouseEvent.BUTTON1) {
149
                 m_pointSelected = event.getPoint();
150
                 IFFrame[] fframes=layout.getLayoutContext().getFFrames();
151
                 if (fframes.length > 0) {
152
                     ArrayList listSelect = new ArrayList();
153
                     for (int j = 0; j < fframes.length; j++) {
154
                         if (fframes[j].getContains(
155
                                     m_pointSelected) != IFFrame.NOSELECT) {
156
                             listSelect.add(fframes[j]);
157
                         }
158
                     }
159

    
160
                     if (listSelect.size() > 0) {
161
                         for (int k = 0; k < listSelect.size(); k++) {
162
                             if (((IFFrame) listSelect.get(k)).getSelected() != IFFrame.NOSELECT) {
163
                                 index = listSelect.size() - k;
164

    
165
                                 break;
166
                             }
167
                         }
168

    
169
                         if (!FLayoutUtilities.isEqualList(listSelect,
170
                                     lastSelect) ||
171
                                 (index > (listSelect.size() - 1))) {
172
                             index = 0;
173
                         }
174
                         for (int j = 0; j < fframes.length;
175
                                 j++) {
176
                             IFFrame fframe = fframes[j];
177

    
178
                             if (!event.getEvent().isShiftDown()) {
179
                                 fframe.setSelected(false);
180
                             } else {
181
                                 if (fframe.getSelected() != IFFrame.NOSELECT) {
182
                                     if (fframe.getContains(m_pointSelected) != IFFrame.NOSELECT) {
183
                                         fframe.setSelected(false);
184
                                     }
185
                                 }
186
                             }
187
                         }
188

    
189
                         ((IFFrame) listSelect.get((listSelect.size() - 1 -
190
                             index))).setSelected(true);
191
                         index++;
192
                         lastSelect = listSelect;
193
                     }
194

    
195
                     layout.getLayoutControl().setStatus(LayoutControl.ACTUALIZADO);
196
                     layout.repaint();
197

    
198
                     if (event.getEvent().getClickCount() > 1) {
199
                         FLayoutGraphics flg = new FLayoutGraphics(layout);
200
                         flg.openFFrameDialog();
201
                         layout.getLayoutControl().setStatus(LayoutControl.ACTUALIZADO);
202
                         layout.repaint();
203
                     }
204
                 }
205

    
206
                 PluginServices.getMainFrame().enableControls();
207
         }
208
        }
209

    
210
        public void move(PointEvent event) throws BehaviorException {
211
                 Image cursor = null;
212
         Point2D p = event.getPoint();
213
         IFFrame[] fframes=layout.getLayoutContext().getFFrameSelected();
214
         for (int i = 0; i < fframes.length; i++) {
215
             if (fframes[i].getContains(p)!=IFFrame.NOSELECT){
216
                     cursor=fframes[i].getMapCursor(p);
217
             }
218
             if (cursor != null) {
219
                 layout.getLayoutControl().setMapCursor(cursor);
220
             }
221
//             else {
222
//                 layout.setMapCursor(Layout.icrux);
223
//             }
224
         }
225
          }
226

    
227
}