KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectstyle > cayenne > modeler > util > CayenneDialog


1 /* ====================================================================
2  *
3  * The ObjectStyle Group Software License, version 1.1
4  * ObjectStyle Group - http://objectstyle.org/
5  *
6  * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
7  * of the software. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if any,
22  * must include the following acknowlegement:
23  * "This product includes software developed by independent contributors
24  * and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
25  * Alternately, this acknowlegement may appear in the software itself,
26  * if and wherever such third-party acknowlegements normally appear.
27  *
28  * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
29  * or promote products derived from this software without prior written
30  * permission. For written permission, email
31  * "andrus at objectstyle dot org".
32  *
33  * 5. Products derived from this software may not be called "ObjectStyle"
34  * or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
35  * names without prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals and hosted on ObjectStyle Group web site. For more
53  * information on the ObjectStyle Group, please see
54  * <http://objectstyle.org/>.
55  */

56 package org.objectstyle.cayenne.modeler.util;
57
58 import java.awt.Dialog JavaDoc;
59 import java.awt.Frame JavaDoc;
60 import java.awt.GraphicsConfiguration JavaDoc;
61 import java.awt.HeadlessException JavaDoc;
62 import java.awt.event.ActionEvent JavaDoc;
63 import java.awt.event.ActionListener JavaDoc;
64 import java.awt.event.KeyEvent JavaDoc;
65 import java.awt.event.WindowEvent JavaDoc;
66
67 import javax.swing.JComponent JavaDoc;
68 import javax.swing.JDialog JavaDoc;
69 import javax.swing.KeyStroke JavaDoc;
70 import javax.swing.event.HyperlinkEvent JavaDoc;
71 import javax.swing.event.HyperlinkListener JavaDoc;
72
73 import org.objectstyle.cayenne.modeler.Application;
74 import org.objectstyle.cayenne.modeler.CayenneModelerFrame;
75 import org.objectstyle.cayenne.modeler.ProjectController;
76 import org.scopemvc.view.awt.AWTUtilities;
77
78 /**
79  * Superclass of CayenneModeler dialogs. Adds support for popping hyperlinks
80  * in the default system browser.
81  *
82  * @author Andrei Adamchik
83  */

84 public class CayenneDialog extends JDialog JavaDoc implements HyperlinkListener JavaDoc {
85
86     public CayenneDialog() throws HeadlessException JavaDoc {
87         super();
88     }
89
90     public CayenneDialog(Frame JavaDoc owner) throws HeadlessException JavaDoc {
91         super(owner);
92     }
93
94     public CayenneDialog(Frame JavaDoc owner, boolean modal) throws HeadlessException JavaDoc {
95         super(owner, modal);
96     }
97
98     public CayenneDialog(Frame JavaDoc owner, String JavaDoc title) throws HeadlessException JavaDoc {
99         super(owner, title);
100     }
101
102     public CayenneDialog(Frame JavaDoc owner, String JavaDoc title, boolean modal)
103         throws HeadlessException JavaDoc {
104         super(owner, title, modal);
105     }
106
107     public CayenneDialog(
108         Frame JavaDoc owner,
109         String JavaDoc title,
110         boolean modal,
111         GraphicsConfiguration JavaDoc gc) {
112         super(owner, title, modal, gc);
113     }
114
115     public CayenneDialog(Dialog JavaDoc owner) throws HeadlessException JavaDoc {
116         super(owner);
117     }
118
119     public CayenneDialog(Dialog JavaDoc owner, boolean modal) throws HeadlessException JavaDoc {
120         super(owner, modal);
121     }
122
123     public CayenneDialog(Dialog JavaDoc owner, String JavaDoc title) throws HeadlessException JavaDoc {
124         super(owner, title);
125     }
126
127     public CayenneDialog(Dialog JavaDoc owner, String JavaDoc title, boolean modal)
128         throws HeadlessException JavaDoc {
129         super(owner, title, modal);
130     }
131
132     public CayenneDialog(
133         Dialog JavaDoc owner,
134         String JavaDoc title,
135         boolean modal,
136         GraphicsConfiguration JavaDoc gc)
137         throws HeadlessException JavaDoc {
138         super(owner, title, modal, gc);
139     }
140
141     public CayenneDialog(CayenneModelerFrame frame, String JavaDoc title, boolean modal) {
142         super(frame, title, modal);
143     }
144
145     /**
146      * Makes dialog closeable when ESC button is clicked.
147      */

148     protected void initCloseOnEscape() {
149         // make dialog closable on escape
150
// TODO: Note that if a dialog contains subcomponents
151
// that use ESC for their own purposes (like editable JTable or JComboBox),
152
// this code will still close the dialog (e.g. not just an expanded
153
// ComboBox). To fix it see this advise (Swing is Fun!!):
154
//
155
// http://www.eos.dk/pipermail/swing/2001-June/000789.html
156

157         KeyStroke JavaDoc escReleased = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true);
158         ActionListener JavaDoc closeAction = new ActionListener JavaDoc() {
159             public void actionPerformed(ActionEvent JavaDoc e) {
160                 if (CayenneDialog.this.isVisible()) {
161                     // dispatch window closing event
162
WindowEvent JavaDoc windowClosing =
163                         new WindowEvent JavaDoc(CayenneDialog.this, WindowEvent.WINDOW_CLOSING);
164                     CayenneDialog.super.processWindowEvent(windowClosing);
165                 }
166             }
167         };
168         getRootPane().registerKeyboardAction(
169             closeAction,
170             escReleased,
171             JComponent.WHEN_IN_FOCUSED_WINDOW);
172     }
173
174     /**
175      * Centers this dialog relative to the parent Window
176      */

177     public void centerWindow() {
178         AWTUtilities.centreOnWindow(getParentEditor(), this);
179     }
180
181     public CayenneModelerFrame getParentEditor() {
182         return (CayenneModelerFrame) super.getParent();
183     }
184
185     /**
186      * Opens hyperlink in the default browser.
187      */

188     public void hyperlinkUpdate(HyperlinkEvent JavaDoc event) {
189         if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
190             BrowserControl.displayURL(event.getURL().toExternalForm());
191         }
192     }
193
194     /**
195      * Returns current CayenneModeler mediator.
196      */

197     public ProjectController getMediator() {
198         return Application.getInstance().getFrameController().getProjectController();
199     }
200
201     protected void dialogInit() {
202         super.dialogInit();
203         initCloseOnEscape();
204     }
205 }
Popular Tags