Changeset 144:d6db753b7c78
- Timestamp:
- 08/02/2008 10:18:23 AM
(4 months ago)
- Author:
- marc@f1.local
- branch:
- default
- Message:
tweaked focus policy for bug #90
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r78 |
r144 |
|
| 1 | 1 | package field.core.ui; |
|---|
| 2 | 2 | |
|---|
| | 3 | import java.awt.Component; |
|---|
| 3 | 4 | import java.awt.Frame; |
|---|
| | 5 | import java.awt.KeyboardFocusManager; |
|---|
| 4 | 6 | import java.awt.Window; |
|---|
| 5 | 7 | import java.awt.event.WindowEvent; |
|---|
| 6 | 8 | import java.awt.event.WindowListener; |
|---|
| 7 | 9 | import java.lang.ref.WeakReference; |
|---|
| 8 | | import java.nio.channels.OverlappingFileLockException; |
|---|
| 9 | 10 | import java.util.ArrayList; |
|---|
| 10 | 11 | import java.util.List; |
|---|
| 11 | 12 | |
|---|
| 12 | | import javax.swing.JFrame; |
|---|
| 13 | | |
|---|
| | 13 | import field.bytecode.protect.Woven; |
|---|
| | 14 | import field.bytecode.protect.annotations.NextUpdate; |
|---|
| 14 | 15 | import field.core.ui.Quaqua15TigerLookAndFeelField.ToolPalette; |
|---|
| 15 | | import field.graphics.windowing.OverlayCanvas; |
|---|
| 16 | 16 | import field.launch.Launcher; |
|---|
| 17 | 17 | import field.launch.iUpdateable; |
|---|
| … | … | |
| 22 | 22 | static List<WeakReference<Frame>> palettes = new ArrayList<WeakReference<Frame>>(); |
|---|
| 23 | 23 | static MutableFloat in = new MutableFloat(0); |
|---|
| 24 | | |
|---|
| | 24 | |
|---|
| 25 | 25 | static public boolean suspendRegistration = false; |
|---|
| 26 | 26 | |
|---|
| 27 | 27 | static public void registerFloatingPalette(Frame frame) { |
|---|
| 28 | | if (suspendRegistration) return; |
|---|
| 29 | | |
|---|
| | 28 | if (suspendRegistration) |
|---|
| | 29 | return; |
|---|
| | 30 | |
|---|
| 30 | 31 | palettes.add(new WeakReference<Frame>(frame)); |
|---|
| 31 | 32 | frame.addWindowListener(new WindowListener() { |
|---|
| … | … | |
| 33 | 34 | List<WeakReference<Frame>> palettes = FloatingPalettes.palettes; |
|---|
| 34 | 35 | MutableFloat in = FloatingPalettes.in; |
|---|
| 35 | | |
|---|
| | 36 | |
|---|
| 36 | 37 | public void windowActivated(WindowEvent e) { |
|---|
| 37 | 38 | if (e.getOppositeWindow() != null && (e.getOppositeWindow().getClass().getName().contains("OverlayCanvas") || e.getOppositeWindow().getClass().getName().contains("PopupInfoWindow"))) { |
|---|
| … | … | |
| 49 | 50 | |
|---|
| 50 | 51 | public void windowDeactivated(WindowEvent e) { |
|---|
| 51 | | if (e.getOppositeWindow() != null && (e.getOppositeWindow().getClass().getName().contains("OverlayCanvas") || e.getOppositeWindow().getClass().getName().contains("PopupInfoWindow"))) { |
|---|
| | 52 | if (e.getOppositeWindow() != null && (e.getOppositeWindow().getClass().getName().contains("OverlayCanvas") || e.getOppositeWindow().getClass().getName().contains("PopupInfoWindow"))) { |
|---|
| 52 | 53 | } else if (palletteOf(e.getOppositeWindow(), palettes)) { |
|---|
| 53 | 54 | } else { |
|---|
| … | … | |
| 71 | 72 | |
|---|
| 72 | 73 | FloatingPalettes.palettes = new ArrayList<WeakReference<Frame>>(); |
|---|
| 73 | | FloatingPalettes.in= new MutableFloat(1); |
|---|
| | 74 | FloatingPalettes.in = new MutableFloat(1); |
|---|
| 74 | 75 | |
|---|
| 75 | 76 | Launcher.getLauncher().registerUpdateable(new iUpdateable() { |
|---|
| 76 | 77 | List<WeakReference<Frame>> palettes = FloatingPalettes.palettes; |
|---|
| 77 | 78 | MutableFloat in = FloatingPalettes.in; |
|---|
| 78 | | |
|---|
| | 79 | |
|---|
| | 80 | boolean edge = false; |
|---|
| | 81 | |
|---|
| | 82 | Component focus = null; |
|---|
| | 83 | |
|---|
| 79 | 84 | public void update() { |
|---|
| 80 | 85 | if (in.d > 0) { |
|---|
| | 86 | if (!edge) { |
|---|
| | 87 | restoreFocus(focus); |
|---|
| | 88 | } |
|---|
| | 89 | Component focus2 = saveFocus(); |
|---|
| | 90 | if (focus2 != null) |
|---|
| | 91 | focus = focus2; |
|---|
| | 92 | edge = true; |
|---|
| 81 | 93 | moveIn(palettes); |
|---|
| 82 | | } else |
|---|
| | 94 | } else { |
|---|
| | 95 | if (edge) { |
|---|
| | 96 | } |
|---|
| | 97 | edge = false; |
|---|
| 83 | 98 | moveOut(palettes); |
|---|
| | 99 | } |
|---|
| 84 | 100 | if (in.d < 0) |
|---|
| 85 | 101 | in.d = 0; |
|---|
| … | … | |
| 87 | 103 | in.d = 1; |
|---|
| 88 | 104 | } |
|---|
| | 105 | |
|---|
| | 106 | @Woven |
|---|
| | 107 | @NextUpdate(delay = 5) |
|---|
| | 108 | private void restoreFocus(final Component focus2) { |
|---|
| | 109 | if (focus2 != null) { |
|---|
| | 110 | // completely crazy! Why do I have to |
|---|
| | 111 | // keep asking for the focus until I get |
|---|
| | 112 | // it? |
|---|
| | 113 | Launcher.getLauncher().registerUpdateable(new iUpdateable() { |
|---|
| | 114 | |
|---|
| | 115 | int n = 0; |
|---|
| | 116 | |
|---|
| | 117 | public void update() { |
|---|
| | 118 | |
|---|
| | 119 | n++; |
|---|
| | 120 | focus2.requestFocus(); |
|---|
| | 121 | if (focus2.isFocusOwner() || n > 5) { |
|---|
| | 122 | Launcher.getLauncher().deregisterUpdateable(this); |
|---|
| | 123 | } |
|---|
| | 124 | } |
|---|
| | 125 | }); |
|---|
| | 126 | } |
|---|
| | 127 | } |
|---|
| | 128 | |
|---|
| | 129 | private Component saveFocus() { |
|---|
| | 130 | return KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); |
|---|
| | 131 | } |
|---|
| 89 | 132 | }); |
|---|
| 90 | | |
|---|
| | 133 | |
|---|
| 91 | 134 | FloatingPalettes.palettes.add(new WeakReference<Frame>(frame)); |
|---|
| 92 | 135 | frame.addWindowListener(new WindowListener() { |
|---|
| … | … | |
| 96 | 139 | |
|---|
| 97 | 140 | public void windowActivated(WindowEvent e) { |
|---|
| 98 | | if (e.getOppositeWindow() != null && (e.getOppositeWindow().getClass().getName().contains("OverlayCanvas") || e.getOppositeWindow().getClass().getName().contains("PopupInfoWindow"))) { |
|---|
| | 141 | if (e.getOppositeWindow() != null && (e.getOppositeWindow().getClass().getName().contains("OverlayCanvas") || e.getOppositeWindow().getClass().getName().contains("PopupInfoWindow"))) { |
|---|
| 99 | 142 | } else if (palletteOf(e.getOppositeWindow(), palettes)) { |
|---|
| 100 | 143 | } else { |
|---|
| 101 | 144 | in.d++; |
|---|
| 102 | 145 | } |
|---|
| | 146 | // |
|---|
| | 147 | // if (e.getOppositeWindow()!=null) |
|---|
| | 148 | // { |
|---|
| | 149 | // System.out.println(" oposite is <"+e.getOppositeWindow()+"> <"+e.getSource()+">"); |
|---|
| | 150 | // } |
|---|
| 103 | 151 | } |
|---|
| 104 | 152 | |
|---|
| … | … | |
| 110 | 158 | |
|---|
| 111 | 159 | public void windowDeactivated(WindowEvent e) { |
|---|
| 112 | | if (e.getOppositeWindow() != null && (e.getOppositeWindow().getClass().getName().contains("OverlayCanvas") || e.getOppositeWindow().getClass().getName().contains("PopupInfoWindow"))) { |
|---|
| | 160 | if (e.getOppositeWindow() != null && (e.getOppositeWindow().getClass().getName().contains("OverlayCanvas") || e.getOppositeWindow().getClass().getName().contains("PopupInfoWindow"))) { |
|---|
| 113 | 161 | } else if (palletteOf(e.getOppositeWindow(), palettes)) { |
|---|
| 114 | 162 | } else { |
|---|
| r81 |
r144 |
|
| 74 | 74 | float lastOpacity = -1f; |
|---|
| 75 | 75 | |
|---|
| | 76 | boolean hadFocusOnHide = false; |
|---|
| 76 | 77 | |
|---|
| 77 | 78 | public ToolPalette(String title) throws HeadlessException { |
|---|
| … | … | |
| 101 | 102 | if (opacity < 1e-2 && opacity<lastOpacity) |
|---|
| 102 | 103 | if (ToolPalette.super.isVisible()) |
|---|
| | 104 | { |
|---|
| 103 | 105 | ToolPalette.super.show(false); |
|---|
| | 106 | } |
|---|
| 104 | 107 | if (opacity > 1e-2 && opacity>lastOpacity) |
|---|
| 105 | 108 | if (!ToolPalette.super.isVisible()) |
|---|
| | 109 | { |
|---|
| 106 | 110 | ToolPalette.super.show(true); |
|---|
| | 111 | } |
|---|
| 107 | 112 | |
|---|
| 108 | 113 | if (Math.abs(lastOpacity-opacity)>0.01 || (opacity==0 && lastOpacity!=0) || (opacity==1 && lastOpacity!=1)) |
|---|
| r143 |
r144 |
|
| 617 | 617 | } |
|---|
| 618 | 618 | |
|---|
| | 619 | @Override |
|---|
| | 620 | public boolean isFocusable() { |
|---|
| | 621 | return true; |
|---|
| | 622 | } |
|---|
| 619 | 623 | }; |
|---|
| 620 | 624 | |
|---|
| r86 |
r144 |
|
| 145 | 145 | <key>forceNativeBuffers</key> |
|---|
| 146 | 146 | <string>1</string> |
|---|
| | 147 | <key>java.library.path</key> |
|---|
| | 148 | <string>$JAVAROOT:$JAVAROOT/../../../../extensions/</string> |
|---|
| 147 | 149 | <key>java.source.paths</key> |
|---|
| 148 | 150 | <string>$JAVAROOT/../../../../../../development/java:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/src.jar</string> |
|---|
| … | … | |
| 167 | 169 | </dict> |
|---|
| 168 | 170 | <key>VMOptions</key> |
|---|
| 169 | | <string>-Xms500m -Xmx2000m -noverify -XX:ReservedCodeCacheSize 50m -XX:+UseDefaultStackSize -Xss256K</string> |
|---|
| | 171 | <string>-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n -Xms500m -Xmx2000m -noverify -XX:ReservedCodeCacheSize 50m -XX:+UseDefaultStackSize -Xss256K</string> |
|---|
| 170 | 172 | <key>WorkingDirectory</key> |
|---|
| 171 | 173 | <string>$APP_PACKAGE/Contents/Resources/Java</string> |
|---|