Revision 43266

View differences:

tags/org.gvsig.desktop-2.0.183/org.gvsig.desktop.buildtools/src/main/resources/gvsig/checkstyle.xml
1
<?xml version="1.0"?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
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 3
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., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<!DOCTYPE module PUBLIC
28
    "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
29
    "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
30

  
31
<!--
32

  
33
  Checkstyle configuration that checks the sun coding conventions from:
34

  
35
    - the Java Language Specification at
36
      http://java.sun.com/docs/books/jls/second_edition/html/index.html
37

  
38
    - the Sun Code Conventions at http://java.sun.com/docs/codeconv/
39

  
40
    - the Javadoc guidelines at
41
      http://java.sun.com/j2se/javadoc/writingdoccomments/index.html
42

  
43
    - the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html
44

  
45
    - some best practices
46

  
47
  Checkstyle is very configurable. Be sure to read the documentation at
48
  http://checkstyle.sf.net (or in your downloaded distribution).
49

  
50
  Most Checks are configurable, be sure to consult the documentation.
51

  
52
  To completely disable a check, just comment it out or delete it from the file.
53

  
54
  Finally, it is worth reading the documentation.
55

  
56
-->
57

  
58
<module name="Checker">
59
    <!--
60
        If you set the basedir property below, then all reported file
61
        names will be relative to the specified directory. See
62
        http://checkstyle.sourceforge.net/5.x/config.html#Checker
63

  
64
        <property name="basedir" value="${basedir}"/>
65
    -->
66
    <!-- gvSIG: All project files have the ISO-8859-1 charset -->
67
	<property name="charset" value="ISO-8859-1" />
68

  
69
    <!-- Checks that a package-info.java file exists for each package.     -->
70
    <!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage -->
71
	<module name="JavadocPackage">
72
		<property name="allowLegacy" value="true" />
73
	</module>
74

  
75
    <!-- Checks whether files end with a new line.                        -->
76
    <!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
77
    <module name="NewlineAtEndOfFile"/>
78

  
79
    <!-- Checks that property files contain the same keys.         -->
80
    <!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
81
    <module name="Translation"/>
82
    
83
    <!-- Checks for Size Violations.                    -->
84
    <!-- See http://checkstyle.sf.net/config_sizes.html -->
85
    <module name="FileLength"/>
86
    
87
    <!-- Checks for whitespace                               -->
88
    <!-- See http://checkstyle.sf.net/config_whitespace.html -->
89
    <module name="FileTabCharacter"/>
90

  
91

  
92
    <module name="TreeWalker">
93

  
94
	    <!-- Miscellaneous other checks.                   -->
95
	    <!-- See http://checkstyle.sf.net/config_misc.html -->
96
	    <!-- gvSIG: apply only to java files -->
97
	    <module name="RegexpSinglelineJava">
98
	       <property name="format" value="\s+$"/>
99
	       <property name="minimum" value="0"/>
100
	       <property name="maximum" value="0"/>
101
	       <property name="message" value="Line has trailing spaces."/>
102
	       <property name="ignoreComments" value="true"/>
103
	    </module>
104
	    
105
        <!-- Checks for Javadoc comments.                     -->
106
        <!-- See http://checkstyle.sf.net/config_javadoc.html -->
107
		<!--
108
			gvSIG rule 3: All protected or public classes must have a Javadoc comments,
109
			except getters and setters
110
		-->
111
		<module name="JavadocMethod">
112
			<property name="scope" value="protected" />
113
			<property name="allowMissingPropertyJavadoc" value="true" />
114
		</module>
115
		<!--
116
			gvSIG rule 9: All classes must have a Javadoc comment
117
			with the "@author tag" and the "@version $Id$" tag included 
118
		-->
119
		<module name="JavadocType">
120
			<property name="scope" value="private" />
121
			<property name="authorFormat" value="\S" />
122
			<property name="versionFormat" value="\$Id.*\$"/>
123
		</module>
124
        <module name="JavadocVariable">
125
			<property name="scope" value="protected" />
126
		</module>
127
		<!-- gvSIG rule 3: Check correctly formatted Javadoc -->
128
		<module name="JavadocStyle">
129
			<property name="scope" value="protected" />
130
		</module>
131

  
132

  
133
        <!-- Checks for Naming Conventions.                  -->
134
        <!-- See http://checkstyle.sf.net/config_naming.html -->
135
        <module name="ConstantName"/>
136
        <module name="LocalFinalVariableName"/>
137
        <module name="LocalVariableName"/>
138
        <module name="MemberName"/>
139
        <module name="MethodName"/>
140
		<!-- gvSIG rule 15: All packages must begin with org.gvsig.  -->
141
		<module name="PackageName">
142
			<property name="format" value="^org\.gvsig(\.[a-z][a-z0-9]*)+$" />
143
		</module>
144
		<!-- gvSIG advised rule 1: Abstract class names must begin with Abstract. -->
145
		<!-- module name="AbstractClassName" /-->
146
        <module name="ParameterName"/>
147
        <module name="StaticVariableName"/>
148
        <module name="TypeName"/>
149

  
150
        <!-- Checks for imports                              -->
151
        <!-- See http://checkstyle.sf.net/config_import.html -->
