Revision 397

View differences:

org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.72/org.gvsig.toolbox.gui/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
    <modelVersion>4.0.0</modelVersion>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.toolbox.gui</artifactId>
6
    <packaging>jar</packaging>
7
    <name>${project.artifactId}</name>
8
	
9
    <parent>
10
        <groupId>org.gvsig</groupId>
11
        <artifactId>org.gvsig.toolbox</artifactId>
12
        <version>1.0.72</version>
13
    </parent>
14
	
15
    <dependencies>
16
        <dependency>
17
            <groupId>org.gvsig</groupId>
18
            <artifactId>org.gvsig.fmap.dal.api</artifactId>
19
            <scope>compile</scope>
20
        </dependency>         
21
        <dependency>
22
            <groupId>org.gvsig</groupId>
23
            <artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
24
            <scope>compile</scope>
25
        </dependency> 
26
        <dependency>    
27
        <groupId>org.gvsig</groupId>
28
            <artifactId>org.gvsig.expressionevaluator.lib.api</artifactId>
29
            <scope>compile</scope>
30
        </dependency>           
31
        <dependency>
32
            <groupId>org.gvsig</groupId>
33
            <artifactId>org.gvsig.expressionevaluator.swing.api</artifactId>
34
            <scope>compile</scope>
35
        </dependency>        
36
        <dependency>
37
            <groupId>org.gvsig</groupId>
38
            <artifactId>org.gvsig.temporarystorage.lib.api</artifactId>
39
            <scope>compile</scope>
40
        </dependency>
41
        <dependency>
42
            <groupId>org.gvsig</groupId>
43
            <artifactId>org.gvsig.fmap.geometry.api</artifactId>
44
            <scope>compile</scope>
45
        </dependency>
46
        <dependency>
47
            <groupId>org.gvsig</groupId>
48
            <artifactId>org.gvsig.toolbox.core</artifactId>
49
        </dependency>
50
        <dependency>
51
            <groupId>es.unex</groupId>
52
            <artifactId>sextante_wps</artifactId>
53
            <scope>compile</scope>
54
        </dependency>
55
        <dependency>
56
            <groupId>es.unex</groupId>
57
            <artifactId>libDocEngines</artifactId>
58
            <scope>compile</scope>
59
        </dependency>
60
        <dependency>
61
            <groupId>net.sf</groupId>
62
            <artifactId>jgraph</artifactId>
63
            <scope>compile</scope>
64
        </dependency>
65
        <dependency>
66
            <groupId>info.clearthought</groupId>
67
            <artifactId>TableLayout-bin-jdk1.5</artifactId>
68
            <scope>compile</scope>
69
        </dependency>
70
        <dependency>
71
            <groupId>org.beanshell</groupId>
72
            <artifactId>bsh</artifactId>
73
            <scope>compile</scope>
74
        </dependency>
75
        <dependency>
76
            <groupId>net.sf.kxml</groupId>
77
            <artifactId>kxml2</artifactId>
78
            <scope>compile</scope>
79
        </dependency>
80
        <dependency>
81
            <groupId>org.japura</groupId>
82
            <artifactId>org.japura</artifactId>
83
            <scope>compile</scope>
84
        </dependency>
85
        <dependency>
86
            <groupId>org.gvsig</groupId>
87
            <artifactId>org.gvsig.fmap.dal.swing.api</artifactId>
88
            <scope>compile</scope>
89
        </dependency>
90
    </dependencies>
91
</project>
0 92

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.72/org.gvsig.toolbox.gui/build.xml
1
<project name="SEXTANTE_LIB" default="generate-without-source" basedir=".">
2
    <description>
3
        SEXTANTE_GUI
4
    </description>
5
	<property name="version.number" value="0.7"/>
6

  
7
  <target name="generate-without-source"
8
  	description="generate the distribution without the source file">
9

  
10
  	       <tstamp>
11
  	         <format property="TODAY" pattern="yyyy-MM-dd HH:mm:ss" />
12
  	       </tstamp>
13

  
14
  	    <manifest file="MANIFEST.MF">
15
  	        <attribute name="Implementation-Version"
16
  	            value="${version.number}"/>
17
  	        <attribute name="Built-Date" value="${TODAY}"/>
18
  	   </manifest>
19

  
20
    <jar jarfile="../dist/sextante_gui.jar" manifest="MANIFEST.MF">
21
  		<fileset dir="bin">
22
  			<include name="**"/>
23
 		</fileset>
24
 	</jar>
25

  
26
    <jar jarfile="../dist/sextante_gui.jar" update ="true">
27
        <fileset dir=".">
28
            <include name="i18n/**"/>
29
        </fileset>
30
    </jar>
31

  
32
    <jar jarfile="../dist/sextante_gui.jar" update ="true">
33
        <fileset dir=".">
34
            <include name="images/**"/>
35
        	<include name="grass/**"/>
36
        </fileset>
37
    </jar>
38

  
39
    <copy todir="../dist">
40
    	<fileset dir="lib" includes="**"/>
41
    </copy>
42

  
43
  </target>
