View Javadoc

1   /*
2    *  Licensed under the Apache License, Version 2.0 (the "License");
3    *  you may not use this file except in compliance with the License.
4    *  You may obtain a copy of the License at
5    *
6    *      http://www.apache.org/licenses/LICENSE-2.0
7    *
8    *  Unless required by applicable law or agreed to in writing, software
9    *  distributed under the License is distributed on an "AS IS" BASIS,
10   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   *  See the License for the specific language governing permissions and
12   *  limitations under the License.
13   */
14  /*
15   * This file has been modified by Chris Pheby in accordance with Section 4.2
16   * of the Apache Software License
17   */
18  package org.jadira.dependencynavigator.gui;
19  
20  import java.io.File;
21  
22  import javax.swing.JLabel;
23  import javax.swing.SwingUtilities;
24  
25  import org.jadira.dependencynavigator.implementations.IProgressMeter;
26  import org.jadira.dependencynavigator.model.Artifact;
27  
28  public class ProgressMeter implements IProgressMeter {
29  
30      private final JLabel label;
31  
32      public ProgressMeter(JLabel label) {
33          this.label = label;
34      }
35  
36      public JLabel getLabel() {
37          return this.label;
38      }
39  
40      private void report(String message) {
41          SwingUtilities.invokeLater(new ProgressUpdateThread(message));
42      }
43  
44      public void resolving(Artifact artifact) {
45          report("resolving: " + artifact.getId());
46      }
47  
48      public void scanning(File pomFile) {
49          report("scanning: " + pomFile.getPath());
50      }
51  
52      public void adding(File pomFile) {
53          report("adding: " + pomFile.getPath());
54      }
55  
56      public void error(Exception e) {
57          report("error [" + e.getClass().getName() + "] " + e.getMessage());
58      }
59  
60      public void ready() {
61          report("ready");
62      }
63  
64      public void snapshotComplete() {
65          report("snapshot complete");
66      }
67  
68      private class ProgressUpdateThread implements Runnable {
69  
70          private String message;
71  
72          public ProgressUpdateThread(String message) {
73              this.message = message;
74          }
75  
76          public void run() {
77              label.setText(message);
78          }
79  
80      }
81  }