diff --git a/platform/platform-api/src/com/intellij/ui/dsl/gridLayout/builders/RowsGridBuilder.kt b/platform/platform-api/src/com/intellij/ui/dsl/gridLayout/builders/RowsGridBuilder.kt index 13900650c22b..8c93fb7d06ca 100644 --- a/platform/platform-api/src/com/intellij/ui/dsl/gridLayout/builders/RowsGridBuilder.kt +++ b/platform/platform-api/src/com/intellij/ui/dsl/gridLayout/builders/RowsGridBuilder.kt @@ -53,36 +53,6 @@ class RowsGridBuilder(private val panel: JComponent, grid: Grid? = null) { return this } - @Suppress("DeprecatedCallableAddReplaceWith") - @Deprecated("Use the overloaded function with UnscaledGaps in parameters") - @ApiStatus.ScheduledForRemoval - fun cell(component: JComponent, - width: Int = 1, - horizontalAlign: HorizontalAlign = defaultHorizontalAlign, - verticalAlign: VerticalAlign = defaultVerticalAlign, - baselineAlign: Boolean = defaultBaselineAlign, - resizableColumn: Boolean = false, - gaps: Gaps = Gaps.EMPTY, - visualPaddings: Gaps = Gaps.EMPTY, - widthGroup: String? = null, - componentHelper: ComponentHelper? = null): RowsGridBuilder { - return cell(component, width, horizontalAlign, verticalAlign, baselineAlign, resizableColumn, - gaps.toUnscaled(), visualPaddings.toUnscaled(), widthGroup, componentHelper) - } - - // todo needed only while migration Gaps to UnscaledGaps. Should be removed later - fun cell(component: JComponent, - width: Int = 1, - horizontalAlign: HorizontalAlign = defaultHorizontalAlign, - verticalAlign: VerticalAlign = defaultVerticalAlign, - baselineAlign: Boolean = defaultBaselineAlign, - resizableColumn: Boolean = false, - widthGroup: String? = null, - componentHelper: ComponentHelper? = null): RowsGridBuilder { - return cell(component, width, horizontalAlign, verticalAlign, baselineAlign, resizableColumn, - UnscaledGaps.EMPTY, UnscaledGaps.EMPTY, widthGroup, componentHelper) - } - fun cell(component: JComponent, width: Int = 1, horizontalAlign: HorizontalAlign = defaultHorizontalAlign, @@ -108,32 +78,6 @@ class RowsGridBuilder(private val panel: JComponent, grid: Grid? = null) { return skip(width) } - @Suppress("DeprecatedCallableAddReplaceWith") - @Deprecated("Use the overloaded function with UnscaledGaps in parameters") - @ApiStatus.ScheduledForRemoval - fun constraints(width: Int = 1, - horizontalAlign: HorizontalAlign = defaultHorizontalAlign, - verticalAlign: VerticalAlign = defaultVerticalAlign, - baselineAlign: Boolean = defaultBaselineAlign, - gaps: Gaps = Gaps.EMPTY, - visualPaddings: Gaps = Gaps.EMPTY, - widthGroup: String? = null, - componentHelper: ComponentHelper? = null): Constraints { - return constraints(width, horizontalAlign, verticalAlign, baselineAlign, - gaps.toUnscaled(), visualPaddings.toUnscaled(), widthGroup, componentHelper) - } - - // todo needed only while migration Gaps to UnscaledGaps. Should be removed later - fun constraints(width: Int = 1, - horizontalAlign: HorizontalAlign = defaultHorizontalAlign, - verticalAlign: VerticalAlign = defaultVerticalAlign, - baselineAlign: Boolean = defaultBaselineAlign, - widthGroup: String? = null, - componentHelper: ComponentHelper? = null): Constraints { - return constraints(width, horizontalAlign, verticalAlign, baselineAlign, - UnscaledGaps.EMPTY, UnscaledGaps.EMPTY, widthGroup, componentHelper) - } - fun constraints(width: Int = 1, horizontalAlign: HorizontalAlign = defaultHorizontalAlign, verticalAlign: VerticalAlign = defaultVerticalAlign, @@ -155,19 +99,6 @@ class RowsGridBuilder(private val panel: JComponent, grid: Grid? = null) { return result } - @Suppress("DeprecatedCallableAddReplaceWith") - @Deprecated("Use the overloaded function with UnscaledGaps in parameters") - @ApiStatus.ScheduledForRemoval - fun subGrid(width: Int = 1, - horizontalAlign: HorizontalAlign = defaultHorizontalAlign, - verticalAlign: VerticalAlign = defaultVerticalAlign, - baselineAlign: Boolean = defaultBaselineAlign, - resizableColumn: Boolean = false, - gaps: Gaps = Gaps.EMPTY, - visualPaddings: Gaps = Gaps.EMPTY): Grid { - return subGrid(width, horizontalAlign, verticalAlign, baselineAlign, resizableColumn, gaps.toUnscaled(), visualPaddings.toUnscaled()) - } - fun subGrid(width: Int = 1, horizontalAlign: HorizontalAlign = defaultHorizontalAlign, verticalAlign: VerticalAlign = defaultVerticalAlign, @@ -187,30 +118,6 @@ class RowsGridBuilder(private val panel: JComponent, grid: Grid? = null) { return layout.addLayoutSubGrid(constraints) } - @Suppress("DeprecatedCallableAddReplaceWith") - @Deprecated("Use the overloaded function with UnscaledGaps in parameters") - @ApiStatus.ScheduledForRemoval - fun subGridBuilder(width: Int = 1, - horizontalAlign: HorizontalAlign = defaultHorizontalAlign, - verticalAlign: VerticalAlign = defaultVerticalAlign, - baselineAlign: Boolean = defaultBaselineAlign, - resizableColumn: Boolean = false, - gaps: Gaps = Gaps.EMPTY, - visualPaddings: Gaps = Gaps.EMPTY): RowsGridBuilder { - return subGridBuilder(width, horizontalAlign, verticalAlign, baselineAlign, - resizableColumn, gaps.toUnscaled(), visualPaddings.toUnscaled()) - } - - - // todo needed only while migration Gaps to UnscaledGaps. Should be removed later - fun subGridBuilder(width: Int = 1, - horizontalAlign: HorizontalAlign = defaultHorizontalAlign, - verticalAlign: VerticalAlign = defaultVerticalAlign, - baselineAlign: Boolean = defaultBaselineAlign, - resizableColumn: Boolean = false): RowsGridBuilder { - return subGridBuilder(width, horizontalAlign, verticalAlign, baselineAlign, resizableColumn, UnscaledGaps.EMPTY, UnscaledGaps.EMPTY) - } - fun subGridBuilder(width: Int = 1, horizontalAlign: HorizontalAlign = defaultHorizontalAlign, verticalAlign: VerticalAlign = defaultVerticalAlign, diff --git a/platform/platform-impl/src/com/intellij/internal/ui/gridLayoutTestAction/GridLayoutTestAction.kt b/platform/platform-impl/src/com/intellij/internal/ui/gridLayoutTestAction/GridLayoutTestAction.kt index d0a05e95af64..4246957d995c 100644 --- a/platform/platform-impl/src/com/intellij/internal/ui/gridLayoutTestAction/GridLayoutTestAction.kt +++ b/platform/platform-impl/src/com/intellij/internal/ui/gridLayoutTestAction/GridLayoutTestAction.kt @@ -5,6 +5,7 @@ import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.project.DumbAwareAction import com.intellij.openapi.ui.DialogWrapper +import com.intellij.ui.JBColor import com.intellij.ui.components.JBList import com.intellij.ui.components.JBTabbedPane import com.intellij.ui.dsl.gridLayout.* @@ -166,8 +167,8 @@ internal class GridLayoutTestAction : DumbAwareAction("Show GridLayout Test") { ) } val grid = (panel.layout as GridLayout).rootGrid - grid.resizableColumns.addAll(0..HorizontalAlign.values().size) - grid.resizableRows.addAll(0..VerticalAlign.values().size) + grid.resizableColumns.addAll(0..HorizontalAlign.entries.size) + grid.resizableRows.addAll(0..VerticalAlign.entries.size) return createTabPanel("Every second cell has own Gaps", panel) } @@ -226,18 +227,18 @@ internal class GridLayoutTestAction : DumbAwareAction("Show GridLayout Test") { } fun createCellAlignmentsPanel(): JPanel { - val panel = createPanelLabels(HorizontalAlign.values().size, VerticalAlign.values().size) { grid, x, y -> + val panel = createPanelLabels(HorizontalAlign.entries.size, VerticalAlign.entries.size) { grid, x, y -> Constraints( grid, x, y, - horizontalAlign = HorizontalAlign.values()[x], - verticalAlign = VerticalAlign.values()[y] + horizontalAlign = HorizontalAlign.entries[x], + verticalAlign = VerticalAlign.entries[y] ) } val grid = (panel.layout as GridLayout).rootGrid - grid.resizableColumns.addAll(0..HorizontalAlign.values().size) - grid.resizableRows.addAll(0..VerticalAlign.values().size) + grid.resizableColumns.addAll(0..HorizontalAlign.entries.size) + grid.resizableRows.addAll(0..VerticalAlign.entries.size) return createTabPanel("Cells size is equal, component layouts have different alignments", panel) } @@ -407,7 +408,7 @@ fun createTabPanel(title: String, content: JComponent): JPanel { rootGrid.resizableColumns.add(0) rootGrid.resizableRows.add(1) val label = JLabel("$title
${gridToHtmlString((content.layout as GridLayout).rootGrid)}") - label.background = Color.LIGHT_GRAY + label.background = JBColor.LIGHT_GRAY label.isOpaque = true result.add(label, Constraints(rootGrid, 0, 0, width = 2, horizontalAlign = HorizontalAlign.FILL)) result.add( @@ -461,7 +462,7 @@ private fun createControls(container: JComponent, content: JComponent, grid: Gri isSelected, cellHasFocus ) as DefaultListCellRenderer - result.foreground = if (label.isVisible) Color.BLACK else Color.LIGHT_GRAY + result.foreground = if (label.isVisible) JBColor.BLACK else JBColor.LIGHT_GRAY return result } diff --git a/platform/platform-tests/testSrc/com/intellij/ui/dsl/gridLayout/GridLayoutBaselineTest.kt b/platform/platform-tests/testSrc/com/intellij/ui/dsl/gridLayout/GridLayoutBaselineTest.kt index 43428883f0b5..bd8a65424bce 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/dsl/gridLayout/GridLayoutBaselineTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/dsl/gridLayout/GridLayoutBaselineTest.kt @@ -17,7 +17,7 @@ class GridLayoutBaselineTest { @Test fun testBaseline() { - for (verticalAlign in VerticalAlign.values()) { + for (verticalAlign in VerticalAlign.entries) { if (verticalAlign == VerticalAlign.FILL) { continue } @@ -46,7 +46,7 @@ class GridLayoutBaselineTest { @Test fun testBaselineWithSubPanels() { - for (verticalAlign in VerticalAlign.values()) { + for (verticalAlign in VerticalAlign.entries) { if (verticalAlign == VerticalAlign.FILL) { continue } diff --git a/platform/platform-tests/testSrc/com/intellij/ui/dsl/gridLayout/GridLayoutTest.kt b/platform/platform-tests/testSrc/com/intellij/ui/dsl/gridLayout/GridLayoutTest.kt index 56129a2c8717..26b23c327f7d 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/dsl/gridLayout/GridLayoutTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/dsl/gridLayout/GridLayoutTest.kt @@ -3,6 +3,7 @@ package com.intellij.ui.dsl.gridLayout import com.intellij.ui.dsl.* import com.intellij.ui.dsl.gridLayout.builders.RowsGridBuilder +import com.intellij.ui.scale.JBUIScale import org.junit.Assert import org.junit.Test import java.awt.Dimension @@ -36,15 +37,16 @@ class GridLayoutTest { @Test fun testOneCellGaps() { val panel = JPanel(GridLayout()) - val gaps = Gaps(1, 2, 3, 4) + val gaps = UnscaledGaps(1, 2, 3, 4) RowsGridBuilder(panel).cell(label(), gaps = gaps) - assertEquals(panel.preferredSize, Dimension(PREFERRED_WIDTH + gaps.width, PREFERRED_HEIGHT + gaps.height)) + assertEquals(panel.preferredSize, + Dimension(PREFERRED_WIDTH + JBUIScale.scale(gaps.width), PREFERRED_HEIGHT + JBUIScale.scale(gaps.height))) } @Test fun testOneCellVisualPaddings() { val panel = JPanel(GridLayout()) - val visualPaddings = Gaps(1, 2, 3, 4) + val visualPaddings = UnscaledGaps(1, 2, 3, 4) val label = label() RowsGridBuilder(panel) .cell(label, visualPaddings = visualPaddings) @@ -72,47 +74,47 @@ class GridLayoutTest { @Test fun testOneCellHorizontalAlignments() { val panel = JPanel(GridLayout()) - val gaps = Gaps(1, 2, 3, 4) + val gaps = UnscaledGaps(1, 2, 3, 4) val label = label() RowsGridBuilder(panel) .cell(label, gaps = gaps, horizontalAlign = HorizontalAlign.LEFT, resizableColumn = true) doLayout(panel, 200, 100) assertEquals(label.size, PREFERRED_SIZE) - assertEquals(gaps.left, label.x) + assertEquals(JBUIScale.scale(gaps.left), label.x) panel.removeAll() RowsGridBuilder(panel) .cell(label, gaps = gaps, horizontalAlign = HorizontalAlign.CENTER, resizableColumn = true) doLayout(panel, 200, 100) assertEquals(PREFERRED_SIZE, label.size) - assertEquals(gaps.left + (200 - PREFERRED_WIDTH - gaps.width) / 2, label.x) + assertEquals(JBUIScale.scale(gaps.left) + (200 - PREFERRED_WIDTH - JBUIScale.scale(gaps.width)) / 2, label.x) panel.removeAll() RowsGridBuilder(panel) .cell(label, gaps = gaps, horizontalAlign = HorizontalAlign.RIGHT, resizableColumn = true) doLayout(panel, 200, 100) assertEquals(PREFERRED_SIZE, label.size) - assertEquals(200 - PREFERRED_WIDTH - gaps.right, label.x) + assertEquals(200 - PREFERRED_WIDTH - JBUIScale.scale(gaps.right), label.x) panel.removeAll() RowsGridBuilder(panel) .cell(label, gaps = gaps, horizontalAlign = HorizontalAlign.FILL, resizableColumn = true) doLayout(panel, 200, 100) - assertEquals(Dimension(200 - gaps.width, PREFERRED_HEIGHT), label.size) - assertEquals(gaps.left, label.x) + assertEquals(Dimension(200 - JBUIScale.scale(gaps.width), PREFERRED_HEIGHT), label.size) + assertEquals(JBUIScale.scale(gaps.left), label.x) } @Test fun testOneCellVerticalAlignments() { val panel = JPanel(GridLayout()) - val gaps = Gaps(1, 2, 3, 4) + val gaps = UnscaledGaps(1, 2, 3, 4) val label = label() RowsGridBuilder(panel) .row(resizable = true) .cell(label, gaps = gaps, verticalAlign = VerticalAlign.TOP) doLayout(panel, 200, 100) assertEquals(label.size, PREFERRED_SIZE) - assertEquals(gaps.top, label.y) + assertEquals(JBUIScale.scale(gaps.top), label.y) panel.removeAll() RowsGridBuilder(panel) @@ -120,7 +122,7 @@ class GridLayoutTest { .cell(label, gaps = gaps, verticalAlign = VerticalAlign.CENTER) doLayout(panel, 200, 100) assertEquals(PREFERRED_SIZE, label.size) - assertEquals(gaps.top + (100 - PREFERRED_HEIGHT - gaps.height) / 2, label.y) + assertEquals(JBUIScale.scale(gaps.top) + (100 - PREFERRED_HEIGHT - JBUIScale.scale(gaps.height)) / 2, label.y) panel.removeAll() RowsGridBuilder(panel) @@ -128,23 +130,23 @@ class GridLayoutTest { .cell(label, gaps = gaps, verticalAlign = VerticalAlign.BOTTOM) doLayout(panel, 200, 100) assertEquals(PREFERRED_SIZE, label.size) - assertEquals(100 - PREFERRED_HEIGHT - gaps.bottom, label.y) + assertEquals(100 - PREFERRED_HEIGHT - JBUIScale.scale(gaps.bottom), label.y) panel.removeAll() RowsGridBuilder(panel) .row(resizable = true) .cell(label, gaps = gaps, verticalAlign = VerticalAlign.FILL) doLayout(panel, 200, 100) - assertEquals(Dimension(PREFERRED_WIDTH, 100 - gaps.height), label.size) - assertEquals(gaps.top, label.y) + assertEquals(Dimension(PREFERRED_WIDTH, 100 - JBUIScale.scale(gaps.height)), label.size) + assertEquals(JBUIScale.scale(gaps.top), label.y) } @Test fun testOneCellComplex() { val panel = JPanel(GridLayout()) val label = label() - val gaps = Gaps(1, 2, 3, 4) - val visualPaddings = Gaps(5, 6, 7, 8) + val gaps = UnscaledGaps(1, 2, 3, 4) + val visualPaddings = UnscaledGaps(5, 6, 7, 8) RowsGridBuilder(panel) .row(resizable = true) .cell(label, horizontalAlign = HorizontalAlign.LEFT, verticalAlign = VerticalAlign.CENTER, resizableColumn = true, gaps = gaps, @@ -152,8 +154,8 @@ class GridLayoutTest { doLayout(panel, 200, 100) assertEquals(PREFERRED_SIZE, label.preferredSize) // Visual paddings are compensated by layout, so whole component is fit - assertEquals(max(0, gaps.left - visualPaddings.left), label.x) - assertEquals(gaps.top + (100 - PREFERRED_HEIGHT - gaps.height + visualPaddings.height) / 2 - visualPaddings.top, label.y) + assertEquals(max(0, JBUIScale.scale(gaps.left) - JBUIScale.scale(visualPaddings.left)), label.x) + assertEquals(JBUIScale.scale(gaps.top) + (100 - PREFERRED_HEIGHT - JBUIScale.scale(gaps.height) + JBUIScale.scale(visualPaddings.height)) / 2 - JBUIScale.scale(visualPaddings.top), label.y) panel.removeAll() RowsGridBuilder(panel) @@ -180,7 +182,7 @@ class GridLayoutTest { label(preferredWidth = Random.nextInt(150))) builder .row() - .cell(row[0], horizontalAlign = HorizontalAlign.values().random()) + .cell(row[0], horizontalAlign = HorizontalAlign.entries.random()) .cell(row[1], resizableColumn = true) .cell(row[2]) labels.add(row)