mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[followup] Add/refactor JBUI.JBIcon/ScalableJBIcon/ValidatingScalableJBIcon
This commit is contained in:
@@ -81,7 +81,6 @@ public class LayeredIcon extends JBUI.AuxScalableJBIcon {
|
||||
}
|
||||
for (Icon icon : myIcons) {
|
||||
if (icon != null && !(icon instanceof ScalableIcon)) {
|
||||
setScale(1f);
|
||||
return myScaledIcons = myIcons;
|
||||
}
|
||||
}
|
||||
@@ -221,13 +220,14 @@ public class LayeredIcon extends JBUI.AuxScalableJBIcon {
|
||||
@Override
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
if (updateJBUIScale()) updateSize();
|
||||
int i = 0;
|
||||
for (Icon icon : myScaledIcons()) {
|
||||
Icon[] icons = myScaledIcons();
|
||||
if (icons == null) return;
|
||||
for (int i = 0; i < icons.length; i++) {
|
||||
Icon icon = icons[i];
|
||||
if (icon == null || myDisabledLayers[i]) continue;
|
||||
int xOffset = x + scaleVal(myXShift + myHShifts[i], Scale.ARBITRARY);
|
||||
int yOffset = y + scaleVal(myYShift + myVShifts[i], Scale.ARBITRARY);
|
||||
icon.paintIcon(c, g, xOffset, yOffset);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,6 @@ public class RowIcon extends JBUI.AuxScalableJBIcon {
|
||||
}
|
||||
for (Icon icon : myIcons) {
|
||||
if (icon != null && !(icon instanceof ScalableIcon)) {
|
||||
setScale(1f);
|
||||
return myScaledIcons = myIcons;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -16,6 +16,7 @@
|
||||
package com.intellij.codeInsight.lookup;
|
||||
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.openapi.util.ScalableIcon;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.meta.PsiMetaData;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
@@ -48,10 +49,9 @@ public class DefaultLookupItemRenderer extends LookupElementRenderer<LookupItem>
|
||||
@Nullable
|
||||
public static Icon getRawIcon(final LookupElement item, boolean real) {
|
||||
Icon icon = _getRawIcon(item, real);
|
||||
// align SAMPLE_ICON.getIconHeight() with the 'icon' scale
|
||||
int sampleIconHeight = ScalableJBIcon.scaleVal(icon, SAMPLE_ICON.getIconHeight(), Scale.ARBITRARY);
|
||||
if (icon != null && icon.getIconHeight() > sampleIconHeight) {
|
||||
return new SizedIcon(icon, icon.getIconWidth(), sampleIconHeight, true);
|
||||
if (icon instanceof ScalableIcon) icon = ((ScalableIcon)icon).scale(1f);
|
||||
if (icon != null && icon.getIconHeight() > SAMPLE_ICON.getIconHeight()) {
|
||||
return new SizedIcon(icon, icon.getIconWidth(), SAMPLE_ICON.getIconHeight());
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
@@ -31,23 +31,9 @@ public class SizedIcon extends JBUI.CachingScalableJBIcon {
|
||||
private Icon myScaledDelegate;
|
||||
|
||||
public SizedIcon(Icon delegate, int width, int height) {
|
||||
this(delegate, width, height, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param delegate the delegate icon
|
||||
* @param width this icon width
|
||||
* @param height this icon height
|
||||
* @param inDelegateScale whether to align this icon scale with the delegate icon scale
|
||||
*/
|
||||
public SizedIcon(Icon delegate, int width, int height, boolean inDelegateScale) {
|
||||
float scale = 1f;
|
||||
if (inDelegateScale && delegate instanceof ScalableIcon) {
|
||||
setScale(scale = ((ScalableIcon)delegate).getScale());
|
||||
}
|
||||
myScaledDelegate = myDelegate = delegate;
|
||||
myWidth = (int)(width / scale);
|
||||
myHeight = (int)(height / scale);
|
||||
myWidth = width;
|
||||
myHeight = height;
|
||||
}
|
||||
|
||||
protected SizedIcon(SizedIcon icon) {
|
||||
|
||||
@@ -908,18 +908,22 @@ public class ArrayUtil extends ArrayUtilRt {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null -> null; !null -> !null")
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T[] copyOf(@Nullable T[] original) {
|
||||
if (original == null) return null;
|
||||
return (T[]) Arrays.copyOf(original, original.length, original.getClass());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null -> null; !null -> !null")
|
||||
public static boolean[] copyOf(@Nullable boolean[] original) {
|
||||
if (original == null) return null;
|
||||
return Arrays.copyOf(original, original.length);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null -> null; !null -> !null")
|
||||
public static int[] copyOf(@Nullable int[] original) {
|
||||
if (original == null) return null;
|
||||
return Arrays.copyOf(original, original.length);
|
||||
|
||||
@@ -291,7 +291,7 @@ public class JBUI {
|
||||
* @author tav
|
||||
*/
|
||||
public static abstract class JBIcon implements Icon {
|
||||
private float myInitialJBUIScale = scale(1f);
|
||||
private float myInitialJBUIScale = currentJBUIScale();
|
||||
|
||||
protected JBIcon() {}
|
||||
|
||||
@@ -299,11 +299,17 @@ public class JBUI {
|
||||
myInitialJBUIScale = icon.myInitialJBUIScale;
|
||||
}
|
||||
|
||||
static float currentJBUIScale() {
|
||||
// We don't JBUI-scale images on Retina, see comments in ImageLoader.loadFromUrl(..)
|
||||
// So, make icons JBUI-scale conformant.
|
||||
return UIUtil.isRetina() ? 1f : scale(1f);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the scale factor aligning the icon size metrics to conform to up-to-date JBUI.scale
|
||||
*/
|
||||
private float getAligningScale() {
|
||||
return scale(1f) / myInitialJBUIScale;
|
||||
return currentJBUIScale() / myInitialJBUIScale;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -317,7 +323,7 @@ public class JBUI {
|
||||
* Sets the icon size metrics to {@code preScaled}
|
||||
*/
|
||||
protected void setJBUIPreScaled(boolean preScaled) {
|
||||
myInitialJBUIScale = preScaled ? scale(1f) : 1f;
|
||||
myInitialJBUIScale = preScaled ? currentJBUIScale() : 1f;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -499,7 +505,7 @@ public class JBUI {
|
||||
* @author tav
|
||||
*/
|
||||
public static abstract class AuxScalableJBIcon extends CachingScalableJBIcon implements AuxJBUIScale {
|
||||
private float myCachedJBUIScale = JBUI.scale(1f);
|
||||
private float myCachedJBUIScale = currentJBUIScale();
|
||||
|
||||
protected AuxScalableJBIcon() {}
|
||||
|
||||
@@ -510,7 +516,7 @@ public class JBUI {
|
||||
@Override
|
||||
public boolean updateJBUIScale() {
|
||||
if (needUpdateJBUIScale()) {
|
||||
myCachedJBUIScale = JBUI.scale(1f);
|
||||
myCachedJBUIScale = currentJBUIScale();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -518,7 +524,7 @@ public class JBUI {
|
||||
|
||||
@Override
|
||||
public boolean needUpdateJBUIScale() {
|
||||
return myCachedJBUIScale != JBUI.scale(1f);
|
||||
return myCachedJBUIScale != currentJBUIScale();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user