# this more complex script shows how two plotElements can get data from the same source,
# and how jython can be used to render mouse gestures.

from org.das2.graph import ContoursRenderer, SpectrogramRenderer
from org.das2.event import ArrowDragRenderer, DragRenderer,MouseBoxEvent
from org.autoplot import RenderType
reset()

plot( 'vap+inline:ripples(100,100)' )

model = getApplicationModel()

contourPlotElement= addPlotElement(0)

plot( 1, 'vap+inline:ripples(100,100)&RENDER_TYPE=contour>contours=0.5,1,3,5,10,30,50' )  # make it plot the same thing
dom.plotElements[1].style.color= Color.WHITE
dom.plotElements[1].dataSourceFilterId= dom.plotElements[0].dataSourceFilterId
dom.plotElements[1].renderType= RenderType.contour

specRend= dom.plots[0].controller.dasPlot.getRenderer(0)
from org.das2.graph.SpectrogramRenderer import RebinnerEnum
dom.plotElements[0].style.rebinMethod= RebinnerEnum.nearestNeighbor

dom.plots[0].isotropic= True

# custom dragRenderer code draws a line instead of a box
class AngleSelectionDragRenderer(ArrowDragRenderer):
    def renderDrag( self, g, p1, p2 ):
        from java.awt.geom import Line2D
        g.draw( Line2D.Double(p1,p2) )
    def clear(self,g):
        pass
    def getMouseDragEvent( self, src, p1, p2, isModified ):
        return MouseBoxEvent(src,p1,p2,isModified)
        
from org.das2.event import BoxSelectorMouseModule
from org.das2.components import AngleSpectrogramSlicer

plot= dom.plots[0].controller.dasPlot

aSlicer= AngleSpectrogramSlicer.createSlicer(plot,  specRend);
arend=  AngleSelectionDragRenderer();
bsel=  BoxSelectorMouseModule( plot, plot.getXAxis(), plot.getYAxis(), specRend,
                arend,
                "Angle Slice" );
bsel.setDragEvents(True);        
bsel.addBoxSelectionListener( aSlicer );  

dom.plots[0].controller.dasPlot.dasMouseInputAdapter.setPrimaryModule( bsel )

print bsel

