|
30 | 30 | package sc.fiji.bdvpg.bdv; |
31 | 31 |
|
32 | 32 | import bdv.tools.brightness.ConverterSetup; |
33 | | -import bdv.ui.CardPanel; |
34 | 33 | import bdv.util.BdvFunctions; |
35 | 34 | import bdv.util.BdvHandle; |
| 35 | +import bdv.util.BdvHandleFrame; |
| 36 | +import bdv.util.BdvHandlePanel; |
36 | 37 | import bdv.util.BdvOptions; |
37 | 38 | import bdv.util.BdvOverlay; |
38 | 39 | import bdv.viewer.Source; |
@@ -336,13 +337,19 @@ public static double[] getDisplayRange(ConverterSetup converterSetup) { |
336 | 337 | } |
337 | 338 |
|
338 | 339 | public static JFrame getJFrame(BdvHandle bdvh) { |
| 340 | + if (!(bdvh instanceof BdvHandleFrame)) { |
| 341 | + throw new RuntimeException("The BdvHandle is a Panel, not a Frame"); |
| 342 | + } |
339 | 343 | return (JFrame) SwingUtilities.getWindowAncestor(bdvh.getViewerPanel()); |
340 | 344 | } |
341 | 345 |
|
342 | 346 | public static void setBdvHandleCloseOperation(BdvHandle bdvh, CacheService cs, |
343 | 347 | SourceAndConverterBdvDisplayService bdvsds, boolean putWindowOnTop, |
344 | 348 | Runnable runnable) |
345 | 349 | { |
| 350 | + if (bdvh instanceof BdvHandlePanel) { |
| 351 | + throw new RuntimeException("The BdvHandle is a Panel, not a Frame"); |
| 352 | + } |
346 | 353 | JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(bdvh |
347 | 354 | .getViewerPanel()); |
348 | 355 | WindowAdapter wa; |
@@ -375,38 +382,50 @@ public void windowActivated(WindowEvent e) { |
375 | 382 | topFrame.addWindowListener(wa); |
376 | 383 |
|
377 | 384 | if (putWindowOnTop) { |
378 | | - cs.put("LAST_ACTIVE_BDVH", new WeakReference<>(bdvh));// why a weak |
379 | | - // reference ? |
380 | | - // because we want |
381 | | - // to dispose the |
382 | | - // bdvhandle if it |
383 | | - // is closed |
| 385 | + cs.put("LAST_ACTIVE_BDVH", new WeakReference<>(bdvh));// why a wea kreference ? |
| 386 | + // because we want to dispose the bdvhandle if it is closed |
384 | 387 | } |
385 | 388 | } |
386 | 389 |
|
387 | 390 | public static void activateWindow(BdvHandle bdvh) { |
388 | 391 | JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(bdvh |
389 | 392 | .getViewerPanel()); |
390 | | - topFrame.toFront(); |
391 | | - topFrame.requestFocus(); |
| 393 | + if (topFrame != null) { |
| 394 | + topFrame.toFront(); |
| 395 | + topFrame.requestFocus(); |
| 396 | + } else { |
| 397 | + bdvh.getViewerPanel().requestFocus(); |
| 398 | + } |
392 | 399 | } |
393 | 400 |
|
394 | 401 | public static void closeWindow(BdvHandle bdvh) { |
395 | 402 | JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(bdvh |
396 | 403 | .getViewerPanel()); |
397 | | - topFrame.dispatchEvent(new WindowEvent(topFrame, |
398 | | - WindowEvent.WINDOW_CLOSING)); |
| 404 | + if (topFrame!=null) { |
| 405 | + topFrame.dispatchEvent(new WindowEvent(topFrame, |
| 406 | + WindowEvent.WINDOW_CLOSING)); |
| 407 | + } else { |
| 408 | + System.err.println("Can't close the bdv handle because it is of class "+bdvh.getClass().getName()); |
| 409 | + } |
399 | 410 | } |
400 | 411 |
|
401 | 412 | public static void setWindowTitle(BdvHandle bdvh, String title) { |
402 | 413 | JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(bdvh |
403 | 414 | .getViewerPanel()); |
404 | | - topFrame.setTitle(title); |
| 415 | + if (topFrame!=null) { |
| 416 | + topFrame.setTitle(title); |
| 417 | + } else { |
| 418 | + System.err.println("Can't set the bdv handle window title because it is of class "+bdvh.getClass().getName()); |
| 419 | + } |
405 | 420 | } |
406 | 421 |
|
407 | 422 | public static String getWindowTitle(BdvHandle bdvh) { |
408 | 423 | JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(bdvh |
409 | | - .getViewerPanel()); |
| 424 | + .getViewerPanel()); |
| 425 | + if (topFrame == null) { |
| 426 | + System.err.println("Can't set the window title since the bdv handle because it is of class "+bdvh.getClass().getName()); |
| 427 | + return bdvh.toString(); |
| 428 | + } |
410 | 429 | return topFrame.getTitle(); |
411 | 430 | } |
412 | 431 |
|
|
0 commit comments