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

# src/cz/neubauer/tomas/hazardanalysis/viewcontroller/dangeranalysis/CriticalDangerVariantFrame.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.event.ActionEvent;
    00009 import java.awt.event.ActionListener;
    00010 import java.awt.event.MouseAdapter;
    00011 import java.awt.event.MouseEvent;
    00012 import java.util.ArrayList;
    00013
    00014 import javax.swing.JComboBox;
    00015 import javax.swing.JFrame;
    00016 import javax.swing.JScrollPane;
    00017 import javax.swing.JTable;
    00018
    00019 import cz.neubauer.tomas.hazardanalysis.model.dangers.DangerType;
    00020 import cz.neubauer.tomas.hazardanalysis.model.dangers.DangerVariant;
    00021 import cz.neubauer.tomas.hazardanalysis.model.tablemodels.DangerVariantTableModel;
    00022 import cz.neubauer.tomas.hazardanalysis.viewcontroller.windowmanipulator.WindowManipulator;
    00023
    00027 public class CriticalDangerVariantFrame extends JFrame {
    00031         private static final long serialVersionUID = -2009393442557761987L;
    00032
    00033         private JTable tableVariants;
    00034
    00035         private DangerVariantTableModel dangerVariantTableModel;
    00036
    00037         private JComboBox cmbTypes;
    00038
    00039         private ArrayList<DangerType> types;
    00040
    00041         public CriticalDangerVariantFrame(ArrayList<DangerType> types) {
    00042                 this.types = types;
    00043                 initGUI();
    00044                 WindowManipulator.centerWindow(this);
    00045                 refresh(0);
    00046                 setVisible(true);
    00047         }
    00048
    00052         private void initGUI() {
    00053                 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    00054                 setTitle("Volba závažných nebezpečí");
    00055
    00056                 cmbTypes = new JComboBox();
    00057                 int dangerTypeCount = types.size();
    00058                 for (int i = 0; i < dangerTypeCount; i++) {
    00059                         cmbTypes.addItem(types.get(i).getDescription());
    00060                 }
    00061                 cmbTypes.addActionListener(new ActionListener() {
    00062                         @Override
    00063                         public void actionPerformed(ActionEvent e) {
    00064                                 CriticalDangerVariantFrame.this.cmbTypesChanged();
    00065                         }
    00066                 });
    00067                 this.add(cmbTypes, BorderLayout.NORTH);
    00068
    00069                 dangerVariantTableModel = new DangerVariantTableModel(
    00070                                 new ArrayList<DangerVariant>(10));
    00071
    00072                 tableVariants = new JTable(dangerVariantTableModel);
    00073
    00074                 tableVariants.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    00075                 tableVariants.getColumnModel().getColumn(0).setPreferredWidth(400);
    00076                 tableVariants.getColumnModel().getColumn(1).setPreferredWidth(50);
    00077
    00078                 tableVariants.addMouseListener(new MouseAdapter() {
    00079                         @Override
    00080                         public void mouseClicked(MouseEvent e) {
    00081                                 CriticalDangerVariantFrame.this.tableClicked();
    00082                         }
    00083                 });
    00084                 JScrollPane spn = new JScrollPane(tableVariants);
    00085                 spn.setViewportView(tableVariants);
    00086                 spn.setPreferredSize(new Dimension(453, 200));
    00087
    00088                 this.add(spn, BorderLayout.CENTER);
    00089                 pack();
    00090         }
    00091
    00095         protected void tableClicked() {
    00096                 int selectedRow = tableVariants.getSelectedRow();
    00097                 int selectedColumn = tableVariants.getSelectedColumn();
    00098                 if (selectedRow >= 0 && selectedColumn == 1) {
    00099                         DangerVariant currentDangerVariant = dangerVariantTableModel
    00100                                         .getDangerVariants().get(selectedRow);
    00101                         currentDangerVariant
    00102                                         .setCritical(!currentDangerVariant.isCritical());
    00103                         dangerVariantTableModel.fireTableDataChanged();
    00104                 }
    00105         }
    00106
    00110         protected void cmbTypesChanged() {
    00111                 int selectedIndex = cmbTypes.getSelectedIndex();
    00112                 if (selectedIndex >= 0) {
    00113                         refresh(selectedIndex);
    00114                 }
    00115         }
    00116
    00120         private void refresh(int index) {
    00121                 dangerVariantTableModel.setDangerVariants(types.get(index)
    00122                                 .getVariants());
    00123                 dangerVariantTableModel.fireTableDataChanged();
    00124                 this.repaint();
    00125                 // this.tableVariants.setModel(dangerVariantTableModel);
    00126         }
    00127 }