gwt.material.design.incubator.client.progress.ProgressLineBar Maven / Gradle / Ivy
/*
* #%L
* GwtMaterial
* %%
* Copyright (C) 2015 - 2017 GwtMaterialDesign
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package gwt.material.design.incubator.client.progress;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
import gwt.material.design.client.MaterialDesignBase;
import gwt.material.design.client.base.MaterialWidget;
import gwt.material.design.incubator.client.AddinsIncubator;
import gwt.material.design.incubator.client.base.IncubatorWidget;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Another progress bar that provides an individual blocks
* to produce a bar item to indicate how many percent the '
* current progress is.
*
*
* Note: This component is under the incubation process and subject to change.
*
*
* @author kevzlou7979
*/
public class ProgressLineBar extends MaterialWidget {
static {
IncubatorWidget.showWarning(ProgressLineBar.class);
if (AddinsIncubator.isDebug()) {
MaterialDesignBase.injectCss(ProgressLineBarDebugClientBundle.INSTANCE.progressLineBarDebugCss());
} else {
MaterialDesignBase.injectCss(ProgressLineBarClientBundle.INSTANCE.progressLineBarCss());
}
}
private Map options = new HashMap<>();
private List values;
public ProgressLineBar() {
super(Document.get().createDivElement(), "progress-line-bar");
}
@Override
protected void onLoad() {
super.onLoad();
double width = 100.00 / options.keySet().size();
for (T value : options.keySet()) {
ProgressLineBarItem item = options.get(value);
item.setWidth(width + "%");
}
if (values != null) {
for (T value : values) {
ProgressLineBarItem item = options.get(value);
item.setActive(true);
}
}
}
public void addOption(T option) {
ProgressLineBarItem item = new ProgressLineBarItem();
add(item);
options.put(option, item);
}
public List getValues() {
return values;
}
public void setValues(List values) {
this.values = values;
}
public void setActive(int index) {
if (index < 0) {
GWT.log("Index must be greater than 0", new IllegalStateException());
return;
}
if (options.size() <= 0) {
GWT.log("No values has been added to the options.", new IllegalStateException());
return;
}
options.get(index).setActive(true);
}
}