diff --git a/platform/platform-impl/src/com/intellij/ui/AppUIUtil.java b/platform/platform-impl/src/com/intellij/ui/AppUIUtil.java index 2ffcc3c422ec..ab97eb8e8fab 100644 --- a/platform/platform-impl/src/com/intellij/ui/AppUIUtil.java +++ b/platform/platform-impl/src/com/intellij/ui/AppUIUtil.java @@ -456,6 +456,10 @@ public class AppUIUtil { public static void targetToDevice(@NotNull Component comp, @Nullable Component target) { if (comp.isShowing()) return; GraphicsConfiguration gc = target != null ? target.getGraphicsConfiguration() : null; + setGraphicsConfiguration(comp, gc); + } + + public static void setGraphicsConfiguration(@NotNull Component comp, @Nullable GraphicsConfiguration gc) { AWTAccessor.getComponentAccessor().setGraphicsConfiguration(comp, gc); } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/ui/layout/SpacingConfiguration.kt b/platform/platform-impl/src/com/intellij/ui/layout/SpacingConfiguration.kt index af92670bd5b1..33700e3e42ad 100644 --- a/platform/platform-impl/src/com/intellij/ui/layout/SpacingConfiguration.kt +++ b/platform/platform-impl/src/com/intellij/ui/layout/SpacingConfiguration.kt @@ -19,7 +19,7 @@ fun createIntelliJSpacingConfiguration(): SpacingConfiguration { return object : SpacingConfiguration { override val labelColumnVerticalTopGap = JBUI.scale(labelColumnVerticalTopGap) - override val isCompensateVisualPaddings = SystemInfoRt.isMac || isUnderWin10LookAndFeel + override val isCompensateVisualPaddings = !SystemInfoRt.isLinux override val horizontalGap = JBUI.scale(8) override val verticalGap = JBUI.scale(5 * 2) diff --git a/platform/platform-tests/testData/ui/layout/Darcula/align fields in the nested grid.yml b/platform/platform-tests/testData/ui/layout/Darcula/align fields in the nested grid.yml index dc71a55517ba..23ca650a6a5e 100644 --- a/platform/platform-tests/testData/ui/layout/Darcula/align fields in the nested grid.yml +++ b/platform/platform-tests/testData/ui/layout/Darcula/align fields in the nested grid.yml @@ -12,7 +12,6 @@ layoutConstraints: - {horizontal: true, unit: 0, value: 0.0} - {horizontal: false, unit: 0, value: 0.0} - {horizontal: true, unit: 0, value: 0.0} - visualPadding: false rowConstraints: constraints: - align: {horizontal: false, unit: 6, value: 0.0} @@ -41,7 +40,7 @@ componentConstrains: 'Database:': horizontal: gapBefore: - min: &id006 {horizontal: true, value: 23.0} + min: &id006 {horizontal: true, value: 21.0} preferred: *id006 vertical: gapBefore: @@ -61,7 +60,7 @@ componentConstrains: 'Master Password:': horizontal: gapBefore: - min: &id009 {horizontal: true, value: 23.0} + min: &id009 {horizontal: true, value: 21.0} preferred: *id009 vertical: gapBefore: @@ -78,18 +77,18 @@ componentConstrains: spanX: 2097051 wrap: true cellBounds: -- [0, 0, 480, 23] -- [0, 33, 115, 32] -- [121, 33, 351, 32] -- [121, 33, 351, 32] -- [0, 75, 115, 30] -- [121, 75, 359, 30] -- [121, 111, 359, 16] +- [0, 0, 480, 24] +- [0, 34, 113, 24] +- [119, 34, 353, 24] +- [119, 34, 353, 24] +- [0, 68, 113, 25] +- [119, 68, 361, 25] +- [119, 99, 361, 16] componentBounds: - In KeePass: [0, 0, 78, 23] - 'Database:': [23, 41, 51, 16] - 'JTextField #2': [121, 33, 326, 32] - 'JLabel #3': [451, 41, 21, 16] - 'Master Password:': [23, 81, 92, 16] - 'JBPasswordField #5': [121, 75, 250, 30] - Stored using weak encryption.: [122, 111, 159, 16] + In KeePass: [-2, 0, 78, 24] + 'Database:': [21, 38, 51, 16] + 'JTextField #2': [117, 32, 332, 28] + 'JLabel #3': [451, 38, 21, 16] + 'Master Password:': [21, 72, 92, 16] + 'JBPasswordField #5': [117, 67, 254, 28] + Stored using weak encryption.: [120, 99, 159, 16] diff --git a/platform/platform-tests/testData/ui/layout/Darcula/align fields.yml b/platform/platform-tests/testData/ui/layout/Darcula/align fields.yml index fcbe63484296..3d923fa49677 100644 --- a/platform/platform-tests/testData/ui/layout/Darcula/align fields.yml +++ b/platform/platform-tests/testData/ui/layout/Darcula/align fields.yml @@ -12,7 +12,6 @@ layoutConstraints: - {horizontal: true, unit: 0, value: 0.0} - {horizontal: false, unit: 0, value: 0.0} - {horizontal: true, unit: 0, value: 0.0} - visualPadding: false rowConstraints: constraints: - align: {horizontal: false, unit: 6, value: 0.0} @@ -47,11 +46,11 @@ componentConstrains: spanX: 2097051 wrap: true cellBounds: -- [0, 0, 124, 22] -- [130, 0, 350, 22] -- [0, 32, 124, 32] -- [130, 32, 350, 32] +- [0, 0, 124, 24] +- [130, 0, 350, 24] +- [0, 34, 124, 24] +- [130, 34, 350, 24] componentBounds: Create Android module: [0, 4, 124, 16] - 'Android module name:': [0, 36, 123, 16] - 'JTextField #3': [130, 32, 350, 32] + 'Android module name:': [0, 38, 123, 16] + 'JTextField #3': [128, 32, 354, 28] diff --git a/platform/platform-tests/testData/ui/layout/Darcula/cell.yml b/platform/platform-tests/testData/ui/layout/Darcula/cell.yml index 53452f2c7b3c..7c38ed00992b 100644 --- a/platform/platform-tests/testData/ui/layout/Darcula/cell.yml +++ b/platform/platform-tests/testData/ui/layout/Darcula/cell.yml @@ -12,7 +12,6 @@ layoutConstraints: - {horizontal: true, unit: 0, value: 0.0} - {horizontal: false, unit: 0, value: 0.0} - {horizontal: true, unit: 0, value: 0.0} - visualPadding: false rowConstraints: constraints: - align: {horizontal: false, unit: 6, value: 0.0} @@ -53,7 +52,7 @@ componentConstrains: Use File -> Settings Repository... to configure: horizontal: gapBefore: - min: &id008 {horizontal: true, value: 4.0} + min: &id008 {horizontal: true, value: 1.0} preferred: *id008 skip: 1 spanX: 2097051 @@ -65,14 +64,14 @@ componentConstrains: vertical: {grow: 100.0} wrap: true cellBounds: -- [0, 0, 59, 30] -- [65, 0, 407, 30] -- [65, 0, 407, 30] -- [65, 36, 415, 16] -- [0, 62, 480, 248] +- [0, 0, 59, 24] +- [65, 0, 407, 24] +- [65, 0, 407, 24] +- [65, 30, 415, 16] +- [0, 56, 480, 254] componentBounds: 'Repository:': [0, 4, 59, 16] - 'ComboBox #1': [65, 0, 41, 30] - Delete: [114, 0, 78, 30] - Use File -> Settings Repository... to configure: [69, 36, 237, 16] - 'JBScrollPane #4': [0, 62, 480, 248] + 'ComboBox #1': [62, -3, 41, 30] + Delete: [105, -3, 78, 30] + Use File -> Settings Repository... to configure: [66, 30, 237, 16] + 'JBScrollPane #4': [0, 56, 480, 254] diff --git a/platform/platform-tests/testData/ui/layout/Darcula/note row in the dialog.yml b/platform/platform-tests/testData/ui/layout/Darcula/note row in the dialog.yml index c64b3b4a2c0e..dbbe0a895c07 100644 --- a/platform/platform-tests/testData/ui/layout/Darcula/note row in the dialog.yml +++ b/platform/platform-tests/testData/ui/layout/Darcula/note row in the dialog.yml @@ -12,7 +12,6 @@ layoutConstraints: - {horizontal: true, unit: 0, value: 0.0} - {horizontal: false, unit: 0, value: 0.0} - {horizontal: true, unit: 0, value: 0.0} - visualPadding: false rowConstraints: constraints: - align: {horizontal: false, unit: 6, value: 0.0} @@ -65,14 +64,14 @@ componentConstrains: wrap: true cellBounds: - [0, 0, 480, 62] -- [0, 72, 83, 30] -- [89, 72, 391, 30] -- [89, 112, 391, 22] -- [0, 144, 480, 52] +- [0, 72, 83, 25] +- [89, 72, 391, 25] +- [89, 107, 391, 24] +- [0, 141, 480, 52] componentBounds: Profiler requires access to the kernel-level API. Enter the sudo password to allow this.: [ 0, 10, 242, 32] - 'Sudo password:': [0, 78, 83, 16] - 'JPasswordField #2': [89, 72, 250, 30] - !!binary "G1JlbWVtYmVy": [89, 112, 89, 22] - 'SimpleColoredComponent #4': [0, 156, 271, 20] + 'Sudo password:': [0, 76, 83, 16] + 'JPasswordField #2': [87, 71, 254, 28] + !!binary "G1JlbWVtYmVy": [87, 107, 89, 24] + 'SimpleColoredComponent #4': [0, 153, 271, 20] diff --git a/platform/platform-tests/testData/ui/layout/Darcula/visual paddings.yml b/platform/platform-tests/testData/ui/layout/Darcula/visual paddings.yml index 335d2891af0e..33aac9baff37 100644 --- a/platform/platform-tests/testData/ui/layout/Darcula/visual paddings.yml +++ b/platform/platform-tests/testData/ui/layout/Darcula/visual paddings.yml @@ -12,7 +12,6 @@ layoutConstraints: - {horizontal: true, unit: 0, value: 0.0} - {horizontal: false, unit: 0, value: 0.0} - {horizontal: true, unit: 0, value: 0.0} - visualPadding: false rowConstraints: constraints: - align: {horizontal: false, unit: 6, value: 0.0} @@ -151,7 +150,7 @@ componentConstrains: 'Scroll pane:': vertical: gapBefore: - max: &id021 {horizontal: false, value: 4.0} + max: &id021 {horizontal: false, value: 1.0} min: *id021 preferred: *id021 'JBScrollPane #26': @@ -161,57 +160,57 @@ componentConstrains: vertical: {grow: 100.0} wrap: true cellBounds: -- [0, 0, 108, 32] -- [114, 0, 529, 32] -- [0, 42, 108, 30] -- [114, 42, 529, 30] -- [0, 82, 108, 30] -- [114, 82, 529, 30] -- [0, 122, 108, 30] -- [114, 122, 529, 30] -- [0, 162, 108, 30] -- [114, 162, 529, 30] -- [0, 202, 108, 22] -- [114, 202, 529, 22] -- [0, 234, 108, 23] -- [114, 234, 529, 23] -- [0, 267, 108, 30] -- [114, 267, 529, 30] -- [0, 307, 108, 30] -- [114, 307, 529, 30] -- [0, 347, 108, 32] -- [114, 347, 521, 32] -- [114, 347, 521, 32] -- [114, 347, 521, 32] -- [114, 347, 521, 32] -- [114, 347, 521, 32] -- [114, 347, 521, 32] -- [0, 389, 108, 20] -- [114, 389, 529, 20] +- [0, 0, 108, 24] +- [114, 0, 509, 24] +- [0, 34, 108, 24] +- [114, 34, 509, 24] +- [0, 68, 108, 24] +- [114, 68, 509, 24] +- [0, 102, 108, 24] +- [114, 102, 509, 24] +- [0, 136, 108, 24] +- [114, 136, 509, 24] +- [0, 170, 108, 24] +- [114, 170, 509, 24] +- [0, 204, 108, 24] +- [114, 204, 509, 24] +- [0, 238, 108, 24] +- [114, 238, 509, 24] +- [0, 272, 108, 24] +- [114, 272, 509, 24] +- [0, 306, 108, 24] +- [114, 306, 501, 24] +- [114, 306, 501, 24] +- [114, 306, 501, 24] +- [114, 306, 501, 24] +- [114, 306, 501, 24] +- [114, 306, 501, 24] +- [0, 340, 108, 20] +- [114, 340, 509, 20] componentBounds: 'Text field:': [0, 4, 51, 16] - 'JTextField #1': [114, 0, 529, 32] - 'Password:': [0, 46, 53, 16] - 'JPasswordField #3': [114, 42, 250, 30] - 'Combobox:': [0, 86, 63, 16] - 'JComboBox #5': [114, 82, 529, 30] - 'Combobox Editable:': [0, 126, 108, 16] - 'JComboBox #7': [114, 122, 529, 30] - 'Button:': [0, 166, 39, 16] - label: [114, 234, 48, 23] - 'CheckBox:': [0, 206, 56, 16] - enabled: [114, 202, 65, 22] - 'RadioButton:': [0, 238, 69, 16] - 'Spinner:': [0, 271, 43, 16] - 'JBIntSpinner #15': [114, 267, 72, 30] - 'Text with browse:': [0, 311, 92, 16] - 'TextFieldWithHistoryWithBrowseButton #17': [114, 307, 529, 30] - 'All:': [0, 351, 17, 16] - 'JTextField #19': [114, 347, 40, 32] - 'JPasswordField #20': [162, 347, 250, 30] - 'JComboBox #21': [420, 347, 50, 30] - b: [478, 347, 78, 30] - c: [564, 347, 29, 22] - rb: [601, 347, 34, 23] - 'Scroll pane:': [0, 393, 61, 16] - 'JBScrollPane #26': [114, 389, 529, 20] + 'JTextField #1': [112, -2, 513, 28] + 'Password:': [0, 38, 53, 16] + 'JPasswordField #3': [112, 32, 254, 28] + 'Combobox:': [0, 72, 63, 16] + 'JComboBox #5': [111, 65, 515, 30] + 'Combobox Editable:': [0, 106, 108, 16] + 'JComboBox #7': [111, 99, 515, 30] + 'Button:': [0, 140, 39, 16] + label: [112, 204, 48, 24] + 'CheckBox:': [0, 174, 56, 16] + enabled: [112, 170, 65, 24] + 'RadioButton:': [0, 208, 69, 16] + 'Spinner:': [0, 242, 43, 16] + 'JBIntSpinner #15': [111, 235, 72, 30] + 'Text with browse:': [0, 276, 92, 16] + 'TextFieldWithHistoryWithBrowseButton #17': [111, 269, 515, 30] + 'All:': [0, 310, 17, 16] + 'JTextField #19': [112, 304, 40, 28] + 'JPasswordField #20': [156, 304, 254, 28] + 'JComboBox #21': [413, 303, 50, 30] + b: [465, 303, 78, 30] + c: [546, 306, 29, 24] + rb: [581, 306, 34, 24] + 'Scroll pane:': [0, 341, 61, 16] + 'JBScrollPane #26': [114, 340, 509, 20] diff --git a/platform/platform-tests/testData/ui/layout/Darcula/win/align fields in the nested grid.svg b/platform/platform-tests/testData/ui/layout/Darcula/win/align fields in the nested grid.svg index 3f9dc5621fa1..cf9d5f678e81 100644 --- a/platform/platform-tests/testData/ui/layout/Darcula/win/align fields in the nested grid.svg +++ b/platform/platform-tests/testData/ui/layout/Darcula/win/align fields in the nested grid.svg @@ -11,13 +11,13 @@ - + - + - + @@ -26,56 +26,56 @@ - + - + - + - + Stored using weak encryption. - - + + - - + + - - + + - + Master Password: - + - - + + - - + + - - + + - + Database: - - - - - In KeePass + + + + + In KeePass diff --git a/platform/platform-tests/testData/ui/layout/Darcula/win/align fields.svg b/platform/platform-tests/testData/ui/layout/Darcula/win/align fields.svg index a4f61a4490e1..3f7d25fb0b6a 100644 --- a/platform/platform-tests/testData/ui/layout/Darcula/win/align fields.svg +++ b/platform/platform-tests/testData/ui/layout/Darcula/win/align fields.svg @@ -8,19 +8,19 @@ - + - + - + - + @@ -29,26 +29,26 @@ - - + + - - + + - - input + + input - - + + - + Android module name: - - - - - Android module name: + + + + + Android module name: Create Android module diff --git a/platform/platform-tests/testData/ui/layout/Darcula/win/cell.svg b/platform/platform-tests/testData/ui/layout/Darcula/win/cell.svg index 3746aec9b075..e395c59f2db9 100644 --- a/platform/platform-tests/testData/ui/layout/Darcula/win/cell.svg +++ b/platform/platform-tests/testData/ui/layout/Darcula/win/cell.svg @@ -12,22 +12,22 @@ - + - + - + - + - + @@ -39,42 +39,42 @@ - - + + - - + + - - + + - + Use File -> Settings Repository... to configure - + - + - + Delete - + - + - + - + - + diff --git a/platform/platform-tests/testData/ui/layout/Darcula/win/note row in the dialog.svg b/platform/platform-tests/testData/ui/layout/Darcula/win/note row in the dialog.svg index eaae83d0424e..cb8efce93163 100644 --- a/platform/platform-tests/testData/ui/layout/Darcula/win/note row in the dialog.svg +++ b/platform/platform-tests/testData/ui/layout/Darcula/win/note row in the dialog.svg @@ -11,13 +11,13 @@ - + - + - + @@ -29,28 +29,28 @@ - + Should be an empty row above as a gap. Click me . - - - - - &Remember + + + + + &Remember - - + + - - + + - - + + - + Sudo password: diff --git a/platform/platform-tests/testData/ui/layout/Darcula/win/visual paddings.svg b/platform/platform-tests/testData/ui/layout/Darcula/win/visual paddings.svg index 86a6a13b7fc4..ef4ce5e4aa36 100644 --- a/platform/platform-tests/testData/ui/layout/Darcula/win/visual paddings.svg +++ b/platform/platform-tests/testData/ui/layout/Darcula/win/visual paddings.svg @@ -1,5 +1,5 @@ - + @@ -13,19 +13,19 @@ - + - + - + - + @@ -43,28 +43,28 @@ - + - + - + - + - + - + - + @@ -79,19 +79,19 @@ - + - + - + @@ -100,7 +100,7 @@ - + @@ -109,217 +109,217 @@ - + - + - + - + - - + + - + - - - + + + - + Scroll pane: - - - - - rb + + + + + rb - - - - - c + + + + + c - + - + - + b - + - + - + - + c1 - + - - + + - - + + - - • - • - • - • - • - • + + • + • + • + • + • + • - - + + - - + + - - + + - - t + + t - - + + - + All: - - + + - + Text with browse: - + - + - + - + Spinner: - - - - - label + + + + + label - + RadioButton: - - - - - enabled + + + + + enabled - + CheckBox: - - + + - - + + - - label + + label - - - + + + - + Button: - - - + + + - - + + - - + + - + Combobox Editable: - - - + + + - - + + - - + + one - - + + - + Combobox: - - + + - - + + - - • - • - • - • - • - • + + • + • + • + • + • + • - - + + - + Password: - - + + - - + + - - text + + text - - + + Text field: diff --git a/platform/platform-tests/testSrc/com/intellij/ui/SvgRenderer.kt b/platform/platform-tests/testSrc/com/intellij/ui/SvgRenderer.kt index c0802f097526..0bb3d0af6129 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/SvgRenderer.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/SvgRenderer.kt @@ -13,12 +13,10 @@ import org.apache.batik.svggen.ImageHandlerBase64Encoder import org.apache.batik.svggen.SVGGeneratorContext import org.apache.batik.svggen.SVGGraphics2D import org.apache.batik.svggen.SVGSyntax -import org.apache.xmlgraphics.java2d.GraphicsConfigurationWithTransparency import org.w3c.dom.Element import java.awt.Component import java.awt.GraphicsConfiguration import java.awt.Image -import java.awt.Rectangle import java.io.StringWriter import java.nio.file.Path import java.nio.file.Paths @@ -28,14 +26,9 @@ import javax.xml.transform.dom.DOMSource import javax.xml.transform.stream.StreamResult // jFreeSvg produces not so compact and readable SVG as batik -internal class SvgRenderer(val svgFileDir: Path) { +internal class SvgRenderer(val svgFileDir: Path, private val deviceConfiguration: GraphicsConfiguration) { private val xmlTransformer = TransformerFactory.newInstance().newTransformer() - // todo check on Retina - does it works or not (is Retina disabled or not) - val deviceConfiguration = object : GraphicsConfigurationWithTransparency() { - override fun getBounds() = Rectangle(0, 0, 1000, 1000) - } - private val xmlFactory = GenericDOMImplementation.getDOMImplementation().createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI, "svg", null) private val context = SVGGeneratorContext.createDefault(xmlFactory) @@ -84,8 +77,8 @@ internal class SvgRenderer(val svgFileDir: Path) { val index = outputPath.indexOf(moduleName) if (index > 0) { return FileUtilRt.toSystemIndependentName(svgFileDir - .relativize(Paths.get(PathManagerEx.getCommunityHomePath(), relativePath, outputPath.substring(index + moduleName.length + 1 /* slash */))) - .toString()) + .relativize(Paths.get(PathManagerEx.getCommunityHomePath(), relativePath, outputPath.substring(index + moduleName.length + 1 /* slash */))) + .toString()) } } diff --git a/platform/platform-tests/testSrc/com/intellij/ui/UiTestRule.kt b/platform/platform-tests/testSrc/com/intellij/ui/UiTestRule.kt new file mode 100644 index 000000000000..13bbc95ab0b7 --- /dev/null +++ b/platform/platform-tests/testSrc/com/intellij/ui/UiTestRule.kt @@ -0,0 +1,38 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.ui + +import com.intellij.util.ui.JBUI +import org.apache.xmlgraphics.java2d.GraphicsConfigurationWithTransparency +import org.junit.rules.TestName +import java.awt.Rectangle +import java.nio.file.Path +import javax.swing.JPanel + +class UiTestRule(private val testDataRoot: Path) : RequireHeadlessMode() { + // must be lazy, otherwise we cannot change `java.awt.headless` + private val graphicsConfiguration by lazy { + object : GraphicsConfigurationWithTransparency() { + override fun getBounds() = Rectangle(0, 0, 1000, 1000) + } + } + + fun validate(panel: JPanel, testName: TestName, lafName: String) { + validate(panel, testName.snapshotFileName, lafName) + } + + fun validate(panel: JPanel, snapshotName: String, lafName: String) { + val svgRenderer = SvgRenderer(testDataRoot.resolve(getSnapshotRelativePath(lafName, isForImage = true)), graphicsConfiguration) + + // to run tests on retina monitor (@2x images must be not used and so on) + // actually, not required (IconUtil correctly uses graphics device configuration), but just to be sure + AppUIUtil.setGraphicsConfiguration(panel, graphicsConfiguration) + + val preferredSize = panel.preferredSize + panel.setBounds(0, 0, Math.max(preferredSize.width, JBUI.scale(480)), Math.max(preferredSize.height, 320)) + panel.doLayout() + + validateUsingImage(panel, svgRenderer, snapshotName) + validateBounds(panel, testDataRoot.resolve(getSnapshotRelativePath(lafName, isForImage = false)), snapshotName) + } +} \ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/ui/laf/LafTest.kt b/platform/platform-tests/testSrc/com/intellij/ui/laf/LafTest.kt index 396cc4e0fcb9..357b7ff6fd6c 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/laf/LafTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/laf/LafTest.kt @@ -6,7 +6,9 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory import com.intellij.openapi.ui.VerticalFlowLayout import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.UsefulTestCase -import com.intellij.ui.* +import com.intellij.ui.JBIntSpinner +import com.intellij.ui.UiTestRule +import com.intellij.ui.changeLafIfNeed import com.intellij.ui.components.CheckBox import com.intellij.ui.components.textFieldWithHistoryWithBrowseButton import com.intellij.ui.layout.* @@ -34,7 +36,7 @@ class LafTest { @JvmField @ClassRule - val requireHeadlessMode = RequireHeadlessMode() + val uiRule = UiTestRule(Paths.get(PlatformTestUtil.getPlatformTestDataPath(), "ui", "laf")) } @Suppress("MemberVisibilityCanBePrivate") @@ -77,7 +79,7 @@ class LafTest { private fun doTest(panelCreator: () -> JPanel) { invokeAndWaitIfNeed { - validatePanel(panelCreator(), Paths.get(PlatformTestUtil.getPlatformTestDataPath(), "ui", "laf"), testName.snapshotFileName, lafName) + uiRule.validate(panelCreator(), testName, lafName) } } } \ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/ui/layout/MigLayoutTestApp.kt b/platform/platform-tests/testSrc/com/intellij/ui/layout/MigLayoutTestApp.kt index f3c311abfc75..2089ed32b1fc 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/layout/MigLayoutTestApp.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/layout/MigLayoutTestApp.kt @@ -2,6 +2,7 @@ package com.intellij.ui.layout import com.intellij.ide.ui.laf.IntelliJLaf +import com.intellij.ide.ui.laf.darcula.DarculaLaf import com.intellij.openapi.util.SystemInfoRt import com.intellij.testFramework.runInEdtAndWait import com.intellij.ui.components.dialog @@ -28,8 +29,8 @@ object MigLayoutTestApp { runInEdtAndWait { UIManager.setLookAndFeel(MetalLookAndFeel()) - UIManager.setLookAndFeel(IntelliJLaf()) -// UIManager.setLookAndFeel(DarculaLaf()) +// UIManager.setLookAndFeel(IntelliJLaf()) + UIManager.setLookAndFeel(DarculaLaf()) // val panel = visualPaddingsPanelOnlyButton() // val panel = visualPaddingsPanelOnlyComboBox() diff --git a/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt b/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt index 2a2665667879..7275a9484ee6 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt @@ -5,13 +5,14 @@ import com.intellij.openapi.application.invokeAndWaitIfNeed import com.intellij.openapi.util.SystemInfoRt import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.UsefulTestCase -import com.intellij.ui.RequireHeadlessMode +import com.intellij.ui.UiTestRule import com.intellij.ui.changeLafIfNeed -import com.intellij.ui.snapshotFileName -import com.intellij.ui.validatePanel import net.miginfocom.layout.LayoutUtil -import org.junit.* +import org.junit.After import org.junit.Assume.assumeTrue +import org.junit.Before +import org.junit.Rule +import org.junit.Test import org.junit.rules.TestName import org.junit.runner.RunWith import org.junit.runners.Parameterized @@ -29,8 +30,7 @@ class UiDslTest { fun lafNames() = listOf("Darcula", "IntelliJ") @JvmField - @ClassRule - val requireHeadlessMode = RequireHeadlessMode() + val uiRule = UiTestRule(Paths.get(PlatformTestUtil.getPlatformTestDataPath(), "ui", "layout")) } @Suppress("MemberVisibilityCanBePrivate") @@ -85,7 +85,7 @@ class UiDslTest { LayoutUtil.setGlobalDebugMillis(1000) val panel = panelCreator() try { - validatePanel(panel, Paths.get(PlatformTestUtil.getPlatformTestDataPath(), "ui", "layout"), testName.snapshotFileName, lafName) + uiRule.validate(panel, testName, lafName) } finally { LayoutUtil.setGlobalDebugMillis(0) diff --git a/platform/platform-tests/testSrc/com/intellij/ui/uiTestUtil.kt b/platform/platform-tests/testSrc/com/intellij/ui/uiTestUtil.kt index 7a391a591fe8..c853bd133be9 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/uiTestUtil.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/uiTestUtil.kt @@ -12,7 +12,6 @@ import com.intellij.ui.layout.* import com.intellij.util.io.exists import com.intellij.util.io.sanitizeFileName import com.intellij.util.io.write -import com.intellij.util.ui.JBUI import com.intellij.util.ui.TestScaleHelper import com.intellij.util.ui.UIUtil import io.netty.util.internal.SystemPropertyUtil @@ -29,7 +28,6 @@ import java.io.File import java.nio.file.Path import javax.swing.AbstractButton import javax.swing.JLabel -import javax.swing.JPanel import javax.swing.UIManager import javax.swing.plaf.metal.MetalLookAndFeel @@ -47,7 +45,7 @@ class NoScaleRule : ExternalResource() { } } -class RequireHeadlessMode : ExternalResource() { +open class RequireHeadlessMode : ExternalResource() { override fun before() { // there is some difference if run as not headless (on retina monitor, at least), not yet clear why, so, just require to run in headless mode if (UsefulTestCase.IS_UNDER_TEAMCITY) { @@ -167,29 +165,3 @@ internal fun getComponentKey(c: Component, index: Int): String { return "${c.javaClass.simpleName} #${index}" } } - -fun validatePanel(userPanel: JPanel, testDataRoot: Path, snapshotName: String, lafName: String) { - val svgRenderer = SvgRenderer(testDataRoot.resolve(getSnapshotRelativePath(lafName, isForImage = true))) - - // to run tests on retina monitor (@2x images must be not used and so on) - // Graphics2D.getDeviceConfiguration is not enough because our IconLoader.paintIcon uses component.getGraphicsConfiguration() instead of g.getDeviceConfiguration() -// val panel = object : JComponent() { -// override fun getGraphicsConfiguration() = svgRenderer.deviceConfiguration -// -// override fun paint(g: Graphics) { -// // paint userPanel directly to ensure that SVG doesn't contain this wrapper -// userPanel.paint(g) -// } -// } - -// panel.add(userPanel) - -// panel.addNotify() - val preferredSize = userPanel.preferredSize -// panel.setBounds(0, 0, Math.max(preferredSize.width, JBUI.scale(480)), Math.max(preferredSize.height, 320)) - userPanel.setBounds(0, 0, Math.max(preferredSize.width, JBUI.scale(480)), Math.max(preferredSize.height, 320)) - userPanel.doLayout() - - validateUsingImage(userPanel, svgRenderer, snapshotName) - validateBounds(userPanel, testDataRoot.resolve(getSnapshotRelativePath(lafName, isForImage = false)), snapshotName) -} \ No newline at end of file diff --git a/platform/util/src/com/intellij/util/ui/JBUI.java b/platform/util/src/com/intellij/util/ui/JBUI.java index ba1f79a0e208..dc15b1ee738a 100644 --- a/platform/util/src/com/intellij/util/ui/JBUI.java +++ b/platform/util/src/com/intellij/util/ui/JBUI.java @@ -563,7 +563,7 @@ public class JBUI { * An equivalent of {@code isHiDPI(scale(1f))} */ public static boolean isUsrHiDPI() { - return isHiDPI(scale(1f)); + return isHiDPI(scale(1f)); } /** @@ -1477,7 +1477,7 @@ public class JBUI { * Correct input size is used now only for UI DSL. */ public static boolean isUseCorrectInputHeight(@NotNull Component component) { - if (!(SystemInfoRt.isMac || UIUtil.isUnderWin10LookAndFeel())) { + if (SystemInfoRt.isLinux) { return false; } @@ -1486,6 +1486,6 @@ public class JBUI { } public static boolean isCompensateVisualPaddingOnComponentLevel(@Nullable Component parent) { - return !((SystemInfoRt.isMac || UIUtil.isUnderWin10LookAndFeel()) && parent instanceof JPanel && ((JPanel)parent).getClientProperty(COMPENSATE_VISUAL_PADDING_KEY) == Boolean.FALSE); + return SystemInfoRt.isLinux || !(parent instanceof JPanel && ((JPanel)parent).getClientProperty(COMPENSATE_VISUAL_PADDING_KEY) == Boolean.FALSE); } } \ No newline at end of file