1 /* |
1 /* |
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
30 import java.awt.event.*; |
30 import java.awt.event.*; |
31 import java.awt.peer.*; |
31 import java.awt.peer.*; |
32 import java.io.*; |
32 import java.io.*; |
33 import java.util.Locale; |
33 import java.util.Locale; |
34 import java.util.Arrays; |
34 import java.util.Arrays; |
35 import com.sun.java.swing.plaf.motif.*; |
|
36 import javax.swing.plaf.ComponentUI; |
|
37 import java.security.AccessController; |
35 import java.security.AccessController; |
38 import java.security.PrivilegedAction; |
36 import java.security.PrivilegedAction; |
|
37 |
|
38 import sun.awt.AWTAccessor.ComponentAccessor; |
39 import sun.util.logging.PlatformLogger; |
39 import sun.util.logging.PlatformLogger; |
40 import sun.awt.AWTAccessor; |
40 import sun.awt.AWTAccessor; |
41 |
41 |
42 class XFileDialogPeer extends XDialogPeer implements FileDialogPeer, ActionListener, ItemListener, KeyEventDispatcher, XChoicePeerListener { |
42 class XFileDialogPeer extends XDialogPeer |
43 private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XFileDialogPeer"); |
43 implements FileDialogPeer, ActionListener, ItemListener, |
|
44 KeyEventDispatcher, XChoicePeerListener { |
|
45 |
|
46 private static final PlatformLogger log = |
|
47 PlatformLogger.getLogger("sun.awt.X11.XFileDialogPeer"); |
44 |
48 |
45 FileDialog target; |
49 FileDialog target; |
46 |
50 |
47 // This variable holds value exactly the same as value of the 'target.file' variable except: |
51 // This variable holds value exactly the same as value of the 'target.file' variable except: |
48 // 1) is changed to null after quit (see handleQuitButton()) |
52 // 1) is changed to null after quit (see handleQuitButton()) |
284 1, 0, GridBagConstraints.HORIZONTAL, buttonsInset); |
288 1, 0, GridBagConstraints.HORIZONTAL, buttonsInset); |
285 |
289 |
286 fileDialog.setSize(400, 400); |
290 fileDialog.setSize(400, 400); |
287 |
291 |
288 // Update choice's popup width |
292 // Update choice's popup width |
289 XChoicePeer choicePeer = (XChoicePeer)pathChoice.getPeer(); |
293 XChoicePeer choicePeer = AWTAccessor.getComponentAccessor() |
|
294 .getPeer(pathChoice); |
290 choicePeer.setDrawSelectedItem(false); |
295 choicePeer.setDrawSelectedItem(false); |
291 choicePeer.setAlignUnder(pathField); |
296 choicePeer.setAlignUnder(pathField); |
292 |
297 |
293 filterField.addActionListener(this); |
298 filterField.addActionListener(this); |
294 selectionField.addActionListener(this); |
299 selectionField.addActionListener(this); |
640 handleQuitButton(); |
645 handleQuitButton(); |
641 } |
646 } |
642 } |
647 } |
643 } |
648 } |
644 |
649 |
645 @SuppressWarnings("deprecation") |
|
646 public boolean dispatchKeyEvent(KeyEvent keyEvent) { |
650 public boolean dispatchKeyEvent(KeyEvent keyEvent) { |
647 int id = keyEvent.getID(); |
651 int id = keyEvent.getID(); |
648 int keyCode = keyEvent.getKeyCode(); |
652 int keyCode = keyEvent.getKeyCode(); |
649 |
653 |
650 if (id == KeyEvent.KEY_PRESSED && keyCode == KeyEvent.VK_ESCAPE) { |
654 if (id == KeyEvent.KEY_PRESSED && keyCode == KeyEvent.VK_ESCAPE) { |
651 synchronized (target.getTreeLock()) { |
655 synchronized (target.getTreeLock()) { |
652 Component comp = (Component) keyEvent.getSource(); |
656 Component comp = (Component) keyEvent.getSource(); |
653 while (comp != null) { |
657 while (comp != null) { |
654 // Fix for 6240084 Disposing a file dialog when the drop-down is active does not dispose the dropdown menu, on Xtoolkit |
658 // Fix for 6240084 Disposing a file dialog when the drop-down is active does not dispose the dropdown menu, on Xtoolkit |
655 // See also 6259493 |
659 // See also 6259493 |
|
660 ComponentAccessor acc = AWTAccessor.getComponentAccessor(); |
656 if (comp == pathChoice) { |
661 if (comp == pathChoice) { |
657 XChoicePeer choicePeer = (XChoicePeer)pathChoice.getPeer(); |
662 XChoicePeer choicePeer = acc.getPeer(pathChoice); |
658 if (choicePeer.isUnfurled()){ |
663 if (choicePeer.isUnfurled()){ |
659 return false; |
664 return false; |
660 } |
665 } |
661 } |
666 } |
662 if (comp.getPeer() == this) { |
667 Object peer = acc.getPeer(comp); |
|
668 if (peer == this) { |
663 handleCancel(); |
669 handleCancel(); |
664 return true; |
670 return true; |
665 } |
671 } |
666 comp = comp.getParent(); |
672 comp = comp.getParent(); |
667 } |
673 } |
794 // Seems we shouldn't restore Motif behaviour in this case |
800 // Seems we shouldn't restore Motif behaviour in this case |
795 setFile(savedFile); |
801 setFile(savedFile); |
796 } |
802 } |
797 |
803 |
798 super.setVisible(b); |
804 super.setVisible(b); |
|
805 XChoicePeer choicePeer = AWTAccessor.getComponentAccessor() |
|
806 .getPeer(pathChoice); |
799 if (b == true){ |
807 if (b == true){ |
800 // See 6240074 for more information |
808 // See 6240074 for more information |
801 XChoicePeer choicePeer = (XChoicePeer)pathChoice.getPeer(); |
|
802 choicePeer.addXChoicePeerListener(this); |
809 choicePeer.addXChoicePeerListener(this); |
803 KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this); |
810 KeyboardFocusManager.getCurrentKeyboardFocusManager() |
|
811 .addKeyEventDispatcher(this); |
804 }else{ |
812 }else{ |
805 // See 6240074 for more information |
813 // See 6240074 for more information |
806 XChoicePeer choicePeer = (XChoicePeer)pathChoice.getPeer(); |
|
807 choicePeer.removeXChoicePeerListener(); |
814 choicePeer.removeXChoicePeerListener(); |
808 KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(this); |
815 KeyboardFocusManager.getCurrentKeyboardFocusManager() |
|
816 .removeKeyEventDispatcher(this); |
809 } |
817 } |
810 |
818 |
811 selectionField.requestFocusInWindow(); |
819 selectionField.requestFocusInWindow(); |
812 } |
820 } |
813 |
821 |