Search in sources :

Example 1 with EdgeColor

use of org.gephi.preview.types.EdgeColor in project gephi by gephi.

the class EdgeLabelRenderer method render.

@Override
public void render(Item item, RenderTarget target, PreviewProperties properties) {
    Edge edge = (Edge) item.getSource();
    //Label
    Color edgeColor = item.getData(EDGE_COLOR);
    Color color = item.getData(EdgeLabelItem.COLOR);
    DependantOriginalColor propColor = properties.getValue(PreviewProperty.EDGE_LABEL_COLOR);
    color = propColor.getColor(edgeColor, color);
    String label = item.getData(EdgeLabelItem.LABEL);
    Float x = item.getData(LABEL_X);
    Float y = item.getData(LABEL_Y);
    //Skip if empty
    if (label == null || label.trim().isEmpty()) {
        return;
    }
    //Outline
    DependantColor outlineDependantColor = properties.getValue(PreviewProperty.EDGE_LABEL_OUTLINE_COLOR);
    Float outlineSize = properties.getFloatValue(PreviewProperty.EDGE_LABEL_OUTLINE_SIZE);
    outlineSize = outlineSize * (font.getSize() / 32f);
    int outlineAlpha = (int) ((properties.getFloatValue(PreviewProperty.EDGE_LABEL_OUTLINE_OPACITY) / 100f) * 255f);
    if (outlineAlpha < 0) {
        outlineAlpha = 0;
    }
    if (outlineAlpha > 255) {
        outlineAlpha = 255;
    }
    Color outlineColor = outlineDependantColor.getColor(edgeColor);
    outlineColor = new Color(outlineColor.getRed(), outlineColor.getGreen(), outlineColor.getBlue(), outlineAlpha);
    if (target instanceof G2DTarget) {
        renderG2D((G2DTarget) target, label, x, y, color, outlineSize, outlineColor);
    } else if (target instanceof SVGTarget) {
        renderSVG((SVGTarget) target, edge, label, x, y, color, outlineSize, outlineColor);
    } else if (target instanceof PDFTarget) {
        renderPDF(((PDFTarget) target), label, x, y, color, outlineSize, outlineColor);
    }
}
Also used : DependantColor(org.gephi.preview.types.DependantColor) Color(java.awt.Color) EdgeColor(org.gephi.preview.types.EdgeColor) DependantColor(org.gephi.preview.types.DependantColor) DependantOriginalColor(org.gephi.preview.types.DependantOriginalColor) DependantOriginalColor(org.gephi.preview.types.DependantOriginalColor) Edge(org.gephi.graph.api.Edge)

Example 2 with EdgeColor

use of org.gephi.preview.types.EdgeColor in project gephi by gephi.

the class EdgeRenderer method getColor.

public static Color getColor(final Item item, final PreviewProperties properties) {
    final Item sourceItem = item.getData(SOURCE);
    final Item targetItem = item.getData(TARGET);
    final EdgeColor edgeColor = (EdgeColor) properties.getValue(PreviewProperty.EDGE_COLOR);
    final Color color = edgeColor.getColor((Color) item.getData(EdgeItem.COLOR), (Color) sourceItem.getData(NodeItem.COLOR), (Color) targetItem.getData(NodeItem.COLOR));
    return new Color(color.getRed(), color.getGreen(), color.getBlue(), (int) (getAlpha(properties) * 255));
}
Also used : EdgeColor(org.gephi.preview.types.EdgeColor) EdgeItem(org.gephi.preview.plugin.items.EdgeItem) NodeItem(org.gephi.preview.plugin.items.NodeItem) Color(java.awt.Color) EdgeColor(org.gephi.preview.types.EdgeColor)

Example 3 with EdgeColor

use of org.gephi.preview.types.EdgeColor in project gephi by gephi.

the class EdgeColorPanel method setup.

public void setup(EdgeColorPropertyEditor propertyEditor) {
    this.propertyEditor = propertyEditor;
    EdgeColor edgeColor = (EdgeColor) propertyEditor.getValue();
    if (edgeColor.getMode().equals(EdgeColor.Mode.CUSTOM)) {
        customRadio.setSelected(true);
        ((JColorButton) colorButton).setColor(edgeColor.getCustomColor());
    } else if (edgeColor.getMode().equals(EdgeColor.Mode.MIXED)) {
        mixedRadio.setSelected(true);
    } else if (edgeColor.getMode().equals(EdgeColor.Mode.ORIGINAL)) {
        originalRadio.setSelected(true);
    } else if (edgeColor.getMode().equals(EdgeColor.Mode.SOURCE)) {
        sourceRadio.setSelected(true);
    } else if (edgeColor.getMode().equals(EdgeColor.Mode.TARGET)) {
        targetRadio.setSelected(true);
    }
}
Also used : EdgeColor(org.gephi.preview.types.EdgeColor) JColorButton(org.gephi.ui.components.JColorButton)

Example 4 with EdgeColor

use of org.gephi.preview.types.EdgeColor in project gephi by gephi.

the class EdgeLabelRenderer method preProcess.

@Override
public void preProcess(PreviewModel previewModel) {
    PreviewProperties properties = previewModel.getProperties();
    if (properties.getBooleanValue(PreviewProperty.EDGE_LABEL_SHORTEN)) {
        //Shorten labels
        Item[] EdgeLabelsItems = previewModel.getItems(Item.EDGE_LABEL);
        int maxChars = properties.getIntValue(PreviewProperty.EDGE_LABEL_MAX_CHAR);
        for (Item item : EdgeLabelsItems) {
            String label = item.getData(EdgeLabelItem.LABEL);
            if (label.length() >= maxChars + 3) {
                label = label.substring(0, maxChars) + "...";
                item.setData(EdgeLabelItem.LABEL, label);
            }
        }
    }
    //Put parent color, and calculate position
    for (Item item : previewModel.getItems(Item.EDGE_LABEL)) {
        Edge edge = (Edge) item.getSource();
        Item edgeItem = previewModel.getItem(Item.EDGE, edge);
        EdgeColor edgeColor = (EdgeColor) properties.getValue(PreviewProperty.EDGE_COLOR);
        NodeItem sourceItem = (NodeItem) edgeItem.getData(EdgeRenderer.SOURCE);
        NodeItem targetItem = (NodeItem) edgeItem.getData(EdgeRenderer.TARGET);
        Color color = edgeColor.getColor((Color) item.getData(EdgeItem.COLOR), (Color) sourceItem.getData(NodeItem.COLOR), (Color) targetItem.getData(NodeItem.COLOR));
        item.setData(EDGE_COLOR, color);
        if (edge.isSelfLoop()) {
            //Middle
            Float x = sourceItem.getData(NodeItem.X);
            Float y = sourceItem.getData(NodeItem.Y);
            Float size = sourceItem.getData(NodeItem.SIZE);
            Vector v1 = new Vector(x, y);
            v1.add(size, -size);
            Vector v2 = new Vector(x, y);
            v2.add(size, size);
            Vector middle = bezierPoint(x, y, v1.x, v1.y, v2.x, v2.y, x, y, 0.5f);
            item.setData(LABEL_X, middle.x);
            item.setData(LABEL_Y, middle.y);
        } else if (properties.getBooleanValue(PreviewProperty.EDGE_CURVED)) {
            //Middle of the curve
            Float x1 = sourceItem.getData(NodeItem.X);
            Float x2 = targetItem.getData(NodeItem.X);
            Float y1 = sourceItem.getData(NodeItem.Y);
            Float y2 = targetItem.getData(NodeItem.Y);
            //Curved edgs
            Vector direction = new Vector(x2, y2);
            direction.sub(new Vector(x1, y1));
            float length = direction.mag();
            direction.normalize();
            float factor = properties.getFloatValue(EdgeRenderer.BEZIER_CURVENESS) * length;
            // normal vector to the edge
            Vector n = new Vector(direction.y, -direction.x);
            n.mult(factor);
            // first control point
            Vector v1 = new Vector(direction.x, direction.y);
            v1.mult(factor);
            v1.add(new Vector(x1, y1));
            v1.add(n);
            // second control point
            Vector v2 = new Vector(direction.x, direction.y);
            v2.mult(-factor);
            v2.add(new Vector(x2, y2));
            v2.add(n);
            Vector middle = bezierPoint(x1, y1, v1.x, v1.y, v2.x, v2.y, x2, y2, 0.5f);
            item.setData(LABEL_X, middle.x);
            item.setData(LABEL_Y, middle.y);
        } else {
            Float x = ((Float) sourceItem.getData(NodeItem.X) + (Float) targetItem.getData(NodeItem.X)) / 2f;
            Float y = ((Float) sourceItem.getData(NodeItem.Y) + (Float) targetItem.getData(NodeItem.Y)) / 2f;
            item.setData(LABEL_X, x);
            item.setData(LABEL_Y, y);
        }
    }
    //Property font
    font = properties.getFontValue(PreviewProperty.EDGE_LABEL_FONT);
}
Also used : EdgeColor(org.gephi.preview.types.EdgeColor) EdgeLabelItem(org.gephi.preview.plugin.items.EdgeLabelItem) EdgeItem(org.gephi.preview.plugin.items.EdgeItem) NodeItem(org.gephi.preview.plugin.items.NodeItem) NodeItem(org.gephi.preview.plugin.items.NodeItem) Color(java.awt.Color) EdgeColor(org.gephi.preview.types.EdgeColor) DependantColor(org.gephi.preview.types.DependantColor) DependantOriginalColor(org.gephi.preview.types.DependantOriginalColor) Edge(org.gephi.graph.api.Edge) GlyphVector(java.awt.font.GlyphVector)

Example 5 with EdgeColor

use of org.gephi.preview.types.EdgeColor in project gephi by gephi.

the class BasicEdgeColorPropertyEditor method setAsText.

@Override
public void setAsText(String s) {
    if (matchColorMode(s, EdgeColor.Mode.CUSTOM.name().toLowerCase())) {
        Pattern p = Pattern.compile("\\w+\\s*\\[\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\]");
        Matcher m = p.matcher(s);
        if (m.lookingAt()) {
            int r = Integer.valueOf(m.group(1));
            int g = Integer.valueOf(m.group(2));
            int b = Integer.valueOf(m.group(3));
            setValue(new EdgeColor(new Color(r, g, b)));
        }
    } else if (matchColorMode(s, EdgeColor.Mode.MIXED.name().toLowerCase())) {
        setValue(new EdgeColor(EdgeColor.Mode.MIXED));
    } else if (matchColorMode(s, EdgeColor.Mode.ORIGINAL.name().toLowerCase())) {
        setValue(new EdgeColor(EdgeColor.Mode.ORIGINAL));
    } else if (matchColorMode(s, EdgeColor.Mode.SOURCE.name().toLowerCase())) {
        setValue(new EdgeColor(EdgeColor.Mode.SOURCE));
    } else if (matchColorMode(s, EdgeColor.Mode.TARGET.name().toLowerCase())) {
        setValue(new EdgeColor(EdgeColor.Mode.TARGET));
    }
}
Also used : EdgeColor(org.gephi.preview.types.EdgeColor) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Color(java.awt.Color) EdgeColor(org.gephi.preview.types.EdgeColor)

Aggregations

EdgeColor (org.gephi.preview.types.EdgeColor)6 Color (java.awt.Color)4 Edge (org.gephi.graph.api.Edge)2 EdgeItem (org.gephi.preview.plugin.items.EdgeItem)2 NodeItem (org.gephi.preview.plugin.items.NodeItem)2 DependantColor (org.gephi.preview.types.DependantColor)2 DependantOriginalColor (org.gephi.preview.types.DependantOriginalColor)2 GlyphVector (java.awt.font.GlyphVector)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 EdgeLabelItem (org.gephi.preview.plugin.items.EdgeLabelItem)1 JColorButton (org.gephi.ui.components.JColorButton)1