Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
Copyright 2008-2010 Gephi
Authors : Eduardo Ramos
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.datalab.impl;
import com.csvreader.CsvReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.gephi.datalab.api.AttributeColumnsController;
import org.gephi.datalab.api.GraphElementsController;
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.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;
/**
* Implementation of the AttributeColumnsController interface declared in the Data Laboratory API.
*
* @author Eduardo Ramos
* @see AttributeColumnsController
*/
@ServiceProvider(service = AttributeColumnsController.class)
public class AttributeColumnsControllerImpl implements AttributeColumnsController {
@Override
public boolean setAttributeValue(Object value, Element row, Column column) {
if (!canChangeColumnData(column)) {
return false;
}
Class targetType = column.getTypeClass();
if (value != null && !value.getClass().equals(targetType)) {
try {
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
}
}
if (value == null && !canClearColumnData(column)) {
return false;//Do not set a null value when the column can't have a null value
} else {
try {
if (value == null) {
row.removeAttribute(column);
} else {
row.setAttribute(column, value);
}
return true;
} catch (Exception e) {
Logger.getLogger("").log(Level.SEVERE, null, e);
return false;
}
}
}
@Override
public Column addAttributeColumn(Table table, String title, Class type) {
if (title == null || title.isEmpty()) {
return null;
}
if (table.hasColumn(title)) {
return null;
}
return table.addColumn(title, type, Origin.DATA);
}
@Override
public void deleteAttributeColumn(Table table, Column column) {
if (canDeleteColumn(column)) {
table.removeColumn(column);
}
}
@Override
public Column convertAttributeColumnToDynamic(Table table, Column column, double low, double high) {
return convertColumnToDynamic(table, column, low, high, null);
}
@Override
public Column convertAttributeColumnToNewDynamicColumn(Table table, Column column, double low, double high, String newColumnTitle) {
return convertColumnToDynamic(table, column, low, high, newColumnTitle);
}
private Column convertColumnToDynamic(Table table, Column column, double low, double high, String newColumnTitle) {
Class oldType = column.getTypeClass();
TimeRepresentation timeRepresentation = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getConfiguration().getTimeRepresentation();
Class> newType;
if (timeRepresentation == TimeRepresentation.TIMESTAMP) {
newType = AttributeUtils.getTimestampMapType(oldType);
} else {
newType = AttributeUtils.getIntervalMapType(oldType);
}
if (newColumnTitle != null) {
if (newColumnTitle.equals(column.getTitle())) {
throw new IllegalArgumentException("Column titles can't be equal");
}
}
Element rows[] = getTableAttributeRows(table);
Object[] oldValues = new Object[rows.length];
for (int i = 0; i < rows.length; i++) {
oldValues[i] = rows[i].getAttribute(column);
}
Column newColumn;
if (newColumnTitle == null) {
table.removeColumn(column);
newColumn = table.addColumn(column.getTitle(), newType, column.getOrigin());
} else {
newColumn = table.addColumn(newColumnTitle, newType, column.getOrigin());
}
if (timeRepresentation == TimeRepresentation.TIMESTAMP) {
for (int i = 0; i < rows.length; i++) {
if (oldValues[i] != null) {
rows[i].setAttribute(newColumn, oldValues[i], low);
}
}
} else {
Interval interval = new Interval(low, high);
for (int i = 0; i < rows.length; i++) {
if (oldValues[i] != null) {
rows[i].setAttribute(newColumn, oldValues[i], interval);
}
}
}
return newColumn;
}
@Override
public Column duplicateColumn(Table table, Column column, String title, Class type) {
Column newColumn = addAttributeColumn(table, title, type);
if (newColumn == null) {
return null;
}
copyColumnDataToOtherColumn(table, column, newColumn);
return newColumn;
}
@Override
public void copyColumnDataToOtherColumn(Table table, Column sourceColumn, Column targetColumn) {
if (sourceColumn == targetColumn) {
throw new IllegalArgumentException("Source and target columns can't be equal");
}
Class targetType = targetColumn.getTypeClass();
Object value;
if (!targetType.equals(sourceColumn.getTypeClass())) {
for (Element row : getTableAttributeRows(table)) {
value = row.getAttribute(sourceColumn);
setAttributeValue(value, row, targetColumn);
}
} else {
for (Element row : getTableAttributeRows(table)) {
value = row.getAttribute(sourceColumn);
if (value == null) {
row.removeAttribute(targetColumn);
} else {
row.setAttribute(targetColumn, value);
}
}
}
}
@Override
public void fillColumnWithValue(Table table, Column column, String value) {
if (canChangeColumnData(column)) {
for (Element row : getTableAttributeRows(table)) {
setAttributeValue(value, row, column);
}
}
}
@Override
public void fillNodesColumnWithValue(Node[] nodes, Column column, String value) {
if (canChangeColumnData(column)) {
for (Node node : nodes) {
setAttributeValue(value, node, column);
}
}
}
@Override
public void fillEdgesColumnWithValue(Edge[] edges, Column column, String value) {
if (canChangeColumnData(column)) {
for (Edge edge : edges) {
setAttributeValue(value, edge, column);
}
}
}
@Override
public void clearColumnData(Table table, Column column) {
if (canClearColumnData(column)) {
for (Element row : getTableAttributeRows(table)) {
row.removeAttribute(column);
}
}
}
@Override
public Map