Revision 1738

View differences:

trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/tools/behavior/LayoutRectangleByTwoPointsBehavior.java
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.behavior;
23

  
24
import java.awt.Color;
25
import java.awt.Graphics;
26
import java.awt.Graphics2D;
27
import java.awt.Point;
28
import java.awt.Rectangle;
29
import java.awt.event.MouseEvent;
30
import java.awt.geom.AffineTransform;
31
import java.awt.geom.Point2D;
32
import java.awt.geom.Rectangle2D;
33
import java.awt.image.BufferedImage;
34
import org.gvsig.app.project.documents.layout.FLayoutUtilities;
35
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
36
import org.gvsig.app.project.documents.layout.tools.listener.LayoutRectangleListener;
37
import org.gvsig.app.project.documents.layout.tools.listener.LayoutToolListener;
38
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
39
import org.gvsig.fmap.geom.GeometryLocator;
40
import org.gvsig.fmap.geom.GeometryManager;
41
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
42
import org.gvsig.fmap.geom.primitive.Envelope;
43
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
44
import org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent;
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

  
48
/**
49
 * Behaviour que espera un listener de tipo LayoutRectangleListener.
50
 * 
51
 * @author Vicente Caballero Navarro
52
 */
53
public class LayoutRectangleByTwoPointsBehavior extends LayoutBehavior {
54

  
55
    private static final GeometryManager geomManager = GeometryLocator
56
        .getGeometryManager();
57
    private static final Logger logger = LoggerFactory
58
        .getLogger(LayoutRectangleByTwoPointsBehavior.class);
59
    private LayoutRectangleListener listener;
60
    
61
    boolean findingSecondPoint = false;
62
    private Point firstPoint;
63

  
64

  
65
    /**
66
     * Crea un nuevo RectangleBehavior.
67
     * 
68
     * @param zili
69
     *            listener.
70
     */
71
    public LayoutRectangleByTwoPointsBehavior(LayoutRectangleListener lrl) {
72
        listener = lrl;
73
    }
74

  
75
    /**
76
     * @see org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
77
     */
78
    @Override
79
    public void paintComponent(Graphics g) {
80
        BufferedImage img = getLayoutControl().getImage();
81
        BufferedImage imgRuler = getLayoutControl().getImgRuler();
82
        g.drawImage(img, 0, 0, getLayoutControl().getComponent());
83
        g.drawImage(imgRuler, 0, 0, getLayoutControl().getComponent());
84
        g.setColor(Color.black);
85
        g.setXORMode(Color.white);
86

  
87
        // Borramos el anterior
88
        Rectangle r = new Rectangle();
89

  
90
        // Dibujamos el actual
91
        if (findingSecondPoint && (getLayoutControl().getFirstPoint() != null)
92
            && (getLayoutControl().getLastPoint() != null)) {
93
            r.setFrameFromDiagonal(getLayoutControl().getFirstPoint(),
94
                getLayoutControl().getLastPoint());
95
            g.drawRect(r.x, r.y, r.width, r.height);
96
        }
97
        IFFrame[] frames =
98
            getLayoutControl().getLayoutContext().getSelectedFFrames();
99
        for (IFFrame frame : frames) {
100
            g.setColor(Color.black);
101
            frame.drawHandlers((Graphics2D) g);
102
        }
103
        g.setPaintMode();
104
    }
105

  
106
    /**
107
     * Reimplementaci?n del m?todo mousePressed de Behavior.
108
     * 
109
     * @param e
110
     *            MouseEvent
111
     * @throws BehaviorException
112
     */
113
    @Override
114
    public void mousePressed(MouseEvent e) throws BehaviorException {
115
    }
116

  
117
    /**
118
     * Reimplementaci?n del m?todo mouseReleased de Behavior.
119
     * 
120
     * @param e
121
     *            MouseEvent
122
     * 
123
     * @throws BehaviorException
124
     *             Excepci?n lanzada cuando el Behavior.
125
     */
126
    @Override
127
    public void mouseReleased(MouseEvent e) throws BehaviorException {
128
    }
129
    
130
    @Override
131
    public void mouseClicked(MouseEvent e) throws BehaviorException {
132

  
133
        if (e.getButton() != MouseEvent.BUTTON1) {
134
            return;
135
        }
136
        
137
        if(!findingSecondPoint) {
138
            getLayoutControl().setPointAnt();
139
            getLayoutControl().setFirstPoint();
140
            this.firstPoint = getLayoutControl().getFirstPoint();
141

  
142
            if (listener.cancelDrawing()) {
143
                // getLayout().cancelDrawing();
144
            }
145
            getLayoutControl().repaint();
146
            this.findingSecondPoint = true;
147
            return;
148
        }
149
        
150
        getLayoutControl().setLastPoint();
151
        getLayoutControl().setPointAnt();
152
        getLayoutControl().setPosition(firstPoint);
153
        getLayoutControl().setFirstPoint();
154

  
155
        Point2D p1;
156
        Point2D p2;
157
        Point pScreen = getLayoutControl().getLastPoint();
158

  
159
        AffineTransform at = getLayoutControl().getAT();
160

  
161
        p1 =
162
            FLayoutUtilities.toSheetPoint(getLayoutControl().getFirstPoint(),
163
                at);
164
        p2 = FLayoutUtilities.toSheetPoint(pScreen, at);
165

  
166
        if (e.getButton() == MouseEvent.BUTTON1) {
167
            // Fijamos el nuevo extent
168
            // Rectangle2D.Double r = new Rectangle2D.Double();
169
            // r.setFrameFromDiagonal(p1, p2);
170
            Envelope r;
171
            try {
172
                r =
173
                    geomManager.createEnvelope(p1.getX(), p1.getY(), p2.getX(),
174
                        p2.getY(), SUBTYPES.GEOM2D);
175
                Rectangle2D rectPixel = new Rectangle();
176
                rectPixel.setFrameFromDiagonal(getLayoutControl()
177
                    .getFirstPoint(), pScreen);
178

  
179
                EnvelopeEvent event = new EnvelopeEvent(r, e, rectPixel);
180
                listener.rectangle(event);
181
            } catch (CreateEnvelopeException e1) {
182
                logger.error("Error creating the envelope", e);
183
            }
184
        }
185
        findingSecondPoint = false;
186
    }
187
    
188
    
189

  
190
    /**
191
     * Reimplementaci?n del m?todo mouseDragged de Behavior.
192
     * 
193
     * @param e
194
     *            MouseEvent
195
     * @throws BehaviorException
196
     */
197
    @Override
198
    public void mouseDragged(MouseEvent e) throws BehaviorException {
199
    }
200

  
201
    @Override
202
    public void mouseMoved(MouseEvent e) throws BehaviorException {
203
        if (e.getButton() != MouseEvent.NOBUTTON) {
204
            return;
205
        }
206
        if (findingSecondPoint) {
207
            getLayoutControl().setLastPoint();
208
            getLayoutControl().repaint();
209
        }
210
    }
211

  
212
    /**
213
     * @see org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener)
214
     */
215
    public void setListener(LayoutToolListener listener) {
216
        this.listener = (LayoutRectangleListener) listener;
217
    }
218

  
219
    /**
220
     * @see org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior#getListener()
221
     */
222
    @Override
223
    public LayoutToolListener getListener() {
224
        return listener;
225
    }
226

  
227
    @Override
228
    public boolean isAdjustable() {
229
        return true;
230
    }
231
}
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/DefaultLayoutControl.java
68 68
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutEditBehavior;
69 69
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutMoveBehavior;
70 70
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutPointBehavior;
71
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutRectangleBehavior;
71
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutRectangleByTwoPointsBehavior;
72 72
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutSelectBehavior;
73 73
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutViewMoveBehavior;
74 74
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutViewZoomBehavior;
......
127 127
    private FLayoutZooms layoutZooms;
