Search in sources :

Example 1 with VisualPropertyDependency

use of org.cytoscape.view.vizmap.VisualPropertyDependency in project cytoscape-impl by cytoscape.

the class VizMapperMediator method updateVisualPropertySheets.

@SuppressWarnings("rawtypes")
private void updateVisualPropertySheets(final VisualStyle vs, final boolean resetDefaultVisibleItems) {
    if (vs == null)
        return;
    final VisualPropertySheet curNetSheet = vizMapperMainPanel.getVisualPropertySheet(CyNetwork.class);
    final VisualPropertySheetModel curModel = curNetSheet != null ? curNetSheet.getModel() : null;
    final VisualStyle curStyle = curModel != null ? curModel.getVisualStyle() : null;
    final CyNetworkView curNetView = vmProxy.getCurrentNetworkView();
    final String newRendererId = curNetView != null ? curNetView.getRendererId() : "";
    // If a different style or renderer, rebuild all property sheets
    boolean rebuild = !vs.equals(curStyle) || !newRendererId.equals(curRendererId);
    if (curNetView != null)
        curRendererId = curNetView.getRendererId();
    if (!rebuild) {
        // Also check if dependencies have changed
        final Map<String, VisualPropertyDependency<?>> map = new HashMap<>();
        final Set<VisualPropertyDependency<?>> dependencies = vs.getAllVisualPropertyDependencies();
        for (final VisualPropertyDependency<?> dep : dependencies) {
            final Class<? extends CyIdentifiable> type = dep.getParentVisualProperty().getTargetDataType();
            final VisualPropertySheet sheet = vizMapperMainPanel.getVisualPropertySheet(type);
            if (sheet.getItem(dep) == null) {
                // There's a new dependency!
                rebuild = true;
                break;
            }
            map.put(dep.getIdString(), dep);
        }
        if (!rebuild) {
            final Set<VisualPropertySheet> vpSheets = vizMapperMainPanel.getVisualPropertySheets();
            for (final VisualPropertySheet sheet : vpSheets) {
                for (final VisualPropertySheetItem<?> item : sheet.getItems()) {
                    final VisualPropertyDependency<?> dep = item.getModel().getVisualPropertyDependency();
                    if (dep != null && !map.containsKey(dep.getIdString())) {
                        // This dependency has been removed from the Visual Style!
                        rebuild = true;
                        break;
                    }
                }
            }
        }
    }
    if (rebuild) {
        createVisualPropertySheets(resetDefaultVisibleItems);
    } else {
        // Just update the current Visual Property sheets
        final Set<VisualPropertySheet> vpSheets = vizMapperMainPanel.getVisualPropertySheets();
        for (final VisualPropertySheet sheet : vpSheets) {
            for (final VisualPropertySheetItem<?> item : sheet.getItems()) {
                // Update values
                final VisualPropertySheetItemModel model = item.getModel();
                model.update(vizMapperMainPanel.getRenderingEngine());
                if (model.getVisualPropertyDependency() != null)
                    item.update();
                // Also make sure items with mappings are visible
                if (model.getVisualMappingFunction() != null)
                    item.setVisible(true);
            }
        }
        if (resetDefaultVisibleItems)
            updateVisibleItems(resetDefaultVisibleItems);
    }
}
Also used : HashMap(java.util.HashMap) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 2 with VisualPropertyDependency

use of org.cytoscape.view.vizmap.VisualPropertyDependency in project cytoscape-impl by cytoscape.

the class VisualPropertySheet method createMenuItems.

