Search in sources :

Example 1 with HandleFactory

use of org.cytoscape.view.presentation.property.values.HandleFactory in project cytoscape-impl by cytoscape.

the class CyActivator method startPresentationImpl.

private void startPresentationImpl(final BundleContext bc, final CyServiceRegistrar serviceRegistrar) {
    DVisualLexicon dVisualLexicon = new DVisualLexicon(cgManager);
    NVLTFActionSupport nvltfActionSupport = new NVLTFActionSupport(serviceRegistrar);
    ViewTaskFactoryListener vtfListener = new ViewTaskFactoryListener(nvltfActionSupport);
    AnnotationFactoryManager annotationFactoryManager = new AnnotationFactoryManager();
    AnnotationManager annotationManager = new AnnotationManagerImpl(serviceRegistrar);
    DingGraphLOD dingGraphLOD = new DingGraphLOD(serviceRegistrar);
    registerService(bc, dingGraphLOD, PropertyUpdatedListener.class, new Properties());
    DingGraphLODAll dingGraphLODAll = new DingGraphLODAll();
    HandleFactory handleFactory = new HandleFactoryImpl();
    registerService(bc, handleFactory, HandleFactory.class, new Properties());
    DingRenderingEngineFactory dingRenderingEngineFactory = new DingRenderingEngineFactory(dVisualLexicon, vtfListener, annotationFactoryManager, dingGraphLOD, handleFactory, serviceRegistrar);
    DingNavigationRenderingEngineFactory dingNavigationRenderingEngineFactory = new DingNavigationRenderingEngineFactory(serviceRegistrar, dVisualLexicon);
    DingRenderingEngineFactory dingVisualStyleRenderingEngineFactory = new DingVisualStyleRenderingEngineFactory(dVisualLexicon, vtfListener, annotationFactoryManager, dingGraphLOD, handleFactory, serviceRegistrar);
    DingThumbnailRenderingEngineFactory dingThumbnailRenderingEngineFactory = new DingThumbnailRenderingEngineFactory(dVisualLexicon, serviceRegistrar);
    AddEdgeNodeViewTaskFactoryImpl addEdgeNodeViewTaskFactory = new AddEdgeNodeViewTaskFactoryImpl(serviceRegistrar);
    ContinuousMappingCellRendererFactory continuousMappingCellRendererFactory = getService(bc, ContinuousMappingCellRendererFactory.class);
    // Object Position Editor
    ObjectPositionValueEditor objectPositionValueEditor = new ObjectPositionValueEditor();
    ObjectPositionEditor objectPositionEditor = new ObjectPositionEditor(objectPositionValueEditor, continuousMappingCellRendererFactory, serviceRegistrar);
    DingViewModelFactory dingNetworkViewFactory = new DingViewModelFactory(dVisualLexicon, vtfListener, annotationFactoryManager, dingGraphLOD, handleFactory, serviceRegistrar);
    DingRenderer renderer = DingRenderer.getInstance();
    renderer.registerNetworkViewFactory(dingNetworkViewFactory);
    renderer.registerRenderingEngineFactory(NetworkViewRenderer.DEFAULT_CONTEXT, dingRenderingEngineFactory);
    renderer.registerRenderingEngineFactory(NetworkViewRenderer.BIRDS_EYE_CONTEXT, dingNavigationRenderingEngineFactory);
    renderer.registerRenderingEngineFactory(NetworkViewRenderer.VISUAL_STYLE_PREVIEW_CONTEXT, dingVisualStyleRenderingEngineFactory);
    renderer.registerRenderingEngineFactory(NetworkViewRenderer.THUMBNAIL_CONTEXT, dingThumbnailRenderingEngineFactory);
    registerService(bc, renderer, NetworkViewRenderer.class, new Properties());
    // Edge Bend editor
    EdgeBendValueEditor edgeBendValueEditor = new EdgeBendValueEditor(dingNetworkViewFactory, dingRenderingEngineFactory, serviceRegistrar);
    EdgeBendEditor edgeBendEditor = new EdgeBendEditor(edgeBendValueEditor, continuousMappingCellRendererFactory, serviceRegistrar);
    Properties dingRenderingEngineFactoryProps = new Properties();
    dingRenderingEngineFactoryProps.setProperty(ID, "ding");
    registerAllServices(bc, dingRenderingEngineFactory, dingRenderingEngineFactoryProps);
    Properties dingNavigationRenderingEngineFactoryProps = new Properties();
    dingNavigationRenderingEngineFactoryProps.setProperty(ID, "dingNavigation");
    registerAllServices(bc, dingNavigationRenderingEngineFactory, dingNavigationRenderingEngineFactoryProps);
    Properties addEdgeNodeViewTaskFactoryProps = new Properties();
    addEdgeNodeViewTaskFactoryProps.setProperty(PREFERRED_ACTION, "Edge");
    addEdgeNodeViewTaskFactoryProps.setProperty(PREFERRED_MENU, NODE_ADD_MENU);
    addEdgeNodeViewTaskFactoryProps.setProperty(TITLE, "Edge");
    addEdgeNodeViewTaskFactoryProps.setProperty(MENU_GRAVITY, "0.1");
    registerService(bc, addEdgeNodeViewTaskFactory, NodeViewTaskFactory.class, addEdgeNodeViewTaskFactoryProps);
    Properties dVisualLexiconProps = new Properties();
    dVisualLexiconProps.setProperty(ID, "ding");
    registerService(bc, dVisualLexicon, VisualLexicon.class, dVisualLexiconProps);
    final Properties positionEditorProp = new Properties();
    positionEditorProp.setProperty(ID, "objectPositionValueEditor");
    registerService(bc, objectPositionValueEditor, ValueEditor.class, positionEditorProp);
    final Properties objectPositionEditorProp = new Properties();
    objectPositionEditorProp.setProperty(ID, "objectPositionEditor");
    registerService(bc, objectPositionEditor, VisualPropertyEditor.class, objectPositionEditorProp);
    registerAllServices(bc, edgeBendValueEditor, new Properties());
    registerService(bc, edgeBendEditor, VisualPropertyEditor.class, new Properties());
    Properties dingNetworkViewFactoryServiceProps = new Properties();
    registerService(bc, dingNetworkViewFactory, CyNetworkViewFactory.class, dingNetworkViewFactoryServiceProps);
    // Annotations
    registerServiceListener(bc, annotationFactoryManager::addAnnotationFactory, annotationFactoryManager::removeAnnotationFactory, AnnotationFactory.class);
    registerService(bc, annotationManager, AnnotationManager.class, new Properties());
    // Arrow
    AnnotationFactory<?> arrowAnnotationFactory = new ArrowAnnotationFactory(serviceRegistrar);
    Properties arrowFactory = new Properties();
    arrowFactory.setProperty("type", "ArrowAnnotation.class");
    registerService(bc, arrowAnnotationFactory, AnnotationFactory.class, arrowFactory);
    AddArrowTaskFactory addArrowTaskFactory = new AddArrowTaskFactory(arrowAnnotationFactory);
    Properties addArrowTaskFactoryProps = new Properties();
    addArrowTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    addArrowTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_ADD_MENU);
    addArrowTaskFactoryProps.setProperty(MENU_GRAVITY, "1.2");
    addArrowTaskFactoryProps.setProperty(TITLE, "Arrow Annotation");
    registerService(bc, addArrowTaskFactory, NetworkViewLocationTaskFactory.class, addArrowTaskFactoryProps);
    // Image annotation
    AnnotationFactory<?> imageAnnotationFactory = new ImageAnnotationFactory(serviceRegistrar);
    Properties imageFactory = new Properties();
    imageFactory.setProperty("type", "ImageAnnotation.class");
    registerService(bc, imageAnnotationFactory, AnnotationFactory.class, imageFactory);
    AddAnnotationTaskFactory addImageTaskFactory = new AddAnnotationTaskFactory(imageAnnotationFactory);
    Properties addImageTaskFactoryProps = new Properties();
    addImageTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    addImageTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_ADD_MENU);
    addImageTaskFactoryProps.setProperty(MENU_GRAVITY, "1.3");
    addImageTaskFactoryProps.setProperty(TITLE, "Image Annotation");
    registerService(bc, addImageTaskFactory, NetworkViewLocationTaskFactory.class, addImageTaskFactoryProps);
    // Shape annotation
    AnnotationFactory<?> shapeAnnotationFactory = new ShapeAnnotationFactory(serviceRegistrar);
    Properties shapeFactory = new Properties();
    shapeFactory.setProperty("type", "ShapeAnnotation.class");
    registerService(bc, shapeAnnotationFactory, AnnotationFactory.class, shapeFactory);
    AddAnnotationTaskFactory addShapeTaskFactory = new AddAnnotationTaskFactory(shapeAnnotationFactory);
    Properties addShapeTaskFactoryProps = new Properties();
    addShapeTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    addShapeTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_ADD_MENU);
    addShapeTaskFactoryProps.setProperty(MENU_GRAVITY, "1.4");
    addShapeTaskFactoryProps.setProperty(TITLE, "Shape Annotation");
    registerService(bc, addShapeTaskFactory, NetworkViewLocationTaskFactory.class, addShapeTaskFactoryProps);
    // Text annotation
    AnnotationFactory<?> textAnnotationFactory = new TextAnnotationFactory(serviceRegistrar);
    Properties textFactory = new Properties();
    textFactory.setProperty("type", "TextAnnotation.class");
    registerService(bc, textAnnotationFactory, AnnotationFactory.class, textFactory);
    AddAnnotationTaskFactory addTextTaskFactory = new AddAnnotationTaskFactory(textAnnotationFactory);
    Properties addTextTaskFactoryProps = new Properties();
    addTextTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    addTextTaskFactoryProps.setProperty(MENU_GRAVITY, "1.5");
    addTextTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_ADD_MENU);
    addTextTaskFactoryProps.setProperty(TITLE, "Text Annotation");
    registerService(bc, addTextTaskFactory, NetworkViewLocationTaskFactory.class, addTextTaskFactoryProps);
    // Bounded Text annotation
    AnnotationFactory<?> boundedAnnotationFactory = new BoundedTextAnnotationFactory(serviceRegistrar);
    Properties boundedFactory = new Properties();
    boundedFactory.setProperty("type", "BoundedTextAnnotation.class");
    registerService(bc, boundedAnnotationFactory, AnnotationFactory.class, boundedFactory);
    AddAnnotationTaskFactory addBoundedTextTaskFactory = new AddAnnotationTaskFactory(boundedAnnotationFactory);
    Properties addBoundedTextTaskFactoryProps = new Properties();
    addBoundedTextTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    addBoundedTextTaskFactoryProps.setProperty(MENU_GRAVITY, "1.6");
    addBoundedTextTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_ADD_MENU);
    addBoundedTextTaskFactoryProps.setProperty(TITLE, "Bounded Text Annotation");
    registerService(bc, addBoundedTextTaskFactory, NetworkViewLocationTaskFactory.class, addBoundedTextTaskFactoryProps);
    AnnotationFactory<?> groupAnnotationFactory = new GroupAnnotationFactory(serviceRegistrar);
    Properties groupFactory = new Properties();
    groupFactory.setProperty("type", "GroupAnnotation.class");
    registerService(bc, groupAnnotationFactory, AnnotationFactory.class, groupFactory);
    // Annotation edit
    EditAnnotationTaskFactory editAnnotationTaskFactory = new EditAnnotationTaskFactory();
    Properties editAnnotationTaskFactoryProps = new Properties();
    editAnnotationTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    editAnnotationTaskFactoryProps.setProperty(MENU_GRAVITY, "2.0");
    editAnnotationTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_EDIT_MENU);
    editAnnotationTaskFactoryProps.setProperty(TITLE, "Modify Annotation");
    registerService(bc, editAnnotationTaskFactory, NetworkViewLocationTaskFactory.class, editAnnotationTaskFactoryProps);
    MoveAnnotationTaskFactory moveAnnotationTaskFactory = new MoveAnnotationTaskFactory();
    Properties moveAnnotationTaskFactoryProps = new Properties();
    moveAnnotationTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    moveAnnotationTaskFactoryProps.setProperty(MENU_GRAVITY, "2.1");
    moveAnnotationTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_EDIT_MENU);
    moveAnnotationTaskFactoryProps.setProperty(TITLE, "Move Annotation");
    registerService(bc, moveAnnotationTaskFactory, NetworkViewLocationTaskFactory.class, moveAnnotationTaskFactoryProps);
    LayerAnnotationTaskFactory moveTFAnnotationTaskFactory = new LayerAnnotationTaskFactory(-10000);
    Properties moveTFAnnotationTaskFactoryProps = new Properties();
    moveTFAnnotationTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    moveTFAnnotationTaskFactoryProps.setProperty(MENU_GRAVITY, "3.1");
    moveTFAnnotationTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_EDIT_MENU + ".Reorder Annotations[2.2]");
    moveTFAnnotationTaskFactoryProps.setProperty(TITLE, "Move Annotation To Front");
    registerService(bc, moveTFAnnotationTaskFactory, NetworkViewLocationTaskFactory.class, moveTFAnnotationTaskFactoryProps);
    LayerAnnotationTaskFactory moveFAnnotationTaskFactory = new LayerAnnotationTaskFactory(-1);
    Properties moveFAnnotationTaskFactoryProps = new Properties();
    moveFAnnotationTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    moveFAnnotationTaskFactoryProps.setProperty(MENU_GRAVITY, "3.2");
    moveFAnnotationTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_EDIT_MENU + ".Reorder Annotations[2.2]");
    moveFAnnotationTaskFactoryProps.setProperty(TITLE, "Move Annotation Forwards");
    registerService(bc, moveFAnnotationTaskFactory, NetworkViewLocationTaskFactory.class, moveFAnnotationTaskFactoryProps);
    LayerAnnotationTaskFactory moveBAnnotationTaskFactory = new LayerAnnotationTaskFactory(1);
    Properties moveBAnnotationTaskFactoryProps = new Properties();
    moveBAnnotationTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    moveBAnnotationTaskFactoryProps.setProperty(MENU_GRAVITY, "3.3");
    moveBAnnotationTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_EDIT_MENU + ".Reorder Annotations[2.2]");
    moveBAnnotationTaskFactoryProps.setProperty(TITLE, "Move Annotation Backwards");
    registerService(bc, moveBAnnotationTaskFactory, NetworkViewLocationTaskFactory.class, moveBAnnotationTaskFactoryProps);
    LayerAnnotationTaskFactory moveTBAnnotationTaskFactory = new LayerAnnotationTaskFactory(10000);
    Properties moveTBAnnotationTaskFactoryProps = new Properties();
    moveTBAnnotationTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    moveTBAnnotationTaskFactoryProps.setProperty(MENU_GRAVITY, "3.4");
    moveTBAnnotationTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_EDIT_MENU + ".Reorder Annotations[2.2]");
    moveTBAnnotationTaskFactoryProps.setProperty(TITLE, "Move Annotation To Back");
    moveTBAnnotationTaskFactoryProps.setProperty(INSERT_SEPARATOR_AFTER, "true");
    registerService(bc, moveTBAnnotationTaskFactory, NetworkViewLocationTaskFactory.class, moveTBAnnotationTaskFactoryProps);
    ChangeAnnotationCanvasTaskFactory pullAnnotationTaskFactory = new ChangeAnnotationCanvasTaskFactory(Annotation.FOREGROUND);
    Properties pullAnnotationTaskFactoryProps = new Properties();
    pullAnnotationTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    pullAnnotationTaskFactoryProps.setProperty(MENU_GRAVITY, "3.5");
    pullAnnotationTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_EDIT_MENU + ".Reorder Annotations[2.2]");
    pullAnnotationTaskFactoryProps.setProperty(TITLE, "Pull Annotation to Foreground Canvas");
    registerService(bc, pullAnnotationTaskFactory, NetworkViewLocationTaskFactory.class, pullAnnotationTaskFactoryProps);
    ChangeAnnotationCanvasTaskFactory pushAnnotationTaskFactory = new ChangeAnnotationCanvasTaskFactory(Annotation.BACKGROUND);
    Properties pushAnnotationTaskFactoryProps = new Properties();
    pushAnnotationTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    pushAnnotationTaskFactoryProps.setProperty(MENU_GRAVITY, "3.6");
    pushAnnotationTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_EDIT_MENU + ".Reorder Annotations[2.2]");
    pushAnnotationTaskFactoryProps.setProperty(TITLE, "Push Annotation to Background Canvas");
    registerService(bc, pushAnnotationTaskFactory, NetworkViewLocationTaskFactory.class, pushAnnotationTaskFactoryProps);
    ResizeAnnotationTaskFactory resizeAnnotationTaskFactory = new ResizeAnnotationTaskFactory();
    Properties resizeAnnotationTaskFactoryProps = new Properties();
    resizeAnnotationTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    resizeAnnotationTaskFactoryProps.setProperty(MENU_GRAVITY, "2.3");
    resizeAnnotationTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_EDIT_MENU);
    resizeAnnotationTaskFactoryProps.setProperty(TITLE, "Resize Annotation");
    registerService(bc, resizeAnnotationTaskFactory, NetworkViewLocationTaskFactory.class, resizeAnnotationTaskFactoryProps);
    // Annotation delete
    RemoveAnnotationTaskFactory removeAnnotationTaskFactory = new RemoveAnnotationTaskFactory();
    Properties removeAnnotationTaskFactoryProps = new Properties();
    removeAnnotationTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    removeAnnotationTaskFactoryProps.setProperty(MENU_GRAVITY, "1.1");
    removeAnnotationTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_DELETE_MENU);
    removeAnnotationTaskFactoryProps.setProperty(TITLE, "Annotation");
    registerService(bc, removeAnnotationTaskFactory, NetworkViewLocationTaskFactory.class, removeAnnotationTaskFactoryProps);
    // Annotation select
    SelectAnnotationTaskFactory selectAnnotationTaskFactory = new SelectAnnotationTaskFactory();
    Properties selectAnnotationTaskFactoryProps = new Properties();
    selectAnnotationTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    selectAnnotationTaskFactoryProps.setProperty(MENU_GRAVITY, "1.1");
    selectAnnotationTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_SELECT_MENU);
    selectAnnotationTaskFactoryProps.setProperty(TITLE, "Select/Unselect Annotation");
    registerService(bc, selectAnnotationTaskFactory, NetworkViewLocationTaskFactory.class, selectAnnotationTaskFactoryProps);
    // Annotation group
    GroupAnnotationsTaskFactory groupAnnotationTaskFactory = new GroupAnnotationsTaskFactory();
    Properties groupAnnotationTaskFactoryProps = new Properties();
    groupAnnotationTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    groupAnnotationTaskFactoryProps.setProperty(MENU_GRAVITY, "100");
    groupAnnotationTaskFactoryProps.setProperty(INSERT_SEPARATOR_BEFORE, "true");
    groupAnnotationTaskFactoryProps.setProperty(IN_MENU_BAR, "false");
    groupAnnotationTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_GROUP_MENU);
    groupAnnotationTaskFactoryProps.setProperty(TITLE, "Group Annotations");
    registerService(bc, groupAnnotationTaskFactory, NetworkViewTaskFactory.class, groupAnnotationTaskFactoryProps);
    // Annotation ungroup
    UngroupAnnotationsTaskFactory ungroupAnnotationTaskFactory = new UngroupAnnotationsTaskFactory();
    Properties ungroupAnnotationTaskFactoryProps = new Properties();
    ungroupAnnotationTaskFactoryProps.setProperty(PREFERRED_ACTION, "NEW");
    ungroupAnnotationTaskFactoryProps.setProperty(MENU_GRAVITY, "100");
    ungroupAnnotationTaskFactoryProps.setProperty(INSERT_SEPARATOR_BEFORE, "true");
    ungroupAnnotationTaskFactoryProps.setProperty(PREFERRED_MENU, NETWORK_GROUP_MENU);
    ungroupAnnotationTaskFactoryProps.setProperty(TITLE, "Ungroup Annotations");
    registerService(bc, ungroupAnnotationTaskFactory, NetworkViewLocationTaskFactory.class, ungroupAnnotationTaskFactoryProps);
    // Set mouse drag selection modes
    SelectModeAction selectNodesOnlyAction = new SelectModeAction(SelectModeAction.NODES, 0.5f, serviceRegistrar);
    registerAllServices(bc, selectNodesOnlyAction, new Properties());
    SelectModeAction selectEdgesOnlyAction = new SelectModeAction(SelectModeAction.EDGES, 0.6f, serviceRegistrar);
    registerAllServices(bc, selectEdgesOnlyAction, new Properties());
    SelectModeAction selectNodesAndEdgesAction = new SelectModeAction(SelectModeAction.ALL, 0.7f, serviceRegistrar);
    registerAllServices(bc, selectNodesAndEdgesAction, new Properties());
    {
        // Toggle Graphics Details
        ShowGraphicsDetailsTaskFactory factory = new ShowGraphicsDetailsTaskFactory(dingGraphLOD, dingGraphLODAll);
        Properties props = new Properties();
        props.setProperty(ID, "showGraphicsDetailsTaskFactory");
        // Used at least by cyREST
        registerService(bc, factory, NetworkViewTaskFactory.class, props);
        // Main menu
        GraphicsDetailAction mainMenuAction = new GraphicsDetailAction(5.0f, "View", factory, serviceRegistrar);
        registerAllServices(bc, mainMenuAction);
        // Network tab's context menu
        GraphicsDetailAction networkMenuAction = new GraphicsDetailAction(11.0f, null, factory, serviceRegistrar);
        props = new Properties();
        props.setProperty(IN_NETWORK_PANEL_CONTEXT_MENU, "true");
        registerAllServices(bc, networkMenuAction, props);
    }
    // if IN_CONTEXT_MENU is not specified, default to true
    final String vtfFilter = String.format("(| (!(%s=*)) (%s=true))", IN_CONTEXT_MENU, IN_CONTEXT_MENU);
    registerServiceListener(bc, vtfListener::addNodeViewTaskFactory, vtfListener::removeNodeViewTaskFactory, NodeViewTaskFactory.class, vtfFilter);
    registerServiceListener(bc, vtfListener::addEdgeViewTaskFactory, vtfListener::removeEdgeViewTaskFactory, EdgeViewTaskFactory.class, vtfFilter);
    registerServiceListener(bc, vtfListener::addNetworkViewTaskFactory, vtfListener::removeNetworkViewTaskFactory, NetworkViewTaskFactory.class, vtfFilter);
    registerServiceListener(bc, vtfListener::addNetworkViewLocationTaskFactory, vtfListener::removeNetworkViewLocationTaskFactory, NetworkViewLocationTaskFactory.class);
    registerServiceListener(bc, vtfListener::addCyEdgeViewContextMenuFactory, vtfListener::removeCyEdgeViewContextMenuFactory, CyEdgeViewContextMenuFactory.class);
    registerServiceListener(bc, vtfListener::addCyNodeViewContextMenuFactory, vtfListener::removeCyNodeViewContextMenuFactory, CyNodeViewContextMenuFactory.class);
    registerServiceListener(bc, vtfListener::addCyNetworkViewContextMenuFactory, vtfListener::removeCyNetworkViewContextMenuFactory, CyNetworkViewContextMenuFactory.class);
    registerServiceListener(bc, annotationFactoryManager::addAnnotationFactory, annotationFactoryManager::removeAnnotationFactory, AnnotationFactory.class);
    BendFactory bendFactory = new BendFactoryImpl();
    registerService(bc, bendFactory, BendFactory.class, new Properties());
    // Register the factory
    dVisualLexicon.addBendFactory(bendFactory, new HashMap<Object, Object>());
    // Translators for Passthrough
    final CustomGraphicsTranslator cgTranslator = new CustomGraphicsTranslator(cgManager, cg2Manager);
    registerService(bc, cgTranslator, ValueTranslator.class, new Properties());
    // Factories for Visual Property Dependency
    final NodeSizeDependencyFactory nodeSizeDependencyFactory = new NodeSizeDependencyFactory(dVisualLexicon);
    registerService(bc, nodeSizeDependencyFactory, VisualPropertyDependencyFactory.class, new Properties());
    final EdgeColorDependencyFactory edgeColorDependencyFactory = new EdgeColorDependencyFactory(dVisualLexicon);
    registerService(bc, edgeColorDependencyFactory, VisualPropertyDependencyFactory.class, new Properties());
    final CustomGraphicsSizeDependencyFactory cgSizeDependencyFactory = new CustomGraphicsSizeDependencyFactory(dVisualLexicon);
    registerService(bc, cgSizeDependencyFactory, VisualPropertyDependencyFactory.class, new Properties());
    // Custom Graphics Editors
    final CyCustomGraphicsValueEditor cgValueEditor = new CyCustomGraphicsValueEditor(cgManager, cg2Manager, cgBrowser, serviceRegistrar);
    registerAllServices(bc, cgValueEditor, new Properties());
    final CustomGraphicsVisualPropertyEditor cgVisualPropertyEditor = new CustomGraphicsVisualPropertyEditor(CyCustomGraphics.class, cgValueEditor, continuousMappingCellRendererFactory, serviceRegistrar);
    registerService(bc, cgVisualPropertyEditor, VisualPropertyEditor.class, new Properties());
}
Also used : EditAnnotationTaskFactory(org.cytoscape.ding.impl.cyannotator.tasks.EditAnnotationTaskFactory) DingVisualStyleRenderingEngineFactory(org.cytoscape.ding.impl.DingVisualStyleRenderingEngineFactory) BendFactory(org.cytoscape.view.presentation.property.values.BendFactory) ChangeAnnotationCanvasTaskFactory(org.cytoscape.ding.impl.cyannotator.tasks.ChangeAnnotationCanvasTaskFactory) CustomGraphicsSizeDependencyFactory(org.cytoscape.ding.dependency.CustomGraphicsSizeDependencyFactory) ImageAnnotationFactory(org.cytoscape.ding.impl.cyannotator.create.ImageAnnotationFactory) ViewTaskFactoryListener(org.cytoscape.ding.impl.ViewTaskFactoryListener) EdgeColorDependencyFactory(org.cytoscape.ding.dependency.EdgeColorDependencyFactory) CyCustomGraphicsValueEditor(org.cytoscape.ding.impl.editor.CyCustomGraphicsValueEditor) SelectAnnotationTaskFactory(org.cytoscape.ding.impl.cyannotator.tasks.SelectAnnotationTaskFactory) DingViewModelFactory(org.cytoscape.ding.impl.DingViewModelFactory) NVLTFActionSupport(org.cytoscape.ding.impl.NVLTFActionSupport) GroupAnnotationsTaskFactory(org.cytoscape.ding.impl.cyannotator.tasks.GroupAnnotationsTaskFactory) HandleFactoryImpl(org.cytoscape.ding.impl.HandleFactoryImpl) NetworkViewTaskFactory(org.cytoscape.task.NetworkViewTaskFactory) AddEdgeNodeViewTaskFactoryImpl(org.cytoscape.ding.impl.AddEdgeNodeViewTaskFactoryImpl) DingGraphLOD(org.cytoscape.ding.impl.DingGraphLOD) AnnotationManager(org.cytoscape.view.presentation.annotations.AnnotationManager) AddArrowTaskFactory(org.cytoscape.ding.impl.cyannotator.tasks.AddArrowTaskFactory) AnnotationManagerImpl(org.cytoscape.ding.impl.cyannotator.AnnotationManagerImpl) ObjectPositionEditor(org.cytoscape.ding.impl.editor.ObjectPositionEditor) Properties(java.util.Properties) DingThumbnailRenderingEngineFactory(org.cytoscape.ding.impl.DingThumbnailRenderingEngineFactory) TextAnnotationFactory(org.cytoscape.ding.impl.cyannotator.create.TextAnnotationFactory) BoundedTextAnnotationFactory(org.cytoscape.ding.impl.cyannotator.create.BoundedTextAnnotationFactory) LayerAnnotationTaskFactory(org.cytoscape.ding.impl.cyannotator.tasks.LayerAnnotationTaskFactory) ContinuousMappingCellRendererFactory(org.cytoscape.view.vizmap.gui.editor.ContinuousMappingCellRendererFactory) ResizeAnnotationTaskFactory(org.cytoscape.ding.impl.cyannotator.tasks.ResizeAnnotationTaskFactory) DingNavigationRenderingEngineFactory(org.cytoscape.ding.impl.DingNavigationRenderingEngineFactory) NodeSizeDependencyFactory(org.cytoscape.ding.dependency.NodeSizeDependencyFactory) HandleFactory(org.cytoscape.view.presentation.property.values.HandleFactory) GraphicsDetailAction(org.cytoscape.ding.action.GraphicsDetailAction) DingGraphLODAll(org.cytoscape.ding.impl.DingGraphLODAll) DingRenderingEngineFactory(org.cytoscape.ding.impl.DingRenderingEngineFactory) RemoveAnnotationTaskFactory(org.cytoscape.ding.impl.cyannotator.tasks.RemoveAnnotationTaskFactory) ArrowAnnotationFactory(org.cytoscape.ding.impl.cyannotator.create.ArrowAnnotationFactory) UngroupAnnotationsTaskFactory(org.cytoscape.ding.impl.cyannotator.tasks.UngroupAnnotationsTaskFactory) AddAnnotationTaskFactory(org.cytoscape.ding.impl.cyannotator.tasks.AddAnnotationTaskFactory) MoveAnnotationTaskFactory(org.cytoscape.ding.impl.cyannotator.tasks.MoveAnnotationTaskFactory) GroupAnnotationFactory(org.cytoscape.ding.impl.cyannotator.create.GroupAnnotationFactory) EdgeBendValueEditor(org.cytoscape.ding.impl.editor.EdgeBendValueEditor) DingRenderer(org.cytoscape.ding.impl.DingRenderer) ShapeAnnotationFactory(org.cytoscape.ding.impl.cyannotator.create.ShapeAnnotationFactory) BendFactoryImpl(org.cytoscape.ding.impl.BendFactoryImpl) CustomGraphicsTranslator(org.cytoscape.ding.customgraphics.CustomGraphicsTranslator) EdgeBendEditor(org.cytoscape.ding.impl.editor.EdgeBendEditor) BoundedTextAnnotationFactory(org.cytoscape.ding.impl.cyannotator.create.BoundedTextAnnotationFactory) AnnotationFactoryManager(org.cytoscape.ding.impl.cyannotator.AnnotationFactoryManager) CustomGraphicsVisualPropertyEditor(org.cytoscape.ding.impl.editor.CustomGraphicsVisualPropertyEditor)

