OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 174 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 174 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
Line 14... Line 14...
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.Categorie;
17
import org.openconcerto.erp.core.sales.pos.model.Categorie;
18
import org.openconcerto.ui.touch.ScrollableList;
18
import org.openconcerto.ui.touch.ScrollableList;
-
 
19
import org.openconcerto.utils.QuickOrderedMap;
-
 
20
import org.openconcerto.utils.StringUtils;
19
 
21
 
20
import java.awt.Color;
22
import java.awt.Color;
21
import java.awt.FlowLayout;
23
import java.awt.FlowLayout;
22
import java.awt.Font;
24
import java.awt.Font;
23
import java.awt.Graphics;
25
import java.awt.Graphics;
Line 100... Line 102...
100
            }
102
            }
101
 
103
 
102
            @Override
104
            @Override
103
            public void paintCell(Graphics g, Object object, int index, boolean isSelected, int posY) {
105
            public void paintCell(Graphics g, Object object, int index, boolean isSelected, int posY) {
104
                Article article = (Article) object;
106
                Article article = (Article) object;
105
                paintArticle(f, g, article, isSelected, posY, this.getWidth(), this.getCellHeight(), this.maxStringWidth, getLeftMargin());
107
                paintArticle(f, g, article, isSelected, posY, this.getWidth(), this.getCellHeight(), this.maxStringWidth, getLeftMargin(), false);
106
 
108
 
107
            }
109
            }
108
        };
110
        };
109
 
111
 
110
        this.list.setFixedCellHeight(64);
112
        this.list.setFixedCellHeight(64);
Line 183... Line 185...
183
            this.list.setSelectedValue(articleSelected, true);
185
            this.list.setSelectedValue(articleSelected, true);
184
        }
186
        }
185
 
187
 
186
    }
188
    }
187
 
189
 
188
    public static void paintArticle(final Font f, Graphics g, Article article, boolean isSelected, int posY, int cellWidth, int cellHeight, int maxWidth, int leftMargin) {
190
    public static void paintArticle(final Font f, Graphics g, Article article, boolean isSelected, int posY, int cellWidth, int cellHeight, int maxWidth, int leftMargin, boolean showCode) {
189
 
191
 
190
        g.setFont(f);
192
        g.setFont(f);
191
 
193
 
192
        if (isSelected) {
194
        if (isSelected) {
193
            g.setColor(new Color(232, 242, 254));
195
            g.setColor(new Color(232, 242, 254));
Line 206... Line 208...
206
            g.setColor(Color.GRAY);
208
            g.setColor(Color.GRAY);
207
        }
209
        }
208
        ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
210
        ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
209
 
211
 
210
        String label = article.getName();
212
        String label = article.getName();
-
 
213
        if (showCode && article.getCode() != null && !article.getCode().isEmpty()) {
-
 
214
            label += " [" + article.getCode() + "]";
-
 
215
        }
-
 
216
        StringBuilder declinaisons = null;
-
 
217
        QuickOrderedMap<String, String> decls = article.getDeclinaisons();
-
 
218
        if (decls != null && !decls.isEmpty()) {
-
 
219
            declinaisons = new StringBuilder();
-
 
220
            for (int i = 0; i < decls.size(); i++) {
-
 
221
                declinaisons.append(StringUtils.firstUpThenLow(decls.getKey(i)));
-
 
222
                declinaisons.append(": ");
-
 
223
                declinaisons.append(decls.getValue(i));
-
 
224
                declinaisons.append("  ");
-
 
225
            }
-
 
226
        }
211
 
227
 
212
        if (label.length() > maxWidth * 2) {
228
        if (label.length() > maxWidth * 2) {
213
            label = label.substring(0, maxWidth * 2) + "...";
229
            label = label.substring(0, maxWidth * 2) + "...";
214
        }
230
        }
215
        String label2 = null;
231
        String label2 = null;
Line 223... Line 239...
223
            label = label.substring(0, lastSpace).trim();
239
            label = label.substring(0, lastSpace).trim();
224
            if (label2.length() > maxWidth) {
240
            if (label2.length() > maxWidth) {
225
                label2 = label2.substring(0, maxWidth) + "...";
241
                label2 = label2.substring(0, maxWidth) + "...";
226
            }
242
            }
227
        }
243
        }
-
 
244
        if (declinaisons != null) {
-
 
245
            String textDeclinaisons = declinaisons.toString();
-
 
246
            if (label2 == null) {
-
 
247
                label2 = textDeclinaisons;
-
 
248
            } else {
-
 
249
                if (label2.length() + textDeclinaisons.length() > maxWidth) {
-
 
250
                    label2 = label2.substring(0, maxWidth - textDeclinaisons.length()) + "...";
-
 
251
                }
-
 
252
                label2 = label2 + " " + textDeclinaisons;
-
 
253
            }
-
 
254
 
-
 
255
        }
228
 
256
 
229
        final BigDecimal priceInCents = article.getPriceWithTax();
257
        final BigDecimal priceInCents = article.getPriceWithTax(BigDecimal.ONE);
230
        String euro = getPrice(priceInCents);
258
        String euro = getPrice(priceInCents);
231
 
259
 
232
        int wEuro = (int) g.getFontMetrics().getStringBounds(euro, g).getWidth();
260
        int wEuro = (int) g.getFontMetrics().getStringBounds(euro, g).getWidth();
233
        if (label2 == null) {
261
        if (label2 == null) {
234
            g.drawString(label, leftMargin, posY + 39);
262
            g.drawString(label, leftMargin, posY + 39);