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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
/*
* Copyright (c) 2005-2006, David Benson
*
* See LICENSE file in distribution for licensing details of this source file
*/
package com.jgraph.example.portlabels;
import java.util.Map;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultPort;
import org.jgraph.graph.ParentMap;
import org.jgraph.graph.Port;
/**
* Graph model cell that has a number of fixed offset ports on the left
* and right hand sides. It provides a number of utility methods to add
* and remove those ports.
*/
public class PortLabelCell extends DefaultGraphCell {
/**
* The number of ports on the left hand side of this cell
*/
protected int numLeftPorts = 0;
/**
* The number of ports on the right hand side of this cell
*/
protected int numRightPorts = 0;
/**
* Default constructor
*
*/
public PortLabelCell() {
this(null);
}
/**
* Constructor with user object to set for cell. Whatever the user object
* returns with toString will appear in the vertex label.
* @param userObject the userObject to set
*/
public PortLabelCell(Object userObject) {
super(userObject);
}
/**
* Adds a port with the specified label to the left hand side of the vertex
* at the specified position order
* @param position this ports position in the order of port from top to bottom
* @param portLabel the label to set for this port
* @return the new Port created
*/
public Port addLeftPort(int position, String portLabel, Map nestedMap, ParentMap parentMap) {
return addLeftPort(position, new DefaultPort(portLabel), nestedMap, parentMap);
}
/**
* Adds a port to the left hand side of the vertex at the specified
* position order
* @param position this ports position in the order of port from top to bottom
* @param port the instance of the new port
* @return the the port
*/
public Port addLeftPort(int position, Port port, Map nestedMap, ParentMap parentMap) {
if (position > numLeftPorts) {
throw new RuntimeException("Incorrect port position of left-hand side of cell");
}
return null;
}
/**
* Adds a port with the specified label to the right hand side of the vertex
* at the specified position order
* @param position this ports position in the order of port from top to bottom
* @param portLabel the label to set for this port
* @return the new Port created
*/
public Port addRightPort(int position, String portLabel, Map nestedMap, ParentMap parentMap) {
return addRightPort(position, new DefaultPort(portLabel), nestedMap, parentMap);
}
/**
* Adds a port to the right hand side of the vertex at the specified
* position order
* @param position this ports position in the order of port from top to bottom
* @param port the instance of the new port
* @return the the port
*/
public Port addRightPort(int position, Port port, Map nestedMap, ParentMap parentMap) {
if (position > numRightPorts) {
throw new RuntimeException("Incorrect port position of right-hand side of cell");
}
return null;
}
/**
* Removes the left-hand side port at the specified position order
* @param position the position order of the port to be removed
*/
public void removeLeftPort(int position, Map nestedMap, ParentMap parentMap) {
}
/**
* Removes the left-hand side port at the specified position order
* @param position the position order of the port to be removed
*/
public void removeRightPort(int position, Map nestedMap, ParentMap parentMap) {
}
/**
* @return Returns the numLeftPorts.
*/
public int getNumLeftPorts() {
return numLeftPorts;
}
/**
* @param numLeftPorts The numLeftPorts to set.
*/
public void setNumLeftPorts(int numLeftPorts) {
this.numLeftPorts = numLeftPorts;
}
/**
* @return Returns the numRightPorts.
*/
public int getNumRightPorts() {
return numRightPorts;
}
/**
* @param numRightPorts The numRightPorts to set.
*/
public void setNumRightPorts(int numRightPorts) {
this.numRightPorts = numRightPorts;
}
}
|