You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VProgressBar.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.v7.client.ui;
  17. import com.google.gwt.dom.client.Element;
  18. import com.google.gwt.dom.client.Style.Unit;
  19. import com.google.gwt.user.client.DOM;
  20. import com.google.gwt.user.client.ui.HasEnabled;
  21. import com.google.gwt.user.client.ui.Widget;
  22. import com.vaadin.client.StyleConstants;
  23. /**
  24. * Widget for showing the current progress of a long running task.
  25. * <p>
  26. * The default mode is to show the current progress internally represented by a
  27. * floating point value between 0 and 1 (inclusive). The progress bar can also
  28. * be in an indeterminate mode showing an animation indicating that the task is
  29. * running but without providing any information about the current progress.
  30. *
  31. * @since 7.1
  32. * @author Vaadin Ltd
  33. */
  34. public class VProgressBar extends Widget implements HasEnabled {
  35. public static final String PRIMARY_STYLE_NAME = "v-progressbar";
  36. Element wrapper = DOM.createDiv();
  37. Element indicator = DOM.createDiv();
  38. private boolean indeterminate = false;
  39. private float state = 0.0f;
  40. private boolean enabled;
  41. public VProgressBar() {
  42. setElement(DOM.createDiv());
  43. getElement().appendChild(wrapper);
  44. wrapper.appendChild(indicator);
  45. setStylePrimaryName(PRIMARY_STYLE_NAME);
  46. }
  47. /*
  48. * (non-Javadoc)
  49. *
  50. * @see
  51. * com.google.gwt.user.client.ui.UIObject#setStylePrimaryName(java.lang.
  52. * String)
  53. */
  54. @Override
  55. public void setStylePrimaryName(String style) {
  56. super.setStylePrimaryName(style);
  57. indicator.setClassName(getStylePrimaryName() + "-indicator");
  58. wrapper.setClassName(getStylePrimaryName() + "-wrapper");
  59. }
  60. public void setIndeterminate(boolean indeterminate) {
  61. this.indeterminate = indeterminate;
  62. setStyleName(getStylePrimaryName() + "-indeterminate", indeterminate);
  63. }
  64. public void setState(float state) {
  65. final int size = Math.round(100 * state);
  66. indicator.getStyle().setWidth(size, Unit.PCT);
  67. }
  68. public boolean isIndeterminate() {
  69. return indeterminate;
  70. }
  71. public float getState() {
  72. return state;
  73. }
  74. @Override
  75. public boolean isEnabled() {
  76. return enabled;
  77. }
  78. @Override
  79. public void setEnabled(boolean enabled) {
  80. if (this.enabled != enabled) {
  81. this.enabled = enabled;
  82. setStyleName(StyleConstants.DISABLED, !enabled);
  83. }
  84. }
  85. }