From 847531419a4c04b3f94f22538262bfe20680cab9 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sun, 6 Apr 2008 13:42:10 +0200 Subject: [PATCH] Add a progress monitor inteface and some simple implementions of it Signed-off-by: Robin Rosenberg --- .../spearce/jgit/lib/AbstractProgressMonitor.java | 14 +++---- .../src/org/spearce/jgit/lib/ProgressMonitor.java | 43 ++++++++++++---------- .../org/spearce/jgit/lib/TextProgressMonitor.java | 2 +- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/AbstractProgressMonitor.java b/org.spearce.jgit/src/org/spearce/jgit/lib/AbstractProgressMonitor.java index 5bb16474..5e308548 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/AbstractProgressMonitor.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/AbstractProgressMonitor.java @@ -24,7 +24,7 @@ public abstract class AbstractProgressMonitor implements ProgressMonitor { private int total; private int worked; - private String task; + private String message; private boolean done; public void done() { @@ -41,12 +41,12 @@ public abstract class AbstractProgressMonitor implements ProgressMonitor { return false; } - public void setCancelled(final boolean cancelled) { + public void setCanceled(final boolean cancelled) { // empty } - public void setTask(final String task) { - this.task = task; + public void setMessage(final String message) { + this.message = message; report(); } @@ -56,7 +56,7 @@ public abstract class AbstractProgressMonitor implements ProgressMonitor { } public void beginTask(final String task, final int total) { - this.task = task; + this.message = task; this.total = total; report(); } @@ -66,8 +66,8 @@ public abstract class AbstractProgressMonitor implements ProgressMonitor { */ abstract protected void report(); - public String getTask() { - return task; + public String getMessage() { + return message; } public int getWorked() { diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ProgressMonitor.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ProgressMonitor.java index 47ae9eaf..ce1986ff 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/ProgressMonitor.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ProgressMonitor.java @@ -1,31 +1,36 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. +/* + * Copyright (C) 2007 Robin Rosenberg * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License, version 2, as published by the Free Software Foundation. * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + */ package org.spearce.jgit.lib; /** - * A progress monitor. A ripoff of IProgressMonitor. + * A progress reporting interface */ public interface ProgressMonitor { /** - * Set task name + * Set information name * * @param message */ - void setTask(String message); + void setMessage(String message); /** - * @return taskname + * @return progress message */ - String getTask(); + String getMessage(); /** * Set the total expected amount of work @@ -65,18 +70,18 @@ public interface ProgressMonitor { boolean isCancelled(); /** - * Request the task to be cancelled + * Request the task to be canceled * - * @param cancelled + * @param canceled */ - void setCancelled(boolean cancelled); + void setCanceled(boolean canceled); /** * Begin a task * - * @param task + * @param message * @param total */ - void beginTask(String task, int total); + void beginTask(String message, int total); } diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/TextProgressMonitor.java b/org.spearce.jgit/src/org/spearce/jgit/lib/TextProgressMonitor.java index 8696989e..61ad687c 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/TextProgressMonitor.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/TextProgressMonitor.java @@ -27,7 +27,7 @@ public class TextProgressMonitor extends AbstractProgressMonitor { protected void report() { int tot = getTotal() + 1; if ((lastWorked+1)*100/tot != (getWorked()+1)*100/tot) - System.out.println(getTask() + " " + (getWorked()*100 / tot) + "%"); + System.out.println(getMessage() + " " + (getWorked()*100 / tot) + "%"); lastWorked = getWorked(); } -- 2.11.4.GIT