Package org.locationtech.udig.ui.graphics

Examples of org.locationtech.udig.ui.graphics.ViewportGraphics


   
    public void drawDirect( Image image, Display display, SimpleFeature feature,
            Rule rule ){
        AffineTransform worldToScreenTransform = new AffineTransform();
       
        ViewportGraphics graphics = createSWTGraphics(image, display);
    drawFeature( graphics, feature,
                worldToScreenTransform, false, getSymbolizers(rule), null);
    graphics.dispose();
    }
View Full Code Here


        this.maxWidth = legendStyle.legendWidth;

        locationStyle.x = legendStyle.xPos;
        locationStyle.y = legendStyle.yPos;

        final ViewportGraphics graphics = context.getGraphics();
        GC gc = graphics.getGraphics(GC.class);
        if (gc != null) {
            gc.setAntialias(SWT.ON);
        }

        final int rowHeight = Math.max(boxHeight, graphics.getFontHeight()); // space allocated to
        // each layer
        Font oldFont = fontStyle.getFont();

        int fontHeight = rowHeight < 12 ? 8 : rowHeight - 8;
        Font font = new Font(oldFont.getName(), fontStyle.getFont().getStyle(), fontHeight);
        if (font != null) {
            graphics.setFont(font);
        } else {
            graphics.setFont(fontStyle.getFont());
        }

        List<Map<ILayer, FeatureTypeStyle[]>> layers = new ArrayList<Map<ILayer, FeatureTypeStyle[]>>();

        int longestRow = 0; // used to calculate the width of the graphic
        final int[] numberOfEntries = new int[1]; // total number of entries to draw
        numberOfEntries[0] = 0;
        /*
         * Set up the layers that we want to draw so we can operate just on
         * those ones. Layers at index 0 are on the bottom of the map, so we
         * must iterate in reverse.
         *
         * While we are doing this, determine the longest row so we can properly
         * draw the graphic's border.
         */
        for( int i = context.getMapLayers().size() - 1; i >= 0; i-- ) {
            ILayer layer = context.getMapLayers().get(i);
            IGeoResource geoResource = layer.getGeoResource();
            boolean isMapgraphic = geoResource.canResolve(MapGraphicResource.class);
            if (!isMapgraphic && layer.isVisible()) {

                // String layerName = LayerGeneratedGlyphDecorator.generateLabel((Layer) layer);
                String layerName = layer.getName();
                if (layerName != null && layerName.length() != 0) {

                    FeatureTypeStyle[] styles = locateStyle(layer);

                    if (styles != null && rules(styles).size() > 0) {
                        numberOfEntries[0] += rules(styles).size();

                        List<Rule> rules = rules(styles);
                        for( Rule rule : rules ) {
                            String text = getText(rule);
                            Rectangle2D bounds = graphics.getStringBounds(text);
                            int length = indentSize + boxWidth + horizontalSpacing
                                    + (int) bounds.getWidth();

                            if (length > longestRow) {
                                longestRow = length;
                            }
                        }
                    } else if (!layer.hasResource(MapGraphic.class)) {
                        // TODO for other layer types
                        continue;
                    } else {
                        continue;
                    }

                    Map<ILayer, FeatureTypeStyle[]> map = Collections.singletonMap(layer, styles);
                    layers.add(map);
                    if (styles != null && rules(styles).size() > 1) {
                        numberOfEntries[0]++; // add a line for the layer label
                    }
                    Rectangle2D bounds = graphics.getStringBounds(layerName);
                    int length = (int) bounds.getWidth();
                    if (styles != null && rules(styles).size() < 2) {
                        length += boxWidth + horizontalSpacing;
                    }

                    if (length > longestRow) {
                        longestRow = length;
                    }
                }
            }
        }

        if (numberOfEntries[0] == 0) {
            // nothing to draw!
            return;
        }

        // total width of the graphic
        int width = longestRow + horizontalMargin * 2;
        if (maxWidth > 0) {
            if (maxWidth > width) {
                width = maxWidth;
            }
            // width = Math.min(width, maxWidth);
        }
        // total height of the graphic
        int height = rowHeight * numberOfEntries[0] + verticalMargin * 2 + verticalSpacing
                * (numberOfEntries[0] - 1);
        if (maxHeight > 0) {
            if (maxHeight > height) {
                height = maxHeight;
            }
            // height = Math.min(height, maxHeight);
        }

        if (locationStyle.width < 1 || locationStyle.getHeight() < 1) {
            // we want to grow and shrink as we desire so we'll use a different
            // rectangle than the one on the blackboard.
            int x = locationStyle.x;
            int y = locationStyle.y;
            locationStyle = new Rectangle();
            locationStyle.x = x;
            locationStyle.y = y;
            locationStyle.width = width;
            locationStyle.height = height;
        }
        // ensure box within the display
        Dimension displaySize = context.getMapDisplay().getDisplaySize();
        if (locationStyle.x < 0) {
            locationStyle.x = displaySize.width - locationStyle.width + locationStyle.x;
        }
        if ((locationStyle.x + locationStyle.width + 6) > displaySize.width) {
            locationStyle.x = displaySize.width - width - 5;
        }

        if (locationStyle.y < 0) {
            locationStyle.y = displaySize.height - locationStyle.height - 5 + locationStyle.y;
        }
        if ((locationStyle.y + height + 6) > displaySize.height) {
            locationStyle.y = displaySize.height - locationStyle.height - 5;
        }

        graphics.setClip(new Rectangle(locationStyle.x, locationStyle.y, locationStyle.width + 1,
                locationStyle.height + 1));

        /*
         * Draw the box containing the layers/icons
         */
        drawOutline(graphics, context, locationStyle);

        /*
         * Draw the layer names/icons
         */
        final int[] rowsDrawn = new int[1];
        rowsDrawn[0] = 0;
        final int[] x = new int[1];
        x[0] = locationStyle.x + horizontalMargin;
        final int[] y = new int[1];
        y[0] = locationStyle.y + verticalMargin;

        for( int i = 0; i < layers.size(); i++ ) {
            Map<ILayer, FeatureTypeStyle[]> map = layers.get(i);
            final ILayer layer = map.keySet().iterator().next();
            final FeatureTypeStyle[] styles = map.values().iterator().next();

            final String layerName = layer.getName();

            PlatformGIS.syncInDisplayThread(new Runnable(){
                public void run() {
                    if (styles != null && rules(styles).size() > 1) {
                        drawRow(graphics, x[0], y[0], null, layerName, false);

                        y[0] += rowHeight;
                        if ((rowsDrawn[0] + 1) < numberOfEntries[0]) {
                            y[0] += verticalSpacing;
                        }
                        rowsDrawn[0]++;
                        List<Rule> rules = rules(styles);
                        for( Rule rule : rules ) {

                            BufferedImage awtIcon = null;
                            if (layer.hasResource(FeatureSource.class) && rule != null) {
                                SimpleFeatureType type = layer.getSchema();
                                GeometryDescriptor geom = type.getGeometryDescriptor();
                                if (geom != null) {
                                    Class geom_type = geom.getType().getBinding();
                                    if (geom_type == Point.class || geom_type == MultiPoint.class) {
                                        awtIcon = point(rule, boxWidth, boxHeight);
                                    } else if (geom_type == LineString.class
                                            || geom_type == MultiLineString.class) {
                                        awtIcon = line(rule, boxWidth, boxHeight);
                                    } else if (geom_type == Polygon.class
                                            || geom_type == MultiPolygon.class) {
                                        awtIcon = polygon(rule, boxWidth, boxHeight);
                                    } else if (geom_type == Geometry.class
                                            || geom_type == GeometryCollection.class) {
                                        awtIcon = geometry(rule, boxWidth, boxHeight);
                                    } else {
                                        continue;
                                    }
                                }
                            }
                            // swtIcon = LayerGeneratedGlyphDecorator.generateStyledIcon(layer,
                            // rule)
                            // .createImage();

                            drawRow(graphics, x[0], y[0], awtIcon, getText(rule), true);

                            y[0] += rowHeight;
                            if ((rowsDrawn[0] + 1) < numberOfEntries[0]) {
                                y[0] += verticalSpacing;
                            }
                            rowsDrawn[0]++;
                        }
                    } else {
                        BufferedImage awtIcon = generateIcon((Layer) layer, boxWidth, boxHeight);

                        drawRow(graphics, x[0], y[0], awtIcon, layerName, false);

                        y[0] += rowHeight;
                        if ((rowsDrawn[0] + 1) < numberOfEntries[0]) {
                            y[0] += verticalSpacing;
                        }
                        rowsDrawn[0]++;
                    }

                }
            });
        }
        // clear the clip so we don't affect other rendering processes
        graphics.setClip(null);
    }
