Search in sources :

Example 1 with NodeLabelItem

use of org.gephi.preview.plugin.items.NodeLabelItem in project gephi by gephi.

the class NodeLabelBuilder method getItems.

@Override
public Item[] getItems(Graph graph) {
    boolean useTextData = false;
    for (Node n : graph.getNodes()) {
        TextProperties textData = n.getTextProperties();
        if (textData != null && textData.getText() != null && !textData.getText().isEmpty()) {
            useTextData = true;
        }
    }
    //Build text
    VisualizationController vizController = Lookup.getDefault().lookup(VisualizationController.class);
    Column[] nodeColumns = vizController != null ? vizController.getNodeTextColumns() : null;
    List<Item> items = new ArrayList<>();
    for (Node n : graph.getNodes()) {
        NodeLabelItem labelItem = new NodeLabelItem(n);
        String label = getLabel(n, nodeColumns, graph.getView());
        labelItem.setData(NodeLabelItem.LABEL, label);
        TextProperties textData = n.getTextProperties();
        if (textData != null && useTextData) {
            if (textData.getR() != -1) {
                labelItem.setData(NodeLabelItem.COLOR, new Color((int) (textData.getR() * 255), (int) (textData.getG() * 255), (int) (textData.getB() * 255), (int) (textData.getAlpha() * 255)));
            }
            //                labelItem.setData(NodeLabelItem.WIDTH, textData.getWidth());
            //                labelItem.setData(NodeLabelItem.HEIGHT, textData.getHeight());
            labelItem.setData(NodeLabelItem.SIZE, textData.getSize());
            labelItem.setData(NodeLabelItem.VISIBLE, textData.isVisible());
            labelItem.setData(NodeLabelItem.LABEL, textData.getText());
            if (textData.isVisible() && label != null && !label.isEmpty()) {
                items.add(labelItem);
            }
        } else if (label != null && !label.isEmpty()) {
            items.add(labelItem);
        }
    }
    return items.toArray(new Item[0]);
}
Also used : NodeLabelItem(org.gephi.preview.plugin.items.NodeLabelItem) Item(org.gephi.preview.api.Item) NodeLabelItem(org.gephi.preview.plugin.items.NodeLabelItem) Column(org.gephi.graph.api.Column) VisualizationController(org.gephi.visualization.api.VisualizationController) Node(org.gephi.graph.api.Node) Color(java.awt.Color) ArrayList(java.util.ArrayList) TextProperties(org.gephi.graph.api.TextProperties)

Aggregations

Color (java.awt.Color)1 ArrayList (java.util.ArrayList)1 Column (org.gephi.graph.api.Column)1 Node (org.gephi.graph.api.Node)1 TextProperties (org.gephi.graph.api.TextProperties)1 Item (org.gephi.preview.api.Item)1 NodeLabelItem (org.gephi.preview.plugin.items.NodeLabelItem)1 VisualizationController (org.gephi.visualization.api.VisualizationController)1