View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.server.ldap.gui;
21  
22  
23  import java.awt.BorderLayout;
24  
25  import javax.swing.JOptionPane;
26  import javax.swing.JPanel;
27  import javax.swing.JDialog;
28  import javax.swing.JButton;
29  import javax.swing.JTextField;
30  import javax.swing.BoxLayout;
31  import javax.swing.JLabel;
32  
33  
34  public class ShutdownDialog extends JDialog
35  {
36      private static final long serialVersionUID = -6681747075037789868L;
37  
38      private JPanel jContentPane = null;
39      private JPanel inputsPanel = null;
40      private JPanel buttonsPanel = null;
41      private JButton sendButton = null;
42      private JButton cancelButton = null;
43      private JPanel jPanel = null;
44      private JPanel jPanel1 = null;
45      private JLabel jLabel = null;
46      private JTextField timeOfflineField = null;
47      private JLabel jLabel1 = null;
48      private JTextField delayField = null;
49      private boolean canceled = true;
50  
51  
52      /**
53       * This is the default constructor
54       */
55      public ShutdownDialog()
56      {
57          super();
58          initialize();
59      }
60  
61  
62      public boolean isSendCanceled()
63      {
64          return canceled;
65      }
66  
67  
68      public int getTimeOffline()
69      {
70          return Integer.parseInt( timeOfflineField.getText() );
71      }
72  
73  
74      public int getDelay()
75      {
76          return Integer.parseInt( delayField.getText() );
77      }
78  
79  
80      public boolean isCanceled()
81      {
82          return canceled;
83      }
84  
85  
86      /**
87       * This method initializes this
88       * 
89       * @return void
90       */
91      private void initialize()
92      {
93          this.setSize( 248, 171 );
94          this.setTitle( "Shutdown Parameters" );
95          this.setContentPane( getJContentPane() );
96      }
97  
98  
99      /**
100      * This method initializes jContentPane
101      * 
102      * @return javax.swing.JPanel
103      */
104     private JPanel getJContentPane()
105     {
106         if ( jContentPane == null )
107         {
108             jContentPane = new JPanel();
109             jContentPane.setLayout( new BorderLayout() );
110             jContentPane.add( getJPanel(), java.awt.BorderLayout.CENTER );
111             jContentPane.add( getJPanel2(), java.awt.BorderLayout.SOUTH );
112         }
113         return jContentPane;
114     }
115 
116 
117     /**
118      * This method initializes jPanel    
119      *     
120      * @return javax.swing.JPanel    
121      */
122     private JPanel getJPanel()
123     {
124         if ( inputsPanel == null )
125         {
126             inputsPanel = new JPanel();
127             inputsPanel.setLayout( null );
128             inputsPanel.setBorder( javax.swing.BorderFactory
129                 .createEtchedBorder( javax.swing.border.EtchedBorder.RAISED ) );
130             inputsPanel.add( getJPanel3(), null );
131             inputsPanel.add( getJPanel1(), null );
132         }
133         return inputsPanel;
134     }
135 
136 
137     /**
138      * This method initializes jPanel    
139      *     
140      * @return javax.swing.JPanel    
141      */
142     private JPanel getJPanel2()
143     {
144         if ( buttonsPanel == null )
145         {
146             buttonsPanel = new JPanel();
147             buttonsPanel.add( getJButton(), null );
148             buttonsPanel.add( getJButton2(), null );
149         }
150         return buttonsPanel;
151     }
152 
153 
154     /**
155      * This method initializes jButton    
156      *     
157      * @return javax.swing.JButton    
158      */
159     private JButton getJButton()
160     {
161         if ( sendButton == null )
162         {
163             sendButton = new JButton();
164             sendButton.setText( "Send" );
165             sendButton.addActionListener( new java.awt.event.ActionListener()
166             {
167                 public void actionPerformed( java.awt.event.ActionEvent e )
168                 {
169                     int timeOffline = 0;
170                     try
171                     {
172                         timeOffline = Integer.parseInt( timeOfflineField.getText() );
173                         if ( timeOffline > 720 || timeOffline < 0 )
174                         {
175                             JOptionPane.showMessageDialog( ShutdownDialog.this,
176                                 "Time Offline is out of range: 0 ... 720", "Range Problem", JOptionPane.ERROR_MESSAGE );
177                             timeOfflineField.setText( "" );
178                             return;
179                         }
180                     }
181                     catch ( NumberFormatException nfe )
182                     {
183                         JOptionPane.showMessageDialog( ShutdownDialog.this,
184                             "The value for Time Offline is not a number", "Not a Number", JOptionPane.ERROR_MESSAGE );
185                         timeOfflineField.setText( "" );
186                         return;
187                     }
188                     int delay = 0;
189                     try
190                     {
191                         delay = Integer.parseInt( delayField.getText() );
192                         if ( delay > 86400 || delay < 0 )
193                         {
194                             JOptionPane.showMessageDialog( ShutdownDialog.this, "Delay is out of range: 0 ... 86400",
195                                 "Range Problem", JOptionPane.ERROR_MESSAGE );
196                             delayField.setText( "" );
197                             return;
198                         }
199                     }
200                     catch ( NumberFormatException nfe )
201                     {
202                         JOptionPane.showMessageDialog( ShutdownDialog.this, "Delay is not a number", "Not a Number",
203                             JOptionPane.ERROR_MESSAGE );
204                         delayField.setText( "" );
205                         return;
206                     }
207                     canceled = false;
208                     setVisible( false );
209                     dispose();
210                 }
211             } );
212         }
213         return sendButton;
214     }
215 
216 
217     /**
218      * This method initializes jButton    
219      *     
220      * @return javax.swing.JButton    
221      */
222     private JButton getJButton2()
223     {
224         if ( cancelButton == null )
225         {
226             cancelButton = new JButton();
227             cancelButton.setText( "Cancel" );
228             cancelButton.setSelected( true );
229             cancelButton.addActionListener( new java.awt.event.ActionListener()
230             {
231                 public void actionPerformed( java.awt.event.ActionEvent e )
232                 {
233                     canceled = true;
234                     setVisible( false );
235                     dispose();
236                     return;
237                 }
238             } );
239         }
240         return cancelButton;
241     }
242 
243 
244     /**
245      * This method initializes jPanel    
246      *     
247      * @return javax.swing.JPanel    
248      */
249     private JPanel getJPanel3()
250     {
251         if ( jPanel == null )
252         {
253             jLabel = new JLabel();
254             jLabel.setText( "Minutes Offline: " );
255             jPanel = new JPanel();
256             jPanel.setLayout( new BoxLayout( getJPanel3(), BoxLayout.X_AXIS ) );
257             jPanel.setBounds( new java.awt.Rectangle( 35, 28, 163, 16 ) );
258             jPanel.add( jLabel, null );
259             jPanel.add( getJTextField(), null );
260         }
261         return jPanel;
262     }
263 
264 
265     /**
266      * This method initializes jPanel1    
267      *     
268      * @return javax.swing.JPanel    
269      */
270     private JPanel getJPanel1()
271     {
272         if ( jPanel1 == null )
273         {
274             jLabel1 = new JLabel();
275             jLabel1.setText( "Seconds Delay: " );
276             jPanel1 = new JPanel();
277             jPanel1.setLayout( new BoxLayout( getJPanel1(), BoxLayout.X_AXIS ) );
278             jPanel1.setBounds( new java.awt.Rectangle( 42, 57, 156, 16 ) );
279             jPanel1.add( jLabel1, null );
280             jPanel1.add( getJTextField1(), null );
281         }
282         return jPanel1;
283     }
284 
285 
286     /**
287      * This method initializes jTextField    
288      *     
289      * @return javax.swing.JTextField    
290      */
291     private JTextField getJTextField()
292     {
293         if ( timeOfflineField == null )
294         {
295             timeOfflineField = new JTextField();
296         }
297         return timeOfflineField;
298     }
299 
300 
301     /**
302      * This method initializes jTextField1    
303      *     
304      * @return javax.swing.JTextField    
305      */
306     private JTextField getJTextField1()
307     {
308         if ( delayField == null )
309         {
310             delayField = new JTextField();
311         }
312         return delayField;
313     }
314 
315 } //  @jve:decl-index=0:visual-constraint="10,10"