Skip to content

Commit

Permalink
Polyline: Support arrow heads
Browse files Browse the repository at this point in the history
  • Loading branch information
kasemir committed Aug 26, 2024
1 parent 49d51e5 commit 53c0a1f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/main/java/dbwr/widgets/PolylineWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
******************************************************************************/
package dbwr.widgets;

import static dbwr.WebDisplayRepresentation.logger;

import java.io.PrintWriter;
import java.util.logging.Level;

import org.w3c.dom.Element;

Expand All @@ -22,7 +25,13 @@ public class PolylineWidget extends SvgWidget
WidgetFactory.registerLegacy("org.csstudio.opibuilder.widgets.polyline", "polyline");
}

private enum Arrows
{
NONE, FROM, TO, BOTH
}

protected final int line_width;
protected Arrows arrows;
protected String line_color, points;
protected String dasharray;

Expand Down Expand Up @@ -85,6 +94,17 @@ protected PolylineWidget(final ParentWidget parent, final Element xml, final Str
dasharray = null;
}

int arrows_code = XMLUtil.getChildInteger(xml, "arrows").orElse(0);
try
{
arrows = Arrows.values()[arrows_code];
}
catch (Throwable ex)
{
logger.log(Level.WARNING, "Invalid <arrrow> index " + arrows_code, ex);
arrows = Arrows.NONE;
}

final StringBuilder buf = new StringBuilder();
final Element pe = XMLUtil.getChildElement(xml, "points");
if (pe != null)
Expand Down Expand Up @@ -126,10 +146,27 @@ private void adjustXMLPoints(final Element widget_xml)
protected void fillHTML(final PrintWriter html, final int indent)
{
HTMLUtil.indent(html, indent+2);

if (arrows != Arrows.NONE)
{ // Define arrow head. Magically scales with line_width!
html.print("<defs> <marker id=\"arrow\" viewBox=\"0 0 10 10\" refX=\"8\" refY=\"5\" " +
"markerWidth=\"6\" markerHeight=\"6\" orient=\"auto-start-reverse\"> " +
"<path d=\"M 0 0 L 10 5 L 0 10 z\" fill=\"" + line_color + "\" /> " +
"</marker> </defs>");
HTMLUtil.indent(html, indent+2);
}

html.print("<polyline fill=\"transparent\" points=\"" + points +
"\" stroke=\"" + line_color + "\" stroke-width=\"" + line_width + "\"");
if (dasharray != null)
html.print(" stroke-dasharray=\"" + dasharray + "\"");

// Add arrow heads
if (arrows == Arrows.FROM || arrows == Arrows.BOTH)
html.print("marker-start=\"url(#arrow)\"");
if (arrows == Arrows.TO || arrows == Arrows.BOTH)
html.print("marker-end=\"url(#arrow)\"");

html.println("/>");
}
}
1 change: 1 addition & 0 deletions src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ view.jsp?cache=false&amp;display=file:/Path/to/Display+Builder/01_main.bob
<hr>

<div id="versions">
2024-08-26 Polyline: Support arrow heads.<br>
2024-05-22 Treat hex-formatted numbers in text update as "unsigned".<br>
2024-05-10 Text update handles 'string' format since PVWS now sends long strings as byte array<br>
2024-03-06 Support alpha for shape backgrounds. Polyline/gon default line color. Ellipse, arc default sizes.<br>
Expand Down

0 comments on commit 53c0a1f

Please sign in to comment.