зеркало из https://github.com/mozilla/smarthome.git
ImageItem and RawType added
Signed-off-by: Oliver Libutzki <o.libutzki@external.telekom.de>
This commit is contained in:
Родитель
d683b8b0d9
Коммит
af425a667c
|
@ -7,16 +7,17 @@
|
|||
*/
|
||||
package org.eclipse.smarthome.core.library;
|
||||
|
||||
import org.eclipse.smarthome.core.items.GenericItem;
|
||||
import org.eclipse.smarthome.core.items.ItemFactory;
|
||||
import org.eclipse.smarthome.core.library.items.ColorItem;
|
||||
import org.eclipse.smarthome.core.library.items.ContactItem;
|
||||
import org.eclipse.smarthome.core.library.items.DateTimeItem;
|
||||
import org.eclipse.smarthome.core.library.items.DimmerItem;
|
||||
import org.eclipse.smarthome.core.library.items.ImageItem;
|
||||
import org.eclipse.smarthome.core.library.items.NumberItem;
|
||||
import org.eclipse.smarthome.core.library.items.RollershutterItem;
|
||||
import org.eclipse.smarthome.core.library.items.StringItem;
|
||||
import org.eclipse.smarthome.core.library.items.SwitchItem;
|
||||
import org.eclipse.smarthome.core.items.GenericItem;
|
||||
import org.eclipse.smarthome.core.items.ItemFactory;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -26,7 +27,7 @@ import org.eclipse.smarthome.core.items.ItemFactory;
|
|||
*/
|
||||
public class CoreItemFactory implements ItemFactory {
|
||||
|
||||
private static String[] ITEM_TYPES = new String[] { "Switch", "Rollershutter", "Contact", "String", "Number", "Dimmer", "DateTime", "Color" };
|
||||
private static String[] ITEM_TYPES = new String[] { "Switch", "Rollershutter", "Contact", "String", "Number", "Dimmer", "DateTime", "Color", "Image" };
|
||||
|
||||
/**
|
||||
* @{inheritDoc}
|
||||
|
@ -40,6 +41,7 @@ public class CoreItemFactory implements ItemFactory {
|
|||
if (itemTypeName.equals(ITEM_TYPES[5])) return new DimmerItem(itemName);
|
||||
if (itemTypeName.equals(ITEM_TYPES[6])) return new DateTimeItem(itemName);
|
||||
if (itemTypeName.equals(ITEM_TYPES[7])) return new ColorItem(itemName);
|
||||
if (itemTypeName.equals(ITEM_TYPES[8])) return new ImageItem(itemName);
|
||||
else return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* Copyright (c) 2010-2013, openHAB.org and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.smarthome.core.library.items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.smarthome.core.items.GenericItem;
|
||||
import org.eclipse.smarthome.core.library.types.RawType;
|
||||
import org.eclipse.smarthome.core.types.Command;
|
||||
import org.eclipse.smarthome.core.types.State;
|
||||
import org.eclipse.smarthome.core.types.UnDefType;
|
||||
|
||||
/**
|
||||
* An ImageItem holds the binary image data as its status.
|
||||
*
|
||||
* @author Kai Kreuzer
|
||||
*
|
||||
*/
|
||||
public class ImageItem extends GenericItem {
|
||||
|
||||
private static List<Class<? extends State>> acceptedDataTypes = new ArrayList<Class<? extends State>>();
|
||||
private static List<Class<? extends Command>> acceptedCommandTypes = new ArrayList<Class<? extends Command>>();
|
||||
|
||||
static {
|
||||
acceptedDataTypes.add(RawType.class);
|
||||
acceptedDataTypes.add(UnDefType.class);
|
||||
}
|
||||
|
||||
public ImageItem(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public List<Class<? extends State>> getAcceptedDataTypes() {
|
||||
return acceptedDataTypes;
|
||||
}
|
||||
|
||||
public List<Class<? extends Command>> getAcceptedCommandTypes() {
|
||||
return acceptedCommandTypes;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
* Copyright (c) 2010-2013, openHAB.org and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.smarthome.core.library.types;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
import org.eclipse.smarthome.core.types.PrimitiveType;
|
||||
import org.eclipse.smarthome.core.types.State;
|
||||
|
||||
/**
|
||||
* This type can be used for all binary data such as images, documents, sounds etc.
|
||||
* Note that it is NOT adequate for any kind of streams, but only for fixed-size data.
|
||||
*
|
||||
* @author Kai Kreuzer
|
||||
*
|
||||
*/
|
||||
public class RawType implements PrimitiveType, State {
|
||||
|
||||
protected byte[] bytes;
|
||||
|
||||
|
||||
public RawType() {
|
||||
this(new byte[0]);
|
||||
}
|
||||
|
||||
public RawType(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static RawType valueOf(String value) {
|
||||
return new RawType(DatatypeConverter.parseBase64Binary(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return DatatypeConverter.printBase64Binary(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(String pattern) {
|
||||
return toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + Arrays.hashCode(bytes);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
RawType other = (RawType) obj;
|
||||
if (!Arrays.equals(bytes, other.bytes))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* Copyright (c) 2010-2013, openHAB.org and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.smarthome.core.library.types;
|
||||
|
||||
import org.eclipse.smarthome.core.types.Command;
|
||||
import org.eclipse.smarthome.core.types.PrimitiveType;
|
||||
|
||||
public enum RefreshType implements PrimitiveType, Command {
|
||||
|
||||
REFRESH;
|
||||
|
||||
public String format(String pattern) {
|
||||
return String.format(pattern, this.toString());
|
||||
}
|
||||
|
||||
}
|
Загрузка…
Ссылка в новой задаче