Search in sources :

Example 51 with AppContext

use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.

the class SunFontManager method registerFont.

public boolean registerFont(Font font) {
    /* This method should not be called with "null".
         * It is the caller's responsibility to ensure that.
         */
    if (font == null) {
        return false;
    }
    /* Initialise these objects only once we start to use this API */
    synchronized (regFamilyKey) {
        if (createdByFamilyName == null) {
            createdByFamilyName = new Hashtable<String, FontFamily>();
            createdByFullName = new Hashtable<String, Font2D>();
        }
    }
    if (!FontAccess.getFontAccess().isCreatedFont(font)) {
        return false;
    }
    /* We want to ensure that this font cannot override existing
         * installed fonts. Check these conditions :
         * - family name is not that of an installed font
         * - full name is not that of an installed font
         * - family name is not the same as the full name of an installed font
         * - full name is not the same as the family name of an installed font
         * The last two of these may initially look odd but the reason is
         * that (unfortunately) Font constructors do not distinuguish these.
         * An extreme example of such a problem would be a font which has
         * family name "Dialog.Plain" and full name of "Dialog".
         * The one arguably overly stringent restriction here is that if an
         * application wants to supply a new member of an existing family
         * It will get rejected. But since the JRE can perform synthetic
         * styling in many cases its not necessary.
         * We don't apply the same logic to registered fonts. If apps want
         * to do this lets assume they have a reason. It won't cause problems
         * except for themselves.
         */
    HashSet<String> names = getInstalledNames();
    Locale l = getSystemStartupLocale();
    String familyName = font.getFamily(l).toLowerCase();
    String fullName = font.getFontName(l).toLowerCase();
    if (names.contains(familyName) || names.contains(fullName)) {
        return false;
    }
    /* Checks passed, now register the font */
    Hashtable<String, FontFamily> familyTable;
    Hashtable<String, Font2D> fullNameTable;
    if (!maybeMultiAppContext()) {
        familyTable = createdByFamilyName;
        fullNameTable = createdByFullName;
        fontsAreRegistered = true;
    } else {
        AppContext appContext = AppContext.getAppContext();
        familyTable = (Hashtable<String, FontFamily>) appContext.get(regFamilyKey);
        fullNameTable = (Hashtable<String, Font2D>) appContext.get(regFullNameKey);
        if (familyTable == null) {
            familyTable = new Hashtable<String, FontFamily>();
            fullNameTable = new Hashtable<String, Font2D>();
            appContext.put(regFamilyKey, familyTable);
            appContext.put(regFullNameKey, fullNameTable);
        }
        fontsAreRegisteredPerAppContext = true;
    }
    /* Create the FontFamily and add font to the tables */
    Font2D font2D = FontUtilities.getFont2D(font);
    int style = font2D.getStyle();
    FontFamily family = familyTable.get(familyName);
    if (family == null) {
        family = new FontFamily(font.getFamily(l));
        familyTable.put(familyName, family);
    }
    /* Remove name cache entries if not using app contexts.
         * To accommodate a case where code may have registered first a plain
         * family member and then used it and is now registering a bold family
         * member, we need to remove all members of the family, so that the
         * new style can get picked up rather than continuing to synthesise.
         */
    if (fontsAreRegistered) {
        removeFromCache(family.getFont(Font.PLAIN));
        removeFromCache(family.getFont(Font.BOLD));
        removeFromCache(family.getFont(Font.ITALIC));
        removeFromCache(family.getFont(Font.BOLD | Font.ITALIC));
        removeFromCache(fullNameTable.get(fullName));
    }
    family.setFont(font2D, style);
    fullNameTable.put(fullName, font2D);
    return true;
}
Also used : Locale(java.util.Locale) AppContext(sun.awt.AppContext)

Example 52 with AppContext

use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.

the class SunFontManager method preferLocaleFonts.

