| CODENOTIFIER | HelpYou are not signed inSign in |
Project: JNA
Revision: 647
Author: twalljava
Date: 22 Aug 2008 10:35:27
Changes:avoid more content dragging on OSX, or warn
Files:| ... | ...@@ -239,8 +239,6 @@ | |
| 239 | 239 | frame.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); |
| 240 | 240 | frame.getContentPane().add(face); |
| 241 | 241 | frame.setUndecorated(true); |
| 242 | frame.pack(); | |
| 243 | frame.setLocation(100, 100); | |
| 244 | 242 | try { |
| 245 | 243 | Shape mask = new Area(new Ellipse2D.Float(0, 0, 150, 150)); |
| 246 | 244 | WindowUtils.setWindowMask(frame, mask); |
| ... | ...@@ -249,8 +247,11 @@ | |
| 249 | 247 | } |
| 250 | 248 | frame.setIconImage(face.getIconImage()); |
| 251 | 249 | frame.setResizable(false); |
| 252 | frame.setVisible(true); | |
| 253 | 250 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| 251 | ||
| 252 | frame.pack(); | |
| 253 | frame.setLocation(100, 100); | |
| 254 | frame.setVisible(true); | |
| 254 | 255 | } |
| 255 | 256 | catch(UnsatisfiedLinkError e) { |
| 256 | 257 | e.printStackTrace(); |
| ... | ...@@ -112,7 +112,15 @@ | |
| 112 | 112 | * Window#paint(Graphics)} on OS X, you'll need to explicitly set the clip |
| 113 | 113 | * mask on the <code>Graphics</code> object with the window mask; only the |
| 114 | 114 | * content pane of the window and below have the window mask automatically |
| 115 | * applied. | |
| 115 | * applied.<p> | |
| 116 | * NOTE: On OSX, the property | |
| 117 | * <code>apple.awt.draggableWindowBackground</code> is set automatically when | |
| 118 | * a window's background color has an alpha component. That property must be | |
| 119 | * set to its final value <em>before</em> the heavyweight peer for the Window | |
| 120 | * is created. Once {@link Component#addNotify} has been called on the | |
| 121 | * component, causing creation of the heavyweight peer, changing this | |
| 122 | * property has no effect. | |
| 123 | * @see <a href="http://developer.apple.com/technotes/tn2007/tn2196.html#APPLE_AWT_DRAGGABLEWINDOWBACKGROUND">Apple Technote 2007</a> | |
| 116 | 124 | */ |
| 117 | 125 | // TODO: setWindowMask() should accept a threshold; some cases want a |
| 118 | 126 | // 50% threshold, some might want zero/non-zero |
| ... | ...@@ -923,24 +931,52 @@ | |
| 923 | 931 | return content; |
| 924 | 932 | } |
| 925 | 933 | |
| 934 | /** Note that the property | |
| 935 | * <code>apple.awt.draggableWindowBackground</code> must be set to its | |
| 936 | * final value <em>before</em> the heavyweight peer for the Window is | |
| 937 | * created. Once {@link Component#addNotify} has been called on the | |
| 938 | * component, causing creation of the heavyweight peer, changing this | |
| 939 | * property has no effect. | |
| 940 | * @see <a href="http://developer.apple.com/technotes/tn2007/tn2196.html#APPLE_AWT_DRAGGABLEWINDOWBACKGROUND">Apple Technote 2007</a> | |
| 941 | */ | |
| 926 | 942 | public void setWindowTransparent(Window w, boolean transparent) { |
| 927 | 943 | boolean isTransparent = w.getBackground() != null |
| 928 | 944 | && w.getBackground().getAlpha() == 0; |
| 929 | 945 | if (transparent != isTransparent) { |
| 930 | 946 | installTransparentContent(w); |
| 931 | setBackgroundTransparent(w, transparent); | |
| 947 | setBackgroundTransparent(w, transparent, "setWindowTransparent"); | |
| 932 | 948 | setLayersTransparent(w, transparent); |
| 933 | 949 | } |
| 934 | 950 | } |
| 935 | 951 | |
| 936 | public void setWindowAlpha(final Window w, final float alpha) { | |
| 952 | /** Setting this false restores the original setting. */ | |
| 953 | private static final String WDRAG = "apple.awt.draggableWindowBackground"; | |
| 954 | private void fixWindowDragging(Window w, String context) { | |
| 937 | 955 | if (w instanceof RootPaneContainer) { |
| 938 | SwingUtilities.invokeLater(new Runnable() { | |
| 939 | public void run() { | |
| 940 | JRootPane p = ((RootPaneContainer)w).getRootPane(); | |
| 941 | p.putClientProperty("Window.alpha", new Float(alpha)); | |
| 956 | JRootPane p = ((RootPaneContainer)w).getRootPane(); | |
| 957 | Boolean oldDraggable = (Boolean)p.getClientProperty(WDRAG); | |
| 958 | if (oldDraggable == null) { | |
| 959 | p.putClientProperty(WDRAG, Boolean.FALSE); | |
| 960 | if (w.isDisplayable()) { | |
| 961 | System.err.println(context + "(): To avoid content dragging, " + context + "() must be called before the window is realized, or " + WDRAG + " must be set to Boolean.FALSE before the window is realized. If you really want content dragging, set " + WDRAG + " on the window's root pane to Boolean.TRUE before calling " + context + "() to hide this message."); | |
| 942 | 962 | } |
| 943 | }); | |
| 963 | } | |
| 964 | } | |
| 965 | } | |
| 966 | ||
| 967 | /** Note that the property | |
| 968 | * <code>apple.awt.draggableWindowBackground</code> must be set to its | |
| 969 | * final value <em>before</em> the heavyweight peer for the Window is | |
| 970 | * created. Once {@link Component#addNotify} has been called on the | |
| 971 | * component, causing creation of the heavyweight peer, changing this | |
| 972 | * property has no effect. | |
| 973 | * @see <a href="http://developer.apple.com/technotes/tn2007/tn2196.html#APPLE_AWT_DRAGGABLEWINDOWBACKGROUND">Apple Technote 2007</a> | |
| 974 | */ | |
| 975 | public void setWindowAlpha(final Window w, final float alpha) { | |
| 976 | if (w instanceof RootPaneContainer) { | |
| 977 | JRootPane p = ((RootPaneContainer)w).getRootPane(); | |
| 978 | p.putClientProperty("Window.alpha", new Float(alpha)); | |
| 979 | fixWindowDragging(w, "setWindowAlpha"); | |
| 944 | 980 | } |
| 945 | 981 | whenDisplayable(w, new Runnable() { |
| 946 | 982 | public void run() { |
| ... | ...@@ -973,7 +1009,7 @@ | |
| 973 | 1009 | Window w = (Window)c; |
| 974 | 1010 | OSXTransparentContent content = installTransparentContent(w); |
| 975 | 1011 | content.setMask(shape); |
| 976 | setBackgroundTransparent(w, shape != MASK_NONE); | |
| 1012 | setBackgroundTransparent(w, shape != MASK_NONE, "setWindowMask"); | |
| 977 | 1013 | } |
| 978 | 1014 | else { |
| 979 | 1015 | // not yet implemented |
| ... | ...@@ -1015,14 +1051,12 @@ | |
| 1015 | 1051 | } |
| 1016 | 1052 | } |
| 1017 | 1053 | |
| 1018 | private void setBackgroundTransparent(Window w, boolean transparent) { | |
| 1054 | private void setBackgroundTransparent(Window w, boolean transparent, String context) { | |
| 1019 | 1055 | JRootPane rp = w instanceof RootPaneContainer |
| 1020 | 1056 | ? ((RootPaneContainer)w).getRootPane() : null; |
| 1021 | 1057 | if (transparent) { |
| 1022 | 1058 | if (rp != null) { |
| 1023 | 1059 | rp.putClientProperty("bg.old", w.getBackground()); |
| 1024 | rp.putClientProperty("draggable.old", | |
| 1025 | rp.getClientProperty("apple.awt.draggableWindowBackground")); | |
| 1026 | 1060 | } |
| 1027 | 1061 | w.setBackground(new Color(0,0,0,0)); |
| 1028 | 1062 | } |
| ... | ...@@ -1034,12 +1068,7 @@ | |
| 1034 | 1068 | w.setBackground(null); |
| 1035 | 1069 | } |
| 1036 | 1070 | } |
| 1037 | if (rp != null) { | |
| 1038 | // disable dragging by content | |
| 1039 | Boolean old = (Boolean)rp.getClientProperty("apple.awt.draggableWindowBackground"); | |
| 1040 | rp.putClientProperty("apple.awt.draggableWindowBackground", | |
| 1041 | transparent ? Boolean.FALSE : old); | |
| 1042 | } | |
| 1071 | fixWindowDragging(w, context); | |
| 1043 | 1072 | } |
| 1044 | 1073 | } |
| 1045 | 1074 | private static class X11WindowUtils extends NativeWindowUtils { |
| ... | ...@@ -1439,7 +1468,14 @@ | |
| 1439 | 1468 | * opaque, 0.0 fully transparent. The alpha level is applied equally |
| 1440 | 1469 | * to all window pixels.<p> |
| 1441 | 1470 | * NOTE: Windows requires that <code>sun.java2d.noddraw=true</code> |
| 1442 | * in order for alpha to work. | |
| 1471 | * in order for alpha to work.<p> | |
| 1472 | * NOTE: On OSX, the property | |
| 1473 | * <code>apple.awt.draggableWindowBackground</code> must be set to its | |
| 1474 | * final value <em>before</em> the heavyweight peer for the Window is | |
| 1475 | * created. Once {@link Component#addNotify} has been called on the | |
| 1476 | * component, causing creation of the heavyweight peer, changing this | |
| 1477 | * property has no effect. | |
| 1478 | * @see <a href="http://developer.apple.com/technotes/tn2007/tn2196.html#APPLE_AWT_DRAGGABLEWINDOWBACKGROUND">Apple Technote 2007</a> | |
| 1443 | 1479 | */ |
| 1444 | 1480 | public static void setWindowAlpha(Window w, float alpha) { |
| 1445 | 1481 | getInstance().setWindowAlpha(w, Math.max(0f, Math.min(alpha, 1f))); |
| ... | ...@@ -1449,6 +1485,13 @@ | |
| 1449 | 1485 | * Set the window to be transparent. Only explicitly painted pixels |
| 1450 | 1486 | * will be non-transparent. All pixels will be composited with |
| 1451 | 1487 | * whatever is under the window using their alpha values. |
| 1488 | * | |
| 1489 | * On OSX, the property <code>apple.awt.draggableWindowBackground</code> | |
| 1490 | * must be set to its final value <em>before</em> the heavyweight peer for | |
| 1491 | * the Window is created. Once {@link Component#addNotify} has been | |
| 1492 | * called on the component, causing creation of the heavyweight peer, | |
| 1493 | * changing this property has no effect. | |
| 1494 | * @see <a href="http://developer.apple.com/technotes/tn2007/tn2196.html#APPLE_AWT_DRAGGABLEWINDOWBACKGROUND">Apple Technote 2007</a> | |
| 1452 | 1495 | */ |
| 1453 | 1496 | public static void setWindowTransparent(Window w, boolean transparent) { |
| 1454 | 1497 | getInstance().setWindowTransparent(w, transparent); |
| ... | ...@@ -1,4 +1,12 @@ | |
| 1 | 1 | <a name="top"></a> |
| 2 | <h2>Release 3.x.x</h2> | |
| 3 | <b>Features</b><br> | |
| 4 | <ul> | |
| 5 | </ul> | |
| 6 | <b>Bug Fixes</b><br> | |
| 7 | <ul> | |
| 8 | <li>Avoid more content dragging on OSX or warn if it's too late. | |
| 9 | </ul> | |
| 2 | 10 | <h2>Release 3.0.5</h2> |
| 3 | 11 | <b>Features</b><br> |
| 4 | 12 | <ul> |