1 /* -------------------------------------------------------------------
2 * Java source file for the class WindowCloseAdapter
3 *
4 * Copyright (c), 2002, Masahiro Takatsuka.
5 * All Rights Researved.
6 *
7 * Original Author: Masahiro Takatsuka (masa@jbeans.net)
8 * $Author: takatsukam $
9 *
10 * $Date: 2003/07/25 04:51:47 $
11 *
12 * $Id: WindowCloseAdapter.java,v 1.1.1.1 2003/07/25 04:51:47 takatsukam Exp $
13 *
14 * Reference: Document no:
15 * ___ ___
16 *
17 * To Do:
18 * ___
19 *
20 ------------------------------------------------------------------- */
21
22 /* --------------------------- Package ---------------------------- */
23 package net.jbeans.ui.window;
24
25 /* ------------------ Import classes (packages) ------------------- *//package-summary/html">color="#329900"> ------------------ Import classes (packages) ------------------- *//package-summary.html">color="#329900">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">color="#329900"> ------------------ Import classes (packages) ------------------- */
26 import java.awt.*;
27 import java.awt.event.*;
28
29 /*====================================================================
30 Implementation of class WindowCloseAdapter
31 ====================================================================*/
32 /***
33 * Helper class to handle window close events on a target window.
34 *
35 * @version $Revision: 1.1.1.1 $
36 * @author Masahiro Takatsuka (masa@jbeans.net)
37 * @see WindowListener
38 */
39
40 public class WindowCloseAdapter implements WindowListener {
41 public static final int FIRST = 0;
42 public static final int DO_NOTHING_ON_CLOSE = FIRST;
43 public static final int EXIT_ON_CLOSE = DO_NOTHING_ON_CLOSE + 1;
44 public static final int HIDE_ON_CLOSE = EXIT_ON_CLOSE + 1;
45 public static final int JUST_CLOSE = HIDE_ON_CLOSE + 1;
46 public static final int LAST = JUST_CLOSE;
47
48 private int mode;
49
50 /***
51 * Create an adaptor to listen for window close events on the given window.
52 *
53 * @param w the target window.
54 */
55 public WindowCloseAdapter(Window w, int mode) {
56 if (mode < FIRST || mode > LAST) {
57 mode = FIRST;
58 }
59 this.mode = mode;
60 w.addWindowListener(this);
61 }
62
63 public void windowOpened(WindowEvent e) {
64 }
65
66 public void windowClosing(WindowEvent e) {
67 switch (this.mode) {
68 case DO_NOTHING_ON_CLOSE:
69 default:
70 break; // do nothing
71 case HIDE_ON_CLOSE:
72 e.getWindow().setVisible(false);
73 break;
74 case JUST_CLOSE:
75 e.getWindow().dispose();
76 break;
77 case EXIT_ON_CLOSE:
78 System.exit(0);
79 }
80 }
81
82 public void windowClosed(WindowEvent e) {
83 switch (this.mode) {
84 case DO_NOTHING_ON_CLOSE:
85 default:
86 break; // do nothing
87 case HIDE_ON_CLOSE:
88 e.getWindow().setVisible(false);
89 break;
90 case JUST_CLOSE:
91 e.getWindow().dispose();
92 break;
93 case EXIT_ON_CLOSE:
94 System.exit(0);
95 }
96 }
97
98 public void windowIconified(WindowEvent e) {
99 }
100
101 public void windowDeiconified(WindowEvent e) {
102 }
103
104 public void windowActivated(WindowEvent e) {
105 }
106
107 public void windowDeactivated(WindowEvent e) {
108 }
109 }
This page was automatically generated by Maven