// Openbravo POS is a point of sales application designed for touch screens. // Copyright (C) 2007-2009 Openbravo, S.L. // http://www.openbravo.com/product/pos // // This file is part of Openbravo POS. // // Openbravo POS is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Openbravo POS is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Openbravo POS. If not, see <http://www.gnu.org/licenses/>. package com.openbravo.pos.inventory; import com.openbravo.basic.BasicException; import java.awt.Component; import java.awt.Dialog; import java.awt.Frame; import java.awt.Window; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.JFrame; import com.openbravo.pos.forms.AppLocal; import com.openbravo.pos.forms.AppView; /** * * @author adrianromero * @author Andrey Svininykh <svininykh@gmail.com> * @version NORD POS 3 */ public class JInventoryLineEdit extends javax.swing.JDialog { private InventoryLine returnLine; private InventoryLine m_oLine; private boolean m_bunitsok; private boolean m_bpriceok; private JInventoryLineEdit(java.awt.Frame parent, boolean modal) { super(parent, modal); } private JInventoryLineEdit(java.awt.Dialog parent, boolean modal) { super(parent, modal); } private InventoryLine init(AppView app, InventoryLine oLine) throws BasicException { // Inicializo los componentes initComponents(); m_oLine = oLine; m_bunitsok = true; m_bpriceok = true; m_jName.setEnabled(m_oLine.getProductID() == null && app.getAppUserView().getUser().hasPermission("com.openbravo.pos.sales.JPanelTicketEdits")); m_jPrice.setEnabled(app.getAppUserView().getUser().hasPermission("com.openbravo.pos.sales.JPanelTicketEdits")); m_jName.setText(m_oLine.getProductName()); m_jUnits.setDoubleValue(oLine.getMultiply()); m_jPrice.setDoubleValue(oLine.getPriceBuy()); m_jName.addPropertyChangeListener("Edition", new RecalculateName()); m_jUnits.addPropertyChangeListener("Edition", new RecalculateUnits()); m_jPrice.addPropertyChangeListener("Edition", new RecalculatePrice()); m_jUnits.addEditorKeys(m_jKeys); m_jPrice.addEditorKeys(m_jKeys); m_jPrice.activate(); printTotals(); getRootPane().setDefaultButton(m_jButtonOK); returnLine = null; setVisible(true); return returnLine; } private void printTotals() { if (m_bunitsok && m_bpriceok) { m_jTotal.setText(m_oLine.printSubValue()); m_jButtonOK.setEnabled(true); } else { m_jTotal.setText(null); m_jButtonOK.setEnabled(false); } } private class RecalculateUnits implements PropertyChangeListener { @Override public void propertyChange(PropertyChangeEvent evt) { Double value = m_jUnits.getDoubleValue(); if (value == null || value == 0.0) { m_bunitsok = false; } else { m_oLine.setMultiply(value); m_bunitsok = true; } printTotals(); } } private class RecalculatePrice implements PropertyChangeListener { @Override public void propertyChange(PropertyChangeEvent evt) { Double value = m_jPrice.getDoubleValue(); if (value == null || value == 0.0) { m_bpriceok = false; } else { m_oLine.setPriceBuy(value); m_bpriceok = true; } printTotals(); } } private class RecalculateName implements PropertyChangeListener { @Override public void propertyChange(PropertyChangeEvent evt) { m_oLine.setProductName(m_jName.getText()); } } private static Window getWindow(Component parent) { if (parent == null) { return new JFrame(); } else if (parent instanceof Frame || parent instanceof Dialog) { return (Window) parent; } else { return getWindow(parent.getParent()); } } public static InventoryLine showMessage(Component parent, AppView app, InventoryLine oLine) throws BasicException { Window window = getWindow(parent); JInventoryLineEdit myMsg; if (window instanceof Frame) { myMsg = new JInventoryLineEdit((Frame) window, true); } else { myMsg = new JInventoryLineEdit((Dialog) window, true); } return myMsg.init(app, oLine); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel5 = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); m_jUnits = new com.openbravo.editor.JEditorDouble(); m_jPrice = new com.openbravo.editor.JEditorCurrency(); jLabel6 = new javax.swing.JLabel(); m_jTotal = new javax.swing.JLabel(); m_jName = new javax.swing.JLabel(); jPanel1 = new javax.swing.JPanel(); m_jButtonOK = new javax.swing.JButton(); m_jButtonCancel = new javax.swing.JButton(); jPanel3 = new javax.swing.JPanel(); jPanel4 = new javax.swing.JPanel(); m_jKeys = new com.openbravo.editor.JEditorKeys(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle(AppLocal.getIntString("label.editline")); // NOI18N jPanel5.setLayout(new java.awt.BorderLayout()); jLabel1.setText(AppLocal.getIntString("label.price")); // NOI18N jLabel2.setText(AppLocal.getIntString("label.units")); // NOI18N jLabel4.setText(AppLocal.getIntString("label.item")); // NOI18N jLabel6.setText(AppLocal.getIntString("label.totalcash")); // NOI18N m_jTotal.setBackground(javax.swing.UIManager.getDefaults().getColor("TextField.disabledBackground")); m_jTotal.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); m_jTotal.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createLineBorder(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow")), javax.swing.BorderFactory.createEmptyBorder(1, 4, 1, 4))); m_jTotal.setOpaque(true); m_jTotal.setPreferredSize(new java.awt.Dimension(150, 25)); m_jTotal.setRequestFocusEnabled(false); m_jName.setBackground(javax.swing.UIManager.getDefaults().getColor("TextField.disabledBackground")); m_jName.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createLineBorder(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow")), javax.swing.BorderFactory.createEmptyBorder(1, 4, 1, 4))); m_jName.setOpaque(true); m_jName.setPreferredSize(new java.awt.Dimension(150, 25)); m_jName.setRequestFocusEnabled(false); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(jLabel6)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(m_jPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(m_jName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE) .addComponent(m_jUnits, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(m_jTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(42, Short.MAX_VALUE)) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel4) .addComponent(m_jName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel2) .addComponent(m_jUnits, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel1) .addComponent(m_jPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel6) .addComponent(m_jTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel5.add(jPanel2, java.awt.BorderLayout.CENTER); jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT)); m_jButtonOK.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_ok.png"))); // NOI18N m_jButtonOK.setText(AppLocal.getIntString("Button.OK")); // NOI18N m_jButtonOK.setFocusPainted(false); m_jButtonOK.setFocusable(false); m_jButtonOK.setMargin(new java.awt.Insets(8, 16, 8, 16)); m_jButtonOK.setRequestFocusEnabled(false); m_jButtonOK.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { m_jButtonOKActionPerformed(evt); } }); jPanel1.add(m_jButtonOK); m_jButtonCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_cancel.png"))); // NOI18N m_jButtonCancel.setText(AppLocal.getIntString("Button.Cancel")); // NOI18N m_jButtonCancel.setFocusPainted(false); m_jButtonCancel.setFocusable(false); m_jButtonCancel.setMargin(new java.awt.Insets(8, 16, 8, 16)); m_jButtonCancel.setRequestFocusEnabled(false); m_jButtonCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { m_jButtonCancelActionPerformed(evt); } }); jPanel1.add(m_jButtonCancel); jPanel5.add(jPanel1, java.awt.BorderLayout.SOUTH); getContentPane().add(jPanel5, java.awt.BorderLayout.CENTER); jPanel3.setLayout(new java.awt.BorderLayout()); jPanel4.setLayout(new javax.swing.BoxLayout(jPanel4, javax.swing.BoxLayout.Y_AXIS)); jPanel4.add(m_jKeys); jPanel3.add(jPanel4, java.awt.BorderLayout.NORTH); getContentPane().add(jPanel3, java.awt.BorderLayout.EAST); setSize(new java.awt.Dimension(580, 362)); setLocationRelativeTo(null); }// </editor-fold>//GEN-END:initComponents private void m_jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jButtonCancelActionPerformed dispose(); }//GEN-LAST:event_m_jButtonCancelActionPerformed private void m_jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jButtonOKActionPerformed returnLine = m_oLine; dispose(); }//GEN-LAST:event_m_jButtonOKActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel6; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel5; private javax.swing.JButton m_jButtonCancel; private javax.swing.JButton m_jButtonOK; private com.openbravo.editor.JEditorKeys m_jKeys; private javax.swing.JLabel m_jName; private com.openbravo.editor.JEditorCurrency m_jPrice; private javax.swing.JLabel m_jTotal; private com.openbravo.editor.JEditorDouble m_jUnits; // End of variables declaration//GEN-END:variables }