152
        <module name="AvoidStarImport"/>
153
        <module name="IllegalImport"/> <!-- defaults to sun.* packages -->
154
        <module name="RedundantImport"/>
155
        <module name="UnusedImports"/>
156

  
157

  
158
        <!-- Checks for Size Violations.                    -->
159
        <!-- See http://checkstyle.sf.net/config_sizes.html -->
160
        <module name="LineLength"/>
161
        <module name="MethodLength"/>
162
        <module name="ParameterNumber"/>
163

  
164

  
165
        <!-- Checks for whitespace                               -->
166
        <!-- See http://checkstyle.sf.net/config_whitespace.html -->
167
        <module name="EmptyForIteratorPad"/>
168
        <module name="GenericWhitespace"/>
169
        <module name="MethodParamPad"/>
170
        <module name="NoWhitespaceAfter"/>
171
        <module name="NoWhitespaceBefore"/>
172
        <module name="OperatorWrap"/>
173
        <module name="ParenPad"/>
174
        <module name="TypecastParenPad"/>
175
        <module name="WhitespaceAfter"/>
176
        <module name="WhitespaceAround"/>
177

  
178

  
179
        <!-- Modifier Checks                                    -->
180
        <!-- See http://checkstyle.sf.net/config_modifiers.html -->
181
        <module name="ModifierOrder"/>
182
        <module name="RedundantModifier"/>
183

  
184

  
185
        <!-- Checks for blocks. You know, those {}'s         -->
186
        <!-- See http://checkstyle.sf.net/config_blocks.html -->
187
        <module name="AvoidNestedBlocks"/>
188
        <module name="EmptyBlock"/>
189
        <module name="LeftCurly"/>
190
        <module name="NeedBraces"/>
191
        <module name="RightCurly"/>
192

  
193

  
194
        <!-- Checks for common coding problems               -->
195
        <!-- See http://checkstyle.sf.net/config_coding.html -->
196
        <module name="AvoidInlineConditionals"/>
197
        <module name="DoubleCheckedLocking"/>    <!-- MY FAVOURITE -->
198
        <module name="EmptyStatement"/>
199
        <module name="EqualsHashCode"/>
200
        <module name="HiddenField"/>
201
        <module name="IllegalInstantiation"/>
202
        <module name="InnerAssignment"/>
203
        <module name="MagicNumber"/>
204
        <module name="MissingSwitchDefault"/>
205
        <module name="RedundantThrows"/>
206
        <module name="SimplifyBooleanExpression"/>
207
        <module name="SimplifyBooleanReturn"/>
208

  
209
		<!-- gvSIG: Check for some common programming errors -->
210
		<module name="CovariantEquals" />
211
		<module name="StringLiteralEquality" />
212

  
213
        <!-- Checks for class design                         -->
214
        <!-- See http://checkstyle.sf.net/config_design.html -->
215
        <module name="DesignForExtension"/>
216
        <module name="FinalClass"/>
217
        <module name="HideUtilityClassConstructor"/>
218
        <module name="InterfaceIsType"/>
219
        <module name="VisibilityModifier"/>
220

  
221

  
222
        <!-- Miscellaneous other checks.                   -->
223
        <!-- See http://checkstyle.sf.net/config_misc.html -->
224
        <module name="ArrayTypeStyle"/>
225
        <!-- gvSIG: removed -->
226
        <!-- module name="FinalParameters"/-->
227
        <module name="TodoComment"/>
228
        <module name="UpperEll"/>
229
				
230
	    <!-- gvSIG rule 2: Sun style with 4 spaces -->
231
	    <module name="Indentation">
232
	    	<property name="basicOffset" value="4"/>
233
		    <property name="caseIndent" value="0"/>
234
		</module>
235
        
236
        <!-- gvSIG rule 10: Do not use System.out/err to log -->
237
		<module name="Regexp">
238
		    <!-- . matches any character, so we need to escape it and use \. 
239
		    to match dots.-->
240
		    <property name="format" value="System\.[out|err]\.println"/>
241
		    <property name="illegalPattern" value="true"/>
242
		</module>
243
		
244
		<!-- gvSIG rule 11: Try to avoid catching Throwable or 
245
		Exception and catch specific exceptions instead. -->
246
		<module name="IllegalCatch"/>
247
		
248
		<!-- gvSIG rule 13: Use interfaces in the declaration of 
249
		methods and variables.
250
        By default only avoids usage of Classes:
251
			"java.util.GregorianCalendar, java.util.Hashtable, 
252
		  	java.util.HashSet, java.util.HashMap, java.util.ArrayList, 
253
		  	java.util.LinkedList, java.util.LinkedHashMap, 
254
		  	java.util.LinkedHashSet, java.util.TreeSet, 
255
		  	java.util.TreeMap, java.util.Vector" -->
256
		<module name="IllegalType">
257
		    <property name="ignoredMethodNames" value="getInstance"/>
258
		</module>
259
		
260
    </module>
261

  
262
	<!--  gvSIG rule 1: check for the gvSIG header -->
263
    <!-- Uneeded, use the maven-license-plugin instead
264
	<module name="RegexpHeader"> -->
265
		<!-- The follow property value demonstrates the ability     -->
266
		<!-- to have access to ANT properties. In this case it uses -->