44

  
45
</project>
0 46

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.72/org.gvsig.toolbox.gui/sextante_grass.bat
1
set HOME=%USERPROFILE%
2
set PATH=%GRASSDIR%\msys\bin;%PATH%
3
set PATH=%GRASSDIR%\extrabin;%GRASSDIR%\extralib;%PATH%
4
set PATH=%GRASSDIR%\tcl-tk\bin;%GRASSDIR%\sqlite\bin;%GRASSDIR%\gpsbabel;%PATH%
5
set GRASS_HTML_BROWSER=%PROGRAMFILES%/Internet Explorer/iexplore.exe
6
set GRASS_PROJSHARE=%GRASSDIR%\proj
7
set PYTHONHOME=%GRASSDIR%\Python25
8
set WINGISBASE=%GRASSDIR%
9
set GISBASE=%GRASSDIR%
10
set SAVEPATH=%PATH%
11
set PATH=%WINGISBASE%\bin;%WINGISBASE%\lib;%PATH%
12
set GISRC=%HOME%\.grassrc6
13

  
14
g.gisenv set="MAPSET=%MAPSET%"
15
g.gisenv set="LOCATION=%LOCATION_NAME%"
16
g.gisenv set="LOCATION_NAME=%LOCATION_NAME%"
17
g.gisenv set="GISDBASE=%GISDBASE%"
18

  
19
set GRASS_VERSION=6.4.0RC5
20

  
21
set GRASS_PAGER=more
22
if "%GRASS_WISH%"=="" set GRASS_WISH=wish.exe
23
if "%GRASS_SH%"=="" set GRASS_SH=c:\msys\1.0\bin\sh.exe
24
if "%GRASS_HTML_BROWSER%"=="" set GRASS_HTML_BROWSER=%SYSTEMDRIVE%/PROGRA~1/INTERN~1/IEXPLORE.EXE
25
if "%GRASS_PROJSHARE%"=="" set GRASS_PROJSHARE=/c/Programs/GIS/OSGeo4W/share/proj
26

  
27
set PATHEXT=%PATHEXT%;.PY
28

  
29
g.gisenv "set=GRASS_GUI=text"
30

  
31
call "%GRASS_BATCH_JOB%"
32

  
33
"%WINGISBASE%\etc\clean_temp" > NUL:
34

  
35
set PATH=%SAVEPATH%
36
set SAVEPATH=
37

  
38
rem exit
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.72/org.gvsig.toolbox.gui/MANIFEST.MF
1
Manifest-Version: 1.0
2
Ant-Version: Apache Ant 1.7.1
3
Created-By: 20.1-b02 (Sun Microsystems Inc.)
4
Implementation-Version: 0.7
5
Built-Date: 2013-03-04 16:06:37
6

  
0 7

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.72/org.gvsig.toolbox.gui/src/main/java/jsh/shell/Utils.java
1
/*
2
 * 20:25:20 20/05/99
3
 *
4
 * The Java Shell: Utilities.
5
 * (C)1999 Romain Guy, Osvaldo Pinali Doederlein.
6
 *
7
 * LICENSE
8
 * =======
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 *
23
 * CHANGES
24
 * =======
25
 * 1.0.8 - Filled the listRoots method                   (Romain & Osvaldo)
26
 * 1.0.7 - Several bug fixes in constructPath            (Romain)
27
 * 1.0.6 - Split JDK1.1/1.2                              (Osvaldo)
28
 * 1.0.5 - Important bug fix in constructPath(String)    (Romain)
29
 * 1.0.4 - Added getSize(Enumeration)                    (Osvaldo)
30
 * 1.0.3 - Changed sortStrings bubble-sort algorithm to  (Romain)
31
 *         quick-sort (James Gosling)
32
 * 1.0.2 - Fixed two little bug in constructPath(String) (Romain)
33
 * 1.0.1 - Added listFiles(String[], boolean)            (Romain)
34
 *       - Removed unecessary createWhiteSpace(int)      (Romain)
35
 *       - Modified getWildCardMatches(String, boolean)  (Romain)
36
 *       - Slighty improved javadoc comments             (Romain)
37
 * 1.0.0 - Initial release.                              (Romain & Osvaldo)
38
 *
39
 * LINKS
40
 * =====
41
 * Contact: mailto@osvaldo.visionnaire.com.br
42
 * Site #1: http://www.geocities.com/ResearchTriangle/Node/2005/
43
 * Site #2: http://student.vub.ac.be/~opinalid/
44
 */
45

  
46
package jsh.shell;
47

  
48
import java.io.File;
49
import java.util.Enumeration;
50
import java.util.Vector;
51

  
52
import es.unex.sextante.gui.core.SextanteGUI;
53

  
54
/**
55
 * The Java Shell: Utility pack.
56
 *
57
 * @author Romain Guy.
58
 * @author Osvaldo Pinali Doederlein.
59
 */
