OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Blame | Last modification | View Log | RSS feed

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * 
 * Copyright 2011 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
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
 * language governing permissions and limitations under the License.
 * 
 * When distributing the software, include this License Header Notice in each file.
 */
 
 package org.openconcerto.erp.core.sales.pos.ui;

import org.openconcerto.erp.core.common.ui.NumericTextField;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class PostalCodeEditorPanel extends JPanel {

    private final NumericTextField postalCodeTextField;

    private final NumericKeypadPanel keyPad;

    public PostalCodeEditorPanel(final CaisseFrame caisseFrame, final CaissePanel caissePanel) {

        this.setBackground(Color.WHITE);
        this.setOpaque(true);
        this.setLayout(new GridBagLayout());
        final GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.HORIZONTAL;
        c.anchor = GridBagConstraints.EAST;
        c.weightx = 0;
        c.weighty = 1;
        c.gridx = 0;
        c.gridy = 0;
        c.insets = new Insets(20, 20, 30, 20);
        // Line 1
        c.gridwidth = 2;
        POSLabel title = new POSLabel("Code postal");
        this.add(title, c);
        // Line 2
        this.postalCodeTextField = new NumericTextField(8);
        this.postalCodeTextField.setFont(this.postalCodeTextField.getFont().deriveFont(16f));
        c.gridy++;
        this.add(this.postalCodeTextField, c);

        c.gridy++;
        c.gridx = 0;
        c.fill = GridBagConstraints.NONE;
        c.anchor = GridBagConstraints.SOUTHEAST;

        final JPanel buttons = new JPanel(new GridLayout(1, 2, 10, 0));
        buttons.setOpaque(false);
        POSButton bCancel = new POSButton("Annuler");
        buttons.add(bCancel, c);
        POSButton bApply = new POSButton("Valider");
        buttons.add(bApply, c);
        bApply.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                caissePanel.getControler().setCodePostal(PostalCodeEditorPanel.this.postalCodeTextField.getText());
                caissePanel.validateTicket(caisseFrame);
                caisseFrame.showCaisse();
            }
        });
        bCancel.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                caisseFrame.showCaisse();
            }
        });

        this.add(buttons, c);

        c.anchor = GridBagConstraints.CENTER;
        c.weightx = 0;
        c.weighty = 0;
        c.gridx = 3;
        c.gridy = 2;
        c.insets = new Insets(20, 20, 30, 20);
        // Line 1
        c.gridheight = 5;
        keyPad = new NumericKeypadPanel(postalCodeTextField);
        this.add(keyPad, c);

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                postalCodeTextField.requestFocus();
            }
        });
    }

}