View Full Code Here

            e.printStackTrace();
            context.getLayer().setStatus(ILayer.ERROR);
            return;
        }

        final ViewportGraphics graphics = context.getGraphics();

        /* Draw the legend. */
        if (categories.size() == 0 || categories.size() != colorRules.size()) {
            // draw a color ramp legend

            int rulesNum = colorRules.size();

            // get initially the text properties from the title
            String titleString = legendStyle.titleString;
            int textheight = (int) round(graphics.getStringBounds(titleString).getHeight());
            if (titleString.length() == 0)
                textheight = 0;

            int w = round(legendStyle.legendWidth);
            int h = round(legendStyle.legendHeight);
            int x = round(legendStyle.xPos);
            int y = round(legendStyle.yPos);

            int bWidth = round(legendStyle.boxWidth);
            /*
             * calculate the boxheight from:
             * legendHeight = 1/2 bHeight + textHeight + 1/2 bHeight + rulseNum*bHeight + 1/2 bHeight
             */
            int bHeight = round((h - textheight) / (3f / 2f + rulesNum));
            int yInset = bHeight / 2;
            int xInset = 15;

            int currentX = x + xInset;
            int currentY = y + yInset + textheight;
            if (textheight == 0) {
                currentY = y;
                h = h - yInset;
            }

            if (legendStyle.isRoundedRectangle) {
                graphics.setColor(legendStyle.backgroundColor);
                graphics.fillRoundRect(round(x), round(y), round(w), round(h), 15, 15);
                graphics.setColor(legendStyle.foregroundColor);
                graphics.setBackground(legendStyle.backgroundColor);
                graphics.drawRoundRect(round(x), round(y), round(w), round(h), 15, 15);
            } else {
                graphics.setColor(legendStyle.backgroundColor);
                graphics.fillRect(round(x), round(y), round(w), round(h));
                graphics.setColor(legendStyle.foregroundColor);
                graphics.setBackground(legendStyle.backgroundColor);
                graphics.drawRect(round(x), round(y), round(w), round(h));
            }

            // draw the title
            if (textheight != 0) {
                graphics.setColor(legendStyle.fontColor);
                graphics.drawString(titleString, currentX,// +horizontalMargin,
                        currentY,// +textVerticalOffset,
                        ViewportGraphics.ALIGN_LEFT, ViewportGraphics.ALIGN_LEFT);
            }
            currentY = currentY + yInset;

            for( int i = 0; i < colorRules.size(); i++ ) {
                String rule = colorRules.get(i);

                double[] values = new double[2];
                Color[] colors = new Color[2];
                JGrassColorTable.parseColorRule(rule, values, colors);

                String firstValue = String.valueOf(values[0]);
                Color actualColor = colors[0];

                String secondValue = String.valueOf(values[1]);
                Color nextColor = colors[1];

                graphics.fillGradientRectangle(currentX, currentY, bWidth, bHeight, actualColor, nextColor, true);

                int tx = round(currentX + 1.5f * bWidth);
                graphics.setColor(legendStyle.fontColor);
                graphics.drawString(String.format("%-8.2f", Float.parseFloat(firstValue)), //$NON-NLS-1$
                        tx,// +horizontalMargin,
                        currentY, // - graphics.getFontAscent(),// +textVerticalOffset,
                        ViewportGraphics.ALIGN_LEFT, ViewportGraphics.ALIGN_MIDDLE);

                currentY = currentY + bHeight;

                if (i == colorRules.size() - 1) {
                    // add also last text
                    tx = round(currentX + 1.5f * bWidth);
                    graphics.setColor(legendStyle.fontColor);
                    graphics.drawString(String.format("%-8.2f", Float.parseFloat(secondValue)), //$NON-NLS-1$
                            tx,// +horizontalMargin,
                            currentY, // - graphics.getFontAscent(),// +textVerticalOffset,
                            ViewportGraphics.ALIGN_LEFT, ViewportGraphics.ALIGN_MIDDLE);
                }

            }

        } else {

            // draw a categories legend
            int rulesNum = colorRules.size();

            // get initially the text properties from the title
            String titleString = legendStyle.titleString;
            int textheight = (int) round(graphics.getStringBounds(titleString).getHeight());
            if (titleString.length() == 0)
                textheight = 0;

            int w = round(legendStyle.legendWidth);
            int h = round(legendStyle.legendHeight);
            int x = round(legendStyle.xPos);
            int y = round(legendStyle.yPos);

            int bWidth = round(legendStyle.boxWidth);
            /*
             * calculate the boxheight from:
             * legendHeight = 1/2 bHeight + textHeight + 1/2 bHeight + rulseNum*(bHeight + 1/3 bHeight) + 1/2 bHeight
             */
            int bHeight = round((h - textheight) / (3f / 2f + 4f / 3f * rulesNum));
            int yInset = bHeight / 2;
            int xInset = 15;

            int currentX = x + xInset;
            int currentY = y + yInset + textheight;
            if (textheight == 0) {
                currentY = y;
                h = (int) (h - yInset - 1f / 3f * bHeight);
            }

            if (legendStyle.isRoundedRectangle) {
                graphics.setColor(legendStyle.backgroundColor);
                graphics.fillRoundRect(round(x), round(y), round(w), round(h), 15, 15);
                graphics.setColor(legendStyle.foregroundColor);
                graphics.setBackground(legendStyle.backgroundColor);
                graphics.drawRoundRect(round(x), round(y), round(w), round(h), 15, 15);
            } else {
                graphics.setColor(legendStyle.backgroundColor);
                graphics.fillRect(round(x), round(y), round(w), round(h));
                graphics.setColor(legendStyle.foregroundColor);
                graphics.setBackground(legendStyle.backgroundColor);
                graphics.drawRect(round(x), round(y), round(w), round(h));
            }

            // draw the title
            if (textheight != 0) {
                graphics.setColor(legendStyle.fontColor);
                graphics.drawString(titleString, currentX,// +horizontalMargin,
                        currentY,// +textVerticalOffset,
                        ViewportGraphics.ALIGN_LEFT, ViewportGraphics.ALIGN_LEFT);
            }
            currentY = currentY + yInset;

            for( int i = 0; i < colorRules.size(); i++ ) {
                String rule = colorRules.get(i);
                String cat = categories.get(i);

                int lastColon = cat.lastIndexOf(':');
                String attribute = cat.substring(lastColon + 1);

                double[] values = new double[2];
                Color[] colors = new Color[2];
                JGrassColorTable.parseColorRule(rule, values, colors);
                String firstValue = String.valueOf(values[0]);

                graphics.setColor(Color.black);
                graphics.drawRect(currentX, currentY, bWidth, bHeight);
                graphics.setColor(colors[0]);
                graphics.fillRect(currentX, currentY, bWidth, bHeight);

                int tx = round(currentX + 1.5f * bWidth);
                int tHeight = (int) round(graphics.getStringBounds(attribute).getHeight());
                graphics.setColor(legendStyle.fontColor);
                int ty = round(currentY - graphics.getFontAscent() + tHeight);// + tHeight -
                // bHeight/3f);
                graphics.drawString(attribute, tx,// +horizontalMargin,
                        ty, // - graphics.getFontAscent(),// +textVerticalOffset,
                        ViewportGraphics.ALIGN_LEFT, ViewportGraphics.ALIGN_MIDDLE);

                currentY = round(currentY + 4f / 3f * bHeight);

 
View Full Code Here

        if (configBean.getNumberFormat() == null) throw new NullPointerException("ScaleDenomMapGraphicBean number format must not be null"); //$NON-NLS-1$
        if (configBean.getWidth() <= 0) throw new IllegalArgumentException("ScaleDenomMapGraphicBean width must be a positive number"); //$NON-NLS-1$
        if (configBean.getHeight() <= 0) throw new IllegalArgumentException("ScaleDenomMapGraphicBean height must be a positive number"); //$NON-NLS-1$
        if (configBean.getLabel() == null) throw new NullPointerException("ScaleDenomMapGraphicBean label must not be null"); //$NON-NLS-1$
       
        ViewportGraphics g = context.getGraphics();
        IBlackboard mapblackboard = context.getMap().getBlackboard();
       
        double scaleDenom = context.getViewportModel().getScaleDenominator();
       
        Object value = mapblackboard.get("scale"); // scale may be set by printing engine       
        if( value != null && value instanceof Double ){
            scaleDenom = ((Double)value).doubleValue();
        }
       
        if (configBean.getBackgroundColor() != null) {
            g.setBackground(configBean.getBackgroundColor());
            g.clearRect(0, 0, configBean.getWidth(), configBean.getHeight());
        }
        g.setColor(configBean.getTextColor());
        g.setFont(configBean.getFont());
        String denomStr = configBean.getNumberFormat().format(scaleDenom);
        int horizAlignment;
        int anchorPointX;
        if (configBean.getHorizAlignment() == ScaleDenomMapGraphicBean.ALIGN_CENTER) {
            horizAlignment = ViewportGraphics.ALIGN_MIDDLE;
            anchorPointX = configBean.getWidth() / 2;
        } else if (configBean.getHorizAlignment() == ScaleDenomMapGraphicBean.ALIGN_RIGHT) {
            horizAlignment = ViewportGraphics.ALIGN_RIGHT;
            anchorPointX = configBean.getWidth();
        } else {
            horizAlignment = ViewportGraphics.ALIGN_LEFT;
            anchorPointX = 0;
        }
        g.drawString(configBean.getLabel()+"1:"+denomStr, anchorPointX, configBean.getHeight() / 2, horizAlignment, ViewportGraphics.ALIGN_MIDDLE); //$NON-NLS-1$
    }
View Full Code Here

      drawArrow( context, here );
    }
  }

  private void drawArrow( MapGraphicContext context, Point here ) {
    ViewportGraphics g = context.getGraphics();
    AffineTransform t = g.getTransform();
   
    try {
      int nTop = ARROW_HEIGHT + SPACE_ABOVE_N;     
      int arrowCenterX = ARROW_WIDTH / 2;
      int totalHeight = ARROW_HEIGHT + SPACE_ABOVE_N + g.getFontAscent();

            AffineTransform t1 = g.getTransform();
            AffineTransform t2 = g.getTransform();
            t1.translate( here.x + ARROW_WIDTH, here.y + totalHeight );           
            t2.translate( here.x + ARROW_WIDTH, here.y + totalHeight );
           
            t1.scale( -1.0, -1.0 );
            t1.rotate( Math.PI / 2 );
            t1.rotate( -theta );
            g.setTransform( t1 );           
            g.setStroke(ViewportGraphics.LINE_SOLID, 1);     
     
      Point tip = new Point(arrowCenterX, BOTTOM_INSET);
      Point centerBase = new Point(arrowCenterX, ARROW_HEIGHT);
      Point bottomLeft = new Point(0, 0);
      Point bottomRight = new Point(ARROW_WIDTH, 0);
     
      //This polygon is drawn on the left, but then gets rotated
      //so it actually appears on the right if North is up.
      Polygon left = new Polygon();
      left.addPoint(centerBase.x, centerBase.y);
      left.addPoint(tip.x, tip.y);
      left.addPoint(bottomLeft.x, bottomLeft.y);      
      g.setColor( Color.black );
      g.fill(left);
      g.draw(left);
     
      Polygon right = new Polygon();
      right.addPoint(centerBase.x, centerBase.y);
      right.addPoint(tip.x, tip.y);
      right.addPoint(bottomRight.x, bottomRight.y);
      g.setColor( Color.white );
      g.fill(right);
      g.setColor( Color.black );
      g.draw(right);

      //TODO: center the N properly.  presently it relies on the default font and font size
            // to be some particular values
            g.setColor(Color.BLACK);
            g.drawString("N", arrowCenterX-5, nTop, ViewportGraphics.ALIGN_LEFT, ViewportGraphics.ALIGN_MIDDLE); //$NON-NLS-1$
           
     
    } finally {
      g.setTransform( t );
    }
   
    }
