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

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

Zobrazit dokumentaci tohoto souboru.

    00001
    00004 package cz.neubauer.tomas.hazardanalysis.viewcontroller.dangeranalysis;
    00005
    00006 import java.awt.Font;
    00007 import java.awt.GridBagConstraints;
    00008 import java.awt.GridBagLayout;
    00009 import java.awt.Insets;
    00010 import java.awt.event.ActionEvent;
    00011 import java.awt.event.ActionListener;
    00012
    00013 import javax.swing.JComboBox;
    00014 import javax.swing.JLabel;
    00015 import javax.swing.JPanel;
    00016 import javax.swing.SwingConstants;
    00017
    00021 public class DangerCalculatorPanel extends JPanel {
    00022
    00026         private static final long serialVersionUID = -4750827546637595078L;
    00027
    00028         private String dangerDescription;
    00029
    00030         private JLabel lblDescription, lblDangerValue;
    00031
    00032         private JComboBox cmbHealth, cmbDuration, cmbPrevention, cmbProbability;
    00033
    00034         public DangerCalculatorPanel(String description) {
    00035                 dangerDescription = description;
    00036                 initGUI();
    00037         }
    00038
    00042         private void initGUI() {
    00043                 GridBagLayout gbl = new GridBagLayout();
    00044                 setLayout(gbl);
    00045
    00046                 gbl.columnWidths = new int[] { 120, 200, 250, 80 };
    00047                 GridBagConstraints c = new GridBagConstraints();
    00048
    00049                 c.anchor = GridBagConstraints.NORTHWEST;
    00050                 c.fill = GridBagConstraints.BOTH;
    00051                 c.insets = new Insets(0, 6, 0, 6);
    00052
    00053                 c.gridx = 0;
    00054                 c.gridy = 0;
    00055                 c.gridwidth = 1;
    00056                 c.gridheight = 4;
    00057                 lblDescription = new JLabel(
    00058                                 "<html><body style=\"text-align: center;\">"
    00059                                                 + dangerDescription + "</body></html>");
    00060                 lblDescription.setFont(new Font(lblDescription.getFont().getName(),
    00061                                 Font.BOLD, 14));
    00062                 this.add(lblDescription, c);
    00063
    00064                 c.gridx = 1;
    00065                 c.gridy = 0;
    00066                 c.gridheight = 1;
    00067                 this.add(new JLabel("Závažnost možné škody na zdraví:"), c);
    00068
    00069                 c.gridx = 1;
    00070                 c.gridy = 1;
    00071                 c.gridheight = 1;
    00072                 this.add(new JLabel("Četnost a doba trvání ohrožení:"), c);
    00073
    00074                 c.gridx = 1;
    00075                 c.gridy = 2;
    00076                 c.gridheight = 1;
    00077                 this.add(new JLabel("Možnost vyvarování se nebezpečí:"), c);
    00078
    00079                 c.gridx = 1;
    00080                 c.gridy = 3;
    00081                 c.gridheight = 1;
    00082                 this.add(new JLabel("Pst. výskytu nebezpečné události:"), c);
    00083
    00084                 // ---
    00085                 c.gridx = 2;
    00086                 c.gridy = 0;
    00087                 c.gridheight = 1;
    00088                 cmbHealth = new JComboBox();
    00089                 cmbHealth.addActionListener(new ActionListener() {
    00090                         @Override
    00091                         public void actionPerformed(ActionEvent e) {
    00092                                 DangerCalculatorPanel.this.compute();
    00093                         }
    00094                 });
    00095                 cmbHealth.addItem("S0 - žádné nebezpečí");
    00096                 cmbHealth.addItem("S1 - lehké poškození (přechodné následky)");
    00097                 cmbHealth.addItem("S2 - těžké zranění (trvalé následky)");
    00098                 cmbHealth.addItem("S3 - smrt");
    00099                 this.add(cmbHealth, c);
    00100
    00101                 c.gridx = 2;
    00102                 c.gridy = 1;
    00103                 c.gridheight = 1;
    00104                 cmbDuration = new JComboBox();
    00105                 cmbDuration.addActionListener(new ActionListener() {
    00106                         @Override
    00107                         public void actionPerformed(ActionEvent e) {
    00108                                 DangerCalculatorPanel.this.compute();
    00109                         }
    00110                 });
    00111                 cmbDuration.addItem("A1 - zřídka až častěji");
    00112                 cmbDuration.addItem("A2 - často až trvale");
    00113                 this.add(cmbDuration, c);
    00114
    00115                 c.gridx = 2;
    00116                 c.gridy = 2;
    00117                 c.gridheight = 1;
    00118                 cmbPrevention = new JComboBox();
    00119                 cmbPrevention.addItem("E1 - možné");
    00120                 cmbPrevention.addItem("E2 - možné za určitých okolností");
    00121                 cmbPrevention.addItem("E3 - sotva možné");
    00122                 cmbPrevention.addActionListener(new ActionListener() {
    00123                         @Override
    00124                         public void actionPerformed(ActionEvent e) {
    00125                                 DangerCalculatorPanel.this.compute();
    00126                         }
    00127                 });
    00128                 this.add(cmbPrevention, c);
    00129
    00130                 c.gridx = 2;
    00131                 c.gridy = 3;
    00132                 c.gridheight = 1;
    00133                 cmbProbability = new JComboBox();
    00134                 cmbProbability.addItem("W1 - malá");
    00135                 cmbProbability.addItem("W2 - střední");
    00136                 cmbProbability.addItem("W3 - velká");
    00137                 cmbProbability.addActionListener(new ActionListener() {
    00138                         @Override
    00139                         public void actionPerformed(ActionEvent e) {
    00140                                 DangerCalculatorPanel.this.compute();
    00141                         }
    00142                 });
    00143                 this.add(cmbProbability, c);
    00144
    00145                 c.gridx = 3;
    00146                 c.gridy = 0;
    00147                 c.gridheight = 1;
    00148                 this.add(new JLabel("Velikost rizika"));
    00149
    00150                 c.gridx = 3;
    00151                 c.gridy = 1;
    00152                 c.gridheight = 3;
    00153                 lblDangerValue = new JLabel("0");
    00154                 lblDangerValue.setFont(new Font(lblDangerValue.getFont().getName(),
    00155                                 Font.BOLD, 28));
    00156                 lblDangerValue.setHorizontalTextPosition(SwingConstants.CENTER);
    00157                 this.add(lblDangerValue, c);
    00158         }
    00159
    00163         protected void compute() {
    00164                 int s = cmbHealth.getSelectedIndex() - 1;
    00165                 int result = 0;
    00166                 if (s >= 0) {
    00167                         int a = cmbDuration.getSelectedIndex();
    00168                         int e = cmbPrevention.getSelectedIndex();
    00169                         int w = cmbProbability.getSelectedIndex();
    00170                         result = 6 * s + 3 * a + w + e - 1;
    00171                 }
    00172
    00173                 if (lblDangerValue != null) {
    00174                         lblDangerValue.setText(String.valueOf(result >= 0 ? result : 0));
    00175                 }
    00176         }
    00177
    00178         public void setS(int s) {
    00179                 cmbHealth.setSelectedIndex(s);
    00180         }
    00181
    00182         public int getS() {
    00183                 return cmbHealth.getSelectedIndex();
    00184         }
    00185
    00186         public void setA(int a) {
    00187                 cmbDuration.setSelectedIndex(a);
    00188         }
    00189
    00190         public int getA() {
    00191                 return cmbDuration.getSelectedIndex();
    00192         }
    00193
    00194         public void setE(int e) {
    00195                 cmbPrevention.setSelectedIndex(e);
    00196         }
    00197
    00198         public int getE() {
    00199                 return cmbPrevention.getSelectedIndex();
    00200         }
    00201
    00202         public void setW(int w) {
    00203                 cmbProbability.setSelectedIndex(w);
    00204         }
    00205
    00206         public int getW() {
    00207                 return cmbProbability.getSelectedIndex();
    00208         }
    00209
    00210         public String getCurrentS() {
    00211                 return cmbHealth.getSelectedItem().toString();
    00212         }
    00213
    00214         public String getCurrentA() {
    00215                 return cmbDuration.getSelectedItem().toString();
    00216         }
    00217
    00218         public String getCurrentE() {
    00219                 return cmbPrevention.getSelectedItem().toString();
    00220         }
    00221
    00222         public String getCurrentW() {
    00223                 return cmbProbability.getSelectedItem().toString();
    00224         }
    00225
    00226         public String getCurrentDangerLevel() {
    00227                 return lblDangerValue.getText();
    00228         }
    00229 }