]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/PackageEditor/src/org/tianocore/packaging/ModalFrameUtil.java
2 Java class ModalFrameUtil is used to show modal frame.
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 package org
.tianocore
.packaging
;
17 import java
.awt
.event
.WindowAdapter
;
18 import java
.awt
.event
.WindowEvent
;
19 import java
.lang
.reflect
.InvocationHandler
;
20 import java
.lang
.reflect
.Method
;
21 import java
.lang
.reflect
.Proxy
;
24 This class is used to show modal frame.
26 @since PackageEditor 1.0
28 public class ModalFrameUtil
{
30 Invocation handler for event threads
32 @since PackageEditor 1.0
34 static class EventPump
implements InvocationHandler
{
37 public EventPump(Frame frame
) {
42 Invocation handler invoked by Method.invoke
44 public Object
invoke(Object proxy
, Method method
, Object
[] args
) throws Throwable
{
46 // return frame showing status for Conditional.evaluate()
48 return frame
.isShowing() ? Boolean
.TRUE
: Boolean
.FALSE
;
51 public void start() throws Exception
{
52 Class clazz
= Class
.forName("java.awt.Conditional");
54 // Conditional proxy instance will invoke "this" InvocationHandler.invoke when calling its methods
56 Object conditional
= Proxy
.newProxyInstance(clazz
.getClassLoader(), new Class
[] { clazz
}, this);
58 // EventDisaptchThread.pumpEvents will be called under Conditional "conditional"
60 Method pumpMethod
= Class
.forName("java.awt.EventDispatchThread").getDeclaredMethod("pumpEvents",
61 new Class
[] { clazz
});
62 pumpMethod
.setAccessible(true);
64 // pumpEvents when conditional.evaluate() == true (frame.isShowing() in EventPump.invoke)
66 pumpMethod
.invoke(Thread
.currentThread(), new Object
[] { conditional
});
71 Show modal frame, return only when frame closed.
73 @param frame Frame to be modal
74 @param owner Parent Frame
76 public static void showAsModal(final Frame frame
, final Frame owner
) {
77 frame
.addWindowListener(new WindowAdapter() {
78 public void windowOpened(WindowEvent e
) {
79 owner
.setEnabled(false);
82 public void windowClosed(WindowEvent e
) {
83 owner
.setEnabled(true);
84 owner
.setVisible(true);
85 owner
.removeWindowListener(this);
89 owner
.addWindowListener(new WindowAdapter() {
90 public void windowActivated(WindowEvent e
) {
91 if (frame
.isShowing()) {
92 frame
.setExtendedState(JFrame
.NORMAL
);
95 owner
.removeWindowListener(this);
100 frame
.setVisible(true);
102 new EventPump(frame
).start();
103 } catch (Throwable throwable
) {
104 throw new RuntimeException(throwable
);