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.BufferedReader;
035: import java.io.File;
036: import java.io.FileReader;
037: import java.io.IOException;
038:
039: public class WorldFile {
040:
041: public static final WorldFile DEFAULT = new WorldFile();
042:
043: private String filename;
044: private float xSize = 1;
045: private float ySize = -1;
046: private float rowRotation = 0;
047: private float colRotation = 0;
048:
049: private double xUpperLeft = 0;
050: private double yUpperLeft = 0;
051:
052: private WorldFile() {
053: }
054:
055: /**
056: * bpw: bip, bmp
057: * gfw: gif
058: * tfw: tif
059: * jgw: jpg
060: *
061: * wld: universal
062: *
063: * @param file
064: * @return
065: */
066: public static WorldFile read(File file) throws IOException {
067:
068: FileReader fin = new FileReader(file);
069: BufferedReader in = new BufferedReader(fin);
070: String lineIn = in.readLine();
071: int line = 0;
072:
073: WorldFile wf = new WorldFile();
074: wf.filename = file.getPath();
075:
076: while ((in.ready() || lineIn != null) && line < 6) {
077: if (lineIn != null && !"".equals(lineIn)) {
078: switch (line) {
079: case 0:
080: wf.xSize = Float.valueOf(lineIn.trim())
081: .floatValue();
082: break;
083: case 1:
084: wf.rowRotation = Float.valueOf(lineIn.trim())
085: .floatValue();
086: break;
087: case 2:
088: wf.colRotation = Float.valueOf(lineIn.trim())
089: .floatValue();
090: break;
091: case 3:
092: wf.ySize = Float.valueOf(lineIn.trim())
093: .floatValue();
094: break;
095: case 4:
096: wf.xUpperLeft = Double.valueOf(lineIn.trim())
097: .doubleValue();
098: break;
099: case 5:
100: wf.yUpperLeft = Double.valueOf(lineIn.trim())
101: .doubleValue();
102: break;
103: }
104: }
105: line++;
106: lineIn = null;
107: if (in.ready())
108: lineIn = in.readLine();
109: }
110:
111: return wf;
112: }
113:
114: public float getColRotation() {
115: return colRotation;
116: }
117:
118: public String getFilename() {
119: return filename;
120: }
121:
122: public float getRowRotation() {
123: return rowRotation;
124: }
125:
126: public float getXSize() {
127: return xSize;
128: }
129:
130: public double getXUpperLeft() {
131: return xUpperLeft;
132: }
133:
134: public float getYSize() {
135: return ySize;
136: }
137:
138: public double getYUpperLeft() {
139: return yUpperLeft;
140: }
141: }
|