hi Konstantin,
thanks again for help and information,
here is what I've done using your post:
Iv'e written java implementation of ajax progress bar by bramus:
http://www.bram.us/projects/js_bramus/j ... arhandler/which can be used via D&D in Desinger or in handcoded code and also used as decorator for span elements on web page,
using your information I've modified constructors and factory methods in progress bar class:
- Code: Select all
public ProgressBar() {
this(ProgressBar.options.copy());
}
ProgressBar(ProgressBarOptions options) {
setElement(DOM.createSpan());
setStyleName("bramus-JSProgressBar");
impl = new ProgressBarImpl(getElement(), options);
}
public one is used by Designer via D&D with all default options, second one (default scoped) is used by factory method:
- Code: Select all
public static ProgressBar createProgressBar(ProgressBarOptions options) {}
I've also written factory data class that way using your template:
- Code: Select all
package us.bram.jsprogressbar.example.client;
import us.bram.jsprogressbar.ProgressBarOptions;
import us.bram.jsprogressbar.ProgressBar;
/**
* @wbp.factory
*/
public class ProgressBarFactory {
/**
* static initializer to set default options (here we just reset defaults to
* configuration)
*/
static {
ProgressBarFactory.setDefaultOptions();
}
/**
* @return instance of {@link ProgressBar} with OSX Aqua like progress bar
*/
public static ProgressBar createAquaProgressBar() {
ProgressBarOptions options = getAquaBarOptions();
return ProgressBar.createProgressBar(options);
}
/**
* @return instance of {@link ProgressBar} with 4 color based progress bar
*/
public static ProgressBar createColoredProgressBar() {
ProgressBarOptions options = getColoredBarOptions();
return ProgressBar.createProgressBar(options);
}
/**
* @return instance of {@link ProgressBar} using default configuration
*/
public static ProgressBar createDefaultProgressBar() {
ProgressBar pb = new ProgressBar();
pb.setProgress(70);
return pb;
}
/**
* @return instance of {@link ProgressBar} with red progress bar
*/
public static ProgressBar createRedProgressBar() {
ProgressBarOptions options = getRedBarOptions();
return ProgressBar.createProgressBar(options);
}
/**
* @return options for custom OSX Aqua like progress bar
*/
public static ProgressBarOptions getAquaBarOptions() {
ProgressBarOptions options = ProgressBar.getDefaultOptions();
options.width = 154;
options.height = 11;
options.boxImage = "images/bramus/example/custom1_box.gif";
options.barImages = new String[] {"images/bramus/example/custom1_bar.gif"};
return options;
}
public static ProgressBarOptions getColoredBarOptions() {
ProgressBarOptions options = ProgressBar.getDefaultOptions();
options.animate = false;
options.percentage = 70;
options.barImages = new String[] {
"images/bramus/example/percentImage_back4.png",
"images/bramus/example/percentImage_back2.png",
"images/bramus/example/percentImage_back1.png",
"images/bramus/example/percentImage_back3.png"};
return options;
}
/**
*
* @return options for red colored bar
*/
public static ProgressBarOptions getRedBarOptions() {
ProgressBarOptions options = ProgressBar.getDefaultOptions();
options.barImages = new String[] {"images/bramus/example/percentImage_back3.png"};
return options;
}
/**
* static factory method to reset default configuration option for
* {@link ProgressBar}
*/
public static void setDefaultOptions() {
ProgressBarOptions options = ProgressBar.getDefaultOptions();
options.animate = true;
options.barImages = new String[] {"images/bramus/percentImage_back.png"};
options.boxImage = "images/bramus/percentImage.png";
options.height = 12;
options.showText = true;
options.width = 120;
options.percentage = 0;
ProgressBar.setDefaultOptions(options);
}
}
generated (in Design view) and handcoded code looks like:
- Code: Select all
/**
*
*/
public void onModuleLoad() {
// widgets attached via D&D in Design view
RootPanel rootPanel = RootPanel.get("container");
panel = new VerticalPanel();
rootPanel.add(panel);
panel.setSpacing(10);
final Label label = new Label("Progress bars created in Design view");
panel.add(label);
defaultWidget = new ProgressBar();
panel.add(defaultWidget);
defaultWidget.setAnimated(true);
defaultWidget.setProgress(60);
defaultFromFactory = ProgressBarFactory.createDefaultProgressBar();
panel.add(defaultFromFactory);
defaultFromFactory.setProgress(100);
auqaFromFactory = ProgressBarFactory.createAquaProgressBar();
panel.add(auqaFromFactory);
auqaFromFactory.setProgress(33);
coloredFromFactory = ProgressBarFactory.createColoredProgressBar();
panel.add(coloredFromFactory);
coloredFromFactory.setAnimated(true);
redFromFactory = ProgressBarFactory.createRedProgressBar();
panel.add(redFromFactory);
redFromFactory.setProgress(10);
//
// progress bars attached to existing span elements manually
//
// default widget
ProgressBar.fromElement($("progress1")).setProgress(60);
// default widget from options
ProgressBar.fromElement($("progress2"), ProgressBar.getDefaultOptions()).setProgress(
100);
// aqua OSX like style configuration
ProgressBar.fromElement($("progress3"),
ProgressBarFactory.getAquaBarOptions()).setProgress(33);
// colored progress bar
ProgressBar.fromElement($("progress4"),
ProgressBarFactory.getColoredBarOptions());
// red colored progress bar
ProgressBar.fromElement($("progress5"),
ProgressBarFactory.getRedBarOptions()).setProgress(10);
}
private static Element $(String id) {
return DOM.getElementById(id);
}
and here are screenshots:
- Design view in IDE
- designView.jpg (69.59 KiB) Viewed 2123 times
- hosted mode view
- hostedModeView.jpg (42.79 KiB) Viewed 2123 times
I hope you'll find it usefull with your futher work you've mentioned,
as you could see I had implementation design issue with public parametrized constructor, It does not work in Design view, so it should be defaulted and instead accessed via static factories,
If we could have public parametrized constructor with non-statically created params that would be nice, but I guess most people could live without that for now
regards,
Peter