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