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.application.splash;
017    
018    import org.springframework.richclient.progress.ProgressMonitor;
019    
020    /**
021     * <code>ProgressMonitor</code> adapter implementation for the <code>InfiniteProgressPanel</code>.
022     * 
023     * @author Peter De Bruycker
024     */
025    public class InfiniteProgressPanelProgressMonitor implements ProgressMonitor {
026            private boolean cancelled;
027    
028            private InfiniteProgressPanel progressPanel;
029    
030            public InfiniteProgressPanelProgressMonitor(InfiniteProgressPanel progressPanel) {
031                    this.progressPanel = progressPanel;
032            }
033    
034            public void worked(int work) {
035                    // not used
036            }
037    
038            public void taskStarted(String name, int totalWork) {
039                    progressPanel.setText(name);
040                    progressPanel.start();
041            }
042    
043            public void subTaskStarted(String name) {
044                    progressPanel.setText(name);
045            }
046    
047            public void setCanceled(boolean b) {
048                    if (b) {
049                            progressPanel.interrupt();
050                    }
051                    cancelled = b;
052            }
053    
054            public boolean isCanceled() {
055                    return cancelled;
056            }
057    
058            public void done() {
059                    progressPanel.stop();
060            }
061    }