60

  
61
public class Utils {
62

  
63
   /**
64
    * Removes some elements from a String array.
65
    *
66
    * @param arr
67
    *                The array.
68
    * @param first
69
    *                First element to keep (new 0-index).
70
    * @param last
71
    *                Last element to keep.
72
    * @return Copy of arr[first..]
73
    */
74
   public static String[] subarray(final String[] arr,
75
                                   int first,
76
                                   final int last) {
77
      final String[] newArr = new String[last - first + 1];
78

  
79
      for (int i = 0; i < newArr.length; ++i, ++first) {
80
         newArr[i] = arr[first];
81
      }
82

  
83
      return newArr;
84
   }
85

  
86

  
87
   /**
88
    * Removes some leading elements from a String array.
89
    *
90
    * @param arr
91
    *                The array.
92
    * @param first
93
    *                First element to keep (new 0-index).
94
    * @return Copy of arr[first..]
95
    */
96
   public static String[] subarray(final String[] arr,
97
                                   final int first) {
98
      return subarray(arr, first, arr.length - 1);
99
   }
100

  
101

  
102
   /**
103
    * Formats a number of bytes for output.
104
    *
105
    * @param bytes
106
    *                Number of bytes.
107
    * @return "xxxxK" form.
108
    */
109
   public static String fmtBytes(final long bytes) {
110
      return Long.toString(bytes / 1024) + "K";
111
   }
112

  
113

  
114
   /**
115
    * Formats time for output.
116
    *
117
    * @param bytes
118
    *                Number of milliseconds.
119
    * @return "x,yyys" form.
120
    */
121
   public static String fmtTime(final long ms) {
122
      return Float.toString(ms / 1000.0f) + "s";
123
   }
124

  
125

  
126
   /**
127
    * Return a String made of spaces.
128
    *
129
    * @param len
130
    *                Number of spaces
131
    */
132
   public static String getSpaces(final int len) {
133
      final StringBuffer buf = new StringBuffer();
134

  
135
      for (int i = 0; i < len; i++) {
136
         buf.append(' ');
137
      }
138

  
139
      return buf.toString();
140
   }
141

  
142

  
143
   public static String[] toArray(final Vector strings) {
144
      final String[] arr = new String[strings.size()];
145

  
146
      for (int i = 0; i < strings.size(); ++i) {
147
         arr[i] = (String) strings.elementAt(i);
148
      }
149

  
150
      return arr;
151
   }
152

  
153

  
154
   /**
155
    * When the user has to specify file names, he can use wildcards (*, ?). This methods handles the usage of these wildcards.
156
    *
157
    * @param s
158
    *                Wilcards
159
    * @param sort
160
    *                Set to true will sort file names
161
    * @return An array of String which contains all files matching <code>s</code> in current directory.
162
    * @see Utils#match(String, String)
163
    */
164

  
165
   public static String[] getWildCardMatches(final String s,
166
                                             final boolean sort) {
167
      final String args = new String(s.trim());
168
      String files[];
169
      final Vector filesThatMatchVector = new Vector();
170
      String filesThatMatch[];
171

  
172
      files = (new File(getUserDirectory())).list();
173

  
174
      for (int i = 0; i < files.length; i++) {
175
         if (match(args, files[i])) {
176
            final File temp = new File(getUserDirectory(), files[i]);
177
            filesThatMatchVector.addElement(new String(temp.getName()));
178
         }
179
      }
180

  
181
      filesThatMatch = new String[filesThatMatchVector.size()];
182
      filesThatMatchVector.copyInto(filesThatMatch);
183

  
184
      if (sort) {
185
         sortStrings(filesThatMatch);
186
      }
187

  
188
      return filesThatMatch;
189
   }
190

  
191

  
192
   /**
193
    * This method can determine if a String matches a pattern of wildcards
194
    *
195
    * @param pattern
196
    *                The pattern used for comparison
197
    * @param string
198
    *                The String to be checked
199
    * @return true if <code>string</code> matches <code>pattern</code>
200
    * @see Utils#getWildCardMatches(String)
201
    */
202

  
203
   public static boolean match(final String pattern,
204
                               final String string) {
205
      for (int p = 0;; p++) {
206
         for (int s = 0;; p++, s++) {
207
            final boolean sEnd = (s >= string.length());
208
            final boolean pEnd = (p >= pattern.length() || pattern.charAt(p) == '|');
209

  
210
            if (sEnd && pEnd) {
211
               return true;
212
            }
213
            if (sEnd || pEnd) {
214
               break;
215
            }
216
            if (pattern.charAt(p) == '?') {
217
               continue;
218
            }
219

  
220
            if (pattern.charAt(p) == '*') {
221
               int i;
222
               p++;
223

  
224
               for (i = string.length(); i >= s; --i) {
225
                  if (match(pattern.substring(p), string.substring(i))) {
226
                     return true;
227
                  }
228
               }
229

  
230
               break;
231
            }
232

  
233
            if (pattern.charAt(p) != string.charAt(s)) {
234
               break;
235
            }
236
         }
237

  
238
         p = pattern.indexOf('|', p);
239

  
240
         if (p == -1) {
241
            return false;
242
         }
243
      }
244
   }
245

  
246

  
247
   /**
248
    * Quick sort an array of Strings.
249
    *
250
    * @param string
251
    *                Strings to be sorted
252
    */
253

  
254
   public static void sortStrings(final String[] strings) {
255
      sortStrings(strings, 0, strings.length - 1);
256
   }
257

  
258

  
259
   /**
260
    * Quick sort an array of Strings.
261
    *
262
    * @param a
263
    *                Strings to be sorted
264
    * @param lo0
265
    *                Lower bound
266
    * @param hi0
267
    *                Higher bound
268
    */
269

  
270
   public static void sortStrings(final String a[],
271
                                  final int lo0,
272
                                  final int hi0) {
273
      int lo = lo0;
274
      int hi = hi0;
275
      String mid;
276

  
277
      if (hi0 > lo0) {
278
         mid = a[(lo0 + hi0) / 2];
279

  
280
         while (lo <= hi) {
281
            while (lo < hi0 && a[lo].compareTo(mid) < 0) {
282
               ++lo;
283
            }
284

  
285
            while (hi > lo0 && a[hi].compareTo(mid) > 0) {
286
               --hi;
287
            }
288

  
289
            if (lo <= hi) {
290
               swap(a, lo, hi);
291
               ++lo;
292
               --hi;
293
            }
294
         }
295

  
296
         if (lo0 < hi) {
297
            sortStrings(a, lo0, hi);
298
         }
299

  
300
         if (lo < hi0) {
301
            sortStrings(a, lo, hi0);
302
         }
303
      }
304
   }
305

  
306

  
307
   /**
308
    * Swaps two Strings.
309
    *
310
    * @param a
311
    *                The array to be swapped
312
    * @param i
313
    *                First String index
314
    * @param j
315
    *                Second String index
316
    */
317

  
318
   public static void swap(final String a[],
319
                           final int i,
320
                           final int j) {
321
      String T;
322
      T = a[i];
323
      a[i] = a[j];
324
      a[j] = T;
325
   }
326

  
327

  
328
   /**
329
    * Returns the user current directory.
330
    */
331
   public static String getUserDirectory() {
332

  
333
      String folder = SextanteGUI.getOutputFolder();
334
      if (folder == null) {
335
         folder = System.getProperty("user.home");
336
      }
337

  
338
      return folder;
339

  
340
   }
341

  
342

  
343
   /**
344
    * Sometimes, Strings are too long to be correctly displayed. This method will reduce a String, keeping first and last
345
    * characters.
346
    *
347
    * @param longString
348
    *                The String to be modified
349
    * @param maxLength
350
    *                The maximum length of the String
351
    * @return A shorter String
352
    */
353

  
354
   public static String getShortStringOf(final String longString,
355
                                         final int maxLength) {
356
      final int len = longString.length();
357

  
358
      if (len < maxLength) {
359
         return longString;
360
      }
361
      else {
362
         return longString.substring(0, maxLength / 2) + "..." + longString.substring(len - (maxLength / 2));
363
      }
364
   }
365

  
366

  
367
   /**
368
    * Because a lot of people still use JDK 1.1, we need this method to create an array of Files from an array of String.
369
    *
370
    * @param names
371
    *                Names of the files
372
    * @param construct
373
    *                Set it to true if names does not contain full paths
374
    * @return An array of Files
375
    */
376
   public static File[] listFiles(final String[] names,
377
                                  final boolean construct) {
378
      final File[] files = new File[names.length];
379

  
380
      String path = Utils.getUserDirectory();
381

  
382
      if (construct) {
383
         if (!path.endsWith(File.separator)) {
384
            path += File.separator;
385
         }
386
      }
387

  
388
      for (int i = 0; i < files.length; i++) {
389
         if (construct) {
390
            files[i] = new File(path + names[i]);
391
         }
392
         else {
393
            files[i] = new File(names[i]);
394
         }
395
      }
396

  
397
      return files;
398
   }
399

  
400

  
401
   /**
402
    * Counts things in an Enumeration (and destroys it as a side effect).
403
    *
404
    * @param enum
405
    *                The enumeration, in the start position.
406
    * @return Elements found.
407
    */
408
   public static int getSize(final Enumeration enu) {
409
      int size = 0;
410

  
411
      while (enu.hasMoreElements()) {
412
         ++size;
413
         enu.nextElement();
414
      }
415

  
416
      return size;
417
   }
418

  
419

  
420
   /**
421
    * Constructs a new path from current user path. This is an easy way to get a path if the user specified, for example,
422
    * "..\Java" as new path. This method will return the argument if this one is a path to a root (i.e, if <code>change</code>
423
    * is equal to C:\Jdk, constructPath will return C:\Jdk).
424
    *
425
    * @param change
426
    *                The modification to apply to the path
427
    * @see Utils#beginsWithRoot(String), Utils#getRoot(String)
428
    */
429

  
430
   public static String constructPath(final String change) {
431
      if (change == null || beginsWithRoot(change)) {
432
         return change;
433
      }
434

  
435
      String newPath = getUserDirectory();
436

  
437
      char current;
438
      char lastChar = '\0';
439
      boolean toAdd = false;
440
      StringBuffer buf = new StringBuffer(change.length());
441

  
442
      for (int i = 0; i < change.length(); i++) {
443
         switch ((current = change.charAt(i))) {
444
            case '.':
445
               if (lastChar == '.') {
446
                  final String parent = (new File(newPath)).getParent();
447
                  if (parent != null) {
448
                     newPath = parent;
449
                  }
450
               }
451
               else if (lastChar != '\0' && lastChar != '\\' && lastChar != '/') {
452
                  buf.append('.');
453
               }
454
               lastChar = '.';
455
               break;
456
            case '\\':
457
            case '/':
458
               if (lastChar == '\0') {
459
                  newPath = getRoot(newPath);
460
               }
461
               else {
462
                  if (!newPath.endsWith("\\")) {
463
                     newPath += File.separator + buf.toString();
464
                  }
465
                  else {
466
                     newPath += buf.toString();
467
                  }
468
                  buf = new StringBuffer();
469
                  toAdd = false;
470
               }
471
               lastChar = '\\';
472
               break;
473
            case '~':
474
               if (i < change.length() - 1) {
475
                  if (change.charAt(i + 1) == '\\' || change.charAt(i + 1) == '/') {
476
                     newPath = System.getProperties().getProperty("user.home");
477
                  }
478
                  else {
479
                     buf.append('~');
480
                  }
481
               }
482
               else if (i == 0) {
483
                  newPath = System.getProperties().getProperty("user.home");
484
               }
485
               else {
486
                  buf.append('~');
487
               }
488
               lastChar = '~';
489
               break;
490
            default:
491
               lastChar = current;
492
               buf.append(current);
493
               toAdd = true;
494
               break;
495
         }
496
      }
497

  
498
      if (toAdd) {
499
         if (!newPath.endsWith(File.separator)) {
500
            newPath += File.separator + buf.toString();
501
         }
502
         else {
503
            newPath += buf.toString();
504
         }
505
      }
506

  
507
      return newPath;
508
   }
509

  
510

  
511
   /**
512
    * It can be necessary to determine which is the root of a path. For example, the root of D:\Projects\Java is D:\.
513
    *
514
    * @param path
515
    *                The path used to get a root
516
    * @return The root which contais the specified path
517
    */
518

  
519
   public static String getRoot(final String path) {
520
      final File roots[] = listRoots(new File(path));
521

  
522
      for (int i = 0; i < roots.length; i++) {
523
         if (path.startsWith(roots[i].getPath())) {
524
            return roots[i].getPath();
525
         }
526
      }
527

  
528
      return path;
529
   }
530

  
531

  
532
   /**
533
    * It can be necessary to determine if a path begins with a root.
534
    *
535
    * @param path
536
    *                The path to check
537
    * @return True if path begins with a root, false otherwise
538
    */
539

  
540
   public static boolean beginsWithRoot(final String path) {
541
      final File roots[] = listRoots(new File(path));
542

  
543
      for (int i = 0; i < roots.length; i++) {
544
         if (path.regionMatches(true, 0, roots[i].getPath(), 0, roots[i].getPath().length())) {
545
            return true;
546
         }
547
      }
548

  
549
      return false;
550
   }
551

  
552

  
553
   /**
554
    * We override a Java2 specific method.
555
    *
556
    * @param f
557
    *                A File
558
    * @return A list of standards roots
559
    */
560

  
561
   public static File[] listRoots(final File f) {
562
      if (System.getProperty("os.name").startsWith("Windows")) {
563
         return new File[] { new File("A:\\"), new File("B:\\"), new File("C:\\"), new File("D:\\"), new File("E:\\"),
564
                  new File("F:\\"), new File("G:\\"), new File("H:\\"), new File("I:\\") };
565
         //return new File[]{new File(System.getProperty("java.home").substring(0, 3))};
566
      }
567
      else {
568
         return new File[] { new File("/") };
569
      }
570
   }
571

  
572

  
573
   /**
574
    * We override a Java2 spcific method.
575
    *
576
    * @param file
577
    *                Determine if this file is hidden or not
578
    * @return Always false
579
    */
580

  
581
   public boolean isHidden(final File file) {
582
      return false;
583
   }
584

  
585
}
586

  
587
// End of Utils.java
0 588

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.72/org.gvsig.toolbox.gui/src/main/java/es/unex/sextante/gui/grass/GrassBlackList.java
1
package es.unex.sextante.gui.grass;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import es.unex.sextante.core.Sextante;
7

  
8

  
9
/**
10
 * A hard-coded list of those GRASS algorithms not compatible with SEXTANTE, that should not be shown in the toolbox or any other
11
 * SEXTANTE component
12
 *
13
 * @author volaya
14
 *
15
 */
