01: /*
02: * This file is part of the GeOxygene project source files.
03: *
04: * GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
05: * the development and deployment of geographic (GIS) applications. It is a open source
06: * contribution of the COGIT laboratory at the Institut Géographique National (the French
07: * National Mapping Agency).
08: *
09: * See: http://oxygene-project.sourceforge.net
10: *
11: * Copyright (C) 2005 Institut Géographique National
12: *
13: * This library is free software; you can redistribute it and/or modify it under the terms
14: * of the GNU Lesser General Public License as published by the Free Software Foundation;
15: * either version 2.1 of the License, or any later version.
16: *
17: * This library is distributed in the hope that it will be useful, but WITHOUT ANY
18: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19: * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
20: *
21: * You should have received a copy of the GNU Lesser General Public License along with
22: * this library (see file LICENSE if present); if not, write to the Free Software
23: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: *
25: */
26:
27: package fr.ign.cogit.geoxygene.util.viewer;
28:
29: import java.awt.event.ActionEvent;
30: import java.awt.event.ActionListener;
31: import java.io.File;
32: import java.net.URL;
33:
34: import javax.swing.JFileChooser;
35:
36: /**
37: * This class defines actions for open file (menu bar and toolbar).
38: *
39: * @author Thierry Badard & Arnaud Braun
40: * @version 1.0
41: *
42: */
43:
44: class GeOxygeneViewerOpenFileAction implements ActionListener {
45:
46: private ObjectViewerInterface objectViewerInterface;
47:
48: public GeOxygeneViewerOpenFileAction(
49: ObjectViewerInterface objViewerInterface) {
50: this .objectViewerInterface = objViewerInterface;
51: }
52:
53: public void actionPerformed(ActionEvent e) {
54: final JFileChooser fc = new JFileChooser();
55: fc.addChoosableFileFilter(new ShapefileFileFilter());
56: fc.addChoosableFileFilter(new GIFImageFileFilter());
57: fc.addChoosableFileFilter(new JPEGImageFileFilter());
58:
59: int returnVal = fc.showOpenDialog(objectViewerInterface);
60:
61: if (returnVal == JFileChooser.APPROVE_OPTION) {
62: File file = fc.getSelectedFile();
63: String fileExtension = Utils.getExtension(file);
64: String filename = file.getAbsolutePath();
65: System.out.println("\nLoading " + filename + " ...");
66: try {
67: if (fileExtension.equals("shp")) {
68: int dotIndex = filename.lastIndexOf(".");
69: filename = filename.substring(0, dotIndex);
70: objectViewerInterface.addAShapefileTheme(new URL(
71: "file:///" + filename));
72: } else if (fileExtension.equals("jpg")
73: || fileExtension.equals("jpeg")
74: || fileExtension.equals("gif")) {
75: objectViewerInterface.addAnImageTheme(filename, 0,
76: 0, 1, 1);
77: }
78: } catch (Exception ex) {
79: }
80: }
81: }
82: }
|