1 18 package org.apache.batik.css.engine; 19 20 import org.apache.batik.css.engine.value.Value; 21 22 28 public class StyleDeclaration { 29 30 protected final static int INITIAL_LENGTH = 8; 31 32 35 protected Value[] values = new Value[INITIAL_LENGTH]; 36 37 40 protected int[] indexes = new int[INITIAL_LENGTH]; 41 42 45 protected boolean[] priorities = new boolean[INITIAL_LENGTH]; 46 47 50 protected int count; 51 52 55 public int size() { 56 return count; 57 } 58 59 62 public Value getValue(int idx) { 63 return values[idx]; 64 } 65 66 69 public int getIndex(int idx) { 70 return indexes[idx]; 71 } 72 73 76 public boolean getPriority(int idx) { 77 return priorities[idx]; 78 } 79 80 83 public void remove(int idx) { 84 count--; 85 for (int i = idx; i < count; i++) { 86 values[i] = values[i + 1]; 87 indexes[i] = indexes[i + 1]; 88 priorities[i] = priorities[i + 1]; 89 } 90 } 91 92 95 public void put(int idx, Value v, int i, boolean prio) { 96 values[idx] = v; 97 indexes[idx] = i; 98 priorities[idx] = prio; 99 } 100 101 104 public void append(Value v, int idx, boolean prio) { 105 if (values.length == count) { 106 Value[] newval = new Value[count * 2]; 107 int[] newidx = new int[count * 2]; 108 boolean[] newprio = new boolean[count * 2]; 109 for (int i = 0; i < count; i++) { 110 newval[i] = values[i]; 111 newidx[i] = indexes[i]; 112 newprio[i] = priorities[i]; 113 } 114 values = newval; 115 indexes = newidx; 116 priorities = newprio; 117 } 118 for (int i = 0; i < count; i++) { 119 if (indexes[i] == idx) { 120 if (prio || (priorities[i] == prio)) { 123 values [i] = v; 124 priorities[i] = prio; 125 } 126 return; 127 } 128 } 129 values [count] = v; 130 indexes [count] = idx; 131 priorities[count] = prio; 132 count++; 133 } 134 135 138 public String toString(CSSEngine eng) { 139 StringBuffer sb = new StringBuffer (); 140 for (int i = 0; i < count; i++) { 141 sb.append(eng.getPropertyName(indexes[i])); 142 sb.append(": "); 143 sb.append(values[i]); 144 sb.append(";\n"); 145 } 146 return sb.toString(); 147 } 148 } 149 | Popular Tags |