summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/kitfox/svg/xml
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/kitfox/svg/xml')
-rw-r--r--src/main/java/com/kitfox/svg/xml/StyleAttribute.java16
-rw-r--r--src/main/java/com/kitfox/svg/xml/StyleSheet.java56
-rw-r--r--src/main/java/com/kitfox/svg/xml/StyleSheetRule.java59
3 files changed, 128 insertions, 3 deletions
diff --git a/src/main/java/com/kitfox/svg/xml/StyleAttribute.java b/src/main/java/com/kitfox/svg/xml/StyleAttribute.java
index 2566724..b60a1bd 100644
--- a/src/main/java/com/kitfox/svg/xml/StyleAttribute.java
+++ b/src/main/java/com/kitfox/svg/xml/StyleAttribute.java
@@ -79,10 +79,20 @@ public class StyleAttribute implements Serializable
this.stringValue = stringValue;
}
- public String getName() { return name; }
- public StyleAttribute setName(String name) { this.name = name; return this; }
+ public String getName() {
+ return name;
+ }
- public String getStringValue() { return stringValue; }
+ public StyleAttribute setName(String name)
+ {
+ this.name = name;
+ return this;
+ }
+
+ public String getStringValue()
+ {
+ return stringValue;
+ }
public String[] getStringList()
{
diff --git a/src/main/java/com/kitfox/svg/xml/StyleSheet.java b/src/main/java/com/kitfox/svg/xml/StyleSheet.java
new file mode 100644
index 0000000..da3db2e
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/xml/StyleSheet.java
@@ -0,0 +1,56 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.kitfox.svg.xml;
+
+import java.util.HashMap;
+
+/**
+ *
+ * @author kitfox
+ */
+public class StyleSheet
+{
+ HashMap ruleMap = new HashMap();
+
+ public void addStyleRule(StyleSheetRule rule, String value)
+ {
+ ruleMap.put(rule, value);
+ }
+
+ public boolean getStyle(StyleAttribute attrib, String tagName, String cssClass)
+ {
+ StyleSheetRule rule = new StyleSheetRule(attrib.getName(), tagName, cssClass);
+ String value = (String)ruleMap.get(rule);
+
+ if (value != null)
+ {
+ attrib.setStringValue(value);
+ return true;
+ }
+
+ //Try again using just class name
+ rule = new StyleSheetRule(attrib.getName(), null, cssClass);
+ value = (String)ruleMap.get(rule);
+
+ if (value != null)
+ {
+ attrib.setStringValue(value);
+ return true;
+ }
+
+ //Try again using just tag name
+ rule = new StyleSheetRule(attrib.getName(), tagName, null);
+ value = (String)ruleMap.get(rule);
+
+ if (value != null)
+ {
+ attrib.setStringValue(value);
+ return true;
+ }
+
+ return false;
+ }
+
+}
diff --git a/src/main/java/com/kitfox/svg/xml/StyleSheetRule.java b/src/main/java/com/kitfox/svg/xml/StyleSheetRule.java
new file mode 100644
index 0000000..5389c2d
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/xml/StyleSheetRule.java
@@ -0,0 +1,59 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.kitfox.svg.xml;
+
+/**
+ *
+ * @author kitfox
+ */
+public class StyleSheetRule
+{
+ final String styleName;
+ final String tag;
+ final String className;
+
+ public StyleSheetRule(String styleName, String tag, String className)
+ {
+ this.styleName = styleName;
+ this.tag = tag;
+ this.className = className;
+ }
+
+ public int hashCode()
+ {
+ int hash = 7;
+ hash = 13 * hash + (this.styleName != null ? this.styleName.hashCode() : 0);
+ hash = 13 * hash + (this.tag != null ? this.tag.hashCode() : 0);
+ hash = 13 * hash + (this.className != null ? this.className.hashCode() : 0);
+ return hash;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ final StyleSheetRule other = (StyleSheetRule) obj;
+ if ((this.styleName == null) ? (other.styleName != null) : !this.styleName.equals(other.styleName))
+ {
+ return false;
+ }
+ if ((this.tag == null) ? (other.tag != null) : !this.tag.equals(other.tag))
+ {
+ return false;
+ }
+ if ((this.className == null) ? (other.className != null) : !this.className.equals(other.className))
+ {
+ return false;
+ }
+ return true;
+ }
+
+}