GraphManager.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  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 = n.getId();
  345. if (activeSubGraph != null){
  346. nodeId = activeSubGraph.getId() + nodeId;
  347. }
  348. g.addNode(nodeId);
  349. g.getNode(nodeId).addAttributes(attributes);
  350. if (activeSubGraph != null && !activeSubGraph.equals(g)) {
  351. activeSubGraph.addNode(n.getId());
  352. activeSubGraph.getNode(n.getId()).addAttributes(attributes);
  353. g.getNode(nodeId).addAttribute("originalElement", activeSubGraph.getId() + "+#" + n.getId());
  354. g.getNode(nodeId).addAttribute("originalGraph", activeSubGraph.getId());
  355. }
  356. }
  357. /**
  358. * Returns the smallest X Coordinate of any Node in the Graph.
  359. *
  360. * @return the smallest X Coordinate in the Graph
  361. */
  362. public double getMinX() {
  363. return g.getMinX();
  364. }
  365. /**
  366. * Returns the biggest X Coordinate of any Node in the Graph.
  367. *
  368. * @return the biggest X Coordinate in the Graph
  369. */
  370. public double getMaxX() {
  371. return g.getMaxX();
  372. }
  373. /**
  374. * Returns the smallest Y Coordinate of any Node in the Graph.
  375. *
  376. * @return the smallest Y Coordinate in the Graph
  377. */
  378. public double getMinY() {
  379. return g.getMinY();
  380. }
  381. /**
  382. * Returns the biggest Y Coordinate of any Node in the Graph.
  383. *
  384. * @return the biggest Y Coordinate in the Graph
  385. */
  386. public double getMaxY() {
  387. return g.getMaxY();
  388. }
  389. /**
  390. * Returns the Stylesheet used by the Graph.
  391. *
  392. * @return the Stylesheet in use
  393. */
  394. public String getStylesheet() {
  395. return stylesheet;
  396. }
  397. /**
  398. * Sets the Stylesheet to be used by the Graph.
  399. *
  400. * @param stylesheet
  401. * the new stylesheet to use
  402. */
  403. public void setStylesheet(String stylesheet) {
  404. this.stylesheet = stylesheet;
  405. g.removeAttribute("ui.stylesheet");
  406. String completeStylesheet = stylesheet;
  407. completeStylesheet = completeStylesheet.concat(StylesheetManager.getNodeStylesheet());
  408. completeStylesheet = completeStylesheet
  409. .concat(StylesheetManager.getLayerStyle((Layer) g.getAttribute("layer")));
  410. g.addAttribute("ui.stylesheet", completeStylesheet);
  411. }
  412. /**
  413. * adds the given listener to the underlying graph the listener will be
  414. * notified, when an Edge is added.
  415. *
  416. * @param e
  417. * the EdgeCreatedListener
  418. */
  419. public void addEdgeCreatedListener(EdgeCreatedListener e) {
  420. ((MyGraph) g).addEdgeCreatedListener(e);
  421. }
  422. /**
  423. * adds the given listener to the underlying graph the listener will be
  424. * notified, when a Node is added.
  425. *
  426. * @param n
  427. * the NodeCreatedListener
  428. */
  429. public void addNodeCreatedListener(NodeCreatedListener n) {
  430. ((MyGraph) g).addNodeCreatedListener(n);
  431. }
  432. /**
  433. * Updates the Stylesheet, causing any changes to it to come into effect.
  434. */
  435. public void updateStylesheet() {
  436. setStylesheet(this.stylesheet);
  437. }
  438. /**
  439. * Sets typeofNode as the ui.class of all Nodes.
  440. *
  441. */
  442. public void convertUiClass() {
  443. Collection<Node> allNodes = g.getNodeSet();
  444. for (Node n : allNodes) {
  445. if (n.hasAttribute("typeofNode")) {
  446. n.addAttribute("ui.class", n.getAttribute("typeofNode").toString());
  447. }
  448. }
  449. }
  450. /**
  451. * Create Edges based on CreateMode.
  452. *
  453. * @param id
  454. * The ID for the newly created Edge
  455. */
  456. public void createEdges(String id) {
  457. switch (Main.getInstance().getCreationMode()) {
  458. case CREATE_DIRECTED_EDGE:
  459. case CREATE_UNDIRECTED_EDGE:
  460. if (lastClickedID == null) {
  461. lastClickedID = id;
  462. if (!selectNodeForEdgeCreation(lastClickedID)) {
  463. lastClickedID = null;
  464. }
  465. } else if (id.equals(lastClickedID) || createEdge(id, lastClickedID)) {
  466. deselectNodesAfterEdgeCreation(lastClickedID);
  467. lastClickedID = null;
  468. }
  469. break;
  470. default:
  471. break;
  472. }
  473. PropertiesManager.setItemsProperties();
  474. }
  475. /**
  476. * creates a edge between two nodes.
  477. *
  478. * @author MW
  479. * @param to
  480. * ID of the destination node
  481. * @param from
  482. * ID of the origin node
  483. * @return true if the edge was created. false otherwise
  484. */
  485. protected boolean createEdge(String to, String from) {
  486. if (getGraph().getNode(from).hasEdgeBetween(to))
  487. return false;
  488. String newID = Main.getInstance().getUnusedID();
  489. boolean isDirected = (Main.getInstance().getCreationMode() == CreationMode.CREATE_DIRECTED_EDGE);
  490. Node sourceNode = g.getNode(from);
  491. Node targetNode = g.getNode(to);
  492. if (activeSubGraph != null && !activeSubGraph.equals(g)) {
  493. if (sourceNode.getAttribute("originalGraph").equals(activeSubGraph.getId())
  494. && targetNode.getAttribute("originalGraph").equals(activeSubGraph.getId())) {
  495. g.addEdge(newID, from, to, isDirected);
  496. activeSubGraph.addEdge(newID, from.substring(activeSubGraph.getId().length()), to.substring(activeSubGraph.getId().length()), isDirected);
  497. g.getEdge(newID).addAttribute("originalElement", activeSubGraph.getId() + "+#" + newID);
  498. } else {
  499. Debug.out(sourceNode.getAttribute("originalGraph").toString() + targetNode.getAttribute("originalGraph").toString());
  500. if (sourceNode.getAttribute("originalGraph").equals(targetNode.getAttribute("originalGraph"))){
  501. Debug.out("Can Only add edges to currently active Subgraph!", 2);
  502. } else {
  503. Debug.out("Can not create Edge between Nodes of different Subgraphs!", 2);
  504. }
  505. return false;
  506. }
  507. } else {
  508. g.addEdge(newID, from, to, isDirected);
  509. }
  510. selectEdge(newID);
  511. return true;
  512. }
  513. /**
  514. * Selects a Node as the starting point for creating a new Edge.
  515. *
  516. * @param nodeID
  517. * the ID of the Node to select
  518. */
  519. protected boolean selectNodeForEdgeCreation(String nodeID) {
  520. deselect();
  521. Node n = getGraph().getNode(nodeID);
  522. if (!hasClass(n, UI_CLASS_PROCESSING_ENABLED) || !GraphDisplayManager.getCurrentLayer().equals(Layer.MAPPING)) {
  523. n.changeAttribute("ui.style", "fill-color:green; size: 15px;");
  524. }
  525. return true;
  526. }
  527. /**
  528. * Reset the Selection of the Node after Edge has been successfully created.
  529. *
  530. * @param nodeID
  531. * the Id of the node to deselect.
  532. */
  533. protected void deselectNodesAfterEdgeCreation(String nodeID) {
  534. Node n = getGraph().getNode(nodeID);
  535. if (n == null) {
  536. return;
  537. }
  538. if (!hasClass(n, UI_CLASS_PROCESSING_ENABLED) || !GraphDisplayManager.getCurrentLayer().equals(Layer.MAPPING)) {
  539. n.removeAttribute("ui.style");
  540. n.changeAttribute("ui.style", "fill-color: #000000; size: 15px;");
  541. }
  542. }
  543. /**
  544. * Resets the selction of the Node for Edge selection
  545. */
  546. public void deselectEdgeCreationNodes() {
  547. if (lastClickedID != null)
  548. deselectNodesAfterEdgeCreation(lastClickedID);
  549. lastClickedID = null;
  550. }
  551. public void setActiveSubGraph(String id) {
  552. for (MyGraph subGraph : g.getAllSubGraphs()) {
  553. if (subGraph.getId().equals(id)) {
  554. activeSubGraph = subGraph;
  555. return;
  556. }
  557. }
  558. }
  559. protected boolean addClass(String id, String className) {
  560. Element e = getGraph().getEdge(id);
  561. if (e == null)
  562. e = getGraph().getNode(id);
  563. if (e == null)
  564. return false;
  565. String eClass = e.getAttribute("ui.class");
  566. if (eClass == null || eClass.equals(""))
  567. eClass = className;
  568. else if (!(eClass.equals(className) || eClass.startsWith(className.concat(", "))
  569. || eClass.contains(", ".concat(className))))
  570. eClass = className.concat(", ").concat(eClass);
  571. e.addAttribute("ui.class", eClass);
  572. Debug.out("added " + className + ": " + eClass);
  573. return true;
  574. }
  575. protected boolean removeClass(String id, String className) {
  576. Element e = getGraph().getEdge(id);
  577. if (e == null)
  578. e = getGraph().getNode(id);
  579. if (e == null)
  580. return false;
  581. String eClass = e.getAttribute("ui.class");
  582. if (eClass == null || eClass.equals(className))
  583. eClass = "";
  584. else
  585. eClass = eClass.replace(className.concat(", "), "").replace(", ".concat(className), "");
  586. e.addAttribute("ui.class", eClass);
  587. Debug.out("removed " + className + ": " + eClass);
  588. return true;
  589. }
  590. protected boolean toggleClass(String id, String className) {
  591. Element e = getGraph().getEdge(id);
  592. if (e == null)
  593. e = getGraph().getNode(id);
  594. if (e == null)
  595. return false;
  596. String eClass = e.getAttribute("ui.class");
  597. if (eClass == null || !(eClass.equals(className) || eClass.startsWith(className.concat(", "))
  598. || eClass.contains(", ".concat(className))))
  599. return addClass(id, className);
  600. return removeClass(id, className);
  601. }
  602. protected boolean hasClass(String id, String className) {
  603. Element e = getGraph().getEdge(id);
  604. if (e == null)
  605. e = getGraph().getNode(id);
  606. if (e == null)
  607. return false;
  608. String eClass = e.getAttribute("ui.class");
  609. return (eClass != null && (eClass.equals(className) || eClass.startsWith(className.concat(", "))
  610. || eClass.contains(", ".concat(className))));
  611. }
  612. protected boolean hasClass(Edge e, String className) {
  613. if (e == null)
  614. return false;
  615. String eClass = e.getAttribute("ui.class");
  616. return (eClass != null && (eClass.equals(className) || eClass.startsWith(className.concat(", "))
  617. || eClass.contains(", ".concat(className))));
  618. }
  619. protected boolean hasClass(Node n, String className) {
  620. if (n == null)
  621. return false;
  622. String nClass = n.getAttribute("ui.class");
  623. /*
  624. * TODO: nochmal angucken, wenn CSS Manager steht, ist gerade gehackt
  625. * damit, Vorführung läuft. return (nClass != null &&
  626. * (nClass.equals(className) ||
  627. * nClass.startsWith(className.concat(", ")) ||
  628. * nClass.contains(", ".concat(className))));
  629. */
  630. return (nClass != null && nClass.contains(className));
  631. }
  632. }