Statistics
| Revision:

svn-document-layout / branches / usability_v2 / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / tools / behavior / LayoutViewMoveBehavior.java @ 142

History | View | Annotate | Download (5.09 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.event.MouseEvent;
28
import java.awt.geom.Rectangle2D;
29

    
30
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
31
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap;
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 LayoutViewMoveBehavior extends LayoutBehavior {
43

    
44
    private LayoutMoveListener listener;
45

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

    
56
    /**
57
     * @see org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
58
     */
59
    public void paintComponent(Graphics g) {
60
            IFFrameUseFMap[] fframes = getLayoutControl().getLayoutContext().getSelectedFFrames(IFFrameUseFMap.class);
61
        for (int i = 0; i < fframes.length; i++) {
62
                IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i];
63
                Rectangle2D.Double rec =
64
                                ((IFFrame) fframe).getBoundingBox(getLayoutControl()
65
                                                .getAT());
66

    
67
                if (getLayoutControl().getImage() != null) {
68
                        rec =
69
                                        (Rectangle2D.Double) rec
70
                                        .createIntersection(getLayoutControl()
71
                                                        .getComponent().getVisibleRect());
72
                }
73

    
74
                if (fframe.getBufferedImage() != null) {
75
                        getLayoutControl().getLayoutDraw().drawHandlers(
76
                                        (Graphics2D) g, Color.black);
77
                        g.clipRect((int) rec.x, (int) rec.y, (int) rec.width,
78
                                        (int) rec.height);
79

    
80
                        Rectangle2D.Double r1 =
81
                                        ((IFFrame) fframe)
82
                                        .getBoundingBox(getLayoutControl().getAT());
83
                        g.drawImage(fframe.getBufferedImage(), (int) r1.getX()
84
                                        + getLayoutControl().getLastPoint().x
85
                                        - getLayoutControl().getPointAnt().x,
86
                                        (int) r1.getY()
87
                                        + getLayoutControl().getLastPoint().y
88
                                        - getLayoutControl().getPointAnt().y,
89
                                        getLayoutControl().getComponent());
90

    
91
                        fframe.refresh();
92
                }
93
        }
94

    
95
        // g.setClip(rClip);
96
        getLayoutControl().getLayoutDraw().drawHandlers((Graphics2D) g,
97
            Color.black);
98
        g.drawImage(getLayoutControl().getImgRuler(), 0, 0, getLayoutControl()
99
            .getComponent());
100

    
101
    }
102

    
103
    /**
104
     * @throws BehaviorException
105
     * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
106
     */
107
    public void mousePressed(MouseEvent e) throws BehaviorException {
108
        super.mousePressed(e);
109
        PointEvent event = new PointEvent(e.getPoint(), e);
110
        listener.press(event);
111
    }
112

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

    
127
    }
128

    
129
    /**
130
     * Reimplementaci?n del m?todo mouseDragged de Behavior.
131
     * 
132
     * @param e
133
     *            MouseEvent
134
     * @throws BehaviorException
135
     */
136
    public void mouseDragged(MouseEvent e) throws BehaviorException {
137
        super.mouseDragged(e);
138
        PointEvent event = new PointEvent(e.getPoint(), e);
139
        listener.drag(event);
140
    }
141

    
142
    /**
143
     * @see org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener)
144
     */
145
    public void setListener(LayoutToolListener listener) {
146
        this.listener = (LayoutMoveListener) listener;
147
    }
148

    
149
    /**
150
     * @see org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior#getListener()
151
     */
152
    public LayoutToolListener getListener() {
153
        return listener;
154
    }
155
}