use of com.intellij.ide.diff.DirDiffOperation in project intellij-community by JetBrains.
the class SetOperationToBase method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
DirDiffOperation operation = getOperation();
boolean setToDefault = operation == DirDiffOperation.NONE;
final DirDiffTableModel model = getModel(e);
final JTable table = getTable(e);
assert model != null && table != null;
for (DirDiffElementImpl element : model.getSelectedElements()) {
if (isEnabledFor(element)) {
element.setOperation(setToDefault ? element.getDefaultOperation() : operation);
} else {
element.setOperation(DirDiffOperation.NONE);
}
}
table.repaint();
}
use of com.intellij.ide.diff.DirDiffOperation in project intellij-community by JetBrains.
the class DirDiffTableCellRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(final JTable table, Object value, boolean isSelected, boolean hasFocus, final int row, final int column) {
final DirDiffTableModel model = (DirDiffTableModel) table.getModel();
final DirDiffElementImpl element = model.getElementAt(row);
if (element == null)
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
final int modelColumn = table.convertColumnIndexToModel(column);
if (element.isSeparator()) {
return new SimpleColoredComponent() {
{
setIcon(ObjectUtils.chooseNotNull(element.getSourceIcon(), element.getTargetIcon()));
append(element.getName());
}
@Override
protected void doPaint(Graphics2D g) {
int offset = 0;
int i = 0;
final TableColumnModel columnModel = table.getColumnModel();
while (i < column) {
offset += columnModel.getColumn(i).getWidth();
i++;
}
g.translate(-offset, 0);
super.doPaint(g);
g.translate(offset, 0);
}
};
}
final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (c instanceof JLabel) {
final JLabel label = (JLabel) c;
Border border = label.getBorder();
if ((hasFocus || isSelected) && border != null) {
label.setBorder(new EmptyBorder(border.getBorderInsets(label)));
}
label.setIcon(null);
final DirDiffOperation op = element.getOperation();
if (modelColumn == (table.getColumnCount() - 1) / 2) {
label.setIcon(op.getIcon());
label.setHorizontalAlignment(CENTER);
return label;
}
Color fg = isSelected ? UIUtil.getTableSelectionForeground() : op.getTextColor();
label.setForeground(fg);
final String name = table.getColumnName(column);
if (DirDiffTableModel.COLUMN_DATE.equals(name)) {
label.setHorizontalAlignment(CENTER);
} else if (DirDiffTableModel.COLUMN_SIZE.equals(name)) {
label.setHorizontalAlignment(RIGHT);
} else {
label.setHorizontalAlignment(LEFT);
final String text = label.getText();
label.setText(" " + text);
if (text != null && text.trim().length() > 0) {
label.setIcon(modelColumn == 0 ? element.getSourceIcon() : element.getTargetIcon());
}
}
}
return c;
}
Aggregations