Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / Export.java @ 312

History | View | Annotate | Download (3.44 KB)

1
/*
2
 * Created on 17-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;
8

    
9
import java.awt.Image;
10
import java.io.File;
11
import java.io.FileOutputStream;
12

    
13
import com.iver.cit.gvsig.gui.View;
14
import com.iver.mdiApp.App;
15
import com.iver.mdiApp.AppStatus;
16
import com.iver.mdiApp.Utilities;
17
import com.iver.mdiApp.plugins.AbstractExtension;
18
import com.iver.mdiApp.plugins.files.FileExtension;
19
import com.iver.mdiApp.plugins.files.SelectedFile;
20
import com.iver.mdiApp.ui.MDIApplicationContext;
21
import com.sun.jimi.core.Jimi;
22
import com.sun.jimi.core.raster.JimiRasterImage;
23

    
24

    
25
/**
26
 * DOCUMENT ME!
27
 *
28
 * @author Fernando Gonz?lez Cort?s
29
 */
30
public class Export extends AbstractExtension implements FileExtension {
31
    /**
32
     * DOCUMENT ME!
33
     *
34
     * @param status DOCUMENT ME!
35
     * @param s DOCUMENT ME!
36
     *
37
     * @throws Exception DOCUMENT ME!
38
     */
39
    public void updateUI(AppStatus status, String s) throws Exception {
40
        SelectedFile sf = App.instance.getMDIContext().showFileChooser(this,
41
                new String[] { "bmp", "png", "jpg" },
42
                new String[] {
43
                    Utilities.getMessage(this, "bmp"),
44
                    Utilities.getMessage(this, "png"),
45
                    Utilities.getMessage(this, "jpg")
46
                }, Utilities.getMessage(this, "exportar"), true,
47
                MDIApplicationContext.FILES_AND_DIRECTORIES);
48

    
49
        if (sf != null) {
50
            sf.write(((View) status.getActiveView()).getImage());
51
        }
52
    }
53

    
54
    /**
55
     * DOCUMENT ME!
56
     *
57
     * @return DOCUMENT ME!
58
     */
59
    public boolean isEnabled() {
60
        View f = (View) App.instance.getMDIContext().getActiveView();
61

    
62
        if (f == null) {
63
            return false;
64
        }
65

    
66
        return f.getModel().getMapContext().getLayers().getActives().length > 0;
67
    }
68

    
69
    /**
70
     * DOCUMENT ME!
71
     *
72
     * @return DOCUMENT ME!
73
     */
74
    public boolean isVisible() {
75
        com.iver.mdiApp.ui.MDIManager.View f = App.instance.getMDIContext()
76
                                                           .getActiveView();
77

    
78
        if (f == null) {
79
            return false;
80
        }
81

    
82
        return (f.getClass() == View.class);
83
    }
84

    
85
    /**
86
     * @see com.iver.mdiApp.FileListener#readFile(java.io.File)
87
     */
88
    public Object read(File f) {
89
        return null;
90
    }
91

    
92
    /**
93
     * @see com.iver.mdiApp.FileListener#writeFile(java.io.File)
94
     */
95
    public void write(File f, Object object) {
96
        Image tempImage;
97

    
98
        try {
99
            tempImage = (Image) object;
100

    
101
            JimiRasterImage jrf = Jimi.createRasterImage(tempImage.getSource());
102
            String tempName = f.getName().toUpperCase().trim();
103

    
104
            if (tempName.endsWith(".JPG")) {
105
                FileOutputStream fout = new FileOutputStream(f);
106
                Jimi.putImage("image/jpg", jrf, fout);
107
                fout.close();
108
            } else if (tempName.endsWith(".PNG")) {
109
                FileOutputStream fout = new FileOutputStream(f);
110
                Jimi.putImage("image/png", jrf, fout);
111
                fout.close();
112
            } else if (tempName.endsWith(".BMP")) {
113
                FileOutputStream fout = new FileOutputStream(f);
114
                Jimi.putImage("image/bmp", jrf, fout);
115
                fout.close();
116
            }
117
        } catch (Exception e) {
118
            System.out.println("Exception   " + e);
119
        }
120
    }
121
}