1. /*
  2. * @(#)MetalIconFactory.java 1.46 00/02/02
  3. *
  4. * Copyright 1998-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.swing.plaf.metal;
  11. import javax.swing.*;
  12. import javax.swing.plaf.UIResource;
  13. import java.awt.*;
  14. import java.awt.image.BufferedImage;
  15. import java.io.Serializable;
  16. /**
  17. * Factory object that can vend Icons appropriate for Metal.
  18. * These are used extensively in Metal via the defaults mechanism.
  19. * While other Look and Feels use GIFs for some of these, doing this
  20. * work in code facilitates things when switching to other Themes.
  21. * <p>
  22. * <strong>Warning:</strong>
  23. * Serialized objects of this class will not be compatible with
  24. * future Swing releases. The current serialization support is appropriate
  25. * for short term storage or RMI between applications running the same
  26. * version of Swing. A future release of Swing will provide support for
  27. * long term persistence.
  28. *
  29. * @version 1.46 02/02/00
  30. * @author Michael C. Albers
  31. */
  32. public class MetalIconFactory implements Serializable {
  33. // List of code-drawn Icons
  34. private static Icon fileChooserDetailViewIcon;
  35. private static Icon fileChooserHomeFolderIcon;
  36. private static Icon fileChooserListViewIcon;
  37. private static Icon fileChooserNewFolderIcon;
  38. private static Icon fileChooserUpFolderIcon;
  39. private static Icon internalFrameAltMaximizeIcon;
  40. private static Icon internalFrameCloseIcon;
  41. private static Icon internalFrameDefaultMenuIcon;
  42. private static Icon internalFrameMaximizeIcon;
  43. private static Icon internalFrameMinimizeIcon;
  44. private static Icon radioButtonIcon;
  45. private static Icon treeComputerIcon;
  46. private static Icon treeFloppyDriveIcon;
  47. private static Icon treeHardDriveIcon;
  48. private static Icon menuArrowIcon;
  49. private static Icon menuItemCheckIcon;
  50. private static Icon menuItemArrowIcon;
  51. private static Icon checkBoxMenuItemIcon;
  52. private static Icon radioButtonMenuItemIcon;
  53. private static Icon checkBoxIcon;
  54. // Constants
  55. public static final boolean DARK = false;
  56. public static final boolean LIGHT = true;
  57. // Accessor functions for Icons. Does the caching work.
  58. public static Icon getFileChooserDetailViewIcon() {
  59. if (fileChooserDetailViewIcon == null) {
  60. fileChooserDetailViewIcon = new FileChooserDetailViewIcon();
  61. }
  62. return fileChooserDetailViewIcon;
  63. }
  64. public static Icon getFileChooserHomeFolderIcon() {
  65. if (fileChooserHomeFolderIcon == null) {
  66. fileChooserHomeFolderIcon = new FileChooserHomeFolderIcon();
  67. }
  68. return fileChooserHomeFolderIcon;
  69. }
  70. public static Icon getFileChooserListViewIcon() {
  71. if (fileChooserListViewIcon == null) {
  72. fileChooserListViewIcon = new FileChooserListViewIcon();
  73. }
  74. return fileChooserListViewIcon;
  75. }
  76. public static Icon getFileChooserNewFolderIcon() {
  77. if (fileChooserNewFolderIcon == null) {
  78. fileChooserNewFolderIcon = new FileChooserNewFolderIcon();
  79. }
  80. return fileChooserNewFolderIcon;
  81. }
  82. public static Icon getFileChooserUpFolderIcon() {
  83. if (fileChooserUpFolderIcon == null) {
  84. fileChooserUpFolderIcon = new FileChooserUpFolderIcon();
  85. }
  86. return fileChooserUpFolderIcon;
  87. }
  88. public static Icon getInternalFrameAltMaximizeIcon(int size) {
  89. return new InternalFrameAltMaximizeIcon(size);
  90. }
  91. public static Icon getInternalFrameCloseIcon(int size) {
  92. return new InternalFrameCloseIcon(size);
  93. }
  94. public static Icon getInternalFrameDefaultMenuIcon() {
  95. if (internalFrameDefaultMenuIcon == null) {
  96. internalFrameDefaultMenuIcon = new InternalFrameDefaultMenuIcon();
  97. }
  98. return internalFrameDefaultMenuIcon;
  99. }
  100. public static Icon getInternalFrameMaximizeIcon(int size) {
  101. return new InternalFrameMaximizeIcon(size);
  102. }
  103. public static Icon getInternalFrameMinimizeIcon(int size) {
  104. return new InternalFrameMinimizeIcon(size);
  105. }
  106. public static Icon getRadioButtonIcon() {
  107. if (radioButtonIcon == null) {
  108. radioButtonIcon = new RadioButtonIcon();
  109. }
  110. return radioButtonIcon;
  111. }
  112. /**
  113. * Returns a checkbox icon
  114. * @since 1.3
  115. */
  116. public static Icon getCheckBoxIcon() {
  117. if (checkBoxIcon == null) {
  118. checkBoxIcon = new CheckBoxIcon();
  119. }
  120. return checkBoxIcon;
  121. }
  122. public static Icon getTreeComputerIcon() {
  123. if ( treeComputerIcon == null ) {
  124. treeComputerIcon = new TreeComputerIcon();
  125. }
  126. return treeComputerIcon;
  127. }
  128. public static Icon getTreeFloppyDriveIcon() {
  129. if ( treeFloppyDriveIcon == null ) {
  130. treeFloppyDriveIcon = new TreeFloppyDriveIcon();
  131. }
  132. return treeFloppyDriveIcon;
  133. }
  134. public static Icon getTreeFolderIcon() {
  135. return new TreeFolderIcon();
  136. }
  137. public static Icon getTreeHardDriveIcon() {
  138. if ( treeHardDriveIcon == null ) {
  139. treeHardDriveIcon = new TreeHardDriveIcon();
  140. }
  141. return treeHardDriveIcon;
  142. }
  143. public static Icon getTreeLeafIcon() {
  144. return new TreeLeafIcon();
  145. }
  146. public static Icon getTreeControlIcon( boolean isCollapsed ) {
  147. return new TreeControlIcon( isCollapsed );
  148. }
  149. public static Icon getMenuArrowIcon() {
  150. if (menuArrowIcon == null) {
  151. menuArrowIcon = new MenuArrowIcon();
  152. }
  153. return menuArrowIcon;
  154. }
  155. public static Icon getMenuItemCheckIcon() {
  156. if (menuItemCheckIcon == null) {
  157. menuItemCheckIcon = new MenuItemCheckIcon();
  158. }
  159. return menuItemCheckIcon;
  160. }
  161. public static Icon getMenuItemArrowIcon() {
  162. if (menuItemArrowIcon == null) {
  163. menuItemArrowIcon = new MenuItemArrowIcon();
  164. }
  165. return menuItemArrowIcon;
  166. }
  167. public static Icon getCheckBoxMenuItemIcon() {
  168. if (checkBoxMenuItemIcon == null) {
  169. checkBoxMenuItemIcon = new CheckBoxMenuItemIcon();
  170. }
  171. return checkBoxMenuItemIcon;
  172. }
  173. public static Icon getRadioButtonMenuItemIcon() {
  174. if (radioButtonMenuItemIcon == null) {
  175. radioButtonMenuItemIcon = new RadioButtonMenuItemIcon();
  176. }
  177. return radioButtonMenuItemIcon;
  178. }
  179. public static Icon getHorizontalSliderThumbIcon() {
  180. // don't cache these, bumps don't get updated otherwise
  181. return new HorizontalSliderThumbIcon();
  182. }
  183. public static Icon getVerticalSliderThumbIcon() {
  184. // don't cache these, bumps don't get updated otherwise
  185. return new VerticalSliderThumbIcon();
  186. }
  187. // File Chooser Detail View code
  188. private static class FileChooserDetailViewIcon implements Icon, UIResource, Serializable {
  189. public void paintIcon(Component c, Graphics g, int x, int y) {
  190. g.translate(x, y);
  191. // Draw outside edge of each of the documents
  192. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  193. // top
  194. g.drawLine(2,2, 5,2); // top
  195. g.drawLine(2,3, 2,7); // left
  196. g.drawLine(3,7, 6,7); // bottom
  197. g.drawLine(6,6, 6,3); // right
  198. // bottom
  199. g.drawLine(2,10, 5,10); // top
  200. g.drawLine(2,11, 2,15); // left
  201. g.drawLine(3,15, 6,15); // bottom
  202. g.drawLine(6,14, 6,11); // right
  203. // Draw little dots next to documents
  204. // Same color as outside edge
  205. g.drawLine(8,5, 15,5); // top
  206. g.drawLine(8,13, 15,13); // bottom
  207. // Draw inner highlight on documents
  208. g.setColor(MetalLookAndFeel.getPrimaryControl());
  209. g.drawRect(3,3, 2,3); // top
  210. g.drawRect(3,11, 2,3); // bottom
  211. // Draw inner inner highlight on documents
  212. g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
  213. g.drawLine(4,4, 4,5); // top
  214. g.drawLine(4,12, 4,13); // bottom
  215. g.translate(-x, -y);
  216. }
  217. public int getIconWidth() {
  218. return 18;
  219. }
  220. public int getIconHeight() {
  221. return 18;
  222. }
  223. } // End class FileChooserDetailViewIcon
  224. // File Chooser Home Folder code
  225. private static class FileChooserHomeFolderIcon implements Icon, UIResource, Serializable {
  226. public void paintIcon(Component c, Graphics g, int x, int y) {
  227. g.translate(x, y);
  228. // Draw outside edge of house
  229. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  230. g.drawLine(8,1, 1,8); // left edge of roof
  231. g.drawLine(8,1, 15,8); // right edge of roof
  232. g.drawLine(11,2, 11,3); // left edge of chimney
  233. g.drawLine(12,2, 12,4); // right edge of chimney
  234. g.drawLine(3,7, 3,15); // left edge of house
  235. g.drawLine(13,7, 13,15); // right edge of house
  236. g.drawLine(4,15, 12,15); // bottom edge of house
  237. // Draw door frame
  238. // same color as edge of house
  239. g.drawLine( 6,9, 6,14); // left
  240. g.drawLine(10,9, 10,14); // right
  241. g.drawLine( 7,9, 9, 9); // top
  242. // Draw roof body
  243. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  244. g.fillRect(8,2, 1,1); //top toward bottom
  245. g.fillRect(7,3, 3,1);
  246. g.fillRect(6,4, 5,1);
  247. g.fillRect(5,5, 7,1);
  248. g.fillRect(4,6, 9,2);
  249. // Draw doornob
  250. // same color as roof body
  251. g.drawLine(9,12, 9,12);
  252. // Paint the house
  253. g.setColor(MetalLookAndFeel.getPrimaryControl());
  254. g.drawLine(4,8, 12,8); // above door
  255. g.fillRect(4,9, 2,6); // left of door
  256. g.fillRect(11,9, 2,6); // right of door
  257. g.translate(-x, -y);
  258. }
  259. public int getIconWidth() {
  260. return 18;
  261. }
  262. public int getIconHeight() {
  263. return 18;
  264. }
  265. } // End class FileChooserHomeFolderIcon
  266. // File Chooser List View code
  267. private static class FileChooserListViewIcon implements Icon, UIResource, Serializable {
  268. public void paintIcon(Component c, Graphics g, int x, int y) {
  269. g.translate(x, y);
  270. // Draw outside edge of each of the documents
  271. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  272. // top left
  273. g.drawLine(2,2, 5,2); // top
  274. g.drawLine(2,3, 2,7); // left
  275. g.drawLine(3,7, 6,7); // bottom
  276. g.drawLine(6,6, 6,3); // right
  277. // top right
  278. g.drawLine(10,2, 13,2); // top
  279. g.drawLine(10,3, 10,7); // left
  280. g.drawLine(11,7, 14,7); // bottom
  281. g.drawLine(14,6, 14,3); // right
  282. // bottom left
  283. g.drawLine(2,10, 5,10); // top
  284. g.drawLine(2,11, 2,15); // left
  285. g.drawLine(3,15, 6,15); // bottom
  286. g.drawLine(6,14, 6,11); // right
  287. // bottom right
  288. g.drawLine(10,10, 13,10); // top
  289. g.drawLine(10,11, 10,15); // left
  290. g.drawLine(11,15, 14,15); // bottom
  291. g.drawLine(14,14, 14,11); // right
  292. // Draw little dots next to documents
  293. // Same color as outside edge
  294. g.drawLine(8,5, 8,5); // top left
  295. g.drawLine(16,5, 16,5); // top right
  296. g.drawLine(8,13, 8,13); // bottom left
  297. g.drawLine(16,13, 16,13); // bottom right
  298. // Draw inner highlight on documents
  299. g.setColor(MetalLookAndFeel.getPrimaryControl());
  300. g.drawRect(3,3, 2,3); // top left
  301. g.drawRect(11,3, 2,3); // top right
  302. g.drawRect(3,11, 2,3); // bottom left
  303. g.drawRect(11,11, 2,3); // bottom right
  304. // Draw inner inner highlight on documents
  305. g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
  306. g.drawLine(4,4, 4,5); // top left
  307. g.drawLine(12,4, 12,5); // top right
  308. g.drawLine(4,12, 4,13); // bottom left
  309. g.drawLine(12,12, 12,13); // bottom right
  310. g.translate(-x, -y);
  311. }
  312. public int getIconWidth() {
  313. return 18;
  314. }
  315. public int getIconHeight() {
  316. return 18;
  317. }
  318. } // End class FileChooserListViewIcon
  319. // File Chooser New Folder code
  320. private static class FileChooserNewFolderIcon implements Icon, UIResource, Serializable {
  321. public void paintIcon(Component c, Graphics g, int x, int y) {
  322. g.translate(x, y);
  323. // Fill background
  324. g.setColor(MetalLookAndFeel.getPrimaryControl());
  325. g.fillRect(3,5, 12,9);
  326. // Draw outside edge of folder
  327. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  328. g.drawLine(1,6, 1,14); // left
  329. g.drawLine(2,14, 15,14); // bottom
  330. g.drawLine(15,13, 15,5); // right
  331. g.drawLine(2,5, 9,5); // top left
  332. g.drawLine(10,6, 14,6); // top right
  333. // Draw inner folder highlight
  334. g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
  335. g.drawLine( 2,6, 2,13); // left
  336. g.drawLine( 3,6, 9,6); // top left
  337. g.drawLine(10,7, 14,7); // top right
  338. // Draw tab on folder
  339. g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
  340. g.drawLine(11,3, 15,3); // top
  341. g.drawLine(10,4, 15,4); // bottom
  342. g.translate(-x, -y);
  343. }
  344. public int getIconWidth() {
  345. return 18;
  346. }
  347. public int getIconHeight() {
  348. return 18;
  349. }
  350. } // End class FileChooserNewFolderIcon
  351. // File Chooser Up Folder code
  352. private static class FileChooserUpFolderIcon implements Icon, UIResource, Serializable {
  353. public void paintIcon(Component c, Graphics g, int x, int y) {
  354. g.translate(x, y);
  355. // Fill background
  356. g.setColor(MetalLookAndFeel.getPrimaryControl());
  357. g.fillRect(3,5, 12,9);
  358. // Draw outside edge of folder
  359. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  360. g.drawLine(1,6, 1,14); // left
  361. g.drawLine(2,14, 15,14); // bottom
  362. g.drawLine(15,13, 15,5); // right
  363. g.drawLine(2,5, 9,5); // top left
  364. g.drawLine(10,6, 14,6); // top right
  365. // Draw the UP arrow
  366. // same color as edge
  367. g.drawLine(8,13, 8,16); // arrow shaft
  368. g.drawLine(8, 9, 8, 9); // arrowhead top
  369. g.drawLine(7,10, 9,10);
  370. g.drawLine(6,11, 10,11);
  371. g.drawLine(5,12, 11,12);
  372. // Draw inner folder highlight
  373. g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
  374. g.drawLine( 2,6, 2,13); // left
  375. g.drawLine( 3,6, 9,6); // top left
  376. g.drawLine(10,7, 14,7); // top right
  377. // Draw tab on folder
  378. g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
  379. g.drawLine(11,3, 15,3); // top
  380. g.drawLine(10,4, 15,4); // bottom
  381. g.translate(-x, -y);
  382. }
  383. public int getIconWidth() {
  384. return 18;
  385. }
  386. public int getIconHeight() {
  387. return 18;
  388. }
  389. } // End class FileChooserUpFolderIcon
  390. /**
  391. * Defines an icon for Palette close
  392. * @since 1.3
  393. */
  394. public static class PaletteCloseIcon implements Icon, UIResource, Serializable{
  395. int iconSize = 7;
  396. public void paintIcon(Component c, Graphics g, int x, int y) {
  397. JButton parentButton = (JButton)c;
  398. ButtonModel buttonModel = parentButton.getModel();
  399. Color back;
  400. Color highlight = MetalLookAndFeel.getPrimaryControlHighlight();
  401. Color shadow = MetalLookAndFeel.getPrimaryControlInfo();
  402. if (buttonModel.isPressed() && buttonModel.isArmed()) {
  403. back = shadow;
  404. } else {
  405. back = MetalLookAndFeel.getPrimaryControlDarkShadow();
  406. }
  407. g.translate(x, y);
  408. g.setColor(back);
  409. g.drawLine( 0, 1, 5, 6);
  410. g.drawLine( 1, 0, 6, 5);
  411. g.drawLine( 1, 1, 6, 6);
  412. g.drawLine( 6, 1, 1, 6);
  413. g.drawLine( 5,0, 0,5);
  414. g.drawLine(5,1, 1,5);
  415. g.setColor(highlight);
  416. g.drawLine(6,2, 5,3);
  417. g.drawLine(2,6, 3, 5);
  418. g.drawLine(6,6,6,6);
  419. g.translate(-x, -y);
  420. }
  421. public int getIconWidth() {
  422. return iconSize;
  423. }
  424. public int getIconHeight() {
  425. return iconSize;
  426. }
  427. }
  428. // Internal Frame Close code
  429. private static class InternalFrameCloseIcon implements Icon, UIResource, Serializable {
  430. int iconSize = 16;
  431. public InternalFrameCloseIcon(int size) {
  432. iconSize = size;
  433. }
  434. public void paintIcon(Component c, Graphics g, int x, int y) {
  435. JButton parentButton = (JButton)c;
  436. ButtonModel buttonModel = parentButton.getModel();
  437. Color backgroundColor = MetalLookAndFeel.getPrimaryControl();
  438. Color internalBackgroundColor =
  439. MetalLookAndFeel.getPrimaryControl();
  440. Color mainItemColor =
  441. MetalLookAndFeel.getPrimaryControlDarkShadow();
  442. Color darkHighlightColor = MetalLookAndFeel.getBlack();
  443. Color xLightHighlightColor = MetalLookAndFeel.getWhite();
  444. Color boxLightHighlightColor = MetalLookAndFeel.getWhite();
  445. // if the inactive window
  446. if (parentButton.getClientProperty("paintActive") != Boolean.TRUE)
  447. {
  448. backgroundColor = MetalLookAndFeel.getControl();
  449. internalBackgroundColor = backgroundColor;
  450. mainItemColor = MetalLookAndFeel.getControlDarkShadow();
  451. // if inactive and pressed
  452. if (buttonModel.isPressed() && buttonModel.isArmed()) {
  453. internalBackgroundColor =
  454. MetalLookAndFeel.getControlShadow();
  455. xLightHighlightColor = internalBackgroundColor;
  456. mainItemColor = darkHighlightColor;
  457. }
  458. }
  459. // if pressed
  460. else if (buttonModel.isPressed() && buttonModel.isArmed()) {
  461. internalBackgroundColor =
  462. MetalLookAndFeel.getPrimaryControlShadow();
  463. xLightHighlightColor = internalBackgroundColor;
  464. mainItemColor = darkHighlightColor;
  465. // darkHighlightColor is still "getBlack()"
  466. }
  467. // Some calculations that are needed more than once later on.
  468. int oneHalf = (int)(iconSize / 2); // 16 -> 8
  469. g.translate(x, y);
  470. // fill background
  471. g.setColor(backgroundColor);
  472. g.fillRect(0,0, iconSize,iconSize);
  473. // fill inside of box area
  474. g.setColor(internalBackgroundColor);
  475. g.fillRect(3,3, iconSize-6,iconSize-6);
  476. // THE BOX
  477. // the top/left dark higlight - some of this will get overwritten
  478. g.setColor(darkHighlightColor);
  479. g.drawRect(1,1, iconSize-3,iconSize-3);
  480. // draw the inside bottom/right highlight
  481. g.drawRect(2,2, iconSize-5,iconSize-5);
  482. // draw the light/outside, bottom/right highlight
  483. g.setColor(boxLightHighlightColor);
  484. g.drawRect(2,2, iconSize-3,iconSize-3);
  485. // draw the "normal" box
  486. g.setColor(mainItemColor);
  487. g.drawRect(2,2, iconSize-4,iconSize-4);
  488. g.drawLine(3,iconSize-3, 3,iconSize-3); // lower left
  489. g.drawLine(iconSize-3,3, iconSize-3,3); // up right
  490. // THE "X"
  491. // Dark highlight
  492. g.setColor(darkHighlightColor);
  493. g.drawLine(4,5, 5,4); // far up left
  494. g.drawLine(4,iconSize-6, iconSize-6,4); // against body of "X"
  495. // Light highlight
  496. g.setColor(xLightHighlightColor);
  497. g.drawLine(6,iconSize-5, iconSize-5,6); // against body of "X"
  498. // one pixel over from the body
  499. g.drawLine(oneHalf,oneHalf+2, oneHalf+2,oneHalf);
  500. // bottom right
  501. g.drawLine(iconSize-5,iconSize-5, iconSize-4,iconSize-5);
  502. g.drawLine(iconSize-5,iconSize-4, iconSize-5,iconSize-4);
  503. // Main color
  504. g.setColor(mainItemColor);
  505. // Upper left to lower right
  506. g.drawLine(5,5, iconSize-6,iconSize-6); // g.drawLine(5,5, 10,10);
  507. g.drawLine(6,5, iconSize-5,iconSize-6); // g.drawLine(6,5, 11,10);
  508. g.drawLine(5,6, iconSize-6,iconSize-5); // g.drawLine(5,6, 10,11);
  509. // Lower left to upper right
  510. g.drawLine(5,iconSize-5, iconSize-5,5); // g.drawLine(5,11, 11,5);
  511. g.drawLine(5,iconSize-6, iconSize-6,5); // g.drawLine(5,10, 10,5);
  512. g.translate(-x, -y);
  513. }
  514. public int getIconWidth() {
  515. return iconSize;
  516. }
  517. public int getIconHeight() {
  518. return iconSize;
  519. }
  520. } // End class InternalFrameCloseIcon
  521. // Internal Frame Alternate Maximize code (actually, the un-maximize icon)
  522. private static class InternalFrameAltMaximizeIcon implements Icon, UIResource, Serializable {
  523. int iconSize = 16;
  524. public InternalFrameAltMaximizeIcon(int size) {
  525. iconSize = size;
  526. }
  527. public void paintIcon(Component c, Graphics g, int x, int y) {
  528. JButton parentButton = (JButton)c;
  529. ButtonModel buttonModel = parentButton.getModel();
  530. Color backgroundColor = MetalLookAndFeel.getPrimaryControl();
  531. Color internalBackgroundColor =
  532. MetalLookAndFeel.getPrimaryControl();
  533. Color mainItemColor =
  534. MetalLookAndFeel.getPrimaryControlDarkShadow();
  535. Color darkHighlightColor = MetalLookAndFeel.getBlack();
  536. // ul = Upper Left and lr = Lower Right
  537. Color ulLightHighlightColor = MetalLookAndFeel.getWhite();
  538. Color lrLightHighlightColor = MetalLookAndFeel.getWhite();
  539. // if the internal frame is inactive
  540. if (parentButton.getClientProperty("paintActive") != Boolean.TRUE)
  541. {
  542. backgroundColor = MetalLookAndFeel.getControl();
  543. internalBackgroundColor = backgroundColor;
  544. mainItemColor = MetalLookAndFeel.getControlDarkShadow();
  545. // if inactive and pressed
  546. if (buttonModel.isPressed() && buttonModel.isArmed()) {
  547. internalBackgroundColor =
  548. MetalLookAndFeel.getControlShadow();
  549. ulLightHighlightColor = internalBackgroundColor;
  550. mainItemColor = darkHighlightColor;
  551. }
  552. }
  553. // if the button is pressed and the mouse is over it
  554. else if (buttonModel.isPressed() && buttonModel.isArmed()) {
  555. internalBackgroundColor =
  556. MetalLookAndFeel.getPrimaryControlShadow();
  557. ulLightHighlightColor = internalBackgroundColor;
  558. mainItemColor = darkHighlightColor;
  559. // darkHighlightColor is still "getBlack()"
  560. }
  561. g.translate(x, y);
  562. // fill background
  563. g.setColor(backgroundColor);
  564. g.fillRect(0,0, iconSize,iconSize);
  565. // BOX
  566. // fill inside the box
  567. g.setColor(internalBackgroundColor);
  568. g.fillRect(3,6, iconSize-9,iconSize-9);
  569. // draw dark highlight color
  570. g.setColor(darkHighlightColor);
  571. g.drawRect(1,5, iconSize-8,iconSize-8);
  572. g.drawLine(1,iconSize-2, 1,iconSize-2); // extra pixel on bottom
  573. // draw lower right light highlight
  574. g.setColor(lrLightHighlightColor);
  575. g.drawRect(2,6, iconSize-7,iconSize-7);
  576. // draw upper left light highlight
  577. g.setColor(ulLightHighlightColor);
  578. g.drawRect(3,7, iconSize-9,iconSize-9);
  579. // draw the main box
  580. g.setColor(mainItemColor);
  581. g.drawRect(2,6, iconSize-8,iconSize-8);
  582. // Six extraneous pixels to deal with
  583. g.setColor(ulLightHighlightColor);
  584. g.drawLine(iconSize-6,8,iconSize-6,8);
  585. g.drawLine(iconSize-9,6, iconSize-7,8);
  586. g.setColor(mainItemColor);
  587. g.drawLine(3,iconSize-3,3,iconSize-3);
  588. g.setColor(darkHighlightColor);
  589. g.drawLine(iconSize-6,9,iconSize-6,9);
  590. g.setColor(backgroundColor);
  591. g.drawLine(iconSize-9,5,iconSize-9,5);
  592. // ARROW
  593. // do the shaft first
  594. g.setColor(mainItemColor);
  595. g.fillRect(iconSize-7,3, 3,5); // do a big block
  596. g.drawLine(iconSize-6,5, iconSize-3,2); // top shaft
  597. g.drawLine(iconSize-6,6, iconSize-2,2); // bottom shaft
  598. g.drawLine(iconSize-6,7, iconSize-3,7); // bottom arrow head
  599. // draw the dark highlight
  600. g.setColor(darkHighlightColor);
  601. g.drawLine(iconSize-8,2, iconSize-7,2); // top of arrowhead
  602. g.drawLine(iconSize-8,3, iconSize-8,7); // left of arrowhead
  603. g.drawLine(iconSize-6,4, iconSize-3,1); // top of shaft
  604. g.drawLine(iconSize-4,6, iconSize-3,6); // top,right of arrowhead
  605. // draw the light highlight
  606. g.setColor(lrLightHighlightColor);
  607. g.drawLine(iconSize-6,3, iconSize-6,3); // top
  608. g.drawLine(iconSize-4,5, iconSize-2,3); // under shaft
  609. g.drawLine(iconSize-4,8, iconSize-3,8); // under arrowhead
  610. g.drawLine(iconSize-2,8, iconSize-2,7); // right of arrowhead
  611. g.translate(-x, -y);
  612. }
  613. public int getIconWidth() {
  614. return iconSize;
  615. }
  616. public int getIconHeight() {
  617. return iconSize;
  618. }
  619. } // End class InternalFrameAltMaximizeIcon
  620. // Code for the default icons that goes in the upper left corner
  621. private static class InternalFrameDefaultMenuIcon implements Icon, UIResource, Serializable {
  622. public void paintIcon(Component c, Graphics g, int x, int y) {
  623. Color windowBodyColor = MetalLookAndFeel.getWindowBackground();
  624. Color titleColor = MetalLookAndFeel.getPrimaryControl();
  625. Color edgeColor = MetalLookAndFeel.getPrimaryControlDarkShadow();
  626. g.translate(x, y);
  627. // draw background color for title area
  628. // catch four corners and title area
  629. g.setColor(titleColor);
  630. g.fillRect(0,0, 16,16);
  631. // fill body of window
  632. g.setColor(windowBodyColor);
  633. g.fillRect(2,6, 13,9);
  634. // draw light parts of two "bumps"
  635. g.drawLine(2,2, 2,2);
  636. g.drawLine(5,2, 5,2);
  637. g.drawLine(8,2, 8,2);
  638. g.drawLine(11,2, 11,2);
  639. // draw line around edge of title and icon
  640. g.setColor(edgeColor);
  641. g.drawRect(1,1, 13,13); // entire inner edge
  642. g.drawLine(1,0, 14,0); // top outter edge
  643. g.drawLine(15,1, 15,14); // right outter edge
  644. g.drawLine(1,15, 14,15); // bottom outter edge
  645. g.drawLine(0,1, 0,14); // left outter edge
  646. g.drawLine(2,5, 13,5); // bottom of title bar area
  647. // draw dark part of four "bumps" (same color)
  648. g.drawLine(3,3, 3,3);
  649. g.drawLine(6,3, 6,3);
  650. g.drawLine(9,3, 9,3);
  651. g.drawLine(12,3, 12,3);
  652. g.translate(-x, -y);
  653. }
  654. public int getIconWidth() {
  655. return 16;
  656. }
  657. public int getIconHeight() {
  658. return 16;
  659. }
  660. } // End class InternalFrameDefaultMenuIcon
  661. // Internal Frame Maximize code
  662. private static class InternalFrameMaximizeIcon implements Icon, UIResource, Serializable {
  663. protected int iconSize = 16;
  664. public InternalFrameMaximizeIcon(int size) {
  665. iconSize = size;
  666. }
  667. public void paintIcon(Component c, Graphics g, int x, int y) {
  668. JButton parentButton = (JButton)c;
  669. ButtonModel buttonModel = parentButton.getModel();
  670. Color backgroundColor = MetalLookAndFeel.getPrimaryControl();
  671. Color internalBackgroundColor =
  672. MetalLookAndFeel.getPrimaryControl();
  673. Color mainItemColor =
  674. MetalLookAndFeel.getPrimaryControlDarkShadow();
  675. Color darkHighlightColor = MetalLookAndFeel.getBlack();
  676. // ul = Upper Left and lr = Lower Right
  677. Color ulLightHighlightColor = MetalLookAndFeel.getWhite();
  678. Color lrLightHighlightColor = MetalLookAndFeel.getWhite();
  679. // if the internal frame is inactive
  680. if (parentButton.getClientProperty("paintActive") != Boolean.TRUE)
  681. {
  682. backgroundColor = MetalLookAndFeel.getControl();
  683. internalBackgroundColor = backgroundColor;
  684. mainItemColor = MetalLookAndFeel.getControlDarkShadow();
  685. // if inactive and pressed
  686. if (buttonModel.isPressed() && buttonModel.isArmed()) {
  687. internalBackgroundColor =
  688. MetalLookAndFeel.getControlShadow();
  689. ulLightHighlightColor = internalBackgroundColor;
  690. mainItemColor = darkHighlightColor;
  691. }
  692. }
  693. // if the button is pressed and the mouse is over it
  694. else if (buttonModel.isPressed() && buttonModel.isArmed()) {
  695. internalBackgroundColor =
  696. MetalLookAndFeel.getPrimaryControlShadow();
  697. ulLightHighlightColor = internalBackgroundColor;
  698. mainItemColor = darkHighlightColor;
  699. // darkHighlightColor is still "getBlack()"
  700. }
  701. g.translate(x, y);
  702. // fill background
  703. g.setColor(backgroundColor);
  704. g.fillRect(0,0, iconSize,iconSize);
  705. // BOX drawing
  706. // fill inside the box
  707. g.setColor(internalBackgroundColor);
  708. g.fillRect(3,7, iconSize-10,iconSize-10);
  709. // light highlight
  710. g.setColor(ulLightHighlightColor);
  711. g.drawRect(3,7, iconSize-10,iconSize-10); // up,left
  712. g.setColor(lrLightHighlightColor);
  713. g.drawRect(2,6, iconSize-7,iconSize-7); // low,right
  714. // dark highlight
  715. g.setColor(darkHighlightColor);
  716. g.drawRect(1,5, iconSize-7,iconSize-7); // outer
  717. g.drawRect(2,6, iconSize-9,iconSize-9); // inner
  718. // main box
  719. g.setColor(mainItemColor);
  720. g.drawRect(2,6, iconSize-8,iconSize-8); // g.drawRect(2,6, 8,8);
  721. // ARROW drawing
  722. // dark highlight
  723. g.setColor(darkHighlightColor);
  724. // down,left to up,right - inside box
  725. g.drawLine(3,iconSize-5, iconSize-9,7);
  726. // down,left to up,right - outside box
  727. g.drawLine(iconSize-6,4, iconSize-5,3);
  728. // outside edge of arrow head
  729. g.drawLine(iconSize-7,1, iconSize-7,2);
  730. // outside edge of arrow head
  731. g.drawLine(iconSize-6,1, iconSize-2,1);
  732. // light highlight
  733. g.setColor(ulLightHighlightColor);
  734. // down,left to up,right - inside box
  735. g.drawLine(5,iconSize-4, iconSize-8,9);
  736. g.setColor(lrLightHighlightColor);
  737. g.drawLine(iconSize-6,3, iconSize-4,5); // outside box
  738. g.drawLine(iconSize-4,5, iconSize-4,6); // one down from this
  739. g.drawLine(iconSize-2,7, iconSize-1,7); // outside edge arrow head
  740. g.drawLine(iconSize-1,2, iconSize-1,6); // outside edge arrow head
  741. // main part of arrow
  742. g.setColor(mainItemColor);
  743. g.drawLine(3,iconSize-4, iconSize-3,2); // top edge of staff
  744. g.drawLine(3,iconSize-3, iconSize-2,2); // bottom edge of staff
  745. g.drawLine(4,iconSize-3, 5,iconSize-3); // highlights inside of box
  746. g.drawLine(iconSize-7,8, iconSize-7,9); // highlights inside of box
  747. g.drawLine(iconSize-6,2, iconSize-4,2); // top of arrow head
  748. g.drawRect(iconSize-3,3, 1,3); // right of arrow head
  749. g.translate(-x, -y);
  750. }
  751. public int getIconWidth() {
  752. return iconSize;
  753. }
  754. public int getIconHeight() {
  755. return iconSize;
  756. }
  757. } // End class InternalFrameMaximizeIcon
  758. // Internal Frame Minimize code
  759. private static class InternalFrameMinimizeIcon implements Icon, UIResource, Serializable {
  760. int iconSize = 16;
  761. public InternalFrameMinimizeIcon(int size) {
  762. iconSize = size;
  763. }
  764. public void paintIcon(Component c, Graphics g, int x, int y) {
  765. JButton parentButton = (JButton)c;
  766. ButtonModel buttonModel = parentButton.getModel();
  767. Color backgroundColor = MetalLookAndFeel.getPrimaryControl();
  768. Color internalBackgroundColor =
  769. MetalLookAndFeel.getPrimaryControl();
  770. Color mainItemColor =
  771. MetalLookAndFeel.getPrimaryControlDarkShadow();
  772. Color darkHighlightColor = MetalLookAndFeel.getBlack();
  773. // ul = Upper Left and lr = Lower Right
  774. Color ulLightHighlightColor = MetalLookAndFeel.getWhite();
  775. Color lrLightHighlightColor = MetalLookAndFeel.getWhite();
  776. // if the internal frame is inactive
  777. if (parentButton.getClientProperty("paintActive") != Boolean.TRUE)
  778. {
  779. backgroundColor = MetalLookAndFeel.getControl();
  780. internalBackgroundColor = backgroundColor;
  781. mainItemColor = MetalLookAndFeel.getControlDarkShadow();
  782. // if inactive and pressed
  783. if (buttonModel.isPressed() && buttonModel.isArmed()) {
  784. internalBackgroundColor =
  785. MetalLookAndFeel.getControlShadow();
  786. ulLightHighlightColor = internalBackgroundColor;
  787. mainItemColor = darkHighlightColor;
  788. }
  789. }
  790. // if the button is pressed and the mouse is over it
  791. else if (buttonModel.isPressed() && buttonModel.isArmed()) {
  792. internalBackgroundColor =
  793. MetalLookAndFeel.getPrimaryControlShadow();
  794. ulLightHighlightColor = internalBackgroundColor;
  795. mainItemColor = darkHighlightColor;
  796. // darkHighlightColor is still "getBlack()"
  797. }
  798. g.translate(x, y);
  799. // fill background
  800. g.setColor(backgroundColor);
  801. g.fillRect(0,0, iconSize,iconSize);
  802. // BOX drawing
  803. // fill inside the box
  804. g.setColor(internalBackgroundColor);
  805. g.fillRect(4,11, iconSize-13,iconSize-13);
  806. // light highlight
  807. g.setColor(lrLightHighlightColor);
  808. g.drawRect(2,10, iconSize-10,iconSize-11); // low,right
  809. g.setColor(ulLightHighlightColor);
  810. g.drawRect(3,10, iconSize-12,iconSize-12); // up,left
  811. // dark highlight
  812. g.setColor(darkHighlightColor);
  813. g.drawRect(1,8, iconSize-10,iconSize-10); // outer
  814. g.drawRect(2,9, iconSize-12,iconSize-12); // inner
  815. // main box
  816. g.setColor(mainItemColor);
  817. g.drawRect(2,9, iconSize-11,iconSize-11);
  818. g.drawLine(iconSize-10,10, iconSize-10,10); // up right highlight
  819. g.drawLine(3,iconSize-3, 3,iconSize-3); // low left highlight
  820. // ARROW
  821. // do the shaft first
  822. g.setColor(mainItemColor);
  823. g.fillRect(iconSize-7,3, 3,5); // do a big block
  824. g.drawLine(iconSize-6,5, iconSize-3,2); // top shaft
  825. g.drawLine(iconSize-6,6, iconSize-2,2); // bottom shaft
  826. g.drawLine(iconSize-6,7, iconSize-3,7); // bottom arrow head
  827. // draw the dark highlight
  828. g.setColor(darkHighlightColor);
  829. g.drawLine(iconSize-8,2, iconSize-7,2); // top of arrowhead
  830. g.drawLine(iconSize-8,3, iconSize-8,7); // left of arrowhead
  831. g.drawLine(iconSize-6,4, iconSize-3,1); // top of shaft
  832. g.drawLine(iconSize-4,6, iconSize-3,6); // top,right of arrowhead
  833. // draw the light highlight
  834. g.setColor(lrLightHighlightColor);
  835. g.drawLine(iconSize-6,3, iconSize-6,3); // top
  836. g.drawLine(iconSize-4,5, iconSize-2,3); // under shaft
  837. g.drawLine(iconSize-7,8, iconSize-3,8); // under arrowhead
  838. g.drawLine(iconSize-2,8, iconSize-2,7); // right of arrowhead
  839. g.translate(-x, -y);
  840. }
  841. public int getIconWidth() {
  842. return iconSize;
  843. }
  844. public int getIconHeight() {
  845. return iconSize;
  846. }
  847. } // End class InternalFrameMinimizeIcon
  848. private static class CheckBoxIcon implements Icon, UIResource, Serializable {
  849. protected int getControlSize() { return 13; }
  850. public void paintIcon(Component c, Graphics g, int x, int y) {
  851. JCheckBox cb = (JCheckBox)c;
  852. ButtonModel model = cb.getModel();
  853. int controlSize = getControlSize();
  854. boolean drawCheck = model.isSelected();
  855. if ( model.isEnabled() ) {
  856. if (model.isPressed() && model.isArmed()) {
  857. g.setColor( MetalLookAndFeel.getControlShadow() );
  858. g.fillRect( x, y, controlSize-1, controlSize-1);
  859. MetalUtils.drawPressed3DBorder(g, x, y, controlSize, controlSize);
  860. } else {
  861. MetalUtils.drawFlush3DBorder(g, x, y, controlSize, controlSize);
  862. }
  863. g.setColor( MetalLookAndFeel.getControlInfo() );
  864. } else {
  865. g.setColor( MetalLookAndFeel.getControlShadow() );
  866. g.drawRect( x, y, controlSize-1, controlSize-1);
  867. }
  868. if (model.isSelected()) {
  869. drawCheck(c,g,x,y);
  870. }
  871. }
  872. protected void drawCheck(Component c, Graphics g, int x, int y) {
  873. int controlSize = getControlSize();
  874. g.fillRect( x+3, y+5, 2, controlSize-8 );
  875. g.drawLine( x+(controlSize-4), y+3, x+5, y+(controlSize-6) );
  876. g.drawLine( x+(controlSize-4), y+4, x+5, y+(controlSize-5) );
  877. }
  878. public int getIconWidth() {
  879. return getControlSize();
  880. }
  881. public int getIconHeight() {
  882. return getControlSize();
  883. }
  884. } // End class CheckBoxIcon
  885. // Radio button code
  886. private static class RadioButtonIcon implements Icon, UIResource, Serializable {
  887. public void paintIcon(Component c, Graphics g, int x, int y) {
  888. JRadioButton rb = (JRadioButton)c;
  889. ButtonModel model = rb.getModel();
  890. boolean drawDot = model.isSelected();
  891. Color background = c.getBackground();
  892. Color dotColor = c.getForeground();
  893. Color shadow = MetalLookAndFeel.getControlShadow();
  894. Color darkCircle = MetalLookAndFeel.getControlDarkShadow();
  895. Color whiteInnerLeftArc = MetalLookAndFeel.getControlHighlight();
  896. Color whiteOuterRightArc = MetalLookAndFeel.getControlHighlight();
  897. Color interiorColor = background;
  898. // Set up colors per RadioButtonModel condition
  899. if ( !model.isEnabled() ) {
  900. whiteInnerLeftArc = whiteOuterRightArc = background;
  901. darkCircle = dotColor = shadow;
  902. }
  903. else if (model.isPressed() && model.isArmed() ) {
  904. whiteInnerLeftArc = interiorColor = shadow;
  905. }
  906. g.translate(x, y);
  907. // fill interior
  908. g.setColor(interiorColor);
  909. g.fillRect(2,2, 9,9);
  910. // draw Dark Circle (start at top, go clockwise)
  911. g.setColor(darkCircle);
  912. g.drawLine( 4, 0, 7, 0);
  913. g.drawLine( 8, 1, 9, 1);
  914. g.drawLine(10, 2, 10, 3);
  915. g.drawLine(11, 4, 11, 7);
  916. g.drawLine(10, 8, 10, 9);
  917. g.drawLine( 9,10, 8,10);
  918. g.drawLine( 7,11, 4,11);
  919. g.drawLine( 3,10, 2,10);
  920. g.drawLine( 1, 9, 1, 8);
  921. g.drawLine( 0, 7, 0, 4);
  922. g.drawLine( 1, 3, 1, 2);
  923. g.drawLine( 2, 1, 3, 1);
  924. // draw Inner Left (usually) White Arc
  925. // start at lower left corner, go clockwise
  926. g.setColor(whiteInnerLeftArc);
  927. g.drawLine( 2, 9, 2, 8);
  928. g.drawLine( 1, 7, 1, 4);
  929. g.drawLine( 2, 2, 2, 3);
  930. g.drawLine( 2, 2, 3, 2);
  931. g.drawLine( 4, 1, 7, 1);
  932. g.drawLine( 8, 2, 9, 2);
  933. // draw Outer Right White Arc
  934. // start at upper right corner, go clockwise
  935. g.setColor(whiteOuterRightArc);
  936. g.drawLine(10, 1, 10, 1);
  937. g.drawLine(11, 2, 11, 3);
  938. g.drawLine(12, 4, 12, 7);
  939. g.drawLine(11, 8, 11, 9);
  940. g.drawLine(10,10, 10,10);
  941. g.drawLine( 9,11, 8,11);
  942. g.drawLine( 7,12, 4,12);
  943. g.drawLine( 3,11, 2,11);
  944. // selected dot
  945. if ( drawDot ) {
  946. g.setColor(dotColor);
  947. g.fillRect( 4, 4, 4, 4);
  948. g.drawLine( 4, 3, 7, 3);
  949. g.drawLine( 8, 4, 8, 7);
  950. g.drawLine( 7, 8, 4, 8);
  951. g.drawLine( 3, 7, 3, 4);
  952. }
  953. g.translate(-x, -y);
  954. }
  955. public int getIconWidth() {
  956. return 13;
  957. }
  958. public int getIconHeight() {
  959. return 13;
  960. }
  961. } // End class RadioButtonIcon
  962. // Tree Computer Icon code
  963. private static class TreeComputerIcon implements Icon, UIResource, Serializable {
  964. public void paintIcon(Component c, Graphics g, int x, int y) {
  965. g.translate(x, y);
  966. // Fill glass portion of monitor
  967. g.setColor(MetalLookAndFeel.getPrimaryControl());
  968. g.fillRect(5,4, 6,4);
  969. // Draw outside edge of monitor
  970. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  971. g.drawLine( 2,2, 2,8); // left
  972. g.drawLine(13,2, 13,8); // right
  973. g.drawLine( 3,1, 12,1); // top
  974. g.drawLine(12,9, 12,9); // bottom right base
  975. g.drawLine( 3,9, 3,9); // bottom left base
  976. // Draw the edge of the glass
  977. g.drawLine( 4,4, 4,7); // left
  978. g.drawLine( 5,3, 10,3); // top
  979. g.drawLine(11,4, 11,7); // right
  980. g.drawLine( 5,8, 10,8); // bottom
  981. // Draw the edge of the CPU
  982. g.drawLine( 1,10, 14,10); // top
  983. g.drawLine(14,10, 14,14); // right
  984. g.drawLine( 1,14, 14,14); // bottom
  985. g.drawLine( 1,10, 1,14); // left
  986. // Draw the disk drives
  987. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  988. g.drawLine( 6,12, 8,12); // left
  989. g.drawLine(10,12, 12,12); // right
  990. g.translate(-x, -y);
  991. }
  992. public int getIconWidth() {
  993. return 16;
  994. }
  995. public int getIconHeight() {
  996. return 16;
  997. }
  998. } // End class TreeComputerIcon
  999. // Tree HardDrive Icon code
  1000. private static class TreeHardDriveIcon implements Icon, UIResource, Serializable {
  1001. public void paintIcon(Component c, Graphics g, int x, int y) {
  1002. g.translate(x, y);
  1003. // Draw edges of the disks
  1004. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  1005. // top disk
  1006. g.drawLine(1,4, 1,5); // left
  1007. g.drawLine(2,3, 3,3);
  1008. g.drawLine(4,2, 11,2); // top
  1009. g.drawLine(12,3, 13,3);
  1010. g.drawLine(14,4, 14,5); // right
  1011. g.drawLine(12,6, 13,6);
  1012. g.drawLine(4,7, 11,7); // bottom
  1013. g.drawLine(2,6, 3,6);
  1014. // middle disk
  1015. g.drawLine(1,7, 1,8); // left
  1016. g.drawLine(2,9, 3,9);
  1017. g.drawLine(4,10, 11,10); // bottom
  1018. g.drawLine(12,9, 13,9);
  1019. g.drawLine(14,7, 14, 8); // right
  1020. // bottom disk
  1021. g.drawLine(1,10, 1,11); // left
  1022. g.drawLine(2,12, 3,12);
  1023. g.drawLine(4,13, 11,13); // bottom
  1024. g.drawLine(12,12, 13,12);
  1025. g.drawLine(14,10, 14,11); // right
  1026. // Draw the down right shadows
  1027. g.setColor(MetalLookAndFeel.getControlShadow());
  1028. // top disk
  1029. g.drawLine(7,6, 7,6);
  1030. g.drawLine(9,6, 9,6);
  1031. g.drawLine(10,5, 10,5);
  1032. g.drawLine(11,6, 11,6);
  1033. g.drawLine(12,5, 13,5);
  1034. g.drawLine(13,4, 13,4);
  1035. // middle disk
  1036. g.drawLine(7,9, 7,9);
  1037. g.drawLine(9,9, 9,9);
  1038. g.drawLine(10,8, 10,8);
  1039. g.drawLine(11,9, 11,9);
  1040. g.drawLine(12,8, 13,8);
  1041. g.drawLine(13,7, 13,7);
  1042. // bottom disk
  1043. g.drawLine(7,12, 7,12);
  1044. g.drawLine(9,12, 9,12);
  1045. g.drawLine(10,11, 10,11);
  1046. g.drawLine(11,12, 11,12);
  1047. g.drawLine(12,11, 13,11);
  1048. g.drawLine(13,10, 13,10);
  1049. // Draw the up left highlight
  1050. g.setColor(MetalLookAndFeel.getControlHighlight());
  1051. // top disk
  1052. g.drawLine(4,3, 5,3);
  1053. g.drawLine(7,3, 9,3);
  1054. g.drawLine(11,3, 11,3);
  1055. g.drawLine(2,4, 6,4);
  1056. g.drawLine(8,4, 8,4);
  1057. g.drawLine(2,5, 3,5);
  1058. g.drawLine(4,6, 4,6);
  1059. // middle disk
  1060. g.drawLine(2,7, 3,7);
  1061. g.drawLine(2,8, 3,8);
  1062. g.drawLine(4,9, 4,9);
  1063. // bottom disk
  1064. g.drawLine(2,10, 3,10);
  1065. g.drawLine(2,11, 3,11);
  1066. g.drawLine(4,12, 4,12);
  1067. g.translate(-x, -y);
  1068. }
  1069. public int getIconWidth() {
  1070. return 16;
  1071. }
  1072. public int getIconHeight() {
  1073. return 16;
  1074. }
  1075. } // End class TreeHardDriveIcon
  1076. // Tree FloppyDrive Icon code
  1077. private static class TreeFloppyDriveIcon implements Icon, UIResource, Serializable {
  1078. public void paintIcon(Component c, Graphics g, int x, int y) {
  1079. g.translate(x, y);
  1080. // Fill body of floppy
  1081. g.setColor(MetalLookAndFeel.getPrimaryControl());
  1082. g.fillRect(2,2, 12,12);
  1083. // Draw outside edge of floppy
  1084. g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
  1085. g.drawLine( 1, 1, 13, 1); // top
  1086. g.drawLine(14, 2, 14,14); // right
  1087. g.drawLine( 1,14, 14,14); // bottom
  1088. g.drawLine( 1, 1, 1,14); // left
  1089. // Draw grey-ish highlights
  1090. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  1091. g.fillRect(5,2, 6,5); // metal disk protector part
  1092. g.drawLine(4,8, 11,8); // top of label
  1093. g.drawLine(3,9, 3,13); // left of label
  1094. g.drawLine(12,9, 12,13); // right of label
  1095. // Draw label and exposed disk
  1096. g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
  1097. g.fillRect(8,3, 2,3); // exposed disk
  1098. g.fillRect(4,9, 8,5); // label
  1099. // Draw text on label
  1100. g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
  1101. g.drawLine(5,10, 9,10);
  1102. g.drawLine(5,12, 8,12);
  1103. g.translate(-x, -y);
  1104. }
  1105. public int getIconWidth() {
  1106. return 16;
  1107. }
  1108. public int getIconHeight() {
  1109. return 16;
  1110. }
  1111. } // End class TreeFloppyDriveIcon
  1112. static private final Dimension folderIcon16Size = new Dimension( 16, 16 );
  1113. /**
  1114. * <p>
  1115. * <strong>Warning:</strong>
  1116. * Serialized objects of this class will not be compatible with
  1117. * future Swing releases. The current serialization support is appropriate
  1118. * for short term storage or RMI between applications running the same
  1119. * version of Swing. A future release of Swing will provide support for
  1120. * long term persistence.
  1121. */
  1122. public static class FolderIcon16 implements Icon, Serializable {
  1123. transient Image image;
  1124. public void paintIcon(Component c, Graphics g, int x, int y) {
  1125. if (image == null) {
  1126. image = new BufferedImage(getIconWidth(), getIconHeight(),
  1127. BufferedImage.TYPE_INT_ARGB);
  1128. Graphics imageG = image.getGraphics();
  1129. paintMe(c,imageG);
  1130. imageG.dispose();
  1131. }
  1132. g.drawImage(image, x, y+getShift(), null);
  1133. }
  1134. private void paintMe(Component c, Graphics g) {
  1135. int right = folderIcon16Size.width - 1;
  1136. int bottom = folderIcon16Size.height - 1;
  1137. // Draw tab top
  1138. g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
  1139. g.drawLine( right - 5, 3, right, 3 );
  1140. g.drawLine( right - 6, 4, right, 4 );
  1141. // Draw folder front
  1142. g.setColor( MetalLookAndFeel.getPrimaryControl() );
  1143. g.fillRect( 2, 7, 13, 8 );
  1144. // Draw tab bottom
  1145. g.setColor( MetalLookAndFeel.getPrimaryControlShadow() );
  1146. g.drawLine( right - 6, 5, right - 1, 5 );
  1147. // Draw outline
  1148. g.setColor( MetalLookAndFeel.getPrimaryControlInfo() );
  1149. g.drawLine( 0, 6, 0, bottom ); // left side
  1150. g.drawLine( 1, 5, right - 7, 5 ); // first part of top
  1151. g.drawLine( right - 6, 6, right - 1, 6 ); // second part of top
  1152. g.drawLine( right, 5, right, bottom ); // right side
  1153. g.drawLine( 0, bottom, right, bottom ); // bottom
  1154. // Draw highlight
  1155. g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
  1156. g.drawLine( 1, 6, 1, bottom - 1 );
  1157. g.drawLine( 1, 6, right - 7, 6 );
  1158. g.drawLine( right - 6, 7, right - 1, 7 );
  1159. }
  1160. public int getShift() { return 0; }
  1161. public int getAdditionalHeight() { return 0; }
  1162. public int getIconWidth() { return folderIcon16Size.width; }
  1163. public int getIconHeight() { return folderIcon16Size.height + getAdditionalHeight(); }
  1164. }
  1165. /**
  1166. * <p>
  1167. * <strong>Warning:</strong>
  1168. * Serialized objects of this class will not be compatible with
  1169. * future Swing releases. The current serialization support is appropriate
  1170. * for short term storage or RMI between applications running the same
  1171. * version of Swing. A future release of Swing will provide support for
  1172. * long term persistence.
  1173. */
  1174. public static class TreeFolderIcon extends FolderIcon16 {
  1175. public int getShift() { return -1; }
  1176. public int getAdditionalHeight() { return 2; }
  1177. }
  1178. static private final Dimension fileIcon16Size = new Dimension( 16, 16 );
  1179. /**
  1180. * <p>
  1181. * <strong>Warning:</strong>
  1182. * Serialized objects of this class will not be compatible with
  1183. * future Swing releases. The current serialization support is appropriate
  1184. * for short term storage or RMI between applications running the same
  1185. * version of Swing. A future release of Swing will provide support for
  1186. * long term persistence.
  1187. */
  1188. public static class FileIcon16 implements Icon, Serializable {
  1189. transient Image image;
  1190. public void paintIcon(Component c, Graphics g, int x, int y) {
  1191. if (image == null) {
  1192. image = new BufferedImage(getIconWidth(), getIconHeight(),
  1193. BufferedImage.TYPE_INT_ARGB);
  1194. Graphics imageG = image.getGraphics();
  1195. paintMe(c,imageG);
  1196. imageG.dispose();
  1197. }
  1198. g.drawImage(image, x, y+getShift(), null);
  1199. }
  1200. private void paintMe(Component c, Graphics g) {
  1201. int right = fileIcon16Size.width - 1;
  1202. int bottom = fileIcon16Size.height - 1;
  1203. // Draw fill
  1204. g.setColor( MetalLookAndFeel.getWindowBackground() );
  1205. g.fillRect( 4, 2, 9, 12 );
  1206. // Draw frame
  1207. g.setColor( MetalLookAndFeel.getPrimaryControlInfo() );
  1208. g.drawLine( 2, 0, 2, bottom ); // left
  1209. g.drawLine( 2, 0, right - 4, 0 ); // top
  1210. g.drawLine( 2, bottom, right - 1, bottom ); // bottom
  1211. g.drawLine( right - 1, 6, right - 1, bottom ); // right
  1212. g.drawLine( right - 6, 2, right - 2, 6 ); // slant 1
  1213. g.drawLine( right - 5, 1, right - 4, 1 ); // part of slant 2
  1214. g.drawLine( right - 3, 2, right - 3, 3 ); // part of slant 2
  1215. g.drawLine( right - 2, 4, right - 2, 5 ); // part of slant 2
  1216. // Draw highlight
  1217. g.setColor( MetalLookAndFeel.getPrimaryControl() );
  1218. g.drawLine( 3, 1, 3, bottom - 1 ); // left
  1219. g.drawLine( 3, 1, right - 6, 1 ); // top
  1220. g.drawLine( right - 2, 7, right - 2, bottom - 1 ); // right
  1221. g.drawLine( right - 5, 2, right - 3, 4 ); // slant
  1222. g.drawLine( 3, bottom - 1, right - 2, bottom - 1 ); // bottom
  1223. }
  1224. public int getShift() { return 0; }
  1225. public int getAdditionalHeight() { return 0; }
  1226. public int getIconWidth() { return fileIcon16Size.width; }
  1227. public int getIconHeight() { return fileIcon16Size.height + getAdditionalHeight(); }
  1228. }
  1229. public static class TreeLeafIcon extends FileIcon16 {
  1230. public int getShift() { return 2; }
  1231. public int getAdditionalHeight() { return 4; }
  1232. }
  1233. static private final Dimension treeControlSize = new Dimension( 18, 18 );
  1234. /**
  1235. * <p>
  1236. * <strong>Warning:</strong>
  1237. * Serialized objects of this class will not be compatible with
  1238. * future Swing releases. The current serialization support is appropriate
  1239. * for short term storage or RMI between applications running the same
  1240. * version of Swing. A future release of Swing will provide support for
  1241. * long term persistence.
  1242. */
  1243. public static class TreeControlIcon implements Icon, Serializable {
  1244. // This data member should not have been exposed. It's called
  1245. // isLight, but now it really means isCollapsed. Since we can't change
  1246. // any APIs... that's life.
  1247. protected boolean isLight;
  1248. public TreeControlIcon( boolean isCollapsed ) {
  1249. isLight = isCollapsed;
  1250. }
  1251. transient Image image;
  1252. transient boolean cachedOrientation = true;
  1253. public void paintIcon(Component c, Graphics g, int x, int y) {
  1254. if (image == null || cachedOrientation != MetalUtils.isLeftToRight(c)) {
  1255. cachedOrientation = MetalUtils.isLeftToRight(c);
  1256. image = new BufferedImage(getIconWidth(), getIconHeight(),
  1257. BufferedImage.TYPE_INT_ARGB);
  1258. Graphics imageG = image.getGraphics();
  1259. paintMe(c,imageG,x,y);
  1260. imageG.dispose();
  1261. }
  1262. if (MetalUtils.isLeftToRight(c)) {
  1263. if (isLight) { // isCollapsed
  1264. g.drawImage(image, x+5, y+3, x+18, y+13,
  1265. 4,3, 17, 13, null);
  1266. }
  1267. else {
  1268. g.drawImage(image, x+5, y+3, x+18, y+17,
  1269. 4,3, 17, 17, null);
  1270. }
  1271. }
  1272. else {
  1273. if (isLight) { // isCollapsed
  1274. g.drawImage(image, x+3, y+3, x+16, y+13,
  1275. 4, 3, 17, 13, null);
  1276. }
  1277. else {
  1278. g.drawImage(image, x+3, y+3, x+16, y+17,
  1279. 4, 3, 17, 17, null);
  1280. }
  1281. }
  1282. }
  1283. public void paintMe(Component c, Graphics g, int x, int y) {
  1284. g.setColor( MetalLookAndFeel.getPrimaryControlInfo() );
  1285. int xoff = (MetalUtils.isLeftToRight(c)) ? 0 : 4;
  1286. // Draw circle
  1287. g.drawLine( xoff + 4, 6, xoff + 4, 9 ); // left
  1288. g.drawLine( xoff + 5, 5, xoff + 5, 5 ); // top left dot
  1289. g.drawLine( xoff + 6, 4, xoff + 9, 4 ); // top
  1290. g.drawLine( xoff + 10, 5, xoff + 10, 5 ); // top right dot
  1291. g.drawLine( xoff + 11, 6, xoff + 11, 9 ); // right
  1292. g.drawLine( xoff + 10, 10, xoff + 10, 10 ); // botom right dot
  1293. g.drawLine( xoff + 6, 11, xoff + 9, 11 ); // bottom
  1294. g.drawLine( xoff + 5, 10, xoff + 5, 10 ); // bottom left dot
  1295. // Draw Center Dot
  1296. g.drawLine( xoff + 7, 7, xoff + 8, 7 );
  1297. g.drawLine( xoff + 7, 8, xoff + 8, 8 );
  1298. // Draw Handle
  1299. if ( isLight ) { // isCollapsed
  1300. if( MetalUtils.isLeftToRight(c) ) {
  1301. g.drawLine( 12, 7, 15, 7 );
  1302. g.drawLine( 12, 8, 15, 8 );
  1303. // g.setColor( c.getBackground() );
  1304. // g.drawLine( 16, 7, 16, 8 );
  1305. }
  1306. else {
  1307. g.drawLine(4, 7, 7, 7);
  1308. g.drawLine(4, 8, 7, 8);
  1309. }
  1310. }
  1311. else {
  1312. g.drawLine( xoff + 7, 12, xoff + 7, 15 );
  1313. g.drawLine( x