KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cvsgrab > util > MaskingThread


1 /*
2  * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification,are permitted provided that the following conditions are met:
6  * - Redistribution of source code must retain the above copyright notice, this list
7  * of conditions and the following disclaimer.
8  * - Redistribution in binary form must reproduce the above copyright notice,
9  * this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  *
12  * Neither the name of Sun Microsystems, Inc. or the names of contributors may
13  * be used to endorse or promote products derived from this software without
14  * specific prior written permission.
15  * This software is provided "AS IS," without a warranty of any kind. ALL
16  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
17  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
18  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
19  * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
20  * A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
21  * IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
22  * OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
23  * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
24  * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
25  * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
26  *
27  * You acknowledge that this software is not designed, licensed or intended for
28  * use in the design, construction, operation or maintenance of any nuclear facility.
29  */

30
31 package net.sourceforge.cvsgrab.util;
32
33
34 /**
35  * This class attempts to erase characters echoed to the console.
36  * @author <a HREF=mailto:"qmahmoud@javacourses.com">Qusay H. Mahmoud</a>
37  */

38 public class MaskingThread extends Thread JavaDoc {
39     private boolean _stop = false;
40     private String JavaDoc _prompt;
41
42     /**
43      * Constructor for MaskingThread
44      *
45      * @param prompt The prompt displayed to the user
46      */

47     public MaskingThread(String JavaDoc prompt) {
48         this._prompt = prompt;
49     }
50
51     /**
52      * Begin masking until asked to stop.
53      */

54     public void run() {
55         while (!_stop) {
56             try {
57                 // attempt masking at this rate
58
Thread.sleep(1);
59             } catch (InterruptedException JavaDoc iex) {
60                 iex.printStackTrace();
61             }
62
63             if (!_stop) {
64                 System.out.print("\r" + _prompt + " \r" + _prompt);
65             }
66
67             System.out.flush();
68         }
69     }
70
71     /**
72      * Instruct the thread to stop masking.
73      */

74     public void stopMasking() {
75         this._stop = true;
76     }
77 }
78
Popular Tags