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

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

Zobrazit dokumentaci tohoto souboru.

    00001
    00004 package cz.neubauer.tomas.hazardanalysis.viewcontroller.dangeranalysis;
    00005
    00006 import java.awt.BorderLayout;
    00007 import java.awt.Color;
    00008 import java.awt.Dimension;
    00009 import java.awt.FlowLayout;
    00010 import java.awt.GridBagConstraints;
    00011 import java.awt.GridBagLayout;
    00012 import java.awt.Insets;
    00013 import java.awt.event.ActionEvent;
    00014 import java.awt.event.ActionListener;
    00015 import java.io.BufferedWriter;
    00016 import java.io.File;
    00017 import java.io.FileWriter;
    00018 import java.io.IOException;
    00019 import java.util.ArrayList;
    00020
    00021 import javax.swing.BorderFactory;
    00022 import javax.swing.JButton;
    00023 import javax.swing.JComboBox;
    00024 import javax.swing.JFrame;
    00025 import javax.swing.JLabel;
    00026 import javax.swing.JOptionPane;
    00027 import javax.swing.JPanel;
    00028 import javax.swing.JScrollPane;
    00029 import javax.swing.JTextArea;
    00030 import javax.swing.JTextField;
    00031
    00032 import cz.neubauer.tomas.hazardanalysis.Rizika;
    00033 import cz.neubauer.tomas.hazardanalysis.model.dangers.DangerEstimationBacking;
    00034 import cz.neubauer.tomas.hazardanalysis.model.dangers.DangerVariant;
    00035 import cz.neubauer.tomas.hazardanalysis.model.stages.VariantStage;
    00036
    00041 public class DangerEstimationFrame extends JFrame {
    00042
    00046         private static final long serialVersionUID = 5956510294800607915L;
    00047
    00048         private Rizika application;
    00049
    00050         private CriticalDangerAnalysisFrame owner;
    00051
    00052         private ArrayList<DangerEstimationBacking> dangerData;
    00053
    00054         private JScrollPane scrollPane;
    00055
    00056         private JPanel pnlMain;
    00057
    00058         private StepPanel stpStep1, stpStep2, stpStep3;
    00059
    00060         private DangerCalculatorPanel cpnPocatecniRiziko;
    00061
    00062         private JPanel pnlVariant;
    00063
    00064         private JComboBox cmbVariant;
    00065
    00066         private JPanel pnlHeader;
    00067
    00068         private JTextField txtDangerNumber, txtDangerID, txtDangerGroup,
    00069                         txtDangerType;
    00070
    00071         private JPanel pnlDescription;
    00072
    00073         private JPanel pnlPersons;
    00074
    00075         private JButton btnPersonSelection;
    00076
    00077         private JTextField txtStage, txtDangerArea, txtPersons;
    00078
    00079         private JComboBox cmbState;
    00080
    00081         private JTextField txtDangerVariant;
    00082
    00083         private JTextArea txaDangerEventDescription;
    00084
    00085         private JPanel pnlButton;
    00086
    00087         private JButton btnSave;
    00088
    00089         private PersonSelectionFrame personSelectionFrame;
    00090
    00091         public DangerEstimationFrame(Rizika application,
    00092                         CriticalDangerAnalysisFrame owner,
    00093                         ArrayList<VariantStage> variantStages) {
    00094                 this.owner = owner;
    00095                 this.application = application;
    00096                 dangerData = new ArrayList<DangerEstimationBacking>(variantStages
    00097                                 .size());
    00098                 setVariantStagesData(variantStages);
    00099                 initGUI();
    00100         }
    00101
    00106         public void setVariantStagesData(ArrayList<VariantStage> variantStages) {
    00107                 dangerData.clear();
    00108                 for (int i = 0; i < variantStages.size(); i++) {
    00109                         DangerEstimationBacking deb = new DangerEstimationBacking(
    00110                                         application);
    00111                         deb.setVariantStage(variantStages.get(i));
    00112                         dangerData.add(deb);
    00113                 }
    00114         }
    00115
    00119         private void initGUI() {
    00120                 setTitle("Formulář pro odhad rizika");
    00121                 setDefaultCloseOperation(HIDE_ON_CLOSE);
    00122                 GridBagLayout gbl = new GridBagLayout();
    00123                 pnlMain = new JPanel(gbl);
    00124
    00125                 gbl.rowHeights = new int[] { 14, 50, 75, 123, 123, 123 };
    00126
    00127                 GridBagConstraints c = new GridBagConstraints();
    00128                 c.anchor = GridBagConstraints.NORTHWEST;
    00129                 c.fill = GridBagConstraints.BOTH;
    00130                 c.insets = new Insets(2, 6, 2, 6);
    00131                 c.gridx = 0;
    00132                 c.gridy = 0;
    00133                 c.gridwidth = 1;
    00134                 c.gridheight = 1;
    00135
    00136                 scrollPane = new JScrollPane(pnlMain);
    00137
    00138                 initVariantPanel();
    00139                 pnlMain.add(pnlVariant, c);
    00140                 c.gridy++;
    00141
    00142                 initHeaderPanel();
    00143                 pnlMain.add(pnlHeader, c);
    00144                 c.gridy++;
    00145
    00146                 initDescriptionPanel();
    00147                 pnlMain.add(pnlDescription, c);
    00148                 c.gridy++;
    00149
    00150                 initPocatecniPanel();
    00151                 pnlMain.add(cpnPocatecniRiziko, c);
    00152                 c.gridy++;
    00153
    00154                 initStep1Panel();
    00155                 pnlMain.add(stpStep1, c);
    00156                 c.gridy++;
    00157
    00158                 initStep2Panel();
    00159                 pnlMain.add(stpStep2, c);
    00160                 c.gridy++;
    00161
    00162                 initStep3Panel();
    00163                 pnlMain.add(stpStep3, c);
    00164                 c.gridy++;
    00165
    00166                 initButtonPanel();
    00167                 pnlMain.add(pnlButton, c);
    00168                 c.gridy++;
    00169
    00170                 scrollPane.setPreferredSize(new Dimension(800, 500));
    00171
    00172                 this.add(scrollPane);
    00173
    00174                 pack();
    00175                 setVisible(true);
    00176                 cmbVariantChanged();
    00177         }
    00178
    00182         private void initButtonPanel() {
    00183                 pnlButton = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    00184
    00185                 btnSave = new JButton("uložit");
    00186                 btnSave.addActionListener(new ActionListener() {
    00187                         @Override
    00188                         public void actionPerformed(ActionEvent e) {
    00189                                 DangerEstimationFrame.this.btnSavePerformed();
    00190                         }
    00191                 });
    00192                 pnlButton.add(btnSave);
    00193
    00194         }
    00195
    00199         protected void btnSavePerformed() {
    00200                 DangerEstimationBacking deb = (DangerEstimationBacking) cmbVariant
    00201                                 .getSelectedItem();
    00202
    00203                 int[] step0 = new int[] { cpnPocatecniRiziko.getS(),
    00204                                 cpnPocatecniRiziko.getA(), cpnPocatecniRiziko.getE(),
    00205                                 cpnPocatecniRiziko.getW() };
    00206                 deb.setStep0(step0);
    00207
    00208                 deb.setCounterAct1(stpStep1.getCounterActDescription());
    00209                 int[] step1 = new int[] { stpStep1.getS(), stpStep1.getA(),
    00210                                 stpStep1.getE(), stpStep1.getW() };
    00211                 deb.setStep1(step1);
    00212
    00213                 deb.setCounterAct2(stpStep2.getCounterActDescription());
    00214                 int[] step2 = new int[] { stpStep2.getS(), stpStep2.getA(),
    00215                                 stpStep2.getE(), stpStep2.getW() };
    00216                 deb.setStep2(step2);
    00217
    00218                 deb.setCounterAct3(stpStep3.getCounterActDescription());
    00219                 int[] step3 = new int[] { stpStep3.getS(), stpStep3.getA(),
    00220                                 stpStep3.getE(), stpStep3.getW() };
    00221                 deb.setStep3(step3);
    00222
    00223                 deb.setDangerArea(txtDangerArea.getText());
    00224                 deb.setDangerEventDescription(txaDangerEventDescription.getText());
    00225                 deb.setPersons(txtPersons.getText());
    00226                 deb.setState(cmbState.getSelectedIndex());
    00227
    00228                 deb.saveHistory();
    00229
    00230                 JOptionPane.showMessageDialog(this, "Aktuální formulář byl uložen");
    00231
    00232         }
    00233
    00237         private void initVariantPanel() {
    00238                 pnlVariant = new JPanel();
    00239
    00240                 cmbVariant = new JComboBox();
    00241                 for (int i = 0; i < dangerData.size(); i++) {
    00242                         cmbVariant.addItem(dangerData.get(i));
    00243                 }
    00244                 cmbVariant.addActionListener(new ActionListener() {
    00245                         @Override
    00246                         public void actionPerformed(ActionEvent e) {
    00247                                 DangerEstimationFrame.this.cmbVariantChanged();
    00248
    00249                         }
    00250                 });
    00251
    00252                 pnlVariant.add(cmbVariant);
    00253         }
    00254
    00258         protected void cmbVariantChanged() {
    00259                 DangerEstimationBacking deb = (DangerEstimationBacking) cmbVariant
    00260                                 .getSelectedItem();
    00261
    00262                 DangerVariant dv = deb.getVariantStage().getDangerVariant();
    00263                 txtDangerNumber.setText(dv.getDangerType().getCode());
    00264
    00265                 ArrayList<DangerVariant> criticalVariants = owner.getCriticalVarians();
    00266
    00267                 int index = 0;
    00268                 DangerVariant currentDV;
    00269                 for (int i = 0; i < criticalVariants.size(); i++) {
    00270                         currentDV = criticalVariants.get(i);
    00271                         if (currentDV.getDangerType().equals(
    00272                                         deb.getVariantStage().getDangerVariant().getDangerType())) {
    00273                                 index++;
    00274                         }
    00275                         if (currentDV.equals(deb.getVariantStage().getDangerVariant())) {
    00276                                 break;
    00277                         }
    00278                 }
    00279
    00280                 txtDangerID.setText(String.valueOf(index));
    00281                 txtDangerGroup.setText(dv.getDangerType().getDangerGroup().getName());
    00282                 txtDangerType.setText(dv.getDangerType().getDescription());
    00283                 txtStage.setText(deb.getVariantStage().getStage().getDescription());
    00284                 txtDangerVariant.setText(dv.getDescription());
    00285                 txtPersons.setText(deb.getPersons());
    00286                 txtDangerArea.setText(deb.getDangerArea());
    00287                 cmbState.setSelectedIndex(deb.getState());
    00288
    00289                 txaDangerEventDescription.setText(deb.getDangerEventDescription());
    00290
    00291                 cpnPocatecniRiziko.setS(deb.getStep0()[0]);
    00292                 cpnPocatecniRiziko.setA(deb.getStep0()[1]);
    00293                 cpnPocatecniRiziko.setE(deb.getStep0()[2]);
    00294                 cpnPocatecniRiziko.setW(deb.getStep0()[3]);
    00295
    00296                 stpStep1.setCounterActDescription(deb.getCounterAct1());
    00297                 stpStep1.setS(deb.getStep1()[0]);
    00298                 stpStep1.setA(deb.getStep1()[1]);
    00299                 stpStep1.setE(deb.getStep1()[2]);
    00300                 stpStep1.setW(deb.getStep1()[3]);
    00301
    00302                 stpStep2.setCounterActDescription(deb.getCounterAct2());
    00303                 stpStep2.setS(deb.getStep2()[0]);
    00304                 stpStep2.setA(deb.getStep2()[1]);
    00305                 stpStep2.setE(deb.getStep2()[2]);
    00306                 stpStep2.setW(deb.getStep2()[3]);
    00307
    00308                 stpStep3.setCounterActDescription(deb.getCounterAct3());
    00309                 stpStep3.setS(deb.getStep3()[0]);
    00310                 stpStep3.setA(deb.getStep3()[1]);
    00311                 stpStep3.setE(deb.getStep3()[2]);
    00312                 stpStep3.setW(deb.getStep3()[3]);
    00313
    00314         }
    00315
    00319         private void initHeaderPanel() {
    00320                 GridBagLayout gbl = new GridBagLayout();
    00321                 gbl.columnWidths = new int[] { 80, 20, 80, 195 };
    00322                 gbl.rowHeights = new int[] { 13, 13 };
    00323                 pnlHeader = new JPanel(gbl);
    00324                 GridBagConstraints c = new GridBagConstraints();
    00325                 c.anchor = GridBagConstraints.NORTHWEST;
    00326                 c.fill = GridBagConstraints.BOTH;
    00327                 c.insets = new Insets(2, 6, 2, 6);
    00328                 c.gridwidth = 1;
    00329                 c.gridheight = 1;
    00330
    00331                 c.gridx = 0;
    00332                 c.gridy = 0;
    00333                 pnlHeader.add(new JLabel("Číslo nebezpečí dle ČSN EN 1050:"), c);
    00334
    00335                 txtDangerNumber = new JTextField();
    00336                 txtDangerNumber.setEditable(false);
    00337                 c.gridx = 0;
    00338                 c.gridy = 1;
    00339                 pnlHeader.add(txtDangerNumber, c);
    00340
    00341                 c.gridx = 1;
    00342                 c.gridy = 0;
    00343                 pnlHeader.add(new JLabel("Identif. číslo:"), c);
    00344
    00345                 txtDangerID = new JTextField();
    00346                 txtDangerID.setEditable(false);
    00347                 c.gridx = 1;
    00348                 c.gridy = 1;
    00349                 pnlHeader.add(txtDangerID, c);
    00350
    00351                 c.gridx = 2;
    00352                 c.gridy = 0;
    00353                 pnlHeader.add(new JLabel("Označení nebezpečí dle ČSN EN 1050:"), c);
    00354
    00355                 txtDangerGroup = new JTextField();
    00356                 txtDangerGroup.setEditable(false);
    00357                 c.gridx = 3;
    00358                 c.gridy = 0;
    00359                 pnlHeader.add(txtDangerGroup, c);
    00360
    00361                 txtDangerType = new JTextField();
    00362                 txtDangerType.setEditable(false);
    00363                 c.gridx = 2;
    00364                 c.gridy = 1;
    00365                 c.gridwidth = 2;
    00366                 pnlHeader.add(txtDangerType, c);
    00367
    00368                 pnlHeader.setBorder(BorderFactory.createLineBorder(Color.black, 1));
    00369
    00370         }
    00371
    00375         private void initDescriptionPanel() {
    00376                 GridBagLayout gbl = new GridBagLayout();
    00377                 gbl.columnWidths = new int[] { 80, 180, 80, 180 };
    00378                 gbl.rowHeights = new int[] { 13, 13, 13, 50 };
    00379                 pnlDescription = new JPanel(gbl);
    00380                 GridBagConstraints c = new GridBagConstraints();
    00381                 c.anchor = GridBagConstraints.NORTHWEST;
    00382                 c.fill = GridBagConstraints.BOTH;
    00383                 c.insets = new Insets(2, 6, 2, 6);
    00384
    00385                 c.gridx = 0;
    00386                 c.gridy = 0;
    00387                 c.gridwidth = 1;
    00388                 c.gridheight = 1;
    00389                 pnlDescription.add(new JLabel("Životní etapa stroje:"), c);
    00390
    00391                 txtStage = new JTextField();
    00392                 txtStage.setEditable(false);
    00393                 c.gridx = 1;
    00394                 c.gridy = 0;
    00395                 pnlDescription.add(txtStage, c);
    00396
    00397                 c.gridx = 2;
    00398                 c.gridy = 0;
    00399                 pnlDescription.add(new JLabel("Nebezpečný prostor:"), c);
    00400
    00401                 txtDangerArea = new JTextField();
    00402                 c.gridx = 3;
    00403                 c.gridy = 0;
    00404                 pnlDescription.add(txtDangerArea, c);
    00405
    00406                 c.gridx = 0;
    00407                 c.gridy = 1;
    00408                 pnlDescription.add(new JLabel("Ohrožené osoby:"), c);
    00409
    00410                 pnlPersons = new JPanel(new BorderLayout());
    00411                 txtPersons = new JTextField();
    00412                 txtPersons.setEditable(false);
    00413                 btnPersonSelection = new JButton("...");
    00414                 btnPersonSelection.addActionListener(new ActionListener() {
    00415                         @Override
    00416                         public void actionPerformed(ActionEvent e) {
    00417                                 DangerEstimationFrame.this.btnPersonSelectionPerformed();
    00418                         }
    00419                 });
    00420                 c.gridx = 1;
    00421                 c.gridy = 1;
    00422                 pnlPersons.add(txtPersons, BorderLayout.CENTER);
    00423                 pnlPersons.add(btnPersonSelection, BorderLayout.EAST);
    00424                 pnlDescription.add(pnlPersons, c);
    00425
    00426                 c.gridx = 2;
    00427                 c.gridy = 1;
    00428                 pnlDescription.add(new JLabel("Provozní stav stroje:"), c);
    00429
    00430                 cmbState = new JComboBox();
    00431                 cmbState.addItem("normální provoz");
    00432                 cmbState.addItem("selhání stroje");
    00433                 cmbState.addItem("nepředpokládané chování obsluhy");
    00434                 cmbState.addItem("neoprávněný zásah třetí osoby");
    00435                 cmbState.addItem("stroj mimo provoz");
    00436                 cmbState.setSelectedIndex(0);
    00437
    00438                 c.gridx = 3;
    00439                 c.gridy = 1;
    00440                 pnlDescription.add(cmbState, c);
    00441
    00442                 c.gridx = 0;
    00443                 c.gridy = 2;
    00444                 pnlDescription
    00445                                 .add(
    00446                                                 new JLabel(
    00447                                                                 "<html><body>Popis nebezpečné situace/události:</body></html>"),
    00448                                                 c);
    00449
    00450                 txtDangerVariant = new JTextField();
    00451                 txtDangerVariant.setEditable(false);
    00452                 c.gridx = 1;
    00453                 c.gridy = 2;
    00454                 c.gridwidth = 3;
    00455                 c.gridheight = 1;
    00456                 pnlDescription.add(txtDangerVariant, c);
    00457
    00458                 txaDangerEventDescription = new JTextArea();
    00459                 JScrollPane scroll = new JScrollPane(txaDangerEventDescription);
    00460                 scroll.setViewportView(txaDangerEventDescription);
    00461                 c.gridx = 1;
    00462                 c.gridy = 3;
    00463                 c.gridwidth = 3;
    00464                 c.gridheight = 1;
    00465                 pnlDescription.add(scroll, c);
    00466
    00467                 pnlDescription
    00468                                 .setBorder(BorderFactory.createLineBorder(Color.black, 1));
    00469
    00470         }
    00471
    00475         protected void btnPersonSelectionPerformed() {
    00476                 if (personSelectionFrame == null) {
    00477                         personSelectionFrame = new PersonSelectionFrame(this);
    00478                 }
    00479
    00480                 personSelectionFrame.setVisible(true);
    00481         }
    00482
    00486         private void initStep3Panel() {
    00487                 stpStep3 = new StepPanel(3,
    00488                                 "Informace pro používání (dle ČSN EN ISO 12100-1:2004)",
    00489                                 "Zbytkové riziko");
    00490         }
    00491
    00495         private void initStep2Panel() {
    00496                 stpStep2 = new StepPanel(
    00497                                 2,
    00498                                 "Bezpečnostní ochrana a doplňková ochranná opatření (dle ČSN EN ISO 12100-1:2004)",
    00499                                 "Snížené riziko po opatření");
    00500         }
    00501
    00505         private void initStep1Panel() {
    00506                 stpStep1 = new StepPanel(
    00507                                 1,
    00508                                 "Opatření zabudovaná v konstrukci (dle ČSN EN ISO 12100-1:2004)",
    00509                                 "Snížené riziko po opatření");
    00510         }
    00511
    00515         private void initPocatecniPanel() {
    00516                 cpnPocatecniRiziko = new DangerCalculatorPanel("Počáteční riziko");
    00517                 cpnPocatecniRiziko.setBorder(BorderFactory.createLineBorder(
    00518                                 Color.black, 1));
    00519         }
    00520
    00521         protected void setPersons(String text) {
    00522                 txtPersons.setText(text);
    00523         }
    00524
    00525         public ArrayList<DangerEstimationBacking> getDangerData() {
    00526                 return dangerData;
    00527         }
    00528
    00529         public void setDangerData(ArrayList<DangerEstimationBacking> dangerData) {
    00530                 this.dangerData = dangerData;
    00531         }
    00532
    00533         public void export(String filePrefix) {
    00534                 try {
    00535                         BufferedWriter bw = null;
    00536                         for (int i = 0; i < dangerData.size(); i++) {
    00537                                 DangerEstimationBacking deb = dangerData.get(i);
    00538                                 cmbVariant.setSelectedIndex(i);
    00539                                 bw = new BufferedWriter(new FileWriter(new File(filePrefix
    00540                                                 + "-"
    00541                                                 + deb.getVariantStage().getStage().getDescription()
    00542                                                 + "-"
    00543                                                 + deb.getVariantStage().getDangerVariant()
    00544                                                                 .getDangerType().getCode() + "-"
    00545                                                 + txtDangerID.getText() + ".txt")));
    00546
    00547                                 bw.write(txtDangerNumber.getText() + "\n");
    00548                                 bw.write(txtDangerID.getText() + "\n");
    00549                                 bw.write(txtDangerGroup.getText() + "\n");
    00550                                 bw.write(txtDangerType.getText() + "\n");
    00551                                 bw.write(deb.getVariantStage().getStage().getDescription()
    00552                                                 + "\n");
    00553                                 bw.write(txtPersons.getText() + "\n");
    00554                                 bw.write(txtDangerArea.getText() + "\n");
    00555                                 bw.write(cmbState.getSelectedItem() + "\n");
    00556                                 bw.write(deb.getVariantStage().getDangerVariant()
    00557                                                 .getDescription()
    00558                                                 + "\n");
    00559                                 bw.write(txaDangerEventDescription.getText() + "\n");
    00560                                 bw.write(cpnPocatecniRiziko.getCurrentS() + "\n");
    00561                                 bw.write(cpnPocatecniRiziko.getCurrentA() + "\n");
    00562                                 bw.write(cpnPocatecniRiziko.getCurrentE() + "\n");
    00563                                 bw.write(cpnPocatecniRiziko.getCurrentW() + "\n");
    00564                                 bw.write(cpnPocatecniRiziko.getCurrentDangerLevel() + "\n");
    00565
    00566                                 bw.write(stpStep1.getCounterActDescription() + "\n");
    00567                                 bw.write(stpStep1.getCurrentS() + "\n");
    00568                                 bw.write(stpStep1.getCurrentA() + "\n");
    00569                                 bw.write(stpStep1.getCurrentE() + "\n");
    00570                                 bw.write(stpStep1.getCurrentW() + "\n");
    00571                                 bw.write(stpStep1.getCurrentDangerLevel() + "\n");
    00572
    00573                                 bw.write(stpStep2.getCounterActDescription() + "\n");
    00574                                 bw.write(stpStep2.getCurrentS() + "\n");
    00575                                 bw.write(stpStep2.getCurrentA() + "\n");
    00576                                 bw.write(stpStep2.getCurrentE() + "\n");
    00577                                 bw.write(stpStep2.getCurrentW() + "\n");
    00578                                 bw.write(stpStep2.getCurrentDangerLevel() + "\n");
    00579
    00580                                 bw.write(stpStep3.getCounterActDescription() + "\n");
    00581                                 bw.write(stpStep3.getCurrentS() + "\n");
    00582                                 bw.write(stpStep3.getCurrentA() + "\n");
    00583                                 bw.write(stpStep3.getCurrentE() + "\n");
    00584                                 bw.write(stpStep3.getCurrentW() + "\n");
    00585                                 bw.write(stpStep3.getCurrentDangerLevel() + "\n");
    00586
    00587                                 bw.close();
    00588                         }
    00589                 } catch (IOException e) {
    00590                         e.printStackTrace();
    00591                 }
    00592         }
    00593 }