public void drawImageCentred(Graphics g, Image image) { if (element != null) { Graphics2D g2 = (Graphics2D) g; Rectangle r = element.jGetBounds(); int mitteX = r.width / 2; int mitteY = r.height / 2; int imageMitteX = image.getWidth(null) / 2; int imageMitteY = image.getHeight(null) / 2; g2.drawImage(image, r.x + mitteX - imageMitteX, r.y + mitteY - imageMitteY, null); } }
public void paint(java.awt.Graphics g) { if (element != null) { Rectangle bounds = element.jGetBounds(); Graphics2D g2 = (Graphics2D) g; g2.setFont(font); int mitteX = bounds.x + (bounds.width) / 2; int mitteY = bounds.y + (bounds.height) / 2; int distanceY = 10; g2.setColor(new Color(204, 204, 255)); g2.fillRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY); g2.setColor(Color.BLACK); g2.drawRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY); String caption = "dec(" + variable.getValue() + ")"; FontMetrics fm = g2.getFontMetrics(); Rectangle2D r = fm.getStringBounds(caption, g2); g2.setColor(Color.BLACK); g.drawString( caption, mitteX - (int) (r.getWidth() / 2), (int) (mitteY + fm.getHeight() / 2) - 3); } super.paint(g); }