Package realcix20.guis.views

Source Code of realcix20.guis.views.TestFormulaDialog

package realcix20.guis.views;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import realcix20.classes.TaxTypeClass;
import realcix20.classes.basic.BaseClass;
import realcix20.classes.basic.Row;
import realcix20.guis.utils.DialogManager;
import realcix20.guis.utils.ImageManager;
import realcix20.guis.utils.MnemonicGenerator;
import realcix20.guis.utils.TxtManager;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.FormSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.layout.Sizes;

public class TestFormulaDialog extends JDialog implements ActionListener {
 
        private ObjectEdit container;
        private BaseClass object;
        private Row selectedRow;
       
        private JTextField b1TextField = new JTextField();
        private JTextField b2TextField = new JTextField();
       
        public TestFormulaDialog(ObjectEdit container, BaseClass object, Row selectedRow) {
           
                super(container);
                this.container = container;
                this.object = object;
                this.selectedRow = selectedRow;
               
                initComponents();
           
        }       

  private void initComponents() {
                      
    JLabel b1label = new JLabel();
    JLabel b2label = new JLabel();
    JPanel panel = new JPanel();
    JButton confirmButton = new JButton();
    JButton cancelButton = new JButton();
    CellConstraints cc = new CellConstraints();

    //======== this ========
                addWindowListener(
                        new WindowAdapter() {
                   
                            public void windowClosing(WindowEvent e) {
                                TestFormulaDialog thisWindow = (TestFormulaDialog)e.getSource();
                                thisWindow.container.setEnabled(true);
                                thisWindow.dispose();
                            }
                   
                        }
                );
    Container contentPane = getContentPane();
    contentPane.setLayout(new FormLayout(
      new ColumnSpec[] {
        new ColumnSpec("10px"),
        FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
        new ColumnSpec("100px"),
        FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
        new ColumnSpec("100px"),
        FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
        new ColumnSpec(ColumnSpec.FILL, Sizes.DEFAULT, FormSpec.DEFAULT_GROW)
      },
      new RowSpec[] {
        new RowSpec("10px"),
        FormFactory.LINE_GAP_ROWSPEC,
        new RowSpec("20px"),
        FormFactory.LINE_GAP_ROWSPEC,
        new RowSpec("20px"),
        FormFactory.LINE_GAP_ROWSPEC,
        FormFactory.DEFAULT_ROWSPEC
      }));
                              
    //---- b1label ----
    b1label.setText(TxtManager.getTxt("VIEW.OBJECTEDIT.TAX.TAXBASEAMT1"));
    contentPane.add(b1label, cc.xy(3, 3));
    contentPane.add(b1TextField, cc.xy(5, 3));
               
    //---- b2label ----
    b2label.setText(TxtManager.getTxt("VIEW.OBJECTEDIT.TAX.TAXBASEAMT2"));
    contentPane.add(b2label, cc.xy(3, 5));
    contentPane.add(b2TextField, cc.xy(5, 5));

    //======== panel ========
    {
      panel.setLayout(new FlowLayout());
     
      //---- confirmButton ----
                        confirmButton.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.GLOBAL.CONFIRMBUTTON"), KeyEvent.VK_O));
                        confirmButton.setMnemonic(KeyEvent.VK_O);
                        confirmButton.setIcon(ImageManager.getImage(ImageManager.CONFIRM_IMAGE));
                        confirmButton.setActionCommand("Confirm");
                        confirmButton.addActionListener(this);
      confirmButton.setPreferredSize(new Dimension(75, 20));
      panel.add(confirmButton);
     
      //---- cancelButton ----
                        cancelButton.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.GLOBAL.CANCELBUTTON"), KeyEvent.VK_C));
                        cancelButton.setMnemonic(KeyEvent.VK_C);
                        cancelButton.setIcon(ImageManager.getImage(ImageManager.CANCEL_IMAGE));
                        cancelButton.setActionCommand("Cancel");
                        cancelButton.addActionListener(this);
      cancelButton.setPreferredSize(new Dimension(75, 20));
      panel.add(cancelButton);
    }
    contentPane.add(panel, cc.xywh(3, 7, 3, 1));
   
               
                pack();
                setTitle(TxtManager.getTxt("VIEW.OBJECTEDIT.TAXTYPE.TESTFORMULA"));
                setVisible(true);
                setLocationRelativeTo(null);
                setResizable(false);
               
  }
       
        private boolean validateForm() {
           
                boolean result = true;
               
                if (b1TextField.getText() != null) {
                    try {
                        Double.parseDouble((String)b1TextField.getText());
                    } catch (Exception e) {
                        result = false;
                    }
                }
               
                if (b2TextField.getText() != null) {
                    try {
                        Double.parseDouble((String)b2TextField.getText());
                    } catch (Exception e) {
                        result = false;
                    }
                }
               
                return result;
           
        }
       
        public void actionPerformed(ActionEvent e) {
           
                if (e.getActionCommand().equals("Cancel")) {
                    container.setEnabled(true);
                    dispose();
                } else if (e.getActionCommand().equals("Confirm")) {                   
                    //DialogManager dialogManager = DialogManager.getInstance();
                    if (!validateForm()) {
                       DialogManager.showMessageDialog(container, TxtManager.getTxt("INFORMATION.INPUTNUMBER"));
                    } else {
                        double b1 = Double.parseDouble((String)b1TextField.getText());
                        double b2 = Double.parseDouble((String)b2TextField.getText());
                        Vector result = new Vector();
                        if (((TaxTypeClass)object).testFormula(b1, b2, result, selectedRow)) {
                            StringBuffer sb = new StringBuffer(TxtManager.getTxt("VIEW.OBJECTEDIT.TAXTYPE.TESTSUCCESS"));
                            sb.append(result.get(0).toString() + " . ");
                            DialogManager.showMessageDialog(container, sb.toString());
                        } else {
                            DialogManager.showMessageDialog(container, TxtManager.getTxt("VIEW.OBJECTEDIT.TAXTYPE.TESTFAIL"));
                        }
                        container.setEnabled(true);
                        dispose();
                    }
                }
           
        }
                 
}
TOP

Related Classes of realcix20.guis.views.TestFormulaDialog

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.