使用拾取模式时如何用Jung更新布局的大小?

发布于 2024-11-03 01:28:19 字数 632 浏览 8 评论 0原文

我想知道如何使用 jung 更改与 VisualizationViewer 关联的布局的大小?

我解释一下目的:实际上,当使用SatelliteVisualizationViewer时,我们可以选择一个节点并将其移动到SatelliteVisualizationViewer未覆盖的区域。

我们可以在 JUNG 发行版的 SatelliteViewDemo 类中看到这一点。启动演示,选择一个节点并将其移至布局尺寸之外。该节点在 VisualizationViewer 中显示良好,但在卫星视图中显示不佳。

因此,我尝试在 PickingGraphMousePlugin 的 MouseListener 中添加一些代码,特别是在 mouseReleased(...) 方法中,以便根据包含图形所有节点的矩形的大小来更新布局大小。执行此操作后,应更新 SatelliteView。 但如何做到这一点呢?

编辑:抱歉,不够详细。事实上,更改布局大小不会更改 SatelliteView,因此位于布局外部的顶点(在拾取和移动操作之后)仍然不会被 SatelliteView 覆盖。

也许我错过了一些东西......

实际上真正的问题是:如何更改 SatelliteVisualizationViewer 覆盖的区域? !!!

I wondering how to change the size of the layout associated to a VisualizationViewer with jung?

I explain the purpose: actually, when using a SatelliteVisualizationViewer, we can pick a node and move it in an area that is not covered by the SatelliteVisualisationViewer.

We can see this in the SatelliteViewDemo class in the JUNG distribution. Launch the demo, pick a node and move it outside the layout size. The node is well displayed in the VisualizationViewer but not in the satellite view.

So, I try to add some code in the MouseListener of PickingGraphMousePlugin, specifically in the mouseReleased(...) method in order to update the layout size by the size of the rectangle that contains all the nodes of the graph. Doing this, the SatelliteView should be updated.
But how to do this?

Edit: Sorry to have not detailled enough. In fact, changing the layout size does not change the SatelliteView, so vertex located outside the layout (after a pick and move operation) are still not covered by the SatelliteView.

Maybe I have miss something...

Actually the real question is: how to change the area covered by the SatelliteVisualizationViewer? !!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巷雨优美回忆 2024-11-10 01:28:19

听起来您似乎很清楚如何继续。你卡在哪一块了?更改布局大小?更新可视化?还有别的事吗?

It sounds like you've got a pretty good idea of how to proceed. What piece are you stuck on? Changing the layout size? Updating the visualization? Something else?

独自←快乐 2024-11-10 01:28:19

我想相对于启用了选择支持的 VisualizationViewer 自动更新卫星视图。

我最终采用了另一种解决方案:不自动更新卫星视图,而是使用鼠标按钮 2 进行平移,并使用 CTRL+Mouse_Wheel 进行缩放。

这是课程,可能会有所帮助......:

