Revision 38490
tags/v2_0_0_Build_2049/libraries/libIverUtiles/resources-test/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
|
2 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
3 |
|
|
4 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
5 |
|
|
6 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
7 |
<layout class="org.apache.log4j.PatternLayout"> |
|
8 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
9 |
</layout> |
|
10 |
</appender> |
|
11 |
|
|
12 |
<category name="org.gvsig.tools"> |
|
13 |
<priority value="DEBUG" /> |
|
14 |
</category> |
|
15 |
|
|
16 |
<category name="org.gvsig.utils"> |
|
17 |
<priority value="DEBUG" /> |
|
18 |
</category> |
|
19 |
|
|
20 |
<root> |
|
21 |
<priority value="INFO" /> |
|
22 |
<appender-ref ref="CONSOLE" /> |
|
23 |
</root> |
|
24 |
</log4j:configuration> |
tags/v2_0_0_Build_2049/libraries/libIverUtiles/src/org/gvsig/tools/IverUtilesLibrary.java | ||
---|---|---|
1 |
package org.gvsig.tools; |
|
2 |
|
|
3 |
import org.gvsig.tools.library.AbstractLibrary; |
|
4 |
import org.gvsig.tools.library.LibraryException; |
|
5 |
|
|
6 |
public class IverUtilesLibrary extends AbstractLibrary { |
|
7 |
|
|
8 |
@Override |
|
9 |
public void doRegistration() { |
|
10 |
registerAsAPI(IverUtilesLibrary.class); |
|
11 |
} |
|
12 |
|
|
13 |
@Override |
|
14 |
protected void doInitialize() throws LibraryException { |
|
15 |
// Nothing to do |
|
16 |
} |
|
17 |
|
|
18 |
@Override |
|
19 |
protected void doPostInitialize() throws LibraryException { |
|
20 |
// nothing to do |
|
21 |
} |
|
22 |
} |
|
0 | 23 |
tags/v2_0_0_Build_2049/libraries/libIverUtiles/src/org/gvsig/tools/backup/DefaultBackupGeneratorFactory.java | ||
---|---|---|
1 |
package org.gvsig.tools.backup; |
|
2 |
|
|
3 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
4 |
* |
|
5 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
6 |
* of the Valencian Government (CIT) |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
21 |
* MA 02110-1301, USA. |
|
22 |
* |
|
23 |
*/ |
|
24 |
|
|
25 |
/** |
|
26 |
* <p>Factory that gets a {@link DefaultBackupGenerator DefaultBackupGenerator} as a particular version of |
|
27 |
* backup generator.</p> |
|
28 |
* |
|
29 |
* @author Jose Ignacio Yarza (jiyarza@opensistemas.com) |
|
30 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
|
31 |
*/ |
|
32 |
public class DefaultBackupGeneratorFactory extends BackupGeneratorFactory { |
|
33 |
/* |
|
34 |
* (non-Javadoc) |
|
35 |
* @see com.iver.utiles.backup.BackupGeneratorFactory#getBackupGenerator() |
|
36 |
*/ |
|
37 |
public BackupGenerator getBackupGenerator() { |
|
38 |
return new DefaultBackupGenerator(); |
|
39 |
} |
|
40 |
} |
tags/v2_0_0_Build_2049/libraries/libIverUtiles/src/org/gvsig/tools/backup/BackupGenerator.java | ||
---|---|---|
1 |
package org.gvsig.tools.backup; |
|
2 |
|
|
3 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
4 |
* |
|
5 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
6 |
* of the Valencian Government (CIT) |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
21 |
* MA 02110-1301, USA. |
|
22 |
* |
|
23 |
*/ |
|
24 |
|
|
25 |
import java.io.File; |
|
26 |
|
|
27 |
import org.gvsig.tools.backup.exceptions.BackupException; |
|
28 |
|
|
29 |
|
|
30 |
/** |
|
31 |
* <p>A tagging interface that all file backups must implement.</p> |
|
32 |
* |
|
33 |
* @author Jose Ignacio Yarza (jiyarza@opensistemas.com) |
|
34 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
|
35 |
*/ |
|
36 |
public interface BackupGenerator { |
|
37 |
/** |
|
38 |
* <p>Performs a backup of <code>source</code>.</p> |
|
39 |
* |
|
40 |
* @param source the source file |
|
41 |
*/ |
|
42 |
public void backup(File source) throws BackupException; |
|
43 |
} |
tags/v2_0_0_Build_2049/libraries/libIverUtiles/src/org/gvsig/tools/backup/DefaultBackupGenerator.java | ||
---|---|---|
1 |
package org.gvsig.tools.backup; |
|
2 |
|
|
3 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
4 |
* |
|
5 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
6 |
* of the Valencian Government (CIT) |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
21 |
* MA 02110-1301, USA. |
|
22 |
* |
|
23 |
*/ |
|
24 |
|
|
25 |
import java.io.File; |
|
26 |
import java.io.FileInputStream; |
|
27 |
import java.io.FileOutputStream; |
|
28 |
import java.nio.channels.FileChannel; |
|
29 |
|
|
30 |
import org.gvsig.tools.backup.exceptions.BackupException; |
|
31 |
|
|
32 |
|
|
33 |
/** |
|
34 |
* <p>Performs a backup of a file, into another file at the same path (directory), with the file extension |
|
35 |
* changed to <i>.bak</i>.</p> |
|
36 |
* |
|
37 |
* @author Jose Ignacio Yarza (jiyarza@opensistemas.com) |
|
38 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
|
39 |
*/ |
|
40 |
public class DefaultBackupGenerator implements BackupGenerator { |
|
41 |
/* |
|
42 |
* (non-Javadoc) |
|
43 |
* @see com.iver.utiles.backup.BackupGenerator#backup(java.io.File) |
|
44 |
*/ |
|
45 |
public void backup(File source) throws BackupException { |
|
46 |
try { |
|
47 |
int index = source.getAbsolutePath().lastIndexOf("."); |
|
48 |
|
|
49 |
if (index == -1) |
|
50 |
return; |
|
51 |
|
|
52 |
File dest = new File(source.getAbsolutePath().substring(0, index) + ".bak"); |
|
53 |
|
|
54 |
// Create channel on the source |
|
55 |
FileChannel srcChannel = new FileInputStream(source).getChannel(); |
|
56 |
|
|
57 |
// Create channel on the destination |
|
58 |
FileChannel dstChannel = new FileOutputStream(dest).getChannel(); |
|
59 |
|
|
60 |
// Copy file contents from source to destination |
|
61 |
dstChannel.transferFrom(srcChannel, 0, srcChannel.size()); |
|
62 |
|
|
63 |
// Close the channels |
|
64 |
srcChannel.close(); |
|
65 |
dstChannel.close(); |
|
66 |
} catch (Exception ex) { |
|
67 |
throw new BackupException(ex.getMessage(), ex, source); |
|
68 |
} |
|
69 |
} |
|
70 |
} |
tags/v2_0_0_Build_2049/libraries/libIverUtiles/src/org/gvsig/tools/backup/exceptions/BackupException.java | ||
---|---|---|
1 |
package org.gvsig.tools.backup.exceptions; |
|
2 |
|
|
3 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
4 |
* |
|
5 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
6 |
* of the Valencian Government (CIT) |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
21 |
* MA 02110-1301, USA. |
|
22 |
* |
|
23 |
*/ |
|
24 |
|
|
25 |
import java.io.File; |
|
26 |
|
|
27 |
/** |
|
28 |
* <p>Exception to report that a backup process has failed.</p> |
|
29 |
* |
|
30 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
|
31 |
*/ |
|
32 |
public class BackupException extends Exception { |
|
33 |
private static final long serialVersionUID = -2846421984617208883L; |
|
34 |
|
|
35 |
/** |
|
36 |
* <p>The source file to be backup.</p> |
|
37 |
*/ |
|
38 |
protected File source; |
|
39 |
|
|
40 |
/** |
|
41 |
* <p>Constructs a new backup exception with the specified detail message and cause.</p> |
|
42 |
* |
|
43 |
* @param message the detail message (which is saved for later retrieval by the <code>getMessage()</code> method). |
|
44 |
* @param cause the cause (which is saved for later retrieval by the <code>getCause()</code> method). (A <code>null</code> |
|
45 |
* value is permitted, and indicates that the cause is nonexistent or unknown.) |
|
46 |
* @param source the file from that was going to be done a backup |
|
47 |
* |
|
48 |
* @see Exception#Exception(String, Throwable) |
|
49 |
*/ |
|
50 |
public BackupException(String message, Throwable cause, File source) { |
|
51 |
super(message, cause); |
|
52 |
this.source = source; |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* <p>Gets the source file to be backup.</p> |
|
57 |
* |
|
58 |
* @return the source file |
|
59 |
*/ |
|
60 |
public File getSource() { |
|
61 |
return source; |
|
62 |
} |
|
63 |
} |
tags/v2_0_0_Build_2049/libraries/libIverUtiles/src/org/gvsig/tools/backup/BackupGeneratorFactory.java | ||
---|---|---|
1 |
package org.gvsig.tools.backup; |
|
2 |
|
|
3 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
4 |
* |
|
5 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
6 |
* of the Valencian Government (CIT) |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
21 |
* MA 02110-1301, USA. |
|
22 |
* |
|
23 |
*/ |
|
24 |
|
|
25 |
/** |
|
26 |
* <p>Generic factory that creates a {@link BackupGenerator BackupGenerator} that performs a particular |
|
27 |
* kind of backup.</p> |
|
28 |
* |
|
29 |
* @author Jose Ignacio Yarza (jiyarza@opensistemas.com) |
|
30 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
|
31 |
*/ |
|
32 |
public abstract class BackupGeneratorFactory { |
|
33 |
/** |
|
34 |
* <p>Gets an instance of a backup generator that performs a particular kind of backup.</p> |
|
35 |
* |
|
36 |
* @return an instance of a backup generator that performs a particular kind of backup |
|
37 |
*/ |
|
38 |
public abstract BackupGenerator getBackupGenerator(); |
|
39 |
} |
tags/v2_0_0_Build_2049/libraries/libIverUtiles/src/org/gvsig/utils/DefaultListModel.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
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 2 |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.utils; |
|
42 |
import java.util.Collection; |
|
43 |
import java.util.Enumeration; |
|
44 |
import java.util.Vector; |
|
45 |
|
|
46 |
import javax.swing.AbstractListModel; |
|
47 |
|
|
48 |
|
|
49 |
/** |
|
50 |
* Esta es la misma clase que javax.swing.DefaultListModel |
|
51 |
* pero tiene un constructor que toma como par?metro una |
|
52 |
* collection. |
|
53 |
*/ |
|
54 |
public class DefaultListModel extends AbstractListModel |
|
55 |
{ |
|
56 |
private Vector delegate; |
|
57 |
|
|
58 |
public DefaultListModel(Collection c){ |
|
59 |
delegate = new Vector(c); |
|
60 |
} |
|
61 |
|
|
62 |
public DefaultListModel(){ |
|
63 |
delegate = new Vector(); |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* Returns the number of components in this list. |
|
68 |
* <p> |
|
69 |
* This method is identical to <code>size</code>, which implements the |
|
70 |
* <code>List</code> interface defined in the 1.2 Collections framework. |
|
71 |
* This method exists in conjunction with <code>setSize</code> so that |
|
72 |
* <code>size</code> is identifiable as a JavaBean property. |
|
73 |
* |
|
74 |
* @return the number of components in this list |
|
75 |
* @see #size() |
|
76 |
*/ |
|
77 |
public int getSize() { |
|
78 |
return delegate.size(); |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Returns the component at the specified index. |
|
83 |
* <blockquote> |
|
84 |
* <b>Note:</b> Although this method is not deprecated, the preferred |
|
85 |
* method to use is <code>get(int)</code>, which implements the |
|
86 |
* <code>List</code> interface defined in the 1.2 Collections framework. |
|
87 |
* </blockquote> |
|
88 |
* @param index an index into this list |
|
89 |
* @return the component at the specified index |
|
90 |
* @exception ArrayIndexOutOfBoundsException if the <code>index</code> |
|
91 |
* is negative or greater than the current size of this |
|
92 |
* list |
|
93 |
* @see #get(int) |
|
94 |
*/ |
|
95 |
public Object getElementAt(int index) { |
|
96 |
return delegate.elementAt(index); |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* Copies the components of this list into the specified array. |
|
101 |
* The array must be big enough to hold all the objects in this list, |
|
102 |
* else an <code>IndexOutOfBoundsException</code> is thrown. |
|
103 |
* |
|
104 |
* @param anArray the array into which the components get copied |
|
105 |
* @see Vector#copyInto(Object[]) |
|
106 |
*/ |
|
107 |
public void copyInto(Object anArray[]) { |
|
108 |
delegate.copyInto(anArray); |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* Trims the capacity of this list to be the list's current size. |
|
113 |
* |
|
114 |
* @see Vector#trimToSize() |
|
115 |
*/ |
|
116 |
public void trimToSize() { |
|
117 |
delegate.trimToSize(); |
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* Increases the capacity of this list, if necessary, to ensure |
|
122 |
* that it can hold at least the number of components specified by |
|
123 |
* the minimum capacity argument. |
|
124 |
* |
|
125 |
* @param minCapacity the desired minimum capacity |
|
126 |
* @see Vector#ensureCapacity(int) |
|
127 |
*/ |
|
128 |
public void ensureCapacity(int minCapacity) { |
|
129 |
delegate.ensureCapacity(minCapacity); |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Sets the size of this list. |
|
134 |
* |
|
135 |
* @param newSize the new size of this list |
|
136 |
* @see Vector#setSize(int) |
|
137 |
*/ |
|
138 |
public void setSize(int newSize) { |
|
139 |
int oldSize = delegate.size(); |
|
140 |
delegate.setSize(newSize); |
|
141 |
if (oldSize > newSize) { |
|
142 |
fireIntervalRemoved(this, newSize, oldSize-1); |
|
143 |
} |
|
144 |
else if (oldSize < newSize) { |
|
145 |
fireIntervalAdded(this, oldSize, newSize-1); |
|
146 |
} |
|
147 |
} |
|
148 |
|
|
149 |
/** |
|
150 |
* Returns the current capacity of this list. |
|
151 |
* |
|
152 |
* @return the current capacity |
|
153 |
* @see Vector#capacity() |
|
154 |
*/ |
|
155 |
public int capacity() { |
|
156 |
return delegate.capacity(); |
|
157 |
} |
|
158 |
|
|
159 |
/** |
|
160 |
* Returns the number of components in this list. |
|
161 |
* |
|
162 |
* @return the number of components in this list |
|
163 |
* @see Vector#size() |
|
164 |
*/ |
|
165 |
public int size() { |
|
166 |
return delegate.size(); |
|
167 |
} |
|
168 |
|
|
169 |
/** |
|
170 |
* Tests whether this list has any components. |
|
171 |
* |
|
172 |
* @return <code>true</code> if and only if this list has |
|
173 |
* no components, that is, its size is zero; |
|
174 |
* <code>false</code> otherwise |
|
175 |
* @see Vector#isEmpty() |
|
176 |
*/ |
|
177 |
public boolean isEmpty() { |
|
178 |
return delegate.isEmpty(); |
|
179 |
} |
|
180 |
|
|
181 |
/** |
|
182 |
* Returns an enumeration of the components of this list. |
|
183 |
* |
|
184 |
* @return an enumeration of the components of this list |
|
185 |
* @see Vector#elements() |
|
186 |
*/ |
|
187 |
public Enumeration elements() { |
|
188 |
return delegate.elements(); |
|
189 |
} |
|
190 |
|
|
191 |
/** |
|
192 |
* Tests whether the specified object is a component in this list. |
|
193 |
* |
|
194 |
* @param elem an object |
|
195 |
* @return <code>true</code> if the specified object |
|
196 |
* is the same as a component in this list |
|
197 |
* @see Vector#contains(Object) |
|
198 |
*/ |
|
199 |
public boolean contains(Object elem) { |
|
200 |
return delegate.contains(elem); |
|
201 |
} |
|
202 |
|
|
203 |
/** |
|
204 |
* Searches for the first occurrence of <code>elem</code>. |
|
205 |
* |
|
206 |
* @param elem an object |
|
207 |
* @return the index of the first occurrence of the argument in this |
|
208 |
* list; returns <code>-1</code> if the object is not found |
|
209 |
* @see Vector#indexOf(Object) |
|
210 |
*/ |
|
211 |
public int indexOf(Object elem) { |
|
212 |
return delegate.indexOf(elem); |
|
213 |
} |
|
214 |
|
|
215 |
/** |
|
216 |
* Searches for the first occurrence of <code>elem</code>, beginning |
|
217 |
* the search at <code>index</code>. |
|
218 |
* |
|
219 |
* @param elem an desired component |
|
220 |
* @param index the index from which to begin searching |
|
221 |
* @return the index where the first occurrence of <code>elem</code> |
|
222 |
* is found after <code>index</code>; returns <code>-1</code> |
|
223 |
* if the <code>elem</code> is not found in the list |
|
224 |
* @see Vector#indexOf(Object,int) |
|
225 |
*/ |
|
226 |
public int indexOf(Object elem, int index) { |
|
227 |
return delegate.indexOf(elem, index); |
|
228 |
} |
|
229 |
|
|
230 |
/** |
|
231 |
* Returns the index of the last occurrence of <code>elem</code>. |
|
232 |
* |
|
233 |
* @param elem the desired component |
|
234 |
* @return the index of the last occurrence of <code>elem</code> |
|
235 |
* in the list; returns <code>-1</code> if the object is not found |
|
236 |
* @see Vector#lastIndexOf(Object) |
|
237 |
*/ |
|
238 |
public int lastIndexOf(Object elem) { |
|
239 |
return delegate.lastIndexOf(elem); |
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
243 |
* Searches backwards for <code>elem</code>, starting from the |
|
244 |
* specified index, and returns an index to it. |
|
245 |
* |
|
246 |
* @param elem the desired component |
|
247 |
* @param index the index to start searching from |
|
248 |
* @return the index of the last occurrence of the <code>elem</code> |
|
249 |
* in this list at position less than <code>index</code>; |
|
250 |
* returns <code>-1</code> if the object is not found |
|
251 |
* @see Vector#lastIndexOf(Object,int) |
|
252 |
*/ |
|
253 |
public int lastIndexOf(Object elem, int index) { |
|
254 |
return delegate.lastIndexOf(elem, index); |
|
255 |
} |
|
256 |
|
|
257 |
/** |
|
258 |
* Returns the component at the specified index. |
|
259 |
* Throws an <code>ArrayIndexOutOfBoundsException</code> if the index |
|
260 |
* is negative or not less than the size of the list. |
|
261 |
* <blockquote> |
|
262 |
* <b>Note:</b> Although this method is not deprecated, the preferred |
|
263 |
* method to use is <code>get(int)</code>, which implements the |
|
264 |
* <code>List</code> interface defined in the 1.2 Collections framework. |
|
265 |
* </blockquote> |
|
266 |
* |
|
267 |
* @param index an index into this list |
|
268 |
* @return the component at the specified index |
|
269 |
* @see #get(int) |
|
270 |
* @see Vector#elementAt(int) |
|
271 |
*/ |
|
272 |
public Object elementAt(int index) { |
|
273 |
return delegate.elementAt(index); |
|
274 |
} |
|
275 |
|
|
276 |
/** |
|
277 |
* Returns the first component of this list. |
|
278 |
* Throws a <code>NoSuchElementException</code> if this |
|
279 |
* vector has no components. |
|
280 |
* @return the first component of this list |
|
281 |
* @see Vector#firstElement() |
|
282 |
*/ |
|
283 |
public Object firstElement() { |
|
284 |
return delegate.firstElement(); |
|
285 |
} |
|
286 |
|
|
287 |
/** |
|
288 |
* Returns the last component of the list. |
|
289 |
* Throws a <code>NoSuchElementException</code> if this vector |
|
290 |
* has no components. |
|
291 |
* |
|
292 |
* @return the last component of the list |
|
293 |
* @see Vector#lastElement() |
|
294 |
*/ |
|
295 |
public Object lastElement() { |
|
296 |
return delegate.lastElement(); |
|
297 |
} |
|
298 |
|
|
299 |
/** |
|
300 |
* Sets the component at the specified <code>index</code> of this |
|
301 |
* list to be the specified object. The previous component at that |
|
302 |
* position is discarded. |
|
303 |
* <p> |
|
304 |
* Throws an <code>ArrayIndexOutOfBoundsException</code> if the index |
|
305 |
* is invalid. |
|
306 |
* <blockquote> |
|
307 |
* <b>Note:</b> Although this method is not deprecated, the preferred |
|
308 |
* method to use is <code>set(int,Object)</code>, which implements the |
|
309 |
* <code>List</code> interface defined in the 1.2 Collections framework. |
|
310 |
* </blockquote> |
|
311 |
* |
|
312 |
* @param obj what the component is to be set to |
|
313 |
* @param index the specified index |
|
314 |
* @see #set(int,Object) |
|
315 |
* @see Vector#setElementAt(Object,int) |
|
316 |
*/ |
|
317 |
public void setElementAt(Object obj, int index) { |
|
318 |
delegate.setElementAt(obj, index); |
|
319 |
fireContentsChanged(this, index, index); |
|
320 |
} |
|
321 |
|
|
322 |
/** |
|
323 |
* Deletes the component at the specified index. |
|
324 |
* <p> |
|
325 |
* Throws an <code>ArrayIndexOutOfBoundsException</code> if the index |
|
326 |
* is invalid. |
|
327 |
* <blockquote> |
|
328 |
* <b>Note:</b> Although this method is not deprecated, the preferred |
|
329 |
* method to use is <code>remove(int)</code>, which implements the |
|
330 |
* <code>List</code> interface defined in the 1.2 Collections framework. |
|
331 |
* </blockquote> |
|
332 |
* |
|
333 |
* @param index the index of the object to remove |
|
334 |
* @see #remove(int) |
|
335 |
* @see Vector#removeElementAt(int) |
|
336 |
*/ |
|
337 |
public void removeElementAt(int index) { |
|
338 |
delegate.removeElementAt(index); |
|
339 |
fireIntervalRemoved(this, index, index); |
|
340 |
} |
|
341 |
|
|
342 |
/** |
|
343 |
* Inserts the specified object as a component in this list at the |
|
344 |
* specified <code>index</code>. |
|
345 |
* <p> |
|
346 |
* Throws an <code>ArrayIndexOutOfBoundsException</code> if the index |
|
347 |
* is invalid. |
|
348 |
* <blockquote> |
|
349 |
* <b>Note:</b> Although this method is not deprecated, the preferred |
|
350 |
* method to use is <code>add(int,Object)</code>, which implements the |
|
351 |
* <code>List</code> interface defined in the 1.2 Collections framework. |
|
352 |
* </blockquote> |
|
353 |
* |
|
354 |
* @param obj the component to insert |
|
355 |
* @param index where to insert the new component |
|
356 |
* @exception ArrayIndexOutOfBoundsException if the index was invalid |
|
357 |
* @see #add(int,Object) |
|
358 |
* @see Vector#insertElementAt(Object,int) |
|
359 |
*/ |
|
360 |
public void insertElementAt(Object obj, int index) { |
|
361 |
delegate.insertElementAt(obj, index); |
|
362 |
fireIntervalAdded(this, index, index); |
|
363 |
} |
|
364 |
|
|
365 |
/** |
|
366 |
* Adds the specified component to the end of this list. |
|
367 |
* |
|
368 |
* @param obj the component to be added |
|
369 |
* @see Vector#addElement(Object) |
|
370 |
*/ |
|
371 |
public void addElement(Object obj) { |
|
372 |
int index = delegate.size(); |
|
373 |
delegate.addElement(obj); |
|
374 |
fireIntervalAdded(this, index, index); |
|
375 |
} |
|
376 |
|
|
377 |
/** |
|
378 |
* Removes the first (lowest-indexed) occurrence of the argument |
|
379 |
* from this list. |
|
380 |
* |
|
381 |
* @param obj the component to be removed |
|
382 |
* @return <code>true</code> if the argument was a component of this |
|
383 |
* list; <code>false</code> otherwise |
|
384 |
* @see Vector#removeElement(Object) |
|
385 |
*/ |
|
386 |
public boolean removeElement(Object obj) { |
|
387 |
int index = indexOf(obj); |
|
388 |
boolean rv = delegate.removeElement(obj); |
|
389 |
if (index >= 0) { |
|
390 |
fireIntervalRemoved(this, index, index); |
|
391 |
} |
|
392 |
return rv; |
|
393 |
} |
|
394 |
|
|
395 |
|
|
396 |
/** |
|
397 |
* Removes all components from this list and sets its size to zero. |
|
398 |
* <blockquote> |
|
399 |
* <b>Note:</b> Although this method is not deprecated, the preferred |
|
400 |
* method to use is <code>clear</code>, which implements the |
|
401 |
* <code>List</code> interface defined in the 1.2 Collections framework. |
|
402 |
* </blockquote> |
|
403 |
* |
|
404 |
* @see #clear() |
|
405 |
* @see Vector#removeAllElements() |
|
406 |
*/ |
|
407 |
public void removeAllElements() { |
|
408 |
int index1 = delegate.size()-1; |
|
409 |
delegate.removeAllElements(); |
|
410 |
if (index1 >= 0) { |
|
411 |
fireIntervalRemoved(this, 0, index1); |
|
412 |
} |
|
413 |
} |
|
414 |
|
|
415 |
|
|
416 |
/** |
|
417 |
* Returns a string that displays and identifies this |
|
418 |
* object's properties. |
|
419 |
* |
|
420 |
* @return a String representation of this object |
|
421 |
*/ |
|
422 |
public String toString() { |
|
423 |
return delegate.toString(); |
|
424 |
} |
|
425 |
|
|
426 |
|
|
427 |
/* The remaining methods are included for compatibility with the |
|
428 |
* Java 2 platform Vector class. |
|
429 |
*/ |
|
430 |
|
|
431 |
/** |
|
432 |
* Returns an array containing all of the elements in this list in the |
|
433 |
* correct order. |
|
434 |
* |
|
435 |
* @return an array containing the elements of the list |
|
436 |
* @see Vector#toArray() |
|
437 |
*/ |
|
438 |
public Object[] toArray() { |
|
439 |
Object[] rv = new Object[delegate.size()]; |
|
440 |
delegate.copyInto(rv); |
|
441 |
return rv; |
|
442 |
} |
|
443 |
|
|
444 |
/** |
|
445 |
* Returns the element at the specified position in this list. |
|
446 |
* <p> |
|
447 |
* Throws an <code>ArrayIndexOutOfBoundsException</code> |
|
448 |
* if the index is out of range |
|
449 |
* (<code>index < 0 || index >= size()</code>). |
|
450 |
* |
|
451 |
* @param index index of element to return |
|
452 |
*/ |
|
453 |
public Object get(int index) { |
|
454 |
return delegate.elementAt(index); |
|
455 |
} |
|
456 |
|
|
457 |
/** |
|
458 |
* Replaces the element at the specified position in this list with the |
|
459 |
* specified element. |
|
460 |
* <p> |
|
461 |
* Throws an <code>ArrayIndexOutOfBoundsException</code> |
|
462 |
* if the index is out of range |
|
463 |
* (<code>index < 0 || index >= size()</code>). |
|
464 |
* |
|
465 |
* @param index index of element to replace |
|
466 |
* @param element element to be stored at the specified position |
|
467 |
* @return the element previously at the specified position |
|
468 |
*/ |
|
469 |
public Object set(int index, Object element) { |
|
470 |
Object rv = delegate.elementAt(index); |
|
471 |
delegate.setElementAt(element, index); |
|
472 |
fireContentsChanged(this, index, index); |
|
473 |
return rv; |
|
474 |
} |
|
475 |
|
|
476 |
/** |
|
477 |
* Inserts the specified element at the specified position in this list. |
|
478 |
* <p> |
|
479 |
* Throws an <code>ArrayIndexOutOfBoundsException</code> if the |
|
480 |
* index is out of range |
|
481 |
* (<code>index < 0 || index > size()</code>). |
|
482 |
* |
|
483 |
* @param index index at which the specified element is to be inserted |
|
484 |
* @param element element to be inserted |
|
485 |
*/ |
|
486 |
public void add(int index, Object element) { |
|
487 |
delegate.insertElementAt(element, index); |
|
488 |
fireIntervalAdded(this, index, index); |
|
489 |
} |
|
490 |
|
|
491 |
/** |
|
492 |
* Removes the element at the specified position in this list. |
|
493 |
* Returns the element that was removed from the list. |
|
494 |
* <p> |
|
495 |
* Throws an <code>ArrayIndexOutOfBoundsException</code> |
|
496 |
* if the index is out of range |
|
497 |
* (<code>index < 0 || index >= size()</code>). |
|
498 |
* |
|
499 |
* @param index the index of the element to removed |
|
500 |
*/ |
|
501 |
public Object remove(int index) { |
|
502 |
Object rv = delegate.elementAt(index); |
|
503 |
delegate.removeElementAt(index); |
|
504 |
fireIntervalRemoved(this, index, index); |
|
505 |
return rv; |
|
506 |
} |
|
507 |
|
|
508 |
/** |
|
509 |
* Removes all of the elements from this list. The list will |
|
510 |
* be empty after this call returns (unless it throws an exception). |
|
511 |
*/ |
|
512 |
public void clear() { |
|
513 |
int index1 = delegate.size()-1; |
|
514 |
delegate.removeAllElements(); |
|
515 |
if (index1 >= 0) { |
|
516 |
fireIntervalRemoved(this, 0, index1); |
|
517 |
} |
|
518 |
} |
|
519 |
|
|
520 |
/** |
|
521 |
* Deletes the components at the specified range of indexes. |
|
522 |
* The removal is inclusive, so specifying a range of (1,5) |
|
523 |
* removes the component at index 1 and the component at index 5, |
|
524 |
* as well as all components in between. |
|
525 |
* <p> |
|
526 |
* Throws an <code>ArrayIndexOutOfBoundsException</code> |
|
527 |
* if the index was invalid. |
|
528 |
* Throws an <code>IllegalArgumentException</code> if |
|
529 |
* <code>fromIndex > toIndex</code>. |
|
530 |
* |
|
531 |
* @param fromIndex the index of the lower end of the range |
|
532 |
* @param toIndex the index of the upper end of the range |
|
533 |
* @see #remove(int) |
|
534 |
*/ |
|
535 |
public void removeRange(int fromIndex, int toIndex) { |
|
536 |
for(int i = toIndex; i >= fromIndex; i--) { |
|
537 |
delegate.removeElementAt(i); |
|
538 |
} |
|
539 |
fireIntervalRemoved(this, fromIndex, toIndex); |
|
540 |
} |
|
541 |
|
|
542 |
/* |
|
543 |
public void addAll(Collection c) { |
|
544 |
} |
|
545 |
|
|
546 |
public void addAll(int index, Collection c) { |
|
547 |
} |
|
548 |
*/ |
|
549 |
} |
|
0 | 550 |
tags/v2_0_0_Build_2049/libraries/libIverUtiles/src/org/gvsig/utils/xmlViewer/XMLContent.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
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 2 |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.utils.xmlViewer; |
|
42 |
|
|
43 |
import org.xml.sax.ContentHandler; |
|
44 |
import org.xml.sax.SAXException; |
|
45 |
|
|
46 |
|
|
47 |
/** |
|
48 |
* Interfaz que surte de datos al control XMLViewer |
|
49 |
* |
|
50 |
* @author Fernando Gonz?lez Cort?s |
|
51 |
*/ |
|
52 |
public interface XMLContent { |
|
53 |
/** |
|
54 |
* Mediante este m?todo el control se registra como handler de los eventos |
|
55 |
* SAX disparados en el evento parse |
|
56 |
* |
|
57 |
* @param handler Handler de los eventos del m?todo parse que meter? toda |
|
58 |
* la informaci?n en el control |
|
59 |
*/ |
|
60 |
public void setContentHandler(ContentHandler handler); |
|
61 |
|
|
62 |
/** |
|
63 |
* Debe de lanzar los eventos SAX del contenido XML que representa |
|
64 |
* |
|
65 |
* @throws SAXException Si se produce alg?n error relacionado con los |
|
66 |
* eventos |
|
67 |
*/ |
|
68 |
public void parse() throws SAXException; |
|
69 |
} |
|
0 | 70 |
tags/v2_0_0_Build_2049/libraries/libIverUtiles/src/org/gvsig/utils/xmlViewer/TextXMLContent.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
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 2 |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.utils.xmlViewer; |
|
42 |
|
|
43 |
import java.io.ByteArrayInputStream; |
|
44 |
import java.io.IOException; |
|
45 |
|
|
46 |
import org.xml.sax.ContentHandler; |
|
47 |
import org.xml.sax.InputSource; |
|
48 |
import org.xml.sax.SAXException; |
|
49 |
import org.xml.sax.XMLReader; |
|
50 |
import org.xml.sax.helpers.XMLReaderFactory; |
|
51 |
|
|
52 |
|
|
53 |
/** |
|
54 |
* Clase que sirve de XMLContent al control XMLViewer a partir de un string con |
|
55 |
* un fichero XML |
|
56 |
* |
|
57 |
* @author Fernando Gonz?lez Cort?s |
|
58 |
*/ |
|
59 |
public class TextXMLContent implements XMLContent { |
|
60 |
private String text; |
|
61 |
private ContentHandler handler; |
|
62 |
|
|
63 |
/** |
|
64 |
* Crea un nuevo TextXMLContent. |
|
65 |
* |
|
66 |
* @param text Texto con el XML |
|
67 |
*/ |
|
68 |
public TextXMLContent(String text) { |
|
69 |
this.text = text; |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* @see org.gvsig.utils.xmlViewer.XMLContent#setContentHandler(org.xml.sax.ContentHandler) |
|
74 |
*/ |
|
75 |
public void setContentHandler(ContentHandler handler) { |
|
76 |
this.handler = handler; |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* @see org.gvsig.utils.xmlViewer.XMLContent#parse() |
|
81 |
*/ |
|
82 |
public void parse() throws SAXException { |
|
83 |
XMLReader reader = XMLReaderFactory.createXMLReader(); |
|
84 |
reader.setFeature("http://xml.org/sax/features/namespaces", false); |
|
85 |
reader.setContentHandler(handler); |
|
86 |
|
|
87 |
if (text == null) { |
|
88 |
text = "<?xml version='1.0'?>"; |
|
89 |
} |
|
90 |
|
|
91 |
try { |
|
92 |
reader.parse(new InputSource( |
|
93 |
new ByteArrayInputStream(text.getBytes()))); |
|
94 |
} catch (IOException e) { |
|
95 |
//Una IO exception en un array de bytes??? |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
public String toString(){ |
|
100 |
return text; |
|
101 |
} |
|
102 |
} |
|
0 | 103 |
tags/v2_0_0_Build_2049/libraries/libIverUtiles/src/org/gvsig/utils/xmlViewer/sample/Sample.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
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 2 |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.utils.xmlViewer.sample; |
|
42 |
|
|
43 |
import javax.swing.JFrame; |
|
44 |
|
|
45 |
import org.gvsig.utils.xmlViewer.MultipleXMLContent; |
|
46 |
import org.gvsig.utils.xmlViewer.XMLViewer; |
|
47 |
import org.xml.sax.SAXException; |
|
48 |
|
|
49 |
public class Sample extends JFrame { |
|
50 |
|
|
51 |
private javax.swing.JPanel jContentPane = null; |
|
52 |
|
|
53 |
private XMLViewer XMLViewer = null; |
|
54 |
/** |
|
55 |
* This method initializes XMLViewer |
|
56 |
* |
|
57 |
* @return com.iver.utiles.xmlViewer.XMLViewer |
|
58 |
*/ |
|
59 |
private XMLViewer getXMLViewer() { |
|
60 |
if (XMLViewer == null) { |
|
61 |
XMLViewer = new XMLViewer(); |
|
62 |
XMLViewer.getXmlTree().setRootVisible(false); |
|
63 |
MultipleXMLContent model = new MultipleXMLContent(); |
|
64 |
model.addXML("<?xml version='1.0'?><hola><adios/></hola>"); |
|
65 |
model.addXML("<?xml version='1.0'?><adios><hola/></adios>"); |
|
66 |
try { |
|
67 |
XMLViewer.setModel(model); |
|
68 |
} catch (SAXException e) { |
|
69 |
e.printStackTrace(); |
|
70 |
} |
|
71 |
} |
|
72 |
return XMLViewer; |
|
73 |
} |
|
74 |
public static void main(String[] args) { |
|
75 |
Sample s = new Sample(); |
|
76 |
s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
77 |
s.show(); |
|
78 |
} |
|
79 |
/** |
|
80 |
* This is the default constructor |
|
81 |
*/ |
|
82 |
public Sample() { |
|
83 |
super(); |
|
84 |
initialize(); |
|
85 |
} |
|
86 |
/** |
|
87 |
* This method initializes this |
|
88 |
* |
|
89 |
* @return void |
|
90 |
*/ |
|
91 |
private void initialize() { |
|
92 |
this.setSize(300,200); |
|
93 |
this.setContentPane(getJContentPane()); |
|
94 |
this.setTitle("JFrame"); |
|
95 |
} |
|
96 |
/** |
|
97 |
* This method initializes jContentPane |
|
98 |
* |
|
99 |
* @return javax.swing.JPanel |
|
100 |
*/ |
|
101 |
private javax.swing.JPanel getJContentPane() { |
|
102 |
if(jContentPane == null) { |
|
103 |
jContentPane = new javax.swing.JPanel(); |
|
104 |
jContentPane.setLayout(new java.awt.BorderLayout()); |
|
105 |
jContentPane.add(getXMLViewer(), java.awt.BorderLayout.CENTER); |
|
106 |
} |
|
107 |
return jContentPane; |
|
108 |
} |
|
109 |
} |
|
0 | 110 |
tags/v2_0_0_Build_2049/libraries/libIverUtiles/src/org/gvsig/utils/xmlViewer/XMLViewer.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 13-sep-2004 |
|
3 |
* |
|
4 |
* To change the template for this generated file go to |
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments |
|
6 |
*/ |
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
8 |
* |
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
10 |
* |
|
11 |
* This program is free software; you can redistribute it and/or |
|
12 |
* modify it under the terms of the GNU General Public License |
|
13 |
* as published by the Free Software Foundation; either version 2 |
|
14 |
* of the License, or (at your option) any later version. |
|
15 |
* |
|
16 |
* This program is distributed in the hope that it will be useful, |
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
* GNU General Public License for more details. |
|
20 |
* |
|
21 |
* You should have received a copy of the GNU General Public License |
|
22 |
* along with this program; if not, write to the Free Software |
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
24 |
* |
|
25 |
* For more information, contact: |
|
26 |
* |
|
27 |
* Generalitat Valenciana |
|
28 |
* Conselleria d'Infraestructures i Transport |
|
29 |
* Av. Blasco Ib??ez, 50 |
|
30 |
* 46010 VALENCIA |
|
31 |
* SPAIN |
|
32 |
* |
|
33 |
* +34 963862235 |
|
34 |
* gvsig@gva.es |
|
35 |
* www.gvsig.gva.es |
|
36 |
* |
|
37 |
* or |
|
38 |
* |
|
39 |
* IVER T.I. S.A |
|
40 |
* Salamanca 50 |
|
41 |
* 46005 Valencia |
|
42 |
* Spain |
|
43 |
* |
|
44 |
* +34 963163400 |
|
45 |
* dac@iver.es |
|
46 |
*/ |
|
47 |
package org.gvsig.utils.xmlViewer; |
|
48 |
|
|
49 |
import java.util.HashMap; |
|
50 |
import java.util.Iterator; |
|
51 |
import java.util.Stack; |
|
52 |
|
|
53 |
import javax.swing.JPanel; |
|
54 |
import javax.swing.table.DefaultTableModel; |
|
55 |
import javax.swing.tree.DefaultMutableTreeNode; |
|
56 |
import javax.swing.tree.DefaultTreeModel; |
|
57 |
|
|
58 |
import org.xml.sax.Attributes; |
|
59 |
import org.xml.sax.ContentHandler; |
|
60 |
import org.xml.sax.Locator; |
|
61 |
import org.xml.sax.SAXException; |
|
62 |
|
|
63 |
|
|
64 |
/** |
|
65 |
* Control que visualiza los contenidos de un XML jerarquicamente en un arbol, |
|
66 |
* los attributos de cada nodo en una tabla y el texto contenido entre los |
|
67 |
* tags en un area de texto |
|
68 |
* |
|
69 |
* @author Fernando Gonz?lez Cort?s |
|
70 |
*/ |
|
71 |
public class XMLViewer extends JPanel { |
|
72 |
|
|
73 |
private javax.swing.JScrollPane jScrollPane = null; |
|
74 |
private javax.swing.JTree xmlTree = null; |
|
75 |
private javax.swing.JScrollPane jScrollPane1 = null; |
|
76 |
private javax.swing.JTable attributeTable = null; |
|
77 |
private javax.swing.JSplitPane jSplitPane = null; |
|
78 |
private javax.swing.JScrollPane jScrollPane2 = null; |
|
79 |
private javax.swing.JTextArea txtContent = null; |
|
80 |
private javax.swing.JSplitPane jSplitPane1 = null; |
|
81 |
private DefaultTreeModel treeModel = null; |
|
82 |
private XMLContent content; |
|
83 |
private javax.swing.JPanel jPanel = null; |
|
84 |
private javax.swing.JPanel jPanel1 = null; |
|
85 |
private String[] namesColumn; |
|
86 |
|
|
87 |
/** |
|
88 |
* This is the default constructor |
|
89 |
*/ |
|
90 |
public XMLViewer() { |
|
91 |
super(); |
|
92 |
initialize(); |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* Establece el origen XML del control |
|
97 |
* |
|
98 |
* @param content Objeto que lanzar? los eventos del XML a representar |
|
99 |
* |
|
100 |
* @throws SAXException Si se produce alg?n error en el parseado del |
|
101 |
* contenido |
|
102 |
*/ |
|
103 |
public synchronized void setModel(XMLContent content) throws SAXException { |
|
104 |
this.content = content; |
|
105 |
parse(); |
|
106 |
} |
|
107 |
|
|
108 |
/** |
|
109 |
* Parsea el modelo rellenando los controles con la informaci?n |
|
110 |
* |
|
111 |
* @throws SAXException Si se produce un error de SAX parseando el |
|
112 |
* XMLContent |
|
113 |
*/ |
|
114 |
private void parse() throws SAXException { |
|
115 |
MyContentHandler contentHandler = new MyContentHandler(); |
|
116 |
content.setContentHandler(contentHandler); |
|
117 |
content.parse(); |
|
118 |
treeModel = new DefaultTreeModel(contentHandler.getRoot()); |
|
119 |
xmlTree.setModel(treeModel); |
|
120 |
xmlTree.clearSelection(); |
|
121 |
// getJSplitPane().setDividerLocation(1.0); // Por defecto |
|
122 |
|
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* This method initializes this |
|
127 |
*/ |
|
128 |
private void initialize() { |
|
129 |
this.setLayout(new java.awt.BorderLayout()); |
|
130 |
this.add(getJSplitPane1(), java.awt.BorderLayout.CENTER); |
|
131 |
//this.setPreferredSize(new Dimension(600, 600)); |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* This method initializes jScrollPane |
|
136 |
* |
|
137 |
* @return javax.swing.JScrollPane |
|
138 |
*/ |
|
139 |
private javax.swing.JScrollPane getJScrollPane() { |
|
140 |
if (jScrollPane == null) { |
|
141 |
jScrollPane = new javax.swing.JScrollPane(); |
|
142 |
jScrollPane.setViewportView(getJPanel()); |
|
143 |
} |
|
144 |
|
|
145 |
return jScrollPane; |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* This method initializes xmlTree |
|
150 |
* |
|
151 |
* @return javax.swing.JTree |
|
152 |
*/ |
|
153 |
public javax.swing.JTree getXmlTree() { |
|
154 |
if (xmlTree == null) { |
|
155 |
xmlTree = new javax.swing.JTree(); |
|
156 |
xmlTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() { |
|
157 |
|
|
158 |
public void valueChanged( |
|
159 |
javax.swing.event.TreeSelectionEvent e) { |
|
160 |
DefaultTableModel tableModel = new DefaultTableModel(); |
|
161 |
for (int i=0;i<namesColumn.length;i++){ |
|
162 |
tableModel.addColumn(namesColumn[i]); |
|
163 |
} |
|
164 |
|
|
165 |
Node selected = (Node) e.getPath().getLastPathComponent(); |
|
166 |
xmlTree.expandPath(e.getPath()); |
|
167 |
HashMap map = selected.attributes; |
|
168 |
boolean hasAtts = false; |
|
169 |
Iterator i = map.keySet().iterator(); |
|
170 |
|
|
171 |
while (i.hasNext()) { |
|
172 |
hasAtts = true; |
|
173 |
|
|
174 |
Object key = i.next(); |
|
175 |
tableModel.addRow(new Object[] { key, map.get(key) }); |
|
176 |
} |
|
177 |
|
|
178 |
getAttributeTable().setModel(tableModel); |
|
179 |
getAttributeTable().getTableHeader().setVisible(true); |
|
180 |
|
|
181 |
if (selected.content == null) { |
|
182 |
getTxtContent().setVisible( false); |
|
183 |
} else { |
|
184 |
getTxtContent().setVisible(true); |
|
185 |
getTxtContent().setText(selected.content); |
|
186 |
getTxtContent().setEditable( false); |
|
187 |
getJSplitPane().setDividerLocation(0);//(jSplitPane.getHeight()); |
|
188 |
} |
|
189 |
|
|
190 |
} |
|
191 |
}); |
|
192 |
} |
|
193 |
xmlTree.setShowsRootHandles(true); |
|
194 |
xmlTree.setExpandsSelectedPaths(true); |
|
195 |
// xmlTree.setToggleClickCount(1); |
|
196 |
return xmlTree; |
|
197 |
} |
|
198 |
|
|
199 |
/** |
|
200 |
* This method initializes attributeTable |
|
201 |
* |
|
202 |
* @return javax.swing.JTable |
|
203 |
*/ |
|
204 |
private javax.swing.JTable getAttributeTable() { |
|
205 |
if (attributeTable == null) { |
|
206 |
attributeTable = new javax.swing.JTable(); |
|
207 |
attributeTable.getTableHeader().setVisible(true); |
|
208 |
} |
|
209 |
|
|
210 |
return attributeTable; |
|
211 |
} |
|
212 |
|
|
213 |
/** |
|
214 |
* This method initializes jScrollPane1 |
|
215 |
* |
|
216 |
* @return javax.swing.JScrollPane |
|
217 |
*/ |
|
218 |
private javax.swing.JScrollPane getJScrollPane1() { |
|
219 |
if (jScrollPane1 == null) { |
|
220 |
jScrollPane1 = new javax.swing.JScrollPane(); |
|
221 |
jScrollPane1.setViewportView(getAttributeTable()); |
|
222 |
} |
|
223 |
|
|
224 |
return jScrollPane1; |
|
225 |
} |
|
226 |
|
|
227 |
/** |
|
228 |
* This method initializes jSplitPane |
|
229 |
* |
|
230 |
* @return javax.swing.JSplitPane |
|
231 |
*/ |
|
232 |
private javax.swing.JSplitPane getJSplitPane() { |
|
233 |
if (jSplitPane == null) { |
|
234 |
jSplitPane = new javax.swing.JSplitPane(); |
|
235 |
jSplitPane.setTopComponent(getJScrollPane1()); |
|
236 |
jSplitPane.setBottomComponent(getJScrollPane2()); |
|
237 |
jSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); |
|
238 |
//jSplitPane.setOrientation(javax.swing.JSplitPane.HORIZONTAL_SPLIT); |
|
239 |
jSplitPane.setDividerLocation(0.9); |
|
240 |
jSplitPane.setResizeWeight(0.9); |
|
241 |
jSplitPane.setDividerSize(5); |
|
242 |
} |
|
243 |
|
|
244 |
return jSplitPane; |
|
245 |
} |
|
246 |
|
|
247 |
/** |
|
248 |
* This method initializes jScrollPane2 |
|
249 |
* |
|
250 |
* @return javax.swing.JScrollPane |
|
251 |
*/ |
|
252 |
private javax.swing.JScrollPane getJScrollPane2() { |
Also available in: Unified diff