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);
}
}
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;
}
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;
}
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));
}
}
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();
}
}
Aggregations