StylesheetManager.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package de.tu_darmstadt.informatik.tk.scopviz.ui;
  2. import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
  3. import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
  4. import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
  5. /**
  6. * Class to manage the various Stylesheets used by the Graph and UI Elements.
  7. *
  8. * @author Jascha Bohne
  9. *
  10. */
  11. public class StylesheetManager {
  12. /**
  13. * all available graphic styles
  14. */
  15. private static String[] allNodeGraphics = { "Shapes" };
  16. /**
  17. * The Stylesheet that is given to every graph that is added to display
  18. * everything correctly.
  19. */
  20. public static final String DEFAULT_STYLESHEET = "node{text-alignment:at-right; size:15px;} \n"
  21. + "edge{text-offset: 4px,-4px;} edge.selected{fill-color: #FF0000;}";
  22. /**
  23. * Part of the stylesheet that styles the different Nodes with shapes.
  24. */
  25. public static final String STYLE_NODES_SHAPES = "node.standard{shape: diamond;}" + "node.source{shape: triangle;}"
  26. + "node.procEn{shape: circle;}" + "node.sink{shape: box;}" + "node.operator{shape: diamond;}";
  27. /**
  28. * Part of the stylesheet that styles the different Nodes with sprites.
  29. */
  30. @Deprecated
  31. public static final String STYLE_NODES_SPRITES = "node.standard{fill-mode: image-scaled; fill-image: url('src/main/resources/png/standard.png'); }"
  32. + "node.source{fill-mode: image-scaled; fill-image: url('src/main/resources/png/source.png'); }"
  33. + "node.procEn{fill-mode: image-scaled; fill-image: url('src/main/resources/png/procEn.png'); }"
  34. + "node.sink{fill-mode: image-scaled; fill-image: url('src/main/resources/png/sink.png'); }"
  35. + "node.operator{fill-mode: image-scaled; fill-image: url('src/main/resources/png/operator.png'); }";
  36. /** The currently selected Display Mode. */
  37. private static String nodeGraphics = allNodeGraphics[0];
  38. /** The currently active Stylesheet. */
  39. private static String nodeStylesheet = STYLE_NODES_SHAPES;
  40. /** Layer specific Stylesheet for Underlay layer. */
  41. private static String styleLayerUnderlay = "";
  42. /** Layer specific Stylesheet for Operator layer. */
  43. private static String styleLayerOperator = "";
  44. /** Layer specific Stylesheet for Mapping layer. */
  45. private static String styleLayerMapping = "edge.mapping {stroke-color: #33ff33; stroke-mode: dashes; fill-mode: none; size: 0px;}"
  46. + "node.procEn {fill-mode: plain; shape: pie-chart; fill-color: #555555, #cccc00, #32cd32, #8b0000; size: 20px;}";
  47. /** Layer specific Stylesheet for Symbol layer. */
  48. private static String styleLayerSymbol = "";
  49. /** Private Constructor to prevent instantiation. */
  50. private StylesheetManager() {
  51. }
  52. /**
  53. * Changes the Stylesheet and updates all Nodes to use it.
  54. *
  55. * @param newGraphics
  56. * the new Stylesheet to use
  57. */
  58. public static void adjustNodeGraphics(String newGraphics) {
  59. if (!newGraphics.equalsIgnoreCase(StylesheetManager.nodeGraphics)) {
  60. StylesheetManager.nodeGraphics = newGraphics;
  61. if (newGraphics.equals(StylesheetManager.allNodeGraphics[0])) {
  62. StylesheetManager.setNodeStylesheet(StylesheetManager.STYLE_NODES_SHAPES);
  63. } else if (newGraphics.equals(StylesheetManager.allNodeGraphics[1])) {
  64. StylesheetManager.setNodeStylesheet(StylesheetManager.STYLE_NODES_SPRITES);
  65. } else {
  66. throw new RuntimeException("These graphics do not exist");
  67. }
  68. }
  69. Main.getInstance().getGraphManager().setStylesheet();
  70. }
  71. /**
  72. * Returns all available Stylesheets as Strings.
  73. *
  74. * @return all the StyleSheets
  75. */
  76. public static String[] getAllNodeGraphics() {
  77. return StylesheetManager.allNodeGraphics;
  78. }
  79. /**
  80. * Returns the currently active StyleSheet.
  81. *
  82. * @return the currently active StyleSheet as a String
  83. */
  84. public static String getNodeStylesheet() {
  85. return StylesheetManager.nodeStylesheet;
  86. }
  87. /**
  88. * Sets the current Stylesheet.
  89. *
  90. * @param stylesheet
  91. * the Stylesheet to use
  92. */
  93. public static void setNodeStylesheet(String stylesheet) {
  94. StylesheetManager.nodeStylesheet = stylesheet;
  95. }
  96. /**
  97. * the identifier of the currently used Stylesheet
  98. *
  99. * @return nodeGraphics the identifier of the currently used stylesheet as a
  100. * String
  101. */
  102. public static String getNodeGraphics() {
  103. return nodeGraphics;
  104. }
  105. /**
  106. * Returns the styleSheet for a given Layer.
  107. *
  108. * @param l
  109. * the Layer
  110. * @return the Stylesheet
  111. */
  112. public static String getLayerStyle(Layer l) {
  113. switch (l) {
  114. case UNDERLAY:
  115. return styleLayerUnderlay;
  116. case OPERATOR:
  117. return styleLayerOperator;
  118. case MAPPING:
  119. return styleLayerMapping;
  120. case SYMBOL:
  121. return styleLayerSymbol;
  122. default:
  123. Debug.out("OptionsManager: Stylesheet for an unknown Layer Requested");
  124. return "";
  125. }
  126. }
  127. /**
  128. * Sets the Stylesheet for a given Layer.
  129. *
  130. * @param l
  131. * the Layer
  132. * @param newStyle
  133. * the Stylesheet
  134. */
  135. public static void setLayerStyle(Layer l, String newStyle) {
  136. switch (l) {
  137. case UNDERLAY:
  138. styleLayerUnderlay = newStyle;
  139. break;
  140. case OPERATOR:
  141. styleLayerOperator = newStyle;
  142. break;
  143. case MAPPING:
  144. styleLayerMapping = newStyle;
  145. break;
  146. case SYMBOL:
  147. styleLayerSymbol = newStyle;
  148. break;
  149. default:
  150. Debug.out("OptionsManager: Stylesheet for an unknown Layer Requested");
  151. }
  152. }
  153. }