267
		<!-- the ${basedir} property to allow Checkstyle to be run  -->
268
		<!-- from any directory within a project. See property      -->
269
		<!-- expansion,                                             -->
270
		<!-- http://checkstyle.sf.net/config.html#properties        -->
271
    <!--
272
		<property name="headerFile" value="${checkstyle.header.file}" />
273
	</module>
274
    -->
275

  
276
</module>
0 277

  
tags/org.gvsig.desktop-2.0.183/org.gvsig.desktop.buildtools/src/main/resources/header.txt
1
gvSIG. Desktop Geographic Information System.
2

  
3
Copyright (C) 2007-2013 gvSIG Association.
4
  
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation; either version 3
8
of the License, or (at your option) any later version.
9
  
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14
 
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
18
MA  02110-1301, USA.
19

  
20
For any additional information, do not hesitate to contact us 
21
at info AT gvsig.com, or visit our website www.gvsig.com.
0 22

  
tags/org.gvsig.desktop-2.0.183/org.gvsig.desktop.buildtools/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/xsd/maven-4.0.0.xsd">
3
  <modelVersion>4.0.0</modelVersion>
4
  <groupId>org.gvsig</groupId>
5
  <artifactId>org.gvsig.desktop.buildtools</artifactId>
6
  <version>1.0.0</version>
7
  <packaging>jar</packaging>
8
  <name>${project.artifactId}</name>
9
  <description>Resources used for build gvsig desktop</description>
10

  
11

  
12
<!-- No puede ser hijo de org.gvsig.desktop para evitar referencas circulares -->
13
<!--
14
  <parent>
15
    <groupId>org.gvsig</groupId>
16
    <artifactId>org.gvsig.desktop</artifactId>
17
    <version>2.0.10-SNAPSHOT</version>
18
  </parent>  
19
-->
20

  
21

  
22
    <licenses>
23
        <license>
24
            <name>GPLv3</name>
25
            <url>http://www.gnu.org/licenses/gpl.html</url>
26
            <distribution>repo</distribution>
27
            <comments>
28
			"GPL" stands for "General Public License". The most widespread such
29
			license is the GNU General Public License, or GNU GPL for short.
30
			This can be further shortened to "GPL", when it is understood that
31
			the GNU GPL is the one intended.
32
	      	</comments>
33
        </license>
34
    </licenses>
35

  
36
    <organization>
37
        <name>gvSIG Association</name>
38
        <url>http://www.gvsig.com/</url>
39
    </organization>
40

  
41
    <scm>
42
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-desktop/trunk</connection>
43
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-desktop/trunk</developerConnection>
44
        <url>https://devel.gvsig.org/redmine/projects/gvsig-desktop/repository/show/trunk</url>
45
    </scm>
46
    
47
    <repositories>
48
      <repository>
49
        <id>gvsig-public-http-repository</id>
50
        <name>gvSIG maven public HTTP repository</name>
51
        <url>http://devel.gvsig.org/m2repo/j2se</url>
52
        <releases>
53
          <enabled>true</enabled>
54
          <updatePolicy>daily</updatePolicy>
55
          <checksumPolicy>warn</checksumPolicy>
56
        </releases>
57
        <snapshots>
58
          <enabled>true</enabled>
59
          <updatePolicy>daily</updatePolicy>
60
          <checksumPolicy>warn</checksumPolicy>
61
        </snapshots>
62
      </repository>
63
    </repositories>
64

  
65
    <distributionManagement>
66
      <site>
67
        <id>gvsig-repository</id>
68
        <url>dav:https://devel.gvsig.org/sites/${project.artifactId}/${project.version}</url>
69
      </site>
70
      <repository>
71
          <id>gvsig-repository</id>
72
          <name>gvSIG maven repository</name>
73
          <url>dav:https://devel.gvsig.org/m2repo/j2se</url>
74
          <uniqueVersion>false</uniqueVersion>
75
      </repository>
76
      <snapshotRepository>
77
          <id>gvsig-repository</id>
78
          <name>gvSIG maven repository</name>
79
          <url>dav:https://devel.gvsig.org/m2repo/j2se</url>
80
          <uniqueVersion>false</uniqueVersion>
81
      </snapshotRepository>
82
    </distributionManagement>
83
    
84
    <issueManagement>
85
      <system>redmine</system>
86
      <url>https://devel.gvsig.org/redmine/projects/gvsig-desktop</url>
87
    </issueManagement>
88

  
89
    <mailingLists>
90
      <mailingList>
91
        <name>User List</name>
92
        <subscribe>http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_usuarios</subscribe>
93
        <unsubscribe>http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_usuarios</unsubscribe>
94
        <post>gvsig_usuarios@listserv.gva.es</post>
95
        <archive>http://www.gvsig.org/web/community/mailing-lists/gvsig-nabble</archive>
96
        <otherArchives>
97
          <otherArchive>http://www.mail-archive.com/gvsig_usuarios@runas.cap.gva.es</otherArchive>
98
          <otherArchive>http://dir.gmane.org/index.php?prefix=gmane.comp.gis.gvsig</otherArchive>
99
        </otherArchives>
100
      </mailingList>
101
      <mailingList>
102
        <name>Developer List</name>
