Search in sources :

Example 1 with DirDiffOperation

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();
}
Also used : DirDiffTableModel(com.intellij.openapi.diff.impl.dir.DirDiffTableModel) DirDiffElementImpl(com.intellij.openapi.diff.impl.dir.DirDiffElementImpl) DirDiffOperation(com.intellij.ide.diff.DirDiffOperation)

Example 2 with DirDiffOperation

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;
}
Also used : TableColumnModel(javax.swing.table.TableColumnModel) DirDiffOperation(com.intellij.ide.diff.DirDiffOperation) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent) EmptyBorder(javax.swing.border.EmptyBorder) EmptyBorder(javax.swing.border.EmptyBorder) Border(javax.swing.border.Border) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent)

Aggregations

DirDiffOperation (com.intellij.ide.diff.DirDiffOperation)2 DirDiffElementImpl (com.intellij.openapi.diff.impl.dir.DirDiffElementImpl)1 DirDiffTableModel (com.intellij.openapi.diff.impl.dir.DirDiffTableModel)1 SimpleColoredComponent (com.intellij.ui.SimpleColoredComponent)1 Border (javax.swing.border.Border)1 EmptyBorder (javax.swing.border.EmptyBorder)1 TableColumnModel (javax.swing.table.TableColumnModel)1