GraphManager.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  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. if(g.getNode(Main.getInstance().getGraphManager().getActiveSubGraph() + newId) == null|| g.getNode(Main.getInstance().getGraphManager().getActiveSubGraph() + newId).getAttribute("originalElement") == null){
  172. deletedEdges = new LinkedList<>();
  173. deletedNode = null;
  174. return;
  175. }
  176. String origElement = GraphHelper.propagateElementUndeletion(g, e,
  177. g.getNode(newId).getAttribute("originalElement"));
  178. if (origElement != null) {
  179. g.getEdge(id).addAttribute("originalElement", origElement);
  180. }
  181. }
  182. deletedEdges = new LinkedList<>();
  183. deletedNode = null;
  184. }
  185. /**
  186. * @return the activeSubGraph
  187. */
  188. public MyGraph getActiveSubGraph() {
  189. return activeSubGraph;
  190. }
  191. /**
  192. * returns a View of the Graph. The View lives in the Swing Thread and the
  193. * Graph in the Main thread.
  194. *
  195. *
  196. * @return a View of the Graph, inheriting from JPanel
  197. */
  198. public ViewPanel getView() {
  199. return view;
  200. }
  201. /**
  202. * Returns the ID of the currently selected Node.
  203. *
  204. * @return the node's ID
  205. */
  206. public String getSelectedNodeID() {
  207. return selectedNodeID;
  208. }
  209. /**
  210. * Returns the ID of the currently selected Edge.
  211. *
  212. * @return the edge's ID
  213. */
  214. public String getSelectedEdgeID() {
  215. return selectedEdgeID;
  216. }
  217. /**
  218. * Selects the Node with the given ID, resets Edge selection.
  219. *
  220. * @param nodeID
  221. * the ID of the Node to select
  222. */
  223. public void selectNode(String nodeID) {
  224. if (nodeID != null && g.getNode(nodeID) != null) {
  225. deselect();
  226. this.selectedNodeID = nodeID;
  227. Node n = g.getNode(nodeID);
  228. // set selected node color to red
  229. if (!hasClass(n, UI_CLASS_PROCESSING_ENABLED)
  230. || !GraphDisplayManager.getCurrentLayer().equals(Layer.MAPPING)) {
  231. n.changeAttribute("ui.style", "fill-color : #F00; size: 15px;");
  232. PropertiesManager.setItemsProperties();
  233. }
  234. }
  235. }
  236. /**
  237. * Selects the Edge with the given ID, resets Node selection.
  238. *
  239. * @param edgeID
  240. * the ID of the Edge to select
  241. */
  242. public void selectEdge(String edgeID) {
  243. if (edgeID != null && g.getEdge(edgeID) != null) {
  244. deselect();
  245. this.selectedEdgeID = edgeID;
  246. addClass(edgeID, "selected");
  247. PropertiesManager.setItemsProperties();
  248. }
  249. }
  250. /**
  251. * Deselect any currently selected nodes or edges.
  252. */
  253. // TODO call this before save
  254. public void deselect() {
  255. // Set last selected Edge Color to Black
  256. if (getSelectedEdgeID() != null && g.getEdge(getSelectedEdgeID()) != null) {
  257. removeClass(getSelectedEdgeID(), "selected");
  258. }
  259. // Set last selected Node color to black
  260. else if (getSelectedNodeID() != null && g.getNode(getSelectedNodeID()) != null) {
  261. Node n = g.getNode(getSelectedNodeID());
  262. if (!hasClass(n, UI_CLASS_PROCESSING_ENABLED)
  263. || !GraphDisplayManager.getCurrentLayer().equals(Layer.MAPPING)) {
  264. String nodeType = n.getAttribute("ui.class");
  265. n.removeAttribute("ui.style");
  266. n.changeAttribute("ui.style", "fill-color: #000000; size: 15px;");
  267. n.changeAttribute("ui.class", nodeType.split("_")[0]);
  268. }
  269. }
  270. this.selectedNodeID = null;
  271. this.selectedEdgeID = null;
  272. }
  273. /**
  274. * Returns a reference to the Graph object managed by this visualizer.
  275. *
  276. * @return the graph
  277. */
  278. public MyGraph getGraph() {
  279. return g;
  280. }
  281. /**
  282. * Zooms in the view of the graph by 5 percent.
  283. */
  284. public void zoomIn() {
  285. zoom(-0.05);
  286. }
  287. /**
  288. * Zooms out the view of the graph by 5 percent.
  289. */
  290. public void zoomOut() {
  291. zoom(0.05);
  292. }
  293. /**
  294. * Zooms the view by the given Amount, positive values zoom out, negative
  295. * values zoom in.
  296. *
  297. * @param amount
  298. * the amount of zoom, should usually be between -0.2 and 0.2 for
  299. * reasonable zoom.
  300. */
  301. public void zoom(double amount) {
  302. view.getCamera().setViewPercent(view.getCamera().getViewPercent() * (1 + amount));
  303. }
  304. /**
  305. * Pumps the Pipe from the graphical Representation to the underlying Graph,
  306. * propagating all Changes made.
  307. */
  308. public void pumpIt() {
  309. fromViewer.pump();
  310. }
  311. @Override
  312. public String toString() {
  313. return "Visualizer for Graph \"" + g.getId() + "\"";
  314. }
  315. /**
  316. * Returns the current Save Path on Disk for the Graph.
  317. *
  318. * @return the current Path
  319. */
  320. public String getCurrentPath() {
  321. return currentPath;
  322. }
  323. /**
  324. * Sets the Save Path.
  325. *
  326. * @param currentPath
  327. * the new Path to set
  328. */
  329. public void setCurrentPath(String currentPath) {
  330. this.currentPath = currentPath;
  331. }
  332. /**
  333. * Adds a <b>Copy</b> of the given Node to the graph. The Copy retains the
  334. * ID and all attributes.
  335. *
  336. * @param n
  337. * the Node to be added to the graph
  338. */
  339. public void addNode(Node n) {
  340. HashMap<String, Object> attributes = new HashMap<>();
  341. for (String s : n.getAttributeKeySet()) {
  342. attributes.put(s, n.getAttribute(s));
  343. }
  344. String nodeId = activeSubGraph.getId() + n.getId();
  345. g.addNode(nodeId);
  346. g.getNode(nodeId).addAttributes(attributes);
  347. if (activeSubGraph != null && !activeSubGraph.equals(g)) {
  348. activeSubGraph.addNode(n.getId());
  349. activeSubGraph.getNode(n.getId()).addAttributes(attributes);
  350. g.getNode(nodeId).addAttribute("originalElement", activeSubGraph.getId() + "+#" + n.getId());
  351. g.getNode(nodeId).addAttribute("originalGraph", activeSubGraph.getId());
  352. }
  353. }
  354. /**
  355. * Returns the smallest X Coordinate of any Node in the Graph.
  356. *
  357. * @return the smallest X Coordinate in the Graph
  358. */
  359. public double getMinX() {
  360. return g.getMinX();
  361. }
  362. /**
  363. * Returns the biggest X Coordinate of any Node in the Graph.
  364. *
  365. * @return the biggest X Coordinate in the Graph
  366. */
  367. public double getMaxX() {
  368. return g.getMaxX();
  369. }
  370. /**
  371. * Returns the smallest Y Coordinate of any Node in the Graph.
  372. *
  373. * @return the smallest Y Coordinate in the Graph
  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. */
  383. public double getMaxY() {
  384. return g.getMaxY();
  385. }
  386. /**
  387. * Returns the Stylesheet used by the Graph.
  388. *
  389. * @return the Stylesheet in use
  390. */
  391. public String getStylesheet() {
  392. return stylesheet;
  393. }
  394. /**
  395. * Sets the Stylesheet to be used by the Graph.
  396. *
  397. * @param stylesheet
  398. * the new stylesheet to use
  399. */
  400. public void setStylesheet(String stylesheet) {
  401. this.stylesheet = stylesheet;
  402. g.removeAttribute("ui.stylesheet");
  403. String completeStylesheet = stylesheet;
  404. completeStylesheet = completeStylesheet.concat(StylesheetManager.getNodeStylesheet());
  405. completeStylesheet = completeStylesheet
  406. .concat(StylesheetManager.getLayerStyle((Layer) g.getAttribute("layer")));
  407. g.addAttribute("ui.stylesheet", completeStylesheet);
  408. }
  409. /**
  410. * adds the given listener to the underlying graph the listener will be
  411. * notified, when an Edge is added.
  412. *
  413. * @param e
  414. * the EdgeCreatedListener
  415. */
  416. public void addEdgeCreatedListener(EdgeCreatedListener e) {
  417. ((MyGraph) g).addEdgeCreatedListener(e);
  418. }
  419. /**
  420. * adds the given listener to the underlying graph the listener will be
  421. * notified, when a Node is added.
  422. *
  423. * @param n
  424. * the NodeCreatedListener
  425. */
  426. public void addNodeCreatedListener(NodeCreatedListener n) {
  427. ((MyGraph) g).addNodeCreatedListener(n);
  428. }
  429. /**
  430. * Updates the Stylesheet, causing any changes to it to come into effect.
  431. */
  432. public void updateStylesheet() {
  433. setStylesheet(this.stylesheet);
  434. }
  435. /**
  436. * Sets typeofNode as the ui.class of all Nodes.
  437. *
  438. */
  439. public void convertUiClass() {
  440. Collection<Node> allNodes = g.getNodeSet();
  441. for (Node n : allNodes) {
  442. if (n.hasAttribute("typeofNode")) {
  443. n.addAttribute("ui.class", n.getAttribute("typeofNode").toString());
  444. }
  445. }
  446. }
  447. /**
  448. * Create Edges based on CreateMode.
  449. *
  450. * @param id
  451. * The ID for the newly created Edge
  452. */
  453. public void createEdges(String id) {
  454. switch (Main.getInstance().getCreationMode()) {
  455. case CREATE_DIRECTED_EDGE:
  456. case CREATE_UNDIRECTED_EDGE:
  457. if (lastClickedID == null) {
  458. lastClickedID = id;
  459. if (!selectNodeForEdgeCreation(lastClickedID)) {
  460. lastClickedID = null;
  461. }
  462. } else if (id.equals(lastClickedID) || createEdge(id, lastClickedID)) {
  463. deselectNodesAfterEdgeCreation(lastClickedID);
  464. lastClickedID = null;
  465. }
  466. break;
  467. default:
  468. break;
  469. }
  470. PropertiesManager.setItemsProperties();
  471. }
  472. /**
  473. * creates a edge between two nodes.
  474. *
  475. * @author MW
  476. * @param to
  477. * ID of the destination node
  478. * @param from
  479. * ID of the origin node
  480. * @return true if the edge was created. false otherwise
  481. */
  482. protected boolean createEdge(String to, String from) {
  483. if (getGraph().getNode(from).hasEdgeBetween(to))
  484. return false;
  485. String newID = Main.getInstance().getUnusedID();
  486. boolean isDirected = (Main.getInstance().getCreationMode() == CreationMode.CREATE_DIRECTED_EDGE);
  487. Node sourceNode = g.getNode(from);
  488. Node targetNode = g.getNode(to);
  489. if (activeSubGraph != null && !activeSubGraph.equals(g)) {
  490. if (sourceNode.getAttribute("originalGraph").equals(activeSubGraph.getId())
  491. && targetNode.getAttribute("originalGraph").equals(activeSubGraph.getId())) {
  492. g.addEdge(newID, from, to, isDirected);
  493. activeSubGraph.addEdge(newID, from.substring(activeSubGraph.getId().length()), to.substring(activeSubGraph.getId().length()), isDirected);
  494. g.getEdge(newID).addAttribute("originalElement", activeSubGraph.getId() + "+#" + newID);
  495. } else {
  496. Debug.out(sourceNode.getAttribute("originalGraph").toString() + targetNode.getAttribute("originalGraph").toString());
  497. if (sourceNode.getAttribute("originalGraph").equals(targetNode.getAttribute("originalGraph"))){
  498. Debug.out("Can Only add edges to currently active Subgraph!", 2);
  499. } else {
  500. Debug.out("Can not create Edge between Nodes of different Subgraphs!", 2);
  501. }
  502. return false;
  503. }
  504. } else {
  505. g.addEdge(newID, from, to, isDirected);
  506. }
  507. selectEdge(newID);
  508. return true;
  509. }
  510. /**
  511. * Selects a Node as the starting point for creating a new Edge.
  512. *
  513. * @param nodeID
  514. * the ID of the Node to select
  515. */
  516. protected boolean selectNodeForEdgeCreation(String nodeID) {
  517. deselect();
  518. Node n = getGraph().getNode(nodeID);
  519. if (!hasClass(n, UI_CLASS_PROCESSING_ENABLED) || !GraphDisplayManager.getCurrentLayer().equals(Layer.MAPPING)) {
  520. n.changeAttribute("ui.style", "fill-color:green; size: 15px;");
  521. }
  522. return true;
  523. }
  524. /**
  525. * Reset the Selection of the Node after Edge has been successfully created.
  526. *
  527. * @param nodeID
  528. * the Id of the node to deselect.
  529. */
  530. protected void deselectNodesAfterEdgeCreation(String nodeID) {
  531. Node n = getGraph().getNode(nodeID);
  532. if (n == null) {
  533. return;
  534. }
  535. if (!hasClass(n, UI_CLASS_PROCESSING_ENABLED) || !GraphDisplayManager.getCurrentLayer().equals(Layer.MAPPING)) {
  536. n.removeAttribute("ui.style");
  537. n.changeAttribute("ui.style", "fill-color: #000000; size: 15px;");
  538. }
  539. }
  540. /**
  541. * Resets the selction of the Node for Edge selection
  542. */
  543. public void deselectEdgeCreationNodes() {
  544. if (lastClickedID != null)
  545. deselectNodesAfterEdgeCreation(lastClickedID);
  546. lastClickedID = null;
  547. }
  548. public void setActiveSubGraph(String id) {
  549. for (MyGraph subGraph : g.getAllSubGraphs()) {
  550. if (subGraph.getId().equals(id)) {
  551. activeSubGraph = subGraph;
  552. return;
  553. }
  554. }
  555. }
  556. protected boolean addClass(String id, String className) {
  557. Element e = getGraph().getEdge(id);
  558. if (e == null)
  559. e = getGraph().getNode(id);
  560. if (e == null)
  561. return false;
  562. String eClass = e.getAttribute("ui.class");
  563. if (eClass == null || eClass.equals(""))
  564. eClass = className;
  565. else if (!(eClass.equals(className) || eClass.startsWith(className.concat(", "))
  566. || eClass.contains(", ".concat(className))))
  567. eClass = className.concat(", ").concat(eClass);
  568. e.addAttribute("ui.class", eClass);
  569. Debug.out("added " + className + ": " + eClass);
  570. return true;
  571. }
  572. protected boolean removeClass(String id, String className) {
  573. Element e = getGraph().getEdge(id);
  574. if (e == null)
  575. e = getGraph().getNode(id);
  576. if (e == null)
  577. return false;
  578. String eClass = e.getAttribute("ui.class");
  579. if (eClass == null || eClass.equals(className))
  580. eClass = "";
  581. else
  582. eClass = eClass.replace(className.concat(", "), "").replace(", ".concat(className), "");
  583. e.addAttribute("ui.class", eClass);
  584. Debug.out("removed " + className + ": " + eClass);
  585. return true;
  586. }
  587. protected boolean toggleClass(String id, String className) {
  588. Element e = getGraph().getEdge(id);
  589. if (e == null)
  590. e = getGraph().getNode(id);
  591. if (e == null)
  592. return false;
  593. String eClass = e.getAttribute("ui.class");
  594. if (eClass == null || !(eClass.equals(className) || eClass.startsWith(className.concat(", "))
  595. || eClass.contains(", ".concat(className))))
  596. return addClass(id, className);
  597. return removeClass(id, className);
  598. }
  599. protected boolean hasClass(String id, String className) {
  600. Element e = getGraph().getEdge(id);
  601. if (e == null)
  602. e = getGraph().getNode(id);
  603. if (e == null)
  604. return false;
  605. String eClass = e.getAttribute("ui.class");
  606. return (eClass != null && (eClass.equals(className) || eClass.startsWith(className.concat(", "))
  607. || eClass.contains(", ".concat(className))));
  608. }
  609. protected boolean hasClass(Edge e, String className) {
  610. if (e == null)
  611. return false;
  612. String eClass = e.getAttribute("ui.class");
  613. return (eClass != null && (eClass.equals(className) || eClass.startsWith(className.concat(", "))
  614. || eClass.contains(", ".concat(className))));
  615. }
  616. protected boolean hasClass(Node n, String className) {
  617. if (n == null)
  618. return false;
  619. String nClass = n.getAttribute("ui.class");
  620. /*
  621. * TODO: nochmal angucken, wenn CSS Manager steht, ist gerade gehackt
  622. * damit, Vorführung läuft. return (nClass != null &&
  623. * (nClass.equals(className) ||
  624. * nClass.startsWith(className.concat(", ")) ||
  625. * nClass.contains(", ".concat(className))));
  626. */
  627. return (nClass != null && nClass.contains(className));
  628. }
  629. }