001 /* 002 * Copyright 2002-2006 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.springframework.richclient.progress; 017 018 import javax.swing.JProgressBar; 019 020 import org.springframework.util.Assert; 021 022 /** 023 * <code>ProgressMonitor</code> implementation that delegates to a 024 * <code>JProgressBar</code>. 025 * 026 * @author Peter De Bruycker 027 */ 028 public class ProgressBarProgressMonitor implements ProgressMonitor { 029 030 private JProgressBar progressBar; 031 private boolean canceled; 032 033 public ProgressBarProgressMonitor(JProgressBar progressBar) { 034 Assert.notNull(progressBar, "ProgressBar cannot be null."); 035 this.progressBar = progressBar; 036 } 037 038 public JProgressBar getProgressBar() { 039 return progressBar; 040 } 041 042 public boolean isCanceled() { 043 return canceled; 044 } 045 046 public void setCanceled(boolean b) { 047 this.canceled = b; 048 } 049 050 public void done() { 051 // not used 052 } 053 054 public void subTaskStarted(String name) { 055 progressBar.setString(name); 056 } 057 058 public void taskStarted(String name, int totalWork) { 059 progressBar.setIndeterminate(false); 060 progressBar.setMinimum(0); 061 progressBar.setMaximum(totalWork); 062 progressBar.setString(name); 063 } 064 065 public void worked(int work) { 066 progressBar.setValue(progressBar.getValue() + work); 067 } 068 }