Search in sources :

Example 1 with LockedValueState

use of org.cytoscape.view.vizmap.gui.internal.model.LockedValueState in project cytoscape-impl by cytoscape.

the class VisualPropertySheetItem method updateBypassButton.

public void updateBypassButton() {
    if (bypassBtn != null) {
        final LockedValueState state = model.getLockedValueState();
        bypassBtn.setEnabled(isEnabled() && state != LockedValueState.DISABLED);
        if (state == LockedValueState.ENABLED_MULTIPLE_VALUES) {
            final IconManager iconManager = servicesUtil.get(IconManager.class);
            bypassBtn.setForeground(LookAndFeelUtil.getInfoColor());
            bypassBtn.setFont(iconManager.getIconFont(19.0f));
            bypassBtn.setText(IconManager.ICON_QUESTION_CIRCLE);
        } else {
            bypassBtn.setForeground(getForegroundColor());
            bypassBtn.setFont(UIManager.getFont("Button.font"));
            bypassBtn.setText("");
        }
        bypassBtn.setIcon(getIcon(model.getLockedValue(), VALUE_ICON_WIDTH, VALUE_ICON_HEIGHT));
        final String elementsStr = model.getTargetDataType() == CyNode.class ? "nodes" : "edges";
        String toolTipText = "No bypass";
        if (state == LockedValueState.DISABLED)
            toolTipText = "To bypass the visual property, first select one or more " + elementsStr;
        else if (state == LockedValueState.ENABLED_UNIQUE_VALUE)
            toolTipText = "Bypass: " + VisualPropertyUtil.getDisplayString(model.getLockedValue());
        else if (state == LockedValueState.ENABLED_MULTIPLE_VALUES)
            toolTipText = "The selected " + elementsStr + " have different bypass values";
        bypassBtn.setToolTipText(toolTipText);
    }
}
Also used : LockedValueState(org.cytoscape.view.vizmap.gui.internal.model.LockedValueState) IconManager(org.cytoscape.util.swing.IconManager) CyNode(org.cytoscape.model.CyNode)

Example 2 with LockedValueState

use of org.cytoscape.view.vizmap.gui.internal.model.LockedValueState in project cytoscape-impl by cytoscape.

the class VizMapperMediator method updateVpInfoLockedState.

private <T, S extends CyIdentifiable> void updateVpInfoLockedState(final VisualPropertySheetItemModel<T> model, final Set<T> lockedValues, final Set<View<S>> selectedViews) {
    T value = null;
    LockedValueState state = LockedValueState.DISABLED;
    if (lockedValues.size() == 1) {
        value = lockedValues.iterator().next();
        state = value == null ? LockedValueState.ENABLED_NOT_SET : LockedValueState.ENABLED_UNIQUE_VALUE;
    } else if (lockedValues.size() > 1) {
        state = LockedValueState.ENABLED_MULTIPLE_VALUES;
    }
    model.setLockedValue(value);
    model.setLockedValueState(state);
}
Also used : LockedValueState(org.cytoscape.view.vizmap.gui.internal.model.LockedValueState) ViewUtil.invokeOnEDT(org.cytoscape.view.vizmap.gui.internal.util.ViewUtil.invokeOnEDT)

Example 3 with LockedValueState

use of org.cytoscape.view.vizmap.gui.internal.model.LockedValueState in project cytoscape-impl by cytoscape.

the class VizMapperMediator method addViewListeners.

private void addViewListeners(final VisualPropertySheet vpSheet, final VisualPropertySheetItem<?> vpSheetItem) {
    if (vpSheetItem.getModel().getVisualPropertyDependency() == null) {
        // It's a regular VisualProperty Editor...
        // Default value button clicked
        vpSheetItem.getDefaultBtn().addActionListener(evt -> {
            openDefaultValueEditor(evt, vpSheetItem);
        });
        // Default value button right-clicked
        vpSheetItem.getDefaultBtn().addMouseListener(new MouseAdapter() {

            @Override
            public void mousePressed(final MouseEvent e) {
                maybeShowContextMenu(e);
            }

            @Override
            public void mouseReleased(final MouseEvent e) {
                maybeShowContextMenu(e);
            }

            private void maybeShowContextMenu(final MouseEvent e) {
                if (e.isPopupTrigger()) {
                    final JPopupMenu contextMenu = new JPopupMenu();
                    contextMenu.add(new JMenuItem(new AbstractAction("Reset Default Value") {

                        @Override
                        public void actionPerformed(final ActionEvent e) {
                            vpSheetItem.getModel().resetDefaultValue();
                        }
                    }));
                    showContextMenu(contextMenu, e);
                }
            }
        });
        // Bypass button clicked
        if (vpSheetItem.getModel().isLockedValueAllowed()) {
            // Create context menu
            final JPopupMenu bypassMenu = new JPopupMenu();
            final JMenuItem removeBypassMenuItem;
            bypassMenu.add(new JMenuItem(new AbstractAction("Set Bypass...") {

                @Override
                public void actionPerformed(final ActionEvent e) {
                    openLockedValueEditor(e, vpSheetItem);
                }
            }));
            bypassMenu.add(removeBypassMenuItem = new JMenuItem(new AbstractAction("Remove Bypass") {

                @Override
                public void actionPerformed(final ActionEvent e) {
                    removeLockedValue(e, vpSheetItem);
                }
            }));
            // Right-clicked
            vpSheetItem.getBypassBtn().addMouseListener(new MouseAdapter() {

                @Override
                public void mousePressed(final MouseEvent e) {
                    maybeShowContextMenu(e);
                }

                @Override
                public void mouseReleased(final MouseEvent e) {
                    maybeShowContextMenu(e);
                }

                private void maybeShowContextMenu(final MouseEvent e) {
                    if (vpSheetItem.getBypassBtn().isEnabled() && e.isPopupTrigger()) {
                        final LockedValueState state = vpSheetItem.getModel().getLockedValueState();
                        removeBypassMenuItem.setEnabled(state != LockedValueState.ENABLED_NOT_SET);
                        showContextMenu(bypassMenu, e);
                    }
                }
            });
            // Left-clicked
            vpSheetItem.getBypassBtn().addActionListener(evt -> {
                final LockedValueState state = vpSheetItem.getModel().getLockedValueState();
                final JButton btn = vpSheetItem.getBypassBtn();
                if (state == LockedValueState.ENABLED_NOT_SET) {
                    // There is only one option to execute, so do it now, rather than showing the popup menu
                    openLockedValueEditor(evt, vpSheetItem);
                } else {
                    bypassMenu.show(btn, 0, btn.getHeight());
                    bypassMenu.requestFocusInWindow();
                }
            });
        }
        // Right-click
        final ContextMenuMouseListener cmMouseListener = new ContextMenuMouseListener(vpSheet, vpSheetItem);
        vpSheetItem.addMouseListener(cmMouseListener);
        if (vpSheetItem.getModel().isVisualMappingAllowed()) {
            vpSheetItem.getPropSheetPnl().getTable().addMouseListener(cmMouseListener);
            vpSheetItem.getRemoveMappingBtn().addActionListener(evt -> {
                removeVisualMapping(vpSheetItem);
            });
            vpSheetItem.getPropSheetTbl().addPropertyChangeListener("editingVizMapperProperty", evt -> {
                // Save the current editor (the one the user is interacting with)
                curVpSheetItem = vpSheetItem;
                curVizMapperProperty = (VizMapperProperty<?, ?, ?>) evt.getNewValue();
                final VizMapperProperty<String, VisualMappingFunctionFactory, VisualMappingFunction<?, ?>> mappingTypeProperty = vizMapPropertyBuilder.getMappingTypeProperty(vpSheetItem.getPropSheetPnl());
                final VisualMappingFunctionFactory factory = (VisualMappingFunctionFactory) mappingTypeProperty.getValue();
                attrProxy.setCurrentMappingType(factory != null ? factory.getMappingFunctionType() : null);
                final VizMapperProperty<VisualProperty<?>, String, VisualMappingFunctionFactory> columnProp = vizMapPropertyBuilder.getColumnProperty(vpSheetItem.getPropSheetPnl());
                final Object columnValue = columnProp.getValue();
                mappingFactoryProxy.setCurrentColumnName(columnValue != null ? columnValue.toString() : null);
                mappingFactoryProxy.setCurrentTargetDataType(vpSheet.getModel().getTargetDataType());
            });
        }
    } else {
        // It's a Dependency Editor...
        vpSheetItem.getDependencyCkb().addItemListener(evt -> {
            onDependencySelectionChanged(evt, vpSheetItem);
        });
    }
    // Save sheet items that were explicitly shown/hidden by the user,
    // so his preferences can be respected when the current style changes
    vpSheetItem.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentShown(final ComponentEvent e) {
            userProps.put(vpSheetItem.getModel().getId(), Boolean.TRUE);
        }

        @Override
        public void componentHidden(final ComponentEvent e) {
            userProps.put(vpSheetItem.getModel().getId(), Boolean.FALSE);
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) JButton(javax.swing.JButton) JPopupMenu(javax.swing.JPopupMenu) LockedValueState(org.cytoscape.view.vizmap.gui.internal.model.LockedValueState) DefaultVisualizableVisualProperty(org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty) VisualProperty(org.cytoscape.view.model.VisualProperty) ComponentEvent(java.awt.event.ComponentEvent) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) ComponentAdapter(java.awt.event.ComponentAdapter)

Aggregations

LockedValueState (org.cytoscape.view.vizmap.gui.internal.model.LockedValueState)3 ActionEvent (java.awt.event.ActionEvent)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 AbstractAction (javax.swing.AbstractAction)1 JButton (javax.swing.JButton)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 CyNode (org.cytoscape.model.CyNode)1 IconManager (org.cytoscape.util.swing.IconManager)1 VisualProperty (org.cytoscape.view.model.VisualProperty)1 DefaultVisualizableVisualProperty (org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty)1 VisualMappingFunction (org.cytoscape.view.vizmap.VisualMappingFunction)1 VisualMappingFunctionFactory (org.cytoscape.view.vizmap.VisualMappingFunctionFactory)1 ViewUtil.invokeOnEDT (org.cytoscape.view.vizmap.gui.internal.util.ViewUtil.invokeOnEDT)1