Revision 38338
tags/v2_0_0_Build_2047/libraries/libFMap_controls/libFMap_controls/src-test/org/gvsig/fmap/mapcontrol/tools/AreaListenerTest.java | ||
---|---|---|
1 |
package org.gvsig.fmap.mapcontrol.tools; |
|
2 |
|
|
3 |
import java.awt.geom.Point2D; |
|
4 |
|
|
5 |
import org.cresques.cts.IProjection; |
|
6 |
import org.gvsig.fmap.crs.CRSFactory; |
|
7 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
8 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
9 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
10 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
11 |
|
|
12 |
|
|
13 |
public class AreaListenerTest extends AbstractLibraryAutoInitTestCase { |
|
14 |
private IProjection projectionUTM = CRSFactory.getCRS("EPSG:23030"); |
|
15 |
private IProjection projectionGeo = CRSFactory.getCRS("EPSG:4230"); |
|
16 |
|
|
17 |
@Override |
|
18 |
protected void doSetUp() throws Exception { |
|
19 |
// Nothing to do |
|
20 |
} |
|
21 |
|
|
22 |
public void test1() { |
|
23 |
AreaListenerImpl areaListenerUTM=new AreaListenerImpl(newMapControlUTM()); |
|
24 |
AreaListenerImpl areaListenerGeo=new AreaListenerImpl(newMapControlGeo()); |
|
25 |
Double[] xsUTM=new Double[] {new Double(731292),new Double(731901),new Double(730138)}; |
|
26 |
Double[] ysUTM=new Double[] {new Double(4351223),new Double(4350768),new Double(4349232)}; |
|
27 |
double areaUTM=areaListenerUTM.returnCoordsArea(xsUTM,ysUTM,new Point2D.Double(730138,4349232)); |
|
28 |
Double[] xsGeo=new Double[] {new Double(-0.31888183),new Double(-0.31173131),new Double(-0.33268401)}; |
|
29 |
Double[] ysGeo=new Double[] {new Double(39.27871741),new Double(39.27464327),new Double(39.26117368)}; |
|
30 |
double areaGeo=areaListenerGeo.returnGeoCArea(xsGeo,ysGeo,new Point2D.Double(-0.33268401,39.26117368)); |
|
31 |
assertTrue("Area UTM igual a Geo",areaUTM<(areaGeo+1000)&& areaUTM>(areaGeo-1000)); |
|
32 |
} |
|
33 |
private MapControl newMapControlUTM() { |
|
34 |
ViewPort vp = new ViewPort(projectionUTM); |
|
35 |
MapControl mc=new MapControl(); |
|
36 |
mc.setMapContext(new MapContext(vp)); |
|
37 |
return mc; |
|
38 |
} |
|
39 |
private MapControl newMapControlGeo() { |
|
40 |
ViewPort vp = new ViewPort(projectionGeo); |
|
41 |
MapControl mc=new MapControl(); |
|
42 |
mc.setMapContext(new MapContext(vp)); |
|
43 |
return mc; |
|
44 |
} |
|
45 |
} |
|
0 | 46 |
tags/v2_0_0_Build_2047/libraries/libFMap_controls/libFMap_controls/src/org/gvsig/fmap/mapcontrol/swing/dynobject/DynObjectEditor.java | ||
---|---|---|
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 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 IVER T.I. S.A. {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
*/ |
|
31 |
package org.gvsig.fmap.mapcontrol.swing.dynobject; |
|
32 |
|
|
33 |
import java.awt.BorderLayout; |
|
34 |
import java.awt.Component; |
|
35 |
import java.awt.GridBagConstraints; |
|
36 |
import java.awt.GridBagLayout; |
|
37 |
import java.awt.Insets; |
|
38 |
import java.awt.event.ActionEvent; |
|
39 |
import java.awt.event.ActionListener; |
|
40 |
|
|
41 |
import javax.swing.JButton; |
|
42 |
import javax.swing.JLabel; |
|
43 |
import javax.swing.JPanel; |
|
44 |
|
|
45 |
import org.slf4j.Logger; |
|
46 |
import org.slf4j.LoggerFactory; |
|
47 |
|
|
48 |
import org.gvsig.i18n.Messages; |
|
49 |
import org.gvsig.tools.dynobject.DynObject; |
|
50 |
import org.gvsig.tools.service.ServiceException; |
|
51 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
52 |
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent; |
|
53 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
54 |
|
|
55 |
/** |
|
56 |
* Editor for a store parameters. |
|
57 |
* |
|
58 |
* @author gvSIG Team |
|
59 |
* @version $Id$ |
|
60 |
*/ |
|
61 |
public class DynObjectEditor extends JPanel implements ActionListener { |
|
62 |
|
|
63 |
private static final long serialVersionUID = 23898787077741411L; |
|
64 |
|
|
65 |
private static final Logger LOG = LoggerFactory |
|
66 |
.getLogger(DynObjectEditor.class); |
|
67 |
|
|
68 |
private static final WindowManager WINDOW_MANAGER = |
|
69 |
ToolsSwingLocator.getWindowManager(); |
|
70 |
|
|
71 |
private String title; |
|
72 |
|
|
73 |
private JButton botAcept; |
|
74 |
private JButton botCancel; |
|
75 |
private JButton botRestoreDefaults; |
|
76 |
private JPanel panButtons; |
|
77 |
|
|
78 |
private boolean modal; |
|
79 |
|
|
80 |
private JDynObjectComponent component; |
|
81 |
|
|
82 |
public DynObjectEditor(DynObject parameters) throws ServiceException { |
|
83 |
component = |
|
84 |
ToolsSwingLocator.getDynObjectSwingManager() |
|
85 |
.createJDynObjectComponent(parameters, true); |
|
86 |
this.setLayout(new BorderLayout()); |
|
87 |
this.add(component.asJComponent(), BorderLayout.CENTER); |
|
88 |
this.add(getButtonsPanel(), BorderLayout.SOUTH); |
|
89 |
} |
|
90 |
|
|
91 |
private JPanel getButtonsPanel() { |
|
92 |
if (this.panButtons == null) { |
|
93 |
this.panButtons = new JPanel(); |
|
94 |
this.panButtons.setLayout(new GridBagLayout()); |
|
95 |
GridBagConstraints constr = new GridBagConstraints(); |
|
96 |
constr.anchor = GridBagConstraints.LAST_LINE_END; |
|
97 |
constr.fill = GridBagConstraints.HORIZONTAL; |
|
98 |
constr.weightx = 1; |
|
99 |
constr.weighty = 0; |
|
100 |
this.panButtons.add(new JLabel(), constr); |
|
101 |
|
|
102 |
constr = this.getDefaultParametersConstraints(); |
|
103 |
constr.fill = GridBagConstraints.NONE; |
|
104 |
constr.weightx = 0; |
|
105 |
constr.weighty = 0; |
|
106 |
|
|
107 |
this.panButtons.add(this.getAcceptButton(), constr); |
|
108 |
this.panButtons.add(this.getCancelButton(), constr); |
|
109 |
this.panButtons.add(this.getRestoreDefaults(), constr); |
|
110 |
} |
|
111 |
return this.panButtons; |
|
112 |
} |
|
113 |
|
|
114 |
private GridBagConstraints getDefaultParametersConstraints() { |
|
115 |
GridBagConstraints constr = new GridBagConstraints(); |
|
116 |
constr.insets = new Insets(2, 2, 2, 2); |
|
117 |
constr.ipadx = 2; |
|
118 |
constr.ipady = 2; |
|
119 |
constr.anchor = GridBagConstraints.PAGE_START; |
|
120 |
return constr; |
|
121 |
|
|
122 |
} |
|
123 |
|
|
124 |
private JButton getRestoreDefaults() { |
|
125 |
if (this.botRestoreDefaults == null) { |
|
126 |
this.botRestoreDefaults = |
|
127 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton( |
|
128 |
Messages.getText("restoreDefaults")); |
|
129 |
this.botRestoreDefaults.addActionListener(this); |
|
130 |
} |
|
131 |
return this.botRestoreDefaults; |
|
132 |
} |
|
133 |
|
|
134 |
private JButton getCancelButton() { |
|
135 |
if (this.botCancel == null) { |
|
136 |
this.botCancel = |
|
137 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton( |
|
138 |
Messages.getText("cancel")); |
|
139 |
this.botCancel.addActionListener(this); |
|
140 |
} |
|
141 |
return this.botCancel; |
|
142 |
} |
|
143 |
|
|
144 |
private JButton getAcceptButton() { |
|
145 |
if (this.botAcept == null) { |
|
146 |
this.botAcept = |
|
147 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton( |
|
148 |
Messages.getText("accept")); |
|
149 |
this.botAcept.addActionListener(this); |
|
150 |
} |
|
151 |
return this.botAcept; |
|
152 |
} |
|
153 |
|
|
154 |
public void actionPerformed(ActionEvent e) { |
|
155 |
Component source = (Component) e.getSource(); |
|
156 |
if (source == this.botAcept) { |
|
157 |
this.component.saveStatus(); |
|
158 |
this.closeWindow(); |
|
159 |
|
|
160 |
} else |
|
161 |
if (source == this.botCancel) { |
|
162 |
// TODO Close windows |
|
163 |
this.closeWindow(); |
|
164 |
} else |
|
165 |
if (source == this.botRestoreDefaults) { |
|
166 |
// TODO: implement |
|
167 |
// this.component.restore(); |
|
168 |
|
|
169 |
} |
|
170 |
} |
|
171 |
|
|
172 |
protected void closeWindow() { |
|
173 |
LOG.debug("Closing window, values edited: ", component.getDynObject()); |
|
174 |
this.setVisible(false); |
|
175 |
} |
|
176 |
|
|
177 |
public void editObject(boolean modal) { |
|
178 |
this.modal = modal; |
|
179 |
|
|
180 |
WINDOW_MANAGER.showWindow(this, |
|
181 |
Messages.getText("explorer_parameters"), |
|
182 |
WindowManager.MODE.DIALOG); |
|
183 |
} |
|
184 |
|
|
185 |
public String getTitle() { |
|
186 |
return title; |
|
187 |
} |
|
188 |
|
|
189 |
public void setTitle(String title) { |
|
190 |
this.title = title; |
|
191 |
} |
|
192 |
|
|
193 |
public DynObject getParameters() { |
|
194 |
return component.getDynObject(); |
|
195 |
} |
|
196 |
} |
|
0 | 197 |
tags/v2_0_0_Build_2047/libraries/libFMap_controls/libFMap_controls/src/org/gvsig/fmap/mapcontrol/swing/dynobject/LayersDynObjectSetComponent.java | ||
---|---|---|
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; |
|
23 |
|
|
24 |
import org.gvsig.tools.dispose.Disposable; |
|
25 |
import org.gvsig.tools.swing.api.Component; |
|
26 |
|
|
27 |
/** |
|
28 |
* Interface for components to show information of a list of layers. |
|
29 |
* |
|
30 |
* @author gvSIG Team |
|
31 |
* @version $Id$ |
|
32 |
*/ |
|
33 |
public interface LayersDynObjectSetComponent extends Component, Disposable { |
|
34 |
|
|
35 |
|
|
36 |
} |
tags/v2_0_0_Build_2047/libraries/libFMap_controls/libFMap_controls/src/org/gvsig/fmap/mapcontrol/swing/dynobject/impl/DefaultLayersDynObjectSetComponent.java | ||
---|---|---|
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 |
} |
tags/v2_0_0_Build_2047/libraries/libFMap_controls/libFMap_controls/src/org/gvsig/fmap/mapcontrol/swing/dynobject/impl/LayersDynObjectSetComponentModel.java | ||
---|---|---|
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.util.Iterator; |
|
25 |
import java.util.Map; |
|
26 |
import java.util.Set; |
|
27 |
|
|
28 |
import javax.swing.AbstractListModel; |
|
29 |
|
|
30 |
import org.gvsig.fmap.mapcontrol.swing.dynobject.LayersDynObjectSetComponent; |
|
31 |
import org.gvsig.tools.dispose.Disposable; |
|
32 |
import org.gvsig.tools.dynobject.DynObjectSet; |
|
33 |
|
|
34 |
/** |
|
35 |
* Model for a {@link LayersDynObjectSetComponent}. |
|
36 |
* |
|
37 |
* @author gvSIG Team |
|
38 |
* @version $Id$ |
|
39 |
*/ |
|
40 |
public class LayersDynObjectSetComponentModel extends AbstractListModel |
|
41 |
implements Disposable { |
|
42 |
|
|
43 |
private static final long serialVersionUID = -7978388308830573063L; |
|
44 |
|
|
45 |
private final Map<String, DynObjectSet> layerName2InfoByPoint; |
|
46 |
private final String[] layerNames; |
|
47 |
|
|
48 |
public LayersDynObjectSetComponentModel( |
|
49 |
Map<String, DynObjectSet> layerName2InfoByPoint) { |
|
50 |
this.layerName2InfoByPoint = layerName2InfoByPoint; |
|
51 |
Set<String> keyset = layerName2InfoByPoint.keySet(); |
|
52 |
layerNames = keyset.toArray(new String[keyset.size()]); |
|
53 |
} |
|
54 |
|
|
55 |
public String[] getLayerNames() { |
|
56 |
Set<String> keyset = layerName2InfoByPoint.keySet(); |
|
57 |
return keyset.toArray(new String[keyset.size()]); |
|
58 |
} |
|
59 |
|
|
60 |
public DynObjectSet getLayerInfoByPoint(String layerName) { |
|
61 |
return layerName2InfoByPoint.get(layerName); |
|
62 |
} |
|
63 |
|
|
64 |
public int getSize() { |
|
65 |
return layerName2InfoByPoint.size(); |
|
66 |
} |
|
67 |
|
|
68 |
public Object getElementAt(int index) { |
|
69 |
return layerNames[index]; |
|
70 |
} |
|
71 |
|
|
72 |
public void dispose() { |
|
73 |
for (Iterator<DynObjectSet> iterator = |
|
74 |
layerName2InfoByPoint.values().iterator(); iterator.hasNext();) { |
|
75 |
iterator.next().dispose(); |
|
76 |
} |
|
77 |
layerName2InfoByPoint.clear(); |
|
78 |
} |
|
79 |
} |
tags/v2_0_0_Build_2047/libraries/libFMap_controls/libFMap_controls/src/org/gvsig/fmap/mapcontrol/swing/dynobject/DynObjectViewer.java | ||
---|---|---|
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 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 IVER T.I. S.A. {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.mapcontrol.swing.dynobject; |
|
29 |
|
|
30 |
import java.awt.Color; |
|
31 |
import java.awt.GridBagConstraints; |
|
32 |
import java.awt.GridBagLayout; |
|
33 |
|
|
34 |
import javax.swing.JLabel; |
|
35 |
import javax.swing.JPanel; |
|
36 |
import javax.swing.JTextField; |
|
37 |
|
|
38 |
import org.cresques.cts.IProjection; |
|
39 |
|
|
40 |
import org.gvsig.i18n.Messages; |
|
41 |
import org.gvsig.tools.dynobject.DynClass; |
|
42 |
import org.gvsig.tools.dynobject.DynField; |
|
43 |
import org.gvsig.tools.dynobject.DynObject; |
|
44 |
|
|
45 |
|
|
46 |
public class DynObjectViewer extends JPanel { |
|
47 |
|
|
48 |
/** |
|
49 |
* |
|
50 |
*/ |
|
51 |
private static final long serialVersionUID = -5277036770491043233L; |
|
52 |
private GridBagConstraints paramsListLabelConstraint; |
|
53 |
private GridBagConstraints paramsListValueConstraint; |
|
54 |
private GridBagConstraints paramsListFillConstraint; |
|
55 |
|
|
56 |
public DynObjectViewer() { |
|
57 |
super(); |
|
58 |
this.intialize(); |
|
59 |
} |
|
60 |
|
|
61 |
private void intialize() { |
|
62 |
this.setLayout(new GridBagLayout()); |
|
63 |
|
|
64 |
paramsListLabelConstraint = new GridBagConstraints(); |
|
65 |
paramsListValueConstraint = new GridBagConstraints(); |
|
66 |
paramsListFillConstraint = new GridBagConstraints(); |
|
67 |
|
|
68 |
paramsListLabelConstraint.ipadx = 3; |
|
69 |
paramsListLabelConstraint.ipady = 3; |
|
70 |
paramsListLabelConstraint.anchor = GridBagConstraints.FIRST_LINE_START; |
|
71 |
paramsListLabelConstraint.gridwidth = GridBagConstraints.RELATIVE; |
|
72 |
paramsListLabelConstraint.fill = GridBagConstraints.HORIZONTAL; |
|
73 |
paramsListLabelConstraint.weightx = 0.5; |
|
74 |
|
|
75 |
paramsListValueConstraint.ipadx = 3; |
|
76 |
paramsListValueConstraint.ipady = 3; |
|
77 |
paramsListValueConstraint.anchor = GridBagConstraints.FIRST_LINE_END; |
|
78 |
paramsListValueConstraint.gridwidth = GridBagConstraints.REMAINDER; |
|
79 |
paramsListValueConstraint.fill = GridBagConstraints.HORIZONTAL; |
|
80 |
paramsListValueConstraint.weightx = 0.5; |
|
81 |
|
|
82 |
paramsListFillConstraint.ipadx = 3; |
|
83 |
paramsListFillConstraint.ipady = 3; |
|
84 |
paramsListFillConstraint.anchor = GridBagConstraints.FIRST_LINE_END; |
|
85 |
paramsListFillConstraint.gridwidth = GridBagConstraints.REMAINDER; |
|
86 |
paramsListFillConstraint.fill = GridBagConstraints.BOTH; |
|
87 |
paramsListFillConstraint.weightx = 1; |
|
88 |
paramsListFillConstraint.weighty = 1; |
|
89 |
} |
|
90 |
|
|
91 |
private String getLocalizedText(String txt) { |
|
92 |
try { |
|
93 |
return Messages.getText(txt); |
|
94 |
} catch (Exception e) { |
|
95 |
return txt; |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
public void load(DynObject dynObj) { |
|
100 |
this.removeAll(); |
|
101 |
|
|
102 |
if (dynObj == null) { |
|
103 |
this.doLayout(); |
|
104 |
return; |
|
105 |
} |
|
106 |
DynClass dynClass = dynObj.getDynClass(); |
|
107 |
|
|
108 |
JTextField label; |
|
109 |
JTextField text; |
|
110 |
Object value; |
|
111 |
String strValue; |
|
112 |
|
|
113 |
// label = new JLabel(); |
|
114 |
// label.setText(getLocalizedText("parameter")); |
|
115 |
// label.setBackground(Color.LIGHT_GRAY); |
|
116 |
// this.add(label, paramsListLabelConstraint); |
|
117 |
|
|
118 |
text = new JTextField(); |
|
119 |
text.setText(getLocalizedText("parameter")); |
|
120 |
text.setEditable(false); |
|
121 |
text.setBackground(Color.LIGHT_GRAY); |
|
122 |
this.add(text, paramsListLabelConstraint); |
|
123 |
|
|
124 |
text = new JTextField(); |
|
125 |
text.setText(getLocalizedText("value")); |
|
126 |
text.setEditable(false); |
|
127 |
text.setBackground(Color.LIGHT_GRAY); |
|
128 |
this.add(text, paramsListValueConstraint); |
|
129 |
|
|
130 |
for (DynField field : dynClass.getDynFields()) { |
|
131 |
label = new JTextField(); |
|
132 |
label.setText(field.getDescription()); |
|
133 |
label.setEditable(false); |
|
134 |
this.add(label, paramsListLabelConstraint); |
|
135 |
|
|
136 |
strValue = ""; |
|
137 |
value = dynObj.getDynValue(field.getName()); |
|
138 |
if (value != null) { |
|
139 |
if (value instanceof String) { |
|
140 |
strValue = (String) value; |
|
141 |
} else if (value instanceof IProjection) { |
|
142 |
strValue = ((IProjection) value).getAbrev(); |
|
143 |
} else { |
|
144 |
strValue = value.toString(); |
|
145 |
} |
|
146 |
|
|
147 |
} |
|
148 |
text = new JTextField(); |
|
149 |
text.setText(strValue); |
|
150 |
text.setEditable(false); |
|
151 |
this.add(text, paramsListValueConstraint); |
|
152 |
} |
|
153 |
|
|
154 |
this.add(new JLabel(), paramsListFillConstraint); |
|
155 |
|
|
156 |
this.doLayout(); |
|
157 |
this.repaint(); |
|
158 |
|
|
159 |
} |
|
160 |
} |
|
0 | 161 |
tags/v2_0_0_Build_2047/libraries/libFMap_controls/libFMap_controls/src/org/gvsig/fmap/mapcontrol/MapControlManager.java | ||
---|---|---|
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 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {Iver T.I.} {Task} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.mapcontrol; |
|
29 |
|
|
30 |
import java.util.Map; |
|
31 |
import java.util.prefs.Preferences; |
|
32 |
|
|
33 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
34 |
import org.gvsig.fmap.mapcontrol.swing.dynobject.LayersDynObjectSetComponent; |
|
35 |
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapper; |
|
36 |
import org.gvsig.tools.dynobject.DynObject; |
|
37 |
import org.gvsig.tools.dynobject.DynObjectSet; |
|
38 |
|
|
39 |
/** |
|
40 |
* <p> |
|
41 |
* This class is the manager of the MapControl library. It is used to |
|
42 |
* manage all the properties related with the drawing of objects |
|
43 |
* in a map, including default symbols used to draw objects |
|
44 |
* in a map, the tolerance used by the selection or edition tools... |
|
45 |
* </p> |
|
46 |
* <p> |
|
47 |
* It also holds the implementations of the {@link MapControlDrawer}'s, |
|
48 |
* that is the responsible to draw graphical objects in a map. |
|
49 |
* </p> |
|
50 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
51 |
*/ |
|
52 |
public interface MapControlManager { |
|
53 |
|
|
54 |
public MapControl createJMapControlPanel() throws MapControlCreationException; |
|
55 |
|
|
56 |
/** |
|
57 |
* Register a <code>MapControlDrawer</code> by name. |
|
58 |
* @param name |
|
59 |
* Name of the <code>MapControlDrawer</code>. |
|
60 |
* @param mapControolDrawerClass |
|
61 |
* Class used to draw graphical objects on a map. |
|
62 |
*/ |
|
63 |
public void registerMapControlDrawer(String name, Class mapControolDrawerClass); |
|
64 |
|
|
65 |
/** |
|
66 |
* Creates a <code>MapControlDrawer</code> from a name. |
|
67 |
* @param name |
|
68 |
* Name of the <code>MapControlDrawer</code>. |
|
69 |
* @return |
|
70 |
* A <code>MapControlDrawer</code>. |
|
71 |
* @throws MapControlCreationException |
|
72 |
*/ |
|
73 |
public MapControlDrawer createMapControlDrawer(String name) throws MapControlCreationException; |
|
74 |
|
|
75 |
/** |
|
76 |
* It registers the default implementation for the <code>MapControlDrawer</code>. |
|
77 |
* @param mapControlDrawerClass |
|
78 |
* A <code>MapControlDrawer</code>. |
|
79 |
*/ |
|
80 |
public void registerDefaultMapControlDrawer(Class mapControlDrawerClass); |
|
81 |
|
|
82 |
/** |
|
83 |
* It returns the default implementation for the <code>MapControlDrawer</code>. |
|
84 |
* @return |
|
85 |
* The default <code>MapControlDrawer</code>. |
|
86 |
* @throws MapControlCreationException |
|
87 |
*/ |
|
88 |
public MapControlDrawer createDefaultMapControlDrawer() throws MapControlCreationException; |
|
89 |
|
|
90 |
/** |
|
91 |
* Returns a snapper in a concrete position; |
|
92 |
* @param index |
|
93 |
* Snapper position. |
|
94 |
* @return |
|
95 |
* A snapper. |
|
96 |
*/ |
|
97 |
public ISnapper getSnapperAt(int index); |
|
98 |
|
|
99 |
/** |
|
100 |
* Returns the number of registered snappers. |
|
101 |
* @return |
|
102 |
* The number of registered snappers. |
|
103 |
*/ |
|
104 |
public int getSnapperCount(); |
|
105 |
|
|
106 |
/** |
|
107 |
* Add a snapper. |
|
108 |
* @param snapper |
|
109 |
*/ |
|
110 |
public void registerSnapper(String name, Class snapperClass); |
|
111 |
|
|
112 |
|
|
113 |
public Preferences getEditionPreferences(); |
|
114 |
|
|
115 |
/** |
|
116 |
* Tolerance (in pixels) that has to be used by the tools |
|
117 |
* that use snapping. |
|
118 |
* @return |
|
119 |
* The distance in pixels. |
|
120 |
*/ |
|
121 |
public int getTolerance(); |
|
122 |
|
|
123 |
/** |
|
124 |
* Sets the tolerance (in pixels) that has to be used by the |
|
125 |
* tools that use snapping. |
|
126 |
* @param tolerance |
|
127 |
* The tolerance to apply |
|
128 |
*/ |
|
129 |
public void setTolerance(int tolerance); |
|
130 |
|
|
131 |
/** |
|
132 |
* Sets the symbol that has to be used to draw a geometry when |
|
133 |
* it is selected. |
|
134 |
* @param selectionSymbol |
|
135 |
* The symbol to apply. |
|
136 |
* @deprecated the symbol for edition is the selection symbol |
|
137 |
*/ |
|
138 |
public void setSelectionSymbol(ISymbol selectionSymbol); |
|
139 |
|
|
140 |
/** |
|
141 |
* Gets the symbol used to draw the selected geometries. |
|
142 |
* @return |
|
143 |
* The symbol used to draw the selected geometries. |
|
144 |
* @deprecated the symbol for edition is the selection symbol |
|
145 |
*/ |
|
146 |
public ISymbol getSelectionSymbol(); |
|
147 |
|
|
148 |
/** |
|
149 |
* Sets the symbol that has to be used to draw a geometry that |
|
150 |
* represent the axis of a geometry. |
|
151 |
* @param axisReferencesSymbol |
|
152 |
* The symbol to apply. |
|
153 |
*/ |
|
154 |
public void setAxisReferenceSymbol(ISymbol axisReferencesSymbol); |
|
155 |
|
|
156 |
/** |
|
157 |
* Gets the symbol used to draw the axis of a geometry. |
|
158 |
* @return |
|
159 |
* The symbol used to draw the axis of a geometry. |
|
160 |
*/ |
|
161 |
public ISymbol getAxisReferenceSymbol(); |
|
162 |
|
|
163 |
/** |
|
164 |
* Sets the symbol that has to be used to draw a geometry when |
|
165 |
* it is selected. |
|
166 |
* @param geometrySelectionSymbol |
|
167 |
* The symbol to apply. |
|
168 |
*/ |
|
169 |
public void setGeometrySelectionSymbol(ISymbol geometrySelectionSymbol); |
|
170 |
|
|
171 |
/** |
|
172 |
* Gets the symbol used to draw the selected geometries. |
|
173 |
* @return |
|
174 |
* The symbol used to draw the selected geometries. |
|
175 |
*/ |
|
176 |
public ISymbol getGeometrySelectionSymbol(); |
|
177 |
|
|
178 |
/** |
|
179 |
* Sets the symbol that has to be used to draw the handlers. |
|
180 |
* @param handlerSymbol |
|
181 |
* The symbol to apply. |
|
182 |
*/ |
|
183 |
public void setHandlerSymbol(ISymbol handlerSymbol); |
|
184 |
|
|
185 |
/** |
|
186 |
* Gets the symbol used to draw the handlers. |
|
187 |
* @return |
|
188 |
* The symbol used to draw the handlers. |
|
189 |
*/ |
|
190 |
public ISymbol getHandlerSymbol(); |
|
191 |
|
|
192 |
/** |
|
193 |
* Creates a readonly component to view information of a set of layers. The |
|
194 |
* information must be provided as a set of {@link DynObject}s, through a |
|
195 |
* {@link DynObjectSet}. |
|
196 |
* |
|
197 |
* @param layerName2InfoByPoint |
|
198 |
* the map of {@link DynObjectSet} for each layer. |
|
199 |
* @return the component to view the information |
|
200 |
*/ |
|
201 |
public LayersDynObjectSetComponent createLayersDynObjectSetComponent( |
|
202 |
Map<String, DynObjectSet> layerName2InfoByPoint); |
|
203 |
|
|
204 |
/** |
|
205 |
* Creates a component to view information of a set of layers. The |
|
206 |
* information must be provided as a set of {@link DynObject}s, through a |
|
207 |
* {@link DynObjectSet}. |
|
208 |
* |
|
209 |
* @param layerName2InfoByPoint |
|
210 |
* the map of {@link DynObjectSet} for each layer. |
|
211 |
* @param writable |
|
212 |
* if the DynObjects loaded must be able to be edited |
|
213 |
* @return the component to view the information |
|
214 |
*/ |
|
215 |
public LayersDynObjectSetComponent createLayersDynObjectSetComponent( |
|
216 |
Map<String, DynObjectSet> layerName2InfoByPoint, boolean writable); |
|
217 |
} |
|
218 |
|
|
0 | 219 |
tags/v2_0_0_Build_2047/libraries/libFMap_controls/libFMap_controls/src/org/gvsig/fmap/mapcontrol/MapControlException.java | ||
---|---|---|
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 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {Iver T.I.} {Task} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.mapcontrol; |
|
29 |
|
|
30 |
import org.gvsig.tools.exception.BaseException; |
|
31 |
|
|
32 |
/** |
|
33 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
34 |
*/ |
|
35 |
public class MapControlException extends BaseException { |
|
36 |
private static final long serialVersionUID = 981894833703125550L; |
|
37 |
|
|
38 |
/** |
|
39 |
* @see BaseException#BaseException(String, String, long) |
|
40 |
*/ |
|
41 |
public MapControlException(String message, String key, long code) { |
|
42 |
super(message, key, code); |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* @see BaseException#BaseException(String, Throwable, String, long) |
|
47 |
*/ |
|
48 |
public MapControlException(String message, Throwable cause, String key, |
|
49 |
long code) { |
|
50 |
super(message, cause, key, code); |
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
|
|
0 | 55 |
tags/v2_0_0_Build_2047/libraries/libFMap_controls/libFMap_controls/src/org/gvsig/fmap/mapcontrol/MapControl.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.fmap.mapcontrol; |
|
42 |
|
|
43 |
import java.awt.Color; |
|
44 |
import java.awt.Cursor; |
|
45 |
import java.awt.Dimension; |
|
46 |
import java.awt.Graphics; |
|
47 |
import java.awt.Graphics2D; |
|
48 |
import java.awt.Image; |
|
49 |
import java.awt.Point; |
|
50 |
import java.awt.Toolkit; |
|
51 |
import java.awt.event.ActionEvent; |
|
52 |
import java.awt.event.ActionListener; |
|
53 |
import java.awt.event.ComponentEvent; |
|
54 |
import java.awt.event.ComponentListener; |
|
55 |
import java.awt.event.MouseEvent; |
|
56 |
import java.awt.event.MouseListener; |
|
57 |
import java.awt.event.MouseMotionListener; |
|
58 |
import java.awt.event.MouseWheelEvent; |
|
59 |
import java.awt.event.MouseWheelListener; |
|
60 |
import java.awt.geom.Point2D; |
|
61 |
import java.awt.image.BufferedImage; |
|
62 |
import java.awt.image.MemoryImageSource; |
|
63 |
import java.util.ArrayList; |
|
64 |
import java.util.Comparator; |
|
65 |
import java.util.HashMap; |
|
66 |
import java.util.List; |
|
67 |
import java.util.Set; |
|
68 |
import java.util.TreeMap; |
|
69 |
import java.util.prefs.Preferences; |
|
70 |
|
|
71 |
import javax.swing.JComponent; |
|
72 |
import javax.swing.SwingUtilities; |
|
73 |
import javax.swing.Timer; |
|
74 |
|
|
75 |
import org.cresques.cts.IProjection; |
|
76 |
import org.slf4j.Logger; |
|
77 |
import org.slf4j.LoggerFactory; |
|
78 |
|
|
79 |
import org.gvsig.fmap.crs.CRSFactory; |
|
80 |
import org.gvsig.fmap.dal.DataStoreNotification; |
|
81 |
import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
|
82 |
import org.gvsig.fmap.geom.Geometry; |
|
83 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
84 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
85 |
import org.gvsig.fmap.geom.GeometryManager; |
|
86 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
|
87 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
88 |
import org.gvsig.fmap.geom.util.Converter; |
|
89 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
90 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
91 |
import org.gvsig.fmap.mapcontext.events.AtomicEvent; |
|
92 |
import org.gvsig.fmap.mapcontext.events.listeners.AtomicEventListener; |
|
93 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
94 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent; |
|
95 |
import org.gvsig.fmap.mapcontext.layers.LayerEvent; |
|
96 |
import org.gvsig.fmap.mapcontext.layers.SpatialCache; |
|
97 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
98 |
import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer; |
|
99 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
|
100 |
import org.gvsig.fmap.mapcontrol.tools.CompoundBehavior; |
|
101 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
|
102 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener; |
|
103 |
import org.gvsig.fmap.mapcontrol.tools.grid.Grid; |
|
104 |
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapper; |
|
105 |
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapperGeometriesVectorial; |
|
106 |
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapperRaster; |
|
107 |
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapperVectorial; |
|
108 |
import org.gvsig.tools.observer.Observable; |
|
109 |
import org.gvsig.tools.observer.Observer; |
|
110 |
import org.gvsig.tools.task.Cancellable; |
|
111 |
import org.gvsig.utils.exceptionHandling.ExceptionHandlingSupport; |
|
112 |
import org.gvsig.utils.exceptionHandling.ExceptionListener; |
|
113 |
|
|
114 |
/** |
|
115 |
* <p> |
|
116 |
* A component that includes a {@link MapContext MapContext} with support for |
|
117 |
* use it as a particular {@link Behavior Behavior}. |
|
118 |
* </p> |
|
119 |
* |
|
120 |
* <p> |
|
121 |
* A developer can register a set of <code>Behavior</code>, but only one (that |
|
122 |
* can be a composition of several) of them can be active. The active one |
|
123 |
* defines the way to work and access with its <code>MapContext</code>'s layers. |
|
124 |
* The active behavior, in combination with the appropriate {@link ToolListener |
|
125 |
* ToolListener} will allow user work with a particular <i>tool</i>. |
|
126 |
* </p> |
|
127 |
* |
|
128 |
* <p> |
|
129 |
* All mouse events produced on this component will be delegated to the current |
|
130 |
* active behavior, the <i>currentMapTool</i>. |
|
131 |
* </p> |
|
132 |
* |
|
133 |
* <p> |
|
134 |
* <b>Drawing process:</b> |
|
135 |
* </p> |
|
136 |
* |
|
137 |
* <p> |
|
138 |
* Uses a double buffer for the drawing process of <code>MapContext</code>'s |
|
139 |
* information. |
|
140 |
* </p> |
|
141 |
* |
|
142 |
* <p> |
|
143 |
* If the double buffer wasn't created, creates a new one. |
|
144 |
* </p> |
|
145 |
* |
|
146 |
* <p> |
|
147 |
* Paints the component according the following algorithm: <br> |
|
148 |
*   If <i>status</i> is <i>UPDATED</i>:<br> |
|
149 |
*     If there is a <i>double buffer</i>:<br> |
|
150 |
*       If there is a <i>behavior</i> for managing the |
|
151 |
* <code>MapControl</code> instance, delegates the drawing process to that |
|
152 |
* behavior, calling: <code><i>behavior_instance</i>.paintComponent(g)</code>.<br> |
|
153 |
*       Else, repaints the current graphical information quickly |
|
154 |
* calling: <code>g.drawImage(image,0,0,null)</code>.<br> |
|
155 |
*   Else, (<i>status</i> is <i>OUTDATED</i>, or <i>ONLY_GRAPHICS</i>): |
|
156 |
* executes a quickly repaint of the previous information calling |
|
157 |
* <code>g.drawImage(image,0,0,null)</code>, and creates a <i>painting |
|
158 |
* request</i> to delegate the heavy drawing process to the {@link Drawer2 |
|
159 |
* Drawer2}'s worker thread, according the <i>SingleWorketThread</i> pattern, |
|
160 |
* starting a timer to update (invoking <code>repaint()</code>) the view every |
|
161 |
* delay of <code>1000 / drawFrameRate</code> ms. during that heavy drawing |
|
162 |
* process, and if its enabled <code>drawAnimationEnabled</code>. The |
|
163 |
* <i>painting request</i> once is being attended, invokes |
|
164 |
* <code>MapContext</code> to draw the layers: |
|
165 |
* <code>mapContext.draw(image, g, cancel,mapContext.getScaleView());</code> |
|
166 |
* <br> |
|
167 |
* <p> |
|
168 |
* Some notes: |
|
169 |
* <ul> |
|
170 |
* <li>The painting process can be cancelled calling {@link #cancelDrawing() |
|
171 |
* #cancelDrawing()}.</li> |
|
172 |
* <li>At last resort, the particular implementation of each layer in a |
|
173 |
* <code>MapControl</code>'s <code>MapContrext</code> will be that one which |
|
174 |
* will draw the graphical information, and, if supports, which could cancel its |
|
175 |
* drawing subprocess.</li> |
|
176 |
* <li>It's possible to force repaint all layers, calling |
|
177 |
* {@link #drawMap(boolean doClear) #drawMap(boolean)}.</li> |
|
178 |
* <li>It's possible repaint only the dirty layers, calling |
|
179 |
* {@link #rePaintDirtyLayers() #rePaintDirtyLayers()}.</li> |
|
180 |
* <li>It's possible repaint only the {@link GraphicLayer GraphicLayer}, calling |
|
181 |
* {@link #drawGraphics() #drawGraphics()}.</li> |
|
182 |
* </ul> |
|
183 |
* </p> |
|
184 |
* |
|
185 |
* <p> |
|
186 |
* <b>Tools:</b> |
|
187 |
* </p> |
|
188 |
* |
|
189 |
* <p> |
|
190 |
* A developer can: |
|
191 |
* <ul> |
|
192 |
* <li>Register each tool as: |
|
193 |
* <ul> |
|
194 |
* <li>A single behavior: {@link #addBehavior(String, Behavior) |
|
195 |
* #addMapTool(String, Behavior)}.</li> |
|
196 |
* <li>Or, a compound behavior: {@link #addBehavior(String, Behavior) |
|
197 |
* #addMapTool(String, Behavior)}.</li> |
|
198 |
* </ul> |
|
199 |
* </li> |
|
200 |
* <li>Get the current active tool: {@link #getCurrentMapTool() |
|
201 |
* #getCurrentMapTool()}.</li> |
|
202 |
* <li>Get the current active tool name: {@link #getCurrentTool() |
|
203 |
* #getCurrentTool()}.</li> |
|
204 |
* <li>Get a registered tool: {@link #getMapTool(String) #getMapTool(String)}.</li> |
|
205 |
* <li>Get the name of all tools registered: {@link #getMapToolsKeySet() |
|
206 |
* #getMapToolsKeySet()}.</li> |
|
207 |
* <li>Get all tools registered, including the name they were registered: |
|
208 |
* {@link #getNamesMapTools() #getNamesMapTools()}.</li> |
|
209 |
* <li>Determine if has a tool registered: {@link #hasTool(String) |
|
210 |
* #hasTool(String)}.</li> |
|
211 |
* <li>Set as an active tool, one of the registered: {@link #setTool(String) |
|
212 |
* #setTool(String)}.</li> |
|
213 |
* <li>Set as active tool, the previous used: {@link #setPrevTool() |
|
214 |
* #setPrevTool()}.</li> |
|
215 |
* <li>Set the current tool: {@link #setCurrentMapTool(Behavior) |
|
216 |
* #setCurrentMapTool(Behavior)}.</li> |
|
217 |
* <li>Change the draw frame rate: {@link #setDrawFrameRate(int) |
|
218 |
* #setDrawFrameRate(int)} and {@link #applyFrameRate() #applyFrameRate()}.</li> |
|
219 |
* <li>Get the draw frame rate: {@link #getDrawFrameRate() #getDrawFrameRate()}. |
|
220 |
* </li> |
|
221 |
* <li>Determine if will repaint this component each time timer finishes: |
|
222 |
* {@link #isDrawAnimationEnabled() #isDrawAnimationEnabled()}.</li> |
|
223 |
* <li>Change if will repaint this component each time timer finishes: |
|
224 |
* {@link #setDrawAnimationEnabled(boolean) #setDrawAnimationEnabled(boolean)}.</li> |
|
225 |
* <li>Get the shared object that determines if a drawing process must be |
|
226 |
* cancelled or can continue: {@link #getCanceldraw() #getCanceldraw()}.</li> |
|
227 |
* <li>Get the combined tool: {@link #getCombinedTool() #getCombinedTool()}.</li> |
|
228 |
* <li>Set a combined tool: {@link #setCombinedTool(Behavior) |
|
229 |
* #setCombinedTool(Behavior)}.</li> |
|
230 |
* <li>Remove the combined tool: {@link #removeCombinedTool() |
|
231 |
* #removeCombinedTool()}.</li> |
|
232 |
* </ul> |
|
233 |
* </p> |
|
234 |
* |
|
235 |
* <p> |
|
236 |
* <b>Exception listener:</b> |
|
237 |
* </p> |
|
238 |
* |
|
239 |
* <p> |
|
240 |
* Adding an <code>ExceptionListener</code>, can get notification about any |
|
241 |
* exception produced: |
|
242 |
* <ul> |
|
243 |
* <li>Attending a <i>painting request</i>.</li> |
|
244 |
* <li>Working with the active tool.</li> |
|
245 |
* <li>Applying a <i>zoom in</i> or <i>zoom out</i> operation.</li> |
|
246 |
* </ul> |
|
247 |
* </p> |
|
248 |
* |
|
249 |
* <p> |
|
250 |
* <b>Other:</b> |
|
251 |
* </p> |
|
252 |
* |
|
253 |
* <p> |
|
254 |
* Other useful capabilities of <code>MapControl</code>: |
|
255 |
* <ul> |
|
256 |
* <li>Cancel the current drawing process (notifying it also to the inner |
|
257 |
* <code>MapContext</code> instance and its layers): {@link #cancelDrawing() |
|
258 |
* #cancelDrawing()}.</li> |
|
259 |
* <li>Applying a <i>zoom in</i> operation centered at mouse position (without a |
|
260 |
* <code>ToolListener</code>): {@link #zoomIn() #zoomIn()}.</li> |
|
261 |
* <li>Applying a <i>zoom out</i> operation centered at mouse position (without |
|
262 |
* a <code>ToolListener</code>): {@link #zoomOut() #zoomOut()}.</li> |
|
263 |
* </ul> |
|
264 |
* </p> |
|
265 |
* |
|
266 |
* @see CancelDraw |
|
267 |
* @see Drawer |
|
268 |
* @see MapContextListener |
|
269 |
* @see MapToolListener |
|
270 |
* |
|
271 |
* @author Fernando Gonz?lez Cort?s |
|
272 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
|
273 |
*/ |
|
274 |
public class MapControl extends JComponent implements ComponentListener, |
|
275 |
Observer { |
|
276 |
|
|
277 |
protected static final GeometryManager geomManager = |
|
278 |
GeometryLocator.getGeometryManager(); |
|
279 |
protected static final Logger logger = |
|
280 |
LoggerFactory.getLogger(GeometryManager.class); |
|
281 |
|
|
282 |
/** |
|
283 |
* <p> |
|
284 |
* One of the possible status of <code>MapControl</code>. Determines that |
|
285 |
* all visible information has been drawn and its updated. |
|
286 |
* </p> |
|
287 |
*/ |
|
288 |
public static final int ACTUALIZADO = 0; |
|
289 |
|
|
290 |
/** |
|
291 |
* <p> |
|
292 |
* One of the possible status of <code>MapControl</code>. Determines that |
|
293 |
* not all visible information has been drawn or isn't updated. |
|
294 |
* </p> |
|
295 |
*/ |
|
296 |
public static final int DESACTUALIZADO = 1; |
|
297 |
|
|
298 |
/** |
|
299 |
* <p> |
|
300 |
* Determines if the drawer can update this <code>MapControl</code> instance |
|
301 |
* when the timer launches an event. |
|
302 |
* </p> |
|
303 |
*/ |
|
304 |
private static boolean drawAnimationEnabled = true; |
|
305 |
|
|
306 |
/** |
|
307 |
* <p> |
|
308 |
* Inner model with the layers, event support for drawing them, and the |
|
309 |
* <code>ViewPort</code> with information to adapt to the bounds available |
|
310 |
* in <i>image coordinates</i>. |
|
311 |
* </p> |
|
312 |
* |
|
313 |
* @see #getMapContext() |
|
314 |
* @see #setMapContext(MapContext) |
|
315 |
*/ |
|
316 |
private MapContext mapContext = null; |
|
317 |
|
|
318 |
/** |
|
319 |
* <p> |
|
320 |
* All registered <code>Behavior</code> that can define a way to work with |
|
321 |
* this <code>MapControl</code>. |
|
322 |
* </p> |
|
323 |
* |
|
324 |
* <p> |
|
325 |
* Only one of them can be active at a given moment. |
|
326 |
* </p> |
|
327 |
* |
|
328 |
* @see #addBehavior(String, Behavior) |
|
329 |
* @see #addBehavior(String, Behavior[]) |
|
330 |
* @see #getMapTool(String) |
|
331 |
* @see #getMapToolsKeySet() |
|
332 |
* @see #getNamesMapTools() |
|
333 |
*/ |
|
334 |
protected HashMap namesMapTools = new HashMap(); |
|
335 |
|
|
336 |
/** |
|
337 |
* <p> |
|
338 |
* Active {@link Behavior Behavior} that will generate events according a |
|
339 |
* criterion, and then, with a {@link ToolListener ToolListener} associated, |
|
340 |
* will simulate to user that works with this component as a particular |
|
341 |
* tool. |
|
342 |
* </p> |
|
343 |
* |
|
344 |
* @see #getCurrentMapTool() |
|
345 |
* @see #getCurrentTool() |
|
346 |
* @see #setTool(String) |
|
347 |
*/ |
|
348 |
protected Behavior currentMapTool = null; |
|
349 |
|
|
350 |
/** |
|
351 |
* <p> |
|
352 |
* Determines which's the current drawn status of this component: |
|
353 |
* <ul> |
|
354 |
* <li><b>OUTDATED</b>: all visible information has been drawn or isn't |
|
355 |
* updated.</li> |
|
356 |
* <li><b>UTDATED</b>: all visible information has been drawn and its |
|
357 |
* updated.</li> |
|
358 |
* <li><b>ONLY_GRAPHICS</b>: only the graphical layer must be drawn / |
|
359 |
* updated.</li> |
|
360 |
* </ul> |
|
361 |
* </p> |
|
362 |
* |
|
363 |
* <p> |
|
364 |
* The <code>MapControl</code> drawing process will consider the value of |
|
365 |
* this parameter to decide which elements will be updated or drawn. |
|
366 |
* </p> |
|
367 |
*/ |
|
368 |
private int status = DESACTUALIZADO; |
|
369 |
|
|
370 |
/** |
|
371 |
* <p> |
|
372 |
* Image with a buffer to accelerate the draw the changes of the graphical |
|
373 |
* items in this component. |
|
374 |
* </p> |
|
375 |
* |
|
376 |
* <p> |
|
377 |
* Firstly, information will be drawn in the buffer, and, when is outright |
|
378 |
* drawn, that information will be displayed. Meanwhile, the previous image |
|
379 |
* can be kept showed. |
|
380 |
* </p> |
|
381 |
* |
|
382 |
* @see BufferedImage |
|
383 |
* |
|
384 |
* @see #getImage() |
|
385 |
*/ |
|
386 |
private BufferedImage image = null; |
|
387 |
|
|
388 |
/** |
|
389 |
* <p> |
|
390 |
* Name of the tool used currently to interact with this component. |
|
391 |
* </p> |
|
392 |
* |
|
393 |
* @see #getCurrentTool() |
|
394 |
* @see #setTool(String) |
|
395 |
*/ |
|
396 |
protected String currentTool; |
|
397 |
|
|
398 |
/** |
|
399 |
* <p> |
|
400 |
* Object to store the flag that notifies a drawing thread task and |
|
401 |
* <code>MapContext</code>'s layers, that must be canceled or can continue |
|
402 |
* with the process. |
|
403 |
* </p> |
|
404 |
* |
|
405 |
* @see #cancelDrawing() |
|
406 |
*/ |
|
407 |
private CancelDraw canceldraw; |
|
408 |
|
|
409 |
// private boolean isCancelled = true; |
|
410 |
|
|
411 |
/** |
|
412 |
* <p> |
|
413 |
* Fires an action events after a specified delay. |
|
414 |
* </p> |
|
415 |
* |
|
416 |
* <p> |
|
417 |
* <code>MapControl</code> will use the timer to update its visible |
|
418 |
* graphical information during a drawing process, or allowing to cancel |
|
419 |
* that process. |
|
420 |
* </p> |
|
421 |
* |
|
422 |
* <p> |
|
423 |
* This is very useful to pretend faster interactivity to user when |
|
424 |
* <code>MapControl</code> has lots of layers, and / or layers with heavy |
|
425 |
* graphical elements, that need a long time to finish drawing all its data. |
|
426 |
* </p> |
|
427 |
*/ |
|
428 |
private Timer timer; |
|
429 |
|
|
430 |
/** |
|
431 |
* <p> |
|
432 |
* Reference to the {@link ViewPort ViewPort} of the {@link MapContext |
|
433 |
* MapContext} of this component. |
|
434 |
* </p> |
|
435 |
* |
|
436 |
* <p> |
|
437 |
* The view port once is created an instance of <code>MapControl</code>, is |
|
438 |
* obtained from the <i>EPSG:23030</i> projection, that's the default |
|
439 |
* projection for this component. |
|
440 |
* </p> |
|
441 |
* |
|
442 |
* <p> |
|
443 |
* After, the view port will change adapting itself according the current |
|
444 |
* projection and the extent. |
|
445 |
* </p> |
|
446 |
* |
|
447 |
* @see #getViewPort() |
|
448 |
* |
|
449 |
* @see ViewPort |
|
450 |
*/ |
|
451 |
protected ViewPort vp; |
|
452 |
|
|
453 |
/** |
|
454 |
* <p> |
|
455 |
* Manager of all <code>MapControl</code> painting requests. |
|
456 |
* </p> |
|
457 |
*/ |
|
458 |
private Drawer drawer; |
|
459 |
|
|
460 |
/** |
|
461 |
* <p> |
|
462 |
* Listener of all kind of mouse events produced in this component. |
|
463 |
* </p> |
|
464 |
* |
|
465 |
* <p> |
|
466 |
* Delegates each mouse event to the current map tool. |
|
467 |
* </p> |
|
468 |
* |
|
469 |
* @see #addBehavior(String, Behavior) |
|
470 |
* @see #addBehavior(String, Behavior[]) |
|
471 |
* @see #getMapTool(String) |
|
472 |
* @see #getMapToolsKeySet() |
|
473 |
* @see #getNamesMapTools() |
|
474 |
* @see #setTool(String) |
|
475 |
*/ |
|
476 |
protected MapToolListener mapToolListener = new MapToolListener(); |
|
477 |
|
|
478 |
/** |
|
479 |
* <p> |
|
480 |
* Listener of all events produced in a this component's |
|
481 |
* <code>MapContext</code> object during an atomic period of time. |
|
482 |
* </p> |
|
483 |
*/ |
|
484 |
private MapContextListener mapContextListener = new MapContextListener(); |
|
485 |
|
|
486 |
/** |
|
487 |
* <p> |
|
488 |
* Group of <code>ExceptionListener</code> that, in whatever moment could be |
|
489 |
* notified a Throwable Java error or exception. |
|
490 |
* </p> |
|
491 |
* |
|
492 |
* @see #addExceptionListener(ExceptionListener) |
|
493 |
* @see #removeExceptionListener(ExceptionListener) |
Also available in: Unified diff