Search in sources :

Example 1 with DependantColor

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

the class DependantColorPanel method setup.

public void setup(DependantColorPropertyEditor propertyEditor) {
    this.propertyEditor = propertyEditor;
    DependantColor dependantColor = (DependantColor) propertyEditor.getValue();
    if (dependantColor.getMode().equals(DependantColor.Mode.CUSTOM)) {
        customRadio.setSelected(true);
        ((JColorButton) colorButton).setColor(dependantColor.getCustomColor());
    } else if (dependantColor.getMode().equals(DependantColor.Mode.PARENT)) {
        parentRadio.setSelected(true);
    }
}
Also used : JColorButton(org.gephi.ui.components.JColorButton) DependantColor(org.gephi.preview.types.DependantColor)

Example 2 with DependantColor

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

the class DependantColorPanel method itemStateChanged.

@Override
public void itemStateChanged(ItemEvent e) {
    if (customRadio.isSelected()) {
        colorButton.setEnabled(true);
    } else {
        colorButton.setEnabled(false);
    }
    DependantColor.Mode selectedMode = null;
    if (parentRadio.isSelected()) {
        selectedMode = DependantColor.Mode.PARENT;
    } else if (customRadio.isSelected()) {
        selectedMode = DependantColor.Mode.CUSTOM;
    }
    propertyEditor.setValue(new DependantColor(selectedMode));
}
Also used : DependantColor(org.gephi.preview.types.DependantColor)

Example 3 with DependantColor

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

the class NodeRenderer method renderPDF.

public void renderPDF(Item item, PDFTarget target, PreviewProperties properties) {
    Float x = item.getData(NodeItem.X);
    Float y = item.getData(NodeItem.Y);
    Float size = item.getData(NodeItem.SIZE);
    size /= 2f;
    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.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());
    cb.setLineWidth(borderSize);
    cb.setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue());
    if (alpha < 1f) {
        cb.saveState();
        PdfGState gState = new PdfGState();
        gState.setFillOpacity(alpha);
        gState.setStrokeOpacity(alpha);
        cb.setGState(gState);
    }
    cb.circle(x, -y, size);
    if (borderSize > 0) {
        cb.fillStroke();
    } else {
        cb.fill();
    }
    if (alpha < 1f) {
        cb.restoreState();
    }
}
Also used : DependantColor(org.gephi.preview.types.DependantColor) Color(java.awt.Color) DependantColor(org.gephi.preview.types.DependantColor) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte) PdfGState(com.itextpdf.text.pdf.PdfGState)

Example 4 with DependantColor

use of org.gephi.preview.types.DependantColor 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 5 with DependantColor

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

the class NodeLabelRenderer method render.

@Override
public void render(Item item, RenderTarget target, PreviewProperties properties) {
    Node node = (Node) item.getSource();
    // Label
    Color nodeColor = item.getData(NODE_COLOR);
    Color color = item.getData(NodeLabelItem.COLOR);
    DependantOriginalColor propColor = properties.getValue(PreviewProperty.NODE_LABEL_COLOR);
    color = propColor.getColor(nodeColor, color);
    String label = item.getData(NodeLabelItem.LABEL);
    Integer fontSize = item.getData(FONT_SIZE);
    Float x = item.getData(NODE_X);
    Float y = item.getData(NODE_Y);
    // Skip if empty
    if (label == null || label.trim().isEmpty()) {
        return;
    }
    // Outline
    DependantColor outlineDependantColor = properties.getValue(PreviewProperty.NODE_LABEL_OUTLINE_COLOR);
    Float outlineSize = properties.getFloatValue(PreviewProperty.NODE_LABEL_OUTLINE_SIZE);
    outlineSize = outlineSize * (fontSize / 32f);
    int outlineAlpha = (int) ((properties.getFloatValue(PreviewProperty.NODE_LABEL_OUTLINE_OPACITY) / 100f) * 255f);
    if (outlineAlpha < 0) {
        outlineAlpha = 0;
    }
    if (outlineAlpha > 255) {
        outlineAlpha = 255;
    }
    Color outlineColor = outlineDependantColor.getColor(nodeColor);
    outlineColor = new Color(outlineColor.getRed(), outlineColor.getGreen(), outlineColor.getBlue(), outlineAlpha);
    // Box
    Boolean showBox = properties.getValue(PreviewProperty.NODE_LABEL_SHOW_BOX);
    DependantColor boxDependantColor = properties.getValue(PreviewProperty.NODE_LABEL_BOX_COLOR);
    Color boxColor = boxDependantColor.getColor(nodeColor);
    int boxAlpha = (int) ((properties.getFloatValue(PreviewProperty.NODE_LABEL_BOX_OPACITY) / 100f) * 255f);
    if (boxAlpha < 0) {
        boxAlpha = 0;
    }
    if (boxAlpha > 255) {
        boxAlpha = 255;
    }
    boxColor = new Color(boxColor.getRed(), boxColor.getGreen(), boxColor.getBlue(), boxAlpha);
    if (target instanceof G2DTarget) {
        renderG2D((G2DTarget) target, label, x, y, fontSize, color, outlineSize, outlineColor, showBox, boxColor);
    } else if (target instanceof SVGTarget) {
        renderSVG((SVGTarget) target, node, label, x, y, fontSize, color, outlineSize, outlineColor, showBox, boxColor);
    } else if (target instanceof PDFTarget) {
        renderPDF((PDFTarget) target, node, label, x, y, fontSize, color, outlineSize, outlineColor, showBox, boxColor);
    }
}
Also used : DependantColor(org.gephi.preview.types.DependantColor) Node(org.gephi.graph.api.Node) Color(java.awt.Color) DependantColor(org.gephi.preview.types.DependantColor) DependantOriginalColor(org.gephi.preview.types.DependantOriginalColor) DependantOriginalColor(org.gephi.preview.types.DependantOriginalColor)

Aggregations

DependantColor (org.gephi.preview.types.DependantColor)9 Color (java.awt.Color)7 BasicStroke (java.awt.BasicStroke)2 Graphics2D (java.awt.Graphics2D)2 Node (org.gephi.graph.api.Node)2 DependantOriginalColor (org.gephi.preview.types.DependantOriginalColor)2 PdfContentByte (com.itextpdf.text.pdf.PdfContentByte)1 PdfGState (com.itextpdf.text.pdf.PdfGState)1 Rectangle (java.awt.Rectangle)1 Stroke (java.awt.Stroke)1 Ellipse2D (java.awt.geom.Ellipse2D)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Edge (org.gephi.graph.api.Edge)1 EdgeColor (org.gephi.preview.types.EdgeColor)1 JColorButton (org.gephi.ui.components.JColorButton)1 Element (org.w3c.dom.Element)1