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 /** The layout of a rectangular shape on a rectangular canvas. */
28 public final class Layout {
29 private final Dimension dim;
30 private final Offset offset;
31
32 /**
33 * Create a new layout.
34 *
35 * @param dim
36 * the dimension of the shape
37 * @param offset
38 * the offset between the top left corner of the shape and the top left corner of the canvas
39 */
40 public Layout(Dimension dim, Offset offset) {
41 this.dim = dim;
42 this.offset = offset;
43 }
44
45 /** Return the dimension of the shape. */
46 public Dimension getDimension() {
47 return dim;
48 }
49
50 /** Return the offset between the shape's and canvas' origin. */
51 public Offset getOffset() {
52 return offset;
53 }
54
55 @Override
56 public boolean equals(Object that) {
57 return (this == that) || (that instanceof Layout && eqFields((Layout) that));
58 }
59
60 private boolean eqFields(Layout that) {
61 return eq(dim, that.dim) && eq(offset, that.offset);
62 }
63
64 @Override
65 public int hashCode() {
66 return hash(dim, offset);
67 }
68 }