提交 26ebffda 编写于 作者: E Eduardo Ramos

Use AttributeUtils.print with configured time format and time zone in data...

Use AttributeUtils.print with configured time format and time zone in data laboratory where necessary.
上级 1fba8c1a
......@@ -124,7 +124,7 @@ public interface SearchReplaceController {
public void resetStatus() {
regionStart = 0;
startingRow = null;
startingRow = null;
startingColumn = null;
}
/**
......
......@@ -50,16 +50,13 @@ import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import org.gephi.datalab.api.AttributeColumnsController;
import org.gephi.graph.api.AttributeUtils;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Element;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.Table;
import org.gephi.graph.api.TimeFormat;
import org.gephi.graph.api.types.IntervalMap;
import org.gephi.graph.api.types.IntervalSet;
import org.gephi.graph.api.types.TimestampMap;
import org.gephi.graph.api.types.TimestampSet;
import org.joda.time.DateTimeZone;
import org.openide.util.Lookup;
......@@ -215,17 +212,7 @@ public class AttributeTableCSVExporter {
}
if (value != null) {
if(value instanceof TimestampSet){
text = ((TimestampSet) value).toString(timeFormat, timeZone);
} else if(value instanceof TimestampMap){
text = ((TimestampMap) value).toString(timeFormat, timeZone);
} else if(value instanceof IntervalSet){
text = ((IntervalSet) value).toString(timeFormat, timeZone);
} else if(value instanceof IntervalMap){
text = ((IntervalMap) value).toString(timeFormat, timeZone);
} else {
text = value.toString();
}
text = AttributeUtils.print(value, timeFormat, timeZone);
} else {
text = "";
}
......
......@@ -68,14 +68,17 @@ import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Element;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Interval;
import org.gephi.graph.api.Node;
import org.gephi.graph.api.Origin;
import org.gephi.graph.api.Table;
import org.gephi.graph.api.TimeFormat;
import org.gephi.graph.api.TimeRepresentation;
import org.gephi.graph.api.types.IntervalMap;
import org.gephi.graph.api.types.TimestampMap;
import org.gephi.utils.StatisticsUtils;
import org.joda.time.DateTimeZone;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.lookup.ServiceProvider;
......@@ -98,13 +101,9 @@ public class AttributeColumnsControllerImpl implements AttributeColumnsControlle
Class targetType = column.getTypeClass();
if (value != null && !value.getClass().equals(targetType)) {
try {
String stringValue;
if (value.getClass().isArray()) {
stringValue = AttributeUtils.printArray(value);
} else {
stringValue = value.toString();
}
GraphModel graphModel = column.getTable().getGraph().getModel();
String stringValue = AttributeUtils.print(value, graphModel.getTimeFormat(), graphModel.getTimeZone());
value = AttributeUtils.parse(stringValue, targetType);//Try to convert to target type from string representation
} catch (Exception ex) {
return false;//Could not parse
......@@ -303,10 +302,13 @@ public class AttributeColumnsControllerImpl implements AttributeColumnsControlle
}
Matcher matcher;
Object value;
TimeFormat timeFormat = table.getGraph().getModel().getTimeFormat();
DateTimeZone timeZone = table.getGraph().getModel().getTimeZone();
for (Element row : getTableAttributeRows(table)) {
value = row.getAttribute(column);
if (value != null) {
matcher = pattern.matcher(value.toString());
matcher = pattern.matcher(AttributeUtils.print(value, timeFormat, timeZone));
} else {
matcher = pattern.matcher("");
}
......@@ -339,10 +341,14 @@ public class AttributeColumnsControllerImpl implements AttributeColumnsControlle
Matcher matcher;
Object value;
ArrayList<String> foundGroups = new ArrayList<>();
TimeFormat timeFormat = table.getGraph().getModel().getTimeFormat();
DateTimeZone timeZone = table.getGraph().getModel().getTimeZone();
for (Element row : getTableAttributeRows(table)) {
value = row.getAttribute(column);
if (value != null) {
matcher = pattern.matcher(value.toString());
matcher = pattern.matcher(AttributeUtils.print(value, timeFormat, timeZone));
} else {
matcher = pattern.matcher("");
}
......@@ -910,10 +916,14 @@ public class AttributeColumnsControllerImpl implements AttributeColumnsControlle
Graph graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph();
Object value;
String strValue;
TimeFormat timeFormat = graph.getModel().getTimeFormat();
DateTimeZone timeZone = graph.getModel().getTimeZone();
for (Node node : graph.getNodes().toArray()) {
value = node.getAttribute(column);
if (value != null) {
strValue = value.toString();
strValue = AttributeUtils.print(value, timeFormat, timeZone);
if (!caseSensitive) {
strValue = strValue.toLowerCase();
}
......
......@@ -50,10 +50,13 @@ import org.gephi.datalab.api.AttributeColumnsMergeStrategiesController;
import org.gephi.graph.api.AttributeUtils;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Element;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Origin;
import org.gephi.graph.api.Table;
import org.gephi.graph.api.TimeFormat;
import org.gephi.graph.api.types.IntervalSet;
import org.gephi.utils.StatisticsUtils;
import org.joda.time.DateTimeZone;
import org.openide.util.Lookup;
import org.openide.util.lookup.ServiceProvider;
......@@ -86,13 +89,17 @@ public class AttributeColumnsMergeStrategiesControllerImpl implements AttributeC
Object value;
StringBuilder sb;
final int columnsCount = columnsToMerge.length;
GraphModel graphModel = table.getGraph().getModel();
TimeFormat timeFormat = graphModel.getTimeFormat();
DateTimeZone timeZone = graphModel.getTimeZone();
for (Element row : ac.getTableAttributeRows(table)) {
sb = new StringBuilder();
for (int i = 0; i < columnsCount; i++) {
value = row.getAttribute(columnsToMerge[i]);
if (value != null) {
sb.append(value.toString());
sb.append(AttributeUtils.print(value, timeFormat, timeZone));
if (i < columnsCount - 1) {
sb.append(separator);
}
......
......@@ -47,18 +47,22 @@ import org.gephi.datalab.api.AttributeColumnsController;
import org.gephi.datalab.api.GraphElementsController;
import org.gephi.datalab.api.SearchReplaceController;
import org.gephi.datalab.api.SearchReplaceController.SearchResult;
import org.gephi.graph.api.AttributeUtils;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Element;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Node;
import org.gephi.graph.api.Table;
import org.gephi.graph.api.TimeFormat;
import org.joda.time.DateTimeZone;
import org.openide.util.Lookup;
import org.openide.util.lookup.ServiceProvider;
/**
* Implementation of the SearchReplaceController interface
* declared in the Data Laboratory API.
* Implementation of the SearchReplaceController interface declared in the Data Laboratory API.
*
* @see SearchReplaceController
* @author Eduardo Ramos
*/
......@@ -143,8 +147,14 @@ public class SearchReplaceControllerImpl implements SearchReplaceController {
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 ? value.toString() : "";
str = value != null ? AttributeUtils.print(value, timeFormat, timeZone) : "";
StringBuffer sb = new StringBuffer();
//Match and replace the result:
......@@ -200,7 +210,10 @@ public class SearchReplaceControllerImpl implements SearchReplaceController {
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])) {
continue;//Make sure node is still in graph when continuing a search
......@@ -210,7 +223,7 @@ public class SearchReplaceControllerImpl implements SearchReplaceController {
if (searchAllColumns || columnsToSearch.contains(columnIndex)) {
column = table.getColumn(columnIndex);
value = row.getAttribute(column);
result = matchRegex(value, searchOptions, rowIndex, columnIndex);
result = matchRegex(value, searchOptions, rowIndex, columnIndex, timeFormat, timeZone);
if (result != null) {
result.setFoundNode(nodes[rowIndex]);
return result;
......@@ -234,7 +247,10 @@ public class SearchReplaceControllerImpl implements SearchReplaceController {
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])) {
continue;//Make sure edge is still in graph when continuing a search
......@@ -244,7 +260,7 @@ public class SearchReplaceControllerImpl implements SearchReplaceController {
if (searchAllColumns || columnsToSearch.contains(columnIndex)) {
column = table.getColumn(columnIndex);
value = row.getAttribute(column);
result = matchRegex(value, searchOptions, rowIndex, columnIndex);
result = matchRegex(value, searchOptions, rowIndex, columnIndex, timeFormat, timeZone);
if (result != null) {
result.setFoundEdge(edges[rowIndex]);
return result;
......@@ -258,9 +274,11 @@ public class SearchReplaceControllerImpl implements SearchReplaceController {
return result;
}
private SearchResult matchRegex(Object value, SearchOptions searchOptions, int rowIndex, int columnIndex) {
private SearchResult matchRegex(Object value, SearchOptions searchOptions, int rowIndex, int columnIndex, TimeFormat timeFormat, DateTimeZone timeZone) {
boolean found;
String str = value != null ? value.toString() : "";
String str = value != null ? AttributeUtils.print(value, timeFormat, timeZone) : "";
Matcher matcher = searchOptions.getRegexPattern().matcher(str);
if (str.isEmpty()) {
if (searchOptions.getRegionStart() > 0) {
......
......@@ -53,6 +53,7 @@ import org.gephi.datalab.api.AttributeColumnsController;
import org.gephi.datalab.plugin.manipulators.columns.ui.ColumnValuesFrequencyUI;
import org.gephi.datalab.spi.columns.AttributeColumnsManipulator;
import org.gephi.datalab.spi.columns.AttributeColumnsManipulatorUI;
import org.gephi.graph.api.AttributeUtils;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Table;
import org.gephi.utils.HTMLEscape;
......@@ -182,7 +183,7 @@ public class ColumnValuesFrequency implements AttributeColumnsManipulator {
sb.append("<li>");
sb.append("<b>");
if (value != null) {
sb.append(HTMLEscape.stringToHTMLString(value.toString()));
sb.append(HTMLEscape.stringToHTMLString(AttributeUtils.print(value)));
} else {
sb.append("null");
}
......@@ -201,11 +202,11 @@ public class ColumnValuesFrequency implements AttributeColumnsManipulator {
}
public JFreeChart buildPieChart(final Map<Object, Integer> valuesFrequencies) {
final ArrayList<Object> values= new ArrayList<>(valuesFrequencies.keySet());
final ArrayList<Object> values = new ArrayList<>(valuesFrequencies.keySet());
DefaultPieDataset pieDataset = new DefaultPieDataset();
for (Object value : values) {
pieDataset.setValue(value != null ? "'" + value.toString() + "'" : "null", valuesFrequencies.get(value));
pieDataset.setValue(value != null ? "'" + AttributeUtils.print(value) + "'" : "null", valuesFrequencies.get(value));
}
JFreeChart chart = ChartFactory.createPieChart(NbBundle.getMessage(ColumnValuesFrequency.class, "ColumnValuesFrequency.report.piechart.title"), pieDataset, false, true, false);
......@@ -215,10 +216,9 @@ public class ColumnValuesFrequency implements AttributeColumnsManipulator {
private void writePieChart(final StringBuilder sb, JFreeChart chart, Dimension dimension) throws IOException {
TempDir tempDir = TempDirUtils.createTempDir();
String imageFile = "";
String fileName = "frequencies-pie-chart.png";
File file = tempDir.createFile(fileName);
imageFile = "<center><img src=\"file:" + file.getAbsolutePath() + "\"</img></center>";
String imageFile = "<center><img src=\"file:" + file.getAbsolutePath() + "\"</img></center>";
ChartUtilities.saveChartAsPNG(file, chart, dimension != null ? dimension.width : 1000, dimension != null ? dimension.height : 1000);
sb.append(imageFile);
......
......@@ -52,18 +52,22 @@ import org.gephi.datalab.api.SearchReplaceController;
import org.gephi.datalab.api.SearchReplaceController.SearchOptions;
import org.gephi.datalab.api.SearchReplaceController.SearchResult;
import org.gephi.datalab.api.datatables.DataTablesController;
import org.gephi.graph.api.AttributeUtils;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.Node;
import org.gephi.graph.api.Table;
import org.gephi.graph.api.TimeFormat;
import org.gephi.utils.HTMLEscape;
import org.joda.time.DateTimeZone;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
/**
* Special UI for SearchReplace GeneralActionsManipulator
*
* @author Eduardo Ramos
*/
@ServiceProvider(service = SearchReplaceUI.class)
......@@ -83,7 +87,9 @@ public final class SearchReplaceUI extends javax.swing.JPanel {
private Pattern regexPattern;
private boolean active = false;
/** Creates new form SearchReplaceUI */
/**
* Creates new form SearchReplaceUI
*/
public SearchReplaceUI() {
initComponents();
......@@ -213,6 +219,7 @@ public final class SearchReplaceUI extends javax.swing.JPanel {
private void showSearchResult() {
if (searchResult != null) {
Table table;
Object value;
if (mode == Mode.NODES_TABLE) {
Node node = searchResult.getFoundNode();
......@@ -220,8 +227,8 @@ public final class SearchReplaceUI extends javax.swing.JPanel {
if (!dataTablesController.isNodeTableMode()) {
dataTablesController.selectNodesTable();
}
Table table = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable();
table = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable();
value = node.getAttribute(table.getColumn(searchResult.getFoundColumnIndex()));
} else {
Edge edge = searchResult.getFoundEdge();
......@@ -229,10 +236,13 @@ public final class SearchReplaceUI extends javax.swing.JPanel {
if (!dataTablesController.isEdgeTableMode()) {
dataTablesController.selectEdgesTable();
}
Table table = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getEdgeTable();
table = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getEdgeTable();
value = edge.getAttribute(table.getColumn(searchResult.getFoundColumnIndex()));
}
TimeFormat timeFormat = table.getGraph().getModel().getTimeFormat();
DateTimeZone timeZone = table.getGraph().getModel().getTimeZone();
String columnName;
if (mode == Mode.NODES_TABLE) {
columnName = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable().getColumn(searchResult.getFoundColumnIndex()).getTitle();
......@@ -245,7 +255,7 @@ public final class SearchReplaceUI extends javax.swing.JPanel {
sb.append(NbBundle.getMessage(SearchReplaceUI.class, "SearchReplaceUI.column", HTMLEscape.stringToHTMLString(columnName)));
sb.append("<br>");
if (value != null) {
String text = value.toString();
String text = AttributeUtils.print(value, timeFormat, timeZone);
sb.append(HTMLEscape.stringToHTMLString(text.substring(0, searchResult.getStart())));
sb.append("<font color='blue'>");
sb.append(HTMLEscape.stringToHTMLString(text.substring(searchResult.getStart(), searchResult.getEnd())));
......@@ -261,8 +271,8 @@ public final class SearchReplaceUI extends javax.swing.JPanel {
resultText.setText("");
}
}
private void nextResult(){
private void nextResult() {
searchResult = searchReplaceController.findNext(searchOptions);
refreshSearchOptions();
showSearchResult();
......@@ -294,10 +304,8 @@ public final class SearchReplaceUI extends javax.swing.JPanel {
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
......@@ -556,7 +564,7 @@ public final class SearchReplaceUI extends javax.swing.JPanel {
}//GEN-LAST:event_columnsToSearchComboBoxItemStateChanged
private void searchTextKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchTextKeyPressed
if(evt.getKeyCode() == KeyEvent.VK_ENTER){
if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
nextResult();
}
}//GEN-LAST:event_searchTextKeyPressed
......
......@@ -45,8 +45,11 @@ import javax.swing.Icon;
import org.gephi.datalab.plugin.manipulators.rows.merge.ui.JoinWithSeparatorUI;
import org.gephi.datalab.spi.ManipulatorUI;
import org.gephi.datalab.spi.rows.merge.AttributeRowsMergeStrategy;
import org.gephi.graph.api.AttributeUtils;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Element;
import org.gephi.graph.api.TimeFormat;
import org.joda.time.DateTimeZone;
import org.openide.util.ImageUtilities;
import org.openide.util.NbBundle;
import org.openide.util.NbPreferences;
......@@ -86,12 +89,15 @@ public class JoinWithSeparator implements AttributeRowsMergeStrategy {
Object value;
StringBuilder sb;
final int rowsCount = rows.length;
TimeFormat timeFormat = column.getTable().getGraph().getModel().getTimeFormat();
DateTimeZone timeZone = column.getTable().getGraph().getModel().getTimeZone();
sb = new StringBuilder();
for (int i = 0; i < rows.length; i++) {
value = rows[i].getAttribute(column);
if (value != null) {
sb.append(value.toString());
sb.append(AttributeUtils.print(value, timeFormat, timeZone));
if (i < rowsCount - 1) {
sb.append(separator);
}
......
......@@ -140,7 +140,7 @@ public class AttributeTypesSupportCellEditor extends DefaultCellEditor {
} else if (isDecimalType) {
valueStr = DoubleStringConverter.FORMAT.format(value);
} else {
valueStr = value.toString();
valueStr = AttributeUtils.print(value, timeFormat, timeZone);
}
textField.setBorder(originalBorder);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册