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