AWT modal enhancements in Java SE 6

Source: Internet
Author: User
Tags range window java se

   first, the introduction

Mode has always been one of my favorite topics, at least because there has been a lot of interest in the customer's feedback on this content. As a Java SE test engineer, this is what drives me to work-it keeps me busy and brings happiness to my work. On the other hand, it also shows that modal is one of the most widely used features of the client, whether using swing or using AWT for development.

In the Java SE 6 (code name Mustang), my work has become more interesting--a lot of improvements in the mode. These improvements will provide greater flexibility for application developers in the process of designing programs that may be used in modal dialog box behavior. Before delving into these improvements, let's take a look at the functionality that AWT provides before Mustang.

From its introduction, AWT provides only two types of modes: Modal and modeless.

• Modal-when any modal window is displayed, all windows in the application are blocked.

• Modeless-This is a dialog box that does not block any windows.

We may ask the following interesting questions:

• Why should a modal dialog box block all windows in the current application?

• If the modal dialog box blocks only the parent window instead of the other window, is it OK?

• Is it not OK for the application developer to decide (instead of AWT) what Windows should be blocked in his application's dialog box? For example, when a modal dialog is active, if an application user wants to scroll through the Help window to see what choices he or she makes in the dialog box, how does he/she do that?

AWT enhances this functionality in the new Java SE 6. Now, it offers four types of modes (ranging from wide to narrow): toolbox, applications, documents, and non modal. The developer can choose the appropriate modal type for his dialog box, depending on the specific needs.

   Second, the Toolbox modal

Select this type if:

• Your dialog box must block all windows in your application (except for the child Level window of the dialog box)

• Your dialog box should block your applet and all other applets in the same toolbox

• Your dialog box should block the browser itself

• You want to use a dialog box with the maximum blocking range

   Third, Application Mode

There are not many differences between application and toolbox modes, as far as the usual applications are concerned. However, if you are developing an applet, it is important to understand the difference.

• If you start several applets in your browser, they can be treated as separate applications or individual applications depending on which browser you are using (check your browser documentation). The Application modal dialog box blocks all windows in the same application

• The default modal type, used when no content is specified for the modal dialog box.

Four, document mode

Select this type if:

• The dialog box only blocks windows in the same document (the document is determined by the window with no owner closest to the top)

• Dialog boxes should have a minimum range of blocking from the adjacent modeless window.

   Five, non-modal

If you don't want your dialog box to block any windows, then you can use this mode.

   Note that since the Toolbox modal dialog box can block browser/java WebStart, you need a awtpermission "toolkitmodality" to use this type of modal from an applet.

In general, this provides a lot of flexibility for application developers when selecting the appropriate modal type for each dialog box (depending on how it should block the specified range of other top-level windows in the application).

  Vi. modal exclusion

There is another place-there are many windows in your application, and you want your modal dialog box to block all but one window. In this case, you will have to select the modal type-it has the maximum range of blocking capabilities. But is it possible to exclude windows that should not be blocked from the window blocked by the dialog box? Yes, absolutely!

Below, let's look at the functionality that AWT provides in this regard:

In Java SE 6, AWT introduces two modal exclusion types (refer to Figure 1).

(i) Block Toolbox modal dialog box exclusion type

If a window is excluded from the toolbox modal, it is not blocked by any application or Toolbox modal dialog box. In addition, it will not be a document modal dialog box from other child-level windows (Note: If you are using an applet environment, you will require awtpermission-"toolkitmodality" to use this exclusion type) to block outside.


(ii) Blocking Application modal dialog box exclusion type

If a window is excluded by an application modal, it is not blocked by any application modal dialog box. In addition, it is not blocked by the document modal dialog box from outside its child hierarchy window.


Figure 1. Windows excluded from Application Mode

By default, the modal exclusion property of a window is closed. That is, by default, it is blocked-if it is within the blocking range of any modal dialogs that are visible.
Before using any modal or exclusion type, check to see if your platform supports this type-by invoking the method provided by the Java.awt.Toolkit class ismodalitysupported () and ismodalexclusiontypesupported () to achieve.

   Seven, no parent dialog box

All along, the dialog box always has a parent window associated with it. But is it really necessary for a dialog box to always have a parent window? The answer is no longer the case!
Now, in Java SE 6, it is possible to create an AWT dialog box with a parent window of "null" (the "parent" parameter value in the dialog constructor is null). In previous releases, this always throws an exception.

So if you don't want your dialog box to have a parent window, you no longer need to create a "dummy" parent window!

In addition, there are some interesting things to explore:

(i) If no parent dialog box is a document modal

A document modal dialog box without an owner automatically becomes a root of the document, so its blocking range is empty. So it behaves like a modeless dialog box.

(ii) If no parent dialog box is an application or toolbox modal

The blocking scope of an application or Toolbox modal dialog box (relative to a document modal dialog box) does not depend on its owner and therefore has no effect on the blocking scope.

In any case, a modal dialog box should always be at the top of the other top-level windows it blocks. You cannot change the modal type of a dialog box that is already visible. If you want to do this, then you need to hide it and show it again so that the newly specified modal type works.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.