| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
| 2 |
|
| 3 |
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000802//EN" "http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd" > |
| 4 |
|
| 5 |
<!-- |
| 6 |
|
| 7 |
Licensed to the Apache Software Foundation (ASF) under one or more |
| 8 |
contributor license agreements. See the NOTICE file distributed with |
| 9 |
this work for additional information regarding copyright ownership. |
| 10 |
The ASF licenses this file to You under the Apache License, Version 2.0 |
| 11 |
(the "License"); you may not use this file except in compliance with |
| 12 |
the License. You may obtain a copy of the License at |
| 13 |
|
| 14 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 15 |
|
| 16 |
Unless required by applicable law or agreed to in writing, software |
| 17 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 18 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 |
See the License for the specific language governing permissions and |
| 20 |
limitations under the License. |
| 21 |
|
| 22 |
--> |
| 23 |
<!-- ====================================================================== --> |
| 24 |
<!-- Modification of a polygon attributes --> |
| 25 |
<!-- --> |
| 26 |
<!-- @author [email protected] --> |
| 27 |
<!-- @version $Id$ --> |
| 28 |
<!-- ====================================================================== --> |
| 29 |
<?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?> |
| 30 |
|
| 31 |
<svg width="450" viewBox="0 0 450 500" height="500" id="body"> |
| 32 |
<title><polygon> attributes 'onload'</title> |
| 33 |
|
| 34 |
<text x="50%" y="45" class="title"><polygon> getPoints() in 'onload' |
| 35 |
</text> |
| 36 |
<script type="text/ecmascript"><![CDATA[ |
| 37 |
function getNumberOfItems(evt) |
| 38 |
{ |
| 39 |
var elt = evt.target; |
| 40 |
nb = elt.getPoints().getNumberOfItems(); |
| 41 |
var text = elt.getOwnerDocument().getElementById('test1_text'); |
| 42 |
text.getFirstChild().appendData(" "+nb+" points"); |
| 43 |
} |
| 44 |
function insertItemBefore(evt,fromIndex,index) |
| 45 |
{ |
| 46 |
var elt = evt.target; |
| 47 |
pointProvider = elt.getOwnerDocument().getElementById('test1'); |
| 48 |
point = pointProvider.getPoints().getItem(fromIndex); |
| 49 |
nb = elt.getPoints().insertItemBefore(point,index); |
| 50 |
var text = elt.getOwnerDocument().getElementById('test4_text'); |
| 51 |
text.getFirstChild().appendData(" ("+nb.getX()+","+nb.getY()+")"); |
| 52 |
} |
| 53 |
function replaceItem(evt,fromIndex,index) |
| 54 |
{ |
| 55 |
var elt = evt.target; |
| 56 |
pointProvider = elt.getOwnerDocument().getElementById('test1'); |
| 57 |
point = pointProvider.getPoints().getItem(fromIndex); |
| 58 |
nb = elt.getPoints().replaceItem(point,index); |
| 59 |
var text = elt.getOwnerDocument().getElementById('test5_text'); |
| 60 |
text.getFirstChild().appendData(" ("+nb.getX()+","+nb.getY()+")"); |
| 61 |
} |
| 62 |
|
| 63 |
function initializeAppendItem(evt,fromIndex1,fromIndex2) |
| 64 |
{ |
| 65 |
var elt = evt.target; |
| 66 |
pointProvider = elt.getOwnerDocument().getElementById('test1'); |
| 67 |
point = pointProvider.getPoints().getItem(fromIndex1); |
| 68 |
nb = elt.getPoints().initialize(point); |
| 69 |
var text = elt.getOwnerDocument().getElementById('test71_text'); |
| 70 |
text.getFirstChild().appendData(" ("+nb.getX()+","+nb.getY()+")"); |
| 71 |
point = pointProvider.getPoints().getItem(fromIndex2); |
| 72 |
nb = elt.getPoints().appendItem(point); |
| 73 |
text = elt.getOwnerDocument().getElementById('test72_text'); |
| 74 |
text.getFirstChild().appendData(" ("+nb.getX()+","+nb.getY()+")"); |
| 75 |
} |
| 76 |
|
| 77 |
function createNextSibling(evt){ |
| 78 |
|
| 79 |
var elt = evt.target; |
| 80 |
var doc = elt.getOwnerDocument(); |
| 81 |
|
| 82 |
var polygon = doc.createElementNS(elt.getNamespaceURI(),"polygon"); |
| 83 |
polygon.setAttribute("style","fill:#ffd700;stroke-width:4.0;stroke:#ffa500"); |
| 84 |
var pointsList = polygon.getPoints(); |
| 85 |
|
| 86 |
var point = doc.getDocumentElement().createSVGPoint(); |
| 87 |
|
| 88 |
point.setX(219); |
| 89 |
point.setY(175); |
| 90 |
pointsList.appendItem(point); |
| 91 |
point.setX(255); |
| 92 |
point.setY(193); |
| 93 |
pointsList.appendItem(point); |
| 94 |
point.setX(268); |
| 95 |
point.setY(235); |
| 96 |
pointsList.appendItem(point); |
| 97 |
point.setX(242); |
| 98 |
point.setY(269); |
| 99 |
pointsList.appendItem(point); |
| 100 |
point.setX(199); |
| 101 |
point.setY(270); |
| 102 |
pointsList.appendItem(point); |
| 103 |
point.setX(171); |
| 104 |
point.setY(237); |
| 105 |
pointsList.appendItem(point); |
| 106 |
point.setX(179); |
| 107 |
point.setY(195); |
| 108 |
pointsList.appendItem(point); |
| 109 |
|
| 110 |
var text = elt.getOwnerDocument().getElementById('test8_text'); |
| 111 |
text.getFirstChild().appendData(" "+pointsList.getNumberOfItems()+" points"); |
| 112 |
|
| 113 |
elt.getParentNode().insertBefore(polygon,elt.getNextSibling()); |
| 114 |
} |
| 115 |
]]></script> |
| 116 |
<g id="test-content" transform="matrix(1.0 0.0 0.0 1.0 -148.27586 -91.37931)"> |
| 117 |
|
| 118 |
<!-- onload="getNumberOfItems(evt)" --> |
| 119 |
<text x="180" y="160" font-size="11">points provider</text> |
| 120 |
<polygon style="opacity:0.5;fill:#eee; stroke:#aaa; stroke-width:4" points="219 175, 255 193, 268 235, 242 269, 199 270, 171 237, 179 195"/> |
| 121 |
<polygon id="test1" style="fill:gold; stroke:orange; stroke-width:4" points="219 175, 255 193, 268 235, 242 269, 199 270, 171 237, 179 195" onload="getNumberOfItems(evt)"/> |
| 122 |
<text x="160" font-size="9" y="290" id="test1_text"> |
| 123 |
polygon with |
| 124 |
</text> |
| 125 |
|
| 126 |
<g transform="translate(0,150)" > |
| 127 |
<!-- onload="insertItemBefore(evt)" --> |
| 128 |
<text x="180" y="160" font-size="11" >insertItemBefore</text> |
| 129 |
<polygon style="opacity:0.5;fill:#eee; stroke:#aaa; stroke-width:4" points="219 175, 255 193, 268 235, 242 269, 199 270, 171 237, 179 195"/> |
| 130 |
<polygon id="test4" fill="#ffd700" stroke-width="4.0" |
| 131 |
points="200,200 200,250 250,250 250,200" |
| 132 |
stroke="#ffa500" |
| 133 |
onload="insertItemBefore(evt,5,1)" /> |
| 134 |
<text x="160" font-size="9" y="290" id="test4_text"> |
| 135 |
inserted point |
| 136 |
</text> |
| 137 |
</g> |
| 138 |
|
| 139 |
<g transform="translate(150,150)" > |
| 140 |
<!-- onload="replaceItem(evt)" --> |
| 141 |
<text x="180" y="160" font-size="11" >replaceItem</text> |
| 142 |
<polygon style="opacity:0.5;fill:#eee; stroke:#aaa; stroke-width:4" points="219 175, 255 193, 268 235, 242 269, 199 270, 171 237, 179 195"/> |
| 143 |
<polygon id="test5" fill="#ffd700" stroke-width="4.0" |
| 144 |
points="200,200 200,250 250,250 250,200" |
| 145 |
stroke="#ffa500" |
| 146 |
onload="replaceItem(evt,4,1)" /> |
| 147 |
<text x="160" font-size="9" y="290" id="test5_text"> |
| 148 |
replaced point |
| 149 |
</text> |
| 150 |
</g> |
| 151 |
|
| 152 |
<g transform="translate(300,150)" > |
| 153 |
<!-- onload="initialize/appendItem(evt)" --> |
| 154 |
<text x="180" y="160" font-size="11" >initialize/appendItem</text> |
| 155 |
<polygon style="opacity:0.5;fill:#eee; stroke:#aaa; stroke-width:4" points="219 175, 255 193, 268 235, 242 269, 199 270, 171 237, 179 195"/> |
| 156 |
<polygon id="test7" fill="#ffd700" stroke-width="4.0" |
| 157 |
points="200,200 200,250 250,250 250,200" |
| 158 |
stroke="#ffa500" |
| 159 |
onload="initializeAppendItem(evt,1,2)" /> |
| 160 |
<text x="160" font-size="9" y="275" id="test71_text"> |
| 161 |
intialized point |
| 162 |
</text> |
| 163 |
<text x="160" font-size="9" y="285" id="test72_text"> |
| 164 |
appended point |
| 165 |
</text> |
| 166 |
</g> |
| 167 |
|
| 168 |
<g transform="translate(300,0)" > |
| 169 |
<!-- onload="fromScratch(evt)" --> |
| 170 |
<text x="180" y="160" font-size="11" >new Polygon</text> |
| 171 |
<polygon style="opacity:0.5;fill:#eee; stroke:#aaa; stroke-width:4" points="219 175, 255 193, 268 235, 242 269, 199 270, 171 237, 179 195" onload="createNextSibling(evt)"/> |
| 172 |
<text x="160" font-size="9" y="285" id="test8_text"> |
| 173 |
polygon with |
| 174 |
</text> |
| 175 |
</g> |
| 176 |
|
| 177 |
</g> |
| 178 |
</svg> |