103
        <subscribe>http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_desarrolladores</subscribe>
104
        <unsubscribe>http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_desarrolladores</unsubscribe>
105
        <post>gvsig_desarrolladores@listserv.gva.es</post>
106
        <archive>http://www.gvsig.org/web/community/mailing-lists/gvsig-nabble</archive>
107
        <otherArchives>
108
          <otherArchive>http://www.mail-archive.com/gvsig_desarrolladores@runas.cap.gva.es</otherArchive>
109
          <otherArchive>http://dir.gmane.org/index.php?prefix=gmane.comp.gis.gvsig</otherArchive>
110
        </otherArchives>
111
      </mailingList>
112
      <mailingList>
113
        <name>International List</name>
114
        <subscribe>http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional</subscribe>
115
        <unsubscribe>http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional</unsubscribe>
116
        <post>gvsig_internacional@listserv.gva.es</post>
117
        <archive>http://www.gvsig.org/web/community/mailing-lists/gvsig-nabble</archive>
118
        <otherArchives>
119
          <otherArchive>http://www.mail-archive.com/gvsig_internacional@runas.cap.gva.es</otherArchive>
120
          <otherArchive>http://dir.gmane.org/index.php?prefix=gmane.comp.gis.gvsig</otherArchive>
121
        </otherArchives>
122
      </mailingList>
123
    </mailingLists>
124
    
125
    <build>
126
        <extensions>
127
            <extension>
128
                <groupId>org.apache.maven.wagon</groupId>
129
                <artifactId>wagon-webdav-jackrabbit</artifactId>
130
                <version>1.0-beta-7</version>
131
            </extension>
132
        </extensions>
133
    </build>
134

  
135
</project>
0 136

  
tags/org.gvsig.desktop-2.0.183/org.gvsig.desktop.library/org.gvsig.utils/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<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/xsd/maven-4.0.0.xsd">
4
  <modelVersion>4.0.0</modelVersion>
5
  <artifactId>org.gvsig.utils</artifactId>
6
  <packaging>jar</packaging>
7
  <name>${project.artifactId}</name>
8
  <parent>
9
      <groupId>org.gvsig</groupId>
10
      <artifactId>org.gvsig.desktop.library</artifactId>
11
      <version>2.0.183</version>
12
  </parent>
13

  
14
  <dependencies>
15
    <dependency>
16
        <groupId>org.gvsig</groupId>
17
        <artifactId>org.gvsig.tools.lib</artifactId>
18
        <scope>compile</scope>
19
    </dependency>
20
    <dependency>
21
        <groupId>org.gvsig</groupId>
22
        <artifactId>org.gvsig.tools.swing.api</artifactId>
23
        <scope>compile</scope>
24
    </dependency>
25
    <dependency>
26
        <groupId>org.gvsig</groupId>
27
        <artifactId>org.gvsig.tools.lib</artifactId>
28
        <type>test-jar</type>
29
        <scope>test</scope>
30
    </dependency>
31
    <dependency>
32
      <groupId>castor</groupId>
33
      <artifactId>castor</artifactId>
34
      <scope>compile</scope>
35
    </dependency>  
36
  </dependencies>
37

  
38
  <build>
39
    
40
    <!-- TODO: MAKE TESTS WORK AND REMOVE THIS OPTION -->
41
    <plugins>
42
      <plugin>
43
        <groupId>org.apache.maven.plugins</groupId>
44
        <artifactId>maven-surefire-plugin</artifactId>
45
        <configuration>
46
          <skipTests>true</skipTests>
47
        </configuration>
48
      </plugin>
49

  
50
    </plugins>
51
  </build>
52

  
53
</project>
0 54

  
tags/org.gvsig.desktop-2.0.183/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/tools/IverUtilesLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools;
25

  
26
import org.gvsig.tools.library.AbstractLibrary;
27
import org.gvsig.tools.library.LibraryException;
28
import org.gvsig.utils.swing.jcomboServer.ServerData;
29

  
30
public class IverUtilesLibrary extends AbstractLibrary {
31

  
32
    @Override
33
    public void doRegistration() {
34
        registerAsAPI(IverUtilesLibrary.class);
35
    }
36

  
37
	@Override
38
	protected void doInitialize() throws LibraryException {
39
		// Nothing to do
40
	}
41

  
42
	@Override
43
	protected void doPostInitialize() throws LibraryException {
44
		ServerData.registerPersistence();
45
	}
46
}
0 47

  
tags/org.gvsig.desktop-2.0.183/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/tools/backup/DefaultBackupGeneratorFactory.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.backup;
25

  
26
/* gvSIG. Geographic Information System of the Valencian Government
27
 *
28
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
29
 * of the Valencian Government (CIT)
30
 * 
31
 * This program is free software; you can redistribute it and/or
32
 * modify it under the terms of the GNU General Public License
33
 * as published by the Free Software Foundation; either version 2
34
 * of the License, or (at your option) any later version.
35
 * 
36
 * This program is distributed in the hope that it will be useful,
37
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39
 * GNU General Public License for more details.
40
 *  
41
 * You should have received a copy of the GNU General Public License
42
 * along with this program; if not, write to the Free Software
43
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
44
 * MA  02110-1301, USA.
45
 * 
46
 */
47

  
48
/**
49
 * <p>Factory that gets a {@link DefaultBackupGenerator DefaultBackupGenerator} as a particular version of
50
 *  backup generator.</p>
51
 *
52
 * @author Jose Ignacio Yarza (jiyarza@opensistemas.com)
53
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
54
 */
55
public class DefaultBackupGeneratorFactory extends BackupGeneratorFactory {
56
	/*
57
	 * (non-Javadoc)
58
	 * @see com.iver.utiles.backup.BackupGeneratorFactory#getBackupGenerator()
59
	 */
60
	public BackupGenerator getBackupGenerator() {		
61
		return new DefaultBackupGenerator();
62
	}
63
}
0 64

  
tags/org.gvsig.desktop-2.0.183/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/tools/backup/BackupGenerator.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.backup;
25

  
26
/* gvSIG. Geographic Information System of the Valencian Government
27
 *
28
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
29
 * of the Valencian Government (CIT)
30
 * 
31
 * This program is free software; you can redistribute it and/or
32
 * modify it under the terms of the GNU General Public License
33
 * as published by the Free Software Foundation; either version 2
34
 * of the License, or (at your option) any later version.
35
 * 
36
 * This program is distributed in the hope that it will be useful,
37
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39
 * GNU General Public License for more details.
40
 *  
41
 * You should have received a copy of the GNU General Public License
42
 * along with this program; if not, write to the Free Software
43
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
44
 * MA  02110-1301, USA.
45
 * 
46
 */
47

  
48
import java.io.File;
49

  
50
import org.gvsig.tools.backup.exceptions.BackupException;
51

  
52

  
53
/**
54
 * <p>A tagging interface that all file backups must implement.</p>
55
 *
56
 * @author Jose Ignacio Yarza (jiyarza@opensistemas.com)
57
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
58
 */
59
public interface BackupGenerator {
60
	/**
61
	 * <p>Performs a backup of <code>source</code>.</p>
62
	 * 
63
	 * @param source the source file
64
	 */
65
	public void backup(File source) throws BackupException;
66
}
0 67

  
tags/org.gvsig.desktop-2.0.183/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/tools/backup/DefaultBackupGenerator.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.backup;
25

  
26
/* gvSIG. Geographic Information System of the Valencian Government
27
 *
28
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
29
 * of the Valencian Government (CIT)
30
 * 
31
 * This program is free software; you can redistribute it and/or
32
 * modify it under the terms of the GNU General Public License
33
 * as published by the Free Software Foundation; either version 2
34
 * of the License, or (at your option) any later version.
35
 * 
36
 * This program is distributed in the hope that it will be useful,
37
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39
 * GNU General Public License for more details.
40
 *  
41
 * You should have received a copy of the GNU General Public License
42
 * along with this program; if not, write to the Free Software
43
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
44
 * MA  02110-1301, USA.
45
 * 
46
 */ 
47

  
48
import java.io.File;
49
import java.io.FileInputStream;
50
import java.io.FileOutputStream;
51
import java.nio.channels.FileChannel;
52

  
53
import org.gvsig.tools.backup.exceptions.BackupException;
54

  
55

  
56
/**
57
 * <p>Performs a backup of a file, into another file at the same path (directory), with the file extension 
58
 *  changed to <i>.bak</i>.</p>
59
 *
60
 * @author Jose Ignacio Yarza (jiyarza@opensistemas.com)
61
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
62
 */
63
public class DefaultBackupGenerator implements BackupGenerator {
64
	/*
65
	 * (non-Javadoc)
66
	 * @see com.iver.utiles.backup.BackupGenerator#backup(java.io.File)
67
	 */
68
	public void backup(File source) throws BackupException {
69
		try {
70
			int index = source.getAbsolutePath().lastIndexOf(".");
71

  
72
			if (index == -1)
73
				return;
74

  
75
			File dest = new File(source.getAbsolutePath().substring(0, index) + ".bak");
76

  
77
	        // Create channel on the source
78
	        FileChannel srcChannel = new FileInputStream(source).getChannel();
79

  
80
	        // Create channel on the destination
81
	        FileChannel dstChannel = new FileOutputStream(dest).getChannel();
82

  
83
	        // Copy file contents from source to destination
84
	        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
85

  
86
	        // Close the channels
87
	        srcChannel.close();
88
	        dstChannel.close();
89
	    } catch (Exception ex) {
90
	    	throw new BackupException(ex.getMessage(), ex, source);
91
	    }
92
	}
93
}
0 94

  
tags/org.gvsig.desktop-2.0.183/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/tools/backup/exceptions/BackupException.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.backup.exceptions;
25

  
26
/* gvSIG. Geographic Information System of the Valencian Government
27
 *
28
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
29
 * of the Valencian Government (CIT)
30
 * 
31
 * This program is free software; you can redistribute it and/or
32
 * modify it under the terms of the GNU General Public License
33
 * as published by the Free Software Foundation; either version 2
34
 * of the License, or (at your option) any later version.
35
 * 
36
 * This program is distributed in the hope that it will be useful,
37
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39
 * GNU General Public License for more details.
40
 *  
41
 * You should have received a copy of the GNU General Public License
42
 * along with this program; if not, write to the Free Software
43
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
44
 * MA  02110-1301, USA.
45
 * 
46
 */
47

  
48
import java.io.File;
49

  
50
/**
51
 * <p>Exception to report that a backup process has failed.</p>
52
 *
53
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
54
 */
55
public class BackupException extends Exception {
56
	private static final long serialVersionUID = -2846421984617208883L;
57

  
58
	/**
59
	 * <p>The source file to be backup.</p>
60
	 */
61
	protected File source;
62

  
63
	/**
64
	 * <p>Constructs a new backup exception with the specified detail message and cause.</p>
65
	 * 
66
	 * @param message the detail message (which is saved for later retrieval by the <code>getMessage()</code> method).
67
	 * @param cause the cause (which is saved for later retrieval by the <code>getCause()</code> method). (A <code>null</code>
68
	 *  value is permitted, and indicates that the cause is nonexistent or unknown.)
69
	 * @param source the file from that was going to be done a backup
70
	 * 
71
	 * @see Exception#Exception(String, Throwable)
72
	 */
73
	public BackupException(String message, Throwable cause, File source) {
74
		super(message, cause);
75
		this.source = source;
76
	}
77

  
78
	/**
79
	 * <p>Gets the source file to be backup.</p> 
80
	 * 
81
	 * @return the source file
82
	 */
83
	public File getSource() {
84
		return source;
85
	}
86
}
0 87

  
tags/org.gvsig.desktop-2.0.183/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/tools/backup/BackupGeneratorFactory.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.backup;
25

  
26
/* gvSIG. Geographic Information System of the Valencian Government
27
 *
28
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
29
 * of the Valencian Government (CIT)
30
 * 
31
 * This program is free software; you can redistribute it and/or
32
 * modify it under the terms of the GNU General Public License
33
 * as published by the Free Software Foundation; either version 2
34
 * of the License, or (at your option) any later version.
35
 * 
36
 * This program is distributed in the hope that it will be useful,
37
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39
 * GNU General Public License for more details.
40
 *  
41
 * You should have received a copy of the GNU General Public License
42
 * along with this program; if not, write to the Free Software
43
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
44
 * MA  02110-1301, USA.
45
 * 
46
 */
47
 
48
/**
49
 * <p>Generic factory that creates a {@link BackupGenerator BackupGenerator} that performs a particular
50
 *  kind of backup.</p>
51
 *
52
 * @author Jose Ignacio Yarza (jiyarza@opensistemas.com)
53
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
54
 */
55
public abstract class BackupGeneratorFactory {
56
	/**
57
	 * <p>Gets an instance of a backup generator that performs a particular kind of backup.</p>
58
	 * 
59
	 * @return an instance of a backup generator that performs a particular kind of backup
60
	 */
61
	public abstract BackupGenerator getBackupGenerator();
62
}
0 63

  
tags/org.gvsig.desktop-2.0.183/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/DoubleUtilities.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.utils;
25

  
26
import java.text.DecimalFormat;
27
import java.text.DecimalFormatSymbols;
28

  
29
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
30
 *
31
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
32
 *
33
 * This program is free software; you can redistribute it and/or
34
 * modify it under the terms of the GNU General Public License
35
 * as published by the Free Software Foundation; either version 2
36
 * of the License, or (at your option) any later version.
37
 *
38
 * This program is distributed in the hope that it will be useful,
39
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
41
 * GNU General Public License for more details.
42
 *
43
 * You should have received a copy of the GNU General Public License
44
 * along with this program; if not, write to the Free Software
45
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
46
 *
47
 * For more information, contact:
48
 *
49
 *  Generalitat Valenciana
50
 *   Conselleria d'Infraestructures i Transport
51
 *   Av. Blasco Ib??ez, 50
52
 *   46010 VALENCIA
53
 *   SPAIN
54
 *
55
 *      +34 963862235
56
 *   gvsig@gva.es
57
 *      www.gvsig.gva.es
58
 *
59
 *    or
60
 *
61
 *   IVER T.I. S.A
62
 *   Salamanca 50
63
 *   46005 Valencia
64
 *   Spain
65
 *
66
 *   +34 963163400
67
 *   dac@iver.es
68
 */
69
/* CVS MESSAGES:
70
 *
71
 * $Id: DoubleUtilities.java 29631 2009-06-29 16:56:19Z jpiera $
72
 * $Log$
73
 * Revision 1.3  2006-10-30 11:59:47  nacho
74
 * formateado de double
75
 *
76
 * Revision 1.2  2006/09/13 08:10:07  jorpiell
77
 * Se limita el n?mero de decimales por arriba y por abajo
78
 *
79
 * Revision 1.1  2006/05/16 13:02:41  jorpiell
80
 * Se ha a?adido la clase DoubleUtiles, donde ha un metodo para limitar el tama?o de los decimales de un double y para quitar los "puntos" de la parte entera
81
 *
82
 *
83
 */
84
/**
85
 * This class has some methods to manage "Doubles"
86
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
87
 */
88
public class DoubleUtilities {
89
	/**
90
	 * Formats a double with an specified number of decimals. It 
91
	 * removes the separator character of the integer part. 
92
	 * @param value
93
	 * Separator char of the integer part
94
	 * @param decimalSeparator
95
	 * Separator char of the decimal part
96
	 * @param decimalsNumber
97
	 * Number of decimals
98
	 * @return
99
	 * The formatted double
100
	 */
101
	public static double format(double value,
102
			char decimalSeparator,
103
			int decimalsNumber){
104
			
105
		DecimalFormat dFormat = new DecimalFormat("#");
106
		DecimalFormatSymbols dFormatSymbols = new DecimalFormatSymbols();
107
		
108
		dFormatSymbols.setDecimalSeparator(decimalSeparator);
109
		dFormat.setMaximumFractionDigits(decimalsNumber);
110
		dFormat.setMaximumFractionDigits(decimalsNumber);
111
		dFormat.setDecimalFormatSymbols(dFormatSymbols);
112
		double d = Double.parseDouble(dFormat.format(value));
113
		return Double.parseDouble(dFormat.format(value));		
114
	}
115

  
116
	/**
117
	 * Formats a double with an specified number of decimals. 
118
	 * @param num
119
	 * Value to tail
120
	 * @param n
121
	 * Number of decimals
122
	 * @return
123
	 * The formatted double
124
	 */
125
    public static double format(double num, int n){
126
    	long m = (long)Math.pow(10, n);
127
        num *= m;
128
        long aux = ((long)num);
129
        num = (double)((double)aux / (double)m);
130
        return num;
131
    }
132

  
133
}
0 134

  
tags/org.gvsig.desktop-2.0.183/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/swing/fileFilter/ExampleFileFilter.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.utils.swing.fileFilter;
25

  
26
/*
27
 * Copyright (c) 2003 Sun Microsystems, Inc. All  Rights Reserved.
28
 * 
29
 * Redistribution and use in source and binary forms, with or without
30
 * modification, are permitted provided that the following conditions
31
 * are met:
32
 * 
33
 * -Redistributions of source code must retain the above copyright
34
 *  notice, this list of conditions and the following disclaimer.
35
 * 
36
 * -Redistribution in binary form must reproduct the above copyright
37
 *  notice, this list of conditions and the following disclaimer in
38
 *  the documentation and/or other materials provided with the distribution.
39
 * 
40
 * Neither the name of Sun Microsystems, Inc. or the names of contributors
41
 * may be used to endorse or promote products derived from this software
42
 * without specific prior written permission.
43
 * 
44
 * This software is provided "AS IS," without a warranty of any kind. ALL
45
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
46
 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
47
 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT
48
 * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
49
 * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
50
 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
51
 * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
52
 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
53
 * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
54
 * IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
55
 * 
56
 * You acknowledge that Software is not designed, licensed or intended for
57
 * use in the design, construction, operation or maintenance of any nuclear
58
 * facility.
59
 */
60

  
61
/*
62
 * @(#)ExampleFileFilter.java	1.14 03/01/23
63
 */
64
import java.io.File;
65
import java.util.Enumeration;
66
import java.util.Hashtable;
67

  
68
import javax.swing.filechooser.FileFilter;
69

  
70
/**
71
 * A convenience implementation of FileFilter that filters out
72
 * all files except for those type extensions that it knows about.
73
 *
74
 * Extensions are of the type ".foo", which is typically found on
75
 * Windows and Unix boxes, but not on Macinthosh. Case is ignored.
76
 *
77
 * Example - create a new filter that filerts out all files
78
 * but gif and jpg image files:
79
 *
80
 *     JFileChooser chooser = new JFileChooser();
81
 *     ExampleFileFilter filter = new ExampleFileFilter(
82
 *                   new String{"gif", "jpg"}, "JPEG & GIF Images")
83
 *     chooser.addChoosableFileFilter(filter);
84
 *     chooser.showOpenDialog(this);
85
 *
86
 * @version 1.14 01/23/03
87
 * @author Jeff Dinkins
88
 */
89
public class ExampleFileFilter extends FileFilter {
90

  
91
    private static String TYPE_UNKNOWN = "Type Unknown";
92
    private static String HIDDEN_FILE = "Hidden File";
93

  
94
    private Hashtable filters = null;
95
    private String description = null;
96
    private String fullDescription = null;
97
    private boolean useExtensionsInDescription = true;
98

  
99
    /**
100
     * Creates a file filter. If no filters are added, then all
101
     * files are accepted.
102
     *
103
     * @see #addExtension
104
     */
105
    public ExampleFileFilter() {
106
	this.filters = new Hashtable();
107
    }
108

  
109
    /**
110
     * Creates a file filter that accepts files with the given extension.
111
     * Example: new ExampleFileFilter("jpg");
112
     *
113
     * @see #addExtension
114
     */
115
    public ExampleFileFilter(String extension) {
116
	this(extension,null);
117
    }
118

  
119
    /**
120
     * Creates a file filter that accepts the given file type.
121
     * Example: new ExampleFileFilter("jpg", "JPEG Image Images");
122
     *
123
     * Note that the "." before the extension is not needed. If
124
     * provided, it will be ignored.
125
     *
126
     * @see #addExtension
127
     */
128
    public ExampleFileFilter(String extension, String description) {
129
	this();
130
	if(extension!=null) addExtension(extension);
131
 	if(description!=null) setDescription(description);
132
    }
133

  
134
    /**
135
     * Creates a file filter from the given string array.
136
     * Example: new ExampleFileFilter(String {"gif", "jpg"});
137
     *
138
     * Note that the "." before the extension is not needed adn
139
     * will be ignored.
140
     *
141
     * @see #addExtension
142
     */
143
    public ExampleFileFilter(String[] filters) {
144
	this(filters, null);
145
    }
146

  
147
    /**
148
     * Creates a file filter from the given string array and description.
149
     * Example: new ExampleFileFilter(String {"gif", "jpg"}, "Gif and JPG Images");
150
     *
151
     * Note that the "." before the extension is not needed and will be ignored.
152
     *
153
     * @see #addExtension
154
     */
155
    public ExampleFileFilter(String[] filters, String description) {
156
	this();
157
	for (int i = 0; i < filters.length; i++) {
158
	    // add filters one by one
159
	    addExtension(filters[i]);
160
	}
161
 	if(description!=null) setDescription(description);
162
    }
163

  
164
    /**
165
     * Return true if this file should be shown in the directory pane,
166
     * false if it shouldn't.
167
     *
168
     * Files that begin with "." are ignored.
169
     *
170
     * @see #getExtension
171
     * @see FileFilter#accepts
172
     */
173
    public boolean accept(File f) {
174
	if(f != null) {
175
	    if(f.isDirectory()) {
176
		return true;
177
	    }
178
	    String extension = getExtension(f);
179
	    if(extension != null && filters.get(getExtension(f)) != null) {
180
		return true;
181
	    };
182
	}
183
	return false;
184
    }
185

  
186
    /**
187
     * Return the extension portion of the file's name .
188
     *
189
     * @see #getExtension
190
     * @see FileFilter#accept
191
     */
192
     public String getExtension(File f) {
193
	if(f != null) {
194
	    String filename = f.getName();
195
	    int i = filename.lastIndexOf('.');
196
	    if(i>0 && i<filename.length()-1) {
197
		return filename.substring(i+1).toLowerCase();
198
	    };
199
	}
200
	return null;
201
    }
202

  
203
    /**
204
     * Adds a filetype "dot" extension to filter against.
205
     *
206
     * For example: the following code will create a filter that filters
207
     * out all files except those that end in ".jpg" and ".tif":
208
     *
209
     *   ExampleFileFilter filter = new ExampleFileFilter();
210
     *   filter.addExtension("jpg");
211
     *   filter.addExtension("tif");
212
     *
213
     * Note that the "." before the extension is not needed and will be ignored.
214
     */
215
    public void addExtension(String extension) {
216
	if(filters == null) {
217
	    filters = new Hashtable(5);
218
	}
219
	filters.put(extension.toLowerCase(), this);
220
	fullDescription = null;
221
    }
222

  
223

  
224
    /**
225
     * Returns the human readable description of this filter. For
226
     * example: "JPEG and GIF Image Files (*.jpg, *.gif)"
227
     *
228
     * @see setDescription
229
     * @see setExtensionListInDescription
230
     * @see isExtensionListInDescription
231
     * @see FileFilter#getDescription
232
     */
233
    public String getDescription() {
234
	if(fullDescription == null) {
235
	    if(description == null || isExtensionListInDescription()) {
236
 		fullDescription = description==null ? "(" : description + " (";
237
		// build the description from the extension list
238
		Enumeration extensions = filters.keys();
239
		if(extensions != null) {
240
		    fullDescription += "." + (String) extensions.nextElement();
241
		    while (extensions.hasMoreElements()) {
242
			fullDescription += ", ." + (String) extensions.nextElement();
243
		    }
244
		}
245
		fullDescription += ")";
246
	    } else {
247
		fullDescription = description;
248
	    }
249
	}
250
	return fullDescription;
251
    }
252

  
253
    /**
254
     * Sets the human readable description of this filter. For
255
     * example: filter.setDescription("Gif and JPG Images");
256
     *
257
     * @see setDescription
258
     * @see setExtensionListInDescription
259
     * @see isExtensionListInDescription
260
     */
261
    public void setDescription(String description) {
262
	this.description = description;
263
	fullDescription = null;
264
    }
265

  
266
    /**
267
     * Determines whether the extension list (.jpg, .gif, etc) should
268
     * show up in the human readable description.
269
     *
270
     * Only relevent if a description was provided in the constructor
271
     * or using setDescription();
272
     *
273
     * @see getDescription
274
     * @see setDescription
275
     * @see isExtensionListInDescription
276
     */
277
    public void setExtensionListInDescription(boolean b) {
278
	useExtensionsInDescription = b;
279
	fullDescription = null;
280
    }
281

  
282
    /**
283
     * Returns whether the extension list (.jpg, .gif, etc) should
284
     * show up in the human readable description.
285
     *
286
     * Only relevent if a description was provided in the constructor
287
     * or using setDescription();
288
     *
289
     * @see getDescription
290
     * @see setDescription
291
     * @see setExtensionListInDescription
292
     */
293
    public boolean isExtensionListInDescription() {
294
	return useExtensionsInDescription;
295
    }
296
}
297

  
298

  
0 299

  
tags/org.gvsig.desktop-2.0.183/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/swing/threads/DefaultCancellableMonitorable.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff