PageRenderTime 24ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/libjava/classpath/javax/swing/plaf/multi/MultiPanelUI.java

https://bitbucket.org/pizzafactory/pf-gcc
Java | 352 lines | 160 code | 19 blank | 173 comment | 16 complexity | eca3f4b6ebcd2d2040031ae538d7c83b MD5 | raw file
  1. /* MultiPanelUI.java --
  2. Copyright (C) 2005 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.swing.plaf.multi;
  32. import java.awt.Dimension;
  33. import java.awt.Graphics;
  34. import java.util.Iterator;
  35. import java.util.Vector;
  36. import javax.accessibility.Accessible;
  37. import javax.swing.JComponent;
  38. import javax.swing.LookAndFeel;
  39. import javax.swing.UIManager;
  40. import javax.swing.plaf.ComponentUI;
  41. import javax.swing.plaf.PanelUI;
  42. /**
  43. * A UI delegate that that coordinates multiple {@link PanelUI}
  44. * instances, one from the primary look and feel, and one or more from the
  45. * auxiliary look and feel(s).
  46. *
  47. * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel)
  48. */
  49. public class MultiPanelUI extends PanelUI
  50. {
  51. /** A list of references to the actual component UIs. */
  52. protected Vector uis;
  53. /**
  54. * Creates a new <code>MultiPanelUI</code> instance.
  55. *
  56. * @see #createUI(JComponent)
  57. */
  58. public MultiPanelUI()
  59. {
  60. uis = new Vector();
  61. }
  62. /**
  63. * Creates a delegate object for the specified component. If any auxiliary
  64. * look and feels support this component, a <code>MultiPanelUI</code> is
  65. * returned, otherwise the UI from the default look and feel is returned.
  66. *
  67. * @param target the component.
  68. *
  69. * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent)
  70. */
  71. public static ComponentUI createUI(JComponent target)
  72. {
  73. MultiPanelUI mui = new MultiPanelUI();
  74. return MultiLookAndFeel.createUIs(mui, mui.uis, target);
  75. }
  76. /**
  77. * Calls the {@link ComponentUI#installUI(JComponent)} method for all
  78. * the UI delegates managed by this <code>MultiPanelUI</code>.
  79. *
  80. * @param c the component.
  81. */
  82. public void installUI(JComponent c)
  83. {
  84. Iterator iterator = uis.iterator();
  85. while (iterator.hasNext())
  86. {
  87. ComponentUI ui = (ComponentUI) iterator.next();
  88. ui.installUI(c);
  89. }
  90. }
  91. /**
  92. * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all
  93. * the UI delegates managed by this <code>MultiPanelUI</code>.
  94. *
  95. * @param c the component.
  96. */
  97. public void uninstallUI(JComponent c)
  98. {
  99. Iterator iterator = uis.iterator();
  100. while (iterator.hasNext())
  101. {
  102. ComponentUI ui = (ComponentUI) iterator.next();
  103. ui.uninstallUI(c);
  104. }
  105. }
  106. /**
  107. * Returns an array containing the UI delegates managed by this
  108. * <code>MultiPanelUI</code>. The first item in the array is always
  109. * the UI delegate from the installed default look and feel.
  110. *
  111. * @return An array of UI delegates.
  112. */
  113. public ComponentUI[] getUIs()
  114. {
  115. return MultiLookAndFeel.uisToArray(uis);
  116. }
  117. /**
  118. * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all
  119. * the UI delegates managed by this <code>MultiPanelUI</code>,
  120. * returning the result for the UI delegate from the primary look and
  121. * feel.
  122. *
  123. * @param c the component.
  124. * @param x the x-coordinate.
  125. * @param y the y-coordinate.
  126. *
  127. * @return <code>true</code> if the specified (x, y) coordinate falls within
  128. * the bounds of the component as rendered by the UI delegate in the
  129. * primary look and feel, and <code>false</code> otherwise.
  130. */
  131. public boolean contains(JComponent c, int x, int y)
  132. {
  133. boolean result = false;
  134. Iterator iterator = uis.iterator();
  135. // first UI delegate provides the return value
  136. if (iterator.hasNext())
  137. {
  138. ComponentUI ui = (ComponentUI) iterator.next();
  139. result = ui.contains(c, x, y);
  140. }
  141. // return values from auxiliary UI delegates are ignored
  142. while (iterator.hasNext())
  143. {
  144. ComponentUI ui = (ComponentUI) iterator.next();
  145. /* boolean ignored = */ ui.contains(c, x, y);
  146. }
  147. return result;
  148. }
  149. /**
  150. * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all
  151. * the UI delegates managed by this <code>MultiPanelUI</code>.
  152. *
  153. * @param g the graphics device.
  154. * @param c the component.
  155. */
  156. public void update(Graphics g, JComponent c)
  157. {
  158. Iterator iterator = uis.iterator();
  159. while (iterator.hasNext())
  160. {
  161. ComponentUI ui = (ComponentUI) iterator.next();
  162. ui.update(g, c);
  163. }
  164. }
  165. /**
  166. * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI
  167. * delegates managed by this <code>MultiPanelUI</code>.
  168. *
  169. * @param g the graphics device.
  170. * @param c the component.
  171. */
  172. public void paint(Graphics g, JComponent c)
  173. {
  174. Iterator iterator = uis.iterator();
  175. while (iterator.hasNext())
  176. {
  177. ComponentUI ui = (ComponentUI) iterator.next();
  178. ui.paint(g, c);
  179. }
  180. }
  181. /**
  182. * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all
  183. * the UI delegates managed by this <code>MultiPanelUI</code>,
  184. * returning the preferred size for the UI delegate from the primary look and
  185. * feel.
  186. *
  187. * @param c the component.
  188. *
  189. * @return The preferred size returned by the UI delegate from the primary
  190. * look and feel.
  191. */
  192. public Dimension getPreferredSize(JComponent c)
  193. {
  194. Dimension result = null;
  195. Iterator iterator = uis.iterator();
  196. // first UI delegate provides the return value
  197. if (iterator.hasNext())
  198. {
  199. ComponentUI ui = (ComponentUI) iterator.next();
  200. result = ui.getPreferredSize(c);
  201. }
  202. // return values from auxiliary UI delegates are ignored
  203. while (iterator.hasNext())
  204. {
  205. ComponentUI ui = (ComponentUI) iterator.next();
  206. /* Dimension ignored = */ ui.getPreferredSize(c);
  207. }
  208. return result;
  209. }
  210. /**
  211. * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all
  212. * the UI delegates managed by this <code>MultiPanelUI</code>,
  213. * returning the minimum size for the UI delegate from the primary look and
  214. * feel.
  215. *
  216. * @param c the component.
  217. *
  218. * @return The minimum size returned by the UI delegate from the primary
  219. * look and feel.
  220. */
  221. public Dimension getMinimumSize(JComponent c)
  222. {
  223. Dimension result = null;
  224. Iterator iterator = uis.iterator();
  225. // first UI delegate provides the return value
  226. if (iterator.hasNext())
  227. {
  228. ComponentUI ui = (ComponentUI) iterator.next();
  229. result = ui.getMinimumSize(c);
  230. }
  231. // return values from auxiliary UI delegates are ignored
  232. while (iterator.hasNext())
  233. {
  234. ComponentUI ui = (ComponentUI) iterator.next();
  235. /* Dimension ignored = */ ui.getMinimumSize(c);
  236. }
  237. return result;
  238. }
  239. /**
  240. * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all
  241. * the UI delegates managed by this <code>MultiPanelUI</code>,
  242. * returning the maximum size for the UI delegate from the primary look and
  243. * feel.
  244. *
  245. * @param c the component.
  246. *
  247. * @return The maximum size returned by the UI delegate from the primary
  248. * look and feel.
  249. */
  250. public Dimension getMaximumSize(JComponent c)
  251. {
  252. Dimension result = null;
  253. Iterator iterator = uis.iterator();
  254. // first UI delegate provides the return value
  255. if (iterator.hasNext())
  256. {
  257. ComponentUI ui = (ComponentUI) iterator.next();
  258. result = ui.getMaximumSize(c);
  259. }
  260. // return values from auxiliary UI delegates are ignored
  261. while (iterator.hasNext())
  262. {
  263. ComponentUI ui = (ComponentUI) iterator.next();
  264. /* Dimension ignored = */ ui.getMaximumSize(c);
  265. }
  266. return result;
  267. }
  268. /**
  269. * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method
  270. * for all the UI delegates managed by this <code>MultiPanelUI</code>,
  271. * returning the count for the UI delegate from the primary look and
  272. * feel.
  273. *
  274. * @param c the component.
  275. *
  276. * @return The count returned by the UI delegate from the primary
  277. * look and feel.
  278. */
  279. public int getAccessibleChildrenCount(JComponent c)
  280. {
  281. int result = 0;
  282. Iterator iterator = uis.iterator();
  283. // first UI delegate provides the return value
  284. if (iterator.hasNext())
  285. {
  286. ComponentUI ui = (ComponentUI) iterator.next();
  287. result = ui.getAccessibleChildrenCount(c);
  288. }
  289. // return values from auxiliary UI delegates are ignored
  290. while (iterator.hasNext())
  291. {
  292. ComponentUI ui = (ComponentUI) iterator.next();
  293. /* int ignored = */ ui.getAccessibleChildrenCount(c);
  294. }
  295. return result;
  296. }
  297. /**
  298. * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method
  299. * for all the UI delegates managed by this <code>MultiPanelUI</code>,
  300. * returning the child for the UI delegate from the primary look and
  301. * feel.
  302. *
  303. * @param c the component
  304. * @param i the child index.
  305. *
  306. * @return The child returned by the UI delegate from the primary
  307. * look and feel.
  308. */
  309. public Accessible getAccessibleChild(JComponent c, int i)
  310. {
  311. Accessible result = null;
  312. Iterator iterator = uis.iterator();
  313. // first UI delegate provides the return value
  314. if (iterator.hasNext())
  315. {
  316. ComponentUI ui = (ComponentUI) iterator.next();
  317. result = ui.getAccessibleChild(c, i);
  318. }
  319. // return values from auxiliary UI delegates are ignored
  320. while (iterator.hasNext())
  321. {
  322. ComponentUI ui = (ComponentUI) iterator.next();
  323. /* Accessible ignored = */ ui.getAccessibleChild(c, i);
  324. }
  325. return result;
  326. }
  327. }