| •1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
package com.github.weisj.jsvg.nodes.animation; |
| 23 |
|
| 24 |
import org.jetbrains.annotations.NotNull; |
| 25 |
import org.jetbrains.annotations.Nullable; |
| 26 |
|
| 27 |
import com.github.weisj.jsvg.animation.Additive; |
| 28 |
import com.github.weisj.jsvg.animation.AnimationValuesType; |
| 29 |
import com.github.weisj.jsvg.animation.Track; |
| 30 |
import com.github.weisj.jsvg.nodes.AbstractSVGNode; |
| 31 |
import com.github.weisj.jsvg.parser.impl.AttributeNode; |
| 32 |
import com.github.weisj.jsvg.parser.impl.SeparatorMode; |
| 33 |
|
| 34 |
public abstract class BaseAnimationNode extends AbstractSVGNode { |
| 35 |
|
| 36 |
|
| 37 |
private static final @NotNull String INITIAL_PLACEHOLDER = "<<initial>>"; |
| 38 |
|
| 39 |
protected String[] values; |
| 40 |
protected @Nullable Track track; |
| 41 |
|
| 42 |
BaseAnimationNode() {} |
| 43 |
|
| 44 |
public static @Nullable String attributeName(@NotNull AttributeNode attributeNode) { |
| 45 |
return attributeNode.getValue("attributeName"); |
| 46 |
} |
| 47 |
|
| 48 |
@SuppressWarnings("ReferenceEquality") |
| 49 |
protected static boolean isPlaceholder(@NotNull String value) { |
| 50 |
return value == INITIAL_PLACEHOLDER; |
| 51 |
} |
| 52 |
|
| 53 |
@Override |
| 54 |
public void build(@NotNull AttributeNode attributeNode) { |
| 55 |
super.build(attributeNode); |
| 56 |
|
| 57 |
String from = attributeNode.getValue("from"); |
| 58 |
String to = attributeNode.getValue("to"); |
| 59 |
String by = attributeNode.getValue("by"); |
| 60 |
|
| 61 |
if (to != null) by = null; |
| 62 |
|
| 63 |
AnimationValuesType valuesType = null; |
| 64 |
if (attributeNode.getValue("values") != null) { |
| 65 |
values = attributeNode.getStringList("values", SeparatorMode.SEMICOLON_ONLY); |
| 66 |
valuesType = AnimationValuesType.VALUES; |
| 67 |
} else { |
| 68 |
if (from != null && to != null) { |
| 69 |
values = new String[] {from, to}; |
| 70 |
valuesType = AnimationValuesType.FROM_TO; |
| 71 |
} else if (from != null && by != null) { |
| 72 |
values = new String[] {from, by}; |
| 73 |
valuesType = AnimationValuesType.FROM_BY; |
| 74 |
} else if (by != null) { |
| 75 |
values = new String[] {INITIAL_PLACEHOLDER, by}; |
| 76 |
valuesType = AnimationValuesType.BY; |
| 77 |
} else if (to != null) { |
| 78 |
values = new String[] {INITIAL_PLACEHOLDER, to}; |
| 79 |
valuesType = AnimationValuesType.TO; |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
if (valuesType != null) { |
| 84 |
Additive additive = valuesType.endIsBy() |
| 85 |
? Additive.SUM |
| 86 |
: attributeNode.getEnum("additive", Additive.REPLACE); |
| 87 |
track = Track.parse(attributeNode, valuesType, additive); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
public @Nullable Track track() { |
| 92 |
return track; |
| 93 |
} |
| 94 |
} |