1. /*
  2. * @(#)MetalIconFactory.java 1.60 04/02/15
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.plaf.metal;
  8. import javax.swing.*;
  9. import javax.swing.plaf.UIResource;
  10. import java.awt.*;
  11. import java.awt.image.BufferedImage;
  12. import java.io.Serializable;
  13. import java.util.Enumeration;
  14. import java.util.Vector;
  15. /**
  16. * Factory object that vends <code>Icon</code>s for
  17. * the Java<sup><font size="-2">TM</font></sup> look and feel (Metal).
  18. * These icons are used extensively in Metal via the defaults mechanism.
  19. * While other look and feels often use GIFs for icons, creating icons
  20. * in code facilitates switching to other themes.
  21. *
  22. * <p>
  23. * Each method in this class returns
  24. * either an <code>Icon</code> or <code>null</code>,
  25. * where <code>null</code> implies that there is no default icon.
  26. *
  27. * <p>
  28. * <strong>Warning:</strong>
  29. * Serialized objects of this class will not be compatible with
  30. * future Swing releases. The current serialization support is
  31. * appropriate for short term storage or RMI between applications running
  32. * the same version of Swing. As of 1.4, support for long term storage
  33. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  34. * has been added to the <code>java.beans</code> package.
  35. * Please see {@link java.beans.XMLEncoder}.
  36. *
  37. * @version 1.60 02/15/04
  38. * @author Michael C. Albers
  39. */
  40. public class MetalIconFactory implements Serializable {
  41. // List of code-drawn Icons
  42. private static Icon fileChooserDetailViewIcon;
  43. private static Icon fileChooserHomeFolderIcon;
  44. private static Icon fileChooserListViewIcon;
  45. private static Icon fileChooserNewFolderIcon;
  46. private static Icon fileChooserUpFolderIcon;
  47. private static Icon internalFrameAltMaximizeIcon;
  48. private static Icon internalFrameCloseIcon;
  49. private static Icon internalFrameDefaultMenuIcon;
  50. private static Icon internalFrameMaximizeIcon;
  51. private static Icon internalFrameMinimizeIcon;
  52. private static Icon radioButtonIcon;
  53. private static Icon treeComputerIcon;
  54. private static Icon treeFloppyDriveIcon;
  55. private static Icon treeHardDriveIcon;
  56. private static Icon menuArrowIcon;
  57. private static Icon menuItemArrowIcon;
  58. private static Icon checkBoxMenuItemIcon;
  59. private static Icon radioButtonMenuItemIcon;
  60. private static Icon checkBoxIcon;
  61. // Ocean icons
  62. private static Icon oceanHorizontalSliderThumb;
  63. private static Icon oceanVerticalSliderThumb;
  64. // Constants
  65. public static final boolean DARK = false;
  66. public static final boolean LIGHT = true;
  67. // Accessor functions for Icons. Does the caching work.
  68. public static Icon getFileChooserDetailViewIcon() {
  69. if (fileChooserDetailViewIcon == null) {
  70. fileChooserDetailViewIcon = new FileChooserDetailViewIcon();
  71. }
  72. return fileChooserDetailViewIcon;
  73. }
  74. public static Icon getFileChooserHomeFolderIcon() {
  75. if (fileChooserHomeFolderIcon == null) {
  76. fileChooserHomeFolderIcon = new FileChooserHomeFolderIcon();
  77. }
  78. return fileChooserHomeFolderIcon;
  79. }
  80. public static Icon getFileChooserListViewIcon() {
  81. if (fileChooserListViewIcon == null) {
  82. fileChooserListViewIcon = new FileChooserListViewIcon();
  83. }
  84. return fileChooserListViewIcon;
  85. }
  86. public static Icon getFileChooserNewFolderIcon() {
  87. if (fileChooserNewFolderIcon == null) {
  88. fileChooserNewFolderIcon = new FileChooserNewFolderIcon();
  89. }
  90. return fileChooserNewFolderIcon;
  91. }
  92. public static Icon getFileChooserUpFolderIcon() {
  93. if (fileChooserUpFolderIcon == null) {
  94. fileChooserUpFolderIcon = new FileChooserUpFolderIcon();
  95. }
  96. return fileChooserUpFolderIcon;
  97. }
  98. public static Icon getInternalFrameAltMaximizeIcon(int size) {
  99. return new InternalFrameAltMaximizeIcon(size);
  100. }
  101. public static Icon getInternalFrameCloseIcon(int size) {
  102. return new InternalFrameCloseIcon(size);
  103. }
  104. public static Icon getInternalFrameDefaultMenuIcon() {
  105. if (internalFrameDefaultMenuIcon == null) {
  106. internalFrameDefaultMenuIcon = new InternalFrameDefaultMenuIcon();
  107. }
  108. return internalFrameDefaultMenuIcon;
  109. }
  110. public static Icon getInternalFrameMaximizeIcon(int size) {
  111. return new InternalFrameMaximizeIcon(size);
  112. }
  113. public static Icon getInternalFrameMinimizeIcon(int size) {
  114. return new InternalFrameMinimizeIcon(size);
  115. }
  116. public static Icon getRadioButtonIcon() {
  117. if (radioButtonIcon == null) {
  118. radioButtonIcon = new RadioButtonIcon();
  119. }
  120. return radioButtonIcon;
  121. }
  122. /**
  123. * Returns a checkbox icon.
  124. * @since 1.3
  125. */
  126. public static Icon getCheckBoxIcon() {
  127. if (checkBoxIcon == null) {
  128. checkBoxIcon = new CheckBoxIcon();
  129. }
  130. return checkBoxIcon;
  131. }
  132. public static Icon getTreeComputerIcon() {
  133. if ( treeComputerIcon == null ) {
  134. treeComputerIcon = new TreeComputerIcon();
  135. }
  136. return treeComputerIcon;
  137. }
  138. public static Icon getTreeFloppyDriveIcon() {
  139. if ( treeFloppyDriveIcon == null ) {
  140. treeFloppyDriveIcon = new TreeFloppyDriveIcon();
  141. }
  142. return treeFloppyDriveIcon;
  143. }
  144. public static Icon getTreeFolderIcon() {
  145. return new TreeFolderIcon();
  146. }
  147. public static Icon getTreeHardDriveIcon() {
  148. if ( treeHardDriveIcon == null ) {
  149. treeHardDriveIcon = new TreeHardDriveIcon();
  150. }
  151. return treeHardDriveIcon;
  152. }
  153. public static Icon getTreeLeafIcon() {
  154. return new TreeLeafIcon();
  155. }
  156. public static Icon getTreeControlIcon( boolean isCollapsed ) {
  157. return new TreeControlIcon( isCollapsed );
  158. }
  159. public static Icon getMenuArrowIcon() {
  160. if (menuArrowIcon == null) {
  161. menuArrowIcon = new MenuArrowIcon();
  162. }
  163. return menuArrowIcon;
  164. }
  165. /**
  166. * Returns an icon to be used by <code>JCheckBoxMenuItem</code>.
  167. *
  168. * @return the default icon for check box menu items,
  169. * or <code>null</code> if no default exists
  170. */
  171. public static Icon getMenuItemCheckIcon() {
  172. return null;
  173. }
  174. public static Icon getMenuItemArrowIcon() {
  175. if (menuItemArrowIcon == null) {
  176. menuItemArrowIcon = new MenuItemArrowIcon();
  177. }
  178. return menuItemArrowIcon;
  179. }
  180. public static Icon getCheckBoxMenuItemIcon() {
  181. if (checkBoxMenuItemIcon == null) {
  182. checkBoxMenuItemIcon = new CheckBoxMenuItemIcon();
  183. }
  184. return checkBoxMenuItemIcon;
  185. }
  186. public static Icon getRadioButtonMenuItemIcon() {
  187. if (radioButtonMenuItemIcon == null) {
  188. radioButtonMenuItemIcon = new RadioButtonMenuItemIcon();
  189. }
  190. return radioButtonMenuItemIcon;
  191. }
  192. public static Icon getHorizontalSliderThumbIcon() {
  193. if (MetalLookAndFeel.usingOcean()) {
  194. if (oceanHorizontalSliderThumb == null) {
  195. oceanHorizontalSliderThumb =
  196. new OceanHorizontalSliderThumbIcon();
  197. }
  198. return oceanHorizontalSliderThumb;
  199. }
  200. // don't cache these, bumps don't get updated otherwise
  201. return new HorizontalSliderThumbIcon();
  202. }
  203. public static Icon getVerticalSliderThumbIcon() {
  204. if (MetalLookAndFeel.usingOcean()) {
  205. if (oceanVerticalSliderThumb == null) {
  206. oceanVerticalSliderThumb = new OceanVerticalSliderThumbIcon();
  207. }
  208. return oceanVerticalSliderThumb;
  209. }
  210. // don't cache these, bumps don't get updated otherwise
  211. return new VerticalSliderThumbIcon();
  212. }
  213. // File Chooser Detail View code
  214. private static class FileChooserDetailViewIcon implements Icon, UIResource, Serializable {
  215. public void paintIcon(Component c, Graphics g, int x, int y) {
  216. g.translate(x, y);
  217. // Draw outside edge of each of the documents
  218. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  219. // top
  220. g.drawLine(2,2, 5,2); // top
  221. g.drawLine(2,3, 2,7); // left
  222. g.drawLine(3,7, 6,7); // bottom
  223. g.drawLine(6,6, 6,3); // right
  224. // bottom
  225. g.drawLine(2,10, 5,10); // top
  226. g.drawLine(2,11, 2,15); // left
  227. g.drawLine(3,15, 6,15); // bottom
  228. g.drawLine(6,14, 6,11); // right
  229. // Draw little dots next to documents
  230. // Same color as outside edge
  231. g.drawLine(8,5, 15,5); // top
  232. g.drawLine(8,13, 15,13); // bottom
  233. // Draw inner highlight on documents
  234. g.setColor(MetalLookAndFeel.getPrimaryControl());
  235. g.drawRect(3,3, 2,3); // top
  236. g.drawRect(3,11, 2,3); // bottom
  237. // Draw inner inner highlight on documents
  238. g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
  239. g.drawLine(4,4, 4,5); // top
  240. g.drawLine(4,12, 4,13); // bottom
  241. g.translate(-x, -y);
  242. }
  243. public int getIconWidth() {
  244. return 18;
  245. }
  246. public int getIconHeight() {
  247. return 18;
  248. }
  249. } // End class FileChooserDetailViewIcon
  250. // File Chooser Home Folder code
  251. private static class FileChooserHomeFolderIcon implements Icon, UIResource, Serializable {
  252. public void paintIcon(Component c, Graphics g, int x, int y) {
  253. g.translate(x, y);
  254. // Draw outside edge of house
  255. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  256. g.drawLine(8,1, 1,8); // left edge of roof
  257. g.drawLine(8,1, 15,8); // right edge of roof
  258. g.drawLine(11,2, 11,3); // left edge of chimney
  259. g.drawLine(12,2, 12,4); // right edge of chimney
  260. g.drawLine(3,7, 3,15); // left edge of house
  261. g.drawLine(13,7, 13,15); // right edge of house
  262. g.drawLine(4,15, 12,15); // bottom edge of house
  263. // Draw door frame
  264. // same color as edge of house
  265. g.drawLine( 6,9, 6,14); // left
  266. g.drawLine(10,9, 10,14); // right
  267. g.drawLine( 7,9, 9, 9); // top
  268. // Draw roof body
  269. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  270. g.fillRect(8,2, 1,1); //top toward bottom
  271. g.fillRect(7,3, 3,1);
  272. g.fillRect(6,4, 5,1);
  273. g.fillRect(5,5, 7,1);
  274. g.fillRect(4,6, 9,2);
  275. // Draw doornob
  276. // same color as roof body
  277. g.drawLine(9,12, 9,12);
  278. // Paint the house
  279. g.setColor(MetalLookAndFeel.getPrimaryControl());
  280. g.drawLine(4,8, 12,8); // above door
  281. g.fillRect(4,9, 2,6); // left of door
  282. g.fillRect(11,9, 2,6); // right of door
  283. g.translate(-x, -y);
  284. }
  285. public int getIconWidth() {
  286. return 18;
  287. }
  288. public int getIconHeight() {
  289. return 18;
  290. }
  291. } // End class FileChooserHomeFolderIcon
  292. // File Chooser List View code
  293. private static class FileChooserListViewIcon implements Icon, UIResource, Serializable {
  294. public void paintIcon(Component c, Graphics g, int x, int y) {
  295. g.translate(x, y);
  296. // Draw outside edge of each of the documents
  297. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  298. // top left
  299. g.drawLine(2,2, 5,2); // top
  300. g.drawLine(2,3, 2,7); // left
  301. g.drawLine(3,7, 6,7); // bottom
  302. g.drawLine(6,6, 6,3); // right
  303. // top right
  304. g.drawLine(10,2, 13,2); // top
  305. g.drawLine(10,3, 10,7); // left
  306. g.drawLine(11,7, 14,7); // bottom
  307. g.drawLine(14,6, 14,3); // right
  308. // bottom left
  309. g.drawLine(2,10, 5,10); // top
  310. g.drawLine(2,11, 2,15); // left
  311. g.drawLine(3,15, 6,15); // bottom
  312. g.drawLine(6,14, 6,11); // right
  313. // bottom right
  314. g.drawLine(10,10, 13,10); // top
  315. g.drawLine(10,11, 10,15); // left
  316. g.drawLine(11,15, 14,15); // bottom
  317. g.drawLine(14,14, 14,11); // right
  318. // Draw little dots next to documents
  319. // Same color as outside edge
  320. g.drawLine(8,5, 8,5); // top left
  321. g.drawLine(16,5, 16,5); // top right
  322. g.drawLine(8,13, 8,13); // bottom left
  323. g.drawLine(16,13, 16,13); // bottom right
  324. // Draw inner highlight on documents
  325. g.setColor(MetalLookAndFeel.getPrimaryControl());
  326. g.drawRect(3,3, 2,3); // top left
  327. g.drawRect(11,3, 2,3); // top right
  328. g.drawRect(3,11, 2,3); // bottom left
  329. g.drawRect(11,11, 2,3); // bottom right
  330. // Draw inner inner highlight on documents
  331. g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
  332. g.drawLine(4,4, 4,5); // top left
  333. g.drawLine(12,4, 12,5); // top right
  334. g.drawLine(4,12, 4,13); // bottom left
  335. g.drawLine(12,12, 12,13); // bottom right
  336. g.translate(-x, -y);
  337. }
  338. public int getIconWidth() {
  339. return 18;
  340. }
  341. public int getIconHeight() {
  342. return 18;
  343. }
  344. } // End class FileChooserListViewIcon
  345. // File Chooser New Folder code
  346. private static class FileChooserNewFolderIcon implements Icon, UIResource, Serializable {
  347. public void paintIcon(Component c, Graphics g, int x, int y) {
  348. g.translate(x, y);
  349. // Fill background
  350. g.setColor(MetalLookAndFeel.getPrimaryControl());
  351. g.fillRect(3,5, 12,9);
  352. // Draw outside edge of folder
  353. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  354. g.drawLine(1,6, 1,14); // left
  355. g.drawLine(2,14, 15,14); // bottom
  356. g.drawLine(15,13, 15,5); // right
  357. g.drawLine(2,5, 9,5); // top left
  358. g.drawLine(10,6, 14,6); // top right
  359. // Draw inner folder highlight
  360. g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
  361. g.drawLine( 2,6, 2,13); // left
  362. g.drawLine( 3,6, 9,6); // top left
  363. g.drawLine(10,7, 14,7); // top right
  364. // Draw tab on folder
  365. g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
  366. g.drawLine(11,3, 15,3); // top
  367. g.drawLine(10,4, 15,4); // bottom
  368. g.translate(-x, -y);
  369. }
  370. public int getIconWidth() {
  371. return 18;
  372. }
  373. public int getIconHeight() {
  374. return 18;
  375. }
  376. } // End class FileChooserNewFolderIcon
  377. // File Chooser Up Folder code
  378. private static class FileChooserUpFolderIcon implements Icon, UIResource, Serializable {
  379. public void paintIcon(Component c, Graphics g, int x, int y) {
  380. g.translate(x, y);
  381. // Fill background
  382. g.setColor(MetalLookAndFeel.getPrimaryControl());
  383. g.fillRect(3,5, 12,9);
  384. // Draw outside edge of folder
  385. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  386. g.drawLine(1,6, 1,14); // left
  387. g.drawLine(2,14, 15,14); // bottom
  388. g.drawLine(15,13, 15,5); // right
  389. g.drawLine(2,5, 9,5); // top left
  390. g.drawLine(10,6, 14,6); // top right
  391. // Draw the UP arrow
  392. // same color as edge
  393. g.drawLine(8,13, 8,16); // arrow shaft
  394. g.drawLine(8, 9, 8, 9); // arrowhead top
  395. g.drawLine(7,10, 9,10);
  396. g.drawLine(6,11, 10,11);
  397. g.drawLine(5,12, 11,12);
  398. // Draw inner folder highlight
  399. g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
  400. g.drawLine( 2,6, 2,13); // left
  401. g.drawLine( 3,6, 9,6); // top left
  402. g.drawLine(10,7, 14,7); // top right
  403. // Draw tab on folder
  404. g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
  405. g.drawLine(11,3, 15,3); // top
  406. g.drawLine(10,4, 15,4); // bottom
  407. g.translate(-x, -y);
  408. }
  409. public int getIconWidth() {
  410. return 18;
  411. }
  412. public int getIconHeight() {
  413. return 18;
  414. }
  415. } // End class FileChooserUpFolderIcon
  416. /**
  417. * Defines an icon for Palette close
  418. * @since 1.3
  419. */
  420. public static class PaletteCloseIcon implements Icon, UIResource, Serializable{
  421. int iconSize = 7;
  422. public void paintIcon(Component c, Graphics g, int x, int y) {
  423. JButton parentButton = (JButton)c;
  424. ButtonModel buttonModel = parentButton.getModel();
  425. Color back;
  426. Color highlight = MetalLookAndFeel.getPrimaryControlHighlight();
  427. Color shadow = MetalLookAndFeel.getPrimaryControlInfo();
  428. if (buttonModel.isPressed() && buttonModel.isArmed()) {
  429. back = shadow;
  430. } else {
  431. back = MetalLookAndFeel.getPrimaryControlDarkShadow();
  432. }
  433. g.translate(x, y);
  434. g.setColor(back);
  435. g.drawLine( 0, 1, 5, 6);
  436. g.drawLine( 1, 0, 6, 5);
  437. g.drawLine( 1, 1, 6, 6);
  438. g.drawLine( 6, 1, 1, 6);
  439. g.drawLine( 5,0, 0,5);
  440. g.drawLine(5,1, 1,5);
  441. g.setColor(highlight);
  442. g.drawLine(6,2, 5,3);
  443. g.drawLine(2,6, 3, 5);
  444. g.drawLine(6,6,6,6);
  445. g.translate(-x, -y);
  446. }
  447. public int getIconWidth() {
  448. return iconSize;
  449. }
  450. public int getIconHeight() {
  451. return iconSize;
  452. }
  453. }
  454. // Internal Frame Close code
  455. private static class InternalFrameCloseIcon implements Icon, UIResource, Serializable {
  456. int iconSize = 16;
  457. public InternalFrameCloseIcon(int size) {
  458. iconSize = size;
  459. }
  460. public void paintIcon(Component c, Graphics g, int x, int y) {
  461. JButton parentButton = (JButton)c;
  462. ButtonModel buttonModel = parentButton.getModel();
  463. Color backgroundColor = MetalLookAndFeel.getPrimaryControl();
  464. Color internalBackgroundColor =
  465. MetalLookAndFeel.getPrimaryControl();
  466. Color mainItemColor =
  467. MetalLookAndFeel.getPrimaryControlDarkShadow();
  468. Color darkHighlightColor = MetalLookAndFeel.getBlack();
  469. Color xLightHighlightColor = MetalLookAndFeel.getWhite();
  470. Color boxLightHighlightColor = MetalLookAndFeel.getWhite();
  471. // if the inactive window
  472. if (parentButton.getClientProperty("paintActive") != Boolean.TRUE)
  473. {
  474. backgroundColor = MetalLookAndFeel.getControl();
  475. internalBackgroundColor = backgroundColor;
  476. mainItemColor = MetalLookAndFeel.getControlDarkShadow();
  477. // if inactive and pressed
  478. if (buttonModel.isPressed() && buttonModel.isArmed()) {
  479. internalBackgroundColor =
  480. MetalLookAndFeel.getControlShadow();
  481. xLightHighlightColor = internalBackgroundColor;
  482. mainItemColor = darkHighlightColor;
  483. }
  484. }
  485. // if pressed
  486. else if (buttonModel.isPressed() && buttonModel.isArmed()) {
  487. internalBackgroundColor =
  488. MetalLookAndFeel.getPrimaryControlShadow();
  489. xLightHighlightColor = internalBackgroundColor;
  490. mainItemColor = darkHighlightColor;
  491. // darkHighlightColor is still "getBlack()"
  492. }
  493. // Some calculations that are needed more than once later on.
  494. int oneHalf = (int)(iconSize / 2); // 16 -> 8
  495. g.translate(x, y);
  496. // fill background
  497. g.setColor(backgroundColor);
  498. g.fillRect(0,0, iconSize,iconSize);
  499. // fill inside of box area
  500. g.setColor(internalBackgroundColor);
  501. g.fillRect(3,3, iconSize-6,iconSize-6);
  502. // THE BOX
  503. // the top/left dark higlight - some of this will get overwritten
  504. g.setColor(darkHighlightColor);
  505. g.drawRect(1,1, iconSize-3,iconSize-3);
  506. // draw the inside bottom/right highlight
  507. g.drawRect(2,2, iconSize-5,iconSize-5);
  508. // draw the light/outside, bottom/right highlight
  509. g.setColor(boxLightHighlightColor);
  510. g.drawRect(2,2, iconSize-3,iconSize-3);
  511. // draw the "normal" box
  512. g.setColor(mainItemColor);
  513. g.drawRect(2,2, iconSize-4,iconSize-4);
  514. g.drawLine(3,iconSize-3, 3,iconSize-3); // lower left
  515. g.drawLine(iconSize-3,3, iconSize-3,3); // up right
  516. // THE "X"
  517. // Dark highlight
  518. g.setColor(darkHighlightColor);
  519. g.drawLine(4,5, 5,4); // far up left
  520. g.drawLine(4,iconSize-6, iconSize-6,4); // against body of "X"
  521. // Light highlight
  522. g.setColor(xLightHighlightColor);
  523. g.drawLine(6,iconSize-5, iconSize-5,6); // against body of "X"
  524. // one pixel over from the body
  525. g.drawLine(oneHalf,oneHalf+2, oneHalf+2,oneHalf);
  526. // bottom right
  527. g.drawLine(iconSize-5,iconSize-5, iconSize-4,iconSize-5);
  528. g.drawLine(iconSize-5,iconSize-4, iconSize-5,iconSize-4);
  529. // Main color
  530. g.setColor(mainItemColor);
  531. // Upper left to lower right
  532. g.drawLine(5,5, iconSize-6,iconSize-6); // g.drawLine(5,5, 10,10);
  533. g.drawLine(6,5, iconSize-5,iconSize-6); // g.drawLine(6,5, 11,10);
  534. g.drawLine(5,6, iconSize-6,iconSize-5); // g.drawLine(5,6, 10,11);
  535. // Lower left to upper right
  536. g.drawLine(5,iconSize-5, iconSize-5,5); // g.drawLine(5,11, 11,5);
  537. g.drawLine(5,iconSize-6, iconSize-6,5); // g.drawLine(5,10, 10,5);
  538. g.translate(-x, -y);
  539. }
  540. public int getIconWidth() {
  541. return iconSize;
  542. }
  543. public int getIconHeight() {
  544. return iconSize;
  545. }
  546. } // End class InternalFrameCloseIcon
  547. // Internal Frame Alternate Maximize code (actually, the un-maximize icon)
  548. private static class InternalFrameAltMaximizeIcon implements Icon, UIResource, Serializable {
  549. int iconSize = 16;
  550. public InternalFrameAltMaximizeIcon(int size) {
  551. iconSize = size;
  552. }
  553. public void paintIcon(Component c, Graphics g, int x, int y) {
  554. JButton parentButton = (JButton)c;
  555. ButtonModel buttonModel = parentButton.getModel();
  556. Color backgroundColor = MetalLookAndFeel.getPrimaryControl();
  557. Color internalBackgroundColor =
  558. MetalLookAndFeel.getPrimaryControl();
  559. Color mainItemColor =
  560. MetalLookAndFeel.getPrimaryControlDarkShadow();
  561. Color darkHighlightColor = MetalLookAndFeel.getBlack();
  562. // ul = Upper Left and lr = Lower Right
  563. Color ulLightHighlightColor = MetalLookAndFeel.getWhite();
  564. Color lrLightHighlightColor = MetalLookAndFeel.getWhite();
  565. // if the internal frame is inactive
  566. if (parentButton.getClientProperty("paintActive") != Boolean.TRUE)
  567. {
  568. backgroundColor = MetalLookAndFeel.getControl();
  569. internalBackgroundColor = backgroundColor;
  570. mainItemColor = MetalLookAndFeel.getControlDarkShadow();
  571. // if inactive and pressed
  572. if (buttonModel.isPressed() && buttonModel.isArmed()) {
  573. internalBackgroundColor =
  574. MetalLookAndFeel.getControlShadow();
  575. ulLightHighlightColor = internalBackgroundColor;
  576. mainItemColor = darkHighlightColor;
  577. }
  578. }
  579. // if the button is pressed and the mouse is over it
  580. else if (buttonModel.isPressed() && buttonModel.isArmed()) {
  581. internalBackgroundColor =
  582. MetalLookAndFeel.getPrimaryControlShadow();
  583. ulLightHighlightColor = internalBackgroundColor;
  584. mainItemColor = darkHighlightColor;
  585. // darkHighlightColor is still "getBlack()"
  586. }
  587. g.translate(x, y);
  588. // fill background
  589. g.setColor(backgroundColor);
  590. g.fillRect(0,0, iconSize,iconSize);
  591. // BOX
  592. // fill inside the box
  593. g.setColor(internalBackgroundColor);
  594. g.fillRect(3,6, iconSize-9,iconSize-9);
  595. // draw dark highlight color
  596. g.setColor(darkHighlightColor);
  597. g.drawRect(1,5, iconSize-8,iconSize-8);
  598. g.drawLine(1,iconSize-2, 1,iconSize-2); // extra pixel on bottom
  599. // draw lower right light highlight
  600. g.setColor(lrLightHighlightColor);
  601. g.drawRect(2,6, iconSize-7,iconSize-7);
  602. // draw upper left light highlight
  603. g.setColor(ulLightHighlightColor);
  604. g.drawRect(3,7, iconSize-9,iconSize-9);
  605. // draw the main box
  606. g.setColor(mainItemColor);
  607. g.drawRect(2,6, iconSize-8,iconSize-8);
  608. // Six extraneous pixels to deal with
  609. g.setColor(ulLightHighlightColor);
  610. g.drawLine(iconSize-6,8,iconSize-6,8);
  611. g.drawLine(iconSize-9,6, iconSize-7,8);
  612. g.setColor(mainItemColor);
  613. g.drawLine(3,iconSize-3,3,iconSize-3);
  614. g.setColor(darkHighlightColor);
  615. g.drawLine(iconSize-6,9,iconSize-6,9);
  616. g.setColor(backgroundColor);
  617. g.drawLine(iconSize-9,5,iconSize-9,5);
  618. // ARROW
  619. // do the shaft first
  620. g.setColor(mainItemColor);
  621. g.fillRect(iconSize-7,3, 3,5); // do a big block
  622. g.drawLine(iconSize-6,5, iconSize-3,2); // top shaft
  623. g.drawLine(iconSize-6,6, iconSize-2,2); // bottom shaft
  624. g.drawLine(iconSize-6,7, iconSize-3,7); // bottom arrow head
  625. // draw the dark highlight
  626. g.setColor(darkHighlightColor);
  627. g.drawLine(iconSize-8,2, iconSize-7,2); // top of arrowhead
  628. g.drawLine(iconSize-8,3, iconSize-8,7); // left of arrowhead
  629. g.drawLine(iconSize-6,4, iconSize-3,1); // top of shaft
  630. g.drawLine(iconSize-4,6, iconSize-3,6); // top,right of arrowhead
  631. // draw the light highlight
  632. g.setColor(lrLightHighlightColor);
  633. g.drawLine(iconSize-6,3, iconSize-6,3); // top
  634. g.drawLine(iconSize-4,5, iconSize-2,3); // under shaft
  635. g.drawLine(iconSize-4,8, iconSize-3,8); // under arrowhead
  636. g.drawLine(iconSize-2,8, iconSize-2,7); // right of arrowhead
  637. g.translate(-x, -y);
  638. }
  639. public int getIconWidth() {
  640. return iconSize;
  641. }
  642. public int getIconHeight() {
  643. return iconSize;
  644. }
  645. } // End class InternalFrameAltMaximizeIcon
  646. // Code for the default icons that goes in the upper left corner
  647. private static class InternalFrameDefaultMenuIcon implements Icon, UIResource, Serializable {
  648. public void paintIcon(Component c, Graphics g, int x, int y) {
  649. Color windowBodyColor = MetalLookAndFeel.getWindowBackground();
  650. Color titleColor = MetalLookAndFeel.getPrimaryControl();
  651. Color edgeColor = MetalLookAndFeel.getPrimaryControlDarkShadow();
  652. g.translate(x, y);
  653. // draw background color for title area
  654. // catch four corners and title area
  655. g.setColor(titleColor);
  656. g.fillRect(0,0, 16,16);
  657. // fill body of window
  658. g.setColor(windowBodyColor);
  659. g.fillRect(2,6, 13,9);
  660. // draw light parts of two "bumps"
  661. g.drawLine(2,2, 2,2);
  662. g.drawLine(5,2, 5,2);
  663. g.drawLine(8,2, 8,2);
  664. g.drawLine(11,2, 11,2);
  665. // draw line around edge of title and icon
  666. g.setColor(edgeColor);
  667. g.drawRect(1,1, 13,13); // entire inner edge
  668. g.drawLine(1,0, 14,0); // top outter edge
  669. g.drawLine(15,1, 15,14); // right outter edge
  670. g.drawLine(1,15, 14,15); // bottom outter edge
  671. g.drawLine(0,1, 0,14); // left outter edge
  672. g.drawLine(2,5, 13,5); // bottom of title bar area
  673. // draw dark part of four "bumps" (same color)
  674. g.drawLine(3,3, 3,3);
  675. g.drawLine(6,3, 6,3);
  676. g.drawLine(9,3, 9,3);
  677. g.drawLine(12,3, 12,3);
  678. g.translate(-x, -y);
  679. }
  680. public int getIconWidth() {
  681. return 16;
  682. }
  683. public int getIconHeight() {
  684. return 16;
  685. }
  686. } // End class InternalFrameDefaultMenuIcon
  687. // Internal Frame Maximize code
  688. private static class InternalFrameMaximizeIcon implements Icon, UIResource, Serializable {
  689. protected int iconSize = 16;
  690. public InternalFrameMaximizeIcon(int size) {
  691. iconSize = size;
  692. }
  693. public void paintIcon(Component c, Graphics g, int x, int y) {
  694. JButton parentButton = (JButton)c;
  695. ButtonModel buttonModel = parentButton.getModel();
  696. Color backgroundColor = MetalLookAndFeel.getPrimaryControl();
  697. Color internalBackgroundColor =
  698. MetalLookAndFeel.getPrimaryControl();
  699. Color mainItemColor =
  700. MetalLookAndFeel.getPrimaryControlDarkShadow();
  701. Color darkHighlightColor = MetalLookAndFeel.getBlack();
  702. // ul = Upper Left and lr = Lower Right
  703. Color ulLightHighlightColor = MetalLookAndFeel.getWhite();
  704. Color lrLightHighlightColor = MetalLookAndFeel.getWhite();
  705. // if the internal frame is inactive
  706. if (parentButton.getClientProperty("paintActive") != Boolean.TRUE)
  707. {
  708. backgroundColor = MetalLookAndFeel.getControl();
  709. internalBackgroundColor = backgroundColor;
  710. mainItemColor = MetalLookAndFeel.getControlDarkShadow();
  711. // if inactive and pressed
  712. if (buttonModel.isPressed() && buttonModel.isArmed()) {
  713. internalBackgroundColor =
  714. MetalLookAndFeel.getControlShadow();
  715. ulLightHighlightColor = internalBackgroundColor;
  716. mainItemColor = darkHighlightColor;
  717. }
  718. }
  719. // if the button is pressed and the mouse is over it
  720. else if (buttonModel.isPressed() && buttonModel.isArmed()) {
  721. internalBackgroundColor =
  722. MetalLookAndFeel.getPrimaryControlShadow();
  723. ulLightHighlightColor = internalBackgroundColor;
  724. mainItemColor = darkHighlightColor;
  725. // darkHighlightColor is still "getBlack()"
  726. }
  727. g.translate(x, y);
  728. // fill background
  729. g.setColor(backgroundColor);
  730. g.fillRect(0,0, iconSize,iconSize);
  731. // BOX drawing
  732. // fill inside the box
  733. g.setColor(internalBackgroundColor);
  734. g.fillRect(3,7, iconSize-10,iconSize-10);
  735. // light highlight
  736. g.setColor(ulLightHighlightColor);
  737. g.drawRect(3,7, iconSize-10,iconSize-10); // up,left
  738. g.setColor(lrLightHighlightColor);
  739. g.drawRect(2,6, iconSize-7,iconSize-7); // low,right
  740. // dark highlight
  741. g.setColor(darkHighlightColor);
  742. g.drawRect(1,5, iconSize-7,iconSize-7); // outer
  743. g.drawRect(2,6, iconSize-9,iconSize-9); // inner
  744. // main box
  745. g.setColor(mainItemColor);
  746. g.drawRect(2,6, iconSize-8,iconSize-8); // g.drawRect(2,6, 8,8);
  747. // ARROW drawing
  748. // dark highlight
  749. g.setColor(darkHighlightColor);
  750. // down,left to up,right - inside box
  751. g.drawLine(3,iconSize-5, iconSize-9,7);
  752. // down,left to up,right - outside box
  753. g.drawLine(iconSize-6,4, iconSize-5,3);
  754. // outside edge of arrow head
  755. g.drawLine(iconSize-7,1, iconSize-7,2);
  756. // outside edge of arrow head
  757. g.drawLine(iconSize-6,1, iconSize-2,1);
  758. // light highlight
  759. g.setColor(ulLightHighlightColor);
  760. // down,left to up,right - inside box
  761. g.drawLine(5,iconSize-4, iconSize-8,9);
  762. g.setColor(lrLightHighlightColor);
  763. g.drawLine(iconSize-6,3, iconSize-4,5); // outside box
  764. g.drawLine(iconSize-4,5, iconSize-4,6); // one down from this
  765. g.drawLine(iconSize-2,7, iconSize-1,7); // outside edge arrow head
  766. g.drawLine(iconSize-1,2, iconSize-1,6); // outside edge arrow head
  767. // main part of arrow
  768. g.setColor(mainItemColor);
  769. g.drawLine(3,iconSize-4, iconSize-3,2); // top edge of staff
  770. g.drawLine(3,iconSize-3, iconSize-2,2); // bottom edge of staff
  771. g.drawLine(4,iconSize-3, 5,iconSize-3); // highlights inside of box
  772. g.drawLine(iconSize-7,8, iconSize-7,9); // highlights inside of box
  773. g.drawLine(iconSize-6,2, iconSize-4,2); // top of arrow head
  774. g.drawRect(iconSize-3,3, 1,3); // right of arrow head
  775. g.translate(-x, -y);
  776. }
  777. public int getIconWidth() {
  778. return iconSize;
  779. }
  780. public int getIconHeight() {
  781. return iconSize;
  782. }
  783. } // End class InternalFrameMaximizeIcon
  784. // Internal Frame Minimize code
  785. private static class InternalFrameMinimizeIcon implements Icon, UIResource, Serializable {
  786. int iconSize = 16;
  787. public InternalFrameMinimizeIcon(int size) {
  788. iconSize = size;
  789. }
  790. public void paintIcon(Component c, Graphics g, int x, int y) {
  791. JButton parentButton = (JButton)c;
  792. ButtonModel buttonModel = parentButton.getModel();
  793. Color backgroundColor = MetalLookAndFeel.getPrimaryControl();
  794. Color internalBackgroundColor =
  795. MetalLookAndFeel.getPrimaryControl();
  796. Color mainItemColor =
  797. MetalLookAndFeel.getPrimaryControlDarkShadow();
  798. Color darkHighlightColor = MetalLookAndFeel.getBlack();
  799. // ul = Upper Left and lr = Lower Right
  800. Color ulLightHighlightColor = MetalLookAndFeel.getWhite();
  801. Color lrLightHighlightColor = MetalLookAndFeel.getWhite();
  802. // if the internal frame is inactive
  803. if (parentButton.getClientProperty("paintActive") != Boolean.TRUE)
  804. {
  805. backgroundColor = MetalLookAndFeel.getControl();
  806. internalBackgroundColor = backgroundColor;
  807. mainItemColor = MetalLookAndFeel.getControlDarkShadow();
  808. // if inactive and pressed
  809. if (buttonModel.isPressed() && buttonModel.isArmed()) {
  810. internalBackgroundColor =
  811. MetalLookAndFeel.getControlShadow();
  812. ulLightHighlightColor = internalBackgroundColor;
  813. mainItemColor = darkHighlightColor;
  814. }
  815. }
  816. // if the button is pressed and the mouse is over it
  817. else if (buttonModel.isPressed() && buttonModel.isArmed()) {
  818. internalBackgroundColor =
  819. MetalLookAndFeel.getPrimaryControlShadow();
  820. ulLightHighlightColor = internalBackgroundColor;
  821. mainItemColor = darkHighlightColor;
  822. // darkHighlightColor is still "getBlack()"
  823. }
  824. g.translate(x, y);
  825. // fill background
  826. g.setColor(backgroundColor);
  827. g.fillRect(0,0, iconSize,iconSize);
  828. // BOX drawing
  829. // fill inside the box
  830. g.setColor(internalBackgroundColor);
  831. g.fillRect(4,11, iconSize-13,iconSize-13);
  832. // light highlight
  833. g.setColor(lrLightHighlightColor);
  834. g.drawRect(2,10, iconSize-10,iconSize-11); // low,right
  835. g.setColor(ulLightHighlightColor);
  836. g.drawRect(3,10, iconSize-12,iconSize-12); // up,left
  837. // dark highlight
  838. g.setColor(darkHighlightColor);
  839. g.drawRect(1,8, iconSize-10,iconSize-10); // outer
  840. g.drawRect(2,9, iconSize-12,iconSize-12); // inner
  841. // main box
  842. g.setColor(mainItemColor);
  843. g.drawRect(2,9, iconSize-11,iconSize-11);
  844. g.drawLine(iconSize-10,10, iconSize-10,10); // up right highlight
  845. g.drawLine(3,iconSize-3, 3,iconSize-3); // low left highlight
  846. // ARROW
  847. // do the shaft first
  848. g.setColor(mainItemColor);
  849. g.fillRect(iconSize-7,3, 3,5); // do a big block
  850. g.drawLine(iconSize-6,5, iconSize-3,2); // top shaft
  851. g.drawLine(iconSize-6,6, iconSize-2,2); // bottom shaft
  852. g.drawLine(iconSize-6,7, iconSize-3,7); // bottom arrow head
  853. // draw the dark highlight
  854. g.setColor(darkHighlightColor);
  855. g.drawLine(iconSize-8,2, iconSize-7,2); // top of arrowhead
  856. g.drawLine(iconSize-8,3, iconSize-8,7); // left of arrowhead
  857. g.drawLine(iconSize-6,4, iconSize-3,1); // top of shaft
  858. g.drawLine(iconSize-4,6, iconSize-3,6); // top,right of arrowhead
  859. // draw the light highlight
  860. g.setColor(lrLightHighlightColor);
  861. g.drawLine(iconSize-6,3, iconSize-6,3); // top
  862. g.drawLine(iconSize-4,5, iconSize-2,3); // under shaft
  863. g.drawLine(iconSize-7,8, iconSize-3,8); // under arrowhead
  864. g.drawLine(iconSize-2,8, iconSize-2,7); // right of arrowhead
  865. g.translate(-x, -y);
  866. }
  867. public int getIconWidth() {
  868. return iconSize;
  869. }
  870. public int getIconHeight() {
  871. return iconSize;
  872. }
  873. } // End class InternalFrameMinimizeIcon
  874. private static class CheckBoxIcon implements Icon, UIResource, Serializable {
  875. protected int getControlSize() { return 13; }
  876. private void paintOceanIcon(Component c, Graphics g, int x, int y) {
  877. ButtonModel model = ((JCheckBox)c).getModel();
  878. g.translate(x, y);
  879. int w = getIconWidth();
  880. int h = getIconHeight();
  881. if ( model.isEnabled() ) {
  882. if (model.isPressed() && model.isArmed()) {
  883. g.setColor(MetalLookAndFeel.getControlShadow());
  884. g.fillRect(0, 0, w, h);
  885. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  886. g.fillRect(0, 0, w, 2);
  887. g.fillRect(0, 2, 2, h - 2);
  888. g.fillRect(w - 1, 1, 1, h - 1);
  889. g.fillRect(1, h - 1, w - 2, 1);
  890. } else if (model.isRollover()) {
  891. MetalUtils.drawGradient(c, g, "CheckBox.gradient", 0, 0,
  892. w, h, true);
  893. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  894. g.drawRect(0, 0, w - 1, h - 1);
  895. g.setColor(MetalLookAndFeel.getPrimaryControl());
  896. g.drawRect(1, 1, w - 3, h - 3);
  897. g.drawRect(2, 2, w - 5, h - 5);
  898. }
  899. else {
  900. MetalUtils.drawGradient(c, g, "CheckBox.gradient", 0, 0,
  901. w, h, true);
  902. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  903. g.drawRect(0, 0, w - 1, h - 1);
  904. }
  905. g.setColor( MetalLookAndFeel.getControlInfo() );
  906. } else {
  907. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  908. g.drawRect(0, 0, w - 1, h - 1);
  909. }
  910. g.translate(-x, -y);
  911. if (model.isSelected()) {
  912. drawCheck(c,g,x,y);
  913. }
  914. }
  915. public void paintIcon(Component c, Graphics g, int x, int y) {
  916. if (MetalLookAndFeel.usingOcean()) {
  917. paintOceanIcon(c, g, x, y);
  918. return;
  919. }
  920. ButtonModel model = ((JCheckBox)c).getModel();
  921. int controlSize = getControlSize();
  922. if ( model.isEnabled() ) {
  923. if (model.isPressed() && model.isArmed()) {
  924. g.setColor( MetalLookAndFeel.getControlShadow() );
  925. g.fillRect( x, y, controlSize-1, controlSize-1);
  926. MetalUtils.drawPressed3DBorder(g, x, y, controlSize, controlSize);
  927. } else {
  928. MetalUtils.drawFlush3DBorder(g, x, y, controlSize, controlSize);
  929. }
  930. g.setColor( MetalLookAndFeel.getControlInfo() );
  931. } else {
  932. g.setColor( MetalLookAndFeel.getControlShadow() );
  933. g.drawRect( x, y, controlSize-2, controlSize-2);
  934. }
  935. if (model.isSelected()) {
  936. drawCheck(c,g,x,y);
  937. }
  938. }
  939. protected void drawCheck(Component c, Graphics g, int x, int y) {
  940. int controlSize = getControlSize();
  941. g.fillRect( x+3, y+5, 2, controlSize-8 );
  942. g.drawLine( x+(controlSize-4), y+3, x+5, y+(controlSize-6) );
  943. g.drawLine( x+(controlSize-4), y+4, x+5, y+(controlSize-5) );
  944. }
  945. public int getIconWidth() {
  946. return getControlSize();
  947. }
  948. public int getIconHeight() {
  949. return getControlSize();
  950. }
  951. } // End class CheckBoxIcon
  952. // Radio button code
  953. private static class RadioButtonIcon implements Icon, UIResource, Serializable {
  954. public void paintOceanIcon(Component c, Graphics g, int x, int y) {
  955. ButtonModel model = ((JRadioButton)c).getModel();
  956. boolean enabled = model.isEnabled();
  957. boolean pressed = (enabled && model.isPressed() &&
  958. model.isArmed());
  959. boolean rollover = (enabled && model.isRollover());
  960. g.translate(x, y);
  961. if (enabled && !pressed) {
  962. // PENDING: this isn't quite right, when we're sure it won't
  963. // change it needs to be cleaned.
  964. MetalUtils.drawGradient(c, g, "RadioButton.gradient",
  965. 1, 1, 10, 10, true);
  966. g.setColor(c.getBackground());
  967. g.fillRect(1, 1, 1, 1);
  968. g.fillRect(10, 1, 1, 1);
  969. g.fillRect(1, 10, 1, 1);
  970. g.fillRect(10, 10, 1, 1);
  971. }
  972. else if (pressed || !enabled) {
  973. if (pressed) {
  974. g.setColor(MetalLookAndFeel.getPrimaryControl());
  975. }
  976. else {
  977. g.setColor(MetalLookAndFeel.getControl());
  978. }
  979. g.fillRect(2, 2, 8, 8);
  980. g.fillRect(4, 1, 4, 1);
  981. g.fillRect(4, 10, 4, 1);
  982. g.fillRect(1, 4, 1, 4);
  983. g.fillRect(10, 4, 1, 4);
  984. }
  985. // draw Dark Circle (start at top, go clockwise)
  986. if (!enabled) {
  987. g.setColor(MetalLookAndFeel.getInactiveControlTextColor());
  988. }
  989. else {
  990. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  991. }
  992. g.drawLine( 4, 0, 7, 0);
  993. g.drawLine( 8, 1, 9, 1);
  994. g.drawLine(10, 2, 10, 3);
  995. g.drawLine(11, 4, 11, 7);
  996. g.drawLine(10, 8, 10, 9);
  997. g.drawLine( 9,10, 8,10);
  998. g.drawLine( 7,11, 4,11);
  999. g.drawLine( 3,10, 2,10);
  1000. g.drawLine( 1, 9, 1, 8);
  1001. g.drawLine( 0, 7, 0, 4);
  1002. g.drawLine( 1, 3, 1, 2);
  1003. g.drawLine( 2, 1, 3, 1);
  1004. if (pressed) {
  1005. g.fillRect(1, 4, 1, 4);
  1006. g.fillRect(2, 2, 1, 2);
  1007. g.fillRect(3, 2, 1, 1);
  1008. g.fillRect(4, 1, 4, 1);
  1009. }
  1010. else if (rollover) {
  1011. g.setColor(MetalLookAndFeel.getPrimaryControl());
  1012. g.fillRect(4, 1, 4, 2);
  1013. g.fillRect(8, 2, 2, 2);
  1014. g.fillRect(9, 4, 2, 4);
  1015. g.fillRect(8, 8, 2, 2);
  1016. g.fillRect(4, 9, 4, 2);
  1017. g.fillRect(2, 8, 2, 2);
  1018. g.fillRect(1, 4, 2, 4);
  1019. g.fillRect(2, 2, 2, 2);
  1020. }
  1021. // selected dot
  1022. if (model.isSelected()) {
  1023. if (enabled) {
  1024. g.setColor(c.getForeground());
  1025. } else {
  1026. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  1027. }
  1028. g.fillRect(4, 4, 4, 4);
  1029. g.drawLine(4, 3, 7, 3);
  1030. g.drawLine(8, 4, 8, 7);
  1031. g.drawLine(7, 8, 4, 8);
  1032. g.drawLine(3, 7, 3, 4);
  1033. }
  1034. g.translate(-x, -y);
  1035. }
  1036. public void paintIcon(Component c, Graphics g, int x, int y) {
  1037. if (MetalLookAndFeel.usingOcean()) {
  1038. paintOceanIcon(c, g, x, y);
  1039. return;
  1040. }
  1041. JRadioButton rb = (JRadioButton)c;
  1042. ButtonModel model = rb.getModel();
  1043. boolean drawDot = model.isSelected();
  1044. Color background = c.getBackground();
  1045. Color dotColor = c.getForeground();
  1046. Color shadow = MetalLookAndFeel.getControlShadow();
  1047. Color darkCircle = MetalLookAndFeel.getControlDarkShadow();
  1048. Color whiteInnerLeftArc = MetalLookAndFeel.getControlHighlight();
  1049. Color whiteOuterRightArc = MetalLookAndFeel.getControlHighlight();
  1050. Color interiorColor = background;
  1051. // Set up colors per RadioButtonModel condition
  1052. if ( !model.isEnabled() ) {
  1053. whiteInnerLeftArc = whiteOuterRightArc = background;
  1054. darkCircle = dotColor = shadow;
  1055. }
  1056. else if (model.isPressed() && model.isArmed() ) {
  1057. whiteInnerLeftArc = interiorColor = shadow;
  1058. }
  1059. g.translate(x, y);
  1060. // fill interior
  1061. g.setColor(interiorColor);
  1062. g.fillRect(2,2, 9,9);
  1063. // draw Dark Circle (start at top, go clockwise)
  1064. g.setColor(darkCircle);
  1065. g.drawLine( 4, 0, 7, 0);
  1066. g.drawLine( 8, 1, 9, 1);
  1067. g.drawLine(10, 2, 10, 3);
  1068. g.drawLine(11, 4, 11, 7);
  1069. g.drawLine(10, 8, 10, 9);
  1070. g.drawLine( 9,10, 8,10);
  1071. g.drawLine( 7,11, 4,11);
  1072. g.drawLine( 3,10, 2,10);
  1073. g.drawLine( 1, 9, 1, 8);
  1074. g.drawLine( 0, 7, 0, 4);
  1075. g.drawLine( 1, 3, 1, 2);
  1076. g.drawLine( 2, 1, 3, 1);
  1077. // draw Inner Left (usually) White Arc
  1078. // start at lower left corner, go clockwise
  1079. g.setColor(whiteInnerLeftArc);
  1080. g.drawLine( 2, 9, 2, 8);
  1081. g.drawLine( 1, 7, 1, 4);
  1082. g.drawLine( 2, 2, 2, 3);
  1083. g.drawLine( 2, 2, 3, 2);
  1084. g.drawLine( 4, 1, 7, 1);
  1085. g.drawLine( 8, 2, 9, 2);
  1086. // draw Outer Right White Arc
  1087. // start at upper right corner, go clockwise
  1088. g.setColor(whiteOuterRightArc);
  1089. g.drawLine(10, 1, 10, 1);
  1090. g.drawLine(11, 2, 11, 3);
  1091. g.drawLine(12, 4, 12, 7);
  1092. g.drawLine(11, 8, 11, 9);
  1093. g.drawLine(10,10, 10,10);
  1094. g.drawLine( 9,11, 8,11);
  1095. g.drawLine( 7,12, 4,12);
  1096. g.drawLine( 3,11, 2,11);
  1097. // selected dot
  1098. if ( drawDot ) {
  1099. g.setColor(dotColor);
  1100. g.fillRect( 4, 4, 4, 4);
  1101. g.drawLine( 4, 3, 7, 3);
  1102. g.drawLine( 8, 4, 8, 7);
  1103. g.drawLine( 7, 8, 4, 8);
  1104. g.drawLine( 3, 7, 3, 4);
  1105. }
  1106. g.translate(-x, -y);
  1107. }
  1108. public int getIconWidth() {
  1109. return 13;
  1110. }
  1111. public int getIconHeight() {
  1112. return 13;
  1113. }
  1114. } // End class RadioButtonIcon
  1115. // Tree Computer Icon code
  1116. private static class TreeComputerIcon implements Icon, UIResource, Serializable {
  1117. public void paintIcon(Component c, Graphics g, int x, int y) {
  1118. g.translate(x, y);
  1119. // Fill glass portion of monitor
  1120. g.setColor(MetalLookAndFeel.getPrimaryControl());
  1121. g.fillRect(5,4, 6,4);
  1122. // Draw outside edge of monitor
  1123. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  1124. g.drawLine( 2,2, 2,8); // left
  1125. g.drawLine(13,2, 13,8); // right
  1126. g.drawLine( 3,1, 12,1); // top
  1127. g.drawLine(12,9, 12,9); // bottom right base
  1128. g.drawLine( 3,9, 3,9); // bottom left base
  1129. // Draw the edge of the glass
  1130. g.drawLine( 4,4, 4,7); // left
  1131. g.drawLine( 5,3, 10,3); // top
  1132. g.drawLine(11,4, 11,7); // right
  1133. g.drawLine( 5,8, 10,8); // bottom
  1134. // Draw the edge of the CPU
  1135. g.drawLine( 1,10, 14,10); // top
  1136. g.drawLine(14,10, 14,14); // right
  1137. g.drawLine( 1,14, 14,14); // bottom
  1138. g.drawLine( 1,10, 1,14); // left
  1139. // Draw the disk drives
  1140. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  1141. g.drawLine( 6,12, 8,12); // left
  1142. g.drawLine(10,12, 12,12); // right
  1143. g.translate(-x, -y);
  1144. }
  1145. public int getIconWidth() {
  1146. return 16;
  1147. }
  1148. public int getIconHeight() {
  1149. return 16;
  1150. }
  1151. } // End class TreeComputerIcon
  1152. // Tree HardDrive Icon code
  1153. private static class TreeHardDriveIcon implements Icon, UIResource, Serializable {
  1154. public void paintIcon(Component c, Graphics g, int x, int y) {
  1155. g.translate(x, y);
  1156. // Draw edges of the disks
  1157. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  1158. // top disk
  1159. g.drawLine(1,4, 1,5); // left
  1160. g.drawLine(2,3, 3,3);
  1161. g.drawLine(4,2, 11,2); // top
  1162. g.drawLine(12,3, 13,3);
  1163. g.drawLine(14,4, 14,5); // right
  1164. g.drawLine(12,6, 13,6);
  1165. g.drawLine(4,7, 11,7); // bottom
  1166. g.drawLine(2,6, 3,6);
  1167. // middle disk
  1168. g.drawLine(1,7, 1,8); // left
  1169. g.drawLine(2,9, 3,9);
  1170. g.drawLine(4,10, 11,10); // bottom
  1171. g.drawLine(12,9, 13,9);
  1172. g.drawLine(14,7, 14, 8); // right
  1173. // bottom disk
  1174. g.drawLine(1,10, 1,11); // left
  1175. g.drawLine(2,12, 3,12);
  1176. g.drawLine(4,13, 11,13); // bottom
  1177. g.drawLine(12,12, 13,12);
  1178. g.drawLine(14,10, 14,11); // right
  1179. // Draw the down right shadows
  1180. g.setColor(MetalLookAndFeel.getControlShadow());
  1181. // top disk
  1182. g.drawLine(7,6, 7,6);
  1183. g.drawLine(9,6, 9,6);
  1184. g.drawLine(10,5, 10,5);
  1185. g.drawLine(11,6, 11,6);
  1186. g.drawLine(12,5, 13,5);
  1187. g.drawLine(13,4, 13,4);
  1188. // middle disk
  1189. g.drawLine(7,9, 7,9);
  1190. g.drawLine(9,9, 9,9);
  1191. g.drawLine(10,8, 10,8);
  1192. g.drawLine(11,9, 11,9);
  1193. g.drawLine(12,8, 13,8);
  1194. g.drawLine(13,7, 13,7);
  1195. // bottom disk
  1196. g.drawLine(7,12, 7,12);
  1197. g.drawLine(9,12, 9,12);
  1198. g.drawLine(10,11, 10,11);
  1199. g.drawLine(11,12, 11,12);
  1200. g.drawLine(12,11, 13,11);
  1201. g.drawLine(13,10, 13,10);
  1202. // Draw the up left highlight
  1203. g.setColor(MetalLookAndFeel.getControlHighlight());
  1204. // top disk
  1205. g.drawLine(4,3, 5,3);
  1206. g.drawLine(7,3, 9,3);
  1207. g.drawLine(11,3, 11,3);
  1208. g.drawLine(2,4, 6,4);
  1209. g.drawLine(8,4, 8,4);
  1210. g.drawLine(2,5, 3,5);
  1211. g.drawLine(4,6, 4,6);
  1212. // middle disk
  1213. g.drawLine(2,7, 3,7);
  1214. g.drawLine(2,8, 3,8);
  1215. g.drawLine(4,9, 4,9);
  1216. // bottom disk
  1217. g.drawLine(2,10, 3,10);
  1218. g.drawLine(2,11, 3,11);
  1219. g.drawLine(4,12, 4,12);
  1220. g.translate(-x, -y);
  1221. }
  1222. public int getIconWidth() {
  1223. return 16;
  1224. }
  1225. public int getIconHeight() {
  1226. return 16;
  1227. }
  1228. } // End class TreeHardDriveIcon
  1229. // Tree FloppyDrive Icon code
  1230. private static class TreeFloppyDriveIcon implements Icon, UIResource, Serializable {
  1231. public void paintIcon(Component c, Graphics g, int x, int y) {
  1232. g.translate(x, y);
  1233. // Fill body of floppy
  1234. g.setColor(MetalLookAndFeel.getPrimaryControl());
  1235. g.fillRect(2,2, 12,12);
  1236. // Draw outside edge of floppy
  1237. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  1238. g.drawLine( 1, 1, 13, 1); // top
  1239. g.drawLine(14, 2, 14,14); // right
  1240. g.drawLine( 1,14, 14,14); // bottom
  1241. g.drawLine( 1, 1, 1,14); // left
  1242. // Draw grey-ish highlights
  1243. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  1244. g.fillRect(5,2, 6,5); // metal disk protector part
  1245. g.drawLine(4,8, 11,8); // top of label
  1246. g.drawLine(3,9, 3,13); // left of label
  1247. g.drawLine(12,9, 12,13); // right of label
  1248. // Draw label and exposed disk
  1249. g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
  1250. g.fillRect(8,3, 2,3); // exposed disk
  1251. g.fillRect(4,9, 8,5); // label
  1252. // Draw text on label
  1253. g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
  1254. g.drawLine(5,10, 9,10);
  1255. g.drawLine(5,12, 8,12);
  1256. g.translate(-x, -y);
  1257. }
  1258. public int getIconWidth() {
  1259. return 16;
  1260. }
  1261. public int getIconHeight() {
  1262. return 16;
  1263. }
  1264. } // End class TreeFloppyDriveIcon
  1265. static private final Dimension folderIcon16Size = new Dimension( 16, 16 );
  1266. /**
  1267. * Utility class for caching icon images. This is necessary because
  1268. * we need a new image whenever we are rendering into a new
  1269. * GraphicsConfiguration, but we do not want to keep recreating icon
  1270. * images for GC's that we have already seen (for example,
  1271. * dragging a window back and forth between monitors on a multimon
  1272. * system, or drawing an icon to different Components that have different
  1273. * GC's).
  1274. * So now whenever we create a new icon image for a given GC, we
  1275. * cache that image with the GC for later retrieval.
  1276. */
  1277. static class ImageCacher {
  1278. // PENDING: Replace this class with CachedPainter.
  1279. Vector images = new Vector(1, 1);
  1280. ImageGcPair currentImageGcPair;
  1281. class ImageGcPair {
  1282. Image image;
  1283. GraphicsConfiguration gc;
  1284. ImageGcPair(Image image, GraphicsConfiguration gc) {
  1285. this.image = image;
  1286. this.gc = gc;
  1287. }
  1288. boolean hasSameConfiguration(GraphicsConfiguration newGC) {
  1289. if (((newGC != null) && (newGC.equals(gc))) ||
  1290. ((newGC == null) && (gc == null)))
  1291. {
  1292. return true;
  1293. }
  1294. return false;
  1295. }
  1296. }
  1297. Image getImage(GraphicsConfiguration newGC) {
  1298. if ((currentImageGcPair == null) ||
  1299. !(currentImageGcPair.hasSameConfiguration(newGC)))
  1300. {
  1301. Enumeration elements = images.elements();
  1302. while (elements.hasMoreElements()) {
  1303. ImageGcPair imgGcPair = (ImageGcPair)elements.nextElement();
  1304. if (imgGcPair.hasSameConfiguration(newGC)) {
  1305. currentImageGcPair = imgGcPair;
  1306. return imgGcPair.image;
  1307. }
  1308. }
  1309. return null;
  1310. }
  1311. return currentImageGcPair.image;
  1312. }
  1313. void cacheImage(Image image, GraphicsConfiguration gc) {
  1314. ImageGcPair imgGcPair = new ImageGcPair(image, gc);
  1315. images.addElement(imgGcPair);
  1316. currentImageGcPair = imgGcPair;
  1317. }
  1318. }
  1319. /**
  1320. * <p>
  1321. * <strong>Warning:</strong>
  1322. * Serialized objects of this class will not be compatible with
  1323. * future Swing releases. The current serialization support is
  1324. * appropriate for short term storage or RMI between applications running
  1325. * the same version of Swing. As of 1.4, support for long term storage
  1326. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  1327. * has been added to the <code>java.beans</code> package.
  1328. * Please see {@link java.beans.XMLEncoder}.
  1329. */
  1330. public static class FolderIcon16 implements Icon, Serializable {
  1331. ImageCacher imageCacher;
  1332. public void paintIcon(Component c, Graphics g, int x, int y) {
  1333. GraphicsConfiguration gc = c.getGraphicsConfiguration();
  1334. if (imageCacher == null) {
  1335. imageCacher = new ImageCacher();
  1336. }
  1337. Image image = imageCacher.getImage(gc);
  1338. if (image == null) {
  1339. if (gc != null) {
  1340. image = gc.createCompatibleImage(getIconWidth(),
  1341. getIconHeight(),
  1342. Transparency.BITMASK);
  1343. } else {
  1344. image = new BufferedImage(getIconWidth(),
  1345. getIconHeight(),
  1346. BufferedImage.TYPE_INT_ARGB);
  1347. }
  1348. Graphics imageG = image.getGraphics();
  1349. paintMe(c,imageG);
  1350. imageG.dispose();
  1351. imageCacher.cacheImage(image, gc);
  1352. }
  1353. g.drawImage(image, x, y+getShift(), null);
  1354. }
  1355. private void paintMe(Component c, Graphics g) {
  1356. int right = folderIcon16Size.width - 1;
  1357. int bottom = folderIcon16Size.height - 1;
  1358. // Draw tab top
  1359. g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
  1360. g.drawLine( right - 5, 3, right, 3 );
  1361. g.drawLine( right - 6, 4, right, 4 );
  1362. // Draw folder front
  1363. g.setColor( MetalLookAndFeel.getPrimaryControl() );
  1364. g.fillRect( 2, 7, 13, 8 );
  1365. // Draw tab bottom
  1366. g.setColor( MetalLookAndFeel.getPrimaryControlShadow() );
  1367. g.drawLine( right - 6, 5, right - 1, 5 );
  1368. // Draw outline
  1369. g.setColor( MetalLookAndFeel.getPrimaryControlInfo() );
  1370. g.drawLine( 0, 6, 0, bottom ); // left side
  1371. g.drawLine( 1, 5, right - 7, 5 ); // first part of top
  1372. g.drawLine( right - 6, 6, right - 1, 6 ); // second part of top
  1373. g.drawLine( right, 5, right, bottom ); // right side
  1374. g.drawLine( 0, bottom, right, bottom ); // bottom
  1375. // Draw highlight
  1376. g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
  1377. g.drawLine( 1, 6, 1, bottom - 1 );
  1378. g.drawLine( 1, 6, right - 7, 6 );
  1379. g.drawLine( right - 6, 7, right - 1, 7 );
  1380. }
  1381. public int getShift() { return 0; }
  1382. public int getAdditionalHeight() { return 0; }
  1383. public int getIconWidth() { return folderIcon16Size.width; }
  1384. public int getIconHeight() { return folderIcon16Size.height + getAdditionalHeight(); }
  1385. }
  1386. /**
  1387. * <p>
  1388. * <strong>Warning:</strong>
  1389. * Serialized objects of this class will not be compatible with
  1390. * future Swing releases. The current serialization support is
  1391. * appropriate for short term storage or RMI between applications running
  1392. * the same version of Swing. As of 1.4, support for long term storage
  1393. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  1394. * has been added to the <code>java.beans</code> package.
  1395. * Please see {@link java.beans.XMLEncoder}.
  1396. */
  1397. public static class TreeFolderIcon extends FolderIcon16 {
  1398. public int getShift() { return -1; }
  1399. public int getAdditionalHeight() { return 2; }
  1400. }
  1401. static private final Dimension fileIcon16Size = new Dimension( 16, 16 );
  1402. /**
  1403. * <p>
  1404. * <strong>Warning:</strong>
  1405. * Serialized objects of this class will not be compatible with
  1406. * future Swing releases. The current serialization support is
  1407. * appropriate for short term storage or RMI between applications running
  1408. * the same version of Swing. As of 1.4, support for long term storage
  1409. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  1410. * has been added to the <code>java.beans</code> package.
  1411. * Please see {@link java.beans.XMLEncoder}.
  1412. */
  1413. public static class FileIcon16 implements Icon, Serializable {
  1414. ImageCacher imageCacher;
  1415. public void paintIcon(Component c, Graphics g, int x, int y) {
  1416. GraphicsConfiguration gc = c.getGraphicsConfiguration();
  1417. if (imageCacher == null) {
  1418. imageCacher = new ImageCacher();
  1419. }
  1420. Image image = imageCacher.getImage(gc);
  1421. if (image == null) {
  1422. if (gc != null) {
  1423. image = gc.createCompatibleImage(getIconWidth(),
  1424. getIconHeight(),
  1425. Transparency.BITMASK);
  1426. } else {
  1427. image = new BufferedImage(getIconWidth(),
  1428. getIconHeight(),
  1429. BufferedImage.TYPE_INT_ARGB);
  1430. }
  1431. Graphics imageG = image.getGraphics();
  1432. paintMe(c,imageG);
  1433. imageG.dispose();
  1434. imageCacher.cacheImage(image, gc);
  1435. }
  1436. g.drawImage(image, x, y+getShift(), null);
  1437. }
  1438. private void paintMe(Component c, Graphics g) {
  1439. int right = fileIcon16Size.width - 1;
  1440. int bottom = fileIcon16Size.height - 1;
  1441. // Draw fill
  1442. g.setColor( MetalLookAndFeel.getWindowBackground() );
  1443. g.fillRect( 4, 2, 9, 12 );
  1444. // Draw frame
  1445. g.setColor( MetalLookAndFeel.getPrimaryControlInfo() );
  1446. g.drawLine( 2, 0, 2, bottom ); // left
  1447. g.drawLine( 2, 0, right - 4, 0 ); // top
  1448. g.drawLine( 2, bottom, right - 1, bottom ); // bottom
  1449. g.drawLine( right - 1, 6, right - 1, bottom ); // right
  1450. g.drawLine( right - 6, 2, right - 2, 6 ); // slant 1
  1451. g.drawLine( right - 5, 1, right - 4, 1 ); // part of slant 2
  1452. g.drawLine( right - 3, 2, right - 3, 3 ); // part of slant 2
  1453. g.drawLine( right - 2, 4, right - 2, 5 ); // part of slant 2
  1454. // Draw highlight
  1455. g.setColor( MetalLookAndFeel.getPrimaryControl() );
  1456. g.drawLine( 3, 1, 3, bottom - 1 ); // left
  1457. g.drawLine( 3, 1, right - 6, 1 ); // top
  1458. g.drawLine( right - 2, 7, right - 2, bottom - 1 ); // right
  1459. g.drawLine( right - 5, 2, right - 3, 4 ); // slant
  1460. g.drawLine( 3, bottom - 1, right - 2, bottom - 1 ); // bottom
  1461. }
  1462. public int getShift() { return 0; }
  1463. public int getAdditionalHeight() { return 0; }
  1464. public int getIconWidth() { return fileIcon16Size.width; }
  1465. public int getIconHeight() { return fileIcon16Size.height + getAdditionalHeight(); }
  1466. }
  1467. public static class TreeLeafIcon extends FileIcon16 {
  1468. public int getShift() { return 2; }
  1469. public int getAdditionalHeight() { return 4; }
  1470. }
  1471. static private final Dimension treeControlSize = new Dimension( 18, 18 );
  1472. /**
  1473. * <p>
  1474. * <strong>Warning:</strong>
  1475. * Serialized objects of this class will not be compatible with
  1476. * future Swing releases. The current serialization support is
  1477. * appropriate for short term storage or RMI between applications running
  1478. * the same version of Swing. As of 1.4, support for long term storage
  1479. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  1480. * has been added to the <code>java.beans</code> package.
  1481. * Please see {@link java.beans.XMLEncoder}.
  1482. */
  1483. public static class TreeControlIcon implements Icon, Serializable {
  1484. // This data member should not have been exposed. It's called
  1485. // isLight, but now it really means isCollapsed. Since we can't change
  1486. // any APIs... that's life.
  1487. protected boolean isLight;
  1488. public TreeControlIcon( boolean isCollapsed ) {
  1489. isLight = isCollapsed;
  1490. }
  1491. ImageCacher imageCacher;
  1492. transient boolean cachedOrientation = true;
  1493. public void paintIcon(Component c, Graphics g, int x, int y) {
  1494. GraphicsConfiguration gc = c.getGraphicsConfiguration();
  1495. if (imageCacher == null) {
  1496. imageCacher = new ImageCacher();
  1497. }
  1498. Image image = imageCacher.getImage(gc);
  1499. if (image == null || cachedOrientation != MetalUtils.isLeftToRight(c)) {
  1500. cachedOrientation = MetalUtils.isLeftToRight(c);
  1501. if (gc != null) {
  1502. image = gc.createCompatibleImage(getIconWidth(),
  1503. getIconHeight(),
  1504. Transparency.BITMASK);
  1505. } else {
  1506. image = new BufferedImage(getIconWidth(),
  1507. getIconHeight(),
  1508. BufferedImage.TYPE_INT_ARGB);
  1509. }
  1510. Graphics imageG = image.getGraphics();
  1511. paintMe(c,imageG,x,y);
  1512. imageG.dispose();
  1513. imageCacher.cacheImage(image, gc);
  1514. }
  1515. if (MetalUtils.isLeftToRight(c)) {
  1516. if (isLight) { // isCollapsed
  1517. g.drawImage(image, x+5, y+3, x+18, y+13,
  1518. 4,3, 17, 13, null);
  1519. }
  1520. else {
  1521. g.drawImage(image, x+5, y+3, x+18, y+17,
  1522. 4,3, 17, 17, null);
  1523. }
  1524. }
  1525. else {
  1526. if (isLight) { // isCollapsed
  1527. g.drawImage(image, x+3, y+3, x+16, y+13,
  1528. 4, 3, 17, 13, null);
  1529. }
  1530. else {
  1531. g.drawImage(image, x+3, y+3, x+16, y+17,
  1532. 4, 3, 17, 17, null);
  1533. }
  1534. }
  1535. }
  1536. public void paintMe(Component c, Graphics g, int x, int y) {
  1537. g.setColor( MetalLookAndFeel.getPrimaryControlInfo() );
  1538. int xoff = (MetalUtils.isLeftToRight(c)) ? 0 : 4;
  1539. // Draw circle
  1540. g.drawLine( xoff + 4, 6, xoff + 4, 9 ); // left
  1541. g.drawLine( xoff + 5, 5, xoff + 5, 5 ); // top left dot
  1542. g.drawLine( xoff + 6, 4, xoff + 9, 4 ); // top
  1543. g.drawLine( xoff + 10, 5, xoff + 10, 5 ); // top right dot
  1544. g.drawLine( xoff + 11, 6, xoff + 11, 9 ); // right
  1545. g.drawLine( xoff + 10, 10, xoff + 10, 10 ); // botom right dot
  1546. g.drawLine( xoff + 6, 11, xoff + 9, 11 ); // bottom
  1547. g.drawLine( xoff + 5, 10, xoff + 5, 10 ); // bottom left dot
  1548. // Draw Center Dot
  1549. g.drawLine( xoff + 7, 7, xoff + 8, 7 );
  1550. g.drawLine( xoff + 7, 8, xoff + 8, 8 );
  1551. // Draw Handle
  1552. if ( isLight ) { // isCollapsed
  1553. if( MetalUtils.isLeftToRight(c) ) {
  1554. g.drawLine( 12, 7, 15, 7 );
  1555. g.drawLine( 12, 8, 15, 8 );
  1556. // g.setColor( c.getBackground() );
  1557. // g.drawLine( 16, 7, 16, 8 );
  1558. }
  1559. else {
  1560. g.drawLine(4, 7, 7, 7);
  1561. g.drawLine(4, 8, 7, 8);
  1562. }
  1563. }
  1564. else {
  1565. g.drawLine( xoff + 7, 12, xoff + 7, 15 );
  1566. g.drawLine( xoff + 8, 12, xoff + 8, 15 );
  1567. // g.setColor( c.getBackground() );
  1568. // g.drawLine( xoff + 7, 16, xoff + 8, 16 );
  1569. }
  1570. // Draw Fill
  1571. g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
  1572. g.drawLine( xoff + 5, 6, xoff + 5, 9 ); // left shadow
  1573. g.drawLine( xoff + 6, 5, xoff + 9, 5 ); // top shadow
  1574. g.setColor( MetalLookAndFeel.getPrimaryControlShadow() );
  1575. g.drawLine( xoff + 6, 6, xoff + 6, 6 ); // top left fill
  1576. g.drawLine( xoff + 9, 6, xoff + 9, 6 ); // top right fill
  1577. g.drawLine( xoff + 6, 9, xoff + 6, 9 ); // bottom left fill
  1578. g.drawLine( xoff + 10, 6, xoff + 10, 9 ); // right fill
  1579. g.drawLine( xoff + 6, 10, xoff + 9, 10 ); // bottom fill
  1580. g.setColor( MetalLookAndFeel.getPrimaryControl() );
  1581. g.drawLine( xoff + 6, 7, xoff + 6, 8 ); // left highlight
  1582. g.drawLine( xoff + 7, 6, xoff + 8, 6 ); // top highlight
  1583. g.drawLine( xoff + 9, 7, xoff + 9, 7 ); // right highlight
  1584. g.drawLine( xoff + 7, 9, xoff + 7, 9 ); // bottom highlight
  1585. g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
  1586. g.drawLine( xoff + 8, 9, xoff + 9, 9 );
  1587. g.drawLine( xoff + 9, 8, xoff + 9, 8 );
  1588. }
  1589. public int getIconWidth() { return treeControlSize.width; }
  1590. public int getIconHeight() { return treeControlSize.height; }
  1591. }
  1592. //
  1593. // Menu Icons
  1594. //
  1595. static private final Dimension menuArrowIconSize = new Dimension( 4, 8 );
  1596. static private final Dimension menuCheckIconSize = new Dimension( 10, 10 );
  1597. static private final int xOff = 4;
  1598. private static class MenuArrowIcon implements Icon, UIResource, Serializable
  1599. {
  1600. public void paintIcon( Component c, Graphics g, int x, int y )
  1601. {
  1602. JMenuItem b = (JMenuItem) c;
  1603. ButtonModel model = b.getModel();
  1604. g.translate( x, y );
  1605. if ( !model.isEnabled() )
  1606. {
  1607. g.setColor( MetalLookAndFeel.getMenuDisabledForeground() );
  1608. }
  1609. else
  1610. {
  1611. if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) )
  1612. {
  1613. g.setColor( MetalLookAndFeel.getMenuSelectedForeground() );
  1614. }
  1615. else
  1616. {
  1617. g.setColor( b.getForeground() );
  1618. }
  1619. }
  1620. if( MetalUtils.isLeftToRight(b) ) {
  1621. g.drawLine( 0, 0, 0, 7 );
  1622. g.drawLine( 1, 1, 1, 6 );
  1623. g.drawLine( 2, 2, 2, 5 );
  1624. g.drawLine( 3, 3, 3, 4 );
  1625. } else {
  1626. g.drawLine( 4, 0, 4, 7 );
  1627. g.drawLine( 3, 1, 3, 6 );
  1628. g.drawLine( 2, 2, 2, 5 );
  1629. g.drawLine( 1, 3, 1, 4 );
  1630. }
  1631. g.translate( -x, -y );
  1632. }
  1633. public int getIconWidth() { return menuArrowIconSize.width; }
  1634. public int getIconHeight() { return menuArrowIconSize.height; }
  1635. } // End class MenuArrowIcon
  1636. private static class MenuItemArrowIcon implements Icon, UIResource, Serializable
  1637. {
  1638. public void paintIcon( Component c, Graphics g, int x, int y )
  1639. {
  1640. }
  1641. public int getIconWidth() { return menuArrowIconSize.width; }
  1642. public int getIconHeight() { return menuArrowIconSize.height; }
  1643. } // End class MenuItemArrowIcon
  1644. private static class CheckBoxMenuItemIcon implements Icon, UIResource, Serializable
  1645. {
  1646. public void paintOceanIcon(Component c, Graphics g, int x, int y) {
  1647. ButtonModel model = ((JMenuItem)c).getModel();
  1648. boolean isSelected = model.isSelected();
  1649. boolean isEnabled = model.isEnabled();
  1650. boolean isPressed = model.isPressed();
  1651. boolean isArmed = model.isArmed();
  1652. g.translate(x, y);
  1653. if (isEnabled) {
  1654. MetalUtils.drawGradient(c, g, "CheckBoxMenuItem.gradient",
  1655. 1, 1, 7, 7, true);
  1656. if (isPressed || isArmed) {
  1657. g.setColor(MetalLookAndFeel.getControlInfo());
  1658. g.drawLine( 0, 0, 8, 0 );
  1659. g.drawLine( 0, 0, 0, 8 );
  1660. g.drawLine( 8, 2, 8, 8 );
  1661. g.drawLine( 2, 8, 8, 8 );
  1662. g.setColor(MetalLookAndFeel.getPrimaryControl());
  1663. g.drawLine( 9, 1, 9, 9 );
  1664. g.drawLine( 1, 9, 9, 9 );
  1665. }
  1666. else {
  1667. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  1668. g.drawLine( 0, 0, 8, 0 );
  1669. g.drawLine( 0, 0, 0, 8 );
  1670. g.drawLine( 8, 2, 8, 8 );
  1671. g.drawLine( 2, 8, 8, 8 );
  1672. g.setColor(MetalLookAndFeel.getControlHighlight());
  1673. g.drawLine( 9, 1, 9, 9 );
  1674. g.drawLine( 1, 9, 9, 9 );
  1675. }
  1676. }
  1677. else {
  1678. g.setColor(MetalLookAndFeel.getMenuDisabledForeground());
  1679. g.drawRect( 0, 0, 8, 8 );
  1680. }
  1681. if (isSelected) {
  1682. if (isEnabled) {
  1683. if (isArmed || ( c instanceof JMenu && isSelected)) {
  1684. g.setColor(
  1685. MetalLookAndFeel.getMenuSelectedForeground() );
  1686. }
  1687. else {
  1688. g.setColor(c.getForeground());
  1689. }
  1690. }
  1691. else {
  1692. g.setColor( MetalLookAndFeel.getMenuDisabledForeground());
  1693. }
  1694. g.drawLine( 2, 2, 2, 6 );
  1695. g.drawLine( 3, 2, 3, 6 );
  1696. g.drawLine( 4, 4, 8, 0 );
  1697. g.drawLine( 4, 5, 9, 0 );
  1698. }
  1699. g.translate( -x, -y );
  1700. }
  1701. public void paintIcon( Component c, Graphics g, int x, int y )
  1702. {
  1703. if (MetalLookAndFeel.usingOcean()) {
  1704. paintOceanIcon(c, g, x, y);
  1705. return;
  1706. }
  1707. JMenuItem b = (JMenuItem) c;
  1708. ButtonModel model = b.getModel();
  1709. boolean isSelected = model.isSelected();
  1710. boolean isEnabled = model.isEnabled();
  1711. boolean isPressed = model.isPressed();
  1712. boolean isArmed = model.isArmed();
  1713. g.translate( x, y );
  1714. if ( isEnabled )
  1715. {
  1716. if ( isPressed || isArmed )
  1717. {
  1718. g.setColor( MetalLookAndFeel.getControlInfo() );
  1719. g.drawLine( 0, 0, 8, 0 );
  1720. g.drawLine( 0, 0, 0, 8 );
  1721. g.drawLine( 8, 2, 8, 8 );
  1722. g.drawLine( 2, 8, 8, 8 );
  1723. g.setColor( MetalLookAndFeel.getPrimaryControl() );
  1724. g.drawLine( 1, 1, 7, 1 );
  1725. g.drawLine( 1, 1, 1, 7 );
  1726. g.drawLine( 9, 1, 9, 9 );
  1727. g.drawLine( 1, 9, 9, 9 );
  1728. }
  1729. else
  1730. {
  1731. g.setColor( MetalLookAndFeel.getControlDarkShadow() );
  1732. g.drawLine( 0, 0, 8, 0 );
  1733. g.drawLine( 0, 0, 0, 8 );
  1734. g.drawLine( 8, 2, 8, 8 );
  1735. g.drawLine( 2, 8, 8, 8 );
  1736. g.setColor( MetalLookAndFeel.getControlHighlight() );
  1737. g.drawLine( 1, 1, 7, 1 );
  1738. g.drawLine( 1, 1, 1, 7 );
  1739. g.drawLine( 9, 1, 9, 9 );
  1740. g.drawLine( 1, 9, 9, 9 );
  1741. }
  1742. }
  1743. else
  1744. {
  1745. g.setColor( MetalLookAndFeel.getMenuDisabledForeground() );
  1746. g.drawRect( 0, 0, 8, 8 );
  1747. }
  1748. if ( isSelected )
  1749. {
  1750. if ( isEnabled )
  1751. {
  1752. if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) )
  1753. {
  1754. g.setColor( MetalLookAndFeel.getMenuSelectedForeground() );
  1755. }
  1756. else
  1757. {
  1758. g.setColor( b.getForeground() );
  1759. }
  1760. }
  1761. else
  1762. {
  1763. g.setColor( MetalLookAndFeel.getMenuDisabledForeground() );
  1764. }
  1765. g.drawLine( 2, 2, 2, 6 );
  1766. g.drawLine( 3, 2, 3, 6 );
  1767. g.drawLine( 4, 4, 8, 0 );
  1768. g.drawLine( 4, 5, 9, 0 );
  1769. }
  1770. g.translate( -x, -y );
  1771. }
  1772. public int getIconWidth() { return menuCheckIconSize.width; }
  1773. public int getIconHeight() { return menuCheckIconSize.height; }
  1774. } // End class CheckBoxMenuItemIcon
  1775. private static class RadioButtonMenuItemIcon implements Icon, UIResource, Serializable
  1776. {
  1777. public void paintOceanIcon(Component c, Graphics g, int x, int y) {
  1778. ButtonModel model = ((JMenuItem)c).getModel();
  1779. boolean isSelected = model.isSelected();
  1780. boolean isEnabled = model.isEnabled();
  1781. boolean isPressed = model.isPressed();
  1782. boolean isArmed = model.isArmed();
  1783. g.translate( x, y );
  1784. if (isEnabled) {
  1785. MetalUtils.drawGradient(c, g, "RadioButtonMenuItem.gradient",
  1786. 1, 1, 7, 7, true);
  1787. if (isPressed || isArmed) {
  1788. g.setColor(MetalLookAndFeel.getPrimaryControl());
  1789. }
  1790. else {
  1791. g.setColor(MetalLookAndFeel.getControlHighlight());
  1792. }
  1793. g.drawLine( 2, 9, 7, 9 );
  1794. g.drawLine( 9, 2, 9, 7 );
  1795. g.drawLine( 8, 8, 8, 8 );
  1796. if (isPressed || isArmed) {
  1797. g.setColor(MetalLookAndFeel.getControlInfo());
  1798. }
  1799. else {
  1800. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  1801. }
  1802. }
  1803. else {
  1804. g.setColor( MetalLookAndFeel.getMenuDisabledForeground() );
  1805. }
  1806. g.drawLine( 2, 0, 6, 0 );
  1807. g.drawLine( 2, 8, 6, 8 );
  1808. g.drawLine( 0, 2, 0, 6 );
  1809. g.drawLine( 8, 2, 8, 6 );
  1810. g.drawLine( 1, 1, 1, 1 );
  1811. g.drawLine( 7, 1, 7, 1 );
  1812. g.drawLine( 1, 7, 1, 7 );
  1813. g.drawLine( 7, 7, 7, 7 );
  1814. if (isSelected) {
  1815. if (isEnabled) {
  1816. if (isArmed || (c instanceof JMenu && model.isSelected())){
  1817. g.setColor(MetalLookAndFeel.
  1818. getMenuSelectedForeground() );
  1819. }
  1820. else {
  1821. g.setColor(c.getForeground());
  1822. }
  1823. }
  1824. else {
  1825. g.setColor(MetalLookAndFeel.getMenuDisabledForeground());
  1826. }
  1827. g.drawLine( 3, 2, 5, 2 );
  1828. g.drawLine( 2, 3, 6, 3 );
  1829. g.drawLine( 2, 4, 6, 4 );
  1830. g.drawLine( 2, 5, 6, 5 );
  1831. g.drawLine( 3, 6, 5, 6 );
  1832. }
  1833. g.translate( -x, -y );
  1834. }
  1835. public void paintIcon( Component c, Graphics g, int x, int y )
  1836. {
  1837. if (MetalLookAndFeel.usingOcean()) {
  1838. paintOceanIcon(c, g, x, y);
  1839. return;
  1840. }
  1841. JMenuItem b = (JMenuItem) c;
  1842. ButtonModel model = b.getModel();
  1843. boolean isSelected = model.isSelected();
  1844. boolean isEnabled = model.isEnabled();
  1845. boolean isPressed = model.isPressed();
  1846. boolean isArmed = model.isArmed();
  1847. g.translate( x, y );
  1848. if ( isEnabled )
  1849. {
  1850. if ( isPressed || isArmed )
  1851. {
  1852. g.setColor( MetalLookAndFeel.getPrimaryControl() );
  1853. g.drawLine( 3, 1, 8, 1 );
  1854. g.drawLine( 2, 9, 7, 9 );
  1855. g.drawLine( 1, 3, 1, 8 );
  1856. g.drawLine( 9, 2, 9, 7 );
  1857. g.drawLine( 2, 2, 2, 2 );
  1858. g.drawLine( 8, 8, 8, 8 );
  1859. g.setColor( MetalLookAndFeel.getControlInfo() );
  1860. g.drawLine( 2, 0, 6, 0 );
  1861. g.drawLine( 2, 8, 6, 8 );
  1862. g.drawLine( 0, 2, 0, 6 );
  1863. g.drawLine( 8, 2, 8, 6 );
  1864. g.drawLine( 1, 1, 1, 1 );
  1865. g.drawLine( 7, 1, 7, 1 );
  1866. g.drawLine( 1, 7, 1, 7 );
  1867. g.drawLine( 7, 7, 7, 7 );
  1868. }
  1869. else
  1870. {
  1871. g.setColor( MetalLookAndFeel.getControlHighlight() );
  1872. g.drawLine( 3, 1, 8, 1 );
  1873. g.drawLine( 2, 9, 7, 9 );
  1874. g.drawLine( 1, 3, 1, 8 );
  1875. g.drawLine( 9, 2, 9, 7 );
  1876. g.drawLine( 2, 2, 2, 2 );
  1877. g.drawLine( 8, 8, 8, 8 );
  1878. g.setColor( MetalLookAndFeel.getControlDarkShadow() );
  1879. g.drawLine( 2, 0, 6, 0 );
  1880. g.drawLine( 2, 8, 6, 8 );
  1881. g.drawLine( 0, 2, 0, 6 );
  1882. g.drawLine( 8, 2, 8, 6 );
  1883. g.drawLine( 1, 1, 1, 1 );
  1884. g.drawLine( 7, 1, 7, 1 );
  1885. g.drawLine( 1, 7, 1, 7 );
  1886. g.drawLine( 7, 7, 7, 7 );
  1887. }
  1888. }
  1889. else
  1890. {
  1891. g.setColor( MetalLookAndFeel.getMenuDisabledForeground() );
  1892. g.drawLine( 2, 0, 6, 0 );
  1893. g.drawLine( 2, 8, 6, 8 );
  1894. g.drawLine( 0, 2, 0, 6 );
  1895. g.drawLine( 8, 2, 8, 6 );
  1896. g.drawLine( 1, 1, 1, 1 );
  1897. g.drawLine( 7, 1, 7, 1 );
  1898. g.drawLine( 1, 7, 1, 7 );
  1899. g.drawLine( 7, 7, 7, 7 );
  1900. }
  1901. if ( isSelected )
  1902. {
  1903. if ( isEnabled )
  1904. {
  1905. if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) )
  1906. {
  1907. g.setColor( MetalLookAndFeel.getMenuSelectedForeground() );
  1908. }
  1909. else
  1910. {
  1911. g.setColor( b.getForeground() );
  1912. }
  1913. }
  1914. else
  1915. {
  1916. g.setColor( MetalLookAndFeel.getMenuDisabledForeground() );
  1917. }
  1918. g.drawLine( 3, 2, 5, 2 );
  1919. g.drawLine( 2, 3, 6, 3 );
  1920. g.drawLine( 2, 4, 6, 4 );
  1921. g.drawLine( 2, 5, 6, 5 );
  1922. g.drawLine( 3, 6, 5, 6 );
  1923. }
  1924. g.translate( -x, -y );
  1925. }
  1926. public int getIconWidth() { return menuCheckIconSize.width; }
  1927. public int getIconHeight() { return menuCheckIconSize.height; }
  1928. } // End class RadioButtonMenuItemIcon
  1929. private static class VerticalSliderThumbIcon implements Icon, Serializable, UIResource {
  1930. protected static MetalBumps controlBumps;
  1931. protected static MetalBumps primaryBumps;
  1932. public VerticalSliderThumbIcon() {
  1933. controlBumps = new MetalBumps( 6, 10,
  1934. MetalLookAndFeel.getControlHighlight(),
  1935. MetalLookAndFeel.getControlInfo(),
  1936. MetalLookAndFeel.getControl() );
  1937. primaryBumps = new MetalBumps( 6, 10,
  1938. MetalLookAndFeel.getPrimaryControl(),
  1939. MetalLookAndFeel.getPrimaryControlDarkShadow(),
  1940. MetalLookAndFeel.getPrimaryControlShadow() );
  1941. }
  1942. public void paintIcon( Component c, Graphics g, int x, int y ) {
  1943. JSlider slider = (JSlider)c;
  1944. boolean leftToRight = MetalUtils.isLeftToRight(slider);
  1945. g.translate( x, y );
  1946. // Draw the frame
  1947. if ( slider.hasFocus() ) {
  1948. g.setColor( MetalLookAndFeel.getPrimaryControlInfo() );
  1949. }
  1950. else {
  1951. g.setColor( slider.isEnabled() ? MetalLookAndFeel.getPrimaryControlInfo() :
  1952. MetalLookAndFeel.getControlDarkShadow() );
  1953. }
  1954. if (leftToRight) {
  1955. g.drawLine( 1,0 , 8,0 ); // top
  1956. g.drawLine( 0,1 , 0,13 ); // left
  1957. g.drawLine( 1,14 , 8,14 ); // bottom
  1958. g.drawLine( 9,1 , 15,7 ); // top slant
  1959. g.drawLine( 9,13 , 15,7 ); // bottom slant
  1960. }
  1961. else {
  1962. g.drawLine( 7,0 , 14,0 ); // top
  1963. g.drawLine( 15,1 , 15,13 ); // right
  1964. g.drawLine( 7,14 , 14,14 ); // bottom
  1965. g.drawLine( 0,7 , 6,1 ); // top slant
  1966. g.drawLine( 0,7 , 6,13 ); // bottom slant
  1967. }
  1968. // Fill in the background
  1969. if ( slider.hasFocus() ) {
  1970. g.setColor( c.getForeground() );
  1971. }
  1972. else {
  1973. g.setColor( MetalLookAndFeel.getControl() );
  1974. }
  1975. if (leftToRight) {
  1976. g.fillRect( 1,1 , 8,13 );
  1977. g.drawLine( 9,2 , 9,12 );
  1978. g.drawLine( 10,3 , 10,11 );
  1979. g.drawLine( 11,4 , 11,10 );
  1980. g.drawLine( 12,5 , 12,9 );
  1981. g.drawLine( 13,6 , 13,8 );
  1982. g.drawLine( 14,7 , 14,7 );
  1983. }
  1984. else {
  1985. g.fillRect( 7,1, 8,13 );
  1986. g.drawLine( 6,3 , 6,12 );
  1987. g.drawLine( 5,4 , 5,11 );
  1988. g.drawLine( 4,5 , 4,10 );
  1989. g.drawLine( 3,6 , 3,9 );
  1990. g.drawLine( 2,7 , 2,8 );
  1991. }
  1992. // Draw the bumps
  1993. int offset = (leftToRight) ? 2 : 8;
  1994. if ( slider.isEnabled() ) {
  1995. if ( slider.hasFocus() ) {
  1996. primaryBumps.paintIcon( c, g, offset, 2 );
  1997. }
  1998. else {
  1999. controlBumps.paintIcon( c, g, offset, 2 );
  2000. }
  2001. }
  2002. // Draw the highlight
  2003. if ( slider.isEnabled() ) {
  2004. g.setColor( slider.hasFocus() ? MetalLookAndFeel.getPrimaryControl()
  2005. : MetalLookAndFeel.getControlHighlight() );
  2006. if (leftToRight) {
  2007. g.drawLine( 1, 1, 8, 1 );
  2008. g.drawLine( 1, 1, 1, 13 );
  2009. }
  2010. else {
  2011. g.drawLine( 8,1 , 14,1 ); // top
  2012. g.drawLine( 1,7 , 7,1 ); // top slant
  2013. }
  2014. }
  2015. g.translate( -x, -y );
  2016. }
  2017. public int getIconWidth() {
  2018. return 16;
  2019. }
  2020. public int getIconHeight() {
  2021. return 15;
  2022. }
  2023. }
  2024. private static class HorizontalSliderThumbIcon implements Icon, Serializable, UIResource {
  2025. protected static MetalBumps controlBumps;
  2026. protected static MetalBumps primaryBumps;
  2027. public HorizontalSliderThumbIcon() {
  2028. controlBumps = new MetalBumps( 10, 6,
  2029. MetalLookAndFeel.getControlHighlight(),
  2030. MetalLookAndFeel.getControlInfo(),
  2031. MetalLookAndFeel.getControl() );
  2032. primaryBumps = new MetalBumps( 10, 6,
  2033. MetalLookAndFeel.getPrimaryControl(),
  2034. MetalLookAndFeel.getPrimaryControlDarkShadow(),
  2035. MetalLookAndFeel.getPrimaryControlShadow() );
  2036. }
  2037. public void paintIcon( Component c, Graphics g, int x, int y ) {
  2038. JSlider slider = (JSlider)c;
  2039. g.translate( x, y );
  2040. // Draw the frame
  2041. if ( slider.hasFocus() ) {
  2042. g.setColor( MetalLookAndFeel.getPrimaryControlInfo() );
  2043. }
  2044. else {
  2045. g.setColor( slider.isEnabled() ? MetalLookAndFeel.getPrimaryControlInfo() :
  2046. MetalLookAndFeel.getControlDarkShadow() );
  2047. }
  2048. g.drawLine( 1,0 , 13,0 ); // top
  2049. g.drawLine( 0,1 , 0,8 ); // left
  2050. g.drawLine( 14,1 , 14,8 ); // right
  2051. g.drawLine( 1,9 , 7,15 ); // left slant
  2052. g.drawLine( 7,15 , 14,8 ); // right slant
  2053. // Fill in the background
  2054. if ( slider.hasFocus() ) {
  2055. g.setColor( c.getForeground() );
  2056. }
  2057. else {
  2058. g.setColor( MetalLookAndFeel.getControl() );
  2059. }
  2060. g.fillRect( 1,1, 13, 8 );
  2061. g.drawLine( 2,9 , 12,9 );
  2062. g.drawLine( 3,10 , 11,10 );
  2063. g.drawLine( 4,11 , 10,11 );
  2064. g.drawLine( 5,12 , 9,12 );
  2065. g.drawLine( 6,13 , 8,13 );
  2066. g.drawLine( 7,14 , 7,14 );
  2067. // Draw the bumps
  2068. if ( slider.isEnabled() ) {
  2069. if ( slider.hasFocus() ) {
  2070. primaryBumps.paintIcon( c, g, 2, 2 );
  2071. }
  2072. else {
  2073. controlBumps.paintIcon( c, g, 2, 2 );
  2074. }
  2075. }
  2076. // Draw the highlight
  2077. if ( slider.isEnabled() ) {
  2078. g.setColor( slider.hasFocus() ? MetalLookAndFeel.getPrimaryControl()
  2079. : MetalLookAndFeel.getControlHighlight() );
  2080. g.drawLine( 1, 1, 13, 1 );
  2081. g.drawLine( 1, 1, 1, 8 );
  2082. }
  2083. g.translate( -x, -y );
  2084. }
  2085. public int getIconWidth() {
  2086. return 15;
  2087. }
  2088. public int getIconHeight() {
  2089. return 16;
  2090. }
  2091. }
  2092. private static class OceanVerticalSliderThumbIcon extends CachedPainter
  2093. implements Icon, Serializable, UIResource {
  2094. // Used for clipping when the orientation is left to right
  2095. private static Polygon LTR_THUMB_SHAPE;
  2096. // Used for clipping when the orientation is right to left
  2097. private static Polygon RTL_THUMB_SHAPE;
  2098. static {
  2099. LTR_THUMB_SHAPE = new Polygon(new int[] { 0, 8, 15, 8, 0},
  2100. new int[] { 0, 0, 7, 14, 14 }, 5);
  2101. RTL_THUMB_SHAPE = new Polygon(new int[] { 15, 15, 7, 0, 7},
  2102. new int[] { 0, 14, 14, 7, 0}, 5);
  2103. }
  2104. OceanVerticalSliderThumbIcon() {
  2105. super(3);
  2106. }
  2107. public void paintIcon(Component c, Graphics g, int x, int y) {
  2108. if (!(g instanceof Graphics2D)) {
  2109. return;
  2110. }
  2111. paint(c, g, x, y, getIconWidth(), getIconHeight(),
  2112. MetalUtils.isLeftToRight(c), c.hasFocus(), c.isEnabled(),
  2113. MetalLookAndFeel.getCurrentTheme());
  2114. }
  2115. protected void paintToImage(Component c, Graphics g2,
  2116. int w, int h, Object[] args) {
  2117. Graphics2D g = (Graphics2D)g2;
  2118. boolean leftToRight = ((Boolean)args[0]).booleanValue();
  2119. boolean hasFocus = ((Boolean)args[1]).booleanValue();
  2120. boolean enabled = ((Boolean)args[2]).booleanValue();
  2121. Rectangle clip = g.getClipBounds();
  2122. if (leftToRight) {
  2123. g.clip(LTR_THUMB_SHAPE);
  2124. }
  2125. else {
  2126. g.clip(RTL_THUMB_SHAPE);
  2127. }
  2128. if (!enabled) {
  2129. g.setColor(MetalLookAndFeel.getControl());
  2130. g.fillRect(1, 1, 14, 14);
  2131. }
  2132. else if (hasFocus) {
  2133. MetalUtils.drawGradient(c, g, "Slider.focusGradient",
  2134. 1, 1, 14, 14, false);
  2135. }
  2136. else {
  2137. MetalUtils.drawGradient(c, g, "Slider.gradient",
  2138. 1, 1, 14, 14, false);
  2139. }
  2140. g.setClip(clip);
  2141. // Draw the frame
  2142. if (hasFocus) {
  2143. g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
  2144. }
  2145. else {
  2146. g.setColor(enabled ? MetalLookAndFeel.getPrimaryControlInfo() :
  2147. MetalLookAndFeel.getControlDarkShadow());
  2148. }
  2149. if (leftToRight) {
  2150. g.drawLine( 1,0 , 8,0 ); // top
  2151. g.drawLine( 0,1 , 0,13 ); // left
  2152. g.drawLine( 1,14 , 8,14 ); // bottom
  2153. g.drawLine( 9,1 , 15,7 ); // top slant
  2154. g.drawLine( 9,13 , 15,7 ); // bottom slant
  2155. }
  2156. else {
  2157. g.drawLine( 7,0 , 14,0 ); // top
  2158. g.drawLine( 15,1 , 15,13 ); // right
  2159. g.drawLine( 7,14 , 14,14 ); // bottom
  2160. g.drawLine( 0,7 , 6,1 ); // top slant
  2161. g.drawLine( 0,7 , 6,13 ); // bottom slant
  2162. }
  2163. if (hasFocus && enabled) {
  2164. // Inner line.
  2165. g.setColor(MetalLookAndFeel.getPrimaryControl());
  2166. if (leftToRight) {
  2167. g.drawLine( 1,1 , 8,1 ); // top
  2168. g.drawLine( 1,1 , 1,13 ); // left
  2169. g.drawLine( 1,13 , 8,13 ); // bottom
  2170. g.drawLine( 9,2 , 14,7 ); // top slant
  2171. g.drawLine( 9,12 , 14,7 ); // bottom slant
  2172. }
  2173. else {
  2174. g.drawLine( 7,1 , 14,1 ); // top
  2175. g.drawLine( 14,1 , 14,13 ); // right
  2176. g.drawLine( 7,13 , 14,13 ); // bottom
  2177. g.drawLine( 1,7 , 7,1 ); // top slant
  2178. g.drawLine( 1,7 , 7,13 ); // bottom slant
  2179. }
  2180. }
  2181. }
  2182. public int getIconWidth() {
  2183. return 16;
  2184. }
  2185. public int getIconHeight() {
  2186. return 15;
  2187. }
  2188. protected Image createImage(Component c, int w, int h,
  2189. GraphicsConfiguration config) {
  2190. return config.createCompatibleImage(
  2191. w, h, Transparency.BITMASK);
  2192. }
  2193. }
  2194. private static class OceanHorizontalSliderThumbIcon extends CachedPainter
  2195. implements Icon, Serializable, UIResource {
  2196. // Used for clipping
  2197. private static Polygon THUMB_SHAPE;
  2198. static {
  2199. THUMB_SHAPE = new Polygon(new int[] { 0, 14, 14, 7, 0 },
  2200. new int[] { 0, 0, 8, 15, 8 }, 5);
  2201. }
  2202. OceanHorizontalSliderThumbIcon() {
  2203. super(3);
  2204. }
  2205. public void paintIcon(Component c, Graphics g, int x, int y) {
  2206. if (!(g instanceof Graphics2D)) {
  2207. return;
  2208. }
  2209. paint(c, g, x, y, getIconWidth(), getIconHeight(),
  2210. c.hasFocus(), c.isEnabled(),
  2211. MetalLookAndFeel.getCurrentTheme());
  2212. }
  2213. protected Image createImage(Component c, int w, int h,
  2214. GraphicsConfiguration config) {
  2215. return config.createCompatibleImage(
  2216. w, h, Transparency.BITMASK);
  2217. }
  2218. protected void paintToImage(Component c, Graphics g2,
  2219. int w, int h, Object[] args) {
  2220. Graphics2D g = (Graphics2D)g2;
  2221. boolean hasFocus = ((Boolean)args[0]).booleanValue();
  2222. boolean enabled = ((Boolean)args[1]).booleanValue();
  2223. // Fill in the background
  2224. Rectangle clip = g.getClipBounds();
  2225. g.clip(THUMB_SHAPE);
  2226. if (!enabled) {
  2227. g.setColor(MetalLookAndFeel.getControl());
  2228. g.fillRect(1, 1, 13, 14);
  2229. }
  2230. else if (hasFocus) {
  2231. MetalUtils.drawGradient(c, g, "Slider.focusGradient",
  2232. 1, 1, 13, 14, true);
  2233. }
  2234. else {
  2235. MetalUtils.drawGradient(c, g, "Slider.gradient",
  2236. 1, 1, 13, 14, true);
  2237. }
  2238. g.setClip(clip);
  2239. // Draw the frame
  2240. if (hasFocus) {
  2241. g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
  2242. }
  2243. else {
  2244. g.setColor(enabled ? MetalLookAndFeel.getPrimaryControlInfo() :
  2245. MetalLookAndFeel.getControlDarkShadow());
  2246. }
  2247. g.drawLine( 1,0 , 13,0 ); // top
  2248. g.drawLine( 0,1 , 0,8 ); // left
  2249. g.drawLine( 14,1 , 14,8 ); // right
  2250. g.drawLine( 1,9 , 7,15 ); // left slant
  2251. g.drawLine( 7,15 , 14,8 ); // right slant
  2252. if (hasFocus && enabled) {
  2253. // Inner line.
  2254. g.setColor(MetalLookAndFeel.getPrimaryControl());
  2255. g.fillRect(1, 1, 13, 1);
  2256. g.fillRect(1, 2, 1, 7);
  2257. g.fillRect(13, 2, 1, 7);
  2258. g.drawLine(2, 9, 7, 14);
  2259. g.drawLine(8, 13, 12, 9);
  2260. }
  2261. }
  2262. public int getIconWidth() {
  2263. return 15;
  2264. }
  2265. public int getIconHeight() {
  2266. return 16;
  2267. }
  2268. }
  2269. }