Revision 41957
tags/org.gvsig.desktop-2.0.78/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.78/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.78/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.78/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.78/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.78/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.78/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.78/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.78/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.78/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/swing/objectSelection/ObjectSelection.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.objectSelection; |
|
25 |
|
|
26 |
import javax.swing.DefaultComboBoxModel; |
|
27 |
import javax.swing.JLabel; |
|
28 |
import javax.swing.JPanel; |
|
29 |
|
|
30 |
import org.gvsig.utils.swing.JComboBox; |
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
/** |
|
35 |
* Control consistente en un texto y un combo autocompletable |
|
36 |
* |
|
37 |
* @author Fernando Gonz?lez Cort?s |
|
38 |
*/ |
|
39 |
public class ObjectSelection extends JPanel { |
|
40 |
private JLabel jLabel = null; |
|
41 |
private JComboBox combo = null; |
|
42 |
private ObjectSelectionModel model; |
|
43 |
private DefaultComboBoxModel cmbModel = new DefaultComboBoxModel(); |
|
44 |
private Object selected; |
|
45 |
/** |
|
46 |
* This is the default constructor |
|
47 |
*/ |
|
48 |
public ObjectSelection() { |
|
49 |
super(); |
|
50 |
initialize(); |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* This method initializes this |
|
55 |
*/ |
|
56 |
private void initialize() { |
|
57 |
jLabel = new JLabel(); |
|
58 |
this.setSize(504, 265); |
|
59 |
this.add(jLabel, null); |
|
60 |
this.add(getCombo(), null); |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* Obtiene una referencia al combo |
|
65 |
* |
|
66 |
* @return com.iver.utiles.swing.JComboBox |
|
67 |
*/ |
|
68 |
protected JComboBox getCombo() { |
|
69 |
if (combo == null) { |
|
70 |
combo = new JComboBox(); |
|
71 |
combo.setModel(cmbModel); |
|
72 |
combo.setEditable(true); |
|
73 |
combo.addItemListener(new java.awt.event.ItemListener() { |
|
74 |
public void itemStateChanged(java.awt.event.ItemEvent e) { |
|
75 |
seleccion(); |
|
76 |
} |
|
77 |
}); |
|
78 |
} |
|
79 |
|
|
80 |
return combo; |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* M?todo invocado cuando cambia la selecci?n del combo |
|
85 |
*/ |
|
86 |
protected void seleccion() { |
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* Establece el modelo del control |
|
91 |
* |
|
92 |
* @param model The model to set. |
|
93 |
* |
|
94 |
* @throws SelectionException Si hay alg?n error leyendo los |
|
95 |
* datos del modelo |
|
96 |
*/ |
|
97 |
public void setModel(ObjectSelectionModel model) throws SelectionException { |
|
98 |
this.model = model; |
|
99 |
|
|
100 |
Object[] objects = model.getObjects(); |
|
101 |
cmbModel.removeAllElements(); |
|
102 |
|
|
103 |
for (int i = 0; i < objects.length; i++) { |
|
104 |
cmbModel.addElement(objects[i]); |
|
105 |
} |
|
106 |
|
|
107 |
getCombo().setSelectedIndex(-1); |
|
108 |
|
|
109 |
jLabel.setText(model.getMsg()); |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* Obtiene el elemento actualmente seleccionado |
|
114 |
* |
|
115 |
* @return Returns the selected item. |
|
116 |
*/ |
|
117 |
public Object getSelected() { |
|
118 |
return cmbModel.getSelectedItem(); |
|
119 |
} |
|
120 |
} // @jve:decl-index=0:visual-constraint="10,10" |
|
0 | 121 |
tags/org.gvsig.desktop-2.0.78/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/swing/objectSelection/ObjectSelectionModel.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.objectSelection; |
|
25 |
|
|
26 |
/** |
|
27 |
* Modelo del control ObjectSelection |
|
28 |
* |
|
29 |
* @author Fernando Gonz?lez Cort?s |
|
30 |
*/ |
|
31 |
public interface ObjectSelectionModel { |
|
32 |
/** |
|
33 |
* Obtiene las referencias a los objetos que aparecer?n |
|
34 |
* seleccionables en el combo |
|
35 |
* |
|
36 |
* @return array de objetos |
|
37 |
* |
|
38 |
* @throws SelectionException Si se produce alg?n error |
|
39 |
*/ |
|
40 |
public Object[] getObjects() throws SelectionException; |
|
41 |
|
|
42 |
/** |
|
43 |
* Obtiene el mensaje que se mostrar? al usuario |
|
44 |
* |
|
45 |
* @return String |
|
46 |
* |
|
47 |
*/ |
|
48 |
public String getMsg(); |
|
49 |
} |
|
0 | 50 |
tags/org.gvsig.desktop-2.0.78/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/swing/objectSelection/SelectionException.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.objectSelection; |
|
25 |
|
|
26 |
/** |
|
27 |
* Excepci?n que indica que el modelo del control ObjectSelection no puede |
|
28 |
* proporcionar la informaci?n requerida. |
|
29 |
* |
|
30 |
* @author Fernando Gonz?lez Cort?s |
|
31 |
*/ |
|
32 |
public class SelectionException extends Exception { |
|
33 |
/** |
|
34 |
* |
|
35 |
*/ |
|
36 |
public SelectionException() { |
|
37 |
super(); |
|
38 |
|
|
39 |
// TODO Auto-generated constructor stub |
|
40 |
} |
|
41 |
|
|
42 |
/** |
|
43 |
* constructor |
|
44 |
* |
|
45 |
* @param message |
|
46 |
*/ |
|
47 |
public SelectionException(String message) { |
|
48 |
super(message); |
|
49 |
|
|
50 |
// TODO Auto-generated constructor stub |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* constructor |
|
55 |
* |
|
56 |
* @param message |
|
57 |
* @param cause |
|
58 |
*/ |
|
59 |
public SelectionException(String message, Throwable cause) { |
|
60 |
super(message, cause); |
|
61 |
|
|
62 |
// TODO Auto-generated constructor stub |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* constructor |
|
67 |
* |
|
68 |
* @param cause |
|
69 |
*/ |
|
70 |
public SelectionException(Throwable cause) { |
|
71 |
super(cause); |
|
72 |
|
|
73 |
// TODO Auto-generated constructor stub |
|
74 |
} |
|
75 |
} |
|
0 | 76 |
tags/org.gvsig.desktop-2.0.78/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/swing/jcomboServer/JComboServer.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 |
|
|
25 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
26 |
* |
|
27 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
28 |
* |
|
29 |
* This program is free software; you can redistribute it and/or |
|
30 |
* modify it under the terms of the GNU General Public License |
|
31 |
* as published by the Free Software Foundation; either version 2 |
|
32 |
* of the License, or (at your option) any later version. |
|
33 |
* |
|
34 |
* This program is distributed in the hope that it will be useful, |
|
35 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
36 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
37 |
* GNU General Public License for more details. |
|
38 |
* |
|
39 |
* You should have received a copy of the GNU General Public License |
|
40 |
* along with this program; if not, write to the Free Software |
|
41 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
42 |
* |
|
43 |
* For more information, contact: |
|
44 |
* |
|
45 |
* Generalitat Valenciana |
|
46 |
* Conselleria d'Infraestructures i Transport |
|
47 |
* Av. Blasco Ib??ez, 50 |
|
48 |
* 46010 VALENCIA |
|
49 |
* SPAIN |
|
50 |
* |
|
51 |
* +34 963862235 |
|
52 |
* gvsig@gva.es |
|
53 |
* www.gvsig.gva.es |
|
54 |
* |
|
55 |
* or |
|
56 |
* |
|
57 |
* IVER T.I. S.A |
|
58 |
* Salamanca 50 |
|
59 |
* 46005 Valencia |
|
60 |
* Spain |
|
61 |
* |
|
62 |
* +34 963163400 |
|
63 |
* dac@iver.es |
|
64 |
*/ |
|
65 |
package org.gvsig.utils.swing.jcomboServer; |
|
66 |
import javax.swing.JComboBox; |
|
67 |
|
|
68 |
/** |
|
69 |
* This class is a user interface component that looks equal to |
|
70 |
* a JComboBox component, but it contains ServerData objects and |
|
71 |
* it is able to show them in last access order.It has methods to |
|
72 |
* add ServerData objects and to retrieve them. |
|
73 |
* |
|
74 |
* @see java.swing.JComboBox |
|
75 |
* @see es.gva.cit.catalogClient.utils.comboserver.ServerData |
|
76 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
|
77 |
*/ |
|
78 |
public class JComboServer extends JComboBox { |
|
79 |
|
|
80 |
/** |
|
81 |
* Just a simple constructor |
|
82 |
* |
|
83 |
*/ |
|
84 |
public JComboServer() { |
|
85 |
super(); |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* A constructor |
|
90 |
* |
|
91 |
* |
|
92 |
* @param servers Array with all the rervers to show |
|
93 |
*/ |
|
94 |
public JComboServer(ServerData[] servers) { |
|
95 |
super(setLastAccessOrder(servers)); |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* This method returns the selected server |
|
100 |
* |
|
101 |
* |
|
102 |
* @return A Server |
|
103 |
*/ |
|
104 |
public ServerData getSelectedServer() { |
|
105 |
try { |
|
106 |
return (ServerData) getSelectedItem(); |
|
107 |
}catch(ClassCastException e){ |
|
108 |
return new ServerData((String)getSelectedItem(),"",""); |
|
109 |
} |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* This method adds a new Server in order |
|
114 |
* |
|
115 |
* |
|
116 |
* @param server New Server |
|
117 |
*/ |
|
118 |
public void addServer(ServerData server) { |
|
119 |
ServerData[] servers = getAllServers(); |
|
120 |
ServerData[] newServers = new ServerData[servers.length + 1]; |
|
121 |
System.arraycopy(servers, 0, newServers, 0, servers.length); |
|
122 |
newServers[servers.length] = server; |
|
123 |
newServers = setLastAccessOrder(newServers); |
|
124 |
setServerList(newServers); |
|
125 |
} |
|
126 |
|
|
127 |
/** |
|
128 |
* This method returns an array with all the servers that the |
|
129 |
* combo contains |
|
130 |
* |
|
131 |
* |
|
132 |
* @return An array of servers |
|
133 |
*/ |
|
134 |
public ServerData[] getAllServers() { |
|
135 |
ServerData[] servers = new ServerData[getItemCount()]; |
|
136 |
for (int i=0 ; i<getItemCount() ; i++){ |
|
137 |
servers[i] = (ServerData) this.getItemAt(i); |
|
138 |
} |
|
139 |
return servers; |
|
140 |
} |
|
141 |
|
|
142 |
/** |
|
143 |
* It adds a server list |
|
144 |
* |
|
145 |
* |
|
146 |
* @param servers Array with servers |
|
147 |
*/ |
|
148 |
public void setServerList(ServerData[] servers) { |
|
149 |
removeAllItems(); |
|
150 |
servers = setLastAccessOrder(servers); |
|
151 |
for (int i=0 ; i<servers.length ; i++){ |
|
152 |
try{ |
|
153 |
if (!(servers[i].getServerAddress().equals(""))){ |
|
154 |
addItem(servers[i]); |
|
155 |
} |
|
156 |
}catch(java.lang.NullPointerException e){ |
|
157 |
//Server is null |
|
158 |
} |
|
159 |
} |
|
160 |
} |
|
161 |
|
|
162 |
/** |
|
163 |
* This method order all the servers in the combo |
|
164 |
* |
|
165 |
*/ |
|
166 |
public void setServersOrder() { |
|
167 |
ServerData[] servers = getAllServers(); |
|
168 |
servers = setLastAccessOrder(servers); |
|
169 |
setServerList(servers); |
|
170 |
} |
|
171 |
|
|
172 |
/** |
|
173 |
* This static method ordered an array of servers by last access |
|
174 |
* |
|
175 |
* |
|
176 |
* @return A new array |
|
177 |
* @param servers Array of servers |
|
178 |
*/ |
|
179 |
private static ServerData[] setLastAccessOrder(ServerData[] servers) { |
|
180 |
ServerData[] orderedServerData = new ServerData[servers.length]; |
|
181 |
|
|
182 |
for (int i=0 ; i<servers.length ; i++){ |
|
183 |
int pos = getServerPosition(servers, i); |
|
184 |
orderedServerData[pos] = servers[i]; |
|
185 |
} |
|
186 |
return orderedServerData; |
|
187 |
} |
|
188 |
|
|
189 |
/** |
|
190 |
* This static function return the ordered position of a server. The algorithm to |
|
191 |
* order can be changed. |
|
192 |
* |
|
193 |
* |
|
194 |
* @return Number with the new position |
|
195 |
* @param servers Array that contains all the servers |
|
196 |
* @param serverPos Server position |
|
197 |
*/ |
|
198 |
private static int getServerPosition(ServerData[] servers, int serverPos) { |
|
199 |
int pos=0; |
|
200 |
for (int i=0 ; i<servers.length ; i++){ |
|
201 |
if (!(servers[serverPos].getServerAddress().equals(servers[i].getServerAddress()))){ |
|
202 |
if (servers[serverPos].getLastAccess().before(servers[i].getLastAccess())){ |
|
203 |
pos++; |
|
204 |
} |
|
205 |
if (servers[serverPos].getLastAccess().equals(servers[i].getLastAccess())){ |
|
206 |
if (serverPos < i){ |
|
207 |
pos++; |
|
208 |
} |
|
209 |
} |
|
210 |
|
|
211 |
} |
|
212 |
} |
|
213 |
return pos; |
|
214 |
} |
|
215 |
} |
|
0 | 216 |
tags/org.gvsig.desktop-2.0.78/org.gvsig.desktop.library/org.gvsig.utils/src/main/java/org/gvsig/utils/swing/jcomboServer/ServerData.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.jcomboServer; |
|
25 |
import java.util.Date; |
|
26 |
import java.util.Properties; |
|
27 |
|
|
28 |
import org.gvsig.tools.ToolsLocator; |
|
29 |
import org.gvsig.tools.dynobject.DynStruct; |
|
30 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
31 |
import org.gvsig.tools.persistence.Persistent; |
|
32 |
import org.gvsig.tools.persistence.PersistentState; |
|
33 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
34 |
import org.gvsig.utils.DateTime; |
|
35 |
|
|
36 |
|
|
37 |
/** |
|
38 |
* This class represents a data server, that can be a WMS, WFS, Catalog or |
|
39 |
* any kind of server. It contains the server URL and has a couple of |
|
40 |
* attributes that describe the server type (serverType and serverSubType). |
|
41 |
* It contains the date when the server was created and the date when the server |
|
42 |
* was accessed last time. * |
|
43 |
* |
|
44 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
|
45 |
*/ |
|
46 |
|
|
47 |
public class ServerData implements Persistent { |
|
48 |
public static final String PERSISTENT_NAME = "ServerData_Persistent"; |
|
49 |
public static final String PERSISTENT_DESCRIPTION = "ServerData Persistent"; |
|
50 |
|
|
51 |
|
|
52 |
/** |
|
53 |
* |
|
54 |
* |
|
55 |
*/ |
|
56 |
public static final String SERVER_TYPE_CATALOG = "CATALOG"; |
|
57 |
|
|
58 |
/** |
|
59 |
* |
|
60 |
* |
|
61 |
*/ |
|
62 |
public static final String SERVER_TYPE_GAZETTEER = "GAZETTEER"; |
|
63 |
|
|
64 |
/** |
|
65 |
* |
|
66 |
* |
|
67 |
*/ |
|
68 |
public static final String SERVER_TYPE_MULTIPLE = "MULTIPLE"; |
|
69 |
/** |
|
70 |
* |
|
71 |
* |
|
72 |
*/ |
|
73 |
public static final String SERVER_TYPE_WMS = "WMS"; |
|
74 |
|
|
75 |
/** |
|
76 |
* |
|
77 |
* |
|
78 |
*/ |
|
79 |
public static final String SERVER_TYPE_WCS = "WCS"; |
|
80 |
|
|
81 |
/** |
|
82 |
* |
|
83 |
* |
|
84 |
*/ |
|
85 |
public static final String SERVER_TYPE_WFS = "WFS"; |
|
86 |
|
|
87 |
/** |
|
88 |
* |
|
89 |
* |
|
90 |
*/ |
|
91 |
public static final String SERVER_TYPE_WMTS = "WMTS"; |
|
92 |
|
|
93 |
/** |
|
94 |
* |
|
95 |
* |
|
96 |
*/ |
|
97 |
public static final String SERVER_SUBTYPE_CATALOG_Z3950 = "Z3950"; |
|
98 |
|
|
99 |
/** |
|
100 |
* |
|
101 |
* |
|
102 |
*/ |
|
103 |
public static final String SERVER_SUBTYPE_CATALOG_SRW = "SRW"; |
|
104 |
|
|
105 |
/** |
|
106 |
* |
|
107 |
* |
|
108 |
*/ |
|
109 |
public static final String SERVER_SUBTYPE_CATALOG_CSW = "CSW"; |
|
110 |
|
|
111 |
/** |
|
112 |
* |
|
113 |
* |
|
114 |
*/ |
|
115 |
public static final String SERVER_SUBTYPE_GAZETTEER_WFSG = "WFS-G"; |
|
116 |
|
|
117 |
/** |
|
118 |
* |
|
119 |
* |
|
120 |
*/ |
|
121 |
public static final String SERVER_SUBTYPE_GAZETTEER_ADL = "ADL"; |
Also available in: Unified diff