]> git.basschouten.com Git - openhab-addons.git/blob
295dc9f5185943ff27c5a3221b4f07d8e11e1c36
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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 java.awt.Color;
16 import java.awt.Graphics2D;
17 import java.util.Arrays;
18 import java.util.List;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.nanoleaf.internal.layout.DrawingSettings;
22 import org.openhab.binding.nanoleaf.internal.layout.ImagePoint2D;
23 import org.openhab.binding.nanoleaf.internal.layout.PanelState;
24 import org.openhab.binding.nanoleaf.internal.layout.Point2D;
25 import org.openhab.binding.nanoleaf.internal.layout.ShapeType;
26 import org.openhab.core.library.types.HSBType;
27 import org.openhab.core.util.ColorUtil;
28
29 /**
30  * A shape without any area.
31  *
32  * @author Jørgen Austvik - Initial contribution
33  */
34 @NonNullByDefault
35 public class Point extends Panel {
36
37     private static final int POINT_DIAMETER = 4;
38
39     private final Point2D position;
40     private final int panelId;
41
42     public Point(ShapeType shapeType, int panelId, Point2D position) {
43         super(shapeType);
44         this.position = position;
45         this.panelId = panelId;
46     }
47
48     @Override
49     public List<Point2D> generateOutline() {
50         return Arrays.asList(position);
51     }
52
53     @Override
54     public void draw(Graphics2D graphics, DrawingSettings settings, PanelState state) {
55         ImagePoint2D pos = settings.generateImagePoint(position);
56
57         if (settings.shouldFillWithColor()) {
58             HSBType color = state.getHSBForPanel(panelId);
59             graphics.setColor(new Color(ColorUtil.hsbTosRgb(color)));
60             graphics.fillOval(pos.getX(), pos.getY(), POINT_DIAMETER, POINT_DIAMETER);
61         }
62
63         if (settings.shouldDrawOutline()) {
64             graphics.setColor(settings.getOutlineColor());
65             graphics.drawOval(pos.getX(), pos.getY(), POINT_DIAMETER, POINT_DIAMETER);
66         }
67
68         if (settings.shouldDrawLabels()) {
69             graphics.setColor(settings.getLabelColor());
70             graphics.drawString(Integer.toString(panelId), pos.getX(), pos.getY());
71         }
72     }
73 }