diff options
Diffstat (limited to 'src/nativewindow/classes')
3 files changed, 35 insertions, 36 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTWindowClosingProtocol.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTWindowClosingProtocol.java index df32f5942..d78b4ac15 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTWindowClosingProtocol.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTWindowClosingProtocol.java @@ -43,7 +43,7 @@ public class AWTWindowClosingProtocol implements WindowClosingProtocol { private Runnable closingOperation; private volatile boolean closingListenerSet = false; private Object closingListenerLock = new Object(); - private int defaultCloseOperation = DISPOSE_ON_CLOSE; + private WindowClosingMode defaultCloseOperation = WindowClosingMode.DISPOSE_ON_CLOSE; private boolean defaultCloseOperationSetByUser = false; public AWTWindowClosingProtocol(Component comp, Runnable closingOperation) { @@ -54,9 +54,9 @@ public class AWTWindowClosingProtocol implements WindowClosingProtocol { class WindowClosingAdapter extends WindowAdapter { @Override public void windowClosing(WindowEvent e) { - int op = AWTWindowClosingProtocol.this.getDefaultCloseOperation(); + final WindowClosingMode op = AWTWindowClosingProtocol.this.getDefaultCloseOperation(); - if( DISPOSE_ON_CLOSE == op ) { + if( WindowClosingMode.DISPOSE_ON_CLOSE == op ) { // we have to issue this call right away, // otherwise the window gets destroyed closingOperation.run(); @@ -111,27 +111,23 @@ public class AWTWindowClosingProtocol implements WindowClosingProtocol { /** * - * @return the user set close operation if set by {@link #setDefaultCloseOperation(int) setDefaultCloseOperation(int)}, + * @return the user set close operation if set by {@link #setDefaultCloseOperation(WindowClosingMode) setDefaultCloseOperation(int)}, * otherwise return the AWT/Swing close operation value translated to * a {@link WindowClosingProtocol} value . */ - public final int getDefaultCloseOperation() { - int op = -1; + public final WindowClosingMode getDefaultCloseOperation() { synchronized(closingListenerLock) { if(defaultCloseOperationSetByUser) { - op = defaultCloseOperation; + return defaultCloseOperation; } } - if(0 <= op) { - return op; - } // User didn't determine the behavior, use underlying AWT behavior return AWTMisc.getNWClosingOperation(comp); } - public final int setDefaultCloseOperation(int op) { + public final WindowClosingMode setDefaultCloseOperation(WindowClosingMode op) { synchronized(closingListenerLock) { - int _op = defaultCloseOperation; + final WindowClosingMode _op = defaultCloseOperation; defaultCloseOperation = op; defaultCloseOperationSetByUser = true; return _op; diff --git a/src/nativewindow/classes/javax/media/nativewindow/WindowClosingProtocol.java b/src/nativewindow/classes/javax/media/nativewindow/WindowClosingProtocol.java index 949aee79c..884c916e4 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/WindowClosingProtocol.java +++ b/src/nativewindow/classes/javax/media/nativewindow/WindowClosingProtocol.java @@ -32,35 +32,38 @@ package javax.media.nativewindow; * Protocol for handling window closing events. * <p> * The implementation shall obey either the user value set by this interface,<br> - * an underlying toolkit set user value or it's default, eg. {@link #DO_NOTHING_ON_CLOSE DO_NOTHING_ON_CLOSE} within an AWT environment.<br> + * an underlying toolkit set user value or it's default, eg. {@link WindowClosingMode#DO_NOTHING_ON_CLOSE DO_NOTHING_ON_CLOSE} within an AWT environment.<br> * If none of the above determines the operation, - * this protocol default behavior {@link #DISPOSE_ON_CLOSE DISPOSE_ON_CLOSE} shall be used.</p> + * this protocol default behavior {@link WindowClosingMode#DISPOSE_ON_CLOSE DISPOSE_ON_CLOSE} shall be used.</p> */ public interface WindowClosingProtocol { - /** - * Dispose resources on native window close operation.<br> - * This is the default behavior in case no underlying toolkit defines otherwise. - */ - int DISPOSE_ON_CLOSE = 1; + public enum WindowClosingMode { + /** + * Do nothing on native window close operation.<br> + * This is the default behavior within an AWT environment. + */ + DO_NOTHING_ON_CLOSE, + + /** + * Dispose resources on native window close operation.<br> + * This is the default behavior in case no underlying toolkit defines otherwise. + */ + DISPOSE_ON_CLOSE; + } - /** - * Do nothing on native window close operation.<br> - * This is the default behavior within an AWT environment. - */ - int DO_NOTHING_ON_CLOSE = 0; /** * @return the current close operation value - * @see #DISPOSE_ON_CLOSE - * @see #DO_NOTHING_ON_CLOSE + * @see WindowClosingMode#DISPOSE_ON_CLOSE + * @see WindowClosingMode#DO_NOTHING_ON_CLOSE */ - int getDefaultCloseOperation(); + WindowClosingMode getDefaultCloseOperation(); /** * @param op the new close operation value * @return the previous close operation value - * @see #DISPOSE_ON_CLOSE - * @see #DO_NOTHING_ON_CLOSE + * @see WindowClosingMode#DISPOSE_ON_CLOSE + * @see WindowClosingMode#DO_NOTHING_ON_CLOSE */ - int setDefaultCloseOperation(int op); + WindowClosingMode setDefaultCloseOperation(WindowClosingMode op); } diff --git a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java index 834d8a703..d77cd75ef 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java +++ b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java @@ -75,22 +75,22 @@ public class AWTMisc { MenuSelectionManager.defaultManager().clearSelectedPath(); } - public static int AWT2NWClosingOperation(int awtClosingOperation) { + public static WindowClosingProtocol.WindowClosingMode AWT2NWClosingOperation(int awtClosingOperation) { switch (awtClosingOperation) { case WindowConstants.DISPOSE_ON_CLOSE: case WindowConstants.EXIT_ON_CLOSE: - return WindowClosingProtocol.DISPOSE_ON_CLOSE; + return WindowClosingProtocol.WindowClosingMode.DISPOSE_ON_CLOSE; case WindowConstants.DO_NOTHING_ON_CLOSE: case WindowConstants.HIDE_ON_CLOSE: - return WindowClosingProtocol.DO_NOTHING_ON_CLOSE; + return WindowClosingProtocol.WindowClosingMode.DO_NOTHING_ON_CLOSE; default: throw new NativeWindowException("Unhandled AWT Closing Operation: " + awtClosingOperation); } } - public static int getNWClosingOperation(Component c) { - JFrame jf = getJFrame(c); - int op = (null != jf) ? jf.getDefaultCloseOperation() : WindowConstants.DO_NOTHING_ON_CLOSE ; + public static WindowClosingProtocol.WindowClosingMode getNWClosingOperation(Component c) { + final JFrame jf = getJFrame(c); + final int op = (null != jf) ? jf.getDefaultCloseOperation() : WindowConstants.DO_NOTHING_ON_CLOSE ; return AWT2NWClosingOperation(op); } } |