001: package com.vividsolutions.jump.workbench.imagery.graphic;
002:
003: /*
004: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
005: * for visualizing and manipulating spatial features with geometry and attributes.
006: *
007: * Copyright (C) 2003 Vivid Solutions
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; either version 2
012: * of the License, or (at your option) any later version.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with this program; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * For more information, contact:
024: *
025: * Vivid Solutions
026: * Suite #1A
027: * 2328 Government Street
028: * Victoria BC V8T 5G5
029: * Canada
030: *
031: * (250)385-6040
032: * www.vividsolutions.com
033: */
034: import java.io.File;
035: import java.io.FilenameFilter;
036: import java.io.IOException;
037:
038: import com.vividsolutions.jump.workbench.imagery.ReferencedImage;
039: import com.vividsolutions.jump.workbench.imagery.ReferencedImageFactory;
040:
041: public class GraphicImageFactory implements ReferencedImageFactory {
042: public String getTypeName() {
043: return "Picture";
044: }
045:
046: public ReferencedImage createImage(String location) {
047:
048: WorldFile wf = findWF(location);
049:
050: return new GraphicImage(new File(location), wf);
051: }
052:
053: private WorldFile findWF(final String location) {
054: File f = new File(location);
055: if (f != null && f.exists()) {
056: File parent = f.getParentFile();
057: String name = f.getName();
058:
059: int i = name.indexOf(".");
060: name = i == -1 ? name : name.substring(0, i);
061: final String nm = name;
062: File[] children = parent.listFiles(new FilenameFilter() {
063: public boolean accept(File dir, String name) {
064: String suffix = name
065: .substring(name.indexOf(".") + 1);
066: if (suffix != null)
067: if (suffix.equalsIgnoreCase("jgw")
068: || suffix.equalsIgnoreCase("tfw")
069: || suffix.equalsIgnoreCase("gfw")
070: || suffix.equalsIgnoreCase("bpw"))
071: return name.startsWith(nm);
072: if (name != null
073: && name.equalsIgnoreCase(location + "w"))
074: return true;
075: return false;
076: }
077: });
078: if (children != null) {
079: for (int c = 0; c < children.length; c++) {
080: if (children[c].exists()
081: && !children[c].isDirectory()) {
082: WorldFile wf;
083: try {
084: wf = WorldFile.read(children[c]);
085: if (wf != null)
086: return wf;
087: } catch (IOException e) {
088: // eat it ... we are guessing here
089: }
090: }
091: }
092: }
093: }
094: return null;
095: }
096:
097: public String getDescription() {
098: return getTypeName();
099: }
100:
101: public String[] getExtensions() {
102: return new String[] { "gif", "png", "jpg", "jpeg" };
103: }
104:
105: public boolean isEditableImage(String location) {
106: return true;
107: }
108:
109: public boolean isAvailable() {
110: Class c = null;
111: try {
112: c = this .getClass().getClassLoader().loadClass(
113: "javax.media.jai.JAI");
114: } catch (ClassNotFoundException e) {
115: // eat it
116: return false;
117: }
118:
119: return c != null;
120: }
121:
122: }
|