01: package com.jgraph.example.groupeditor;
02:
03: import java.awt.Color;
04: import java.awt.Graphics;
05: import java.awt.Rectangle;
06: import java.awt.geom.Point2D;
07: import java.awt.geom.Rectangle2D;
08:
09: import org.jgraph.graph.VertexRenderer;
10:
11: /**
12: * A renderer that display an active rectangle that trigger the cell or group edition when clicked
13: * @author rvalyi
14: * @see com.jgraph.example.JGraphGroupRenderer
15: */
16: public class EditableGroupRenderer extends VertexRenderer {
17:
18: public static Rectangle editorButton = new Rectangle(0, 0, 7, 7);
19:
20: /**
21: * renderer paint method
22: */
23: public void paint(Graphics g) {
24: super .paint(g);
25: if (selected) {
26: g.setColor(Color.GRAY);
27: g.fillRect(getWidth() - editorButton.width - 1, 0,
28: editorButton.width, editorButton.height);
29: g.setColor(Color.RED);
30: g.drawString("e", getWidth() - editorButton.width - 2, 7);
31: //g.drawRect(getWidth() - editorButton.width -1, 0, editorButton.width, editorButton.height);
32: }
33: }
34:
35: public boolean isEditAsked(Point2D pt, Rectangle2D rectBounds) {
36: //return editorButton.contains(pt.getX(), pt.getY());
37: return editorButton.contains(editorButton.width + pt.getX()
38: - rectBounds.getWidth(), pt.getY());
39: }
40:
41: }
|