Revision 22281
branches/v10/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/FLayers.java | ||
---|---|---|
75 | 75 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection; |
76 | 76 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
77 | 77 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem; |
78 |
import com.iver.cit.gvsig.fmap.layers.order.DefaultOrderManager; |
|
79 |
import com.iver.cit.gvsig.fmap.layers.order.OrderManager; |
|
78 | 80 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
79 | 81 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
80 | 82 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
... | ... | |
142 | 144 |
protected static Logger logger = Logger.getLogger(FLayers.class.getName()); |
143 | 145 |
|
144 | 146 |
/** |
147 |
* <p>Note: Don't access it directly, use {@link #getOrderManager()} instead.</p> |
|
148 |
* <p>When a new layer is added to this FLayers, |
|
149 |
* the order manager will decide the right position for the |
|
150 |
* layer.</p> <p>The orderManager will only be used when adding a layer, |
|
151 |
* so it will not affect to the collection order when the user modifies the |
|
152 |
* order.</p> |
|
153 |
*/ |
|
154 |
private OrderManager orderManager = null; |
|
155 |
|
|
156 |
/** |
|
145 | 157 |
* Default <code>FLayers</code> constructor. |
146 | 158 |
* |
147 | 159 |
* @param fmap reference to the <code>MapContext</code> instance that contains this node of layers |
... | ... | |
207 | 219 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#addLayer(com.iver.cit.gvsig.fmap.layers.FLayer) |
208 | 220 |
*/ |
209 | 221 |
public void addLayer(FLayer layer) { |
210 |
addLayer(layers.size(), layer); |
|
222 |
int position = getOrderManager().getPosition(this, layer); |
|
223 |
addLayer(position, layer); |
|
211 | 224 |
} |
212 | 225 |
|
213 | 226 |
/** |
... | ... | |
226 | 239 |
|
227 | 240 |
if (layer instanceof FLayers){ |
228 | 241 |
FLayers layers=(FLayers)layer; |
242 |
if (!layers.hasOrderManager()) { |
|
243 |
layers.setOrderManager(getOrderManager()); |
|
244 |
} |
|
229 | 245 |
fmap.addAsCollectionListener(layers); |
230 | 246 |
} |
231 | 247 |
callLayerAdding(LayerCollectionEvent.createLayerAddingEvent(layer)); |
... | ... | |
1127 | 1143 |
} |
1128 | 1144 |
} |
1129 | 1145 |
|
1130 |
this.addLayer(layer); |
|
1146 |
this.addLayer(layers.size(), layer);
|
|
1131 | 1147 |
} |
1132 | 1148 |
} /*azabala-modificaciones en layerfactory- |
1133 | 1149 |
catch (DriverException e) { |
... | ... | |
1166 | 1182 |
String[] s = xml.getStringArrayProperty("LayerNames"); |
1167 | 1183 |
// try { |
1168 | 1184 |
fmap.clearErrors(); |
1169 |
for (int i = 0; i < numLayers; i++) { |
|
1170 |
this.addLayerFromXML(xml.getChild(i),s[i]); |
|
1171 |
|
|
1172 |
|
|
1173 |
} |
|
1174 |
/* } catch (DriverException e) { |
|
1175 |
throw new XMLException(e); |
|
1176 |
} */ |
|
1177 |
/*if (loadLayerException.getExceptions().size()>0){ |
|
1178 |
throw loadLayerException; |
|
1179 |
}*/ |
|
1185 |
for (int i = 0; i < numLayers; i++) { |
|
1186 |
this.addLayerFromXML(xml.getChild(i),s[i]); |
|
1187 |
} |
|
1180 | 1188 |
} |
1181 | 1189 |
|
1182 | 1190 |
/* |
... | ... | |
1651 | 1659 |
|
1652 | 1660 |
} |
1653 | 1661 |
|
1654 |
this.addLayer(layer); |
|
1662 |
this.addLayer(layers.size(), layer);
|
|
1655 | 1663 |
long t2 = System.currentTimeMillis(); |
1656 | 1664 |
logger.debug("layer: "+ layer.getName() +" loaded. " + (t2-t1) + " msecs."); |
1657 | 1665 |
// Comprobar que la proyecci?n es la misma que la de FMap |
... | ... | |
1695 | 1703 |
} |
1696 | 1704 |
} |
1697 | 1705 |
|
1698 |
/** |
|
1699 |
* <p>Creates a new layer of the same class as the property <i>className</i> of the XML, after, adds the XML entity to that layer |
|
1700 |
* and loads the layer. Then, adds the layer to this collection of layers, and if there is a projection defined, |
|
1701 |
* inserts the transformation coordinates to the layer.</p> |
|
1702 |
* |
|
1703 |
* <p>If the new layer is an instance of <code>FLyrVect</code>, and has a label field, creates a label layer on the layer.</p> |
|
1704 |
* |
|
1705 |
* @param xml tree-node structure with information about layers |
|
1706 |
* @param name name of the layer to add |
|
1707 |
*/ |
|
1708 |
private void addLayerFromXMLNew(XMLEntity xml, String name) { |
|
1709 |
FLayer layer = null; |
|
1710 | 1706 |
|
1711 |
|
|
1712 |
try { |
|
1713 |
String className = xml.getStringProperty("className"); |
|
1714 |
|
|
1715 |
if (className.equals((FLayers.class.getName()))){ |
|
1716 |
layer = new FLayers(getMapContext(),this); |
|
1717 |
} else { |
|
1718 |
// Por compatibilidad |
|
1719 |
if (className.equals(FLyrVect.class.getName())) { |
|
1720 |
if (xml.contains("file")) { |
|
1721 |
layer = new FLayerFileVectorial(); |
|
1722 |
} else if (xml.contains("db")) { |
|
1723 |
try { |
|
1724 |
layer = (FLayer)((ExtensionPoint)ExtensionPointsSingleton.getInstance().get("Layers")).create("com.iver.cit.gvsig.fmap.layers.FLayerJDBCVectorial"); |
|
1725 |
} catch (Exception e) { |
|
1726 |
throw new XMLException(new Exception("No se tiene registrada la capa de tipo JDBC")); |
|
1727 |
} |
|
1728 |
//className = FLayerJDBCVectorial.class.getName(); |
|
1729 |
} else if (xml.contains("other")){ |
|
1730 |
layer = new FLayerGenericVectorial(); |
|
1731 |
} else { |
|
1732 |
throw new XMLException(new Exception("Capa vectorial de tipo no reconocido")); |
|
1733 |
} |
|
1734 |
// Fin por compatibilidad |
|
1735 |
} else { |
|
1736 |
try { |
|
1737 |
layer = (FLayer)(((ExtensionPoint)ExtensionPointsSingleton.getInstance().get("Layers")).create(className)); |
|
1738 |
} catch (Exception e) { |
|
1739 |
//puende que no este registrada como punto de extension |
|
1740 |
Class clase = Class.forName(className); |
|
1741 |
layer = (FLayer) clase.newInstance(); |
|
1742 |
// FIXME: Hacemos algo aqui o dejamos que suba el error? |
|
1743 |
} |
|
1744 |
} |
|
1745 |
|
|
1746 |
} |
|
1747 |
layer.setXMLEntity(xml); |
|
1748 |
if (name != null) layer.setName(name); |
|
1749 |
try { |
|
1750 |
layer.load(); |
|
1751 |
}catch (DriverIOException e) { |
|
1752 |
throw new XMLException(e); |
|
1753 |
} |
|
1754 |
|
|
1755 |
this.addLayer(layer); |
|
1756 |
logger.debug("layer: "+ layer.getName() +" loaded"); |
|
1757 |
// Comprobar que la proyecci?n es la misma que la de FMap |
|
1758 |
// Si no lo es, es una capa que est? reproyectada al vuelo |
|
1759 |
IProjection proj = layer.getProjection(); |
|
1760 |
if ((proj != null)) |
|
1761 |
if (proj != getMapContext().getProjection()) |
|
1762 |
{ |
|
1763 |
ICoordTrans ct = proj.getCT(getMapContext().getProjection()); |
|
1764 |
// TODO: REVISAR CON LUIS |
|
1765 |
// Se lo fijamos a todas, luego cada una que se reproyecte |
|
1766 |
// si puede, o que no haga nada |
|
1767 |
layer.setCoordTrans(ct); |
|
1768 |
// NOTA: DESPU?S DE ESTO DEBER?AMOS CREAR LAS ETIQUETAS |
|
1769 |
// SI ES NECESARIO. |
|
1770 |
// TODO: REVISAR A FONDO ESTO, PORQUE LAS ETIQUETAS SE CREAN |
|
1771 |
// 2 VECES SI HAY REPROYECC?N |
|
1772 |
if (layer instanceof FLyrVect) |
|
1773 |
{ |
|
1774 |
FLyrVect lyrVect = (FLyrVect)layer; |
|
1775 |
VectorialLegend legend = (VectorialLegend) lyrVect.getLegend(); |
|
1776 |
if (legend.getLabelField() != null) { |
|
1777 |
lyrVect.createLabelLayer(lyrVect.getRecordset()); |
|
1778 |
} |
|
1779 |
|
|
1780 |
} |
|
1781 |
} |
|
1782 |
}catch (Exception e) { |
|
1783 |
fmap.addLayerError(xml.getStringProperty("name")); |
|
1784 |
//loadLayerException.addException(e); |
|
1785 |
/*if (layer!=null){ |
|
1786 |
layer.setActive(false); |
|
1787 |
layer.setVisible(false); |
|
1788 |
this.addLayer(layer); |
|
1789 |
}*/ |
|
1790 |
//throw new XMLException(e); |
|
1791 |
System.err.println("No se ha podido cargar la capa : "+xml.getStringProperty("name")); |
|
1792 |
logger.debug("No se ha podido cargar la capa : "+xml.getStringProperty("name") + ". Raz?n:"); |
|
1793 |
// logger.debug(e.fillInStackTrace()); |
|
1794 |
e.printStackTrace(); |
|
1795 |
} |
|
1796 |
} |
|
1797 |
|
|
1798 | 1707 |
/** |
1799 | 1708 |
* <p>Calls recursively to its layer children to tell them that the layer is going |
1800 | 1709 |
* to be removed from the view. Overwrites <code>FLyrDefault.removingThisLayer()</code>.</p> |
... | ... | |
1810 | 1719 |
} |
1811 | 1720 |
} |
1812 | 1721 |
} |
1722 |
|
|
1723 |
public void setOrderManager(OrderManager manager) { |
|
1724 |
orderManager = manager; |
|
1725 |
// change also the OrderManager of children |
|
1726 |
for (int i=0; i<layers.size(); i++) { |
|
1727 |
if (layers.get(i) instanceof FLayers) { |
|
1728 |
FLayers layer = (FLayers) layers.get(i); |
|
1729 |
layer.setOrderManager(orderManager); |
|
1730 |
} |
|
1731 |
} |
|
1732 |
} |
|
1733 |
|
|
1734 |
public OrderManager getOrderManager() { |
|
1735 |
if (orderManager==null) { |
|
1736 |
orderManager = new DefaultOrderManager(); |
|
1737 |
} |
|
1738 |
return orderManager; |
|
1739 |
} |
|
1740 |
|
|
1741 |
private boolean hasOrderManager() { |
|
1742 |
return (orderManager!=null); |
|
1743 |
} |
|
1813 | 1744 |
} |
branches/v10/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/order/OrderManager.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.layers.order; |
|
2 |
|
|
3 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
4 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
|
5 |
import com.iver.utiles.IPersistance; |
|
6 |
import com.iver.utiles.extensionPoints.IExtensionBuilder; |
|
7 |
|
|
8 |
/** |
|
9 |
* <p>The classes implementing this interface will decide the right position |
|
10 |
* to add a new layer (FLayer) to a layer collection (FLayers) according with |
|
11 |
* its own criterion.</p> |
|
12 |
* <p>Some order managers may study the existing layers in the collection and |
|
13 |
* the new layer's type in order to apply its criterion.</p> |
|
14 |
* <p>For example, an OrderManager |
|
15 |
* may decide that VectorLayers should be placed over Raster Layers. |
|
16 |
* Another OrderManager may decide that a new layer is placed just |
|
17 |
* over the existing layers (this had always been the default gvSIG |
|
18 |
* behaviour).</p> |
|
19 |
* |
|
20 |
* @author Cesar Martinez Izquierdo <cesar.martinez@iver.es> |
|
21 |
* |
|
22 |
*/ |
|
23 |
public interface OrderManager extends IPersistance, Cloneable, IExtensionBuilder { |
|
24 |
|
|
25 |
/** |
|
26 |
* <p>Gets the proposed position for the newLayer in the target layer |
|
27 |
* collection. The OrderManager will study the arrangement of the |
|
28 |
* target layer collection and will decide the right position for |
|
29 |
* the new layer, according to its own criterion.</p> |
|
30 |
* |
|
31 |
* @param target The target collection to which <code>newLayer</code> |
|
32 |
* will be added |
|
33 |
* @param newLayer The layer to be inserted in the layer collection |
|
34 |
* |
|
35 |
* @return The proposed position for the new layer |
|
36 |
*/ |
|
37 |
public int getPosition(FLayers target, FLayer newLayer); |
|
38 |
|
|
39 |
/** |
|
40 |
* <p>Gets the name. The name should identify the |
|
41 |
* policy followed by this OrderManager to sort the layers.</p> |
|
42 |
* |
|
43 |
* @return The name of the OrderManager |
|
44 |
*/ |
|
45 |
public String getName(); |
|
46 |
|
|
47 |
/** |
|
48 |
* <p>Gets the description. The description should be enough to get |
|
49 |
* an idea of the policy and features of this OrderManager.</p> |
|
50 |
* |
|
51 |
* @return The description of the OrderManager |
|
52 |
*/ |
|
53 |
public String getDescription(); |
|
54 |
|
|
55 |
/** |
|
56 |
* <p>Gets the code used to register this OrderManager |
|
57 |
* in the ExtensionPoint.</p> |
|
58 |
* |
|
59 |
* @return The code used to register this orderManager in the |
|
60 |
* ExtensionPoint. |
|
61 |
*/ |
|
62 |
public String getCode(); |
|
63 |
|
|
64 |
public Object clone(); |
|
65 |
} |
|
0 | 66 |
branches/v10/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/order/DefaultOrderManager.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.layers.order; |
|
2 |
|
|
3 |
import java.util.Map; |
|
4 |
|
|
5 |
import org.apache.log4j.Logger; |
|
6 |
|
|
7 |
import com.iver.cit.gvsig.fmap.MapContext; |
|
8 |
import com.iver.cit.gvsig.fmap.Messages; |
|
9 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
10 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
|
11 |
import com.iver.utiles.XMLEntity; |
|
12 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
|
13 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
|
14 |
|
|
15 |
/** |
|
16 |
* Implements the default gvSIG behaviour when adding a new layer |
|
17 |
* to a collection. |
|
18 |
* |
|
19 |
* @author Cesar Martinez Izquierdo <cesar.martinez@iver.es> |
|
20 |
* |
|
21 |
*/ |
|
22 |
public class DefaultOrderManager implements OrderManager { |
|
23 |
protected static final String extensionPointName = "layer.order.manager"; |
|
24 |
protected static final String configuredManagerKey = "default.manager"; |
|
25 |
protected static final String name = "DefaultsOrderManager"; |
|
26 |
protected static final String description = "New_layers_are_always_placed_on_top."; |
|
27 |
|
|
28 |
public int getPosition(FLayers target, FLayer newLayer) { |
|
29 |
return target.getLayersCount(); |
|
30 |
} |
|
31 |
|
|
32 |
public static String getExtensionPointName() { |
|
33 |
return extensionPointName; |
|
34 |
} |
|
35 |
|
|
36 |
public static String getDefaultManagerKey() { |
|
37 |
return configuredManagerKey; |
|
38 |
} |
|
39 |
|
|
40 |
public String getClassName() { |
|
41 |
return this.getClass().getName(); |
|
42 |
} |
|
43 |
|
|
44 |
public XMLEntity getXMLEntity() { |
|
45 |
return null; |
|
46 |
} |
|
47 |
|
|
48 |
public void setXMLEntity(XMLEntity xml) { |
|
49 |
} |
|
50 |
|
|
51 |
public String getDescription() { |
|
52 |
return Messages.getString(description); |
|
53 |
} |
|
54 |
|
|
55 |
public String getName() { |
|
56 |
return Messages.getString(name); |
|
57 |
} |
|
58 |
|
|
59 |
public String toString() { |
|
60 |
return getName(); |
|
61 |
} |
|
62 |
|
|
63 |
public String getCode() { |
|
64 |
return getClassName(); |
|
65 |
} |
|
66 |
|
|
67 |
public Object clone() { |
|
68 |
try { |
|
69 |
return super.clone(); |
|
70 |
} catch (CloneNotSupportedException e) {} |
|
71 |
return null; |
|
72 |
} |
|
73 |
|
|
74 |
public Object create() { |
|
75 |
return this; |
|
76 |
} |
|
77 |
|
|
78 |
public Object create(Object[] args) { |
|
79 |
return this; |
|
80 |
} |
|
81 |
|
|
82 |
public Object create(Map args) { |
|
83 |
return this; |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* Gets the default OrderManager, as configured in the extension point. |
|
88 |
* |
|
89 |
* @return The default OrderManager, as configured in the extension point, |
|
90 |
* or null if no manager was configured. |
|
91 |
*/ |
|
92 |
public static OrderManager getDefaultOrderManager(){ |
|
93 |
try { |
|
94 |
ExtensionPoint ep = |
|
95 |
(ExtensionPoint) ExtensionPointsSingleton.getInstance(). |
|
96 |
get(DefaultOrderManager.getExtensionPointName()); |
|
97 |
if (ep!=null) { |
|
98 |
Object obj = ep.create(DefaultOrderManager.getDefaultManagerKey()); |
|
99 |
if (obj!=null) { |
|
100 |
return (OrderManager) obj; |
|
101 |
} |
|
102 |
} |
|
103 |
} |
|
104 |
catch (Exception ex) { |
|
105 |
Logger.getLogger(MapContext.class).warn("Error getting default layer order manager", ex); |
|
106 |
} |
|
107 |
// if something goes wrong, just return the fallback default order manager |
|
108 |
return null; |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* Gets the OrderManager registered as <code>managerCode</code> in the |
|
113 |
* extension point. |
|
114 |
* |
|
115 |
* @return the OrderManager registered as <code>managerCode</code> in the |
|
116 |
* extension point, or an instance of DefaultOrderManager if not found. |
|
117 |
*/ |
|
118 |
public static OrderManager getOrderManager(String managerCode){ |
|
119 |
try { |
|
120 |
ExtensionPoint ep = |
|
121 |
(ExtensionPoint) ExtensionPointsSingleton.getInstance(). |
|
122 |
get(DefaultOrderManager.getExtensionPointName()); |
|
123 |
if (ep!=null) { |
|
124 |
Object obj = ep.create(managerCode); |
|
125 |
if (obj!=null) { |
|
126 |
return (OrderManager) obj; |
|
127 |
} |
|
128 |
} |
|
129 |
} |
|
130 |
catch (Exception ex) { |
|
131 |
Logger.getLogger(MapContext.class).warn("Error getting default layer order manager", ex); |
|
132 |
} |
|
133 |
// if something goes wrong, just return the fallback default order manager |
|
134 |
return new DefaultOrderManager(); |
|
135 |
} |
|
136 |
|
|
137 |
/** |
|
138 |
* Checks whether an OrderManager was configured as default in the |
|
139 |
* extension point. |
|
140 |
* |
|
141 |
* @return <code>true</code> if there is a default OrderManager configured |
|
142 |
* in the extension point, or <code>false</code> otherwise. |
|
143 |
*/ |
|
144 |
public static boolean existsDefaultOrderManager() { |
|
145 |
try { |
|
146 |
ExtensionPoint ep = |
|
147 |
(ExtensionPoint) ExtensionPointsSingleton.getInstance(). |
|
148 |
get(DefaultOrderManager.getExtensionPointName()); |
|
149 |
if (ep!=null) { |
|
150 |
Object obj = ep.create(DefaultOrderManager.getDefaultManagerKey()); |
|
151 |
if (obj!=null) { |
|
152 |
return true; |
|
153 |
} |
|
154 |
} |
|
155 |
} |
|
156 |
catch (Exception ex) { |
|
157 |
Logger.getLogger(MapContext.class).warn("Error getting default layer order manager", ex); |
|
158 |
} |
|
159 |
return false; |
|
160 |
} |
|
161 |
|
|
162 |
/** |
|
163 |
* Sets as system default OrderManager the provided manager code. |
|
164 |
*/ |
|
165 |
public static void setDefaultOrderManager(String code){ |
|
166 |
try { |
|
167 |
ExtensionPoint ep = |
|
168 |
(ExtensionPoint) ExtensionPointsSingleton.getInstance(). |
|
169 |
get(DefaultOrderManager.getExtensionPointName()); |
|
170 |
if (ep!=null) { |
|
171 |
ep.addAlias(code, DefaultOrderManager.getDefaultManagerKey()); |
|
172 |
} |
|
173 |
} |
|
174 |
catch (Exception ex) { |
|
175 |
Logger.getLogger(MapContext.class).warn("Error getting default layer order manager", ex); |
|
176 |
} |
|
177 |
} |
|
178 |
} |
|
0 | 179 |
branches/v10/libraries/libFMap/src/com/iver/cit/gvsig/fmap/MapContext.java | ||
---|---|---|
52 | 52 |
|
53 | 53 |
import javax.print.attribute.PrintRequestAttributeSet; |
54 | 54 |
|
55 |
import org.apache.log4j.Logger; |
|
55 | 56 |
import org.cresques.cts.ICoordTrans; |
56 | 57 |
import org.cresques.cts.IProjection; |
57 | 58 |
import org.cresques.geo.Projected; |
58 |
|
|
59 | 59 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
60 | 60 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
61 | 61 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
... | ... | |
70 | 70 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
71 | 71 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable; |
72 | 72 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
73 |
import com.iver.cit.gvsig.fmap.layers.order.DefaultOrderManager; |
|
74 |
import com.iver.cit.gvsig.fmap.layers.order.OrderManager; |
|
73 | 75 |
import com.iver.cit.gvsig.fmap.operations.strategies.SelectedZoomVisitor; |
74 | 76 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
75 | 77 |
import com.iver.utiles.XMLEntity; |
78 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
|
79 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
|
76 | 80 |
import com.iver.utiles.swing.threads.Cancellable; |
77 | 81 |
|
78 | 82 |
/** |
... | ... | |
136 | 140 |
public static ArrayList AREAABBR=new ArrayList(); |
137 | 141 |
public static ArrayList AREATRANS2METER=new ArrayList(); |
138 | 142 |
|
143 |
/** |
|
144 |
* <p>Note: Don't access it directly, use {@link #getOrderManager()} instead.</p> |
|
145 |
* <p>When a new layer is added to this MapContext, |
|
146 |
* the order manager will decide the right position for the |
|
147 |
* layer.</p> <p>The orderManager will only be used when adding a layer, |
|
148 |
* so it will not affect to the collection order when the user modifies the |
|
149 |
* order.</p> |
|
150 |
*/ |
|
151 |
private OrderManager orderManager = null; |
|
152 |
|
|
139 | 153 |
static{ |
140 | 154 |
addAreaUnit("Kilometros","Km",true,1000); |
141 | 155 |
addAreaUnit("Metros","m",true,1); |
... | ... | |
669 | 683 |
throw new XMLException(e); |
670 | 684 |
} |
671 | 685 |
} |
686 |
aux.setOrderManager((OrderManager)antLayers.getOrderManager().clone()); |
|
672 | 687 |
ret.layers = aux; |
673 | 688 |
return ret; |
674 | 689 |
|
... | ... | |
1130 | 1145 |
xml.putProperty("className", this.getClass().getName()); |
1131 | 1146 |
xml.addChild(viewPort.getXMLEntity()); |
1132 | 1147 |
xml.addChild(layers.getXMLEntity()); |
1133 |
|
|
1148 |
if (orderManager!=null) { |
|
1149 |
xml.putProperty(DefaultOrderManager.getExtensionPointName(), orderManager.getCode()); |
|
1150 |
XMLEntity child = orderManager.getXMLEntity(); |
|
1151 |
if (child!=null) { |
|
1152 |
child.putProperty("name", DefaultOrderManager.getExtensionPointName()); |
|
1153 |
child.putProperty("code", orderManager.getCode()); |
|
1154 |
xml.addChild(child); |
|
1155 |
} |
|
1156 |
} |
|
1134 | 1157 |
return xml; |
1135 | 1158 |
} |
1136 | 1159 |
|
... | ... | |
1178 | 1201 |
ViewPort vp = ViewPort.createFromXML(xml.getChild(0)); |
1179 | 1202 |
MapContext fmap = new MapContext(vp); |
1180 | 1203 |
fmap.layers.setXMLEntity(xml.getChild(1)); |
1181 |
|
|
1204 |
// read the orderManager |
|
1205 |
String managerKey = null; |
|
1206 |
if (xml.contains(DefaultOrderManager.getExtensionPointName())){ |
|
1207 |
managerKey = xml.getStringProperty(DefaultOrderManager.getExtensionPointName()); |
|
1208 |
} |
|
1209 |
// set if even if it's null, to ensure MapContext gets a valid Manager |
|
1210 |
fmap.setOrderManager(managerKey); |
|
1211 |
// process the rest of childs |
|
1212 |
for (int i=2; i<xml.getChildrenCount(); i++) { |
|
1213 |
XMLEntity child = xml.getChild(i); |
|
1214 |
if (child.contains("name")) { |
|
1215 |
if (child.getName().equals(DefaultOrderManager.getExtensionPointName())) { |
|
1216 |
// order manager config |
|
1217 |
fmap.getOrderManager().setXMLEntity(child); |
|
1218 |
} |
|
1219 |
// else {} // other childs may be added here |
|
1220 |
} |
|
1221 |
|
|
1222 |
} |
|
1182 | 1223 |
return fmap; |
1183 | 1224 |
} |
1184 | 1225 |
|
... | ... | |
1492 | 1533 |
if (getLayers().getLayersCount() > 0) |
1493 | 1534 |
getLayers().moveTo(0,0); |
1494 | 1535 |
} |
1536 |
|
|
1537 |
/** |
|
1538 |
* <p>Sets the OrderManager. When a new layer is added to this MapContext, |
|
1539 |
* the order manager will decide the right position for the |
|
1540 |
* layer.</p> <p>The orderManager will only be used when adding a layer, |
|
1541 |
* so it will not affect to the collection order when the user modifies the |
|
1542 |
* order.</p> |
|
1543 |
*/ |
|
1544 |
public void setOrderManager(OrderManager manager) { |
|
1545 |
this.orderManager = manager; |
|
1546 |
layers.setOrderManager(manager); |
|
1547 |
} |
|
1548 |
|
|
1549 |
/** |
|
1550 |
* <p>Returns the OrderManager. When a new layer is added to this MapContext, |
|
1551 |
* the order manager will decide the right position for the |
|
1552 |
* layer.</p> <p>The orderManager will only be used when adding a layer, |
|
1553 |
* so it will not affect to the collection order when the user modifies the |
|
1554 |
* order.</p> |
|
1555 |
* |
|
1556 |
* @return The order manager, or null if the OrderManager was not set. |
|
1557 |
*/ |
|
1558 |
public OrderManager getOrderManager() { |
|
1559 |
return orderManager; |
|
1560 |
} |
|
1561 |
|
|
1562 |
/** |
|
1563 |
* <p>Try to set the OrderManager corresponding to the provided code. |
|
1564 |
* If there is no such OrderManager in the ExtensionPoint, then sets the |
|
1565 |
* {@link DefaultOrderManager}.</p> |
|
1566 |
* |
|
1567 |
* @param managerKey The code which was used to register the |
|
1568 |
* OrderManager in the ExtensionPoint. |
|
1569 |
* |
|
1570 |
* @see OrderManger |
|
1571 |
* @see DefaultOrderManager |
|
1572 |
*/ |
|
1573 |
public void setOrderManager(String managerKey) { |
|
1574 |
if (managerKey!=null) { |
|
1575 |
ExtensionPoint ep = |
|
1576 |
(ExtensionPoint) ExtensionPointsSingleton.getInstance(). |
|
1577 |
get(DefaultOrderManager.getExtensionPointName()); |
|
1578 |
if (ep!=null) { |
|
1579 |
Object obj; |
|
1580 |
try { |
|
1581 |
obj = ep.create(managerKey); |
|
1582 |
if (obj!=null && obj instanceof OrderManager) { |
|
1583 |
setOrderManager((OrderManager) obj); |
|
1584 |
return; |
|
1585 |
} |
|
1586 |
} |
|
1587 |
catch (InstantiationException e) {} |
|
1588 |
catch (IllegalAccessException e) {} |
|
1589 |
} |
|
1590 |
} |
|
1591 |
// if the configured manager is not found, create default one |
|
1592 |
setOrderManager(DefaultOrderManager.getDefaultOrderManager()); |
|
1593 |
} |
|
1495 | 1594 |
} |
Also available in: Unified diff