public synchronized void preferLocaleFonts() {
    if (FontUtilities.isLogging()) {
        FontUtilities.getLogger().info("Entered preferLocaleFonts().");
    }
    /* Test if re-ordering will have any effect */
    if (!FontConfiguration.willReorderForStartupLocale()) {
        return;
    }
    if (!maybeMultiAppContext()) {
        if (gLocalePref == true) {
            return;
        }
        gLocalePref = true;
        createCompositeFonts(fontNameCache, gLocalePref, gPropPref);
        _usingAlternateComposites = true;
    } else {
        AppContext appContext = AppContext.getAppContext();
        if (appContext.get(localeFontKey) == localeFontKey) {
            return;
        }
        appContext.put(localeFontKey, localeFontKey);
        boolean acPropPref = appContext.get(proportionalFontKey) == proportionalFontKey;
        ConcurrentHashMap<String, Font2D> altNameCache = new ConcurrentHashMap<String, Font2D>();
        /* If there is an existing hashtable, we can drop it. */
        appContext.put(CompositeFont.class, altNameCache);
        _usingPerAppContextComposites = true;
        createCompositeFonts(altNameCache, true, acPropPref);
    }
}
Also used : AppContext(sun.awt.AppContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 53 with AppContext

use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.

the class SunFontManager method useAlternateFontforJALocales.

/* Modifies the behaviour of a subsequent call to preferLocaleFonts()
     * to use Mincho instead of Gothic for dialoginput in JA locales
     * on windows. Not needed on other platforms.
     */
public synchronized void useAlternateFontforJALocales() {
    if (FontUtilities.isLogging()) {
        FontUtilities.getLogger().info("Entered useAlternateFontforJALocales().");
    }
    if (!FontUtilities.isWindows) {
        return;
    }
    if (!maybeMultiAppContext()) {
        gAltJAFont = true;
    } else {
        AppContext appContext = AppContext.getAppContext();
        appContext.put(altJAFontKey, altJAFontKey);
    }
}
Also used : AppContext(sun.awt.AppContext)

Example 54 with AppContext

use of sun.awt.AppContext in project adempiere by adempiere.

the class PLAFEditor method setLFSelection.

//  dynInit
/**
	 *  Set Picks From Environment
	 */
private void setLFSelection() {
    m_setting = true;
    //  Search for PLAF
    ValueNamePair plaf = null;
    LookAndFeel lookFeel = UIManager.getLookAndFeel();
    String look = lookFeel.getClass().getName();
    for (int i = 0; i < AdempierePLAF.getPLAFs().length; i++) {
        ValueNamePair vp = AdempierePLAF.getPLAFs()[i];
        if (vp.getValue().equals(look)) {
            plaf = vp;
            break;
        }
    }
    if (plaf != null)
        lfField.setSelectedItem(plaf);
    //  Search for Theme
    MetalTheme metalTheme = null;
    ValueNamePair theme = null;
    boolean metal = UIManager.getLookAndFeel() instanceof MetalLookAndFeel;
    themeField.setModel(new DefaultComboBoxModel(AdempierePLAF.getThemes()));
    if (metal) {
        theme = null;
        AppContext context = AppContext.getAppContext();
        metalTheme = (MetalTheme) context.get("currentMetalTheme");
        if (metalTheme != null) {
            String lookTheme = metalTheme.getName();
            for (int i = 0; i < AdempierePLAF.getThemes().length; i++) {
                ValueNamePair vp = AdempierePLAF.getThemes()[i];
                if (vp.getName().equals(lookTheme)) {
                    theme = vp;
                    break;
                }
            }
        }
        if (theme != null)
            themeField.setSelectedItem(theme);
    }
    m_setting = false;
    log.info(lookFeel + " - " + metalTheme);
}
Also used : MetalTheme(javax.swing.plaf.metal.MetalTheme) AppContext(sun.awt.AppContext) ValueNamePair(org.compiere.util.ValueNamePair) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) MetalLookAndFeel(javax.swing.plaf.metal.MetalLookAndFeel) LookAndFeel(javax.swing.LookAndFeel) CompiereLookAndFeel(org.compiere.plaf.CompiereLookAndFeel) MetalLookAndFeel(javax.swing.plaf.metal.MetalLookAndFeel)

Example 55 with AppContext

use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.

the class MotifCheckBoxUI method createUI.

// ********************************
//         Create PLAF
// ********************************
public static ComponentUI createUI(JComponent c) {
    AppContext appContext = AppContext.getAppContext();
    MotifCheckBoxUI motifCheckBoxUI = (MotifCheckBoxUI) appContext.get(MOTIF_CHECK_BOX_UI_KEY);
    if (motifCheckBoxUI == null) {
        motifCheckBoxUI = new MotifCheckBoxUI();
        appContext.put(MOTIF_CHECK_BOX_UI_KEY, motifCheckBoxUI);
    }
    return motifCheckBoxUI;
}
Also used : AppContext(sun.awt.AppContext)

Aggregations

AppContext (sun.awt.AppContext)74 HashMap (java.util.HashMap)3 Hashtable (java.util.Hashtable)3 Locale (java.util.Locale)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 EventListenerAggregate (sun.awt.EventListenerAggregate)3 FlavorListener (java.awt.datatransfer.FlavorListener)2 WeakReference (java.lang.ref.WeakReference)2 Map (java.util.Map)2 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)2 LookAndFeel (javax.swing.LookAndFeel)2 MetalLookAndFeel (javax.swing.plaf.metal.MetalLookAndFeel)2 MetalTheme (javax.swing.plaf.metal.MetalTheme)2 ValueNamePair (org.compiere.util.ValueNamePair)2 PeerEvent (sun.awt.PeerEvent)2 AccumulativeRunnable (sun.swing.AccumulativeRunnable)2 Container (java.awt.Container)1 EventQueue (java.awt.EventQueue)1 Font (java.awt.Font)1 Rectangle (java.awt.Rectangle)1