static void ensureValidCache() { LookAndFeel currentLookAndFeel = UIManager.getLookAndFeel(); if (currentLookAndFeel != cachedLookAndFeel) { clearLookAndFeelBasedCaches(); cachedLookAndFeel = currentLookAndFeel; } }
/** * Lazily checks and answers whether the Aqua look&feel is active. * * @return {@code true} if the current look&feel is Aqua */ public static boolean isLafAqua() { ensureValidCache(); if (cachedIsLafAqua == null) { cachedIsLafAqua = Boolean.valueOf(computeIsLafAqua()); } return cachedIsLafAqua.booleanValue(); }
/** * Lazily checks and answers whether the Aqua look&feel is active. * * @return {@code true} if the current look&feel is Aqua * * @deprecated Replaced by {@link FormUtils#isLafAqua()}. */ public static boolean isLafAqua() { return FormUtils.isLafAqua(); }
/** * Lazily creates and returns a fallback for the dialog font * that is used to compute the dialog base units. * This fallback font is cached and will be reset if the L&F changes. * * @return the cached fallback font used to compute the dialog base units */ private Font getCachedDefaultDialogFont() { FormUtils.ensureValidCache(); if (cachedDefaultDialogFont == null) { cachedDefaultDialogFont = lookupDefaultDialogFont(); } return cachedDefaultDialogFont; }
/** * Parses the encoded row specifications and returns a RowSpec object * that represents the string. Variables are expanded using the given * LayoutMap. * * @param encodedRowSpec the encoded column specification * @param layoutMap expands layout row variables * * @return a RowSpec instance for the given specification * @throws NullPointerException if {@code encodedRowSpec} or * {@code layoutMap} is {@code null} * * @see #decodeSpecs(String, LayoutMap) * * @since 1.2 */ public static RowSpec decode(String encodedRowSpec, LayoutMap layoutMap) { FormUtils.assertNotBlank(encodedRowSpec, "encoded row specification"); FormUtils.assertNotNull(layoutMap, "LayoutMap"); String trimmed = encodedRowSpec.trim(); String lower = trimmed.toLowerCase(Locale.ENGLISH); return decodeExpanded(layoutMap.expand(lower, false)); }
/** * Throws an exception if the specified text is blank using the given * text description. * * @param text the text to check * @param description describes the text, used in the exception message * * @throws NullPointerException if {@code text} is {@code null} * @throws IllegalArgumentException if {@code text} is empty, or blank */ public static void assertNotBlank(String text, String description) { if (text == null) throw new NullPointerException("The " + description + " must not be null."); if (FormUtils.isBlank(text)) { throw new IllegalArgumentException( "The " + description + " must not be empty, or whitespace. " + "See FormUtils.isBlank(String)"); } }
/** * Constructs a parser for the given encoded column/row specification, * the given LayoutMap, and orientation. * * @param source the raw encoded column or row specification * as provided by the user * @param description describes the source, e.g. "column specification" * @param layoutMap maps layout variable names to ColumnSpec and * RowSpec objects * @param horizontal {@code true} for columns, {@code false} for rows * * @throws NullPointerException if {@code source} is {@code null} */ private FormSpecParser( String source, String description, LayoutMap layoutMap, boolean horizontal) { FormUtils.assertNotNull(source, description); FormUtils.assertNotNull(layoutMap, "LayoutMap"); this.layoutMap = layoutMap; this.source = this.layoutMap.expand(source, horizontal); }
/** * Specifies whether the given component shall be taken into account * for sizing and positioning. This setting overrides the container-wide * default. See {@link #setHonorsVisibility(boolean)} for details. * * @param component the component that shall get an individual setting * @param b <code>Boolean.TRUE</code> to override the container * default and honor the visibility for the given component, * <code>Boolean.FALSE</code> to override the container default and * ignore the visibility for the given component, * <code>null</code> to use the container default value as specified * by {@link #getHonorsVisibility()}. * * @since 1.2 */ public void setHonorsVisibility(Component component, Boolean b) { CellConstraints constraints = getConstraints0(component); if (FormUtils.equals(b, constraints.honorsVisibility)) return; constraints.honorsVisibility = b; invalidateAndRepaint(component.getParent()); }
FormUtils.assertNotBlank(encodedDescription, "encoded form specification"); String[] token = TOKEN_SEPARATOR_PATTERN.split(encodedDescription); if (token.length == 0) {
/** * Lazily creates and returns a fallback for the dialog font * that is used to compute the dialog base units. * This fallback font is cached and will be reset if the L&F changes. * * @return the cached fallback font used to compute the dialog base units */ private Font getCachedDefaultDialogFont() { FormUtils.ensureValidCache(); if (cachedDefaultDialogFont == null) { cachedDefaultDialogFont = lookupDefaultDialogFont(); } return cachedDefaultDialogFont; }
/** * Parses the encoded column specifications and returns a ColumnSpec object * that represents the string. Variables are expanded using the given * LayoutMap. * * @param encodedColumnSpec the encoded column specification * @param layoutMap expands layout column variables * * @return a ColumnSpec instance for the given specification * @throws NullPointerException if {@code encodedColumnSpec} or * {@code layoutMap} is {@code null} * * @see #decodeSpecs(String, LayoutMap) * * @since 1.2 */ public static ColumnSpec decode(String encodedColumnSpec, LayoutMap layoutMap) { FormUtils.assertNotBlank(encodedColumnSpec, "encoded column specification"); FormUtils.assertNotNull(layoutMap, "LayoutMap"); String trimmed = encodedColumnSpec.trim(); String lower = trimmed.toLowerCase(Locale.ENGLISH); return decodeExpanded(layoutMap.expand(lower, true)); }
/** * Lazily checks and answers whether the Aqua look&feel is active. * * @return {@code true} if the current look&feel is Aqua */ public static boolean isLafAqua() { ensureValidCache(); if (cachedIsLafAqua == null) { cachedIsLafAqua = Boolean.valueOf(computeIsLafAqua()); } return cachedIsLafAqua.booleanValue(); }
/** * Looks up and returns the font used for title labels. * Since Mac Aqua uses an inappropriate titled border font, * we use a bold label font instead. Actually if the title * is used in a titled separator, the bold weight is questionable. * It seems that most native Aqua tools use a plain label in * titled separators. * * @return the font used for title labels */ private static Font getTitleFont() { return FormUtils.isLafAqua() ? UIManager.getFont("Label.font").deriveFont(Font.BOLD) : UIManager.getFont("TitledBorder.font"); }
/** * Looks up and returns the dialog base units for the given component. * In case the component is <code>null</code> the global dialog base units * are answered.<p> * * Before we compute the dialog base units we check whether they * have been computed and cached before - for the same component * <code>FontMetrics</code>. * * @param c the component that provides the graphics object * @return the DialogBaseUnits object for the given component */ private DialogBaseUnits getDialogBaseUnits(Component c) { FormUtils.ensureValidCache(); if (c == null) { // || (font = c.getFont()) == null) { // logInfo("Missing font metrics: " + c); return getGlobalDialogBaseUnits(); } FontMetrics fm = c.getFontMetrics(getDefaultDialogFont()); DialogBaseUnits dialogBaseUnits = (DialogBaseUnits) cachedDialogBaseUnits.get(fm); if (dialogBaseUnits == null) { dialogBaseUnits = computeDialogBaseUnits(fm); cachedDialogBaseUnits.put(fm, dialogBaseUnits); } return dialogBaseUnits; }
static void ensureValidCache() { LookAndFeel currentLookAndFeel = UIManager.getLookAndFeel(); if (currentLookAndFeel != cachedLookAndFeel) { clearLookAndFeelBasedCaches(); cachedLookAndFeel = currentLookAndFeel; } }
/** * Looks up and returns the font used for title labels. * Since Mac Aqua uses an inappropriate titled border font, * we use a bold label font instead. Actually if the title * is used in a titled separator, the bold weight is questionable. * It seems that most native Aqua tools use a plain label in * titled separators. * * @return the font used for title labels */ private Font getTitleFont() { return FormUtils.isLafAqua() ? UIManager.getFont("Label.font").deriveFont(Font.BOLD) : UIManager.getFont("TitledBorder.font"); }
/** * Looks up and returns the dialog base units for the given component. * In case the component is {@code null} the global dialog base units * are answered.<p> * * Before we compute the dialog base units we check whether they * have been computed and cached before - for the same component * {@code FontMetrics}. * * @param c the component that provides the graphics object * @return the DialogBaseUnits object for the given component */ private DialogBaseUnits getDialogBaseUnits(Component c) { FormUtils.ensureValidCache(); if (c == null) { // || (font = c.getFont()) == null) { // logInfo("Missing font metrics: " + c); return getGlobalDialogBaseUnits(); } FontMetrics fm = c.getFontMetrics(getDefaultDialogFont()); if (fm.equals(cachedFontMetrics)) { return cachedDialogBaseUnits; } DialogBaseUnits dialogBaseUnits = computeDialogBaseUnits(fm); cachedFontMetrics = fm; cachedDialogBaseUnits = dialogBaseUnits; return dialogBaseUnits; }
+ " must be one of: LEFT, CENTER, RIGHT."); JPanel panel = new JPanel(new TitledSeparatorLayout(!FormUtils.isLafAqua())); panel.setOpaque(false); panel.add(label);
|| horizontalAlignment == SwingConstants.RIGHT, "The label's horizontal alignment must be one of: LEFT, CENTER, RIGHT."); JPanel panel = new JPanel(new TitledSeparatorLayout(!FormUtils.isLafAqua())); panel.setOpaque(false); panel.add(label);