001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2008-2010 Sun Microsystems, Inc. 025 * Portions Copyright 2014-2015 ForgeRock AS 026 */ 027 028package org.opends.guitools.controlpanel.ui; 029 030 031import static com.forgerock.opendj.util.OperatingSystem.isWindows; 032import static com.forgerock.opendj.util.OperatingSystem.isMacOS; 033 034import java.awt.Color; 035import java.awt.Font; 036 037import javax.swing.JScrollPane; 038import javax.swing.UIManager; 039import javax.swing.border.Border; 040import javax.swing.plaf.metal.MetalBorders; 041 042import org.opends.guitools.controlpanel.util.Utilities; 043 044/** 045 * Class containing some Fonts and Colors used in the Control Panel. 046 * 047 */ 048public class ColorAndFontConstants 049{ 050 /** 051 * Foreground color (the color of normal text). 052 */ 053 public static final Color foreground = 054 UIManager.getColor("TextField.foreground"); 055 /** 056 * Background color (the color of the panels). 057 */ 058 public static final Color background; 059 private static Color toggleButtonColor; 060 /** 061 * The border to be used for a text area. 062 */ 063 public static final Border textAreaBorder; 064 static 065 { 066 Color bg = Color.white; 067 try 068 { 069 if (foreground.getGreen() + foreground.getRed() + foreground.getBlue() > 200 * 3) 070 { 071 // This is done to avoid problem in high contrast UIs 072 bg = UIManager.getColor("TextField.background"); 073 } 074 else 075 { 076 bg = Color.white; 077 } 078 toggleButtonColor = UIManager.getColor("ToggleButton.background"); 079 if (toggleButtonColor == null) 080 { 081 toggleButtonColor = new Color(200, 200, 200); 082 } 083 } 084 catch (Throwable t) 085 { 086 } 087 Border border = null; 088 try 089 { 090 JScrollPane scroll = new JScrollPane(); 091 border = scroll.getBorder(); 092 // If the border is of class MetalBorders$ScrollPaneBorder it cannot 093 // be used. 094 if (border instanceof MetalBorders.ScrollPaneBorder) 095 { 096 border = null; 097 } 098 } 099 catch (Throwable t) 100 { 101 border = null; 102 } 103 if (border == null) 104 { 105 border = new MetalBorders.Flush3DBorder(); 106 } 107 textAreaBorder = border; 108 background = bg; 109 } 110 /** 111 * The text color of buttons. 112 */ 113 public static final Color buttonForeground = 114 UIManager.getColor("Button.foreground"); 115 /** 116 * The text color of the category items. 117 */ 118 public static final Color categoryForeground = foreground; 119 /** 120 * The text color of the BasicExpander components. 121 */ 122 public static final Color expanderForeground = foreground; 123 /** 124 * The grey color background that is used for instance as background for the 125 * buttons in the dialogs (in the bottom of the dialogs). 126 */ 127 public static final Color greyBackground = isWindows() ? 128 UIManager.getColor("MenuBar.background") : 129 UIManager.getColor("Panel.background"); 130 131 /** 132 * The default border color. 133 */ 134 public static final Color defaultBorderColor = 135 Utilities.deriveColorHSB(toggleButtonColor, 0, 0, -.2f); 136 137 /** 138 * The grid color for the table. 139 */ 140 public static final Color gridColor = 141 isMacOS() ? defaultBorderColor : 142 UIManager.getColor("Table.gridColor"); 143 /** 144 * The color of the text in the table. 145 */ 146 public static final Color tableForeground = foreground; 147 /** 148 * The background color of the table. 149 */ 150 public static final Color tableBackground = background; 151 /** 152 * The text color of the tree. 153 */ 154 public static final Color treeForeground = foreground; 155 /** 156 * The background color of the tree. 157 */ 158 public static final Color treeBackground = background; 159 /** 160 * The color of the background when the mouse is over (this is used in some 161 * components, like the accordion components or some tables to have a visual 162 * hint that some components can be clicked). 163 */ 164 public static final Color mouseOverBackground = 165 UIManager.getColor("TextField.selectionBackground"); 166 /** 167 * Text color indicating that a field is valid. 168 */ 169 public static final Color validFontColor = foreground; 170 171 /** 172 * The color of the text when the mouse is over (this is used in some 173 * components, like the accordion components or some tables to have a visual 174 * hint that some components can be clicked). 175 */ 176 public static final Color mouseOverForeground = 177 UIManager.getColor("TextField.selectionForeground"); 178 /** 179 * The color of the background when the mouse is pressed (this is used in some 180 * components, like the accordion components or some tables to have a visual 181 * hint that some components can be clicked). 182 */ 183 public static final Color pressedBackground = 184 Utilities.deriveColorHSB(mouseOverBackground, 185 0, 0, -.20f); 186 /** 187 * The color of the text when the mouse is pressed (this is used in some 188 * components, like the accordion components or some tables to have a visual 189 * hint that some components can be clicked). 190 */ 191 public static final Color pressedForeground = 192 Utilities.deriveColorHSB(mouseOverForeground, 193 0, 0, +.20f); 194 195 /** 196 * The default font of the labels. 197 */ 198 public static final Font defaultFont = UIManager.getFont("Label.font"); 199 /** 200 * The font of the BasicExpander component. 201 */ 202 public static final Font expanderFont = defaultFont.deriveFont(Font.BOLD); 203 /** 204 * The in-line help font. 205 */ 206 public static final Font inlineHelpFont = defaultFont.deriveFont( 207 (float)(defaultFont.getSize() - 2)); 208 /** 209 * The font of the table header. 210 */ 211 public static final Font headerFont = 212 UIManager.getFont("TableHeader.font").deriveFont(Font.BOLD); 213 /** 214 * The font to be used in the title of the error panes. 215 */ 216 public static final Font errorTitleFont = 217 defaultFont.deriveFont(Font.BOLD).deriveFont(13f); 218 /** 219 * The font to be used in the CategoryButton component. 220 */ 221 public static final Font categoryFont = 222 UIManager.getFont("Label.font").deriveFont(Font.BOLD); 223 /** 224 * The top border of the accordion component. 225 */ 226 public static final Color topAccordionBorderColor = Utilities.deriveColorHSB( 227 toggleButtonColor, 0, 0, .2f); 228 /** 229 * The font to be used in primary labels. 230 */ 231 public static final Font primaryFont = defaultFont.deriveFont(Font.BOLD); 232 /** 233 * The font to be used in the tree. 234 */ 235 public static final Font treeFont = UIManager.getFont("Tree.font"); 236 /** 237 * The font to be used in the table. 238 */ 239 public static final Font tableFont = UIManager.getFont("Table.font"); 240 /** 241 * The font to be used in the title of the TitlePanel component. 242 */ 243 public static final Font titleFont = 244 defaultFont.deriveFont(Font.BOLD).deriveFont(14f); 245 /** 246 * Text color indicating that a field is not valid. 247 */ 248 public static final Color invalidFontColor = Color.red; 249 /** 250 * The font to be used when the field associated with a primary label is not 251 * valid. 252 */ 253 public static final Font primaryInvalidFont = 254 primaryFont.deriveFont(Font.ITALIC); 255 /** 256 * The font to be used when the field associated with a normal label is not 257 * valid. 258 */ 259 public static final Font invalidFont = defaultFont.deriveFont(Font.ITALIC); 260 /** 261 * The font to be used in the progress dialog's 'Details' section. 262 */ 263 public static final Font progressFont = UIManager.getFont("EditorPane.font"); 264 /** 265 * Specifies the font for the command-line output in the detail panel. 266 */ 267 public static final Font outputFont = Font.decode("Monospaced-PLAIN-12"); 268}