Java Swing Font autoAwesomeLookAndFeel(String fontName, Map defaults)

Here you can find the source of autoAwesomeLookAndFeel(String fontName, Map defaults)

Description

auto Awesome Look And Feel

License

Open Source License

Declaration

public static void autoAwesomeLookAndFeel(String fontName, Map<Object, Object> defaults) 

Method Source Code

//package com.java2s;
/**********************************************************************************************
 *
 * Asprise OCR Java API/*w w w .  j  ava 2s  .  c  om*/
 * Copyright (C) 1998-2015. Asprise Inc. <asprise.com>
 *
 * This file is licensed under the GNU Affero General Public License version 3 as published by
 * the Free Software Foundation.
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * You should have received a copy of the GNU Affero General Public License.  If not, please
 * visit <http://www.gnu.org/licenses/agpl-3.0.html>.
 *
 **********************************************************************************************/

import javax.swing.UIManager;

import javax.swing.plaf.FontUIResource;

import java.awt.Color;

import java.awt.Font;

import java.util.Map;

public class Main {
    public static void autoAwesomeLookAndFeel(String fontName, Map<Object, Object> defaults) {

        if (!isWindows()) {
            setSystemLookAndFeel();
        }

        if (UIManager.getLookAndFeel().toString().contains("MetalLookAndFeel")) {

            FontUIResource font = new FontUIResource(fontName == null ? Font.SANS_SERIF : fontName.trim(),
                    Font.PLAIN, 12);
            java.util.Enumeration keys = UIManager.getDefaults().keys();
            while (keys.hasMoreElements()) {
                Object key = keys.nextElement();
                Object value = UIManager.get(key);
                if (value instanceof javax.swing.plaf.FontUIResource) {
                    FontUIResource fontExisting = (FontUIResource) value;

                    UIManager.put(key, font);
                }
            }

            UIManager.put("SplitPaneDivider.draggingColor", Color.gray);

            if (defaults != null) {
                for (Object key : defaults.keySet()) {
                    UIManager.put(key, defaults.get(key));
                }
            }
        }
    }

    public static boolean isWindows() {
        return System.getProperty("os.name").toLowerCase().contains("windows");
    }

    public static void setSystemLookAndFeel() {
        if (isWindows()) {
            setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } else if (isMac()) {
            setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } else {
            setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
    }

    private static boolean setLookAndFeel(String lookAndFeelClass) {
        try {
            UIManager.setLookAndFeel(lookAndFeelClass);
            return true;
        } catch (Throwable t) {
            System.err.println(t.getMessage());
            return false;
        }
    }

    public static boolean isMac() {
        return System.getProperty("os.name").toLowerCase().contains("mac");
    }
}

Related

  1. addLabel(Container component, String text, Icon icon, int horizontalAlignment, Font font)
  2. applyComponentFont(JComponent c)
  3. applyFont(JPanel p)
  4. applyProperties(final Component comp, final Color colBack, final Color colFore, final Font font)
  5. boldFont(JComponent component)
  6. clipText(JComponent c, Font fnt, String val, int xFrom, int xTo)
  7. createTextAttributes(Font baseFont, Color color, boolean bold, boolean italic)
  8. createTextLayout(JComponent c, String s, Font f, FontRenderContext frc)