[8084] | 1 | /*
|
---|
| 2 | * To change this template, choose Tools | Templates
|
---|
| 3 | * and open the template in the editor.
|
---|
| 4 | */
|
---|
| 5 | package com.kitfox.svg.xml;
|
---|
| 6 |
|
---|
| 7 | import com.kitfox.svg.SVGConst;
|
---|
| 8 | import java.util.HashMap;
|
---|
| 9 | import java.util.logging.Level;
|
---|
| 10 | import java.util.logging.Logger;
|
---|
| 11 |
|
---|
| 12 | /**
|
---|
| 13 | *
|
---|
| 14 | * @author kitfox
|
---|
| 15 | */
|
---|
| 16 | public class StyleSheet
|
---|
| 17 | {
|
---|
[11525] | 18 | HashMap<StyleSheetRule, String> ruleMap = new HashMap<>();
|
---|
[8084] | 19 |
|
---|
| 20 | public static StyleSheet parseSheet(String src)
|
---|
| 21 | {
|
---|
| 22 | //Implement CS parser later
|
---|
| 23 | Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
|
---|
| 24 | "CSS parser not implemented yet");
|
---|
| 25 | return null;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | public void addStyleRule(StyleSheetRule rule, String value)
|
---|
| 29 | {
|
---|
| 30 | ruleMap.put(rule, value);
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | public boolean getStyle(StyleAttribute attrib, String tagName, String cssClass)
|
---|
| 34 | {
|
---|
| 35 | StyleSheetRule rule = new StyleSheetRule(attrib.getName(), tagName, cssClass);
|
---|
| 36 | String value = (String)ruleMap.get(rule);
|
---|
| 37 |
|
---|
| 38 | if (value != null)
|
---|
| 39 | {
|
---|
| 40 | attrib.setStringValue(value);
|
---|
| 41 | return true;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | //Try again using just class name
|
---|
| 45 | rule = new StyleSheetRule(attrib.getName(), null, cssClass);
|
---|
| 46 | value = (String)ruleMap.get(rule);
|
---|
| 47 |
|
---|
| 48 | if (value != null)
|
---|
| 49 | {
|
---|
| 50 | attrib.setStringValue(value);
|
---|
| 51 | return true;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | //Try again using just tag name
|
---|
| 55 | rule = new StyleSheetRule(attrib.getName(), tagName, null);
|
---|
| 56 | value = (String)ruleMap.get(rule);
|
---|
| 57 |
|
---|
| 58 | if (value != null)
|
---|
| 59 | {
|
---|
| 60 | attrib.setStringValue(value);
|
---|
| 61 | return true;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | return false;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | }
|
---|