PageRenderTime 45ms CodeModel.GetById 18ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/3.3.0/src/org/getopt/luke/Progress.java

http://luke.googlecode.com/
Java | 61 lines | 51 code | 9 blank | 1 comment | 5 complexity | 3c175b949fde5eb3e3def355df68cd27 MD5 | raw file
 1package org.getopt.luke;
 2
 3import java.io.IOException;
 4import java.util.Observable;
 5import java.util.Observer;
 6
 7public class Progress implements Observer {
 8  Object ui;
 9  Object bar, msg;
10  boolean showing = false;
11  Luke luke;
12  
13  public Progress(Luke luke) {
14    try {
15      ui = luke.parse("/xml/progress.xml", this);
16    } catch (IOException e) {
17      // TODO Auto-generated catch block
18      e.printStackTrace();
19    }
20    this.luke = luke;
21    bar = luke.find(ui, "bar");
22    msg = luke.find(ui, "msg");
23  }
24  
25  public void setMessage(String message) {
26    luke.setString(msg, "text", message);
27  }
28  
29  public void show() {
30    luke.add(ui);
31    luke.repaint();
32    showing = true;
33  }
34  
35  public void hide() {
36    luke.remove(ui);
37    showing = false;
38  }
39  
40  public void cancel(Object dialog) {
41    
42  }
43
44  public void update(Observable o, Object arg) {
45    if (arg instanceof ProgressNotification) {
46      ProgressNotification pn = (ProgressNotification)arg;
47      if (pn.message != null) {
48        luke.setString(msg, "text", pn.message);
49      }
50      luke.setInteger(bar, "minimum", pn.minValue);
51      luke.setInteger(bar, "maximum", pn.maxValue);
52      luke.setInteger(bar, "value", pn.curValue);
53    } else {
54      luke.setString(msg, "text", arg.toString());
55    }
56    if (!showing) {
57      show();
58    }
59    luke.doLayout(ui);
60  }
61}