textfield.adoc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. = textfield
  2. :author:
  3. :revnumber:
  4. :revdate: 2016/03/17 20:48
  5. :relfileprefix: ../../../
  6. :imagesdir: ../../..
  7. ifdef::env-github,env-browser[:outfilesuffix: .adoc]
  8. == TextField Class
  9. Textfields are single line text input fields, that provide the following functionality:
  10. * Caret & Text Range
  11. * Mouse select
  12. * Keyboard nav using:
  13. ** arrows (nav by letter)
  14. ** SHIFT+arrows (text range by latter)
  15. ** CTRL+arrows (nav by word)
  16. ** SHIFT+CTRL+arrows (text range by word)
  17. ** etc.
  18. * Cut & Paste
  19. [NOTE]
  20. ====
  21. This control is still a work in progress and will be updated as either time permits or issues arise. There is a known issue with the Cut & Paste function as of right now and it has been disabled.
  22. ====
  23. TextFields provide the standard 3 constructors as shown in the <<jme3/contributions/tonegodgui/quickstart#,Quick Start Guide>>.
  24. *Constructor 1:*
  25. [source,java]
  26. ----
  27. /** Parameters:
  28. * Screen screen,
  29. * String UID,
  30. * Vector2f position
  31. */
  32. TextField text = new TextField(screen, “text”, new Vector2f(15, 15));
  33. ----
  34. *Constructor 2:*
  35. [source,java]
  36. ----
  37. /** Additional Parameter:
  38. * Vector2f dimensions */
  39. TextField text = new TextField(screen, “text”, new Vector2f(15, 15),
  40. new Vector2f(150, 25)
  41. );
  42. ----
  43. *Constructor 3:*
  44. [source,java]
  45. ----
  46. /** Additional Parameters:
  47. * Vector4f resizeBorders,
  48. * String defaultImg
  49. */
  50. TextField text = new TextField(screen, “text”, new Vector2f(15, 15), new Vector2f(150, 25),
  51. new Vector4f(3,3,3,3),
  52. “tonegod/gui/style/def/TextField/text_field_x.png”
  53. );
  54. ----
  55. === Validations & Rules
  56. TextFields can be set to a specific Type using:
  57. [source,java]
  58. ----
  59. text.setType(TextField.Type type);
  60. ----
  61. [cols="2", options="header"]
  62. |===
  63. a| Rule
  64. a| Description
  65. a| Type.DEFAULT
  66. a| Accept all characters
  67. a| Type.ALPHA
  68. a| Accept only lower case, uppercase alpha character + spacebar
  69. a| Type.ALPHA_NOSPACE
  70. a| Accept only lower case, uppercase alpha character - no spacebar
  71. a| Type.NUMERIC
  72. a| Accept only numeric values + decimal
  73. a| Type.ALPHANUMERIC
  74. a| Apply both ALPHA and NUMERIC rules
  75. a| Type.ALPHANUMERIC_NOSPACE
  76. a| Apply both ALPHA_NOSPACE and NUMERIC rules
  77. a| Type.EXCLUDE_SPECIAL
  78. a| Exclude all spacial characters
  79. a| Type.EXCLUDE_CUSTOM
  80. a| Exclude all user defined character (see below)
  81. a| Type.INCLUDE_CUSTOM
  82. a| Accept only user defined characters (see below)
  83. |===
  84. To define a custom validation for Type.EXCLUDE_CUSTOM or Type.INCLUDE_CUSTOM, use the following method:
  85. [source,java]
  86. ----
  87. text.setCustomValidation("Character List to include/exclude");
  88. ----
  89. You can also limit the number of characters the TextField will accept using:
  90. [source,java]
  91. ----
  92. text.setMaxLimit(int maxLimit);
  93. ----
  94. You can force upper and lower case by using:
  95. [source,java]
  96. ----
  97. text.setForceUpperCase(boolean forceUpperCase);
  98. text.setForceLowerCase(boolean forceLowerCase);
  99. ----
  100. === Methods specific to the TextField class:
  101. [source,java]
  102. ----
  103. // Get the TextField text
  104. text.getText();
  105. // Set the TextField text !IMPORTANT! setTextFieldText is now @Deprecated, use the following instead:
  106. text.setText(String s);
  107. // Retrieve numeric values (all numeric parsers throw NumberFormatException
  108. text.parseInt();
  109. text.parseFloat();
  110. text.parseShort();
  111. text.parseDouble();
  112. text.parseLong();
  113. ----
  114. === Hooks:
  115. [source,java]
  116. ----
  117. public void controlKeyPressHook(KeyInputEvent evt, String text) { }
  118. ----