01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2005-2006, Geotools Project Managment Committee (PMC)
05: * (C) 2005, Institut de Recherche pour le Développement
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: */
17: package org.geotools.gui.swing.referencing;
18:
19: // OpenGIS dependencies
20: import org.opengis.referencing.AuthorityFactory;
21: import org.opengis.referencing.FactoryException;
22:
23: /**
24: * An element in a {@link CodeList}. This element stores the {@linkplain #code code value}.
25: * The description name will be fetched when first needed and returned by {@link #toString}.
26: *
27: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/widgets-swing/src/main/java/org/geotools/gui/swing/referencing/Code.java $
28: * @version $Id: Code.java 20883 2006-08-07 13:48:09Z jgarnett $
29: * @author Martin Desruisseaux
30: */
31: final class Code {
32: /**
33: * The sequential index.
34: */
35: final int index;
36:
37: /**
38: * The authority code.
39: */
40: public final String code;
41:
42: /**
43: * The CRS object description for the {@linkplain #code}.
44: * Will be extracted only when first needed.
45: */
46: private String name;
47:
48: /**
49: * The authority factory to use for fetching the name. Will be set to {@code null} after
50: * {@linkplain #name} has been made available, in order to allow the garbage collector
51: * to do its work if possible.
52: */
53: private AuthorityFactory factory;
54:
55: /**
56: * Creates a code from the specified value.
57: *
58: * @param factory The authority factory.
59: * @param code The authority code.
60: */
61: public Code(final AuthorityFactory factory, final String code,
62: final int index) {
63: this .factory = factory;
64: this .code = code;
65: this .index = index;
66: }
67:
68: /**
69: * Returns the name for this code.
70: *
71: * @todo Maybe we should use the widget Locale when invoking InternationalString.toString(...).
72: */
73: public String toString() {
74: if (name == null)
75: try {
76: name = factory.getDescriptionText(code).toString();
77: } catch (FactoryException e) {
78: name = code + " - " + e.getLocalizedMessage();
79: }
80: factory = null;
81: return name;
82: }
83: }
|