KickJava   Java API By Example, From Geeks To Geeks.

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


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 GuiInputBackupFrame 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 GuiInputBackupFrame(Frame JavaDoc owner, String JavaDoc[] entries,
146       ActionListener JavaDoc listener) throws HeadlessException JavaDoc
147   {
148     super(owner, GuiTranslate.get("frame.backup.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 = 550;
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_BACKUP_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, 10);
174     sampleJList.setFont(displayFont);
175     sampleJList.addListSelectionListener(new ValueReporter());
176     sampleJList.addKeyListener(keyListener);
177     JScrollPane JavaDoc listPane = new JScrollPane JavaDoc(sampleJList);
178
179     JPanel JavaDoc listPanel = new JPanel JavaDoc();
180     listPanel.setEnabled(false);
181     listPanel.setBackground(Color.white);
182     Border JavaDoc listPanelBorder = BorderFactory.createTitledBorder(GuiTranslate
183         .get("frame.backup.list"));
184     listPanel.setBorder(listPanelBorder);
185     listPanel.add(listPane);
186     content.add(listPanel, BorderLayout.CENTER);
187     JLabel JavaDoc valueLabel = new JLabel JavaDoc(GuiTranslate.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     
209     selectPanel.add(optionConfirm);
210     content.add(selectPanel, BorderLayout.SOUTH);
211     pack();
212   }
213
214   private class ValueReporter implements ListSelectionListener JavaDoc
215   {
216     /**
217      * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
218      */

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

231   public JTextField JavaDoc getValueField()
232   {
233     return valueField;
234   }
235
236   /**
237    * Sets the value value.
238    *
239    * @param value The value to set.
240    */

241   public final void setValue(String JavaDoc value)
242   {
243     valueField.setText(value);
244     valueField.repaint();
245   }
246 }
Popular Tags