|
36 | 36 | import org.scijava.display.event.DisplayActivatedEvent; |
37 | 37 | import org.scijava.display.event.DisplayDeletedEvent; |
38 | 38 | import org.scijava.display.event.DisplayUpdatedEvent; |
| 39 | +import org.scijava.display.event.DisplayUpdatedEvent.DisplayUpdateLevel; |
39 | 40 | import org.scijava.plugin.Plugin; |
40 | 41 | import org.scijava.plugin.RichPlugin; |
41 | 42 | import org.scijava.ui.UserInterface; |
@@ -90,16 +91,34 @@ public interface DisplayViewer<T> extends RichPlugin, Disposable { |
90 | 91 | DisplayPanel getPanel(); |
91 | 92 |
|
92 | 93 | /** Synchronizes the user interface appearance with the display model. */ |
93 | | - void onDisplayUpdatedEvent(DisplayUpdatedEvent e); |
| 94 | + default void onDisplayUpdatedEvent(final DisplayUpdatedEvent e) { |
| 95 | + if (e.getLevel() == DisplayUpdateLevel.REBUILD) { |
| 96 | + getPanel().redoLayout(); |
| 97 | + } |
| 98 | + getPanel().redraw(); |
| 99 | + } |
94 | 100 |
|
95 | 101 | /** Removes the user interface when the display is deleted. */ |
96 | | - void onDisplayDeletedEvent(DisplayDeletedEvent e); |
| 102 | + @SuppressWarnings("unused") |
| 103 | + default void onDisplayDeletedEvent(final DisplayDeletedEvent e) { |
| 104 | + getPanel().getWindow().close(); |
| 105 | + } |
97 | 106 |
|
98 | 107 | /** |
99 | 108 | * Handles a display activated event directed at this viewer's display. Note |
100 | 109 | * that the event's display may not be the viewer's display, but the active |
101 | 110 | * display will always be the viewer's display. |
102 | 111 | */ |
103 | | - void onDisplayActivatedEvent(DisplayActivatedEvent e); |
104 | | - |
| 112 | + @SuppressWarnings("unused") |
| 113 | + default void onDisplayActivatedEvent(final DisplayActivatedEvent e) { |
| 114 | + getPanel().getWindow().requestFocus(); |
| 115 | + } |
| 116 | + |
| 117 | + // -- Disposable methods -- |
| 118 | + |
| 119 | + @Override |
| 120 | + default void dispose() { |
| 121 | + final DisplayWindow w = getWindow(); |
| 122 | + if (w != null) w.close(); |
| 123 | + } |
105 | 124 | } |
0 commit comments