001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020 package org.apache.directory.server.ldap.gui; 021 022 023 import java.awt.BorderLayout; 024 025 import javax.swing.JOptionPane; 026 import javax.swing.JPanel; 027 import javax.swing.JDialog; 028 import javax.swing.JButton; 029 import javax.swing.JTextField; 030 import javax.swing.BoxLayout; 031 import javax.swing.JLabel; 032 033 034 public class ShutdownDialog extends JDialog 035 { 036 private static final long serialVersionUID = -6681747075037789868L; 037 038 private JPanel jContentPane = null; 039 private JPanel inputsPanel = null; 040 private JPanel buttonsPanel = null; 041 private JButton sendButton = null; 042 private JButton cancelButton = null; 043 private JPanel jPanel = null; 044 private JPanel jPanel1 = null; 045 private JLabel jLabel = null; 046 private JTextField timeOfflineField = null; 047 private JLabel jLabel1 = null; 048 private JTextField delayField = null; 049 private boolean canceled = true; 050 051 052 /** 053 * This is the default constructor 054 */ 055 public ShutdownDialog() 056 { 057 super(); 058 initialize(); 059 } 060 061 062 public boolean isSendCanceled() 063 { 064 return canceled; 065 } 066 067 068 public int getTimeOffline() 069 { 070 return Integer.parseInt( timeOfflineField.getText() ); 071 } 072 073 074 public int getDelay() 075 { 076 return Integer.parseInt( delayField.getText() ); 077 } 078 079 080 public boolean isCanceled() 081 { 082 return canceled; 083 } 084 085 086 /** 087 * This method initializes this 088 * 089 * @return void 090 */ 091 private void initialize() 092 { 093 this.setSize( 248, 171 ); 094 this.setTitle( "Shutdown Parameters" ); 095 this.setContentPane( getJContentPane() ); 096 } 097 098 099 /** 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"