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 import java.awt.Cursor;
025
026 import javax.swing.JPanel;
027 import javax.swing.JDialog;
028 import javax.swing.JButton;
029 import javax.swing.JProgressBar;
030
031
032 public class ShutdownProgress extends JDialog implements Runnable
033 {
034 private static final long serialVersionUID = 1L;
035 private JPanel jContentPane = null;
036 private JPanel jPanel = null;
037 private JButton jButton = null;
038 private JProgressBar jProgressBar = null;
039 private long timeMillis = 0;
040 private boolean bypass = false;
041
042
043 public void setTime( long millis )
044 {
045 this.timeMillis = millis;
046 }
047
048
049 public void run()
050 {
051 setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) );
052 jProgressBar.setEnabled( true );
053 jProgressBar.setMinimum( 0 );
054 jProgressBar.setMaximum( ( int ) timeMillis );
055 jProgressBar.setValue( 0 );
056 jProgressBar.setStringPainted( true );
057 final long startTime = System.currentTimeMillis();
058 while ( System.currentTimeMillis() - startTime < timeMillis && !bypass )
059 {
060 try
061 {
062 Thread.sleep( 100 );
063 }
064 catch ( InterruptedException e )
065 {
066 // TODO Auto-generated catch block
067 e.printStackTrace();
068 }
069 jProgressBar.setString( ( timeMillis - ( System.currentTimeMillis() - startTime ) ) / 1000
070 + " seconds remaining ..." );
071 jProgressBar.setValue( jProgressBar.getValue() + 100 );
072 this.repaint();
073 }
074
075 setCursor( null );
076 setVisible( false );
077 dispose();
078 }
079
080
081 /**
082 * This is the default constructor
083 */
084 public ShutdownProgress()
085 {
086 super();
087 initialize();
088 }
089
090
091 /**
092 * This method initializes this
093 *
094 * @return void
095 */
096 private void initialize()
097 {
098 this.setSize( 300, 104 );
099 this.setContentPane( getJContentPane() );
100 }
101
102
103 /**
104 * This method initializes jContentPane
105 *
106 * @return javax.swing.JPanel
107 */
108 private JPanel getJContentPane()
109 {
110 if ( jContentPane == null )
111 {
112 jContentPane = new JPanel();
113 jContentPane.setLayout( new BorderLayout() );
114 jContentPane.add( getJPanel(), java.awt.BorderLayout.SOUTH );
115 jContentPane.add( getJProgressBar(), java.awt.BorderLayout.CENTER );
116 }
117 return jContentPane;
118 }
119
120
121 /**
122 * This method initializes jPanel
123 *
124 * @return javax.swing.JPanel
125 */
126 private JPanel getJPanel()
127 {
128 if ( jPanel == null )
129 {
130 jPanel = new JPanel();
131 jPanel.add( getJButton(), null );
132 }
133 return jPanel;
134 }
135
136
137 /**
138 * This method initializes jButton
139 *
140 * @return javax.swing.JButton
141 */
142 private JButton getJButton()
143 {
144 if ( jButton == null )
145 {
146 jButton = new JButton();
147 jButton.setText( "Bypass Delay" );
148 jButton.setText( "Bypass Delay" );
149 jButton.addActionListener( new java.awt.event.ActionListener()
150 {
151 public void actionPerformed( java.awt.event.ActionEvent e )
152 {
153 bypass = true;
154 }
155 } );
156 }
157 return jButton;
158 }
159
160
161 /**
162 * This method initializes jProgressBar
163 *
164 * @return javax.swing.JProgressBar
165 */
166 private JProgressBar getJProgressBar()
167 {
168 if ( jProgressBar == null )
169 {
170 jProgressBar = new JProgressBar();
171 }
172 return jProgressBar;
173 }
174
175 } // @jve:decl-index=0:visual-constraint="10,10"