KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > gui > frames > GuiSelectDumpFrame


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.console.gui.frames;
26
27 import java.awt.BorderLayout JavaDoc;
28 import java.awt.Color JavaDoc;
29 import java.awt.Container JavaDoc;
30 import java.awt.Dimension JavaDoc;
31 import java.awt.Font JavaDoc;
32 import java.awt.Frame JavaDoc;
33 import java.awt.HeadlessException JavaDoc;
34 import java.awt.Toolkit JavaDoc;
35 import java.awt.event.ActionListener JavaDoc;
36 import java.awt.event.WindowEvent JavaDoc;
37 import java.awt.event.WindowListener JavaDoc;
38 import java.awt.event.WindowStateListener JavaDoc;
39
40 import javax.swing.BorderFactory JavaDoc;
41 import javax.swing.JButton JavaDoc;
42 import javax.swing.JDialog JavaDoc;
43 import javax.swing.JLabel JavaDoc;
44 import javax.swing.JList JavaDoc;
45 import javax.swing.JPanel JavaDoc;
46 import javax.swing.JScrollPane JavaDoc;
47 import javax.swing.JTextField JavaDoc;
48 import javax.swing.border.Border JavaDoc;
49 import javax.swing.event.ListSelectionEvent JavaDoc;
50 import javax.swing.event.ListSelectionListener JavaDoc;
51
52 import org.objectweb.cjdbc.common.i18n.GuiTranslate;
53 import org.objectweb.cjdbc.console.gui.FrameConfirmKeyListener;
54 import org.objectweb.cjdbc.console.gui.constants.GuiCommands;
55 import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
56
57 /**
58  * This class defines a GuiSelectCheckpoint
59  *
60  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
61  * @version 1.0
62  */

