Statistics
| Revision:

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 / behavior / LayoutViewZoomBehavior.java @ 36648

History | View | Annotate | Download (4.61 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.behavior;
23

    
24
import java.awt.Color;
25
import java.awt.Graphics;
26
import java.awt.Graphics2D;
27
import java.awt.Rectangle;
28
import java.awt.event.MouseEvent;
29
import java.awt.image.BufferedImage;
30

    
31
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
32
import org.gvsig.app.project.documents.layout.tools.listener.LayoutMoveListener;
33
import org.gvsig.app.project.documents.layout.tools.listener.LayoutToolListener;
34
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
35
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent;
36

    
37
/**
38
 * Behaviour que espera un listener de tipo MoveListener.
39
 * 
40
 * @author Vicente Caballero Navarro
41
 */
42
public class LayoutViewZoomBehavior extends LayoutBehavior {
43

    
44
    private LayoutMoveListener listener;
45
    private boolean dragged = false;
46

    
47
    /**
48
     * Crea un nuevo MoveBehavior.
49
     * 
50
     * @param pli
51
     *            listener.
52
     */
53
    public LayoutViewZoomBehavior(LayoutMoveListener lpl) {
54
        listener = lpl;
55
    }
56

    
57
    /**
58
     * @see org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
59
     */
60
    public void paintComponent(Graphics g) {
61
        BufferedImage img = getLayoutControl().getImage();
62
        BufferedImage imgRuler = getLayoutControl().getImgRuler();
63
        g.drawImage(img, 0, 0, getLayoutControl().getComponent());
64
        g.drawImage(imgRuler, 0, 0, getLayoutControl().getComponent());
65
        g.setColor(Color.black);
66
        g.setXORMode(Color.white);
67

    
68
        // Borramos el anterior
69
        Rectangle r = new Rectangle();
70

    
71
        // Dibujamos el actual
72
        if (dragged && (getLayoutControl().getFirstPoint() != null)
73
            && (getLayoutControl().getLastPoint() != null)) {
74
            r.setFrameFromDiagonal(getLayoutControl().getFirstPoint(),
75
                getLayoutControl().getLastPoint());
76
            g.drawRect(r.x, r.y, r.width, r.height);
77
        }
78
        IFFrame[] frames =
79
            getLayoutControl().getLayoutContext().getFFrameSelected();
80
        for (int i = 0; i < frames.length; i++) {
81
            g.setColor(Color.black);
82
            frames[i].drawHandlers((Graphics2D) g);
83
        }
84
        g.setPaintMode();
85
    }
86

    
87
    /**
88
     * @throws BehaviorException
89
     * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
90
     */
91
    public void mousePressed(MouseEvent e) throws BehaviorException {
92
        super.mousePressed(e);
93
        PointEvent event = new PointEvent(e.getPoint(), e);
94
        listener.press(event);
95
    }
96

    
97
    /**
98
     * Reimplementaci?n del m?todo mouseReleased de Behavior.
99
     * 
100
     * @param e
101
     *            MouseEvent
102
     * 
103
     * @throws BehaviorException
104
     *             Excepci?n lanzada cuando el Behavior.
105
     */
106
    public void mouseReleased(MouseEvent e) throws BehaviorException {
107
        super.mouseReleased(e);
108
        PointEvent event = new PointEvent(e.getPoint(), e);
109
        listener.release(event);
110
        dragged = false;
111
    }
112

    
113
    /**
114
     * Reimplementaci?n del m?todo mouseDragged de Behavior.
115
     * 
116
     * @param e
117
     *            MouseEvent
118
     * @throws BehaviorException
119
     */
120
    public void mouseDragged(MouseEvent e) throws BehaviorException {
121
        super.mouseDragged(e);
122
        PointEvent event = new PointEvent(e.getPoint(), e);
123
        listener.drag(event);
124
        dragged = true;
125
    }
126

    
127
    /**
128
     * @see org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener)
129
     */
130
    public void setListener(LayoutToolListener listener) {
131
        this.listener = (LayoutMoveListener) listener;
132
    }
133

    
134
    /**
135
     * @see org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior#getListener()
136
     */
137
    public LayoutToolListener getListener() {
138
        return listener;
139
    }
140
}