private void drawText(Graphics2D g2d, final String text, final PixelPos textCenter, final float offsetX) { if (text == null || textCenter == null) { return; } g2d = prepareGraphics2D(offsetX, g2d); final FontMetrics fontMetrics = g2d.getFontMetrics(); final Color color = g2d.getColor(); g2d.setColor(Color.black); g2d.drawString(text, (int) textCenter.x - fontMetrics.stringWidth(text) / 2.0f, (int) textCenter.y + fontMetrics.getAscent() / 2.0f); g2d.setColor(color); }
public NestWorldMapPane(NestWorldMapPaneDataModel dataModel) { this.dataModel = dataModel; try { layerCanvas = new LayerCanvas(); layerCanvas.getModel().getViewport().setModelYAxisDown(false); installLayerCanvasNavigation(layerCanvas, dataModel); layerCanvas.addOverlay(new BoundaryOverlay()); final Layer rootLayer = layerCanvas.getLayer(); final Dimension dimension = new Dimension(400, 150); final Viewport viewport = layerCanvas.getViewport(); viewport.setViewBounds(new Rectangle(dimension)); setPreferredSize(dimension); setSize(dimension); setLayout(new BorderLayout()); add(layerCanvas, BorderLayout.CENTER); dataModel.addModelChangeListener(new ModelChangeListener()); worldMapLayer = dataModel.getWorldMapLayer(new WorldMapLayerContext(rootLayer)); layerCanvas.getLayer().getChildren().add(worldMapLayer); layerCanvas.getViewport().zoom(worldMapLayer.getModelBounds()); setNavControlVisible(true); } catch (Exception e) { SnapApp.getDefault().handleError("Error in worldmap initialization", e); } }
@Override public void paintOverlay(LayerCanvas canvas, Rendering rendering) { for (final NestWorldMapPaneDataModel.Boundary extraGeoBoundary : dataModel.getAdditionalGeoBoundaries()) { drawGeoBoundary(rendering.getGraphics(), assemblePathList(extraGeoBoundary.geoBoundary), extraGeoBoundary.isClosed, transWhiteColor, borderWhiteColor); } for (final NestWorldMapPaneDataModel.Boundary selectGeoBoundary : dataModel.getSelectedGeoBoundaries()) { drawGeoBoundary(rendering.getGraphics(), assemblePathList(selectGeoBoundary.geoBoundary), selectGeoBoundary.isClosed, transRedColor, borderRedColor); } final Product selectedProduct = dataModel.getSelectedProduct(); for (final Product product : dataModel.getProducts()) { if (product != null && selectedProduct != product) { drawProduct(rendering.getGraphics(), product, transWhiteColor, Color.WHITE); } } if (selectedProduct != null) { drawProduct(rendering.getGraphics(), selectedProduct, transWhiteColor, Color.RED); } final NestWorldMapPaneDataModel.Boundary selectionBox = dataModel.getSelectionBoundary(); drawGeoBoundary(rendering.getGraphics(), assemblePathList(selectionBox.geoBoundary),//selectionBox.boundaryPaths, selectionBox.isClosed, selectionFillColor, selectionBorderColor); }
private void drawProduct(final Graphics2D g2d, final Product product, final Color fillColor, final Color borderColor) { final GeoCoding geoCoding = product.getSceneGeoCoding(); if (geoCoding == null) { return; } GeneralPath[] boundaryPaths = getGeoBoundaryPaths(product); final String text = String.valueOf(product.getRefNo()); final PixelPos textCenter = getProductCenter(product); drawGeoBoundaryPath(g2d, boundaryPaths, fillColor, borderColor); drawText(g2d, text, textCenter, 0.0f); }