Java Code Examples for javax.swing.UIDefaults#keys()

The following examples show how to use javax.swing.UIDefaults#keys() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultsDisplay.java    From littleluck with Apache License 2.0 6 votes vote down vote up
public UIDefaultsTableModel() {
    // make a local copy of the defaults table in case the look and feel changes
    defaults = new UIDefaults();
    keys = new ArrayList<Object>();
    UIDefaults realDefaults = UIManager.getDefaults();
    Enumeration keysEnum = realDefaults.keys();
    while (keysEnum.hasMoreElements()) {
        Object key = keysEnum.nextElement();
        if (!defaults.containsKey(key)) {
            keys.add(key);
            defaults.put(key, realDefaults.get(key));
        } else {
            System.out.println("found duplicate key:"+key);
        }
    }
}
 
Example 2
Source File: DefaultsDisplay.java    From beautyeye with Apache License 2.0 6 votes vote down vote up
public UIDefaultsTableModel() {
    // make a local copy of the defaults table in case the look and feel changes
    defaults = new UIDefaults();
    keys = new ArrayList<Object>();
    UIDefaults realDefaults = UIManager.getDefaults();
    Enumeration keysEnum = realDefaults.keys();
    while (keysEnum.hasMoreElements()) {
        Object key = keysEnum.nextElement();
        if (!defaults.containsKey(key)) {
            keys.add(key);
            defaults.put(key, realDefaults.get(key));
        } else {
            System.out.println("found duplicate key:"+key);
        }
    }
}
 
Example 3
Source File: ColorEditor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Initialized fields used in Swing Palette. */
private static void initSwingConstants() {
    if (swingColorNames != null)
        return;

    UIDefaults def = UIManager.getDefaults ();
    Enumeration e = def.keys ();
    
    java.util.TreeSet<String> names = new java.util.TreeSet<String>();
    
    while (e.hasMoreElements ()) {
        Object k = e.nextElement ();
        if (! (k instanceof String))
            continue;
        Object v = def.get (k);
        if (! (v instanceof Color))
            continue;
        names.add((String)k);
    }
    
    swingColorNames = new String [names.size ()];
    names.toArray(swingColorNames);
    swingColors = new Color [swingColorNames.length];
    
    int i, k = swingColorNames.length;
    for (i = 0; i < k; i++)
        swingColors [i] = (Color) def.get (swingColorNames [i]);
        }
 
Example 4
Source File: FreeColLookAndFeel.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the default font in all UI elements.
 *
 * @param defaultFont A {@code Font} to use by default.
 */
public static void installFont(Font defaultFont) {
    UIDefaults u = UIManager.getDefaults();
    java.util.Enumeration<Object> keys = u.keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (u.get(key) instanceof javax.swing.plaf.FontUIResource) {
            u.put(key, defaultFont);
        }
    }
}
 
Example 5
Source File: IOSImageUtil.java    From ios-image-util with MIT License 4 votes vote down vote up
public static void main(String[] args) {
	try {
		/* Mac OS X El Capitan has a little problem with mac look and feel. Ignore it.
		for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
			if (info.getClassName().equals("com.apple.laf.AquaLookAndFeel")) {
				System.setProperty("apple.laf.useScreenMenuBar", "true");
				System.setProperty("com.apple.mrj.application.apple.menu.about.name", "ios-image-util");
				UIManager.setLookAndFeel(info.getClassName());
				break;
			}
		}
		*/

		// Use anti-aliasing font on Windows platform in Japanese by default.
		System.setProperty("awt.useSystemAAFontSettings", "lcd"); // Maybe not effective. Don't care.
		ResourceBundle resource = ResourceBundle.getBundle("application");
		if (resource.containsKey("font.default.name") && System.getProperty("file.separator").equals("\\")) { // Windows only
			UIDefaults uiDefaults = UIManager.getLookAndFeelDefaults();
			for (Enumeration<Object> enu = uiDefaults.keys(); enu.hasMoreElements();) {
				String key = enu.nextElement().toString();
				Font font;
				if (key.toLowerCase().endsWith("font") && (font = uiDefaults.getFont(key)) != null) {
					uiDefaults.put(key, new Font(resource.getString("font.default.name"), font.getStyle(), font.getSize()));
				}
			}
		}

		long l1 = System.currentTimeMillis();
		MainFrame mainFrame = new MainFrame();
		mainFrame.setLocationByPlatform(true);

		File defaultProperties = new File(getDefaultDirectory(mainFrame), DEFAULT_PROPERTIES_FILENAME);
		if (defaultProperties.exists()) {
			boolean loadSystemProperties = true;
			boolean forceNew = false;
			for (int i = 0; i < args.length; i++) {
				String arg = args[i].toLowerCase();
				if (arg.startsWith("/")) arg = "-".concat(arg.substring(1));
				if (arg.equals("-r") || arg.equals("-reset")) { loadSystemProperties = false; break; }
				if (arg.equals("-b") || arg.equals("-batch")) { loadSystemProperties = false; break; }
				if (arg.equals("-h") || arg.equals("-help")) { loadSystemProperties = false; break; }
				if (arg.equals("-n") || arg.equals("-new")) { forceNew = true; }
			}
			if (loadSystemProperties) {
				mainFrame.loadProperties(defaultProperties, true, forceNew);
			}
		}

		if (args.length > 0) {
			if (!initialize(mainFrame, args)) {
				if (mainFrame.isBatchMode()) {
					System.exit(1);
				}
			}
		}

		if (mainFrame.isBatchMode()) {
			int exitCode = 0;
			if (!mainFrame.isSilentMode()) {
				System.out.println(String.format("START: %s", (new java.util.Date(l1)).toString()));
				System.out.println(String.format("  Initializing takes %.2f secs.", ((double)(System.currentTimeMillis() - l1) / 1000d)));
				System.out.println();
			}
			if (mainFrame.isGenerateImagesReqested() && !mainFrame.generate()) {
				exitCode = 1;
				usage(mainFrame);
			}
			if (mainFrame.isSplitImageRequested() && !mainFrame.batchSplit()) {
				exitCode = 1;
				usage(mainFrame);
			}
			long l2 = System.currentTimeMillis();
			if (!mainFrame.isSilentMode()) {
				System.out.println(String.format("FINISH: %s", (new java.util.Date(l2)).toString()));
				System.out.println(String.format("  Generate images takes %.2f secs.", ((double)(l2 - l1) / 1000d)));
				System.out.println();
			}
			System.exit(exitCode);
		} else {
			if (mainFrame.isCheckForUpdatesOnStartUp()) {
				mainFrame.checkForUpdatesInBackground();
			}
			mainFrame.initializeGUI();
			mainFrame.setVisible(true);
		}
	} catch (Throwable t) {
		t.printStackTrace(System.err);
		System.exit(1);
	}
}