use of javax.swing.plaf.basic.BasicRadioButtonUI in project intellij-community by JetBrains.
the class JBCheckBox method setTextIcon.
/**
* Sets given icon to display between checkbox icon and text.
*
* @return true in case of success and false otherwise
*/
public boolean setTextIcon(@NotNull Icon icon) {
if (UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF()) {
return false;
}
ButtonUI ui = getUI();
if (ui instanceof BasicRadioButtonUI) {
Icon defaultIcon = ((BasicRadioButtonUI) ui).getDefaultIcon();
if (defaultIcon != null) {
MergedIcon mergedIcon = new MergedIcon(defaultIcon, 10, icon);
setIcon(mergedIcon);
return true;
}
}
return false;
}
use of javax.swing.plaf.basic.BasicRadioButtonUI in project intellij-community by JetBrains.
the class UIUtil method getCheckBoxTextHorizontalOffset.
public static int getCheckBoxTextHorizontalOffset(@NotNull JCheckBox cb) {
// logic copied from javax.swing.plaf.basic.BasicRadioButtonUI.paint
ButtonUI ui = cb.getUI();
String text = cb.getText();
Icon buttonIcon = cb.getIcon();
if (buttonIcon == null && ui != null) {
if (ui instanceof BasicRadioButtonUI) {
buttonIcon = ((BasicRadioButtonUI) ui).getDefaultIcon();
} else if (isUnderAquaLookAndFeel()) {
// inheritors of AquaButtonToggleUI
Ref<Method> cached = ourDefaultIconMethodsCache.get(ui.getClass());
if (cached == null) {
cached = Ref.create(ReflectionUtil.findMethod(Arrays.asList(ui.getClass().getMethods()), "getDefaultIcon", JComponent.class));
ourDefaultIconMethodsCache.put(ui.getClass(), cached);
if (!cached.isNull()) {
cached.get().setAccessible(true);
}
}
Method method = cached.get();
if (method != null) {
try {
buttonIcon = (Icon) method.invoke(ui, cb);
} catch (Exception e) {
cached.set(null);
}
}
}
}
Dimension size = new Dimension();
Rectangle viewRect = new Rectangle();
Rectangle iconRect = new Rectangle();
Rectangle textRect = new Rectangle();
Insets i = cb.getInsets();
size = cb.getSize(size);
viewRect.x = i.left;
viewRect.y = i.top;
viewRect.width = size.width - (i.right + viewRect.x);
viewRect.height = size.height - (i.bottom + viewRect.y);
iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
textRect.x = textRect.y = textRect.width = textRect.height = 0;
SwingUtilities.layoutCompoundLabel(cb, cb.getFontMetrics(cb.getFont()), text, buttonIcon, cb.getVerticalAlignment(), cb.getHorizontalAlignment(), cb.getVerticalTextPosition(), cb.getHorizontalTextPosition(), viewRect, iconRect, textRect, text == null ? 0 : cb.getIconTextGap());
return textRect.x;
}
use of javax.swing.plaf.basic.BasicRadioButtonUI in project intellij-community by JetBrains.
the class CheckBoxList method getCheckBoxDimension.
@NotNull
private static Dimension getCheckBoxDimension(@NotNull JCheckBox checkBox) {
Icon icon = null;
BasicRadioButtonUI ui = ObjectUtils.tryCast(checkBox.getUI(), BasicRadioButtonUI.class);
if (ui != null) {
icon = ui.getDefaultIcon();
}
if (icon == null) {
// com.intellij.ide.ui.laf.darcula.ui.DarculaCheckBoxUI.getDefaultIcon()
icon = JBUI.scale(EmptyIcon.create(20));
}
Insets margin = checkBox.getMargin();
return new Dimension(margin.left + icon.getIconWidth(), margin.top + icon.getIconHeight());
}
use of javax.swing.plaf.basic.BasicRadioButtonUI in project intellij-community by JetBrains.
the class UIUtil method getTextAlignBorder.
public static EmptyBorder getTextAlignBorder(@NotNull JToggleButton alignSource) {
ButtonUI ui = alignSource.getUI();
int leftGap = alignSource.getIconTextGap();
Border border = alignSource.getBorder();
if (border != null) {
leftGap += border.getBorderInsets(alignSource).left;
}
if (ui instanceof BasicRadioButtonUI) {
leftGap += ((BasicRadioButtonUI) alignSource.getUI()).getDefaultIcon().getIconWidth();
} else {
Method method = ReflectionUtil.getMethod(ui.getClass(), "getDefaultIcon", JComponent.class);
if (method != null) {
try {
Object o = method.invoke(ui, alignSource);
if (o instanceof Icon) {
leftGap += ((Icon) o).getIconWidth();
}
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
return new EmptyBorder(0, leftGap, 0, 0);
}
Aggregations