use of org.cytoscape.view.presentation.RenderingEngine in project cytoscape-impl by cytoscape.
the class NetworkViewGrid method recreateThumbnails.
private void recreateThumbnails() {
final Dimension size = getSize();
if (size == null || size.width <= 0)
return;
final List<ThumbnailPanel> previousSelection = getSelectedItems();
getGridPanel().removeAll();
for (ThumbnailPanel tp : thumbnailPanels.values()) {
tp.getThumbnailRenderingEngine().ifPresent(RenderingEngine::dispose);
}
thumbnailPanels.clear();
if (engines == null || engines.isEmpty()) {
// Just show an info label
final GroupLayout layout = new GroupLayout(getGridPanel());
getGridPanel().setLayout(layout);
layout.setAutoCreateContainerGaps(true);
layout.setAutoCreateGaps(true);
layout.setHorizontalGroup(layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE).addComponent(getInfoLabel(), PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addGap(0, 0, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE).addComponent(getInfoLabel()).addGap(0, 0, Short.MAX_VALUE));
// Clear cache
detachedViews.clear();
selectedNetworkViews.clear();
currentNetworkView = null;
} else {
maxThumbnailSize = maxThumbnailSize(thumbnailSize, size.width);
int cols = calculateColumns(maxThumbnailSize, size.width);
int rows = calculateRows(engines.size(), cols);
getGridPanel().setLayout(new GridLayout(rows, cols));
for (RenderingEngines engines : engines.values()) {
final ThumbnailPanel tp = new ThumbnailPanel(engines, maxThumbnailSize);
thumbnailPanels.put(tp.getNetworkView(), tp);
setSelectionKeyBindings(tp);
if (previousSelection.contains(tp))
tp.setSelected(true);
}
for (Map.Entry<CyNetworkView, ThumbnailPanel> entry : thumbnailPanels.entrySet()) getGridPanel().add(entry.getValue());
if (thumbnailPanels.size() < cols) {
final int diff = cols - thumbnailPanels.size();
for (int i = 0; i < diff; i++) {
final JPanel filler = new JPanel();
filler.setOpaque(false);
getGridPanel().add(filler);
}
}
// Clear cache
for (Iterator<CyNetworkView> iter = detachedViews.iterator(); iter.hasNext(); ) {
if (!thumbnailPanels.containsKey(iter.next()))
iter.remove();
}
for (Iterator<CyNetworkView> iter = selectedNetworkViews.iterator(); iter.hasNext(); ) {
if (!thumbnailPanels.containsKey(iter.next()))
iter.remove();
}
if (currentNetworkView != null && !thumbnailPanels.containsKey(currentNetworkView))
currentNetworkView = null;
}
dirty = false;
updateToolBar();
getGridPanel().updateUI();
firePropertyChange("thumbnailPanels", null, new ArrayList<>(thumbnailPanels.values()));
}
use of org.cytoscape.view.presentation.RenderingEngine in project cytoscape-impl by cytoscape.
the class NetworkViewPreviewDialog method getGridPanel.
private JPanel getGridPanel() {
if (gridPanel == null) {
gridPanel = new GridPanel();
gridPanel.setOpaque(false);
gridPanel.setLayout(new BoxLayout(gridPanel, BoxLayout.X_AXIS));
final CyNetworkViewManager netViewManager = serviceRegistrar.getService(CyNetworkViewManager.class);
final RenderingEngineManager engineManager = serviceRegistrar.getService(RenderingEngineManager.class);
final Collection<CyNetworkView> netViews = netViewManager.getNetworkViews(network);
for (CyNetworkView view : netViews) {
final Collection<RenderingEngine<?>> engines = engineManager.getRenderingEngines(view);
for (RenderingEngine<?> re : engines) {
final ThumbnailPanel tp = new ThumbnailPanel(re, DEFAULT_THUMBNAIL_SIZE);
gridPanel.add(tp);
break;
}
}
}
return gridPanel;
}
use of org.cytoscape.view.presentation.RenderingEngine in project cytoscape-impl by cytoscape.
the class CopyExistingViewTask method run.
@Override
public void run(TaskMonitor tm) {
if (sourceView == null)
throw new NullPointerException("source network view is null.");
if (newView == null)
throw new NullPointerException("new network view is null.");
tm.setProgress(0.0);
final Collection<RenderingEngine<?>> engines = renderingEngineMgr.getAllRenderingEngines();
Collection<VisualProperty<?>> nodeProps = null;
Collection<VisualProperty<?>> edgeProps = null;
if (!engines.isEmpty()) {
final VisualLexicon lexicon = engines.iterator().next().getVisualLexicon();
nodeProps = lexicon.getAllDescendants(BasicVisualLexicon.NODE);
edgeProps = lexicon.getAllDescendants(BasicVisualLexicon.EDGE);
}
// Copy some network view properties
if (!fitContent) {
newView.setVisualProperty(BasicVisualLexicon.NETWORK_CENTER_X_LOCATION, sourceView.getVisualProperty(BasicVisualLexicon.NETWORK_CENTER_X_LOCATION));
newView.setVisualProperty(BasicVisualLexicon.NETWORK_CENTER_Y_LOCATION, sourceView.getVisualProperty(BasicVisualLexicon.NETWORK_CENTER_Y_LOCATION));
newView.setVisualProperty(BasicVisualLexicon.NETWORK_CENTER_Z_LOCATION, sourceView.getVisualProperty(BasicVisualLexicon.NETWORK_CENTER_Z_LOCATION));
newView.setVisualProperty(BasicVisualLexicon.NETWORK_SCALE_FACTOR, sourceView.getVisualProperty(BasicVisualLexicon.NETWORK_SCALE_FACTOR));
newView.setVisualProperty(BasicVisualLexicon.NETWORK_WIDTH, sourceView.getVisualProperty(BasicVisualLexicon.NETWORK_WIDTH));
newView.setVisualProperty(BasicVisualLexicon.NETWORK_HEIGHT, sourceView.getVisualProperty(BasicVisualLexicon.NETWORK_HEIGHT));
newView.setVisualProperty(BasicVisualLexicon.NETWORK_DEPTH, sourceView.getVisualProperty(BasicVisualLexicon.NETWORK_DEPTH));
}
// Copy node locations and locked visual properties
for (final View<CyNode> newNodeView : newView.getNodeViews()) {
final View<CyNode> origNodeView = getOriginalNodeView(newNodeView);
if (origNodeView == null)
continue;
newNodeView.setVisualProperty(BasicVisualLexicon.NODE_X_LOCATION, origNodeView.getVisualProperty(BasicVisualLexicon.NODE_X_LOCATION));
newNodeView.setVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION, origNodeView.getVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION));
if (nodeProps != null) {
// Set lock (if necessary)
for (final VisualProperty vp : nodeProps) {
if (origNodeView.isValueLocked(vp))
newNodeView.setLockedValue(vp, origNodeView.getVisualProperty(vp));
}
}
}
tm.setProgress(0.5);
// Copy edge locked visual properties
for (final View<CyEdge> newEdgeView : newView.getEdgeViews()) {
final View<CyEdge> origEdgeView = getOriginalEdgeView(newEdgeView);
if (origEdgeView != null && edgeProps != null) {
// Set lock (if necessary)
for (final VisualProperty vp : edgeProps) {
if (origEdgeView.isValueLocked(vp))
newEdgeView.setLockedValue(vp, origEdgeView.getVisualProperty(vp));
}
}
}
tm.setProgress(0.9);
if (style != null) {
style.apply(newView);
newView.updateView();
}
if (fitContent)
newView.fitContent();
tm.setProgress(1.0);
}
use of org.cytoscape.view.presentation.RenderingEngine in project cytoscape-impl by cytoscape.
the class ViewWriterTest method setUp.
@Before
@SuppressWarnings("rawtypes")
public void setUp() throws Exception {
final PresentationWriterManager viewWriterMgr = mock(PresentationWriterManager.class);
final CyApplicationManager applicationManager = mock(CyApplicationManager.class);
final RenderingEngineManager engineManager = mock(RenderingEngineManager.class);
final CyNetworkView view = mock(CyNetworkView.class);
final CyNetwork network = mock(CyNetwork.class);
final CyRow row = mock(CyRow.class);
final RenderingEngine re = mock(RenderingEngine.class);
final CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
when(serviceRegistrar.getService(CyApplicationManager.class)).thenReturn(applicationManager);
when(serviceRegistrar.getService(RenderingEngineManager.class)).thenReturn(engineManager);
when(serviceRegistrar.getService(PresentationWriterManager.class)).thenReturn(viewWriterMgr);
fileFilter = mock(CyFileFilter.class);
when(fileFilter.getDescription()).thenReturn("A dummy filter");
when(fileFilter.getExtensions()).thenReturn(Collections.singleton("dummy"));
final List<CyFileFilter> filters = new ArrayList<>();
filters.add(fileFilter);
when(viewWriterMgr.getAvailableWriterFilters()).thenReturn(filters);
when(view.getModel()).thenReturn(network);
when(network.getRow(network)).thenReturn(row);
cyWriter = new ViewWriter(view, re, serviceRegistrar);
final CyWriter aWriter = mock(CyWriter.class);
when(viewWriterMgr.getWriter(eq(view), eq(re), eq(fileFilter), argThat(new AnyOutputStreamMatcher()))).thenReturn(aWriter);
}
use of org.cytoscape.view.presentation.RenderingEngine in project cytoscape-impl by cytoscape.
the class ExportNetworkImageTaskFactoryTest method setUp.
@Before
@SuppressWarnings({ "rawtypes", "unchecked" })
public void setUp() throws Exception {
final CyFileFilter dummyFilter = mock(CyFileFilter.class);
final RenderingEngine engine = mock(RenderingEngine.class);
final List<CyFileFilter> filters = new ArrayList<>();
filters.add(dummyFilter);
when(dummyFilter.getDescription()).thenReturn("dummy description");
when(dummyFilter.getExtensions()).thenReturn(Collections.singleton("dummy"));
when(viewWriterMgr.getAvailableWriterFilters()).thenReturn(filters);
when(applicationManager.getCurrentRenderingEngine()).thenReturn(engine);
when(serviceRegistrar.getService(CyApplicationManager.class)).thenReturn(applicationManager);
when(serviceRegistrar.getService(RenderingEngineManager.class)).thenReturn(engineManager);
when(serviceRegistrar.getService(PresentationWriterManager.class)).thenReturn(viewWriterMgr);
}
Aggregations