KickJava   Java API By Example, From Geeks To Geeks.

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


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.event.ActionEvent JavaDoc;
35 import java.awt.event.KeyEvent JavaDoc;
36
37 import javax.swing.DefaultComboBoxModel JavaDoc;
38 import javax.swing.JButton JavaDoc;
39 import javax.swing.JLabel JavaDoc;
40 import javax.swing.JList JavaDoc;
41 import javax.swing.JPanel JavaDoc;
42 import javax.swing.JScrollPane JavaDoc;
43 import javax.swing.JTextField JavaDoc;
44 import javax.swing.event.ListSelectionEvent JavaDoc;
45
46 import com.genimen.djeneric.language.Messages;
47 import com.genimen.djeneric.repository.DjPackage;
48 import com.genimen.djeneric.repository.DjPersistenceManager;
49 import com.genimen.djeneric.ui.DjVerticalFlowLayout;
50 import com.genimen.djeneric.ui.Util;
51 import com.genimen.djeneric.util.DjLogger;
52
53 public class PackageEditorPanel extends JPanel JavaDoc
54 {
55   private static final long serialVersionUID = 1L;
56   BorderLayout JavaDoc borderLayout1 = new BorderLayout JavaDoc();
57   JPanel JavaDoc jPanel3 = new JPanel JavaDoc();
58   JButton JavaDoc _butCreate = new JButton JavaDoc();
59   JButton JavaDoc _butRemove = new JButton JavaDoc();
60   BorderLayout JavaDoc borderLayout3 = new BorderLayout JavaDoc();
61   JScrollPane JavaDoc jScrollPane1 = new JScrollPane JavaDoc();
62   DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout();
63   JList JavaDoc _lstPackages = new JList JavaDoc();
64   DjPersistenceManager _mgr;
65   JPanel JavaDoc jPanel1 = new JPanel JavaDoc();
66   JLabel JavaDoc _lblPackage = new JLabel JavaDoc();
67   JTextField JavaDoc _edtName = new JTextField JavaDoc();
68   BorderLayout JavaDoc borderLayout2 = new BorderLayout JavaDoc();
69   JPanel JavaDoc jPanel2 = new JPanel JavaDoc();
70   BorderLayout JavaDoc borderLayout4 = new BorderLayout JavaDoc();
71
72   public PackageEditorPanel(DjPersistenceManager mgr)
73   {
74     _mgr = mgr;
75
76     try
77     {
78       jbInit();
79       updateModel(null);
80
81     }
82     catch (Exception JavaDoc ex)
83     {
84       DjLogger.log(ex);
85     }
86   }
87
88   private void updateModel(DjPackage selectThisOne)
89   {
90     _lstPackages.setModel(new DefaultComboBoxModel JavaDoc(_mgr.getPackages()));
91     if (selectThisOne != null) _lstPackages.setSelectedValue(selectThisOne, true);
92   }
93
94   void jbInit() throws Exception JavaDoc
95   {
96     this.setLayout(borderLayout1);
97     _butCreate.setText(Messages.getString("global.Create"));
98     _butCreate.addActionListener(new PackageEditorPanel__butCreate_actionAdapter(this));
99     _butRemove.setText(Messages.getString("global.Delete"));
100     _butRemove.addActionListener(new PackageEditorPanel__butRemove_actionAdapter(this));
101     jPanel3.setLayout(verticalFlowLayout1);
102     _lblPackage.setText(Messages.getString("PackageEditorPanel.PackageName"));
103     jPanel1.setLayout(borderLayout2);
104     _edtName.setFont(new java.awt.Font JavaDoc("Monospaced", 0, 11));
105     _edtName.setPreferredSize(new Dimension JavaDoc(200, 21));
106     _edtName.setText("");
107     _edtName.addKeyListener(new PackageEditorPanel__edtName_keyAdapter(this));
108     _lstPackages.setFont(new java.awt.Font JavaDoc("Monospaced", 0, 11));
109     _lstPackages.addListSelectionListener(new PackageEditorPanel__lstPackages_listSelectionAdapter(this));
110     jPanel2.setLayout(borderLayout4);
111     jPanel3.add(_butCreate, null);
112     jPanel3.add(_butRemove, null);
113     this.add(jPanel2, BorderLayout.CENTER);
114     jPanel2.add(jScrollPane1, BorderLayout.CENTER);
115     jPanel2.add(jPanel1, BorderLayout.SOUTH);
116     jScrollPane1.getViewport().add(_lstPackages, null);
117     this.add(jPanel3, BorderLayout.EAST);
118     jPanel1.add(_lblPackage, BorderLayout.NORTH);
119     jPanel1.add(_edtName, BorderLayout.CENTER);
120
121     Util.sizeButtons(jPanel3);
122   }
123
124   void _butCreate_actionPerformed(ActionEvent JavaDoc e)
125   {
126     DjPackage newPack = new DjPackage(Messages.getString("PackageEditorPanel.NewPackage"));
127     _mgr.addPackage(newPack);
128     updateModel(newPack);
129     _edtName.requestFocus();
130     _edtName.selectAll();
131   }
132
133   void _butRemove_actionPerformed(ActionEvent JavaDoc e)
134   {
135     DjPackage sel = (DjPackage) _lstPackages.getSelectedValue();
136     if (sel != null) _mgr.removePackage(sel);
137     updateModel(null);
138   }
139
140   void _lstPackages_valueChanged(ListSelectionEvent JavaDoc e)
141   {
142     String JavaDoc name = "";
143     DjPackage sel = (DjPackage) _lstPackages.getSelectedValue();
144     if (sel != null) name = sel.getName();
145     _edtName.setText(name);
146   }
147
148   void _edtName_keyReleased(KeyEvent JavaDoc e)
149   {
150     DjPackage sel = (DjPackage) _lstPackages.getSelectedValue();
151     if (sel != null && _edtName.getText().trim().length() > 0)
152     {
153       sel.setName(_edtName.getText().trim());
154       _lstPackages.repaint();
155     }
156     else _edtName.setText("");
157
158   }
159
160 }
161
162 class PackageEditorPanel__butCreate_actionAdapter implements java.awt.event.ActionListener JavaDoc
163 {
164   PackageEditorPanel adaptee;
165
166   PackageEditorPanel__butCreate_actionAdapter(PackageEditorPanel adaptee)
167   {
168     this.adaptee = adaptee;
169   }
170
171   public void actionPerformed(ActionEvent JavaDoc e)
172   {
173     adaptee._butCreate_actionPerformed(e);
174   }
175 }
176
177 class PackageEditorPanel__butRemove_actionAdapter implements java.awt.event.ActionListener JavaDoc
178 {
179   PackageEditorPanel adaptee;
180
181   PackageEditorPanel__butRemove_actionAdapter(PackageEditorPanel adaptee)
182   {
183     this.adaptee = adaptee;
184   }
185
186   public void actionPerformed(ActionEvent JavaDoc e)
187   {
188     adaptee._butRemove_actionPerformed(e);
189   }
190 }
191
192 class PackageEditorPanel__lstPackages_listSelectionAdapter implements javax.swing.event.ListSelectionListener JavaDoc
193 {
194   PackageEditorPanel adaptee;
195
196   PackageEditorPanel__lstPackages_listSelectionAdapter(PackageEditorPanel adaptee)
197   {
198     this.adaptee = adaptee;
199   }
200
201   public void valueChanged(ListSelectionEvent JavaDoc e)
202   {
203     adaptee._lstPackages_valueChanged(e);
204   }
205 }
206
207 class PackageEditorPanel__edtName_keyAdapter extends java.awt.event.KeyAdapter JavaDoc
208 {
209   PackageEditorPanel adaptee;
210
211   PackageEditorPanel__edtName_keyAdapter(PackageEditorPanel adaptee)
212   {
213     this.adaptee = adaptee;
214   }
215
216   public void keyReleased(KeyEvent JavaDoc e)
217   {
218     adaptee._edtName_keyReleased(e);
219   }
220 }
Popular Tags