View Full Code Here

* @since 1.1.0
*/
public class GridMapGraphic implements MapGraphic {

    public void draw( MapGraphicContext context ) {
        ViewportGraphics graphics = context.getGraphics();
        GridStyle style = getStyle(context.getLayer());
       
        graphics.setColor(style.getColor());
        graphics.setStroke(style.getLineStyle(), style.getLineWidth());

        switch( getStyle(context.getLayer()).getType() ) {
        case SCREEN:
            screenMapGraphic(context);
            break;
View Full Code Here

       
        int width = context.getMapDisplay().getWidth();
        int height = context.getMapDisplay().getHeight();

       
        ViewportGraphics g = context.getGraphics();
       
        int x=0,y=0;
       
        while( x<width){
            x+=dx;
            g.drawLine(x, 0, x, height);
        }
       
        while ( y<height ){
            y+=dy;
            g.drawLine(0, y, width, y);
        }
       
    }
View Full Code Here

            coord.x+=gridSize[0];
        }
        while( context.worldToPixel(coord).y<0 ){
            coord.y-=gridSize[1];
        }
        ViewportGraphics graphics = context.getGraphics();
        Point pixel = null;
        while(true){
            pixel = context.worldToPixel(coord);           
            coord.x+=gridSize[0];
            coord.y-=gridSize[1];
            Point next=context.worldToPixel(coord);
            if( next.x-pixel.x<2 || next.y-pixel.y<2 ){
                context.getLayer().setStatus(ILayer.WARNING);
                context.getLayer().setStatusMessage(Messages.GridMapGraphic_grids_too_close);
                break;
            }
            if( (pixel.x>=context.getMapDisplay().getWidth() && pixel.y>=context.getMapDisplay().getHeight()) )
                break;
           
            if( pixel.x<context.getMapDisplay().getWidth())
                graphics.drawLine(pixel.x,0,pixel.x,context.getMapDisplay().getHeight());
            if( pixel.y<context.getMapDisplay().getHeight())
                graphics.drawLine(0, pixel.y,context.getMapDisplay().getWidth(),pixel.y);
            pixel=next;
        }
    }
