Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove method from interface ILayer and update all places accordingly #619

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ static void writeContext(IMap map, BufferedWriter out) throws IOException {
append(2, out, "<ResourceList>"); //$NON-NLS-1$
for (ILayer layer : map.getMapLayers()) {
try {
if (layer.isType(Layer.class)) {
if (layer.hasResource(Layer.class)) {
writeLayer(layer, out);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering what would happen here, since WMSLayer.hasResource() is always false whereas isType was true ..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically WMSLayer.java is located into the module "org.locationtech.udig.info.tests" - so it's a test class. Does it really that matter? From my perspective we may even think about removing this class (should not belong to a test bundle).

} else if (layer.isType(WFSDataStore.class)) {
} else if (layer.hasResource(WFSDataStore.class)) {
writeFeatureType(layer, out);
} else {
// n/a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* uDig - User Friendly Desktop Internet GIS client
* http://udig.refractions.net
* (C) 2004, Refractions Research Inc.
/**
* uDig - User Friendly Desktop Internet GIS client
* http://udig.refractions.net
* (C) 2004, Refractions Research Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -43,27 +43,29 @@
*/
public class GlyphBuilder {

public static ImageDescriptor createImageDescriptor( final RenderedImage image ) {
return new ImageDescriptor(){
public static ImageDescriptor createImageDescriptor(final RenderedImage image) {
return new ImageDescriptor() {
@Override
public ImageData getImageData() {
return createImageData(image);
}
};
}
/** Create a buffered image that can be be coverted to SWTland later */
public static BufferedImage createBufferedImage( int w, int h ) {

/** Create a buffered image that can be be converted to SWTland later */
public static BufferedImage createBufferedImage(int w, int h) {
return new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR_PRE);
}
public static Image createSWTImage( RenderedImage image ) {
// Rectangle size = new Rectangle(0, 0, image.getWidth(), image.getHeight());

public static Image createSWTImage(RenderedImage image) {
ImageData data = createImageData(image);

return new org.eclipse.swt.graphics.Image(Display.getDefault(), data);
}

public static final int TRANSPARENT = 0x220000 | 0x2200 | 0x22;

public static ImageData createImageData( RenderedImage image ) {
public static ImageData createImageData(RenderedImage image) {
ImageData swtdata = null;
int width = image.getWidth();
int height = image.getHeight();
Expand All @@ -78,21 +80,17 @@ public static ImageData createImageData( RenderedImage image ) {
byte blueT = (byte) ((TRANSPARENT) & 0xFF);
byte greenT = (byte) ((TRANSPARENT >> 8) & 0xFF);
byte redT = (byte) ((TRANSPARENT >> 16) & 0xFF);
// System.out.println("red="+redT+"blue"+blueT+"green"+greenT);
// System.out.println("Transparent"+TRANSPARENT);

// awtImage2.getRGB();
Raster raster = image.getData();
int[] awtdata = raster.getPixels(0, 0, width, height, new int[width * height * 3]);// raster.getNumBands()]);
int[] awtdata = raster.getPixels(0, 0, width, height, new int[width * height * 3]);
int step = swtdata.depth / 8;

byte[] data = swtdata.data;
int baseindex = 0;
// System.out.println( "AWT size:" + awtdata.length );
for( int y = 0; y < height; y++ ) {
for (int y = 0; y < height; y++) {
int idx = ((0 + y) * swtdata.bytesPerLine) + (0 * step);

for( int x = 0; x < width; x++ ) {
for (int x = 0; x < width; x++) {
baseindex = (x + (y * width)) * 4;

if (awtdata[baseindex + 3] == 0) {
Expand All @@ -108,22 +106,23 @@ public static ImageData createImageData( RenderedImage image ) {
}
return swtdata;
}
public ImageDescriptor createWMSGylph( Layer target ) {
if (target.isType(WebMapServer.class))

public ImageDescriptor createWMSGylph(Layer target) {
if (target.hasResource(WebMapServer.class))
return null;
try {
WebMapServer wms = target.getResource(WebMapServer.class, null);
org.geotools.ows.wms.Layer layer = target.getResource(
org.geotools.ows.wms.Layer.class, null);
org.geotools.ows.wms.Layer layer = target.getResource(org.geotools.ows.wms.Layer.class,
null);

if (wms.getCapabilities().getRequest().getGetLegendGraphic() != null) {

GetLegendGraphicRequest request = wms.createGetLegendGraphicRequest();
request.setLayer(layer.getName());

String desiredFormat = null;
List formats = wms.getCapabilities().getRequest()
.getGetLegendGraphic().getFormats();
List formats = wms.getCapabilities().getRequest().getGetLegendGraphic()
.getFormats();
if (formats.contains("image/png")) { //$NON-NLS-1$
desiredFormat = "image/png"; //$NON-NLS-1$
}
Expand All @@ -141,13 +140,9 @@ public ImageDescriptor createWMSGylph( Layer target ) {
// darn
}
return null;
/*
* BufferedImage image = createBufferedImage( target, 16, 16); Graphics2D g2 = (Graphics2D)
* image.getGraphics(); g2.setColor(Color.GREEN); g2.fillRect(1, 1, 14, 14);
* g2.setColor(Color.BLACK); g2.drawRect(0, 0, 15, 15); return createImageDescriptor(image);
*/
}
private SimpleFeature sampleFeature( Layer layer ) {

private SimpleFeature sampleFeature(Layer layer) {
FeatureIterator<SimpleFeature> reader = null;
try {
reader = layer.getResource(FeatureSource.class, null).getFeatures().features();
Expand All @@ -163,7 +158,7 @@ private SimpleFeature sampleFeature( Layer layer ) {
}
}

public Image createGlyph( Layer layer, Style styleObject ) {
public Image createGlyph(Layer layer, Style styleObject) {
int width = 16;
int height = 16;

Expand All @@ -172,93 +167,20 @@ public Image createGlyph( Layer layer, Style styleObject ) {
ViewportGraphics graphics = Drawing.createGraphics(new GC(image), Display.getDefault(),
new Dimension(width - 1, width - 1));
graphics.clearRect(0, 0, width, height);
// graphics.clearRect(0,0,16,16);
AffineTransform transform = Drawing.worldToScreenTransform(feature.getBounds(),
new Rectangle(1, 0, width - 1, width - 1));
// Drawing.createGraphics(image.createGraphics());
Drawing.create().drawFeature(graphics, feature, transform, styleObject);
// return createSWTImage(image);
return image;
// StyleImpl imp = (StyleImpl) styleObject;
// FeatureTypeStyle style = imp.getFeatureTypeStyles()[0];
// Rule rule = style.getRules()[0];
// Symbolizer symbolizer = rule.getSymbolizers()[0];
// SimpleFeature feature = sampleFeature( layer );
//
// if (symbolizer instanceof LineSymbolizer) {
// try {
// LineSymbolizer line = (LineSymbolizer) symbolizer;
// Stroke stroke = line.getStroke();
// Color color = stroke.getColor(feature);
//
// BufferedImage image = createBufferedImage( layer, 16, 16);
// Graphics2D g2 = (Graphics2D) image.getGraphics();
// g2.setColor(color);
// g2.drawArc(4, 4, 24, 24, 90, 90);
// g2.drawLine(0, 2, 11, 11);
// g2.drawLine(11, 11, 15, 8);
//
// g2.setColor(Color.BLACK);
// g2.drawRect(0, 0, 15, 15);
// return createImageDescriptor(image);
// } catch (Exception e) {
// BufferedImage image = createBufferedImage(16, 16);
// Graphics2D g2 = (Graphics2D) image.getGraphics();
// g2.setColor(Color.BLACK);
// g2.drawArc(4, 4, 24, 24, 90, 90);
// g2.drawLine(0, 2, 11, 11);
// g2.drawLine(11, 11, 15, 8);
//
// g2.setColor(Color.BLACK);
// g2.drawRect(0, 0, 15, 15);
// return createImageDescriptor(image);
// }
// } else if (symbolizer instanceof PolygonSymbolizer) {
// try {
// PolygonSymbolizer poly = (PolygonSymbolizer) symbolizer;
// Stroke stroke = poly.getStroke();
// Color color = stroke.getColor(feature);
// Fill fill = poly.getFill();
// Paint fillColor = (Paint) fill.getColor().getValue(feature);
//
// BufferedImage image = createBufferedImage( layer, 16, 16);
// Graphics2D g2 = (Graphics2D) image.getGraphics();
// g2.setPaint(fillColor);
// g2.fillArc(4, 4, 24, 24, 90, 90);
// g2.setPaint(color);
// g2.drawArc(4, 4, 24, 24, 90, 90);
//
// g2.setColor(Color.BLACK);
// g2.drawRect(0, 0, 16, 16);
// return createImageDescriptor(image);
// } catch (Exception e) {
// BufferedImage image = createBufferedImage( layer, 16, 16);
// Graphics2D g2 = (Graphics2D) image.getGraphics();
//
// g2.setColor(Color.BLACK);
// g2.drawRect(2, 2, 11, 11);
// g2.setColor(Color.BLUE);
// g2.fillRect(3, 3, 10, 10);
//
// g2.setColor(Color.BLACK);
// g2.drawRect(0, 0, 15, 15);
// return createImageDescriptor(image);
// }
// }
// return null;
}
public Object createGlyph( Layer layer ) {

public Object createGlyph(Layer layer) {
try {
ImageDescriptor glyph;
if (layer.isType(WebMapServer.class)) {
if (layer.hasResource(WebMapServer.class)) {
glyph = createWMSGylph(layer);
if (glyph != null)
return glyph;
}
/*
* // This so does not work right now if (layer.getStyle() != null) { glyph =
* createGylph( layer, layer.getStyle() ); if( glyph != null ) return glyph; }
*/
} catch (Throwable t) {
t.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* uDig - User Friendly Desktop Internet GIS client
* http://udig.refractions.net
* (C) 2004, Refractions Research Inc.
/**
* uDig - User Friendly Desktop Internet GIS client
* http://udig.refractions.net
* (C) 2004, Refractions Research Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -29,7 +29,7 @@

/**
* Counts all the features that are within the current view.
*
*
* @author jeichar
* @since 1.0
*/
Expand All @@ -39,23 +39,25 @@ public class FeaturesInView implements IOp {
* @see org.locationtech.udig.ui.operations.IOp#op(org.eclipse.swt.widgets.Display,
* java.lang.Object, org.eclipse.core.runtime.IProgressMonitor)
*/
public void op( final Display display, Object target, IProgressMonitor monitor )
@Override
public void op(final Display display, Object target, IProgressMonitor monitor)
throws Exception {
IMap map = (IMap) target;

Exception e = null;

int featureCount = 0;
for( ILayer layer : map.getMapLayers() ) {
if (layer.isType(FeatureSource.class) && layer.isVisible()) {
for (ILayer layer : map.getMapLayers()) {
if (layer.hasResource(FeatureSource.class) && layer.isVisible()) {
try {
FeatureSource<SimpleFeatureType, SimpleFeature> source = layer.getResource(FeatureSource.class, monitor);
FeatureSource<SimpleFeatureType, SimpleFeature> source = layer
.getResource(FeatureSource.class, monitor);
Filter filter = layer.createBBoxFilter(map.getViewportModel().getBounds(),
monitor);
FeatureCollection<SimpleFeatureType, SimpleFeature> results = source.getFeatures(new Query(layer.getSchema()
.getName().getLocalPart(), filter));
FeatureCollection<SimpleFeatureType, SimpleFeature> results = source
.getFeatures(
new Query(layer.getSchema().getName().getLocalPart(), filter));
int count = results.size();
// FeatureReader<SimpleFeatureType, SimpleFeature> reader=results.reader()
if (count > 0) {
featureCount += count;
}
Expand All @@ -69,17 +71,16 @@ public void op( final Display display, Object target, IProgressMonitor monitor )
final Exception exception = e;
final int finalCount = featureCount;

display.asyncExec(new Runnable(){
display.asyncExec(new Runnable() {
@Override
public void run() {
if (exception == null)
MessageDialog.openInformation(display.getActiveShell(),
Messages.FeaturesInView_0,
Messages.FeaturesInView_1 + finalCount);
MessageDialog.openInformation(display.getActiveShell(),
Messages.FeaturesInView_0, Messages.FeaturesInView_1 + finalCount);
else
MessageDialog.openInformation(display.getActiveShell(),
Messages.FeaturesInView_0,
MessageFormat.format(Messages.FeaturesInView_3, new Object[] {finalCount})
);
MessageDialog.openInformation(display.getActiveShell(),
Messages.FeaturesInView_0, MessageFormat.format(
Messages.FeaturesInView_3, new Object[] { finalCount }));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,6 @@ public interface ILayer extends ILegendItem, Comparable<ILayer> {
*/
public <T> boolean hasResource(Class<T> resourceType);

/**
* @see #hasResource(Class)
*
* @deprecated use {@link #hasResource(Class)}
*/
@Deprecated
public <T> boolean isType(Class<T> resourceType);

/**
* Returns a <i>real</i> resource that one of the GeoResources can resolved to.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,15 +588,6 @@ public void setMaxScaleDenominator(double value) {
layer.setMaxScaleDenominator(value);
}

/**
* @deprecated
*/
@Deprecated
@Override
public <T> boolean isType(Class<T> resourceType) {
return layer.hasResource(resourceType);
}

@Override
public <T> boolean hasResource(Class<T> resourceType) {
return layer.hasResource(resourceType);
Expand Down
Loading