Changeset 7804 for trunk/projects/slim-plugin/src
- Timestamp:
- 11/11/11 15:21:12 (8 years ago)
- Location:
- trunk/projects/slim-plugin/src/main/java/loci/slim
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/projects/slim-plugin/src/main/java/loci/slim/SLIMProcessor.java
r7740 r7804 249 249 uiPanel.setX(0); 250 250 uiPanel.setY(0); 251 uiPanel.setStart(m_timeBins / 2 ); //TODO hokey252 uiPanel.setStop(m_timeBins - 1 );251 uiPanel.setStart(m_timeBins / 2, false); //TODO hokey 252 uiPanel.setStop(m_timeBins - 1, false); 253 253 uiPanel.setThreshold(100); 254 254 uiPanel.setFunctionParameters(0, DEFAULT_SINGLE_EXP_PARAMS); … … 272 272 m_cancel = true; 273 273 } 274 275 /** 276 * Triggers refit of current pixel. 277 */ 278 public void doPixelFit() { 279 // ordinarily these fits take place in the thread at the end 280 // of this method. 281 // this is a hack until I refactor out a FittingEngine. 282 fitPixel(uiPanel); 283 } 284 274 285 /** 275 286 * Quits running plugin. … … 342 353 getFitSettings(m_grayScaleImage, uiPanel); 343 354 // fit on the pixel clicked 344 fitPixel(uiPanel , x, y);355 fitPixel(uiPanel); 345 356 } 346 357 } … … 405 416 406 417 int[] results = CursorHelper.estimateDecayCursors(m_timeRange, decay); 407 uiPanel.setStart(results[0] );408 uiPanel.setStop(results[1] );418 uiPanel.setStart(results[0], false); 419 uiPanel.setStop(results[1], false); 409 420 } 410 421 … … 438 449 excitation.setBase(results[2]); 439 450 440 uiPanel.setStart((int) results[3] );441 uiPanel.setStop((int) results[4] );451 uiPanel.setStart((int) results[3], false); 452 uiPanel.setStop((int) results[4], false); 442 453 443 454 m_excitationPanel = new ExcitationPanel(excitation); … … 837 848 setFittedParamsFromData(resultsCursor, dataArray); 838 849 return fittedPixels; 850 } 851 852 // added kludge to make moving cursors in DecayGraph do a refit. 853 private Image<DoubleType> fitPixel(IUserInterfacePanel uiPanel) { 854 int x = uiPanel.getX(); 855 int y = uiPanel.getY(); 856 m_startBin = uiPanel.getStart(); 857 m_stopBin = uiPanel.getStop(); 858 return fitPixel(uiPanel, x, y); 839 859 } 840 860 … … 1552 1572 * @param data fitted data 1553 1573 */ 1554 private void showDecayGraph(String title, final IUserInterfacePanel uiPanel, double irf[], ICurveFitData data) { 1555 DecayGraph decayGraph = new DecayGraph(title, m_startBin, m_stopBin, m_timeBins, m_timeRange, irf, data); 1574 private void showDecayGraph(final String title, final IUserInterfacePanel uiPanel, final double irf[], final ICurveFitData data) { 1575 loci.slim.refactor.ui.charts.IDecayGraph decayGraph = loci.slim.refactor.ui.charts.DecayGraph.getInstance(); 1576 JFrame frame = decayGraph.init(uiPanel.getFrame(), m_timeBins, m_timeRange); 1577 decayGraph.setTitle(title); 1578 int start = uiPanel.getStart(); 1579 int stop = uiPanel.getStop(); 1580 decayGraph.setStartStop(start, stop); 1581 decayGraph.setData(irf, data); 1556 1582 decayGraph.setStartStopListener( 1557 1583 new IStartStopListener() { 1558 1584 public void setStartStop(int start, int stop) { 1559 uiPanel.setStart(start );1560 uiPanel.setStop(stop );1585 uiPanel.setStart(start, false); 1586 uiPanel.setStop(stop, true); // do a refit 1561 1587 } 1562 1588 } 1563 1589 ); 1564 JFrame frame = decayGraph.getFrame();1565 frame.setLocationRelativeTo(uiPanel.getFrame());1566 frame.setVisible(true);1567 //TODO focus listener could show fit parameters in UI as you click on decay graph1568 /*frame.addFocusListener(1569 new FocusListener() {1570 public void focusGained(FocusEvent e) {1571 //System.out.println("focus gained " + e);1572 }1573 public void focusLost(FocusEvent e) {1574 }1575 });*/1576 1590 } 1577 1591 } -
trunk/projects/slim-plugin/src/main/java/loci/slim/refactor/ui/charts/DecayGraph.java
r7796 r7804 69 69 * @author Aivar Grislis 70 70 */ 71 public class DecayGraph implements /*IDecayGraph,*/IStartStopProportionListener {71 public class DecayGraph implements IDecayGraph, IStartStopProportionListener { 72 72 static final Dimension SIZE = new Dimension(500, 270); 73 static final Dimension FRAME_SIZE = new Dimension(450, 450); 73 74 static final String PHOTON_AXIS_LABEL = "Photons"; 74 75 static final String TIME_AXIS_LABEL = "Time"; … … 89 90 IStartStopListener _startStopListener; 90 91 91 92 92 private StartStopDraggingUI<JComponent> _startStopDraggingUI; 93 93 private double _timeInc; … … 95 95 private Integer _start; 96 96 private Integer _stop; 97 98 99 97 private boolean _logarithmic = true; 100 98 101 102 103 104 105 //boolean _headless = false;106 99 XYPlot _decaySubPlot; 107 100 XYSeriesCollection _decayDataset; 108 101 XYSeriesCollection _residualDataset; 109 //static ChartPanel _panel;110 102 111 103 JFreeChart m_decayChart; … … 116 108 */ 117 109 public DecayGraph() { 110 _frame = null; 118 111 } 119 112 … … 123 116 * @return singleton instance 124 117 */ 125 public s ynchronized DecayGraph getInstance() {118 public static synchronized DecayGraph getInstance() { 126 119 if (null == _instance) { 127 120 _instance = new DecayGraph(); … … 129 122 return _instance; 130 123 } 124 125 /** 126 * Sets up a listener to listen for start/stop changes. 127 * 128 * @param startStopListener 129 */ 130 public void setStartStopListener(IStartStopListener startStopListener) { 131 _startStopListener = startStopListener; 132 } 131 133 132 134 /** 133 135 * Initialize the graph and returns the containing JFrame. 134 136 * 135 * @param title136 137 * @param bins 137 138 * @param timeInc 138 139 * @return frame 139 140 */ 140 public JFrame init(final String title, final int bins, final double timeInc) { 141 _bins = bins; 142 _timeInc = timeInc; 143 144 // create the combined chart 145 JFreeChart chart = createCombinedChart(bins, timeInc); 146 ChartPanel panel = new ChartPanel(chart, true, true, true, false, true); 147 panel.setDomainZoomable(false); 148 panel.setRangeZoomable(false); 149 panel.setPreferredSize(SIZE); 150 151 // add start/stop vertical bar handling 152 _start = _stop = null; 153 JXLayer<JComponent> layer = new JXLayer<JComponent>(panel); 154 _startStopDraggingUI = 155 new StartStopDraggingUI<JComponent>(panel, _decaySubPlot, this); 156 layer.setUI(_startStopDraggingUI); 157 158 // create a frame for the chart 159 _frame = new JFrame(title); 160 _frame.getContentPane().add(layer); 161 _frame.setSize(450, 450); 162 _frame.pack(); 163 141 public JFrame init(final JFrame frame, final int bins, final double timeInc) { 142 boolean create = false; 143 if (null == _frame 144 || !_frame.isVisible() 145 || _bins != bins 146 || _timeInc != timeInc) 147 { 148 // save incoming parameters 149 _bins = bins; 150 _timeInc = timeInc; 151 152 if (null != _frame) { 153 // delete existing frame 154 _frame.setVisible(false); 155 _frame.dispose(); 156 } 157 158 // create the combined chart 159 JFreeChart chart = createCombinedChart(bins, timeInc); 160 ChartPanel panel = new ChartPanel 161 (chart, true, true, true, false, true); 162 panel.setDomainZoomable(false); 163 panel.setRangeZoomable(false); 164 panel.setPreferredSize(SIZE); 165 166 // add start/stop vertical bar handling 167 _start = _stop = null; 168 JXLayer<JComponent> layer = new JXLayer<JComponent>(panel); 169 _startStopDraggingUI = 170 new StartStopDraggingUI<JComponent> 171 (panel, _decaySubPlot, this); 172 layer.setUI(_startStopDraggingUI); 173 174 // create a frame for the chart 175 _frame = new JFrame(); 176 _frame.getContentPane().add(layer); 177 _frame.setSize(FRAME_SIZE); 178 _frame.pack(); 179 _frame.setLocationRelativeTo(frame); 180 _frame.setVisible(true); 181 } 164 182 return _frame; 183 } 184 185 public void setTitle(final String title) { 186 _frame.setTitle(title); 165 187 } 166 188 … … 172 194 */ 173 195 public void setData(final double[] irf, ICurveFitData data) { 196 createDatasets(10, 200, _bins, _timeInc, irf, data); 174 197 175 198 } … … 187 210 double stopValue = stop * _timeInc; 188 211 double maxValue = _bins * _timeInc; 189 _startStopDraggingUI.setStartStopValues(startValue, stopValue, maxValue); //TODO Get maxValue out of here 212 _startStopDraggingUI.setStartStopValues 213 (startValue, stopValue, maxValue); 190 214 } 191 215 … … 203 227 * @param stopProportion 204 228 */ 205 public void setStartStopProportion(double startProportion, double stopProportion) { 229 public void setStartStopProportion 230 (double startProportion, double stopProportion) 231 { 206 232 // calculate new start and stop 207 233 int start = (int) (startProportion * _bins + 0.5); … … 249 275 decayRenderer.setSeriesShapesVisible(1, false); 250 276 decayRenderer.setSeriesLinesVisible(2, false); 251 decayRenderer.setSeriesShape(2, new Ellipse2D.Float(2.0f, 2.0f, 2.0f, 2.0f)); 277 decayRenderer.setSeriesShape 278 (2, new Ellipse2D.Float(2.0f, 2.0f, 2.0f, 2.0f)); 252 279 253 280 decayRenderer.setSeriesPaint(0, IRF_COLOR); … … 255 282 decayRenderer.setSeriesPaint(2, DECAY_COLOR); 256 283 257 _decaySubPlot = new XYPlot(_decayDataset, null, photonAxis, decayRenderer); 284 _decaySubPlot = new XYPlot 285 (_decayDataset, null, photonAxis, decayRenderer); 258 286 _decaySubPlot.setDomainCrosshairVisible(true); 259 287 _decaySubPlot.setRangeCrosshairVisible(true); … … 267 295 residualRenderer.setSeriesShapesVisible(0, false); 268 296 residualRenderer.setSeriesPaint(0, RESIDUAL_COLOR); 269 XYPlot residualSubPlot = new XYPlot(_residualDataset, null, residualAxis, residualRenderer); 297 XYPlot residualSubPlot = new XYPlot 298 (_residualDataset, null, residualAxis, residualRenderer); 270 299 residualSubPlot.setDomainCrosshairVisible(true); 271 300 residualSubPlot.setRangeCrosshairVisible(true); … … 276 305 277 306 // now make the top level JFreeChart 278 JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, parent, true); 307 JFreeChart chart = new JFreeChart 308 (null, JFreeChart.DEFAULT_TITLE_FONT, parent, true); 279 309 chart.removeLegend(); 280 310 … … 291 321 * @param data from the fit 292 322 */ 293 private void createDatasets(int start, int stop, int bins, double timeInc, double[] irf, ICurveFitData data) { 294 323 private void createDatasets(int start, int stop, int bins, double timeInc, 324 double[] irf, ICurveFitData data) 325 { 295 326 XYSeries series1 = new XYSeries("IRF"); 296 327 double xCurrent = 0; … … 319 350 series3.add(xCurrent, (yData > 0.0 ? yData : null)); 320 351 // are we in fitted region? 321 if ( start <= i && i <=stop) {352 if (_start <= i && i <= _stop) { 322 353 // yes, show fitted curve and residuals 323 354 yFitted = data.getYFitted()[i]; … … 339 370 } 340 371 372 _decayDataset.removeAllSeries(); 341 373 _decayDataset.addSeries(series1); 342 374 _decayDataset.addSeries(series2); 343 375 _decayDataset.addSeries(series3); 344 376 377 _residualDataset.removeAllSeries(); 345 378 _residualDataset.addSeries(series4); 346 379 } … … 352 385 * @param <V> component 353 386 */ 354 static class StartStopDraggingUI<V extends JComponent> extends AbstractLayerUI<V> { 387 static class StartStopDraggingUI<V extends JComponent> 388 extends AbstractLayerUI<V> 389 { 355 390 private static final int CLOSE_ENOUGH = 4; // pizels 356 391 private ChartPanel _panel; … … 359 394 boolean _draggingStartMarker = false; 360 395 boolean _draggingStopMarker = false; 361 private double _startMarkerProportion = 0.25;362 private double _stopMarkerProportion = 0.75;396 private Double _startMarkerProportion; 397 private Double _stopMarkerProportion; 363 398 private int _y0; 364 399 private int _y1; … … 373 408 * @param listener to be notified when user drags start/stop vertical bars 374 409 */ 375 StartStopDraggingUI(ChartPanel panel, XYPlot plot, IStartStopProportionListener listener) { 410 StartStopDraggingUI(ChartPanel panel, XYPlot plot, 411 IStartStopProportionListener listener) 412 { 376 413 _panel = panel; 377 414 _plot = plot; 378 415 _listener = listener; 379 } 380 381 void setStartStopValues(double startValue, double stopValue, double maxValue) { 416 _startMarkerProportion = null; 417 _stopMarkerProportion = null; 418 } 419 420 void setStartStopValues 421 (double startValue, double stopValue, double maxValue) 422 { 382 423 Rectangle2D area = getDataArea(); 383 424 double x = area.getX(); … … 390 431 double minRepresentedValue = screenToValue((int) x); 391 432 double maxRepresentedValue = screenToValue((int) (x + width)); 392 _startMarkerProportion = (float) (startValue - minRepresentedValue) / (maxRepresentedValue - minRepresentedValue); 393 _stopMarkerProportion = (float) (stopValue - minRepresentedValue) / (maxRepresentedValue - minRepresentedValue); 433 _startMarkerProportion = 434 (float) (startValue - minRepresentedValue) / 435 (maxRepresentedValue - minRepresentedValue); 436 _stopMarkerProportion = 437 (float) (stopValue - minRepresentedValue) / 438 (maxRepresentedValue - minRepresentedValue); 394 439 } 395 440 } … … 407 452 // this paints layer as is 408 453 super.paintLayer(g2D, layer); 409 410 // adjust to current size 411 Rectangle2D area = getDataArea(); 412 double x = area.getX(); 413 _y0 = (int) area.getY(); 414 _y1 = (int) (area.getY() + area.getHeight()); 415 double width = area.getWidth(); 416 _xStart = (int) Math.round(x + width * _startMarkerProportion) + HORZ_TWEAK; 417 _xStop = (int) Math.round(x + width * _stopMarkerProportion) + HORZ_TWEAK; 418 419 // custom painting is here 420 g2D.setStroke(new BasicStroke(2f)); 421 g2D.setXORMode(XORvalue(START_COLOR)); 422 g2D.drawLine(_xStart, _y0, _xStart, _y1); 423 g2D.setXORMode(XORvalue(STOP_COLOR)); 424 g2D.drawLine(_xStop, _y0, _xStop, _y1); 454 455 if (null != _startMarkerProportion && null != _stopMarkerProportion) { 456 // adjust to current size 457 Rectangle2D area = getDataArea(); 458 double x = area.getX(); 459 _y0 = (int) area.getY(); 460 _y1 = (int) (area.getY() + area.getHeight()); 461 double width = area.getWidth(); 462 _xStart = (int) Math.round(x + width * _startMarkerProportion) 463 + HORZ_TWEAK; 464 _xStop = (int) Math.round(x + width * _stopMarkerProportion) 465 + HORZ_TWEAK; 466 467 // custom painting is here 468 g2D.setStroke(new BasicStroke(2f)); 469 g2D.setXORMode(XORvalue(START_COLOR)); 470 g2D.drawLine(_xStart, _y0, _xStart, _y1); 471 g2D.setXORMode(XORvalue(STOP_COLOR)); 472 g2D.drawLine(_xStop, _y0, _xStop, _y1); 473 } 425 474 } 426 475 … … 431 480 * @param layer 432 481 */ 433 protected void processMouseMotionEvent(MouseEvent event, JXLayer<? extends V> layer) { 482 protected void processMouseMotionEvent 483 (MouseEvent event, JXLayer<? extends V> layer) 484 { 434 485 super.processMouseMotionEvent(event, layer); 435 486 if (event.getID() == MouseEvent.MOUSE_DRAGGED) { … … 466 517 */ 467 518 private double getDraggedProportion(MouseEvent e) { 468 Rectangle2D dataArea = _panel.getChartRenderingInfo().getPlotInfo().getDataArea(); 519 Rectangle2D dataArea = 520 _panel.getChartRenderingInfo().getPlotInfo().getDataArea(); 469 521 Rectangle2D area = getDataArea(); 470 522 double proportion = (e.getX() - area.getX()) / area.getWidth(); … … 485 537 protected void processMouseEvent(MouseEvent e, JXLayer<? extends V> l) { 486 538 super.processMouseEvent(e, l); 487 if (e.getID() == MouseEvent.MOUSE_PRESSED) { 488 int x = e.getX(); 489 int y = e.getY(); 490 if (y > _y0 - CLOSE_ENOUGH && y < _y1 + CLOSE_ENOUGH) { 491 if (Math.abs(x - _xStart) < CLOSE_ENOUGH) { 492 // start dragging start line 493 _draggingStartMarker = true; 494 495 } 496 else if (Math.abs(x - _xStop) < CLOSE_ENOUGH) { 497 // start dragging stop line 498 _draggingStopMarker = true; 539 if (null != _startMarkerProportion && null != _stopMarkerProportion) { 540 if (e.getID() == MouseEvent.MOUSE_PRESSED) { 541 int x = e.getX(); 542 int y = e.getY(); 543 if (y > _y0 - CLOSE_ENOUGH && y < _y1 + CLOSE_ENOUGH) { 544 if (Math.abs(x - _xStart) < CLOSE_ENOUGH) { 545 // start dragging start line 546 _draggingStartMarker = true; 547 548 } 549 else if (Math.abs(x - _xStop) < CLOSE_ENOUGH) { 550 // start dragging stop line 551 _draggingStopMarker = true; 552 } 499 553 } 500 554 } 501 } 502 if (e.getID() == MouseEvent.MOUSE_RELEASED) { 503 _draggingStartMarker = _draggingStopMarker = false; 504 SwingUtilities.invokeLater( 505 new Runnable() { 506 public void run() { 507 _listener.setStartStopProportion(_startMarkerProportion, _stopMarkerProportion); 508 } 509 }); 555 if (e.getID() == MouseEvent.MOUSE_RELEASED) { 556 _draggingStartMarker = _draggingStopMarker = false; 557 SwingUtilities.invokeLater( 558 new Runnable() { 559 public void run() { 560 if (null != _listener) { 561 _listener.setStartStopProportion 562 (_startMarkerProportion, 563 _stopMarkerProportion); 564 } 565 } 566 }); 567 } 510 568 } 511 569 } … … 517 575 */ 518 576 private Rectangle2D getDataArea() { 519 Rectangle2D dataArea = _panel.getChartRenderingInfo().getPlotInfo().getDataArea(); 577 Rectangle2D dataArea = 578 _panel.getChartRenderingInfo().getPlotInfo().getDataArea(); 520 579 return dataArea; 521 580 } … … 529 588 530 589 private double screenToValue(int x) { 531 return _plot.getDomainAxis().java2DToValue((double) x, getDataArea(), RectangleEdge.TOP); 590 return _plot.getDomainAxis().java2DToValue( 591 (double) x, getDataArea(), RectangleEdge.TOP); 532 592 } 533 593 } … … 540 600 */ 541 601 interface IStartStopProportionListener { 542 public void setStartStopProportion(double startProportion, double stopProportion); 602 public void setStartStopProportion 603 (double startProportion, double stopProportion); 543 604 } -
trunk/projects/slim-plugin/src/main/java/loci/slim/ui/IUserInterfacePanel.java
r7668 r7804 123 123 * 124 124 * @param bin 125 */ 126 public void setStart(int bin); 125 * @param refit 126 */ 127 public void setStart(int bin, boolean refit); 127 128 128 129 /** … … 137 138 * 138 139 * @param bin 139 */ 140 public void setStop(int bin); 140 * @param refit 141 */ 142 public void setStop(int bin, boolean refit); 143 141 144 142 145 /** -
trunk/projects/slim-plugin/src/main/java/loci/slim/ui/IUserInterfacePanelListener.java
r7671 r7804 51 51 */ 52 52 public void cancelFit(); 53 54 /** 55 * Triggers a refit of current pixel. 56 */ 57 public void doPixelFit(); 53 58 54 59 /** -
trunk/projects/slim-plugin/src/main/java/loci/slim/ui/UserInterfacePanel.java
r7697 r7804 998 998 } 999 999 1000 public void setStart(int start ) {1000 public void setStart(int start, boolean refit) { 1001 1001 m_startField.setText("" + start); 1002 if (refit && null != m_listener) { 1003 m_listener.doPixelFit(); 1004 } 1002 1005 } 1003 1006 … … 1006 1009 } 1007 1010 1008 public void setStop(int stop ) {1011 public void setStop(int stop, boolean refit) { 1009 1012 m_stopField.setText("" + stop); 1013 if (refit && null != m_listener) { 1014 m_listener.doPixelFit(); 1015 } 1010 1016 } 1011 1017
Note: See TracChangeset
for help on using the changeset viewer.