Revision: 4802 http://sourceforge.net/p/jump-pilot/code/4802 Author: ma15569 Date: 2016-01-26 06:25:08 +0000 (Tue, 26 Jan 2016) Log Message: ----------- Added some boolena and string methods
Modified Paths: -------------- core/trunk/src/com/vividsolutions/jump/workbench/model/Layer.java core/trunk/src/org/openjump/core/rasterimage/RasterImageLayer.java Modified: core/trunk/src/com/vividsolutions/jump/workbench/model/Layer.java =================================================================== --- core/trunk/src/com/vividsolutions/jump/workbench/model/Layer.java 2016-01-22 11:54:12 UTC (rev 4801) +++ core/trunk/src/com/vividsolutions/jump/workbench/model/Layer.java 2016-01-26 06:25:08 UTC (rev 4802) @@ -40,7 +40,9 @@ import javax.swing.SwingUtilities; +import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.util.Assert; +import com.vividsolutions.jump.I18N; import com.vividsolutions.jump.feature.Feature; import com.vividsolutions.jump.feature.FeatureCollection; import com.vividsolutions.jump.feature.FeatureCollectionWrapper; @@ -49,7 +51,10 @@ import com.vividsolutions.jump.feature.Operation; import com.vividsolutions.jump.io.datasource.DataSourceQuery; import com.vividsolutions.jump.util.Blackboard; +import com.vividsolutions.jump.workbench.imagery.ReferencedImageStyle; import com.vividsolutions.jump.workbench.ui.plugin.AddNewLayerPlugIn; +import com.vividsolutions.jump.workbench.ui.plugin.datastore.DataStoreDataSource; +import com.vividsolutions.jump.workbench.ui.plugin.datastore.DataStoreQueryDataSource; import com.vividsolutions.jump.workbench.ui.renderer.style.BasicStyle; import com.vividsolutions.jump.workbench.ui.renderer.style.LabelStyle; import com.vividsolutions.jump.workbench.ui.renderer.style.SquareVertexStyle; @@ -587,5 +592,219 @@ } expressions = null; } + /* + * Giuseppe Aruta 25/01/2015 + * Some experimental boolean methods + */ + + /** + * @return true if the layer is a temporary layer + * Both layers in memory and layes stored into TEMP folder are considered + * as "Temporary layers" + */ + public boolean isTemporaryLayer() { + if (!hasReadableDataSource() + || getName().contains(System.getProperty("java.io.tmpdir"))) { + return true; + } else{ + return false; + } + } + + /** + * @return true if the layer has been modified + */ + public boolean isModifiedLayer() { + if (isFeatureCollectionModified()) { + return true; + } else{ + return false; + } + } + + /** + * @return true if the layer is a vector layer (eg. SHP, JML, GML) + * excluding excluding Datastores and Image layers + */ + public boolean isVectorLayer() { + if (!(getDataSourceQuery().getDataSource() instanceof DataStoreQueryDataSource) + &&((getStyle(ReferencedImageStyle.class) == null)) ) { + return true; + } else{ + return false; + } + } + + /** + * @return true if the layer is an image Layer (eg. JPG, TIF, ECW) + */ + public boolean isImageLayer() { + if (getStyle(ReferencedImageStyle.class) != null) { + return true; + } else{ + return false; + } + } + + /** + * @return true if the ayer is a collection of + * Image layers (eg. JPG, TIF, ECW) + */ + public boolean isMultipleImagesLayer() { + if (getStyle(ReferencedImageStyle.class) != null + && getFeatureCollectionWrapper().getFeatures().size()>1) { + return true; + } else{ + return false; + } + } + /** + * @return true if the layer is a datastore layer (eg. Oracle, SpatiaLite, MySQL) + */ + public boolean isDataStoreLayer() { + if (getDataSourceQuery().getDataSource() instanceof DataStoreQueryDataSource) { + return true; + } else{ + return false; + } + } + + /** + * @return true if the layer is a system Layer + * currently Fence and Measure Layers + */ + public boolean isSystemLayer() { + if (getName().equals(FenceLayerFinder.LAYER_NAME) + || getName().equals(MeasureLayerFinder.LAYER_NAME) ) { + return true; + } else{ + return false; + } + } + + /** + * @return true Check if the layer is a cad Layer + * following DXF PlugIn schema it defines Cad layer with + * the presence of COLOR and TEXT attributes + */ + public boolean isCadLayer() { + if (getFeatureCollectionWrapper().getFeatureSchema().hasAttribute("COLOR") + && getFeatureCollectionWrapper().getFeatureSchema().hasAttribute("TEXT") ) { + return true; + } else{ + return false; + } + } + /** + * @return true Check if the layer has different types of geometries (point, linestring, etc) + */ + + public boolean isMixedGeometryTypes(){ + String geoClass = ""; + FeatureCollectionWrapper fcw = getFeatureCollectionWrapper(); + Geometry geo = null; + boolean multipleGeoTypes = false; + for (@SuppressWarnings("unchecked") + Iterator<FeatureCollectionWrapper> i = fcw.getFeatures().iterator(); i.hasNext();) { + geo = ((Feature) i.next()).getGeometry(); + if (geo != null) { + if (geoClass.equals("")) + geoClass = geo.getClass().getName(); + else if (!geo.getClass().getName().equals(geoClass)) + multipleGeoTypes = true; + } + } + if (multipleGeoTypes) { + return true; + } else{ + return false; + } + } + + /** + * + * @return true if the layer is empty + */ + + public boolean isEmpy(){ + FeatureCollectionWrapper fcw = getFeatureCollectionWrapper(); + if (fcw.isEmpty()){ + return true; + } else{ + return false; + } + } + private final static String NO_FEATURES = I18N + .get("org.openjump.core.ui.plugin.layer.LayerPropertiesPlugIn.No-Features"); // no features were found + private final static String MULTIPLE_GEOMETRY_TYPES = I18N + .get("org.openjump.core.ui.plugin.layer.LayerPropertiesPlugIn.Multiple-geometry-types"); // mixed +private final static String NULL_GEOMETRIES = I18N + .get("org.openjump.core.ui.plugin.layer.LayerPropertiesPlugIn.Null-Geometries"); + + /** + * @return the geometry type of the layer (ex. point, linestring, polygon or multiple geometries) + */ + public String getGeometryType(){ + String geoClass = ""; + FeatureCollectionWrapper fcw = getFeatureCollectionWrapper(); + int numFeatures = fcw.size(); + Geometry geo = null; + boolean multipleGeoTypes = false; + for (@SuppressWarnings("unchecked") + Iterator<FeatureCollectionWrapper> i = fcw.getFeatures().iterator(); i.hasNext();) { + geo = ((Feature) i.next()).getGeometry(); + if (geo != null) { + if (geoClass.equals("")) + geoClass = geo.getClass().getName(); + else if (!geo.getClass().getName().equals(geoClass)) + multipleGeoTypes = true; + } + } + if (geoClass.equals("")) + geoClass = NULL_GEOMETRIES; + + if (numFeatures == 0) + geoClass = NO_FEATURES; + else { + if (multipleGeoTypes) { + geoClass = MULTIPLE_GEOMETRY_TYPES; + } else { + int dotPos = geoClass.lastIndexOf("."); + if (dotPos > 0) + geoClass = geoClass.substring(dotPos + 1); + } + } + return geoClass; + } + + private final static String NODATASOURCELAYER = I18N + .get("org.openjump.core.ui.plugin.layer.LayerPropertiesPlugIn.nodatasourcelayer.message"); + /** + *@return the File path of a RasterImageLayer.class + *eg. C/File/vectorname.shp + */ + public String getFilePath() { + DataSourceQuery dsq = getDataSourceQuery(); + String fileName = null; + if (dsq != null || !getName().contains(System.getProperty("java.io.tmpdir"))) { + Object fnameObj = dsq.getDataSource().getProperties() + .get("File"); + if (fnameObj == null) { + fnameObj = dsq + .getDataSource() + .getProperties() + .get(DataStoreDataSource.CONNECTION_DESCRIPTOR_KEY); + } + if (fnameObj != null) { + fileName = fnameObj.toString(); + } + } else{ + fileName = NODATASOURCELAYER; + } + + return fileName; + } + + } \ No newline at end of file Modified: core/trunk/src/org/openjump/core/rasterimage/RasterImageLayer.java =================================================================== --- core/trunk/src/org/openjump/core/rasterimage/RasterImageLayer.java 2016-01-22 11:54:12 UTC (rev 4801) +++ core/trunk/src/org/openjump/core/rasterimage/RasterImageLayer.java 2016-01-26 06:25:08 UTC (rev 4802) @@ -35,6 +35,7 @@ import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.Polygon; +import com.vividsolutions.jump.I18N; import com.vividsolutions.jump.util.Blackboard; import com.vividsolutions.jump.workbench.Logger; import com.vividsolutions.jump.workbench.WorkbenchContext; @@ -1685,5 +1686,44 @@ return uuid; } + + /* + * Giuseppe Aruta 26/01/2015 + * Some experimental boolean methods + */ + /** + * Check if selected sextante raster layer is Temporary layer + * Both layers in memory and layes stored into TEMP folder are considered + * as "Temporary layers" + */ + public boolean isTemporaryLayer() { + if (getName().contains(System.getProperty("java.io.tmpdir"))) { + return true; + } else{ + return false; + } + } + + + + private final static String NODATASOURCELAYER= I18N + .get("org.openjump.core.ui.plugin.layer.LayerPropertiesPlugIn.nodatasourcelayer.message"); + /** + *@return the file path of a RasterImageLayer.class + *eg. C/File/imagename.tif. If the file path is a TEMP folder + * it returns that the layer has no datasource + */ + public String getFilePath() { + String fileName = null; + if (!getName().contains(System.getProperty("java.io.tmpdir"))) { + fileName = getImageFileName(); + } else{ + fileName = NODATASOURCELAYER; + } + return fileName; + } + + + } ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel