GraphManager.java 20 KB

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