[git] Interactive Rebase Dialog: Scale graph dimensions

GitOrigin-RevId: 3204371fb0a46abe34c620b12285e4b8d4f7b2f2
This commit is contained in:
Nikolay Rykunov
2020-05-13 14:16:28 +00:00
committed by intellij-monorepo-bot
parent fceeb20dc1
commit e39f4aa9c8
2 changed files with 25 additions and 25 deletions
@@ -3,6 +3,7 @@ package com.intellij.openapi.vcs.ui
import com.intellij.ui.JBColor
import com.intellij.ui.SimpleColoredRenderer
import com.intellij.util.ui.JBUI
import java.awt.*
import java.awt.geom.Ellipse2D
import javax.swing.JTable
@@ -10,16 +11,15 @@ import javax.swing.table.TableCellRenderer
open class CommitIconTableCellRenderer(
private val graphColorSupplier: () -> JBColor,
defaultCellHeight: Int = 22,
private val defaultCellHeight: Int = 22,
private val graphLineWidth: Float = 1.5f
) : SimpleColoredRenderer(), TableCellRenderer {
companion object {
private const val NODE_WIDTH = 8
private const val NODE_CENTER_X = NODE_WIDTH
}
private val NODE_CENTER_Y = defaultCellHeight / 2
protected open val nodeWidth
get() = JBUI.scale(8)
protected val nodeCenterX
get() = nodeWidth
protected val nodeCenterY
get() = defaultCellHeight / 2
private var rowIndex = 0
private var isLastRow = false
@@ -72,13 +72,13 @@ open class CommitIconTableCellRenderer(
}
protected open fun drawNode(g: Graphics2D) {
drawCircle(g, NODE_CENTER_X, NODE_CENTER_Y)
drawCircle(g, nodeCenterX, nodeCenterY)
}
protected open fun drawCircle(g: Graphics2D,
x0: Int,
y0: Int,
circleRadius: Int = NODE_WIDTH / 2,
circleRadius: Int = nodeWidth / 2,
circleColor: Color = graphColorSupplier()) {
val circle = Ellipse2D.Double(
x0 - circleRadius + 0.5,
@@ -91,9 +91,9 @@ open class CommitIconTableCellRenderer(
}
protected open fun drawEdge(g: Graphics2D, tableRowHeight: Int, isDownEdge: Boolean) {
val y1 = NODE_CENTER_Y
val y1 = nodeCenterY
val y2 = if (isDownEdge) tableRowHeight else 0
val x = NODE_CENTER_X
val x = nodeCenterX
g.color = graphColorSupplier()
g.stroke = BasicStroke(graphLineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)
g.drawLine(x, y1, x, y2)
@@ -14,6 +14,7 @@ import com.intellij.ui.ColoredTableCellRenderer
import com.intellij.ui.JBColor
import com.intellij.ui.SimpleTextAttributes
import com.intellij.ui.TableSpeedSearch
import com.intellij.ui.scale.JBUIScale
import com.intellij.ui.speedSearch.SpeedSearchUtil
import com.intellij.ui.table.JBTable
import com.intellij.util.ui.JBUI
@@ -24,6 +25,7 @@ import git4idea.rebase.interactive.GitRebaseTodoModel
import git4idea.rebase.interactive.dialog.GitRebaseCommitsTableView.Companion.DEFAULT_CELL_HEIGHT
import git4idea.rebase.interactive.dialog.GitRebaseCommitsTableView.Companion.GRAPH_COLOR
import git4idea.rebase.interactive.dialog.GitRebaseCommitsTableView.Companion.GRAPH_LINE_WIDTH
import git4idea.rebase.interactive.dialog.GitRebaseCommitsTableView.Companion.GRAPH_NODE_WIDTH
import git4idea.rebase.interactive.dialog.view.CommitMessageCellEditor
import java.awt.*
import javax.swing.DefaultListSelectionModel
@@ -39,7 +41,10 @@ internal open class GitRebaseCommitsTableView(
) : JBTable(model) {
companion object {
const val GRAPH_LINE_WIDTH = 1.5f
val GRAPH_LINE_WIDTH: Float
get() = JBUIScale.scale(1.5f)
val GRAPH_NODE_WIDTH: Int
get() = JBUI.scale(8)
val DEFAULT_CELL_HEIGHT: Int
get() = JBUI.scale(PaintParameters.ROW_HEIGHT)
val GRAPH_COLOR = JBColor.namedColor("VersionControl.GitCommits.graphColor", JBColor(Color(174, 185, 192), Color(135, 146, 154)))
@@ -85,7 +90,7 @@ internal open class GitRebaseCommitsTableView(
}
private fun adjustCommitIconColumnWidth() {
val contentWidth = getExpandedColumnWidth(GitRebaseCommitsTableModel.COMMIT_ICON_COLUMN) + UIUtil.DEFAULT_HGAP
val contentWidth = 2 * GRAPH_NODE_WIDTH + UIUtil.DEFAULT_HGAP
val column = columnModel.getColumn(GitRebaseCommitsTableModel.COMMIT_ICON_COLUMN)
column.maxWidth = contentWidth
column.preferredWidth = contentWidth
@@ -247,13 +252,8 @@ private class SubjectRenderer : ColoredTableCellRenderer() {
}
private class GitRebaseCommitIconTableCellRenderer : CommitIconTableCellRenderer({ GRAPH_COLOR }, DEFAULT_CELL_HEIGHT, GRAPH_LINE_WIDTH) {
companion object {
private const val NODE_WIDTH = 8
private const val NODE_CENTER_X = NODE_WIDTH
private val NODE_CENTER_Y
get() = DEFAULT_CELL_HEIGHT / 2
}
override val nodeWidth: Int
get() = GRAPH_NODE_WIDTH
private var isHead = false
private var nodeType = NodeType.SIMPLE_NODE
@@ -289,10 +289,10 @@ private class GitRebaseCommitIconTableCellRenderer : CommitIconTableCellRenderer
}
private fun drawDoubleNode(g: Graphics2D) {
val circleRadius = NODE_WIDTH / 2
val circleRadius = nodeWidth / 2
val backgroundCircleRadius = circleRadius + 1
val leftCircleX0 = NODE_CENTER_X
val y0 = NODE_CENTER_Y
val leftCircleX0 = nodeCenterX
val y0 = nodeCenterY
val rightCircleX0 = leftCircleX0 + circleRadius
// right circle
@@ -307,7 +307,7 @@ private class GitRebaseCommitIconTableCellRenderer : CommitIconTableCellRenderer
private fun drawEditNode(g: Graphics2D) {
val icon = AllIcons.Actions.Pause
icon.paintIcon(null, g, NODE_CENTER_X - icon.iconWidth / 2, NODE_CENTER_Y - icon.iconHeight / 2)
icon.paintIcon(null, g, nodeCenterX - icon.iconWidth / 2, nodeCenterY - icon.iconHeight / 2)
}
}