View Full Code Here

        while (topLeftMostCoord.y + gridSize[1] < bounds.getMaxY()) {
            topLeftMostCoord.y += gridSize[1];
        }
        Coordinate coord = topLeftMostCoord;

        ViewportGraphics graphics = context.getGraphics();
        int mapPixelWidth = context.getMapDisplay().getWidth();
        int mapPixelHeight = context.getMapDisplay().getHeight();
       
        //cover the right side and bottom of map with thin strips
        final int RIGHT_STRIP_WIDTH = (int)(mapPixelWidth * 0.05);
        final int BOTTOM_STRIP_HEIGHT = (int)(mapPixelHeight * 0.03);
        final int GRID_LINE_EXTENSION = (int)(RIGHT_STRIP_WIDTH * 0.1);
        graphics.setColor(Color.white);
        graphics.fillRect(mapPixelWidth - RIGHT_STRIP_WIDTH,
                          0,
                          RIGHT_STRIP_WIDTH,
                          mapPixelHeight);
        graphics.fillRect(0,
                          mapPixelHeight - BOTTOM_STRIP_HEIGHT,
                          mapPixelWidth,
                          BOTTOM_STRIP_HEIGHT);  
       
        //draw grid lines
        graphics.setColor(style.getColor());
        Point pixel = null;
        while(true){
            pixel = context.worldToPixel(coord);           
            coord.x+=gridSize[0];
            coord.y-=gridSize[1];
            Point next=context.worldToPixel(coord);
            if( next.x-pixel.x<2 || next.y-pixel.y<2 ){
                context.getLayer().setStatus(ILayer.WARNING);
                context.getLayer().setStatusMessage(Messages.GridMapGraphic_grids_too_close);
                break;
            }
            if( (pixel.x>=mapPixelWidth && pixel.y>=mapPixelHeight) )
                break;
           
            //draw vertical lines and labels
            if( pixel.x<mapPixelWidth)
                graphics.drawLine(pixel.x,
                                  0,
                                  pixel.x,
                                  mapPixelHeight - BOTTOM_STRIP_HEIGHT + GRID_LINE_EXTENSION);
                if (showLabels) {
                    graphics.drawString( String.valueOf( (int) coord.y ),
                                    pixel.x,
                                    mapPixelHeight - BOTTOM_STRIP_HEIGHT + GRID_LINE_EXTENSION,
                                    ViewportGraphics.ALIGN_MIDDLE,
                                    ViewportGraphics.ALIGN_TOP);
                }
           
            //draw horizontal lines and labels
            if( pixel.y<mapPixelHeight)
                graphics.drawLine(0,
                                  pixel.y,
                                  mapPixelWidth - RIGHT_STRIP_WIDTH + GRID_LINE_EXTENSION,
                                  pixel.y);
                if (showLabels) {
                    graphics.drawString( String.valueOf( (int)coord.x) ,
                                    mapPixelWidth - RIGHT_STRIP_WIDTH + GRID_LINE_EXTENSION,
                                    pixel.y,
                                    ViewportGraphics.ALIGN_LEFT,
                                    ViewportGraphics.ALIGN_MIDDLE);
                }
            pixel=next;
        }
   
        //outline the map       
        graphics.drawRect(0,
                          0,
                          mapPixelWidth - RIGHT_STRIP_WIDTH,
                          mapPixelHeight - BOTTOM_STRIP_HEIGHT);
     
    }       
View Full Code Here

    public void draw( MapGraphicContext context ) {
        context.getLayer().setStatus(ILayer.WORKING);

        // initialize the graphics handle
        ViewportGraphics g = context.getGraphics();
        if (g instanceof AWTGraphics) {
            AWTGraphics awtG = (AWTGraphics) g;
            Graphics2D g2D = awtG.g;
            // setting rendering hints
            @SuppressWarnings("unchecked")
            RenderingHints hints = new RenderingHints(Collections.EMPTY_MAP);
            hints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
            g2D.addRenderingHints(hints);
        }

        Dimension screen = context.getMapDisplay().getDisplaySize();

        // get the active region
        IStyleBlackboard blackboard = context.getLayer().getStyleBlackboard();
        ProcessingRegionStyle style = (ProcessingRegionStyle) blackboard.get(ProcessingRegionStyleContent.ID);
        if (style == null) {
            style = ProcessingRegionStyleContent.createDefault();
            blackboard.put(ProcessingRegionStyleContent.ID, style);
        }

        Coordinate ul = new Coordinate(style.west, style.north);
        Coordinate ur = new Coordinate(style.east, style.north);
        Coordinate ll = new Coordinate(style.west, style.south);
        Coordinate lr = new Coordinate(style.east, style.south);

        // draw the rectangle around the active region green:143
        float[] rgba = style.backgroundColor.getColorComponents(null);
        g.setColor(new Color(rgba[0], rgba[1], rgba[2], style.bAlpha));

        Point ulPoint = context.worldToPixel(ul);
        Point urPoint = context.worldToPixel(ur);
        Point llPoint = context.worldToPixel(ll);
        Point lrPoint = context.worldToPixel(lr);

        // Point xyRes = new Point((urPoint.x - ulPoint.x) / style.cols, (llPoint.y - ulPoint.y) /
        // style.rows);

        int screenWidth = screen.width;
        int screenHeight = screen.height;

        GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
        path.moveTo(0, 0);
        path.lineTo(screenWidth, 0);
        path.lineTo(screenWidth, screenHeight);
        path.lineTo(0, screenHeight);
        path.closePath();
        path.moveTo(ulPoint.x, ulPoint.y);
        path.lineTo(urPoint.x, urPoint.y);
        path.lineTo(lrPoint.x, lrPoint.y);
        path.lineTo(llPoint.x, llPoint.y);
        path.closePath();

        g.fill(path);

        rgba = style.foregroundColor.getColorComponents(null);
        g.setColor(new Color(rgba[0], rgba[1], rgba[2], style.fAlpha));
        g.setStroke(ViewportGraphics.LINE_SOLID, 2);
        g.draw(path);

        context.getLayer().setStatus(ILayer.DONE);
        context.getLayer().setStatusMessage("Layer rendered");

    }
View Full Code Here

TOP

Related Classes of org.locationtech.udig.ui.graphics.ViewportGraphics

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.