ShapeCreatedEvent

This type of event is posted when a shape is created in one of the windows. A typical example would be when a polyline has been drawn in a map view for specifying an arbitrary path.

The following example shows how to implement a listener that looks for polyline creation on map views, extract the coordinates in Inline/Xline domain and print them into a JTextPane jTextPane1.

        public void onEvent(EventObject evt) {
        if (evt instanceof ShapeCreatedEvent) {
            Object source = evt.getSource();
            cgShape shape = ((ShapeCreatedEvent) evt).getShape();
            if (!(shape instanceof cgPolyline)) {
                return;
            }
            if (source instanceof ILayer2D) {
                ILayer2D layer = (ILayer2D) source;
                ILayeredWindow window = layer.getViewerWindow();
                if (window instanceof IMapWindow) {
                    IMapWindow mapWindow = (IMapWindow) window;
                    cgPolyline polyline = (cgPolyline) shape;
                    double xValues[] = polyline.getXValues();
                    double yValues[] = polyline.getYValues();
                    if (mapWindow.getDisplayMode() == IMapWindow.XY) {
                        // transform to IJ if map is in XY
                        IJToXYTransformation tr = mapWindow.getIJToXYTransformation();
                        if (tr == null || !tr.isValidCoordMatrix()) {
                            return;
                        }
                        double tValues[];
                        for (int i=0; i<xValues.length; i++) {
                            tValues = tr.invCoordTrans(xValues[i], yValues[i]);
                            xValues[i] = tValues[0];
                            yValues[i] = tValues[1];
                        }
                    }
                    // print the values into a text pane
                    String buffer = "";
                    for (int i=0; i<xValues.length; i++) {
                        buffer += xValues[i] + " " + yValues[i] + "\n";
                    }
                    jTextPane1.setText(buffer);
                }
            }
        }
    }