Search in sources :

Example 16 with VisualStyle

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

the class GenerateDiscreteValuesAction method generateValues.

// ==[ PRIVATE METHODS ]============================================================================================
@SuppressWarnings({ "rawtypes", "unchecked" })
private void generateValues(final VisualPropertySheetItem<?> vpsItem, final String attrName, final VisualProperty<?> vp, final Map<DiscreteMapping<?, ?>, Map<Object, Object>> previousMappingValues, final Map<DiscreteMapping<?, ?>, Map<Object, ?>> newMappingValues) {
    final VisualStyle style = servicesUtil.get(VisualMappingManager.class).getCurrentVisualStyle();
    final VisualMappingFunction<?, ?> mapping = style.getVisualMappingFunction(vp);
    if (!(mapping instanceof DiscreteMapping))
        return;
    final DiscreteMapping<Object, Object> dm = (DiscreteMapping) mapping;
    final PropertySheetPanel propSheetPnl = vpsItem.getPropSheetPnl();
    final SortedSet<Object> keySet = new TreeSet<Object>();
    final Map<Object, Object> previousValues = new HashMap<Object, Object>();
    for (final Property p : propSheetPnl.getProperties()) {
        final VizMapperProperty<?, ?, ?> vmp = (VizMapperProperty<?, ?, ?>) p;
        if (vmp.getCellType().equals(CellType.DISCRETE)) {
            keySet.add(vmp.getKey());
            // Save the current value for undo
            previousValues.put(vmp.getKey(), vmp.getValue());
        }
    }
    if (!keySet.isEmpty()) {
        // Generate values
        final Map<Object, ?> newValues = generator.generateMap(keySet);
        // Save the mapping->old_values for undo
        previousMappingValues.put(dm, previousValues);
        // Save the mapping->new_values for redo
        newMappingValues.put(dm, newValues);
        // Update the visual mapping
        dm.putAll(newValues);
    }
}
Also used : PropertySheetPanel(com.l2fprod.common.propertysheet.PropertySheetPanel) HashMap(java.util.HashMap) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) TreeSet(java.util.TreeSet) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) Property(com.l2fprod.common.propertysheet.Property) VisualProperty(org.cytoscape.view.model.VisualProperty)

Example 17 with VisualStyle

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

the class VizMapperMediator method createVisualPropertySheets.

private void createVisualPropertySheets(final boolean resetDefaultVisibleItems) {
    final VisualStyle style = vmProxy.getCurrentVisualStyle();
    final VisualLexicon lexicon = vmProxy.getCurrentVisualLexicon();
    invokeOnEDT(() -> {
        final VisualPropertySheet selVpSheet = getSelectedVisualPropertySheet();
        final Class<? extends CyIdentifiable> selectedTargetDataType = selVpSheet != null ? selVpSheet.getModel().getTargetDataType() : null;
        for (final Class<? extends CyIdentifiable> type : SHEET_TYPES) {
            // Create Visual Property Sheet
            final VisualPropertySheetModel model = new VisualPropertySheetModel(type, style, lexicon);
            final VisualPropertySheet vpSheet = new VisualPropertySheet(model, servicesUtil);
            vizMapperMainPanel.addVisualPropertySheet(vpSheet);
            // Create Visual Property Sheet Items
            final Set<VisualPropertySheetItem<?>> vpSheetItems = createVisualPropertySheetItems(vpSheet.getModel().getTargetDataType(), lexicon, style);
            vpSheet.setItems(vpSheetItems);
            // Add event listeners to the new components
            addViewListeners(vpSheet);
            // Add another menu item to the Properties menu
            vpSheet.getVpsMenu().add(new JSeparator());
            final JMenuItem mi = new JMenuItem("Make Default");
            mi.addActionListener(evt -> saveDefaultVisibleItems(vpSheet));
            vpSheet.getVpsMenu().add(mi);
        }
        updateVisibleItems(resetDefaultVisibleItems);
        updateItemsStatus();
        // Update panel's width
        int minWidth = 200;
        for (final VisualPropertySheet vpSheet : vizMapperMainPanel.getVisualPropertySheets()) {
            minWidth = Math.max(minWidth, vpSheet.getMinimumSize().width);
        }
        vizMapperMainPanel.setPreferredSize(new Dimension(vizMapperMainPanel.getPropertiesPn().getMinimumSize().width + 20, vizMapperMainPanel.getPreferredSize().height));
        // Select the same sheet that was selected before
        final VisualPropertySheet vpSheet = vizMapperMainPanel.getVisualPropertySheet(selectedTargetDataType);
        vizMapperMainPanel.setSelectedVisualPropertySheet(vpSheet);
    });
}
Also used : BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualLexicon(org.cytoscape.view.model.VisualLexicon) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) Dimension(java.awt.Dimension) JMenuItem(javax.swing.JMenuItem) JSeparator(javax.swing.JSeparator)

Example 18 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle 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 19 with VisualStyle

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

the class VizMapperMediator method updateVisualStyleList.

private void updateVisualStyleList(final SortedSet<VisualStyle> styles, final boolean resetDefaultVisibleItems) {
    attrProxy.setCurrentMappingType(null);
    mappingFactoryProxy.setCurrentColumnName(null);
    final RenderingEngineFactory<CyNetwork> engineFactory = vmProxy.getRenderingEngineFactory(previewNetView);
    invokeOnEDT(() -> {
        ignoreVisualStyleSelectedEvents = true;
        vizMapperMainPanel.updateVisualStyles(styles, previewNetView, engineFactory);
        final VisualStyle vs = vmProxy.getCurrentVisualStyle();
        selectCurrentVisualStyle(vs);
        updateVisualPropertySheets(vs, resetDefaultVisibleItems);
        ignoreVisualStyleSelectedEvents = false;
    });
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) VisualStyle(org.cytoscape.view.vizmap.VisualStyle)

Example 20 with VisualStyle

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

the class VizMapperMediator method selectCurrentVisualStyle.

private void selectCurrentVisualStyle(final VisualStyle vs) {
    invokeOnEDT(() -> {
        final VisualStyle selectedVs = vizMapperMainPanel.getSelectedVisualStyle();
        // Switching styles.  Need to reset the range tracer
        ContinuousMappingEditorPanel.setTracer(new EditorValueRangeTracer(servicesUtil));
        if (vs != null && !vs.equals(selectedVs))
            vizMapperMainPanel.setSelectedVisualStyle(vs);
    });
}
Also used : VisualStyle(org.cytoscape.view.vizmap.VisualStyle) EditorValueRangeTracer(org.cytoscape.view.vizmap.gui.internal.view.editor.mappingeditor.EditorValueRangeTracer)

Aggregations

VisualStyle (org.cytoscape.view.vizmap.VisualStyle)100 CyNetworkView (org.cytoscape.view.model.CyNetworkView)42 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)37 CyNetwork (org.cytoscape.model.CyNetwork)35 CyNode (org.cytoscape.model.CyNode)30 CyEdge (org.cytoscape.model.CyEdge)24 CyEventHelper (org.cytoscape.event.CyEventHelper)14 HashSet (java.util.HashSet)13 VisualProperty (org.cytoscape.view.model.VisualProperty)12 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)12 Paint (java.awt.Paint)11 HashMap (java.util.HashMap)11 CyApplicationManager (org.cytoscape.application.CyApplicationManager)11 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)11 Color (java.awt.Color)10 ArrayList (java.util.ArrayList)10 RenderingEngineManager (org.cytoscape.view.presentation.RenderingEngineManager)9 BasicVisualLexicon (org.cytoscape.view.presentation.property.BasicVisualLexicon)9 ContinuousMapping (org.cytoscape.view.vizmap.mappings.ContinuousMapping)9 View (org.cytoscape.view.model.View)8