OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 156 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 15... Line 15...
15
 
15
 
16
import org.openconcerto.erp.core.sales.pos.model.Client;
16
import org.openconcerto.erp.core.sales.pos.model.Client;
17
import org.openconcerto.ui.DefaultListModel;
17
import org.openconcerto.ui.DefaultListModel;
18
import org.openconcerto.ui.touch.ScrollableList;
18
import org.openconcerto.ui.touch.ScrollableList;
19
 
19
 
-
 
20
import java.awt.BorderLayout;
20
import java.awt.Color;
21
import java.awt.Color;
21
import java.awt.FlowLayout;
22
import java.awt.FlowLayout;
22
import java.awt.Font;
23
import java.awt.Font;
23
import java.awt.Graphics;
24
import java.awt.Graphics;
24
import java.awt.Graphics2D;
25
import java.awt.Graphics2D;
Line 27... Line 28...
27
import java.awt.Insets;
28
import java.awt.Insets;
28
import java.awt.RenderingHints;
29
import java.awt.RenderingHints;
29
import java.awt.event.ActionEvent;
30
import java.awt.event.ActionEvent;
30
import java.awt.event.ActionListener;
31
import java.awt.event.ActionListener;
31
import java.math.RoundingMode;
32
import java.math.RoundingMode;
-
 
33
import java.util.ArrayList;
-
 
34
import java.util.List;
32
import java.util.Vector;
35
import java.util.Vector;
33
 
36
 
-
 
37
import javax.swing.BorderFactory;
-
 
38
import javax.swing.ImageIcon;
-
 
39
import javax.swing.JLabel;
34
import javax.swing.JPanel;
40
import javax.swing.JPanel;
-
 
41
import javax.swing.JTextField;
-
 
42
import javax.swing.SwingUtilities;
-
 
43
import javax.swing.event.DocumentEvent;
-
 
44
import javax.swing.event.DocumentListener;
35
import javax.swing.event.ListSelectionEvent;
45
import javax.swing.event.ListSelectionEvent;
36
import javax.swing.event.ListSelectionListener;
46
import javax.swing.event.ListSelectionListener;
37
 
47
 