Example 2 with HandleFactory

use of org.cytoscape.view.presentation.property.values.HandleFactory in project cytoscape-impl by cytoscape.

the class LayerOrderNode method layout.

public void layout() {
    taskMonitor.setProgress(0.0);
    taskMonitor.setStatusMessage("Capturing snapshot of network and selected nodes");
    if (cancelled)
        return;
    /* construct node list with selected nodes first */
    int numLayoutNodes = nodesToLayOut.size();
    if (numLayoutNodes == 1) {
        // We were asked to do a hierchical layout of a single node -- done!
        return;
    }
    HashMap<Long, Integer> suid2Index = new HashMap<Long, Integer>(numLayoutNodes);
    List<View<CyNode>> nodeViews = new ArrayList<View<CyNode>>(nodesToLayOut);
    int index = 0;
    for (View<CyNode> view : nodeViews) {
        CyNode node = view.getModel();
        Long suid = node.getSUID();
        suid2Index.put(suid, index);
        index++;
    }
    if (cancelled)
        return;
    /* create edge list from edges between selected nodes */
    LinkedList<Edge> edges = new LinkedList();
    for (View<CyEdge> ev : networkView.getEdgeViews()) {
        // FIXME: much better would be to query adjacent edges of selected nodes...
        Integer edgeFrom = suid2Index.get(ev.getModel().getSource().getSUID());
        Integer edgeTo = suid2Index.get(ev.getModel().getTarget().getSUID());
        if ((edgeFrom == null) || (edgeTo == null)) {
            // Must be from an unselected node
            continue;
        }
        if (cancelled)
            return;
        if ((numLayoutNodes <= 1) || ((edgeFrom < numLayoutNodes) && (edgeTo < numLayoutNodes))) {
            /* add edge to graph */
            Edge theEdge = new Edge(edgeFrom, edgeTo);
            edges.add(theEdge);
        }
    }
    /* find horizontal and vertical coordinates of each node */
    Edge[] edge = new Edge[edges.size()];
    edges.toArray(edge);
    Graph graph = new Graph(numLayoutNodes, edge);
    /*
		int edgeIndex;
		for (edgeIndex = 0; edgeIndex<edge.length; edgeIndex++) {
		     System.out.println("Edge: " + edge[edgeIndex].getFrom() + " - " + edge[edgeIndex].getTo());
		}
		*/
    int[] cI = graph.componentIndex();
    int x;
    /*
		System.out.println("Node index:\n");
		for (x=0; x<graph.getNodecount(); x++) {
		    System.out.println(cI[x]);
		}
		System.out.println("Partitioning into components:\n");
		*/
    taskMonitor.setProgress(0.1);
    taskMonitor.setStatusMessage("Finding connected components");
    if (cancelled)
        return;
    int[] renumber = new int[cI.length];
    Graph[] component = graph.partition(cI, renumber);
    final int numComponents = component.length;
    int[][] layer = new int[numComponents][];
    int[][] horizontalPosition = new int[numComponents][];
    Graph[] reduced = new Graph[component.length];
    Graph[] reducedTmp = new Graph[component.length];
    HashMap<Integer, Edge>[] dummy2Edge = new HashMap[component.length];
    int[] dummyStartForComp = new int[component.length];
    HashMap<Edge, View<CyEdge>>[] myEdges2EdgeViews = new HashMap[component.length];
    for (x = 0; x < component.length; x++) {
        /*
			System.out.println("plain component:\n");
			System.out.println(component[x]);
			System.out.println("filtered component:\n");
			System.out.println(component[x].getGraphWithoutOneOrTwoCycles());
			System.out.println("nonmulti component:\n");
			System.out.println(component[x].getGraphWithoutMultipleEdges());
			int cycleEliminationPriority[] = component[x].getCycleEliminationVertexPriority();
			System.out.println("acyclic component:\n");
			System.out.println(component[x].getGraphWithoutCycles(cycleEliminationPriority));
			System.out.println("reduced component:\n");
			System.out.println(component[x].getReducedGraph());
			System.out.println("layer assignment:\n");
			*/
        taskMonitor.setProgress((20 + ((40 * (x * 3)) / numComponents / 3)) / 100.0);
        taskMonitor.setStatusMessage("making acyclic transitive reduction");
        Thread.yield();
        if (cancelled)
            return;
        reducedTmp[x] = component[x].getReducedGraph();
        taskMonitor.setProgress((20 + ((40 * ((x * 3) + 1)) / numComponents / 3)) / 100.0);
        taskMonitor.setStatusMessage("layering nodes vertically");
        Thread.yield();
        if (cancelled)
            return;
        layer[x] = reducedTmp[x].getVertexLayers();
        LinkedList<Integer> layerWithDummy = new LinkedList<Integer>();
        for (int i = 0; i < layer[x].length; i++) layerWithDummy.add(Integer.valueOf(layer[x][i]));
        /*
			int y;
			for (y=0;y<layer[x].length;y++) {
			    System.out.println("" + y + " : " + layer[x][y]);
			}
			System.out.println("horizontal position:\n");
			*/
        /* Insertion of the dummy nodes in the graph */
        Edge[] allEdges = component[x].GetEdges();
        LinkedList<Edge> edgesWithAdd = new LinkedList<Edge>();
        int dummyStart = component[x].getNodecount();
        dummyStartForComp[x] = dummyStart;
        dummy2Edge[x] = new HashMap<Integer, Edge>();
        for (int i = 0; i < allEdges.length; i++) {
            int from = allEdges[i].getFrom();
            int to = allEdges[i].getTo();
            if (layer[x][from] == (layer[x][to] + 1)) {
                edgesWithAdd.add(allEdges[i]);
            } else {
                if (layer[x][from] < layer[x][to]) {
                    int tmp = from;
                    from = to;
                    to = tmp;
                }
                layerWithDummy.add(Integer.valueOf(layer[x][to] + 1));
                dummy2Edge[x].put(Integer.valueOf(layerWithDummy.size() - 1), allEdges[i]);
                edgesWithAdd.add(new Edge(layerWithDummy.size() - 1, to));
                for (int j = layer[x][to] + 2; j < layer[x][from]; j++) {
                    layerWithDummy.add(Integer.valueOf(j));
                    dummy2Edge[x].put(Integer.valueOf(layerWithDummy.size() - 1), allEdges[i]);
                    edgesWithAdd.add(new Edge(layerWithDummy.size() - 1, layerWithDummy.size() - 2));
                }
                edgesWithAdd.add(new Edge(from, layerWithDummy.size() - 1));
            }
        }
        allEdges = new Edge[edgesWithAdd.size()];
        edgesWithAdd.toArray(allEdges);
        reduced[x] = new Graph(layerWithDummy.size(), allEdges);
        reduced[x].setDummyNodesStart(dummyStart);
        reduced[x].setReduced(true);
        int[] layerNew = new int[layerWithDummy.size()];
        Iterator<Integer> iter = layerWithDummy.iterator();
        for (int i = 0; i < layerNew.length; i++) layerNew[i] = iter.next();
        layer[x] = layerNew;
        taskMonitor.setProgress((20 + ((40 * ((x * 3) + 2)) / numComponents / 3)) / 100.0);
        taskMonitor.setStatusMessage("positioning nodes within layer");
        Thread.yield();
        if (cancelled)
            return;
        horizontalPosition[x] = reduced[x].getHorizontalPositionReverse(layer[x]);
    /*
			for (y=0;y<horizontalPosition[x].length;y++) {
			    System.out.println("" + y + " : " + horizontalPosition[x][y]);
			}
			*/
    }
    int resize = renumber.length;
    for (int i = 0; i < component.length; i++) resize += (layer[i].length - dummyStartForComp[i]);
    int[] newRenumber = new int[resize];
    int[] newcI = new int[resize];
    for (int i = 0; i < renumber.length; i++) {
        newRenumber[i] = renumber[i];
        newcI[i] = cI[i];
    }
    int t = renumber.length;
    for (int i = 0; i < reduced.length; i++) {
        for (int j = reduced[i].getDummyNodesStart(); j < reduced[i].getNodecount(); j++) {
            newRenumber[t] = j;
            newcI[t] = i;
            t++;
        }
    }
    renumber = newRenumber;
    cI = newcI;
    edges = new LinkedList<Edge>();
    for (int i = 0; i < reduced.length; i++) {
        edge = reduced[i].GetEdges();
        for (int j = 0; j < edge.length; j++) {
            // uzasna budzevina!!!!!! // FIXME: what does this mean?
            int from = -1;
            int to = -1;
            for (int k = 0; k < cI.length; k++) {
                if ((cI[k] == i) && (renumber[k] == edge[j].getFrom()))
                    from = k;
                if ((cI[k] == i) && (renumber[k] == edge[j].getTo()))
                    to = k;
                if ((from != -1) && (to != -1))
                    break;
            }
            // edges.add(new Edge(to, from));
            edges.add(new Edge(from, to));
        }
    }
    edge = new Edge[edges.size()];
    edges.toArray(edge);
    graph = new Graph(resize, edge);
    taskMonitor.setProgress(0.6);
    taskMonitor.setStatusMessage("Repositioning nodes in view");
    Thread.yield();
    if (cancelled)
        return;
    /* order nodeviews by layout order */
    HierarchyFlowLayoutOrderNode[] flowLayoutOrder = new HierarchyFlowLayoutOrderNode[resize];
    for (x = 0; x < resize; x++) {
        if (x < numLayoutNodes)
            flowLayoutOrder[x] = new HierarchyFlowLayoutOrderNode(nodeViews.get(x), cI[x], reduced[cI[x]].getNodecount(), layer[cI[x]][renumber[x]], horizontalPosition[cI[x]][renumber[x]], x);
        else
            flowLayoutOrder[x] = new HierarchyFlowLayoutOrderNode(null, cI[x], reduced[cI[x]].getNodecount(), layer[cI[x]][renumber[x]], horizontalPosition[cI[x]][renumber[x]], x);
        nodes2HFLON.put(x, flowLayoutOrder[x]);
    }
    Arrays.sort(flowLayoutOrder);
    int lastComponent = -1;
    int lastLayer = -1;
    int startBandY = context.topEdge;
    int cleanBandY = context.topEdge;
    int startComponentX = context.leftEdge;
    int cleanComponentX = context.leftEdge;
    int startLayerY = context.topEdge;
    int cleanLayerY = context.topEdge;
    int cleanLayerX = context.leftEdge;
    int[] layerStart = new int[numLayoutNodes + 1];
    /* layout nodes which are selected */
    int nodeIndex;
    /* layout nodes which are selected */
    int lastComponentEnd = -1;
    for (nodeIndex = 0; nodeIndex < resize; nodeIndex++) {
        HierarchyFlowLayoutOrderNode node = flowLayoutOrder[nodeIndex];
        int currentComponent = node.componentNumber;
        int currentLayer = node.layer;
        View<CyNode> currentView = node.nodeView;
        taskMonitor.setProgress((60 + ((40 * (nodeIndex + 1)) / resize)) / 100.0);
        taskMonitor.setStatusMessage("layering nodes vertically");
        Thread.yield();
        if (cancelled)
            return;
        if (lastComponent == -1) {
            /* this is the first component */
            lastComponent = currentComponent;
            lastLayer = currentLayer;
            layerStart[currentLayer] = -1;
        }
        if (lastComponent != currentComponent) {
            /* new component */
            // first call function for Horizontal Positioning of nodes in lastComponent
            int[] minXArray = new int[1];
            int maxX = HorizontalNodePositioning(nodeIndex - flowLayoutOrder[nodeIndex - 1].componentSize, nodeIndex - 1, flowLayoutOrder, graph, renumber, cI, dummyStartForComp, minXArray);
            int minX = minXArray[0];
            lastComponentEnd = nodeIndex - 1;
            for (int i = nodeIndex - flowLayoutOrder[nodeIndex - 1].componentSize; i <= (nodeIndex - 1); i++) flowLayoutOrder[i].xPos -= (minX - startComponentX);
            maxX -= (minX - startComponentX);
            layerStart[lastLayer] = startComponentX;
            /* initialize for new component */
            startComponentX = cleanComponentX + context.componentSpacing;
            if (maxX > startComponentX)
                startComponentX = maxX + context.componentSpacing;
            if (startComponentX > context.rightMargin) {
                /* new band */
                startBandY = cleanBandY + context.bandGap;
                cleanBandY = startBandY;
                startComponentX = context.leftEdge;
                cleanComponentX = context.leftEdge;
            }
            startLayerY = startBandY;
            cleanLayerY = startLayerY;
            cleanLayerX = startComponentX;
            layerStart[currentLayer] = -1;
        } else if (lastLayer != currentLayer) {
            /* new layer */
            layerStart[lastLayer] = startComponentX;
            startLayerY = cleanLayerY + context.nodeVerticalSpacing;
            cleanLayerY = startLayerY;
            cleanLayerX = startComponentX;
            layerStart[currentLayer] = -1;
        }
        node.setXPos(cleanLayerX);
        node.setYPos(startLayerY);
        cleanLayerX += context.nodeHorizontalSpacing;
        int currentBottom;
        int currentRight;
        if (currentView != null) {
            currentBottom = startLayerY + currentView.getVisualProperty(BasicVisualLexicon.NODE_HEIGHT).intValue();
            currentRight = cleanLayerX + currentView.getVisualProperty(BasicVisualLexicon.NODE_WIDTH).intValue();
        } else {
            currentBottom = startLayerY;
            currentRight = cleanLayerX;
        }
        if (currentBottom > cleanBandY)
            cleanBandY = currentBottom;
        if (currentRight > cleanComponentX)
            cleanComponentX = currentRight;
        if (currentBottom > cleanLayerY)
            cleanLayerY = currentBottom;
        if (currentRight > cleanLayerX)
            cleanLayerX = currentRight;
        lastComponent = currentComponent;
        lastLayer = currentLayer;
    }
    if (cancelled)
        return;
    /* Set horizontal positions of last component */
    int[] minXArray = new int[1];
    HorizontalNodePositioning(lastComponentEnd + 1, resize - 1, flowLayoutOrder, graph, renumber, cI, dummyStartForComp, minXArray);
    int minX = minXArray[0];
    for (int i = lastComponentEnd + 1; i < resize; i++) flowLayoutOrder[i].xPos -= (minX - startComponentX);
    /* Map edges to edge views in order to map dummy nodes to edge bends properly */
    for (View<CyEdge> ev : networkView.getEdgeViews()) {
        Integer edgeFrom = suid2Index.get(ev.getModel().getSource().getSUID());
        Integer edgeTo = suid2Index.get(ev.getModel().getTarget().getSUID());
        if ((edgeFrom == null) || (edgeTo == null)) {
            // Must be from an unselected node
            continue;
        }
        if ((numLayoutNodes <= 1) || ((edgeFrom < numLayoutNodes) && (edgeTo < numLayoutNodes))) {
            /* add edge to graph */
            Edge theEdge = component[cI[edgeFrom]].GetTheEdge(renumber[edgeFrom], renumber[edgeTo]);
            if (myEdges2EdgeViews[cI[edgeFrom]] == null)
                myEdges2EdgeViews[cI[edgeFrom]] = new HashMap<Edge, View<CyEdge>>();
            myEdges2EdgeViews[cI[edgeFrom]].put(theEdge, ev);
        }
    }
    for (nodeIndex = 0; nodeIndex < resize; nodeIndex++) {
        HierarchyFlowLayoutOrderNode node = flowLayoutOrder[nodeIndex];
        if (node.nodeView != null) {
            View<CyNode> currentView = node.nodeView;
            currentView.setVisualProperty(BasicVisualLexicon.NODE_X_LOCATION, Double.valueOf((double) node.getXPos()));
            currentView.setVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION, Double.valueOf((double) node.getYPos()));
        }
    }
    final HandleFactory handleFactory = serviceRegistrar.getService(HandleFactory.class);
    final BendFactory bendFactory = serviceRegistrar.getService(BendFactory.class);
    for (nodeIndex = 0; nodeIndex < resize; nodeIndex++) {
        HierarchyFlowLayoutOrderNode node = flowLayoutOrder[nodeIndex];
        if (node.nodeView == null) {
            Edge theEdge = (Edge) dummy2Edge[cI[node.graphIndex]].get(Integer.valueOf(renumber[node.graphIndex]));
            View<CyEdge> ev = myEdges2EdgeViews[cI[node.graphIndex]].get(theEdge);
            if (ev != null) {
                View<CyNode> source = networkView.getNodeView(ev.getModel().getSource());
                View<CyNode> target = networkView.getNodeView(ev.getModel().getTarget());
                double k = (getYPositionOf(target) - getYPositionOf(source)) / (getXPositionOf(target) - getXPositionOf(source));
                double xPos = getXPositionOf(source);
                if (k != 0)
                    xPos += ((node.yPos - getYPositionOf(source)) / k);
                Bend b = bendFactory.createBend();
                Handle h = handleFactory.createHandle(networkView, ev, xPos, node.yPos);
                b.insertHandleAt(0, h);
                ev.setVisualProperty(BasicVisualLexicon.EDGE_BEND, b);
            }
        }
    }
    for (nodeIndex = 0; nodeIndex < resize; nodeIndex++) {
        HierarchyFlowLayoutOrderNode node = flowLayoutOrder[nodeIndex];
        if (node.nodeView == null) {
            Edge theEdge = dummy2Edge[cI[node.graphIndex]].get(Integer.valueOf(renumber[node.graphIndex]));
            View<CyEdge> ev = myEdges2EdgeViews[cI[node.graphIndex]].get(theEdge);
            if (ev != null) {
                List<Handle> handles = ev.getVisualProperty(BasicVisualLexicon.EDGE_BEND).getAllHandles();
                for (Handle h : handles) {
                    Point2D handelPt = h.calculateHandleLocation(networkView, ev);
                    if (handelPt.getY() == node.yPos) {
                        h.defineHandle(networkView, ev, (double) (node.xPos), (double) (node.yPos));
                        break;
                    }
                }
            }
        }
    }
    taskMonitor.setProgress(1.0);
    taskMonitor.setStatusMessage("hierarchical layout complete");
}
Also used : BendFactory(org.cytoscape.view.presentation.property.values.BendFactory) HashMap(java.util.HashMap) Bend(org.cytoscape.view.presentation.property.values.Bend) ArrayList(java.util.ArrayList) HandleFactory(org.cytoscape.view.presentation.property.values.HandleFactory) Point2D(java.awt.geom.Point2D) CyNode(org.cytoscape.model.CyNode) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge) LinkedList(java.util.LinkedList) Handle(org.cytoscape.view.presentation.property.values.Handle) CyEdge(org.cytoscape.model.CyEdge)

