001: /*
002: * Copyright (c) 2005-2006, David Benson
003: *
004: * See LICENSE file in distribution for licensing details of this source file
005: */
006: package com.jgraph.example.portlabels;
007:
008: import java.util.Map;
009:
010: import org.jgraph.graph.DefaultGraphCell;
011: import org.jgraph.graph.DefaultPort;
012: import org.jgraph.graph.ParentMap;
013: import org.jgraph.graph.Port;
014:
015: /**
016: * Graph model cell that has a number of fixed offset ports on the left
017: * and right hand sides. It provides a number of utility methods to add
018: * and remove those ports.
019: */
020: public class PortLabelCell extends DefaultGraphCell {
021:
022: /**
023: * The number of ports on the left hand side of this cell
024: */
025: protected int numLeftPorts = 0;
026:
027: /**
028: * The number of ports on the right hand side of this cell
029: */
030: protected int numRightPorts = 0;
031:
032: /**
033: * Default constructor
034: *
035: */
036: public PortLabelCell() {
037: this (null);
038: }
039:
040: /**
041: * Constructor with user object to set for cell. Whatever the user object
042: * returns with toString will appear in the vertex label.
043: * @param userObject the userObject to set
044: */
045: public PortLabelCell(Object userObject) {
046: super (userObject);
047: }
048:
049: /**
050: * Adds a port with the specified label to the left hand side of the vertex
051: * at the specified position order
052: * @param position this ports position in the order of port from top to bottom
053: * @param portLabel the label to set for this port
054: * @return the new Port created
055: */
056: public Port addLeftPort(int position, String portLabel,
057: Map nestedMap, ParentMap parentMap) {
058: return addLeftPort(position, new DefaultPort(portLabel),
059: nestedMap, parentMap);
060: }
061:
062: /**
063: * Adds a port to the left hand side of the vertex at the specified
064: * position order
065: * @param position this ports position in the order of port from top to bottom
066: * @param port the instance of the new port
067: * @return the the port
068: */
069: public Port addLeftPort(int position, Port port, Map nestedMap,
070: ParentMap parentMap) {
071: if (position > numLeftPorts) {
072: throw new RuntimeException(
073: "Incorrect port position of left-hand side of cell");
074: }
075: return null;
076: }
077:
078: /**
079: * Adds a port with the specified label to the right hand side of the vertex
080: * at the specified position order
081: * @param position this ports position in the order of port from top to bottom
082: * @param portLabel the label to set for this port
083: * @return the new Port created
084: */
085: public Port addRightPort(int position, String portLabel,
086: Map nestedMap, ParentMap parentMap) {
087: return addRightPort(position, new DefaultPort(portLabel),
088: nestedMap, parentMap);
089: }
090:
091: /**
092: * Adds a port to the right hand side of the vertex at the specified
093: * position order
094: * @param position this ports position in the order of port from top to bottom
095: * @param port the instance of the new port
096: * @return the the port
097: */
098: public Port addRightPort(int position, Port port, Map nestedMap,
099: ParentMap parentMap) {
100: if (position > numRightPorts) {
101: throw new RuntimeException(
102: "Incorrect port position of right-hand side of cell");
103: }
104: return null;
105: }
106:
107: /**
108: * Removes the left-hand side port at the specified position order
109: * @param position the position order of the port to be removed
110: */
111: public void removeLeftPort(int position, Map nestedMap,
112: ParentMap parentMap) {
113:
114: }
115:
116: /**
117: * Removes the left-hand side port at the specified position order
118: * @param position the position order of the port to be removed
119: */
120: public void removeRightPort(int position, Map nestedMap,
121: ParentMap parentMap) {
122:
123: }
124:
125: /**
126: * @return Returns the numLeftPorts.
127: */
128: public int getNumLeftPorts() {
129: return numLeftPorts;
130: }
131:
132: /**
133: * @param numLeftPorts The numLeftPorts to set.
134: */
135: public void setNumLeftPorts(int numLeftPorts) {
136: this .numLeftPorts = numLeftPorts;
137: }
138:
139: /**
140: * @return Returns the numRightPorts.
141: */
142: public int getNumRightPorts() {
143: return numRightPorts;
144: }
145:
146: /**
147: * @param numRightPorts The numRightPorts to set.
148: */
149: public void setNumRightPorts(int numRightPorts) {
150: this.numRightPorts = numRightPorts;
151: }
152:
153: }
|