Package org.gephi.visualization.opengl.text

Source Code of org.gephi.visualization.opengl.text.TextDataBuilderImpl

/*
Copyright 2008-2010 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org

This file is part of Gephi.

Gephi is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

Gephi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with Gephi.  If not, see <http://www.gnu.org/licenses/>.
*/
package org.gephi.visualization.opengl.text;

import org.gephi.data.attributes.api.AttributeColumn;
import org.gephi.data.attributes.api.Estimator;
import org.gephi.data.attributes.type.DynamicType;
import org.gephi.data.attributes.type.TimeInterval;
import org.gephi.graph.api.EdgeData;
import org.gephi.graph.api.NodeData;
import org.gephi.graph.api.TextData;
import org.gephi.graph.spi.TextDataFactory;
import org.gephi.visualization.impl.TextDataImpl;
import org.gephi.visualization.opengl.text.TextModel;
import org.openide.util.lookup.ServiceProvider;

/**
*
* @author Mathieu Bastian
*/
public class TextDataBuilderImpl {

    private Estimator defaultEstimator;
    private Estimator numberEstimator;

    public void buildNodeText(NodeData nodeData, TextDataImpl textDataImpl, TextModel model, TimeInterval timeInterval) {
        if (model.getNodeTextColumns() != null) {
            String str = "";
            int i = 0;
            for (AttributeColumn c : model.getNodeTextColumns()) {
                if (i++ > 0) {
                    str += " - ";
                }
                Object val = nodeData.getAttributes().getValue(c.getIndex());
                if (val instanceof DynamicType) {
                    DynamicType dynamicType = (DynamicType) val;
                    Estimator estimator = defaultEstimator;
                    if (Number.class.isAssignableFrom(dynamicType.getUnderlyingType())) {
                        estimator = numberEstimator;
                    }
                    if (timeInterval != null) {
                        val = dynamicType.getValue(timeInterval.getLow(), timeInterval.getHigh(), estimator);
                    } else {
                        val = dynamicType.getValue(estimator);
                    }
                }
                str += val != null ? val : "";
            }
            textDataImpl.setText(str);
        }
    }

    public void buildEdgeText(EdgeData edgeData, TextDataImpl textDataImpl, TextModel model, TimeInterval timeInterval) {
        if (model.getEdgeTextColumns() != null) {
            String str = "";
            int i = 0;
            for (AttributeColumn c : model.getEdgeTextColumns()) {
                if (i++ > 0) {
                    str += " - ";
                }
                Object val = edgeData.getAttributes().getValue(c.getIndex());
                if (val instanceof DynamicType) {
                    DynamicType dynamicType = (DynamicType) val;
                    Estimator estimator = defaultEstimator;
                    if (Number.class.isAssignableFrom(dynamicType.getUnderlyingType())) {
                        estimator = numberEstimator;
                    }
                    if (timeInterval != null) {
                        val = dynamicType.getValue(timeInterval.getLow(), timeInterval.getHigh(), estimator);
                    } else {
                        val = dynamicType.getValue(estimator);
                    }
                }
                str += val != null ? val : "";
            }
            textDataImpl.setText(str);
        }
    }

    public void setDefaultEstimator(Estimator defaultEstimator) {
        this.defaultEstimator = defaultEstimator;
    }

    public void setNumberEstimator(Estimator numberEstimator) {
        this.numberEstimator = numberEstimator;
    }
}
TOP

Related Classes of org.gephi.visualization.opengl.text.TextDataBuilderImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.