فهرست منبع

Merge remote-tracking branch 'origin/Matthias' into Matthias

MW 8 سال پیش
والد
کامیت
92678a967e

+ 26 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/css/CSSCondition.java

@@ -0,0 +1,26 @@
+package de.tu_darmstadt.informatik.tk.scopviz.ui.css;
+
+import java.util.HashSet;
+import java.util.Iterator;
+
+class CSSCondition {
+	String type;
+	HashSet<String> classes = new HashSet<String>();
+
+	public CSSCondition(String type, HashSet<String> classes) {
+		this.type = type;
+		this.classes = classes;
+	}
+
+	int ConditionsMetBy(CSSable suspect) {
+		if (type != null && !type.equals(suspect.getType()))
+			return 0;
+
+		Iterator<String> i = classes.iterator();
+		while (i.hasNext()) {
+			if (!suspect.getClasses().contains(i.next()))
+				return 0;
+		}
+		return classes.size();
+	}
+}

+ 54 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/css/CSSManager.java

@@ -0,0 +1,54 @@
+package de.tu_darmstadt.informatik.tk.scopviz.ui.css;
+
+import java.util.HashSet;
+
+import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
+
+public class CSSManager {
+	/**
+	 * Du zerstörst diesen REGEX und Matthias zerstört dich
+	 */
+	private static final String CSS_MATCH_REGEX = "(\\s*([A-Za-z]+|[A-Za-z]*(\\.[A-Za-z_-]*)+)\\s*\\{\\s*[A-Za-z_-]+\\s*\\:\\s*[A-Za-z\\(\\)_\\#\\'\\\"-]+\\s*\\;?\\s*\\})+\\s*";
+
+	static HashSet<CSSRule> rules = new HashSet<CSSRule>();
+
+	public static void addRule(String rule) {
+		if (!rule.matches(CSS_MATCH_REGEX)) {
+			Debug.out("rule <<" + rule + ">> doesn't match regex");
+			return;
+		}
+
+		HashSet<CSSCondition> conditions = new HashSet<>();
+		String[] ruleSplit = rule.split("{");
+		int i = 0;
+		String front = ruleSplit[0].trim();
+		while (i < ruleSplit.length - 1) {
+			String type = "";
+			HashSet<String> classes = new HashSet<String>();
+			if (front.contains(".")) {
+				String[] dots = front.split(".");
+				int j = 1;
+				if (front.startsWith(".")) {
+					j = 0;
+				} else {
+					type = dots[0];
+				}
+				while (j < dots.length) {
+					classes.add(dots[i]);
+				}
+			} else {
+				type = front;
+			}
+			conditions.add(new CSSCondition(type, classes));
+			i++;
+		}
+		
+		//TODO , split einfügen
+
+		String css = null;
+
+		CSSRule e = new CSSRule(conditions, css);
+
+		rules.add(e);
+	}
+}

+ 32 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/css/CSSRule.java

@@ -0,0 +1,32 @@
+package de.tu_darmstadt.informatik.tk.scopviz.ui.css;
+
+import java.util.HashSet;
+import java.util.Iterator;
+
+class CSSRule {
+	HashSet<CSSCondition> conditions = new HashSet<CSSCondition>();
+	String css;
+
+	public CSSRule(HashSet<CSSCondition> conditions, String css) {
+		super();
+		this.conditions = conditions;
+		this.css = css;
+	}
+
+	int ConditionsMetBy(CSSable suspect) {
+		int result = 0;
+		Iterator<CSSCondition> i = conditions.iterator();
+		while (i.hasNext()) {
+			CSSCondition condition = i.next();
+			int r = condition.ConditionsMetBy(suspect);
+			if (r > result)
+				result = r;
+		}
+
+		return result;
+	}
+
+	String getCSS() {
+		return css;
+	}
+}

+ 46 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/css/CSSable.java

@@ -0,0 +1,46 @@
+package de.tu_darmstadt.informatik.tk.scopviz.ui.css;
+
+import java.util.Set;
+
+public interface CSSable {
+	/**
+	 * Adds a CSS class to the object. classes already added are ignored
+	 * silently. multiple classes can be separated by a '.' or ' '.
+	 * 
+	 * @param c
+	 *            the class to add
+	 */
+	public void addCSSClass(String c);
+
+	/**
+	 * Removes a CSS class from the object. classes not part of the object are
+	 * ignored silently. multiple classes can be separated by a '.' or ' '.
+	 * 
+	 * @param c
+	 *            the class to add
+	 */
+	public void removeCSSClass(String c);
+
+	/**
+	 * 
+	 * @return a Set of Strings containing all the previously added CSS classes
+	 */
+	public Set<String> getClasses();
+
+	/**
+	 * 
+	 * @return the Type of the CSS Object
+	 */
+	public String getType();
+
+	/**
+	 * Updates the stored CSS String
+	 */
+	public void updateCSS();
+
+	/**
+	 * 
+	 * @return the stored CSS String
+	 */
+	public String getCSS();
+}