GraphManager.java 20 KB

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