private void createMenuItems() {
    final JPopupMenu rootMenu = getVpsMenu();
    // Remove previous menu items
    menuItemMap.clear();
    final int length = rootMenu.getSubElements() != null ? rootMenu.getSubElements().length : 0;
    for (int i = 0; i < length; i++) rootMenu.remove(i);
    // Add new menu items
    final VisualLexicon lexicon = model.getVisualLexicon();
    final VisualProperty<?> rootVp = model.getRootVisualProperty();
    final VisualLexiconNode rootNode = lexicon.getVisualLexiconNode(rootVp);
    // Menu Items for showing/hiding each VP Sheet Item
    // ------------------------------------------------
    // -- Visual Properties --
    final Queue<VisualLexiconNode> queue = new PriorityQueue<>(50, new Comparator<VisualLexiconNode>() {

        @Override
        public int compare(final VisualLexiconNode n1, final VisualLexiconNode n2) {
            final Collator collator = Collator.getInstance(Locale.getDefault());
            collator.setStrength(Collator.PRIMARY);
            return collator.compare(VisualPropertySheetItemModel.createTitle(n1.getVisualProperty()), VisualPropertySheetItemModel.createTitle(n2.getVisualProperty()));
        }
    });
    queue.addAll(rootNode.getChildren());
    final Map<VisualLexiconNode, JComponent> menuMap = new HashMap<>();
    menuMap.put(rootNode, rootMenu);
    final VisualStyle style = model.getVisualStyle();
    final Set<VisualProperty<?>> disabledProps = new HashSet<>();
    // final Set<VisualPropertyDependency<?>> depSet = style.getAllVisualPropertyDependencies();
    // for (final VisualPropertyDependency<?> dep : depSet) {
    // // To do the same as in Cytoscape v2.8, we only care about these dependencies
    // if (!dep.getIdString().equals("arrowColorMatchesEdge") && !dep.getIdString().equals("nodeSizeLocked"))
    // continue; // TODO: revisit these requirements and remove this workaround.
    // In general, the user should not be able to lock the child properties of an enabled dependency.
    // if (dep.isDependencyEnabled())
    // disabledProps.addAll(dep.getVisualProperties());
    // else
    // disabledProps.add(dep.getParentVisualProperty());
    // }
    final Set<VisualLexiconNode> nextNodes = new HashSet<>();
    while (!queue.isEmpty()) {
        final VisualLexiconNode curNode = queue.poll();
        final VisualProperty<?> vp = curNode.getVisualProperty();
        if (vp.getTargetDataType() == model.getTargetDataType()) {
            final Collection<VisualLexiconNode> children = curNode.getChildren();
            nextNodes.addAll(children);
            if (PropertySheetUtil.isCompatible(vp)) {
                VisualLexiconNode parentNode = curNode.getParent();
                boolean leaf = children.isEmpty();
                final VisualPropertySheetItem<?> vpSheetItem = getItem(vp);
                final String label = vpSheetItem != null ? vpSheetItem.getModel().getTitle() : VisualPropertySheetItemModel.createTitle(vp);
                if (!leaf) {
                    // Non-leaf visual property...
                    final JMenuItem nonLeafMenu = new JMenu(label);
                    menuMap.put(curNode, nonLeafMenu);
                    menuMap.get(parentNode).add(nonLeafMenu);
                    // So this VP can also be added as a child of itself
                    parentNode = curNode;
                }
                if (vpSheetItem != null) {
                    final JCheckBoxMenuItem mi = new JCheckBoxMenuItem(label, vpSheetItem.isVisible());
                    mi.addActionListener(evt -> {
                        // Show/hide the Visual Property Sheet Item
                        setVisible(vpSheetItem, !vpSheetItem.isVisible());
                    });
                    menuMap.get(parentNode).add(mi);
                    menuItemMap.put(vpSheetItem, mi);
                    if (parentNode == curNode)
                        menuMap.get(parentNode).add(new JSeparator());
                    // Should this visual property be disabled?
                    if (disabledProps.contains(vp))
                        mi.setEnabled(false);
                }
            }
        }
        queue.addAll(nextNodes);
        nextNodes.clear();
    }
    // -- Visual Property Dependencies --
    final TreeSet<VisualPropertyDependency<?>> depTreeSet = new TreeSet<>((VisualPropertyDependency<?> d1, VisualPropertyDependency<?> d2) -> {
        final Collator collator = Collator.getInstance(Locale.getDefault());
        collator.setStrength(Collator.PRIMARY);
        return collator.compare(d1.getDisplayName(), d2.getDisplayName());
    });
    depTreeSet.addAll(style.getAllVisualPropertyDependencies());
    for (final VisualPropertyDependency<?> dep : depTreeSet) {
        final VisualPropertySheetItem<?> vpSheetItem = getItem(dep);
        if (vpSheetItem != null) {
            final JCheckBoxMenuItem mi = new JCheckBoxMenuItem(dep.getDisplayName(), vpSheetItem.isVisible());
            mi.addActionListener(evt -> {
                // Show/hide the Visual Property Sheet Item
                setVisible(vpSheetItem, !vpSheetItem.isVisible());
            });
            final VisualLexiconNode parentNode = lexicon.getVisualLexiconNode(dep.getParentVisualProperty());
            JComponent parentMenu = menuMap.get(parentNode);
            if (// just add it directly to the popup menu
            parentMenu == null)
                parentMenu = rootMenu;
            parentMenu.add(mi);
            menuItemMap.put(vpSheetItem, mi);
        }
    }
    // ------------------------------------------------
    if (menuMap.size() > 1) {
        rootMenu.add(new JSeparator());
        {
            final JMenuItem mi = new JMenuItem("Show All");
            mi.addActionListener(evt -> {
                for (Entry<VisualPropertySheetItem<?>, JCheckBoxMenuItem> entry : menuItemMap.entrySet()) setVisible(entry.getKey(), true);
            });
            rootMenu.add(mi);
        }
        {
            final JMenuItem mi = new JMenuItem("Hide All");
            mi.addActionListener(evt -> {
                for (Entry<VisualPropertySheetItem<?>, JCheckBoxMenuItem> entry : menuItemMap.entrySet()) setVisible(entry.getKey(), false);
            });
            rootMenu.add(mi);
        }
        getVpsBtn().setEnabled(true);
    } else {
        getVpsBtn().setEnabled(false);
    }
}
Also used : SortedSet(java.util.SortedSet) PriorityQueue(java.util.PriorityQueue) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) IconManager(org.cytoscape.util.swing.IconManager) Locale(java.util.Locale) CyNetwork(org.cytoscape.model.CyNetwork) Map(java.util.Map) MouseAdapter(java.awt.event.MouseAdapter) Font(java.awt.Font) Collection(java.util.Collection) Set(java.util.Set) JMenu(javax.swing.JMenu) VisualLexicon(org.cytoscape.view.model.VisualLexicon) NavigableSet(java.util.NavigableSet) BorderFactory(javax.swing.BorderFactory) GridBagConstraints(java.awt.GridBagConstraints) ComponentEvent(java.awt.event.ComponentEvent) Box(javax.swing.Box) Dimension(java.awt.Dimension) PopupMenuEvent(javax.swing.event.PopupMenuEvent) LookAndFeelUtil(org.cytoscape.util.swing.LookAndFeelUtil) JSeparator(javax.swing.JSeparator) Entry(java.util.Map.Entry) Queue(java.util.Queue) GridBagLayout(java.awt.GridBagLayout) JPanel(javax.swing.JPanel) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) SwingUtilities(javax.swing.SwingUtilities) VisualLexiconNode(org.cytoscape.view.model.VisualLexiconNode) JMenuItem(javax.swing.JMenuItem) Collator(java.text.Collator) BoxLayout(javax.swing.BoxLayout) VisualProperty(org.cytoscape.view.model.VisualProperty) JComponent(javax.swing.JComponent) LookAndFeelUtil.isAquaLAF(org.cytoscape.util.swing.LookAndFeelUtil.isAquaLAF) JButton(javax.swing.JButton) Iterator(java.util.Iterator) JPopupMenu(javax.swing.JPopupMenu) PopupMenuListener(javax.swing.event.PopupMenuListener) MouseEvent(java.awt.event.MouseEvent) ComponentAdapter(java.awt.event.ComponentAdapter) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) ServicesUtil(org.cytoscape.view.vizmap.gui.internal.util.ServicesUtil) GroupLayout(javax.swing.GroupLayout) PropertySheetUtil(org.cytoscape.view.vizmap.gui.util.PropertySheetUtil) Comparator(java.util.Comparator) Collections(java.util.Collections) VisualLexicon(org.cytoscape.view.model.VisualLexicon) HashMap(java.util.HashMap) JSeparator(javax.swing.JSeparator) Collator(java.text.Collator) Entry(java.util.Map.Entry) TreeSet(java.util.TreeSet) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) JMenuItem(javax.swing.JMenuItem) HashSet(java.util.HashSet) VisualLexiconNode(org.cytoscape.view.model.VisualLexiconNode) JComponent(javax.swing.JComponent) PriorityQueue(java.util.PriorityQueue) JPopupMenu(javax.swing.JPopupMenu) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) VisualProperty(org.cytoscape.view.model.VisualProperty) JMenu(javax.swing.JMenu)

