Search in sources :

Example 1 with CyDiscreteValuePropertyEditor

use of org.cytoscape.view.vizmap.gui.internal.view.editor.propertyeditor.CyDiscreteValuePropertyEditor in project cytoscape-impl by cytoscape.

the class EditorManagerImpl method buildDiscreteEditors.

@SuppressWarnings({ "unchecked", "rawtypes" })
private <V> void buildDiscreteEditors(final VisualLexicon lexicon) {
    final Set<VisualProperty> vps = (Set) lexicon.getAllVisualProperties();
    for (final VisualProperty<V> vp : vps) {
        final Range<?> range = vp.getRange();
        // If data type is basic (String, Boolean, etc.), custom editor is not necessary.
        final Class<?> targetDataType = range.getType();
        synchronized (mutex) {
            if (REGISTRY.getEditor(targetDataType) != null)
                continue;
            if (this.getVisualPropertyEditor(vp) != null)
                continue;
            if (range instanceof DiscreteRange<?>) {
                DiscreteValueEditor<?> valEditor = (DiscreteValueEditor) getVisualPropertyValueEditor(vp);
                if (valEditor == null) {
                    valEditor = new DiscreteValueEditor(range.getType(), ((DiscreteRange) range).values(), servicesUtil);
                    this.addVisualPropertyValueEditor(valEditor, null);
                }
                final CyDiscreteValuePropertyEditor<?> discretePropEditor = new CyDiscreteValuePropertyEditor(valEditor);
                final Set values = ((DiscreteRange) range).values();
                // FIXME how can we manage the custom icon size based on value type?
                Integer width = ICON_WIDTH_MAP.get(range.getType());
                if (width == null)
                    width = ICON_W;
                final ContinuousMappingCellRendererFactory cellRendererFactory = servicesUtil.get(ContinuousMappingCellRendererFactory.class);
                final VisualPropertyEditor<?> vpEditor = new DiscreteValueVisualPropertyEditor(range.getType(), discretePropEditor, cellRendererFactory, values, width, ICON_H);
                this.addVisualPropertyEditor(vpEditor, null);
                servicesUtil.registerService(vpEditor, SetCurrentRenderingEngineListener.class, new Properties());
            }
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Properties(java.util.Properties) ContinuousMappingCellRendererFactory(org.cytoscape.view.vizmap.gui.editor.ContinuousMappingCellRendererFactory) DiscreteValueEditor(org.cytoscape.view.vizmap.gui.internal.view.editor.valueeditor.DiscreteValueEditor) CyDiscreteValuePropertyEditor(org.cytoscape.view.vizmap.gui.internal.view.editor.propertyeditor.CyDiscreteValuePropertyEditor) VisualProperty(org.cytoscape.view.model.VisualProperty) DiscreteRange(org.cytoscape.view.model.DiscreteRange)

Aggregations

HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 Set (java.util.Set)1 DiscreteRange (org.cytoscape.view.model.DiscreteRange)1 VisualProperty (org.cytoscape.view.model.VisualProperty)1 ContinuousMappingCellRendererFactory (org.cytoscape.view.vizmap.gui.editor.ContinuousMappingCellRendererFactory)1 CyDiscreteValuePropertyEditor (org.cytoscape.view.vizmap.gui.internal.view.editor.propertyeditor.CyDiscreteValuePropertyEditor)1 DiscreteValueEditor (org.cytoscape.view.vizmap.gui.internal.view.editor.valueeditor.DiscreteValueEditor)1