use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.
the class GradientEditor method setValue.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void setValue(final Object value) {
if (value instanceof ContinuousMapping == false)
throw new IllegalArgumentException("Value should be ContinuousMapping: this is " + value);
final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class);
final CyNetwork currentNetwork = appMgr.getCurrentNetwork();
if (currentNetwork == null)
return;
ContinuousMapping<?, ?> mTest = (ContinuousMapping<?, ?>) value;
// TODO: error chekcing
mapping = (ContinuousMapping<Double, Color>) value;
Class<? extends CyIdentifiable> type = (Class<? extends CyIdentifiable>) mapping.getVisualProperty().getTargetDataType();
final CyNetworkTableManager netTblMgr = servicesUtil.get(CyNetworkTableManager.class);
final CyTable attr = netTblMgr.getTable(appMgr.getCurrentNetwork(), type, CyNetwork.DEFAULT_ATTRS);
final VisualMappingManager vmMgr = servicesUtil.get(VisualMappingManager.class);
editorPanel = new GradientEditorPanel(vmMgr.getCurrentVisualStyle(), mapping, attr, editorManager.getValueEditor(Paint.class), servicesUtil);
}
use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.
the class CellEditorEventHandler method copyMappingValues.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void copyMappingValues(final VisualMappingFunction<?, ?> source, final VisualMappingFunction<?, ?> target) {
if (source instanceof ContinuousMapping && target instanceof ContinuousMapping) {
final CyNetwork curNet = servicesUtil.get(CyApplicationManager.class).getCurrentNetwork();
if (curNet != null) {
final ContinuousMapping cm1 = (ContinuousMapping<?, ?>) source;
final ContinuousMapping cm2 = (ContinuousMapping<?, ?>) target;
final List<ContinuousMappingPoint<?, ?>> points1 = cm1.getAllPoints();
if (points1 == null || points1.isEmpty())
return;
// Check if source point values are valid
for (final ContinuousMappingPoint<?, ?> p : points1) {
final Object v = p.getValue();
if (!(v instanceof Number) || Double.isInfinite(((Number) v).doubleValue()) || Double.isNaN(((Number) v).doubleValue()))
// Do not copy!
return;
}
final VisualProperty<?> vp = source.getVisualProperty();
final CyTable dataTable = curNet.getTable(vp.getTargetDataType(), CyNetwork.DEFAULT_ATTRS);
final CyColumn col = dataTable.getColumn(target.getMappingColumnName());
if (col == null)
return;
// Make sure the source points are sorted by their values
final TreeSet<ContinuousMappingPoint<?, ?>> srcPoints = new TreeSet<ContinuousMappingPoint<?, ?>>(new Comparator<ContinuousMappingPoint<?, ?>>() {
@Override
public int compare(final ContinuousMappingPoint<?, ?> o1, final ContinuousMappingPoint<?, ?> o2) {
final double v1 = ((Number) o1.getValue()).doubleValue();
final double v2 = ((Number) o2.getValue()).doubleValue();
return Double.compare(v1, v2);
}
});
srcPoints.addAll(points1);
// Make sure the target mapping has no points, so delete any existing one
int tgtPointsSize = cm2.getPointCount();
for (int i = 0; i < tgtPointsSize; i++) cm2.removePoint(i);
// Convert the source points and copy them to the target mapping
int srcPointsSize = srcPoints.size();
for (int i = 0; i < srcPointsSize; i++) {
final ContinuousMappingPoint<?, ?> mp = cm1.getPoint(i);
final double srcVal = ((Number) cm1.getPoint(i).getValue()).doubleValue();
cm2.addPoint(srcVal, mp.getRange());
}
}
} else if (source instanceof DiscreteMapping && target instanceof DiscreteMapping) {
// TODO The problem here is that the new mapping entries haven't been created yet
// final DiscreteMapping dm1 = (DiscreteMapping<?, ?>) source;
// final DiscreteMapping dm2 = (DiscreteMapping<?, ?>) target;
// final Map map1 = dm1.getAll();
// final Map map2 = dm2.getAll();
// System.out.println("MAP 1: " + map1.size());
// System.out.println("MAP 2: " + map2.size());
//
// if (map1 == null || map1.isEmpty() || map2 == null || map2.isEmpty())
// return;
//
// final Iterator<?> tgtKeyIter = map2.keySet().iterator();
//
// for (final Object srcVal : map1.values()) {
// if (tgtKeyIter.hasNext()) {
// final Object tgtKey = tgtKeyIter.next();
// dm2.putMapValue(tgtKey, srcVal);
// } else {
// break;
// }
// }
}
}
use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.
the class MappingFunctionFactoryProxy method getMappingFactories.
public Set<VisualMappingFunctionFactory> getMappingFactories() {
final SortedSet<VisualMappingFunctionFactory> set = new TreeSet<VisualMappingFunctionFactory>(new Comparator<VisualMappingFunctionFactory>() {
@Override
public int compare(final VisualMappingFunctionFactory f1, final VisualMappingFunctionFactory f2) {
// Locale-specific sorting
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.PRIMARY);
return collator.compare(f1.toString(), f2.toString());
}
});
final MappingFunctionFactoryManager mappingFactoryMgr = servicesUtil.get(MappingFunctionFactoryManager.class);
set.addAll(mappingFactoryMgr.getFactories());
if (currentColumnName != null && currentTargetDataType != null) {
// Remove the factories that don't make sense for the current column type
final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class);
final CyNetwork net = appMgr.getCurrentNetwork();
if (net != null) {
final CyTable table = net.getTable(currentTargetDataType, CyNetwork.DEFAULT_ATTRS);
final CyColumn column = table.getColumn(currentColumnName);
if (column != null && !Number.class.isAssignableFrom(column.getType()))
set.remove(mappingFactoryMgr.getFactory(ContinuousMapping.class));
}
}
return set;
}
use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.
the class AttributeSetProxy method handleEvent.
@Override
public void handleEvent(final NetworkAddedEvent e) {
final CyNetwork network = e.getNetwork();
final Map<Class<? extends CyIdentifiable>, Set<CyTable>> object2tableMap = new HashMap<Class<? extends CyIdentifiable>, Set<CyTable>>();
final Map<Class<? extends CyIdentifiable>, AttributeSet> attrSetMap = new HashMap<Class<? extends CyIdentifiable>, AttributeSet>();
final CyNetworkTableManager netTblMgr = servicesUtil.get(CyNetworkTableManager.class);
for (final Class<? extends CyIdentifiable> objectType : graphObjects) {
final Map<String, CyTable> tableMap = netTblMgr.getTables(network, objectType);
final Collection<CyTable> tables = tableMap.values();
object2tableMap.put(objectType, new HashSet<CyTable>(tables));
final AttributeSet attrSet = new AttributeSet(objectType);
for (CyTable table : tables) {
final Collection<CyColumn> columns = table.getColumns();
for (final CyColumn column : columns) {
final Class<?> type = column.getType();
attrSet.getAttrMap().put(column.getName(), type);
}
}
attrSetMap.put(objectType, attrSet);
}
attrSets.put(network, attrSetMap);
tableSets.put(network, object2tableMap);
}
use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.
the class AttributeSetProxy method handleEvent.
@Override
public void handleEvent(final ColumnNameChangedEvent e) {
final CyTable table = e.getSource();
for (CyNetwork network : tableSets.keySet()) {
Map<Class<? extends CyIdentifiable>, Set<CyTable>> tMap = tableSets.get(network);
for (final Class<? extends CyIdentifiable> objectType : graphObjects) {
final Set<CyTable> targetTables = tMap.get(objectType);
if (targetTables.contains(table)) {
attrSets.get(network).get(objectType).getAttrMap().remove(e.getOldColumnName());
attrSets.get(network).get(objectType).getAttrMap().put(e.getNewColumnName(), table.getColumn(e.getNewColumnName()).getType());
return;
}
}
}
}
Aggregations