BorderUIResource.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  1. /* BorderUIResource.java
  2. Copyright (C) 2002, 2003, 2004 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;
  32. import java.awt.Color;
  33. import java.awt.Component;
  34. import java.awt.Font;
  35. import java.awt.Graphics;
  36. import java.awt.Insets;
  37. import java.io.Serializable;
  38. import javax.swing.Icon;
  39. import javax.swing.border.BevelBorder;
  40. import javax.swing.border.Border;
  41. import javax.swing.border.CompoundBorder;
  42. import javax.swing.border.EmptyBorder;
  43. import javax.swing.border.EtchedBorder;
  44. import javax.swing.border.LineBorder;
  45. import javax.swing.border.MatteBorder;
  46. import javax.swing.border.TitledBorder;
  47. /**
  48. * A wrapper for {@link javax.swing.border.Border} that also
  49. * implements the {@link UIResource} marker interface. This is useful
  50. * for implementing pluggable look-and-feels: When switching the
  51. * current LookAndFeel, only those borders are replaced that are
  52. * marked as {@link UIResource}. For this reason, a look-and-feel
  53. * should always install borders that implement
  54. * <code>UIResource</code>, such as the borders provided by this
  55. * class.
  56. *
  57. * @serial
  58. * @serialField delegate Border the <code>Border</code> wrapped
  59. *
  60. * @author Brian Jones (cbj@gnu.org)
  61. * @author Sascha Brawer (brawer@dandelis.ch)
  62. */
  63. public class BorderUIResource implements Border, UIResource, Serializable
  64. {
  65. /**
  66. * Verified using the <code>serialver</code> tool
  67. * of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5.
  68. */
  69. static final long serialVersionUID = -3440553684010079691L;
  70. /**
  71. * A shared instance of an {@link EtchedBorderUIResource}, or
  72. * <code>null</code> if the {@link #getEtchedBorderUIResource()}
  73. * method has not yet been called.
  74. */
  75. private static Border etchedBorderUIResource;
  76. /**
  77. * A shared instance of a {@link BevelBorderUIResource} whose
  78. * <code>bevelType</code> is {@link
  79. * javax.swing.border.BevelBorder#LOWERED}, or <code>null</code> if
  80. * the {@link #getLoweredBevelBorderUIResource()} has not yet been
  81. * called.
  82. */
  83. private static Border loweredBevelBorderUIResource;
  84. /**
  85. * A shared instance of a {@link BevelBorderUIResource} whose
  86. * <code>bevelType</code> is {@link
  87. * javax.swing.border.BevelBorder#RAISED}, or <code>null</code> if
  88. * the {@link #getRaisedBevelBorderUIResource()} has not yet been
  89. * called.
  90. */
  91. private static Border raisedBevelBorderUIResource;
  92. /**
  93. * A shared instance of a {@link LineBorderUIResource} for
  94. * a one-pixel thick black line, or <code>null</code> if
  95. * the {@link #getBlackLineBorderUIResource()} has not yet been
  96. * called.
  97. */
  98. private static Border blackLineBorderUIResource;
  99. /**
  100. * Returns a shared instance of an etched border which also
  101. * is marked as an {@link UIResource}.
  102. *
  103. * @see javax.swing.border.EtchedBorder
  104. */
  105. public static Border getEtchedBorderUIResource()
  106. {
  107. /* Swing is not designed to be thread-safe, so there is no
  108. * need to synchronize the access to the global variable.
  109. */
  110. if (etchedBorderUIResource == null)
  111. etchedBorderUIResource = new EtchedBorderUIResource();
  112. return etchedBorderUIResource;
  113. }
  114. /**
  115. * Returns a shared instance of {@link BevelBorderUIResource} whose
  116. * <code>bevelType</code> is {@link
  117. * javax.swing.border.BevelBorder#LOWERED}.
  118. *
  119. * @see javax.swing.border.BevelBorder
  120. */
  121. public static Border getLoweredBevelBorderUIResource()
  122. {
  123. /* Swing is not designed to be thread-safe, so there is no
  124. * need to synchronize the access to the global variable.
  125. */
  126. if (loweredBevelBorderUIResource == null)
  127. loweredBevelBorderUIResource = new BevelBorderUIResource(
  128. BevelBorder.LOWERED);
  129. return loweredBevelBorderUIResource;
  130. }
  131. /**
  132. * Returns a shared instance of {@link BevelBorderUIResource} whose
  133. * <code>bevelType</code> is {@link
  134. * javax.swing.border.BevelBorder#RAISED}.
  135. *
  136. * @see javax.swing.border.BevelBorder
  137. */
  138. public static Border getRaisedBevelBorderUIResource()
  139. {
  140. /* Swing is not designed to be thread-safe, so there is no
  141. * need to synchronize the access to the global variable.
  142. */
  143. if (raisedBevelBorderUIResource == null)
  144. raisedBevelBorderUIResource = new BevelBorderUIResource(
  145. BevelBorder.RAISED);
  146. return raisedBevelBorderUIResource;
  147. }
  148. /**
  149. * Returns a shared instance of {@link LineBorderUIResource} for
  150. * a black, one-pixel width border.
  151. *
  152. * @see javax.swing.border.LineBorder
  153. */
  154. public static Border getBlackLineBorderUIResource()
  155. {
  156. /* Swing is not designed to be thread-safe, so there is no
  157. * need to synchronize the access to the global variable.
  158. */
  159. if (blackLineBorderUIResource == null)
  160. blackLineBorderUIResource = new LineBorderUIResource(Color.black);
  161. return blackLineBorderUIResource;
  162. }
  163. /**
  164. * The wrapped border.
  165. */
  166. private Border delegate;
  167. /**
  168. * Constructs a <code>BorderUIResource</code> for wrapping
  169. * a <code>Border</code> object.
  170. *
  171. * @param delegate the border to be wrapped.
  172. */
  173. public BorderUIResource(Border delegate)
  174. {
  175. if (delegate == null)
  176. throw new IllegalArgumentException();
  177. this.delegate = delegate;
  178. }
  179. /**
  180. * Paints the border around an enclosed component by calling
  181. * the <code>paintBorder</code> method of the wrapped delegate.
  182. *
  183. * @param c the component whose border is to be painted.
  184. * @param g the graphics for painting.
  185. * @param x the horizontal position for painting the border.
  186. * @param y the vertical position for painting the border.
  187. * @param width the width of the available area for painting the border.
  188. * @param height the height of the available area for painting the border.
  189. */
  190. public void paintBorder(Component c, Graphics g,
  191. int x, int y, int width, int height)
  192. {
  193. delegate.paintBorder(c, g, x, y, width, height);
  194. }
  195. /**
  196. * Measures the width of this border by calling the
  197. * <code>getBorderInsets</code> method of the wrapped
  198. * delegate.
  199. *
  200. * @param c the component whose border is to be measured.
  201. *
  202. * @return an Insets object whose <code>left</code>, <code>right</code>,
  203. * <code>top</code> and <code>bottom</code> fields indicate the
  204. * width of the border at the respective edge.
  205. */
  206. public Insets getBorderInsets(Component c)
  207. {
  208. return delegate.getBorderInsets(c);
  209. }
  210. /**
  211. * Determines whether this border fills every pixel in its area
  212. * when painting by calling the <code>isBorderOpaque</code>
  213. * method of the wrapped delegate.
  214. *
  215. * @return <code>true</code> if the border is fully opaque, or
  216. * <code>false</code> if some pixels of the background
  217. * can shine through the border.
  218. */
  219. public boolean isBorderOpaque()
  220. {
  221. return delegate.isBorderOpaque();
  222. }
  223. /**
  224. * A {@link javax.swing.border.BevelBorder} that also implements the
  225. * {@link UIResource} marker interface. This is useful for
  226. * implementing pluggable look-and-feels: When switching the current
  227. * LookAndFeel, only those borders are replaced that are marked as
  228. * {@link UIResource}. For this reason, a look-and-feel should
  229. * always install borders that implement <code>UIResource</code>,
  230. * such as the borders provided by this class.
  231. *
  232. * @author Brian Jones (cbj@gnu.org)
  233. * @author Sascha Brawer (brawer@dandelis.ch)
  234. */
  235. public static class BevelBorderUIResource
  236. extends BevelBorder
  237. implements UIResource, Serializable
  238. {
  239. private static final long serialVersionUID = -1275542891108351642L;
  240. /**
  241. * Constructs a BevelBorderUIResource whose colors will be derived
  242. * from the background of the enclosed component. The background
  243. * color is retrieved each time the border is painted, so a border
  244. * constructed by this method will automatically reflect a change
  245. * to the component&#x2019;s background color.
  246. *
  247. * <p><img src="../border/doc-files/BevelBorder-1.png"
  248. * width="500" height="150"
  249. * alt="[An illustration showing raised and lowered BevelBorders]" /></p>
  250. *
  251. * @param bevelType the desired appearance of the border. The value
  252. * must be either {@link javax.swing.border.BevelBorder#RAISED}
  253. * or {@link javax.swing.border.BevelBorder#LOWERED}.
  254. *
  255. * @throws IllegalArgumentException if <code>bevelType</code> has
  256. * an unsupported value.
  257. */
  258. public BevelBorderUIResource(int bevelType)
  259. {
  260. super(bevelType);
  261. }
  262. /**
  263. * Constructs a BevelBorderUIResource given its appearance type
  264. * and two colors for its highlight and shadow.
  265. *
  266. * <p><img src="../border/doc-files/BevelBorder-2.png" width="500"
  267. * height="150" alt="[An illustration showing BevelBorders that were
  268. * constructed with this method]" /></p>
  269. *
  270. * @param bevelType the desired appearance of the border. The value
  271. * must be either {@link javax.swing.border.BevelBorder#RAISED}
  272. * or {@link javax.swing.border.BevelBorder#LOWERED}.
  273. *
  274. * @param highlight the color that will be used for the inner side
  275. * of the highlighted edges (top and left if if
  276. * <code>bevelType</code> is {@link
  277. * javax.swing.border.BevelBorder#RAISED}; bottom and right
  278. * otherwise). The color for the outer side is a brightened
  279. * version of this color.
  280. *
  281. * @param shadow the color that will be used for the outer side of
  282. * the shadowed edges (bottom and right if
  283. * <code>bevelType</code> is {@link
  284. * javax.swing.border.BevelBorder#RAISED}; top and left
  285. * otherwise). The color for the inner side is a brightened
  286. * version of this color.
  287. *
  288. * @throws IllegalArgumentException if <code>bevelType</code> has
  289. * an unsupported value.
  290. *
  291. * @throws NullPointerException if <code>highlight</code> or
  292. * <code>shadow</code> is <code>null</code>.
  293. */
  294. public BevelBorderUIResource(int bevelType,
  295. Color highlight,
  296. Color shadow)
  297. {
  298. super(bevelType, highlight, shadow);
  299. }
  300. /**
  301. * Constructs a BevelBorderUIResource given its appearance type
  302. * and all its colors.
  303. *
  304. * <p><img src="../border/doc-files/BevelBorder-3.png" width="500"
  305. * height="150" alt="[An illustration showing BevelBorders that
  306. * were constructed with this method]" /></p>
  307. *
  308. * @param bevelType the desired appearance of the border. The value
  309. * must be either {@link javax.swing.border.BevelBorder#RAISED}
  310. * or {@link javax.swing.border.BevelBorder#LOWERED}.
  311. *
  312. * @param highlightOuter the color that will be used for the outer
  313. * side of the highlighted edges (top and left if
  314. * <code>bevelType</code> is {@link
  315. * javax.swing.border.BevelBorder#RAISED}; bottom and right
  316. * otherwise).
  317. *
  318. * @param highlightInner the color that will be used for the inner
  319. * side of the highlighted edges.
  320. *
  321. * @param shadowOuter the color that will be used for the outer
  322. * side of the shadowed edges (bottom and right if
  323. * <code>bevelType</code> is {@link
  324. * javax.swing.border.BevelBorder#RAISED}; top and left
  325. * otherwise).
  326. *
  327. * @param shadowInner the color that will be used for the inner
  328. * side of the shadowed edges.
  329. *
  330. * @throws IllegalArgumentException if <code>bevelType</code> has
  331. * an unsupported value.
  332. *
  333. * @throws NullPointerException if one of the passed colors
  334. * is <code>null</code>.
  335. */
  336. public BevelBorderUIResource(int bevelType,
  337. Color highlightOuter,
  338. Color highlightInner,
  339. Color shadowOuter,
  340. Color shadowInner)
  341. {
  342. super(bevelType,
  343. highlightOuter, highlightInner,
  344. shadowOuter, shadowInner);
  345. }
  346. }
  347. /**
  348. * A {@link javax.swing.border.CompoundBorder} that also implements the
  349. * {@link UIResource} marker interface. This is useful for
  350. * implementing pluggable look-and-feels: When switching the current
  351. * LookAndFeel, only those borders are replaced that are marked as
  352. * {@link UIResource}. For this reason, a look-and-feel should
  353. * always install borders that implement <code>UIResource</code>,
  354. * such as the borders provided by this class.
  355. *
  356. * @author Brian Jones (cbj@gnu.org)
  357. * @author Sascha Brawer (brawer@dandelis.ch)
  358. */
  359. public static class CompoundBorderUIResource
  360. extends CompoundBorder
  361. implements UIResource, Serializable
  362. {
  363. private static final long serialVersionUID = 7550017084975167341L;
  364. /**
  365. * Constructs a CompoundBorderUIResource with the specified inside
  366. * and outside borders.
  367. *
  368. * @param outsideBorder the outside border, which is painted to the
  369. * outside of both <code>insideBorder</code> and the enclosed
  370. * component. It is acceptable to pass <code>null</code>, in
  371. * which case no outside border is painted.
  372. *
  373. * @param insideBorder the inside border, which is painted to
  374. * between <code>outsideBorder</code> and the enclosed
  375. * component. It is acceptable to pass <code>null</code>, in
  376. * which case no inside border is painted.
  377. */
  378. public CompoundBorderUIResource(Border outsideBorder,
  379. Border insideBorder)
  380. {
  381. super(outsideBorder, insideBorder);
  382. }
  383. }
  384. /**
  385. * An {@link javax.swing.border.EmptyBorder} that also implements the
  386. * {@link UIResource} marker interface. This is useful for
  387. * implementing pluggable look-and-feels: When switching the current
  388. * LookAndFeel, only those borders are replaced that are marked as
  389. * {@link UIResource}. For this reason, a look-and-feel should
  390. * always install borders that implement <code>UIResource</code>,
  391. * such as the borders provided by this class.
  392. *
  393. * <p><img src="../border/doc-files/EmptyBorder-1.png"
  394. * width="290" height="200"
  395. * alt="[An illustration of EmptyBorder]" /></p>
  396. *
  397. * @author Brian Jones (cbj@gnu.org)
  398. * @author Sascha Brawer (brawer@dandelis.ch)
  399. */
  400. public static class EmptyBorderUIResource
  401. extends EmptyBorder
  402. implements UIResource, Serializable
  403. {
  404. private static final long serialVersionUID = -4914187529340071708L;
  405. /**
  406. * Constructs an empty border given the number of pixels required
  407. * on each side.
  408. *
  409. * @param top the number of pixels that the border will need
  410. * for its top edge.
  411. *
  412. * @param left the number of pixels that the border will need
  413. * for its left edge.
  414. *
  415. * @param bottom the number of pixels that the border will need
  416. * for its bottom edge.
  417. *
  418. * @param right the number of pixels that the border will need
  419. * for its right edge.
  420. */
  421. public EmptyBorderUIResource(int top, int left, int bottom, int right)
  422. {
  423. super(top, left, bottom, right);
  424. }
  425. /**
  426. * Constructs an empty border given the number of pixels required
  427. * on each side, passed in an Insets object.
  428. *
  429. * @param insets the Insets for the new border.
  430. */
  431. public EmptyBorderUIResource(Insets insets)
  432. {
  433. super(insets);
  434. }
  435. }
  436. /**
  437. * An {@link javax.swing.border.EtchedBorder} that also implements the
  438. * {@link UIResource} marker interface. This is useful for
  439. * implementing pluggable look-and-feels: When switching the current
  440. * LookAndFeel, only those borders are replaced that are marked as
  441. * {@link UIResource}. For this reason, a look-and-feel should
  442. * always install borders that implement <code>UIResource</code>,
  443. * such as the borders provided by this class.
  444. *
  445. * <p><img src="../border/doc-files/EtchedBorder-1.png" width="500"
  446. * height="200" alt="[An illustration of the two EtchedBorder
  447. * variants]" /></p>
  448. *
  449. * @author Brian Jones (cbj@gnu.org)
  450. * @author Sascha Brawer (brawer@dandelis.ch)
  451. */
  452. public static class EtchedBorderUIResource
  453. extends EtchedBorder
  454. implements UIResource, Serializable
  455. {
  456. private static final long serialVersionUID = -8186391754165296656L;
  457. /**
  458. * Constructs an EtchedBorderUIResource that appears lowered into
  459. * the surface. The colors will be derived from the background
  460. * color of the enclosed Component when the border gets painted.
  461. */
  462. public EtchedBorderUIResource()
  463. {
  464. super();
  465. }
  466. /**
  467. * Constructs an EtchedBorderUIResource with the specified
  468. * appearance. The colors will be derived from the background
  469. * color of the enclosed Component when the border gets painted.
  470. *
  471. * <p><img src="../border/doc-files/EtchedBorder-1.png"
  472. * width="500" height="200" alt="[An illustration of the two
  473. * EtchedBorder variants]" /></p>
  474. *
  475. * @param etchType the desired appearance of the border. The value
  476. * must be either {@link javax.swing.border.EtchedBorder#RAISED}
  477. * or {@link javax.swing.border.EtchedBorder#LOWERED}.
  478. *
  479. * @throws IllegalArgumentException if <code>etchType</code> has
  480. * an unsupported value.
  481. */
  482. public EtchedBorderUIResource(int etchType)
  483. {
  484. super(etchType);
  485. }
  486. /**
  487. * Constructs a lowered EtchedBorderUIResource, explicitly
  488. * selecting the colors that will be used for highlight and
  489. * shadow.
  490. *
  491. * @param highlight the color that will be used for painting
  492. * the highlight part of the border.
  493. *
  494. * @param shadow the color that will be used for painting
  495. * the shadow part of the border.
  496. *
  497. * @see EtchedBorderUIResource#EtchedBorderUIResource(int, Color, Color)
  498. */
  499. public EtchedBorderUIResource(Color highlight, Color shadow)
  500. {
  501. super(highlight, shadow);
  502. }
  503. /**
  504. * Constructs an EtchedBorderUIResource with the specified
  505. * appearance, explicitly selecting the colors that will be used
  506. * for highlight and shadow.
  507. *
  508. * <p><img src="../border/doc-files/EtchedBorder-2.png" width="500"
  509. * height="200" alt="[An illustration that shows which pixels get
  510. * painted in what color]" /></p>
  511. *
  512. * @param etchType the desired appearance of the border. The value
  513. * must be either {@link javax.swing.border.EtchedBorder#RAISED}
  514. * or {@link javax.swing.border.EtchedBorder#LOWERED}.
  515. *
  516. * @param highlight the color that will be used for painting
  517. * the highlight part of the border.
  518. *
  519. * @param shadow the color that will be used for painting
  520. * the shadow part of the border.
  521. *
  522. * @throws IllegalArgumentException if <code>etchType</code> has
  523. * an unsupported value.
  524. */
  525. public EtchedBorderUIResource(int etchType,
  526. Color highlight, Color shadow)
  527. {
  528. super(etchType, highlight, shadow);
  529. }
  530. }
  531. /**
  532. * A {@link javax.swing.border.LineBorder} that also implements the
  533. * {@link UIResource} marker interface. This is useful for
  534. * implementing pluggable look-and-feels: When switching the current
  535. * LookAndFeel, only those borders are replaced that are marked as
  536. * {@link UIResource}. For this reason, a look-and-feel should
  537. * always install borders that implement <code>UIResource</code>,
  538. * such as the borders provided by this class.
  539. *
  540. * <p><img src="../border/doc-files/LineBorder-1.png" width="500"
  541. * height="200" alt="[An illustration of two LineBorders]" /></p>
  542. *
  543. * @author Brian Jones (cbj@gnu.org)
  544. * @author Sascha Brawer (brawer@dandelis.ch)
  545. */
  546. public static class LineBorderUIResource
  547. extends LineBorder
  548. implements UIResource, Serializable
  549. {
  550. private static final long serialVersionUID = -6171232338180172310L;
  551. /**
  552. * Constructs a LineBorderUIResource given its color. The border
  553. * will be one pixel thick and have plain corners.
  554. *
  555. * @param color the color for drawing the border.
  556. */
  557. public LineBorderUIResource(Color color)
  558. {
  559. super(color);
  560. }
  561. /**
  562. * Constructs a LineBorder given its color and thickness. The
  563. * border will have plain corners.
  564. *
  565. * @param color the color for drawing the border.
  566. * @param thickness the width of the line in pixels.
  567. */
  568. public LineBorderUIResource(Color color, int thickness)
  569. {
  570. super(color, thickness);
  571. }
  572. /* Note: Since JDK1.3, javax.swing.border.LineBorder also has a
  573. * constructor which accepts a value for the roundedCorners
  574. * property. However, as of JDK1.4.1, the LineBorderUIResource
  575. * subclass does not have a corresponding constructor.
  576. *
  577. * A request for enhancing the Swing API has been filed with Sun:
  578. * http://developer.java.sun.com/developer/bugParade/bugs/4879999.html
  579. */
  580. }
  581. /**
  582. * A {@link javax.swing.border.MatteBorder} that also implements the
  583. * {@link UIResource} marker interface. This is useful for
  584. * implementing pluggable look-and-feels: When switching the current
  585. * LookAndFeel, only those borders are replaced that are marked as
  586. * {@link UIResource}. For this reason, a look-and-feel should
  587. * always install borders that implement <code>UIResource</code>,
  588. * such as the borders provided by this class.
  589. *
  590. * <p><img src="../border/doc-files/MatteBorder-1.png" width="500"
  591. * height="150" alt="[An illustration of two MatteBorders]" /></p>
  592. *
  593. * @author Brian Jones (cbj@gnu.org)
  594. * @author Sascha Brawer (brawer@dandelis.ch)
  595. */
  596. public static class MatteBorderUIResource
  597. extends MatteBorder
  598. implements UIResource, Serializable
  599. {
  600. private static final long serialVersionUID = -8107923147541851122L;
  601. /**
  602. * Constructs a MatteBorderUIResource given the width on each side
  603. * and a fill color.
  604. *
  605. * <p><img src="../border/doc-files/MatteBorder-2.png" width="500"
  606. * height="150" alt="[A picture of a MatteBorder made by this
  607. * constructor]" /></p>
  608. *
  609. * @param top the width of the border at its top edge.
  610. * @param left the width of the border at its left edge.
  611. * @param bottom the width of the border at its bottom edge.
  612. * @param right the width of the border at its right edge.
  613. * @param color the color for filling the border.
  614. */
  615. public MatteBorderUIResource(int top, int left,
  616. int bottom, int right,
  617. Color color)
  618. {
  619. super(top, left, bottom, right, color);
  620. }
  621. /**
  622. * Constructs a MatteBorderUIResource given the width on each side
  623. * and an icon for tiling the border area.
  624. *
  625. * <p><img src="../border/doc-files/MatteBorder-4.png" width="500"
  626. * height="150" alt="[A picture of a MatteBorder made by this
  627. * constructor]" /></p>
  628. *
  629. * @param top the width of the border at its top edge.
  630. * @param left the width of the border at its left edge.
  631. * @param bottom the width of the border at its bottom edge.
  632. * @param right the width of the border at its right edge.
  633. * @param tileIcon an icon for tiling the border area.
  634. */
  635. public MatteBorderUIResource(int top, int left,
  636. int bottom, int right,
  637. Icon tileIcon)
  638. {
  639. super(top, left, bottom, right, tileIcon);
  640. }
  641. /**
  642. * Constructs a MatteBorderUIResource given an icon for tiling the
  643. * border area. The icon width is used for the border insets at
  644. * the left and right edge, the icon height for the top and bottom
  645. * edge.
  646. *
  647. * <p><img src="../border/doc-files/MatteBorder-6.png" width="500"
  648. * height="150" alt="[A picture of a MatteBorder made by this
  649. * constructor]" /></p>
  650. *
  651. * @param tileIcon an icon for tiling the border area.
  652. */
  653. public MatteBorderUIResource(Icon tileIcon)
  654. {
  655. super(tileIcon);
  656. }
  657. }
  658. /**
  659. * A {@link javax.swing.border.TitledBorder} that also implements the
  660. * {@link UIResource} marker interface. This is useful for
  661. * implementing pluggable look-and-feels: When switching the current
  662. * LookAndFeel, only those borders are replaced that are marked as
  663. * {@link UIResource}. For this reason, a look-and-feel should
  664. * always install borders that implement <code>UIResource</code>,
  665. * such as the borders provided by this class.
  666. *
  667. * @author Brian Jones (cbj@gnu.org)
  668. * @author Sascha Brawer (brawer@dandelis.ch)
  669. */
  670. public static class TitledBorderUIResource
  671. extends TitledBorder
  672. implements UIResource, Serializable
  673. {
  674. private static final long serialVersionUID = 7667113547406407427L;
  675. /**
  676. * Constructs a TitledBorderUIResource given the text of its title.
  677. *
  678. * @param title the title text, or <code>null</code> to use no
  679. * title text.
  680. */
  681. public TitledBorderUIResource(String title)
  682. {
  683. super(title);
  684. }
  685. /**
  686. * Constructs an initially untitled TitledBorderUIResource
  687. * given another border.
  688. *
  689. * @param border the border underneath the title, or
  690. * <code>null</code> to use a default from
  691. * the current look and feel.
  692. */
  693. public TitledBorderUIResource(Border border)
  694. {
  695. super(border);
  696. }
  697. /**
  698. * Constructs a TitledBorder given its border and title text.
  699. *
  700. * @param border the border underneath the title, or
  701. * <code>null</code> to use a default from
  702. * the current look and feel.
  703. *
  704. * @param title the title text, or <code>null</code>
  705. * to use no title text.
  706. */
  707. public TitledBorderUIResource(Border border, String title)
  708. {
  709. super(border, title);
  710. }
  711. /**
  712. * Constructs a TitledBorderUIResource given its border, title
  713. * text, horizontal alignment, and vertical position.
  714. *
  715. * @param border the border underneath the title, or
  716. * <code>null</code> to use a default
  717. * from the current look and feel.
  718. *
  719. * @param title the title text, or <code>null</code>
  720. * to use no title text.
  721. *
  722. * @param titleJustification the horizontal alignment of the title
  723. * text in relation to the border. The value must be one of
  724. * {@link javax.swing.border.TitledBorder#LEFT},
  725. * {@link javax.swing.border.TitledBorder#CENTER},
  726. * {@link javax.swing.border.TitledBorder#RIGHT},
  727. * {@link javax.swing.border.TitledBorder#LEADING},
  728. * {@link javax.swing.border.TitledBorder#TRAILING}, or
  729. * {@link javax.swing.border.TitledBorder#DEFAULT_JUSTIFICATION}.
  730. *
  731. * @param titlePosition the vertical position of the title text
  732. * in relation to the border. The value must be one of
  733. * {@link javax.swing.border.TitledBorder#ABOVE_TOP},
  734. * {@link javax.swing.border.TitledBorder#TOP},
  735. * {@link javax.swing.border.TitledBorder#BELOW_TOP},
  736. * {@link javax.swing.border.TitledBorder#ABOVE_BOTTOM},
  737. * {@link javax.swing.border.TitledBorder#BOTTOM},
  738. * {@link javax.swing.border.TitledBorder#BELOW_BOTTOM},
  739. * or {@link javax.swing.border.TitledBorder#DEFAULT_POSITION}.
  740. *
  741. * @throws IllegalArgumentException if <code>titleJustification</code>
  742. * or <code>titlePosition</code> have an unsupported value.
  743. */
  744. public TitledBorderUIResource(Border border, String title,
  745. int titleJustification,
  746. int titlePosition)
  747. {
  748. super(border, title, titleJustification, titlePosition);
  749. }
  750. /**
  751. * Constructs a TitledBorder given its border, title text,
  752. * horizontal alignment, vertical position, and font.
  753. *
  754. * @param border the border underneath the title, or
  755. * <code>null</code> to use a default
  756. * from the current look and feel.
  757. *
  758. * @param title the title text, or <code>null</code>
  759. * to use no title text.
  760. *
  761. * @param titleJustification the horizontal alignment of the title
  762. * text in relation to the border. The value must be one of
  763. * {@link javax.swing.border.TitledBorder#LEFT},
  764. * {@link javax.swing.border.TitledBorder#CENTER},
  765. * {@link javax.swing.border.TitledBorder#RIGHT},
  766. * {@link javax.swing.border.TitledBorder#LEADING},
  767. * {@link javax.swing.border.TitledBorder#TRAILING}, or
  768. * {@link javax.swing.border.TitledBorder#DEFAULT_JUSTIFICATION}.
  769. *
  770. * @param titlePosition the vertical position of the title text
  771. * in relation to the border. The value must be one of
  772. * {@link javax.swing.border.TitledBorder#ABOVE_TOP},
  773. * {@link javax.swing.border.TitledBorder#TOP},
  774. * {@link javax.swing.border.TitledBorder#BELOW_TOP},
  775. * {@link javax.swing.border.TitledBorder#ABOVE_BOTTOM},
  776. * {@link javax.swing.border.TitledBorder#BOTTOM},
  777. * {@link javax.swing.border.TitledBorder#BELOW_BOTTOM},
  778. * or {@link javax.swing.border.TitledBorder#DEFAULT_POSITION}.
  779. *
  780. * @param titleFont the font for the title text, or <code>null</code>
  781. * to use a default from the current look and feel.
  782. *
  783. * @throws IllegalArgumentException if <code>titleJustification</code>
  784. * or <code>titlePosition</code> have an unsupported value.
  785. */
  786. public TitledBorderUIResource(Border border, String title,
  787. int titleJustification,
  788. int titlePosition,
  789. Font titleFont)
  790. {
  791. super(border, title, titleJustification, titlePosition,
  792. titleFont);
  793. }
  794. /**
  795. * Constructs a TitledBorder given its border, title text,
  796. * horizontal alignment, vertical position, font, and color.
  797. *
  798. * @param border the border underneath the title, or
  799. * <code>null</code> to use a default
  800. * from the current look and feel.
  801. *
  802. * @param title the title text, or <code>null</code>
  803. * to use no title text.
  804. *
  805. * @param titleJustification the horizontal alignment of the title
  806. * text in relation to the border. The value must be one of
  807. * {@link javax.swing.border.TitledBorder#LEFT},
  808. * {@link javax.swing.border.TitledBorder#CENTER},
  809. * {@link javax.swing.border.TitledBorder#RIGHT},
  810. * {@link javax.swing.border.TitledBorder#LEADING},
  811. * {@link javax.swing.border.TitledBorder#TRAILING}, or
  812. * {@link javax.swing.border.TitledBorder#DEFAULT_JUSTIFICATION}.
  813. *
  814. * @param titlePosition the vertical position of the title text
  815. * in relation to the border. The value must be one of
  816. * {@link javax.swing.border.TitledBorder#ABOVE_TOP},
  817. * {@link javax.swing.border.TitledBorder#TOP},
  818. * {@link javax.swing.border.TitledBorder#BELOW_TOP},
  819. * {@link javax.swing.border.TitledBorder#ABOVE_BOTTOM},
  820. * {@link javax.swing.border.TitledBorder#BOTTOM},
  821. * {@link javax.swing.border.TitledBorder#BELOW_BOTTOM},
  822. * or {@link javax.swing.border.TitledBorder#DEFAULT_POSITION}.
  823. *
  824. * @param titleFont the font for the title text, or <code>null</code>
  825. * to use a default from the current look and feel.
  826. *
  827. * @param titleColor the color for the title text, or <code>null</code>
  828. * to use a default from the current look and feel.
  829. *
  830. * @throws IllegalArgumentException if <code>titleJustification</code>
  831. * or <code>titlePosition</code> have an unsupported value.
  832. */
  833. public TitledBorderUIResource(Border border, String title,
  834. int titleJustification, int titlePosition,
  835. Font titleFont, Color titleColor)
  836. {
  837. super(border, title, titleJustification, titlePosition,
  838. titleFont, titleColor);
  839. }
  840. }
  841. }