]> git.basschouten.com Git - openhab-addons.git/blob
7804b6e9a1c9aafb971f08ecfe78a69efc5d5206
[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.heos.internal.resources;
14
15 import java.beans.PropertyChangeListener;
16 import java.beans.PropertyChangeSupport;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * The {@Link HeosStringPropertyChangeListener} provides the possibility
24  * to add a listener to a String and get informed about the new value.
25  *
26  * @author Johannes Einig - Initial contribution
27  */
28 @NonNullByDefault
29 public class HeosStringPropertyChangeListener {
30     private final Logger logger = LoggerFactory.getLogger(HeosStringPropertyChangeListener.class);
31
32     private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
33
34     public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener) {
35         pcs.addPropertyChangeListener(propertyChangeListener);
36     }
37
38     public void removePropertyChangeListener(PropertyChangeListener listener) {
39         pcs.removePropertyChangeListener(listener);
40     }
41
42     public void setValue(String newValue) {
43         logger.debug("Firing property change: {} {}", newValue, Thread.currentThread());
44         pcs.firePropertyChange("value", null, newValue);
45     }
46 }