Search in sources :

Example 26 with GraphController

use of org.gephi.graph.api.GraphController in project gephi by gephi.

the class DynamicSettingsPanel method createValidation.

public void createValidation(ValidationGroup group) {
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController.getGraphModel();
    TimeFormat timeFormat = graphModel.getTimeFormat();
    if (timeFormat == TimeFormat.DOUBLE) {
        group.add(windowTextField, Validators.REQUIRE_NON_EMPTY_STRING, Validators.numberRange(Double.MIN_VALUE, (bounds.getHigh() - bounds.getLow())));
        group.add(tickTextField, Validators.REQUIRE_NON_EMPTY_STRING, Validators.numberRange(Double.MIN_VALUE, (bounds.getHigh() - bounds.getLow())));
    } else {
        //TODO validation with dates
        group.add(windowTextField, Validators.REQUIRE_NON_EMPTY_STRING, new PositiveNumberValidator(), new DateRangeValidator(windowTimeUnitCombo.getModel()));
        group.add(tickTextField, Validators.REQUIRE_NON_EMPTY_STRING, new PositiveNumberValidator(), new DateRangeValidator(tickTimeUnitCombo.getModel()), new TickUnderWindowValidator(timeFormat != TimeFormat.DOUBLE));
    }
}
Also used : TimeFormat(org.gephi.graph.api.TimeFormat) PositiveNumberValidator(org.gephi.lib.validation.PositiveNumberValidator) GraphModel(org.gephi.graph.api.GraphModel) GraphController(org.gephi.graph.api.GraphController)

Example 27 with GraphController

use of org.gephi.graph.api.GraphController in project gephi by gephi.

the class DynamicSettingsPanel method unsetup.

public void unsetup(DynamicStatistics dynamicStatistics) {
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController.getGraphModel();
    TimeFormat timeFormat = graphModel.getTimeFormat();
    //Bounds is the same
    dynamicStatistics.setBounds(bounds);
    //Window
    double window;
    if (timeFormat == TimeFormat.DOUBLE) {
        window = Double.parseDouble(windowTextField.getText());
    } else {
        TimeUnit timeUnit = getSelectedTimeUnit(windowTimeUnitCombo.getModel());
        window = getTimeInMilliseconds(windowTextField.getText(), timeUnit);
    }
    dynamicStatistics.setWindow(window);
    //Tick
    double tick;
    if (timeFormat == TimeFormat.DOUBLE) {
        tick = Double.parseDouble(tickTextField.getText());
    } else {
        TimeUnit timeUnit = getSelectedTimeUnit(tickTimeUnitCombo.getModel());
        tick = getTimeInMilliseconds(tickTextField.getText(), timeUnit);
    }
    dynamicStatistics.setTick(tick);
    //Save latest selected item
    if (timeFormat != TimeFormat.DOUBLE) {
        saveDefaultTimeUnits();
    }
}
Also used : TimeFormat(org.gephi.graph.api.TimeFormat) GraphModel(org.gephi.graph.api.GraphModel) TimeUnit(java.util.concurrent.TimeUnit) GraphController(org.gephi.graph.api.GraphController)

Example 28 with GraphController

use of org.gephi.graph.api.GraphController in project gephi by gephi.

the class TextModelImpl method readXML.

public void readXML(XMLStreamReader reader, Workspace workspace) throws XMLStreamException {
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController != null ? graphController.getGraphModel(workspace) : null;
    List<Column> nodeCols = new ArrayList<>();
    List<Column> edgeCols = new ArrayList<>();
    boolean nodeColumn = false;
    boolean edgeColumn = false;
    boolean nodeSizeFac = false;
    boolean edgeSizeFac = false;
    boolean end = false;
    while (reader.hasNext() && !end) {
        int type = reader.next();
        switch(type) {
            case XMLStreamReader.START_ELEMENT:
                String name = reader.getLocalName();
                if ("shownodelabels".equalsIgnoreCase(name)) {
                    showNodeLabels = Boolean.parseBoolean(reader.getAttributeValue(null, "enable"));
                } else if ("showedgelabels".equalsIgnoreCase(name)) {
                    showEdgeLabels = Boolean.parseBoolean(reader.getAttributeValue(null, "enable"));
                } else if ("selectedOnly".equalsIgnoreCase(name)) {
                    selectedOnly = Boolean.parseBoolean(reader.getAttributeValue(null, "value"));
                } else if ("nodefont".equalsIgnoreCase(name)) {
                    String nodeFontName = reader.getAttributeValue(null, "name");
                    int nodeFontSize = Integer.parseInt(reader.getAttributeValue(null, "size"));
                    int nodeFontStyle = Integer.parseInt(reader.getAttributeValue(null, "style"));
                    nodeFont = new Font(nodeFontName, nodeFontStyle, nodeFontSize);
                } else if ("edgefont".equalsIgnoreCase(name)) {
                    String edgeFontName = reader.getAttributeValue(null, "name");
                    int edgeFontSize = Integer.parseInt(reader.getAttributeValue(null, "size"));
                    int edgeFontStyle = Integer.parseInt(reader.getAttributeValue(null, "style"));
                    edgeFont = new Font(edgeFontName, edgeFontStyle, edgeFontSize);
                } else if ("nodecolor".equalsIgnoreCase(name)) {
                    nodeColor = ColorUtils.decode(reader.getAttributeValue(null, "value")).getRGBComponents(null);
                } else if ("edgecolor".equalsIgnoreCase(name)) {
                    edgeColor = ColorUtils.decode(reader.getAttributeValue(null, "value")).getRGBComponents(null);
                } else if ("nodesizefactor".equalsIgnoreCase(name)) {
                    nodeSizeFac = true;
                } else if ("edgesizefactor".equalsIgnoreCase(name)) {
                    edgeSizeFac = true;
                } else if ("colormode".equalsIgnoreCase(name)) {
                    String colorModeClass = reader.getAttributeValue(null, "class");
                    if (colorModeClass.equals("TextColorMode")) {
                        colorMode = VizController.getInstance().getTextManager().getColorModes()[2];
                    } else if (colorModeClass.equals("ObjectColorMode")) {
                        colorMode = VizController.getInstance().getTextManager().getColorModes()[1];
                    } else {
                        colorMode = VizController.getInstance().getTextManager().getColorModes()[0];
                    }
                } else if ("sizemode".equalsIgnoreCase(name)) {
                    String sizeModeClass = reader.getAttributeValue(null, "class");
                    if (sizeModeClass.equals("FixedSizeMode")) {
                        sizeMode = VizController.getInstance().getTextManager().getSizeModes()[0];
                    } else if (sizeModeClass.equals("ProportionalSizeMode")) {
                        sizeMode = VizController.getInstance().getTextManager().getSizeModes()[2];
                    } else if (sizeModeClass.equals("ScaledSizeMode")) {
                        sizeMode = VizController.getInstance().getTextManager().getSizeModes()[1];
                    }
                } else if ("nodecolumns".equalsIgnoreCase(name)) {
                    nodeColumn = true;
                } else if ("edgecolumns".equalsIgnoreCase(name)) {
                    edgeColumn = true;
                } else if ("column".equalsIgnoreCase(name)) {
                    String id = reader.getAttributeValue(null, "id");
                    if (nodeColumn && graphModel != null) {
                        Column col = graphModel.getNodeTable().getColumn(id);
                        if (col != null) {
                            nodeCols.add(col);
                        }
                    } else if (edgeColumn && graphModel != null) {
                        Column col = graphModel.getEdgeTable().getColumn(id);
                        if (col != null) {
                            edgeCols.add(col);
                        }
                    }
                }
                break;
            case XMLStreamReader.CHARACTERS:
                if (!reader.isWhiteSpace() && nodeSizeFac) {
                    nodeSizeFactor = Float.parseFloat(reader.getText());
                } else if (!reader.isWhiteSpace() && edgeSizeFac) {
                    edgeSizeFactor = Float.parseFloat(reader.getText());
                }
                break;
            case XMLStreamReader.END_ELEMENT:
                nodeSizeFac = false;
                edgeSizeFac = false;
                if ("nodecolumns".equalsIgnoreCase(reader.getLocalName())) {
                    nodeColumn = false;
                } else if ("edgecolumns".equalsIgnoreCase(reader.getLocalName())) {
                    edgeColumn = false;
                } else if ("textmodel".equalsIgnoreCase(reader.getLocalName())) {
                    end = true;
                }
                break;
        }
    }
    nodeTextColumns = nodeCols.toArray(new Column[0]);
    edgeTextColumns = edgeCols.toArray(new Column[0]);
}
Also used : Column(org.gephi.graph.api.Column) GraphModel(org.gephi.graph.api.GraphModel) ArrayList(java.util.ArrayList) GraphController(org.gephi.graph.api.GraphController) Font(java.awt.Font)

Aggregations

GraphController (org.gephi.graph.api.GraphController)28 GraphModel (org.gephi.graph.api.GraphModel)19 Graph (org.gephi.graph.api.Graph)12 Node (org.gephi.graph.api.Node)9 Edge (org.gephi.graph.api.Edge)7 Column (org.gephi.graph.api.Column)5 TimeFormat (org.gephi.graph.api.TimeFormat)4 MouseClickEventListener (org.gephi.tools.spi.MouseClickEventListener)3 NodeClickEventListener (org.gephi.tools.spi.NodeClickEventListener)3 ArrayList (java.util.ArrayList)2 AbstractShortestPathAlgorithm (org.gephi.algorithms.shortestpath.AbstractShortestPathAlgorithm)2 BellmanFordShortestPathAlgorithm (org.gephi.algorithms.shortestpath.BellmanFordShortestPathAlgorithm)2 DijkstraShortestPathAlgorithm (org.gephi.algorithms.shortestpath.DijkstraShortestPathAlgorithm)2 AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)2 GraphFactory (org.gephi.graph.api.GraphFactory)2 GraphView (org.gephi.graph.api.GraphView)2 DynamicStatistics (org.gephi.statistics.spi.DynamicStatistics)2 NotifyDescriptor (org.openide.NotifyDescriptor)2 Color (java.awt.Color)1 Font (java.awt.Font)1