Changeset 11525 in josm for trunk/src/com/kitfox/svg/SVGElement.java
- Timestamp:
- 2017-02-02T00:08:08+01:00 (9 years ago)
- File:
-
- 1 edited
-
trunk/src/com/kitfox/svg/SVGElement.java (modified) (28 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/SVGElement.java
r8084 r11525 4 4 * All rights reserved. 5 5 * 6 * Redistribution and use in source and binary forms, with or 6 * Redistribution and use in source and binary forms, with or 7 7 * without modification, are permitted provided that the following 8 8 * conditions are met: 9 9 * 10 * - Redistributions of source code must retain the above 10 * - Redistributions of source code must retain the above 11 11 * copyright notice, this list of conditions and the following 12 12 * disclaimer. 13 13 * - Redistributions in binary form must reproduce the above 14 14 * copyright notice, this list of conditions and the following 15 * disclaimer in the documentation and/or other materials 15 * disclaimer in the documentation and/or other materials 16 16 * provided with the distribution. 17 17 * … … 27 27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 * OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 29 * OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 31 * Mark McKay can be contacted at mark@kitfox.com. Salamander and other 32 32 * projects can be found at http://www.kitfox.com … … 35 35 */ 36 36 package com.kitfox.svg; 37 38 import java.awt.geom.AffineTransform; 39 import java.awt.geom.GeneralPath; 40 import java.io.Serializable; 41 import java.net.URI; 42 import java.util.ArrayList; 43 import java.util.Collections; 44 import java.util.HashMap; 45 import java.util.HashSet; 46 import java.util.Iterator; 47 import java.util.LinkedList; 48 import java.util.List; 49 import java.util.Set; 50 import java.util.regex.Matcher; 51 import java.util.regex.Pattern; 52 53 import org.xml.sax.Attributes; 54 import org.xml.sax.SAXException; 37 55 38 56 import com.kitfox.svg.pathcmd.Arc; … … 51 69 import com.kitfox.svg.xml.StyleSheet; 52 70 import com.kitfox.svg.xml.XMLParseUtil; 53 import java.awt.geom.AffineTransform;54 import java.awt.geom.GeneralPath;55 import java.io.Serializable;56 import java.net.URI;57 import java.util.ArrayList;58 import java.util.Collections;59 import java.util.HashMap;60 import java.util.HashSet;61 import java.util.Iterator;62 import java.util.LinkedList;63 import java.util.List;64 import java.util.Set;65 import java.util.regex.Matcher;66 import java.util.regex.Pattern;67 import org.xml.sax.Attributes;68 import org.xml.sax.SAXException;69 70 71 71 72 /** … … 79 80 public static final String SVG_NS = "http://www.w3.org/2000/svg"; 80 81 protected SVGElement parent = null; 81 protected final ArrayList children = new ArrayList(); 82 protected final ArrayList<SVGElement> children = new ArrayList<>(); 82 83 protected String id = null; 83 84 /** … … 88 89 * Styles defined for this elemnt via the <b>style</b> attribute. 89 90 */ 90 protected final HashMap inlineStyles = new HashMap(); 91 protected final HashMap<String, StyleAttribute> inlineStyles = new HashMap<>(); 91 92 /** 92 93 * Presentation attributes set for this element. Ie, any attribute other 93 94 * than the <b>style</b> attribute. 94 95 */ 95 protected final HashMap presAttribs = new HashMap(); 96 protected final HashMap<String, StyleAttribute> presAttribs = new HashMap<>(); 96 97 /** 97 98 * A list of presentation attributes to not include in the presentation 98 99 * attribute set. 99 100 */ 100 protected static final Set ignorePresAttrib; 101 protected static final Set<String> ignorePresAttrib; 101 102 102 103 static 103 104 { 104 HashSet set = new HashSet(); 105 HashSet<String> set = new HashSet<>(); 105 106 // set.add("id"); 106 107 // set.add("class"); … … 157 158 * @return an ordered list of nodes from the root of the tree to this node 158 159 */ 159 public List getPath(List retVec) 160 public List<SVGElement> getPath(List<SVGElement> retVec) 160 161 { 161 162 if (retVec == null) 162 163 { 163 retVec = new ArrayList(); 164 retVec = new ArrayList<>(); 164 165 } 165 166 … … 179 180 * @return The list containing the children of this group 180 181 */ 181 public List getChildren(List retVec) 182 public List<SVGElement> getChildren(List<SVGElement> retVec) 182 183 { 183 184 if (retVec == null) 184 185 { 185 retVec = new ArrayList(); 186 retVec = new ArrayList<>(); 186 187 } 187 188 … … 197 198 public SVGElement getChild(String id) 198 199 { 199 for (Iterator it = children.iterator(); it.hasNext();) 200 { 201 SVGElement ele = (SVGElement) it.next(); 200 for (SVGElement ele : children) { 202 201 String eleId = ele.getId(); 203 202 if (eleId != null && eleId.equals(id)) … … 234 233 } 235 234 236 Object temp = children.get(i);235 SVGElement temp = children.get(i); 237 236 children.set(i, children.get(j)); 238 237 children.set(j, temp); … … 269 268 if (style != null) 270 269 { 271 HashMap map = XMLParseUtil.parseStyle(style, inlineStyles); 270 HashMap<?, ?> map = XMLParseUtil.parseStyle(style, inlineStyles); 272 271 } 273 272 … … 302 301 * @return a set of Strings that corespond to CSS attributes on this element 303 302 */ 304 public Set getInlineAttributes() 303 public Set<String> getInlineAttributes() 305 304 { 306 305 return inlineStyles.keySet(); … … 310 309 * @return a set of Strings that corespond to XML attributes on this element 311 310 */ 312 public Set getPresentationAttributes() 311 public Set<String> getPresentationAttributes() 313 312 { 314 313 return presAttribs.keySet(); … … 330 329 this.diagram = diagram; 331 330 diagram.setElement(id, this); 332 for (Iterator it = children.iterator(); it.hasNext();) 333 { 334 SVGElement ele = (SVGElement) it.next(); 331 for (SVGElement ele : children) { 335 332 ele.setDiagram(diagram); 336 333 } … … 400 397 for (int i = 0; i < children.size(); ++i) 401 398 { 402 SVGElement ele = (SVGElement)children.get(i);399 SVGElement ele = children.get(i); 403 400 ele.build(); 404 401 } … … 418 415 return id; 419 416 } 420 LinkedList contexts = new LinkedList(); 417 LinkedList<SVGElement> contexts = new LinkedList<>(); 421 418 422 419 /** … … 431 428 protected SVGElement popParentContext() 432 429 { 433 return (SVGElement)contexts.removeLast();430 return contexts.removeLast(); 434 431 } 435 432 … … 474 471 475 472 //Check for local inline styles 476 StyleAttribute styAttr = (StyleAttribute)inlineStyles.get(styName);473 StyleAttribute styAttr = inlineStyles.get(styName); 477 474 478 475 attrib.setStringValue(styAttr == null ? "" : styAttr.getStringValue()); … … 486 483 487 484 //Check for presentation attribute 488 StyleAttribute presAttr = (StyleAttribute)presAttribs.get(styName);485 StyleAttribute presAttr = presAttribs.get(styName); 489 486 490 487 attrib.setStringValue(presAttr == null ? "" : presAttr.getStringValue()); … … 533 530 { 534 531 //Check for local inline styles 535 return (StyleAttribute)inlineStyles.get(styName);532 return inlineStyles.get(styName); 536 533 } 537 534 … … 546 543 547 544 //Make sure we have a coresponding presentation attribute 548 StyleAttribute presAttr = (StyleAttribute)presAttribs.get(presName);545 StyleAttribute presAttr = presAttribs.get(presName); 549 546 550 547 //Copy presentation value directly … … 568 565 { 569 566 //Check for local inline styles 570 return (StyleAttribute)presAttribs.get(styName);567 return presAttribs.get(styName); 571 568 } 572 569 … … 601 598 String function = matchWord.group().toLowerCase(); 602 599 603 LinkedList termList = new LinkedList(); 600 LinkedList<String> termList = new LinkedList<>(); 604 601 while (matchWord.find()) 605 602 { … … 609 606 610 607 double[] terms = new double[termList.size()]; 611 Iterator it = termList.iterator(); 608 Iterator<String> it = termList.iterator(); 612 609 int count = 0; 613 610 while (it.hasNext()) 614 611 { 615 terms[count++] = XMLParseUtil.parseDouble( (String)it.next());612 terms[count++] = XMLParseUtil.parseDouble(it.next()); 616 613 } 617 614 … … 661 658 } 662 659 663 static protected float nextFloat(LinkedList l) 664 { 665 String s = (String)l.removeFirst();660 static protected float nextFloat(LinkedList<String> l) 661 { 662 String s = l.removeFirst(); 666 663 return Float.parseFloat(s); 667 664 } … … 672 669 673 670 //Tokenize 674 LinkedList tokens = new LinkedList(); 671 LinkedList<String> tokens = new LinkedList<>(); 675 672 while (matchPathCmd.find()) 676 673 { … … 680 677 681 678 boolean defaultRelative = false; 682 LinkedList cmdList = new LinkedList(); 679 LinkedList<PathCommand> cmdList = new LinkedList<>(); 683 680 char curCmd = 'Z'; 684 681 while (tokens.size() != 0) 685 682 { 686 String curToken = (String)tokens.removeFirst();683 String curToken = tokens.removeFirst(); 687 684 char initChar = curToken.charAt(0); 688 685 if ((initChar >= 'A' && initChar <= 'Z') || (initChar >= 'a' && initChar <= 'z')) … … 825 822 public SVGElement getChild(int i) 826 823 { 827 return (SVGElement)children.get(i);824 return children.get(i); 828 825 } 829 826
Note:
See TracChangeset
for help on using the changeset viewer.
