root / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / swing / dynobject / impl / DefaultLayersDynObjectSetComponent.java @ 33657
History | View | Annotate | Download (4.51 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.fmap.mapcontrol.swing.dynobject.impl; |
23 |
|
24 |
import java.awt.BorderLayout; |
25 |
import java.util.Map; |
26 |
|
27 |
import javax.swing.JComponent; |
28 |
import javax.swing.JList; |
29 |
import javax.swing.JPanel; |
30 |
import javax.swing.ListSelectionModel; |
31 |
import javax.swing.event.ListSelectionEvent; |
32 |
import javax.swing.event.ListSelectionListener; |
33 |
|
34 |
import org.slf4j.Logger; |
35 |
import org.slf4j.LoggerFactory; |
36 |
|
37 |
import org.gvsig.fmap.mapcontrol.swing.dynobject.LayersDynObjectSetComponent; |
38 |
import org.gvsig.tools.dynobject.DynObjectSet; |
39 |
import org.gvsig.tools.exception.BaseException; |
40 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
41 |
import org.gvsig.tools.swing.api.dynobject.set.JDynObjectSetComponent; |
42 |
|
43 |
/**
|
44 |
* @author gvSIG Team
|
45 |
* @version $Id$
|
46 |
*
|
47 |
*/
|
48 |
public class DefaultLayersDynObjectSetComponent extends JPanel implements |
49 |
LayersDynObjectSetComponent, ListSelectionListener {
|
50 |
|
51 |
private static final long serialVersionUID = 5864674721657215264L; |
52 |
|
53 |
private static final Logger LOG = LoggerFactory |
54 |
.getLogger(DefaultLayersDynObjectSetComponent.class); |
55 |
|
56 |
private final LayersDynObjectSetComponentModel model; |
57 |
|
58 |
private JDynObjectSetComponent component;
|
59 |
|
60 |
private JList layersList; |
61 |
|
62 |
private final boolean writable; |
63 |
|
64 |
/**
|
65 |
* Creates a new {@link DefaultLayersDynObjectSetComponent} with the given
|
66 |
* information for a list of layers.
|
67 |
*/
|
68 |
public DefaultLayersDynObjectSetComponent(
|
69 |
Map<String, DynObjectSet> layerName2InfoByPoint) { |
70 |
this(layerName2InfoByPoint, true); |
71 |
} |
72 |
|
73 |
/**
|
74 |
* @param isDoubleBuffered
|
75 |
*/
|
76 |
public DefaultLayersDynObjectSetComponent(
|
77 |
Map<String, DynObjectSet> layerName2InfoByPoint, |
78 |
boolean writable) {
|
79 |
super(new BorderLayout()); |
80 |
this.writable = writable;
|
81 |
model = new LayersDynObjectSetComponentModel(layerName2InfoByPoint);
|
82 |
initializeUI(); |
83 |
} |
84 |
|
85 |
private void initializeUI() { |
86 |
addLayerList(); |
87 |
} |
88 |
|
89 |
private void addLayerList() { |
90 |
layersList = new JList(model); |
91 |
layersList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
92 |
layersList.setLayoutOrientation(JList.VERTICAL);
|
93 |
// list.setVisibleRowCount(20);
|
94 |
layersList.addListSelectionListener(this);
|
95 |
|
96 |
add(layersList, BorderLayout.WEST);
|
97 |
|
98 |
layersList.setSelectedIndex(0);
|
99 |
} |
100 |
|
101 |
public void valueChanged(ListSelectionEvent e) { |
102 |
if (!e.getValueIsAdjusting()) {
|
103 |
String layerName = (String) layersList.getSelectedValue(); |
104 |
setCurrentLayerInfoByPoint(layerName); |
105 |
} |
106 |
} |
107 |
|
108 |
private void setCurrentLayerInfoByPoint(String layerName) { |
109 |
JDynObjectSetComponent newComponent = null;
|
110 |
|
111 |
DynObjectSet dynObjectSet = model.getLayerInfoByPoint(layerName); |
112 |
try {
|
113 |
newComponent = |
114 |
ToolsSwingLocator.getDynObjectSwingManager() |
115 |
.createJDynObjectSetComponent(dynObjectSet, writable); |
116 |
} catch (BaseException e) {
|
117 |
LOG.error("Error creating the JDynObjectSetComponent for "
|
118 |
+ "the DynObjectSet: " + dynObjectSet, e);
|
119 |
} |
120 |
|
121 |
if (newComponent != null) { |
122 |
removeCurrentDynObjectSetComponent(); |
123 |
component = newComponent; |
124 |
add(component.asJComponent(), BorderLayout.CENTER);
|
125 |
revalidate(); |
126 |
repaint(); |
127 |
} |
128 |
} |
129 |
|
130 |
public JComponent asJComponent() { |
131 |
return this; |
132 |
} |
133 |
|
134 |
public void dispose() { |
135 |
removeCurrentDynObjectSetComponent(); |
136 |
model.dispose(); |
137 |
} |
138 |
|
139 |
private void removeCurrentDynObjectSetComponent() { |
140 |
if (component != null) { |
141 |
remove(component.asJComponent()); |
142 |
component.dispose(); |
143 |
} |
144 |
} |
145 |
|
146 |
} |