Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added per-node opacity property #1407

Merged
merged 1 commit into from
Oct 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ public class PreviewProperty {
* 100 means opaque.
*/
public static final String NODE_OPACITY = "node.opacity";

/**
* Node <code>Boolean</code> property indicating whether or not to use the
* opacity value defined as part of the Node color. If true, NODE_OPACITY will
* be ignored.
*/
public static final String NODE_PER_NODE_OPACITY = "node.per.node.opacity";

//Constants edges
/**
* Edge <code>Boolean</code> property defining whether to show edges.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class NodeRenderer implements Renderer {
protected float defaultBorderWidth = 1f;
protected DependantColor defaultBorderColor = new DependantColor(Color.BLACK);
protected float defaultOpacity = 100f;
protected boolean defaultPerNodeOpacity = false;

@Override
public void preProcess(PreviewModel previewModel) {
Expand Down Expand Up @@ -110,7 +111,9 @@ public void renderG2D(Item item, G2DTarget target, PreviewProperties properties)
Color color = item.getData(NodeItem.COLOR);
Color borderColor = ((DependantColor) properties.getValue(PreviewProperty.NODE_BORDER_COLOR)).getColor(color);
float borderSize = properties.getFloatValue(PreviewProperty.NODE_BORDER_WIDTH);
int alpha = (int) ((properties.getFloatValue(PreviewProperty.NODE_OPACITY) / 100f) * 255f);
int alpha = properties.getBooleanValue(PreviewProperty.NODE_PER_NODE_OPACITY) ?
color.getAlpha() :
(int) ((properties.getFloatValue(PreviewProperty.NODE_OPACITY) / 100f) * 255f);
if (alpha < 0) {
alpha = 0;
}
Expand Down Expand Up @@ -144,7 +147,9 @@ public void renderSVG(Item item, SVGTarget target, PreviewProperties properties)
Color color = item.getData(NodeItem.COLOR);
Color borderColor = ((DependantColor) properties.getValue(PreviewProperty.NODE_BORDER_COLOR)).getColor(color);
float borderSize = properties.getFloatValue(PreviewProperty.NODE_BORDER_WIDTH);
float alpha = properties.getFloatValue(PreviewProperty.NODE_OPACITY) / 100f;
float alpha = properties.getBooleanValue(PreviewProperty.NODE_PER_NODE_OPACITY) ?
color.getAlpha() / 255f:
properties.getFloatValue(PreviewProperty.NODE_OPACITY) / 100f;
if (alpha > 1) {
alpha = 1;
}
Expand Down Expand Up @@ -174,7 +179,9 @@ public void renderPDF(Item item, PDFTarget target, PreviewProperties properties)
Color color = item.getData(NodeItem.COLOR);
Color borderColor = ((DependantColor) properties.getValue(PreviewProperty.NODE_BORDER_COLOR)).getColor(color);
float borderSize = properties.getFloatValue(PreviewProperty.NODE_BORDER_WIDTH);
float alpha = properties.getFloatValue(PreviewProperty.NODE_OPACITY) / 100f;
float alpha = properties.getBooleanValue(PreviewProperty.NODE_PER_NODE_OPACITY) ?
color.getAlpha() / 255f :
properties.getFloatValue(PreviewProperty.NODE_OPACITY) / 100f;

PdfContentByte cb = target.getContentByte();
cb.setRGBColorStroke(borderColor.getRed(), borderColor.getGreen(), borderColor.getBlue());
Expand All @@ -201,18 +208,23 @@ public void renderPDF(Item item, PDFTarget target, PreviewProperties properties)
@Override
public PreviewProperty[] getProperties() {
return new PreviewProperty[]{
PreviewProperty.createProperty(this, PreviewProperty.NODE_BORDER_WIDTH, Float.class,
NbBundle.getMessage(NodeRenderer.class, "NodeRenderer.property.borderWidth.displayName"),
NbBundle.getMessage(NodeRenderer.class, "NodeRenderer.property.borderWidth.description"),
PreviewProperty.CATEGORY_NODES).setValue(defaultBorderWidth),
PreviewProperty.createProperty(this, PreviewProperty.NODE_BORDER_COLOR, DependantColor.class,
NbBundle.getMessage(NodeRenderer.class, "NodeRenderer.property.borderColor.displayName"),
NbBundle.getMessage(NodeRenderer.class, "NodeRenderer.property.borderColor.description"),
PreviewProperty.CATEGORY_NODES).setValue(defaultBorderColor),
PreviewProperty.createProperty(this, PreviewProperty.NODE_OPACITY, Float.class,
NbBundle.getMessage(NodeRenderer.class, "NodeRenderer.property.opacity.displayName"),
NbBundle.getMessage(NodeRenderer.class, "NodeRenderer.property.opacity.description"),
PreviewProperty.CATEGORY_NODES).setValue(defaultOpacity)};
PreviewProperty.createProperty(this, PreviewProperty.NODE_BORDER_WIDTH, Float.class,
NbBundle.getMessage(NodeRenderer.class, "NodeRenderer.property.borderWidth.displayName"),
NbBundle.getMessage(NodeRenderer.class, "NodeRenderer.property.borderWidth.description"),
PreviewProperty.CATEGORY_NODES).setValue(defaultBorderWidth),
PreviewProperty.createProperty(this, PreviewProperty.NODE_BORDER_COLOR, DependantColor.class,
NbBundle.getMessage(NodeRenderer.class, "NodeRenderer.property.borderColor.displayName"),
NbBundle.getMessage(NodeRenderer.class, "NodeRenderer.property.borderColor.description"),
PreviewProperty.CATEGORY_NODES).setValue(defaultBorderColor),
PreviewProperty.createProperty(this, PreviewProperty.NODE_OPACITY, Float.class,
NbBundle.getMessage(NodeRenderer.class, "NodeRenderer.property.opacity.displayName"),
NbBundle.getMessage(NodeRenderer.class, "NodeRenderer.property.opacity.description"),
PreviewProperty.CATEGORY_NODES).setValue(defaultOpacity),
PreviewProperty.createProperty(this, PreviewProperty.NODE_PER_NODE_OPACITY, Boolean.class,
NbBundle.getMessage(NodeRenderer.class, "NodeRenderer.property.perNodeOpacity.displayName"),
NbBundle.getMessage(NodeRenderer.class, "NodeRenderer.property.perNodeOpacity.description"),
PreviewProperty.CATEGORY_NODES).setValue(defaultPerNodeOpacity)
};
}

private boolean showNodes(PreviewProperties properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ NodeRenderer.property.borderColor.displayName = Border Color
NodeRenderer.property.borderColor.description =
NodeRenderer.property.opacity.displayName = opacity
NodeRenderer.property.opacity.description =
NodeRenderer.property.perNodeOpacity.displayName = Per-Node Opacity
NodeRenderer.property.perNodeOpacity.description = Use opacity defined at node level. If true, renderer's opacity property will be ignored.

EdgeRenderer.name = Default edges
EdgeRenderer.property.display.displayName = Show Edges
Expand Down