- Hlavní stránka
- Balíky
- Třídy
- Soubory

# src/cz/neubauer/tomas/hazardanalysis/viewcontroller/administration/AdminDangerVariantFrame.java

Zobrazit dokumentaci tohoto souboru.

    00001
    00004 package cz.neubauer.tomas.hazardanalysis.viewcontroller.administration;
    00005
    00006 import java.awt.BorderLayout;
    00007 import java.awt.FlowLayout;
    00008 import java.awt.GridLayout;
    00009 import java.awt.event.ActionEvent;
    00010 import java.awt.event.ActionListener;
    00011 import java.util.ArrayList;
    00012 import java.util.Vector;
    00013
    00014 import javax.swing.JButton;
    00015 import javax.swing.JComboBox;
    00016 import javax.swing.JFrame;
    00017 import javax.swing.JLabel;
    00018 import javax.swing.JPanel;
    00019 import javax.swing.JTextField;
    00020
    00021 import cz.neubauer.tomas.hazardanalysis.model.dangers.DangerType;
    00022 import cz.neubauer.tomas.hazardanalysis.model.dangers.DangerVariant;
    00023 import cz.neubauer.tomas.hazardanalysis.viewcontroller.windowmanipulator.WindowManipulator;
    00024
    00028 public class AdminDangerVariantFrame extends JFrame {
    00029
    00033         private static final long serialVersionUID = 6248731818805186060L;
    00034
    00035         private AdminFrame owner;
    00036
    00037         private ArrayList<DangerType> types;
    00038
    00039         private DangerVariant dangerVariant;
    00040
    00041         private JComboBox cmbTypes;
    00042
    00043         private JPanel pnlTextFields;
    00044
    00045         private JTextField txtDescription;
    00046
    00047         private JButton btnOK;
    00048
    00049         private JButton btnCancel;
    00050
    00051         private JPanel pnlButtons;
    00052
    00053         public AdminDangerVariantFrame(AdminFrame owner, DangerVariant dangerVariant) {
    00054                 this.owner = owner;
    00055                 this.dangerVariant = dangerVariant;
    00056                 types = dangerVariant.getDangerType().getDangerGroup().getTypes();
    00057                 initGUI();
    00058                 WindowManipulator.centerWindow(this);
    00059                 setVisible(true);
    00060         }
    00061
    00065         private void initGUI() {
    00066                 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    00067                 setTitle("Varianta typu nebezpečí");
    00068
    00069                 GridLayout gl = new GridLayout(4, 1);
    00070                 pnlTextFields = new JPanel(gl);
    00071
    00072                 pnlTextFields.add(new JLabel("Popis"));
    00073                 txtDescription = new JTextField(dangerVariant.getDescription(), 50);
    00074                 pnlTextFields.add(txtDescription);
    00075
    00076                 pnlTextFields.add(new JLabel("Typ nebezpečí"));
    00077                 cmbTypes = new JComboBox(new Vector<DangerType>(types));
    00078                 cmbTypes.setSelectedItem(dangerVariant.getDangerType());
    00079                 pnlTextFields.add(cmbTypes);
    00080
    00081                 this.add(pnlTextFields, BorderLayout.CENTER);
    00082
    00083                 pnlButtons = new JPanel(new FlowLayout(FlowLayout.CENTER));
    00084
    00085                 btnOK = new JButton("OK");
    00086                 btnOK.addActionListener(new ActionListener() {
    00087                         @Override
    00088                         public void actionPerformed(ActionEvent e) {
    00089                                 AdminDangerVariantFrame.this.btnOKPerformed();
    00090                         }
    00091                 });
    00092                 pnlButtons.add(btnOK);
    00093
    00094                 btnCancel = new JButton("Zrušit");
    00095                 btnCancel.addActionListener(new ActionListener() {
    00096                         @Override
    00097                         public void actionPerformed(ActionEvent e) {
    00098                                 AdminDangerVariantFrame.this.btnCancelPerformed();
    00099                         }
    00100                 });
    00101                 pnlButtons.add(btnCancel);
    00102
    00103                 this.add(pnlButtons, BorderLayout.SOUTH);
    00104                 pack();
    00105         }
    00106
    00110         protected void btnOKPerformed() {
    00111                 DangerType dt = (DangerType) cmbTypes.getSelectedItem();
    00112                 dangerVariant.setDescription(txtDescription.getText());
    00113                 dangerVariant.setDangerType(dt);
    00114                 dangerVariant.saveToDB(owner.getConnection());
    00115                 owner.refreshTree();
    00116                 dispose();
    00117         }
    00118
    00122         protected void btnCancelPerformed() {
    00123                 dispose();
    00124         }
    00125 }