Revision 44455 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/DefaultViewDocument.java
DefaultViewDocument.java | ||
---|---|---|
21 | 21 |
* For any additional information, do not hesitate to contact us |
22 | 22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
23 | 23 |
*/ |
24 |
|
|
25 | 24 |
package org.gvsig.app.project.documents.view; |
26 | 25 |
|
27 | 26 |
import javax.swing.JOptionPane; |
... | ... | |
50 | 49 |
import org.slf4j.Logger; |
51 | 50 |
import org.slf4j.LoggerFactory; |
52 | 51 |
|
53 |
|
|
54 |
|
|
55 | 52 |
/** |
56 | 53 |
* Clase que representa una vista del proyecto |
57 |
*
|
|
54 |
* |
|
58 | 55 |
*/ |
59 |
|
|
60 | 56 |
public class DefaultViewDocument extends BaseViewDocument { |
61 | 57 |
|
62 |
private static Logger logger = LoggerFactory.getLogger(DefaultViewDocument.class);
|
|
63 |
/**
|
|
64 |
*
|
|
65 |
*/
|
|
66 |
private static final long serialVersionUID = 676711512482334764L;
|
|
58 |
private static Logger logger = LoggerFactory.getLogger(DefaultViewDocument.class);
|
|
59 |
/**
|
|
60 |
*
|
|
61 |
*/
|
|
62 |
private static final long serialVersionUID = 676711512482334764L;
|
|
67 | 63 |
|
68 |
public static final String PERSISTENCE_DEFINITION_NAME = "DefaultViewDocument";
|
|
69 |
|
|
64 |
public static final String PERSISTENCE_DEFINITION_NAME = "DefaultViewDocument";
|
|
65 |
|
|
70 | 66 |
private class SetViewPortExtentWhenAddLayerListener extends BaseLayerCollectionListener { |
71 | 67 |
|
72 | 68 |
private Thread th = null; |
73 | 69 |
private final ViewPort viewPort; |
74 |
|
|
70 |
|
|
75 | 71 |
public SetViewPortExtentWhenAddLayerListener(ViewPort viewPort) { |
76 | 72 |
this.viewPort = viewPort; |
77 | 73 |
} |
78 |
|
|
74 |
|
|
79 | 75 |
@Override |
80 | 76 |
public synchronized void layerAdded(LayerCollectionEvent e) { |
81 |
if( th != null ) {
|
|
77 |
if (th != null) {
|
|
82 | 78 |
return; |
83 | 79 |
} |
84 | 80 |
if (viewPort.getEnvelope() == null) { |
85 | 81 |
final FLayer layer = e.getAffectedLayer(); |
86 |
if (layer.isAvailable() ) {
|
|
82 |
if (layer.isAvailable()) {
|
|
87 | 83 |
th = new Thread(new Runnable() { |
88 | 84 |
@Override |
89 | 85 |
public void run() { |
... | ... | |
91 | 87 |
ApplicationManager application = ApplicationLocator.getManager(); |
92 | 88 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
93 | 89 |
application.message( |
94 |
i18n.getTranslation("_Calculating_envelope"), |
|
95 |
JOptionPane.INFORMATION_MESSAGE |
|
90 |
i18n.getTranslation("_Calculating_envelope"),
|
|
91 |
JOptionPane.INFORMATION_MESSAGE
|
|
96 | 92 |
); |
97 | 93 |
Envelope envelope = layer.getFullEnvelope(); |
98 | 94 |
// Si nadie le ha asignado un envelope mientras se |
... | ... | |
101 | 97 |
viewPort.setEnvelope(envelope); |
102 | 98 |
} |
103 | 99 |
application.message( |
104 |
"", |
|
105 |
JOptionPane.INFORMATION_MESSAGE |
|
100 |
"",
|
|
101 |
JOptionPane.INFORMATION_MESSAGE
|
|
106 | 102 |
); |
107 | 103 |
} catch (ReadException ex) { |
108 | 104 |
} |
... | ... | |
119 | 115 |
} |
120 | 116 |
} |
121 | 117 |
} |
122 |
|
|
118 |
|
|
123 | 119 |
} |
124 | 120 |
|
125 |
public DefaultViewDocument() { |
|
126 |
this(null); |
|
127 |
} |
|
128 |
|
|
129 |
public DefaultViewDocument(DocumentManager factory) { |
|
130 |
super(factory); |
|
121 |
public DefaultViewDocument() { |
|
122 |
this(null); |
|
123 |
} |
|
131 | 124 |
|
132 |
ViewPort vp; |
|
133 |
|
|
134 |
ProjectPreferences preferences = (ProjectPreferences) ApplicationLocator.getManager().getPreferences("project"); |
|
135 |
|
|
136 |
MapContext viewMapContext = new MapContext( |
|
137 |
new ViewPort( preferences.getDefaultProjection() ) |
|
138 |
); |
|
139 |
vp = viewMapContext.getViewPort(); |
|
140 |
vp.setBackColor(preferences.getDefaultViewBackColor()); |
|
141 |
vp.setDistanceUnits(preferences.getDefaultDistanceUnits()); |
|
142 |
vp.setDistanceArea(preferences.getDefaultDistanceArea()); |
|
143 |
|
|
144 |
/* |
|
125 |
public DefaultViewDocument(DocumentManager factory) { |
|
126 |
super(factory); |
|
127 |
|
|
128 |
ViewPort vp; |
|
129 |
|
|
130 |
ProjectPreferences preferences = (ProjectPreferences) ApplicationLocator.getManager().getPreferences("project"); |
|
131 |
|
|
132 |
MapContext viewMapContext = new MapContext( |
|
133 |
new ViewPort(preferences.getDefaultProjection()) |
|
134 |
); |
|
135 |
vp = viewMapContext.getViewPort(); |
|
136 |
vp.setBackColor(preferences.getDefaultViewBackColor()); |
|
137 |
vp.setDistanceUnits(preferences.getDefaultDistanceUnits()); |
|
138 |
vp.setDistanceArea(preferences.getDefaultDistanceArea()); |
|
139 |
|
|
140 |
/* |
|
145 | 141 |
* Another user preference: the order manager |
146 |
*/ |
|
147 |
LayerOrderManager lom = getCurrentOrderManager(); |
|
148 |
viewMapContext.setOrderManager(lom); |
|
149 |
|
|
150 |
|
|
151 |
/* |
|
142 |
*/ |
|
143 |
LayerOrderManager lom = getCurrentOrderManager(); |
|
144 |
viewMapContext.setOrderManager(lom); |
|
145 |
|
|
146 |
/* |
|
152 | 147 |
* Not very elegant but we are forcing meters if projected |
153 |
*/
|
|
154 |
if (viewMapContext.getProjection().isProjected()) {
|
|
155 |
vp.setMapUnits(1);
|
|
156 |
} else {
|
|
148 |
*/
|
|
149 |
if (viewMapContext.getProjection().isProjected()) {
|
|
150 |
vp.setMapUnits(1);
|
|
151 |
} else {
|
|
157 | 152 |
vp.setMapUnits(8); |
158 |
} |
|
159 |
|
|
160 |
|
|
161 |
this.setMapContext(viewMapContext); |
|
162 |
|
|
163 |
MapContext overviewMapContext = new MapContext( |
|
164 |
new ViewPort( viewMapContext.getProjection() ) |
|
165 |
); |
|
166 |
vp = viewMapContext.getViewPort(); |
|
167 |
vp.setBackColor(preferences.getDefaultViewBackColor()); |
|
168 |
this.setMapOverViewContext(overviewMapContext); |
|
169 |
|
|
153 |
} |
|
154 |
|
|
155 |
this.setMapContext(viewMapContext); |
|
156 |
|
|
157 |
MapContext overviewMapContext = new MapContext( |
|
158 |
new ViewPort(viewMapContext.getProjection()) |
|
159 |
); |
|
160 |
vp = viewMapContext.getViewPort(); |
|
161 |
vp.setBackColor(preferences.getDefaultViewBackColor()); |
|
162 |
this.setMapOverViewContext(overviewMapContext); |
|
163 |
|
|
170 | 164 |
this.getMapContext().getLayers().addLayerCollectionListener( |
171 |
new SetViewPortExtentWhenAddLayerListener(this.getMapContext().getViewPort()) |
|
165 |
new SetViewPortExtentWhenAddLayerListener(this.getMapContext().getViewPort())
|
|
172 | 166 |
); |
173 | 167 |
this.getMapOverViewContext().getLayers().addLayerCollectionListener( |
174 |
new SetViewPortExtentWhenAddLayerListener(this.getMapOverViewContext().getViewPort()) |
|
168 |
new SetViewPortExtentWhenAddLayerListener(this.getMapOverViewContext().getViewPort())
|
|
175 | 169 |
); |
176 |
}
|
|
177 |
|
|
178 |
/**
|
|
179 |
* Get current order manager from persistence
|
|
180 |
*
|
|
181 |
* @return
|
|
182 |
*/
|
|
183 |
private LayerOrderManager getCurrentOrderManager() {
|
|
184 |
|
|
185 |
DynObject props = this.getPluginProperties();
|
|
186 |
// current_layer_order_manager
|
|
187 |
Object val_obj = null;
|
|
188 |
if (props.hasDynValue(LayerOrderPage.PREFERENCES_ID)) {
|
|
189 |
val_obj = props.getDynValue(LayerOrderPage.PREFERENCES_ID);
|
|
190 |
}
|
|
191 |
if (val_obj != null && val_obj instanceof LayerOrderManager) {
|
|
192 |
LayerOrderManager lom = (LayerOrderManager) val_obj;
|
|
193 |
return lom;
|
|
194 |
} else {
|
|
195 |
logger.info("No order manager found in persistence.");
|
|
196 |
return MapContextLocator.getDefaultOrderManager();
|
|
197 |
}
|
|
198 |
|
|
199 |
}
|
|
200 |
|
|
201 |
private DynObject getPluginProperties() {
|
|
170 |
}
|
|
171 |
|
|
172 |
/**
|
|
173 |
* Get current order manager from persistence
|
|
174 |
*
|
|
175 |
* @return
|
|
176 |
*/
|
|
177 |
private LayerOrderManager getCurrentOrderManager() {
|
|
178 |
|
|
179 |
DynObject props = this.getPluginProperties();
|
|
180 |
// current_layer_order_manager
|
|
181 |
Object val_obj = null;
|
|
182 |
if (props.hasDynValue(LayerOrderPage.PREFERENCES_ID)) {
|
|
183 |
val_obj = props.getDynValue(LayerOrderPage.PREFERENCES_ID);
|
|
184 |
}
|
|
185 |
if (val_obj != null && val_obj instanceof LayerOrderManager) {
|
|
186 |
LayerOrderManager lom = (LayerOrderManager) val_obj;
|
|
187 |
return lom;
|
|
188 |
} else {
|
|
189 |
logger.info("No order manager found in persistence.");
|
|
190 |
return MapContextLocator.getDefaultOrderManager();
|
|
191 |
}
|
|
192 |
|
|
193 |
}
|
|
194 |
|
|
195 |
private DynObject getPluginProperties() {
|
|
202 | 196 |
PluginsManager pluginsManager = PluginsLocator.getManager(); |
203 | 197 |
return pluginsManager.getPlugin(AddLayer.class).getPluginProperties(); |
204 |
} |
|
205 |
|
|
206 |
|
|
207 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
208 |
super.saveToState(state); |
|
209 |
} |
|
210 |
|
|
211 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
212 |
super.loadFromState(state); |
|
213 |
} |
|
198 |
} |
|
214 | 199 |
|
215 |
public String exportDocumentAsText() { |
|
216 |
// FIXME: jjdc PersistentManager getStateAsText o similar |
|
200 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
201 |
super.saveToState(state); |
|
202 |
} |
|
203 |
|
|
204 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
205 |
super.loadFromState(state); |
|
206 |
} |
|
207 |
|
|
208 |
public String exportDocumentAsText() { |
|
209 |
// FIXME: jjdc PersistentManager getStateAsText o similar |
|
217 | 210 |
// PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
218 | 211 |
// PersistentState state = manager.getState(this); |
219 | 212 |
// return manager.getStateAsText(state); |
220 |
return null;
|
|
221 |
}
|
|
213 |
return null;
|
|
214 |
}
|
|
222 | 215 |
|
223 |
public void setStateFromText(String text) {
|
|
224 |
// FIXME: jjdc PersistentManager getStateFromText o similar
|
|
216 |
public void setStateFromText(String text) {
|
|
217 |
// FIXME: jjdc PersistentManager getStateFromText o similar
|
|
225 | 218 |
// PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
226 | 219 |
// PersistentState state = manager.getStateFromText(text); |
227 | 220 |
// this.loadFromState(state); |
228 |
}
|
|
221 |
}
|
|
229 | 222 |
|
230 |
|
|
231 | 223 |
} |
Also available in: Unified diff