Example 3 with HandleFactory

use of org.cytoscape.view.presentation.property.values.HandleFactory in project cytoscape-impl by cytoscape.

the class EdgeBundlerTask method run.

@Override
public void run(TaskMonitor tm) {
    // Check tunables
    if (numNubs < 1)
        numNubs = 1;
    if (numNubs > 50) {
        logger.warn("Maximum handles is 50.");
        numNubs = 50;
    }
    tm.setTitle("Edge Bundle Layout");
    // Pre-cache data structures
    tm.setStatusMessage("Caching network data");
    Collection<View<CyEdge>> edges = null;
    // Get selection
    if (// Use all edges
    selection == 0) {
        edges = this.view.getEdgeViews();
    } else if (// Use selected nodes only
    selection == 1) {
        Collection<View<CyEdge>> edgeView = this.view.getEdgeViews();
        edges = new ArrayList<View<CyEdge>>(edgeView.size());
        for (View<CyEdge> e : edgeView) {
            boolean n1 = view.getNodeView(e.getModel().getSource()).getVisualProperty(EDGE_SELECTED);
            boolean n2 = view.getNodeView(e.getModel().getTarget()).getVisualProperty(EDGE_SELECTED);
            if (n1 && n2)
                edges.add(e);
        }
    } else if (// Use selected edges only
    selection == 2) {
        Collection<View<CyEdge>> edgeView = this.view.getEdgeViews();
        edges = new ArrayList<View<CyEdge>>(edgeView.size());
        for (View<CyEdge> e : edgeView) if (e.getVisualProperty(EDGE_SELECTED))
            edges.add(e);
    }
    int ei = 0;
    for (View<CyEdge> e : edges) {
        View<CyNode> eSource = view.getNodeView(e.getModel().getSource());
        View<CyNode> eTarget = view.getNodeView(e.getModel().getTarget());
        if (eSource.getSUID().equals(eTarget.getSUID()))
            continue;
        ei++;
    }
    numEdges = ei;
    if (numEdges < 2) {
        logger.warn("Less than two edges found.");
        return;
    }
    edgePos = new double[2][2][numEdges];
    nubs = new double[numNubs][2][numEdges];
    edgeLength = new double[numEdges];
    ei = 0;
    for (final View<CyEdge> e : edges) {
        // System.out.println("SUID: "+e.getModel().getSUID());
        View<CyNode> eSource = view.getNodeView(e.getModel().getSource());
        View<CyNode> eTarget = view.getNodeView(e.getModel().getTarget());
        if (eSource.getSUID().equals(eTarget.getSUID()))
            continue;
        edgePos[0][0][ei] = eSource.getVisualProperty(NODE_X_LOCATION);
        edgePos[0][1][ei] = eSource.getVisualProperty(NODE_Y_LOCATION);
        edgePos[1][0][ei] = eTarget.getVisualProperty(NODE_X_LOCATION);
        edgePos[1][1][ei] = eTarget.getVisualProperty(NODE_Y_LOCATION);
        double diffx = edgePos[1][0][ei] - edgePos[0][0][ei];
        double diffy = edgePos[1][1][ei] - edgePos[0][1][ei];
        for (int ni = 0; ni < numNubs; ni++) {
            nubs[ni][0][ei] = (diffx) * (ni + 1) / (numNubs + 1) + edgePos[0][0][ei];
            nubs[ni][1][ei] = (diffy) * (ni + 1) / (numNubs + 1) + edgePos[0][1][ei];
        }
        edgeLength[ei] = Math.sqrt(diffx * diffx + diffy * diffy);
        ei++;
    }
    computeEdgeCompatability();
    // Simulating physics
    tm.setStatusMessage("Simulating physics");
    double time = System.nanoTime();
    final double maxItrDouble = Double.valueOf(maxIterations);
    // Nub, X/Y, edgeIndex
    final double[][][] forces = new double[numNubs][2][numEdges];
    final HandleFactory handleFactory = serviceRegistrar.getService(HandleFactory.class);
    final BendFactory bendFactory = serviceRegistrar.getService(BendFactory.class);
    final VisualMappingManager visualMappingManager = serviceRegistrar.getService(VisualMappingManager.class);
    final VisualMappingFunctionFactory discreteFactory = serviceRegistrar.getService(VisualMappingFunctionFactory.class, "(mapping.type=discrete)");
    // Repeat the simulation [maxIterations] times.
    for (int iteri = 0; iteri < maxIterations; iteri++) {
        if (this.cancelled) {
            logger.info("Edge bundling cancelled: iter=" + iteri);
            break;
        }
        tm.setProgress(iteri / maxItrDouble);
        updateForces(forces);
        updateNubs(forces);
        // Check convergence once in awhile
        if (iteri % 1000 == 0 && isConverged(forces, .01)) {
            logger.info("Edge bundling converged: iter=" + iteri);
            break;
        }
        if (iteri == maxIterations - 1) {
            logger.info("Edge bundling did not converge: iter=" + iteri);
            break;
        }
        if (animate && System.nanoTime() - time > 3) {
            render(edges, handleFactory, bendFactory, visualMappingManager, discreteFactory);
            time = System.nanoTime();
        }
    }
    render(edges, handleFactory, bendFactory, visualMappingManager, discreteFactory);
}
Also used : BendFactory(org.cytoscape.view.presentation.property.values.BendFactory) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) ArrayList(java.util.ArrayList) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge) HandleFactory(org.cytoscape.view.presentation.property.values.HandleFactory) Collection(java.util.Collection) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager)

