mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-164566 [use KeyFMap; add UIUtil.createImage(Component, ...)]
This commit is contained in:
@@ -87,7 +87,7 @@ public class ImageComponentUI extends ComponentUI {
|
||||
int patternSize = 2 * cellSize;
|
||||
|
||||
if (pattern == null) {
|
||||
pattern = UIUtil.createImage((Graphics2D)g, patternSize, patternSize, BufferedImage.TYPE_INT_ARGB);
|
||||
pattern = UIUtil.createImage(g, patternSize, patternSize, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics imageGraphics = pattern.getGraphics();
|
||||
imageGraphics.setColor(ic.getTransparencyChessboardWhiteColor());
|
||||
imageGraphics.fillRect(0, 0, patternSize, patternSize);
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ public class ArrangementAnimationPanel extends JPanel {
|
||||
//myContent.setDoubleBuffered(false);
|
||||
myContent.setBounds(0, 0, size.width, size.height);
|
||||
myContent.validate();
|
||||
myImage = UIUtil.createImage((Graphics2D)myContent.getGraphics(), size.width, size.height, BufferedImage.TYPE_INT_RGB);
|
||||
myImage = UIUtil.createImage(myContent, size.width, size.height, BufferedImage.TYPE_INT_RGB);
|
||||
assert myImage != null;
|
||||
final Graphics2D graphics = myImage.createGraphics();
|
||||
UISettings.setupAntialiasing(graphics);
|
||||
|
||||
@@ -249,7 +249,7 @@ public abstract class AbstractWizard<T extends Step> extends DialogWrapper {
|
||||
if (myIcon == null) {
|
||||
return;
|
||||
}
|
||||
final BufferedImage image = UIUtil.createImage((Graphics2D)g, myIcon.getIconWidth(), myIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
final BufferedImage image = UIUtil.createImage(g, myIcon.getIconWidth(), myIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
final Graphics2D gg = image.createGraphics();
|
||||
myIcon.paintIcon(this, gg, 0, 0);
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ public class LoadingDecorator {
|
||||
myCurrentAlpha = -1;
|
||||
|
||||
if (takeSnapshot && getWidth() > 0 && getHeight() > 0) {
|
||||
mySnapshot = UIUtil.createImage((Graphics2D)getGraphics(), getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
|
||||
mySnapshot = UIUtil.createImage(getGraphics(), getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
|
||||
final Graphics2D g = mySnapshot.createGraphics();
|
||||
myPane.paint(g);
|
||||
final Component opaque = UIUtil.findNearestOpaque(this);
|
||||
|
||||
@@ -111,7 +111,7 @@ public class ZoomingDelegate {
|
||||
|
||||
if (myCachedImage == null) {
|
||||
Rectangle bounds = myViewportComponent.getBounds();
|
||||
BufferedImage image = UIUtil.createImage((Graphics2D)myViewportComponent.getGraphics(), bounds.width, bounds.height, BufferedImage.TYPE_INT_RGB);
|
||||
BufferedImage image = UIUtil.createImage(myViewportComponent.getGraphics(), bounds.width, bounds.height, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
Graphics graphics = image.getGraphics();
|
||||
graphics.setClip(0, 0, bounds.width, bounds.height);
|
||||
|
||||
@@ -392,12 +392,12 @@ public class JBTabsImpl extends JComponent
|
||||
if (cmp.isShowing()) {
|
||||
final int width = cmp.getWidth();
|
||||
final int height = cmp.getHeight();
|
||||
img = UIUtil.createImage((Graphics2D)info.getComponent().getGraphics(), width > 0 ? width : 500, height > 0 ? height : 500, BufferedImage.TYPE_INT_ARGB);
|
||||
img = UIUtil.createImage(info.getComponent(), width > 0 ? width : 500, height > 0 ? height : 500, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = img.createGraphics();
|
||||
cmp.paint(g);
|
||||
}
|
||||
else {
|
||||
img = UIUtil.createImage((Graphics2D)info.getComponent().getGraphics(), 500, 500, BufferedImage.TYPE_INT_ARGB);
|
||||
img = UIUtil.createImage(info.getComponent(), 500, 500, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return img;
|
||||
}
|
||||
@@ -1370,7 +1370,7 @@ public class JBTabsImpl extends JComponent
|
||||
if (blocked && !myPaintBlocked) {
|
||||
if (takeSnapshot) {
|
||||
if (getWidth() > 0 && getHeight() > 0) {
|
||||
myImage = UIUtil.createImage((Graphics2D)getGraphics(), getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
myImage = UIUtil.createImage(this, getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
final Graphics2D g = myImage.createGraphics();
|
||||
super.paint(g);
|
||||
g.dispose();
|
||||
@@ -3283,7 +3283,7 @@ public class JBTabsImpl extends JComponent
|
||||
Dimension size = label.getPreferredSize();
|
||||
label.setBounds(0, 0, size.width, size.height);
|
||||
|
||||
BufferedImage img = UIUtil.createImage((Graphics2D)getGraphics(), size.width, size.height, BufferedImage.TYPE_INT_ARGB);
|
||||
BufferedImage img = UIUtil.createImage(this, size.width, size.height, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = img.createGraphics();
|
||||
label.paintOffscreen(g);
|
||||
g.dispose();
|
||||
|
||||
@@ -54,7 +54,7 @@ public class FadeInFadeOut extends JComponent {
|
||||
myRatio = myFadeIn ? 0 : 1;
|
||||
myIcon = icon;
|
||||
|
||||
myComponentImage = UIUtil.createImage((Graphics2D)myComponent.getGraphics(), myComponent.getWidth(), myComponent.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
myComponentImage = UIUtil.createImage(myComponent, myComponent.getWidth(), myComponent.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D graphics = myComponentImage.createGraphics();
|
||||
myComponent.paint(graphics);
|
||||
graphics.dispose();
|
||||
|
||||
+2
-2
@@ -85,7 +85,7 @@ public class EditorFragmentComponent extends JPanel {
|
||||
editor.getScrollingModel().scrollHorizontally(0);
|
||||
}
|
||||
|
||||
final BufferedImage textImage = UIUtil.createImage((Graphics2D)getGraphics(), textImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB);
|
||||
final BufferedImage textImage = UIUtil.createImage(this, textImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics textGraphics = textImage.getGraphics();
|
||||
EditorUIUtil.setupAntialiasing(textGraphics);
|
||||
|
||||
@@ -97,7 +97,7 @@ public class EditorFragmentComponent extends JPanel {
|
||||
rowHeader = editor.getGutterComponentEx();
|
||||
markersImageWidth = Math.max(1, rowHeader.getWidth());
|
||||
|
||||
markersImage = UIUtil.createImage((Graphics2D)editor.getComponent().getGraphics(), markersImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB);
|
||||
markersImage = UIUtil.createImage(editor.getComponent(), markersImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics markerGraphics = markersImage.getGraphics();
|
||||
EditorUIUtil.setupAntialiasing(markerGraphics);
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ public class DnDAwareTree extends Tree implements DnDAware {
|
||||
c.setBackground(tree.getBackground());
|
||||
c.setFont(tree.getFont());
|
||||
c.setSize(c.getPreferredSize());
|
||||
final BufferedImage image = UIUtil.createImage((Graphics2D)c.getGraphics(), c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
final BufferedImage image = UIUtil.createImage(c, c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g2 = (Graphics2D)image.getGraphics();
|
||||
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
|
||||
c.paint(g2);
|
||||
|
||||
@@ -235,7 +235,7 @@ public class ColorBlindnessInternalAction extends DumbAwareAction {
|
||||
array[i] = Color.HSBtoRGB(w / width, saturation, brightness);
|
||||
}
|
||||
}
|
||||
BufferedImage image = UIUtil.createImage((Graphics2D)g, bounds.width, bounds.height, BufferedImage.TYPE_INT_RGB);
|
||||
BufferedImage image = UIUtil.createImage(g, bounds.width, bounds.height, BufferedImage.TYPE_INT_RGB);
|
||||
image.setRGB(0, 0, bounds.width, bounds.height, array, 0, bounds.width);
|
||||
myImage = ImageUtil.filter(image, myFilter);
|
||||
}
|
||||
|
||||
+3
-3
@@ -636,7 +636,7 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark
|
||||
Rectangle componentBounds = c.getBounds();
|
||||
ProperTextRange docRange = ProperTextRange.create(0, componentBounds.height);
|
||||
if (myCachedTrack == null || myCachedHeight != componentBounds.height) {
|
||||
myCachedTrack = UIUtil.createImage((Graphics2D)c.getGraphics(), componentBounds.width, componentBounds.height, BufferedImage.TYPE_INT_ARGB);
|
||||
myCachedTrack = UIUtil.createImage(c, componentBounds.width, componentBounds.height, BufferedImage.TYPE_INT_ARGB);
|
||||
myCachedHeight = componentBounds.height;
|
||||
myDirtyYPositions = docRange;
|
||||
dimensionsAreValid = false;
|
||||
@@ -1218,7 +1218,7 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark
|
||||
myCacheStartLine = fitLineToEditor(myVisualLine - myCachePreviewLines);
|
||||
myCacheEndLine = fitLineToEditor(myCacheStartLine + 2 * myCachePreviewLines + 1);
|
||||
if (myCacheLevel2 == null) {
|
||||
myCacheLevel2 = UIUtil.createImage((Graphics2D)g, size.width, myEditor.getLineHeight() * (2 * myCachePreviewLines + 1), BufferedImage.TYPE_INT_RGB);
|
||||
myCacheLevel2 = UIUtil.createImage(g, size.width, myEditor.getLineHeight() * (2 * myCachePreviewLines + 1), BufferedImage.TYPE_INT_RGB);
|
||||
}
|
||||
Graphics2D cg = myCacheLevel2.createGraphics();
|
||||
final AffineTransform t = cg.getTransform();
|
||||
@@ -1247,7 +1247,7 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark
|
||||
|
||||
}
|
||||
if (myCacheLevel1 == null) {
|
||||
myCacheLevel1 = UIUtil.createImage((Graphics2D)g, size.width, myEditor.getLineHeight() * (2 * myPreviewLines + 1), BufferedImage.TYPE_INT_RGB);
|
||||
myCacheLevel1 = UIUtil.createImage(g, size.width, myEditor.getLineHeight() * (2 * myPreviewLines + 1), BufferedImage.TYPE_INT_RGB);
|
||||
isDirty = true;
|
||||
}
|
||||
if (isDirty) {
|
||||
|
||||
@@ -509,7 +509,7 @@ final class Stripe extends JPanel implements UISettingsListener {
|
||||
|
||||
public void processDropButton(final StripeButton button, JComponent buttonImage, Point screenPoint) {
|
||||
if (!isDroppingButton()) {
|
||||
final BufferedImage image = UIUtil.createImage((Graphics2D)button.getGraphics(), button.getWidth(), button.getHeight(), BufferedImage.TYPE_INT_RGB);
|
||||
final BufferedImage image = UIUtil.createImage(button, button.getWidth(), button.getHeight(), BufferedImage.TYPE_INT_RGB);
|
||||
buttonImage.paint(image.getGraphics());
|
||||
myDragButton = button;
|
||||
myDragButtonImage = buttonImage;
|
||||
|
||||
@@ -186,7 +186,7 @@ public final class StripeButton extends AnchoredButton implements ActionListener
|
||||
if (myDragPane == null) return;
|
||||
int width = getWidth() - 1; // -1 because StripeButtonUI.paint will not paint 1 pixel in case (anchor == ToolWindowAnchor.LEFT)
|
||||
int height = getHeight() - 1; // -1 because StripeButtonUI.paint will not paint 1 pixel in case (anchor.isHorizontal())
|
||||
BufferedImage image = UIUtil.createImage((Graphics2D)e.getComponent().getGraphics(), width, height, BufferedImage.TYPE_INT_RGB);
|
||||
BufferedImage image = UIUtil.createImage(e.getComponent(), width, height, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics graphics = image.getGraphics();
|
||||
graphics.setColor(UIUtil.getBgFillColor(getParent()));
|
||||
graphics.fillRect(0, 0, width, height);
|
||||
|
||||
@@ -1264,7 +1264,7 @@ public final class ToolWindowsPane extends JBLayeredPane implements UISettingsLi
|
||||
// is MUCH faster.
|
||||
// On Mac we create a retina-compatible image
|
||||
|
||||
image = UIUtil.createImage((Graphics2D)getGraphics(), width, height, BufferedImage.TYPE_INT_RGB);
|
||||
image = UIUtil.createImage(getGraphics(), width, height, BufferedImage.TYPE_INT_RGB);
|
||||
}
|
||||
imageRef = new SoftReference<>(image);
|
||||
}
|
||||
|
||||
+1
-1
@@ -141,7 +141,7 @@ public class MemoryUsagePanel extends JButton implements CustomStatusBarWidget {
|
||||
final Dimension size = getSize();
|
||||
final Insets insets = getInsets();
|
||||
|
||||
myBufferedImage = UIUtil.createImage((Graphics2D)g, size.width, size.height, BufferedImage.TYPE_INT_ARGB);
|
||||
myBufferedImage = UIUtil.createImage(g, size.width, size.height, BufferedImage.TYPE_INT_ARGB);
|
||||
final Graphics2D g2 = (Graphics2D)myBufferedImage.getGraphics().create();
|
||||
|
||||
final Runtime rt = Runtime.getRuntime();
|
||||
|
||||
@@ -358,7 +358,7 @@ public abstract class AbstractExpandableItemsHandler<KeyType, ComponentType exte
|
||||
if (width <= 0 || height <= 0) return null;
|
||||
|
||||
Dimension size = getImageSize(width, height);
|
||||
myImage = UIUtil.createImage((Graphics2D)renderer.getGraphics(), size.width, size.height, BufferedImage.TYPE_INT_RGB);
|
||||
myImage = UIUtil.createImage(renderer, size.width, size.height, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
Graphics2D g = myImage.createGraphics();
|
||||
g.setClip(null);
|
||||
|
||||
@@ -539,7 +539,7 @@ public abstract class AppIcon {
|
||||
if (text != null) {
|
||||
try {
|
||||
int size = 16;
|
||||
BufferedImage image = UIUtil.createImage((Graphics2D)frame.getComponent().getGraphics(), size, size, BufferedImage.TYPE_INT_ARGB);
|
||||
BufferedImage image = UIUtil.createImage(frame.getComponent(), size, size, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = image.createGraphics();
|
||||
|
||||
int shadowRadius = 16;
|
||||
|
||||
@@ -1640,7 +1640,7 @@ public class BalloonImpl implements Balloon, IdeTooltip.Ui {
|
||||
private void paintChildrenImpl(Graphics g) {
|
||||
// Paint to an image without alpha to preserve fonts subpixel antialiasing
|
||||
@SuppressWarnings("UndesirableClassUsage")
|
||||
BufferedImage image = UIUtil.createImage((Graphics2D)g, getWidth(), getHeight(),
|
||||
BufferedImage image = UIUtil.createImage(g, getWidth(), getHeight(),
|
||||
BufferedImage.TYPE_INT_RGB);//new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D imageGraphics = image.createGraphics();
|
||||
//noinspection UseJBColor
|
||||
@@ -1742,7 +1742,7 @@ public class BalloonImpl implements Balloon, IdeTooltip.Ui {
|
||||
private void initComponentImage(Point pointTarget, Rectangle shapeBounds) {
|
||||
if (myImage != null) return;
|
||||
|
||||
myImage = UIUtil.createImage((Graphics2D)myComp.getGraphics(), getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
myImage = UIUtil.createImage(myComp, getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D imageGraphics = (Graphics2D)myImage.getGraphics();
|
||||
myBalloon.myPosition.paintComponent(myBalloon, shapeBounds, imageGraphics, pointTarget);
|
||||
paintChildrenImpl(imageGraphics);
|
||||
|
||||
@@ -1127,7 +1127,7 @@ public class ColorPicker extends JPanel implements ColorListener, DocumentListen
|
||||
});
|
||||
|
||||
pickerDialog.setSize(DIALOG_SIZE, DIALOG_SIZE);
|
||||
myMaskImage = UIUtil.createImage((Graphics2D)pickerDialog.getGraphics(), SIZE, SIZE, BufferedImage.TYPE_INT_ARGB);
|
||||
myMaskImage = UIUtil.createImage(pickerDialog, SIZE, SIZE, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D maskG = myMaskImage.createGraphics();
|
||||
maskG.setColor(Color.BLUE);
|
||||
maskG.fillRect(0, 0, SIZE, SIZE);
|
||||
@@ -1137,7 +1137,7 @@ public class ColorPicker extends JPanel implements ColorListener, DocumentListen
|
||||
maskG.fillRect(0, 0, SIZE, SIZE);
|
||||
maskG.dispose();
|
||||
|
||||
myPipetteImage = UIUtil.createImage((Graphics2D)pickerDialog.getGraphics(), AllIcons.Ide.Pipette.getIconWidth(), AllIcons.Ide.Pipette.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
myPipetteImage = UIUtil.createImage(pickerDialog, AllIcons.Ide.Pipette.getIconWidth(), AllIcons.Ide.Pipette.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D graphics = myPipetteImage.createGraphics();
|
||||
//noinspection ConstantConditions
|
||||
AllIcons.Ide.Pipette.paintIcon(null, graphics, 0, 0);
|
||||
|
||||
@@ -239,7 +239,7 @@ public class DockManagerImpl extends DockManager implements PersistentStateCompo
|
||||
ratio = requiredSize / height;
|
||||
}
|
||||
|
||||
BufferedImage buffer = UIUtil.createImage((Graphics2D)myWindow.getGraphics(), (int)width, (int)height, BufferedImage.TYPE_INT_ARGB);
|
||||
BufferedImage buffer = UIUtil.createImage(myWindow, (int)width, (int)height, BufferedImage.TYPE_INT_ARGB);
|
||||
buffer.createGraphics().drawImage(previewImage, 0, 0, (int)width, (int)height, null);
|
||||
|
||||
myDefaultDragImage = buffer.getScaledInstance((int)(width * ratio), (int)(height * ratio), Image.SCALE_SMOOTH);
|
||||
|
||||
@@ -136,7 +136,7 @@ public class MacColorPipette extends ColorPipetteBase {
|
||||
pickerDialog.setSize(DIALOG_SIZE, DIALOG_SIZE);
|
||||
pickerDialog.setBackground(myTransparentColor);
|
||||
|
||||
BufferedImage emptyImage = UIUtil.createImage((Graphics2D)pickerDialog.getGraphics(), 1, 1, Transparency.TRANSLUCENT);
|
||||
BufferedImage emptyImage = UIUtil.createImage(pickerDialog, 1, 1, Transparency.TRANSLUCENT);
|
||||
pickerDialog.setCursor(myParent.getToolkit().createCustomCursor(emptyImage, new Point(0, 0), "ColorPicker"));
|
||||
}
|
||||
return pickerDialog;
|
||||
|
||||
@@ -16,11 +16,13 @@
|
||||
package com.intellij.util.ui;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.ScalableIcon;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.ui.border.CustomLineBorder;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import com.intellij.util.keyFMap.KeyFMap;
|
||||
import com.intellij.util.ui.components.BorderLayoutPanel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -125,7 +127,9 @@ public class JBUI {
|
||||
* @see #pixScale(Graphics2D)
|
||||
* @see #pixScale(float)
|
||||
*/
|
||||
PIX,
|
||||
PIX;
|
||||
|
||||
private final Key<Float> key = Key.create(name());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -703,11 +707,15 @@ public class JBUI {
|
||||
// ScaleType.USR - tracked
|
||||
// ScaleType.SYS - tracked
|
||||
// ScaleType.PIX - derived
|
||||
Map<ScaleType, Float> myTrackedJBUIScale = new HashMap<ScaleType, Float>();
|
||||
KeyFMap myTrackedJBUIScale = KeyFMap.EMPTY_MAP;
|
||||
|
||||
JBUIScaleTracker() {
|
||||
myTrackedJBUIScale.put(ScaleType.USR, JBIcon.currentJBUIScale());
|
||||
myTrackedJBUIScale.put(ScaleType.SYS, sysScale());
|
||||
{
|
||||
put(ScaleType.USR.key, JBIcon.currentJBUIScale());
|
||||
put(ScaleType.SYS.key, sysScale());
|
||||
}
|
||||
|
||||
private void put(Key<Float> key, Float value) {
|
||||
myTrackedJBUIScale = myTrackedJBUIScale.plus(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -717,7 +725,7 @@ public class JBUI {
|
||||
|
||||
private boolean updateJBUIScale(float scale, ScaleType type) {
|
||||
if (needUpdateJBUIScale(scale, type)) {
|
||||
myTrackedJBUIScale.put(type, scale);
|
||||
put(type.key, scale);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -746,10 +754,9 @@ public class JBUI {
|
||||
|
||||
@Override
|
||||
public float getJBUIScale(ScaleType type) {
|
||||
if (type == ScaleType.PIX) {
|
||||
return pixScale(this); // derive
|
||||
}
|
||||
return myTrackedJBUIScale.get(type);
|
||||
return type == ScaleType.PIX ?
|
||||
pixScale(this) : // derive
|
||||
myTrackedJBUIScale.get(type.key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -356,14 +356,15 @@ public class UIUtil {
|
||||
}
|
||||
|
||||
private static Boolean jdkManagedHiDPI;
|
||||
private static Method isUIScaleOnMethod;
|
||||
|
||||
/**
|
||||
* Returns whether the JDK-managed HiDPI mode is enabled.
|
||||
* (True for macOS JDK >= 7.10 versions)
|
||||
*/
|
||||
public static boolean isJDKManagedHiDPI() {
|
||||
if (jdkManagedHiDPI != null) return jdkManagedHiDPI;
|
||||
if (jdkManagedHiDPI != null) {
|
||||
return jdkManagedHiDPI;
|
||||
}
|
||||
if (SystemInfo.isMac) {
|
||||
return jdkManagedHiDPI = (SystemInfo.isAppleJvm ? false : true);
|
||||
}
|
||||
@@ -371,8 +372,8 @@ public class UIUtil {
|
||||
try {
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
if (ge instanceof SunGraphicsEnvironment) {
|
||||
isUIScaleOnMethod = ReflectionUtil.getDeclaredMethod(SunGraphicsEnvironment.class, "isUIScaleOn");
|
||||
jdkManagedHiDPI = (Boolean)isUIScaleOnMethod.invoke(ge);
|
||||
Method m = ReflectionUtil.getDeclaredMethod(SunGraphicsEnvironment.class, "isUIScaleOn");
|
||||
jdkManagedHiDPI = (Boolean)m.invoke(ge);
|
||||
}
|
||||
} catch (Throwable ignore) {
|
||||
}
|
||||
@@ -1886,9 +1887,9 @@ public class UIUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a HiDPI-aware BufferedImage in the graphics scale.
|
||||
* Creates a HiDPI-aware BufferedImage in the graphics device scale.
|
||||
*
|
||||
* @param g the graphics of the referent scale
|
||||
* @param g the graphics of the target device
|
||||
* @param width the width in user coordinate space
|
||||
* @param height the height in user coordinate space
|
||||
* @param type the type of the image
|
||||
@@ -1896,16 +1897,36 @@ public class UIUtil {
|
||||
* @return a HiDPI-aware BufferedImage in the graphics scale
|
||||
*/
|
||||
@NotNull
|
||||
public static BufferedImage createImage(Graphics2D g, int width, int height, int type) {
|
||||
if (isJDKManagedHiDPIScreen(g)) {
|
||||
return RetinaImage.create(g, width, height, type);
|
||||
public static BufferedImage createImage(Graphics g, int width, int height, int type) {
|
||||
if (g instanceof Graphics2D) {
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
if (isJDKManagedHiDPIScreen(g2d)) {
|
||||
return RetinaImage.create(g2d, width, height, type);
|
||||
}
|
||||
}
|
||||
//noinspection UndesirableClassUsage
|
||||
return new BufferedImage(width, height, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #createImage(Graphics2D, int, int, int)}.
|
||||
* Creates a HiDPI-aware BufferedImage in the component scale.
|
||||
*
|
||||
* @param comp the component associated with the target graphics device
|
||||
* @param width the width in user coordinate space
|
||||
* @param height the height in user coordinate space
|
||||
* @param type the type of the image
|
||||
*
|
||||
* @return a HiDPI-aware BufferedImage in the component scale
|
||||
*/
|
||||
@NotNull
|
||||
public static BufferedImage createImage(Component comp, int width, int height, int type) {
|
||||
return comp != null ?
|
||||
createImage(comp.getGraphics(), width, height, type) :
|
||||
createImage(width, height, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #createImage(Graphics2D, int, int, int)}
|
||||
*/
|
||||
@NotNull
|
||||
public static BufferedImage createImageForGraphics(Graphics2D g, int width, int height, int type) {
|
||||
@@ -3762,7 +3783,7 @@ public class UIUtil {
|
||||
}
|
||||
|
||||
public static Image getDebugImage(Component component) {
|
||||
BufferedImage image = createImage((Graphics2D)component.getGraphics(), component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
BufferedImage image = createImage(component, component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D graphics = image.createGraphics();
|
||||
graphics.setColor(Color.RED);
|
||||
graphics.fillRect(0, 0, component.getWidth() + 1, component.getHeight() + 1);
|
||||
|
||||
@@ -241,7 +241,7 @@ public class JBTerminalPanel extends TerminalPanel implements FocusListener, Ter
|
||||
|
||||
@Override
|
||||
protected BufferedImage createBufferedImage(int width, int height) {
|
||||
return UIUtil.createImage((Graphics2D)getGraphics(), width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
return UIUtil.createImage(this, width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user