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

# src/cz/neubauer/tomas/hazardanalysis/viewcontroller/dangeranalysis/PhaseDangerVariantFrame.java

Zobrazit dokumentaci tohoto souboru.

    00001
    00004 package cz.neubauer.tomas.hazardanalysis.viewcontroller.dangeranalysis;
    00005
    00006 import java.awt.BorderLayout;
    00007 import java.awt.Dimension;
    00008 import java.awt.GridLayout;
    00009 import java.awt.event.MouseAdapter;
    00010 import java.awt.event.MouseEvent;
    00011 import java.awt.event.WindowEvent;
    00012 import java.awt.event.WindowListener;
    00013 import java.util.ArrayList;
    00014
    00015 import javax.swing.JFrame;
    00016 import javax.swing.JLabel;
    00017 import javax.swing.JPanel;
    00018 import javax.swing.JScrollPane;
    00019 import javax.swing.JTable;
    00020 import javax.swing.JTextField;
    00021
    00022 import cz.neubauer.tomas.hazardanalysis.model.dangers.DangerVariant;
    00023 import cz.neubauer.tomas.hazardanalysis.model.stages.Phase;
    00024 import cz.neubauer.tomas.hazardanalysis.model.tablemodels.PhaseDangerVariantTableModel;
    00025 import cz.neubauer.tomas.hazardanalysis.viewcontroller.windowmanipulator.WindowManipulator;
    00026
    00030 public class PhaseDangerVariantFrame extends JFrame {
    00034         private static final long serialVersionUID = -2009393442557761987L;
    00035
    00036         private StagePanel owner;
    00037
    00038         private JPanel pnlForm, pnlTable;
    00039
    00040         private JTextField txtPhaseName;
    00041
    00042         private JTable tableVariants;
    00043
    00044         private PhaseDangerVariantTableModel phaseDangerVariantTableModel;
    00045
    00046         private ArrayList<DangerVariant> criticalDangerVariants;
    00047
    00048         private Phase phase;
    00049
    00050         public PhaseDangerVariantFrame(StagePanel owner, Phase phase,
    00051                         ArrayList<DangerVariant> criticalDangerVariants) {
    00052                 this.owner = owner;
    00053                 this.phase = phase;
    00054                 this.criticalDangerVariants = criticalDangerVariants;
    00055                 initGUI();
    00056         }
    00057
    00061         private void initGUI() {
    00062                 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    00063                 setTitle("Přiřazení nebezpečí fázi");
    00064
    00065                 initPanelTable();
    00066                 this.add(pnlTable, BorderLayout.CENTER);
    00067
    00068                 initPanelForm();
    00069                 this.add(pnlForm, BorderLayout.NORTH);
    00070
    00071                 addWindowListener(new WindowListener() {
    00072
    00073                         @Override
    00074                         public void windowOpened(WindowEvent e) {
    00075                                 // nop
    00076                         }
    00077
    00078                         @Override
    00079                         public void windowIconified(WindowEvent e) {
    00080                                 // nop
    00081                         }
    00082
    00083                         @Override
    00084                         public void windowDeiconified(WindowEvent e) {
    00085                                 // nop
    00086                         }
    00087
    00088                         @Override
    00089                         public void windowDeactivated(WindowEvent e) {
    00090                                 // nop
    00091                         }
    00092
    00093                         @Override
    00094                         public void windowClosing(WindowEvent e) {
    00095                                 // nop
    00096                         }
    00097
    00098                         @Override
    00099                         public void windowClosed(WindowEvent e) {
    00100                                 phase.setName(txtPhaseName.getText());
    00101                                 owner.refresh();
    00102                         }
    00103
    00104                         @Override
    00105                         public void windowActivated(WindowEvent e) {
    00106                                 // nop
    00107                         }
    00108                 });
    00109
    00110                 pack();
    00111                 WindowManipulator.centerWindow(this);
    00112                 setVisible(true);
    00113         }
    00114
    00118         private void initPanelForm() {
    00119                 pnlForm = new JPanel(new GridLayout(2, 1));
    00120
    00121                 pnlForm.add(new JLabel("Název fáze"));
    00122
    00123                 txtPhaseName = new JTextField(phase.getName(), 10);
    00124                 pnlForm.add(txtPhaseName);
    00125         }
    00126
    00130         private void initPanelTable() {
    00131                 pnlTable = new JPanel();
    00132                 phaseDangerVariantTableModel = new PhaseDangerVariantTableModel(phase,
    00133                                 criticalDangerVariants);
    00134
    00135                 tableVariants = new JTable(phaseDangerVariantTableModel);
    00136
    00137                 tableVariants.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    00138                 tableVariants.getColumnModel().getColumn(0).setPreferredWidth(400);
    00139                 tableVariants.getColumnModel().getColumn(1).setPreferredWidth(50);
    00140
    00141                 tableVariants.addMouseListener(new MouseAdapter() {
    00142                         @Override
    00143                         public void mouseClicked(MouseEvent e) {
    00144                                 PhaseDangerVariantFrame.this.tableClicked();
    00145                         }
    00146                 });
    00147                 JScrollPane spn = new JScrollPane(tableVariants);
    00148                 spn.setViewportView(tableVariants);
    00149                 spn.setPreferredSize(new Dimension(453, 200));
    00150
    00151                 pnlTable.add(spn, BorderLayout.CENTER);
    00152         }
    00153
    00157         protected void tableClicked() {
    00158                 int selectedRowIndex = tableVariants.getSelectedRow();
    00159                 int selectedColumnIndex = tableVariants.getSelectedColumn();
    00160                 if (selectedColumnIndex == 1 && selectedRowIndex >= 0) {
    00161                         DangerVariant selectedVariant = criticalDangerVariants
    00162                                         .get(selectedRowIndex);
    00163                         PhaseDangerVariantTableModel phaseDangerVariantTableModel = (PhaseDangerVariantTableModel) tableVariants
    00164                                         .getModel();
    00165
    00166                         if ((Boolean) (phaseDangerVariantTableModel).getValueAt(
    00167                                         selectedRowIndex, selectedColumnIndex)) {
    00168                                 // je vybrano ... varianta patri do faze
    00169                                 phase.getVariants().remove(selectedVariant);
    00170                         } else {
    00171                                 // neni vybrana
    00172                                 phase.addDangerVariant(selectedVariant);
    00173                         }
    00174
    00175                         phaseDangerVariantTableModel.fireTableDataChanged();
    00176
    00177                 }
    00178         }
    00179 }