| 1 |
/* |
| 2 |
|
| 3 |
Licensed to the Apache Software Foundation (ASF) under one or more |
| 4 |
contributor license agreements. See the NOTICE file distributed with |
| 5 |
this work for additional information regarding copyright ownership. |
| 6 |
The ASF licenses this file to You under the Apache License, Version 2.0 |
| 7 |
(the "License"); you may not use this file except in compliance with |
| 8 |
the License. You may obtain a copy of the License at |
| 9 |
|
| 10 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
|
| 12 |
Unless required by applicable law or agreed to in writing, software |
| 13 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 14 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 |
See the License for the specific language governing permissions and |
| 16 |
limitations under the License. |
| 17 |
|
| 18 |
*/ |
| 19 |
|
| 20 |
var svgNS = "http://www.w3.org/2000/svg"; |
| 21 |
var xlinkNS = "http://www.w3.org/1999/xlink"; |
| 22 |
|
| 23 |
/** |
| 24 |
* Sets the transform attribute to a scale along the x-axis |
| 25 |
*/ |
| 26 |
function xScaleSetter(target, value){ |
| 27 |
if(target != null){ |
| 28 |
target.setAttributeNS(null, "transform", "scale(" + value + ", 1)"); |
| 29 |
} else { |
| 30 |
System.out.println("target is null in xScaleSetter"); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Sets the transform attribute to a scale along the y-axis |
| 36 |
*/ |
| 37 |
function yScaleSetter(target, value){ |
| 38 |
if(target != null){ |
| 39 |
target.setAttributeNS(null, "transform", "scale(1, " + value + ")"); |
| 40 |
} else { |
| 41 |
System.out.println("target is null in yScaleSetter"); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Sets the transform attribute to a translate along the x-axis |
| 47 |
*/ |
| 48 |
function xTranslateSetter(target, value){ |
| 49 |
target.setAttributeNS(null, "transform", "translate(" + value + ", 0)"); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Sets the transform attribute to a translate along the y-axis |
| 54 |
*/ |
| 55 |
function yTranslateSetter(target, value){ |
| 56 |
target.setAttributeNS(null, "transform", "translate(0, " + value + ")"); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
function emptyElement(elt){ |
| 61 |
var child = elt.getFirstChild(); |
| 62 |
while(child != null){ |
| 63 |
elt.removeChild(child); |
| 64 |
child = elt.getFirstChild(); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
/* |
| 69 |
* Sets the properties in the input properties array to the values |
| 70 |
* in the values array on the input element |
| 71 |
*/ |
| 72 |
function setProperties(id, properties, values){ |
| 73 |
var elt = document.getElementById(id); |
| 74 |
if (elt != null){ |
| 75 |
var newElt = elt.cloneNode(true); |
| 76 |
var i = 0; |
| 77 |
var n = properties.length; |
| 78 |
if (n > values.length) { |
| 79 |
n = values.length; |
| 80 |
} |
| 81 |
|
| 82 |
for (i=0; i<properties.length; i++){ |
| 83 |
newElt.setAttributeNS(null, properties[i], values[i]); |
| 84 |
} |
| 85 |
|
| 86 |
elt.getParentNode().replaceChild(newElt, elt); |
| 87 |
} else { |
| 88 |
alert('No element : ' + id); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
/* |
| 93 |
* Set the input property on the target element |
| 94 |
*/ |
| 95 |
function setProperty(id, property, value){ |
| 96 |
var properties = new Array(); |
| 97 |
properties[0] = property; |
| 98 |
var values = new Array(); |
| 99 |
values[0] = value; |
| 100 |
setProperties(id, properties, values); |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Sets the requested attribute on the input element |
| 105 |
*/ |
| 106 |
function setAttribute(id, attr, value){ |
| 107 |
var elt = document.getElementById(id); |
| 108 |
if (elt != null){ |
| 109 |
elt.setAttributeNS(null, attr, value); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Sets the content of a text node |
| 115 |
*/ |
| 116 |
function setTextOrig(id, text){ |
| 117 |
var t = document.getElementById(id); |
| 118 |
emptyElement(t); |
| 119 |
|
| 120 |
var nt = t.cloneNode(true); |
| 121 |
|
| 122 |
var content = document.createTextNode(text); |
| 123 |
nt.appendChild(content); |
| 124 |
|
| 125 |
var textParent = t.getParentNode(); |
| 126 |
t.getParentNode().replaceChild(nt, t); |
| 127 |
|
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Sets the content of a text node. Very hacky. This |
| 132 |
* is a temporary work-around, until we have the |
| 133 |
* bridge in order. |
| 134 |
*/ |
| 135 |
function setText(id, text){ |
| 136 |
var t = document.getElementById(id); |
| 137 |
emptyElement(t); |
| 138 |
|
| 139 |
var textParent = t.getParentNode(); |
| 140 |
textParent.removeChild(t); |
| 141 |
|
| 142 |
var content = document.createTextNode(text); |
| 143 |
t.appendChild(content); |
| 144 |
|
| 145 |
textParent.appendChild(t); |
| 146 |
|
| 147 |
} |