View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.layout;
21  
22  
23  public class PixelLayoutToken extends LayoutToken {
24  
25    static final String SUFFIX = "px";
26  
27    private final PixelMeasure pixel;
28  
29    public PixelLayoutToken(final int pixel) {
30      // here we cannot use this(PixelMeasure.pixelValueOf(pixel)), because of class initialization problems
31      this((PixelMeasure) Measure.valueOf(pixel));
32    }
33  
34    public PixelLayoutToken(final PixelMeasure pixel) {
35      this.pixel = pixel;
36    }
37  
38    public int getPixel() {
39      return pixel.getPixel();
40    }
41  
42    public PixelMeasure getMeasure() {
43      return pixel;
44    }
45  
46    public String toString() {
47      return pixel.toString();
48    }
49  
50    public boolean equals(final Object o) {
51      if (this == o) {
52        return true;
53      }
54      if (o == null || getClass() != o.getClass()) {
55        return false;
56      }
57  
58      final PixelLayoutToken that = (PixelLayoutToken) o;
59  
60      if (pixel != that.pixel) {
61        return false;
62      }
63  
64      return true;
65    }
66  
67    public int hashCode() {
68      return pixel.hashCode();
69    }
70  }