18 package org.turro.pivot.dialog;
20 import java.io.IOException;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23 import org.apache.pivot.serialization.SerializationException;
24 import org.apache.pivot.util.Resources;
25 import org.apache.pivot.wtk.Action;
26 import org.apache.pivot.wtk.ActivityIndicator;
27 import org.apache.pivot.wtk.Label;
28 import org.apache.pivot.wtk.Meter;
29 import org.apache.pivot.wtk.PushButton;
30 import org.apache.pivot.wtk.Sheet;
31 import org.apache.pivot.wtk.Window;
32 import org.apache.pivot.wtk.content.ButtonData;
33 import org.apache.pivot.wtkx.Bindable;
34 import org.apache.pivot.wtkx.WTKX;
35 import org.apache.pivot.wtkx.WTKXSerializer;
43 private boolean canceled =
false, closeable =
true;
44 private Resources resources;
46 @WTKX
private PushButton progressButton;
47 @WTKX
private ActivityIndicator activityIndicator;
48 @WTKX
private Label caption;
49 @WTKX
private Meter meter;
51 private Action progressAction =
new Action(
true) {
53 public void perform() {
58 progressSheet.closeable =
true;
59 progressSheet.caption.setText((String) progressSheet.resources.get(
"canceled"));
60 ((ButtonData) progressSheet.progressButton.getButtonData()).setText(
61 (String) progressSheet.resources.get(
"close"));
67 progressButton.setAction(progressAction);
68 this.resources = resources;
76 progressSheet.canceled =
false;
77 progressSheet.closeable =
false;
78 progressSheet.meter.setVisible(
false);
79 progressSheet.meter.setText(
null);
80 progressSheet.meter.setPercentage(0);
81 progressSheet.progressAction.setEnabled(canCancel);
82 ((ButtonData) progressSheet.progressButton.getButtonData()).setText(
83 (String) progressSheet.resources.get(
"cancel"));
84 progressSheet.caption.setText(caption);
85 progressSheet.activityIndicator.setActive(
true);
86 progressSheet.open(window);
87 window.setEnabled(
false);
91 progressSheet.canceled =
false;
92 progressSheet.closeable =
false;
93 progressSheet.meter.setVisible(
true);
94 progressSheet.meter.setText(
null);
95 progressSheet.meter.setPercentage(0);
96 progressSheet.progressAction.setEnabled(canCancel);
97 ((ButtonData) progressSheet.progressButton.getButtonData()).setText(
98 (String) progressSheet.resources.get(
"cancel"));
99 progressSheet.caption.setText(caption);
100 progressSheet.activityIndicator.setActive(
true);
101 progressSheet.open(window);
102 window.setEnabled(
false);
105 public static void nextProgress(String caption, String step,
double inc) {
107 double percent = progressSheet.meter.getPercentage();
108 if(percent + inc > 1) {
109 progressSheet.meter.setPercentage(1);
111 progressSheet.meter.setPercentage(percent + inc);
114 if(step !=
null) progressSheet.meter.setText(step);
115 if(caption !=
null) progressSheet.caption.setText(caption);
119 if(caption !=
null) progressSheet.caption.setText(caption);
123 progressSheet.closeable =
true;
124 progressSheet.meter.setText(
null);
125 progressSheet.progressAction.setEnabled(
true);
126 ((ButtonData) progressSheet.progressButton.getButtonData()).setText(
127 (String) progressSheet.resources.get(
"close"));
128 if(caption !=
null) progressSheet.caption.setText(caption);
129 progressSheet.activityIndicator.setActive(
false);
133 window.setEnabled(
true);
134 progressSheet.close();
138 return progressSheet;
144 WTKXSerializer wtkxSerializer =
new WTKXSerializer(
new Resources(
ProgressSheet.class.getName()));
145 progressSheet = (
ProgressSheet) wtkxSerializer.readObject(
"org/turro/pivot/dialog/progress_sheet.wtkx");
147 }
catch (IOException ex) {
148 Logger.getLogger(
ProgressSheet.class.getName()).log(Level.SEVERE,
null, ex);
149 }
catch (SerializationException ex) {
150 Logger.getLogger(
ProgressSheet.class.getName()).log(Level.SEVERE,
null, ex);
152 return progressSheet;
156 private static Window window;
static void startMeasuredProgress(String caption, boolean canCancel)
static void closeProgress()
static void nextProgress(String caption)
static ProgressSheet getInstance(Window parent)
static void endProgress(String caption)
static void nextProgress(String caption, String step, double inc)
static ProgressSheet getInstance()
static void startProgress(String caption, boolean canCancel)
void initialize(Resources resources)