File: EditableGroupRenderer.java

package info (click to toggle)
libjgraph-java 5.12.4.2%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 7,884 kB
  • ctags: 7,321
  • sloc: java: 20,619; xml: 135; sh: 51; makefile: 10
file content (39 lines) | stat: -rw-r--r-- 1,173 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.jgraph.example.groupeditor;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

import org.jgraph.graph.VertexRenderer;

/**
 * A renderer that display an active rectangle that trigger the cell or group edition when clicked
 * @author rvalyi
 * @see com.jgraph.example.JGraphGroupRenderer
 */
public class EditableGroupRenderer extends VertexRenderer {

	public static Rectangle editorButton = new Rectangle(0, 0, 7, 7);

	/**
	 * renderer paint method
	 */
	public void paint(Graphics g) {
		super.paint(g);
		if (selected) {
			g.setColor(Color.GRAY);
			g.fillRect(getWidth() - editorButton.width -1 , 0, editorButton.width, editorButton.height);
			g.setColor(Color.RED);
			g.drawString("e", getWidth() - editorButton.width - 2, 7);
			//g.drawRect(getWidth() - editorButton.width -1, 0, editorButton.width, editorButton.height);
		}
	}
	
	public boolean isEditAsked(Point2D pt, Rectangle2D rectBounds) {
		//return editorButton.contains(pt.getX(), pt.getY());
		return editorButton.contains(editorButton.width + pt.getX() - rectBounds.getWidth(), pt.getY());
	}

}