use of javax.swing.UIDefaults in project adempiere by adempiere.
the class CompiereLookAndFeel method getDefaults.
// getDescription
/**************************************************************************
* Get/Create Defaults
* @return UI Defaults
*/
public UIDefaults getDefaults() {
// Theme already created/set
MetalLookAndFeel.setCurrentTheme(s_theme);
// calls init..Defaults
UIDefaults defaults = super.getDefaults();
return defaults;
}
use of javax.swing.UIDefaults in project jmeter by apache.
the class JMeterUtils method applyScaleOnFonts.
/**
* Apply HiDPI scale factor on fonts
* @param scale float scale to apply
*/
public static void applyScaleOnFonts(final float scale) {
log.info("Applying HiDPI scale: {}", scale);
SwingUtilities.invokeLater(() -> {
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
// the font objects are missing, so iterate over the keys, only
for (Object key : new ArrayList<>(defaults.keySet())) {
Object value = defaults.get(key);
log.debug("Try key {} with value {}", key, value);
if (value instanceof Font) {
Font font = (Font) value;
final float newSize = font.getSize() * scale;
if (font instanceof FontUIResource) {
defaults.put(key, new FontUIResource(font.getName(), font.getStyle(), Math.round(newSize)));
} else {
defaults.put(key, font.deriveFont(newSize));
}
}
}
JMeterUtils.refreshUI();
});
}
use of javax.swing.UIDefaults in project jgnash by ccavanaugh.
the class NimbusUtils method changeFontSize.
@SuppressWarnings("ConstantConditions")
public static void changeFontSize(final int size) {
// get UI defaults
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
{
// determine percent reduction for insets, etc.
float baseSize = getBaseFontSize();
growthPercentage = size / baseSize;
}
// reduce font sizes
defaults.keySet().stream().filter(keyObj -> keyObj instanceof String).forEach(keyObj -> {
String key = (String) keyObj;
if (key.contains("font")) {
Object object = defaults.get(key);
if (object instanceof Font) {
Font font = (Font) object;
Font derived = font.deriveFont((float) size);
defaults.put(key, derived);
} else if (object instanceof FontUIResource) {
FontUIResource resource = (FontUIResource) object;
FontUIResource derived = new FontUIResource(resource.deriveFont((float) size));
defaults.put(key, derived);
}
}
});
// reduce content Margins
defaults.keySet().stream().filter(keyObj -> keyObj instanceof String).forEach(keyObj -> {
String key = (String) keyObj;
if (key.contains("contentMargins") || key.contains("padding")) {
Insets derived = (Insets) ((Insets) defaults.get(key)).clone();
if (derived.left > 0) {
derived.left = (int) Math.ceil(derived.left * growthPercentage);
}
if (derived.right > 0) {
derived.right = (int) Math.ceil(derived.right * growthPercentage);
}
if (derived.top > 0) {
derived.top = (int) Math.ceil(derived.top * growthPercentage);
}
if (derived.bottom > 0) {
derived.bottom = (int) Math.ceil(derived.bottom * growthPercentage);
}
defaults.put(key, derived);
}
});
// reduce content Margins
defaults.keySet().stream().filter(keyObj -> keyObj instanceof String).forEach(keyObj -> {
String key = (String) keyObj;
if (key.contains("textIconGap") || key.contains("size") || key.contains("thumbWidth") || key.contains("thumbHeight")) {
Integer integer = (Integer) defaults.get(key);
Integer derived = (int) Math.ceil((float) integer * growthPercentage);
defaults.put(key, derived);
}
});
}
use of javax.swing.UIDefaults in project jgnash by ccavanaugh.
the class NimbusUtils method reduceNimbusButtonMargin.
/**
* Reduce the margins around the content of a button for the Nimbus look and feel
*
* @param button button to alter
*/
public static void reduceNimbusButtonMargin(final JButton button) {
UIDefaults buttonDefaults = new UIDefaults();
buttonDefaults.put("Button.contentMargins", new Insets(6, 6, 6, 6));
button.putClientProperty("Nimbus.Overrides", buttonDefaults);
button.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.FALSE);
}
use of javax.swing.UIDefaults in project ceylon-compiler by ceylon.
the class Test method test.
static void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
JPanel jPanel = new javax.swing.JPanel();
UIDefaults defaults = UIManager.getDefaults();
Object cl = defaults.get("ClassLoader");
ClassLoader uiClassLoader = (cl != null) ? (ClassLoader) cl : jPanel.getClass().getClassLoader();
try {
String className = (String) defaults.get(jPanel.getUIClassID());
if (className != null) {
Class cls = (Class) defaults.get(className);
if (cls == null) {
if (uiClassLoader == null) {
Method m = SwingUtilities.class.getDeclaredMethod("loadSystemClass", String.class);
m.setAccessible(true);
m.invoke(null, className);
// cls = SwingUtilities.loadSystemClass(className);
throw new RuntimeException("FAIL");
} else {
cls = uiClassLoader.loadClass(className);
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (ClassCastException e) {
e.printStackTrace();
}
jPanel.setVisible(true);
}
Aggregations