Dépôt officiel du code source de l'ERP OpenConcerto
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/pos/ui/ListeDesClientsPanel.java |
---|
1,7 → 1,7 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
17,6 → 17,7 |
import org.openconcerto.ui.DefaultListModel; |
import org.openconcerto.ui.touch.ScrollableList; |
import java.awt.BorderLayout; |
import java.awt.Color; |
import java.awt.FlowLayout; |
import java.awt.Font; |
29,9 → 30,18 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionListener; |
import java.math.RoundingMode; |
import java.util.ArrayList; |
import java.util.List; |
import java.util.Vector; |
import javax.swing.BorderFactory; |
import javax.swing.ImageIcon; |
import javax.swing.JLabel; |
import javax.swing.JPanel; |
import javax.swing.JTextField; |
import javax.swing.SwingUtilities; |
import javax.swing.event.DocumentEvent; |
import javax.swing.event.DocumentListener; |
import javax.swing.event.ListSelectionEvent; |
import javax.swing.event.ListSelectionListener; |
41,7 → 51,7 |
private DefaultListModel ticketLlistModel; |
ListeDesClientsPanel(final CaisseFrame caisseFrame) { |
this.setBackground(Color.WHITE); |
this.setBackground(new Color(245, 245, 245)); |
this.setOpaque(true); |
this.setLayout(new GridBagLayout()); |
final GridBagConstraints c = new GridBagConstraints(); |
64,10 → 74,11 |
c.gridy++; |
c.gridwidth = 1; |
c.weighty = 1; |
c.gridheight = 2; |
c.gridheight = 1; |
ticketLlistModel = new DefaultListModel(); |
ticketLlistModel.addAll(new Vector<Client>(caisseFrame.getPOSConf().allClients())); |
final List<Client> allClients = caisseFrame.getPOSConf().allClients(); |
ticketLlistModel.addAll(new Vector<Client>(allClients)); |
final Font f = new Font("Arial", Font.PLAIN, 24); |
clientList = new ScrollableList(ticketLlistModel) { |
@Override |
100,7 → 111,7 |
g.drawString(label, 10, posY + 24); |
g.drawString(euro, getWidth() - 5 - wEuro, posY + 24); |
final String addr = client.getAddr(); |
final String addr = client.getAddr().replace('\n', ' '); |
if (addr != null) { |
g.drawString(addr, 10, posY + 48); |
} |
108,10 → 119,31 |
}; |
this.add(clientList, c); |
// Recherche |
c.gridy++; |
c.weighty = 0; |
c.fill = GridBagConstraints.BOTH; |
JPanel pBottom = new JPanel(); |
pBottom.setOpaque(true); |
pBottom.setBackground(CaissePanel.DARK_BLUE); |
pBottom.setLayout(new BorderLayout(3, 3)); |
// Icon and text |
final Font f1 = new Font("Arial", Font.PLAIN, 21); |
final JLabel label = new JLabel(new ImageIcon(this.getClass().getResource("search.png"))); |
pBottom.add(label, BorderLayout.WEST); |
pBottom.setBorder(BorderFactory.createLineBorder(CaissePanel.DARK_BLUE, 3)); |
final JTextField textField = new JTextField(); |
textField.setBorder(BorderFactory.createLineBorder(CaissePanel.DARK_BLUE, 1)); |
textField.setFont(f1); |
pBottom.add(textField, BorderLayout.CENTER); |
this.add(pBottom, c); |
// Detail |
c.fill = GridBagConstraints.BOTH; |
c.gridx++; |
c.gridheight = 1; |
c.gridx = 1; |
c.gridy = 1; |
c.gridheight = 2; |
c.weighty = 1; |
c.insets = new Insets(10, 10, 10, 10); |
136,8 → 168,47 |
} |
}); |
textField.getDocument().addDocumentListener(new DocumentListener() { |
@Override |
public void removeUpdate(DocumentEvent e) { |
changedUpdate(e); |
} |
@Override |
public void insertUpdate(DocumentEvent e) { |
changedUpdate(e); |
} |
@Override |
public void changedUpdate(DocumentEvent e) { |
List<Client> clients = new ArrayList<>(); |
String text = textField.getText().trim().toLowerCase(); |
if (text.isEmpty()) { |
clients.addAll(allClients); |
} else { |
for (Client c : allClients) { |
if (c.getFullName().toLowerCase().contains(text)) { |
clients.add(c); |
} |
} |
} |
ticketLlistModel.removeAllElements(); |
ticketLlistModel.addAll(clients); |
} |
}); |
SwingUtilities.invokeLater(new Runnable() { |
@Override |
public void run() { |
textField.grabFocus(); |
} |
}); |
} |
public void setSelectedClient(Object selectedValue) { |
clientList.setSelectedValue(selectedValue, true); |
} |