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

# src/cz/neubauer/tomas/hazardanalysis/viewcontroller/MainFrame.java

Zobrazit dokumentaci tohoto souboru.

    00001
    00004 package cz.neubauer.tomas.hazardanalysis.viewcontroller;
    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.JFileChooser;
    00015 import javax.swing.JFrame;
    00016 import javax.swing.JMenu;
    00017 import javax.swing.JMenuBar;
    00018 import javax.swing.JMenuItem;
    00019 import javax.swing.JOptionPane;
    00020 import javax.swing.JPanel;
    00021 import javax.swing.JScrollPane;
    00022 import javax.swing.JTable;
    00023
    00024 import cz.neubauer.tomas.hazardanalysis.Rizika;
    00025 import cz.neubauer.tomas.hazardanalysis.model.analysis.Analysis;
    00026 import cz.neubauer.tomas.hazardanalysis.model.analysis.AnalysisRecord;
    00027 import cz.neubauer.tomas.hazardanalysis.model.components.Component;
    00028 import cz.neubauer.tomas.hazardanalysis.model.dangers.DangerType;
    00029 import cz.neubauer.tomas.hazardanalysis.model.tablemodels.AnalysisTableModel;
    00030 import cz.neubauer.tomas.hazardanalysis.viewcontroller.administration.AdminFrame;
    00031 import cz.neubauer.tomas.hazardanalysis.viewcontroller.dangeranalysis.CriticalDangerAnalysisFrame;
    00032 import cz.neubauer.tomas.hazardanalysis.viewcontroller.dangeranalysis.CriticalDangerVariantFrame;
    00033 import cz.neubauer.tomas.hazardanalysis.viewcontroller.windowmanipulator.WindowManipulator;
    00034
    00038 public class MainFrame extends JFrame {
    00042         private static final long serialVersionUID = 2029345932298186842L;
    00043
    00044         private Rizika application;
    00045
    00046         private JMenuBar menuBar;
    00047
    00048         private JMenu mnuFile;
    00049
    00050         private JMenuItem mniSave, mniLoadDiagramXML;
    00051
    00052         private JMenu mnuOptions;
    00053
    00054         private JMenuItem mniShowAdmin;
    00055
    00056         private JMenuItem mniShowCriticalAnalysis;
    00057
    00058         private JPanel pnlTable;
    00059
    00060         private JTable table;
    00061
    00062         private AnalysisTableModel analysisTableModel;
    00063
    00064         private String currentXMLFile;
    00065
    00066         private AdminFrame adminFrame;
    00067
    00068         public MainFrame(Rizika application) {
    00069                 this.application = application;
    00070                 initGUI();
    00071
    00072                 adminFrame = new AdminFrame(this);
    00073         }
    00074
    00075         private void initGUI() {
    00076                 setDefaultCloseOperation(EXIT_ON_CLOSE);
    00077                 setTitle("Rizika");
    00078
    00079                 initMenu();
    00080                 initTablePanel();
    00081                 // ---------- nechat zakomentované!!! -------------
    00082                 // initEditPanel();
    00083
    00084                 pack();
    00085                 WindowManipulator.centerWindow(this);
    00086                 setResizable(false);
    00087                 setVisible(true);
    00088         }
    00089
    00093         private void initTablePanel() {
    00094                 analysisTableModel = new AnalysisTableModel();
    00095                 table = new JTable(analysisTableModel);
    00096                 // ---------- nechat zakomentované!!! -------------
    00097                 table.addMouseListener(new MouseAdapter() {
    00098                         @Override
    00099                         public void mouseClicked(MouseEvent e) {
    00100                                 MainFrame.this.tableClicked();
    00101                         }
    00102                 });
    00103
    00104                 JScrollPane jsp = new JScrollPane(table);
    00105                 jsp.setViewportView(table);
    00106                 jsp.setPreferredSize(new Dimension(500, 300));
    00107
    00108                 pnlTable = new JPanel();
    00109                 pnlTable.add(jsp);
    00110
    00111                 this.add(pnlTable, BorderLayout.CENTER);
    00112         }
    00113
    00117         private void initMenu() {
    00118                 menuBar = new JMenuBar();
    00119                 setJMenuBar(menuBar);
    00120
    00121                 mnuFile = new JMenu("Soubor");
    00122                 menuBar.add(mnuFile);
    00123
    00124                 mnuOptions = new JMenu("Možnosti");
    00125                 menuBar.add(mnuOptions);
    00126
    00127                 mniLoadDiagramXML = new JMenuItem("Načíst XML");
    00128                 mniLoadDiagramXML.addActionListener(new ActionListener() {
    00129                         @Override
    00130                         public void actionPerformed(ActionEvent e) {
    00131                                 MainFrame.this.mniLoadDiagramXMLPerformed();
    00132                         }
    00133                 });
    00134                 mnuFile.add(mniLoadDiagramXML);
    00135
    00136                 mnuFile.addSeparator();
    00137
    00138                 mniSave = new JMenuItem("Exportovat");
    00139                 mniSave.addActionListener(new ActionListener() {
    00140                         @Override
    00141                         public void actionPerformed(ActionEvent e) {
    00142                                 MainFrame.this.mniSavePerformed();
    00143                         }
    00144                 });
    00145                 mnuFile.add(mniSave);
    00146
    00147                 mniShowAdmin = new JMenuItem("Administrace");
    00148                 mniShowAdmin.addActionListener(new ActionListener() {
    00149                         @Override
    00150                         public void actionPerformed(ActionEvent e) {
    00151                                 MainFrame.this.mniShowAdminPerformed();
    00152                         }
    00153
    00154                 });
    00155                 mnuOptions.add(mniShowAdmin);
    00156
    00157                 mniShowCriticalAnalysis = new JMenuItem("Analýza významných nebezpečí");
    00158                 mniShowCriticalAnalysis.addActionListener(new ActionListener() {
    00159                         @Override
    00160                         public void actionPerformed(ActionEvent e) {
    00161                                 MainFrame.this.mniShowCriticalAnalysisPerformed();
    00162                         }
    00163                 });
    00164                 mnuOptions.add(mniShowCriticalAnalysis);
    00165         }
    00166
    00170         protected void mniShowCriticalAnalysisPerformed() {
    00171                 if (analysisTableModel.getAnalysis().getCriticalDangerVariants().size() > 0) {
    00172
    00173                         new CriticalDangerAnalysisFrame(this, analysisTableModel
    00174                                         .getAnalysis().getCriticalDangerVariants());
    00175                 } else {
    00176                         JOptionPane.showMessageDialog(this,
    00177                                         "Není stanoveno žádné závažné nebezpečí!", "Chyba!",
    00178                                         JOptionPane.ERROR_MESSAGE);
    00179                 }
    00180         }
    00181
    00185         protected void mniLoadDiagramXMLPerformed() {
    00186                 JFileChooser jfch = new JFileChooser();
    00187                 if (jfch.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
    00188                         currentXMLFile = jfch.getSelectedFile().getAbsolutePath();
    00189                         Analysis a = application
    00190                                         .createAnalysis("file:///" + currentXMLFile);
    00191                         analysisTableModel.setAnalysis(a);
    00192                 }
    00193         }
    00194
    00198         protected void mniSavePerformed() {
    00199                 JFileChooser jfch = new JFileChooser();
    00200
    00201                 if (jfch.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
    00202                         String path = jfch.getSelectedFile().getAbsolutePath();
    00203                         Analysis a = analysisTableModel.getAnalysis();
    00204                         a.saveToFile(path);
    00205                 }
    00206         }
    00207
    00208         protected void mniShowAdminPerformed() {
    00209                 adminFrame.setVisible(true);
    00210         }
    00211
    00215         protected void tableClicked() {
    00216                 int selectedRow = table.getSelectedRow();
    00217                 int selectedColumn = table.getSelectedColumn();
    00218                 if (selectedRow >= 0 && selectedColumn == 3) {
    00219                         AnalysisRecord selectedRecord = analysisTableModel.getAnalysis()
    00220                                         .getAnalysisRecord(selectedRow);
    00221                         Component selectedComponent = selectedRecord.getComponent();
    00222
    00223                         ArrayList<DangerType> types = selectedComponent.getDangerTypes();
    00224                         if (types.size() > 0) {
    00225                                 new CriticalDangerVariantFrame(types);
    00226                         }
    00227                 }
    00228         }
    00229
    00230         public Rizika getApplication() {
    00231                 return application;
    00232         }
    00233
    00234         public void refresh() {
    00235                 application.refresh();
    00236                 Analysis a = application.createAnalysis(currentXMLFile);
    00237                 if (a != null) {
    00238                         analysisTableModel.setAnalysis(a);
    00239                 }
    00240         }
    00241
    00242         public Analysis getAnalysis() {
    00243                 return analysisTableModel.getAnalysis();
    00244         }
    00245 }