Search in sources :

Example 1 with SelectionManager

use of org.gephi.visualization.api.selection.SelectionManager in project gephi by gephi.

the class SelectionBar method createPopup.

public JPopupMenu createPopup() {
    SelectionManager manager = VizController.getInstance().getSelectionManager();
    final MouseSelectionPopupPanel popupPanel = new MouseSelectionPopupPanel();
    popupPanel.setDiameter(manager.getMouseSelectionDiameter());
    popupPanel.setProportionnalToZoom(manager.isMouseSelectionZoomProportionnal());
    popupPanel.setChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            SelectionManager manager = VizController.getInstance().getSelectionManager();
            manager.setMouseSelectionDiameter(popupPanel.getDiameter());
            manager.setMouseSelectionZoomProportionnal(popupPanel.isProportionnalToZoom());
        }
    });
    JPopupMenu menu = new JPopupMenu();
    menu.add(popupPanel);
    return menu;
}
Also used : SelectionManager(org.gephi.visualization.api.selection.SelectionManager) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener) JPopupMenu(javax.swing.JPopupMenu)

Example 2 with SelectionManager

use of org.gephi.visualization.api.selection.SelectionManager in project gephi by gephi.

the class DesktopToolController method getToolbar.

@Override
public JComponent getToolbar() {
    // Get tools ui
    HashMap<ToolUI, Tool> toolMap = new HashMap<>();
    List<ToolUI> toolsUI = new ArrayList<>();
    for (Tool tool : tools) {
        ToolUI ui = tool.getUI();
        if (ui != null) {
            toolsUI.add(ui);
            toolMap.put(ui, tool);
        }
    }
    // Sort by priority
    Collections.sort(toolsUI, new Comparator() {

        @Override
        public int compare(Object o1, Object o2) {
            Integer p1 = ((ToolUI) o1).getPosition();
            Integer p2 = ((ToolUI) o2).getPosition();
            return p1.compareTo(p2);
        }
    });
    // Create toolbar
    final Toolbar toolbar = new Toolbar();
    for (final ToolUI toolUI : toolsUI) {
        final Tool tool = toolMap.get(toolUI);
        JToggleButton btn;
        if (toolUI.getIcon() != null) {
            btn = new JToggleButton(toolUI.getIcon());
        } else {
            btn = new JToggleButton(new ImageIcon(getClass().getResource("/org/gephi/desktop/tools/tool.png")));
        }
        btn.setToolTipText(toolUI.getName() + " - " + toolUI.getDescription());
        btn.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                // Let the user unselect a tool (by clicking on it again) without having to select other tool:
                if (tool == currentTool) {
                    toolbar.clearSelection();
                    unselect();
                } else {
                    try {
                        select(tool);
                        propertiesBar.select(toolUI.getPropertiesBar(tool));
                    } catch (UnselectToolException unselectToolException) {
                        toolbar.clearSelection();
                        unselect();
                    }
                }
            }
        });
        toolbar.add(btn);
    }
    // SelectionManager events
    VizController.getInstance().getSelectionManager().addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            SelectionManager selectionManager = VizController.getInstance().getSelectionManager();
            if (selectionManager.isRectangleSelection() && currentTool != null) {
                toolbar.clearSelection();
                unselect();
            } else if (selectionManager.isSelectionEnabled() && currentTool != null && currentTool.getSelectionType() == ToolSelectionType.NONE) {
                toolbar.clearSelection();
                unselect();
            } else if (selectionManager.isDraggingEnabled() && currentTool != null) {
                toolbar.clearSelection();
                unselect();
            }
        }
    });
    return toolbar;
}
Also used : ImageIcon(javax.swing.ImageIcon) SelectionManager(org.gephi.visualization.api.selection.SelectionManager) HashMap(java.util.HashMap) UnselectToolException(org.gephi.tools.spi.UnselectToolException) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) ToolUI(org.gephi.tools.spi.ToolUI) Comparator(java.util.Comparator) JToggleButton(javax.swing.JToggleButton) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener) Tool(org.gephi.tools.spi.Tool)

Example 3 with SelectionManager

use of org.gephi.visualization.api.selection.SelectionManager in project gephi by gephi.

the class VizController method initInstances.

public void initInstances() {
    vizConfig = new VizConfig();
    graphIO = new StandardGraphIO();
    engine = new CompatibilityEngine();
    vizEventManager = new StandardVizEventManager();
    scheduler = new CompatibilityScheduler();
    limits = new GraphLimits();
    dataBridge = new DataBridge();
    textManager = new TextManager();
    screenshotMaker = new ScreenshotMaker();
    currentModel = new VizModel(true);
    selectionManager = new SelectionManager();
    if (vizConfig.isUseGLJPanel()) {
    // No more supported
    } else if (Utilities.isMac()) {
        drawable = createCanvas();
    } else {
        drawable = createNewtCanvas();
    }
    drawable.initArchitecture();
    engine.initArchitecture();
    ((CompatibilityScheduler) scheduler).initArchitecture();
    ((StandardGraphIO) graphIO).initArchitecture();
    dataBridge.initArchitecture();
    textManager.initArchitecture();
    screenshotMaker.initArchitecture();
    vizEventManager.initArchitecture();
    selectionManager.initArchitecture();
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
    pc.addWorkspaceListener(new WorkspaceListener() {

        @Override
        public void initialize(Workspace workspace) {
            if (workspace.getLookup().lookup(VizModel.class) == null) {
                workspace.add(new VizModel(workspace));
            }
        }

        @Override
        public void select(Workspace workspace) {
            engine.reinit();
        }

        @Override
        public void unselect(Workspace workspace) {
        }

        @Override
        public void close(Workspace workspace) {
        }

        @Override
        public void disable() {
            engine.reinit();
        }
    });
    if (pc.getCurrentWorkspace() != null) {
        engine.reinit();
    }
}
Also used : SelectionManager(org.gephi.visualization.api.selection.SelectionManager) CompatibilityEngine(org.gephi.visualization.opengl.CompatibilityEngine) TextManager(org.gephi.visualization.text.TextManager) StandardVizEventManager(org.gephi.visualization.events.StandardVizEventManager) CompatibilityScheduler(org.gephi.visualization.scheduler.CompatibilityScheduler) ProjectController(org.gephi.project.api.ProjectController) WorkspaceListener(org.gephi.project.api.WorkspaceListener) StandardGraphIO(org.gephi.visualization.swing.StandardGraphIO) ScreenshotMaker(org.gephi.visualization.screenshot.ScreenshotMaker) VizConfig(org.gephi.visualization.apiimpl.VizConfig) DataBridge(org.gephi.visualization.bridge.DataBridge) Workspace(org.gephi.project.api.Workspace)

Example 4 with SelectionManager

use of org.gephi.visualization.api.selection.SelectionManager in project gephi by gephi.

the class SelectionToolbar method initContent.

private void initContent() {
    // Mouse
    final JToggleButton mouseButton = new JToggleButton(new ImageIcon(getClass().getResource("/org/gephi/visualization/component/mouse.png")));
    mouseButton.setToolTipText(NbBundle.getMessage(SelectionToolbar.class, "SelectionToolbar.mouse.tooltip"));
    mouseButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (mouseButton.isSelected()) {
                VizController.getInstance().getSelectionManager().setDirectMouseSelection();
            }
        }
    });
    add(mouseButton);
    // Rectangle
    final JToggleButton rectangleButton = new JToggleButton(new ImageIcon(getClass().getResource("/org/gephi/visualization/component/rectangle.png")));
    rectangleButton.setToolTipText(NbBundle.getMessage(SelectionToolbar.class, "SelectionToolbar.rectangle.tooltip"));
    rectangleButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (rectangleButton.isSelected()) {
                VizController.getInstance().getSelectionManager().setRectangleSelection();
            }
        }
    });
    add(rectangleButton);
    // Drag
    final JToggleButton dragButton = new JToggleButton(new ImageIcon(getClass().getResource("/org/gephi/visualization/component/hand.png")));
    dragButton.setToolTipText(NbBundle.getMessage(SelectionToolbar.class, "SelectionToolbar.drag.tooltip"));
    dragButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (dragButton.isSelected()) {
                VizController.getInstance().getSelectionManager().setDraggingMouseSelection();
            }
        }
    });
    add(dragButton);
    addSeparator();
    buttonGroup.setSelected(rectangleButton.getModel(), VizController.getInstance().getVizConfig().isRectangleSelection());
    buttonGroup.setSelected(mouseButton.getModel(), !VizController.getInstance().getVizConfig().isRectangleSelection());
    buttonGroup.setSelected(dragButton.getModel(), VizController.getInstance().getVizConfig().isDraggingEnable());
    // Init events
    VizController.getInstance().getSelectionManager().addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            SelectionManager selectionManager = VizController.getInstance().getSelectionManager();
            if (selectionManager.isBlocked()) {
                buttonGroup.clearSelection();
            } else if (!selectionManager.isSelectionEnabled()) {
                buttonGroup.clearSelection();
            } else if (selectionManager.isDirectMouseSelection()) {
                if (!buttonGroup.isSelected(mouseButton.getModel())) {
                    buttonGroup.setSelected(mouseButton.getModel(), true);
                }
            }
        }
    });
}
Also used : ImageIcon(javax.swing.ImageIcon) SelectionManager(org.gephi.visualization.api.selection.SelectionManager) JToggleButton(javax.swing.JToggleButton) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) ActionEvent(java.awt.event.ActionEvent) ChangeListener(javax.swing.event.ChangeListener)

