Revision 7012

View differences:

tags/vBefore3D_Branch/applications/appgvSIG/build.number
1
#Build Number for ANT. Do not edit!
2
#Tue Aug 08 12:48:13 CEST 2006
3
build.number=859
0 4

  
tags/vBefore3D_Branch/applications/appgvSIG/distFiles/llig-me.txt
1
llig-me.txt
2

  
3
**************************
4

  
5
gvSIG v 0.4
6

  
7
Requisits de la instal?laci?:
8

  
9
    - M?quina Virtual Java 1.4.2 o superior instal?lada (http://java.sun.com).
10

  
11
Requisits de l'aplicaci?:
12

  
13
    - Sistema
14

  
15
        ? M?nims: Pentium III / 256 MB RAM.
16

  
17
        ? Recomanables: Pentium IV / 512 MB RAM.
18

  
19
        ? Sistemes operatius: plataformes Windows i Linux.
20
        Provat en Win98/XP, Linux Suse 8.2/9.0/9.2 i Linux Debian(Lliurex).
21

  
22

  
23
    - Programari instal?lat (disponible en http://www.gvsig.gva.es o en http://java.sun.com)
24

  
25
        ? M?quina Virtual Java 1.4.2 (06 o superior).
26

  
27
        ? JAI (Java Advanced Imaging).
28

  
29
        ? JAI Image I/O.
30

  
31

  
32
Nota: les libreries JAI i JAI Image I/O han d'estar instal?lades sobre la M?quina Virtual Java que gvSIG utilitze en l'execuci?. Si s'instal?la una nova JVM en el sistema i s'usa per a executar gvSIG ser? indispensable instal?lar les llibreries sobre esta.
33

  
34

  
35
M?s informaci? ? suport:
36

  
37
    Web oficial del projecte:
38

  
39
        http://www.gvsig.gva.es
40

  
41
    Llistes de distribuci?:
42

  
43
        http://runas.cap.gva.es/mailman/listinfo/gvsig_usuarios (suport per a usuaris).
44

  
45
        http://runas.cap.gva.es/mailman/listinfo/gvsig_desarrolladores (suport per a desenvolupadors).
46

  
47
        http://runas.cap.gva.es/mailman/listinfo/gvsig_english (suport per a usuaris o desenvolupadors de parla no-hispana).
48

  
0 49

  
tags/vBefore3D_Branch/applications/appgvSIG/distFiles/LEEME.txt
1
gvSIG v 0.2.0 beta.
2

  
3
Prerequisitos:
4
  - Java instalado (JRE 1.4.2 o superior) (http://java.sun.com)
5
  - JAI + JAI image I/O (http://java.sun.com)
6
  - librer?as din?micas para los ECW: vienen con cualquier
7
    producto de ERMAPPER y son gratuitas (Actualmente solo hay disponibles para
8
    MS windows)(http://www.ermapper.com)
9
  
10
Instalaci?n:
11

  
12
	Descomprimir el archivo zip completo en el directorio deseado
13
	
14
Ejecuci?n
15
	En windows: gvSIG.bat
16
	En linux:  gvSIG.sh
17

  
18
M?s informaci?n:
19
	gvsig@gva.es
0 20

  
tags/vBefore3D_Branch/applications/appgvSIG/src/log4j.properties
1
log4j.rootLogger=info, stdout
2

  
3
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
4
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
5

  
6
# Pattern to output the caller's file name and line number.
7
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
8

  
9
log4j.appender.R=org.apache.log4j.RollingFileAppender
10
log4j.appender.R.File=application.log
11

  
12
log4j.appender.R.MaxFileSize=100KB
13
# Keep one backup file
14
log4j.appender.R.MaxBackupIndex=1
15

  
16
log4j.appender.R.layout=org.apache.log4j.PatternLayout
17
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
18

  
0 19

  
tags/vBefore3D_Branch/applications/appgvSIG/src/com/vividsolutions/jump/util/UniqueList.java
1

  
2
/*
3
 * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI 
4
 * for visualizing and manipulating spatial features with geometry and attributes.
5
 *
6
 * Copyright (C) 2003 Vivid Solutions
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 * 
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
 * 
22
 * For more information, contact:
23
 *
24
 * Vivid Solutions
25
 * Suite #1A
26
 * 2328 Government Street
27
 * Victoria BC  V8T 5G5
28
 * Canada
29
 *
30
 * (250)385-6040
31
 * www.vividsolutions.com
32
 */
33

  
34
package com.vividsolutions.jump.util;
35

  
36
import java.util.*;
37

  
38

  
39
/**
40
 * A List that ignores duplicates. Note: performance is not optimized - a simple linear
41
 * search is performed.
42
 */
43
public class UniqueList implements List {
44
    private List list;
45

  
46
    /**
47
     * Creates a UniqueList.
48
     */
49
    public UniqueList() {
50
        this(new ArrayList());
51
    }
52

  
53
    /**
54
     * Creates a UniqueList backed by the given List.
55
     * @param list a List that will be this UniqueList's underlying List
56
     */
57
    public UniqueList(List list) {
58
        this.list = list;
59
    }
60

  
61
    public int size() {
62
        return list.size();
63
    }
64

  
65
    public boolean isEmpty() {
66
        return list.isEmpty();
67
    }
68

  
69
    public boolean contains(Object o) {
70
        return list.contains(o);
71
    }
72

  
73
    public Iterator iterator() {
74
        return list.iterator();
75
    }
76

  
77
    public Object[] toArray() {
78
        return list.toArray();
79
    }
80

  
81
    public Object[] toArray(Object[] a) {
82
        return list.toArray(a);
83
    }
84

  
85
    public boolean add(Object o) {
86
        if (list.contains(o)) {
87
            return false;
88
        }
89

  
90
        return list.add(o);
91
    }
92

  
93
    public boolean remove(Object o) {
94
        return list.remove(o);
95
    }
96

  
97
    public boolean containsAll(Collection c) {
98
        return list.containsAll(c);
99
    }
100

  
101
    public boolean addAll(Collection c) {
102
    	return addAll(size(), c);
103
    }
104

  
105
    public boolean addAll(int index, Collection c) {
106
		ArrayList itemsToAdd = new ArrayList(c);
107
		itemsToAdd.removeAll(this);
108
		return list.addAll(index, itemsToAdd);    	
109
    }
110

  
111
    public boolean removeAll(Collection c) {
112
        return list.removeAll(c);
113
    }
114

  
115
    public boolean retainAll(Collection c) {
116
        return list.retainAll(c);
117
    }
118

  
119
    public void clear() {
120
        list.clear();
121
    }
122

  
123
    public boolean equals(Object o) {
124
        return list.equals(o);
125
    }
126

  
127
    public Object get(int index) {
128
        return list.get(index);
129
    }
130

  
131
    public Object set(int index, Object element) {
132
        return list.set(index, element);
133
    }
134

  
135
    public void add(int index, Object element) {
136
        if (list.contains(element)) {
137
            return;
138
        }
139

  
140
        list.add(index, element);
141
    }
142

  
143
    public Object remove(int index) {
144
        return list.remove(index);
145
    }
146

  
147
    public int indexOf(Object o) {
148
        return list.indexOf(o);
149
    }
150

  
151
    public int lastIndexOf(Object o) {
152
        return list.lastIndexOf(o);
153
    }
154

  
155
    public ListIterator listIterator() {
156
        return list.listIterator();
157
    }
158

  
159
    public ListIterator listIterator(int index) {
160
        return list.listIterator(index);
161
    }
162

  
163
    public List subList(int fromIndex, int toIndex) {
164
        return list.subList(fromIndex, toIndex);
165
    }
166
}
0 167

  
tags/vBefore3D_Branch/applications/appgvSIG/src/com/vividsolutions/jump/util/FlexibleDateParser.txt
1
#Forget 2-digit year specifications ("yyyy"). Otherwise yyMMdd will 
2
#consider "20040203" to be invalid (a valid "200402" with a couple of
3
#extra characters). (FlexibleDateParser skips patterns that don't
4
#parse *all* the characters). Anyway, FlexibleDateParser also tries
5
#the (deprecated) Date constructor, and that should parse the most
6
#common 2-digit-year formats. [Jon Aquino]
7

  
8
#Lines beginning with "#" and blank lines are ignored. [Jon Aquino]
9

  
10
#Earlier patterns have precedence over later patterns. [Jon Aquino]
11

  
12
#####################################################################
13
#Popular SimpleDateFormat strings, culled from the top 1000 hits on 
14
#Google and Google Groups on 21 May 2003 [Jon Aquino]
15

  
16
#Multiple Google hits [Jon Aquino]
17

  
18
yyyy-MM-dd
19
yyyyMMdd
20
dd.MM.yyyy
21

  
22
#Although dd/MM/yyyy had a few more hits in Google, give priority to
23
#MM/dd/yyyy because JUMP will be used mainly in North America. 
24
#Anyway, yyyy-MM-dd should be preferred to both. [Jon Aquino]
25
MM/dd/yyyy
26
dd/MM/yyyy
27

  
28
yyyy-MM-dd HH:mm:ss
29
yyyyMMddHHmmss
30
MMMM d, yyyy
31
yyyy.MM.dd hh:mm:ss
32
yyyy/MM/dd
33
HH:mm
34
MMddyyyy
35
HH:mm:ss
36
ddMMyyyy
37
dd-MMM-yyyy
38
dd-MM-yyyy
39
dd MMM yyyy
40
yyyyMMddHHmmssSSS
41
yyyyMMddHHmm
42
yyyy/MM/dd HH:mm:ss
43
yyyy/MM/dd HH:mm
44
yyyy.MM.dd
45
hh:mm a
46
h:mmaa
47
MMM d, yyyy
48
HHmm
49

  
50
#Single Google hits [Jon Aquino]
51

  
52
yyyyMMddhhmmss
53
yyyy_MM_dd.hh_mm_ss_a.zzz
54
yyyy_MM_dd
55
yyyyMMddhhmmssSSS
56
yyyyMMddHHss
57
yyyyMMddHHmmsszzzzHHmm
58
yyyy/MM/dd/HH/mm/ss/SS
59
yyyy.MMM.dd HH:mm:ss.SSS z
60
yyyy.MM.dd HH:mm:ss
61
yyyy-Md HH:mm:ss
62
yyyy-MM-dd-G-hh-mm-ss-z
63
yyyy-MM-dd'T'HH:mm:ss
64
yyyy-MM-dd hh:mm:ss
65
yyyy-MM-dd HH:mm:sszzzzzzzzz
66
yyyy-MM-dd HH:mm:sszzz
67
yyyy-MM-dd HH:mm:ss.SSSzzzzzzzzz
68
yyyy-MM-dd HH:mm:ss.SSSSSS z
69
yyyy-MM-dd HH:mm:ss.SSS z
70
yyyy-MM-dd HH:mm:ss z
71
yyyy-MM-dd HH:mm
72
yyyy-MM-d HH:mm:ss
73
yyyy-DDD/HH:mm:ss.SSS
74
yyyy'-'MM'-'dd
75
yyyy DDD:HH:mm:ss
76
yyyyMMdd HH:mm
77
yyyy/MM/dd hh:mm:ss
78
MMM dd, yyyy
79
mm:ss:SS
80
MM-dd-yyyy
81
hh:mm:ss:SSS
82
hh:mm:ss dd-MM-yyyy
83
hh:mm
84
h:mm a, zzzz
85
h:mm
86
h:m
87
ddMMyyyyHHmmssSSS
88
ddhhmmz MMM yyyy
89
ddMMMyyyy
90
dd/MM/yyyy HH:mm:ss zzz
91
dd/MMM/yyyy
92
dd/MM/yyyy:HHmm
93
dd/MM/yyyy -- HH:mm:ss
94
dd/MM/yyyy - HH:mm:ss
95
dd/MM/yyyy hh:mm
96
dd.MMM.yyyy
97
dd.MM.yyyy hh:mm:ss a zzz
98
dd.MM.yyyy HH:mm:ss
99
dd.MM.yyyy '-' HH:mm:ss z
100
dd-MMM-yyyy HH:mm
101
dd'/'MM'/'yyyy
102
dd MMMMM, yyyy
103
dd MMMM yyyy
104
dd MM yyyy
105
d_M_yyyy_hh_mm_ss
106
d MMM yyyy
107
MMddyyyy.HHmm
108
MMddyyyyHHmm
109
MMM-dd-yyyy HH:mm:ss.S
110
MMM d hh:mm:ss
111
MM/dd/yyyy hh:mm:ss z
112
MM/dd/yyyy hh:mm:ss.SSS a
113
MM/dd/yyyy HH:mm
114
MM.dd.yyyy
115
MM'/'dd'/'yyyy
116
M/dd/yyyy
117
M/d/yyyy
118
M-dd-yyyy
119
HH:mm:ss '-' dd.MM.yyyy
120
H:mm
121
:mm:ss
122

  
123
#####################################################################
124
# Excel patterns [Jon Aquino]
125

  
126
M/dd
127
dd-MMM
128
MMM-yyyy
129
MM/dd/yyyy hh:mm a
130
M-yyyy
131
hh:mm:ss a
132

  
133
#####################################################################
134
# Other patterns [Jon Aquino]
135
MMM d
136
MMM yyyy
0 137

  
tags/vBefore3D_Branch/applications/appgvSIG/src/com/vividsolutions/jump/util/StringUtil.java
1
/*
2
 * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
3
 * for visualizing and manipulating spatial features with geometry and attributes.
4
 *
5
 * Copyright (C) 2003 Vivid Solutions
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
 *
21
 * For more information, contact:
22
 *
23
 * Vivid Solutions
24
 * Suite #1A
25
 * 2328 Government Street
26
 * Victoria BC  V8T 5G5
27
 * Canada
28
 *
29
 * (250)385-6040
30
 * www.vividsolutions.com
31
 */
32
package com.vividsolutions.jump.util;
33

  
34
import java.io.ByteArrayOutputStream;
35
import java.io.PrintStream;
36
import java.util.ArrayList;
37
import java.util.Collection;
38
import java.util.Iterator;
39
import java.util.List;
40
import java.util.StringTokenizer;
41

  
42
import com.vividsolutions.jts.util.Assert;
43

  
44
/**
45
 * Useful String-related utilities.
46
 */
47
public class StringUtil {
48

  
49
    public static String s(int n) {
50
        return (n != 1) ? "s" : "";
51
    }
52

  
53
    public static String ies(int n) {
54
        return (n != 1) ? "ies" : "y";
55
    }
56

  
57
    public static String classNameWithoutQualifiers(String className) {
58
        return className.substring(
59
            Math.max(className.lastIndexOf("."), className.lastIndexOf("$")) + 1);
60
    }
61

  
62
    public static String classNameWithoutPackageQualifiers(String className) {
63
        return className.substring(className.lastIndexOf(".") + 1);
64
    }
65

  
66
    public static String repeat(char c, int n) {
67
        StringBuffer b = new StringBuffer();
68

  
69
        for (int i = 0; i < n; i++) {
70
            b.append(c);
71
        }
72

  
73
        return b.toString();
74
    }
75

  
76
    /**
77
     *  Line-wraps s by inserting a newline instead of the first space after the nth
78
     *  column. Word-wraps.
79
     */
80
    public static String split(String s, int n) {
81
        StringBuffer b = new StringBuffer();
82
        boolean wrapPending = false;
83

  
84
        for (int i = 0; i < s.length(); i++) {
85
            if (((i % n) == 0) && (i > 0)) {
86
                wrapPending = true;
87
            }
88

  
89
            char c = s.charAt(i);
90

  
91
            if (wrapPending && (c == ' ')) {
92
                b.append("\n");
93
                wrapPending = false;
94
            } else {
95
                b.append(c);
96
            }
97
        }
98

  
99
        return b.toString();
100
    }
101

  
102
    public static String capitalize(String word) {
103
        if (word.length() == 0) {
104
            return word;
105
        }
106

  
107
        return (word.charAt(0) + "").toUpperCase() + word.substring(1);
108
    }
109
    
110
    public static String uncapitalize(String word) {
111
        if (word.length() == 0) {
112
            return word;
113
        }
114

  
115
        return (word.charAt(0) + "").toLowerCase() + word.substring(1);        
116
    }
117

  
118
    /**
119
     * Converts the comma-delimited string into a List of trimmed strings.
120
     * @param s a String with comma-delimited values
121
     * @return a List of the Strings that were delimited by commas
122
     */
123
    public static List fromCommaDelimitedString(String s) {
124
        ArrayList result = new ArrayList();
125
        StringTokenizer tokenizer = new StringTokenizer(s, ",");
126

  
127
        while (tokenizer.hasMoreTokens()) {
128
            result.add(tokenizer.nextToken().toString().trim());
129
        }
130

  
131
        return result;
132
    }
133

  
134
    /**
135
     * Returns a List of empty Strings.
136
     * @param size the size of the List to create
137
     * @return a List of blank Strings
138
     */
139
    public static List blankStringList(int size) {
140
        ArrayList list = new ArrayList();
141

  
142
        for (int i = 0; i < size; i++) {
143
            list.add("");
144
        }
145

  
146
        return list;
147
    }
148

  
149
    public static String toFriendlyName(String className) {
150
        return toFriendlyName(className, null);
151
    }
152
    
153
    public static String friendlyName(Class c) {
154
        return toFriendlyName(c.getName());
155
    }
156

  
157
    public static String toFriendlyName(String className, String substringToRemove) {
158
        String name = className;
159

  
160
        //Remove substring sooner rather than later because, for example,
161
        //?"PlugIn" will become "Plug In". [Jon Aquino]
162
        if (substringToRemove != null) {
163
            name = StringUtil.replaceAll(name, substringToRemove, "");
164
        }
165

  
166
        name = StringUtil.classNameWithoutQualifiers(name);
167
        name = insertSpaces(name);
168

  
169
        return name;
170
    }
171

  
172
    public static String insertSpaces(String s) {
173
        if (s.length() < 2) {
174
            return s;
175
        }
176

  
177
        String result = "";
178

  
179
        for (int i = 0; i < (s.length() - 2); i++) { //-2
180
            result += s.charAt(i);
181

  
182
            if ((Character.isLowerCase(s.charAt(i))
183
                && Character.isUpperCase(s.charAt(i + 1)))
184
                || (Character.isUpperCase(s.charAt(i + 1))
185
                    && Character.isLowerCase(s.charAt(i + 2)))) {
186
                result += " ";
187
            }
188
        }
189

  
190
        result += s.charAt(s.length() - 2);
191
        result += s.charAt(s.length() - 1);
192

  
193
        return result.trim();
194
    }
195

  
196
    /**
197
     * Returns the elements of c separated by commas. If c is empty, an empty
198
     * String will be returned.
199
     * @param c a Collection of objects to convert to Strings and delimit by commas
200
     * @return a String containing c's elements, delimited by commas
201
     */
202
    public static String toCommaDelimitedString(Collection c) {
203
        return toDelimitedString(c, ", ");
204
    }
205

  
206
    /**
207
     *  Returns original with all occurrences of oldSubstring replaced by
208
     *  newSubstring
209
     */
210
    public static String replaceAll(
211
        String original,
212
        String oldSubstring,
213
        String newSubstring) {
214
        return replace(original, oldSubstring, newSubstring, true);
215
    }
216

  
217
    /**
218
     *  Returns original with occurrences of oldSubstring replaced by
219
     *  newSubstring. Set all to true to replace all occurrences, or false to
220
     *  replace the first occurrence only.
221
     */
222
    public static String replace(
223
        String original,
224
        String oldSubstring,
225
        String newSubstring,
226
        boolean all) {
227
        StringBuffer b = new StringBuffer(original);
228
        replace(b, oldSubstring, newSubstring, all);
229

  
230
        return b.toString();
231
    }
232

  
233
    /**
234
     *  Replaces all instances of the String o with the String n in the
235
     *  StringBuffer orig if all is true, or only the first instance if all is
236
     *  false. Posted by Steve Chapel <schapel@breakthr.com> on UseNet
237
     */
238
    public static void replace(StringBuffer orig, String o, String n, boolean all) {
239
        if ((orig == null) || (o == null) || (o.length() == 0) || (n == null)) {
240
            throw new IllegalArgumentException("Null or zero-length String");
241
        }
242

  
243
        int i = 0;
244

  
245
        while ((i + o.length()) <= orig.length()) {
246
            if (orig.substring(i, i + o.length()).equals(o)) {
247
                orig.replace(i, i + o.length(), n);
248

  
249
                if (!all) {
250
                    break;
251
                } else {
252
                    i += n.length();
253
                }
254
            } else {
255
                i++;
256
            }
257
        }
258
    }
259

  
260
    /**
261
     * Returns an throwable's stack trace
262
     */
263
    public static String stackTrace(Throwable t) {
264
        ByteArrayOutputStream os = new ByteArrayOutputStream();
265
        PrintStream ps = new PrintStream(os);
266
        t.printStackTrace(ps);
267

  
268
        return os.toString();
269
    }
270
    
271
    public static String head(String s, int lines) {
272
        int newlinesEncountered = 0;
273
        for (int i = 0; i < s.length(); i++) {
274
            if (s.charAt(i) == '\n') {
275
                newlinesEncountered++;
276
                if (newlinesEncountered == lines) {
277
                    return s.substring(0, i);
278
                }
279
            }
280
        }
281
        return s;
282
    }
283

  
284
    public static String limitLength(String s, int maxLength) {
285
        Assert.isTrue(maxLength >= 3);
286

  
287
        if (s == null) {
288
            return null;
289
        }
290

  
291
        if (s.length() > maxLength) {
292
            return s.substring(0, maxLength - 3) + "...";
293
        }
294

  
295
        return s;
296
    }
297

  
298
    public static boolean isNumber(String token) {
299
        try {
300
            Double.parseDouble(token);
301

  
302
            return true;
303
        } catch (NumberFormatException e) {
304
            return false;
305
        }
306
    }  
307

  
308
    public static String toDelimitedString(Collection c, String delimiter) {
309
        if (c.isEmpty()) {
310
            return "";
311
        }
312

  
313
        StringBuffer result = new StringBuffer();
314

  
315
        for (Iterator i = c.iterator(); i.hasNext();) {
316
            Object o = i.next();
317
            result.append(delimiter + ((o == null) ? "" : o.toString()));
318
        }
319

  
320
        return result.substring(delimiter.length());
321
    }
322

  
323
    public static String toTimeString(long milliseconds) {
324
        long remainder = milliseconds;
325
        long days = remainder / 86400000;
326
        remainder = remainder % 86400000;
327

  
328
        long hours = remainder / 3600000;
329
        remainder = remainder % 3600000;
330

  
331
        long minutes = remainder / 60000;
332
        remainder = remainder % 60000;
333

  
334
        long seconds = remainder / 1000;
335
        String s = "";
336

  
337
        if (days > 0) {
338
            s += (days + " days ");
339
        }
340

  
341
        s
342
            += (Fmt.fmt(hours, 2, Fmt.ZF)
343
                + ":"
344
                + Fmt.fmt(minutes, 2, Fmt.ZF)
345
                + ":"
346
                + Fmt.fmt(seconds, 2, Fmt.ZF));
347

  
348
        return s;
349
    }
350
}
0 351

  
tags/vBefore3D_Branch/applications/appgvSIG/src/com/vividsolutions/jump/util/FlexibleDateParser.java
1
/*
2
 * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI 
3
 * for visualizing and manipulating spatial features with geometry and attributes.
4
 *
5
 * Copyright (C) 2003 Vivid Solutions
6
 * 
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 * 
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 * 
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
 * 
21
 * For more information, contact:
22
 *
23
 * Vivid Solutions
24
 * Suite #1A
25
 * 2328 Government Street
26
 * Victoria BC  V8T 5G5
27
 * Canada
28
 *
29
 * (250)385-6040
30
 * www.vividsolutions.com
31
 */
32
package com.vividsolutions.jump.util;
33

  
34
import com.vividsolutions.jts.util.Assert;
35

  
36
import java.awt.Color;
37
import java.awt.Component;
38

  
39
import java.io.IOException;
40
import java.io.InputStream;
41

  
42
import java.text.DateFormat;
43
import java.text.ParseException;
44
import java.text.ParsePosition;
45
import java.text.SimpleDateFormat;
46

  
47
import java.util.ArrayList;
48
import java.util.Calendar;
49
import java.util.Collection;
50
import java.util.Comparator;
51
import java.util.Date;
52
import java.util.Iterator;
53
import java.util.List;
54
import java.util.StringTokenizer;
55
import java.util.TreeSet;
56

  
57
import javax.swing.DefaultCellEditor;
58
import javax.swing.JComponent;
59
import javax.swing.JTable;
60
import javax.swing.JTextField;
61
import javax.swing.border.LineBorder;
62
import javax.swing.table.TableCellEditor;
63

  
64
/**
65
 * Warning: This class can parse a wide variety of formats. This flexibility is fine for parsing user
66
 * input because the user immediately sees whether the parser is correct and can fix it if
67
 * necessary. However, GML files are advised to stick with a safe format like yyyy-MM-dd.
68
 * yy/MM/dd is not as safe because while 99/03/04 will be parsed as yyyy/MM/dd, 
69
 * 02/03/04 will be parsed as MM/dd/yyyy (because MM/dd/yyyy appears earlier than yyyy/MM/dd
70
 * in FlexibleDateParser.txt).
71
 */
72
public class FlexibleDateParser {
73
    private static Collection lenientFormatters = null;
74
    private static Collection unlenientFormatters = null;
75
    //CellEditor used to be a static field CELL_EDITOR, but I was getting
76
    //problems calling it from ESETextField (it simply didn't appear).
77
    //The problems vanished when I turned it into a static class. I didn't
78
    //investigate further. [Jon Aquino]
79
    public static final class CellEditor extends DefaultCellEditor {
80
        public CellEditor() {
81
            super(new JTextField());
82
        }
83
        private Object value;
84
        private FlexibleDateParser parser = new FlexibleDateParser();
85

  
86
        public boolean stopCellEditing() {
87
            try {
88
                value = parser.parse((String) super.getCellEditorValue(), true);
89
            } catch (Exception e) {
90
                ((JComponent) getComponent()).setBorder(new LineBorder(Color.red));
91

  
92
                return false;
93
            }
94

  
95
            return super.stopCellEditing();
96
        }
97

  
98
        public Component getTableCellEditorComponent(
99
            JTable table,
100
            Object value,
101
            boolean isSelected,
102
            int row,
103
            int column) {
104
            this.value = null;
105
            ((JComponent) getComponent()).setBorder(new LineBorder(Color.black));
106

  
107
            return super.getTableCellEditorComponent(
108
                table,
109
                format((Date) value),
110
                isSelected,
111
                row,
112
                column);
113
        }
114

  
115
        private String format(Date date) {
116
            return (date == null) ? "" : formatter.format(date);
117
        }
118

  
119
        public Object getCellEditorValue() {
120
            return value;
121
        }
122

  
123
        //Same formatter as used by JTable.DateRenderer. [Jon Aquino]
124
        private DateFormat formatter = DateFormat.getDateInstance();
125
    };
126

  
127
    private boolean verbose = false;
128

  
129
    private Collection sortByComplexity(Collection patterns) {
130
        //Least complex to most complex. [Jon Aquino]
131
        TreeSet sortedPatterns = new TreeSet(new Comparator() {
132
            public int compare(Object o1, Object o2) {
133
                int result = complexity(o1.toString()) - complexity(o2.toString());
134
                if (result == 0) {
135
                    //The two patterns have the same level of complexity.
136
                    //Sort by order of appearance (e.g. to resolve
137
                    //MM/dd/yyyy vs dd/MM/yyyy [Jon Aquino]
138
                    result = ((Pattern) o1).index - ((Pattern) o2).index;
139
                }
140
                return result;
141
            }
142

  
143
            private TreeSet uniqueCharacters = new TreeSet();
144

  
145
            private int complexity(String pattern) {
146
                uniqueCharacters.clear();
147

  
148
                for (int i = 0; i < pattern.length(); i++) {
149
                    if (("" + pattern.charAt(i)).trim().length() > 0) {
150
                        uniqueCharacters.add("" + pattern.charAt(i));
151
                    }
152
                }
153

  
154
                return uniqueCharacters.size();
155
            }
156
        });
157
        sortedPatterns.addAll(patterns);
158

  
159
        return sortedPatterns;
160
    }
161

  
162
    private Collection lenientFormatters() {
163
        if (lenientFormatters == null) {
164
            load();
165
        }
166

  
167
        return lenientFormatters;
168
    }
169

  
170
    private Collection unlenientFormatters() {
171
        if (unlenientFormatters == null) {
172
            load();
173
        }
174

  
175
        return unlenientFormatters;
176
    }
177

  
178
    /**
179
     * @return null if s is empty
180
     */
181
    public Date parse(String s, boolean lenient) throws ParseException {
182
        if (s.trim().length() == 0) {
183
            return null;
184
        }
185
        //The deprecated Date#parse method is actually pretty flexible. [Jon Aquino]
186
        try {
187
            if (verbose) {
188
                System.out.println(s + " -- Date constructor");
189
            }
190
            return new Date(s);
191
        } catch (Exception e) {
192
            //Eat it. [Jon Aquino]
193
        }
194

  
195
        try {
196
            return parse(s, unlenientFormatters());
197
        } catch (ParseException e) {
198
            if (lenient) {
199
                return parse(s, lenientFormatters());
200
            }
201

  
202
            throw e;
203
        }
204
    }
205

  
206
    private Date parse(String s, Collection formatters) throws ParseException {
207
        ParseException firstParseException = null;
208

  
209
        for (Iterator i = formatters.iterator(); i.hasNext();) {
210
            SimpleDateFormat formatter = (SimpleDateFormat) i.next();
211

  
212
            if (verbose) {
213
                System.out.println(
214
                    s
215
                        + " -- "
216
                        + formatter.toPattern()
217
                        + (formatter.isLenient() ? "lenient" : ""));
218
            }
219

  
220
            try {
221
                return parse(s, formatter);
222
            } catch (ParseException e) {
223
                if (firstParseException == null) {
224
                    firstParseException = e;
225
                }
226
            }
227
        }
228

  
229
        throw firstParseException;
230
    }
231

  
232
    private Date parse(String s, SimpleDateFormat formatter) throws ParseException {
233
        ParsePosition pos = new ParsePosition(0);
234
        Date date = formatter.parse(s, pos);
235

  
236
        if (pos.getIndex() == 0) {
237
            throw new ParseException(
238
                "Unparseable date: \"" + s + "\"",
239
                pos.getErrorIndex());
240
        }
241

  
242
        //SimpleDateFormat ignores trailing characters in the pattern string that it
243
        //doesn't need. Don't allow it to ignore any characters. [Jon Aquino]
244
        if (pos.getIndex() != s.length()) {
245
            throw new ParseException(
246
                "Unparseable date: \"" + s + "\"",
247
                pos.getErrorIndex());
248
        }
249

  
250
        Calendar calendar = Calendar.getInstance();
251
        calendar.setTime(date);
252

  
253
        if ((calendar.get(Calendar.YEAR) == 1970) && (s.indexOf("70") == -1)) {
254
            calendar.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
255
        }
256

  
257
        return calendar.getTime();
258
    }
259

  
260
    private static class Pattern {
261
        private String pattern;
262
        private int index;
263
        public Pattern(String pattern, int index) {
264
            this.pattern = pattern;
265
            this.index = index;
266
        }
267
        public String toString() {
268
            return pattern;
269
        }
270
    }
271

  
272
    private void load() {
273
        if (lenientFormatters == null) {
274
            InputStream inputStream =
275
                getClass().getResourceAsStream("FlexibleDateParser.txt");
276

  
277
            try {
278
                try {
279
                    Collection patterns = new ArrayList();
280
                    int index = 0;
281
                    for (Iterator i = FileUtil.getContents(inputStream).iterator();
282
                        i.hasNext();
283
                        ) {
284
                        String line = ((String) i.next()).trim();
285

  
286
                        if (line.startsWith("#")) {
287
                            continue;
288
                        }
289

  
290
                        if (line.length() == 0) {
291
                            continue;
292
                        }
293

  
294
                        patterns.add(new Pattern(line, index));
295
                        index++;
296
                    }
297

  
298
                    unlenientFormatters = toFormatters(false, patterns);
299
                    lenientFormatters = toFormatters(true, patterns);
300
                } finally {
301
                    inputStream.close();
302
                }
303
            } catch (IOException e) {
304
                Assert.shouldNeverReachHere(e.toString());
305
            }
306
        }
307
    }
308

  
309
    private Collection toFormatters(boolean lenient, Collection patterns) {
310
        ArrayList formatters = new ArrayList();
311
        //Sort from least complex to most complex; otherwise, ddMMMyyyy 
312
        //instead of MMMd will match "May 15". [Jon Aquino]
313
        for (Iterator i = sortByComplexity(patterns).iterator(); i.hasNext();) {
314
            Pattern pattern = (Pattern) i.next();
315
            SimpleDateFormat formatter = new SimpleDateFormat(pattern.pattern);
316
            formatter.setLenient(lenient);
317
            formatters.add(formatter);
318
        }
319

  
320
        return formatters;
321
    }
322

  
323
    public static void main(String[] args) throws Exception {
324
        System.out.println(DateFormat.getDateInstance().parse("03-Mar-1998"));
325
    }
326

  
327
    public void setVerbose(boolean b) {
328
        verbose = b;
329
    }
330
}
0 331

  
tags/vBefore3D_Branch/applications/appgvSIG/src/com/vividsolutions/jump/util/CoordinateArrays.java
1

  
2
/*
3
 * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI 
4
 * for visualizing and manipulating spatial features with geometry and attributes.
5
 *
6
 * Copyright (C) 2003 Vivid Solutions
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 * 
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
 * 
22
 * For more information, contact:
23
 *
24
 * Vivid Solutions
25
 * Suite #1A
26
 * 2328 Government Street
27
 * Victoria BC  V8T 5G5
28
 * Canada
29
 *
30
 * (250)385-6040
31
 * www.vividsolutions.com
32
 */
33

  
34
package com.vividsolutions.jump.util;
35

  
36
import java.util.*;
37

  
38
import com.vividsolutions.jts.algorithm.CGAlgorithms;
39
import com.vividsolutions.jts.algorithm.RobustCGAlgorithms;
40
import com.vividsolutions.jts.geom.*;
41
import com.vividsolutions.jts.util.Assert;
42

  
43

  
44
/**
45
 * Some utility functions for handling Coordinate arrays.
46
 */
47
public class CoordinateArrays {
48
    //<<TODO:REFACTORING>> JTS already has a class named CoordinateArrays.
49
    //I wonder if we should collapse this class into that one. [Jon Aquino]
50
    // MD - yep, at some point.
51
    private static final CGAlgorithms cga = new RobustCGAlgorithms();
52
    private final static Coordinate[] coordArrayType = new Coordinate[0];
53

  
54
    public static Coordinate[] toCoordinateArray(List coordList) {
55
        return (Coordinate[]) coordList.toArray(coordArrayType);
56
    }
57

  
58
    //<<TODO:REFACTORING>> This functionality is duplicated in
59
    //the protected method Geometry#reversePointOrder. Perhaps we should
60
    //make that method public and deprecate this method, or have this method
61
    //delegate to the other. [Jon Aquino]
62
    //MD: Geometry#reversePointOrder could delegate to this method.  Can't do it other way around.
63
    public static void reverse(Coordinate[] coord) {
64
        int last = coord.length - 1;
65
        int mid = last / 2;
66

  
67
        for (int i = 0; i <= mid; i++) {
68
            Coordinate tmp = coord[i];
69
            coord[i] = coord[last - i];
70
            coord[last - i] = tmp;
71
        }
72
    }
73

  
74
    /**
75
     * Converts an array of coordinates to a line or point, as appropriate.
76
     * @param coords the coordinates of a line or point
77
     * @param fact a factory used to create the Geometry
78
     * @return a line if there is more than one coordinate; a point if there is
79
     * just one coordinate; an empty point otherwise
80
     */
81
    public static Geometry toLineOrPoint(Coordinate[] coords,
82
        GeometryFactory fact) {
83
        if (coords.length > 1) {
84
            return fact.createLineString(coords);
85
        }
86

  
87
        if (coords.length == 1) {
88
            return fact.createPoint(coords[0]);
89
        }
90

  
91
        return fact.createPoint((Coordinate)null);
92
    }
93

  
94
    public static boolean equals(Coordinate[] coord1, Coordinate[] coord2) {
95
        if (coord1 == coord2) {
96
            return true;
97
        }
98

  
99
        if ((coord1 == null) || (coord2 == null)) {
100
            return false;
101
        }
102

  
103
        if (coord1.length != coord2.length) {
104
            return false;
105
        }
106

  
107
        for (int i = 0; i < coord1.length; i++) {
108
            if (!coord1[i].equals(coord2[i])) {
109
                return false;
110
            }
111
        }
112

  
113
        return true;
114
    }
115

  
116
    /**
117
     * Converts a collection of coordinate arrays to a collection of geometries.
118
     * @param coordArrays a collection of Coordinate[]
119
     * @param fact a factory used to create the Geometries
120
     * @return a collection of LineStrings and Points
121
     */
122
    public static List fromCoordinateArrays(List coordArrays,
123
        GeometryFactory fact) {
124
        List geomList = new ArrayList();
125

  
126
        for (Iterator i = coordArrays.iterator(); i.hasNext();) {
127
            Coordinate[] coords = (Coordinate[]) i.next();
128
            Geometry geom = toLineOrPoint(coords, fact);
129
            geomList.add(geom);
130
        }
131

  
132
        return geomList;
133
    }
134

  
135
    /**
136
     * Extract the coordinate arrays for a geometry into a List.
137
     * @param g the Geometry to extract from
138
     * @param coordArrayList the List to add the coordinate arrays to
139
     * @param orientPolygons whether or not the arrays in the List should be
140
     * oriented (clockwise for the shell, counterclockwise for the holes)
141
     */
142
    public static void addCoordinateArrays(Geometry g, boolean orientPolygons,
143
        List coordArrayList) {
144
        if (g.getDimension() <= 0) {
145
            return;
146
        } else if (g instanceof LineString) {
147
            LineString l = (LineString) g;
148
            coordArrayList.add(l.getCoordinates());
149
        } else if (g instanceof Polygon) {
150
            Polygon poly = (Polygon) g;
151
            Coordinate[] shell = poly.getExteriorRing().getCoordinates();
152

  
153
            if (orientPolygons) {
154
                shell = ensureOrientation(shell, CGAlgorithms.CLOCKWISE);
155
            }
156

  
157
            coordArrayList.add(shell);
158

  
159
            for (int i = 0; i < poly.getNumInteriorRing(); i++) {
160
                Coordinate[] hole = poly.getInteriorRingN(i).getCoordinates();
161

  
162
                if (orientPolygons) {
163
                    hole = ensureOrientation(hole, CGAlgorithms.COUNTERCLOCKWISE);
164
                }
165

  
166
                coordArrayList.add(hole);
167
            }
168
        } else if (g instanceof GeometryCollection) {
169
            GeometryCollection gc = (GeometryCollection) g;
170

  
171
            for (int i = 0; i < gc.getNumGeometries(); i++) {
172
                addCoordinateArrays(gc.getGeometryN(i), orientPolygons,
173
                    coordArrayList);
174
            }
175
        } else {
176
            Assert.shouldNeverReachHere("Geometry of type " +
177
                g.getClass().getName() + " not handled");
178
        }
179
    }
180

  
181
    /**
182
     * Sets the orientation of an array of coordinates.
183
     * @param coord the coordinates to inspect
184
     * @param desiredOrientation CGAlgorithms.CLOCKWISE or CGAlgorithms.COUNTERCLOCKWISE
185
     * @return a new array with entries in reverse order, if the orientation is
186
     * incorrect; otherwise, the original array
187
     */
188
    public static Coordinate[] ensureOrientation(Coordinate[] coord,
189
        int desiredOrientation) {
190
        if (coord.length == 0) {
191
            return coord;
192
        }
193

  
194
        int orientation = cga.isCCW(coord) ? CGAlgorithms.COUNTERCLOCKWISE
195
                                           : CGAlgorithms.CLOCKWISE;
196

  
197
        if (orientation != desiredOrientation) {
198
            Coordinate[] reverse = (Coordinate[]) coord.clone();
199
            CoordinateArrays.reverse(reverse);
200

  
201
            return reverse;
202
        }
203

  
204
        return coord;
205
    }
206

  
207
    /**
208
     * Extract the coordinate arrays for a geometry.
209
     * Polygons will be checked to ensure their rings are oriented correctly.
210
     * Note: coordinates from Points or MultiPoints will not be extracted.
211
     * @param g the Geometry to extract from
212
     * @param orientPolygons ensure that Polygons are correctly oriented
213
     * @return a list of Coordinate[]
214
     */
215
    public static List toCoordinateArrays(Geometry g, boolean orientPolygons) {
216
        List coordArrayList = new ArrayList();
217
        addCoordinateArrays(g, orientPolygons, coordArrayList);
218

  
219
        return coordArrayList;
220
    }
221
}
0 222

  
tags/vBefore3D_Branch/applications/appgvSIG/src/com/vividsolutions/jump/util/ColorUtil.java
1
/*
2
 * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
3
 * for visualizing and manipulating spatial features with geometry and attributes.
4
 *
5
 * Copyright (C) 2003 Vivid Solutions
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
 *
21
 * For more information, contact:
22
 *
23
 * Vivid Solutions
24
 * Suite #1A
25
 * 2328 Government Street
26
 * Victoria BC  V8T 5G5
27
 * Canada
28
 *
29
 * (250)385-6040
30
 * www.vividsolutions.com
31
 */
32

  
33
package com.vividsolutions.jump.util;
34

  
35
import java.awt.Color;
36

  
37

  
38
public class ColorUtil {
39
  public static final Color GOLD = new Color(255, 192, 0, 150);
40
  public static final Color PALE_BLUE = new Color(153, 204, 255, 150);
41
  public static final Color PALE_RED = new Color(255, 204, 204, 150);  
42
}
0 43

  
tags/vBefore3D_Branch/applications/appgvSIG/src/com/vividsolutions/jump/util/FileUtil.java
1

  
2
/*
3
 * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
4
 * for visualizing and manipulating spatial features with geometry and attributes.
5
 *
6
 * Copyright (C) 2003 Vivid Solutions
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff