Search in sources :

Example 11 with TimeFormat

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

the class SearchReplaceControllerImpl method replace.

@Override
public SearchResult replace(SearchResult result, String replacement) {
    if (result == null) {
        throw new IllegalArgumentException();
    }
    if (!canReplace(result)) {
        //Go to next search result
        return findNext(result);
    }
    GraphController gc = Lookup.getDefault().lookup(GraphController.class);
    Object value;
    String str;
    Element attributes;
    Column column;
    if (!result.getSearchOptions().isUseRegexReplaceMode()) {
        //Avoid using groups and other regex aspects in the replacement
        replacement = Matcher.quoteReplacement(replacement);
    }
    try {
        //Get value to re-match and replace:
        if (result.getFoundNode() != null) {
            attributes = result.getFoundNode();
            column = gc.getGraphModel().getNodeTable().getColumn(result.getFoundColumnIndex());
        } else {
            attributes = result.getFoundEdge();
            column = gc.getGraphModel().getEdgeTable().getColumn(result.getFoundColumnIndex());
        }
        GraphModel graphModel = column.getTable().getGraph().getModel();
        TimeFormat timeFormat = graphModel.getTimeFormat();
        DateTimeZone timeZone = graphModel.getTimeZone();
        value = attributes.getAttribute(column);
        str = value != null ? AttributeUtils.print(value, timeFormat, timeZone) : "";
        StringBuffer sb = new StringBuffer();
        //Match and replace the result:
        Matcher matcher = result.getSearchOptions().getRegexPattern().matcher(str.substring(result.getStart()));
        if (matcher.find()) {
            matcher.appendReplacement(sb, replacement);
            int replaceLong = sb.length();
            matcher.appendTail(sb);
            str = str.substring(0, result.getStart()) + sb.toString();
            result.getSearchOptions().setRegionStart(result.getStart() + replaceLong);
            Lookup.getDefault().lookup(AttributeColumnsController.class).setAttributeValue(str, attributes, column);
            //Go to next search result
            return findNext(result);
        } else {
            //Go to next search result
            return findNext(result);
        }
    } catch (Exception ex) {
        if (ex instanceof IndexOutOfBoundsException) {
            //Rethrow the exception when it is caused by a bad regex replacement
            throw new IndexOutOfBoundsException();
        }
        //Go to next search result
        return findNext(result);
    }
}
Also used : TimeFormat(org.gephi.graph.api.TimeFormat) Matcher(java.util.regex.Matcher) Element(org.gephi.graph.api.Element) DateTimeZone(org.joda.time.DateTimeZone) Column(org.gephi.graph.api.Column) GraphModel(org.gephi.graph.api.GraphModel) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) GraphController(org.gephi.graph.api.GraphController)

Example 12 with TimeFormat

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

the class SearchReplaceControllerImpl method findOnNodes.

private SearchResult findOnNodes(SearchOptions searchOptions, int rowIndex, int columnIndex) {
    GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
    SearchResult result = null;
    Set<Integer> columnsToSearch = searchOptions.getColumnsToSearch();
    boolean searchAllColumns = columnsToSearch.isEmpty();
    Table table = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable();
    Node[] nodes = searchOptions.getNodesToSearch();
    Node row;
    Column column;
    Object value;
    TimeFormat timeFormat = table.getGraph().getModel().getTimeFormat();
    DateTimeZone timeZone = table.getGraph().getModel().getTimeZone();
    for (; rowIndex < nodes.length; rowIndex++) {
        if (!gec.isNodeInGraph(nodes[rowIndex])) {
            //Make sure node is still in graph when continuing a search
            continue;
        }
        row = nodes[rowIndex];
        for (; columnIndex < table.countColumns(); columnIndex++) {
            if (searchAllColumns || columnsToSearch.contains(columnIndex)) {
                column = table.getColumn(columnIndex);
                value = row.getAttribute(column);
                result = matchRegex(value, searchOptions, rowIndex, columnIndex, timeFormat, timeZone);
                if (result != null) {
                    result.setFoundNode(nodes[rowIndex]);
                    return result;
                }
            }
            //Start at the beginning for the next value
            searchOptions.setRegionStart(0);
        }
        //Start at the beginning for the next value
        searchOptions.setRegionStart(0);
        //Start at the first column for the next row
        columnIndex = 0;
    }
    return result;
}
Also used : TimeFormat(org.gephi.graph.api.TimeFormat) Table(org.gephi.graph.api.Table) Column(org.gephi.graph.api.Column) GraphElementsController(org.gephi.datalab.api.GraphElementsController) Node(org.gephi.graph.api.Node) SearchResult(org.gephi.datalab.api.SearchReplaceController.SearchResult) DateTimeZone(org.joda.time.DateTimeZone)

Example 13 with TimeFormat

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

the class SearchReplaceControllerImpl method findOnEdges.

private SearchResult findOnEdges(SearchOptions searchOptions, int rowIndex, int columnIndex) {
    GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
    SearchResult result = null;
    Set<Integer> columnsToSearch = searchOptions.getColumnsToSearch();
    boolean searchAllColumns = columnsToSearch.isEmpty();
    Table table = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getEdgeTable();
    Edge[] edges = searchOptions.getEdgesToSearch();
    Edge row;
    Column column;
    Object value;
    TimeFormat timeFormat = table.getGraph().getModel().getTimeFormat();
    DateTimeZone timeZone = table.getGraph().getModel().getTimeZone();
    for (; rowIndex < edges.length; rowIndex++) {
        if (!gec.isEdgeInGraph(edges[rowIndex])) {
            //Make sure edge is still in graph when continuing a search
            continue;
        }
        row = edges[rowIndex];
        for (; columnIndex < table.countColumns(); columnIndex++) {
            if (searchAllColumns || columnsToSearch.contains(columnIndex)) {
                column = table.getColumn(columnIndex);
                value = row.getAttribute(column);
                result = matchRegex(value, searchOptions, rowIndex, columnIndex, timeFormat, timeZone);
                if (result != null) {
                    result.setFoundEdge(edges[rowIndex]);
                    return result;
                }
            }
            //Start at the beginning for the next value
            searchOptions.setRegionStart(0);
        }
        //Start at the beginning for the next value
        searchOptions.setRegionStart(0);
        //Start at the first column for the next row
        columnIndex = 0;
    }
    return result;
}
Also used : TimeFormat(org.gephi.graph.api.TimeFormat) Table(org.gephi.graph.api.Table) Column(org.gephi.graph.api.Column) GraphElementsController(org.gephi.datalab.api.GraphElementsController) SearchResult(org.gephi.datalab.api.SearchReplaceController.SearchResult) Edge(org.gephi.graph.api.Edge) DateTimeZone(org.joda.time.DateTimeZone)

Example 14 with TimeFormat

use of org.gephi.graph.api.TimeFormat 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 15 with TimeFormat

use of org.gephi.graph.api.TimeFormat 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)

Aggregations

TimeFormat (org.gephi.graph.api.TimeFormat)17 DateTimeZone (org.joda.time.DateTimeZone)13 Column (org.gephi.graph.api.Column)7 GraphController (org.gephi.graph.api.GraphController)5 GraphModel (org.gephi.graph.api.GraphModel)5 Element (org.gephi.graph.api.Element)4 ArrayList (java.util.ArrayList)3 Matcher (java.util.regex.Matcher)3 AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)3 Edge (org.gephi.graph.api.Edge)3 Node (org.gephi.graph.api.Node)3 Table (org.gephi.graph.api.Table)3 GraphElementsController (org.gephi.datalab.api.GraphElementsController)2 SearchResult (org.gephi.datalab.api.SearchReplaceController.SearchResult)2 CsvWriter (com.csvreader.CsvWriter)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1