OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 94 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 174
Line 26... Line 26...
26
 
26
 
27
public class DeviseTableCellRenderer extends DefaultTableCellRenderer {
27
public class DeviseTableCellRenderer extends DefaultTableCellRenderer {
28
    private final DecimalFormat decimalFormat;
28
    private final DecimalFormat decimalFormat;
29
    private final DecimalFormat decimalFormat2;
29
    private final DecimalFormat decimalFormat2;
30
    private BigDecimal oneCents = new BigDecimal(0.01f);
30
    private BigDecimal oneCents = new BigDecimal(0.01f);
-
 
31
    private boolean hideZeroValue = false;
31
 
32
 
32
    public DeviseTableCellRenderer() {
33
    public DeviseTableCellRenderer() {
33
        this(new DecimalFormat("##,##0.00#"), new DecimalFormat("##,##0.00#######"));
34
        this(new DecimalFormat("##,##0.00#"), new DecimalFormat("##,##0.00#######"));
34
    }
35
    }
35
 
36
 
Line 40... Line 41...
40
        symbol.setDecimalSeparator('.');
41
        symbol.setDecimalSeparator('.');
41
        decimalFormat.setDecimalFormatSymbols(symbol);
42
        decimalFormat.setDecimalFormatSymbols(symbol);
42
        decimalFormat2.setDecimalFormatSymbols(symbol);
43
        decimalFormat2.setDecimalFormatSymbols(symbol);
43
    }
44
    }
44
 
45
 
-
 
46
    public void setHideZeroValue(boolean hideZeroValue) {
-
 
47
        this.hideZeroValue = hideZeroValue;
-
 
48
    }
-
 
49
 
45
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
50
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
46
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
51
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
47
        TableCellRendererUtils.setColors(this, table, isSelected);
52
        TableCellRendererUtils.setColors(this, table, isSelected);
48
        this.setHorizontalAlignment(SwingConstants.RIGHT);
53
        this.setHorizontalAlignment(SwingConstants.RIGHT);
49
        if (table.getColumnClass(column) != BigDecimal.class) {
54
        if (table.getColumnClass(column) != BigDecimal.class) {
50
            throw new IllegalStateException("Value is not a BigDecimal :" + table.getColumnClass(column));
55
            throw new IllegalStateException("Value is not a BigDecimal :" + table.getColumnClass(column));
51
        }
56
        }
-
 
57
 
52
        if (value != null) {
58
        if (value != null) {
-
 
59
            BigDecimal amount = (BigDecimal) value;
-
 
60
            if (this.hideZeroValue && amount.signum() == 0) {
-
 
61
                this.setText("");
-
 
62
            } else {
53
            if (((BigDecimal) value).compareTo(oneCents) < 0)
63
                if (amount.compareTo(oneCents) < 0)
54
                this.setText(decimalFormat2.format(value));
64
                    this.setText(decimalFormat2.format(value));
55
            else
65
                else
56
                this.setText(decimalFormat.format(value));
66
                    this.setText(decimalFormat.format(value));
-
 
67
            }
57
        } else {
68
        } else {
58
            this.setText("");
69
            this.setText("");
59
        }
70
        }
60
 
71
 
61
        return this;
72
        return this;