Search in sources :

Example 66 with CyTable

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);
}
Also used : ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) Color(java.awt.Color) CyNetwork(org.cytoscape.model.CyNetwork) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 67 with CyTable

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;
    // }
    // }
    }
}
Also used : ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) CyColumn(org.cytoscape.model.CyColumn) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) CyNetwork(org.cytoscape.model.CyNetwork) ContinuousMappingPoint(org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint) ContinuousMappingPoint(org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) TreeSet(java.util.TreeSet)

Example 68 with CyTable

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;
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) MappingFunctionFactoryManager(org.cytoscape.view.vizmap.gui.MappingFunctionFactoryManager) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) TreeSet(java.util.TreeSet) CyColumn(org.cytoscape.model.CyColumn) CyNetwork(org.cytoscape.model.CyNetwork) Collator(java.text.Collator)

Example 69 with CyTable

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);
}
Also used : CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) CyColumn(org.cytoscape.model.CyColumn) CyNetwork(org.cytoscape.model.CyNetwork) CyTable(org.cytoscape.model.CyTable) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 70 with CyTable

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;
            }
        }
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) HashSet(java.util.HashSet) Set(java.util.Set) CyNetwork(org.cytoscape.model.CyNetwork) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Aggregations

CyTable (org.cytoscape.model.CyTable)282 CyNetwork (org.cytoscape.model.CyNetwork)79 CyRow (org.cytoscape.model.CyRow)73 CyColumn (org.cytoscape.model.CyColumn)71 ArrayList (java.util.ArrayList)55 CyNode (org.cytoscape.model.CyNode)43 CyEdge (org.cytoscape.model.CyEdge)35 Test (org.junit.Test)29 List (java.util.List)26 HashMap (java.util.HashMap)24 CyApplicationManager (org.cytoscape.application.CyApplicationManager)19 HashSet (java.util.HashSet)18 CyIdentifiable (org.cytoscape.model.CyIdentifiable)14 CyNetworkView (org.cytoscape.view.model.CyNetworkView)14 CyNetworkTableManager (org.cytoscape.model.CyNetworkTableManager)13 RowSetRecord (org.cytoscape.model.events.RowSetRecord)11 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)11 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)11 CyEventHelper (org.cytoscape.event.CyEventHelper)10 CyTableManager (org.cytoscape.model.CyTableManager)10