1 /* 2 * Copyright (c) 2001, 2002, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.swing.plaf.metal; 27 28 import javax.swing.plaf.*; 29 import javax.swing.plaf.basic.*; 30 import javax.swing.plaf.metal.*; 31 import javax.swing.*; 32 import javax.swing.border.*; 33 import java.awt.*; 34 35 /** 36 * A high contrast theme. This is used on Windows if the system property 37 * awt.highContrast.on is true. 38 * 39 * @author Michael C. Albers 40 */ 41 class MetalHighContrastTheme extends DefaultMetalTheme { 42 private static final ColorUIResource primary1 = new 43 ColorUIResource(0, 0, 0); 44 private static final ColorUIResource primary2 = new ColorUIResource( 45 204, 204, 204); 46 private static final ColorUIResource primary3 = new ColorUIResource(255, 47 255, 255); 48 private static final ColorUIResource primaryHighlight = new 49 ColorUIResource(102, 102, 102); 50 private static final ColorUIResource secondary2 = new ColorUIResource( 51 204, 204, 204); 52 private static final ColorUIResource secondary3 = new ColorUIResource( 53 255, 255, 255); 54 private static final ColorUIResource controlHighlight = new 55 ColorUIResource(102, 102, 102); 56 57 58 // This does not override getSecondary1 (102,102,102) 59 getName()60 public String getName() { 61 return "Contrast"; 62 } 63 getPrimary1()64 protected ColorUIResource getPrimary1() { 65 return primary1; 66 } 67 getPrimary2()68 protected ColorUIResource getPrimary2() { 69 return primary2; 70 } 71 getPrimary3()72 protected ColorUIResource getPrimary3() { 73 return primary3; 74 } 75 getPrimaryControlHighlight()76 public ColorUIResource getPrimaryControlHighlight() { 77 return primaryHighlight; 78 } 79 getSecondary2()80 protected ColorUIResource getSecondary2() { 81 return secondary2; 82 } 83 getSecondary3()84 protected ColorUIResource getSecondary3() { 85 return secondary3; 86 } 87 getControlHighlight()88 public ColorUIResource getControlHighlight() { 89 // This was super.getSecondary3(); 90 return secondary2; 91 } 92 getFocusColor()93 public ColorUIResource getFocusColor() { 94 return getBlack(); 95 } 96 getTextHighlightColor()97 public ColorUIResource getTextHighlightColor() { 98 return getBlack(); 99 } 100 getHighlightedTextColor()101 public ColorUIResource getHighlightedTextColor() { 102 return getWhite(); 103 } 104 getMenuSelectedBackground()105 public ColorUIResource getMenuSelectedBackground() { 106 return getBlack(); 107 } 108 getMenuSelectedForeground()109 public ColorUIResource getMenuSelectedForeground() { 110 return getWhite(); 111 } 112 getAcceleratorForeground()113 public ColorUIResource getAcceleratorForeground() { 114 return getBlack(); 115 } 116 getAcceleratorSelectedForeground()117 public ColorUIResource getAcceleratorSelectedForeground() { 118 return getWhite(); 119 } 120 addCustomEntriesToTable(UIDefaults table)121 public void addCustomEntriesToTable(UIDefaults table) { 122 Border blackLineBorder = new BorderUIResource(new LineBorder( 123 getBlack())); 124 Border whiteLineBorder = new BorderUIResource(new LineBorder( 125 getWhite())); 126 Object textBorder = new BorderUIResource(new CompoundBorder( 127 blackLineBorder, new BasicBorders.MarginBorder())); 128 129 Object[] defaults = new Object[] { 130 "ToolTip.border", blackLineBorder, 131 132 "TitledBorder.border", blackLineBorder, 133 134 "TextField.border", textBorder, 135 136 "PasswordField.border", textBorder, 137 138 "TextArea.border", textBorder, 139 140 "TextPane.border", textBorder, 141 142 "EditorPane.border", textBorder, 143 144 "ComboBox.background", getWindowBackground(), 145 "ComboBox.foreground", getUserTextColor(), 146 "ComboBox.selectionBackground", getTextHighlightColor(), 147 "ComboBox.selectionForeground", getHighlightedTextColor(), 148 149 "ProgressBar.foreground", getUserTextColor(), 150 "ProgressBar.background", getWindowBackground(), 151 "ProgressBar.selectionForeground", getWindowBackground(), 152 "ProgressBar.selectionBackground", getUserTextColor(), 153 154 "OptionPane.errorDialog.border.background", 155 getPrimary1(), 156 "OptionPane.errorDialog.titlePane.foreground", 157 getPrimary3(), 158 "OptionPane.errorDialog.titlePane.background", 159 getPrimary1(), 160 "OptionPane.errorDialog.titlePane.shadow", 161 getPrimary2(), 162 "OptionPane.questionDialog.border.background", 163 getPrimary1(), 164 "OptionPane.questionDialog.titlePane.foreground", 165 getPrimary3(), 166 "OptionPane.questionDialog.titlePane.background", 167 getPrimary1(), 168 "OptionPane.questionDialog.titlePane.shadow", 169 getPrimary2(), 170 "OptionPane.warningDialog.border.background", 171 getPrimary1(), 172 "OptionPane.warningDialog.titlePane.foreground", 173 getPrimary3(), 174 "OptionPane.warningDialog.titlePane.background", 175 getPrimary1(), 176 "OptionPane.warningDialog.titlePane.shadow", 177 getPrimary2(), 178 }; 179 180 table.putDefaults(defaults); 181 } 182 183 /** 184 * Returns true if this is a theme provided by the core platform. 185 */ isSystemTheme()186 boolean isSystemTheme() { 187 return (getClass() == MetalHighContrastTheme.class); 188 } 189 } 190