Search in sources :

Example 16 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.

the class ControlPanel method updatePanels.

private void updatePanels() {
    final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
    final CyNetworkView view = appMgr.getCurrentNetworkView();
    final Collection<View<CyNode>> selectedNodeViews = view != null ? findSelectedNodes(view) : null;
    invokeOnEDT(() -> {
        scalePanel.setEnabled(view != null);
        rotatePanel.setEnabled(view != null);
        final boolean enabled = selectedNodeViews != null && !selectedNodeViews.isEmpty();
        alignPanel.setEnabled(enabled);
        distPanel.setEnabled(enabled);
        stackPanel.setEnabled(enabled);
    });
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetworkView(org.cytoscape.view.model.CyNetworkView) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 17 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.

the class ControlPanel method handleEvent.

@Override
public void handleEvent(RowsSetEvent e) {
    if (loadingSession)
        return;
    final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
    final CyNetworkView currentView = appMgr.getCurrentNetworkView();
    if (currentView == null)
        return;
    final CyTable tbl = e.getSource();
    final CyNetworkTableManager netTblMgr = serviceRegistrar.getService(CyNetworkTableManager.class);
    final CyNetwork net = netTblMgr.getNetworkForTable(tbl);
    if (net == null || !net.equals(currentView.getModel()) || !tbl.equals(net.getDefaultNodeTable()))
        return;
    final Collection<RowSetRecord> selectedRecords = e.getColumnRecords(CyNetwork.SELECTED);
    if (!selectedRecords.isEmpty())
        updatePanels();
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) RowSetRecord(org.cytoscape.model.events.RowSetRecord) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 18 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.

the class VizMapPropertyBuilder method createMappingProperties.

public <K, V> void createMappingProperties(final VisualMappingFunction<K, V> visualMapping, final PropertySheetPanel propertySheetPanel, final VisualMappingFunctionFactory factory) {
    final String attrName = visualMapping.getMappingColumnName();
    if (attrName == null)
        return;
    removeMappingProperties(propertySheetPanel);
    final VisualProperty<V> vp = visualMapping.getVisualProperty();
    final VisualPropertyEditor<V> vpEditor = editorManager.getVisualPropertyEditor(vp);
    if (visualMapping instanceof DiscreteMapping) {
        // Discrete Mapping
        // This set should not contain null!
        final SortedSet<Object> attrSet = new TreeSet<Object>();
        final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class);
        final CyNetwork network = appMgr.getCurrentNetwork();
        if (network != null) {
            final Set<CyIdentifiable> graphObjects = new HashSet<CyIdentifiable>();
            if (network != null) {
                if (vp.getTargetDataType().equals(CyNode.class)) {
                    graphObjects.addAll(network.getNodeList());
                } else if (vp.getTargetDataType().equals(CyEdge.class)) {
                    graphObjects.addAll(network.getEdgeList());
                } else if (vp.getTargetDataType().equals(CyNetwork.class)) {
                    graphObjects.add(network);
                } else {
                    throw new IllegalArgumentException("Data type not supported: " + vp.getTargetDataType());
                }
            }
            if (vp.getTargetDataType() == CyNetwork.class) {
                final CyRow row = network.getRow(network);
                final CyColumn column = row.getTable().getColumn(attrName);
                if (column != null)
                    processDiscretValues(row, attrName, column, column.getType(), attrSet);
            } else {
                // Make sure all data sets have the same data type.
                if (!graphObjects.isEmpty()) {
                    final CyIdentifiable firstEntry = graphObjects.iterator().next();
                    final CyRow firstRow = network.getRow(firstEntry);
                    final CyColumn column = firstRow.getTable().getColumn(attrName);
                    if (column != null) {
                        final Class<?> type = column.getType();
                        for (final CyIdentifiable go : graphObjects) {
                            final CyRow row = network.getRow(go);
                            processDiscretValues(row, attrName, column, type, attrSet);
                        }
                    }
                }
            }
        }
        // Also keep current mapping entries that have non-null values
        for (final Map.Entry<K, V> entry : ((DiscreteMapping<K, V>) visualMapping).getAll().entrySet()) {
            if (entry.getValue() != null)
                attrSet.add(entry.getKey());
        }
        setDiscreteProps(vp, visualMapping, attrSet, vpEditor, propertySheetPanel);
    } else if (visualMapping instanceof ContinuousMapping) {
        // TODO: How do we decide when to reset the range tracer for this mapping?
        final VizMapperProperty<String, VisualMappingFunction, VisualMappingFunction<K, V>> graphicalView = new VizMapperProperty<String, VisualMappingFunction, VisualMappingFunction<K, V>>(CellType.CONTINUOUS, visualMapping.getVisualProperty().getDisplayName() + "_" + GRAPHICAL_MAP_VIEW, visualMapping.getClass());
        graphicalView.setShortDescription("Continuous Mapping from " + visualMapping.getMappingColumnName() + " to " + visualMapping.getVisualProperty().getDisplayName());
        graphicalView.setValue(visualMapping);
        graphicalView.setDisplayName("Current Mapping");
        propertySheetPanel.addProperty(2, graphicalView);
        final PropertySheetTable table = propertySheetPanel.getTable();
        final PropertyRendererRegistry rendReg = (PropertyRendererRegistry) table.getRendererFactory();
        final PropertyEditorRegistry cellEditorFactory = (PropertyEditorRegistry) table.getEditorFactory();
        final PropertyEditor continuousCellEditor = editorManager.getContinuousEditor(vp);
        if (continuousCellEditor == null) {
            throw new NullPointerException("Continuous Mapping cell editor is null.");
        } else {
            // Renderer for Continuous mapping icon cell
            final TableCellRenderer continuousRenderer = vpEditor.getContinuousTableCellRenderer((ContinuousMappingEditor<? extends Number, V>) continuousCellEditor);
            rendReg.registerRenderer(graphicalView, continuousRenderer);
            continuousCellEditor.setValue(visualMapping);
            cellEditorFactory.registerEditor(graphicalView, continuousCellEditor);
        }
    } else if (visualMapping instanceof PassthroughMapping && (attrName != null)) {
    // Doesn't need to display the mapped values!
    } else {
        throw new IllegalArgumentException("Unsupported mapping type: " + visualMapping);
    }
    propertySheetPanel.getTable().repaint();
    propertySheetPanel.repaint();
}
Also used : PropertyRendererRegistry(com.l2fprod.common.propertysheet.PropertyRendererRegistry) ContinuousMappingEditor(org.cytoscape.view.vizmap.gui.editor.ContinuousMappingEditor) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) PropertyEditorRegistry(com.l2fprod.common.propertysheet.PropertyEditorRegistry) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) TreeSet(java.util.TreeSet) CyIdentifiable(org.cytoscape.model.CyIdentifiable) HashSet(java.util.HashSet) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) CyColumn(org.cytoscape.model.CyColumn) CyEdge(org.cytoscape.model.CyEdge) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) CyApplicationManager(org.cytoscape.application.CyApplicationManager) PropertySheetTable(com.l2fprod.common.propertysheet.PropertySheetTable) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) VisualPropertyEditor(org.cytoscape.view.vizmap.gui.editor.VisualPropertyEditor) PropertyEditor(java.beans.PropertyEditor) Map(java.util.Map)

