OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
174 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
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
 
16
import org.openconcerto.erp.core.common.ui.NumericTextField;
17
 
18
import java.awt.Color;
19
import java.awt.GridBagConstraints;
20
import java.awt.GridBagLayout;
21
import java.awt.GridLayout;
22
import java.awt.Insets;
23
import java.awt.event.ActionEvent;
24
import java.awt.event.ActionListener;
25
 
26
import javax.swing.JPanel;
27
import javax.swing.SwingUtilities;
28
 
29
public class PostalCodeEditorPanel extends JPanel {
30
 
31
    private final NumericTextField postalCodeTextField;
32
 
33
    private final NumericKeypadPanel keyPad;
34
 
35
    public PostalCodeEditorPanel(final CaisseFrame caisseFrame, final CaissePanel caissePanel) {
36
 
37
        this.setBackground(Color.WHITE);
38
        this.setOpaque(true);
39
        this.setLayout(new GridBagLayout());
40
        final GridBagConstraints c = new GridBagConstraints();
41
        c.fill = GridBagConstraints.HORIZONTAL;
42
        c.anchor = GridBagConstraints.EAST;
43
        c.weightx = 0;
44
        c.weighty = 1;
45
        c.gridx = 0;
46
        c.gridy = 0;
47
        c.insets = new Insets(20, 20, 30, 20);
48
        // Line 1
49
        c.gridwidth = 2;
50
        POSLabel title = new POSLabel("Code postal");
51
        this.add(title, c);
52
        // Line 2
53
        this.postalCodeTextField = new NumericTextField(8);
54
        this.postalCodeTextField.setFont(this.postalCodeTextField.getFont().deriveFont(16f));
55
        c.gridy++;
56
        this.add(this.postalCodeTextField, c);
57
 
58
        c.gridy++;
59
        c.gridx = 0;
60
        c.fill = GridBagConstraints.NONE;
61
        c.anchor = GridBagConstraints.SOUTHEAST;
62
 
63
        final JPanel buttons = new JPanel(new GridLayout(1, 2, 10, 0));
64
        buttons.setOpaque(false);
65
        POSButton bCancel = new POSButton("Annuler");
66
        buttons.add(bCancel, c);
67
        POSButton bApply = new POSButton("Valider");
68
        buttons.add(bApply, c);
69
        bApply.addActionListener(new ActionListener() {
70
 
71
            @Override
72
            public void actionPerformed(ActionEvent e) {
73
                caissePanel.getControler().setCodePostal(PostalCodeEditorPanel.this.postalCodeTextField.getText());
74
                caissePanel.validateTicket(caisseFrame);
75
                caisseFrame.showCaisse();
76
            }
77
        });
78
        bCancel.addActionListener(new ActionListener() {
79
 
80
            @Override
81
            public void actionPerformed(ActionEvent e) {
82
                caisseFrame.showCaisse();
83
            }
84
        });
85
 
86
        this.add(buttons, c);
87
 
88
        c.anchor = GridBagConstraints.CENTER;
89
        c.weightx = 0;
90
        c.weighty = 0;
91
        c.gridx = 3;
92
        c.gridy = 2;
93
        c.insets = new Insets(20, 20, 30, 20);
94
        // Line 1
95
        c.gridheight = 5;
96
        keyPad = new NumericKeypadPanel(postalCodeTextField);
97
        this.add(keyPad, c);
98
 
99
        SwingUtilities.invokeLater(new Runnable() {
100
            public void run() {
101
                postalCodeTextField.requestFocus();
102
            }
103
        });
104
    }
105
 
106
}