2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.nanoleaf.internal.model;
15 import java.util.List;
17 import java.util.TreeMap;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
23 * Represents layout of the light panels
25 * @author Martin Raepple - Initial contribution
30 private int numPanels;
31 private int sideLength;
33 private @Nullable List<PositionDatum> positionData = null;
35 public int getNumPanels() {
39 public void setNumPanels(int numPanels) {
40 this.numPanels = numPanels;
43 public int getSideLength() {
47 public void setSideLength(int sideLength) {
48 this.sideLength = sideLength;
51 public @Nullable List<PositionDatum> getPositionData() {
55 public void setPositionData(List<PositionDatum> positionData) {
56 this.positionData = positionData;
60 * Returns an text representation for a canvas layout.
62 * Note only canvas supported currently due to its easy geometry
64 * @return a String containing the layout
66 public String getLayoutView() {
67 if (positionData != null) {
70 int minx = Integer.MAX_VALUE;
71 int maxx = Integer.MIN_VALUE;
72 int miny = Integer.MAX_VALUE;
73 int maxy = Integer.MIN_VALUE;
75 final int noofDefinedPanels = positionData.size();
76 for (int index = 0; index < noofDefinedPanels; index++) {
77 if (positionData != null) {
79 PositionDatum panel = positionData.get(index);
82 if (panel.getPosX() < minx) {
83 minx = panel.getPosX();
85 if (panel.getPosX() > maxx) {
86 maxx = panel.getPosX();
88 if (panel.getPosY() < miny) {
89 miny = panel.getPosY();
91 if (panel.getPosY() > maxy) {
92 maxy = panel.getPosY();
98 int shiftWidth = getSideLength() / 2;
101 Map<Integer, PositionDatum> map;
103 while (lineY >= miny) {
104 map = new TreeMap<>();
105 for (int index = 0; index < noofDefinedPanels; index++) {
107 if (positionData != null) {
109 PositionDatum panel = positionData.get(index);
111 if (panel != null && panel.getPosY() == lineY)
112 map.put(panel.getPosX(), panel);
116 for (int x = minx; x <= maxx; x += shiftWidth) {
117 if (map.containsKey(x)) {
119 PositionDatum panel = map.get(x);
120 view += String.format("%5s ", panel.getPanelId());