KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 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): Emmanuel Cecchet.
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
37 import javax.swing.BorderFactory JavaDoc;
38 import javax.swing.JButton JavaDoc;
39 import javax.swing.JDialog JavaDoc;
40 import javax.swing.JLabel JavaDoc;
41 import javax.swing.JList JavaDoc;
42 import javax.swing.JPanel JavaDoc;
43 import javax.swing.JScrollPane JavaDoc;
44 import javax.swing.JTextField JavaDoc;
45 import javax.swing.border.Border JavaDoc;
46 import javax.swing.event.ListSelectionEvent JavaDoc;
47 import javax.swing.event.ListSelectionListener JavaDoc;
48
49 import org.objectweb.cjdbc.common.i18n.GuiTranslate;
50 import org.objectweb.cjdbc.console.gui.FrameConfirmKeyListener;
51 import org.objectweb.cjdbc.console.gui.constants.GuiCommands;
52
53 /**
54  * This class defines a GuiSelectCheckpoint
55  *
56  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
57  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
58  * </a>
59  * @version 1.0
60  */

61 public class GuiSelectShutdownFrame extends JDialog JavaDoc
62 {
63   private JList JavaDoc sampleJList;
64   private JTextField JavaDoc valueField;
65   private final String JavaDoc[] entries = new String JavaDoc[]{
66       GuiCommands.COMMAND_SHUTDOWN_SAFE, GuiCommands.COMMAND_SHUTDOWN_WAIT,
67       GuiCommands.COMMAND_SHUTDOWN_FORCE };
68
69   private FrameConfirmKeyListener keyListener;
70
71   /**
72    * Creates a new <code>GuiSelectCheckpoint</code> object
73    *
74    * @param owner the frame to attach to
75    * @param listener for handback
76    * @throws java.awt.HeadlessException if fails
77    */

78   public GuiSelectShutdownFrame(Frame JavaDoc owner, ActionListener JavaDoc listener)
79       throws HeadlessException JavaDoc
80   {
81     super(owner, GuiTranslate.get("frame.shutdown.title"), true);
82
83     // Center
84
Toolkit JavaDoc toolkit = Toolkit.getDefaultToolkit();
85     Dimension JavaDoc dim = toolkit.getScreenSize();
86     int screenHeight = dim.height;
87     int screenWidth = dim.width;
88     int frameWidth = 450;
89     int frameHeight = 50;
90     this.setBounds((screenWidth - frameWidth) / 2,
91         (screenHeight - frameHeight) / 2, frameWidth, frameHeight);
92
93     JButton JavaDoc optionConfirm = new JButton JavaDoc(GuiTranslate.get("frame.ok"));
94     optionConfirm.setActionCommand(GuiCommands.COMMAND_HIDE_SHUTDOWN_FRAME);
95     optionConfirm.addActionListener(listener);
96
97     keyListener = new FrameConfirmKeyListener(optionConfirm);
98     this.addKeyListener(keyListener);
99
100     Container JavaDoc content = getContentPane();
101     sampleJList = new JList JavaDoc(entries);
102     sampleJList.setVisibleRowCount(4);
103     Font JavaDoc displayFont = new Font JavaDoc("Serif", Font.BOLD, 12);
104     sampleJList.setFont(displayFont);
105     sampleJList.addListSelectionListener(new ValueReporter());
106     sampleJList.addKeyListener(keyListener);
107     JScrollPane JavaDoc listPane = new JScrollPane JavaDoc(sampleJList);
108
109     JPanel JavaDoc listPanel = new JPanel JavaDoc();
110     listPanel.setBackground(Color.white);
111     Border JavaDoc listPanelBorder = BorderFactory.createTitledBorder(GuiTranslate
112         .get("frame.shutdown.levels"));
113     listPanel.setBorder(listPanelBorder);
114     listPanel.add(listPane);
115     content.add(listPanel, BorderLayout.CENTER);
116     JLabel JavaDoc valueLabel = new JLabel JavaDoc(GuiTranslate.get("frame.shutdown.selection"));
117     valueLabel.setFont(displayFont);
118     valueField = new JTextField JavaDoc(GuiCommands.COMMAND_SHUTDOWN_SAFE, 7);
119     valueField.setEditable(false);
120     valueField.setFont(displayFont);
121     valueField.addKeyListener(keyListener);
122
123     JPanel JavaDoc valuePanel = new JPanel JavaDoc();
124     valuePanel.setBackground(Color.white);
125     Border JavaDoc valuePanelBorder = BorderFactory.createTitledBorder(GuiTranslate
126         .get("frame.shutdown"));
127     valuePanel.setBorder(valuePanelBorder);
128     valuePanel.add(valueLabel);
129     valuePanel.add(valueField);
130     content.add(valuePanel, BorderLayout.NORTH);
131
132     JPanel JavaDoc selectPanel = new JPanel JavaDoc();
133     selectPanel.setBackground(Color.white);
134     Border JavaDoc selectPanelBorder = BorderFactory.createTitledBorder(GuiTranslate
135         .get("frame.select"));
136     selectPanel.setBorder(selectPanelBorder);
137
138     selectPanel.add(optionConfirm);
139     content.add(selectPanel, BorderLayout.SOUTH);
140     pack();
141   }
142
143   private class ValueReporter implements ListSelectionListener JavaDoc
144   {
145     /**
146      * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
147      */

148     public void valueChanged(ListSelectionEvent JavaDoc event)
149     {
150       if (!event.getValueIsAdjusting())
151         valueField.setText(sampleJList.getSelectedValue().toString());
152     }
153   }
154
155   /**
156    * Returns the sampleJList value.
157    *
158    * @return Returns the sampleJList.
159    */

160   public JList JavaDoc getSampleJList()
161   {
162     return sampleJList;
163   }
164
165   /**
166    * Returns the valueField value.
167    *
168    * @return Returns the valueField.
169    */

170   public JTextField JavaDoc getValueField()
171   {
172     return valueField;
173   }
174 }
Popular Tags