Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFramePicture.java @ 312

History | View | Annotate | Download (5.44 KB)

1
/*
2
 * Created on 20-feb-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
package com.iver.cit.gvsig.gui.layout.fframes;
8

    
9
import com.iver.cit.gvsig.gui.layout.Layout;
10

    
11
import com.iver.mdiApp.App;
12

    
13
import com.iver.utiles.XMLEntity;
14

    
15
import java.awt.Graphics2D;
16
import java.awt.Image;
17
import java.awt.geom.AffineTransform;
18
import java.awt.geom.Rectangle2D;
19
import java.awt.image.BufferedImage;
20

    
21
import javax.swing.ImageIcon;
22

    
23

    
24
/**
25
 * FFrame para introducir una imagen en el Layout.
26
 *
27
 * @author Vicente Caballero Navarro
28
 */
29
public class FFramePicture extends FFrame {
30
    private static final int PRESENTACION = 0;
31
    private static final int BORRADOR = 1;
32
    private static final int ACTIVO = 1;
33
    private static final int SIEMPRE = 0;
34
    private BufferedImage m_image = null;
35
    private int m_quality = PRESENTACION;
36
    private int m_viewing = ACTIVO;
37
    private String m_path = null;
38
        private int num=0;
39
    /**
40
     * Creates a new FFramePicture object.
41
     */
42
    public FFramePicture() {
43
    }
44

    
45
    /**
46
     * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
47
     * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
48
     * de dibujar.
49
     *
50
     * @param g Graphics
51
     * @param at Transformada afin.
52
     * @param rv rect?ngulo sobre el que hacer un clip.
53
     * @param imgBase DOCUMENT ME!
54
     */
55
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
56
        BufferedImage imgBase) {
57
        Rectangle2D.Double r = getBoundingBox(at);
58
        double x = r.getMinX();
59
        double y = r.getMinY();
60
        double w = r.getWidth();
61
        double h = r.getHeight();
62

    
63
        if (intersects(rv,r)) {
64
            if (m_image == null) { //Que no hay una imagen.
65
                drawEmpty(g);
66
            } else {
67
                if ((rv == null) || (getQuality() == PRESENTACION)) {
68
                    double scalex = (double) w / m_image.getWidth(null);
69
                    double scaley = (double) h / m_image.getHeight(null);
70
                    AffineTransform xform = AffineTransform.getScaleInstance(scalex,
71
                            scaley);
72
                    AffineTransform xpos = AffineTransform.getTranslateInstance(x,
73
                            y);
74
                    xpos.concatenate(xform);
75
                    g.drawRenderedImage(m_image, xpos);
76
                } else {
77
                    drawDraft(g);
78
                }
79
            }
80
        }
81
    }
82

    
83
    /**
84
     * Rellena la calidad seg?n el entero que se pasa como par?metro.
85
     *
86
     * @param q entero que representa el tipo de calidad elegido.
87
     */
88
    public void setQuality(int q) {
89
        m_quality = q;
90
    }
91

    
92
    /**
93
     * Devuelve la calidad que est? seleccionada.
94
     *
95
     * @return entero que representa la calidad seleccionada.
96
     */
97
    public int getQuality() {
98
        return m_quality;
99
    }
100

    
101
    /**
102
     * Devuelve un entero que representa la forma en que se actualiza la vista.
103
     *
104
     * @return forma que se actualiza la vista.
105
     */
106
    public int getViewing() {
107
        return m_viewing;
108
    }
109

    
110
    /**
111
     * Rellena la forma de actualizar la vista.
112
     *
113
     * @param v entero que representa la forma de actualizar la vista.
114
     */
115
    public void setViewing(int v) {
116
        m_viewing = v;
117
    }
118

    
119
    /**
120
     * Rellena el nombre de la imagen.
121
     *
122
     * @param path nombre de la imagen.
123
     */
124
    public void setPath(String path) {
125
        m_path = path;
126
    }
127

    
128
    /**
129
     * Devuelve la ruta del fichero.
130
     *
131
     * @return String
132
     */
133
    public String getPath() {
134
        return m_path;
135
    }
136

    
137
    /**
138
     * Rellena la imagen.
139
     *
140
     * @param image
141
     */
142
    public void setImage(BufferedImage image) {
143
        m_image = image;
144
    }
145

    
146
    /**
147
     * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
148
     */
149
    public XMLEntity getXMLEntity() {
150
        XMLEntity xml = super.getXMLEntity();
151
        xml.putProperty("type", Layout.RECTANGLEPICTURE);
152
        xml.putProperty("m_path", m_path);
153
        xml.putProperty("m_quality", m_quality);
154
        xml.putProperty("m_viewing", m_viewing);
155

    
156
        return xml;
157
    }
158

    
159
    /**
160
     * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
161
     *
162
     * @param xml XMLEntity
163
     *
164
     * @return Objeto de esta clase.
165
     */
166
    public static FFramePicture createFFramePicture(XMLEntity xml) {
167
        FFramePicture fframe = new FFramePicture();
168

    
169
        if (xml.getIntProperty("m_Selected") != 0) {
170
            fframe.setSelected(true);
171
        } else {
172
            fframe.setSelected(false);
173
        }
174

    
175
        fframe.m_path = xml.getStringProperty("m_path");
176

    
177
        try {
178
            Image image = new ImageIcon(fframe.m_path).getImage();
179
            BufferedImage bi = new BufferedImage((int) image.getWidth(null),
180
                    (int) image.getHeight(null), BufferedImage.TYPE_INT_RGB);
181
            Graphics2D biContext = bi.createGraphics();
182
            biContext.drawImage(image, 0, 0, null);
183
            fframe.setImage(bi);
184
        } catch (Exception ex) {
185
            App.instance.getNm().addError("Excepci?n :", ex);
186
        }
187

    
188
        fframe.m_quality = xml.getIntProperty("m_quality");
189
        fframe.m_viewing = xml.getIntProperty("m_viewing");
190

    
191
        return fframe;
192
    }
193

    
194
        /**
195
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#updateNum()
196
         */
197
        public void updateNum() {
198
                num=Layout.numPicture++;
199
        }
200
        public int getNum(){
201
                return num;
202
        }
203
}