Next: The Viewable: Loading the Up: The Viewer: Getting and Previous: Configuring the ImageDisplayMap Object

### Updating the coordinate display

Now the `ImageDisplayMap` object is up to date, the viewer is ready to display coordinate positions. New positions are displayed whenever the user moves the mouse, so here is the viewer's `mouseMove()` method.

        public boolean mouseMove(Event event, int x, int y) {

            // only handle event if it occurred within the ImageCanvas
            // display; update the position display using a display
            // pixel that is relative to the ImageCanvas display's origin
            if (display == locate(x, y)) {
                Point displayOrigin = display.location();
                updatePosDisplay(x-displayOrigin.x, y-displayOrigin.y);
            }
            return false;
        }

In this method, we pass the display pixel location to a method called `updatePosDisplay()` which does the actual work. Here's what that method looks like:

    protected void updatePosDisplay(int x, int y) {

        if (pixelMap == null) return;

        // First translate the display pixel to a data pixel;
        Voxel dvox = pixelMap.getDataVoxel(new Point(x, y));

        // display the selected data pixel.  Here we will display the
        // the selection as an integer.
        double dxpos = Math.floor(pixelMap.getXDataPos(dvox));
        double dypos = Math.floor(pixelMap.getYDataPos(dvox));
        xDataPos.setText(Double.toString(dxpos));
        yDataPos.setText(Double.toString(dypos));

        // Now translate the data pixels to coordinate positions
        if (coordSys != null) {

            // convert to a coordinate position and display it.
            try {
                CoordPos cpos = coordSys.getCoordPos(dvox);
                xCoordPos.setText(cpos.valueString(slice.getXaxis(), 2));
                yCoordPos.setText(cpos.valueString(slice.getYaxis(), 2));
            }
            catch (CoordTransformException ex) {
                xCoordPos.setText("Undefined");
                yCoordPos.setText("Undefined");
            }
        }
    }