1 /* 2 * Copyright (c) 2018, 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import javax.swing.UIDefaults; 25 import javax.swing.border.Border; 26 import javax.swing.border.CompoundBorder; 27 import javax.swing.border.LineBorder; 28 import javax.swing.plaf.BorderUIResource; 29 import javax.swing.plaf.ColorUIResource; 30 import javax.swing.plaf.basic.BasicBorders; 31 import javax.swing.plaf.metal.DefaultMetalTheme; 32 33 /** 34 * This class describes a higher-contrast Metal Theme. 35 * 36 * @author Michael C. Albers 37 */ 38 39 public class ContrastTheme extends DefaultMetalTheme { 40 41 public static String NAME = "Contrast"; 42 getName()43 public String getName() { return NAME; } 44 45 private final ColorUIResource primary1 = new ColorUIResource(0, 0, 0); 46 private final ColorUIResource primary2 = new ColorUIResource(204, 204, 204); 47 private final ColorUIResource primary3 = new ColorUIResource(255, 255, 255); 48 private final ColorUIResource primaryHighlight = new ColorUIResource(102,102,102); 49 50 private final ColorUIResource secondary2 = new ColorUIResource(204, 204, 204); 51 private final ColorUIResource secondary3 = new ColorUIResource(255, 255, 255); 52 getPrimary1()53 protected ColorUIResource getPrimary1() { return primary1; } getPrimary2()54 protected ColorUIResource getPrimary2() { return primary2; } getPrimary3()55 protected ColorUIResource getPrimary3() { return primary3; } getPrimaryControlHighlight()56 public ColorUIResource getPrimaryControlHighlight() { return primaryHighlight;} 57 getSecondary2()58 protected ColorUIResource getSecondary2() { return secondary2; } getSecondary3()59 protected ColorUIResource getSecondary3() { return secondary3; } getControlHighlight()60 public ColorUIResource getControlHighlight() { return super.getSecondary3(); } 61 getFocusColor()62 public ColorUIResource getFocusColor() { return getBlack(); } 63 getTextHighlightColor()64 public ColorUIResource getTextHighlightColor() { return getBlack(); } getHighlightedTextColor()65 public ColorUIResource getHighlightedTextColor() { return getWhite(); } 66 getMenuSelectedBackground()67 public ColorUIResource getMenuSelectedBackground() { return getBlack(); } getMenuSelectedForeground()68 public ColorUIResource getMenuSelectedForeground() { return getWhite(); } getAcceleratorForeground()69 public ColorUIResource getAcceleratorForeground() { return getBlack(); } getAcceleratorSelectedForeground()70 public ColorUIResource getAcceleratorSelectedForeground() { return getWhite(); } 71 72 addCustomEntriesToTable(UIDefaults table)73 public void addCustomEntriesToTable(UIDefaults table) { 74 75 Border blackLineBorder = new BorderUIResource(new LineBorder( getBlack() )); 76 77 Object textBorder = new BorderUIResource( new CompoundBorder( 78 blackLineBorder, 79 new BasicBorders.MarginBorder())); 80 81 table.put( "ToolTip.border", blackLineBorder); 82 table.put( "TitledBorder.border", blackLineBorder); 83 84 table.put( "TextField.border", textBorder); 85 table.put( "PasswordField.border", textBorder); 86 table.put( "TextArea.border", textBorder); 87 table.put( "TextPane.border", textBorder); 88 table.put( "EditorPane.border", textBorder); 89 90 91 } 92 93 }