Example 19 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.

the class FitLabelMappingGenerator method generateMap.

@Override
public <T> Map<T, V> generateMap(final Set<T> tableValues) {
    // Generate map for the current network view.
    final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class);
    final CyNetworkView networkView = appMgr.getCurrentNetworkView();
    // If current view is not available, simply return empty map.
    if (networkView == null)
        return Collections.emptyMap();
    // If given set is empty, return empty map.
    if (tableValues == null || tableValues.isEmpty())
        return Collections.emptyMap();
    // This only works with NAME column.
    final T testName = tableValues.iterator().next();
    if (testName instanceof String == false)
        throw new IllegalArgumentException("This generator only works with 'name' column.");
    final CyNetwork network = networkView.getModel();
    final CyTable nodeTable = networkView.getModel().getDefaultNodeTable();
    final VisualMappingManager vmMgr = servicesUtil.get(VisualMappingManager.class);
    final VisualStyle style = vmMgr.getCurrentVisualStyle();
    // Check label size mapping exists or not
    final VisualMappingFunction<?, Integer> fontSizeMapping = style.getVisualMappingFunction(BasicVisualLexicon.NODE_LABEL_FONT_SIZE);
    // Use default label width for checking.  TODO: should we use mapping?
    final Double maxLabelWidth = style.getDefaultValue(BasicVisualLexicon.NODE_LABEL_WIDTH);
    final Map<T, V> valueMap = new HashMap<T, V>();
    for (final T attrVal : tableValues) {
        final Collection<CyRow> rows = nodeTable.getMatchingRows(CyNetwork.NAME, attrVal);
        CyRow row = null;
        if (rows.isEmpty() == false)
            row = rows.iterator().next();
        else
            continue;
        final Long suid = row.get(CyIdentifiable.SUID, Long.class);
        final View<CyNode> nodeView = networkView.getNodeView(network.getNode(suid));
        if (nodeView == null)
            continue;
        final String labelText = nodeView.getVisualProperty(BasicVisualLexicon.NODE_LABEL);
        final int textLen = labelText.length();
        final int fontSize;
        if (fontSizeMapping == null)
            fontSize = style.getDefaultValue(BasicVisualLexicon.NODE_LABEL_FONT_SIZE);
        else
            fontSize = nodeView.getVisualProperty(BasicVisualLexicon.NODE_LABEL_FONT_SIZE);
        final Double width = fontSize * textLen * 0.7;
        if (maxLabelWidth > width)
            valueMap.put(attrVal, (V) width);
        else
            valueMap.put(attrVal, (V) maxLabelWidth);
    }
    return valueMap;
}
Also used : HashMap(java.util.HashMap) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 20 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.

the class C2CEditor method setValue.

@Override
@SuppressWarnings("unchecked")
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;
    mapping = (ContinuousMapping<K, V>) 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 C2CMappingEditorPanel<K, V>(vmMgr.getCurrentVisualStyle(), mapping, attr, servicesUtil);
}
Also used : ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) 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)

Aggregations

CyApplicationManager (org.cytoscape.application.CyApplicationManager)80 CyNetwork (org.cytoscape.model.CyNetwork)40 CyNetworkView (org.cytoscape.view.model.CyNetworkView)30 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)18 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)16 CyNetworkManager (org.cytoscape.model.CyNetworkManager)14 CyEventHelper (org.cytoscape.event.CyEventHelper)12 CyTable (org.cytoscape.model.CyTable)12 ArrayList (java.util.ArrayList)11 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)10 CyNode (org.cytoscape.model.CyNode)9 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)9 Test (org.junit.Test)9 HashSet (java.util.HashSet)8 CyNetworkTableManager (org.cytoscape.model.CyNetworkTableManager)8 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)8 TaskIterator (org.cytoscape.work.TaskIterator)8 HashMap (java.util.HashMap)7 CyGroupManager (org.cytoscape.group.CyGroupManager)7 CyTableManager (org.cytoscape.model.CyTableManager)7