63 public class GuiSelectDumpFrame extends JDialog JavaDoc
64     implements
65       WindowListener JavaDoc,
66       WindowStateListener JavaDoc
67 {
68   private JList JavaDoc sampleJList;
69   private JTextField JavaDoc valueField;
70   private FrameConfirmKeyListener keyListener;
71
72   /**
73    * @see java.awt.event.WindowListener#windowActivated(java.awt.event.WindowEvent)
74    */

75   public void windowActivated(WindowEvent JavaDoc e)
76   {
77
78   }
79
80   /**
81    * @see java.awt.event.WindowListener#windowClosed(java.awt.event.WindowEvent)
82    */

83   public void windowClosed(WindowEvent JavaDoc e)
84   {
85     this.setVisible(false);
86     valueField = null;
87   }
88
89   /**
90    * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
91    */

92   public void windowClosing(WindowEvent JavaDoc e)
93   {
94     valueField = null;
95   }
96
97   /**
98    * @see java.awt.event.WindowListener#windowDeactivated(java.awt.event.WindowEvent)
99    */

100   public void windowDeactivated(WindowEvent JavaDoc e)
101   {
102
103   }
104
105   /**
106    * @see java.awt.event.WindowListener#windowDeiconified(java.awt.event.WindowEvent)
107    */

108   public void windowDeiconified(WindowEvent JavaDoc e)
109   {
110
111   }
112
113   /**
114    * @see java.awt.event.WindowListener#windowIconified(java.awt.event.WindowEvent)
115    */

116   public void windowIconified(WindowEvent JavaDoc e)
117   {
118
119   }
120
121   /**
122    * @see java.awt.event.WindowListener#windowOpened(java.awt.event.WindowEvent)
123    */

124   public void windowOpened(WindowEvent JavaDoc e)
125   {
126
127   }
128
129   /**
130    * @see java.awt.event.WindowStateListener#windowStateChanged(java.awt.event.WindowEvent)
131    */

132   public void windowStateChanged(WindowEvent JavaDoc e)
133   {
134
135   }
136
137   /**
138    * Creates a new <code>GuiSelectCheckpoint</code> object
139    *
140    * @param owner frame owner
141    * @param entries choices for selection
142    * @param listener to receive events
143    * @throws java.awt.HeadlessException if fails
144    */

145   public GuiSelectDumpFrame(Frame JavaDoc owner, String JavaDoc[] entries,
146       ActionListener JavaDoc listener) throws HeadlessException JavaDoc
147   {
148     super(owner, GuiTranslate.get("frame.checkpoint.title"), true);
149
150     // Center
151
Toolkit JavaDoc toolkit = Toolkit.getDefaultToolkit();
152     Dimension JavaDoc dim = toolkit.getScreenSize();
153     int screenHeight = dim.height;
154     int screenWidth = dim.width;
155     int frameWidth = 450;
156     int frameHeight = 50;
157     this.setBounds((screenWidth - frameWidth) / 2,
158         (screenHeight - frameHeight) / 2, frameWidth, frameHeight);
159
160     this.addWindowListener(this);
161     this.addWindowStateListener(this);
162
163     JButton JavaDoc optionConfirm = new JButton JavaDoc(GuiTranslate.get("frame.ok"));
164     optionConfirm.setActionCommand(GuiCommands.COMMAND_HIDE_CHECKPOINT_FRAME);
165     optionConfirm.addActionListener(listener);
166     
167     keyListener = new FrameConfirmKeyListener(optionConfirm);
168     this.addKeyListener(keyListener);
169     
170     Container JavaDoc content = getContentPane();
171     sampleJList = new JList JavaDoc(entries);
172     sampleJList.setVisibleRowCount(4);
173     Font JavaDoc displayFont = new Font JavaDoc("Serif", Font.BOLD, 12);
174     sampleJList.setFont(displayFont);
175     sampleJList.addListSelectionListener(new ValueReporter());
176     JScrollPane JavaDoc listPane = new JScrollPane JavaDoc(sampleJList);
177     sampleJList.addKeyListener(keyListener);
178
179     JPanel JavaDoc listPanel = new JPanel JavaDoc();
180     listPanel.setBackground(Color.white);
181     Border JavaDoc listPanelBorder = BorderFactory.createTitledBorder(GuiTranslate
182         .get("frame.backup.list"));
183     listPanel.setBorder(listPanelBorder);
184     listPanel.add(listPane);
185     content.add(listPanel, BorderLayout.CENTER);
186     JLabel JavaDoc valueLabel = new JLabel JavaDoc(GuiTranslate
187         .get("frame.backup.selection"));
188     valueLabel.setFont(displayFont);
189     valueField = new JTextField JavaDoc(GuiConstants.BACKEND_NO_CHECKPOINT, 7);
190     valueField.setFont(displayFont);
191     valueField.addKeyListener(keyListener);
192
193     JPanel JavaDoc valuePanel = new JPanel JavaDoc();
194     valuePanel.setBackground(Color.white);
195     Border JavaDoc valuePanelBorder = BorderFactory.createTitledBorder(GuiTranslate
196         .get("frame.backup"));
197     valuePanel.setBorder(valuePanelBorder);
198     valuePanel.add(valueLabel);
199     valuePanel.add(valueField);
200     content.add(valuePanel, BorderLayout.NORTH);
201
202     JPanel JavaDoc selectPanel = new JPanel JavaDoc();
203     selectPanel.setBackground(Color.white);
204     Border JavaDoc selectPanelBorder = BorderFactory.createTitledBorder(GuiTranslate
205         .get("frame.select"));
206     selectPanel.setBorder(selectPanelBorder);
207     
208     selectPanel.add(optionConfirm);
209     content.add(selectPanel, BorderLayout.SOUTH);
210     pack();
211   }
212
213   private class ValueReporter implements ListSelectionListener JavaDoc
214   {
215     /**
216      * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
217      */

218     public void valueChanged(ListSelectionEvent JavaDoc event)
219     {
220       if (!event.getValueIsAdjusting())
221         valueField.setText(sampleJList.getSelectedValue().toString());
222     }
223   }
224
225   /**
226    * Returns the valueField value.
227    *
228    * @return Returns the valueField.
229    */

230   public JTextField JavaDoc getValueField()
231   {
232     return valueField;
233   }
234 }
Popular Tags