1 /* 2 Copyright 2007-2014 Fraunhofer IGD, http://www.igd.fraunhofer.de 3 Fraunhofer-Gesellschaft - Institute for Computer Graphics Research 4 5 See the NOTICE file distributed with this work for additional 6 information regarding copyright ownership 7 8 Licensed under the Apache License, Version 2.0 (the "License"); 9 you may not use this file except in compliance with the License. 10 You may obtain a copy of the License at 11 12 http://www.apache.org/licenses/LICENSE-2.0 13 14 Unless required by applicable law or agreed to in writing, software 15 distributed under the License is distributed on an "AS IS" BASIS, 16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 See the License for the specific language governing permissions and 18 limitations under the License. 19 */ 20 package org.universAAL.middleware.ui.rdf; 21 22 import org.universAAL.middleware.container.utils.StringUtils; 23 24 /** 25 * The type of possible values for {@link FormControl#PROP_CONTROL_LABEL}. A 26 * label reveals the intent of the corresponding form control for human users 27 * primarily as a string. This string is stored using the standard property 28 * rdfs:label (see 29 * {@link org.universAAL.middleware.rdf.Resource#getResourceLabel()} and 30 * {@link org.universAAL.middleware.rdf.Resource#setResourceLabel(String)}). 31 * 32 * @see <a href="http://www.w3.org/TR/rdf-schema/#ch_label">RDFS 33 * specification</a> 34 * 35 * @author mtazari 36 * @author Carsten Stockloew 37 */ 38 public class Label extends FormElement { 39 public static final String MY_URI = Form.uAAL_DIALOG_NAMESPACE + "Label"; 40 41 /** 42 * The URL of media objects that can be used as an audio / visual icon 43 * equivalent to the meaning borne by the text label. 44 */ 45 public static final String PROP_ICON_URL = Form.uAAL_DIALOG_NAMESPACE 46 + "iconURL"; 47 48 /** 49 * For use by de-serializers only. 50 */ 51 public Label() { 52 super(); 53 } 54 55 /** 56 * Constructs a new label. 57 * 58 * @param labelText 59 * Mandatory string bearing the intent of the corresponding form 60 * control for human users and stored using the standard property 61 * rdfs:label. 62 * @param iconURL 63 * See {@link #PROP_ICON_URL}; optional. 64 * 65 * @see <a href="http://www.w3.org/TR/rdf-schema/#ch_label">RDFS 66 * specification</a> 67 */ 68 public Label(String labelText, String iconURL) { 69 super(); 70 addType(getStaticFieldValue("MY_URI", MY_URI).toString(), true); 71 setResourceLabel(labelText); 72 if (iconURL != null) 73 props.put(PROP_ICON_URL, iconURL); 74 } 75 76 /** 77 * @see #PROP_ICON_URL 78 */ 79 public String getIconURL() { 80 return (String) props.get(PROP_ICON_URL); 81 } 82 83 int getMaxLength() { 84 String l = getText(); 85 return (l == null) ? -1 : l.length(); 86 } 87 88 /** 89 * Returns the label string. 90 * 91 * @see org.universAAL.middleware.rdf.Resource#getResourceLabel() 92 */ 93 public String getText() { 94 return getResourceLabel(); 95 } 96 97 /** 98 * @see org.universAAL.middleware.rdf.Resource#setProperty(String, Object) 99 */ 100 public boolean setProperty(String propURI, Object value) { 101 if (PROP_ICON_URL.equals(propURI)) { 102 if (!props.containsKey(propURI) && value instanceof String) { 103 props.put(propURI, value); 104 return true; 105 } 106 } else 107 return super.setProperty(propURI, value); 108 return false; 109 } 110 111 /** 112 * Overrides {@link org.universAAL.middleware.rdf.Resource#toString()} in 113 * order to return the label string; only if this is an empty string, the 114 * default implementation is used. 115 */ 116 public String toString() { 117 String txt = getText(); 118 return StringUtils.isNullOrEmpty(txt) ? super.toString() : txt; 119 } 120 }