Example 5 with SelectionManager

use of org.gephi.visualization.api.selection.SelectionManager in project gephi by gephi.

the class StandardGraphIO method mouseWheelMoved.

@Override
public void mouseWheelMoved(MouseEvent e) {
    float scroll = e.getRotation()[1];
    if (scroll == 0f || !vizController.getVizConfig().isCameraControlEnable()) {
        return;
    }
    boolean ctrl = (e.getModifiers() & InputEvent.CTRL_DOWN_MASK) != 0 || (e.getModifiers() & InputEvent.CTRL_MASK) != 0 || (e.getModifiers() & InputEvent.META_MASK) != 0;
    if (ctrl) {
        SelectionManager manager = VizController.getInstance().getSelectionManager();
        if (!manager.isRectangleSelection()) {
            int s = manager.getMouseSelectionDiameter();
            s += scroll * 2;
            s = Math.min(1000, s);
            s = Math.max(1, s);
            manager.setMouseSelectionDiameter(s);
        }
        return;
    }
    // Attributes
    float globalScale = graphDrawable.getGlobalScale();
    float way = scroll / Math.abs(scroll);
    float[] cameraLocation = graphDrawable.getCameraLocation();
    float[] cameraTarget = graphDrawable.getCameraTarget();
    float markerX = (float) graphDrawable.getDraggingMarkerX();
    float markerY = (float) graphDrawable.getDraggingMarkerY();
    // Transform in 3d coordinates
    // Set to centric coordinates
    float mouseX = (float) ((mousePosition[0] - graphDrawable.viewport.get(2) / 2.0) / -markerX) + cameraTarget[0] / globalScale;
    float mouseY = (float) ((mousePosition[1] - graphDrawable.viewport.get(3) / 2.0) / -markerY) + cameraTarget[1] / globalScale;
    // Get mouse position within the clipping plane
    mouseX = MathUtil.clamp(mouseX, limits.getMinXoctree(), limits.getMaxXoctree());
    mouseY = MathUtil.clamp(mouseY, limits.getMinYoctree(), limits.getMaxYoctree());
    mouseX *= globalScale;
    mouseY *= globalScale;
    // Camera location and target vectors
    Vec3f targetVector = new Vec3f(mouseX - cameraTarget[0], mouseY - cameraTarget[1], 0f);
    Vec3f locationVector = new Vec3f(mouseX - cameraLocation[0], mouseY - cameraLocation[1], -cameraLocation[2]);
    // Distance from location to mouse
    float distance = (float) Math.sqrt(locationVector.x() * locationVector.x() + locationVector.y() * locationVector.y() + locationVector.z() * locationVector.z());
    float distanceRatio = MathUtil.clamp(2 * distance / 10000f, 0f, 2f);
    // exp(x-2)*2.2-0.3
    float coeff = (float) (Math.exp(distanceRatio - 2) * 2.2 - 0.295);
    float step = way * (10f + 1000 * coeff);
    if (way == -1) {
        step *= 3;
    }
    float stepRatio = step / distance;
    // Multiply vectors
    targetVector.scale(stepRatio);
    locationVector.scale(stepRatio);
    if (cameraLocation[2] + locationVector.z() >= 1f && cameraLocation[2] + locationVector.z() <= (graphDrawable.farDistance - graphDrawable.nearDistance)) {
        cameraLocation[0] += locationVector.x();
        cameraLocation[1] += locationVector.y();
        cameraLocation[2] += locationVector.z();
        cameraTarget[0] += targetVector.x();
        cameraTarget[1] += targetVector.y();
    }
    // Refresh
    engine.getScheduler().requireUpdateVisible();
}
Also used : SelectionManager(org.gephi.visualization.api.selection.SelectionManager) Vec3f(org.gephi.lib.gleem.linalg.Vec3f)

Aggregations

SelectionManager (org.gephi.visualization.api.selection.SelectionManager)5 ChangeEvent (javax.swing.event.ChangeEvent)3 ChangeListener (javax.swing.event.ChangeListener)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 ImageIcon (javax.swing.ImageIcon)2 JToggleButton (javax.swing.JToggleButton)2 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 JPopupMenu (javax.swing.JPopupMenu)1 Vec3f (org.gephi.lib.gleem.linalg.Vec3f)1 ProjectController (org.gephi.project.api.ProjectController)1 Workspace (org.gephi.project.api.Workspace)1 WorkspaceListener (org.gephi.project.api.WorkspaceListener)1 Tool (org.gephi.tools.spi.Tool)1 ToolUI (org.gephi.tools.spi.ToolUI)1 UnselectToolException (org.gephi.tools.spi.UnselectToolException)1 VizConfig (org.gephi.visualization.apiimpl.VizConfig)1 DataBridge (org.gephi.visualization.bridge.DataBridge)1