OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 151 Rev 174
Line 12... Line 12...
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.sales.pos.ui;
14
 package org.openconcerto.erp.core.sales.pos.ui;
15
 
15
 
16
import org.openconcerto.erp.core.sales.pos.model.Article;
16
import org.openconcerto.erp.core.sales.pos.model.Article;
-
 
17
import org.openconcerto.erp.core.sales.pos.model.TicketItem;
17
import org.openconcerto.ui.touch.ScrollableList;
18
import org.openconcerto.ui.touch.ScrollableList;
18
import org.openconcerto.utils.Pair;
-
 
19
 
19
 
20
import java.awt.Color;
20
import java.awt.Color;
21
import java.awt.Component;
21
import java.awt.Component;
22
import java.awt.Font;
22
import java.awt.Font;
23
import java.awt.Graphics;
23
import java.awt.Graphics;
Line 33... Line 33...
33
import javax.swing.JList;
33
import javax.swing.JList;
34
import javax.swing.JPanel;
34
import javax.swing.JPanel;
35
import javax.swing.ListCellRenderer;
35
import javax.swing.ListCellRenderer;
36
import javax.swing.SwingConstants;
36
import javax.swing.SwingConstants;
37
 
37
 
38
public class TicketCellRenderer implements ListCellRenderer {
38
public class TicketCellRenderer implements ListCellRenderer<TicketItem> {
39
 
39
 
40
    @Override
40
    @Override
41
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
41
    public Component getListCellRendererComponent(JList<? extends TicketItem> list, TicketItem item, int index, boolean isSelected, boolean cellHasFocus) {
42
        @SuppressWarnings("unchecked")
-
 
43
        Pair<Article, Integer> item = (Pair<Article, Integer>) value;
-
 
-
 
42
 
44
        JPanel p = new JPanel();
43
        JPanel p = new JPanel();
45
        p.setLayout(new GridBagLayout());
44
        p.setLayout(new GridBagLayout());
46
        GridBagConstraints c = new GridBagConstraints();
45
        GridBagConstraints c = new GridBagConstraints();
47
        c.gridx = 0;
46
        c.gridx = 0;
48
 
47
 
49
        c.fill = GridBagConstraints.HORIZONTAL;
48
        c.fill = GridBagConstraints.HORIZONTAL;
50
        c.insets = new Insets(5, 5, 5, 5);
49
        c.insets = new Insets(5, 5, 5, 5);
51
        final JLabel l1 = new JLabel(item.getSecond().toString(), SwingConstants.RIGHT);
50
        final JLabel l1 = new JLabel(item.getArticle().toString(), SwingConstants.RIGHT);
52
 
51
 
53
        p.add(l1, c);
52
        p.add(l1, c);
54
        c.gridx++;
53
        c.gridx++;
55
        c.weightx = 1;
54
        c.weightx = 1;
56
        Article article = item.getFirst();
55
        Article article = item.getArticle();
57
        final JLabel l2 = new JLabel(article.getName().toUpperCase(), SwingConstants.LEFT);
56
        final JLabel l2 = new JLabel(article.getName().toUpperCase(), SwingConstants.LEFT);
58
        p.add(l2, c);
57
        p.add(l2, c);
59
        c.gridx++;
58
        c.gridx++;
60
        c.weightx = 0;
59
        c.weightx = 0;
61
 
60
 
Line 80... Line 79...
80
        l3.setFont(new Font("Arial", Font.PLAIN, 18));
79
        l3.setFont(new Font("Arial", Font.PLAIN, 18));
81
 
80
 
82
        return p;
81
        return p;
83
    }
82
    }
84
 
83
 
85
    public void paint(Graphics g, ScrollableList list, Object value, int index, boolean isSelected) {
84
    public void paint(Graphics g, ScrollableList list, TicketItem item, int index, boolean isSelected) {
86
        @SuppressWarnings("unchecked")
-
 
87
        final Pair<Article, Integer> item = (Pair<Article, Integer>) value;
-
 
88
 
85
 
89
        if (isSelected) {
86
        if (isSelected) {
90
            g.setColor(new Color(232, 242, 254));
87
            g.setColor(new Color(232, 242, 254));
91
            g.fillRect(0, 0, list.getWidth(), list.getCellHeight());
88
            g.fillRect(0, 0, list.getWidth(), list.getCellHeight());
92
        }
89
        }
Line 95... Line 92...
95
        final int inset = 5;
92
        final int inset = 5;
96
        ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
93
        ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
97
        g.setFont(new Font("Arial", Font.PLAIN, 16));
94
        g.setFont(new Font("Arial", Font.PLAIN, 16));
98
        final int height = g.getFontMetrics().getMaxAscent() + g.getFontMetrics().getMaxDescent() + inset;
95
        final int height = g.getFontMetrics().getMaxAscent() + g.getFontMetrics().getMaxDescent() + inset;
99
 
96
 
-
 
97
        System.err.println("TicketCellRenderer.paint()" + item);
-
 
98
 
-
 
99
        Article article = item.getArticle();
-
 
100
        final BigDecimal qty = item.getQty();
100
        final String s1 = item.getSecond().toString();
101
        String s1 = qty.toString();
-
 
102
        if (article.getSalesUnit() != null) {
-
 
103
            s1 = qty.toString() + article.getSalesUnit();
-
 
104
        }
101
        g.drawString(s1, inset, height);
105
        g.drawString(s1, inset, height);
102
        final int width1 = (int) g.getFontMetrics().getStringBounds("999 ", g).getWidth() + inset * 2;
106
        final int width1 = (int) g.getFontMetrics().getStringBounds("1999kg ", g).getWidth() + inset * 2;
-
 
107
 
-
 
108
        String s2 = article.getName().toUpperCase().trim();
103
 
109
 
104
        Article article = item.getFirst();
-
 
105
        String s2 = article.getName().toUpperCase();
-
 
106
        final int maxLength = 13;
110
        final int maxLength = 15;
107
        if (s2.length() > maxLength)
111
        if (s2.length() > maxLength)
108
            s2 = s2.substring(0, maxLength + 1) + '…';
112
            s2 = s2.substring(0, maxLength + 1) + '…';
109
        g.drawString(s2, width1 + inset, height);
113
        g.drawString(s2, width1 + inset, height);
110
 
114
 
111
        final String s3 = centsToString(article.getPriceWithTax().movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue());
115
        final String s3 = centsToString(article.getPriceWithTax().multiply(qty).movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue()) + "€";
112
        final int width3 = (int) g.getFontMetrics().getStringBounds(s3, g).getWidth() + inset * 2;
116
        final int width3 = (int) g.getFontMetrics().getStringBounds(s3, g).getWidth() + +inset;
113
        g.drawString(s3, list.getWidth() - width3, height);
117
        g.drawString(s3, list.getWidth() - width3, height - 4);
-
 
118
 
-
 
119
        g.setFont(g.getFont().deriveFont(12f));
-
 
120
        final String s4 = qty.toPlainString() + " x " + centsToString(article.getPriceWithTax().movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue());
-
 
121
 
-
 
122
        final int width4 = (int) g.getFontMetrics().getStringBounds(s4, g).getWidth() + +inset;
-
 
123
        g.drawString(s4, list.getWidth() - width4, height + 11);
-
 
124
 
114
    }
125
    }
115
 
126
 
116
    public static String centsToString(int cents) {
127
    public static String centsToString(int cents) {
117
        final int c = Math.abs(cents) % 100;
128
        final int c = Math.abs(cents) % 100;
118
        String sc = String.valueOf(c);
129
        String sc = String.valueOf(c);
Line 123... Line 134...
123
    }
134
    }
124
 
135
 
125
    public static String toString(final BigDecimal p) {
136
    public static String toString(final BigDecimal p) {
126
        return centsToString(p.movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue());
137
        return centsToString(p.movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue());
127
    }
138
    }
-
 
139
 
128
}
140
}