Revision 69
org.gvsig.catalog/trunk/org.gvsig.catalog/org.gvsig.catalog.lib/src/main/java/org/gvsig/catalog/utils/CatalogConstants.java | ||
---|---|---|
1 |
package org.gvsig.catalog.utils; |
|
2 |
|
|
3 |
import java.awt.Dimension; |
|
4 |
|
|
5 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
6 |
* |
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
8 |
* |
|
9 |
* This program is free software; you can redistribute it and/or |
|
10 |
* modify it under the terms of the GNU General Public License |
|
11 |
* as published by the Free Software Foundation; either version 2 |
|
12 |
* of the License, or (at your option) any later version. |
|
13 |
* |
|
14 |
* This program is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
* GNU General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU General Public License |
|
20 |
* along with this program; if not, write to the Free Software |
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
22 |
* |
|
23 |
* For more information, contact: |
|
24 |
* |
|
25 |
* Generalitat Valenciana |
|
26 |
* Conselleria d'Infraestructures i Transport |
|
27 |
* Av. Blasco Ib??ez, 50 |
|
28 |
* 46010 VALENCIA |
|
29 |
* SPAIN |
|
30 |
* |
|
31 |
* +34 963862235 |
|
32 |
* gvsig@gva.es |
|
33 |
* www.gvsig.gva.es |
|
34 |
* |
|
35 |
* or |
|
36 |
* |
|
37 |
* IVER T.I. S.A |
|
38 |
* Salamanca 50 |
|
39 |
* 46005 Valencia |
|
40 |
* Spain |
|
41 |
* |
|
42 |
* +34 963163400 |
|
43 |
* dac@iver.es |
|
44 |
*/ |
|
45 |
/* CVS MESSAGES: |
|
46 |
* |
|
47 |
* $Id: CatalogConstants.java 602 2007-09-24 11:55:02 +0000 (Mon, 24 Sep 2007) jpiera $ |
|
48 |
* $Log$ |
|
49 |
* Revision 1.1.2.4 2007/07/24 09:45:52 jorpiell |
|
50 |
* Fix some interface bugs |
|
51 |
* |
|
52 |
* Revision 1.1.2.3 2007/07/23 07:14:25 jorpiell |
|
53 |
* Catalog refactoring |
|
54 |
* |
|
55 |
* Revision 1.1.2.2 2007/07/11 13:01:50 jorpiell |
|
56 |
* Catalog UI updated |
|
57 |
* |
|
58 |
* Revision 1.1.2.1 2007/07/10 11:18:04 jorpiell |
|
59 |
* Added the registers |
|
60 |
* |
|
61 |
* |
|
62 |
*/ |
|
63 |
/** |
|
64 |
* This class has some constants for the catalog client |
|
65 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
66 |
*/ |
|
67 |
public class CatalogConstants { |
|
68 |
public static final int BUTTON_LENGHT = 80; |
|
69 |
public static final int BUTTON_WIDTH = 23; |
|
70 |
public static final Dimension BUTTON_SIZE = new Dimension(BUTTON_LENGHT,BUTTON_WIDTH); |
|
71 |
public static final int RESIZE_WINDOW_BUTTON_SIZE = 30; |
|
72 |
|
|
73 |
//Action commands |
|
74 |
public static final String CLOSE_BUTTON_ACTION_COMMAND = "close"; |
|
75 |
public static final String NEXT_BUTTON_ACTION_COMMAND = "next"; |
|
76 |
public static final String LAST_BUTTON_ACTION_COMMAND = "last"; |
|
77 |
public static final String CANCEL_BUTTON_ACTION_COMMAND = "cancel"; |
|
78 |
public static final String SEARCH_BUTTON_ACTION_COMMAND = "search"; |
|
79 |
public static final String PROTOCOL_COMBO_ACTION_COMMAND = "protocolCombo"; |
|
80 |
public static final String SERVER_COMBO_ACTION_COMMAND = "serverCombo"; |
|
81 |
public static final String RESIZE_BUTTON_ACTION_COMMAND = "resize"; |
|
82 |
public static final String CONNECT_BUTTON_ACTION_COMMAND = "connect"; |
|
83 |
public static final String SERVERPROPERTIES_BUTTON_ACTION_COMMAND = "serverProperties"; |
|
84 |
|
|
85 |
//conordancia |
|
86 |
public static final String EXACT_WORDS = "E"; |
|
87 |
public static final String ANY_WORD = "Y"; |
|
88 |
public static final String ALL_WORDS = "A"; |
|
89 |
public static final String OR = "Or"; |
|
90 |
public static final String AND = "And"; |
|
91 |
|
|
92 |
//Connection |
|
93 |
public static final int GET = 0; |
|
94 |
public static final int POST = 1; |
|
95 |
public static final int SOAP = 2; |
|
96 |
public static final int Z3950 = 4; |
|
97 |
|
|
98 |
//XML |
|
99 |
public static final String XML_HEADER_ENCODING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; |
|
100 |
public static final String XML_NS = "xmlns"; |
|
101 |
|
|
102 |
} |
|
0 | 103 |
org.gvsig.catalog/trunk/org.gvsig.catalog/org.gvsig.catalog.lib/src/main/java/org/gvsig/catalog/utils/xmltreetable/XMLTreeCellRenderer.java | ||
---|---|---|
1 |
|
|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
3 |
* |
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
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 2 |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
* |
|
20 |
* For more information, contact: |
|
21 |
* |
|
22 |
* Generalitat Valenciana |
|
23 |
* Conselleria d'Infraestructures i Transport |
|
24 |
* Av. Blasco Ib??ez, 50 |
|
25 |
* 46010 VALENCIA |
|
26 |
* SPAIN |
|
27 |
* |
|
28 |
* +34 963862235 |
|
29 |
* gvsig@gva.es |
|
30 |
* www.gvsig.gva.es |
|
31 |
* |
|
32 |
* or |
|
33 |
* |
|
34 |
* IVER T.I. S.A |
|
35 |
* Salamanca 50 |
|
36 |
* 46005 Valencia |
|
37 |
* Spain |
|
38 |
* |
|
39 |
* +34 963163400 |
|
40 |
* dac@iver.es |
|
41 |
*/ |
|
42 |
package org.gvsig.catalog.utils.xmltreetable; |
|
43 |
|
|
44 |
/** |
|
45 |
* |
|
46 |
* |
|
47 |
* |
|
48 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
|
49 |
*/ |
|
50 |
public class XMLTreeCellRenderer extends javax.swing.tree.DefaultTreeCellRenderer { |
|
51 |
|
|
52 |
/** |
|
53 |
* |
|
54 |
* |
|
55 |
*/ |
|
56 |
public XMLTreeCellRenderer() { |
|
57 |
this.setClosedIcon(null); |
|
58 |
this.setOpenIcon(null); |
|
59 |
this.setLeafIcon(null); |
|
60 |
} |
|
61 |
} |
|
0 | 62 |
org.gvsig.catalog/trunk/org.gvsig.catalog/org.gvsig.catalog.lib/src/main/java/org/gvsig/catalog/utils/xmltreetable/XMLTreeTable.java | ||
---|---|---|
1 |
|
|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
3 |
* |
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
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 2 |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
* |
|
20 |
* For more information, contact: |
|
21 |
* |
|
22 |
* Generalitat Valenciana |
|
23 |
* Conselleria d'Infraestructures i Transport |
|
24 |
* Av. Blasco Ib??ez, 50 |
|
25 |
* 46010 VALENCIA |
|
26 |
* SPAIN |
|
27 |
* |
|
28 |
* +34 963862235 |
|
29 |
* gvsig@gva.es |
|
30 |
* www.gvsig.gva.es |
|
31 |
* |
|
32 |
* or |
|
33 |
* |
|
34 |
* IVER T.I. S.A |
|
35 |
* Salamanca 50 |
|
36 |
* 46005 Valencia |
|
37 |
* Spain |
|
38 |
* |
|
39 |
* +34 963163400 |
|
40 |
* dac@iver.es |
|
41 |
*/ |
|
42 |
package org.gvsig.catalog.utils.xmltreetable; |
|
43 |
import javax.swing.JComponent; |
|
44 |
import javax.swing.JTree; |
|
45 |
|
|
46 |
import next.swing.JTreeTable; |
|
47 |
import next.swing.TreeTableModel; |
|
48 |
|
|
49 |
/** |
|
50 |
* |
|
51 |
* |
|
52 |
* |
|
53 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
|
54 |
*/ |
|
55 |
public class XMLTreeTable extends JTreeTable { |
|
56 |
|
|
57 |
/** |
|
58 |
* |
|
59 |
* |
|
60 |
* |
|
61 |
* @param treeTableModel |
|
62 |
*/ |
|
63 |
public XMLTreeTable(TreeTableModel treeTableModel) { |
|
64 |
super(treeTableModel); |
|
65 |
tree.setCellRenderer(new XMLTreeCellRenderer()); |
|
66 |
setDefaultEditor(JComponent.class, new XMLTreeTableCellEditor()); |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* |
|
71 |
* |
|
72 |
* |
|
73 |
* @return |
|
74 |
*/ |
|
75 |
public JTree getTree() { |
|
76 |
return tree; |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* |
|
81 |
* |
|
82 |
* |
|
83 |
* @return |
|
84 |
* @param x |
|
85 |
* @param y |
|
86 |
*/ |
|
87 |
public boolean isCellEditable(int x, int y) { |
|
88 |
return true; |
|
89 |
} |
|
90 |
} |
|
0 | 91 |
org.gvsig.catalog/trunk/org.gvsig.catalog/org.gvsig.catalog.lib/src/main/java/org/gvsig/catalog/utils/xmltreetable/XMLTreeTableModel.java | ||
---|---|---|
1 |
|
|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
3 |
* |
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
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 2 |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
* |
|
20 |
* For more information, contact: |
|
21 |
* |
|
22 |
* Generalitat Valenciana |
|
23 |
* Conselleria d'Infraestructures i Transport |
|
24 |
* Av. Blasco Ib??ez, 50 |
|
25 |
* 46010 VALENCIA |
|
26 |
* SPAIN |
|
27 |
* |
|
28 |
* +34 963862235 |
|
29 |
* gvsig@gva.es |
|
30 |
* www.gvsig.gva.es |
|
31 |
* |
|
32 |
* or |
|
33 |
* |
|
34 |
* IVER T.I. S.A |
|
35 |
* Salamanca 50 |
|
36 |
* 46005 Valencia |
|
37 |
* Spain |
|
38 |
* |
|
39 |
* +34 963163400 |
|
40 |
* dac@iver.es |
|
41 |
*/ |
|
42 |
package org.gvsig.catalog.utils.xmltreetable; |
|
43 |
import java.awt.Font; |
|
44 |
import java.util.Enumeration; |
|
45 |
import java.util.Vector; |
|
46 |
|
|
47 |
import javax.swing.JEditorPane; |
|
48 |
import javax.swing.JLabel; |
|
49 |
import javax.swing.JScrollPane; |
|
50 |
import javax.swing.JTree; |
|
51 |
import javax.swing.tree.DefaultMutableTreeNode; |
|
52 |
import javax.swing.tree.TreePath; |
|
53 |
|
|
54 |
import next.swing.AbstractTreeTableModel; |
|
55 |
import next.swing.TreeTableModel; |
|
56 |
|
|
57 |
import org.amic.util.date.Date; |
|
58 |
import org.gvsig.catalog.metadataxml.XMLNode; |
|
59 |
import org.gvsig.catalog.utils.Strings; |
|
60 |
|
|
61 |
/** |
|
62 |
* |
|
63 |
* |
|
64 |
* |
|
65 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
|
66 |
*/ |
|
67 |
public class XMLTreeTableModel extends AbstractTreeTableModel { |
|
68 |
|
|
69 |
/** |
|
70 |
* |
|
71 |
* |
|
72 |
*/ |
|
73 |
private Vector columns = null; |
|
74 |
|
|
75 |
/** |
|
76 |
* |
|
77 |
* |
|
78 |
*/ |
|
79 |
private String[] allowed = null; |
|
80 |
|
|
81 |
/** |
|
82 |
* |
|
83 |
* |
|
84 |
*/ |
|
85 |
private String[] forbidden = null; |
|
86 |
|
|
87 |
/** |
|
88 |
* |
|
89 |
* |
|
90 |
*/ |
|
91 |
private boolean dynamic = false; |
|
92 |
|
|
93 |
/** |
|
94 |
* Creates new XmlTreeTableModel |
|
95 |
* |
|
96 |
* |
|
97 |
* @param node |
|
98 |
*/ |
|
99 |
public XMLTreeTableModel(XMLNode node) { |
|
100 |
this(node, -1, null, null); |
|
101 |
} |
|
102 |
|
|
103 |
/** |
|
104 |
* |
|
105 |
* |
|
106 |
* |
|
107 |
* @param node |
|
108 |
* @param level |
|
109 |
* @param allowed |
|
110 |
* @param forbidden |
|
111 |
*/ |
|
112 |
public XMLTreeTableModel(XMLNode node, int level, String[] allowed, String[] forbidden) { |
|
113 |
super(new DefaultMutableTreeNode(node)); |
|
114 |
this.allowed = allowed; |
|
115 |
this.forbidden = forbidden; |
|
116 |
processChildren((DefaultMutableTreeNode) getRoot(), level); |
|
117 |
} |
|
118 |
|
|
119 |
/** |
|
120 |
* |
|
121 |
* |
|
122 |
*/ |
|
123 |
public final int ALIGN_LEFT = JLabel.LEFT; |
|
124 |
|
|
125 |
/** |
|
126 |
* |
|
127 |
* |
|
128 |
*/ |
|
129 |
public final int ALIGN_RIGHT = JLabel.RIGHT; |
|
130 |
|
|
131 |
/** |
|
132 |
* |
|
133 |
* |
|
134 |
*/ |
|
135 |
public final int ALIGN_CENTER = JLabel.CENTER; |
|
136 |
|
|
137 |
/** |
|
138 |
* |
|
139 |
* |
|
140 |
* |
|
141 |
* @param value |
|
142 |
*/ |
|
143 |
public void setDynamic(boolean value) { |
|
144 |
dynamic = value; |
|
145 |
} |
|
146 |
|
|
147 |
/** |
|
148 |
* |
|
149 |
* |
|
150 |
* |
|
151 |
* @return |
|
152 |
* @param node |
|
153 |
*/ |
|
154 |
public boolean isLeaf(Object node) { |
|
155 |
return (getChildCount(node) == 0) && !dynamic; |
|
156 |
} |
|
157 |
|
|
158 |
/** |
|
159 |
* |
|
160 |
* |
|
161 |
* |
|
162 |
* @return |
|
163 |
* @param node |
|
164 |
* @param level |
|
165 |
*/ |
|
166 |
public boolean processChildren(DefaultMutableTreeNode node, int level) { |
|
167 |
if (level == 0) { |
|
168 |
return true; |
|
169 |
} |
|
170 |
boolean doIt = true; |
|
171 |
XMLNode n = (XMLNode) node.getUserObject(); |
|
172 |
if (allowed != null) { |
|
173 |
String name = n.getName(); |
|
174 |
doIt = false; |
|
175 |
for (int i = 0; i < allowed.length; i++) |
|
176 |
if (allowed[i].equals(name)) { |
|
177 |
doIt = true; |
|
178 |
break; |
|
179 |
} |
|
180 |
} |
|
181 |
if (forbidden != null) { |
|
182 |
String name = n.getName(); |
|
183 |
for (int i = 0; i < forbidden.length; i++) |
|
184 |
if (forbidden[i].equals(name)) { |
|
185 |
doIt = false; |
|
186 |
break; |
|
187 |
} |
|
188 |
} |
|
189 |
if (!doIt) { |
|
190 |
return false; |
|
191 |
} |
|
192 |
XMLNode[] nodes = n.getSubnodes(); |
|
193 |
DefaultMutableTreeNode newNode; |
|
194 |
for (int i=0 ; i<nodes.length ; i++) { |
|
195 |
newNode = new DefaultMutableTreeNode(nodes[i]); |
|
196 |
if (processChildren(newNode, level - 1)) { |
|
197 |
node.add(newNode); |
|
198 |
} |
|
199 |
} |
|
200 |
return true; |
|
201 |
} |
|
202 |
|
|
203 |
/** |
|
204 |
* |
|
205 |
* |
|
206 |
* |
|
207 |
* @param ctt |
|
208 |
*/ |
|
209 |
public void configureView(XMLTreeTable ctt) { |
|
210 |
Column col; |
|
211 |
javax.swing.table.TableColumnModel tcm = ctt.getColumnModel(); |
|
212 |
ctt.setRowHeight(20); |
|
213 |
int total = 0; |
|
214 |
for (int i = 1; i < tcm.getColumnCount(); i++) { |
|
215 |
col = ((Column) columns.elementAt(i - 1)); |
|
216 |
tcm.getColumn(i).setPreferredWidth(50); |
|
217 |
total += col.width; |
|
218 |
tcm.getColumn(i).setCellRenderer(new XMLTreeTableCellRenderer()); |
|
219 |
} |
|
220 |
tcm.getColumn(0).setWidth(100); |
|
221 |
setExpandedTree((DefaultMutableTreeNode) getRoot(), ctt.getTree()); |
|
222 |
} |
|
223 |
|
|
224 |
/** |
|
225 |
* |
|
226 |
* |
|
227 |
* |
|
228 |
* @return |
|
229 |
* @param node |
|
230 |
* @param tree |
|
231 |
*/ |
|
232 |
public boolean setExpandedTree(DefaultMutableTreeNode node, JTree tree) { |
|
233 |
boolean isExpanded = false; |
|
234 |
Enumeration children = node.children(); |
|
235 |
while (children.hasMoreElements()) { |
|
236 |
DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement(); |
|
237 |
if (setExpandedTree(child, tree) && (isExpanded == false)) { |
|
238 |
isExpanded = true; |
|
239 |
} |
|
240 |
} |
|
241 |
if (node.isLeaf() && (isValueAt(node) || isAttributeAt(node))) { |
|
242 |
tree.expandPath(new TreePath(node.getPath())); |
|
243 |
return true; |
|
244 |
} |
|
245 |
if (isExpanded) { |
|
246 |
tree.expandPath(new TreePath(node.getPath())); |
|
247 |
} |
|
248 |
return isExpanded; |
|
249 |
} |
|
250 |
|
|
251 |
/** |
|
252 |
* |
|
253 |
* |
|
254 |
* |
|
255 |
* @param name |
|
256 |
* @param attribute |
|
257 |
* @param label |
|
258 |
* @param width |
|
259 |
*/ |
|
260 |
public void addJScrollPaneColumn(String name, String attribute, String label, int width) { |
|
261 |
addColumn(new Column(name, attribute, label, ALIGN_LEFT, width, |
|
262 |
JScrollPane.class, null)); |
|
263 |
} |
|
264 |
|
|
265 |
/** |
|
266 |
* |
|
267 |
* |
|
268 |
* |
|
269 |
* @param name |
|
270 |
* @param attribute |
|
271 |
* @param label |
|
272 |
* @param width |
|
273 |
*/ |
|
274 |
public void addStringColumn(String name, String attribute, String label, int width) { |
|
275 |
addColumn(new Column(name, attribute, label, ALIGN_LEFT, width, |
|
276 |
String.class, null)); |
|
277 |
} |
|
278 |
|
|
279 |
/** |
|
280 |
* |
|
281 |
* |
|
282 |
* |
|
283 |
* @param name |
|
284 |
* @param attribute |
|
285 |
* @param label |
|
286 |
* @param width |
|
287 |
* @param format |
|
288 |
*/ |
|
289 |
public void addNumberColumn(String name, String attribute, String label, int width, String format) { |
|
290 |
addColumn(new Column(name, attribute, label, ALIGN_RIGHT, width, |
|
291 |
Double.class, format)); |
|
292 |
} |
|
293 |
|
|
294 |
/** |
|
295 |
* |
|
296 |
* |
|
297 |
* |
|
298 |
* @param name |
|
299 |
* @param attribute |
|
300 |
* @param label |
|
301 |
* @param width |
|
302 |
* @param format |
|
303 |
*/ |
|
304 |
public void addDateColumn(String name, String attribute, String label, int width, String format) { |
|
305 |
addColumn(new Column(name, attribute, label, ALIGN_LEFT, width, |
|
306 |
Date.class, format)); |
|
307 |
} |
|
308 |
|
|
309 |
/** |
|
310 |
* |
|
311 |
* |
|
312 |
* |
|
313 |
* @param column |
|
314 |
*/ |
|
315 |
public void addColumn(Column column) { |
|
316 |
if (columns == null) { |
|
317 |
columns = new Vector(); |
|
318 |
} |
|
319 |
columns.add(column); |
|
320 |
} |
|
321 |
|
|
322 |
/** |
|
323 |
* |
|
324 |
* |
|
325 |
* |
|
326 |
* @return |
|
327 |
* @param parent |
|
328 |
*/ |
|
329 |
public int getChildCount(Object parent) { |
|
330 |
return ((DefaultMutableTreeNode) parent).getChildCount(); |
|
331 |
} |
|
332 |
|
|
333 |
/** |
|
334 |
* |
|
335 |
* |
|
336 |
* |
|
337 |
* @return |
|
338 |
* @param parent |
|
339 |
* @param index |
|
340 |
*/ |
|
341 |
public Object getChild(Object parent, int index) { |
|
342 |
return ((DefaultMutableTreeNode) parent).getChildAt(index); |
|
343 |
} |
|
344 |
|
|
345 |
/** |
|
346 |
* |
|
347 |
* |
|
348 |
* |
|
349 |
* @return |
|
350 |
* @param column |
|
351 |
*/ |
|
352 |
public String getColumnName(int column) { |
|
353 |
if (column == 0) { |
|
354 |
return ""; |
|
355 |
} |
|
356 |
return ((Column) columns.elementAt(column - 1)).label; |
|
357 |
} |
|
358 |
|
|
359 |
/** |
|
360 |
* |
|
361 |
* |
|
362 |
* |
|
363 |
* @return |
|
364 |
* @param column |
|
365 |
*/ |
|
366 |
public Class getColumnClass(int column) { |
|
367 |
if (column == 0) { |
|
368 |
return TreeTableModel.class; |
|
369 |
} |
|
370 |
return ((Column) columns.elementAt(column - 1)).jClass; |
|
371 |
} |
|
372 |
|
|
373 |
/** |
|
374 |
* |
|
375 |
* |
|
376 |
* |
|
377 |
* @return |
|
378 |
* @param node |
|
379 |
*/ |
|
380 |
public boolean isValueAt(Object node) { |
|
381 |
DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) node; |
|
382 |
if (currentNode.getUserObject() instanceof XMLNode) { |
|
383 |
XMLNode xr = (XMLNode) currentNode.getUserObject(); |
|
384 |
if (xr != null) { |
|
385 |
if (xr.getText() != null) { |
|
386 |
if (!(Strings.replace(xr.getText(), " ", "").equals(""))) { |
|
387 |
return true; |
|
388 |
} |
|
389 |
} |
|
390 |
} |
|
391 |
} |
|
392 |
return false; |
|
393 |
} |
|
394 |
|
|
395 |
/** |
|
396 |
* |
|
397 |
* |
|
398 |
* |
|
399 |
* @return |
|
400 |
* @param node |
|
401 |
*/ |
|
402 |
public boolean isAttributeAt(Object node) { |
|
403 |
DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) node; |
|
404 |
if (currentNode.getUserObject() instanceof XMLNode) { |
|
405 |
XMLNode xr = (XMLNode) currentNode.getUserObject(); |
|
406 |
if (xr != null) { |
|
407 |
if (getAttribute(xr) != null) { |
|
408 |
if (!(Strings.replace(getAttribute(xr), |
|
409 |
" ", "").equals(""))) { |
|
410 |
return true; |
|
411 |
} |
|
412 |
} |
|
413 |
} |
|
414 |
} |
|
415 |
return false; |
|
416 |
} |
|
417 |
|
|
418 |
/** |
|
419 |
* |
|
420 |
* |
|
421 |
* |
|
422 |
* @return |
|
423 |
* @param node |
|
424 |
*/ |
|
425 |
public String getValueAt(Object node) { |
|
426 |
DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) node; |
|
427 |
if (currentNode.getUserObject() instanceof XMLNode) { |
|
428 |
XMLNode xr = (XMLNode) currentNode.getUserObject(); |
|
429 |
|
|
430 |
return xr.getText(); |
|
431 |
} |
|
432 |
return null; |
|
433 |
} |
|
434 |
|
|
435 |
/** |
|
436 |
* |
|
437 |
* |
|
438 |
* |
|
439 |
* @return |
|
440 |
* @param node |
|
441 |
* @param column |
|
442 |
*/ |
|
443 |
public Object getValueAt(Object node, int column) { |
|
444 |
//JScrollPane |
|
445 |
JEditorPane editor = new JEditorPane(); |
|
446 |
editor.setEditable(false); |
|
447 |
JScrollPane scroll = new JScrollPane(editor); |
|
448 |
scroll.setBorder(null); |
|
449 |
//JLabel |
|
450 |
JLabel text = new JLabel(); |
|
451 |
text.setFont(new Font(null, Font.PLAIN, 12)); |
|
452 |
DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) node; |
|
453 |
if (currentNode.getUserObject() instanceof XMLNode) { |
|
454 |
XMLNode xr = (XMLNode) currentNode.getUserObject(); |
|
455 |
if (column == 0) { |
|
456 |
return xr.toString(); |
|
457 |
} |
|
458 |
Column col = (Column) columns.elementAt(column - 1); |
|
459 |
String att = col.attribute; |
|
460 |
try { |
|
461 |
if (att.equals("tag-name")) { |
|
462 |
if (xr.getName().trim().length() > 40) { |
|
463 |
editor.setText(xr.getName()); |
|
464 |
editor.setCaretPosition(0); |
|
465 |
return scroll; |
|
466 |
} |
|
467 |
text.setText(xr.getName()); |
|
468 |
|
|
469 |
return text; |
|
470 |
} else if (att.equals("tag-value")) { |
|
471 |
if (xr.getText().trim().length() > 40) { |
|
472 |
editor.setText(xr.getText()); |
|
473 |
editor.setCaretPosition(0); |
|
474 |
return scroll; |
|
475 |
} |
|
476 |
text.setText(xr.getText()); |
|
477 |
return text; |
|
478 |
} else { |
|
479 |
if (getAttribute(xr).trim().length() > 40) { |
|
480 |
editor.setText(getAttribute(xr)); |
|
481 |
editor.setCaretPosition(0); |
|
482 |
return scroll; |
|
483 |
} |
|
484 |
text.setText(getAttribute(xr)); |
|
485 |
return text; |
|
486 |
} |
|
487 |
} catch (Exception ex) { |
|
488 |
} |
|
489 |
} |
|
490 |
return null; |
|
491 |
} |
|
492 |
|
|
493 |
/** |
|
494 |
* |
|
495 |
* |
|
496 |
* |
|
497 |
* @return |
|
498 |
* @param node |
|
499 |
*/ |
|
500 |
public String getAttribute(XMLNode node) { |
|
501 |
String attributes = ""; |
|
502 |
Vector vAttributes = node.getAttributeNames(); |
|
503 |
|
|
504 |
for (int i = 0; i < vAttributes.size(); i++){ |
|
505 |
String att = (String)vAttributes.get(i); |
|
506 |
String val = node.getAttribute(att); |
|
507 |
attributes = attributes + |
|
508 |
att + "=" + val + " "; |
|
509 |
} |
|
510 |
return attributes; |
|
511 |
} |
|
512 |
|
|
513 |
/** |
|
514 |
* |
|
515 |
* |
|
516 |
* |
|
517 |
* @return |
|
518 |
*/ |
|
519 |
public int getColumnCount() { |
|
520 |
if (columns == null) { |
|
521 |
return 1; |
|
522 |
} |
|
523 |
return columns.size() + 1; |
|
524 |
} |
|
525 |
/** |
|
526 |
* |
|
527 |
* |
|
528 |
*/ |
|
529 |
public class Column { |
|
530 |
|
|
531 |
/** |
|
532 |
* |
|
533 |
* |
|
534 |
*/ |
|
535 |
int align; |
|
536 |
|
|
537 |
/** |
|
538 |
* |
|
539 |
* |
|
540 |
*/ |
|
541 |
int width; |
|
542 |
|
|
543 |
/** |
|
544 |
* |
|
545 |
* |
|
546 |
*/ |
|
547 |
Class jClass; |
|
548 |
|
|
549 |
/** |
|
550 |
* |
|
551 |
* |
|
552 |
*/ |
|
553 |
String name; |
|
554 |
|
|
555 |
/** |
|
556 |
* |
|
557 |
* |
|
558 |
*/ |
|
559 |
String attribute; |
|
560 |
|
|
561 |
/** |
|
562 |
* |
|
563 |
* |
|
564 |
*/ |
|
565 |
String label; |
|
566 |
|
|
567 |
/** |
|
568 |
* |
|
569 |
* |
|
570 |
*/ |
|
571 |
String format; |
|
572 |
|
|
573 |
/** |
|
574 |
* |
|
575 |
* |
|
576 |
* |
|
577 |
* @param name |
|
578 |
* @param attribute |
|
579 |
* @param label |
|
580 |
* @param align |
|
581 |
* @param width |
|
582 |
* @param jClass |
|
583 |
* @param format |
|
584 |
*/ |
|
585 |
Column(String name, String attribute, String label, int align, int width, Class jClass, String format) { |
|
586 |
this.name = name; |
|
587 |
this.attribute = attribute; |
|
588 |
this.label = label; |
|
589 |
this.align = align; |
|
590 |
this.width = width; |
|
591 |
this.jClass = jClass; |
|
592 |
this.format = format; |
|
593 |
} |
|
594 |
} |
|
595 |
} |
|
0 | 596 |
org.gvsig.catalog/trunk/org.gvsig.catalog/org.gvsig.catalog.lib/src/main/java/org/gvsig/catalog/utils/xmltreetable/XMLTreeTableCellEditor.java | ||
---|---|---|
1 |
|
|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
3 |
* |
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
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 2 |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
* |
|
20 |
* For more information, contact: |
|
21 |
* |
|
22 |
* Generalitat Valenciana |
|
23 |
* Conselleria d'Infraestructures i Transport |
|
24 |
* Av. Blasco Ib??ez, 50 |
|
25 |
* 46010 VALENCIA |
|
26 |
* SPAIN |
|
27 |
* |
|
28 |
* +34 963862235 |
|
29 |
* gvsig@gva.es |
|
30 |
* www.gvsig.gva.es |
|
31 |
* |
|
32 |
* or |
|
33 |
* |
|
34 |
* IVER T.I. S.A |
|
35 |
* Salamanca 50 |
|
36 |
* 46005 Valencia |
|
37 |
* Spain |
|
38 |
* |
|
39 |
* +34 963163400 |
|
40 |
* dac@iver.es |
|
41 |
*/ |
|
42 |
package org.gvsig.catalog.utils.xmltreetable; |
|
43 |
import java.awt.Component; |
|
44 |
import java.awt.event.MouseEvent; |
|
45 |
import java.io.Serializable; |
|
46 |
import java.util.EventObject; |
|
47 |
|
|
48 |
import javax.swing.JComponent; |
|
49 |
import javax.swing.JTable; |
|
50 |
import javax.swing.JTree; |
|
51 |
import javax.swing.SwingUtilities; |
|
52 |
import javax.swing.event.CellEditorListener; |
|
53 |
import javax.swing.event.ChangeEvent; |
|
54 |
import javax.swing.event.EventListenerList; |
|
55 |
import javax.swing.table.TableCellEditor; |
|
56 |
import javax.swing.tree.TreeCellEditor; |
|
57 |
|
|
58 |
/** |
|
59 |
* DOCUMENT ME! |
|
60 |
* |
|
61 |
* |
|
62 |
* @author $author$ |
|
63 |
*/ |
|
64 |
public class XMLTreeTableCellEditor implements Serializable, TableCellEditor, TreeCellEditor { |
|
65 |
/** |
|
66 |
* |
|
67 |
* |
|
68 |
*/ |
|
69 |
protected EventListenerList listenerList = new EventListenerList(); |
|
70 |
/** |
|
71 |
* |
|
72 |
* |
|
73 |
*/ |
|
74 |
protected transient ChangeEvent changeEvent = null; |
|
75 |
/** |
|
76 |
* |
|
77 |
* |
|
78 |
*/ |
|
79 |
protected JComponent editorComponent = null; |
|
80 |
/** |
|
81 |
* |
|
82 |
* |
|
83 |
*/ |
|
84 |
protected JComponent container = null; |
|
85 |
// Can be tree or table |
|
86 |
|
|
87 |
/** |
|
88 |
* DOCUMENT ME! |
|
89 |
* |
|
90 |
* |
|
91 |
* @return DOCUMENT ME! |
|
92 |
*/ |
|
93 |
public Component getComponent() { |
|
94 |
return editorComponent; |
|
95 |
} |
|
96 |
|
|
97 |
/** |
|
98 |
* DOCUMENT ME! |
|
99 |
* |
|
100 |
* |
|
101 |
* @return DOCUMENT ME! |
|
102 |
*/ |
|
103 |
public Object getCellEditorValue() { |
|
104 |
return editorComponent; |
|
105 |
} |
|
106 |
|
|
107 |
/** |
|
108 |
* DOCUMENT ME! |
|
109 |
* |
|
110 |
* |
|
111 |
* @return DOCUMENT ME! |
|
112 |
* @param anEvent DOCUMENT ME! |
|
113 |
*/ |
|
114 |
public boolean isCellEditable(EventObject anEvent) { |
|
115 |
return true; |
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* DOCUMENT ME! |
|
120 |
* |
|
121 |
* |
|
122 |
* @return DOCUMENT ME! |
|
123 |
* @param anEvent DOCUMENT ME! |
|
124 |
*/ |
|
125 |
public boolean shouldSelectCell(EventObject anEvent) { |
|
126 |
if ((editorComponent != null) && anEvent instanceof MouseEvent && |
|
127 |
(((MouseEvent) anEvent).getID() == MouseEvent.MOUSE_PRESSED)) { |
|
128 |
Component dispatchComponent = SwingUtilities.getDeepestComponentAt(editorComponent, |
|
129 |
3, 3); |
|
130 |
MouseEvent e = (MouseEvent) anEvent; |
|
131 |
MouseEvent e2 = new MouseEvent(dispatchComponent, |
|
132 |
MouseEvent.MOUSE_RELEASED, e.getWhen() + 100000, |
|
133 |
e.getModifiers(), 3, 3, e.getClickCount(), |
|
134 |
e.isPopupTrigger()); |
|
135 |
dispatchComponent.dispatchEvent(e2); |
|
136 |
e2 = new MouseEvent(dispatchComponent, MouseEvent.MOUSE_CLICKED, |
|
137 |
e.getWhen() + 100001, e.getModifiers(), 3, 3, 1, |
|
138 |
e.isPopupTrigger()); |
|
139 |
dispatchComponent.dispatchEvent(e2); |
|
140 |
} |
|
141 |
return false; |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* DOCUMENT ME! |
|
146 |
* |
|
147 |
* |
|
148 |
* @return DOCUMENT ME! |
|
149 |
*/ |
|
150 |
public boolean stopCellEditing() { |
|
151 |
fireEditingStopped(); |
|
152 |
return true; |
|
153 |
} |
|
154 |
|
|
155 |
/** |
|
156 |
* DOCUMENT ME! |
|
157 |
* |
|
158 |
*/ |
|
159 |
public void cancelCellEditing() { |
|
160 |
fireEditingCanceled(); |
|
161 |
} |
|
162 |
|
|
163 |
/** |
|
164 |
* DOCUMENT ME! |
|
165 |
* |
|
166 |
* |
|
167 |
* @param l DOCUMENT ME! |
|
168 |
*/ |
|
169 |
public void addCellEditorListener(CellEditorListener l) { |
|
170 |
listenerList.add(CellEditorListener.class, l); |
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* DOCUMENT ME! |
|
175 |
* |
|
176 |
* |
|
177 |
* @param l DOCUMENT ME! |
|
178 |
*/ |
|
179 |
public void removeCellEditorListener(CellEditorListener l) { |
|
180 |
listenerList.remove(CellEditorListener.class, l); |
|
181 |
} |
|
182 |
|
|
183 |
/** |
|
184 |
* DOCUMENT ME! |
|
185 |
* |
|
186 |
*/ |
|
187 |
protected void fireEditingStopped() { |
|
188 |
Object[] listeners = listenerList.getListenerList(); |
|
189 |
// Process the listeners last to first, notifying |
|
190 |
// those that are interested in this event |
|
191 |
for (int i = listeners.length - 2; i >= 0; i -= 2) { |
|
192 |
if (listeners[i] == CellEditorListener.class) { |
|
193 |
// Lazily create the event: |
|
194 |
if (changeEvent == null) { |
|
195 |
changeEvent = new ChangeEvent(this); |
|
196 |
} |
|
197 |
((CellEditorListener) listeners[i + 1]).editingStopped(changeEvent); |
|
198 |
} |
|
199 |
} |
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* DOCUMENT ME! |
|
204 |
* |
|
205 |
*/ |
|
206 |
protected void fireEditingCanceled() { |
|
207 |
// Guaranteed to return a non-null array |
|
208 |
Object[] listeners = listenerList.getListenerList(); |
|
209 |
// Process the listeners last to first, notifying |
|
210 |
// those that are interested in this event |
|
211 |
for (int i = listeners.length - 2; i >= 0; i -= 2) { |
|
212 |
if (listeners[i] == CellEditorListener.class) { |
|
213 |
// Lazily create the event: |
|
214 |
if (changeEvent == null) { |
|
215 |
changeEvent = new ChangeEvent(this); |
|
216 |
} |
|
217 |
((CellEditorListener) listeners[i + 1]).editingCanceled(changeEvent); |
|
218 |
} |
|
219 |
} |
|
220 |
} |
|
221 |
// implements javax.swing.tree.TreeCellEditor |
|
222 |
|
|
223 |
/** |
|
224 |
* |
|
225 |
* |
|
226 |
* |
|
227 |
* @return |
|
228 |
* @param tree |
|
229 |
* @param value |
|
230 |
* @param isSelected |
|
231 |
* @param expanded |
|
232 |
* @param leaf |
|
233 |
* @param row |
|
234 |
*/ |
|
235 |
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { |
|
236 |
tree.convertValueToText(value, isSelected, |
|
237 |
expanded, leaf, row, false); |
|
238 |
editorComponent = (JComponent) value; |
|
239 |
container = tree; |
|
240 |
return editorComponent; |
|
241 |
} |
|
242 |
// implements javax.swing.table.TableCellEditor |
|
243 |
|
|
244 |
/** |
|
245 |
* |
|
246 |
* |
|
247 |
* |
|
248 |
* @return |
|
249 |
* @param table |
|
250 |
* @param value |
|
251 |
* @param isSelected |
|
252 |
* @param row |
|
253 |
* @param column |
|
254 |
*/ |
|
255 |
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
|
256 |
editorComponent = (JComponent) value; |
|
257 |
container = table; |
|
258 |
return editorComponent; |
|
259 |
} |
|
260 |
} |
|
261 |
// End of class JComponentCellEditor |
|
0 | 262 |
org.gvsig.catalog/trunk/org.gvsig.catalog/org.gvsig.catalog.lib/src/main/java/org/gvsig/catalog/utils/xmltreetable/XMLTreeTableCellRenderer.java | ||
---|---|---|
1 |
|
|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
3 |
* |
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
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 2 |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
* |
|
20 |
* For more information, contact: |
|
21 |
* |
|
22 |
* Generalitat Valenciana |
|
23 |
* Conselleria d'Infraestructures i Transport |
|
24 |
* Av. Blasco Ib??ez, 50 |
|
25 |
* 46010 VALENCIA |
|
26 |
* SPAIN |
|
27 |
* |
|
28 |
* +34 963862235 |
|
29 |
* gvsig@gva.es |
|
30 |
* www.gvsig.gva.es |
|
31 |
* |
|
32 |
* or |
|
33 |
* |
|
34 |
* IVER T.I. S.A |
|
35 |
* Salamanca 50 |
|
36 |
* 46005 Valencia |
|
37 |
* Spain |
|
38 |
* |
|
39 |
* +34 963163400 |
|
40 |
* dac@iver.es |
|
41 |
*/ |
|
42 |
package org.gvsig.catalog.utils.xmltreetable; |
|
43 |
import java.awt.Component; |
|
44 |
|
|
45 |
import javax.swing.JComponent; |
|
46 |
import javax.swing.JTable; |
|
47 |
import javax.swing.table.TableCellRenderer; |
|
48 |
|
|
49 |
/** |
|
50 |
* |
|
51 |
* |
|
52 |
* |
|
53 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
|
54 |
*/ |
|
55 |
class XMLTreeTableCellRenderer implements TableCellRenderer { |
|
56 |
/* (non-Javadoc) |
|
57 |
* @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int) |
|
58 |
*/ |
|
59 |
|
|
60 |
/** |
|
61 |
* |
|
62 |
* |
|
63 |
* |
|
64 |
* @return |
|
65 |
* @param table |
|
66 |
* @param value |
|
67 |
* @param isSelected |
|
68 |
* @param hasFocus |
|
69 |
* @param row |
|
70 |
* @param column |
|
71 |
*/ |
|
72 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
|
73 |
// TODO Auto-generated method stub |
|
74 |
return (JComponent) value; |
|
75 |
} |
|
76 |
} |
|
0 | 77 |
org.gvsig.catalog/trunk/org.gvsig.catalog/org.gvsig.catalog.lib/src/main/java/org/gvsig/catalog/utils/Strings.java | ||
---|---|---|
1 |
|
|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
3 |
* |
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
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 2 |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
* |
|
20 |
* For more information, contact: |
|
21 |
* |
|
22 |
* Generalitat Valenciana |
|
23 |
* Conselleria d'Infraestructures i Transport |
|
24 |
* Av. Blasco Ib??ez, 50 |
|
25 |
* 46010 VALENCIA |
|
26 |
* SPAIN |
|
27 |
* |
|
28 |
* +34 963862235 |
|
29 |
* gvsig@gva.es |
|
30 |
* www.gvsig.gva.es |
|
31 |
* |
|
32 |
* or |
|
33 |
* |
|
34 |
* IVER T.I. S.A |
|
35 |
* Salamanca 50 |
|
36 |
* 46005 Valencia |
|
37 |
* Spain |
|
38 |
* |
|
39 |
* +34 963163400 |
|
40 |
* dac@iver.es |
|
41 |
*/ |
|
42 |
package org.gvsig.catalog.utils; |
|
43 |
|
|
44 |
import java.util.TreeMap; |
|
45 |
import java.util.Vector; |
|
46 |
|
|
47 |
/** |
|
48 |
* String Functions |
|
49 |
* |
|
50 |
* |
|
51 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
|
52 |
*/ |
|
53 |
public class Strings { |
|
54 |
|
|
55 |
/** |
|
56 |
* Replace a part of a String |
|
57 |
* |
|
58 |
* |
|
59 |
* @return |
|
60 |
* @param str String to find the pattern |
|
61 |
* @param pattern Pattern to find |
|
62 |
* @param replace String to replace |
|
63 |
*/ |
|
64 |
public static String replace(String str, String pattern, String replace) { |
|
65 |
int s = 0; |
|
66 |
int e = 0; |
|
67 |
StringBuffer result = new StringBuffer(); |
|
68 |
while ((e = str.indexOf(pattern, s)) >= 0) { |
|
69 |
result.append(str.substring(s, e)); |
|
70 |
result.append(replace); |
|
71 |
s = e + pattern.length(); |
|
72 |
} |
|
73 |
result.append(str.substring(s)); |
|
74 |
return result.toString(); |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* Find a pattern into one array |
|
79 |
* |
|
80 |
* |
|
81 |
* @return |
|
82 |
* @param pattern |
|
83 |
* @param array |
|
84 |
*/ |
|
85 |
public static boolean find(String pattern, String[] array) { |
|
86 |
if (array != null) { |
|
87 |
for (int i = 0; i < array.length; i++) |
|
88 |
if (pattern.equals(array[i])) { |
|
89 |
return true; |
|
90 |
} |
|
91 |
} |
|
92 |
return false; |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* This function joins two strings |
|
97 |
* |
|
98 |
* |
|
99 |
* @return |
|
100 |
* @param s1 |
|
101 |
* @param s2 |
|
102 |
*/ |
|
103 |
public static String[] join(String[] s1, String[] s2) { |
|
104 |
if (s1 == null) { |
|
105 |
return s2; |
|
106 |
} |
|
107 |
if (s2 == null) { |
|
108 |
return s1; |
|
109 |
} |
|
110 |
String[] out = new String[s1.length + s2.length]; |
|
111 |
for (int i = 0; i < s1.length; i++) |
|
112 |
out[i] = s1[i]; |
|
113 |
for (int i = 0; i < s2.length; i++) |
|
114 |
out[s1.length + i] = s2[i]; |
|
115 |
return out; |
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* returns a list (comma-separated) in one unique string |
|
120 |
* |
|
121 |
* |
|
122 |
* @return |
|
123 |
* @param input |
|
124 |
*/ |
|
125 |
public static String getComaSeparated(String[] input) { |
|
126 |
return getXSeparated("," , input); |
|
127 |
} |
|
128 |
|
|
129 |
/** |
|
130 |
* returns a list (blanck-separated) in one unique string |
|
131 |
* |
|
132 |
* |
|
133 |
* @return |
|
134 |
* @param input |
|
135 |
*/ |
|
136 |
public static String getBlankSeparated(String[] input) { |
|
137 |
return getXSeparated(" " , input); |
|
138 |
} |
|
139 |
|
|
140 |
/** |
|
141 |
* returns a list (X-Character-separated) in one unique string |
|
142 |
* |
|
143 |
* |
|
144 |
* @return |
|
145 |
* @param X |
|
146 |
* @param input |
|
147 |
*/ |
|
148 |
private static String getXSeparated(String X, String[] input) { |
|
149 |
String output = ""; |
|
150 |
if (input.length == 0) { |
|
151 |
return ""; |
|
152 |
} |
|
153 |
output = input[0]; |
|
154 |
for (int i = 1; i < input.length; i++) |
|
155 |
output = output + X + input[i]; |
|
156 |
return output; |
|
157 |
} |
|
158 |
|
|
159 |
/** |
|
160 |
* This method creates an String of words (blanck separated) |
|
161 |
* enveloped by asteriscs: Example |
|
162 |
* "This is an example" returns |
|
163 |
* "*This* *is* *an* *example*" |
|
164 |
* |
|
165 |
* |
|
166 |
* @return String |
|
167 |
* @param array Input String |
|
168 |
*/ |
|
169 |
public static String addAsteriscsFromAnArray(String array) { |
|
170 |
String[] s = array.split(" "); |
|
171 |
String output = ""; |
|
172 |
for (int i=0 ; i<s.length ; i++){ |
|
173 |
output = output + " *" + s[i] + "*"; |
|
174 |
} |
|
175 |
return output; |
|
176 |
} |
|
177 |
|
|
178 |
/** |
|
179 |
* This function is used to try if a string is a number. |
|
180 |
* |
|
181 |
* |
|
182 |
* @return The numbers of the String |
|
183 |
* @param str Input String |
|
184 |
* @param charNumber Number of chars that must be tried |
|
185 |
*/ |
|
186 |
public static String tryIfIsNumber(String str, int charNumber) { |
|
187 |
char[] source = str.toCharArray(); |
|
188 |
if (source.length < charNumber) |
|
189 |
charNumber = source.length; |
|
190 |
char[] resultado = new char[charNumber]; |
|
191 |
int j = 0; |
|
192 |
for (int i = 0; i < resultado.length; i++) |
|
193 |
if (i < (source.length) && (source[i] >= '0') && (source[i] <= '9')) |
|
194 |
resultado[j++] = source[i]; |
|
195 |
return new String(resultado,0,j); |
|
196 |
} |
|
197 |
|
|
198 |
/** |
|
199 |
* This method remove all the string accents |
|
200 |
* @param str |
|
201 |
* Input String |
|
202 |
* @return |
|
203 |
* String withOut accents |
|
204 |
*/ |
|
205 |
public static String removeAccents(String str){ |
|
206 |
str = str.replace ('?','a'); |
|
207 |
str = str.replace ('?','e'); |
|
208 |
str = str.replace ('?','i'); |
|
209 |
str = str.replace ('?','o'); |
|
210 |
str = str.replace ('?','u'); |
|
211 |
str = str.replace ('?','A'); |
|
212 |
str = str.replace ('?','E'); |
|
213 |
str = str.replace ('?','I'); |
|
214 |
str = str.replace ('?','O'); |
|
215 |
str = str.replace ('?','a'); |
|
216 |
str = str.replace ('?','e'); |
|
217 |
str = str.replace ('?','i'); |
|
218 |
str = str.replace ('?','o'); |
|
219 |
str = str.replace ('?','u'); |
|
220 |
str = str.replace ('?','A'); |
|
221 |
str = str.replace ('?','E'); |
|
222 |
str = str.replace ('?','I'); |
|
223 |
str = str.replace ('?','O'); |
|
224 |
str = str.replace ('?','U'); |
|
225 |
str = str.replace ('?','a'); |
|
226 |
str = str.replace ('?','e'); |
|
227 |
str = str.replace ('?','i'); |
|
228 |
str = str.replace ('?','o'); |
|
229 |
str = str.replace ('?','u'); |
|
230 |
str = str.replace ('?','A'); |
|
231 |
str = str.replace ('?','E'); |
|
232 |
str = str.replace ('?','I'); |
|
233 |
str = str.replace ('?','O'); |
Also available in: Unified diff