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