Package org.locationtech.udig.ui.graphics

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


        }
        List<Edge> path = (List<Edge>) mapboard.get("path");
        if( path == null ){
            path = Collections.emptyList();
        }       
        ViewportGraphics graphics = context.getGraphics();
        graphics.setColor( Color.BLACK);
        graphics.setLineWidth(4);
        for( Edge edge : path ){
            Object obj = edge.getObject();
            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);           
        }
        graphics.setColor( Color.YELLOW );
        graphics.setLineWidth(2);
        for( Edge edge : path ){
            Object obj = edge.getObject();
            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);           
        }
        for( Node node : waypoints ){
            Point point = (Point) node.getObject();
            java.awt.Point pixel = context.worldToPixel( point.getCoordinate() );
           
            graphics.setColor( Color.YELLOW );               
            graphics.fillOval(pixel.x-3, pixel.y-3, 7, 7 );

            graphics.setColor( Color.BLACK );
            graphics.drawOval(pixel.x-3, pixel.y-3, 7, 7 );
        }
    }
View Full Code Here


    assert this.context != null;

    if (hide)
      return;

    ViewportGraphics graphics = context.getGraphics();

    graphics.setColor(createColor(getMarkModel().hashCode()));

    if (point != null) {
      final int halfsize = EXTENT_SIZE / 2;

      this.extent = new Rectangle((int) (point.getX() - halfsize), (int) (point.getY() - halfsize), EXTENT_SIZE,
            EXTENT_SIZE);

      graphics.fillOval(extent.x, extent.y, extent.width, extent.height);
      Rectangle2D stringBounds = graphics.getStringBounds(String.valueOf(getMarkModel().getID()));
      graphics.drawString(String.valueOf(getMarkModel().getID()), (int) point.getX(),
            (int) (point.getY() + stringBounds.getHeight()), ViewportGraphics.ALIGN_MIDDLE,
            ViewportGraphics.ALIGN_BOTTOM);
    }
  }