16
public class GrassBlackList {
17

  
18
   private static List           m_List;
19
   private static final String[] ALGS = { "v.build.polylines", "v.build", "v.category", "v.convert", "v.db.connect",
20
            "v.digit", "v.in.db", "v.in.sites", "v.kernel", "v.label.sa",
21
            "v.label", "v.lrs.create", "v.lrs.label", "v.lrs.segment", "v.lrs.where", "v.proj", "v.support", "v.to.rast3",
22
            "v.what", "v.what.rast", "r.compress", "r.random.surface", "r.region",
23
            "r.support", "r.support.stats", "r.timestamp", "r.to.rast3", "r.to.rast3elev", "r.what",
24
            "r.what.color", "v.net.alloc", "v.net", "v.net.iso", "v.net.path", "v.net.salesman", "v.net.steiner", "v.net.visibility",
25
            "r.le.setup", "r.le.patch","r.le.pixel","r.le.trace","r.li.cwed","r.li.dominance","r.li.edgedensity",
26
            "r.li.mpa","r.li.mps","r.li.padcv","r.li.padrange","r.li.padsd","r.li.patchdensity","r.li.patchnum",
27
            "r.li.richness","r.li.setup","r.li.shannon","r.li.shape","r.li.simpson","r.series",
28
            "r.blend","r.cats", "r.mask", "r.tileset","v.build.all", "v.centroids", "v.convert.all",
29
            "v.db.addcol","v.db.addtable","v.db.dropcol","v.db.droptable","v.db.join","v.db.reconnect.all",
30
            "v.db.renamecol","v.db.univar","v.db.update","v.in.e00","v.in.sites.all","v.univar.sh",
31
            "r.external","v.external", "v.colors", "v.in.garmin", "v.in.gpsbabel", "v.out.gpsbabel",
32
            "r.proj", "v.proj", "r.category"}; 
33
   
34
   static {
35

  
36
      m_List = new ArrayList();
37
      for (int i = 0; i < ALGS.length; i++) {
38
         m_List.add(ALGS[i]);
39
      }
40

  
41
   }
42

  
43

  
44
   public static boolean isInBlackList(final GrassAlgorithm alg) {
45

  
46
	   return ( isInBlackList (alg.getName()) );
47

  
48
   }
49

  
50

  
51
   public static boolean isInBlackList(final String sName) {
52
	   if ( m_List.contains(sName)) {
53
		   Sextante.addWarningToLog("SEXTANTE GRASS interface: Module " + sName + " disabled: blacklisted.");
54
		   return ( true );
55
	   }
56
	   return ( false );
57
   }
58
   
59

  
60
}
0 61

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.72/org.gvsig.toolbox.gui/src/main/java/es/unex/sextante/gui/grass/GrassModelerParametersPanel.java
1
package es.unex.sextante.gui.grass;
2

  
3
import info.clearthought.layout.TableLayoutConstants;
4

  
5
import java.util.HashMap;
6

  
7
import javax.swing.JComboBox;
8
import javax.swing.JPanel;
9
import javax.swing.JTextField;
10

  
11
import es.unex.sextante.additionalInfo.AdditionalInfoNumericalValue;
12
import es.unex.sextante.core.ObjectAndDescription;
13
import es.unex.sextante.core.OutputObjectsSet;
14
import es.unex.sextante.core.Sextante;
15
import es.unex.sextante.gui.algorithm.ParameterContainer;
16
import es.unex.sextante.gui.modeler.DefaultModelerParametersPanel;
17
import es.unex.sextante.gui.modeler.OutputLayerSettingsPanel;
18
import es.unex.sextante.gui.modeler.OutputParameterContainer;
19
import es.unex.sextante.outputs.Output;
20
import es.unex.sextante.parameters.Parameter;
21

  
22
public class GrassModelerParametersPanel
23
         extends
24
            DefaultModelerParametersPanel {
25

  
26
   private JComboBox jComboRestrictGeometryType;
27

  
28

  
29
   @Override
30
   protected void addOutputObjects(final JPanel pane) {
31

  
32
      super.addOutputObjects(pane);
33

  
34
      addTitleLabel(pane, Sextante.getText("grass_restrict_geometry_ouput"), m_iCurrentRow, false);
35
      
36
      final String[] options = new String[] { Sextante.getText("Points"), Sextante.getText("Lines"), Sextante.getText("Polygons") };
37
      jComboRestrictGeometryType = new JComboBox(options);
38
      pane.add(jComboRestrictGeometryType, getStringTableCoords(2, m_iCurrentRow));
39
      m_iCurrentRow++;
40

  
41
   }
42

  
43

  
44
   private boolean makeNumericalValueAssignment(final HashMap map,
45
		   final ParameterContainer parameterContainer) {
46

  
47
	   double dValue;
48
	   ObjectAndDescription oad;
49
	   Parameter parameter = null;
50
	   String sKey = null, sInnerKey;
51
	   Double value;
52
	   String sAssignment;
53

  
54
	   final JComboBox comboBox = (JComboBox) parameterContainer.getContainer();
55
	   final JTextField textField = (JTextField) comboBox.getEditor().getEditorComponent();
56
	   final String sValue = textField.getText();
57

  
58
	   try {
59
		   parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
60
		   final AdditionalInfoNumericalValue ai = (AdditionalInfoNumericalValue) parameter.getParameterAdditionalInfo();
61
		   final double dMin = ai.getMinValue();
62
		   final double dMax = ai.getMaxValue();
63
		   sKey = parameter.getParameterName();
64
		   final Object ob = comboBox.getSelectedItem();
65
		   if (ob instanceof ObjectAndDescription) {
66
			   oad = (ObjectAndDescription) ob;
67
			   sAssignment = (String) oad.getObject();
68
			   map.put(sKey, sAssignment);
69
			   return true;
70
		   }
71
		   else {
72
			   try {
73
				   dValue = Double.parseDouble(sValue);
74
				   if ((dValue < dMin) || (dValue > dMax)) {
75
					   return false;
76
				   }
77
				   sInnerKey = getInnerParameterKey();
78
				   map.put(sKey, sInnerKey);
79
				   value = new Double(dValue);
80
				   m_DataObjects.put(sInnerKey, new ObjectAndDescription("Numerical Value", value));
81
				   return true;
82
			   }
83
			   catch (final NumberFormatException e) {
84
				   return false;
85
			   }
86
		   }
87
	   }
88
	   catch (final Exception e) {
89
		   Sextante.addErrorToLog(e);
90
		   return false;
91
	   }
92

  
93
   }   
94
   
95
   
96
   @Override
97
   public boolean assignParameters(final HashMap map) {	   
98

  
99

  
100
	   boolean bAssigningOK = true;
101
	   int i;
102
	   ParameterContainer parameterContainer;	   
103

  
104
	   /* Many GRASS modules have non-mandatory Numerical and String options.
105
	    * Therefore, we cannot use a strict settings check for GRASS algorithms. */
106
	   for (i = 0; i < m_InputParameterContainer.size(); i++) {
107
		   parameterContainer = (ParameterContainer) m_InputParameterContainer.get(i);
108
		   if (parameterContainer.getType().equals("Table") || parameterContainer.getType().equals("Vector Layer")
109
				   || parameterContainer.getType().equals("Raster Layer") || parameterContainer.getType().equals("Point")) {
110
			   makeDataObjectAssignment(map, parameterContainer);
111
		   }
112
		   else if (parameterContainer.getType().equals("Multiple Input")) {
113
			   makeMultipleInputAssignment(map, parameterContainer);
114
		   }
115
		   else if (parameterContainer.getType().equals("Numerical Value")) {
116
			   makeNumericalValueAssignment(map, parameterContainer);
117
			   bAssigningOK = true;
118
		   }
119
		   else if (parameterContainer.getType().equals("String")) {
120
			   makeStringAssignment(map, parameterContainer);
121
			   bAssigningOK = true;
122
		   }
123
		   else if (parameterContainer.getType().equals("Boolean")) {
124
			   bAssigningOK = makeBooleanAssignment(map, parameterContainer);
125
		   }
126
		   else if (parameterContainer.getType().equals("Fixed Table")) {
127
			   bAssigningOK = makeFixedTableAssignment(map, parameterContainer);
128
		   }
129
		   else if (parameterContainer.getType().equals("Filepath")) {
130
			   bAssigningOK = makeFilepathAssignment(map, parameterContainer);
131
		   }
132
		   else if (parameterContainer.getType().equals("Band")) {
133
			   bAssigningOK = makeRasterBandAssignment(map, parameterContainer);
134
		   }
135
		   else if (parameterContainer.getType().equals("Table Field")) {
136
			   makeTableFieldAssignment(map, parameterContainer);
137
			   bAssigningOK = true;
138
		   }
139
		   else if (parameterContainer.getType().equals("Selection")) {
140
			   bAssigningOK = makeSelectionAssignment(map, parameterContainer);
141
		   }
142

  
143
		   if (!bAssigningOK) {
144
			   return false;
145
		   }
146
	   }
147

  
148
	   m_GlobalAlgorithm.setGeometryTypeRestriction(jComboRestrictGeometryType.getSelectedIndex());
149
	   
150
	   /* set output objects */
151
	   final OutputObjectsSet oosetGlobal = this.m_GlobalAlgorithm.getOutputObjects();
152
	   final OutputObjectsSet ooset = this.m_Algorithm.getOutputObjects();
153

  
154
	   for (i = 0; i < m_OutputParameterDefinitionContainer.size(); i++) {
155
		   final OutputParameterContainer opc = (OutputParameterContainer) m_OutputParameterDefinitionContainer.get(i);
156
		   final OutputLayerSettingsPanel olsp = (OutputLayerSettingsPanel) opc.getContainer();
157
		   final String sName = opc.getName() + this.m_sAlgorithmName;
158
		   if (olsp.getKeepAsFinalResult()) {
159
			   try {
160
				   final Output out = ooset.getOutput(opc.getName());
161
				   final Output outToAdd = out.getClass().newInstance();
162
				   outToAdd.setName(sName);
163
				   outToAdd.setDescription(olsp.getName());
164
				   oosetGlobal.add(outToAdd);
165
			   }
166
			   catch (final Exception e) {
167
			   }
168
		   }
169
		   else {
170
			   oosetGlobal.remove(sName);
171
		   }
172
	   }	   
173
	   
174
	   return (true);
175
   }
176

  
177

  
178
   @Override
179
   protected double[][] getTableLayoutMatrix() {
180

  
181
      int i;
182
      int iRows = 0;
183

  
184
      final double iSizeColumns[] = { 10, TableLayoutConstants.FILL, 360, 10 };
185

  
186
      iRows += m_Algorithm.getNumberOfParameters();
187

  
188
      if (m_Algorithm.requiresRasterLayers() || m_Algorithm.requiresMultipleRasterLayers()
189
          || m_Algorithm.requiresMultipleRasterBands()) {
190
         iRows++;
191
      }
192
      if (m_Algorithm.requiresVectorLayers() || m_Algorithm.requiresMultipleVectorLayers()) {
193
         iRows++;
194
      }
195
      if (m_Algorithm.requiresTables() || m_Algorithm.requiresMultipleTables()) {
196
         iRows++;
197
      }
198
      if (m_Algorithm.requires3DRasterLayers()) {
199
         iRows++;
200
      }
201
      if (m_Algorithm.requiresNonDataObjects()) {
202
         iRows++;
203
      }
204

  
205
      final OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
206
      int iOutput = ooSet.getOutputObjectsCount();
207

  
208
      final int iVectorLayers = ooSet.getVectorLayersCount();
209
      if (iVectorLayers != 0) {
210
         iRows += 2;
211
         iOutput += 2;
212
      }
213

  
214
      if (iOutput != 0) {
215
         iRows += (iOutput + 1);
216
      }
217

  
218

  
219
      final double iSizeRows[] = new double[iRows];
220
      for (i = 0; i < iRows - iOutput; i++) {
221
         iSizeRows[i] = CELL_HEIGHT;
222
      }
223
      for (i = iRows - iOutput; i < iRows; i++) {
224
         iSizeRows[i] = CELL_HEIGHT * 2.5;
225
      }
226

  
227
      final double iSize[][] = new double[2][];
228
      iSize[0] = iSizeColumns;
229
      iSize[1] = iSizeRows;
230

  
231
      return iSize;
232

  
233
   }
234

  
235

  
236
}
0 237

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.72/org.gvsig.toolbox.gui/src/main/java/es/unex/sextante/gui/grass/GrassProgressMonitor.java
1
package es.unex.sextante.gui.grass;
2

  
3
import info.clearthought.layout.TableLayout;
4
import info.clearthought.layout.TableLayoutConstants;
5

  
6
import java.awt.Color;
7
import java.awt.Dimension;
8
import java.awt.Font;
9
import java.awt.event.ActionEvent;
10
import java.awt.event.ActionListener;
11

  
12
import javax.swing.JButton;
13
import javax.swing.JDialog;
14
import javax.swing.JLabel;
15
import javax.swing.JProgressBar;
16
import javax.swing.JScrollPane;
17
import javax.swing.JTextPane;
18
import javax.swing.SwingUtilities;
19
import javax.swing.WindowConstants;
20
import javax.swing.text.DefaultStyledDocument;
21

  
22
import es.unex.sextante.gui.core.SextanteGUI;
23
import es.unex.sextante.gui.toolbox.TransparentScrollPane;
24

  
25
/**
26
 * An extended progress monitor for GRASS modules showing a progress bar and a text output area.
27
 *
28
 * @author volaya
29
 *
30
 */
