📄 graphitembreak.java
字号:
package flow.graph.gui.graph.item;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import org.jgraph.graph.CellViewRenderer;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.VertexRenderer;
import org.jgraph.graph.VertexView;
public class GraphItemBreak extends GraphVertexView {
public static transient BreakRenderer renderer = new BreakRenderer();
public static float xWIDTH = 1/7;
public static float xHEIGHT = 1/2;
public static float xSEPERATOR = xWIDTH/2;
public GraphItemBreak() {
super();
}
public GraphItemBreak(Object cell) {
super(cell);
}
/**
* Returns the intersection of the bounding rectangle and the straight line
* between the source and the specified point p. The specified point is
* expected not to intersect the bounds.
*/
// todo public Point2D getPerimeterPoint(Point source, Point p) {
/**
* getArcSize calculates an appropriate arc for the corners of the rectangle
* for boundary size cases of width and height
*/
public static int getArcSize(int width, int height) {
int arcSize;
if (width <= height) {
arcSize = height / 10;
if (arcSize > (width / 5)) {
arcSize = width / 5;
}
} else {
arcSize = width / 10;
if (arcSize > (height / 5)) {
arcSize = height / 5;
}
}
return arcSize;
}
public CellViewRenderer getRenderer() {
return renderer;
}
public static class BreakRenderer extends GraphVertexRender {
/**
* Return a slightly larger preferred size than for a rectangle.
*/
public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
d.width += d.height / 5;
//System.out.println("d1="+d);
return d;
}
public void paint(Graphics g) {
int b = borderWidth;
Graphics2D g2 = (Graphics2D) g;
//g2.setFont(new Font("SansSerif", Font.PLAIN, 10)); // select font
g2.setStroke(new BasicStroke(1.3f)); // 2 pixel lines
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // antialiasing
RenderingHints.VALUE_ANTIALIAS_ON);
//g2.translate(1, 1); // margins
Dimension d = getSize();
int roundRectArc = GraphItemGroup.getArcSize(d.width - b,d.height - b);
//System.out.println(d+",arc="+roundRectArc);
//Shape sp = new RoundRectangle2D.Float(b / 2, b / 2, d.width - (int) (b * 1.5),
// d.height - (int) (b * 1.5), roundRectArc, roundRectArc);
Shape sp = new RoundRectangle2D.Float(b/2+1, b/2+1, d.width-(int)(b*3), d.height-(int)(b*3), roundRectArc, roundRectArc);
RoundRectangle2D rr = (RoundRectangle2D)sp;
boolean tmp = selected;
//g2.setColor(Color.yellow); // Set a color
//g2.fill(sp); // Fill the shape with it
g2.setColor(Color.LIGHT_GRAY); // Switch to black
g2.draw(sp); // Outline the shape with it
g2.setPaint(new GradientPaint(b/2+1, b/2+1,new Color(232,232,232),(int) (b * 3), d.height - (int) (b * 3), Color.BLACK ));
g2.fill(sp);
//添加双竖线
paintBreak(g);
try {
//setBorder(new JGraphShadowBorder());
setBorder(null);
setOpaque(false);
selected = false;
super.paint(g);
} finally {
selected = tmp;
}
}
public void paintBreak(Graphics g){
Graphics2D g2 = (Graphics2D)g;
Dimension d = getSize();
//System.out.println("size="+d);
float x_mid = d.width/2;
float y_mid = d.height/2;
//System.out.println("x_mid="+x_mid+",y_mid="+y_mid);
float xwidth = d.width/7;
float xheight = d.height/2;
//System.out.println("width="+xwidth+",height="+xheight);
float x0 = x_mid - d.width*3/14;
float y0 = y_mid - d.height/4;
float x1 = x_mid + d.width/14;
float y1 = y_mid - d.height/4;
//System.out.println("x0="+x0+",y0="+y0);
//System.out.println("x1="+x1+",y1="+y1);
g2.setColor(Color.YELLOW);
Shape sp1 = new Rectangle2D.Float(x0,y0,xwidth,xheight);
g2.draw(sp1);
g2.setColor(Color.RED);
g2.fill(sp1);
Shape sp2 = new Rectangle2D.Float(x1,y1,xwidth,xheight);
g2.setColor(Color.YELLOW);
g2.draw(sp2);
g2.setColor(Color.RED);
g2.fill(sp2);
//System.out.println("GraphItemBreak..........");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -