I have created the following class:

public class DisegnaPoligono extends DrawPolygonTool {

        /** Nome Plugin  */
    public final static String NAME = "Nuovo Poligono";

    /** Icona Plugin */
    public final static Icon ICON = IconLoader.icon("DrawPolygon.gif");

    public String getName() {
        return NAME;
    }

    public Icon getIcon() {
        return ICON;
    }   
        
        protected DisegnaPoligono(FeatureDrawingUtil featureDrawingUtil) 
        {
         super(featureDrawingUtil);
        }       
        
        public static CursorTool create( LayerNamePanelProxy 
layerNamePanelProxy ) 
        {
        FeatureDrawingUtil featureDrawingUtil = new 
FeatureDrawingUtil(layerNamePanelProxy);
        return featureDrawingUtil.prepare(new 
DisegnaPoligono(featureDrawingUtil), true);
    }

    protected void gestureFinished() throws Exception 
    {
        reportNothingToUndoYet();
       
        String message 
=createEnableCheck(getWorkbench().getContext(),this).check(null);
       
        if(message != null)
        {
            getWorkbench().getFrame().warnUser(message);
            return;
        }

        if (!checkPolygon()) {
            return;
        }

        // Here an add edit transaction is created, you can get the drawed 
polygon with the method getPolygon()
        featureDrawingUtil.drawRing(getPolygon(),isRollingBackInvalidEdits(), 
this, getPanel());

       // If you want to open a custom dialog or something else, change the 
previous line and open your dialog
       // After that, if the dialog has finished correctly, add your feature to 
the editable layer.
    }


}

where I put the code lines that you have sended me 

" DelegatingTool delPolygonTool = (DelegatingTool) 
MyCursorTool.create(toolbox.getContext());
drawPolygonTool = (MyCursorTool) delPolygonTool.getDelegate();
context.getWorkbenchFrame().getToolBar().addCursorTool(drawPolygonTool.getName(),
 
delPolygonTool,
                
MyCursorTool.createEnableCheck(context.getWorkbenchContext(),drawPolygonTool));"

to associate the button to the toolbar




Message: 3
Date: Mon, 28 Apr 2008 11:54:18 +0200
From: Sergio Baños Calvo <[EMAIL PROTECTED]>
Subject: Re: [Kosmo] R: Resumen de Kosmo, Vol 24, Envío 31 (Extending
        the drawPolygon tool)
To: Lista de Kosmo <[email protected]>
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Good morning Giovanni.

I think there is a concept that should be clarified:

PlugIns -> Menu items and toolbar buttons that executes an action
Tools -> Activates a cursor with an associated funcionality

In the example that you sent the two concepts are mixed in one. The 
functionality that you're trying to develop uses a cursor to draw the 
polygon, so a tool should be used. You should change your code and 
redefine only the methods getName() and getIcon() (to use the ones that 
you have indicated) and the gestureFinished() and create() methods:

    public static CursorTool create( LayerNamePanelProxy 
layerNamePanelProxy ) {
        FeatureDrawingUtil featureDrawingUtil = new 
FeatureDrawingUtil(layerNamePanelProxy);

        return featureDrawingUtil.prepare(new 
MyCursorTool(featureDrawingUtil), true);
    }

    protected void gestureFinished() throws Exception {
        reportNothingToUndoYet();
       
        String message = 
createEnableCheck(getWorkbench().getContext(),this).check(null);
       
        if(message != null)
        {
            getWorkbench().getFrame().warnUser(message);
            return;
        }

        if (!checkPolygon()) {
            return;
        }

        // Here an add edit transaction is created, you can get the 
drawed polygon with the method getPolygon()
        featureDrawingUtil.drawRing(getPolygon(), 
isRollingBackInvalidEdits(), this, getPanel());

       // If you want to open a custom dialog or something else, change 
the previous line and open your dialog
       // After that, if the dialog has finished correctly, add your 
feature to the editable layer.
    }

Your class must only extend the DrawPolygonTool class and must no 
implement PlugIn.

In order to add the tool to the main toolbar, use this:

DelegatingTool delPolygonTool = (DelegatingTool) 
MyCursorTool.create(toolbox.getContext());
drawPolygonTool = (MyCursorTool) delPolygonTool.getDelegate();
context.getWorkbenchFrame().getToolBar().addCursorTool(drawPolygonTool.getName(),
 
delPolygonTool,
                
MyCursorTool.createEnableCheck(context.getWorkbenchContext(),drawPolygonTool));

Hope this helps.

Regards,

_______________________________________________
Kosmo mailing list
[email protected]
http://lists.saig.es/mailman/listinfo/kosmo

Responder a