mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[log] Introduce CommitCellRender for rendering without painting graph
This structure is needed for future filters. It existed before, but was accidentally removed because it wasn't used at that time. Move common methods from GraphCommitCellRender to the AbstactPaddingCellRender.
This commit is contained in:
+79
@@ -0,0 +1,79 @@
|
||||
package com.intellij.vcs.log.ui.render;
|
||||
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.vcs.log.graph.render.GraphCommitCell;
|
||||
import com.intellij.vcs.log.printmodel.SpecialPrintElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author erokhins
|
||||
*/
|
||||
public abstract class AbstractPaddingCellRender implements TableCellRenderer {
|
||||
|
||||
public static final Color MARKED_BACKGROUND = new Color(200, 255, 250);
|
||||
|
||||
@NotNull private final ExtDefaultCellRender myCellRender = new ExtDefaultCellRender();
|
||||
|
||||
protected abstract int getLeftPadding(JTable table, Object value);
|
||||
|
||||
@NotNull
|
||||
protected abstract String getCellText(Object value);
|
||||
|
||||
protected abstract void additionPaint(Graphics g, Object value);
|
||||
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
|
||||
boolean hasFocus, int row, int column) {
|
||||
return myCellRender.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
}
|
||||
|
||||
public static boolean isMarked(@Nullable Object value) {
|
||||
if (!(value instanceof GraphCommitCell)) {
|
||||
return false;
|
||||
}
|
||||
GraphCommitCell cell = (GraphCommitCell)value;
|
||||
for (SpecialPrintElement printElement : cell.getPrintCell().getSpecialPrintElements()) {
|
||||
if (printElement.getType() == SpecialPrintElement.Type.COMMIT_NODE && printElement.isMarked()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private class ExtDefaultCellRender extends DefaultTableCellRenderer {
|
||||
private Object myValue;
|
||||
|
||||
public Component getTableCellRendererComponent(JTable table, Object value,
|
||||
boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
myValue = value;
|
||||
super.getTableCellRendererComponent(table, getCellText(value), isSelected, hasFocus, row, column);
|
||||
if (isMarked(value) && !isSelected) {
|
||||
setBackground(MARKED_BACKGROUND);
|
||||
}
|
||||
else {
|
||||
setBackground(isSelected ? table.getSelectionBackground() : JBColor.WHITE);
|
||||
}
|
||||
|
||||
Border paddingBorder = BorderFactory.createEmptyBorder(0, getLeftPadding(table, value), 0, 0);
|
||||
setBorder(BorderFactory.createCompoundBorder(this.getBorder(), paddingBorder));
|
||||
Color textColor = isSelected ? table.getSelectionForeground() : JBColor.BLACK;
|
||||
setForeground(textColor);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
additionPaint(g, myValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.intellij.vcs.log.ui.render;
|
||||
|
||||
import com.intellij.vcs.log.graph.render.CommitCell;
|
||||
import com.intellij.vcs.log.ui.VcsLogColorManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.font.FontRenderContext;
|
||||
|
||||
/**
|
||||
* @author erokhins
|
||||
*/
|
||||
public class CommitCellRender extends AbstractPaddingCellRender {
|
||||
|
||||
@NotNull private final RefPainter refPainter;
|
||||
|
||||
public CommitCellRender(@NotNull VcsLogColorManager colorManager) {
|
||||
refPainter = new RefPainter(colorManager, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLeftPadding(JTable table, Object value) {
|
||||
CommitCell cell = getAssertCommitCell(value);
|
||||
|
||||
FontRenderContext fontContext = ((Graphics2D)table.getGraphics()).getFontRenderContext();
|
||||
return refPainter.padding(cell.getRefsToThisCommit(), fontContext);
|
||||
}
|
||||
|
||||
private static CommitCell getAssertCommitCell(Object value) {
|
||||
assert value instanceof CommitCell : "Value of incorrect class was supplied: " + value;
|
||||
return (CommitCell)value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getCellText(Object value) {
|
||||
CommitCell cell = getAssertCommitCell(value);
|
||||
return cell.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void additionPaint(Graphics g, Object value) {
|
||||
CommitCell cell = getAssertCommitCell(value);
|
||||
Graphics2D g2 = (Graphics2D)g;
|
||||
refPainter.draw(g2, cell.getRefsToThisCommit(), 0, -1);
|
||||
}
|
||||
}
|
||||
+5
-58
@@ -1,21 +1,16 @@
|
||||
package com.intellij.vcs.log.ui.render;
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.vcs.log.VcsRef;
|
||||
import com.intellij.vcs.log.data.VcsLogDataHolder;
|
||||
import com.intellij.vcs.log.printmodel.SpecialPrintElement;
|
||||
import com.intellij.vcs.log.ui.VcsLogColorManager;
|
||||
import com.intellij.vcs.log.graph.render.GraphCellPainter;
|
||||
import com.intellij.vcs.log.graph.render.GraphCommitCell;
|
||||
import com.intellij.vcs.log.ui.VcsLogColorManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import java.awt.*;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -27,24 +22,20 @@ import static com.intellij.vcs.log.graph.render.PrintParameters.WIDTH_NODE;
|
||||
/**
|
||||
* @author erokhins
|
||||
*/
|
||||
public class GraphCommitCellRender implements TableCellRenderer {
|
||||
|
||||
public static final Color MARKED_BACKGROUND = new Color(0xB6, 0xE4, 0xFF);
|
||||
public static final Color APPLIED_BACKGROUND = new Color(0x92, 0xF5, 0x8F);
|
||||
public class GraphCommitCellRender extends AbstractPaddingCellRender {
|
||||
|
||||
@NotNull private final GraphCellPainter graphPainter;
|
||||
@NotNull private final VcsLogDataHolder myDataHolder;
|
||||
@NotNull private final RefPainter refPainter;
|
||||
@NotNull private final ExtDefaultCellRender cellRender;
|
||||
|
||||
public GraphCommitCellRender(@NotNull GraphCellPainter graphPainter, @NotNull VcsLogDataHolder logDataHolder,
|
||||
@NotNull VcsLogColorManager colorManager) {
|
||||
this.graphPainter = graphPainter;
|
||||
myDataHolder = logDataHolder;
|
||||
refPainter = new RefPainter(colorManager, false);
|
||||
cellRender = new ExtDefaultCellRender();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLeftPadding(JTable table, @Nullable Object value) {
|
||||
GraphCommitCell cell = (GraphCommitCell)value;
|
||||
|
||||
@@ -61,6 +52,7 @@ public class GraphCommitCellRender implements TableCellRenderer {
|
||||
return refPadding + graphPadding;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String getCellText(@Nullable Object value) {
|
||||
GraphCommitCell cell = (GraphCommitCell)value;
|
||||
if (cell == null) {
|
||||
@@ -71,6 +63,7 @@ public class GraphCommitCellRender implements TableCellRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void additionPaint(Graphics g, @Nullable Object value) {
|
||||
GraphCommitCell cell = (GraphCommitCell)value;
|
||||
if (cell == null) {
|
||||
@@ -94,50 +87,4 @@ public class GraphCommitCellRender implements TableCellRenderer {
|
||||
|
||||
g.drawImage(image, 0, 0, null);
|
||||
}
|
||||
|
||||
public static boolean isMarked(@Nullable Object value) {
|
||||
GraphCommitCell cell = (GraphCommitCell)value;
|
||||
if (cell == null) {
|
||||
return false;
|
||||
}
|
||||
for (SpecialPrintElement printElement : cell.getPrintCell().getSpecialPrintElements()) {
|
||||
if (printElement.getType() == SpecialPrintElement.Type.COMMIT_NODE && printElement.isMarked()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, @Nullable Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
return cellRender.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
}
|
||||
|
||||
public class ExtDefaultCellRender extends DefaultTableCellRenderer {
|
||||
private Object value;
|
||||
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
this.value = value;
|
||||
super.getTableCellRendererComponent(table, getCellText(value), isSelected, hasFocus, row, column);
|
||||
if (isMarked(value) && !isSelected) {
|
||||
setBackground(MARKED_BACKGROUND);
|
||||
}
|
||||
else {
|
||||
setBackground(isSelected ? table.getSelectionBackground() : JBColor.WHITE);
|
||||
}
|
||||
Border paddingBorder = BorderFactory.createEmptyBorder(0, getLeftPadding(table, value), 0, 0);
|
||||
this.setBorder(BorderFactory.createCompoundBorder(this.getBorder(), paddingBorder));
|
||||
|
||||
Color textColor = isSelected ? table.getSelectionForeground() : JBColor.BLACK;
|
||||
setForeground(textColor);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
additionPaint(g, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user