128 128
//	private LayoutPanel layoutPanel;
129 129

  
130
    private static Cursor transparentCursor = Toolkit.getDefaultToolkit()
130
    private static final Cursor transparentCursor = Toolkit.getDefaultToolkit()
131 131
        .createCustomCursor(
132 132
            Toolkit.getDefaultToolkit().createImage(
133 133
                new MemoryImageSource(16, 16, new int[16 * 16], 0, 16)),
......
163 163
        addLayoutTool("layoutzoomout", new LayoutZoomBehavior(lzol));
164 164

  
165 165
        LayoutAddViewListenerImpl lavl = new LayoutAddViewListenerImpl(layoutPanel);
166
        addLayoutTool("layoutaddview", new LayoutRectangleBehavior(lavl));
166
        addLayoutTool("layoutaddview", new LayoutRectangleByTwoPointsBehavior(lavl));
167 167

  
168 168
        LayoutAddOverViewListenerImpl laovl =
169 169
            new LayoutAddOverViewListenerImpl(layoutPanel);
170
        addLayoutTool("layoutaddoverview", new LayoutRectangleBehavior(laovl));
170
        addLayoutTool("layoutaddoverview", new LayoutRectangleByTwoPointsBehavior(laovl));
171 171

  
172 172
        LayoutAddPictureListenerImpl lapl =
173 173
            new LayoutAddPictureListenerImpl(layoutPanel);
174
        addLayoutTool("layoutaddpicture", new LayoutRectangleBehavior(lapl));
174
        addLayoutTool("layoutaddpicture", new LayoutRectangleByTwoPointsBehavior(lapl));
175 175

  
176 176
        LayoutAddNorthListenerImpl lanorthl =
177 177
            new LayoutAddNorthListenerImpl(layoutPanel);
178
        addLayoutTool("layoutaddnorth", new LayoutRectangleBehavior(lanorthl));
178
        addLayoutTool("layoutaddnorth", new LayoutRectangleByTwoPointsBehavior(lanorthl));
179 179

  
180 180
        LayoutAddScaleListenerImpl lasl =
181 181
            new LayoutAddScaleListenerImpl(layoutPanel);
182
        addLayoutTool("layoutaddscale", new LayoutRectangleBehavior(lasl));
182
        addLayoutTool("layoutaddscale", new LayoutRectangleByTwoPointsBehavior(lasl));
183 183

  
184 184
        LayoutAddLegendListenerImpl lall =
185 185
            new LayoutAddLegendListenerImpl(layoutPanel);
186
        addLayoutTool("layoutaddlegend", new LayoutRectangleBehavior(lall));
186
        addLayoutTool("layoutaddlegend", new LayoutRectangleByTwoPointsBehavior(lall));
187 187

  
188 188
        LayoutAddTextListenerImpl latl = new LayoutAddTextListenerImpl(layoutPanel);
189
        addLayoutTool("layoutaddtext", new LayoutRectangleBehavior(latl));
189
        addLayoutTool("layoutaddtext", new LayoutRectangleByTwoPointsBehavior(latl));
190 190

  
191 191
        LayoutAddBoxListenerImpl labl = new LayoutAddBoxListenerImpl(layoutPanel);
192
        addLayoutTool("layoutaddbox", new LayoutRectangleBehavior(labl));
192
        addLayoutTool("layoutaddbox", new LayoutRectangleByTwoPointsBehavior(labl));
193 193

  
194 194
        LayoutAddPointListenerImpl lapointl =
195 195
            new LayoutAddPointListenerImpl(layoutPanel);
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/layout/mapbox/MapBoxUtils.java
9 9
import org.gvsig.app.project.documents.layout.LayoutControl;
10 10
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
11 11
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutRectangleBehavior;
12
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutRectangleByTwoPointsBehavior;
12 13
import org.gvsig.layout.mapbox.fframe.FFrameMapBox;
13 14
import org.gvsig.layout.mapbox.fframe.FFrameMapBoxFactory;
14 15
import org.gvsig.layout.mapbox.model.CellImpl;
......
34 35
    
35 36
    public static void addLayoutTool(LayoutPanel layoutPanel, LayoutControl control) {
36 37
        LayoutAddMapBoxListenerImpl labl = new LayoutAddMapBoxListenerImpl(layoutPanel);
37
        control.addLayoutTool("layoutaddmapbox", new LayoutRectangleBehavior(labl));
38
        control.addLayoutTool("layoutaddmapbox", new LayoutRectangleByTwoPointsBehavior(labl));
38 39
        LayoutEditMapBoxListenerImpl leditMapBoxListener = new LayoutEditMapBoxListenerImpl(layoutPanel);
39 40
        control.addLayoutTool("layouteditmapbox", new LayoutEditMapBoxBehavior(leditMapBoxListener));
40 41
    }
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/resources-plugin/config.xml
248 248
                tooltip="insertar_texto"
249 249
                action-command="layout-insert-text"
250 250
                icon="layout-insert-text"
251
                position="700401300"
251
                position="700401100"
252 252
            />
253 253
            <action
254 254
                name="layout-insert-point"
......
256 256
                tooltip="insertar_punto"
257 257
                action-command="layout-insert-point"
258 258
                icon="layout-insert-point"
259
                position="700400800"
259
                position="700400500"
260 260
            />
261 261
            <action
262 262
                name="layout-insert-rectangle"
......
264 264
                tooltip="insertar_rectangulo"
265 265
                action-command="layout-insert-rectangle"
266 266
                icon="layout-insert-rectangle"
267
                position="700401100"
267
                position="700401000"
268 268
            />
269 269
            <action
270 270
                name="layout-insert-circle"
......
272 272
                tooltip="insertar_circulo"
273 273
                action-command="layout-insert-circle"
274 274
                icon="layout-insert-circle"
275
                position="700400200"
275
                position="700400900"
276 276
            />
277 277
            <action
278 278
                name="layout-insert-line"
......
280 280
                tooltip="insertar_linea"
281 281
                action-command="layout-insert-line"
282 282
                icon="layout-insert-line"
283
                position="700400500"
283
                position="700400600"
284 284
            />
285 285
            <action
286 286
                name="layout-insert-polyline"
......
288 288
                tooltip="insertar_polilinea"
289 289
                action-command="layout-insert-polyline"
290 290
                icon="layout-insert-polyline"
291
                position="700401000"
291
                position="700400700"
292 292
            />
293 293
            <action
294 294
                name="layout-insert-polygon"
......
296 296
                tooltip="insertar_poligono"
297 297
                action-command="layout-insert-polygon"
298 298
                icon="layout-insert-polygon"
299
                position="700400900"
299
                position="700400800"
300 300
            />
301 301
            <action
302 302
                name="layout-insert-image"
......
304 304
                tooltip="insertar_imagen"
305 305
                action-command="layout-insert-image"
306 306
                icon="layout-insert-image"
307
                position="700400300"
307
                position="700401200"
308 308
            />
309 309
            <action
310 310
                name="layout-insert-view"

Also available in: Unified diff