private void applyStyle() { StyleLayer layer = getSelectedLayer(); Style newStyle = propertiesEditor.getStyle(); List<FeatureTypeStyle> featureTypeStyles = newStyle.featureTypeStyles(); int ftsNum = featureTypeStyles.size(); if (ftsNum < 1) { MessageDialog.openWarning( getShell(), Messages.SimplePointEditorPage_1, Messages.SimplePointEditorPage_2); style = oldStyle; setStyle(oldStyle); layer.revertAll(); layer.apply(); StyleEditorDialog dialog = (StyleEditorDialog) getContainer(); dialog.getCurrentPage().refresh(); return; } newStyle.setName(layer.getName()); setStyle(newStyle); StyleBlackboard styleBlackboard = layer.getStyleBlackboard(); styleBlackboard.put(SLDContent.ID, newStyle); }
@Override protected void refresh() { System.out.println("refresh"); // $NON-NLS-1$ //TODO erase this line IBlackboard blackboard = getStyleBlackboard(); LegendStyle style = (LegendStyle) blackboard.get(LegendStyleContent.ID); if (style == null) { style = LegendStyleContent.createDefault(); blackboard.put(LegendStyleContent.ID, style); ((StyleBlackboard) blackboard).setSelected(new String[] {LegendStyleContent.ID}); } }
@Override public void createPageContent(Composite parent) { mainComposite = new Composite(parent, SWT.NONE); mainComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); stackLayout = new StackLayout(); mainComposite.setLayout(stackLayout); noFeatureLabel = new Label(mainComposite, SWT.NONE); noFeatureLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); noFeatureLabel.setText(Messages.SimplePointEditorPage_0); StyleLayer layer = getSelectedLayer(); IGeoResource resource = layer.getGeoResource(); if (resource.canResolve(FeatureSource.class)) { StyleBlackboard styleBlackboard = layer.getStyleBlackboard(); oldStyle = (Style) styleBlackboard.get(SLDContent.ID); if (oldStyle == null) { oldStyle = Utilities.createDefaultPointStyle(); } DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor(); dsv.visit(oldStyle); style = (Style) dsv.getCopy(); if (isPointStyle(style)) { propertiesEditor = new PointPropertiesEditor(layer); propertiesEditor.open(mainComposite, style); stackLayout.topControl = propertiesEditor.getControl(); } else { stackLayout.topControl = noFeatureLabel; } } else { stackLayout.topControl = noFeatureLabel; } }
public void refresh() { Layer layer = getSelectedLayer(); IGeoResource resource = layer.getGeoResource(); if (!resource.canResolve(FeatureSource.class)) { return; } StyleBlackboard styleBlackboard = layer.getStyleBlackboard(); oldStyle = (Style) styleBlackboard.get(SLDContent.ID); if (oldStyle == null) { oldStyle = Utilities.createDefaultPointStyle(); } DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor(); dsv.visit(oldStyle); style = (Style) dsv.getCopy(); if (!isPointStyle(style)) { stackLayout.topControl = noFeatureLabel; } else { stackLayout.topControl = propertiesEditor.getControl(); propertiesEditor.updateStyle(style); } mainComposite.layout(); }
private void updateBlackboard() { IBlackboard blackboard = getStyleBlackboard(); LegendStyle style = (LegendStyle) blackboard.get(LegendStyleContent.ID); if (style == null) { style = LegendStyleContent.createDefault(); blackboard.put(LegendStyleContent.ID, style); ((StyleBlackboard) blackboard).setSelected(new String[] {LegendStyleContent.ID}); } RGB bg = backgroundColour.getColorValue(); style.backgroundColour = new Color(bg.red, bg.green, bg.blue); RGB fg = fontColour.getColorValue(); style.foregroundColour = new Color(fg.red, fg.green, fg.blue); style.horizontalMargin = Integer.parseInt(horizontalMargin.getText()); style.horizontalSpacing = Integer.parseInt(horizontalSpacing.getText()); style.indentSize = Integer.parseInt(indentSize.getText()); style.verticalMargin = Integer.parseInt(verticalMargin.getText()); style.verticalSpacing = Integer.parseInt(verticalSpacing.getText()); }
public void createControl(Composite parent) { IBlackboard blackboard = getStyleBlackboard(); LegendStyle style = null; if (blackboard != null) { style = (LegendStyle) blackboard.get(LegendStyleContent.ID); } if (style == null) { style = LegendStyleContent.createDefault(); if (blackboard != null) { blackboard.put(LegendStyleContent.ID, style); ((StyleBlackboard) blackboard).setSelected(new String[] {LegendStyleContent.ID}); } } ScrolledComposite scrollComposite = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); Composite composite = new Composite(scrollComposite, SWT.BORDER); GridLayout layout = new GridLayout(2, true); composite.setLayout(layout); GridData layoutData = null; Label verticalMarginLabel = new Label(composite, SWT.NONE); verticalMarginLabel.setText(Messages.LegendGraphicStyleConfigurator_vertical_margin); verticalMarginLabel.setLayoutData(layoutData); verticalMargin = new Text(composite, SWT.BORDER); verticalMargin.setLayoutData(layoutData); Label horizontalMarginLabel = new Label(composite, SWT.NONE); horizontalMarginLabel.setLayoutData(layoutData); horizontalMarginLabel.setText(Messages.LegendGraphicStyleConfigurator_horizontal_margin); horizontalMargin = new Text(composite, SWT.BORDER); horizontalMargin.setLayoutData(layoutData); Label verticalSpacingLabel = new Label(composite, SWT.NONE); verticalSpacingLabel.setLayoutData(layoutData); verticalSpacingLabel.setText(Messages.LegendGraphicStyleConfigurator_vertical_spacing); verticalSpacing = new Text(composite, SWT.BORDER); verticalSpacing.setLayoutData(layoutData); Label horizontalSpacingLabel = new Label(composite, SWT.NONE); horizontalSpacingLabel.setLayoutData(layoutData); horizontalSpacingLabel.setText(Messages.LegendGraphicStyleConfigurator_horizontal_spacing); horizontalSpacing = new Text(composite, SWT.BORDER); horizontalSpacing.setLayoutData(layoutData); Label indentSizeLabel = new Label(composite, SWT.NONE); indentSizeLabel.setLayoutData(layoutData); indentSizeLabel.setText(Messages.LegendGraphicStyleConfigurator_indent_size); indentSize = new Text(composite, SWT.BORDER); indentSize.setLayoutData(layoutData); Label fontColourLabel = new Label(composite, SWT.NONE); fontColourLabel.setLayoutData(layoutData); fontColourLabel.setText(Messages.LegendGraphicStyleConfigurator_font_colour); fontColour = new ColorEditor(composite); Label backgroundColourLabel = new Label(composite, SWT.NONE); backgroundColourLabel.setLayoutData(layoutData); backgroundColourLabel.setText(Messages.LegendGraphicStyleConfigurator_background_colour); backgroundColour = new ColorEditor(composite); composite.layout(); Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); composite.setSize(size); scrollComposite.setContent(composite); verticalMargin.setText(Integer.toString(style.verticalMargin)); horizontalMargin.setText(Integer.toString(style.horizontalMargin)); verticalSpacing.setText(Integer.toString(style.verticalSpacing)); horizontalSpacing.setText(Integer.toString(style.horizontalSpacing)); indentSize.setText(Integer.toString(style.indentSize)); fontColour.setColorValue( new RGB( style.foregroundColour.getRed(), style.foregroundColour.getGreen(), style.foregroundColour.getBlue())); backgroundColour.setColorValue( new RGB( style.backgroundColour.getRed(), style.backgroundColour.getGreen(), style.backgroundColour.getBlue())); verticalMargin.addModifyListener(this); horizontalMargin.addModifyListener(this); verticalSpacing.addModifyListener(this); horizontalSpacing.addModifyListener(this); indentSize.addModifyListener(this); backgroundColour.addSelectionListener(this); fontColour.addSelectionListener(this); }
public synchronized void render( Graphics2D destination, ReferencedEnvelope bounds, IProgressMonitor monitor) throws RenderException { int endLayerStatus = ILayer.DONE; try { if (bounds == null || bounds.isNull()) { bounds = getContext().getImageBounds(); } if (monitor.isCanceled()) return; getContext().setStatus(ILayer.WAIT); WebMapServer wms = getWMS(); GetMapRequest request = wms.createGetMapRequest(); // put in default exception format we understand as a client // (if suppoted by the server) WMSCapabilities capabilities = wms.getCapabilities(); if (capabilities .getRequest() .getGetMap() .getFormats() .contains(GetMapRequest.EXCEPTION_XML)) { request.setExceptions(GetMapRequest.EXCEPTION_XML); } setImageFormat(wms, request); if (monitor.isCanceled()) return; double currScale = getContext().getViewportModel().getScaleDenominator(); List<ILayer> layers = getLayers(); for (int i = layers.size() - 1; i >= 0; i--) { ILayer ilayer = layers.get(i); Layer layer; double minScale = 0; double maxScale = Double.MAX_VALUE; layer = ilayer.getResource(org.geotools.data.ows.Layer.class, null); // check if there are min/max scale rules StyleBlackboard sb = (StyleBlackboard) ilayer.getStyleBlackboard(); Style style = (Style) sb.lookup(Style.class); if (style != null) { Rule rule = style.getFeatureTypeStyles()[0].getRules()[0]; minScale = rule.getMinScaleDenominator(); maxScale = rule.getMaxScaleDenominator(); } if (currScale >= minScale && currScale <= maxScale) { // check for a wms style StyleImpl wmsStyle = (StyleImpl) ilayer.getStyleBlackboard().get(WMSStyleContent.WMSSTYLE); if (wmsStyle != null) { request.addLayer(layer, wmsStyle); } else { request.addLayer(layer); } } } if (monitor.isCanceled()) return; List<Layer> wmsLayers = getWMSLayers(); if (wmsLayers == null || wmsLayers.isEmpty()) { endLayerStatus = ILayer.WARNING; return; } // figure out request CRS String requestCRScode = findRequestCRS(wmsLayers, getViewportCRS(), getContext().getMap()); // TODO: make findRequestCRS more efficient (we are running CRS.decode at *least* twice) CoordinateReferenceSystem requestCRS = CRS.decode(requestCRScode); // figure out viewport // ReferencedEnvelope viewport; // Envelope viewportBBox = getViewportBBox(); // CoordinateReferenceSystem viewportCRS = getViewportCRS(); // if (viewportBBox == null) { // // change viewport to world // viewportBBox = new Envelope(-180, 180, -90, 90); // if (!DefaultGeographicCRS.WGS84.equals(viewportCRS)) { // reproject // viewport = new ReferencedEnvelope(viewportBBox, // DefaultGeographicCRS.WGS84); // viewportBBox = viewport.transform(viewportCRS, true); // } // } ReferencedEnvelope requestBBox = null; Envelope backprojectedBBox = null; // request bbox projected to the viewport crs // viewport = new ReferencedEnvelope(viewportBBox, viewportCRS); // requestBBox = calculateRequestBBox(wmsLayers, viewport, requestCRS); requestBBox = calculateRequestBBox(wmsLayers, bounds, requestCRS, capabilities.getVersion()); // check that a request is needed (not out of a bounds, invalid, etc) if (requestBBox == NILL_BOX) { endLayerStatus = ILayer.WARNING; return; } assert requestBBox.getCoordinateReferenceSystem().equals(requestCRS); if (requestBBox.getCoordinateReferenceSystem().equals(getViewportCRS())) { backprojectedBBox = (Envelope) requestBBox; } else { backprojectedBBox = (Envelope) requestBBox.transform(getViewportCRS(), true); } if (WMSPlugin.isDebugging(Trace.RENDER)) { WMSPlugin.trace("Viewport CRS: " + getViewportCRS().getName()); // $NON-NLS-1$ WMSPlugin.trace("Request CRS: " + requestCRS.getName()); // $NON-NLS-1$ WMSPlugin.trace("Context Image bounds: " + getContext().getImageBounds()); // $NON-NLS-1$ WMSPlugin.trace("Request BBox bounds: " + requestBBox); // $NON-NLS-1$ WMSPlugin.trace("Backprojected request bounds: " + backprojectedBBox); // $NON-NLS-1$ } Service wmsService = capabilities.getService(); Dimension maxDimensions = new Dimension(wmsService.getMaxWidth(), wmsService.getMaxHeight()); // Dimension imageDimensions = // calculateImageDimensions(getContext().getMapDisplay() // .getDisplaySize(), maxDimensions, getViewportBBox(), backprojectedBBox); Dimension imageDimensions = calculateImageDimensions( getContext().getImageSize(), maxDimensions, bounds, backprojectedBBox); if (imageDimensions.height < 1 || imageDimensions.width < 1) { endLayerStatus = ILayer.WARNING; return; } request.setDimensions( imageDimensions.width + "", imageDimensions.height + ""); // $NON-NLS-1$ //$NON-NLS-2$ // epsg could be under identifiers or authority. Set<ReferenceIdentifier> identifiers = requestCRS.getIdentifiers(); String srs = identifiers.isEmpty() ? EPSG_4326 : identifiers.iterator().next().toString(); request.setSRS(srs); // EPSG_4326 request.setBBox(requestBBox); // request.setBBox(requestBBox.getMinX() + "," + requestBBox.getMinY()+ "," + // requestBBox.getMaxX()+ "," + requestBBox.getMaxY()); if (monitor.isCanceled()) return; setFilter(wms, request); // request.setProperty("DACS_ACS", null); BufferedImage image = readImage(wms, request, monitor); if (monitor.isCanceled()) return; if (image == null) { Exception e = new RuntimeException(Messages.BasicWMSRenderer2_unable_to_decode_image); throw wrapException(e); } // backprojectedBBox or viewportBBox renderGridCoverage(destination, backprojectedBBox, imageDimensions, requestBBox, image); } catch (Exception e) { if (e instanceof RenderException) throw (RenderException) e; throw new RenderException(e); } finally { getContext().setStatus(endLayerStatus); if (endLayerStatus == ILayer.DONE) { // clear the status message (rendering was successful) getContext().setStatusMessage(null); } } }