1. /*
  2. * @(#)MetalIconFactory.java 1.54 03/01/23
  3. *
  4. * Copyright 2003 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.54 01/23/03
  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. // Constants
  62. public static final boolean DARK = false;
  63. public static final boolean LIGHT = true;
  64. // Accessor functions for Icons. Does the caching work.
  65. public static Icon getFileChooserDetailViewIcon() {
  66. if (fileChooserDetailViewIcon == null) {
  67. fileChooserDetailViewIcon = new FileChooserDetailViewIcon();
  68. }
  69. return fileChooserDetailViewIcon;
  70. }
  71. public static Icon getFileChooserHomeFolderIcon() {
  72. if (fileChooserHomeFolderIcon == null) {
  73. fileChooserHomeFolderIcon = new FileChooserHomeFolderIcon();
  74. }
  75. return fileChooserHomeFolderIcon;
  76. }
  77. public static Icon getFileChooserListViewIcon() {
  78. if (fileChooserListViewIcon == null) {
  79. fileChooserListViewIcon = new FileChooserListViewIcon();
  80. }
  81. return fileChooserListViewIcon;
  82. }
  83. public static Icon getFileChooserNewFolderIcon() {
  84. if (fileChooserNewFolderIcon == null) {
  85. fileChooserNewFolderIcon = new FileChooserNewFolderIcon();
  86. }
  87. return fileChooserNewFolderIcon;
  88. }
  89. public static Icon getFileChooserUpFolderIcon() {
  90. if (fileChooserUpFolderIcon == null) {
  91. fileChooserUpFolderIcon = new FileChooserUpFolderIcon();
  92. }
  93. return fileChooserUpFolderIcon;
  94. }
  95. public static Icon getInternalFrameAltMaximizeIcon(int size) {
  96. return new InternalFrameAltMaximizeIcon(size);
  97. }
  98. public static Icon getInternalFrameCloseIcon(int size) {
  99. return new InternalFrameCloseIcon(size);
  100. }
  101. public static Icon getInternalFrameDefaultMenuIcon() {
  102. if (internalFrameDefaultMenuIcon == null) {
  103. internalFrameDefaultMenuIcon = new InternalFrameDefaultMenuIcon();
  104. }
  105. return internalFrameDefaultMenuIcon;
  106. }
  107. public static Icon getInternalFrameMaximizeIcon(int size) {
  108. return new InternalFrameMaximizeIcon(size);
  109. }
  110. public static Icon getInternalFrameMinimizeIcon(int size) {
  111. return new InternalFrameMinimizeIcon(size);
  112. }
  113. public static Icon getRadioButtonIcon() {
  114. if (radioButtonIcon == null) {
  115. radioButtonIcon = new RadioButtonIcon();
  116. }
  117. return radioButtonIcon;
  118. }
  119. /**
  120. * Returns a checkbox icon.
  121. * @since 1.3
  122. */
  123. public static Icon getCheckBoxIcon() {
  124. if (checkBoxIcon == null) {
  125. checkBoxIcon = new CheckBoxIcon();
  126. }
  127. return checkBoxIcon;
  128. }
  129. public static Icon getTreeComputerIcon() {
  130. if ( treeComputerIcon == null ) {
  131. treeComputerIcon = new TreeComputerIcon();
  132. }
  133. return treeComputerIcon;
  134. }
  135. public static Icon getTreeFloppyDriveIcon() {
  136. if ( treeFloppyDriveIcon == null ) {
  137. treeFloppyDriveIcon = new TreeFloppyDriveIcon();
  138. }
  139. return treeFloppyDriveIcon;
  140. }
  141. public static Icon getTreeFolderIcon() {
  142. return new TreeFolderIcon();
  143. }
  144. public static Icon getTreeHardDriveIcon() {
  145. if ( treeHardDriveIcon == null ) {
  146. treeHardDriveIcon = new TreeHardDriveIcon();
  147. }
  148. return treeHardDriveIcon;
  149. }
  150. public static Icon getTreeLeafIcon() {
  151. return new TreeLeafIcon();
  152. }
  153. public static Icon getTreeControlIcon( boolean isCollapsed ) {
  154. return new TreeControlIcon( isCollapsed );
  155. }
  156. public static Icon getMenuArrowIcon() {
  157. if (menuArrowIcon == null) {
  158. menuArrowIcon = new MenuArrowIcon();
  159. }
  160. return menuArrowIcon;
  161. }
  162. /**
  163. * Returns an icon to be used by <code>JCheckBoxMenuItem</code>.
  164. *
  165. * @return the default icon for check box menu items,
  166. * or <code>null</code> if no default exists
  167. */
  168. public static Icon getMenuItemCheckIcon() {
  169. return null;
  170. }
  171. public static Icon getMenuItemArrowIcon() {
  172. if (menuItemArrowIcon == null) {
  173. menuItemArrowIcon = new MenuItemArrowIcon();
  174. }
  175. return menuItemArrowIcon;
  176. }
  177. public static Icon getCheckBoxMenuItemIcon() {
  178. if (checkBoxMenuItemIcon == null) {
  179. checkBoxMenuItemIcon = new CheckBoxMenuItemIcon();
  180. }
  181. return checkBoxMenuItemIcon;
  182. }
  183. public static Icon getRadioButtonMenuItemIcon() {
  184. if (radioButtonMenuItemIcon == null) {
  185. radioButtonMenuItemIcon = new RadioButtonMenuItemIcon();
  186. }
  187. return radioButtonMenuItemIcon;
  188. }
  189. public static Icon getHorizontalSliderThumbIcon() {
  190. // don't cache these, bumps don't get updated otherwise
  191. return new HorizontalSliderThumbIcon();
  192. }
  193. public static Icon getVerticalSliderThumbIcon() {
  194. // don't cache these, bumps don't get updated otherwise
  195. return new VerticalSliderThumbIcon();
  196. }
  197. // File Chooser Detail View code
  198. private static class FileChooserDetailViewIcon implements Icon, UIResource, Serializable {
  199. public void paintIcon(Component c, Graphics g, int x, int y) {
  200. g.translate(x, y);
  201. // Draw outside edge of each of the documents
  202. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  203. // top
  204. g.drawLine(2,2, 5,2); // top
  205. g.drawLine(2,3, 2,7); // left
  206. g.drawLine(3,7, 6,7); // bottom
  207. g.drawLine(6,6, 6,3); // right
  208. // bottom
  209. g.drawLine(2,10, 5,10); // top
  210. g.drawLine(2,11, 2,15); // left
  211. g.drawLine(3,15, 6,15); // bottom
  212. g.drawLine(6,14, 6,11); // right
  213. // Draw little dots next to documents
  214. // Same color as outside edge
  215. g.drawLine(8,5, 15,5); // top
  216. g.drawLine(8,13, 15,13); // bottom
  217. // Draw inner highlight on documents
  218. g.setColor(MetalLookAndFeel.getPrimaryControl());
  219. g.drawRect(3,3, 2,3); // top
  220. g.drawRect(3,11, 2,3); // bottom
  221. // Draw inner inner highlight on documents
  222. g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
  223. g.drawLine(4,4, 4,5); // top
  224. g.drawLine(4,12, 4,13); // bottom
  225. g.translate(-x, -y);
  226. }
  227. public int getIconWidth() {
  228. return 18;
  229. }
  230. public int getIconHeight() {
  231. return 18;
  232. }
  233. } // End class FileChooserDetailViewIcon
  234. // File Chooser Home Folder code
  235. private static class FileChooserHomeFolderIcon implements Icon, UIResource, Serializable {
  236. public void paintIcon(Component c, Graphics g, int x, int y) {
  237. g.translate(x, y);
  238. // Draw outside edge of house
  239. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  240. g.drawLine(8,1, 1,8); // left edge of roof
  241. g.drawLine(8,1, 15,8); // right edge of roof
  242. g.drawLine(11,2, 11,3); // left edge of chimney
  243. g.drawLine(12,2, 12,4); // right edge of chimney
  244. g.drawLine(3,7, 3,15); // left edge of house
  245. g.drawLine(13,7, 13,15); // right edge of house
  246. g.drawLine(4,15, 12,15); // bottom edge of house
  247. // Draw door frame
  248. // same color as edge of house
  249. g.drawLine( 6,9, 6,14); // left
  250. g.drawLine(10,9, 10,14); // right
  251. g.drawLine( 7,9, 9, 9); // top
  252. // Draw roof body
  253. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  254. g.fillRect(8,2, 1,1); //top toward bottom
  255. g.fillRect(7,3, 3,1);
  256. g.fillRect(6,4, 5,1);
  257. g.fillRect(5,5, 7,1);
  258. g.fillRect(4,6, 9,2);
  259. // Draw doornob
  260. // same color as roof body
  261. g.drawLine(9,12, 9,12);
  262. // Paint the house
  263. g.setColor(MetalLookAndFeel.getPrimaryControl());
  264. g.drawLine(4,8, 12,8); // above door
  265. g.fillRect(4,9, 2,6); // left of door
  266. g.fillRect(11,9, 2,6); // right of door
  267. g.translate(-x, -y);
  268. }
  269. public int getIconWidth() {
  270. return 18;
  271. }
  272. public int getIconHeight() {
  273. return 18;
  274. }
  275. } // End class FileChooserHomeFolderIcon
  276. // File Chooser List View code
  277. private static class FileChooserListViewIcon implements Icon, UIResource, Serializable {
  278. public void paintIcon(Component c, Graphics g, int x, int y) {
  279. g.translate(x, y);
  280. // Draw outside edge of each of the documents
  281. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  282. // top left
  283. g.drawLine(2,2, 5,2); // top
  284. g.drawLine(2,3, 2,7); // left
  285. g.drawLine(3,7, 6,7); // bottom
  286. g.drawLine(6,6, 6,3); // right
  287. // top right
  288. g.drawLine(10,2, 13,2); // top
  289. g.drawLine(10,3, 10,7); // left
  290. g.drawLine(11,7, 14,7); // bottom
  291. g.drawLine(14,6, 14,3); // right
  292. // bottom left
  293. g.drawLine(2,10, 5,10); // top
  294. g.drawLine(2,11, 2,15); // left
  295. g.drawLine(3,15, 6,15); // bottom
  296. g.drawLine(6,14, 6,11); // right
  297. // bottom right
  298. g.drawLine(10,10, 13,10); // top
  299. g.drawLine(10,11, 10,15); // left
  300. g.drawLine(11,15, 14,15); // bottom
  301. g.drawLine(14,14, 14,11); // right
  302. // Draw little dots next to documents
  303. // Same color as outside edge
  304. g.drawLine(8,5, 8,5); // top left
  305. g.drawLine(16,5, 16,5); // top right
  306. g.drawLine(8,13, 8,13); // bottom left
  307. g.drawLine(16,13, 16,13); // bottom right
  308. // Draw inner highlight on documents
  309. g.setColor(MetalLookAndFeel.getPrimaryControl());
  310. g.drawRect(3,3, 2,3); // top left
  311. g.drawRect(11,3, 2,3); // top right
  312. g.drawRect(3,11, 2,3); // bottom left
  313. g.drawRect(11,11, 2,3); // bottom right
  314. // Draw inner inner highlight on documents
  315. g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
  316. g.drawLine(4,4, 4,5); // top left
  317. g.drawLine(12,4, 12,5); // top right
  318. g.drawLine(4,12, 4,13); // bottom left
  319. g.drawLine(12,12, 12,13); // bottom right
  320. g.translate(-x, -y);
  321. }
  322. public int getIconWidth() {
  323. return 18;
  324. }
  325. public int getIconHeight() {
  326. return 18;
  327. }
  328. } // End class FileChooserListViewIcon
  329. // File Chooser New Folder code
  330. private static class FileChooserNewFolderIcon implements Icon, UIResource, Serializable {
  331. public void paintIcon(Component c, Graphics g, int x, int y) {
  332. g.translate(x, y);
  333. // Fill background
  334. g.setColor(MetalLookAndFeel.getPrimaryControl());
  335. g.fillRect(3,5, 12,9);
  336. // Draw outside edge of folder
  337. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  338. g.drawLine(1,6, 1,14); // left
  339. g.drawLine(2,14, 15,14); // bottom
  340. g.drawLine(15,13, 15,5); // right
  341. g.drawLine(2,5, 9,5); // top left
  342. g.drawLine(10,6, 14,6); // top right
  343. // Draw inner folder highlight
  344. g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
  345. g.drawLine( 2,6, 2,13); // left
  346. g.drawLine( 3,6, 9,6); // top left
  347. g.drawLine(10,7, 14,7); // top right
  348. // Draw tab on folder
  349. g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
  350. g.drawLine(11,3, 15,3); // top
  351. g.drawLine(10,4, 15,4); // bottom
  352. g.translate(-x, -y);
  353. }
  354. public int getIconWidth() {
  355. return 18;
  356. }
  357. public int getIconHeight() {
  358. return 18;
  359. }
  360. } // End class FileChooserNewFolderIcon
  361. // File Chooser Up Folder code
  362. private static class FileChooserUpFolderIcon implements Icon, UIResource, Serializable {
  363. public void paintIcon(Component c, Graphics g, int x, int y) {
  364. g.translate(x, y);
  365. // Fill background
  366. g.setColor(MetalLookAndFeel.getPrimaryControl());
  367. g.fillRect(3,5, 12,9);
  368. // Draw outside edge of folder
  369. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  370. g.drawLine(1,6, 1,14); // left
  371. g.drawLine(2,14, 15,14); // bottom
  372. g.drawLine(15,13, 15,5); // right
  373. g.drawLine(2,5, 9,5); // top left
  374. g.drawLine(10,6, 14,6); // top right
  375. // Draw the UP arrow
  376. // same color as edge
  377. g.drawLine(8,13, 8,16); // arrow shaft
  378. g.drawLine(8, 9, 8, 9); // arrowhead top
  379. g.drawLine(7,10, 9,10);
  380. g.drawLine(6,11, 10,11);
  381. g.drawLine(5,12, 11,12);
  382. // Draw inner folder highlight
  383. g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
  384. g.drawLine( 2,6, 2,13); // left
  385. g.drawLine( 3,6, 9,6); // top left
  386. g.drawLine(10,7, 14,7); // top right
  387. // Draw tab on folder
  388. g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
  389. g.drawLine(11,3, 15,3); // top
  390. g.drawLine(10,4, 15,4); // bottom
  391. g.translate(-x, -y);
  392. }
  393. public int getIconWidth() {
  394. return 18;
  395. }
  396. public int getIconHeight() {
  397. return 18;
  398. }
  399. } // End class FileChooserUpFolderIcon
  400. /**
  401. * Defines an icon for Palette close
  402. * @since 1.3
  403. */
  404. public static class PaletteCloseIcon implements Icon, UIResource, Serializable{
  405. int iconSize = 7;
  406. public void paintIcon(Component c, Graphics g, int x, int y) {
  407. JButton parentButton = (JButton)c;
  408. ButtonModel buttonModel = parentButton.getModel();
  409. Color back;
  410. Color highlight = MetalLookAndFeel.getPrimaryControlHighlight();
  411. Color shadow = MetalLookAndFeel.getPrimaryControlInfo();
  412. if (buttonModel.isPressed() && buttonModel.isArmed()) {
  413. back = shadow;
  414. } else {
  415. back = MetalLookAndFeel.getPrimaryControlDarkShadow();
  416. }
  417. g.translate(x, y);
  418. g.setColor(back);
  419. g.drawLine( 0, 1, 5, 6);
  420. g.drawLine( 1, 0, 6, 5);
  421. g.drawLine( 1, 1, 6, 6);
  422. g.drawLine( 6, 1, 1, 6);
  423. g.drawLine( 5,0, 0,5);
  424. g.drawLine(5,1, 1,5);
  425. g.setColor(highlight);
  426. g.drawLine(6,2, 5,3);
  427. g.drawLine(2,6, 3, 5);
  428. g.drawLine(6,6,6,6);
  429. g.translate(-x, -y);
  430. }
  431. public int getIconWidth() {
  432. return iconSize;
  433. }
  434. public int getIconHeight() {
  435. return iconSize;
  436. }
  437. }
  438. // Internal Frame Close code
  439. private static class InternalFrameCloseIcon implements Icon, UIResource, Serializable {
  440. int iconSize = 16;
  441. public InternalFrameCloseIcon(int size) {
  442. iconSize = size;
  443. }
  444. public void paintIcon(Component c, Graphics g, int x, int y) {
  445. JButton parentButton = (JButton)c;
  446. ButtonModel buttonModel = parentButton.getModel();
  447. Color backgroundColor = MetalLookAndFeel.getPrimaryControl();
  448. Color internalBackgroundColor =
  449. MetalLookAndFeel.getPrimaryControl();
  450. Color mainItemColor =
  451. MetalLookAndFeel.getPrimaryControlDarkShadow();
  452. Color darkHighlightColor = MetalLookAndFeel.getBlack();
  453. Color xLightHighlightColor = MetalLookAndFeel.getWhite();
  454. Color boxLightHighlightColor = MetalLookAndFeel.getWhite();
  455. // if the inactive window
  456. if (parentButton.getClientProperty("paintActive") != Boolean.TRUE)
  457. {
  458. backgroundColor = MetalLookAndFeel.getControl();
  459. internalBackgroundColor = backgroundColor;
  460. mainItemColor = MetalLookAndFeel.getControlDarkShadow();
  461. // if inactive and pressed
  462. if (buttonModel.isPressed() && buttonModel.isArmed()) {
  463. internalBackgroundColor =
  464. MetalLookAndFeel.getControlShadow();
  465. xLightHighlightColor = internalBackgroundColor;
  466. mainItemColor = darkHighlightColor;
  467. }
  468. }
  469. // if pressed
  470. else if (buttonModel.isPressed() && buttonModel.isArmed()) {
  471. internalBackgroundColor =
  472. MetalLookAndFeel.getPrimaryControlShadow();
  473. xLightHighlightColor = internalBackgroundColor;
  474. mainItemColor = darkHighlightColor;
  475. // darkHighlightColor is still "getBlack()"
  476. }
  477. // Some calculations that are needed more than once later on.
  478. int oneHalf = (int)(iconSize / 2); // 16 -> 8
  479. g.translate(x, y);
  480. // fill background
  481. g.setColor(backgroundColor);
  482. g.fillRect(0,0, iconSize,iconSize);
  483. // fill inside of box area
  484. g.setColor(internalBackgroundColor);
  485. g.fillRect(3,3, iconSize-6,iconSize-6);
  486. // THE BOX
  487. // the top/left dark higlight - some of this will get overwritten
  488. g.setColor(darkHighlightColor);
  489. g.drawRect(1,1, iconSize-3,iconSize-3);
  490. // draw the inside bottom/right highlight
  491. g.drawRect(2,2, iconSize-5,iconSize-5);
  492. // draw the light/outside, bottom/right highlight
  493. g.setColor(boxLightHighlightColor);
  494. g.drawRect(2,2, iconSize-3,iconSize-3);
  495. // draw the "normal" box
  496. g.setColor(mainItemColor);
  497. g.drawRect(2,2, iconSize-4,iconSize-4);
  498. g.drawLine(3,iconSize-3, 3,iconSize-3); // lower left
  499. g.drawLine(iconSize-3,3, iconSize-3,3); // up right
  500. // THE "X"
  501. // Dark highlight
  502. g.setColor(darkHighlightColor);
  503. g.drawLine(4,5, 5,4); // far up left
  504. g.drawLine(4,iconSize-6, iconSize-6,4); // against body of "X"
  505. // Light highlight
  506. g.setColor(xLightHighlightColor);
  507. g.drawLine(6,iconSize-5, iconSize-5,6); // against body of "X"
  508. // one pixel over from the body
  509. g.drawLine(oneHalf,oneHalf+2, oneHalf+2,oneHalf);
  510. // bottom right
  511. g.drawLine(iconSize-5,iconSize-5, iconSize-4,iconSize-5);
  512. g.drawLine(iconSize-5,iconSize-4, iconSize-5,iconSize-4);
  513. // Main color
  514. g.setColor(mainItemColor);
  515. // Upper left to lower right
  516. g.drawLine(5,5, iconSize-6,iconSize-6); // g.drawLine(5,5, 10,10);
  517. g.drawLine(6,5, iconSize-5,iconSize-6); // g.drawLine(6,5, 11,10);
  518. g.drawLine(5,6, iconSize-6,iconSize-5); // g.drawLine(5,6, 10,11);
  519. // Lower left to upper right
  520. g.drawLine(5,iconSize-5, iconSize-5,5); // g.drawLine(5,11, 11,5);
  521. g.drawLine(5,iconSize-6, iconSize-6,5); // g.drawLine(5,10, 10,5);
  522. g.translate(-x, -y);
  523. }
  524. public int getIconWidth() {
  525. return iconSize;
  526. }
  527. public int getIconHeight() {
  528. return iconSize;
  529. }
  530. } // End class InternalFrameCloseIcon
  531. // Internal Frame Alternate Maximize code (actually, the un-maximize icon)
  532. private static class InternalFrameAltMaximizeIcon implements Icon, UIResource, Serializable {
  533. int iconSize = 16;
  534. public InternalFrameAltMaximizeIcon(int size) {
  535. iconSize = size;
  536. }
  537. public void paintIcon(Component c, Graphics g, int x, int y) {
  538. JButton parentButton = (JButton)c;
  539. ButtonModel buttonModel = parentButton.getModel();
  540. Color backgroundColor = MetalLookAndFeel.getPrimaryControl();
  541. Color internalBackgroundColor =
  542. MetalLookAndFeel.getPrimaryControl();
  543. Color mainItemColor =
  544. MetalLookAndFeel.getPrimaryControlDarkShadow();
  545. Color darkHighlightColor = MetalLookAndFeel.getBlack();
  546. // ul = Upper Left and lr = Lower Right
  547. Color ulLightHighlightColor = MetalLookAndFeel.getWhite();
  548. Color lrLightHighlightColor = MetalLookAndFeel.getWhite();
  549. // if the internal frame is inactive
  550. if (parentButton.getClientProperty("paintActive") != Boolean.TRUE)
  551. {
  552. backgroundColor = MetalLookAndFeel.getControl();
  553. internalBackgroundColor = backgroundColor;
  554. mainItemColor = MetalLookAndFeel.getControlDarkShadow();
  555. // if inactive and pressed
  556. if (buttonModel.isPressed() && buttonModel.isArmed()) {
  557. internalBackgroundColor =
  558. MetalLookAndFeel.getControlShadow();
  559. ulLightHighlightColor = internalBackgroundColor;
  560. mainItemColor = darkHighlightColor;
  561. }
  562. }
  563. // if the button is pressed and the mouse is over it
  564. else if (buttonModel.isPressed() && buttonModel.isArmed()) {
  565. internalBackgroundColor =
  566. MetalLookAndFeel.getPrimaryControlShadow();
  567. ulLightHighlightColor = internalBackgroundColor;
  568. mainItemColor = darkHighlightColor;
  569. // darkHighlightColor is still "getBlack()"
  570. }
  571. g.translate(x, y);
  572. // fill background
  573. g.setColor(backgroundColor);
  574. g.fillRect(0,0, iconSize,iconSize);
  575. // BOX
  576. // fill inside the box
  577. g.setColor(internalBackgroundColor);
  578. g.fillRect(3,6, iconSize-9,iconSize-9);
  579. // draw dark highlight color
  580. g.setColor(darkHighlightColor);
  581. g.drawRect(1,5, iconSize-8,iconSize-8);
  582. g.drawLine(1,iconSize-2, 1,iconSize-2); // extra pixel on bottom
  583. // draw lower right light highlight
  584. g.setColor(lrLightHighlightColor);
  585. g.drawRect(2,6, iconSize-7,iconSize-7);
  586. // draw upper left light highlight
  587. g.setColor(ulLightHighlightColor);
  588. g.drawRect(3,7, iconSize-9,iconSize-9);
  589. // draw the main box
  590. g.setColor(mainItemColor);
  591. g.drawRect(2,6, iconSize-8,iconSize-8);
  592. // Six extraneous pixels to deal with
  593. g.setColor(ulLightHighlightColor);
  594. g.drawLine(iconSize-6,8,iconSize-6,8);
  595. g.drawLine(iconSize-9,6, iconSize-7,8);
  596. g.setColor(mainItemColor);
  597. g.drawLine(3,iconSize-3,3,iconSize-3);
  598. g.setColor(darkHighlightColor);
  599. g.drawLine(iconSize-6,9,iconSize-6,9);
  600. g.setColor(backgroundColor);
  601. g.drawLine(iconSize-9,5,iconSize-9,5);
  602. // ARROW
  603. // do the shaft first
  604. g.setColor(mainItemColor);
  605. g.fillRect(iconSize-7,3, 3,5); // do a big block
  606. g.drawLine(iconSize-6,5, iconSize-3,2); // top shaft
  607. g.drawLine(iconSize-6,6, iconSize-2,2); // bottom shaft
  608. g.drawLine(iconSize-6,7, iconSize-3,7); // bottom arrow head
  609. // draw the dark highlight
  610. g.setColor(darkHighlightColor);
  611. g.drawLine(iconSize-8,2, iconSize-7,2); // top of arrowhead
  612. g.drawLine(iconSize-8,3, iconSize-8,7); // left of arrowhead
  613. g.drawLine(iconSize-6,4, iconSize-3,1); // top of shaft
  614. g.drawLine(iconSize-4,6, iconSize-3,6); // top,right of arrowhead
  615. // draw the light highlight
  616. g.setColor(lrLightHighlightColor);
  617. g.drawLine(iconSize-6,3, iconSize-6,3); // top
  618. g.drawLine(iconSize-4,5, iconSize-2,3); // under shaft
  619. g.drawLine(iconSize-4,8, iconSize-3,8); // under arrowhead
  620. g.drawLine(iconSize-2,8, iconSize-2,7); // right of arrowhead
  621. g.translate(-x, -y);
  622. }
  623. public int getIconWidth() {
  624. return iconSize;
  625. }
  626. public int getIconHeight() {
  627. return iconSize;
  628. }
  629. } // End class InternalFrameAltMaximizeIcon
  630. // Code for the default icons that goes in the upper left corner
  631. private static class InternalFrameDefaultMenuIcon implements Icon, UIResource, Serializable {
  632. public void paintIcon(Component c, Graphics g, int x, int y) {
  633. Color windowBodyColor = MetalLookAndFeel.getWindowBackground();
  634. Color titleColor = MetalLookAndFeel.getPrimaryControl();
  635. Color edgeColor = MetalLookAndFeel.getPrimaryControlDarkShadow();
  636. g.translate(x, y);
  637. // draw background color for title area
  638. // catch four corners and title area
  639. g.setColor(titleColor);
  640. g.fillRect(0,0, 16,16);
  641. // fill body of window
  642. g.setColor(windowBodyColor);
  643. g.fillRect(2,6, 13,9);
  644. // draw light parts of two "bumps"
  645. g.drawLine(2,2, 2,2);
  646. g.drawLine(5,2, 5,2);
  647. g.drawLine(8,2, 8,2);
  648. g.drawLine(11,2, 11,2);
  649. // draw line around edge of title and icon
  650. g.setColor(edgeColor);
  651. g.drawRect(1,1, 13,13); // entire inner edge
  652. g.drawLine(1,0, 14,0); // top outter edge
  653. g.drawLine(15,1, 15,14); // right outter edge
  654. g.drawLine(1,15, 14,15); // bottom outter edge
  655. g.drawLine(0,1, 0,14); // left outter edge
  656. g.drawLine(2,5, 13,5); // bottom of title bar area
  657. // draw dark part of four "bumps" (same color)
  658. g.drawLine(3,3, 3,3);
  659. g.drawLine(6,3, 6,3);
  660. g.drawLine(9,3, 9,3);
  661. g.drawLine(12,3, 12,3);
  662. g.translate(-x, -y);
  663. }
  664. public int getIconWidth() {
  665. return 16;
  666. }
  667. public int getIconHeight() {
  668. return 16;
  669. }
  670. } // End class InternalFrameDefaultMenuIcon
  671. // Internal Frame Maximize code
  672. private static class InternalFrameMaximizeIcon implements Icon, UIResource, Serializable {
  673. protected int iconSize = 16;
  674. public InternalFrameMaximizeIcon(int size) {
  675. iconSize = size;
  676. }
  677. public void paintIcon(Component c, Graphics g, int x, int y) {
  678. JButton parentButton = (JButton)c;
  679. ButtonModel buttonModel = parentButton.getModel();
  680. Color backgroundColor = MetalLookAndFeel.getPrimaryControl();
  681. Color internalBackgroundColor =
  682. MetalLookAndFeel.getPrimaryControl();
  683. Color mainItemColor =
  684. MetalLookAndFeel.getPrimaryControlDarkShadow();
  685. Color darkHighlightColor = MetalLookAndFeel.getBlack();
  686. // ul = Upper Left and lr = Lower Right
  687. Color ulLightHighlightColor = MetalLookAndFeel.getWhite();
  688. Color lrLightHighlightColor = MetalLookAndFeel.getWhite();
  689. // if the internal frame is inactive
  690. if (parentButton.getClientProperty("paintActive") != Boolean.TRUE)
  691. {
  692. backgroundColor = MetalLookAndFeel.getControl();
  693. internalBackgroundColor = backgroundColor;
  694. mainItemColor = MetalLookAndFeel.getControlDarkShadow();
  695. // if inactive and pressed
  696. if (buttonModel.isPressed() && buttonModel.isArmed()) {
  697. internalBackgroundColor =
  698. MetalLookAndFeel.getControlShadow();
  699. ulLightHighlightColor = internalBackgroundColor;
  700. mainItemColor = darkHighlightColor;
  701. }
  702. }
  703. // if the button is pressed and the mouse is over it
  704. else if (buttonModel.isPressed() && buttonModel.isArmed()) {
  705. internalBackgroundColor =
  706. MetalLookAndFeel.getPrimaryControlShadow();
  707. ulLightHighlightColor = internalBackgroundColor;
  708. mainItemColor = darkHighlightColor;
  709. // darkHighlightColor is still "getBlack()"
  710. }
  711. g.translate(x, y);
  712. // fill background
  713. g.setColor(backgroundColor);
  714. g.fillRect(0,0, iconSize,iconSize);
  715. // BOX drawing
  716. // fill inside the box
  717. g.setColor(internalBackgroundColor);
  718. g.fillRect(3,7, iconSize-10,iconSize-10);
  719. // light highlight
  720. g.setColor(ulLightHighlightColor);
  721. g.drawRect(3,7, iconSize-10,iconSize-10); // up,left
  722. g.setColor(lrLightHighlightColor);
  723. g.drawRect(2,6, iconSize-7,iconSize-7); // low,right
  724. // dark highlight
  725. g.setColor(darkHighlightColor);
  726. g.drawRect(1,5, iconSize-7,iconSize-7); // outer
  727. g.drawRect(2,6, iconSize-9,iconSize-9); // inner
  728. // main box
  729. g.setColor(mainItemColor);
  730. g.drawRect(2,6, iconSize-8,iconSize-8); // g.drawRect(2,6, 8,8);
  731. // ARROW drawing
  732. // dark highlight
  733. g.setColor(darkHighlightColor);
  734. // down,left to up,right - inside box
  735. g.drawLine(3,iconSize-5, iconSize-9,7);
  736. // down,left to up,right - outside box
  737. g.drawLine(iconSize-6,4, iconSize-5,3);
  738. // outside edge of arrow head
  739. g.drawLine(iconSize-7,1, iconSize-7,2);
  740. // outside edge of arrow head
  741. g.drawLine(iconSize-6,1, iconSize-2,1);
  742. // light highlight
  743. g.setColor(ulLightHighlightColor);
  744. // down,left to up,right - inside box
  745. g.drawLine(5,iconSize-4, iconSize-8,9);
  746. g.setColor(lrLightHighlightColor);
  747. g.drawLine(iconSize-6,3, iconSize-4,5); // outside box
  748. g.drawLine(iconSize-4,5, iconSize-4,6); // one down from this
  749. g.drawLine(iconSize-2,7, iconSize-1,7); // outside edge arrow head
  750. g.drawLine(iconSize-1,2, iconSize-1,6); // outside edge arrow head
  751. // main part of arrow
  752. g.setColor(mainItemColor);
  753. g.drawLine(3,iconSize-4, iconSize-3,2); // top edge of staff
  754. g.drawLine(3,iconSize-3, iconSize-2,2); // bottom edge of staff
  755. g.drawLine(4,iconSize-3, 5,iconSize-3); // highlights inside of box
  756. g.drawLine(iconSize-7,8, iconSize-7,9); // highlights inside of box
  757. g.drawLine(iconSize-6,2, iconSize-4,2); // top of arrow head
  758. g.drawRect(iconSize-3,3, 1,3); // right of arrow head
  759. g.translate(-x, -y);
  760. }
  761. public int getIconWidth() {
  762. return iconSize;
  763. }
  764. public int getIconHeight() {
  765. return iconSize;
  766. }
  767. } // End class InternalFrameMaximizeIcon
  768. // Internal Frame Minimize code
  769. private static class InternalFrameMinimizeIcon implements Icon, UIResource, Serializable {
  770. int iconSize = 16;
  771. public InternalFrameMinimizeIcon(int size) {
  772. iconSize = size;
  773. }
  774. public void paintIcon(Component c, Graphics g, int x, int y) {
  775. JButton parentButton = (JButton)c;
  776. ButtonModel buttonModel = parentButton.getModel();
  777. Color backgroundColor = MetalLookAndFeel.getPrimaryControl();
  778. Color internalBackgroundColor =
  779. MetalLookAndFeel.getPrimaryControl();
  780. Color mainItemColor =
  781. MetalLookAndFeel.getPrimaryControlDarkShadow();
  782. Color darkHighlightColor = MetalLookAndFeel.getBlack();
  783. // ul = Upper Left and lr = Lower Right
  784. Color ulLightHighlightColor = MetalLookAndFeel.getWhite();
  785. Color lrLightHighlightColor = MetalLookAndFeel.getWhite();
  786. // if the internal frame is inactive
  787. if (parentButton.getClientProperty("paintActive") != Boolean.TRUE)
  788. {
  789. backgroundColor = MetalLookAndFeel.getControl();
  790. internalBackgroundColor = backgroundColor;
  791. mainItemColor = MetalLookAndFeel.getControlDarkShadow();
  792. // if inactive and pressed
  793. if (buttonModel.isPressed() && buttonModel.isArmed()) {
  794. internalBackgroundColor =
  795. MetalLookAndFeel.getControlShadow();
  796. ulLightHighlightColor = internalBackgroundColor;
  797. mainItemColor = darkHighlightColor;
  798. }
  799. }
  800. // if the button is pressed and the mouse is over it
  801. else if (buttonModel.isPressed() && buttonModel.isArmed()) {
  802. internalBackgroundColor =
  803. MetalLookAndFeel.getPrimaryControlShadow();
  804. ulLightHighlightColor = internalBackgroundColor;
  805. mainItemColor = darkHighlightColor;
  806. // darkHighlightColor is still "getBlack()"
  807. }
  808. g.translate(x, y);
  809. // fill background
  810. g.setColor(backgroundColor);
  811. g.fillRect(0,0, iconSize,iconSize);
  812. // BOX drawing
  813. // fill inside the box
  814. g.setColor(internalBackgroundColor);
  815. g.fillRect(4,11, iconSize-13,iconSize-13);
  816. // light highlight
  817. g.setColor(lrLightHighlightColor);
  818. g.drawRect(2,10, iconSize-10,iconSize-11); // low,right
  819. g.setColor(ulLightHighlightColor);
  820. g.drawRect(3,10, iconSize-12,iconSize-12); // up,left
  821. // dark highlight
  822. g.setColor(darkHighlightColor);
  823. g.drawRect(1,8, iconSize-10,iconSize-10); // outer
  824. g.drawRect(2,9, iconSize-12,iconSize-12); // inner
  825. // main box
  826. g.setColor(mainItemColor);
  827. g.drawRect(2,9, iconSize-11,iconSize-11);
  828. g.drawLine(iconSize-10,10, iconSize-10,10); // up right highlight
  829. g.drawLine(3,iconSize-3, 3,iconSize-3); // low left highlight
  830. // ARROW
  831. // do the shaft first
  832. g.setColor(mainItemColor);
  833. g.fillRect(iconSize-7,3, 3,5); // do a big block
  834. g.drawLine(iconSize-6,5, iconSize-3,2); // top shaft
  835. g.drawLine(iconSize-6,6, iconSize-2,2); // bottom shaft
  836. g.drawLine(iconSize-6,7, iconSize-3,7); // bottom arrow head
  837. // draw the dark highlight
  838. g.setColor(darkHighlightColor);
  839. g.drawLine(iconSize-8,2, iconSize-7,2); // top of arrowhead
  840. g.drawLine(iconSize-8,3, iconSize-8,7); // left of arrowhead
  841. g.drawLine(iconSize-6,4, iconSize-3,1); // top of shaft
  842. g.drawLine(iconSize-4,6, iconSize-3,6); // top,right of arrowhead
  843. // draw the light highlight
  844. g.setColor(lrLightHighlightColor);
  845. g.drawLine(iconSize-6,3, iconSize-6,3); // top
  846. g.drawLine(iconSize-4,5, iconSize-2,3); // under shaft
  847. g.drawLine(iconSize-7,8, iconSize-3,8); // under arrowhead
  848. g.drawLine(iconSize-2,8, iconSize-2,7); // right of arrowhead
  849. g.translate(-x, -y);
  850. }
  851. public int getIconWidth() {
  852. return iconSize;
  853. }
  854. public int getIconHeight() {
  855. return iconSize;
  856. }
  857. } // End class InternalFrameMinimizeIcon
  858. private static class CheckBoxIcon implements Icon, UIResource, Serializable {
  859. protected int getControlSize() { return 13; }
  860. public void paintIcon(Component c, Graphics g, int x, int y) {
  861. JCheckBox cb = (JCheckBox)c;
  862. ButtonModel model = cb.getModel();
  863. int controlSize = getControlSize();
  864. boolean drawCheck = model.isSelected();
  865. if ( model.isEnabled() ) {
  866. if (model.isPressed() && model.isArmed()) {
  867. g.setColor( MetalLookAndFeel.getControlShadow() );
  868. g.fillRect( x, y, controlSize-1, controlSize-1);
  869. MetalUtils.drawPressed3DBorder(g, x, y, controlSize, controlSize);
  870. } else {
  871. MetalUtils.drawFlush3DBorder(g, x, y, controlSize, controlSize);
  872. }
  873. g.setColor( MetalLookAndFeel.getControlInfo() );
  874. } else {
  875. g.setColor( MetalLookAndFeel.getControlShadow() );
  876. g.drawRect( x, y, controlSize-2, controlSize-2);
  877. }
  878. if (model.isSelected()) {
  879. drawCheck(c,g,x,y);
  880. }
  881. }
  882. protected void drawCheck(Component c, Graphics g, int x, int y) {
  883. int controlSize = getControlSize();
  884. g.fillRect( x+3, y+5, 2, controlSize-8 );
  885. g.drawLine( x+(controlSize-4), y+3, x+5, y+(controlSize-6) );
  886. g.drawLine( x+(controlSize-4), y+4, x+5, y+(controlSize-5) );
  887. }
  888. public int getIconWidth() {
  889. return getControlSize();
  890. }
  891. public int getIconHeight() {
  892. return getControlSize();
  893. }
  894. } // End class CheckBoxIcon
  895. // Radio button code
  896. private static class RadioButtonIcon implements Icon, UIResource, Serializable {
  897. public void paintIcon(Component c, Graphics g, int x, int y) {
  898. JRadioButton rb = (JRadioButton)c;
  899. ButtonModel model = rb.getModel();
  900. boolean drawDot = model.isSelected();
  901. Color background = c.getBackground();
  902. Color dotColor = c.getForeground();
  903. Color shadow = MetalLookAndFeel.getControlShadow();
  904. Color darkCircle = MetalLookAndFeel.getControlDarkShadow();
  905. Color whiteInnerLeftArc = MetalLookAndFeel.getControlHighlight();
  906. Color whiteOuterRightArc = MetalLookAndFeel.getControlHighlight();
  907. Color interiorColor = background;
  908. // Set up colors per RadioButtonModel condition
  909. if ( !model.isEnabled() ) {
  910. whiteInnerLeftArc = whiteOuterRightArc = background;
  911. darkCircle = dotColor = shadow;
  912. }
  913. else if (model.isPressed() && model.isArmed() ) {
  914. whiteInnerLeftArc = interiorColor = shadow;
  915. }
  916. g.translate(x, y);
  917. // fill interior
  918. g.setColor(interiorColor);
  919. g.fillRect(2,2, 9,9);
  920. // draw Dark Circle (start at top, go clockwise)
  921. g.setColor(darkCircle);
  922. g.drawLine( 4, 0, 7, 0);
  923. g.drawLine( 8, 1, 9, 1);
  924. g.drawLine(10, 2, 10, 3);
  925. g.drawLine(11, 4, 11, 7);
  926. g.drawLine(10, 8, 10, 9);
  927. g.drawLine( 9,10, 8,10);
  928. g.drawLine( 7,11, 4,11);
  929. g.drawLine( 3,10, 2,10);
  930. g.drawLine( 1, 9, 1, 8);
  931. g.drawLine( 0, 7, 0, 4);
  932. g.drawLine( 1, 3, 1, 2);
  933. g.drawLine( 2, 1, 3, 1);
  934. // draw Inner Left (usually) White Arc
  935. // start at lower left corner, go clockwise
  936. g.setColor(whiteInnerLeftArc);
  937. g.drawLine( 2, 9, 2, 8);
  938. g.drawLine( 1, 7, 1, 4);
  939. g.drawLine( 2, 2, 2, 3);
  940. g.drawLine( 2, 2, 3, 2);
  941. g.drawLine( 4, 1, 7, 1);
  942. g.drawLine( 8, 2, 9, 2);
  943. // draw Outer Right White Arc
  944. // start at upper right corner, go clockwise
  945. g.setColor(whiteOuterRightArc);
  946. g.drawLine(10, 1, 10, 1);
  947. g.drawLine(11, 2, 11, 3);
  948. g.drawLine(12, 4, 12, 7);
  949. g.drawLine(11, 8, 11, 9);
  950. g.drawLine(10,10, 10,10);
  951. g.drawLine( 9,11, 8,11);
  952. g.drawLine( 7,12, 4,12);
  953. g.drawLine( 3,11, 2,11);
  954. // selected dot
  955. if ( drawDot ) {
  956. g.setColor(dotColor);
  957. g.fillRect( 4, 4, 4, 4);
  958. g.drawLine( 4, 3, 7, 3);
  959. g.drawLine( 8, 4, 8, 7);
  960. g.drawLine( 7, 8, 4, 8);
  961. g.drawLine( 3, 7, 3, 4);
  962. }
  963. g.translate(-x, -y);
  964. }
  965. public int getIconWidth() {
  966. return 13;
  967. }
  968. public int getIconHeight() {
  969. return 13;
  970. }
  971. } // End class RadioButtonIcon
  972. // Tree Computer Icon code
  973. private static class TreeComputerIcon implements Icon, UIResource, Serializable {
  974. public void paintIcon(Component c, Graphics g, int x, int y) {
  975. g.translate(x, y);
  976. // Fill glass portion of monitor
  977. g.setColor(MetalLookAndFeel.getPrimaryControl());
  978. g.fillRect(5,4, 6,4);
  979. // Draw outside edge of monitor
  980. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  981. g.drawLine( 2,2, 2,8); // left
  982. g.drawLine(13,2, 13,8); // right
  983. g.drawLine( 3,1, 12,1); // top
  984. g.drawLine(12,9, 12,9); // bottom right base
  985. g.drawLine( 3,9, 3,9); // bottom left base
  986. // Draw the edge of the glass
  987. g.drawLine( 4,4, 4,7); // left
  988. g.drawLine( 5,3, 10,3); // top
  989. g.drawLine(11,4, 11,7); // right
  990. g.drawLine( 5,8, 10,8); // bottom
  991. // Draw the edge of the CPU
  992. g.drawLine( 1,10, 14,10); // top
  993. g.drawLine(14,10, 14,14); // right
  994. g.drawLine( 1,14, 14,14); // bottom
  995. g.drawLine( 1,10, 1,14); // left
  996. // Draw the disk drives
  997. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  998. g.drawLine( 6,12, 8,12); // left
  999. g.drawLine(10,12, 12,12); // right
  1000. g.translate(-x, -y);
  1001. }
  1002. public int getIconWidth() {
  1003. return 16;
  1004. }
  1005. public int getIconHeight() {
  1006. return 16;
  1007. }
  1008. } // End class TreeComputerIcon
  1009. // Tree HardDrive Icon code
  1010. private static class TreeHardDriveIcon implements Icon, UIResource, Serializable {
  1011. public void paintIcon(Component c, Graphics g, int x, int y) {
  1012. g.translate(x, y);
  1013. // Draw edges of the disks
  1014. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  1015. // top disk
  1016. g.drawLine(1,4, 1,5); // left
  1017. g.drawLine(2,3, 3,3);
  1018. g.drawLine(4,2, 11,2); // top
  1019. g.drawLine(12,3, 13,3);
  1020. g.drawLine(14,4, 14,5); // right
  1021. g.drawLine(12,6, 13,6);
  1022. g.drawLine(4,7, 11,7); // bottom
  1023. g.drawLine(2,6, 3,6);
  1024. // middle disk
  1025. g.drawLine(1,7, 1,8); // left
  1026. g.drawLine(2,9, 3,9);
  1027. g.drawLine(4,10, 11,10); // bottom
  1028. g.drawLine(12,9, 13,9);
  1029. g.drawLine(14,7, 14, 8); // right
  1030. // bottom disk
  1031. g.drawLine(1,10, 1,11); // left
  1032. g.drawLine(2,12, 3,12);
  1033. g.drawLine(4,13, 11,13); // bottom
  1034. g.drawLine(12,12, 13,12);
  1035. g.drawLine(14,10, 14,11); // right
  1036. // Draw the down right shadows
  1037. g.setColor(MetalLookAndFeel.getControlShadow());
  1038. // top disk
  1039. g.drawLine(7,6, 7,6);
  1040. g.drawLine(9,6, 9,6);
  1041. g.drawLine(10,5, 10,5);
  1042. g.drawLine(11,6, 11,6);
  1043. g.drawLine(12,5, 13,5);
  1044. g.drawLine(13,4, 13,4);
  1045. // middle disk
  1046. g.drawLine(7,9, 7,9);
  1047. g.drawLine(9,9, 9,9);
  1048. g.drawLine(10,8, 10,8);
  1049. g.drawLine(11,9, 11,9);
  1050. g.drawLine(12,8, 13,8);
  1051. g.drawLine(13,7, 13,7);
  1052. // bottom disk
  1053. g.drawLine(7,12, 7,12);
  1054. g.drawLine(9,12, 9,12);
  1055. g.drawLine(10,11, 10,11);
  1056. g.drawLine(11,12, 11,12);
  1057. g.drawLine(12,11, 13,11);
  1058. g.drawLine(13,10, 13,10);
  1059. // Draw the up left highlight
  1060. g.setColor(MetalLookAndFeel.getControlHighlight());
  1061. // top disk
  1062. g.drawLine(4,3, 5,3);
  1063. g.drawLine(7,3, 9,3);
  1064. g.drawLine(11,3, 11,3);
  1065. g.drawLine(2,4, 6,4);
  1066. g.drawLine(8,4, 8,4);
  1067. g.drawLine(2,5, 3,5);
  1068. g.drawLine(4,6, 4,6);
  1069. // middle disk
  1070. g.drawLine(2,7, 3,7);
  1071. g.drawLine(2,8, 3,8);
  1072. g.drawLine(4,9, 4,9);
  1073. // bottom disk
  1074. g.drawLine(2,10, 3,10);
  1075. g.drawLine(2,11, 3,11);
  1076. g.drawLine(4,12, 4,12);
  1077. g.translate(-x, -y);
  1078. }
  1079. public int getIconWidth() {
  1080. return 16;
  1081. }
  1082. public int getIconHeight() {
  1083. return 16;
  1084. }
  1085. } // End class TreeHardDriveIcon
  1086. // Tree FloppyDrive Icon code
  1087. private static class TreeFloppyDriveIcon implements Icon, UIResource, Serializable {
  1088. public void paintIcon(Component c, Graphics g, int x, int y) {
  1089. g.translate(x, y);
  1090. // Fill body of floppy
  1091. g.setColor(MetalLookAndFeel.getPrimaryControl());
  1092. g.fillRect(2,2, 12,12);
  1093. // Draw outside edge of floppy
  1094. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  1095. g.drawLine( 1, 1, 13, 1); // top
  1096. g.drawLine(14, 2, 14,14); // right
  1097. g.drawLine( 1,14, 14,14); // bottom
  1098. g.drawLine( 1, 1, 1,14); // left
  1099. // Draw grey-ish highlights
  1100. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  1101. g.fillRect(5,2, 6,5); // metal disk protector part
  1102. g.drawLine(4,8, 11,8); // top of label
  1103. g.drawLine(3,9, 3,13); // left of label
  1104. g.drawLine(12,9, 12,13); // right of label
  1105. // Draw label and exposed disk
  1106. g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
  1107. g.fillRect(8,3, 2,3); // exposed disk
  1108. g.fillRect(4,9, 8,5); // label
  1109. // Draw text on label
  1110. g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
  1111. g.drawLine(5,10, 9,10);
  1112. g.drawLine(5,12, 8,12);
  1113. g.translate(-x, -y);
  1114. }
  1115. public int getIconWidth() {
  1116. return 16;
  1117. }
  1118. public int getIconHeight() {
  1119. return 16;
  1120. }
  1121. } // End class TreeFloppyDriveIcon
  1122. static private final Dimension folderIcon16Size = new Dimension( 16, 16 );
  1123. /**
  1124. * Utility class for caching icon images. This is necessary because
  1125. * we need a new image whenever we are rendering into a new
  1126. * GraphicsConfiguration, but we do not want to keep recreating icon
  1127. * images for GC's that we have already seen (for example,
  1128. * dragging a window back and forth between monitors on a multimon
  1129. * system, or drawing an icon to different Components that have different
  1130. * GC's).
  1131. * So now whenever we create a new icon image for a given GC, we
  1132. * cache that image with the GC for later retrieval.
  1133. */
  1134. static class ImageCacher {
  1135. Vector images = new Vector(1, 1);
  1136. ImageGcPair currentImageGcPair;
  1137. class ImageGcPair {
  1138. Image image;
  1139. GraphicsConfiguration gc;
  1140. ImageGcPair(Image image, GraphicsConfiguration gc) {
  1141. this.image = image;
  1142. this.gc = gc;
  1143. }
  1144. boolean hasSameConfiguration(GraphicsConfiguration newGC) {
  1145. if (((newGC != null) && (newGC.equals(gc))) ||
  1146. ((newGC == null) && (gc == null)))
  1147. {
  1148. return true;
  1149. }
  1150. return false;
  1151. }
  1152. }
  1153. Image getImage(GraphicsConfiguration newGC) {
  1154. if ((currentImageGcPair == null) ||
  1155. !(currentImageGcPair.hasSameConfiguration(newGC)))
  1156. {
  1157. Enumeration elements = images.elements();
  1158. while (elements.hasMoreElements()) {
  1159. ImageGcPair imgGcPair = (ImageGcPair)elements.nextElement();
  1160. if (imgGcPair.hasSameConfiguration(newGC)) {
  1161. currentImageGcPair = imgGcPair;
  1162. return imgGcPair.image;
  1163. }
  1164. }
  1165. return null;
  1166. }
  1167. return currentImageGcPair.image;
  1168. }
  1169. void cacheImage(Image image, GraphicsConfiguration gc) {
  1170. ImageGcPair imgGcPair = new ImageGcPair(image, gc);
  1171. images.addElement(imgGcPair);
  1172. currentImageGcPair = imgGcPair;
  1173. }
  1174. }
  1175. /**
  1176. * <p>
  1177. * <strong>Warning:</strong>
  1178. * Serialized objects of this class will not be compatible with
  1179. * future Swing releases. The current serialization support is
  1180. * appropriate for short term storage or RMI between applications running
  1181. * the same version of Swing. As of 1.4, support for long term storage
  1182. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  1183. * has been added to the <code>java.beans</code> package.
  1184. * Please see {@link java.beans.XMLEncoder}.
  1185. */
  1186. public static class FolderIcon16 implements Icon, Serializable {
  1187. ImageCacher imageCacher;
  1188. public void paintIcon(Component c, Graphics g, int x, int y) {
  1189. GraphicsConfiguration gc = c.getGraphicsConfiguration();
  1190. if (imageCacher == null) {
  1191. imageCacher = new ImageCacher();
  1192. }
  1193. Image image = imageCacher.getImage(gc);
  1194. if (image == null) {
  1195. if (gc != null) {
  1196. image = gc.createCompatibleImage(getIconWidth(),
  1197. getIconHeight(),
  1198. Transparency.BITMASK);
  1199. } else {
  1200. image = new BufferedImage(getIconWidth(),
  1201. getIconHeight(),
  1202. BufferedImage.TYPE_INT_ARGB);
  1203. }
  1204. Graphics imageG = image.getGraphics();
  1205. paintMe(c,imageG);
  1206. imageG.dispose();
  1207. imageCacher.cacheImage(image, gc);
  1208. }
  1209. g.drawImage(image, x, y+getShift(), null);
  1210. }
  1211. private void paintMe(Component c, Graphics g) {
  1212. int right = folderIcon16Size.width - 1;
  1213. int bottom = folderIcon16Size.height - 1;
  1214. // Draw tab top
  1215. g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
  1216. g.drawLine( right - 5, 3, right, 3 );
  1217. g.drawLine( right - 6, 4, right, 4 );
  1218. // Draw folder front
  1219. g.setColor( MetalLookAndFeel.getPrimaryControl() );
  1220. g.fillRect( 2, 7, 13, 8 );
  1221. // Draw tab bottom
  1222. g.setColor( MetalLookAndFeel.getPrimaryControlShadow() );
  1223. g.drawLine( right - 6, 5, right - 1, 5 );
  1224. // Draw outline
  1225. g.setColor( MetalLookAndFeel.getPrimaryControlInfo() );
  1226. g.drawLine( 0, 6, 0, bottom ); // left side
  1227. g.drawLine( 1, 5, right - 7, 5 ); // first part of top
  1228. g.drawLine( right - 6, 6, right - 1, 6 ); // second part of top
  1229. g.drawLine( right, 5, right, bottom ); // right side
  1230. g.drawLine( 0, bottom, right, bottom ); // bottom
  1231. // Draw highlight
  1232. g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
  1233. g.drawLine( 1, 6, 1, bottom - 1 );
  1234. g.drawLine( 1, 6, right - 7, 6 );
  1235. g.drawLine( right - 6, 7, right - 1, 7 );
  1236. }
  1237. public int getShift() { return 0; }
  1238. public int getAdditionalHeight() { return 0; }
  1239. public int getIconWidth() { return folderIcon16Size.width; }
  1240. public int getIconHeight() { return folderIcon16Size.height + getAdditionalHeight(); }
  1241. }
  1242. /**
  1243. * <p>
  1244. * <strong>Warning:</strong>
  1245. * Serialized objects of this class will not be compatible with
  1246. * future Swing releases. The current serialization support is
  1247. * appropriate for short term storage or RMI between applications running
  1248. * the same version of Swing. As of 1.4, support for long term storage
  1249. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  1250. * has been added to the <code>java.beans</code> package.
  1251. * Please see {@link java.beans.XMLEncoder}.
  1252. */
  1253. public static class TreeFolderIcon extends FolderIcon16 {
  1254. public int getShift() { return -1; }
  1255. public int getAdditionalHeight() { return 2; }
  1256. }
  1257. static private final Dimension fileIcon16Size = new Dimension( 16, 16 );
  1258. /**
  1259. * <p>
  1260. * <strong>Warning:</strong>
  1261. * Serialized objects of this class will not be compatible with
  1262. * future Swing releases. The current serialization support is
  1263. * appropriate for short term storage or RMI between applications running
  1264. * the same version of Swing. As of 1.4, support for long term storage
  1265. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  1266. * has been added to the <code>java.beans</code> package.
  1267. * Please see {@link java.beans.XMLEncoder}.
  1268. */
  1269. public static class FileIcon16 implements Icon, Serializable {
  1270. ImageCacher imageCacher;
  1271. public void paintIcon(Component c, Graphics g, int x, int y) {
  1272. GraphicsConfiguration gc = c.getGraphicsConfiguration();
  1273. if (imageCacher == null) {
  1274. imageCacher = new ImageCacher();
  1275. }
  1276. Image image = imageCacher.getImage(gc);
  1277. if (image == null) {
  1278. if (gc != null) {
  1279. image = gc.createCompatibleImage(getIconWidth(),
  1280. getIconHeight(),
  1281. Transparency.BITMASK);
  1282. } else {
  1283. image = new BufferedImage(getIconWidth(),
  1284. getIconHeight(),
  1285. BufferedImage.TYPE_INT_ARGB);
  1286. }
  1287. Graphics imageG = image.getGraphics();
  1288. paintMe(c,imageG);
  1289. imageG.dispose();
  1290. imageCacher.cacheImage(image, gc);
  1291. }
  1292. g.drawImage(image, x, y+getShift(), null);
  1293. }
  1294. private void paintMe(Component c, Graphics g) {
  1295. int right = fileIcon16Size.width - 1;
  1296. int bottom = fileIcon16Size.height - 1;
  1297. // Draw fill
  1298. g.setColor( MetalLookAndFeel.getWindowBackground() );
  1299. g.fillRect( 4, 2, 9, 12 );
  1300. // Draw frame
  1301. g.setColor( MetalLookAndFeel.getPrimaryControlInfo() );
  1302. g.drawLine( 2, 0, 2, bottom ); // left
  1303. g.drawLine( 2, 0, right - 4, 0 ); // top
  1304. g.drawLine( 2, bottom, right - 1, bottom ); // bottom
  1305. g.drawLine( right - 1, 6, right - 1, bottom ); // right
  1306. g.drawLine( right - 6, 2, right - 2, 6 ); // slant 1
  1307. g.drawLine( right - 5, 1, right - 4, 1 ); // part of slant 2
  1308. g.drawLine( right - 3, 2, right - 3, 3 ); // part of slant 2
  1309. g.drawLine( right - 2, 4, right - 2, 5 ); // part of slant 2
  1310. // Draw highlight
  1311. g.setColor( MetalLookAndFeel.getPrimaryControl() );
  1312. g.drawLine( 3, 1, 3, bottom - 1 ); // left
  1313. g.drawLine( 3, 1, right - 6, 1 ); // top
  1314. g.drawLine( right - 2, 7, right - 2, bottom - 1 ); // right
  1315. g.drawLine( right - 5, 2, right - 3, 4 ); // slant
  1316. g.drawLine( 3, bottom - 1, right - 2, bottom - 1 ); // bottom
  1317. }
  1318. public int getShift() { return 0; }
  1319. public int getAdditionalHeight() { return 0; }
  1320. public int getIconWidth() { return fileIcon16Size.width; }
  1321. public int getIconHeight() { return fileIcon16Size.height + getAdditionalHeight(); }
  1322. }
  1323. public static class TreeLeafIcon extends FileIcon16 {
  1324. public int getShift() { return 2; }
  1325. public int getAdditionalHeight() { return 4; }
  1326. }
  1327. static private final Dimension treeControlSize = new Dimension( 18, 18 );
  1328. /**
  1329. * <p>
  1330. * <strong>Warning:</strong>
  1331. * Serialized objects of this class will not be compatible with
  1332. * future Swing releases. The current serialization support is
  1333. * appropriate for short term storage or RMI between applications running
  1334. * the same version of Swing. As of 1.4, support for long term storage
  1335. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  1336. * has been added to the <code>java.beans</code> package.
  1337. * Please see {@link java.beans.XMLEncoder}.
  1338. */
  1339. public static class TreeControlIcon implements Icon, Serializable {
  1340. // This data member should not have been exposed. It's called
  1341. // isLight, but now it really means isCollapsed. Since we can't change
  1342. // any APIs... that's life.
  1343. protected boolean isLight;
  1344. public TreeControlIcon( boolean isCollapsed ) {
  1345. isLight = isCollapsed;
  1346. }
  1347. ImageCacher imageCacher;
  1348. transient boolean cachedOrientation = true;
  1349. public void paintIcon(Component c, Graphics g, int x, int y) {
  1350. GraphicsConfiguration gc = c.getGraphicsConfiguration();
  1351. if (imageCacher == null) {
  1352. imageCacher = new ImageCacher();
  1353. }
  1354. Image image = imageCacher.getImage(gc);
  1355. if (image == null || cachedOrientation != MetalUtils.isLeftToRight(c)) {
  1356. cachedOrientation = MetalUtils.isLeftToRight(c);
  1357. if (gc != null) {
  1358. image = gc.createCompatibleImage(getIconWidth(),
  1359. getIconHeight(),
  1360. Transparency.BITMASK);
  1361. } else {
  1362. image = new BufferedImage(getIconWidth(),
  1363. getIconHeight(),
  1364. BufferedImage.TYPE_INT_ARGB);
  1365. }
  1366. Graphics imageG = image.getGraphics();
  1367. paintMe(c,imageG,x,y);
  1368. imageG.dispose();
  1369. imageCacher.cacheImage(image, gc);
  1370. }
  1371. if (MetalUtils.isLeftToRight(c)) {
  1372. if (isLight) { // isCollapsed
  1373. g.drawImage(image, x+5, y+3, x+18, y+13,
  1374. 4,3, 17, 13, null);
  1375. }
  1376. else {
  1377. g.drawImage(image, x+5, y+3, x+18, y+17,
  1378. 4,3, 17, 17, null);
  1379. }
  1380. }
  1381. else {
  1382. if (isLight) { // isCollapsed
  1383. g.drawImage(image, x+3, y+3, x+16, y+13,
  1384. 4, 3, 17, 13, null);
  1385. }
  1386. else {
  1387. g.drawImage(image, x+3, y+3, x+16, y+17,
  1388. 4, 3, 17, 17, null);
  1389. }
  1390. }
  1391. }
  1392. public void paintMe(Component c, Graphics g, int x, int y) {
  1393. g.setColor( MetalLookAndFeel.getPrimaryControlInfo() );
  1394. int xoff = (MetalUtils.isLeftToRight(c)) ? 0 : 4;
  1395. // Draw circle
  1396. g.drawLine( xoff + 4, 6, xoff + 4, 9 ); // left
  1397. g.drawLine( xoff + 5, 5, xoff + 5, 5 ); // top left dot
  1398. g.drawLine( xoff + 6, 4, xoff + 9, 4 ); // top
  1399. g.drawLine( xoff + 10, 5, xoff + 10, 5 ); // top right dot
  1400. g.drawLine( xoff + 11, 6, xoff + 11, 9 ); // right
  1401. g.drawLine( xoff + 10, 10, xoff + 10, 10 ); // botom right dot
  1402. g.drawLine( xoff + 6, 11, xoff + 9, 11 ); // bottom
  1403. g.drawLine( xoff + 5, 10, xoff + 5, 10 ); // bottom left dot
  1404. // Draw Center Dot
  1405. g.drawLine( xoff + 7, 7, xoff + 8, 7 );
  1406. g.drawLine( xoff + 7, 8, xoff + 8, 8 );
  1407. // Draw Handle
  1408. if ( isLight ) { // isCollapsed
  1409. if( MetalUtils.isLeftToRight(c) ) {
  1410. g.drawLine( 12, 7, 15, 7 );
  1411. g.drawLine( 12, 8, 15, 8 );
  1412. // g.setColor( c.getBackground() );
  1413. // g.drawLine( 16, 7, 16, 8 );
  1414. }
  1415. else {
  1416. g.drawLine(4, 7, 7, 7);
  1417. g.drawLine(4, 8, 7, 8);
  1418. }
  1419. }
  1420. else {
  1421. g.drawLine( xoff + 7, 12, xoff + 7, 15 );
  1422. g.drawLine( xoff + 8, 12, xoff + 8, 15 );
  1423. // g.setColor( c.getBackground() );
  1424. // g.drawLine( xoff + 7, 16, xoff + 8, 16 );
  1425. }
  1426. // Draw Fill
  1427. g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
  1428. g.drawLine( xoff + 5, 6, xoff + 5, 9 ); // left shadow
  1429. g.drawLine( xoff + 6, 5, xoff + 9, 5 ); // top shadow
  1430. g.setColor( MetalLookAndFeel.getPrimaryControlShadow() );
  1431. g.drawLine( xoff + 6, 6, xoff + 6, 6 ); // top left fill
  1432. g.drawLine( xoff + 9, 6, xoff + 9, 6 ); // top right fill
  1433. g.drawLine( xoff + 6, 9, xoff + 6, 9 ); // bottom left fill
  1434. g.drawLine( xoff + 10, 6, xoff + 10, 9 ); // right fill
  1435. g.drawLine( xoff + 6, 10, xoff + 9, 10 ); // bottom fill
  1436. g.setColor( MetalLookAndFeel.getPrimaryControl() );
  1437. g.drawLine( xoff + 6, 7, xoff + 6, 8 ); // left highlight
  1438. g.drawLine( xoff + 7, 6, xoff + 8, 6 ); // top highlight
  1439. g.drawLine( xoff + 9, 7, xoff + 9, 7 ); // right highlight
  1440. g.drawLine( xoff + 7, 9, xoff + 7, 9 ); // bottom highlight
  1441. g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
  1442. g.drawLine( xoff + 8, 9, xoff + 9, 9 );
  1443. g.drawLine( xoff + 9, 8, xoff + 9, 8 );
  1444. }
  1445. public int getIconWidth() { return treeControlSize.width; }
  1446. public int getIconHeight() { return treeControlSize.height; }
  1447. }
  1448. //
  1449. // Menu Icons
  1450. //
  1451. static private final Dimension menuArrowIconSize = new Dimension( 4, 8 );
  1452. static private final Dimension menuCheckIconSize = new Dimension( 10, 10 );
  1453. static private final int xOff = 4;
  1454. private static class MenuArrowIcon implements Icon, UIResource, Serializable
  1455. {
  1456. public void paintIcon( Component c, Graphics g, int x, int y )
  1457. {
  1458. JMenuItem b = (JMenuItem) c;
  1459. ButtonModel model = b.getModel();
  1460. g.translate( x, y );
  1461. if ( !model.isEnabled() )
  1462. {
  1463. g.setColor( MetalLookAndFeel.getMenuDisabledForeground() );
  1464. }
  1465. else
  1466. {
  1467. if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) )
  1468. {
  1469. g.setColor( MetalLookAndFeel.getMenuSelectedForeground() );
  1470. }
  1471. else
  1472. {
  1473. g.setColor( b.getForeground() );
  1474. }
  1475. }
  1476. if( MetalUtils.isLeftToRight(b) ) {
  1477. g.drawLine( 0, 0, 0, 7 );
  1478. g.drawLine( 1, 1, 1, 6 );
  1479. g.drawLine( 2, 2, 2, 5 );
  1480. g.drawLine( 3, 3, 3, 4 );
  1481. } else {
  1482. g.drawLine( 4, 0, 4, 7 );
  1483. g.drawLine( 3, 1, 3, 6 );
  1484. g.drawLine( 2, 2, 2, 5 );
  1485. g.drawLine( 1, 3, 1, 4 );
  1486. }
  1487. g.translate( -x, -y );
  1488. }
  1489. public int getIconWidth() { return menuArrowIconSize.width; }
  1490. public int getIconHeight() { return menuArrowIconSize.height; }
  1491. } // End class MenuArrowIcon
  1492. private static class MenuItemArrowIcon implements Icon, UIResource, Serializable
  1493. {
  1494. public void paintIcon( Component c, Graphics g, int x, int y )
  1495. {
  1496. }
  1497. public int getIconWidth() { return menuArrowIconSize.width; }
  1498. public int getIconHeight() { return menuArrowIconSize.height; }
  1499. } // End class MenuItemArrowIcon
  1500. private static class CheckBoxMenuItemIcon implements Icon, UIResource, Serializable
  1501. {
  1502. public void paintIcon( Component c, Graphics g, int x, int y )
  1503. {
  1504. JMenuItem b = (JMenuItem) c;
  1505. ButtonModel model = b.getModel();
  1506. boolean isSelected = model.isSelected();
  1507. boolean isEnabled = model.isEnabled();
  1508. boolean isPressed = model.isPressed();
  1509. boolean isArmed = model.isArmed();
  1510. g.translate( x, y );
  1511. if ( isEnabled )
  1512. {
  1513. if ( isPressed || isArmed )
  1514. {
  1515. g.setColor( MetalLookAndFeel.getControlInfo() );
  1516. g.drawLine( 0, 0, 8, 0 );
  1517. g.drawLine( 0, 0, 0, 8 );
  1518. g.drawLine( 8, 2, 8, 8 );
  1519. g.drawLine( 2, 8, 8, 8 );
  1520. g.setColor( MetalLookAndFeel.getPrimaryControl() );
  1521. g.drawLine( 1, 1, 7, 1 );
  1522. g.drawLine( 1, 1, 1, 7 );
  1523. g.drawLine( 9, 1, 9, 9 );
  1524. g.drawLine( 1, 9, 9, 9 );
  1525. }
  1526. else
  1527. {
  1528. g.setColor( MetalLookAndFeel.getControlDarkShadow() );
  1529. g.drawLine( 0, 0, 8, 0 );
  1530. g.drawLine( 0, 0, 0, 8 );
  1531. g.drawLine( 8, 2, 8, 8 );
  1532. g.drawLine( 2, 8, 8, 8 );
  1533. g.setColor( MetalLookAndFeel.getControlHighlight() );
  1534. g.drawLine( 1, 1, 7, 1 );
  1535. g.drawLine( 1, 1, 1, 7 );
  1536. g.drawLine( 9, 1, 9, 9 );
  1537. g.drawLine( 1, 9, 9, 9 );
  1538. }
  1539. }
  1540. else
  1541. {
  1542. g.setColor( MetalLookAndFeel.getMenuDisabledForeground() );
  1543. g.drawRect( 0, 0, 8, 8 );
  1544. }
  1545. if ( isSelected )
  1546. {
  1547. if ( isEnabled )
  1548. {
  1549. if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) )
  1550. {
  1551. g.setColor( MetalLookAndFeel.getMenuSelectedForeground() );
  1552. }
  1553. else
  1554. {
  1555. g.setColor( b.getForeground() );
  1556. }
  1557. }
  1558. else
  1559. {
  1560. g.setColor( MetalLookAndFeel.getMenuDisabledForeground() );
  1561. }
  1562. g.drawLine( 2, 2, 2, 6 );
  1563. g.drawLine( 3, 2, 3, 6 );
  1564. g.drawLine( 4, 4, 8, 0 );
  1565. g.drawLine( 4, 5, 9, 0 );
  1566. }
  1567. g.translate( -x, -y );
  1568. }
  1569. public int getIconWidth() { return menuCheckIconSize.width; }
  1570. public int getIconHeight() { return menuCheckIconSize.height; }
  1571. } // End class CheckBoxMenuItemIcon
  1572. private static class RadioButtonMenuItemIcon implements Icon, UIResource, Serializable
  1573. {
  1574. public void paintIcon( Component c, Graphics g, int x, int y )
  1575. {
  1576. JMenuItem b = (JMenuItem) c;
  1577. ButtonModel model = b.getModel();
  1578. boolean isSelected = model.isSelected();
  1579. boolean isEnabled = model.isEnabled();
  1580. boolean isPressed = model.isPressed();
  1581. boolean isArmed = model.isArmed();
  1582. g.translate( x, y );
  1583. if ( isEnabled )
  1584. {
  1585. if ( isPressed || isArmed )
  1586. {
  1587. g.setColor( MetalLookAndFeel.getPrimaryControl() );
  1588. g.drawLine( 3, 1, 8, 1 );
  1589. g.drawLine( 2, 9, 7, 9 );
  1590. g.drawLine( 1, 3, 1, 8 );
  1591. g.drawLine( 9, 2, 9, 7 );
  1592. g.drawLine( 2, 2, 2, 2 );
  1593. g.drawLine( 8, 8, 8, 8 );
  1594. g.setColor( MetalLookAndFeel.getControlInfo() );
  1595. g.drawLine( 2, 0, 6, 0 );
  1596. g.drawLine( 2, 8, 6, 8 );
  1597. g.drawLine( 0, 2, 0, 6 );
  1598. g.drawLine( 8, 2, 8, 6 );
  1599. g.drawLine( 1, 1, 1, 1 );
  1600. g.drawLine( 7, 1, 7, 1 );
  1601. g.drawLine( 1, 7, 1, 7 );
  1602. g.drawLine( 7, 7, 7, 7 );
  1603. }
  1604. else
  1605. {
  1606. g.setColor( MetalLookAndFeel.getControlHighlight() );
  1607. g.drawLine( 3, 1, 8, 1 );
  1608. g.drawLine( 2, 9, 7, 9 );
  1609. g.drawLine( 1, 3, 1, 8 );
  1610. g.drawLine( 9, 2, 9, 7 );
  1611. g.drawLine( 2, 2, 2, 2 );
  1612. g.drawLine( 8, 8, 8, 8 );
  1613. g.setColor( MetalLookAndFeel.getControlDarkShadow() );
  1614. g.drawLine( 2, 0, 6, 0 );
  1615. g.drawLine( 2, 8, 6, 8 );
  1616. g.drawLine( 0, 2, 0, 6 );
  1617. g.drawLine( 8, 2, 8, 6 );
  1618. g.drawLine( 1, 1, 1, 1 );
  1619. g.drawLine( 7, 1, 7, 1 );
  1620. g.drawLine( 1, 7, 1, 7 );
  1621. g.drawLine( 7, 7, 7, 7 );
  1622. }
  1623. }
  1624. else
  1625. {
  1626. g.setColor( MetalLookAndFeel.getMenuDisabledForeground() );
  1627. g.drawLine( 2, 0, 6, 0 );
  1628. g.drawLine( 2, 8, 6, 8 );
  1629. g.drawLine( 0, 2, 0, 6 );
  1630. g.drawLine( 8, 2, 8, 6 );
  1631. g.drawLine( 1, 1, 1, 1 );
  1632. g.drawLine( 7, 1, 7, 1 );
  1633. g.drawLine( 1, 7, 1, 7 );
  1634. g.drawLine( 7, 7, 7, 7 );
  1635. }
  1636. if ( isSelected )
  1637. {
  1638. if ( isEnabled )
  1639. {
  1640. if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) )
  1641. {
  1642. g.setColor( MetalLookAndFeel.getMenuSelectedForeground() );
  1643. }
  1644. else
  1645. {
  1646. g.setColor( b.getForeground() );
  1647. }
  1648. }
  1649. else
  1650. {
  1651. g.setColor( MetalLookAndFeel.getMenuDisabledForeground() );
  1652. }
  1653. g.drawLine( 3, 2, 5, 2 );
  1654. g.drawLine( 2, 3, 6, 3 );
  1655. g.drawLine( 2, 4, 6, 4 );
  1656. g.drawLine( 2, 5, 6, 5 );
  1657. g.drawLine( 3, 6, 5, 6 );
  1658. }
  1659. g.translate( -x, -y );
  1660. }
  1661. public int getIconWidth() { return menuCheckIconSize.width; }
  1662. public int getIconHeight() { return menuCheckIconSize.height; }
  1663. } // End class RadioButtonMenuItemIcon
  1664. private static class VerticalSliderThumbIcon implements Icon, Serializable, UIResource {
  1665. protected static MetalBumps controlBumps;
  1666. protected static MetalBumps primaryBumps;
  1667. public VerticalSliderThumbIcon() {
  1668. controlBumps = new MetalBumps( 6, 10,
  1669. MetalLookAndFeel.getControlHighlight(),
  1670. MetalLookAndFeel.getControlInfo(),
  1671. MetalLookAndFeel.getControl() );
  1672. primaryBumps = new MetalBumps( 6, 10,
  1673. MetalLookAndFeel.getPrimaryControl(),
  1674. MetalLookAndFeel.getPrimaryControlDarkShadow(),
  1675. MetalLookAndFeel.getPrimaryControlShadow() );
  1676. }
  1677. public void paintIcon( Component c, Graphics g, int x, int y ) {
  1678. JSlider slider = (JSlider)c;
  1679. boolean leftToRight = MetalUtils.isLeftToRight(slider);
  1680. g.translate( x, y );
  1681. // Draw the frame
  1682. if ( slider.hasFocus() ) {
  1683. g.setColor( MetalLookAndFeel.getPrimaryControlInfo() );
  1684. }
  1685. else {
  1686. g.setColor( slider.isEnabled() ? MetalLookAndFeel.getPrimaryControlInfo() :
  1687. MetalLookAndFeel.getControlDarkShadow() );
  1688. }
  1689. if (leftToRight) {
  1690. g.drawLine( 1,0 , 8,0 ); // top
  1691. g.drawLine( 0,1 , 0,13 ); // left
  1692. g.drawLine( 1,14 , 8,14 ); // bottom
  1693. g.drawLine( 9,1 , 15,7 ); // top slant
  1694. g.drawLine( 9,13 , 15,7 ); // bottom slant
  1695. }
  1696. else {
  1697. g.drawLine( 7,0 , 14,0 ); // top
  1698. g.drawLine( 15,1 , 15,13 ); // right
  1699. g.drawLine( 7,14 , 14,14 ); // bottom
  1700. g.drawLine( 0,7 , 6,1 ); // top slant
  1701. g.drawLine( 0,7 , 6,13 ); // bottom slant
  1702. }
  1703. // Fill in the background
  1704. if ( slider.hasFocus() ) {
  1705. g.setColor( c.getForeground() );
  1706. }
  1707. else {
  1708. g.setColor( MetalLookAndFeel.getControl() );
  1709. }
  1710. if (leftToRight) {
  1711. g.fillRect( 1,1 , 8,13 );
  1712. g.drawLine( 9,2 , 9,12 );
  1713. g.drawLine( 10,3 , 10,11 );
  1714. g.drawLine( 11,4 , 11,10 );
  1715. g.drawLine( 12,5 , 12,9 );
  1716. g.drawLine( 13,6 , 13,8 );
  1717. g.drawLine( 14,7 , 14,7 );
  1718. }
  1719. else {
  1720. g.fillRect( 7,1, 8,13 );
  1721. g.drawLine( 6,3 , 6,12 );
  1722. g.drawLine( 5,4 , 5,11 );
  1723. g.drawLine( 4,5 , 4,10 );
  1724. g.drawLine( 3,6 , 3,9 );
  1725. g.drawLine( 2,7 , 2,8 );
  1726. }
  1727. // Draw the bumps
  1728. int offset = (leftToRight) ? 2 : 8;
  1729. if ( slider.isEnabled() ) {
  1730. if ( slider.hasFocus() ) {
  1731. primaryBumps.paintIcon( c, g, offset, 2 );
  1732. }
  1733. else {
  1734. controlBumps.paintIcon( c, g, offset, 2 );
  1735. }
  1736. }
  1737. // Draw the highlight
  1738. if ( slider.isEnabled() ) {
  1739. g.setColor( slider.hasFocus() ? MetalLookAndFeel.getPrimaryControl()
  1740. : MetalLookAndFeel.getControlHighlight() );
  1741. if (leftToRight) {
  1742. g.drawLine( 1, 1, 8, 1 );
  1743. g.drawLine( 1, 1, 1, 13 );
  1744. }
  1745. else {
  1746. g.drawLine( 8,1 , 14,1 ); // top
  1747. g.drawLine( 1,7 , 7,1 ); // top slant
  1748. }
  1749. }
  1750. g.translate( -x, -y );
  1751. }
  1752. public int getIconWidth() {
  1753. return 16;
  1754. }
  1755. public int getIconHeight() {
  1756. return 15;
  1757. }
  1758. }
  1759. private static class HorizontalSliderThumbIcon implements Icon, Serializable, UIResource {
  1760. protected static MetalBumps controlBumps;
  1761. protected static MetalBumps primaryBumps;
  1762. public HorizontalSliderThumbIcon() {
  1763. controlBumps = new MetalBumps( 10, 6,
  1764. MetalLookAndFeel.getControlHighlight(),
  1765. MetalLookAndFeel.getControlInfo(),
  1766. MetalLookAndFeel.getControl() );
  1767. primaryBumps = new MetalBumps( 10, 6,
  1768. MetalLookAndFeel.getPrimaryControl(),
  1769. MetalLookAndFeel.getPrimaryControlDarkShadow(),
  1770. MetalLookAndFeel.getPrimaryControlShadow() );
  1771. }
  1772. public void paintIcon( Component c, Graphics g, int x, int y ) {
  1773. JSlider slider = (JSlider)c;
  1774. g.translate( x, y );
  1775. // Draw the frame
  1776. if ( slider.hasFocus() ) {
  1777. g.setColor( MetalLookAndFeel.getPrimaryControlInfo() );
  1778. }
  1779. else {
  1780. g.setColor( slider.isEnabled() ? MetalLookAndFeel.getPrimaryControlInfo() :
  1781. MetalLookAndFeel.getControlDarkShadow() );
  1782. }
  1783. g.drawLine( 1,0 , 13,0 ); // top
  1784. g.drawLine( 0,1 , 0,8 ); // left
  1785. g.drawLine( 14,1 , 14,8 ); // right
  1786. g.drawLine( 1,9 , 7,15 ); // left slant
  1787. g.drawLine( 7,15 , 14,8 ); // right slant
  1788. // Fill in the background
  1789. if ( slider.hasFocus() ) {
  1790. g.setColor( c.getForeground() );
  1791. }
  1792. else {
  1793. g.setColor( MetalLookAndFeel.getControl() );
  1794. }
  1795. g.fillRect( 1,1, 13, 8 );
  1796. g.drawLine( 2,9 , 12,9 );
  1797. g.drawLine( 3,10 , 11,10 );
  1798. g.drawLine( 4,11 , 10,11 );
  1799. g.drawLine( 5,12 , 9,12 );
  1800. g.drawLine( 6,13 , 8,13 );
  1801. g.drawLine( 7,14 , 7,14 );
  1802. // Draw the bumps
  1803. if ( slider.isEnabled() ) {
  1804. if ( slider.hasFocus() ) {
  1805. primaryBumps.paintIcon( c, g, 2, 2 );
  1806. }
  1807. else {
  1808. controlBumps.paintIcon( c, g, 2, 2 );
  1809. }
  1810. }
  1811. // Draw the highlight
  1812. if ( slider.isEnabled() ) {
  1813. g.setColor( slider.hasFocus() ? MetalLookAndFeel.getPrimaryControl()
  1814. : MetalLookAndFeel.getControlHighlight() );
  1815. g.drawLine( 1, 1, 13, 1 );
  1816. g.drawLine( 1, 1, 1, 8 );
  1817. }
  1818. g.translate( -x, -y );
  1819. }
  1820. public int getIconWidth() {
  1821. return 15;
  1822. }
  1823. public int getIconHeight() {
  1824. return 16;
  1825. }
  1826. }
  1827. }