// 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.beans;
import java.awt.*;
import javax.swing.*;
public class JPercentDialog extends javax.swing.JDialog {
private static LocaleResources m_resources;
private Double m_dPercent;
public JPercentDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
init();
}
public JPercentDialog(java.awt.Dialog parent, boolean modal) {
super(parent, modal);
init();
}
private void init() {
if (m_resources == null) {
m_resources = new LocaleResources();
m_resources.addBundleName("beans_messages");
}
initComponents();
getRootPane().setDefaultButton(jcmdOK);
m_jpercent.addEditorKeys(m_jKeys);
m_jpercent.reset();
m_jpercent.setDoubleValue(0.0);
m_jpercent.activate();
m_dPercent = null;
}
private void setTitle(String title, String message, Icon icon) {
setTitle(title);
}
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 Double showEditPercent(Component parent, String title) {
return showEditPercent(parent, title, null, null);
}
public static Double showEditPercent(Component parent, String title, String message) {
return showEditPercent(parent, title, message, null);
}
public static Double showEditPercent(Component parent, String title, String message, Icon icon) {
Window window = getWindow(parent);
JPercentDialog myMsg;
if (window instanceof Frame) {
myMsg = new JPercentDialog((Frame) window, true);
} else {
myMsg = new JPercentDialog((Dialog) window, true);
}
myMsg.setTitle(title, message, icon);
myMsg.setVisible(true);
return myMsg.m_dPercent;
}
/** 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();
jcmdOK = new javax.swing.JButton();
jcmdCancel = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jPanelGrid = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
m_jKeys = new com.openbravo.editor.JEditorKeys();
jPanel4 = new javax.swing.JPanel();
m_jpercent = new com.openbravo.editor.JEditorPercent();
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeWindow(evt);
}
});
jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
jcmdOK.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_ok.png"))); // NOI18N
jcmdOK.setText(m_resources.getString("button.ok")); // NOI18N
jcmdOK.setMargin(new java.awt.Insets(8, 16, 8, 16));
jcmdOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jcmdOKActionPerformed(evt);
}
});
jPanel1.add(jcmdOK);
jcmdCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_cancel.png"))); // NOI18N
jcmdCancel.setText(m_resources.getString("button.cancel")); // NOI18N
jcmdCancel.setMargin(new java.awt.Insets(8, 16, 8, 16));
jcmdCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jcmdCancelActionPerformed(evt);
}
});
jPanel1.add(jcmdCancel);
getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);
jPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
jPanel2.setLayout(new java.awt.BorderLayout());
jPanel3.setLayout(new java.awt.BorderLayout());
jPanel3.add(m_jKeys, java.awt.BorderLayout.NORTH);
jPanel4.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
jPanel4.setLayout(new java.awt.BorderLayout());
jPanel4.add(m_jpercent, java.awt.BorderLayout.CENTER);
jPanel3.add(jPanel4, java.awt.BorderLayout.SOUTH);
jPanelGrid.add(jPanel3);
jPanel2.add(jPanelGrid, java.awt.BorderLayout.NORTH);
getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-277)/2, (screenSize.height-390)/2, 277, 390);
}// </editor-fold>//GEN-END:initComponents
private void jcmdOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcmdOKActionPerformed
m_dPercent = m_jpercent.getDoubleValue();
setVisible(false);
dispose();
}//GEN-LAST:event_jcmdOKActionPerformed
private void jcmdCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcmdCancelActionPerformed
setVisible(false);
dispose();
}//GEN-LAST:event_jcmdCancelActionPerformed
private void closeWindow(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeWindow
setVisible(false);
dispose();
}//GEN-LAST:event_closeWindow
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanelGrid;
private javax.swing.JButton jcmdCancel;
private javax.swing.JButton jcmdOK;
private com.openbravo.editor.JEditorKeys m_jKeys;
private com.openbravo.editor.JEditorPercent m_jpercent;
// End of variables declaration//GEN-END:variables
}