View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  
22  package org.opencastproject.composer.layout;
23  
24  import static org.opencastproject.util.EqualsUtil.eq;
25  import static org.opencastproject.util.EqualsUtil.hash;
26  
27  import org.opencastproject.util.RequireUtil;
28  
29  /**
30   * This layout specification describes how to position a shape and how much of the underlying width of the canvas it
31   * shall cover.
32   */
33  public final class HorizontalCoverageLayoutSpec {
34    private final AnchorOffset anchorOffset;
35    private final double horizontalCoverage;
36  
37    /**
38     * Create a new specification.
39     *
40     * @param anchorOffset
41     *          The distance of the anchor points of canvas and shape. The canvas is the "reference", the shape the
42     *          "referring" part of the distance object.
43     * @param horizontalCoverage
44     *          0 <= horizontalCoverage <= 1. How much space of the canvas should be covered.
45     */
46    public HorizontalCoverageLayoutSpec(AnchorOffset anchorOffset, double horizontalCoverage) {
47      this.anchorOffset = anchorOffset;
48      this.horizontalCoverage = RequireUtil.between(horizontalCoverage, 0.0, 1.0);
49    }
50  
51    /** Get the distance between the anchor points of canvas and shape. */
52    public AnchorOffset getAnchorOffset() {
53      return anchorOffset;
54    }
55  
56    /** Get the horizontal coverage. */
57    public double getHorizontalCoverage() {
58      return horizontalCoverage;
59    }
60  
61    @Override
62    public boolean equals(Object that) {
63      return (this == that)
64              || (that instanceof HorizontalCoverageLayoutSpec && eqFields((HorizontalCoverageLayoutSpec) that));
65    }
66  
67    private boolean eqFields(HorizontalCoverageLayoutSpec that) {
68      return eq(anchorOffset, that.anchorOffset) && horizontalCoverage == that.horizontalCoverage;
69    }
70  
71    @Override
72    public int hashCode() {
73      return hash(anchorOffset, horizontalCoverage);
74    }
75  }