src/core/net/sf/basedb/util/ConsoleProgressReporter.java

Code
Comments
Other
Rev Date Author Line
1290 08 Sep 05 nicklas 1 /*
1290 08 Sep 05 nicklas 2   $Id$
1290 08 Sep 05 nicklas 3
3675 16 Aug 07 jari 4   Copyright (C) 2005 Nicklas Nordborg
4889 06 Apr 09 nicklas 5   Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg
1290 08 Sep 05 nicklas 6  
2304 22 May 06 jari 7   This file is part of BASE - BioArray Software Environment.
2304 22 May 06 jari 8   Available at http://base.thep.lu.se/
1290 08 Sep 05 nicklas 9
1290 08 Sep 05 nicklas 10   BASE is free software; you can redistribute it and/or
1290 08 Sep 05 nicklas 11   modify it under the terms of the GNU General Public License
4479 05 Sep 08 jari 12   as published by the Free Software Foundation; either version 3
1290 08 Sep 05 nicklas 13   of the License, or (at your option) any later version.
1290 08 Sep 05 nicklas 14
1290 08 Sep 05 nicklas 15   BASE is distributed in the hope that it will be useful,
1290 08 Sep 05 nicklas 16   but WITHOUT ANY WARRANTY; without even the implied warranty of
1290 08 Sep 05 nicklas 17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1290 08 Sep 05 nicklas 18   GNU General Public License for more details.
1290 08 Sep 05 nicklas 19
1290 08 Sep 05 nicklas 20    You should have received a copy of the GNU General Public License
4515 11 Sep 08 jari 21    along with BASE. If not, see <http://www.gnu.org/licenses/>.
1290 08 Sep 05 nicklas 22 */
1290 08 Sep 05 nicklas 23 package net.sf.basedb.util;
1290 08 Sep 05 nicklas 24
1290 08 Sep 05 nicklas 25 import net.sf.basedb.core.ProgressReporter;
1290 08 Sep 05 nicklas 26
1290 08 Sep 05 nicklas 27 /**
1290 08 Sep 05 nicklas 28   An implementation of the ProgressReporter interface that writes
1290 08 Sep 05 nicklas 29   all messages to the standard console.
1290 08 Sep 05 nicklas 30   
1290 08 Sep 05 nicklas 31   @author Nicklas
1290 08 Sep 05 nicklas 32   @version 2.0
1290 08 Sep 05 nicklas 33   @base.modified $Date$
1290 08 Sep 05 nicklas 34
1290 08 Sep 05 nicklas 35 */
1290 08 Sep 05 nicklas 36 public class ConsoleProgressReporter 
1290 08 Sep 05 nicklas 37   implements ProgressReporter
1290 08 Sep 05 nicklas 38 {
1290 08 Sep 05 nicklas 39
2261 16 May 06 nicklas 40   private final boolean useNewLine;
1290 08 Sep 05 nicklas 41   private boolean needNewLine = false;
1290 08 Sep 05 nicklas 42
2261 16 May 06 nicklas 43   public ConsoleProgressReporter()
2261 16 May 06 nicklas 44   {
2261 16 May 06 nicklas 45     this(true);
2261 16 May 06 nicklas 46   }
2261 16 May 06 nicklas 47   public ConsoleProgressReporter(boolean useNewline)
2261 16 May 06 nicklas 48   {
2261 16 May 06 nicklas 49     this.useNewLine = useNewline;
2261 16 May 06 nicklas 50   }
2261 16 May 06 nicklas 51   
2261 16 May 06 nicklas 52   /*
2261 16 May 06 nicklas 53     From the ProgressReporter interface
2261 16 May 06 nicklas 54     -------------------------------------------
2261 16 May 06 nicklas 55   */
6127 14 Sep 12 nicklas 56   @Override
1290 08 Sep 05 nicklas 57   public void display(int percent, String message)
1290 08 Sep 05 nicklas 58   {
2261 16 May 06 nicklas 59     if (needNewLine) System.out.print(useNewLine ? "\n" : "\r");
5329 29 Apr 10 nicklas 60     System.out.print("["+(percent == -1 ? "unknown" : percent + "%") + "]\t" + 
5329 29 Apr 10 nicklas 61         (message == null ? "" : message));
1290 08 Sep 05 nicklas 62     needNewLine = true;
1290 08 Sep 05 nicklas 63   }
6127 14 Sep 12 nicklas 64   @Override
1290 08 Sep 05 nicklas 65   public void append(String message)
1290 08 Sep 05 nicklas 66   {
1290 08 Sep 05 nicklas 67     System.out.print(message);
1290 08 Sep 05 nicklas 68   }
2261 16 May 06 nicklas 69   // -------------------------------------------
1290 08 Sep 05 nicklas 70
1290 08 Sep 05 nicklas 71 }