public class SatelliteVisualizationViewerMouseControler implements
        MouseListener, MouseMotionListener, MouseWheelListener {

    private SatelliteVisualizationViewer<SVertex, PEdge> vv;
    private Point drag_point;
    private double zoom_factor = 0.1;

    public SatelliteVisualizationViewerMouseControler(
            SatelliteVisualizationViewer<SVertex, PEdge> vv) {
        this.vv = vv;
    }

    @Override
    public void mouseDragged(MouseEvent e) {
        if (drag_point != null) {
            Point2D l_drag_point = vv.getRenderContext()
                .getMultiLayerTransformer()
                .inverseTransform(Layer.LAYOUT, drag_point);

        Point2D l_e_point = vv.getRenderContext()
                .getMultiLayerTransformer()
                .inverseTransform(Layer.LAYOUT, e.getPoint());

        double delta_x = l_e_point.getX() - l_drag_point.getX();
        double delta_y = l_e_point.getY() - l_drag_point.getY();

        double scale = vv.getRenderContext().getMultiLayerTransformer()
                .getTransformer(Layer.VIEW).getScale();

        vv.getRenderContext().getMultiLayerTransformer()
                .getTransformer(Layer.LAYOUT)
                .translate(delta_x * (1 / scale), delta_y * (1 / scale));

        drag_point = e.getPoint();
        }
    }

    @Override
    public void mouseMoved(MouseEvent e) {
    }

    @Override
    public void mouseClicked(MouseEvent e) {
    }

    @Override
    public void mouseEntered(MouseEvent e) {
    }

    @Override
    public void mouseExited(MouseEvent e) {
    }

    @Override
    public void mousePressed(MouseEvent e) {
        if (e.getButton() == MouseEvent.BUTTON2) {
            drag_point = e.getPoint();
        }
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        if (e.getButton() == MouseEvent.BUTTON2) {
            drag_point = null;
        }
    }

    @Override
    public void mouseWheelMoved(MouseWheelEvent e) {
        if (e.getModifiersEx() == MouseEvent.CTRL_DOWN_MASK) {
            vv.getRenderContext()
                    .getMultiLayerTransformer()
                    .getTransformer(Layer.LAYOUT)
                    .scale(1 + (e.getWheelRotation() * zoom_factor),
                            1 + (e.getWheelRotation() * zoom_factor),
                            vv.getCenter());
        }
    }
}

I wanted to automatically update the satellite view relatively to a VisualizationViewer with picking support enabled.

I have finally adopted another solution: no automatic update of the satellite view but a pan using mouse button 2, and a zoom using CTRL+Mouse_Wheel.

Here is the class, it may be helpful... :

public class SatelliteVisualizationViewerMouseControler implements
        MouseListener, MouseMotionListener, MouseWheelListener {

    private SatelliteVisualizationViewer<SVertex, PEdge> vv;
    private Point drag_point;
    private double zoom_factor = 0.1;

    public SatelliteVisualizationViewerMouseControler(
            SatelliteVisualizationViewer<SVertex, PEdge> vv) {
        this.vv = vv;
    }

    @Override
    public void mouseDragged(MouseEvent e) {
        if (drag_point != null) {
            Point2D l_drag_point = vv.getRenderContext()
                .getMultiLayerTransformer()
                .inverseTransform(Layer.LAYOUT, drag_point);

        Point2D l_e_point = vv.getRenderContext()
                .getMultiLayerTransformer()
                .inverseTransform(Layer.LAYOUT, e.getPoint());

        double delta_x = l_e_point.getX() - l_drag_point.getX();
        double delta_y = l_e_point.getY() - l_drag_point.getY();

        double scale = vv.getRenderContext().getMultiLayerTransformer()
                .getTransformer(Layer.VIEW).getScale();

        vv.getRenderContext().getMultiLayerTransformer()
                .getTransformer(Layer.LAYOUT)
                .translate(delta_x * (1 / scale), delta_y * (1 / scale));

        drag_point = e.getPoint();
        }
    }

    @Override
    public void mouseMoved(MouseEvent e) {
    }

    @Override
    public void mouseClicked(MouseEvent e) {
    }

    @Override
    public void mouseEntered(MouseEvent e) {
    }

    @Override
    public void mouseExited(MouseEvent e) {
    }

    @Override
    public void mousePressed(MouseEvent e) {
        if (e.getButton() == MouseEvent.BUTTON2) {
            drag_point = e.getPoint();
        }
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        if (e.getButton() == MouseEvent.BUTTON2) {
            drag_point = null;
        }
    }

    @Override
    public void mouseWheelMoved(MouseWheelEvent e) {
        if (e.getModifiersEx() == MouseEvent.CTRL_DOWN_MASK) {
            vv.getRenderContext()
                    .getMultiLayerTransformer()
                    .getTransformer(Layer.LAYOUT)
                    .scale(1 + (e.getWheelRotation() * zoom_factor),
                            1 + (e.getWheelRotation() * zoom_factor),
                            vv.getCenter());
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文