English 中文(简体)
• 如何在联合政府内部进行协调?
原标题:How to get a vertex coordinate in JUNG?

Is there a way to get the vertex coordinate when using the EditingModalGraphMouse in Jung ?? I ve made a class for the vertex with the coordinate setter and getter but i don t kown how to set the vertex with its specific coordinate ? (i ve user a transformer : Transformer)

问题回答

The following gives you an idea on how to obtain the Cartesian coordinates on a Jung VisualizationViewer instance...

创建内部班级如下:

protected class MyGraphMousePlugin extends TranslatingGraphMousePlugin implements MouseListener {

    @Override
    public void mouseMoved(MouseEvent e) {
        final VisualizationViewer<GeoLocationData.Station,GeoLocationData.Link> vv =
        (VisualizationViewer<GeoLocationData.Station,GeoLocationData.Link>)e.getSource();
        Point2D p = e.getPoint();//vv.getRenderContext().getBasicTransformer().inverseViewTransform(e.getPoint());
        GraphElementAccessor<GeoLocationData.Station,GeoLocationData.Link> pickSupport = vv.getPickSupport();
        if(pickSupport != null) {               
            vv.setToolTipText ("<html>x: "+p.getX()+"<br>y: "+p.getY());
        }
    }

    public MyGraphMousePlugin(int modifiers) {
        super(modifiers);
        // TODO Auto-generated constructor stub
    }

    public MyGraphMousePlugin() {
        super();
    }
}

添加图象:

graphMouse = new DefaultModalGraphMouse<Object, Object>();
vv.setGraphMouse(graphMouse);
vv.addKeyListener(graphMouse.getModeKeyListener());
graphMouse.add(new MyGraphMousePlugin());

http://www.ohchr.org。

接下来的修改将给你考虑到Jung图表版译文的Cartesian坐标:

protected class MyGraphMousePlugin extends TranslatingGraphMousePlugin implements MouseListener {

    @Override
    public void mouseMoved(final MouseEvent e) {

        SwingUtilities.invokeLater(
                new Runnable() {
                    public void run() {
                        final VisualizationViewer<GeoLocationData.Station,GeoLocationData.Link> vv =
                            (VisualizationViewer<GeoLocationData.Station,GeoLocationData.Link>)e.getSource();
                        Point2D p = e.getPoint();//vv.getRenderContext().getBasicTransformer().inverseViewTransform(e.getPoint());
                        GraphElementAccessor<GeoLocationData.Station,GeoLocationData.Link> pickSupport = vv.getPickSupport();
                        if(pickSupport != null) {

                            AffineTransform lat =
                                vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).getTransform();
                            //AffineTransform vat =
                            //  vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).getTransform();
                            //AffineTransform at = new AffineTransform();

                            double x = p.getX() - lat.getTranslateX(); //;
                            double y = p.getY() - lat.getTranslateY(); //;

                            vv.setToolTipText ("<html>x: "+x+"<br>y: "+y);
                        }

                    }
                }
        );
    }

    public MyGraphMousePlugin(int modifiers) {
        super(modifiers);
        // TODO Auto-generated constructor stub
    }

    public MyGraphMousePlugin() {
        super();
    }
}

这还不是完美的,因为它忽略了比额表因素,但你会提出想法。

你们需要从屏幕协调系统计算,以便把系统协调到模型协调系统,以获得模型坐标。

上述法典中的通用型号应当改为您自己的版本:

<><>Edited>

Haha, the clue is already there and it is the correct way...no need to calculate! http://sourceforge.net/projects/jung/forums/forum/252062/topic/3040266?message=6522779

    @Override
    public void mouseMoved(final MouseEvent e) {

        SwingUtilities.invokeLater(
                new Runnable() {
                    public void run() {
                        final VisualizationViewer<GeoLocationData.Station,GeoLocationData.Link> vv =
                            (VisualizationViewer<GeoLocationData.Station,GeoLocationData.Link>)e.getSource();
                        Point2D p = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(e.getPoint());

                        double x = p.getX();
                        double y = p.getY();

                        vv.setToolTipText ("<html>x: "+(int)x+"<br>y: "+(int)y);
                    }
                }
        );
    }




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签