You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

enumerated-values.html 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  5. <title>Enumerated Data Values</title>
  6. <style type= "text/css" >
  7. body {
  8. font-family: Verdana, Helvetica, sans-serif;
  9. }
  10. .note { border: solid 1px #7099C5; background-color: #f0f0ff; }
  11. .note .label { background-color: #7099C5; color: #ffffff; }
  12. .content {
  13. padding: 5px 5px 5px 10px;
  14. font : Verdana, Helvetica, sans-serif; font-size : 90%;
  15. }
  16. </style>
  17. </head>
  18. <body marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" text="#000000" bgcolor="#FFFFFF">
  19. <div class="content">
  20. <h1>Enumerated Data Values</h1>
  21. <ul class="minitoc">
  22. <li>
  23. <a href="#N1000C">Enumerated Data Values</a>
  24. <ul class="minitoc">
  25. <li>
  26. <a href="#N10020">Array representation</a>
  27. </li>
  28. <li>
  29. <a href="#N1005C">HashMap representation</a>
  30. </li>
  31. <li>
  32. <a href="#N1009D">
  33. Factoring Out Common Enumeration Values
  34. </a>
  35. </li>
  36. <li>
  37. <a href="#N100DD">Mapped Numeric Values</a>
  38. </li>
  39. </ul>
  40. </li>
  41. </ul>
  42. <a name="N1000C"></a>
  43. <h3>Enumerated Data Values</h3>
  44. <p>
  45. Property classes which allow enumerated data types must encode
  46. integer constants representing the enumeration tokens, and
  47. must provide a way of translating between the tokens and the
  48. integers, and <em>vice versa</em>. Depending on the number of
  49. tokens in an enumeration set, the mapping from token to
  50. integer is maintained in an array or a <span
  51. class="codefrag">HashMap</span>. The switch-over point from
  52. array to <span class="codefrag">HashMap</span> was determined
  53. by some highly implementation-dependent testing to be in the
  54. region of four to five elements.
  55. </p>
  56. <p>
  57. Many properties share common sets of enumeration tokens,
  58. e.g. those which allow color values, and those applying to
  59. borders and padding. A special case of enumerated value is
  60. the mapped numeric enumeration, in which a token maps to a
  61. Numeric value. These situations are discussed below.
  62. </p>
  63. <a name="N10020"></a>
  64. <h4>Array representation</h4>
  65. <p>
  66. <a href= "javascript:parent.displayCode(
  67. 'Direction.html#DirectionClass' )" ><span
  68. class="codefrag">org.apache.fop.fo.properties.Direction</span></a>
  69. is an example of a class which supports an enumerated value
  70. with a small set of tokens. The <a href=
  71. "javascript:parent.displayCode( 'Direction.html#dataTypes' )"
  72. ><span class="codefrag">dataTypes</span></a> field contains
  73. the <a href= "javascript:parent.displayCode(
  74. 'Property.html#NOTYPE' )" ><span class="codefrag">ENUM</span>
  75. data type constant, defined in <span
  76. class="codefrag">Property</span></a>. The enumeration integer
  77. constants are defined as <span class="codefrag">public static
  78. final int</span> values, <a href=
  79. "javascript:parent.displayCode( 'Direction.html#LTR') "><span
  80. class="codefrag' )" >LTR</span> and <span
  81. class="codefrag">RTL</span></a>. Associating enumeration
  82. tokens with these integer constants occurs in the array <a
  83. href= "javascript:parent.displayCode( 'Direction.html#rwEnums'
  84. )" ><span class="codefrag">String[] rwEnums</span></a>, which
  85. is initialized with the token strings. By convention, zero is
  86. never used to represent a valid enumeration constant, anywhere
  87. in this code. It is, of course, critical that synchronization
  88. between <span class="codefrag">rwEnums</span> and the
  89. enumeration constants be maintained.
  90. </p>
  91. <p>
  92. The publicly accessible mapping from enumeration token to
  93. enumeration constant is achieved through the method <a href=
  94. "javascript:parent.displayCode( 'Direction.html#getEnumIndex'
  95. )" ><span class="codefrag">int
  96. getEnumIndex(String)</span></a>. The corresponding mapping
  97. from enumeration constant to enumeration token is achieved
  98. through the method <a href= "javascript:parent.displayCode(
  99. 'Direction.html#getEnumText' )" ><span class="codefrag">String
  100. getEnumText(int)</span></a>.
  101. </p>
  102. <a name="N1005C"></a>
  103. <h4>HashMap representation</h4>
  104. <p>
  105. <a href= "javascript:parent.displayCode(
  106. 'RenderingIntent.html#RenderingIntentClass' )" ><span
  107. class="codefrag"
  108. >org.apache.fop.fo.properties.RenderingIntent</span ></a> is
  109. an example of a class which supports an enumerated value with
  110. a larger set of tokens. The <a href=
  111. "javascript:parent.displayCode(
  112. 'RenderingIntent.html#dataTypes' )" ><span
  113. class="codefrag">dataTypes</span></a> field contains the <a
  114. href= "javascript:parent.displayCode( 'Property.html#NOTYPE'
  115. )" ><span class="codefrag">ENUM</span> data type constant,
  116. defined in <span class="codefrag">Property</span></a>.
  117. Enumeration integer constants are defined as <a href=
  118. "javascript:parent.displayCode(
  119. 'RenderingIntent.html#PERCEPTUAL' )" ><span
  120. class="codefrag">public static final int</span></a> values.
  121. Zero is never used to represent a valid enumeration constant.
  122. The enumeration tokens are stored in the array <a href=
  123. "javascript:parent.displayCode( 'RenderingIntent.html#rwEnums'
  124. )" ><span class="codefrag">String[] rwEnums</span></a>, which
  125. is initialized with the token strings. Association of
  126. enumeration tokens with the integer constants occurs in the
  127. <span class="codefrag">HashMap</span> <a href=
  128. "javascript:parent.displayCode(
  129. 'RenderingIntent.html#rwEnumHash"><span class="codefrag' )" >
  130. rwEnumHash</span></a>, which is initialized from the token
  131. array in a <span class="codefrag">static {}</span>
  132. initializer. It is, of course, critical that synchronization
  133. between <span class="codefrag">rwEnums</span> and the
  134. enumeration constants be maintained.
  135. </p>
  136. <p>
  137. The publicly accessible mapping from enumeration token to
  138. enumeration constant is achieved through the method <a href=
  139. "javascript:parent.displayCode(
  140. 'RenderingIntent.html#getEnumIndex' )" ><span
  141. class="codefrag">int getEnumIndex(String)</span></a>. The
  142. corresponding mapping from enumeration constant to enumeration
  143. token is achieved through the method <a href=
  144. "javascript:parent.displayCode(
  145. 'RenderingIntent.html#getEnumText' )" ><span
  146. class="codefrag">String getEnumText(int)</span></a>.
  147. </p>
  148. <a name="N1009D"></a>
  149. <h4 id="common-enum-values">
  150. Factoring Out Common Enumeration Values
  151. </h4>
  152. <p>
  153. When a number of properties support a common enumerated value,
  154. that value and its associated access methods may be factored
  155. out to a new class, which each of the properties then extends.
  156. An example of such a common super-class is <a href=
  157. "javascript:parent.displayCode(
  158. 'BorderCommonStyle.html#BorderCommonStyleClass' )" ><span
  159. class="codefrag">BorderCommonStyle</span></a>. Like a
  160. property with a normal HashMap representation of an enumerated
  161. value, BorderCommonStyle defines <a href=
  162. "javascript:parent.displayCode(
  163. 'BorderCommonStyle.html#HIDDEN' )" ><span
  164. class="codefrag">public static final int</span></a>
  165. enumeration integer constants. Similarly, the enumeration
  166. tokens are stored in the array <a href=
  167. "javascript:parent.displayCode(
  168. 'BorderCommonStyle.html#rwEnums' )" ><span
  169. class="codefrag">String[] rwEnums</span></a>, and the
  170. association of enumeration tokens with the integer constants
  171. occurs in the <span class="codefrag">HashMap</span> <a href=
  172. "javascript:parent.displayCode(
  173. 'BorderCommonStyle.html#rwEnumHash' )" ><span
  174. class="codefrag"> rwEnumHash</span></a>, initialized in a
  175. <span class="codefrag">static {}</span> initializer. The
  176. mapping methods <a href= "javascript:parent.displayCode(
  177. 'BorderCommonStyle.html#getEnumIndex' )" ><span
  178. class="codefrag">int getEnumIndex(String)</span></a> and <a
  179. href= "javascript:parent.displayCode(
  180. 'BorderCommonStyle.html#getEnumText' )" ><span
  181. class="codefrag">String getEnumText(int)</span></a> are also
  182. present.
  183. </p>
  184. <p>
  185. Notice, however, that the class has none of the static data
  186. constants described in the discussion of <a
  187. href="simple-properties.html">simple properties</a>. These
  188. values are defined in the individual sub-classes of this
  189. class, e.g. <a href= "javascript:parent.displayCode(
  190. 'BorderLeftStyle.html#BorderLeftStyleClass' )" ><span
  191. class="codefrag">BorderLeftStyle</span></a>. None of the
  192. above fields or methods occur, and <span
  193. class="codefrag">BorderLeftStyle</span> is left looking like
  194. an example of a simple property. The enumeration mapping
  195. methods are, however, available through the super-class <span
  196. class="codefrag">BorderCommonStyle</span>.
  197. </p>
  198. <a name="N100DD"></a>
  199. <h4>Mapped Numeric Values</h4>
  200. <p>
  201. In "normal" enumerated values, the token is, effectively,
  202. passed directly into the layout operation of the flow object
  203. to which the property is applied. Some enumerated values,
  204. however, generate a <span class="codefrag">Numeric</span>
  205. result. Their resolution involves mapping the token to the
  206. indicated <span class="codefrag">Numeric</span> value.
  207. </p>
  208. <p>
  209. An example is the <a href= "javascript:parent.displayCode(
  210. 'BorderCommonWidth.html#BorderCommonWidthClass' )" ><span
  211. class="codefrag">BorderCommonWidth</span></a> property. This,
  212. like the example of <a href="#common-enum-values"><span
  213. class="codefrag">BorderCommonStyle</span></a> above, also
  214. represents common enumerated values which have been factored
  215. out to form a super-class for particular properties. <span
  216. class="codefrag">BorderCommonWidth</span>, therefore, also
  217. defines <a href= "javascript:parent.displayCode(
  218. 'BorderCommonWidth.html#THIN' )" ><span
  219. class="codefrag">enumeration constant values</span></a> and an
  220. array of tokens. In this case, there is no <span
  221. class="codefrag">HashMap</span>, because of the limited number
  222. of tokens, but the mapping methods <a href=
  223. "javascript:parent.displayCode(
  224. 'BorderCommonWidth.html#getEnumIndex' )" ><span
  225. class="codefrag">int getEnumIndex(String)</span></a> and <a
  226. href= "javascript:parent.displayCode(
  227. 'BorderCommonWidth.html#getEnumText' )" ><span
  228. class="codefrag">String getEnumText(int)</span></a> are
  229. present.
  230. </p>
  231. <p>
  232. The added element in this property is the array <a href=
  233. "javascript:parent.displayCode(
  234. 'BorderCommonWidth.html#mappedPoints' )" ><span
  235. class="codefrag">double[] mappedPoints</span></a>. The
  236. entries in this array must by maintained in syncronization
  237. with the <a href= "javascript:parent.displayCode(
  238. 'BorderCommonWidth.html#rwEnums' )" ><span
  239. class="codefrag">String[] rwEnums</span></a> array of tokens
  240. and the set of <a href= "javascript:parent.displayCode(
  241. 'BorderCommonWidth.html#THIN' )" >enumeration constants</a>.
  242. The mapping from token to Numeric value is achieved by the <a
  243. href= "javascript:parent.displayCode(
  244. 'BorderCommonWidth.html#getMappedLength' )" ><span
  245. class="codefrag">Numeric getMappedLength(FONode, int,
  246. int)</span></a> method.
  247. </p>
  248. <p>
  249. <a href= "javascript:parent.displayCode(
  250. 'BorderLeftWidth.html#BorderLeftWidthClass' )" ><span
  251. class="codefrag">BorderLeftWidth</span></a> extends <a href=
  252. "javascript:parent.displayCode( 'BorderCommonWidth.html' )"
  253. ><span class="codefrag">BorderCommonWidth</span></a>. It
  254. includes the basic static data, like <a
  255. href="simple-properties.html">simple properties</a>, and, in
  256. this case, the <a href= "javascript:parent.displayCode(
  257. 'BorderLeftWidth.html#getInitialValue' )" ><span
  258. class="codefrag">PropertyValue getInitialValue(int)</span></a>
  259. method to derive the initial value.
  260. </p>
  261. <a name="N10139"></a>
  262. <h4>Deriving Mapped Numeric Values</h4>
  263. <p>
  264. As usual with property values, the usual method of deriving a
  265. mapped numeric value is by calling the <a href=
  266. "javascript:parent.displayCode(
  267. '../PropertyConsts.html#getMappedNumeric' )" ><span
  268. class="codefrag">Numeric getMappedNumeric(FONode, int,
  269. int)</span></a> method in <a href=
  270. "javascript:parent.displayCode(
  271. '../PropertyConsts.html#pconsts' )" ><span
  272. class="codefrag">pconsts</span></a>. All properties which
  273. support a mapped numeric value must have a <span
  274. class="codefrag">Numeric getMappedNumeric(FONode, int)</span>
  275. method, which will be called through its singleton instance,
  276. stored in the <a href= "javascript:parent.displayCode(
  277. 'PropertyConsts.html#properties' )" ><span class= "codefrag"
  278. >properties</span ></a> array, by the <span
  279. class="codefrag">PropertyConsts</span> method.
  280. </p>
  281. <p>
  282. <strong>Previous:</strong> <a href= "getInitialValue.html"
  283. >getInitialValue()</a>
  284. </p>
  285. <!--
  286. <p>
  287. <strong>Next:</strong> <a href= "getInitialValue.html"
  288. >getInitialValue()</a>
  289. </p>
  290. -->
  291. </div>
  292. <table summary="footer" cellspacing="0" cellpadding="0" width="100%" height="20" border="0">
  293. <tr>
  294. <td colspan="2" height="1" bgcolor="#4C6C8F"><img height="1"
  295. width="1" alt="" src="../../../skin/images/spacer.gif"><a
  296. href="../../../skin/images/label.gif"></a><a
  297. href="../../../skin/images/page.gif"></a><a
  298. href="../../../skin/images/chapter.gif"></a><a
  299. href="../../../skin/images/chapter_open.gif"></a><a
  300. href="../../../skin/images/current.gif"></a><a
  301. href="../../..//favicon.ico"></a></td>
  302. </tr>
  303. <tr>
  304. <td colspan="2" bgcolor="#CFDCED" class="copyright"
  305. align="center"><font size="2" face="Arial, Helvetica,
  306. Sans-Serif">Copyright &copy; 1999-2002&nbsp;The Apache
  307. Software Foundation. All rights reserved.<script
  308. type="text/javascript" language="JavaScript"><!--
  309. document.write(" - "+"Last Published: " +
  310. document.lastModified); // --></script></font></td>
  311. </tr>
  312. <tr>
  313. <td align="left" bgcolor="#CFDCED" class="logos"></td><td
  314. align="right" bgcolor="#CFDCED" class="logos"></td>
  315. </tr>
  316. </table>
  317. </body>
  318. </html>