private void drawLabel(Rendering rendering, String label) { final Graphics2D graphics = rendering.getGraphics(); final Font oldFont = graphics.getFont(); final Stroke oldStroke = graphics.getStroke(); final Paint oldPaint = graphics.getPaint(); try { graphics.setFont(labelFont); GlyphVector glyphVector = labelFont.createGlyphVector(graphics.getFontRenderContext(), label); Rectangle2D logicalBounds = glyphVector.getLogicalBounds(); float tx = (float) (logicalBounds.getX() - 0.5 * logicalBounds.getWidth()); float ty = (float) (getSymbol().getBounds().getMaxY() + logicalBounds.getHeight() + 1.0); Shape labelOutline = glyphVector.getOutline(tx, ty); for (int i = 0; i < labelOutlineAlphas.length; i++) { graphics.setStroke(labelOutlineStrokes[i]); graphics.setPaint(labelOutlineColors[i]); graphics.draw(labelOutline); } graphics.setPaint(labelFontColor); graphics.fill(labelOutline); } finally { graphics.setPaint(oldPaint); graphics.setStroke(oldStroke); graphics.setFont(oldFont); } }
@Override public Handle[] createHandles(int selectionStage) { if (selectionStage == 1) { DefaultFigureStyle handleStyle = new DefaultFigureStyle(); handleStyle.setStrokeColor(Color.YELLOW); handleStyle.setStrokeOpacity(0.8); handleStyle.setStrokeWidth(1.0); handleStyle.setFillColor(Color.YELLOW); handleStyle.setFillOpacity(0.4); Symbol symbol = getSymbol(); if (symbol instanceof NamedSymbol) { NamedSymbol namedSymbol = (NamedSymbol) symbol; symbol = namedSymbol.getSymbol(); } if (symbol instanceof ShapeSymbol) { ShapeSymbol shapeSymbol = (ShapeSymbol) symbol; return new Handle[]{new PointHandle(this, handleStyle, shapeSymbol.getShape())}; } return new Handle[]{new PointHandle(this, handleStyle)}; } return super.createHandles(selectionStage); } }