Revision 16005
branches/v10/extensions/extCatalogAndGazetteer/src/es/gva/cit/gvsig/gazetteer/gui/ShowResultsDialog.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 es.gva.cit.gvsig.gazetteer.gui; |
|
42 |
|
|
43 |
|
|
44 |
import javax.swing.JDialog; |
|
45 |
|
|
46 |
import org.gvsig.i18n.Messages; |
|
47 |
|
|
48 |
import com.iver.andami.ui.mdiManager.IWindow; |
|
49 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
|
50 |
|
|
51 |
import es.gva.cit.gazetteer.GazetteerClient; |
|
52 |
import es.gva.cit.gazetteer.querys.Feature; |
|
53 |
import es.gva.cit.gazetteer.querys.GazetteerQuery; |
|
54 |
import es.gva.cit.gazetteer.ui.showresults.ShowResultsDialogPanel; |
|
55 |
import es.gva.cit.gvsig.gazetteer.loaders.FeatureLoader; |
|
56 |
|
|
57 |
/** |
|
58 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
|
59 |
*/ |
|
60 |
public class ShowResultsDialog extends ShowResultsDialogPanel implements IWindow { |
|
61 |
private SearchDialog searchDialog = null; |
|
62 |
private JDialog frame = null; |
|
63 |
/** |
|
64 |
* @param client |
|
65 |
* @param features |
|
66 |
* @param recordsByPage |
|
67 |
*/ |
|
68 |
public ShowResultsDialog(JDialog frame,GazetteerClient client, Feature[] features, int recordsByPage, GazetteerQuery query) { |
|
69 |
super(client, features, recordsByPage,query); |
|
70 |
this.frame = frame; |
|
71 |
} |
|
72 |
|
|
73 |
/* (non-Javadoc) |
|
74 |
* @see com.iver.andami.ui.mdiManager.View#getViewInfo() |
|
75 |
*/ |
|
76 |
public WindowInfo getWindowInfo() { |
|
77 |
WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG); |
|
78 |
m_viewinfo.setTitle(Messages.getText( "gazetteer_search")); |
|
79 |
return m_viewinfo; |
|
80 |
} |
|
81 |
|
|
82 |
public void closeButtonActionPerformed() { |
|
83 |
closeJDialog(); |
|
84 |
} |
|
85 |
|
|
86 |
public void closeJDialog() { |
|
87 |
frame.setVisible(false); |
|
88 |
} |
|
89 |
|
|
90 |
/** |
|
91 |
* This method have to load the selected feature into gvSIG |
|
92 |
*/ |
|
93 |
public void loadButtonActionPerformed() { |
|
94 |
Feature feature = ppalPanel.getFeature(); |
|
95 |
if (feature != null){ |
|
96 |
|
|
97 |
new FeatureLoader(client.getProjection()).load(feature,query); |
|
98 |
} |
|
99 |
closeJDialog(); |
|
100 |
//getSearchDialog().closeJDialog(); |
|
101 |
} |
|
102 |
|
|
103 |
/** |
|
104 |
* @return Returns the searchDialog. |
|
105 |
*/ |
|
106 |
public SearchDialog getSearchDialog() { |
|
107 |
return searchDialog; |
|
108 |
} |
|
109 |
/** |
|
110 |
* @param searchDialog The searchDialog to set. |
|
111 |
*/ |
|
112 |
public void setSearchDialog(SearchDialog searchDialog) { |
|
113 |
this.searchDialog = searchDialog; |
|
114 |
} |
|
115 |
} |
|
0 | 116 |
branches/v10/extensions/extCatalogAndGazetteer/src/es/gva/cit/gvsig/gazetteer/gui/SearchDialog.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 es.gva.cit.gvsig.gazetteer.gui; |
|
42 |
|
|
43 |
import java.awt.Frame; |
|
44 |
import java.awt.geom.Rectangle2D; |
|
45 |
|
|
46 |
import javax.swing.JDialog; |
|
47 |
|
|
48 |
import org.gvsig.i18n.Messages; |
|
49 |
|
|
50 |
import com.iver.andami.PluginServices; |
|
51 |
import com.iver.andami.ui.mdiManager.IWindow; |
|
52 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
|
53 |
import com.iver.cit.gvsig.fmap.ColorEvent; |
|
54 |
import com.iver.cit.gvsig.fmap.ExtentEvent; |
|
55 |
import com.iver.cit.gvsig.fmap.ProjectionEvent; |
|
56 |
import com.iver.cit.gvsig.fmap.ViewPortListener; |
|
57 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
|
58 |
|
|
59 |
import es.gva.cit.catalog.querys.Coordinates; |
|
60 |
import es.gva.cit.catalog.utils.Frames; |
|
61 |
import es.gva.cit.gazetteer.GazetteerClient; |
|
62 |
import es.gva.cit.gazetteer.querys.Feature; |
|
63 |
import es.gva.cit.gazetteer.ui.search.SearchDialogPanel; |
|
64 |
|
|
65 |
|
|
66 |
/** |
|
67 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
|
68 |
*/ |
|
69 |
public class SearchDialog extends SearchDialogPanel |
|
70 |
implements IWindow,ViewPortListener{ |
|
71 |
public WindowInfo m_windowInfo = null; |
|
72 |
public ConnectDialog parentDialog = null; |
|
73 |
public JDialog frame = null; |
|
74 |
|
|
75 |
public SearchDialog(GazetteerClient client,Object serverConnectFrame){ |
|
76 |
super(client,serverConnectFrame); |
|
77 |
parentDialog = (ConnectDialog)serverConnectFrame; |
|
78 |
setViewChangeListener(); |
|
79 |
loadViewPortCoordinates(); |
|
80 |
} |
|
81 |
|
|
82 |
/* (non-Javadoc) |
|
83 |
* @see com.iver.andami.ui.mdiManager.View#getViewInfo() |
|
84 |
*/ |
|
85 |
public WindowInfo getWindowInfo() { |
|
86 |
if (m_windowInfo == null){ |
|
87 |
m_windowInfo = new WindowInfo(WindowInfo.PALETTE); |
|
88 |
m_windowInfo.setTitle(Messages.getText("gazetteer_search") + " [" + |
|
89 |
getCurrentServer() + "]"); |
|
90 |
m_windowInfo.setHeight(80); |
|
91 |
m_windowInfo.setWidth(525); |
|
92 |
} |
|
93 |
return m_windowInfo; |
|
94 |
|
|
95 |
} |
|
96 |
|
|
97 |
protected void showResultsActionPerformed(Feature[] features) { |
|
98 |
JDialog panel = new JDialog((Frame) PluginServices.getMainFrame(), false); |
|
99 |
Frames.centerFrame(panel,420,258); |
|
100 |
panel.setTitle(Messages.getText( "gazetteer_search")); |
|
101 |
panel.setResizable(false); |
|
102 |
|
|
103 |
ShowResultsDialog dialog = new ShowResultsDialog(panel, |
|
104 |
client, |
|
105 |
features, |
|
106 |
lowerPanel.getResultsByPage(), |
|
107 |
getQuery()); |
|
108 |
|
|
109 |
panel.getContentPane().add(dialog); |
|
110 |
panel.show(); |
|
111 |
} |
|
112 |
|
|
113 |
protected void closeButtonActionPerformed() { |
|
114 |
closeJDialog(); |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* Size button action performed |
|
119 |
*/ |
|
120 |
protected void resizeButtonActionPerformed(){ |
|
121 |
if (isMinimized){ |
|
122 |
frame.setSize(frame.getWidth(),450); |
|
123 |
getLowerPanel().setVisible(true); |
|
124 |
getUpperPanel().setUpIcon(); |
|
125 |
}else{ |
|
126 |
frame.setSize(frame.getWidth(),115); |
|
127 |
getLowerPanel().setVisible(false); |
|
128 |
getUpperPanel().setDownIcon(); |
|
129 |
} |
|
130 |
isMinimized = !isMinimized; |
|
131 |
} |
|
132 |
/** |
|
133 |
* Return button action |
|
134 |
*/ |
|
135 |
protected void lastButtonActionPerformed() { |
|
136 |
closeJDialog(); |
|
137 |
ConnectDialog serverConnect = (ConnectDialog)serverConnectFrame; |
|
138 |
parentDialog.setVisible(true); |
|
139 |
parentDialog.getControlsPanel().enableSearchButton(false); |
|
140 |
PluginServices.getMDIManager().addWindow(serverConnect); |
|
141 |
} |
|
142 |
|
|
143 |
public void closeJDialog() { |
|
144 |
frame.setVisible(false); |
|
145 |
} |
|
146 |
|
|
147 |
/** |
|
148 |
* This method loads the view coordinates to the catalog search dialog |
|
149 |
* |
|
150 |
*/ |
|
151 |
private void loadViewPortCoordinates(){ |
|
152 |
BaseView activeView = |
|
153 |
(BaseView) PluginServices.getMDIManager().getActiveWindow(); |
|
154 |
|
|
155 |
Rectangle2D r2d= activeView.getMapControl().getViewPort().getExtent(); |
|
156 |
|
|
157 |
try{ |
|
158 |
getLowerPanel().setCoordinates(new Coordinates(r2d.getMinX(), |
|
159 |
r2d.getMaxY(), |
|
160 |
r2d.getMaxX(), |
|
161 |
r2d.getMinY())); |
|
162 |
}catch(NullPointerException E){ |
|
163 |
//We cant retrieve the coordinates if it doesn't |
|
164 |
//exist a loaded layer |
|
165 |
} |
|
166 |
} |
|
167 |
/* |
|
168 |
* This method joins the viewPort event to the listener |
|
169 |
*/ |
|
170 |
private void setViewChangeListener(){ |
|
171 |
BaseView activeView = |
|
172 |
(BaseView) PluginServices.getMDIManager().getActiveWindow(); |
|
173 |
|
|
174 |
activeView.getMapControl().getViewPort().addViewPortListener(this); |
|
175 |
|
|
176 |
} |
|
177 |
|
|
178 |
public void extentChanged(ExtentEvent e) { |
|
179 |
loadViewPortCoordinates(); |
|
180 |
|
|
181 |
} |
|
182 |
|
|
183 |
public void backColorChanged(ColorEvent e) { |
|
184 |
// TODO Auto-generated method stub |
|
185 |
|
|
186 |
} |
|
187 |
|
|
188 |
public void projectionChanged(ProjectionEvent e) { |
|
189 |
loadViewPortCoordinates(); |
|
190 |
} |
|
191 |
|
|
192 |
/** |
|
193 |
* @param frame the frame to set |
|
194 |
*/ |
|
195 |
public void setFrame(JDialog dialog) { |
|
196 |
this.frame = dialog; |
|
197 |
} |
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
} |
|
0 | 205 |
branches/v10/extensions/extCatalogAndGazetteer/src/es/gva/cit/gvsig/gazetteer/gui/ConnectDialog.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 es.gva.cit.gvsig.gazetteer.gui; |
|
42 |
|
|
43 |
|
|
44 |
import java.awt.Frame; |
|
45 |
|
|
46 |
import javax.swing.JDialog; |
|
47 |
|
|
48 |
import org.gvsig.i18n.Messages; |
|
49 |
|
|
50 |
import com.iver.andami.PluginServices; |
|
51 |
import com.iver.andami.persistence.serverData.ServerDataPersistence; |
|
52 |
import com.iver.andami.ui.mdiManager.IWindow; |
|
53 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
|
54 |
import com.iver.utiles.swing.jcomboServer.ServerData; |
|
55 |
|
|
56 |
import es.gva.cit.catalog.utils.Frames; |
|
57 |
import es.gva.cit.gazetteer.ui.serverconnect.ServerConnectDialogPanel; |
|
58 |
|
|
59 |
/** |
|
60 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
|
61 |
*/ |
|
62 |
public class ConnectDialog extends ServerConnectDialogPanel |
|
63 |
implements IWindow { |
|
64 |
public WindowInfo m_windowInfo = null; |
|
65 |
|
|
66 |
/** |
|
67 |
* Building the dialog Window |
|
68 |
*/ |
|
69 |
public ConnectDialog(/*FLayers layers, MapControl mapCtrl*/) { |
|
70 |
super(null); |
|
71 |
init(); |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* Establishing window properties |
|
76 |
* |
|
77 |
*/ |
|
78 |
private void init() { |
|
79 |
this.setBounds(0, 0, 610, 263); |
|
80 |
setName("connectDialog"); |
|
81 |
} |
|
82 |
|
|
83 |
public static void addServer(ServerData server) { |
|
84 |
ServerConnectDialogPanel.addTreeMapServer(server); |
|
85 |
} |
|
86 |
|
|
87 |
/* |
|
88 |
* (non-Javadoc) |
|
89 |
* @see es.gva.cit.gazetteer.ui.serverconnect.ServerConnectDialogPanel#searchButtonActionPerformed() |
|
90 |
*/ |
|
91 |
protected void searchButtonActionPerformed() { |
|
92 |
addCurrentHost(); |
|
93 |
closeJDialog(); |
|
94 |
|
|
95 |
JDialog panel = new JDialog((Frame) PluginServices.getMainFrame(), false); |
|
96 |
Frames.centerFrame(panel,525,125); |
|
97 |
panel.setTitle(Messages.getText( "gazetteer_search")); |
|
98 |
SearchDialog dialog = new SearchDialog(client,this); |
|
99 |
dialog.setFrame(panel); |
|
100 |
dialog.setCurrentServer(getCurrentServer()); |
|
101 |
dialog.setFrame(panel); |
|
102 |
panel.getContentPane().add(dialog); |
|
103 |
panel.setVisible(true); |
|
104 |
} |
|
105 |
|
|
106 |
/** |
|
107 |
* Save the current host (if is neccessary) in a file using the andami |
|
108 |
* persistence |
|
109 |
* @param host |
|
110 |
* Host to save |
|
111 |
*/ |
|
112 |
private void addCurrentHost(){ |
|
113 |
String host = client.getSUri(); |
|
114 |
ServerDataPersistence persistence = new ServerDataPersistence(this,ServerData.SERVER_TYPE_GAZETTEER); |
|
115 |
persistence.addServerData(new ServerData(host, ServerData.SERVER_TYPE_GAZETTEER, client.getProtocol())); |
|
116 |
persistence.setPersistent(); |
|
117 |
} |
|
118 |
|
|
119 |
/* |
|
120 |
* (non-Javadoc) |
|
121 |
* @see es.gva.cit.gazetteer.ui.serverconnect.ServerConnectDialogPanel#closeButtonActionPerformed() |
|
122 |
*/ |
|
123 |
protected void closeButtonActionPerformed() { |
|
124 |
closeJDialog(); |
|
125 |
} |
|
126 |
|
|
127 |
/** |
|
128 |
* Cierra el Dialog |
|
129 |
*/ |
|
130 |
public void closeJDialog() { |
|
131 |
PluginServices.getMDIManager().closeWindow(ConnectDialog.this); |
|
132 |
} |
|
133 |
|
|
134 |
/* (non-Javadoc) |
|
135 |
* @see com.iver.andami.ui.mdiManager.View#getViewInfo() |
|
136 |
*/ |
|
137 |
public WindowInfo getWindowInfo() { |
|
138 |
if (m_windowInfo == null){ |
|
139 |
m_windowInfo=new WindowInfo(WindowInfo.RESIZABLE | WindowInfo.MODALDIALOG); |
|
140 |
m_windowInfo.setTitle(Messages.getText( "gazetteer_connect")); |
|
141 |
m_windowInfo.setHeight(225); |
|
142 |
m_windowInfo.setWidth(610); |
|
143 |
} |
|
144 |
return m_windowInfo; |
|
145 |
} |
|
146 |
|
|
147 |
} |
|
0 | 148 |
branches/v10/extensions/extCatalogAndGazetteer/src/es/gva/cit/gvsig/gazetteer/loaders/FeatureLoader.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 es.gva.cit.gvsig.gazetteer.loaders; |
|
42 |
|
|
43 |
|
|
44 |
import java.awt.Color; |
|
45 |
import java.awt.Toolkit; |
|
46 |
import java.awt.geom.Point2D; |
|
47 |
import java.awt.geom.Rectangle2D; |
|
48 |
|
|
49 |
import org.cresques.cts.ICoordTrans; |
|
50 |
import org.cresques.cts.IProjection; |
|
51 |
|
|
52 |
import com.iver.andami.PluginServices; |
|
53 |
import com.iver.cit.gvsig.fmap.MapContext; |
|
54 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
55 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
|
56 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
57 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
|
58 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
|
59 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
|
60 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
|
61 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
|
62 |
import com.iver.cit.gvsig.fmap.rendering.FGraphicLabel; |
|
63 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
|
64 |
|
|
65 |
import es.gva.cit.gazetteer.querys.Feature; |
|
66 |
import es.gva.cit.gazetteer.querys.GazetteerQuery; |
|
67 |
import es.gva.cit.gvsig.gazetteer.DeleteSearchesExtension; |
|
68 |
|
|
69 |
|
|
70 |
/** |
|
71 |
* This class is used to load a new feature like a layer in gvSIG |
|
72 |
* |
|
73 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
|
74 |
*/ |
|
75 |
public class FeatureLoader { |
|
76 |
/** |
|
77 |
* Coordinates Transformer |
|
78 |
*/ |
|
79 |
private ICoordTrans coordTrans; |
|
80 |
|
|
81 |
/** |
|
82 |
* @param projection |
|
83 |
* Server projection |
|
84 |
*/ |
|
85 |
public FeatureLoader(String sProjection){ |
|
86 |
View activeView = |
|
87 |
(View) PluginServices.getMDIManager().getActiveWindow(); |
|
88 |
|
|
89 |
|
|
90 |
IProjection projection = CRSFactory.getCRS(sProjection); |
|
91 |
if (projection == null){ |
|
92 |
projection = activeView.getMapControl().getViewPort().getProjection(); |
|
93 |
} |
|
94 |
|
|
95 |
coordTrans= projection.getCT(activeView.getMapControl().getViewPort().getProjection()); |
|
96 |
} |
|
97 |
/** |
|
98 |
* It makes a zoom in gvSIG |
|
99 |
* @param |
|
100 |
* feature |
|
101 |
* @param |
|
102 |
* query |
|
103 |
* Query that contains advanced options to search and |
|
104 |
* to show the results |
|
105 |
* @return |
|
106 |
* true or false if fail |
|
107 |
*/ |
|
108 |
public boolean load(Feature feature,GazetteerQuery query) { |
|
109 |
addAndDrawLabel(feature, |
|
110 |
query.getOptions().getAspect().isKeepOld(), |
|
111 |
query.getOptions().getAspect().isPaintCurrent()); |
|
112 |
|
|
113 |
if (query.getOptions().getAspect().isGoTo()){ |
|
114 |
focusCenter(feature); |
|
115 |
} |
|
116 |
|
|
117 |
return true; |
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* This method focus the toponim in the center of the view |
|
122 |
* @param feature |
|
123 |
* Feature that contains the coordinates |
|
124 |
*/ |
|
125 |
private void focusCenter(Feature feature){ |
|
126 |
View activeView = |
|
127 |
(View) PluginServices.getMDIManager().getActiveWindow(); |
|
128 |
|
|
129 |
IProjection projection = activeView.getProjection(); |
|
130 |
ViewPort viewPort = activeView.getMapControl().getViewPort(); |
|
131 |
Point2D point = getReprojectedPoint(feature.getCoordinates()); |
|
132 |
|
|
133 |
Rectangle2D zoomExtent = null; |
|
134 |
if (viewPort.getAdjustedExtent() == null){ |
|
135 |
|
|
136 |
}else{ |
|
137 |
Toolkit kit = Toolkit.getDefaultToolkit(); |
|
138 |
double dpi = kit.getScreenResolution(); |
|
139 |
Rectangle2D extent = projection.getExtent(viewPort.getAdjustedExtent(), |
|
140 |
25000, |
|
141 |
viewPort.getImageWidth(), |
|
142 |
viewPort.getImageHeight(), |
|
143 |
MapContext.CHANGE[viewPort.getMapUnits()], |
|
144 |
dpi); |
|
145 |
zoomExtent = new Rectangle2D.Double(point.getX() - extent.getWidth()/2, |
|
146 |
point.getY() - extent.getHeight()/2, |
|
147 |
extent.getWidth(), |
|
148 |
extent.getHeight()); |
|
149 |
activeView.getMapControl().getMapContext().zoomToExtent(zoomExtent); |
|
150 |
} |
|
151 |
|
|
152 |
|
|
153 |
} |
|
154 |
|
|
155 |
/** |
|
156 |
* It adds a new Label to the current view |
|
157 |
* @param feature |
|
158 |
* To obtain the coordinates and the toponim name |
|
159 |
* @param isRemoveOldClicked |
|
160 |
* To remove or keep the old searches |
|
161 |
*/ |
|
162 |
private void addAndDrawLabel(Feature feature,boolean isRemoveOldClicked,boolean isMarkedPlaceClicked){ |
|
163 |
View activeView = |
|
164 |
(View) PluginServices.getMDIManager().getActiveWindow(); |
|
165 |
|
|
166 |
GraphicLayer lyr = activeView.getMapControl().getMapContext().getGraphicsLayer(); |
|
167 |
|
|
168 |
if (isRemoveOldClicked){ |
|
169 |
lyr.clearAllGraphics(); |
|
170 |
} |
|
171 |
|
|
172 |
if (isMarkedPlaceClicked){ |
|
173 |
int idSymbol = lyr.addSymbol(getSymbol()); |
|
174 |
|
|
175 |
IGeometry geom = ShapeFactory.createPoint2D(new FPoint2D(getReprojectedPoint(feature.getCoordinates()))); |
|
176 |
|
|
177 |
FGraphicLabel theLabel = new FGraphicLabel(geom, idSymbol, feature.getName()); |
|
178 |
lyr.addGraphic(theLabel); |
|
179 |
|
|
180 |
DeleteSearchesExtension.setVisible(); |
|
181 |
PluginServices.getMainFrame().enableControls(); |
|
182 |
} |
|
183 |
|
|
184 |
activeView.getMapControl().drawGraphics(); |
|
185 |
|
|
186 |
//This line could look stupid, but is necessary because grawGraphics does't |
|
187 |
//remove the old Graphics searched |
|
188 |
activeView.getMapControl().getViewPort().setExtent(activeView.getMapControl().getViewPort().getExtent()); |
|
189 |
} |
|
190 |
|
|
191 |
/** |
|
192 |
* Creates a FSymbol |
|
193 |
* @return |
|
194 |
* FSymbol |
|
195 |
*/ |
|
196 |
private FSymbol getSymbol(){ |
|
197 |
FSymbol theSymbol = new FSymbol(FConstant.SYMBOL_TYPE_TEXT); |
|
198 |
theSymbol.setColor(Color.RED); |
|
199 |
theSymbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_CIRCLE); |
|
200 |
theSymbol.setFontColor(Color.BLACK); |
|
201 |
theSymbol.setSizeInPixels(true); |
|
202 |
theSymbol.setSize(10); |
|
203 |
return theSymbol; |
|
204 |
} |
|
205 |
|
|
206 |
/** |
|
207 |
* Reprojects the new point |
|
208 |
* @param ptOrig |
|
209 |
* Origin point |
|
210 |
* @return |
|
211 |
* FPoint2D |
|
212 |
*/ |
|
213 |
private Point2D getReprojectedPoint(Point2D ptOrigin){ |
|
214 |
Point2D ptDest = null; |
|
215 |
return getCoordTrans().convert(ptOrigin, ptDest); |
|
216 |
} |
|
217 |
/** |
|
218 |
* @return the coordTrans |
|
219 |
*/ |
|
220 |
public ICoordTrans getCoordTrans() { |
|
221 |
return coordTrans; |
|
222 |
} |
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
} |
|
0 | 227 |
Also available in: Unified diff