Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[udig-devel] button selection listener : call modal tool

Dear all,

 

I would like to add a button in a viewpart which draw a polygon. I've implemented a modal tool and I don't know how to call it in the button's selection listener.

 

My tool is:

public class DrawRectangleTool extends AbstractModalTool implements ModalTool {

 

      public static String ID = "mytools.datamanager.drawRectangle";

      private Point start;

      DrawShapeCommand draw = new DrawShapeCommand();

      public Coordinate startCoord;

      public Coordinate endCoord;

 

 

      /**

       *

       */

      public DrawRectangleTool() {

            draw.setFill(new Color(Color.ORANGE.getRed(),

                        Color.ORANGE.getGreen(), Color.ORANGE.getBlue(), 50));

      }

 

      /**

       * @param targets

       */

      public DrawRectangleTool(int targets) {

            super(targets);

            draw.setFill(new Color(Color.ORANGE.getRed(),

                        Color.ORANGE.getGreen(), Color.ORANGE.getBlue(), 50));

      }

 

      public void onMousePressed(MapMouseEvent e) {

            start = e.getPoint();

            draw.setValid(true);

            draw.setShape(new Rectangle(start.x, start.y, 0, 0));

            getContext().sendASyncCommand(draw);

 

      }

 

      public void mouseDragged(MapMouseEvent e) {

            if (start == null) {

                  mousePressed(e);

                  return;

            }

            draw.setShape(new Rectangle(Math.min(start.x, e.x),

                        Math.min(start.y, e.y), Math.abs(e.x - start.x), Math

                        .abs(start.y - e.y)));

            context.getViewportPane().repaint();

      }

 

      public void mouseReleased(MapMouseEvent e) {

            startCoord = getContext().pixelToWorld(start.x, start.y);

            endCoord = getContext().pixelToWorld(e.x, e.y);

            draw.setValid(false);       

      }

}

 

My listener is:

        polygonButton.addSelectionListener(new SelectionListener() {

                 

                  @Override

                  public void widgetSelected(SelectionEvent e) {

                        Tool modalTool = ApplicationGIS.getToolManager().findTool(DrawRectangleTool.ID);

                        modalTool.setEnabled(true); 

                  }

                 

                  @Override

                  public void widgetDefaultSelected(SelectionEvent e) {                       

                  }

            });

 

I hope you could help me.

Thanks.

 

Best regards,

 

Virginie BERRE - Ingénieur d'études et de développement

+33 (0)1 30 15 40 58 (n° direct)

virginie.berre@xxxxxxxxxxxx


ZA Les Erables - bâtiment 4

66, route de Sartrouville
78230 Le Pecq
Tel: +33 (0)1 30 15 40 50 (standard)
Fax: +33 (0)1 30 15 40 60
www.magellium.fr

MAGELLIUM

MAGELLIUMPensez environnement ! N'imprimez ce mail que si c'est vraiment nécessaire !

 


Back to the top