This commit is contained in:
Alexey Kudravtsev
2017-05-20 13:32:14 +03:00
parent 138fba453c
commit 70bcbe6101
@@ -245,12 +245,12 @@ public class UIUtil {
@NonNls public static final String CENTER_TOOLTIP_DEFAULT = "ToCenterTooltip";
@NonNls public static final String CENTER_TOOLTIP_STRICT = "ToCenterTooltip.default";
public static final Pattern CLOSE_TAG_PATTERN = Pattern.compile("<\\s*([^<>/ ]+)([^<>]*)/\\s*>", Pattern.CASE_INSENSITIVE);
private static final Pattern CLOSE_TAG_PATTERN = Pattern.compile("<\\s*([^<>/ ]+)([^<>]*)/\\s*>", Pattern.CASE_INSENSITIVE);
@NonNls public static final String FOCUS_PROXY_KEY = "isFocusProxy";
@NonNls private static final String FOCUS_PROXY_KEY = "isFocusProxy";
public static Key<Integer> KEEP_BORDER_SIDES = Key.create("keepBorderSides");
private static Key<UndoManager> UNDO_MANAGER = Key.create("undoManager");
public static final Key<Integer> KEEP_BORDER_SIDES = Key.create("keepBorderSides");
private static final Key<UndoManager> UNDO_MANAGER = Key.create("undoManager");
private static final AbstractAction REDO_ACTION = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -406,7 +406,7 @@ public class UIUtil {
}
}
if (SystemInfo.isMac) {
return jreHiDPI = (!SystemInfo.isAppleJvm);
jreHiDPI = !SystemInfo.isAppleJvm;
}
return jreHiDPI;
}
@@ -424,9 +424,9 @@ public class UIUtil {
/**
* Utility class for retina routine
*/
final static class DetectRetinaKit {
static final class DetectRetinaKit {
private final static WeakHashMap<GraphicsDevice, Boolean> devicesToRetinaSupportCacheMap = new WeakHashMap<GraphicsDevice, Boolean>();
private static final WeakHashMap<GraphicsDevice, Boolean> devicesToRetinaSupportCacheMap = new WeakHashMap<GraphicsDevice, Boolean>();
/**
* The best way to understand whether we are on a retina device is [NSScreen backingScaleFactor]
@@ -541,9 +541,8 @@ public class UIUtil {
public static boolean isRetina (Graphics2D graphics) {
if (SystemInfo.isMac && SystemInfo.isJavaVersionAtLeast("1.7")) {
return DetectRetinaKit.isMacRetina(graphics);
} else {
return isRetina();
}
return isRetina();
}
//public static boolean isMacRetina(Graphics2D g) {
@@ -642,7 +641,6 @@ public class UIUtil {
/**
* @param component a Swing component that may hold a client property value
* @param key the client property key that specifies a return type
* @return the property value from the specified component or {@code null}
*/
public static <T> T getClientProperty(Object component, @NotNull Class<T> type) {
@@ -802,7 +800,7 @@ public class UIUtil {
currentAtom.setLength(0);
}
String s = currentLine + currentAtom.toString();
String s = currentLine + currentAtom;
int width = fontMetrics.stringWidth(s);
if (width >= widthLimit - fontMetrics.charWidth('w')) {
@@ -817,7 +815,7 @@ public class UIUtil {
}
}
String s = currentLine + currentAtom.toString();
String s = currentLine + currentAtom;
if (!s.isEmpty()) {
lines.add(s);
}
@@ -1373,7 +1371,7 @@ public class UIUtil {
}
public static Icon getTreeNodeIcon(boolean expanded, boolean selected, boolean focused) {
boolean white = (selected && focused) || isUnderDarcula();
boolean white = selected && focused || isUnderDarcula();
Icon selectedIcon = getTreeSelectedExpandedIcon();
Icon notSelectedIcon = getTreeExpandedIcon();
@@ -1403,7 +1401,7 @@ public class UIUtil {
isUnderNimbusLookAndFeel() ||
isUnderGTKLookAndFeel() ||
isUnderDarcula() ||
(isUnderIntelliJLaF() && !(SystemInfo.isWindows && Registry.is("ide.intellij.laf.win10.ui")))) {
isUnderIntelliJLaF() && !(SystemInfo.isWindows && Registry.is("ide.intellij.laf.win10.ui"))) {
return AllIcons.Mac.Tree_white_right_arrow;
}
return getTreeCollapsedIcon();
@@ -1414,7 +1412,7 @@ public class UIUtil {
isUnderNimbusLookAndFeel() ||
isUnderGTKLookAndFeel() ||
isUnderDarcula() ||
(isUnderIntelliJLaF() && !(SystemInfo.isWindows && Registry.is("ide.intellij.laf.win10.ui")))) {
isUnderIntelliJLaF() && !(SystemInfo.isWindows && Registry.is("ide.intellij.laf.win10.ui"))) {
return AllIcons.Mac.Tree_white_down_arrow;
}
return getTreeExpandedIcon();
@@ -1436,47 +1434,47 @@ public class UIUtil {
return UIManager.getColor("OptionPane.background");
}
@SuppressWarnings({"HardCodedStringLiteral"})
@SuppressWarnings("HardCodedStringLiteral")
public static boolean isUnderAlloyLookAndFeel() {
return UIManager.getLookAndFeel().getName().contains("Alloy");
}
@SuppressWarnings({"HardCodedStringLiteral"})
@SuppressWarnings("HardCodedStringLiteral")
public static boolean isUnderAlloyIDEALookAndFeel() {
return isUnderAlloyLookAndFeel() && UIManager.getLookAndFeel().getName().contains("IDEA");
}
@SuppressWarnings({"HardCodedStringLiteral"})
@SuppressWarnings("HardCodedStringLiteral")
public static boolean isUnderWindowsLookAndFeel() {
return SystemInfo.isWindows && UIManager.getLookAndFeel().getName().equals("Windows");
}
@SuppressWarnings({"HardCodedStringLiteral"})
@SuppressWarnings("HardCodedStringLiteral")
public static boolean isUnderWindowsClassicLookAndFeel() {
return UIManager.getLookAndFeel().getName().equals("Windows Classic");
}
@SuppressWarnings({"HardCodedStringLiteral"})
@SuppressWarnings("HardCodedStringLiteral")
public static boolean isUnderNimbusLookAndFeel() {
return UIManager.getLookAndFeel().getName().contains("Nimbus");
}
@SuppressWarnings({"HardCodedStringLiteral"})
@SuppressWarnings("HardCodedStringLiteral")
public static boolean isUnderAquaLookAndFeel() {
return SystemInfo.isMac && UIManager.getLookAndFeel().getName().contains("Mac OS X");
}
@SuppressWarnings({"HardCodedStringLiteral"})
@SuppressWarnings("HardCodedStringLiteral")
public static boolean isUnderJGoodiesLookAndFeel() {
return UIManager.getLookAndFeel().getName().contains("JGoodies");
}
@SuppressWarnings({"HardCodedStringLiteral"})
@SuppressWarnings("HardCodedStringLiteral")
public static boolean isUnderAquaBasedLookAndFeel() {
return SystemInfo.isMac && (isUnderAquaLookAndFeel() || isUnderDarcula() || isUnderIntelliJLaF());
}
@SuppressWarnings({"HardCodedStringLiteral"})
@SuppressWarnings("HardCodedStringLiteral")
public static boolean isUnderDarcula() {
return UIManager.getLookAndFeel().getName().contains("Darcula");
}
@@ -1489,12 +1487,12 @@ public class UIUtil {
return SystemInfo.isWindows && isUnderIntelliJLaF() && Registry.is("ide.intellij.laf.win10.ui");
}
@SuppressWarnings({"HardCodedStringLiteral"})
@SuppressWarnings("HardCodedStringLiteral")
public static boolean isUnderIntelliJLaF() {
return UIManager.getLookAndFeel().getName().contains("IntelliJ");
}
@SuppressWarnings({"HardCodedStringLiteral"})
@SuppressWarnings("HardCodedStringLiteral")
public static boolean isUnderGTKLookAndFeel() {
return SystemInfo.isXWindow && UIManager.getLookAndFeel().getName().contains("GTK");
}
@@ -1502,7 +1500,7 @@ public class UIUtil {
public static final Color GTK_AMBIANCE_TEXT_COLOR = new Color(223, 219, 210);
public static final Color GTK_AMBIANCE_BACKGROUND_COLOR = new Color(67, 66, 63);
@SuppressWarnings({"HardCodedStringLiteral"})
@SuppressWarnings("HardCodedStringLiteral")
@Nullable
public static String getGtkThemeName() {
final LookAndFeel laf = UIManager.getLookAndFeel();
@@ -1521,7 +1519,7 @@ public class UIUtil {
return null;
}
@SuppressWarnings({"HardCodedStringLiteral"})
@SuppressWarnings("HardCodedStringLiteral")
public static boolean isMurrineBasedTheme() {
final String gtkTheme = getGtkThemeName();
return "Ambiance".equalsIgnoreCase(gtkTheme) ||
@@ -1719,7 +1717,7 @@ public class UIUtil {
final Color bgColor,
final Color fgColor,
final boolean opaque) {
if ((SystemInfo.isMac && !isRetina()) || SystemInfo.isLinux) {
if (SystemInfo.isMac && !isRetina() || SystemInfo.isLinux) {
drawAppleDottedLine(g, startX, endX, lineY, bgColor, fgColor, opaque);
}
else {
@@ -1909,7 +1907,6 @@ public class UIUtil {
/** This method is intended to use when user settings are not accessible yet.
* Use it to set up default RenderingHints.
* @param g
*/
public static void applyRenderingHints(final Graphics g) {
Graphics2D g2d = (Graphics2D)g;
@@ -1993,12 +1990,12 @@ public class UIUtil {
@NotNull
public static BufferedImage createImage(Component comp, int width, int height, int type) {
return comp != null ?
createImage(comp != null ? comp.getGraphicsConfiguration() : null, width, height, type) :
createImage(comp.getGraphicsConfiguration(), width, height, type) :
createImage(width, height, type);
}
/**
* @deprecated use {@link #createImage(Graphics2D, int, int, int)}
* @deprecated use {@link #createImage(Graphics, int, int, int)}
*/
@NotNull
public static BufferedImage createImageForGraphics(Graphics2D g, int width, int height, int type) {
@@ -2527,7 +2524,7 @@ public class UIUtil {
}
public static class JBHtmlEditorKit extends HTMLEditorKit {
private StyleSheet style;
private final StyleSheet style;
public JBHtmlEditorKit() {
this(true);
@@ -2801,7 +2798,7 @@ public class UIUtil {
if (systemLaFClassName != null) {
return systemLaFClassName;
}
else if (SystemInfo.isLinux) {
if (SystemInfo.isLinux) {
// Normally, GTK LaF is considered "system" when:
// 1) Gnome session is run
// 2) gtk lib is available
@@ -2876,7 +2873,8 @@ public class UIUtil {
int dpi = 96;
try {
dpi = Toolkit.getDefaultToolkit().getScreenResolution();
} catch (HeadlessException e) {
}
catch (HeadlessException ignored) {
}
float scale = 1f;
if (dpi < 120) scale = 1f;
@@ -2957,7 +2955,7 @@ public class UIUtil {
return null;
}
@SuppressWarnings({"HardCodedStringLiteral"})
@SuppressWarnings("HardCodedStringLiteral")
public static void fixFormattedField(JFormattedTextField field) {
if (SystemInfo.isMac) {
final Toolkit toolkit = Toolkit.getDefaultToolkit();
@@ -3135,7 +3133,7 @@ public class UIUtil {
@Nullable
public static <T extends JComponent> T findComponentOfType(JComponent parent, Class<T> cls) {
if (parent == null || cls.isAssignableFrom(parent.getClass())) {
@SuppressWarnings({"unchecked"}) final T t = (T)parent;
@SuppressWarnings("unchecked") final T t = (T)parent;
return t;
}
for (Component component : parent.getComponents()) {
@@ -3156,7 +3154,7 @@ public class UIUtil {
private static <T extends JComponent> void findComponentsOfType(JComponent parent, Class<T> cls, ArrayList<T> result) {
if (parent == null) return;
if (cls.isAssignableFrom(parent.getClass())) {
@SuppressWarnings({"unchecked"}) final T t = (T)parent;
@SuppressWarnings("unchecked") final T t = (T)parent;
result.add(t);
}
for (Component c : parent.getComponents()) {
@@ -3248,10 +3246,10 @@ public class UIUtil {
* _position(block width, block height) => (x, y) of the block
*/
public void draw(@NotNull final Graphics g, final PairFunction<Integer, Integer, Couple<Integer>> _position) {
GraphicsUtil.setupAntialiasing(g, true, true);
final int[] maxWidth = {0};
final int[] height = {0};
final int[] maxBulletWidth = {0};
GraphicsUtil.setupAntialiasing(g, true, true);
ContainerUtil.process(myLines, new Processor<Pair<String, LineInfo>>() {
@Override
public boolean process(final Pair<String, LineInfo> pair) {
@@ -3384,7 +3382,7 @@ public class UIUtil {
Component eachParent = c;
while (eachParent != null) {
if (eachParent instanceof JComponent) {
@SuppressWarnings({"unchecked"}) WeakReference<JRootPane> pane =
@SuppressWarnings("unchecked") WeakReference<JRootPane> pane =
(WeakReference<JRootPane>)((JComponent)eachParent).getClientProperty(ROOT_PANE);
if (pane != null) return pane.get();
}
@@ -3562,7 +3560,7 @@ public class UIUtil {
lcdContrastValue = 140;
} else {
Object o = map.get(RenderingHints.KEY_TEXT_LCD_CONTRAST);
lcdContrastValue = (o == null) ? 140 : ((Integer)o);
lcdContrastValue = o == null ? 140 : (Integer)o;
}
}
}
@@ -3601,7 +3599,7 @@ public class UIUtil {
@NotNull
public static Paint getGradientPaint(float x1, float y1, @NotNull Color c1, float x2, float y2, @NotNull Color c2) {
return (Registry.is("ui.no.bangs.and.whistles")) ? ColorUtil.mix(c1, c2, .5) : new GradientPaint(x1, y1, c1, x2, y2, c2);
return Registry.is("ui.no.bangs.and.whistles") ? ColorUtil.mix(c1, c2, .5) : new GradientPaint(x1, y1, c1, x2, y2, c2);
}
@Nullable
@@ -3707,6 +3705,7 @@ public class UIUtil {
for (final UndoableEditListener listener : undoableEditListeners) {
if (listener instanceof UndoManager) {
Runnable runnable = new Runnable() {
@Override
public void run() {
((UndoManager)listener).discardAllEdits();
}