1. /*
  2. * @(#)MetalHighContrastTheme.java 1.4 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.plaf.metal;
  8. import javax.swing.plaf.*;
  9. import javax.swing.plaf.basic.*;
  10. import javax.swing.plaf.metal.*;
  11. import javax.swing.*;
  12. import javax.swing.border.*;
  13. import java.awt.*;
  14. /**
  15. * A high contrast theme. This is used on Windows if the system property
  16. * awt.highContrast.on is true.
  17. *
  18. * @version @(#)MetalHighContrastTheme.java 1.4 03/12/19
  19. * @author Michael C. Albers
  20. */
  21. class MetalHighContrastTheme extends DefaultMetalTheme {
  22. private static final ColorUIResource primary1 = new
  23. ColorUIResource(0, 0, 0);
  24. private static final ColorUIResource primary2 = new ColorUIResource(
  25. 204, 204, 204);
  26. private static final ColorUIResource primary3 = new ColorUIResource(255,
  27. 255, 255);
  28. private static final ColorUIResource primaryHighlight = new
  29. ColorUIResource(102, 102, 102);
  30. private static final ColorUIResource secondary2 = new ColorUIResource(
  31. 204, 204, 204);
  32. private static final ColorUIResource secondary3 = new ColorUIResource(
  33. 255, 255, 255);
  34. private static final ColorUIResource controlHighlight = new
  35. ColorUIResource(102, 102, 102);
  36. // This does not override getSecondary1 (102,102,102)
  37. public String getName() {
  38. return "Contrast";
  39. }
  40. protected ColorUIResource getPrimary1() {
  41. return primary1;
  42. }
  43. protected ColorUIResource getPrimary2() {
  44. return primary2;
  45. }
  46. protected ColorUIResource getPrimary3() {
  47. return primary3;
  48. }
  49. public ColorUIResource getPrimaryControlHighlight() {
  50. return primaryHighlight;
  51. }
  52. protected ColorUIResource getSecondary2() {
  53. return secondary2;
  54. }
  55. protected ColorUIResource getSecondary3() {
  56. return secondary3;
  57. }
  58. public ColorUIResource getControlHighlight() {
  59. // This was super.getSecondary3();
  60. return secondary2;
  61. }
  62. public ColorUIResource getFocusColor() {
  63. return getBlack();
  64. }
  65. public ColorUIResource getTextHighlightColor() {
  66. return getBlack();
  67. }
  68. public ColorUIResource getHighlightedTextColor() {
  69. return getWhite();
  70. }
  71. public ColorUIResource getMenuSelectedBackground() {
  72. return getBlack();
  73. }
  74. public ColorUIResource getMenuSelectedForeground() {
  75. return getWhite();
  76. }
  77. public ColorUIResource getAcceleratorForeground() {
  78. return getBlack();
  79. }
  80. public ColorUIResource getAcceleratorSelectedForeground() {
  81. return getWhite();
  82. }
  83. public void addCustomEntriesToTable(UIDefaults table) {
  84. Border blackLineBorder = new BorderUIResource(new LineBorder(
  85. getBlack()));
  86. Border whiteLineBorder = new BorderUIResource(new LineBorder(
  87. getWhite()));
  88. Object textBorder = new BorderUIResource(new CompoundBorder(
  89. blackLineBorder, new BasicBorders.MarginBorder()));
  90. Object[] defaults = new Object[] {
  91. "ToolTip.border", blackLineBorder,
  92. "TitledBorder.border", blackLineBorder,
  93. "TextField.border", textBorder,
  94. "PasswordField.border", textBorder,
  95. "TextArea.border", textBorder,
  96. "TextPane.border", textBorder,
  97. "EditorPane.border", textBorder,
  98. "ComboBox.background", getWindowBackground(),
  99. "ComboBox.foreground", getUserTextColor(),
  100. "ComboBox.selectionBackground", getTextHighlightColor(),
  101. "ComboBox.selectionForeground", getHighlightedTextColor(),
  102. "ProgressBar.foreground", getUserTextColor(),
  103. "ProgressBar.background", getWindowBackground(),
  104. "ProgressBar.selectionForeground", getWindowBackground(),
  105. "ProgressBar.selectionBackground", getUserTextColor(),
  106. "OptionPane.errorDialog.border.background",
  107. getPrimary1(),
  108. "OptionPane.errorDialog.titlePane.foreground",
  109. getPrimary3(),
  110. "OptionPane.errorDialog.titlePane.background",
  111. getPrimary1(),
  112. "OptionPane.errorDialog.titlePane.shadow",
  113. getPrimary2(),
  114. "OptionPane.questionDialog.border.background",
  115. getPrimary1(),
  116. "OptionPane.questionDialog.titlePane.foreground",
  117. getPrimary3(),
  118. "OptionPane.questionDialog.titlePane.background",
  119. getPrimary1(),
  120. "OptionPane.questionDialog.titlePane.shadow",
  121. getPrimary2(),
  122. "OptionPane.warningDialog.border.background",
  123. getPrimary1(),
  124. "OptionPane.warningDialog.titlePane.foreground",
  125. getPrimary3(),
  126. "OptionPane.warningDialog.titlePane.background",
  127. getPrimary1(),
  128. "OptionPane.warningDialog.titlePane.shadow",
  129. getPrimary2(),
  130. };
  131. table.putDefaults(defaults);
  132. }
  133. /**
  134. * Returns true if this is a theme provided by the core platform.
  135. */
  136. boolean isSystemTheme() {
  137. return (getClass() == MetalHighContrastTheme.class);
  138. }
  139. }