Aggregations

ArrayList (java.util.ArrayList)2 CyEdge (org.cytoscape.model.CyEdge)2 CyNode (org.cytoscape.model.CyNode)2 CyNetworkView (org.cytoscape.view.model.CyNetworkView)2 View (org.cytoscape.view.model.View)2 BendFactory (org.cytoscape.view.presentation.property.values.BendFactory)2 HandleFactory (org.cytoscape.view.presentation.property.values.HandleFactory)2 Point2D (java.awt.geom.Point2D)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 GraphicsDetailAction (org.cytoscape.ding.action.GraphicsDetailAction)1 CustomGraphicsTranslator (org.cytoscape.ding.customgraphics.CustomGraphicsTranslator)1 CustomGraphicsSizeDependencyFactory (org.cytoscape.ding.dependency.CustomGraphicsSizeDependencyFactory)1 EdgeColorDependencyFactory (org.cytoscape.ding.dependency.EdgeColorDependencyFactory)1 NodeSizeDependencyFactory (org.cytoscape.ding.dependency.NodeSizeDependencyFactory)1 AddEdgeNodeViewTaskFactoryImpl (org.cytoscape.ding.impl.AddEdgeNodeViewTaskFactoryImpl)1 BendFactoryImpl (org.cytoscape.ding.impl.BendFactoryImpl)1 DingGraphLOD (org.cytoscape.ding.impl.DingGraphLOD)1