Example 3 with VisualPropertyDependency

use of org.cytoscape.view.vizmap.VisualPropertyDependency in project cytoscape-impl by cytoscape.

the class VisualStyleFactoryImpl method copyDependencies.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void copyDependencies(final VisualStyle original, final VisualStyle copy) {
    final Set<VisualPropertyDependency<?>> allDep1 = original.getAllVisualPropertyDependencies();
    final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
    final VisualLexicon lexicon = appMgr.getCurrentNetworkViewRenderer().getRenderingEngineFactory(NetworkViewRenderer.DEFAULT_CONTEXT).getVisualLexicon();
    final Set<VisualPropertyDependency<?>> allDep2 = copy.getAllVisualPropertyDependencies();
    final Map<String, VisualPropertyDependency<?>> depMap = new HashMap<>();
    for (VisualPropertyDependency<?> dep : allDep2) depMap.put(dep.getIdString(), dep);
    for (VisualPropertyDependency<?> dep1 : allDep1) {
        try {
            VisualPropertyDependency<?> dep2 = depMap.get(dep1.getIdString());
            if (dep2 == null) {
                // Just in case the new Style does not have this dependency...
                dep2 = new VisualPropertyDependency(dep1.getIdString(), dep1.getDisplayName(), dep1.getVisualProperties(), lexicon);
                dep2.setDependency(dep1.isDependencyEnabled());
                copy.addVisualPropertyDependency(dep2);
            } else {
                // The new Style probably has the same dependency already;
                // in this case, just update the enabled state.
                dep2.setDependency(dep1.isDependencyEnabled());
            }
        } catch (Exception e) {
            logger.warn("Cannot copy VisualPropertyDependency " + dep1.getIdString(), e);
        }
    }
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) VisualLexicon(org.cytoscape.view.model.VisualLexicon) HashMap(java.util.HashMap) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency)

