java - Rectangular selection JFreeChart -


i try rectangular selection in xylinechart mousepressed, mousedragged , mousereleased. so, when push button, allows me action:

private deltaonareaselected d; d = new deltaonareaselected(this); monchartpanel.addmouselistener(d); monchartpanel.addmousemotionlistener(d); 

and now, here deltaonareaselected class called push button:

public class deltaonareaselected implements mousemotionlistener, mouselistener{  private spectrumcontroller control;   private chartpanel panel; private jfreechart chart; private spectrumpanel specpanel; private spectrumdataset dataset; private rectangle selection; private point anchor; private double freqmin = double.nan; private double freqmax = double.nan; private double powermin = double.nan; private double powermax = double.nan; private double powerpointmin = double.nan; private double powerpointmax = double.nan; private graphics2d g2d;      public deltaonareaselected(spectrumcontroller c){         control = c;         panel = c.getspectrumchartpanel().getchartpanel();         chart = c.getspectrumchartpanel().getchartpanel().getchart();         specpanel = c.getspectrumpanel();         dataset = c.getspectrumchartpanel().getspectrumdataset();     }      private double getpositionfreq(mouseevent e){         point2d p = panel.translatescreentojava2d(e.getpoint());         rectangle2d plotarea = panel.getscreendataarea();         xyplot plot = (xyplot) chart.getplot();          return plot.getdomainaxis().java2dtovalue(p.getx(), plotarea, plot.getdomainaxisedge());     }      private double getpositionpower(mouseevent e){         point2d p = panel.translatescreentojava2d(e.getpoint());         rectangle2d plotarea = panel.getscreendataarea();         xyplot plot = (xyplot) chart.getplot();          return plot.getrangeaxis().java2dtovalue(p.gety(), plotarea, plot.getrangeaxisedge());     }      @override     public void mousepressed(mouseevent e) {         freqmin = getpositionfreq(e);         powermax = getpositionpower(e);         anchor = e.getpoint();         selection = new rectangle(anchor);         g2d = (graphics2d)panel.getgraphics();     }      @override     public void mousedragged(mouseevent e) {         selection.setbounds( (int)math.min(anchor.x,e.getx()), (int)math.min(anchor.y,e.gety()),                 (int)math.abs(e.getx()-anchor.x), (int)math.abs(e.gety()-anchor.y));         if (selection!=null){             g2d.setcolor(color.red);             g2d.draw(selection);         }         panel.repaint();     }      @override     public void mousereleased(mouseevent e) {         freqmax = getpositionfreq(e);         powermin = getpositionpower(e);         selection = null;         panel.repaint();          powerpointmin = dataset.getcurvedata().getminy(freqmin, freqmax, powermin, powermax).gety();         powerpointmax = dataset.getcurvedata().getmaxy(freqmin, freqmax, powermin, powermax).gety();          //round variables @ 3 numbers         bigdecimal centerfreq = new bigdecimal((freqmax + freqmin)/2);         centerfreq = centerfreq.setscale(3, bigdecimal.round_down);         bigdecimal deltafreq = new bigdecimal(freqmax-freqmin);         deltafreq = deltafreq.setscale(3, bigdecimal.round_down);         bigdecimal deltapower = new bigdecimal(powerpointmax-powerpointmin);         deltapower = deltapower.setscale(3, bigdecimal.round_down);          //display delta on area selected         specpanel.getinfopanel().getdeltaonareatext()                 .settext("delta on area selected : \n"                         + "center freq. (hz) : " + centerfreq.doublevalue() + "\n"                         + "delta freq. (hz) : " + deltafreq.doublevalue() + "\n"                         + "delta power (db) : " + deltapower.doublevalue());         specpanel.getinfopanel().getdeltaonareatext().setvisible(true);     }      @override     public void mouseexited(mouseevent e){         panel.removemouselistener(this);         panel.removemousemotionlistener(this);     }      @override     public void mousemoved(mouseevent e) {}     @override     public void mouseclicked(mouseevent e) {}     @override     public void mouseentered(mouseevent e) {} } 

my problem rectangle displayed jerky , doesn't stay release mouse. have idea me?

thank you!


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -