Examples of ViewportGraphics


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

    this.verticalSpacing = legendStyle.verticalSpacing;
    this.indentSize = legendStyle.indentSize;
    this.imageHeight = legendStyle.imageHeight;
    this.imageWidth = legendStyle.imageWidth;

    final ViewportGraphics graphics = context.getGraphics();

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

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

    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.
     */
    Dimension imageSize = new Dimension(imageWidth,imageHeight);
    Dimension textSize = new Dimension(0, graphics.getFontHeight());
   
    for (int i = context.getMapLayers().size() - 1; i >= 0; i--) {
      ILayer layer = context.getMapLayers().get(i);

      if (!(layer.getGeoResource() instanceof MapGraphicResource)
          && layer.isVisible()) {

        if (layer.hasResource(MapGraphic.class)) {
          // don't include mapgraphics
          continue;
        }
        String layerName = layer.getName();
        if (layerName == null) {
          layerName = null;
        }
        LegendEntry layerEntry = new LegendEntry(layerName);

        FeatureTypeStyle[] styles = locateStyle(layer);
        LegendEntry[] entries = null;
        if (styles == null) {
          // we should have a label but no style
          entries = new LegendEntry[] { layerEntry };
        } else {
          List<Rule> rules = rules(styles);
          int ruleCount = rules.size();

          if (ruleCount == 1
              && layer.getGeoResource().canResolve(
                  GridCoverage.class)) {
            // grid coverage with single rule; lets see if it is a
            // theming style
            List<LegendEntry> cmEntries = ColorMapLegendCreator
                .findEntries(styles, imageSize, textSize);
            if (cmEntries != null) {
              cmEntries.add(0, layerEntry); // add layer legend
                              // entry
              entries = cmEntries
                  .toArray(new LegendEntry[cmEntries.size()]);
            }
          }
          if (entries == null) {
            List<LegendEntry> localEntries = new ArrayList<LegendEntry>();
            if (ruleCount == 1) {
              // only one rule so apply this to the layer legend
              // entry
              layerEntry.setRule(rules.get(0));
            }
            localEntries.add(layerEntry); // add layer legend entry

            if (ruleCount > 1) {
              // we have more than one rule so there is likely
              // some
              // themeing going on; add each of these rules
              for (Rule rule : rules) {
                LegendEntry rentry = new LegendEntry(rule);
                localEntries.add(rentry);
              }
            }
            entries = localEntries
                .toArray(new LegendEntry[localEntries.size()]);
          }
        }
        layers.add(Collections.singletonMap(layer, entries));

        // compute maximum length for each entry
        for (int j = 0; j < entries.length; j++) {
          StringBuilder sb = new StringBuilder();
          for (int k = 0; k < entries[j].getText().length; k++){
            sb.append(entries[j].getText()[k]);
          }
          Rectangle2D bounds = graphics.getStringBounds(sb.toString());
          int length = indentSize + imageWidth + horizontalSpacing
              + (int) bounds.getWidth();

          if (length > longestRow) {
            longestRow = length;
          }
          numberOfEntries[0]++;
        }
      }
    }

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

    final int rowHeight = Math.max(imageHeight, graphics.getFontHeight()); // space
                                        // allocated
                                        // to
                                        // each
                                        // layer

    if (locationStyle.width == 0 || locationStyle.height == 0) {
      // we want to change the location style as needed
      // but not change the saved one so we create a copy here
      locationStyle = new Rectangle(locationStyle);
      if (locationStyle.width == 0) {
        // we want to grow to whatever size we need
        int width = longestRow + horizontalMargin * 2;
        locationStyle.width = width;
      }
      if (locationStyle.height == 0) {
        // we want to grow to whatever size we need
        int height = rowHeight * numberOfEntries[0] + verticalMargin * 2;
        for (int i = 0; i < layers.size(); i++) {
          Map<ILayer, LegendEntry[]> map = layers.get(i);
          final LegendEntry[] entries = map.values().iterator().next();
          for (int j = 0; j < entries.length; j ++){
            if (entries[j].getSpacingAfter() == null){
              height += verticalSpacing;
            }else{
              height += entries[j].getSpacingAfter();
            }
          }
        }
        locationStyle.height = height- verticalSpacing;
      }
    }

    // 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 - locationStyle.width - 5;
    }

    if (locationStyle.y < 0) {
      locationStyle.y = displaySize.height - locationStyle.height - 5
          + locationStyle.y;
    }
    if ((locationStyle.y + locationStyle.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;

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

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

      try {
        layer.getGeoResources().get(0).getInfo(null);
      } catch (Exception ex) {
      }

      PlatformGIS.syncInDisplayThread(new Runnable() {
        public void run() {
          for (int i = 0; i < entries.length; i++) {
            BufferedImage awtIcon = null;
            if (entries[i].getRule() != null) {
              // generate icon from use
              ImageDescriptor descriptor = LayerGeneratedGlyphDecorator
                  .generateStyledIcon(layer,
                      entries[i].getRule());
              if (descriptor == null) {
                descriptor = LayerGeneratedGlyphDecorator
                    .generateIcon((Layer) layer);
              }
              if (descriptor != null) {
                awtIcon = AWTSWTImageUtils
                    .convertToAWT(descriptor.getImageData());
              }
            } else if (entries[i].getIcon() != null) {
              // use set icon
              awtIcon = AWTSWTImageUtils.convertToAWT(entries[i]
                    .getIcon().getImageData());
            } else {
              // no rule, no icon, try default for layer
              ImageDescriptor descriptor = LayerGeneratedGlyphDecorator
                  .generateIcon((Layer) layer);
              if (descriptor != null) {
                awtIcon = AWTSWTImageUtils
                    .convertToAWT(descriptor.getImageData());
              }
            }
            drawRow(graphics, x[0], y[0], awtIcon,
                entries[i].getText(), i != 0, entries[i].getTextPosition());

            y[0] += rowHeight;
            if ((rowsDrawn[0] + 1) < numberOfEntries[0]) {
              if (entries[i].getSpacingAfter() != null){
                y[0] += entries[i].getSpacingAfter();
              }else{
                y[0] += verticalSpacing;
              }
            }
            rowsDrawn[0]++;
          }

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

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

        if ((getStyle()&SWT.DOUBLE_BUFFERED)==0){
            if (buffer == null) {
                buffer = new Image(display, displaySize.width, displaySize.height);
            }

            ViewportGraphics swtGraphics = null;
           
            if (useAdvancedGraphics) {
              swtGraphics = new SWTGraphics(buffer, display);
            } else {
              swtGraphics = new NonAdvancedSWTGraphics(buffer, display);
            }

            painter.paint(swtGraphics, swtImage, minWidth, minHeight);
            swtGraphics.dispose();

            gc.drawImage(buffer, 0, 0);
        }else{

          ViewportGraphics swtGraphics = null;
         
          if (useAdvancedGraphics) {
            swtGraphics = new SWTGraphics(gc, display);
          } else {
            swtGraphics = new NonAdvancedSWTGraphics(gc, display, null);
          }
            painter.paint(swtGraphics, swtImage, minWidth, minHeight);
            swtGraphics.dispose();
        }
    }
View Full Code Here

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

    private void drawOnOffScreenBuffer() {

        Graphics2D graphics = buffer.createGraphics();
//        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        ViewportGraphics vg = new AWTGraphics(graphics);
        do {
            int minWidth = Math.min(buffer.getWidth(), getWidth());
            int minHeight = Math.min(buffer.getHeight(), getHeight());
            validateVolitileImage();
            painter.paint(vg, vImage, minWidth, minHeight);
View Full Code Here

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

        if ((getStyle()&SWT.DOUBLE_BUFFERED)==0){
            if (buffer == null) {
                buffer = new Image(display, displaySize.width, displaySize.height);
            }        

            ViewportGraphics swtGraphics = null;
           
            if (useAdvancedGraphics ) {
              swtGraphics = new SWTGraphics(buffer, display);
            } else {
              swtGraphics = new NonAdvancedSWTGraphics(buffer, display);
            }
            if (renderManager.getViewportModelInternal().isBoundsChanging() ) {
                swtGraphics.getGraphics(GC.class).setAdvanced(false);
            }
            painter.paint(swtGraphics, tiles, minWidth, minHeight);
            swtGraphics.dispose();

            gc.drawImage(buffer, 0, 0);
        }else{

          ViewportGraphics swtGraphics = null;
         
          if (useAdvancedGraphics ) {
            swtGraphics = new SWTGraphics(gc, display);
          } else {
            swtGraphics = new NonAdvancedSWTGraphics(gc, display, null);
          }
          if (renderManager.getViewportModelInternal().isBoundsChanging() ) {
              swtGraphics.getGraphics(GC.class).setAdvanced(false);
          }
            painter.paint(swtGraphics, tiles, minWidth, minHeight);
            swtGraphics.dispose();
        }
    }
View Full Code Here

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

        Font font = new Font("Times", Font.PLAIN, 8);
       
        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 vert lines
        for (int i = 0; i < xCoords.size(); i++) {
            double x = xCoords.get(i).doubleValue();

            for (int j = 0; j < yCoords.size() - 1; j++) {
               
                double y1 = yCoords.get(j).doubleValue();
                Coordinate lastCoord = new Coordinate(x, y1);
                double y2 = yCoords.get(j+1).doubleValue();
                Coordinate thisCoord = new Coordinate(x, y2);
               
            
                Point lastPixel = context.worldToPixel(lastCoord);
                Point thisPixel = context.worldToPixel(thisCoord);
           
                graphics.drawLine(lastPixel.x,
                        lastPixel.y,
                        thisPixel.x,
                        thisPixel.y);
            }
        }

        //draw horiz lines
       
        for (int i = 0; i < yCoords.size(); i++) {
            double y = yCoords.get(i).doubleValue();
            for (int j = 0; j < xCoords.size() - 1; j++) {
               
                double x1 = xCoords.get(j).doubleValue();
                Coordinate lastCoord = new Coordinate(x1, y);
                double x2 = xCoords.get(j+1).doubleValue();
                Coordinate thisCoord = new Coordinate(x2, y);
               
                Point lastPixel = context.worldToPixel(lastCoord);
                Point thisPixel = context.worldToPixel(thisCoord);
               
                graphics.drawLine(lastPixel.x,
                        lastPixel.y,
                        thisPixel.x,
                        thisPixel.y);
   
            }
        }
    
        //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.05);
        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);  
      
       
        //outline the map       
        graphics.setStroke(ViewportGraphics.LINE_SOLID, 1);
        graphics.setColor(Color.BLACK);
        graphics.drawRect(1,
                          1,
                          mapPixelWidth - RIGHT_STRIP_WIDTH - 1,
                          mapPixelHeight - BOTTOM_STRIP_HEIGHT - 1);
       
        //draw labels
        graphics.setFont(font);
        if (showLabels) {
            graphics.setColor(gridColor);
            for (int i = 1; i < yCoords.size() - 1; i++) {
                double y = yCoords.get(i).doubleValue();
                double x = xCoords.get(xCoords.size() - 1).doubleValue();
                Point pixel = context.worldToPixel(new Coordinate(x,y));
                //line is covered by white overlay
                if (pixel.y > mapPixelHeight - BOTTOM_STRIP_HEIGHT)
                    break;
                 graphics.drawString((int)(y)+"",
                                mapPixelWidth - RIGHT_STRIP_WIDTH + GRID_LINE_EXTENSION,
                                pixel.y,
                                ViewportGraphics.ALIGN_LEFT,
                                ViewportGraphics.ALIGN_MIDDLE);
            }
            for (int i = 1; i < xCoords.size() - 1; i++) {
                double x = xCoords.get(i).doubleValue();
                double y = yCoords.get(yCoords.size() - 1).doubleValue();
                Point pixel = context.worldToPixel(new Coordinate(x,y));
                //line is covered by white overlay
                if (pixel.x > mapPixelWidth - RIGHT_STRIP_WIDTH)
                    break;
                graphics.drawString((int)(x)+"",
                                pixel.x,
                                mapPixelHeight - BOTTOM_STRIP_HEIGHT + GRID_LINE_EXTENSION,
                                ViewportGraphics.ALIGN_MIDDLE,
                                ViewportGraphics.ALIGN_TOP);
            }
View Full Code Here

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

        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

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

        Font font = new Font("Times", Font.PLAIN, 8);
       
        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 vert lines
        for (int i = 0; i < xCoords.size(); i++) {
            double x = xCoords.get(i).doubleValue();

            for (int j = 0; j < yCoords.size() - 1; j++) {
               
                double y1 = yCoords.get(j).doubleValue();
                Coordinate lastCoord = new Coordinate(x, y1);
                double y2 = yCoords.get(j+1).doubleValue();
                Coordinate thisCoord = new Coordinate(x, y2);
               
            
                Point lastPixel = context.worldToPixel(lastCoord);
                Point thisPixel = context.worldToPixel(thisCoord);
           
                graphics.drawLine(lastPixel.x,
                        lastPixel.y,
                        thisPixel.x,
                        thisPixel.y);
            }
        }

        //draw horiz lines
       
        for (int i = 0; i < yCoords.size(); i++) {
            double y = yCoords.get(i).doubleValue();
            for (int j = 0; j < xCoords.size() - 1; j++) {
               
                double x1 = xCoords.get(j).doubleValue();
                Coordinate lastCoord = new Coordinate(x1, y);
                double x2 = xCoords.get(j+1).doubleValue();
                Coordinate thisCoord = new Coordinate(x2, y);
               
                Point lastPixel = context.worldToPixel(lastCoord);
                Point thisPixel = context.worldToPixel(thisCoord);
               
                graphics.drawLine(lastPixel.x,
                        lastPixel.y,
                        thisPixel.x,
                        thisPixel.y);
   
            }
        }
    
        //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.05);
        final int GRID_LINE_EXTENSION = (int)(RIGHT_STRIP_WIDTH * 0.1);
        graphics.setColor(Color.white);
        graphics.setBackground(Color.white);
       
        graphics.clearRect(mapPixelWidth - RIGHT_STRIP_WIDTH,
                          0,
                          RIGHT_STRIP_WIDTH,
                          mapPixelHeight);
        graphics.clearRect(0,
                          mapPixelHeight - BOTTOM_STRIP_HEIGHT,
                          mapPixelWidth,
                          BOTTOM_STRIP_HEIGHT);  
      
       
        //outline the map       
        graphics.setColor(Color.BLACK);
        graphics.drawRect(0,
                          0,
                          mapPixelWidth - RIGHT_STRIP_WIDTH - 1,
                          mapPixelHeight - BOTTOM_STRIP_HEIGHT - 1);
       
        //draw labels
        graphics.setFont(font);
        if (showLabels) {
            graphics.setColor(gridColor);
            for (int i = 1; i < yCoords.size() - 1; i++) {
                double y = yCoords.get(i).doubleValue();
                double x = xCoords.get(xCoords.size() - 1).doubleValue();
                Point pixel = context.worldToPixel(new Coordinate(x,y));
                //line is covered by white overlay
                if (pixel.y > mapPixelHeight - BOTTOM_STRIP_HEIGHT)
                    break;
                 graphics.drawString((int)(y)+"",
                                mapPixelWidth - RIGHT_STRIP_WIDTH + GRID_LINE_EXTENSION,
                                pixel.y,
                                ViewportGraphics.ALIGN_LEFT,
                                ViewportGraphics.ALIGN_MIDDLE);
            }
            for (int i = 1; i < xCoords.size() - 1; i++) {
                double x = xCoords.get(i).doubleValue();
                double y = yCoords.get(yCoords.size() - 1).doubleValue();
                Point pixel = context.worldToPixel(new Coordinate(x,y));
                //line is covered by white overlay
                if (pixel.x > mapPixelWidth - RIGHT_STRIP_WIDTH)
                    break;
                graphics.drawString((int)(x)+"",
                                pixel.x,
                                mapPixelHeight - BOTTOM_STRIP_HEIGHT + GRID_LINE_EXTENSION,
                                ViewportGraphics.ALIGN_MIDDLE,
                                ViewportGraphics.ALIGN_TOP);
            }
View Full Code Here

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

        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
TOP
Copyright © 2018 www.massapi.com. 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.