31
public class GrassProgressMonitor
32
         extends
33
            JDialog {
34

  
35
   private StringBuffer sTextBuffer;
36

  
37
   private JLabel       jTitle;
38
   private JButton      jButtonCancel;
39
   private JProgressBar jProgressBar;
40
   private JScrollPane  jScrollPaneGRASS;
41
   private JTextPane    jTextGRASS;
42
   private boolean      m_bCanceled;
43

  
44

  
45
   /**
46
    * Constructor
47
    *
48
    * @param sText
49
    *                The text to show
50
    * @param bDeterminate
51
    *                true if the process to monitor is determinate
52
    * @param parent
53
    *                the parent dialog
54
    */
55
   public GrassProgressMonitor(final String sText,
56
                               final boolean bDeterminate,
57
                               final JDialog parent) {
58

  
59
      super(parent, "", false);
60

  
61
      setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
62
      setLocationRelativeTo(null);
63

  
64
      m_bCanceled = false;
65

  
66
      initGUI(sText, bDeterminate);
67

  
68
   }
69

  
70

  
71
   /**
72
    * Constructor. Uses the main frame as the parent component
73
    *
74
    * @param sText
75
    *                The text to show
76
    * @param bDeterminate
77
    *                true if the process to monitor is determinate
78
    */
79
   public GrassProgressMonitor(final String sText,
80
                               final boolean bDeterminate) {
81

  
82
      super(SextanteGUI.getMainFrame(), "", false);
83

  
84
      setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
85
      setLocationRelativeTo(null);
86

  
87
      m_bCanceled = false;
88

  
89
      initGUI(sText, bDeterminate);
90

  
91
   }
92

  
93

  
94
   private void initGUI(final String sText,
95
                        boolean bDeterminate) {
96

  
97
      final TableLayout thisLayout = new TableLayout(new double[][] {
98
               { 6.0, TableLayoutConstants.FILL, TableLayoutConstants.FILL, 6.0 },
99
               { 1.0, TableLayoutConstants.FILL, TableLayoutConstants.FILL, 1, 15.0, 1.0, 25.0, 1.0 } });
100
      thisLayout.setHGap(5);
101
      thisLayout.setVGap(5);
102
      setPreferredSize(new Dimension(650, 450));
103
      setSize(new Dimension(350, 450));
104
      getContentPane().setLayout(thisLayout);
105
      {
106
         jTitle = new JLabel(sText);
107
         getContentPane().add(jTitle, "1, 1, 2, 1");
108
      }
109
      {
110
         jButtonCancel = new JButton();
111
         getContentPane().add(jButtonCancel, "2, 6");
112
         jButtonCancel.setText("Cancelar");
113
         jButtonCancel.addActionListener(new ActionListener() {
114
            public void actionPerformed(final ActionEvent evt) {
115
               cancel();
116
            }
117
         });
118
      }
119
      {
120
         jProgressBar = new JProgressBar();
121
         jProgressBar.setIndeterminate(!bDeterminate);
122
         if (bDeterminate) {
123
            jProgressBar.setMinimum(0);
124
            jProgressBar.setMaximum(100);
125
            jProgressBar.setValue(0);
126
         }
127
         getContentPane().add(jProgressBar, "1, 4, 2, 4");
128
      }
129
      {
130
         jTextGRASS = new NonWordWrapPane();
131
         jTextGRASS.setStyledDocument(new DefaultStyledDocument());
132
         jTextGRASS.setFont(new Font("Monospaced", Font.PLAIN, 12));
133
         jTextGRASS.setContentType("text/plain");
134
         jTextGRASS.setEditable(false);
135
         jScrollPaneGRASS = new TransparentScrollPane();
136
         jScrollPaneGRASS.setBackground(Color.white);
137
         jScrollPaneGRASS.setSize(new java.awt.Dimension(650, 450));
138
         jScrollPaneGRASS.setViewportView(jTextGRASS);
139
         getContentPane().add(jScrollPaneGRASS, "1, 2, 2, 2");
140
      }
141

  
142
      sTextBuffer = new StringBuffer("");
143

  
144
   }
145

  
146

  
147
   private void cancel() {
148

  
149
      m_bCanceled = true;
150

  
151
   }
152

  
153

  
154
   /**
155
    * Returns true if the process has been canceled using the cancel button
156
    *
157
    * @return true if the process has been canceled
158
    */
159
   public boolean isCanceled() {
160

  
161
      return m_bCanceled;
162

  
163
   }
164

  
165

  
166
   /**
167
    * Adds a line of status text output to the text area.
168
    *
169
    * @param sText
170
    *                the description
171
    */
172
   public void addText(final String sText) {
173

  
174
      try {
175
         SwingUtilities.invokeAndWait(new Runnable() {
176
            public void run() {
177
               sTextBuffer.append(sText);
178
               jTextGRASS.setText("");
179
            }
180
         });
181
      }
182
      catch (final Exception e) {}
183

  
184

  
185
   }
186

  
187

  
188
	/**
189
	 * Sets the description to show at the top of the progress monitor
190
	 *
191
	 * @param sDescription
192
	 *                the description
193
	 */
194
	public void setDescription(final String sDescription) {
195

  
196
		try {
197
			Runnable runnable = new Runnable() {
198
				public void run() {
199
					jTitle.setText(sDescription);
200
				}
201
			};
202
			if (SwingUtilities.isEventDispatchThread()){
203
				runnable.run();
204
			}
205
			else{
206
				SwingUtilities.invokeAndWait(runnable);
207
			}
208
		}
209
		catch (final Exception e) {}
210

  
211

  
212
	}
213

  
214

  
215
	/**
216
	 * Sets the current progress value (in the range 1-100)
217
	 *
218
	 * @param iValue
219
	 */
220
	public void setProgress(final int iValue) {
221

  
222
		try {
223
			Runnable runnable = new Runnable() {
224
				public void run() {
225
					jProgressBar.setValue(iValue);
226
				}
227
			};
228
			if (SwingUtilities.isEventDispatchThread()){
229
				runnable.run();
230
			}
231
			else{
232
				SwingUtilities.invokeAndWait(runnable);
233
			}
234
		}
235
		catch (final Exception e) {}
236

  
237
	}
238

  
239

  
240
	/**
241
	 * Sets whether the process being monitored is determinate or not
242
	 *
243
	 * @param bDeterminate
244
	 */
245
	public void setDeterminate(final boolean bDeterminate) {
246

  
247
		try {
248
			Runnable runnable = new Runnable() {
249
				public void run() {
250
					jProgressBar.setIndeterminate(!bDeterminate);
251
				}
252
			};
253
			if (SwingUtilities.isEventDispatchThread()){
254
				runnable.run();
255
			}
256
			else{
257
				SwingUtilities.invokeAndWait(runnable);
258
			}
259
		}
260
		catch (final Exception e) {}
261

  
262
	}
263

  
264

  
265
   private class NonWordWrapPane
266
            extends
267
               JTextPane {
268

  
269
      public NonWordWrapPane() {
270

  
271
         super();
272

  
273
      }
274

  
275

  
276
      @Override
277
      public boolean getScrollableTracksViewportWidth() {
278

  
279
         return false;
280

  
281
      }
282

  
283
   }
284

  
285
}
0 286

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.72/org.gvsig.toolbox.gui/src/main/java/es/unex/sextante/gui/grass/UnwrappableGrassProcessException.java
1
package es.unex.sextante.gui.grass;
2

  
3
public class UnwrappableGrassProcessException
4
         extends
5
            Exception {
6

  
7
}
0 8

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.72/org.gvsig.toolbox.gui/src/main/java/es/unex/sextante/gui/grass/GrassModelerBlackList.java
1
package es.unex.sextante.gui.grass;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import es.unex.sextante.core.Sextante;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff