Revision 44416

View differences:

tags/org.gvsig.desktop-2.0.247/org.gvsig.desktop.library/org.gvsig.utils/src/main/config/xml-entity.xsd
1
<?xml version="1.0" encoding="UTF-8" ?>
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

  
28
<xs:schema targetNamespace="http://www.gvsig.gva.es"
29
        xmlns:xs="http://www.w3.org/2001/XMLSchema">
30
  <xs:element name="xmlCastor">
31
    <xs:complexType>
32
    <xs:sequence>
33
        <xs:element ref="xml-tag" minOccurs="0" maxOccurs="unbounded" />
34
      </xs:sequence>
35
    </xs:complexType>
36
  </xs:element>
37
  
38
  <xs:element name="property">
39
    <xs:complexType>
40
      <xs:attribute name="key" type="xs:string" use="required" />
41
      <xs:attribute name="value" type="xs:string" use="optional" />
42
    </xs:complexType>
43
  </xs:element>
44

  
45
  <xs:element name="xml-tag">
46
    <xs:complexType>
47
      <xs:sequence>
48
        <xs:element ref="property" minOccurs="0" maxOccurs="unbounded" />
49
        <xs:element ref="xml-tag" minOccurs="0" maxOccurs="unbounded" />
50
      </xs:sequence>
51
      <xs:attribute name="name" type="xs:string" use="optional" />
52
    </xs:complexType>
53
  </xs:element>
54

  
55
</xs:schema>
0 56

  
tags/org.gvsig.desktop-2.0.247/org.gvsig.desktop.library/org.gvsig.utils/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.tools.IverUtilesLibrary
tags/org.gvsig.desktop-2.0.247/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.247/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.247/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.247/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.247/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.247/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.247/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/ExceptionDescription.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
/* CVS MESSAGES:
25
 *
26
 * $Id: ExceptionDescription.java 29631 2009-06-29 16:56:19Z jpiera $
27
 * $Log$
28
 * Revision 1.2  2006-09-22 08:08:04  ldiaz
29
 * layerName y driverName gestionados/almacenados desde esta clase
30
 *
31
 * Revision 1.1  2006/09/21 17:04:52  azabala
32
 * First version in cvs
33
 *
34
 *
35
 */
36
package org.gvsig.utils;
37

  
38
/**
39
 * <p>Most exceptions produced in a layer, has common information (layer name, driver name, error description, error code).</p>
40
 * 
41
 * <p>An <code>ExceptionDescription</code> can provide this extra information describing the cause of the
42
 *  error, and more useful information to give to the user that works with a layer.<p>
43
 * 
44
 * @author azabala
45
 */
46
public abstract class ExceptionDescription {
47
	/**
48
	 * <p>Code which identifies the kind of error which is the cause of this exception.</p>
49
	 */
50
	private int errorCode;
51

  
52
	/**
53
	 * <p>A description about the error which produced this exception.</p>
54
	 */
55
	private String errorDescription;
56

  
57
	/**
58
	 * <p>If this exception was produced using a driver, this attribute describes that driver.</p>
59
	 */
60
	private String driverName;
61

  
62
	/**
63
	 * <p>If this exception was produced using a layer, this attribute describes that layer.</p> 
64
	 */
65
	private String layerName;
66
	
67
	/**
68
	 * <p>Gets the name of the driver (if a driver was using) which this exception was produced.</p>
69
	 * 
70
	 * @return the name of the driver (if a driver was using) which this exception was produced
71
	 */	
72
	public String getDriverName() {
73
		return driverName;
74
	}
75

  
76
	/**
77
	 * <p>Sets the name of the driver (if a driver was using) which this exception was produced.</p>
78
	 * 
79
	 * @param driverName the name of the driver (if a driver was using) which this exception was produced
80
	 */
81
	public void setDriverName(String driverName){
82
		this.driverName = driverName;
83
	}	
84

  
85
	/**
86
	 * <p>Gets the name of the layer (if a layer was using) with that this exception was produced.</p>
87
	 * 
88
	 * @return the name of the layer (if a layer was using) with that this exception was produced
89
	 */
90
	public String getLayerName() {
91
		return driverName;
92
	}
93

  
94
	/**
95
	 * <p>Sets the name of the layer (if a layer was using) with that this exception was produced.</p>
96
	 * 
97
	 * @param layerName the name of the layer (if a layer was using) with that this exception was produced
98
	 */
99
	public void setLayerName(String layerName){
100
		this.layerName = layerName;
101
	}	
102

  
103
	/**
104
	 * <p>Sets the name of the layer (if a layer was using) with that this exception was produced.</p>
105
	 * 
106
	 * @param layerName the name of the layer (if a layer was using) with that this exception was produced
107
	 */
108
	public ExceptionDescription() {
109
	}
110

  
111
	/**
112
	 * <p>Creates a new <code>ExceptionDescription</code> with the useful values initialized.</p>
113
	 * 
114
	 * @param errorCode code which identifies the kind of error which is the cause of this exception
115
	 * @param errorDescription description about the error which produced this exception
116
	 */
117
	public ExceptionDescription(int errorCode, String errorDescription) {
118
		this.errorCode = errorCode;
119
		this.errorDescription = errorDescription;
120
	}
121

  
122
	/**
123
	 * <p>Sets the code which identifies the kind of error which is the cause of this exception.</p>
124
	 * 
125
	 * @param errorCode code which identifies the kind of error which is the cause of this exception
126
	 */
127
	public void setCode(int errorCode) {
128
		this.errorCode = errorCode;
129
	}
130

  
131
	/**
132
	 * <p>Sets the description about the error which produced this exception.</p>
133
	 * 
134
	 * @param description description about the error which produced this exception
135
	 */
136
	public void setDescription(String description) {
137
		this.errorDescription = description;
138
	}
139

  
140
	/**
141
	 * <p>Gets the code which identifies the kind of error which is the cause of this exception.</p>
142
	 * 
143
	 * @return code which identifies the kind of error which is the cause of this exception
144
	 */
145
	public int getErrorCode() {
146
		return errorCode;
147
	}
148

  
149
	/**
150
	 * <p>Gets the description about the error which produced this exception.</p>
151
	 * 
152
	 * @return description about the error which produced this exception
153
	 */
154
	public String getErrorDescription() {
155
		return errorDescription;
156
	}
157

  
158
	/**
159
	 * <p>Returns a message that describes the error which produced this exception, formatted in HTML code.</p>
160
	 * 
161
	 * @return message that describes the error which produced this exception, formatted in HTML code
162
	 */
163
	public abstract String getHtmlErrorMessage();
164
}
0 165

  
tags/org.gvsig.desktop-2.0.247/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/CompareLists.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.util.Comparator;
27
import java.util.List;
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

  
70
/**
71
 * This class has methods to compare lists of objects
72
 * 
73
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
74
 */
75
public class CompareLists {
76
	/**
77
	 * Compares two lists of elements, using the value returned of the <i><b>toString()</b></i> method
78
	 *   of each element. <br>
79
	 * Each element must also implement the {@link Comparable} interface. <br>
80
	 * This method considers case sensitive .
81
	 * 
82
	 * @param l1 First list of items. @see java.util.List
83
	 * @param l2 Second list of items. @see java.util.List
84
	 * @return True if the two lists have the same number of elements, and elements are in the same
85
	 *   position of the two lists and have the same <i>String</i> value .
86
	 */
87
	public synchronized static boolean compare(List l1, List l2) {
88
		// If both are null -> true; if one yes but the other no -> return false
89
		if ((l1 == null) || (l2 == null)) {
90
			if (l1 == l2)
91
				return true;
92
			else
93
				return false;
94
		}
95
		
96
		// If the length isn't equal
97
		if (l1.size() != l2.size())
98
			return false;
99

  
100
		// Compares each item: must have the same value in the same position in the list
101
		for (int i = 0; i < l1.size(); i++) {
102
			if ( l1.get(i).toString().compareTo(l2.get(i).toString()) != 0 )
103
				return false;
104
		}
105
		
106
		return true;
107
	}
108
	
109
	/**
110
	 * Compares two lists of elements, using the value returned of the <i><b>toString()</b></i> method
111
	 *   of each element. <br>
112
	 * Each element must also implement the {@link Comparable} interface. <br>
113
	 * This method ignores case sensitive during the comparation.
114
	 * 
115
	 * @param l1 First list of items. @see java.util.List
116
	 * @param l2 Second list of items. @see java.util.List
117
	 * @return True if the two lists have the same number of elements, and elements are in the same
118
	 *   position of the two lists and have the same <i>String</i> value .
119
	 */
120
	public synchronized static boolean compareIgnoringCaseSensitive(List l1, List l2) {
121
		// If both are null -> true; if one yes but the other no -> return false
122
		if ((l1 == null) || (l2 == null)) {
123
			if (l1 == l2)
124
				return true;
125
			else
126
				return false;
127
		}
128

  
129
		// If the length isn't equal
130
		if (l1.size() != l2.size())
131
			return false;
132

  
133
		// Compares each item: must have the same value in the same position in the list
134
		for (int i = 0; i < l1.size(); i++) {
135
			if ( l1.get(i).toString().compareToIgnoreCase(l2.get(i).toString()) != 0 )
136
				return false;
137
		}
138
		
139
		return true;
140
	}
141
	
142
	/**
143
	 * Compares two lists of elements, using the value returned of the <i><b>toString()</b></i> method
144
	 *   of each element. <br>
145
	 * Each element must also implement the {@link Comparable} interface. <br>
146
	 * 
147
	 * @param l1 First list of items. @see java.util.List
148
	 * @param l2 Second list of items. @see java.util.List
149
	 * @param comp A class which implements the <i><b>compare</b></i> method of the <i>Comparator</i> interface . 
150
	 * @return True if the two lists have the same number of elements, and elements are in the same
151
	 *   position of the two lists and have the same <i>String</i> value .
152
	 */
153
	public synchronized static boolean compare(List l1, List l2, Comparator comp) {
154
		// If both are null -> true; if one yes but the other no -> return false
155
		if ((l1 == null) || (l2 == null)) {
156
			if (l1 == l2)
157
				return true;
158
			else
159
				return false;
160
		}
161

  
162
		// If the length isn't equal
163
		if (l1.size() != l2.size())
164
			return false;
165

  
166
		// Compares each item: must have the same value in the same position in the list
167
		for (int i = 0; i < l1.size(); i++) {
168
			if ( comp.compare(l1.get(i).toString(), (l2.get(i).toString())) != 0 )
169
				return false;
170
		}
171

  
172
		return true;
173
	}
174
	
175
	/**
176
	 * Compares two lists of elements, using the value returned of the <i><b>toString()</b></i> method
177
	 *   of each element. <br>
178
	 * Each element must also implement the {@link Comparable} interface. <br>
179
	 * This method ignores case sensitive during the comparation.
180
	 * 
181
	 * @param l1 First list of items. @see java.util.List
182
	 * @param l2 Second list of items. @see java.util.List
183
	 * @param comp A class which implements the <i><b>compare</b></i> method of the <i>Comparator</i> interface . 
184
	 * @return True if the two lists have the same number of elements, and elements are in the same
185
	 *   position of the two lists and have the same <i>String</i> value .
186
	 */
187
	public synchronized static boolean compareIgnoringCaseSensitive(List l1, List l2, Comparator comp) {
188
		// If both are null -> true; if one yes but the other no -> return false
189
		if ((l1 == null) || (l2 == null)) {
190
			if (l1 == l2)
191
				return true;
192
			else
193
				return false;
194
		}
195

  
196
		// If the length isn't equal
197
		if (l1.size() != l2.size())
198
			return false;
199

  
200
		// Compares each item: must have the same value in the same position in the list
201
		for (int i = 0; i < l1.size(); i++) {
202
			if ( comp.compare(l1.get(i).toString().toLowerCase(), (l2.get(i).toString().toLowerCase())) != 0 )
203
				return false;
204
		}
205

  
206
		return true;
207
	}
208
}
0 209

  
tags/org.gvsig.desktop-2.0.247/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.247/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/swing/jtable/FieldSelectionEvent.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.jtable;
25

  
26
import java.util.BitSet;
27

  
28
/**
29
 * @author Fernando Gonz?lez Cort?s
30
 */
31
public class FieldSelectionEvent {
32
    private BitSet selectedIndices;
33
    private int selectedField;
34
    public int getSelectedField() {
35
        return selectedField;
36
    }
37
    public void setSelectedField(int selectedField) {
38
        this.selectedField = selectedField;
39
    }
40
    public BitSet getSelectedIndices() {
41
        return selectedIndices;
42
    }
43
    public void setSelectedIndices(BitSet selectedIndices) {
44
        this.selectedIndices = selectedIndices;
45
    }
46
}
0 47

  
tags/org.gvsig.desktop-2.0.247/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/swing/jtable/SelectionHeaderSupport.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.jtable;
25

  
26
import java.awt.Component;
27
import java.awt.Insets;
28
import java.awt.event.MouseAdapter;
29
import java.awt.event.MouseEvent;
30
import java.util.BitSet;
31

  
32
import javax.swing.JTable;
33
import javax.swing.JToggleButton;
34
import javax.swing.table.JTableHeader;
35
import javax.swing.table.TableCellRenderer;
36

  
37
/**
38
 * @author Fernando Gonz?lez Cort?s
39
 */
40
public class SelectionHeaderSupport {
41
    private SelectionCellRenderer cellRenderer = new SelectionCellRenderer();
42
    private FieldSelectionListenerSupport listenerSupport = new FieldSelectionListenerSupport();
43

  
44
    public void setTableHeader(final JTableHeader header){
45
		header.setDefaultRenderer(cellRenderer);
46
		header.addMouseListener(new MouseAdapter() {
47
            public void mouseClicked(MouseEvent e) {
48
                for (int i = 0; i < header.getColumnModel().getColumnCount(); i++) {
49
                    if (header.getHeaderRect(i).contains(e.getPoint())){
50
                        if ((e.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) == MouseEvent.CTRL_DOWN_MASK){
51
                            cellRenderer.toggleSelection(i);
52
                        }else{
53
                            cellRenderer.setSelection(i);
54
                        }
55
                        
56
                        FieldSelectionEvent evt = new FieldSelectionEvent();
57
                        evt.setSelectedField(i);
58
                        evt.setSelectedIndices(cellRenderer.selectedColumnIndices);
59
                        callFieldSelected(evt);
60
                        break;
61
                    }
62
                }
63
            }
64
        });
65
    }
66
    
67
    public BitSet getSelectedColumns(){
68
        return cellRenderer.selectedColumnIndices;
69
    }
70

  
71
    /**
72
     * Deja todas las columnas sin seleccionar.
73
     */
74
    public void clearSelectedColumns()
75
    {
76
        cellRenderer.selectedColumnIndices.clear();
77
    }
78
    public class SelectionCellRenderer extends JToggleButton implements TableCellRenderer {
79
        
80
        private BitSet selectedColumnIndices = new BitSet();
81
        
82
        public SelectionCellRenderer(){
83
            this.setMargin(new Insets(0, 0, 0, 0));
84
        }
85
        
86
        /**
87
         * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
88
         */
89
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
90
            this.setText(table.getModel().getColumnName(column));
91
            this.setSelected(false);
92
            for (int i = 0; i < selectedColumnIndices.cardinality(); i++) {
93
                if (selectedColumnIndices.get(column)){
94
                    this.setSelected(true);
95
                }
96
            }
97
            return this;
98
        }
99
    
100
        /**
101
         * @param i
102
         */
103
        public void setSelection(int i) {
104
            selectedColumnIndices.clear();
105
            selectedColumnIndices.set(i);
106
        }
107
        
108
        public void toggleSelection(int i) {
109
            selectedColumnIndices.flip(i);
110
        }
111
        
112
    }
113
    public void addFieldSelectionListener(FieldSelectionListener listener) {
114
        listenerSupport.addFieldSelectionListener(listener);
115
    }
116
    private void callFieldSelected(FieldSelectionEvent arg0) {
117
        listenerSupport.callFieldSelected(arg0);
118
    }
119
    public void removeFieldSelectionListener(FieldSelectionListener listener) {
120
        listenerSupport.removeFieldSelectionListener(listener);
121
    }
122
}
0 123

  
tags/org.gvsig.desktop-2.0.247/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/swing/jtable/FieldSelectionListenerSupport.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.jtable;
25

  
26
import java.util.ArrayList;
27
import java.util.Iterator;
28

  
29

  
30
/**
31
 * DOCUMENT ME!
32
 *
33
 * @author Fernando Gonz?lez Cort?s
34
 */
35
public class FieldSelectionListenerSupport {
36
    private ArrayList listeners = new ArrayList();
37

  
38
    /**
39
     * DOCUMENT ME!
40
     *
41
     * @param listener DOCUMENT ME!
42
     */
43
    public void addFieldSelectionListener(FieldSelectionListener listener) {
44
        listeners.add(listener);
45
    }
46

  
47
    /**
48
     * DOCUMENT ME!
49
     *
50
     * @param listener DOCUMENT ME!
51
     */
52
    public void removeFieldSelectionListener(FieldSelectionListener listener) {
53
        listeners.remove(listener);
54
    }
55

  
56
    /**
57
     * DOCUMENT ME!
58
     *
59
     * @param arg0 DOCUMENT ME!
60
     */
61
    public void callFieldSelected(FieldSelectionEvent arg0) {
62
        Iterator i = listeners.iterator();
63

  
64
        while (i.hasNext()) {
65
            ((FieldSelectionListener) i.next()).fieldSelected(arg0);
66
        }
67
    }
68
}
0 69

  
tags/org.gvsig.desktop-2.0.247/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/swing/jtable/FieldSelectionListener.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.jtable;
25

  
26
/**
27
 * @author Fernando Gonz?lez Cort?s
28
 */
29
public interface FieldSelectionListener {
30
    public void fieldSelected(FieldSelectionEvent e);
31
}
0 32

  
tags/org.gvsig.desktop-2.0.247/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/swing/jtable/TextFieldCellEditor.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.jtable;
25

  
26
import java.awt.Component;
27
import java.awt.event.KeyAdapter;
28
import java.awt.event.KeyEvent;
29
import java.util.ArrayList;
30
import java.util.EventObject;
31

  
32
import javax.swing.JTable;
33
import javax.swing.JTextField;
34
import javax.swing.event.CellEditorListener;
35
import javax.swing.event.ChangeEvent;
36
import javax.swing.table.TableCellEditor;
37

  
38
/**
39
 * @author Fernando Gonz?lez Cort?s
40
 */
41
public class TextFieldCellEditor extends JTextField implements TableCellEditor{
42

  
43
    private ArrayList listeners = new ArrayList();
44
    private String initialValue;
45
    
46
    public TextFieldCellEditor() {
47
        addKeyListener(new KeyAdapter() {
48
            public void keyReleased(KeyEvent e) {
49
                if (e.getKeyCode() == KeyEvent.VK_ENTER){
50
                    stopCellEditing();
51
                }else if (e.getKeyCode() == KeyEvent.VK_ESCAPE){
52
                    cancelCellEditing();
53
                }
54
            }
55
        });
56
    }
57
    
58
    /**
59
     * @see javax.swing.table.TableCellEditor#getTableCellEditorComponent(javax.swing.JTable, java.lang.Object, boolean, int, int)
60
     */
61
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
62
        this.setText(value == null ? "" : value.toString());
63
        return this;
64
    }
65

  
66
    /**
67
     * @see javax.swing.CellEditor#cancelCellEditing()
68
     */
69
    public void cancelCellEditing() {
70
        setText(initialValue);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff