Java Swing Font scaleFontIfApplicable(javax.swing.UIDefaults uiDefaults, java.util.Map.Entry entry, double scale)

Here you can find the source of scaleFontIfApplicable(javax.swing.UIDefaults uiDefaults, java.util.Map.Entry entry, double scale)

Description

scale Font If Applicable

License

Open Source License

Declaration

private static void scaleFontIfApplicable(javax.swing.UIDefaults uiDefaults,
            java.util.Map.Entry<Object, Object> entry, double scale) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006, 2015, Carnegie Mellon University. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * 3. Products derived from the software may not be called "Alice", nor may
 *    "Alice" appear in their name, without prior written permission of
 *    Carnegie Mellon University.//from w  w w  . j a v  a2 s.  c  o  m
 *
 * 4. All advertising materials mentioning features or use of this software must
 *    display the following acknowledgement: "This product includes software
 *    developed by Carnegie Mellon University"
 *
 * 5. The gallery of art assets and animations provided with this software is
 *    contributed by Electronic Arts Inc. and may be used for personal,
 *    non-commercial, and academic use only. Redistributions of any program
 *    source code that utilizes The Sims 2 Assets must also retain the copyright
 *    notice, list of conditions and the disclaimer contained in
 *    The Alice 3.0 Art Gallery License.
 *
 * DISCLAIMER:
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
 * ANY AND ALL EXPRESS, STATUTORY OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,  FITNESS FOR A
 * PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
 * SHALL THE AUTHORS, COPYRIGHT OWNERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING FROM OR OTHERWISE RELATING TO
 * THE USE OF OR OTHER DEALINGS WITH THE SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/

public class Main {
    private static void scaleFontIfApplicable(javax.swing.UIDefaults uiDefaults, Object key,
            javax.swing.plaf.FontUIResource prevFontUIResource, double scale) {
        int prevSize = prevFontUIResource.getSize();
        int nextSize = (int) (Math.round(prevSize * scale));
        if (prevSize != nextSize) {
            javax.swing.plaf.FontUIResource nextFontUIResource = new javax.swing.plaf.FontUIResource(
                    prevFontUIResource.getFamily(), prevFontUIResource.getStyle(), nextSize);
            uiDefaults.put(key, nextFontUIResource);
        }
    }

    private static void scaleFontIfApplicable(javax.swing.UIDefaults uiDefaults,
            java.util.Map.Entry<Object, Object> entry, double scale) {
        Object value = entry.getValue();
        if (value instanceof javax.swing.UIDefaults.ActiveValue) {
            javax.swing.UIDefaults.ActiveValue activeValue = (javax.swing.UIDefaults.ActiveValue) value;
            value = activeValue.createValue(uiDefaults);
        }
        if (value instanceof javax.swing.plaf.FontUIResource) {
            scaleFontIfApplicable(uiDefaults, entry.getKey(), (javax.swing.plaf.FontUIResource) value, scale);
        }
    }
}

Related

  1. mildFont(T comp)
  2. modifyLabelFont(JLabel label, int style, int delta)
  3. newLabel(String text, int fontStyle)
  4. renderComponent(JComponent comp, Font f, Color foregroundColor, boolean opaque)
  5. renderContainerComponents(JComponent comp, Font f, Color foregroundColor, Color backgroundColor)
  6. unBoldAllFonts()
  7. updateFont(JComponent comp, Font f, boolean b)