1. /*
  2. * @(#)MultiTextUI.java 1.30 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.plaf.multi;
  8. import java.util.Vector;
  9. import javax.swing.plaf.TextUI;
  10. import java.awt.Rectangle;
  11. import javax.swing.text.JTextComponent;
  12. import javax.swing.text.BadLocationException;
  13. import java.awt.Point;
  14. import javax.swing.text.EditorKit;
  15. import javax.swing.text.Position;
  16. import javax.swing.text.View;
  17. import javax.swing.plaf.ComponentUI;
  18. import javax.swing.JComponent;
  19. import java.awt.Graphics;
  20. import java.awt.Dimension;
  21. import javax.accessibility.Accessible;
  22. /**
  23. * MultiTextUI implementation
  24. *
  25. * <p>This file was automatically generated by AutoMulti.
  26. *
  27. * @version 1.30 11/29/01 23:13:07
  28. * @author Otto Multey
  29. */
  30. public class MultiTextUI extends TextUI {
  31. /**
  32. * The Vector containing the real UI's. This is populated
  33. * in the call to createUI, and can be obtained by calling
  34. * getUIs. The first element is guaranteed to the real UI
  35. * obtained from the default look and feel.
  36. */
  37. protected Vector uis = new Vector();
  38. ////////////////////
  39. // Common UI methods
  40. ////////////////////
  41. /**
  42. * Return the list of UI's associated with this multiplexing UI. This
  43. * allows processing of the UI's by an application aware of multiplexing
  44. * UI's on components.
  45. */
  46. public ComponentUI[] getUIs() {
  47. return MultiLookAndFeel.uisToArray(uis);
  48. }
  49. ////////////////////
  50. // TextUI methods
  51. ////////////////////
  52. /**
  53. * Call modelToView on each UI handled by this MultiUI.
  54. * Return only the value obtained from the first UI, which is
  55. * the UI obtained from the default LookAndFeel.
  56. */
  57. public Rectangle modelToView(JTextComponent a, int b)
  58. throws BadLocationException {
  59. Rectangle returnValue =
  60. ((TextUI) (uis.elementAt(0))).modelToView(a,b);
  61. for (int i = 1; i < uis.size(); i++) {
  62. ((TextUI) (uis.elementAt(i))).modelToView(a,b);
  63. }
  64. return returnValue;
  65. }
  66. /**
  67. * Converts the given location in the model to a place in
  68. * the view coordinate system.
  69. *
  70. * @param pos the local location in the model to translate >= 0
  71. * @return the coordinates as a rectangle
  72. * @exception BadLocationException if the given position does not
  73. * represent a valid location in the associated document
  74. */
  75. public Rectangle modelToView(JTextComponent t, int pos, Position.Bias bias)
  76. throws BadLocationException {
  77. Rectangle returnValue =
  78. ((TextUI) (uis.elementAt(0))).modelToView(t, pos, bias);
  79. for (int i = 1; i < uis.size(); i++) {
  80. ((TextUI) (uis.elementAt(i))).modelToView(t, pos, bias);
  81. }
  82. return returnValue;
  83. }
  84. /**
  85. * Call viewToModel on each UI handled by this MultiUI.
  86. * Return only the value obtained from the first UI, which is
  87. * the UI obtained from the default LookAndFeel.
  88. */
  89. public int viewToModel(JTextComponent a, Point b) {
  90. int returnValue =
  91. ((TextUI) (uis.elementAt(0))).viewToModel(a,b);
  92. for (int i = 1; i < uis.size(); i++) {
  93. ((TextUI) (uis.elementAt(i))).viewToModel(a,b);
  94. }
  95. return returnValue;
  96. }
  97. /**
  98. * Provides a mapping from the view coordinate space to the logical
  99. * coordinate space of the model. The biasReturn argument will be
  100. * filled in to indicate that the point given is closer to the next
  101. * character in the model or the previous character in the model.
  102. *
  103. * @param x the X coordinate >= 0
  104. * @param y the Y coordinate >= 0
  105. * @param a the allocated region to render into
  106. * @return the location within the model that best represents the
  107. * given point in the view >= 0. The biasReturn argument will be
  108. * filled in to indicate that the point given is closer to the next
  109. * character in the model or the previous character in the model.
  110. */
  111. public int viewToModel(JTextComponent t, Point pt,
  112. Position.Bias[] biasReturn) {
  113. int returnValue =
  114. ((TextUI) (uis.elementAt(0))).viewToModel(t, pt, biasReturn);
  115. for (int i = 1; i < uis.size(); i++) {
  116. ((TextUI) (uis.elementAt(i))).viewToModel(t, pt, biasReturn);
  117. }
  118. return returnValue;
  119. }
  120. /**
  121. * Provides a way to determine the next visually represented model
  122. * location that one might place a caret. Some views may not be visible,
  123. * they might not be in the same order found in the model, or they just
  124. * might not allow access to some of the locations in the model.
  125. *
  126. * @param pos the position to convert >= 0
  127. * @param a the allocated region to render into
  128. * @param direction the direction from the current position that can
  129. * be thought of as the arrow keys typically found on a keyboard.
  130. * This may be SwingConstants.WEST, SwingConstants.EAST,
  131. * SwingConstants.NORTH, or SwingConstants.SOUTH.
  132. * @return the location within the model that best represents the next
  133. * location visual position.
  134. * @exception BadLocationException
  135. * @exception IllegalArgumentException for an invalid direction
  136. */
  137. public int getNextVisualPositionFrom(JTextComponent t, int pos,
  138. Position.Bias b, int direction,
  139. Position.Bias[] biasRet)
  140. throws BadLocationException {
  141. int returnValue =
  142. ((TextUI) (uis.elementAt(0))).getNextVisualPositionFrom(t, pos, b, direction, biasRet);
  143. for (int i = 1; i < uis.size(); i++) {
  144. ((TextUI) (uis.elementAt(i))).getNextVisualPositionFrom(t, pos, b, direction, biasRet);
  145. }
  146. return returnValue;
  147. }
  148. /**
  149. * Call damageRange on each UI handled by this MultiUI.
  150. */
  151. public void damageRange(JTextComponent a, int b, int c) {
  152. for (int i = 0; i < uis.size(); i++) {
  153. ((TextUI) (uis.elementAt(i))).damageRange(a,b,c);
  154. }
  155. }
  156. /**
  157. * Causes the portion of the view responsible for the
  158. * given part of the model to be repainted.
  159. *
  160. * @param p0 the beginning of the range >= 0
  161. * @param p1 the end of the range >= p0
  162. */
  163. public void damageRange(JTextComponent t, int p0, int p1,
  164. Position.Bias firstBias,
  165. Position.Bias secondBias) {
  166. for (int i = 0; i < uis.size(); i++) {
  167. ((TextUI) (uis.elementAt(i))).damageRange(t, p0, p1,
  168. firstBias,
  169. secondBias);
  170. }
  171. }
  172. /**
  173. * Call getEditorKit on each UI handled by this MultiUI.
  174. * Return only the value obtained from the first UI, which is
  175. * the UI obtained from the default LookAndFeel.
  176. */
  177. public EditorKit getEditorKit(JTextComponent a) {
  178. EditorKit returnValue =
  179. ((TextUI) (uis.elementAt(0))).getEditorKit(a);
  180. for (int i = 1; i < uis.size(); i++) {
  181. ((TextUI) (uis.elementAt(i))).getEditorKit(a);
  182. }
  183. return returnValue;
  184. }
  185. /**
  186. * Call getRootView on each UI handled by this MultiUI.
  187. * Return only the value obtained from the first UI, which is
  188. * the UI obtained from the default LookAndFeel.
  189. */
  190. public View getRootView(JTextComponent a) {
  191. View returnValue =
  192. ((TextUI) (uis.elementAt(0))).getRootView(a);
  193. for (int i = 1; i < uis.size(); i++) {
  194. ((TextUI) (uis.elementAt(i))).getRootView(a);
  195. }
  196. return returnValue;
  197. }
  198. ////////////////////
  199. // ComponentUI methods
  200. ////////////////////
  201. /**
  202. * Call installUI on each UI handled by this MultiUI.
  203. */
  204. public void installUI(JComponent a) {
  205. for (int i = 0; i < uis.size(); i++) {
  206. ((ComponentUI) (uis.elementAt(i))).installUI(a);
  207. }
  208. }
  209. /**
  210. * Call uninstallUI on each UI handled by this MultiUI.
  211. */
  212. public void uninstallUI(JComponent a) {
  213. for (int i = 0; i < uis.size(); i++) {
  214. ((ComponentUI) (uis.elementAt(i))).uninstallUI(a);
  215. }
  216. }
  217. /**
  218. * Call paint on each UI handled by this MultiUI.
  219. */
  220. public void paint(Graphics a, JComponent b) {
  221. for (int i = 0; i < uis.size(); i++) {
  222. ((ComponentUI) (uis.elementAt(i))).paint(a,b);
  223. }
  224. }
  225. /**
  226. * Call update on each UI handled by this MultiUI.
  227. */
  228. public void update(Graphics a, JComponent b) {
  229. for (int i = 0; i < uis.size(); i++) {
  230. ((ComponentUI) (uis.elementAt(i))).update(a,b);
  231. }
  232. }
  233. /**
  234. * Call getPreferredSize on each UI handled by this MultiUI.
  235. * Return only the value obtained from the first UI, which is
  236. * the UI obtained from the default LookAndFeel.
  237. */
  238. public Dimension getPreferredSize(JComponent a) {
  239. Dimension returnValue =
  240. ((ComponentUI) (uis.elementAt(0))).getPreferredSize(a);
  241. for (int i = 1; i < uis.size(); i++) {
  242. ((ComponentUI) (uis.elementAt(i))).getPreferredSize(a);
  243. }
  244. return returnValue;
  245. }
  246. /**
  247. * Call getMinimumSize on each UI handled by this MultiUI.
  248. * Return only the value obtained from the first UI, which is
  249. * the UI obtained from the default LookAndFeel.
  250. */
  251. public Dimension getMinimumSize(JComponent a) {
  252. Dimension returnValue =
  253. ((ComponentUI) (uis.elementAt(0))).getMinimumSize(a);
  254. for (int i = 1; i < uis.size(); i++) {
  255. ((ComponentUI) (uis.elementAt(i))).getMinimumSize(a);
  256. }
  257. return returnValue;
  258. }
  259. /**
  260. * Call getMaximumSize on each UI handled by this MultiUI.
  261. * Return only the value obtained from the first UI, which is
  262. * the UI obtained from the default LookAndFeel.
  263. */
  264. public Dimension getMaximumSize(JComponent a) {
  265. Dimension returnValue =
  266. ((ComponentUI) (uis.elementAt(0))).getMaximumSize(a);
  267. for (int i = 1; i < uis.size(); i++) {
  268. ((ComponentUI) (uis.elementAt(i))).getMaximumSize(a);
  269. }
  270. return returnValue;
  271. }
  272. /**
  273. * Call contains on each UI handled by this MultiUI.
  274. * Return only the value obtained from the first UI, which is
  275. * the UI obtained from the default LookAndFeel.
  276. */
  277. public boolean contains(JComponent a, int b, int c) {
  278. boolean returnValue =
  279. ((ComponentUI) (uis.elementAt(0))).contains(a,b,c);
  280. for (int i = 1; i < uis.size(); i++) {
  281. ((ComponentUI) (uis.elementAt(i))).contains(a,b,c);
  282. }
  283. return returnValue;
  284. }
  285. /**
  286. * Return a multiplexing UI instance if any of the auxiliary
  287. * LookAndFeels support this UI. Otherwise, just return a
  288. * UI obtained using the normal methods.
  289. */
  290. public static ComponentUI createUI(JComponent a) {
  291. ComponentUI mui = new MultiTextUI();
  292. return MultiLookAndFeel.createUIs(mui,
  293. ((MultiTextUI) mui).uis,
  294. a);
  295. }
  296. /**
  297. * Call getAccessibleChildrenCount on each UI handled by this MultiUI.
  298. * Return only the value obtained from the first UI, which is
  299. * the UI obtained from the default LookAndFeel.
  300. */
  301. public int getAccessibleChildrenCount(JComponent a) {
  302. int returnValue =
  303. ((ComponentUI) (uis.elementAt(0))).getAccessibleChildrenCount(a);
  304. for (int i = 1; i < uis.size(); i++) {
  305. ((ComponentUI) (uis.elementAt(i))).getAccessibleChildrenCount(a);
  306. }
  307. return returnValue;
  308. }
  309. /**
  310. * Call getAccessibleChild on each UI handled by this MultiUI.
  311. * Return only the value obtained from the first UI, which is
  312. * the UI obtained from the default LookAndFeel.
  313. */
  314. public Accessible getAccessibleChild(JComponent a, int b) {
  315. Accessible returnValue =
  316. ((ComponentUI) (uis.elementAt(0))).getAccessibleChild(a,b);
  317. for (int i = 1; i < uis.size(); i++) {
  318. ((ComponentUI) (uis.elementAt(i))).getAccessibleChild(a,b);
  319. }
  320. return returnValue;
  321. }
  322. }