142 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
182 |
ilm |
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
142 |
ilm |
5 |
*
|
|
|
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
|
|
|
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.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.erp.core.sales.pos.ui;
|
|
|
15 |
|
156 |
ilm |
16 |
import org.openconcerto.erp.core.sales.pos.model.Client;
|
|
|
17 |
import org.openconcerto.ui.DefaultListModel;
|
|
|
18 |
import org.openconcerto.ui.touch.ScrollableList;
|
|
|
19 |
|
182 |
ilm |
20 |
import java.awt.BorderLayout;
|
142 |
ilm |
21 |
import java.awt.Color;
|
|
|
22 |
import java.awt.FlowLayout;
|
|
|
23 |
import java.awt.Font;
|
|
|
24 |
import java.awt.Graphics;
|
|
|
25 |
import java.awt.Graphics2D;
|
|
|
26 |
import java.awt.GridBagConstraints;
|
|
|
27 |
import java.awt.GridBagLayout;
|
|
|
28 |
import java.awt.Insets;
|
|
|
29 |
import java.awt.RenderingHints;
|
|
|
30 |
import java.awt.event.ActionEvent;
|
|
|
31 |
import java.awt.event.ActionListener;
|
|
|
32 |
import java.math.RoundingMode;
|
182 |
ilm |
33 |
import java.util.ArrayList;
|
|
|
34 |
import java.util.List;
|
142 |
ilm |
35 |
import java.util.Vector;
|
|
|
36 |
|
182 |
ilm |
37 |
import javax.swing.BorderFactory;
|
|
|
38 |
import javax.swing.ImageIcon;
|
|
|
39 |
import javax.swing.JLabel;
|
142 |
ilm |
40 |
import javax.swing.JPanel;
|
182 |
ilm |
41 |
import javax.swing.JTextField;
|
|
|
42 |
import javax.swing.SwingUtilities;
|
|
|
43 |
import javax.swing.event.DocumentEvent;
|
|
|
44 |
import javax.swing.event.DocumentListener;
|
142 |
ilm |
45 |
import javax.swing.event.ListSelectionEvent;
|
|
|
46 |
import javax.swing.event.ListSelectionListener;
|
|
|
47 |
|
|
|
48 |
public class ListeDesClientsPanel extends JPanel {
|
|
|
49 |
|
|
|
50 |
private ScrollableList clientList;
|
|
|
51 |
private DefaultListModel ticketLlistModel;
|
|
|
52 |
|
|
|
53 |
ListeDesClientsPanel(final CaisseFrame caisseFrame) {
|
182 |
ilm |
54 |
this.setBackground(new Color(245, 245, 245));
|
142 |
ilm |
55 |
this.setOpaque(true);
|
|
|
56 |
this.setLayout(new GridBagLayout());
|
|
|
57 |
final GridBagConstraints c = new GridBagConstraints();
|
|
|
58 |
c.fill = GridBagConstraints.BOTH;
|
|
|
59 |
c.anchor = GridBagConstraints.CENTER;
|
|
|
60 |
c.weightx = 1;
|
|
|
61 |
c.weighty = 0;
|
|
|
62 |
c.gridx = 0;
|
|
|
63 |
c.gridy = 0;
|
|
|
64 |
c.gridwidth = 2;
|
|
|
65 |
|
|
|
66 |
final StatusBar p = new StatusBar();
|
|
|
67 |
p.setTitle("Liste des clients");
|
|
|
68 |
p.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
|
|
69 |
final POSButton bBack = new POSButton("Fermer");
|
|
|
70 |
p.add(bBack);
|
|
|
71 |
this.add(p, c);
|
|
|
72 |
|
|
|
73 |
// Liste des clients
|
|
|
74 |
c.gridy++;
|
|
|
75 |
c.gridwidth = 1;
|
|
|
76 |
c.weighty = 1;
|
182 |
ilm |
77 |
c.gridheight = 1;
|
142 |
ilm |
78 |
|
|
|
79 |
ticketLlistModel = new DefaultListModel();
|
182 |
ilm |
80 |
final List<Client> allClients = caisseFrame.getPOSConf().allClients();
|
|
|
81 |
ticketLlistModel.addAll(new Vector<Client>(allClients));
|
142 |
ilm |
82 |
final Font f = new Font("Arial", Font.PLAIN, 24);
|
|
|
83 |
clientList = new ScrollableList(ticketLlistModel) {
|
|
|
84 |
@Override
|
|
|
85 |
public void paintCell(Graphics g, Object object, int index, boolean isSelected, int posY) {
|
|
|
86 |
g.setFont(f);
|
|
|
87 |
|
|
|
88 |
if (isSelected) {
|
|
|
89 |
g.setColor(new Color(232, 242, 254));
|
|
|
90 |
} else {
|
|
|
91 |
g.setColor(Color.WHITE);
|
|
|
92 |
}
|
|
|
93 |
g.fillRect(0, posY, getWidth(), getCellHeight());
|
|
|
94 |
|
|
|
95 |
//
|
|
|
96 |
g.setColor(Color.GRAY);
|
|
|
97 |
g.drawLine(0, posY + this.getCellHeight() - 1, this.getWidth(), posY + this.getCellHeight() - 1);
|
|
|
98 |
|
|
|
99 |
if (isSelected) {
|
|
|
100 |
g.setColor(Color.BLACK);
|
|
|
101 |
} else {
|
|
|
102 |
g.setColor(Color.GRAY);
|
|
|
103 |
}
|
|
|
104 |
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
105 |
Client client = (Client) object;
|
|
|
106 |
String label = client.getFullName();
|
|
|
107 |
final int soldeInCents = client.getSolde().movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue();
|
|
|
108 |
String euro = TicketCellRenderer.centsToString(soldeInCents) + "€";
|
|
|
109 |
|
|
|
110 |
int wEuro = (int) g.getFontMetrics().getStringBounds(euro, g).getWidth();
|
|
|
111 |
g.drawString(label, 10, posY + 24);
|
|
|
112 |
g.drawString(euro, getWidth() - 5 - wEuro, posY + 24);
|
|
|
113 |
|
182 |
ilm |
114 |
final String addr = client.getAddr().replace('\n', ' ');
|
142 |
ilm |
115 |
if (addr != null) {
|
|
|
116 |
g.drawString(addr, 10, posY + 48);
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
};
|
|
|
120 |
this.add(clientList, c);
|
|
|
121 |
|
182 |
ilm |
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 |
|
142 |
ilm |
142 |
// Detail
|
|
|
143 |
c.fill = GridBagConstraints.BOTH;
|
182 |
ilm |
144 |
c.gridx = 1;
|
|
|
145 |
c.gridy = 1;
|
|
|
146 |
c.gridheight = 2;
|
142 |
ilm |
147 |
c.weighty = 1;
|
|
|
148 |
c.insets = new Insets(10, 10, 10, 10);
|
|
|
149 |
|
|
|
150 |
final DetailClientPanel detailClientPanel = new DetailClientPanel(caisseFrame);
|
|
|
151 |
this.add(detailClientPanel, c);
|
|
|
152 |
|
|
|
153 |
clientList.addListSelectionListener(new ListSelectionListener() {
|
|
|
154 |
|
|
|
155 |
@Override
|
|
|
156 |
public void valueChanged(ListSelectionEvent e) {
|
|
|
157 |
Client selectedValue = (Client) clientList.getSelectedValue();
|
|
|
158 |
detailClientPanel.setSelectedClient(selectedValue);
|
|
|
159 |
}
|
|
|
160 |
});
|
|
|
161 |
|
|
|
162 |
bBack.addActionListener(new ActionListener() {
|
|
|
163 |
|
|
|
164 |
@Override
|
|
|
165 |
public void actionPerformed(ActionEvent e) {
|
|
|
166 |
caisseFrame.showCaisse();
|
|
|
167 |
|
|
|
168 |
}
|
|
|
169 |
});
|
|
|
170 |
|
182 |
ilm |
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 |
|
142 |
ilm |
210 |
}
|
|
|
211 |
|
|
|
212 |
public void setSelectedClient(Object selectedValue) {
|
|
|
213 |
clientList.setSelectedValue(selectedValue, true);
|
|
|
214 |
}
|
|
|
215 |
}
|