001: /*
002: * GWT-Ext Widget Library
003: * Copyright(c) 2007-2008, GWT-Ext.
004: * licensing@gwt-ext.com
005: *
006: * http://www.gwt-ext.com/license
007: */
008: package com.gwtext.sample.showcase2.client.misc;
009:
010: import com.google.gwt.user.client.Timer;
011: import com.gwtext.client.core.EventObject;
012: import com.gwtext.client.core.Ext;
013: import com.gwtext.client.core.Function;
014: import com.gwtext.client.util.Format;
015: import com.gwtext.client.widgets.*;
016: import com.gwtext.client.widgets.event.ButtonListenerAdapter;
017: import com.gwtext.client.widgets.layout.VerticalLayout;
018: import com.gwtext.sample.showcase2.client.ShowcasePanel;
019:
020: public class ProgressBarSample extends ShowcasePanel {
021:
022: public String getSourceUrl() {
023: return "source/misc/ProgressBarSample.java.html";
024: }
025:
026: public String getCssUrl() {
027: return "source/misc/ProgressBarSample.css.html";
028: }
029:
030: public Panel getViewPanel() {
031: if (panel == null) {
032: panel = new Panel();
033: panel.setLayout(new VerticalLayout(15));
034:
035: final ProgressBar pbar1 = new ProgressBar();
036: pbar1.setWidth(300);
037: pbar1.setText("Ready");
038:
039: Panel panel1 = new Panel();
040: panel1.setTitle("Basic Progress Bar");
041: panel1.setFrame(true);
042: panel1.setWidth(400);
043: panel1.setHeight(150);
044: panel1.setPaddings(20);
045:
046: Button button1 = new Button("Start",
047: new ButtonListenerAdapter() {
048: public void onClick(final Button button,
049: EventObject e) {
050: button.disable();
051: pbar1.reset();
052: for (int i = 1; i < 12; i++) {
053: final int j = i;
054: Timer timer = new Timer() {
055: public void run() {
056: if (j == 11) {
057: pbar1.setText("Done.");
058: button.enable();
059: } else {
060: pbar1
061: .setText(Format
062: .format(
063: "Loading item {0} of 10...",
064: j
065: + ""));
066: pbar1.setValue(pbar1
067: .getValue() + 0.1f);
068: }
069: }
070: };
071: timer.schedule(i * 1000);
072: }
073:
074: }
075: });
076: panel1.add(new HTMLPanel(
077: "A Basic ProgressBar with build-in progress text.",
078: 0, 0, 0, 10));
079: panel1.add(pbar1);
080: panel1.addButton(button1);
081: panel.add(panel1);
082:
083: Panel panel2 = new Panel();
084: panel2.setTitle("Left Align Text");
085: panel2.setFrame(true);
086: panel2.setWidth(400);
087: panel2.setHeight(150);
088: panel2.setPaddings(20);
089:
090: final ProgressBar pbar2 = new ProgressBar();
091: pbar2.setCls("left-align");
092: pbar2.setWidth(300);
093: pbar2.setText("Ready");
094:
095: Button button2 = new Button("Start",
096: new ButtonListenerAdapter() {
097: public void onClick(final Button button,
098: EventObject e) {
099: button.disable();
100: pbar2.reset();
101: for (int i = 1; i < 12; i++) {
102: final int j = i;
103: Timer timer = new Timer() {
104: public void run() {
105: if (j > 11) {
106: pbar2.setText("Done.");
107: button.enable();
108: } else {
109: pbar2
110: .setText(Format
111: .format(
112: "Loading item {0} of 10...",
113: j
114: + ""));
115: pbar2.setValue(pbar2
116: .getValue() + 0.1f);
117: }
118: }
119: };
120: timer.schedule(i * 1000);
121: }
122:
123: }
124: });
125: panel2.add(new HTMLPanel(
126: "A ProgressBar with label left aligned via CSS.",
127: 0, 0, 0, 10));
128: panel2.add(pbar2);
129: panel2.addButton(button2);
130: panel.add(panel2);
131:
132: Panel panel3 = new Panel();
133: panel3.setTitle("Waiting Bar");
134: panel3.setFrame(true);
135: panel3.setWidth(400);
136: panel3.setHeight(150);
137: panel3.setPaddings(20);
138:
139: final ProgressBar pbar3 = new ProgressBar();
140: pbar3.setWidth(300);
141:
142: Button button3 = new Button("Start",
143: new ButtonListenerAdapter() {
144: public void onClick(final Button button,
145: EventObject e) {
146: button.disable();
147: pbar3.reset();
148:
149: pbar3.wait(new WaitConfig() {
150: {
151: setInterval(200);
152: setDuration(8000);
153: setIncrement(15);
154: setCallback(new Function() {
155: public void execute() {
156: button.enable();
157: }
158: });
159: }
160: });
161: }
162: });
163: panel3
164: .add(new HTMLPanel(
165: "Wait for a long operation to complete (example will stop after 8 secs) with progress update every 200ms and in increments of 15 segments.",
166: 0, 0, 0, 10));
167: panel3.add(pbar3);
168: panel3.addButton(button3);
169: panel.add(panel3);
170:
171: Panel panel4 = new Panel();
172: panel4.setTitle("Custom Styles");
173: panel4.setFrame(true);
174: panel4.setWidth(400);
175: panel4.setHeight(170);
176: panel4.setPaddings(20);
177:
178: final ProgressBar pbar4 = new ProgressBar();
179: pbar4.setText("Waiting on you...");
180: pbar4.setTextEl("p4text");
181: pbar4.setCls("custom");
182: pbar4.setWidth(300);
183:
184: Button button4 = new Button("Start",
185: new ButtonListenerAdapter() {
186: public void onClick(final Button button,
187: EventObject e) {
188: button.disable();
189: pbar4.reset();
190:
191: for (int i = 1; i < 12; i++) {
192: final int j = i;
193: Timer timer = new Timer() {
194: public void run() {
195: if (j == 11) {
196: pbar4.setText("All Done!");
197: button.enable();
198: } else {
199: float value = pbar4
200: .getValue() + 0.1f;
201: pbar4
202: .setText(Format
203: .format(
204: "{0}% completed... ",
205: (int) (value * 100)
206: + ""));
207: pbar4.setValue(value);
208: }
209: }
210: };
211: timer.schedule(i * 1000);
212: }
213: }
214: });
215: panel4
216: .add(new HTMLPanel(
217: "Rendered like Windows XP with custom progress text element.",
218: 0, 0, 0, 10));
219: panel4.add(pbar4);
220: HTMLPanel status = new HTMLPanel(
221: "<div class=\"status\"><b>Status:</b> <span id=\"p4text\"></span></div>",
222: 10, 0, 0, 0);
223: //the textEl must be already present in the DOM prior to ProgressBar creation
224: status.render(Ext.getBody().getDOM());
225: panel4.add(status);
226:
227: panel4.addButton(button4);
228: panel.add(panel4);
229: }
230: return panel;
231: }
232:
233: public String getIntro() {
234: return "This example demonstrates various ways a ProgressBar can be configured.";
235: }
236: }
|