📄 graphextends.java
字号:
String host = convertValueToString(graphModel.getParent(target));
String port = convertValueToString(target);
s = s + "Target: " + host + "/" + port + "<br>";
}
}
return s;
}
public DefaultGraphCell getVertexHandle(JGraph graph, Point2D pt) {
Object[] cells = graph.getRoots();
//System.out.println("pt="+pt);
for (int i = 0; i < cells.length; i++) {
//System.out.println("class="+cells[i].getClass());
if(cells[i] instanceof DefaultEdge){
continue;
}
else if(cells[i] instanceof DefaultPort){
continue;
}
DefaultGraphCell cell = (DefaultGraphCell)cells[i];
DefaultGraphCell cell1 = getVertexHandle(graph, cell, pt);
if(cell1 != null)
return cell1;
}
return null;
}
public DefaultGraphCell getVertexHandle(JGraph graph, DefaultGraphCell cell, Point2D pt) {
if(cell != null){
Point2D containerPoint = graph.fromScreen((Point2D) pt.clone());
if(cell.getAttributes() == null){
//System.out.println("cell.getAttributes() == null");
return null;
}
if(GraphConstants.getBounds(cell.getAttributes()) == null){
//System.out.println("GraphConstants.getBounds(cell.getAttributes()) == null");
return null;
}
//System.out.println(cell+"'count="+cell.getChildCount());
if(DefaultGraphModel.isGroup(graph.getModel(), cell)){
for(int i=0;i<cell.getChildCount();i++){
if(cell.getChildAt(i) instanceof DefaultEdge){
continue;
}
else if(cell.getChildAt(i) instanceof DefaultPort){
continue;
}
DefaultGraphCell cell1 = (DefaultGraphCell)cell.getChildAt(i);
if(DefaultGraphModel.isGroup(graph.getModel(), cell)){
DefaultGraphCell cell2 = getVertexHandle(graph, cell1, pt);
if(cell2 != null)
return cell2;
}
}
Rectangle2D rec = graph.getCellBounds(cell.getChildren().toArray());
int inset = GraphConstants.getInset(cell.getAttributes());
Rectangle2D rect = new Rectangle2D.Float((int)rec.getX()-inset, (int)rec.getY()-inset, (int)rec.getWidth()+inset*2, (int)rec.getHeight()+inset*2);
if (rect.contains(containerPoint.getX(), containerPoint.getY())) {
return cell;
}
}
else{
if (GraphConstants.getBounds(cell.getAttributes()).contains(containerPoint.getX(), containerPoint.getY())) {
return cell;
}
}
}
return null;
}
/**
* Notification from the <code>UIManager</code> that the L&F has changed.
* Replaces the current UI object with the latest version from the
* <code>UIManager</code>. Subclassers can override this to support
* different GraphUIs.
*
* @see JComponent#updateUI
*
*/
/*
public void updateUI() {
setUI(new GPGraphUI());
invalidate();
}
*/
/**
* Returns true if the given vertices are conntected by a single edge in
* this document.
*/
public boolean isNeighbour(Object v1, Object v2) {
return DefaultGraphModel.containsEdgeBetween(this.getModel(), v1, v2);
}
// Serialization support
private void readObject(ObjectInputStream s) throws IOException,
ClassNotFoundException {
s.defaultReadObject();
}
//获取BPEL Message类型
public Messages getBPELMessages(){
Messages messages = new Messages();
Object[] cells = getRoots();
for(int i=0;i<cells.length;i++){
if(cells[i] instanceof FlowGraphCell){
FlowGraphCell cell = (FlowGraphCell)cells[i];
if(FlowGraphConstants.getBpelType(cell.getAttributes()).equals(BPELFlag.BPEL_ASSIGN)){
//Message类型由AssignCell存储
//每个Assign中生成Message、Container、Assign等类型
if(FlowGraphConstants.getBpelMessages(cell.getAttributes()) != null){
Vector v = ((Messages)FlowGraphConstants.getBpelMessages(cell.getAttributes())).getMessages();
if(v != null){
for(int j=0;j<v.size();j++){
messages.addMessage((Message)v.get(j));
}
}
}
}
}
}
return messages;
}
public boolean isGroupCell(DefaultGraphCell cell){
if(cell != null){
if(cell.getParent() != null)
return true;
}
return false;
}
public boolean isGroup(DefaultGraphCell cell){
if(cell != null){
if(cell.getChildCount() > 1)
return true;
}
return false;
}
//public
public boolean hasFather(DefaultGraphCell cell){
if(cell != null){
if(cell.getParent() != null)
return true;
}
return false;
}
public boolean hasFather(DefaultPort port){
if(port == null)
return false;
return hasFather((DefaultGraphCell)port.getParent());
}
public boolean isBrotherCell(DefaultGraphCell cell1, DefaultGraphCell cell2){
if(cell1 == null || cell2 == null){
return false;
}
if(cell1.getParent() == null || cell2.getParent() == null){
return false;
}
if(cell1.getParent().equals(cell2.getParent()))
return true;
return false;
}
public DefaultGraphCell getFather(DefaultGraphCell cell){
if(cell != null)
return (DefaultGraphCell)cell.getParent();
return null;
}
public boolean isBrotherPort(DefaultPort port1, DefaultPort port2){
if(port1 == null || port2 == null)
return false;
if(port1.getParent() == null || port2.getParent() == null)
return false;
return isBrotherCell((DefaultGraphCell)port1.getParent(), (DefaultGraphCell)port2.getParent());
}
//判断是否是亲兄弟
public boolean isDirectBrother(DefaultPort port1, DefaultPort port2){
//true,不可连
//System.out.println("1..............");
if(port1 == null || port2 == null){
//System.out.println("2..............");
return true;
}
DefaultGraphCell cell1 = (DefaultGraphCell)port1.getParent();
DefaultGraphCell cell2 = (DefaultGraphCell)port2.getParent();
//System.out.println("3..............");
if(hasFather(cell1) == false && hasFather(cell2) == false){
//都没有父亲,可连
return false;
}
if(hasFather(cell1)){
//cell1有父亲
DefaultGraphCell father1 = getFather(cell1);
if(hasFather(cell2)){
//cell2也有父亲
DefaultGraphCell father2 = getFather(cell2);
if(father1.equals(father2)){
//相同的父亲,可连
return false;
}
else{
//不是相同父亲
return true;
}
}
else{
//cell2没有父亲,不可连
return true;
}
}
if(hasFather(cell2)){
//cell1有父亲
DefaultGraphCell father2 = getFather(cell2);
if(hasFather(cell1)){
//cell2也有父亲
DefaultGraphCell father1 = getFather(cell1);
if(father2.equals(father1)){
//相同的父亲,可连
return false;
}
else{
//不是相同父亲
return true;
}
}
else{
//cell2没有父亲,不可连
return true;
}
}
return false;
}
//判断父子关系
public boolean isFatherAndSon(DefaultPort port1, DefaultPort port2){
if(port1 == null || port2 == null)
return false;
if(port1.getParent() == null || port2.getParent() == null)
return false;
DefaultGraphCell cell1 = (DefaultGraphCell)port1.getParent();
DefaultGraphCell cell2 = (DefaultGraphCell)port2.getParent();
if(cell1.getParent() == null){
//cell1为组
if(cell2.getParent() != null){
//cell2为子
if(cell2.getParent().equals(cell1))
return true;
}
}
if(cell2.getParent() == null){
//cell1为组
if(cell1.getParent() != null){
//cell2为子
if(cell1.getParent().equals(cell2))
return true;
}
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -