1/* 2 * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24package com.sun.hotspot.igv.graph; 25 26import com.sun.hotspot.igv.data.Source; 27import com.sun.hotspot.igv.layout.Link; 28import com.sun.hotspot.igv.layout.Port; 29import java.awt.Color; 30import java.awt.Point; 31import java.util.ArrayList; 32import java.util.List; 33 34/** 35 * 36 * @author Thomas Wuerthinger 37 */ 38public class Connection implements Source.Provider, Link { 39 40 @Override 41 public boolean isVIP() { 42 return style == ConnectionStyle.BOLD; 43 } 44 45 public enum ConnectionStyle { 46 47 NORMAL, 48 DASHED, 49 BOLD 50 } 51 private InputSlot inputSlot; 52 private OutputSlot outputSlot; 53 private Source source; 54 private Color color; 55 private ConnectionStyle style; 56 private List<Point> controlPoints; 57 private String label; 58 private String type; 59 60 protected Connection(InputSlot inputSlot, OutputSlot outputSlot, String label, String type) { 61 this.inputSlot = inputSlot; 62 this.outputSlot = outputSlot; 63 this.label = label; 64 this.type = type; 65 this.inputSlot.connections.add(this); 66 this.outputSlot.connections.add(this); 67 controlPoints = new ArrayList<>(); 68 Figure sourceFigure = this.outputSlot.getFigure(); 69 Figure destFigure = this.inputSlot.getFigure(); 70 sourceFigure.addSuccessor(destFigure); 71 destFigure.addPredecessor(sourceFigure); 72 source = new Source(); 73 74 this.color = Color.BLACK; 75 this.style = ConnectionStyle.NORMAL; 76 } 77 78 public InputSlot getInputSlot() { 79 return inputSlot; 80 } 81 82 public OutputSlot getOutputSlot() { 83 return outputSlot; 84 } 85 86 public Color getColor() { 87 return color; 88 } 89 90 public ConnectionStyle getStyle() { 91 return style; 92 } 93 94 public void setColor(Color c) { 95 color = c; 96 } 97 98 public void setStyle(ConnectionStyle s) { 99 style = s; 100 } 101 102 @Override 103 public Source getSource() { 104 return source; 105 } 106 107 public String getLabel() { 108 return label; 109 } 110 111 public String getType() { 112 return type; 113 } 114 115 public void remove() { 116 inputSlot.getFigure().removePredecessor(outputSlot.getFigure()); 117 inputSlot.connections.remove(this); 118 outputSlot.getFigure().removeSuccessor(inputSlot.getFigure()); 119 outputSlot.connections.remove(this); 120 } 121 122 public String getToolTipText() { 123 StringBuilder builder = new StringBuilder(); 124 if (label != null) { 125 builder.append(label).append(": "); 126 } 127 if (type != null) { 128 builder.append(type).append(" "); 129 } 130 builder.append("from "); 131 builder.append(getOutputSlot().getFigure().getSource().getSourceNodes().get(0).getId()); 132 builder.append(" to "); 133 builder.append(getInputSlot().getFigure().getSource().getSourceNodes().get(0).getId()); 134 return builder.toString(); 135 } 136 137 @Override 138 public String toString() { 139 return "Connection('" + label + "', " + getFrom().getVertex() + " to " + getTo().getVertex() + ")"; 140 } 141 142 @Override 143 public Port getFrom() { 144 return outputSlot; 145 } 146 147 @Override 148 public Port getTo() { 149 return inputSlot; 150 } 151 152 @Override 153 public List<Point> getControlPoints() { 154 return controlPoints; 155 } 156 157 @Override 158 public void setControlPoints(List<Point> list) { 159 controlPoints = list; 160 } 161} 162 163