KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > modeler > dialogs > OpenDialog


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, is permitted provided that the following conditions are met: -
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer. - Redistributions in binary
8  * form must reproduce the above copyright notice, this list of conditions and
9  * the following disclaimer in the documentation and/or other materials
10  * provided with the distribution. - All advertising materials mentioning
11  * features or use of this software must display the following acknowledgment:
12  * "This product includes Djeneric." - Products derived from this software may
13  * not be called "Djeneric" nor may "Djeneric" appear in their names without
14  * prior written permission of Genimen BV. - Redistributions of any form
15  * whatsoever must retain the following acknowledgment: "This product includes
16  * Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG, OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.tools.modeler.dialogs;
31
32 import java.awt.BorderLayout JavaDoc;
33 import java.awt.Dimension JavaDoc;
34 import java.awt.Toolkit JavaDoc;
35 import java.awt.event.ActionEvent JavaDoc;
36 import java.awt.event.KeyEvent JavaDoc;
37 import java.awt.event.MouseEvent JavaDoc;
38 import java.util.Vector JavaDoc;
39
40 import javax.swing.DefaultComboBoxModel JavaDoc;
41 import javax.swing.JButton JavaDoc;
42 import javax.swing.JDialog JavaDoc;
43 import javax.swing.JList JavaDoc;
44 import javax.swing.JPanel JavaDoc;
45 import javax.swing.JScrollPane JavaDoc;
46 import javax.swing.ListSelectionModel JavaDoc;
47
48 import com.genimen.djeneric.language.Messages;
49 import com.genimen.djeneric.repository.DjModelView;
50 import com.genimen.djeneric.tools.modeler.ModelEditor;
51 import com.genimen.djeneric.ui.Util;
52
53 public class OpenDialog extends JDialog JavaDoc
54 {
55   private static final long serialVersionUID = 1L;
56   BorderLayout JavaDoc borderLayout1 = new BorderLayout JavaDoc();
57   JScrollPane JavaDoc jScrollPane1 = new JScrollPane JavaDoc();
58   JList JavaDoc _lstViews = new JList JavaDoc();
59   JPanel JavaDoc jPanel1 = new JPanel JavaDoc();
60   BorderLayout JavaDoc borderLayout2 = new BorderLayout JavaDoc();
61   JPanel JavaDoc jPanel3 = new JPanel JavaDoc();
62   BorderLayout JavaDoc borderLayout3 = new BorderLayout JavaDoc();
63   JPanel JavaDoc jPanel4 = new JPanel JavaDoc();
64   JButton JavaDoc _butOk = new JButton JavaDoc();
65   JButton JavaDoc _butCancel = new JButton JavaDoc();
66
67   boolean _canceled = true;
68   DjModelView[] _allViews;
69   DjModelView _excludeThis = null;
70
71   public OpenDialog(ModelEditor editor, String JavaDoc customTitle) throws Exception JavaDoc
72   {
73     super(editor, customTitle, true);
74     construct(editor);
75   }
76
77   public OpenDialog(ModelEditor editor, String JavaDoc customTitle, DjModelView excludeThis) throws Exception JavaDoc
78   {
79     super(editor, customTitle, true);
80     _excludeThis = excludeThis;
81     construct(editor);
82   }
83
84   public OpenDialog(ModelEditor editor) throws Exception JavaDoc
85   {
86     super(editor, Messages.getString("OpenDialog.OpenView"), true);
87     construct(editor);
88   }
89
90   protected void construct(ModelEditor editor) throws Exception JavaDoc
91   {
92     jbInit();
93
94     _allViews = editor.getPersistenceManager().getViews();
95     Vector JavaDoc vws = new Vector JavaDoc();
96     for (int i = 0; i < _allViews.length; i++)
97     {
98       if (!_allViews[i].equals(_excludeThis)) vws.add(_allViews[i]);
99     }
100
101     _lstViews.setModel(new DefaultComboBoxModel JavaDoc(vws));
102     setSize(290, 230);
103
104     Dimension JavaDoc screenSize = Toolkit.getDefaultToolkit().getScreenSize();
105     Dimension JavaDoc frameSize = getSize();
106     setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
107
108     if (_allViews.length > 0) _lstViews.setSelectedIndex(0);
109
110     setVisible(true);
111     if (_canceled) throw new Exception JavaDoc(Messages.getString("OpenDialog.OpenAborted"));
112   }
113
114   void jbInit() throws Exception JavaDoc
115   {
116     this.getContentPane().setLayout(borderLayout1);
117     jPanel1.setLayout(borderLayout2);
118     jPanel3.setLayout(borderLayout3);
119     _butOk.setText(Messages.getString("global.Ok"));
120     _butOk.addActionListener(new java.awt.event.ActionListener JavaDoc()
121     {
122       public void actionPerformed(ActionEvent JavaDoc e)
123       {
124         _butOk_actionPerformed(e);
125       }
126     });
127     _butCancel.setText(Messages.getString("global.Cancel"));
128     _butCancel.addActionListener(new java.awt.event.ActionListener JavaDoc()
129     {
130       public void actionPerformed(ActionEvent JavaDoc e)
131       {
132         _butCancel_actionPerformed(e);
133       }
134     });
135     _lstViews.addMouseListener(new java.awt.event.MouseAdapter JavaDoc()
136     {
137       public void mouseClicked(MouseEvent JavaDoc e)
138       {
139         _lstViews_mouseClicked(e);
140       }
141     });
142     _lstViews.addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
143     {
144       public void keyPressed(KeyEvent JavaDoc e)
145       {
146         _lstViews_keyPressed(e);
147       }
148     });
149     _lstViews.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
150     this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
151     this.getContentPane().add(jPanel1, BorderLayout.SOUTH);
152     jPanel1.add(jPanel3, BorderLayout.SOUTH);
153     jPanel3.add(jPanel4, BorderLayout.EAST);
154     jPanel4.add(_butCancel, null);
155     jPanel4.add(_butOk, null);
156     jScrollPane1.getViewport().add(_lstViews, null);
157     Util.sizeButtons(jPanel4);
158   }
159
160   void _butOk_actionPerformed(ActionEvent JavaDoc e)
161   {
162     if (_lstViews.getSelectedIndex() == -1) return;
163     _canceled = false;
164     setVisible(false);
165   }
166
167   void _butCancel_actionPerformed(ActionEvent JavaDoc e)
168   {
169     setVisible(false);
170   }
171
172   public DjModelView getModelView()
173   {
174     return (DjModelView) _lstViews.getSelectedValue();
175   }
176
177   void _lstViews_mouseClicked(MouseEvent JavaDoc e)
178   {
179     if (e.getClickCount() > 1) _butOk_actionPerformed(null);
180   }
181
182   void _lstViews_keyPressed(KeyEvent JavaDoc e)
183   {
184     if (e.getKeyCode() == KeyEvent.VK_ENTER) _butOk_actionPerformed(null);
185     if (e.getKeyCode() == KeyEvent.VK_ESCAPE) _butCancel_actionPerformed(null);
186   }
187
188 }
Popular Tags