Example 4 with VisualPropertyDependency

use of org.cytoscape.view.vizmap.VisualPropertyDependency in project cytoscape-impl by cytoscape.

the class VisualStyleSerializer method restoreDependencies.

private void restoreDependencies(final VisualStyle visualStyle, org.cytoscape.io.internal.util.vizmap.model.VisualStyle vsModel) {
    final Node nodeSection = vsModel.getNode();
    final Edge edgeSection = vsModel.getEdge();
    final Network networkSection = vsModel.getNetwork();
    final Set<Dependency> dependencyStates = new HashSet<>();
    if (nodeSection != null)
        dependencyStates.addAll(nodeSection.getDependency());
    if (edgeSection != null)
        dependencyStates.addAll(edgeSection.getDependency());
    if (networkSection != null)
        dependencyStates.addAll(networkSection.getDependency());
    final Set<VisualPropertyDependency<?>> availableDependencies = visualStyle.getAllVisualPropertyDependencies();
    for (final Dependency dep : dependencyStates) {
        final String depName = dep.getName();
        final Boolean enabled = dep.isValue();
        for (final VisualPropertyDependency<?> vsDependency : availableDependencies) {
            if (vsDependency.getIdString().equalsIgnoreCase(depName))
                vsDependency.setDependency(enabled);
        }
    }
}
Also used : CyNode(org.cytoscape.model.CyNode) Node(org.cytoscape.io.internal.util.vizmap.model.Node) CyNetwork(org.cytoscape.model.CyNetwork) Network(org.cytoscape.io.internal.util.vizmap.model.Network) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) Dependency(org.cytoscape.io.internal.util.vizmap.model.Dependency) Edge(org.cytoscape.io.internal.util.vizmap.model.Edge) CyEdge(org.cytoscape.model.CyEdge) HashSet(java.util.HashSet)

Example 5 with VisualPropertyDependency

use of org.cytoscape.view.vizmap.VisualPropertyDependency in project cytoscape-impl by cytoscape.

the class VisualStyleSerializer method createDependencies.

private void createDependencies(final VisualStyle visualStyle, org.cytoscape.io.internal.util.vizmap.model.VisualStyle vsModel) {
    // Create serializable Dependency
    final Set<VisualPropertyDependency<?>> dependencies = visualStyle.getAllVisualPropertyDependencies();
    final List<Dependency> nodeDep = vsModel.getNode().getDependency();
    final List<Dependency> edgeDep = vsModel.getEdge().getDependency();
    final List<Dependency> networkDep = vsModel.getNetwork().getDependency();
    Collection<VisualProperty<?>> nodeVisualProperties = lexicon.getAllDescendants(BasicVisualLexicon.NODE);
    Collection<VisualProperty<?>> edgeVisualProperties = lexicon.getAllDescendants(BasicVisualLexicon.EDGE);
    for (VisualPropertyDependency<?> vpDep : dependencies) {
        try {
            final Dependency newDependency = new Dependency();
            newDependency.setName(vpDep.getIdString());
            newDependency.setValue(vpDep.isDependencyEnabled());
            final VisualProperty<?> parent = vpDep.getParentVisualProperty();
            if (nodeVisualProperties.contains(parent))
                nodeDep.add(newDependency);
            else if (edgeVisualProperties.contains(parent))
                edgeDep.add(newDependency);
            else
                networkDep.add(newDependency);
        } catch (final Exception e) {
            logger.error("Cannot save dependency: " + (vpDep != null ? vpDep.getDisplayName() : ""), e);
        }
    }
}
Also used : VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) VisualProperty(org.cytoscape.view.model.VisualProperty) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) Dependency(org.cytoscape.io.internal.util.vizmap.model.Dependency)

Aggregations

VisualPropertyDependency (org.cytoscape.view.vizmap.VisualPropertyDependency)11 HashSet (java.util.HashSet)5 VisualProperty (org.cytoscape.view.model.VisualProperty)5 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)4 Paint (java.awt.Paint)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 CyNetwork (org.cytoscape.model.CyNetwork)3 VisualLexicon (org.cytoscape.view.model.VisualLexicon)3 TexturePaint (java.awt.TexturePaint)2 Set (java.util.Set)2 SortedSet (java.util.SortedSet)2 Dependency (org.cytoscape.io.internal.util.vizmap.model.Dependency)2 CyEdge (org.cytoscape.model.CyEdge)2 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 Font (java.awt.Font)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 ComponentAdapter (java.awt.event.ComponentAdapter)1