Search in sources :

Example 1 with ThumbnailPanel

use of org.cytoscape.internal.view.NetworkViewGrid.ThumbnailPanel in project cytoscape-impl by cytoscape.

the class NetworkViewMainPanel method createNetworkViewGrid.

private NetworkViewGrid createNetworkViewGrid() {
    final NetworkViewGrid nvg = new NetworkViewGrid(gridViewToggleModel, viewComparator, serviceRegistrar);
    nvg.getDetachSelectedViewsButton().addActionListener(evt -> {
        final List<ThumbnailPanel> selectedItems = networkViewGrid.getSelectedItems();
        if (selectedItems != null) {
            // Get the current view first
            final CyNetworkView currentView = getCurrentNetworkView();
            // Detach the views
            for (ThumbnailPanel tp : selectedItems) {
                if (getNetworkViewCard(tp.getNetworkView()) != null)
                    detachNetworkView(tp.getNetworkView());
            }
            // Set the original current view by bringing its frame to front, if it is detached
            final NetworkViewFrame frame = getNetworkViewFrame(currentView);
            if (frame != null)
                frame.toFront();
        }
    });
    nvg.getReattachAllViewsButton().addActionListener(evt -> {
        final Collection<NetworkViewFrame> allFrames = new ArrayList<>(viewFrames.values());
        for (NetworkViewFrame f : allFrames) reattachNetworkView(f.getNetworkView());
    });
    nvg.getDestroySelectedViewsButton().addActionListener(evt -> {
        final List<CyNetworkView> selectedViews = getSelectedNetworkViews();
        if (selectedViews != null && !selectedViews.isEmpty()) {
            final DialogTaskManager taskMgr = serviceRegistrar.getService(DialogTaskManager.class);
            final DestroyNetworkViewTaskFactory taskFactory = serviceRegistrar.getService(DestroyNetworkViewTaskFactory.class);
            taskMgr.execute(taskFactory.createTaskIterator(selectedViews));
        }
    });
    return nvg;
}
Also used : ArrayList(java.util.ArrayList) DestroyNetworkViewTaskFactory(org.cytoscape.task.destroy.DestroyNetworkViewTaskFactory) DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager) CyNetworkView(org.cytoscape.view.model.CyNetworkView) ThumbnailPanel(org.cytoscape.internal.view.NetworkViewGrid.ThumbnailPanel)

Example 2 with ThumbnailPanel

use of org.cytoscape.internal.view.NetworkViewGrid.ThumbnailPanel in project cytoscape-impl by cytoscape.

the class NetworkViewMediator method initComponents.

@SuppressWarnings("unchecked")
private void initComponents() {
    final NetworkViewMainPanel viewMainPanel = getNetworkViewMainPanel();
    final NetworkViewGrid vg = viewMainPanel.getNetworkViewGrid();
    gridViewToggleModel.addPropertyChangeListener("mode", (PropertyChangeEvent e) -> {
        final Mode mode = (Mode) e.getNewValue();
        if (mode == Mode.GRID) {
            final Component currentCard = viewMainPanel.getCurrentCard();
            if (currentCard instanceof NetworkViewComparisonPanel)
                viewMainPanel.endComparison((NetworkViewComparisonPanel) currentCard);
            viewMainPanel.showGrid(true);
            vg.requestFocusInWindow();
        } else if (mode == Mode.VIEW) {
            final Set<CyNetworkView> selectedViews = new LinkedHashSet<>(viewMainPanel.getSelectedNetworkViews());
            if (selectedViews.size() > 1) {
                viewMainPanel.showComparisonPanel(selectedViews);
            } else {
                final CyNetworkView currentView = vg.getCurrentNetworkView();
                NetworkViewContainer viewContainer = null;
                if (currentView != null) {
                    viewContainer = viewMainPanel.showViewContainer(currentView);
                    if (viewContainer != null) {
                        viewMainPanel.setCurrentNetworkView(viewContainer.getNetworkView());
                        viewContainer.getContentPane().requestFocusInWindow();
                    }
                } else {
                    final CyNetwork currentNet = networkMediator.getCurrentNetwork();
                    viewMainPanel.showNullViewContainer(currentNet);
                }
            }
        }
    });
    vg.addPropertyChangeListener("currentNetworkView", (PropertyChangeEvent e) -> {
        final CyNetworkView targetView = (CyNetworkView) e.getNewValue();
        final CyNetworkViewManager netViewMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
        if (targetView != null) {
            if (netViewMgr.getNetworkViewSet().contains(targetView)) {
                if (viewUpdateRequired.contains(targetView)) {
                    viewUpdateRequired.remove(targetView);
                    final VisualMappingManager vmm = serviceRegistrar.getService(VisualMappingManager.class);
                    final VisualStyle style = vmm.getVisualStyle(targetView);
                    style.apply(targetView);
                    targetView.updateView();
                }
            }
        }
    });
    vg.addPropertyChangeListener("thumbnailPanels", (PropertyChangeEvent e) -> {
        final Collection<ThumbnailPanel> thumbnails = (Collection<ThumbnailPanel>) e.getNewValue();
        for (ThumbnailPanel tp : thumbnails) {
            addMouseListeners(tp, tp, tp.getTitleLabel(), tp.getCurrentLabel(), tp.getImagePanel().getGlassPane());
        }
    });
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) Mode(org.cytoscape.internal.view.GridViewToggleModel.Mode) CyNetwork(org.cytoscape.model.CyNetwork) ThumbnailPanel(org.cytoscape.internal.view.NetworkViewGrid.ThumbnailPanel) Collection(java.util.Collection) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) Component(java.awt.Component) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Aggregations

ThumbnailPanel (org.cytoscape.internal.view.NetworkViewGrid.ThumbnailPanel)2 CyNetworkView (org.cytoscape.view.model.CyNetworkView)2 Component (java.awt.Component)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 Mode (org.cytoscape.internal.view.GridViewToggleModel.Mode)1 CyNetwork (org.cytoscape.model.CyNetwork)1 DestroyNetworkViewTaskFactory (org.cytoscape.task.destroy.DestroyNetworkViewTaskFactory)1 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)1 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)1 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)1 DialogTaskManager (org.cytoscape.work.swing.DialogTaskManager)1