38
public class ListeDesClientsPanel extends JPanel {
48
public class ListeDesClientsPanel extends JPanel {
39
 
49
 
40
    private ScrollableList clientList;
50
    private ScrollableList clientList;
41
    private DefaultListModel ticketLlistModel;
51
    private DefaultListModel ticketLlistModel;
42
 
52
 
43
    ListeDesClientsPanel(final CaisseFrame caisseFrame) {
53
    ListeDesClientsPanel(final CaisseFrame caisseFrame) {
44
        this.setBackground(Color.WHITE);
54
        this.setBackground(new Color(245, 245, 245));
45
        this.setOpaque(true);
55
        this.setOpaque(true);
46
        this.setLayout(new GridBagLayout());
56
        this.setLayout(new GridBagLayout());
47
        final GridBagConstraints c = new GridBagConstraints();
57
        final GridBagConstraints c = new GridBagConstraints();
48
        c.fill = GridBagConstraints.BOTH;
58
        c.fill = GridBagConstraints.BOTH;
49
        c.anchor = GridBagConstraints.CENTER;
59
        c.anchor = GridBagConstraints.CENTER;
Line 62... Line 72...
62
 
72
 
63
        // Liste des clients
73
        // Liste des clients
64
        c.gridy++;
74
        c.gridy++;
65
        c.gridwidth = 1;
75
        c.gridwidth = 1;
66
        c.weighty = 1;
76
        c.weighty = 1;
67
        c.gridheight = 2;
77
        c.gridheight = 1;
68
 
78
 
69
        ticketLlistModel = new DefaultListModel();
79
        ticketLlistModel = new DefaultListModel();
-
 
80
        final List<Client> allClients = caisseFrame.getPOSConf().allClients();
70
        ticketLlistModel.addAll(new Vector<Client>(caisseFrame.getPOSConf().allClients()));
81
        ticketLlistModel.addAll(new Vector<Client>(allClients));
71
        final Font f = new Font("Arial", Font.PLAIN, 24);
82
        final Font f = new Font("Arial", Font.PLAIN, 24);
72
        clientList = new ScrollableList(ticketLlistModel) {
83
        clientList = new ScrollableList(ticketLlistModel) {
73
            @Override
84
            @Override
74
            public void paintCell(Graphics g, Object object, int index, boolean isSelected, int posY) {
85
            public void paintCell(Graphics g, Object object, int index, boolean isSelected, int posY) {
75
                g.setFont(f);
86
                g.setFont(f);
Line 98... Line 109...
98
 
109
 
99
                int wEuro = (int) g.getFontMetrics().getStringBounds(euro, g).getWidth();
110
                int wEuro = (int) g.getFontMetrics().getStringBounds(euro, g).getWidth();
100
                g.drawString(label, 10, posY + 24);
111
                g.drawString(label, 10, posY + 24);
101
                g.drawString(euro, getWidth() - 5 - wEuro, posY + 24);
112
                g.drawString(euro, getWidth() - 5 - wEuro, posY + 24);
102
 
113
 
103
                final String addr = client.getAddr();
114
                final String addr = client.getAddr().replace('\n', ' ');
104
                if (addr != null) {
115
                if (addr != null) {
105
                    g.drawString(addr, 10, posY + 48);
116
                    g.drawString(addr, 10, posY + 48);
106
                }
117
                }
107
            }
118
            }
108
        };
119
        };
109
        this.add(clientList, c);
120
        this.add(clientList, c);
110
 
121
 
-
 
122
        // Recherche
-
 
123
        c.gridy++;
-
 
124
        c.weighty = 0;
-
 
125
        c.fill = GridBagConstraints.BOTH;
-
 
126
 
-
 
127
        JPanel pBottom = new JPanel();
-
 
128
        pBottom.setOpaque(true);
-
 
129
        pBottom.setBackground(CaissePanel.DARK_BLUE);
-
 
130
        pBottom.setLayout(new BorderLayout(3, 3));
-
 
131
        // Icon and text
-
 
132
        final Font f1 = new Font("Arial", Font.PLAIN, 21);
-
 
133
        final JLabel label = new JLabel(new ImageIcon(this.getClass().getResource("search.png")));
-
 
134
        pBottom.add(label, BorderLayout.WEST);
-
 
135
        pBottom.setBorder(BorderFactory.createLineBorder(CaissePanel.DARK_BLUE, 3));
-
 
136
        final JTextField textField = new JTextField();
-
 
137
        textField.setBorder(BorderFactory.createLineBorder(CaissePanel.DARK_BLUE, 1));
-
 
138
        textField.setFont(f1);
-
 
139
        pBottom.add(textField, BorderLayout.CENTER);
-
 
140
        this.add(pBottom, c);
-
 
141
 
111
        // Detail
142
        // Detail
112
        c.fill = GridBagConstraints.BOTH;
143
        c.fill = GridBagConstraints.BOTH;
113
        c.gridx++;
144
        c.gridx = 1;
-
 
145
        c.gridy = 1;
114
        c.gridheight = 1;
146
        c.gridheight = 2;
115
        c.weighty = 1;
147
        c.weighty = 1;
116
        c.insets = new Insets(10, 10, 10, 10);
148
        c.insets = new Insets(10, 10, 10, 10);
117
 
149
 
118
        final DetailClientPanel detailClientPanel = new DetailClientPanel(caisseFrame);
150
        final DetailClientPanel detailClientPanel = new DetailClientPanel(caisseFrame);
119
        this.add(detailClientPanel, c);
151
        this.add(detailClientPanel, c);
Line 134... Line 166...
134
                caisseFrame.showCaisse();
166
                caisseFrame.showCaisse();
135
 
167
 
136
            }
168
            }
137
        });
169
        });
138
 
170
 
-
 
171
        textField.getDocument().addDocumentListener(new DocumentListener() {
-
 
172
 
-
 
173
            @Override
-
 
174
            public void removeUpdate(DocumentEvent e) {
-
 
175
                changedUpdate(e);
-
 
176
            }
-
 
177
 
-
 
178
            @Override
-
 
179
            public void insertUpdate(DocumentEvent e) {
-
 
180
                changedUpdate(e);
-
 
181
            }
-
 
182
 
-
 
183
            @Override
-
 
184
            public void changedUpdate(DocumentEvent e) {
-
 
185
                List<Client> clients = new ArrayList<>();
-
 
186
                String text = textField.getText().trim().toLowerCase();
-
 
187
                if (text.isEmpty()) {
-
 
188
                    clients.addAll(allClients);
-
 
189
                } else {
-
 
190
                    for (Client c : allClients) {
-
 
191
                        if (c.getFullName().toLowerCase().contains(text)) {
-
 
192
                            clients.add(c);
-
 
193
                        }
-
 
194
                    }
-
 
195
                }
-
 
196
                ticketLlistModel.removeAllElements();
-
 
197
                ticketLlistModel.addAll(clients);
-
 
198
 
-
 
199
            }
-
 
200
        });
-
 
201
        SwingUtilities.invokeLater(new Runnable() {
-
 
202
 
-
 
203
            @Override
-
 
204
            public void run() {
-
 
205
                textField.grabFocus();
-
 
206
 
-
 
207
            }
-
 
208
        });
-
 
209
 
139
    }
210
    }
140
 
211
 
141
    public void setSelectedClient(Object selectedValue) {
212
    public void setSelectedClient(Object selectedValue) {
142
        clientList.setSelectedValue(selectedValue, true);
213
        clientList.setSelectedValue(selectedValue, true);
143
    }
214
    }