Search in sources :

Example 1 with RenderingEngine

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()));
}
Also used : JPanel(javax.swing.JPanel) Dimension(java.awt.Dimension) GridLayout(java.awt.GridLayout) RenderingEngine(org.cytoscape.view.presentation.RenderingEngine) GroupLayout(javax.swing.GroupLayout) Map(java.util.Map) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) ActionMap(javax.swing.ActionMap) TreeMap(java.util.TreeMap) InputMap(javax.swing.InputMap) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 2 with RenderingEngine

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;
}
Also used : RenderingEngine(org.cytoscape.view.presentation.RenderingEngine) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) BoxLayout(javax.swing.BoxLayout) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 3 with RenderingEngine

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);
}
Also used : BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualLexicon(org.cytoscape.view.model.VisualLexicon) RenderingEngine(org.cytoscape.view.presentation.RenderingEngine) VisualProperty(org.cytoscape.view.model.VisualProperty) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge)

Example 4 with RenderingEngine

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);
}
Also used : RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) PresentationWriterManager(org.cytoscape.io.write.PresentationWriterManager) CyWriter(org.cytoscape.io.write.CyWriter) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) CyApplicationManager(org.cytoscape.application.CyApplicationManager) RenderingEngine(org.cytoscape.view.presentation.RenderingEngine) CyFileFilter(org.cytoscape.io.CyFileFilter) CyNetworkView(org.cytoscape.view.model.CyNetworkView) ViewWriter(org.cytoscape.task.internal.export.ViewWriter) Before(org.junit.Before)

Example 5 with RenderingEngine

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);
}
Also used : RenderingEngine(org.cytoscape.view.presentation.RenderingEngine) CyFileFilter(org.cytoscape.io.CyFileFilter) ArrayList(java.util.ArrayList) Before(org.junit.Before)

Aggregations

RenderingEngine (org.cytoscape.view.presentation.RenderingEngine)14 CyNetworkView (org.cytoscape.view.model.CyNetworkView)7 RenderingEngineManager (org.cytoscape.view.presentation.RenderingEngineManager)6 CyNetwork (org.cytoscape.model.CyNetwork)4 CyNode (org.cytoscape.model.CyNode)4 Dimension (java.awt.Dimension)3 Image (java.awt.Image)3 BufferedImage (java.awt.image.BufferedImage)3 ArrayList (java.util.ArrayList)3 JPanel (javax.swing.JPanel)3 Color (java.awt.Color)2 Graphics2D (java.awt.Graphics2D)2 JWindow (javax.swing.JWindow)2 CyApplicationManager (org.cytoscape.application.CyApplicationManager)2 CyFileFilter (org.cytoscape.io.CyFileFilter)2 CyEdge (org.cytoscape.model.CyEdge)2 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)2 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)2 VisualLexicon (org.cytoscape.view.model.VisualLexicon)2 VisualProperty (org.cytoscape.view.model.VisualProperty)2