View Full Code Here

  public void draw() {

    if (hide)
      return;

    ViewportGraphics graphics = context.getGraphics();

    graphics.setColor(createColor(mark.hashCode()));
    // get the map coordinate and
    // convert that to a screen point to draw (this way anytime
    // the map is updated with zooming or panning, etc, the point
    // will always be drawn relative to the map and not the screen.
    Point point = null;
    if (!(mark.getXCoord().equals(Double.NaN)) || !(mark.getYCoord().equals(Double.NaN))) {
      point = context.worldToPixel(new Coordinate(mark.getXCoord(), mark.getYCoord()));
    }
    if (point != null) {
      final int halfsize = EXTENT_SIZE / 2;

      this.extent = new Rectangle((int) (point.getX() - halfsize), (int) (point.getY() - halfsize), EXTENT_SIZE,
            EXTENT_SIZE);

      if (this.feedback) {
        Color yellow = Color.YELLOW;
        graphics.setColor(yellow);       
        graphics.fillOval(extent.x , extent.y, extent.width, extent.height);
        Color orange = Color.ORANGE;
        graphics.setColor(orange);
        graphics.drawOval(extent.x, extent.y, extent.width, extent.height);
        // set back to his default color
        graphics.setColor(createColor(mark.hashCode()));
      } else {
        graphics.fillOval(extent.x, extent.y, extent.width, extent.height);
      }

      Rectangle2D stringBounds = graphics.getStringBounds(String.valueOf(mark.getID()));
      graphics.drawString(String.valueOf(mark.getID()), (int) point.getX(),
            (int) (point.getY() + stringBounds.getHeight()), ViewportGraphics.ALIGN_MIDDLE,
            ViewportGraphics.ALIGN_BOTTOM);

    }
View Full Code Here

     * @param feature SimpleFeature to be rendered
     * @param style Style to render feature with
     */
    public void drawDirect( Image image, Display display, SimpleFeature feature, Style style ) {

        ViewportGraphics graphics = createSWTGraphics(image, display);
        drawFeature(graphics, feature, style, new AffineTransform());
        graphics.dispose();
    }
View Full Code Here

    }

    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

        graphics.dispose();
    }

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

        context.getLayer().setStatus(ILayer.WORKING);

        listenService(true);
       
        // initialise the graphics handle
        ViewportGraphics graphic = context.getGraphics();
        if (graphic instanceof AWTGraphics) {
            AWTGraphics awtG = (AWTGraphics) graphic;
            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 AOI
        IAOIService aOIService = PlatformGIS.getAOIService();
        Geometry multiGeometry = aOIService.getGeometry();
        if (multiGeometry != null) {
       
            Geometry innerPolygons = null;
            Polygon polygon = null;
            // 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));
            graphic.setColor(new Color((float)0.5, (float)0.5, (float)0.5, (float)0.5));
   
            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();
           
            // if multi geometry - loop through each geometry
            for (int g=0; g<multiGeometry.getNumGeometries(); g++) {
                Geometry geometry = multiGeometry.getGeometryN(g);
                if (geometry.getGeometryType().equals("Polygon")){
                    polygon = (Polygon) geometry;
                   
                    // get the exterior rings
                    LineString exterior = polygon.getExteriorRing();
                   
                    // collects the internal holes if there are any
                    for (int i=0; i<polygon.getNumInteriorRing(); i++) {
                        if (innerPolygons == null) {
                            innerPolygons = polygon.getInteriorRingN(i);
                        }
                        else {
                            innerPolygons = innerPolygons.union(polygon.getInteriorRingN(i));
                        }
                       
                    }
                   
                    Coordinate[] coordinates = exterior.getCoordinates();
                   
                    // move to the first point
                    Point point = null;
                    if (coordinates.length > 0) {
                        point = context.worldToPixel(coordinates[0]);
                        path.moveTo(point.x, point.y);
                    }
                    // draw all points
                    for (int c=0; c<coordinates.length; c++) {
                        point = context.worldToPixel(coordinates[c]);
                        path.lineTo(point.x, point.y);
                    }
                    path.closePath();
                }
            }
           
            graphic.fill(path);
   
            //rgba = style.foregroundColor.getColorComponents(null);
            //g.setColor(new Color(rgba[0], rgba[1], rgba[2], style.fAlpha));
            graphic.setColor(new Color((float)0.5, (float)0.5, (float)0.5, (float)0.75));
            graphic.setStroke(ViewportGraphics.LINE_SOLID, 1);
            graphic.draw(path);
           
           
           
            // draw inner rings / holes
            if (innerPolygons != null) {
                for (int g=0; g<innerPolygons.getNumGeometries(); g++) {
                    path.reset();
                    Geometry geometry = innerPolygons.getGeometryN(g);
                   
                    Coordinate[] coordinates = geometry.getCoordinates();
                   
                    // move to the first point
                    Point point = null;
                    if (coordinates.length > 0) {
                        point = context.worldToPixel(coordinates[0]);
                        path.moveTo(point.x, point.y);
                    }
                    // draw all points
                    for (int c=0; c<coordinates.length; c++) {
                        point = context.worldToPixel(coordinates[c]);
                        path.lineTo(point.x, point.y);
                    }
                    path.closePath();
                    graphic.setColor(new Color((float)0.5, (float)0.5, (float)0.5, (float)0.5));
                    graphic.fill(path);
                    graphic.setColor(new Color((float)0.5, (float)0.5, (float)0.5, (float)0.75));
                    graphic.draw(path);
                }
            }
           
        }
        context.getLayer().setStatus(ILayer.DONE);
View Full Code Here

        // You can then use this with the AddLayersCommand
    }

    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
        }
        try {
            MathTransform dataToWorldTransform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, context.getCRS() );
   
            // for each location, create a circle and draw
            for (Coordinate location : coordinates) {
                Coordinate world = JTS.transform(location,  null, dataToWorldTransform);
                Point pixel = context.worldToPixel(world);
                Ellipse2D e = new Ellipse2D.Double(pixel.x - 4, pixel.y - 4, 10, 10);
                g.draw(e);
            }
        }
        catch (FactoryException unableToTransform){
            context.getLayer().setStatusMessage(unableToTransform.getMessage());
        } catch (TransformException outOfBounds) {
View Full Code Here

        if (coordinate == null) {
            return;
        }
       
        // initialize the graphics handle
        ViewportGraphics g = context.getGraphics();
        g.setColor(Color.RED);
        g.setStroke(ViewportGraphics.LINE_SOLID, 2);
       
        // figure out our CRS
        CoordinateReferenceSystem ourCRS = crs;
        if (ourCRS == null) {
            ourCRS = context.getLayer().getCRS();
        }
       
        // figure out how to map our coordinate to the world
        CoordinateReferenceSystem worldCRS = context.getCRS();
        MathTransform dataToWorld;
        try {
            dataToWorld = CRS.findMathTransform(ourCRS, worldCRS, false);
        } catch (FactoryException e1) {
            throw (RuntimeException) new RuntimeException( ).initCause( e1 );
        }

        Coordinate worldLocation = new Coordinate();
          
        Coordinate dataLocation = coordinate;
        try {
            JTS.transform(dataLocation, worldLocation, dataToWorld);
        } catch (TransformException e) {
            throw (RuntimeException) new RuntimeException( ).initCause( e );
        }               
             
        java.awt.Point p = context.worldToPixel(worldLocation);
        g.fillOval(p.x, p.y, 10, 10);
        String name = getDisplayName().toString();
        g.drawString(name, p.x + 15, p.y + 15,
                ViewportGraphics.ALIGN_MIDDLE, ViewportGraphics.ALIGN_MIDDLE);

        // draw an ellipse for this seagull
//        Ellipse2D e = new Ellipse2D.Double(coordinate.x-4, coordinate.y-4,10,10);
//        g.draw(e);
View Full Code Here

     * @param feature SimpleFeature to be rendered
     * @param style Style to render feature with
     */
    public void drawDirect( Image image, Display display, SimpleFeature feature, Style style ){

        ViewportGraphics graphics = createSWTGraphics(image, display);
    drawFeature( graphics, feature, style, new AffineTransform() );
    graphics.dispose();
    }
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.