View Javadoc
1   /*
2    * Copyright (c) 2002-2017 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package com.gargoylesoftware.htmlunit.html;
16  
17  import java.util.Map;
18  
19  import com.gargoylesoftware.htmlunit.SgmlPage;
20  
21  /**
22   * Wrapper for the HTML element "input" where type is "range".
23   *
24   * @author Ahmed Ashour
25   */
26  public class HtmlRangeInput extends HtmlInput {
27  
28      /**
29       * Creates an instance.
30       *
31       * @param qualifiedName the qualified name of the element type to instantiate
32       * @param page the page that contains this element
33       * @param attributes the initial attributes
34       */
35      HtmlRangeInput(final String qualifiedName, final SgmlPage page,
36              final Map<String, DomAttr> attributes) {
37          super(qualifiedName, page, attributes);
38          setValueAttribute("50");
39      }
40  
41      /**
42       * {@inheritDoc}
43       */
44      @Override
45      public void setValueAttribute(final String newValue) {
46          try {
47              final int value = Integer.parseInt(newValue);
48              if (value >= 0 && value <= 100) {
49                  super.setValueAttribute(newValue);
50              }
51          }
52          catch (final NumberFormatException e) {
53              // ignore
54          }
55      }
56  
57      /**
58       * {@inheritDoc}
59       */
60      @Override
61      protected boolean isRequiredSupported() {
62          return false;
63      }
64  }