Java Examples for org.w3c.dom.svg.SVGPathElement
The following java examples will help you to understand the usage of org.w3c.dom.svg.SVGPathElement. These source code samples are taken from different open source projects.
Example 1
| Project: delineate-master File: AutotraceSvgOptimizer.java View source code |
private int writePaths(SVGSVGElement rootElement, List styleList, Map styleToColorMap, PrintWriter w) {
NodeList childNodes = rootElement.getChildNodes();
int pathCount = 0;
int styleCount = 0;
String colorText = null;
clearColorCollections();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if (node instanceof SVGPathElement) {
pathCount++;
SVGPathElement path = (SVGPathElement) node;
String styleText = path.getAttribute("style");
if (centerlineEnabled) {
colorText = styleText.substring(8, 14);
} else {
colorText = styleText.substring(6, 12);
}
if (pathCount <= 279 && !colorSet.contains(colorText)) {
Color color = ColorUtilities.getColor(colorText);
colorSet.add(color);
}
if (noGroups()) {
w.print("<path ");
if (centerlineEnabled) {
w.print("fill=\"none\" stroke=\"#");
} else {
w.print("stroke=\"none\" fill=\"#");
}
w.print(colorText);
} else if (oneGroup()) {
if (centerlineEnabled) {
w.print("<path stroke=\"#");
} else {
w.print("<path fill=\"#");
}
w.print(colorText);
} else if (extractStyles()) {
if (!colorToStyleMap.containsKey(colorText)) {
String style = getStyleName(styleCount);
styleList.add(style);
colorToStyleMap.put(colorText, style);
styleToColorMap.put(style, colorText);
styleCount++;
}
w.print("<path class=\"");
w.print((String) colorToStyleMap.get(colorText));
}
if (!groupByColor()) {
w.print("\" d=\"");
}
String pathText = path.getAttribute("d");
int index = pathText.length() - 1;
char c = pathText.charAt(index);
if (c == 'z') {
do {
c = pathText.charAt(--index);
} while (Character.isDigit(c) || Character.isWhitespace(c));
if (c == 'L') {
pathText = pathText.substring(0, index) + 'z';
}
}
if (!groupByColor()) {
w.print(pathText);
w.println("\"/>");
} else {
List list;
if (colorToPathsMap.containsKey(colorText)) {
list = (List) colorToPathsMap.get(colorText);
} else {
list = new ArrayList();
colorList.add(colorText);
colorToPathsMap.put(colorText, list);
}
list.add(pathText);
}
}
}
colors = (Color[]) colorSet.toArray(new Color[colorSet.size()]);
if (groupByColor()) {
for (Iterator iterator = colorList.iterator(); iterator.hasNext(); ) {
colorText = (String) iterator.next();
List pathList = (List) colorToPathsMap.get(colorText);
if (centerlineEnabled) {
w.print("<g fill=\"none\" stroke=\"#");
} else {
w.print("<g stroke=\"none\" fill=\"#");
}
w.print(colorText);
w.println("\">");
for (Iterator i = pathList.iterator(); i.hasNext(); ) {
String pathText = (String) i.next();
w.print("<path d=\"");
w.print(pathText);
w.println("\"/>");
i.remove();
}
w.println("</g>");
iterator.remove();
}
}
return pathCount;
}Example 2
| Project: svg2fx-master File: Document.java View source code |
private void visitGroup(DocumentVisitor db, SVGGElement group) {
db.visitSVGGElement(group);
NodeList nl = group == null ? svgRoot.getChildNodes() : group.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
if (nl.item(i) instanceof SVGGElement) {
visitGroup(db, (SVGGElement) nl.item(i));
visitStyleAttributes(db, ((SVGGElement) nl.item(i)).getAttributeNode("style"));
} else if (nl.item(i) instanceof SVGPathElement) {
visitPathSeg(db, (SVGPathElement) nl.item(i));
visitStyleAttributes(db, ((SVGPathElement) nl.item(i)).getAttributeNode("style"));
} else if (nl.item(i) instanceof SVGCircleElement) {
db.visitSVGCircleElement((SVGCircleElement) nl.item(i));
visitStyleAttributes(db, ((SVGCircleElement) nl.item(i)).getAttributeNode("style"));
} else if (nl.item(i) instanceof SVGEllipseElement) {
db.visitSVGEllipseElement((SVGEllipseElement) nl.item(i));
visitStyleAttributes(db, ((SVGEllipseElement) nl.item(i)).getAttributeNode("style"));
} else if (nl.item(i) instanceof SVGRectElement) {
db.visitSVGRectElement((SVGRectElement) nl.item(i));
visitStyleAttributes(db, ((SVGRectElement) nl.item(i)).getAttributeNode("style"));
} else if (nl.item(i) instanceof SVGLineElement) {
db.visitSVGLineElement((SVGLineElement) nl.item(i));
visitStyleAttributes(db, ((SVGLineElement) nl.item(i)).getAttributeNode("style"));
} else if (nl.item(i) instanceof SVGPolylineElement) {
db.visitSVGPolylineElement((SVGPolylineElement) nl.item(i));
visitStyleAttributes(db, ((SVGPolylineElement) nl.item(i)).getAttributeNode("style"));
}
}
db.visitSVGGElementClose(group);
}Example 3
| Project: jdip-web-master File: GUISupport.java View source code |
// updateDOMMove()
/**
* Note: we don't draw the 3rd part (supSrc->supDest) if moveFound == false.
*
*
*/
private SVGElement[] drawSupportedMove(MapInfo mapInfo, float offset, boolean addMarker) {
// setup
//SVGElement[] elements = new SVGElement[ ((dependentFound) ? 1 : 3) ];
SVGElement[] elements = new SVGElement[1];
Position position = mapInfo.getTurnState().getPosition();
MapMetadata mmd = mapInfo.getMapMetadata();
Point2D.Float ptSrc = mmd.getUnitPt(src.getProvince(), src.getCoast());
Point2D.Float ptSupSrc = mmd.getUnitPt(supSrc.getProvince(), supSrc.getCoast());
Point2D.Float ptSupDest = mmd.getUnitPt(supDest.getProvince(), supDest.getCoast());
// adjust for offset
ptSrc.x += offset;
ptSrc.y += offset;
ptSupSrc.x += offset;
ptSupSrc.y += offset;
ptSupDest.x += offset;
ptSupDest.y += offset;
// destination. If no unit, use the size of an army unit radius divided
// by 2 (as we do in GUIMove)
//
Point2D.Float newSupDest = null;
if (position.hasUnit(supDest.getProvince())) {
// since we're supporting a Move, we should use the Move radius
Unit.Type destUnitType = position.getUnit(supDest.getProvince()).getType();
float moveRadius = mmd.getOrderRadius(MapMetadata.EL_MOVE, mapInfo.getSymbolName(destUnitType));
newSupDest = GUIOrderUtils.getLineCircleIntersection(ptSupSrc.x, ptSupSrc.y, ptSupDest.x, ptSupDest.y, ptSupDest.x, ptSupDest.y, moveRadius);
} else {
float moveRadius = (mmd.getOrderRadius(MapMetadata.EL_MOVE, mapInfo.getSymbolName(Unit.Type.ARMY)) / 2);
newSupDest = GUIOrderUtils.getLineCircleIntersection(ptSupSrc.x, ptSupSrc.y, ptSupDest.x, ptSupDest.y, ptSupDest.x, ptSupDest.y, moveRadius);
}
// calculate failed point marker
// this is sort of a hack; may not really coincide with bezier curve!!
// seems to work fairly well, though. keep for now.
failPt = GUIOrderUtils.getLineMidpoint(ptSrc.x, ptSrc.y, ptSupSrc.x, ptSupSrc.y);
// new test code -- bezier
elements[0] = (SVGPathElement) mapInfo.getDocument().createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, SVGConstants.SVG_PATH_TAG);
StringBuffer sb = new StringBuffer();
sb.append("M ");
// unit start
GUIOrderUtils.appendFloat(sb, ptSrc.x);
sb.append(',');
GUIOrderUtils.appendFloat(sb, ptSrc.y);
sb.append(" C ");
// supporting unit
GUIOrderUtils.appendFloat(sb, ptSupSrc.x);
sb.append(',');
GUIOrderUtils.appendFloat(sb, ptSupSrc.y);
sb.append(' ');
// supporting unit
GUIOrderUtils.appendFloat(sb, ptSupSrc.x);
sb.append(',');
GUIOrderUtils.appendFloat(sb, ptSupSrc.y);
sb.append(' ');
// destination
GUIOrderUtils.appendFloat(sb, newSupDest.x);
sb.append(',');
GUIOrderUtils.appendFloat(sb, newSupDest.y);
sb.append(' ');
elements[0].setAttributeNS(null, SVGConstants.SVG_D_ATTRIBUTE, sb.toString());
elements[0].setAttributeNS(null, SVGConstants.SVG_CLASS_ATTRIBUTE, mmd.getOrderParamString(MapMetadata.EL_SUPPORT, MapMetadata.ATT_STROKESTYLE));
if (addMarker || offset != 0.0f) {
GUIOrderUtils.addMarker(elements[0], mmd, MapMetadata.EL_SUPPORT);
}
// return
return elements;
}Example 4
| Project: jDip-master File: GUISupport.java View source code |
// updateDOMMove()
/**
* Note: we don't draw the 3rd part (supSrc->supDest) if moveFound == false.
*
*
*/
private SVGElement[] drawSupportedMove(MapInfo mapInfo, float offset, boolean addMarker) {
// setup
//SVGElement[] elements = new SVGElement[ ((dependentFound) ? 1 : 3) ];
SVGElement[] elements = new SVGElement[1];
Position position = mapInfo.getTurnState().getPosition();
MapMetadata mmd = mapInfo.getMapMetadata();
Point2D.Float ptSrc = mmd.getUnitPt(src.getProvince(), src.getCoast());
Point2D.Float ptSupSrc = mmd.getUnitPt(supSrc.getProvince(), supSrc.getCoast());
Point2D.Float ptSupDest = mmd.getUnitPt(supDest.getProvince(), supDest.getCoast());
// adjust for offset
ptSrc.x += offset;
ptSrc.y += offset;
ptSupSrc.x += offset;
ptSupSrc.y += offset;
ptSupDest.x += offset;
ptSupDest.y += offset;
// destination. If no unit, use the size of an army unit radius divided
// by 2 (as we do in GUIMove)
//
Point2D.Float newSupDest = null;
if (position.hasUnit(supDest.getProvince())) {
// since we're supporting a Move, we should use the Move radius
Unit.Type destUnitType = position.getUnit(supDest.getProvince()).getType();
float moveRadius = mmd.getOrderRadius(MapMetadata.EL_MOVE, mapInfo.getSymbolName(destUnitType));
newSupDest = GUIOrderUtils.getLineCircleIntersection(ptSupSrc.x, ptSupSrc.y, ptSupDest.x, ptSupDest.y, ptSupDest.x, ptSupDest.y, moveRadius);
} else {
float moveRadius = (mmd.getOrderRadius(MapMetadata.EL_MOVE, mapInfo.getSymbolName(Unit.Type.ARMY)) / 2);
newSupDest = GUIOrderUtils.getLineCircleIntersection(ptSupSrc.x, ptSupSrc.y, ptSupDest.x, ptSupDest.y, ptSupDest.x, ptSupDest.y, moveRadius);
}
// calculate failed point marker
// this is sort of a hack; may not really coincide with bezier curve!!
// seems to work fairly well, though. keep for now.
failPt = GUIOrderUtils.getLineMidpoint(ptSrc.x, ptSrc.y, ptSupSrc.x, ptSupSrc.y);
// new test code -- bezier
elements[0] = (SVGPathElement) mapInfo.getDocument().createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, SVGConstants.SVG_PATH_TAG);
StringBuffer sb = new StringBuffer();
sb.append("M ");
// unit start
GUIOrderUtils.appendFloat(sb, ptSrc.x);
sb.append(',');
GUIOrderUtils.appendFloat(sb, ptSrc.y);
sb.append(" C ");
// supporting unit
GUIOrderUtils.appendFloat(sb, ptSupSrc.x);
sb.append(',');
GUIOrderUtils.appendFloat(sb, ptSupSrc.y);
sb.append(' ');
// supporting unit
GUIOrderUtils.appendFloat(sb, ptSupSrc.x);
sb.append(',');
GUIOrderUtils.appendFloat(sb, ptSupSrc.y);
sb.append(' ');
// destination
GUIOrderUtils.appendFloat(sb, newSupDest.x);
sb.append(',');
GUIOrderUtils.appendFloat(sb, newSupDest.y);
sb.append(' ');
elements[0].setAttributeNS(null, SVGConstants.SVG_D_ATTRIBUTE, sb.toString());
elements[0].setAttributeNS(null, SVGConstants.SVG_CLASS_ATTRIBUTE, mmd.getOrderParamString(MapMetadata.EL_SUPPORT, MapMetadata.ATT_STROKESTYLE));
if (addMarker || offset != 0.0f) {
GUIOrderUtils.addMarker(elements[0], mmd, MapMetadata.EL_SUPPORT);
}
// return
return elements;
}Example 5
| Project: batik-master File: SVGOMPathElement.java View source code |
/**
* <b>DOM</b>: Implements {@link SVGPathElement#getPathLength()}.
*/
public SVGAnimatedNumber getPathLength() {
throw new UnsupportedOperationException(// XXX
"SVGPathElement.getPathLength is not implemented");
}