// 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.mant;
import java.awt.Component;
import java.awt.image.BufferedImage;
import java.util.UUID;
import javax.swing.*;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.format.Formats;
import com.openbravo.basic.BasicException;
import com.openbravo.data.user.EditorRecord;
import com.openbravo.data.user.DirtyManager;
/**
*
* @author adrianromero
*/
public class FloorsEditor extends JPanel implements EditorRecord {
// private DirtyManager m_Dirty = new DirtyManager();
private String m_sID;
/** Creates new form FloorsEditor */
public FloorsEditor(DirtyManager dirty) {
initComponents();
m_jName.getDocument().addDocumentListener(dirty);
m_jImage.addPropertyChangeListener("image", dirty);
writeValueEOF();
}
public void writeValueEOF() {
m_sID = null;
m_jName.setText(null);
m_jImage.setImage(null);
m_jName.setEnabled(false);
m_jImage.setEnabled(false);
}
public void writeValueInsert() {
m_sID = UUID.randomUUID().toString();
m_jName.setText(null);
m_jName.setBackground(COLOR_MANDATORY_FIELD);
m_jImage.setImage(null);
m_jName.setEnabled(true);
m_jImage.setEnabled(true);
}
public void writeValueDelete(Object value) {
Object[] floor = (Object[]) value;
m_sID = Formats.STRING.formatValue(floor[0]);
m_jName.setText(Formats.STRING.formatValue(floor[1]));
m_jImage.setImage((BufferedImage) floor[2]);
m_jName.setEnabled(false);
m_jImage.setEnabled(false);
}
public void writeValueEdit(Object value) {
Object[] floor = (Object[]) value;
m_sID = Formats.STRING.formatValue(floor[0]);
m_jName.setText(Formats.STRING.formatValue(floor[1]));
m_jName.setBackground(null);
m_jImage.setImage((BufferedImage) floor[2]);
m_jName.setEnabled(true);
m_jImage.setEnabled(true);
}
public Object createValue() throws BasicException {
Object[] floor = new Object[3];
floor[0] = m_sID;
floor[1] = m_jName.getText();
floor[2] = m_jImage.getImage();
return floor;
}
public Component getComponent() {
return this;
}
public void refresh() {
}
/** 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() {
jPanel1 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
m_jName = new javax.swing.JTextField();
jPanel3 = new javax.swing.JPanel();
m_jImage = new com.openbravo.data.gui.JImageEditor();
setLayout(new java.awt.BorderLayout());
jPanel1.setPreferredSize(new java.awt.Dimension(150, 100));
jLabel3.setText(AppLocal.getIntString("Label.Name")); // NOI18N
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, 0)
.addComponent(m_jName, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(m_jName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
add(jPanel1, java.awt.BorderLayout.NORTH);
jPanel3.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 5, 0, 0));
jPanel3.setLayout(new java.awt.BorderLayout());
jPanel3.add(m_jImage, java.awt.BorderLayout.CENTER);
add(jPanel3, java.awt.BorderLayout.CENTER);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel3;
private com.openbravo.data.gui.JImageEditor m_jImage;
private javax.swing.JTextField m_jName;
// End of variables declaration//GEN-END:variables
}