Next Generation B / S Development Framework - Echo Tutorial (4)
Implementation of the pattern window
Those familiar with the browser know that it is difficult to implement the mode window on the browser, which is the operation that has been on the top and can prohibit the operation of the parent window. It is generally returned in B / S programming. A new page, then use the link back to the original page. Sometimes there are very few information in the new window, have to think about it to decorate it. Let's see how to use Echo:
Import nextApp.echo. *;
Import nextapp.echo.event. *;
/ **
* Mode window
* /
Public Class CommonWindow Extends Window Implements WINDOWLISTENER {
Protected window parent; // parent window
Public CommonWindow (Window Parent, Boolean Modal) {
THIS.PARENT = Parent;
IF (Modal && Parent! = NULL)
Parent.setVisible (FALSE);
}
PUBLIC CommonWindow () {}
protected void init () {
SetDefaultCloseOperation (window.dispose_on_close);
Addwindowlistener (this);
}
// The window is executed when it is DISPOSE ()
Public void windowClosed (WindowEvent E) {
IF (parent! = null) {
Parent.setVisible (false); // activate the parent window
Parent.setVisible (TRUE);
}
}
Public void windowClosing (WindowEvent E) {}
Public void windowpend (WindowEvent E) {}
}
Take a look at the code above:
The parent window is hidden in the constructor, listening to the incident you destroyed, and activates the parent window after being destroyed If the window is already open, only the window setvisable (true) does not make it visible, so first hide and open.
Other windows generally expand CommonWindow, easily implement a smaller Alert / Confirm window.
Note: A layer-based mode window is provided in echopoint: DialogPanel. IE is relatively poor to the layer, for reference only.
As the parent class of other windows, it is generally necessary to set the default font / color / layout of the window inside. After adjusting the CommonWindow, you can unify the site style.
Because all the buttons in the window often use the same event listener, this also adds such a speculative method in CommonWindow:
/ **
* Add all buttons under the control to add the same action listener, ignore Checkbox and Radiobox
* /
Public static void addallbuttonlistener (Component Component, ActionListener Listener) {
Component [] all = component.getComponents ();
For (int I = 0; i IF (all [i] instanceof AbstractButton &&! (all [i] instanceof togglebutton)) (AbstractButton) All [I]). AddActionListener (Listener); IF (all [i] instanceof component) AddAllButtonListener (all [i], listener; } }