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  import java.awt.Cursor;
25  
26  import javax.swing.JPanel;
27  import javax.swing.JDialog;
28  import javax.swing.JButton;
29  import javax.swing.JProgressBar;
30  
31  
32  public class ShutdownProgress extends JDialog implements Runnable
33  {
34      private static final long serialVersionUID = 1L;
35      private JPanel jContentPane = null;
36      private JPanel jPanel = null;
37      private JButton jButton = null;
38      private JProgressBar jProgressBar = null;
39      private long timeMillis = 0;
40      private boolean bypass = false;
41  
42  
43      public void setTime( long millis )
44      {
45          this.timeMillis = millis;
46      }
47  
48  
49      public void run()
50      {
51          setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) );
52          jProgressBar.setEnabled( true );
53          jProgressBar.setMinimum( 0 );
54          jProgressBar.setMaximum( ( int ) timeMillis );
55          jProgressBar.setValue( 0 );
56          jProgressBar.setStringPainted( true );
57          final long startTime = System.currentTimeMillis();
58          while ( System.currentTimeMillis() - startTime < timeMillis && !bypass )
59          {
60              try
61              {
62                  Thread.sleep( 100 );
63              }
64              catch ( InterruptedException e )
65              {
66                  // TODO Auto-generated catch block
67                  e.printStackTrace();
68              }
69              jProgressBar.setString( ( timeMillis - ( System.currentTimeMillis() - startTime ) ) / 1000
70                  + " seconds remaining ..." );
71              jProgressBar.setValue( jProgressBar.getValue() + 100 );
72              this.repaint();
73          }
74  
75          setCursor( null );
76          setVisible( false );
77          dispose();
78      }
79  
80  
81      /**
82       * This is the default constructor
83       */
84      public ShutdownProgress()
85      {
86          super();
87          initialize();
88      }
89  
90  
91      /**
92       * This method initializes this
93       * 
94       * @return void
95       */
96      private void initialize()
97      {
98          this.setSize( 300, 104 );
99          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"