1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ide.eclipse.adt.internal.editors.resources.descriptors; 18 19 import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor; 20 import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; 21 import com.android.ide.eclipse.adt.internal.editors.descriptors.FlagAttributeDescriptor; 22 import com.android.ide.eclipse.adt.internal.editors.descriptors.IDescriptorProvider; 23 import com.android.ide.eclipse.adt.internal.editors.descriptors.ListAttributeDescriptor; 24 import com.android.ide.eclipse.adt.internal.editors.descriptors.TextAttributeDescriptor; 25 import com.android.ide.eclipse.adt.internal.editors.descriptors.TextValueDescriptor; 26 import com.android.ide.eclipse.adt.internal.resources.ResourceType; 27 28 29 /** 30 * Complete description of the structure for resources XML files (under res/values/) 31 */ 32 public class ResourcesDescriptors implements IDescriptorProvider { 33 34 // Public attributes names, attributes descriptors and elements descriptors 35 36 public static final String ROOT_ELEMENT = "resources"; //$NON-NLS-1$ 37 38 public static final String NAME_ATTR = "name"; //$NON-NLS-1$ 39 public static final String TYPE_ATTR = "type"; //$NON-NLS-1$ 40 41 private static final ResourcesDescriptors sThis = new ResourcesDescriptors(); 42 43 /** The {@link ElementDescriptor} for the root Resources element. */ 44 public final ElementDescriptor mResourcesElement; 45 getInstance()46 public static ResourcesDescriptors getInstance() { 47 return sThis; 48 } 49 50 /* 51 * @see com.android.ide.eclipse.editors.descriptors.IDescriptorProvider#getRootElementDescriptors() 52 */ getRootElementDescriptors()53 public ElementDescriptor[] getRootElementDescriptors() { 54 return new ElementDescriptor[] { mResourcesElement }; 55 } 56 getDescriptor()57 public ElementDescriptor getDescriptor() { 58 return mResourcesElement; 59 } 60 getElementDescriptor()61 public ElementDescriptor getElementDescriptor() { 62 return mResourcesElement; 63 } 64 ResourcesDescriptors()65 private ResourcesDescriptors() { 66 67 // Common attributes used in many placed 68 69 // Elements 70 71 ElementDescriptor color_element = new ElementDescriptor( 72 "color", //$NON-NLS-1$ 73 "Color", 74 "A @color@ value specifies an RGB value with an alpha channel, which can be used in various places such as specifying a solid color for a Drawable or the color to use for text. It always begins with a # character and then is followed by the alpha-red-green-blue information in one of the following formats: #RGB, #ARGB, #RRGGBB or #AARRGGBB.", 75 "http://code.google.com/android/reference/available-resources.html#colorvals", //$NON-NLS-1$ 76 new AttributeDescriptor[] { 77 new TextAttributeDescriptor(NAME_ATTR, 78 "Name*", 79 null /* nsUri */, 80 "The mandatory name used in referring to this color."), 81 new ColorValueDescriptor( 82 "Value*", 83 "A mandatory color value.") 84 }, 85 null, // no child nodes 86 false /* not mandatory */); 87 88 ElementDescriptor string_element = new ElementDescriptor( 89 "string", //$NON-NLS-1$ 90 "String", 91 "@Strings@, with optional simple formatting, can be stored and retrieved as resources. You can add formatting to your string by using three standard HTML tags: b, i, and u. If you use an apostrophe or a quote in your string, you must either escape it or enclose the whole string in the other kind of enclosing quotes.", 92 "http://code.google.com/android/reference/available-resources.html#stringresources", //$NON-NLS-1$ 93 new AttributeDescriptor[] { 94 new TextAttributeDescriptor(NAME_ATTR, 95 "Name*", 96 null /* nsUri */, 97 "The mandatory name used in referring to this string."), 98 new TextValueDescriptor( 99 "Value*", 100 "A mandatory string value.") 101 }, 102 null, // no child nodes 103 false /* not mandatory */); 104 105 ElementDescriptor item_element = new ItemElementDescriptor( 106 "item", //$NON-NLS-1$ 107 "Item", 108 null, // TODO find javadoc 109 null, // TODO find link to javadoc 110 new AttributeDescriptor[] { 111 new TextAttributeDescriptor(NAME_ATTR, 112 "Name*", 113 null /* nsUri */, 114 "The mandatory name used in referring to this resource."), 115 new ListAttributeDescriptor(TYPE_ATTR, 116 "Type*", 117 null /* nsUri */, 118 "The mandatory type of this resource.", 119 ResourceType.getNames() 120 ), 121 new FlagAttributeDescriptor("format", 122 "Format", 123 null /* nsUri */, 124 "The optional format of this resource.", 125 new String[] { 126 "boolean", //$NON-NLS-1$ 127 "color", //$NON-NLS-1$ 128 "dimension", //$NON-NLS-1$ 129 "float", //$NON-NLS-1$ 130 "fraction", //$NON-NLS-1$ 131 "integer", //$NON-NLS-1$ 132 "reference", //$NON-NLS-1$ 133 "string" //$NON-NLS-1$ 134 }), 135 new TextValueDescriptor( 136 "Value", 137 "A standard string, hex color value, or reference to any other resource type.") 138 }, 139 null, // no child nodes 140 false /* not mandatory */); 141 142 ElementDescriptor drawable_element = new ElementDescriptor( 143 "drawable", //$NON-NLS-1$ 144 "Drawable", 145 "A @drawable@ defines a rectangle of color. Android accepts color values written in various web-style formats -- a hexadecimal constant in any of the following forms: #RGB, #ARGB, #RRGGBB, #AARRGGBB. Zero in the alpha channel means transparent. The default value is opaque.", 146 "http://code.google.com/android/reference/available-resources.html#colordrawableresources", //$NON-NLS-1$ 147 new AttributeDescriptor[] { 148 new TextAttributeDescriptor(NAME_ATTR, 149 "Name*", 150 null /* nsUri */, 151 "The mandatory name used in referring to this drawable."), 152 new TextValueDescriptor( 153 "Value*", 154 "A mandatory color value in the form #RGB, #ARGB, #RRGGBB or #AARRGGBB.") 155 }, 156 null, // no child nodes 157 false /* not mandatory */); 158 159 ElementDescriptor dimen_element = new ElementDescriptor( 160 "dimen", //$NON-NLS-1$ 161 "Dimension", 162 "You can create common dimensions to use for various screen elements by defining @dimension@ values in XML. A dimension resource is a number followed by a unit of measurement. Supported units are px (pixels), in (inches), mm (millimeters), pt (points at 72 DPI), dp (density-independent pixels) and sp (scale-independent pixels)", 163 "http://code.google.com/android/reference/available-resources.html#dimension", //$NON-NLS-1$ 164 new AttributeDescriptor[] { 165 new TextAttributeDescriptor(NAME_ATTR, 166 "Name*", 167 null /* nsUri */, 168 "The mandatory name used in referring to this dimension."), 169 new TextValueDescriptor( 170 "Value*", 171 "A mandatory dimension value is a number followed by a unit of measurement. For example: 10px, 2in, 5sp.") 172 }, 173 null, // no child nodes 174 false /* not mandatory */); 175 176 ElementDescriptor style_element = new ElementDescriptor( 177 "style", //$NON-NLS-1$ 178 "Style/Theme", 179 "Both @styles and themes@ are defined in a style block containing one or more string or numerical values (typically color values), or references to other resources (drawables and so on).", 180 "http://code.google.com/android/reference/available-resources.html#stylesandthemes", //$NON-NLS-1$ 181 new AttributeDescriptor[] { 182 new TextAttributeDescriptor(NAME_ATTR, 183 "Name*", 184 null /* nsUri */, 185 "The mandatory name used in referring to this theme."), 186 new TextAttributeDescriptor("parent", // $NON-NLS-1$ 187 "Parent", 188 null /* nsUri */, 189 "An optional parent theme. All values from the specified theme will be inherited into this theme. Any values with identical names that you specify will override inherited values."), 190 }, 191 new ElementDescriptor[] { 192 new ElementDescriptor( 193 "item", //$NON-NLS-1$ 194 "Item", 195 "A value to use in this @theme@. It can be a standard string, a hex color value, or a reference to any other resource type.", 196 "http://code.google.com/android/reference/available-resources.html#stylesandthemes", //$NON-NLS-1$ 197 new AttributeDescriptor[] { 198 new TextAttributeDescriptor(NAME_ATTR, 199 "Name*", 200 null /* nsUri */, 201 "The mandatory name used in referring to this item."), 202 new TextValueDescriptor( 203 "Value*", 204 "A mandatory standard string, hex color value, or reference to any other resource type.") 205 }, 206 null, // no child nodes 207 false /* not mandatory */) 208 }, 209 false /* not mandatory */); 210 211 ElementDescriptor string_array_element = new ElementDescriptor( 212 "string-array", //$NON-NLS-1$ 213 "String Array", 214 "An array of strings. Strings are added as underlying item elements to the array.", 215 null, // tooltips 216 new AttributeDescriptor[] { 217 new TextAttributeDescriptor(NAME_ATTR, 218 "Name*", 219 null /* nsUri */, 220 "The mandatory name used in referring to this string array."), 221 }, 222 new ElementDescriptor[] { 223 new ElementDescriptor( 224 "item", //$NON-NLS-1$ 225 "Item", 226 "A string value to use in this string array.", 227 null, // tooltip 228 new AttributeDescriptor[] { 229 new TextValueDescriptor( 230 "Value*", 231 "A mandatory string.") 232 }, 233 null, // no child nodes 234 false /* not mandatory */) 235 }, 236 false /* not mandatory */); 237 238 ElementDescriptor integer_array_element = new ElementDescriptor( 239 "integer-array", //$NON-NLS-1$ 240 "Integer Array", 241 "An array of integers. Integers are added as underlying item elements to the array.", 242 null, // tooltips 243 new AttributeDescriptor[] { 244 new TextAttributeDescriptor(NAME_ATTR, 245 "Name*", 246 null /* nsUri */, 247 "The mandatory name used in referring to this integer array."), 248 }, 249 new ElementDescriptor[] { 250 new ElementDescriptor( 251 "item", //$NON-NLS-1$ 252 "Item", 253 "An integer value to use in this integer array.", 254 null, // tooltip 255 new AttributeDescriptor[] { 256 new TextValueDescriptor( 257 "Value*", 258 "A mandatory integer.") 259 }, 260 null, // no child nodes 261 false /* not mandatory */) 262 }, 263 false /* not mandatory */); 264 265 mResourcesElement = new ElementDescriptor( 266 ROOT_ELEMENT, 267 "Resources", 268 null, 269 "http://code.google.com/android/reference/available-resources.html", //$NON-NLS-1$ 270 null, // no attributes 271 new ElementDescriptor[] { 272 string_element, 273 color_element, 274 dimen_element, 275 drawable_element, 276 style_element, 277 item_element, 278 string_array_element, 279 integer_array_element, 280 }, 281 true /* mandatory */); 282 } 283 } 284