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);
}
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;
}
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);
}
}
}
}
}
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;
}
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);
}
}
}
Aggregations