Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / tools / behavior / LayoutViewZoomBehavior.java @ 10626

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

    
43
import java.awt.Color;
44
import java.awt.Graphics;
45
import java.awt.Graphics2D;
46
import java.awt.Rectangle;
47
import java.awt.event.MouseEvent;
48
import java.awt.image.BufferedImage;
49

    
50
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
51
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
52
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
53
import com.iver.cit.gvsig.project.documents.layout.tools.listener.LayoutMoveListener;
54
import com.iver.cit.gvsig.project.documents.layout.tools.listener.LayoutToolListener;
55

    
56

    
57
/**
58
 * Behaviour que espera un listener de tipo MoveListener.
59
 *
60
 * @author Vicente Caballero Navarro
61
 */
62
public class LayoutViewZoomBehavior extends LayoutBehavior {
63
        private LayoutMoveListener listener;
64
        private boolean dragged=false;
65
        /**
66
         * Crea un nuevo MoveBehavior.
67
         *
68
         * @param pli listener.
69
         */
70
        public LayoutViewZoomBehavior(LayoutMoveListener lpl) {
71
                listener = lpl;
72
        }
73

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

    
85
                // Borramos el anterior
86
                Rectangle r = new Rectangle();
87

    
88
                // Dibujamos el actual
89
                if (dragged && (getLayoutControl().getFirstPoint() != null) && (getLayoutControl().getLastPoint() != null)) {
90
                        r.setFrameFromDiagonal(getLayoutControl().getFirstPoint(), getLayoutControl().getLastPoint());
91
                        g.drawRect(r.x, r.y, r.width, r.height);
92
                }
93
                 IFFrame[] frames = getLayoutControl().getLayoutContext().getFFrameSelected();
94
                for (int i = 0; i < frames.length; i++) {
95
                    g.setColor(Color.black);
96
                    frames[i].drawHandlers((Graphics2D) g);
97
                }
98
                g.setPaintMode();
99
        }
100

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

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

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

    
138
        /**
139
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener)
140
         */
141
        public void setListener(LayoutToolListener listener) {
142
                this.listener = (LayoutMoveListener) listener;
143
        }
144

    
145
        /**
146
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
147
         */
148
        public LayoutToolListener getListener() {
149
                return listener;
150
        }
151
}