]> git.basschouten.com Git - openhab-addons.git/blob
78e9ec08828ef7c1a825ed7b8417ea01c33cba2d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.nanoleaf.internal.layout.shape;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.nanoleaf.internal.layout.Point2D;
17 import org.openhab.binding.nanoleaf.internal.layout.ShapeType;
18 import org.openhab.binding.nanoleaf.internal.model.PositionDatum;
19
20 /**
21  * Create the correct chape for a given shape type.
22  *
23  * @author Jørgen Austvik - Initial contribution
24  */
25 @NonNullByDefault
26 public class ShapeFactory {
27
28     public static Shape CreateShape(ShapeType shapeType, PositionDatum positionDatum) {
29         Point2D pos = new Point2D(positionDatum.getPosX(), positionDatum.getPosY());
30         switch (shapeType.getDrawingAlgorithm()) {
31             case SQUARE:
32                 return new Square(shapeType, positionDatum.getPanelId(), pos, positionDatum.getOrientation());
33
34             case TRIANGLE:
35                 return new Triangle(shapeType, positionDatum.getPanelId(), pos, positionDatum.getOrientation());
36
37             case HEXAGON:
38                 return new Hexagon(shapeType, positionDatum.getPanelId(), pos, positionDatum.getOrientation());
39
40             default:
41                 return new Point(shapeType, positionDatum.getPanelId(), pos, positionDatum.getOrientation());
42         }
43     }
44 }