GraphManager.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. package de.tu_darmstadt.informatik.tk.scopviz.graphs;
  2. import java.util.Collection;
  3. import java.util.HashMap;
  4. import java.util.LinkedList;
  5. import org.graphstream.graph.Edge;
  6. import org.graphstream.graph.Element;
  7. import org.graphstream.graph.Node;
  8. import org.graphstream.ui.swingViewer.ViewPanel;
  9. import org.graphstream.ui.view.Viewer;
  10. import org.graphstream.ui.view.ViewerPipe;
  11. import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
  12. import de.tu_darmstadt.informatik.tk.scopviz.main.CreationMode;
  13. import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
  14. import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
  15. import de.tu_darmstadt.informatik.tk.scopviz.ui.GraphDisplayManager;
  16. import de.tu_darmstadt.informatik.tk.scopviz.ui.PropertiesManager;
  17. import de.tu_darmstadt.informatik.tk.scopviz.ui.StylesheetManager;
  18. import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.MyMouseManager;
  19. /**
  20. * Interface between GUI and internal Graph representation. Manages internal
  21. * representation of the Graph to accommodate creation and deletion of nodes and
  22. * edges.
  23. *
  24. * @author Jascha Bohne
  25. * @version 3.0.0.0
  26. *
  27. */
  28. public class GraphManager {
  29. /** String for the processing enabled type of node. */
  30. public static final String UI_CLASS_PROCESSING_ENABLED = "procEn";
  31. /** The Graph this instance of GraphManager manages. */
  32. protected MyGraph g;
  33. protected MyGraph activeSubGraph;
  34. /**
  35. * The Stylesheet for this Graph, excluding parts that can be set by
  36. * NodeGraphics.
  37. */
  38. protected String stylesheet = "";
  39. /** The last Node that was deleted. */
  40. protected Node deletedNode;
  41. /** The last Edge that was deleted. */
  42. protected LinkedList<Edge> deletedEdges = new LinkedList<>();
  43. /** The currently selected Node, mutually exclusive with selectedEdgeID. */
  44. protected String selectedNodeID = null;
  45. /** The currently selected Edge, mutually exclusive with selectedNodeID. */
  46. protected String selectedEdgeID = null;
  47. /** The ViewPanel the Graph is drawn in. */
  48. protected ViewPanel view;
  49. /** The Path on Disk the Graph will be saved to. */
  50. protected String currentPath;
  51. /** The Viewer the Graph provides, grants Access to Camera Manipulation. */
  52. protected Viewer viewer;
  53. /**
  54. * The Pipe that notifies the underlying Graph of any Changes within the
  55. * graphic Representation.
  56. */
  57. protected ViewerPipe fromViewer;
  58. /**
  59. * The Id of the Node that was last clicked.
  60. */
  61. protected String lastClickedID;
  62. /**
  63. * Creates a new Manager for the given graph.
  64. *
  65. * @param graph
  66. * the graph this visualizer should handle
  67. */
  68. public GraphManager(MyGraph graph) {
  69. g = graph;
  70. /* Viewer */ viewer = new Viewer(g, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
  71. view = viewer.addDefaultView(false);
  72. viewer.setCloseFramePolicy(Viewer.CloseFramePolicy.EXIT);
  73. /* ViewerPipe */fromViewer = viewer.newViewerPipe();
  74. view.setMouseManager(new MyMouseManager(this));
  75. fromViewer.addSink(graph);
  76. fromViewer.removeElementSink(graph);
  77. }
  78. /**
  79. * Deletes the Node corresponding to the given ID from the Graph. The
  80. * referenced Graph is modified directly. Will throw an
  81. * ElementNotFoundException, when the Node is not Found Will also remove all
  82. * Edges connected to the given Node
  83. *
  84. * @param id
  85. * the ID of the node that will be removed
  86. */
  87. public void deleteNode(final String id) {
  88. deletedEdges.removeAll(deletedEdges);
  89. deletedNode = null;
  90. // Edges have to be deleted first because they clear deletedNode
  91. // and need the Node to still be in the Graph
  92. deleteEdgesOfNode(id);
  93. deletedNode = g.removeNode(id);
  94. }
  95. /**
  96. * Deletes the Edge corresponding to the given ID from the Graph. The
  97. * referenced Graph is modified directly. Will throw an
  98. * ElementNotFoundException, when the Edge is not Found
  99. *
  100. * @param id
  101. * the ID of the Edge that will be removed
  102. */
  103. public void deleteEdge(final String id) {
  104. deselect();
  105. deletedEdges.removeAll(deletedEdges);
  106. deletedNode = null;
  107. deletedEdges.add(g.removeEdge(id));
  108. }
  109. /**
  110. * Deletes all Edges connected to the given Node. The referenced Graph is
  111. * modified directly. Will throw an ElementNotFoundException if the Node is
  112. * not Found
  113. *
  114. * @param id
  115. * the Id of the Node, whose Edges shall be removed
  116. */
  117. protected void deleteEdgesOfNode(final String id) {
  118. deselect();
  119. Node node = g.getNode(id);
  120. deletedEdges.removeAll(deletedEdges);
  121. deletedNode = null;
  122. Edge[] temp = new Edge[0];
  123. temp = g.getEdgeSet().toArray(temp);
  124. for (Edge e : temp) {
  125. if (e.getSourceNode().equals(node) || e.getTargetNode().equals(node)) {
  126. // adds the Edge to the list of deleted Edges and remove sit
  127. // from the Graph
  128. deletedEdges.add(g.removeEdge(e));
  129. }
  130. }
  131. GraphHelper.propagateElementDeletion(g, deletedEdges);
  132. }
  133. /**
  134. * Undoes the last deleting operation on the given Graph. Deleting
  135. * operations are: deleteNode, deleteEdge and deleteEdgesOfNode. Only undoes
  136. * the last deleting operation even if that operation didn't change the
  137. * Graph
  138. */
  139. public void undelete() {
  140. String newId = "";
  141. HashMap<String, Object> attributes = new HashMap<String, Object>();
  142. if (deletedNode != null) {
  143. for (String s : deletedNode.getAttributeKeySet()) {
  144. attributes.put(s, deletedNode.getAttribute(s));
  145. }
  146. newId = Main.getInstance().getUnusedID();
  147. g.addNode(newId);
  148. g.getNode(newId).addAttributes(attributes);
  149. String origElement = GraphHelper.propagateElementUndeletion(g, deletedNode, null);
  150. if (origElement != null) {
  151. g.getNode(newId).addAttribute("originalElement", origElement);
  152. }
  153. }
  154. for (Edge e : deletedEdges) {
  155. String sourceId = null;
  156. String targetId = null;
  157. attributes = new HashMap<String, Object>();
  158. for (String s : e.getAttributeKeySet()) {
  159. attributes.put(s, e.getAttribute(s));
  160. }
  161. String id = Main.getInstance().getUnusedID();
  162. if (deletedNode != null) {
  163. sourceId = (e.getSourceNode().getId().equals(deletedNode.getId())) ? newId : e.getSourceNode().getId();
  164. targetId = (e.getTargetNode().getId().equals(deletedNode.getId())) ? newId : e.getTargetNode().getId();
  165. } else {
  166. sourceId = e.getSourceNode().getId();
  167. targetId = e.getTargetNode().getId();
  168. }
  169. g.addEdge(id, sourceId, targetId, e.isDirected());
  170. g.getEdge(id).addAttributes(attributes);
  171. String origElement = GraphHelper.propagateElementUndeletion(g, e,
  172. g.getNode(newId).getAttribute("originalElement"));
  173. if (origElement != null) {
  174. g.getEdge(id).addAttribute("originalElement", origElement);
  175. }
  176. }
  177. deletedEdges = new LinkedList<>();
  178. deletedNode = null;
  179. }
  180. /**
  181. * @return the activeSubGraph
  182. */
  183. public MyGraph getActiveSubGraph() {
  184. return activeSubGraph;
  185. }
  186. /**
  187. * returns a View of the Graph. The View lives in the Swing Thread and the
  188. * Graph in the Main thread.
  189. *
  190. *
  191. * @return a View of the Graph, inheriting from JPanel
  192. */
  193. public ViewPanel getView() {
  194. return view;
  195. }
  196. /**
  197. * Returns the ID of the currently selected Node.
  198. *
  199. * @return the node's ID
  200. */
  201. public String getSelectedNodeID() {
  202. return selectedNodeID;
  203. }
  204. /**
  205. * Returns the ID of the currently selected Edge.
  206. *
  207. * @return the edge's ID
  208. */
  209. public String getSelectedEdgeID() {
  210. return selectedEdgeID;
  211. }
  212. /**
  213. * Selects the Node with the given ID, resets Edge selection.
  214. *
  215. * @param nodeID
  216. * the ID of the Node to select
  217. */
  218. public void selectNode(String nodeID) {
  219. if (nodeID != null && g.getNode(nodeID) != null) {
  220. deselect();
  221. this.selectedNodeID = nodeID;
  222. Node n = g.getNode(nodeID);
  223. // set selected node color to red
  224. if (!hasClass(n, UI_CLASS_PROCESSING_ENABLED)
  225. || !GraphDisplayManager.getCurrentLayer().equals(Layer.MAPPING)) {
  226. n.changeAttribute("ui.style", "fill-color : #F00; size: 15px;");
  227. PropertiesManager.setItemsProperties();
  228. }
  229. }
  230. }
  231. /**
  232. * Selects the Edge with the given ID, resets Node selection.
  233. *
  234. * @param edgeID
  235. * the ID of the Edge to select
  236. */
  237. public void selectEdge(String edgeID) {
  238. if (edgeID != null && g.getEdge(edgeID) != null) {
  239. deselect();
  240. this.selectedEdgeID = edgeID;
  241. addClass(edgeID, "selected");
  242. PropertiesManager.setItemsProperties();
  243. }
  244. }
  245. /**
  246. * Deselect any currently selected nodes or edges.
  247. */
  248. // TODO call this before save
  249. protected void deselect() {
  250. // Set last selected Edge Color to Black
  251. if (getSelectedEdgeID() != null && g.getEdge(getSelectedEdgeID()) != null) {
  252. removeClass(getSelectedEdgeID(), "selected");
  253. }
  254. // Set last selected Node color to black
  255. else if (getSelectedNodeID() != null && g.getNode(getSelectedNodeID()) != null) {
  256. Node n = g.getNode(getSelectedNodeID());
  257. if (!hasClass(n, UI_CLASS_PROCESSING_ENABLED)
  258. || !GraphDisplayManager.getCurrentLayer().equals(Layer.MAPPING)) {
  259. String nodeType = n.getAttribute("ui.class");
  260. n.removeAttribute("ui.style");
  261. n.changeAttribute("ui.style", "fill-color: #000000; size: 15px;");
  262. n.changeAttribute("ui.class", nodeType.split("_")[0]);
  263. }
  264. }
  265. this.selectedNodeID = null;
  266. this.selectedEdgeID = null;
  267. }
  268. /**
  269. * Returns a reference to the Graph object managed by this visualizer.
  270. *
  271. * @return the graph
  272. */
  273. public MyGraph getGraph() {
  274. return g;
  275. }
  276. /**
  277. * Zooms in the view of the graph by 5 percent.
  278. */
  279. public void zoomIn() {
  280. zoom(-0.05);
  281. }
  282. /**
  283. * Zooms out the view of the graph by 5 percent.
  284. */
  285. public void zoomOut() {
  286. zoom(0.05);
  287. }
  288. /**
  289. * Zooms the view by the given Amount, positive values zoom out, negative
  290. * values zoom in.
  291. *
  292. * @param amount
  293. * the amount of zoom, should usually be between -0.2 and 0.2 for
  294. * reasonable zoom.
  295. */
  296. public void zoom(double amount) {
  297. view.getCamera().setViewPercent(view.getCamera().getViewPercent() * (1 + amount));
  298. }
  299. /**
  300. * Pumps the Pipe from the graphical Representation to the underlying Graph,
  301. * propagating all Changes made.
  302. */
  303. public void pumpIt() {
  304. fromViewer.pump();
  305. }
  306. @Override
  307. public String toString() {
  308. return "Visualizer for Graph \"" + g.getId() + "\"";
  309. }
  310. /**
  311. * Returns the current Save Path on Disk for the Graph.
  312. *
  313. * @return the current Path
  314. */
  315. public String getCurrentPath() {
  316. return currentPath;
  317. }
  318. /**
  319. * Sets the Save Path.
  320. *
  321. * @param currentPath
  322. * the new Path to set
  323. */
  324. public void setCurrentPath(String currentPath) {
  325. this.currentPath = currentPath;
  326. }
  327. /**
  328. * Adds a <b>Copy</b> of the given Node to the graph. The Copy retains the
  329. * ID and all attributes.
  330. *
  331. * @param n
  332. * the Node to be added to the graph
  333. */
  334. public void addNode(Node n) {
  335. HashMap<String, Object> attributes = new HashMap<>();
  336. for (String s : n.getAttributeKeySet()) {
  337. attributes.put(s, n.getAttribute(s));
  338. }
  339. String nodeId = activeSubGraph.getId() + n.getId();
  340. g.addNode(nodeId);
  341. g.getNode(nodeId).addAttributes(attributes);
  342. if (activeSubGraph != null && !activeSubGraph.equals(g)) {
  343. activeSubGraph.addNode(n.getId());
  344. activeSubGraph.getNode(n.getId()).addAttributes(attributes);
  345. g.getNode(nodeId).addAttribute("originalElement", activeSubGraph.getId() + "+#" + n.getId());
  346. g.getNode(nodeId).addAttribute("originalGraph", activeSubGraph.getId());
  347. }
  348. }
  349. /**
  350. * Returns the smallest X Coordinate of any Node in the Graph.
  351. *
  352. * @return the smallest X Coordinate in the Graph
  353. */
  354. public double getMinX() {
  355. return g.getMinX();
  356. }
  357. /**
  358. * Returns the biggest X Coordinate of any Node in the Graph.
  359. *
  360. * @return the biggest X Coordinate in the Graph
  361. */
  362. public double getMaxX() {
  363. return g.getMaxX();
  364. }
  365. /**
  366. * Returns the smallest Y Coordinate of any Node in the Graph.
  367. *
  368. * @return the smallest Y Coordinate in the Graph
  369. */
  370. public double getMinY() {
  371. return g.getMinY();
  372. }
  373. /**
  374. * Returns the biggest Y Coordinate of any Node in the Graph.
  375. *
  376. * @return the biggest Y Coordinate in the Graph
  377. */
  378. public double getMaxY() {
  379. return g.getMaxY();
  380. }
  381. /**
  382. * Returns the Stylesheet used by the Graph.
  383. *
  384. * @return the Stylesheet in use
  385. */
  386. public String getStylesheet() {
  387. return stylesheet;
  388. }
  389. /**
  390. * Sets the Stylesheet to be used by the Graph.
  391. *
  392. * @param stylesheet
  393. * the new stylesheet to use
  394. */
  395. public void setStylesheet(String stylesheet) {
  396. this.stylesheet = stylesheet;
  397. g.removeAttribute("ui.stylesheet");
  398. String completeStylesheet = stylesheet;
  399. completeStylesheet = completeStylesheet.concat(StylesheetManager.getNodeStylesheet());
  400. completeStylesheet = completeStylesheet
  401. .concat(StylesheetManager.getLayerStyle((Layer) g.getAttribute("layer")));
  402. g.addAttribute("ui.stylesheet", completeStylesheet);
  403. }
  404. /**
  405. * adds the given listener to the underlying graph the listener will be
  406. * notified, when an Edge is added.
  407. *
  408. * @param e
  409. * the EdgeCreatedListener
  410. */
  411. public void addEdgeCreatedListener(EdgeCreatedListener e) {
  412. ((MyGraph) g).addEdgeCreatedListener(e);
  413. }
  414. /**
  415. * adds the given listener to the underlying graph the listener will be
  416. * notified, when a Node is added.
  417. *
  418. * @param n
  419. * the NodeCreatedListener
  420. */
  421. public void addNodeCreatedListener(NodeCreatedListener n) {
  422. ((MyGraph) g).addNodeCreatedListener(n);
  423. }
  424. /**
  425. * Updates the Stylesheet, causing any changes to it to come into effect.
  426. */
  427. public void updateStylesheet() {
  428. setStylesheet(this.stylesheet);
  429. }
  430. /**
  431. * Sets typeofNode as the ui.class of all Nodes.
  432. *
  433. */
  434. public void convertUiClass() {
  435. Collection<Node> allNodes = g.getNodeSet();
  436. for (Node n : allNodes) {
  437. if (n.hasAttribute("typeofNode")) {
  438. n.addAttribute("ui.class", n.getAttribute("typeofNode").toString());
  439. }
  440. }
  441. }
  442. /**
  443. * Create Edges based on CreateMode.
  444. *
  445. * @param id
  446. * The ID for the newly created Edge
  447. */
  448. public void createEdges(String id) {
  449. switch (Main.getInstance().getCreationMode()) {
  450. case CREATE_DIRECTED_EDGE:
  451. case CREATE_UNDIRECTED_EDGE:
  452. if (lastClickedID == null) {
  453. lastClickedID = id;
  454. if (!selectNodeForEdgeCreation(lastClickedID)) {
  455. lastClickedID = null;
  456. }
  457. } else if (id.equals(lastClickedID) || createEdge(id, lastClickedID)) {
  458. deselectNodesAfterEdgeCreation(lastClickedID);
  459. lastClickedID = null;
  460. }
  461. break;
  462. default:
  463. break;
  464. }
  465. PropertiesManager.setItemsProperties();
  466. }
  467. /**
  468. * creates a edge between two nodes.
  469. *
  470. * @author MW
  471. * @param to
  472. * ID of the destination node
  473. * @param from
  474. * ID of the origin node
  475. * @return true if the edge was created. false otherwise
  476. */
  477. protected boolean createEdge(String to, String from) {
  478. if (getGraph().getNode(from).hasEdgeBetween(to))
  479. return false;
  480. String newID = Main.getInstance().getUnusedID();
  481. boolean isDirected = (Main.getInstance().getCreationMode() == CreationMode.CREATE_DIRECTED_EDGE);
  482. Node sourceNode = g.getNode(from);
  483. Node targetNode = g.getNode(to);
  484. if (activeSubGraph != null && !activeSubGraph.equals(g)) {
  485. if (sourceNode.getAttribute("originalGraph").equals(activeSubGraph.getId())
  486. && targetNode.getAttribute("originalGraph").equals(activeSubGraph.getId())) {
  487. g.addEdge(newID, from, to, isDirected);
  488. activeSubGraph.addEdge(newID, from.substring(activeSubGraph.getId().length()), to.substring(activeSubGraph.getId().length()), isDirected);
  489. g.getEdge(newID).addAttribute("originalElement", activeSubGraph.getId() + "+#" + newID);
  490. } else {
  491. Debug.out(sourceNode.getAttribute("originalGraph").toString() + targetNode.getAttribute("originalGraph").toString());
  492. if (sourceNode.getAttribute("originalGraph").equals(targetNode.getAttribute("originalGraph"))){
  493. Debug.out("Can Only add edges to currently active Subgraph!", 2);
  494. } else {
  495. Debug.out("Can not create Edge between Nodes of different Subgraphs!", 2);
  496. }
  497. return false;
  498. }
  499. } else {
  500. g.addEdge(newID, from, to, isDirected);
  501. }
  502. selectEdge(newID);
  503. return true;
  504. }
  505. /**
  506. * Selects a Node as the starting point for creating a new Edge.
  507. *
  508. * @param nodeID
  509. * the ID of the Node to select
  510. */
  511. protected boolean selectNodeForEdgeCreation(String nodeID) {
  512. deselect();
  513. Node n = getGraph().getNode(nodeID);
  514. if (!hasClass(n, UI_CLASS_PROCESSING_ENABLED) || !GraphDisplayManager.getCurrentLayer().equals(Layer.MAPPING)) {
  515. n.changeAttribute("ui.style", "fill-color:green; size: 15px;");
  516. }
  517. return true;
  518. }
  519. /**
  520. * Reset the Selection of the Node after Edge has been successfully created.
  521. *
  522. * @param nodeID
  523. * the Id of the node to deselect.
  524. */
  525. protected void deselectNodesAfterEdgeCreation(String nodeID) {
  526. Node n = getGraph().getNode(nodeID);
  527. if (n == null) {
  528. return;
  529. }
  530. if (!hasClass(n, UI_CLASS_PROCESSING_ENABLED) || !GraphDisplayManager.getCurrentLayer().equals(Layer.MAPPING)) {
  531. n.removeAttribute("ui.style");
  532. n.changeAttribute("ui.style", "fill-color: #000000; size: 15px;");
  533. }
  534. }
  535. /**
  536. * Resets the selction of the Node for Edge selection
  537. */
  538. public void deselectEdgeCreationNodes() {
  539. if (lastClickedID != null)
  540. deselectNodesAfterEdgeCreation(lastClickedID);
  541. lastClickedID = null;
  542. }
  543. public void setActiveSubGraph(String id) {
  544. for (MyGraph subGraph : g.getAllSubGraphs()) {
  545. if (subGraph.getId().equals(id)) {
  546. activeSubGraph = subGraph;
  547. return;
  548. }
  549. }
  550. }
  551. protected boolean addClass(String id, String className) {
  552. Element e = getGraph().getEdge(id);
  553. if (e == null)
  554. e = getGraph().getNode(id);
  555. if (e == null)
  556. return false;
  557. String eClass = e.getAttribute("ui.class");
  558. if (eClass == null || eClass.equals(""))
  559. eClass = className;
  560. else if (!(eClass.equals(className) || eClass.startsWith(className.concat(", "))
  561. || eClass.contains(", ".concat(className))))
  562. eClass = className.concat(", ").concat(eClass);
  563. e.addAttribute("ui.class", eClass);
  564. Debug.out("added " + className + ": " + eClass);
  565. return true;
  566. }
  567. protected boolean removeClass(String id, String className) {
  568. Element e = getGraph().getEdge(id);
  569. if (e == null)
  570. e = getGraph().getNode(id);
  571. if (e == null)
  572. return false;
  573. String eClass = e.getAttribute("ui.class");
  574. if (eClass == null || eClass.equals(className))
  575. eClass = "";
  576. else
  577. eClass = eClass.replace(className.concat(", "), "").replace(", ".concat(className), "");
  578. e.addAttribute("ui.class", eClass);
  579. Debug.out("removed " + className + ": " + eClass);
  580. return true;
  581. }
  582. protected boolean toggleClass(String id, String className) {
  583. Element e = getGraph().getEdge(id);
  584. if (e == null)
  585. e = getGraph().getNode(id);
  586. if (e == null)
  587. return false;
  588. String eClass = e.getAttribute("ui.class");
  589. if (eClass == null || !(eClass.equals(className) || eClass.startsWith(className.concat(", "))
  590. || eClass.contains(", ".concat(className))))
  591. return addClass(id, className);
  592. return removeClass(id, className);
  593. }
  594. protected boolean hasClass(String id, String className) {
  595. Element e = getGraph().getEdge(id);
  596. if (e == null)
  597. e = getGraph().getNode(id);
  598. if (e == null)
  599. return false;
  600. String eClass = e.getAttribute("ui.class");
  601. return (eClass != null && (eClass.equals(className) || eClass.startsWith(className.concat(", "))
  602. || eClass.contains(", ".concat(className))));
  603. }
  604. protected boolean hasClass(Edge e, String className) {
  605. if (e == null)
  606. return false;
  607. String eClass = e.getAttribute("ui.class");
  608. return (eClass != null && (eClass.equals(className) || eClass.startsWith(className.concat(", "))
  609. || eClass.contains(", ".concat(className))));
  610. }
  611. protected boolean hasClass(Node n, String className) {
  612. if (n == null)
  613. return false;
  614. String nClass = n.getAttribute("ui.class");
  615. /*
  616. * TODO: nochmal angucken, wenn CSS Manager steht, ist gerade gehackt
  617. * damit, Vorführung läuft. return (nClass != null &&
  618. * (nClass.equals(className) ||
  619. * nClass.startsWith(className.concat(", ")) ||
  620. * nClass.contains(", ".concat(className))));
  621. */
  622. return (nClass != null && nClass.contains(className));
  623. }
  624. }