1 /** 2 * Copyright (c) 2007, Gaudenz Alder 3 */ 4 package com.mxgraph.model; 5 6 import com.mxgraph.util.mxEventSource.mxIEventListener; 7 import com.mxgraph.util.mxUndoableEdit.mxUndoableChange; 8 9 /** 10 * Defines the requirements for a graph model to be used with mxGraph. 11 */ 12 public interface mxIGraphModel 13 { 14 15 /** 16 * Defines the interface for an atomic change of the graph model. 17 */ 18 public abstract class mxAtomicGraphModelChange implements mxUndoableChange 19 { 20 /** 21 * Holds the model where the change happened. 22 */ 23 protected mxIGraphModel model; 24 25 /** 26 * Constructs an empty atomic graph model change. 27 */ mxAtomicGraphModelChange()28 public mxAtomicGraphModelChange() 29 { 30 this(null); 31 } 32 33 /** 34 * Constructs an atomic graph model change for the given model. 35 */ mxAtomicGraphModelChange(mxIGraphModel model)36 public mxAtomicGraphModelChange(mxIGraphModel model) 37 { 38 this.model = model; 39 } 40 41 /** 42 * Returns the model where the change happened. 43 */ getModel()44 public mxIGraphModel getModel() 45 { 46 return model; 47 } 48 49 /** 50 * Sets the model where the change is to be carried out. 51 */ setModel(mxIGraphModel model)52 public void setModel(mxIGraphModel model) 53 { 54 this.model = model; 55 } 56 57 /** 58 * Executes the change on the model. 59 */ execute()60 public abstract void execute(); 61 62 } 63 64 /** 65 * Returns the root of the model or the topmost parent of the given cell. 66 * 67 * @return Returns the root cell. 68 */ getRoot()69 Object getRoot(); 70 71 /** 72 * Sets the root of the model and resets all structures. 73 * 74 * @param root Cell that specifies the new root. 75 */ setRoot(Object root)76 Object setRoot(Object root); 77 78 /** 79 * Returns an array of clones for the given array of cells. 80 * Depending on the value of includeChildren, a deep clone is created for 81 * each cell. Connections are restored based if the corresponding 82 * cell is contained in the passed in array. 83 * 84 * @param cells Array of cells to be cloned. 85 * @param includeChildren Boolean indicating if the cells should be cloned 86 * with all descendants. 87 * @return Returns a cloned array of cells. 88 */ cloneCells(Object[] cells, boolean includeChildren)89 Object[] cloneCells(Object[] cells, boolean includeChildren); 90 91 /** 92 * Returns true if the given parent is an ancestor of the given child. 93 * 94 * @param parent Cell that specifies the parent. 95 * @param child Cell that specifies the child. 96 * @return Returns true if child is an ancestor of parent. 97 */ isAncestor(Object parent, Object child)98 boolean isAncestor(Object parent, Object child); 99 100 /** 101 * Returns true if the model contains the given cell. 102 * 103 * @param cell Cell to be checked. 104 * @return Returns true if the cell is in the model. 105 */ contains(Object cell)106 boolean contains(Object cell); 107 108 /** 109 * Returns the parent of the given cell. 110 * 111 * @param child Cell whose parent should be returned. 112 * @return Returns the parent of the given cell. 113 */ getParent(Object child)114 Object getParent(Object child); 115 116 /** 117 * Adds the specified child to the parent at the given index. If no index 118 * is specified then the child is appended to the parent's array of 119 * children. 120 * 121 * @param parent Cell that specifies the parent to contain the child. 122 * @param child Cell that specifies the child to be inserted. 123 * @param index Integer that specifies the index of the child. 124 * @return Returns the inserted child. 125 */ add(Object parent, Object child, int index)126 Object add(Object parent, Object child, int index); 127 128 /** 129 * Removes the specified cell from the model. This operation will remove 130 * the cell and all of its children from the model. 131 * 132 * @param cell Cell that should be removed. 133 * @return Returns the removed cell. 134 */ remove(Object cell)135 Object remove(Object cell); 136 137 /** 138 * Returns the number of children in the given cell. 139 * 140 * @param cell Cell whose number of children should be returned. 141 * @return Returns the number of children in the given cell. 142 */ getChildCount(Object cell)143 int getChildCount(Object cell); 144 145 /** 146 * Returns the child of the given parent at the given index. 147 * 148 * @param parent Cell that represents the parent. 149 * @param index Integer that specifies the index of the child to be 150 * returned. 151 * @return Returns the child at index in parent. 152 */ getChildAt(Object parent, int index)153 Object getChildAt(Object parent, int index); 154 155 /** 156 * Returns the source or target terminal of the given edge depending on the 157 * value of the boolean parameter. 158 * 159 * @param edge Cell that specifies the edge. 160 * @param isSource Boolean indicating which end of the edge should be 161 * returned. 162 * @return Returns the source or target of the given edge. 163 */ getTerminal(Object edge, boolean isSource)164 Object getTerminal(Object edge, boolean isSource); 165 166 /** 167 * Sets the source or target terminal of the given edge using. 168 * 169 * @param edge Cell that specifies the edge. 170 * @param terminal Cell that specifies the new terminal. 171 * @param isSource Boolean indicating if the terminal is the new source or 172 * target terminal of the edge. 173 * @return Returns the new terminal. 174 */ setTerminal(Object edge, Object terminal, boolean isSource)175 Object setTerminal(Object edge, Object terminal, boolean isSource); 176 177 /** 178 * Returns the number of distinct edges connected to the given cell. 179 * 180 * @param cell Cell that represents the vertex. 181 * @return Returns the number of edges connected to cell. 182 */ getEdgeCount(Object cell)183 int getEdgeCount(Object cell); 184 185 /** 186 * Returns the edge of cell at the given index. 187 * 188 * @param cell Cell that specifies the vertex. 189 * @param index Integer that specifies the index of the edge to return. 190 * @return Returns the edge at the given index. 191 */ getEdgeAt(Object cell, int index)192 Object getEdgeAt(Object cell, int index); 193 194 /** 195 * Returns true if the given cell is a vertex. 196 * 197 * @param cell Cell that represents the possible vertex. 198 * @return Returns true if the given cell is a vertex. 199 */ isVertex(Object cell)200 boolean isVertex(Object cell); 201 202 /** 203 * Returns true if the given cell is an edge. 204 * 205 * @param cell Cell that represents the possible edge. 206 * @return Returns true if the given cell is an edge. 207 */ isEdge(Object cell)208 boolean isEdge(Object cell); 209 210 /** 211 * Returns true if the given cell is connectable. 212 * 213 * @param cell Cell whose connectable state should be returned. 214 * @return Returns the connectable state of the given cell. 215 */ isConnectable(Object cell)216 boolean isConnectable(Object cell); 217 218 /** 219 * Returns the user object of the given cell. 220 * 221 * @param cell Cell whose user object should be returned. 222 * @return Returns the user object of the given cell. 223 */ getValue(Object cell)224 Object getValue(Object cell); 225 226 /** 227 * Sets the user object of then given cell. 228 * 229 * @param cell Cell whose user object should be changed. 230 * @param value Object that defines the new user object. 231 * @return Returns the new value. 232 */ setValue(Object cell, Object value)233 Object setValue(Object cell, Object value); 234 235 /** 236 * Returns the geometry of the given cell. 237 * 238 * @param cell Cell whose geometry should be returned. 239 * @return Returns the geometry of the given cell. 240 */ getGeometry(Object cell)241 mxGeometry getGeometry(Object cell); 242 243 /** 244 * Sets the geometry of the given cell. 245 * 246 * @param cell Cell whose geometry should be changed. 247 * @param geometry Object that defines the new geometry. 248 * @return Returns the new geometry. 249 */ setGeometry(Object cell, mxGeometry geometry)250 mxGeometry setGeometry(Object cell, mxGeometry geometry); 251 252 /** 253 * Returns the style of the given cell. 254 * 255 * @param cell Cell whose style should be returned. 256 * @return Returns the style of the given cell. 257 */ getStyle(Object cell)258 String getStyle(Object cell); 259 260 /** 261 * Sets the style of the given cell. 262 * 263 * @param cell Cell whose style should be changed. 264 * @param style String of the form stylename[;key=value] to specify 265 * the new cell style. 266 * @return Returns the new style. 267 */ setStyle(Object cell, String style)268 String setStyle(Object cell, String style); 269 270 /** 271 * Returns true if the given cell is collapsed. 272 * 273 * @param cell Cell whose collapsed state should be returned. 274 * @return Returns the collapsed state of the given cell. 275 */ isCollapsed(Object cell)276 boolean isCollapsed(Object cell); 277 278 /** 279 * Sets the collapsed state of the given cell. 280 * 281 * @param cell Cell whose collapsed state should be changed. 282 * @param collapsed Boolean that specifies the new collpased state. 283 * @return Returns the new collapsed state. 284 */ setCollapsed(Object cell, boolean collapsed)285 boolean setCollapsed(Object cell, boolean collapsed); 286 287 /** 288 * Returns true if the given cell is visible. 289 * 290 * @param cell Cell whose visible state should be returned. 291 * @return Returns the visible state of the given cell. 292 */ isVisible(Object cell)293 boolean isVisible(Object cell); 294 295 /** 296 * Sets the visible state of the given cell. 297 * 298 * @param cell Cell whose visible state should be changed. 299 * @param visible Boolean that specifies the new visible state. 300 * @return Returns the new visible state. 301 */ setVisible(Object cell, boolean visible)302 boolean setVisible(Object cell, boolean visible); 303 304 /** 305 * Increments the updateLevel by one. The event notification is queued 306 * until updateLevel reaches 0 by use of endUpdate. 307 */ beginUpdate()308 void beginUpdate(); 309 310 /** 311 * Decrements the updateLevel by one and fires a notification event if the 312 * updateLevel reaches 0. 313 */ endUpdate()314 void endUpdate(); 315 316 /** 317 * Binds the specified function to the given event name. If no event name 318 * is given, then the listener is registered for all events. 319 */ addListener(String eventName, mxIEventListener listener)320 void addListener(String eventName, mxIEventListener listener); 321 322 /** 323 * Function: removeListener 324 * 325 * Removes the given listener from the list of listeners. 326 */ removeListener(mxIEventListener listener)327 void removeListener(mxIEventListener listener); 328 329 /** 330 * Function: removeListener 331 * 332 * Removes the given listener from the list of listeners. 333 */ removeListener(mxIEventListener listener, String eventName)334 void removeListener(mxIEventListener listener, String eventName); 335 336 } 337