Package org.locationtech.udig.ui.graphics

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


        Font font = new Font("Times", Font.PLAIN, 7);
       
        Envelope bounds = context.getViewportModel().getBounds();
        List<Double>[] gridLines = chooseGridLines(bounds);
      
        ViewportGraphics graphics = context.getGraphics();
        int mapPixelWidth = context.getMapDisplay().getWidth();
        int mapPixelHeight = context.getMapDisplay().getHeight();
        graphics.setColor(gridColor);
       
        List<Double> xCoords = gridLines[0];
        List<Double> yCoords = gridLines[1];
       
        //draw grid "crosses" and ticks
        for (int i = 0; i < xCoords.size(); i++) {
            double x = xCoords.get(i).doubleValue();

            for (int j = 0; j < yCoords.size() ; j++) {
               
                double y = yCoords.get(j).doubleValue();
                Coordinate thisCoord = new Coordinate(x, y);
            
                Point thisPixel = context.worldToPixel(thisCoord);

                //ticks along left and right
                if (i == 0) {
                    //draw left-most ticks
                    graphics.drawLine(EDGE_WIDTH,
                            thisPixel.y,
                            EDGE_WIDTH + TICK_WIDTH,
                            thisPixel.y);
                   
                    //draw right-most ticks
                    graphics.drawLine(mapPixelWidth - EDGE_WIDTH,
                            thisPixel.y,
                            mapPixelWidth - EDGE_WIDTH - TICK_WIDTH,
                            thisPixel.y);
                   
                }

               
                //ticks along top and bottom
                if (j == 0) {
                    //draw top-most ticks
                    graphics.drawLine(thisPixel.x,
                            EDGE_WIDTH,
                            thisPixel.x,
                            EDGE_WIDTH + TICK_WIDTH);
                   
                    //draw bottom-most ticks
                    graphics.drawLine(thisPixel.x,
                            mapPixelHeight - EDGE_WIDTH,
                            thisPixel.x,
                            mapPixelHeight - EDGE_WIDTH - TICK_WIDTH);
                   
                }

                //draw crosses
                graphics.setColor(Color.YELLOW);
                graphics.drawLine(thisPixel.x - TICK_WIDTH/2,
                        thisPixel.y,
                        thisPixel.x + TICK_WIDTH/2,
                        thisPixel.y);
               
                graphics.drawLine(thisPixel.x,
                        thisPixel.y - TICK_WIDTH/2,
                        thisPixel.x,
                        thisPixel.y + TICK_WIDTH/2);
            }
        } //end crosses and ticks
       
        //top border
        graphics.setColor(Color.white);
        graphics.fillRect(0,
                0,
                mapPixelWidth,
                EDGE_WIDTH);
        //right border
        graphics.fillRect(mapPixelWidth - EDGE_WIDTH,
                0,
                EDGE_WIDTH,
                mapPixelHeight);
        //bottom border
        graphics.fillRect(0,
                          mapPixelHeight - EDGE_WIDTH,
                          mapPixelWidth,
                          EDGE_WIDTH);
        //left border
        graphics.fillRect(0,
                          0,
                          EDGE_WIDTH,
                          mapPixelHeight);
       
        //top-left corner
        graphics.setColor(Color.white);
        graphics.fillRect(0,
                0,
                EDGE_WIDTH*2,
                EDGE_WIDTH*2);
        graphics.setColor(Color.black);
        graphics.fillOval(EDGE_WIDTH/2+1, EDGE_WIDTH/2+1, EDGE_WIDTH, EDGE_WIDTH);
        graphics.drawRect(0,
                0,
                EDGE_WIDTH*2,
                EDGE_WIDTH*2);
       
        //top-right corner
        AffineTransform origTrans = graphics.getTransform();
        AffineTransform topRightTrans = graphics.getTransform();
        topRightTrans.translate(mapPixelWidth - EDGE_WIDTH*2, 0);
        graphics.setTransform(topRightTrans);
        graphics.setColor(Color.white);
        graphics.fillRect(0,
                0,
                EDGE_WIDTH*2,
                EDGE_WIDTH*2);
        graphics.setColor(Color.black);
        graphics.fillOval(EDGE_WIDTH/2+1, EDGE_WIDTH/2+1, EDGE_WIDTH, EDGE_WIDTH);
        graphics.drawRect(0,
                0,
                EDGE_WIDTH*2,
                EDGE_WIDTH*2);
       
        //bottom-right corner
        AffineTransform bottomRightTrans = (AffineTransform)origTrans.clone();
        bottomRightTrans.translate(mapPixelWidth - EDGE_WIDTH*2, mapPixelHeight - EDGE_WIDTH*2);
        graphics.setTransform(bottomRightTrans);
        graphics.setColor(Color.white);
        graphics.fillRect(0,
                0,
                EDGE_WIDTH*2,
                EDGE_WIDTH*2);
        graphics.setColor(Color.black);
        graphics.fillOval(EDGE_WIDTH/2+1, EDGE_WIDTH/2+1, EDGE_WIDTH, EDGE_WIDTH);
        graphics.drawRect(0,
                0,
                EDGE_WIDTH*2,
                EDGE_WIDTH*2);
       
        //Note: bottom left corner is drawn after the outline... see below
       
        //outer outline
        graphics.setTransform(origTrans);
        graphics.setColor(Color.black);
        graphics.setStroke(ViewportGraphics.LINE_SOLID, 1);
        graphics.drawRect(0,
                0,
                mapPixelWidth-1,
                mapPixelHeight-1);
       
        //inner outline, extends to edges       
        graphics.drawLine(0, EDGE_WIDTH, mapPixelWidth, EDGE_WIDTH); //top
        graphics.drawLine(mapPixelWidth - EDGE_WIDTH, 0, mapPixelWidth - EDGE_WIDTH, mapPixelHeight); //right
        graphics.drawLine(0, mapPixelHeight - EDGE_WIDTH, mapPixelWidth, mapPixelHeight - EDGE_WIDTH); //bottom
        graphics.drawLine(EDGE_WIDTH, 0, EDGE_WIDTH, mapPixelHeight)//left


        //bottom left corner
        AffineTransform bottomleftTrans = graphics.getTransform();
        bottomleftTrans.translate(0, mapPixelHeight - EDGE_WIDTH*2);
        graphics.setTransform(bottomleftTrans);
        graphics.setColor(Color.white);
        graphics.fillRect(0,
                0,
                EDGE_WIDTH*2,
                EDGE_WIDTH*2);
        graphics.setColor(Color.black);
        graphics.drawOval(EDGE_WIDTH/4, EDGE_WIDTH/4, EDGE_WIDTH*2 - EDGE_WIDTH/2, EDGE_WIDTH*2 - EDGE_WIDTH/2);
        graphics.fillOval(EDGE_WIDTH - 1, EDGE_WIDTH - 1, 2, 2);
        graphics.drawRect(0,
                0,
                EDGE_WIDTH*2,
                EDGE_WIDTH*2);
        graphics.setTransform(origTrans);
       
        //-------------------------
        //draw labels
        //-------------------------
        graphics.setFont(font);
        graphics.setColor(Color.black);
       
        drawVerticalLabels(bounds, graphics, context, xCoords, yCoords, mapPixelWidth, mapPixelHeight);
        drawHorizontalLeftLabels(bounds, graphics, context, xCoords, yCoords, mapPixelWidth, mapPixelHeight);
        drawHorizontalRightLabels(bounds, graphics, context, xCoords, yCoords, mapPixelWidth, mapPixelHeight);
       
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((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((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

        List<Edge> path = (List<Edge>) mapboard.get("path");
        if( path == null ){
            path = Collections.emptyList();
        }       
        Graph graph = (Graph) mapboard.get("graph");
        ViewportGraphics graphics = context.getGraphics();
        graphics.setColor( Color.LIGHT_GRAY );
        Collection<Node> nodes = graph.getNodes();
        for( Node node : nodes ){
            if( waypoints.contains(node)){
                graphics.setColor( Color.BLACK );               
            }
            Object obj = node.getObject();
            if( obj instanceof Point ){
                Point point = (Point) obj;
                java.awt.Point pixel = context.worldToPixel( point.getCoordinate() );
                graphics.fillOval(pixel.x-2, pixel.y-2, 5, 5 );
            }
            if( waypoints.contains(node)){
                graphics.setColor( Color.LIGHT_GRAY );                               
            }
        }
        Collection<Edge> edges = graph.getEdges();
        graphics.setColor( Color.DARK_GRAY );
        for( Edge edge : edges ){
            Object obj = edge.getObject();
            if( path.contains(edge)){
                graphics.setColor( Color.BLACK );
                graphics.setLineWidth(3);
            }
            Node start = edge.getNodeA();
            Node end = edge.getNodeB();
       
            Point startPoint = (Point) start.getObject();
            Point endPoint = (Point) end.getObject();           
            java.awt.Point startPixel = context.worldToPixel( startPoint.getCoordinate() );
            java.awt.Point endPixel = context.worldToPixel( endPoint.getCoordinate() );
           
            graphics.drawLine(startPixel.x, startPixel.y, endPixel.x, endPixel.y);           
            double angle = Angle.angle(startPoint.getCoordinate(), endPoint.getCoordinate());
            double dx = Math.cos( angle+0.1 );
            double dy = Math.sin( angle+0.1 );
            graphics.drawLine(
                    endPixel.x, endPixel.y,
                    (int)(endPixel.x - (10.0*dx)),
                    (int)(endPixel.y + (10.0*dy)));
            dx = Math.cos( angle-0.1 );
            dy = Math.sin( angle-0.1 );
            graphics.drawLine(
                    endPixel.x, endPixel.y,
                    (int)(endPixel.x - (10.0*dx)),
                    (int)(endPixel.y + (10.0*dy)));
            if( path.contains(edge)){
                graphics.setColor( Color.DARK_GRAY);
                graphics.setLineWidth(1);
            }
        }
    }
View Full Code Here

public class CoordinateGraphic implements MapGraphic {

@SuppressWarnings("unchecked")
public void draw( MapGraphicContext context ) {
    //initialize the graphics handle
     ViewportGraphics g = context.getGraphics();
     g.setColor(Color.RED);
     g.setStroke(ViewportGraphics.LINE_SOLID, 2);
    
     //get the map blackboard
     IMap map = context.getLayer().getMap();
     IBlackboard blackboard = context.getLayer().getMap().getBlackboard();
    
     List<Coordinate> coordinates =
         (List<Coordinate>) blackboard.get("locations");
    
     if (coordinates == null) {
         return; //no coordinates to draw
     }
        
     //for each coordnate, create a circle and draw
     for (Coordinate coordinate : coordinates) {
        Ellipse2D e = new Ellipse2D.Double(
                coordinate.x-4,
                coordinate.y-4,
                10,10);
        g.draw(e);
     }
}
View Full Code Here

        int width = 16;
        int height = 16;

        Image image = new Image(Display.getDefault(), width, height);
        SimpleFeature feature = sampleFeature(layer);
        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);
View Full Code Here

    /**
     * draws a single label for the simple scalebar
     */
    private void drawSingleLabel( MapGraphicContext context, Unit measurement, int nice, int x,
            int y, int height, int barWidth, int width, Color c ) {
        ViewportGraphics graphics = context.getGraphics();

        FontStyle font = getFontStyle(context);

        if (font != null && font.getFont() != null) {
            graphics.setFont(font.getFont());
        }

        MessageFormat formatter = new MessageFormat("", Locale.getDefault()); //$NON-NLS-1$
        formatter.applyPattern(NUMBER_PATTERN + measurement.display);

        Object[] arguments = {nice};
        String msg = formatter.format(arguments);
        Rectangle2D msgBounds = graphics.getStringBounds(msg);

        int yText = y + (height - barWidth) - 4;
        int xText = x + (int) (width * 0.5) - (int) (msgBounds.getWidth() * 0.5);

        // Draw the string denoting kilometres (or metres)
        graphics.setColor(c);
        graphics.drawString(msg, xText, yText, ViewportGraphics.ALIGN_LEFT,
                ViewportGraphics.ALIGN_BOTTOM);
    }
View Full Code Here

     * draws the interval labels
     */
    private void drawIntervalLabels( MapGraphicContext context, Unit measurement, int nice, int x,
            int y, int height, int barWidth, int width, int numIntervals, Color c ) {

        ViewportGraphics graphics = context.getGraphics();

        FontStyle font = getFontStyle(context);

        if (font != null && font.getFont() != null) {
            graphics.setFont(font.getFont());
        }

        MessageFormat formatter = new MessageFormat("", Locale.getDefault()); //$NON-NLS-1$
        formatter.applyPattern(NUMBER_PATTERN);

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
            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
        IBlackboard blackboard = context.getMap().getBlackboard();
        ActiveRegionStyle style = (ActiveRegionStyle) blackboard.get(ActiveregionStyleContent.ID);
        if (style == null) {
            style = ActiveregionStyleContent.createDefault();
            blackboard.put(ActiveregionStyleContent.ID, style);
            // ((IBlackboard) styleBlackboard)
            // .setSelected(new String[]{ActiveregionStyleContent.ID});
        }

        if (style.windPath == null) {
            getMapset(blackboard);
        }

        CoordinateReferenceSystem destinationCRS = context.getCRS();
        try {
            CoordinateReferenceSystem crs = CRS.decode(style.crsString);
            MathTransform transform = CRS.findMathTransform(crs, destinationCRS, true);

            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);

            Coordinate newUL = JTS.transform(ul, null, transform);
            Coordinate newUR = JTS.transform(ur, null, transform);
            Coordinate newLL = JTS.transform(ll, null, transform);
            Coordinate newLR = JTS.transform(lr, null, transform);

            // 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(newUL);
            Point urPoint = context.worldToPixel(newUR);
            Point llPoint = context.worldToPixel(newLL);
            Point lrPoint = context.worldToPixel(newLR);

            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);
            if (style.doGrid && xyRes.x > 1 && xyRes.y > 1) {
                for( int x = ulPoint.x + xyRes.x; x < urPoint.x; x = x + xyRes.x ) {
                    g.drawLine(x, ulPoint.y, x, llPoint.y);
                }
                for( int y = ulPoint.y + xyRes.y; y < llPoint.y; y = y + xyRes.y ) {
                    g.drawLine(urPoint.x, y, ulPoint.x, y);
                }
            }

            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);

            if (style.windPath != null) {
                File windFile = new File(style.windPath);
                if (windFile.exists()) {
                    File mapsetFile = windFile.getParentFile();
                    StringBuilder sb = new StringBuilder();
                    sb.append(mapsetFile.getParentFile().getName());
                    sb.append("/");
                    sb.append(mapsetFile.getName());
                    g.drawString(sb.toString(), 10, 10,
                            ViewportGraphics.ALIGN_LEFT, ViewportGraphics.ALIGN_MIDDLE);
                }
            }

        } catch (Exception e) {
View Full Code Here

  public void draw(MapGraphicContext context) {
    @SuppressWarnings("unchecked")
    List<ReferencedEnvelope> alerts = (List<ReferencedEnvelope>) context.getLayer().getBlackboard().get(ALERTS_KEY);
    if(alerts == null) return;
   
    ViewportGraphics graphics = context.getGraphics();
   
    for (ReferencedEnvelope referencedEnvelope : alerts) {
      Shape shape = context.toShape(referencedEnvelope);
      graphics.setColor(new Color(255,0,0,50));
      graphics.fill(shape);
      graphics.setColor(Color.RED);
      graphics.draw(shape);
    }
  }
View Full Code Here

        // Set styles
        Font plain = GraticuleStyle.getFontStyle(context).getFont();
        Font bold = plain.deriveFont(Font.BOLD);

        // Initialize the graphics handle
        ViewportGraphics g = context.getGraphics();

        // Set font size
        g.setFont(bold);
       
        // Show labels?
        boolean isShowLabels = style.isShowLabels();

        // Get bounds of viewport
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.