Search in sources :

Example 21 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager 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 22 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager 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 23 with CyApplicationManager

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

the class RowsSetViewUpdater method updateView.

private final void updateView(final RowsSetEvent e) {
    boolean refreshView = false;
    boolean refreshOtherViews = false;
    // Acquire services once to avoid performance overhead of repeated lookup
    final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
    final CyColumnIdentifierFactory columnIdentifierFactory = serviceRegistrar.getService(CyColumnIdentifierFactory.class);
    final CyNetworkViewManager networkViewManager = serviceRegistrar.getService(CyNetworkViewManager.class);
    final VisualMappingManager visualMappingManager = serviceRegistrar.getService(VisualMappingManager.class);
    final RenderingEngine<CyNetwork> renderer = applicationManager.getCurrentRenderingEngine();
    final CyNetwork network = applicationManager.getCurrentNetwork();
    if (network == null)
        return;
    // 1: Update current network view
    final Collection<CyNetworkView> views = networkViewManager.getNetworkViews(network);
    CyNetworkView networkView = null;
    if (views.isEmpty())
        return;
    else
        networkView = views.iterator().next();
    final VisualStyle vs = visualMappingManager.getVisualStyle(networkView);
    Map<CyRow, View<? extends CyIdentifiable>> rowViewMap = tracker.getRowViewMap(networkView);
    for (final RowSetRecord record : e.getPayloadCollection()) {
        final CyRow row = record.getRow();
        final String columnName = record.getColumn();
        final CyColumn column = row.getTable().getColumn(columnName);
        if (column == null)
            continue;
        final VirtualColumnInfo virtualColInfo = column.getVirtualColumnInfo();
        final boolean virtual = virtualColInfo.isVirtual();
        final View<? extends CyIdentifiable> v = rowViewMap.get(row);
        if (v == null)
            continue;
        if (v.getModel() instanceof CyNode) {
            final CyNode node = (CyNode) v.getModel();
            if (network.containsNode(node) && isStyleAffected(vs, columnName, renderer, columnIdentifierFactory)) {
                vs.apply(row, v);
                refreshView = false;
            }
        } else if (v.getModel() instanceof CyEdge) {
            final CyEdge edge = (CyEdge) v.getModel();
            if (network.containsEdge(edge) && isStyleAffected(vs, columnName, renderer, columnIdentifierFactory)) {
                vs.apply(row, v);
                refreshView = false;
            }
        }
        // If virtual, it may be used in other networks.
        if (refreshView && virtual)
            refreshOtherViews = true;
    // if (refreshView)
    // vs.apply(record.getRow(), (View<? extends CyIdentifiable>) v);
    }
    if (refreshView) {
        vs.apply(networkView);
        networkView.updateView();
        if (refreshOtherViews) {
            // Check other views. If update is required, set the flag.
            for (final CyNetworkView view : networkViewManager.getNetworkViewSet()) {
                if (view == networkView)
                    continue;
                final VisualStyle style = visualMappingManager.getVisualStyle(view);
                if (style == vs) {
                    // Same style is in use. Need to apply.
                    netViewMediator.setUpdateFlag(view);
                }
            }
        }
    }
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) CyColumnIdentifierFactory(org.cytoscape.view.presentation.property.values.CyColumnIdentifierFactory) CyColumn(org.cytoscape.model.CyColumn) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VirtualColumnInfo(org.cytoscape.model.VirtualColumnInfo) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 24 with CyApplicationManager

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

the class LayoutSettingsDialog method getAlgorithmCmb.

private JComboBox<CyLayoutAlgorithm> getAlgorithmCmb() {
    if (algorithmCmb == null) {
        algorithmCmb = new JComboBox<CyLayoutAlgorithm>();
        algorithmCmb.setRenderer(new LayoutAlgorithmListCellRenderer("-- Select algorithm to view settings --"));
        algorithmCmb.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (initializing)
                    return;
                final Object o = algorithmCmb.getSelectedItem();
                if (o instanceof CyLayoutAlgorithm) {
                    currentLayout = (CyLayoutAlgorithm) o;
                    final PanelTaskManager taskMgr = serviceRegistrar.getService(PanelTaskManager.class);
                    final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
                    // Checking if the context has already been charged, if so there is no need to do it again
                    final Object context = currentLayout.getDefaultLayoutContext();
                    tunablesToSave.add(currentLayout);
                    final DynamicTaskFactoryProvisioner factoryProvisioner = serviceRegistrar.getService(DynamicTaskFactoryProvisioner.class);
                    final TaskFactory provisioner = factoryProvisioner.createFor(wrapWithContext(currentLayout, context));
                    final JPanel tunablePnl = taskMgr.getConfiguration(provisioner, context);
                    layoutAttrPnl = new JPanel();
                    layoutAttrPnl.setLayout(new BoxLayout(layoutAttrPnl, BoxLayout.PAGE_AXIS));
                    // Transparent if Aqua
                    layoutAttrPnl.setOpaque(!LookAndFeelUtil.isAquaLAF());
                    final CyNetworkView view = appMgr.getCurrentNetworkView();
                    setNetworkView(view);
                    getAlgorithmPnl().removeAll();
                    getAlgorithmPnl().add(layoutAttrPnl);
                    if (tunablePnl != null) {
                        tunablePnl.setAlignmentX(Component.CENTER_ALIGNMENT);
                        setPanelsTransparent(tunablePnl);
                        getAlgorithmPnl().add(tunablePnl);
                    }
                    if (currentLayout.getSupportsSelectedOnly() && hasSelectedNodes(view)) {
                        selectedTunable.selectedNodesOnly = true;
                        final JPanel panel = taskMgr.getConfiguration(null, selectedTunable);
                        setPanelsTransparent(panel);
                        getAlgorithmPnl().add(panel);
                    }
                    currentAction = provisioner;
                    LayoutSettingsDialog.this.pack();
                }
            }
        });
    }
    return algorithmCmb;
}
Also used : PanelTaskManager(org.cytoscape.work.swing.PanelTaskManager) JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) DynamicTaskFactoryProvisioner(org.cytoscape.task.DynamicTaskFactoryProvisioner) CyApplicationManager(org.cytoscape.application.CyApplicationManager) ActionListener(java.awt.event.ActionListener) CyLayoutAlgorithm(org.cytoscape.view.layout.CyLayoutAlgorithm) NetworkViewTaskFactory(org.cytoscape.task.NetworkViewTaskFactory) TaskFactory(org.cytoscape.work.TaskFactory) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 25 with CyApplicationManager

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

the class SelectModeAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
    final CyNetworkView view = applicationManager.getCurrentNetworkView();
    if (view != null) {
        if (name.equalsIgnoreCase(NODES)) {
            view.setLockedValue(NETWORK_NODE_SELECTION, Boolean.TRUE);
            view.setLockedValue(NETWORK_EDGE_SELECTION, Boolean.FALSE);
        } else if (name.equalsIgnoreCase(EDGES)) {
            view.setLockedValue(NETWORK_NODE_SELECTION, Boolean.FALSE);
            view.setLockedValue(NETWORK_EDGE_SELECTION, Boolean.TRUE);
        } else if (name.equalsIgnoreCase(ALL)) {
            view.setLockedValue(NETWORK_NODE_SELECTION, Boolean.TRUE);
            view.setLockedValue(NETWORK_EDGE_SELECTION, Boolean.TRUE);
        }
    }
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

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