/* * The MIT License * * Copyright 2015 Jaafar EL Bakkali. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package ersn.openmc; import java.awt.Color; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import javax.swing.JFileChooser; /** * * @author Jaafar EL Bakkali */ public class ERSNOpenMC_New_project extends javax.swing.JFrame { ERSNOpenMC_Singleton tmp = ERSNOpenMC_Singleton.getInstance( ); public ERSNOpenMC_New_project() { initComponents(); getContentPane().setBackground(new Color(0, 0, 128)); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { _new_project = new javax.swing.JTextField(); lbl_project_name = new javax.swing.JLabel(); _workspace = new javax.swing.JTextField(); lbl_workspace = new javax.swing.JLabel(); btn_dir = new javax.swing.JButton(); jSeparator1 = new javax.swing.JSeparator(); select_settings = new javax.swing.JCheckBox(); select_cmfd = new javax.swing.JCheckBox(); select_materials = new javax.swing.JCheckBox(); select_geometry = new javax.swing.JCheckBox(); select_tallies = new javax.swing.JCheckBox(); select_plotting = new javax.swing.JCheckBox(); lbl_xml_files = new javax.swing.JLabel(); btn_create = new javax.swing.JButton(); lbl_description = new javax.swing.JLabel(); _description = new javax.swing.JTextField(); lbl_case = new javax.swing.JLabel(); _case = new javax.swing.JTextField(); lbl_writen_by = new javax.swing.JLabel(); _writen = new javax.swing.JTextField(); lbl_date = new javax.swing.JLabel(); _date = new javax.swing.JTextField(); jButton_abort = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("New OpenMC project"); setType(java.awt.Window.Type.UTILITY); addWindowListener(new java.awt.event.WindowAdapter() { public void windowOpened(java.awt.event.WindowEvent evt) { formWindowOpened(evt); } }); lbl_project_name.setBackground(java.awt.SystemColor.activeCaption); lbl_project_name.setForeground(java.awt.Color.orange); lbl_project_name.setText("Project Name"); lbl_workspace.setBackground(java.awt.SystemColor.activeCaption); lbl_workspace.setForeground(java.awt.Color.orange); lbl_workspace.setText("Workspace"); btn_dir.setText("..."); btn_dir.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btn_dirActionPerformed(evt); } }); select_settings.setBackground(java.awt.SystemColor.activeCaption); select_settings.setForeground(java.awt.Color.orange); select_settings.setSelected(true); select_settings.setText("settings"); select_settings.setEnabled(false); select_cmfd.setBackground(java.awt.SystemColor.activeCaption); select_cmfd.setForeground(java.awt.Color.orange); select_cmfd.setText("cmfd"); select_materials.setBackground(java.awt.SystemColor.activeCaption); select_materials.setForeground(java.awt.Color.orange); select_materials.setSelected(true); select_materials.setText("materials"); select_materials.setEnabled(false); select_geometry.setBackground(java.awt.SystemColor.activeCaption); select_geometry.setForeground(java.awt.Color.orange); select_geometry.setSelected(true); select_geometry.setText("geometry"); select_geometry.setEnabled(false); select_tallies.setBackground(java.awt.SystemColor.activeCaption); select_tallies.setForeground(java.awt.Color.orange); select_tallies.setText("tallies"); select_plotting.setBackground(java.awt.SystemColor.activeCaption); select_plotting.setForeground(java.awt.Color.orange); select_plotting.setText("plots"); lbl_xml_files.setBackground(java.awt.SystemColor.activeCaption); lbl_xml_files.setForeground(java.awt.Color.orange); lbl_xml_files.setText("OpenMC XML files :"); btn_create.setBackground(new java.awt.Color(214, 209, 209)); btn_create.setForeground(java.awt.Color.darkGray); btn_create.setText("create new project"); btn_create.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); btn_create.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btn_createActionPerformed(evt); } }); lbl_description.setBackground(java.awt.SystemColor.activeCaption); lbl_description.setForeground(java.awt.Color.orange); lbl_description.setText("Description"); lbl_case.setBackground(java.awt.SystemColor.activeCaption); lbl_case.setForeground(java.awt.Color.orange); lbl_case.setText("Case"); lbl_writen_by.setBackground(java.awt.SystemColor.activeCaption); lbl_writen_by.setForeground(java.awt.Color.orange); lbl_writen_by.setText("Writen By"); lbl_date.setBackground(java.awt.SystemColor.activeCaption); lbl_date.setForeground(java.awt.Color.orange); lbl_date.setText("Date"); jButton_abort.setBackground(new java.awt.Color(214, 209, 209)); jButton_abort.setForeground(java.awt.Color.darkGray); jButton_abort.setText("abort"); jButton_abort.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); jButton_abort.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton_abortActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton_abort, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btn_create)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(lbl_writen_by, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(12, 12, 12) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(select_geometry) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(select_materials) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(select_settings) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(select_cmfd) .addGap(18, 18, 18) .addComponent(select_tallies) .addGap(19, 19, 19) .addComponent(select_plotting)) .addComponent(lbl_xml_files) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lbl_workspace, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lbl_project_name, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lbl_description, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lbl_case, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lbl_date, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() .addComponent(_workspace) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btn_dir)) .addComponent(_new_project) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(_case, javax.swing.GroupLayout.PREFERRED_SIZE, 347, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(_description, javax.swing.GroupLayout.PREFERRED_SIZE, 347, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(_writen, javax.swing.GroupLayout.PREFERRED_SIZE, 347, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(_date, javax.swing.GroupLayout.PREFERRED_SIZE, 347, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(0, 0, Short.MAX_VALUE))))))) .addGap(0, 4, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(_new_project, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lbl_project_name)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(_workspace, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lbl_workspace) .addComponent(btn_dir, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lbl_description) .addComponent(_description, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lbl_case) .addComponent(_case, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lbl_writen_by) .addComponent(_writen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(35, 35, 35)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(_date, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lbl_date))) .addGap(18, 18, 18) .addComponent(lbl_xml_files) .addGap(20, 20, 20) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(select_materials) .addComponent(select_settings) .addComponent(select_geometry) .addComponent(select_cmfd) .addComponent(select_tallies) .addComponent(select_plotting)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btn_create) .addComponent(jButton_abort)) .addGap(5, 5, 5)) ); pack(); setLocationRelativeTo(null); }// </editor-fold>//GEN-END:initComponents private void btn_dirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_dirActionPerformed JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showOpenDialog(this); if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) { java.io.File file = fc.getSelectedFile( ); String file_name = file.toString( ); _workspace.setText(file_name); } }//GEN-LAST:event_btn_dirActionPerformed public void create_empty_xml_file(String xml_file, String target){ try { FileWriter lu = new FileWriter(_workspace.getText()+"/"+_new_project.getText()+"/"+xml_file); try (BufferedWriter fluxS = new BufferedWriter(lu)) { fluxS.write(target); } } catch (IOException er) { System.out.print("!!!!!!!!!!"); } } private void btn_createActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_createActionPerformed // TODO add your handling code here: java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { // ERSNOpenMC_main dialgo =new ERSNOpenMC_main(); // dialgo.show(); } }); File dir = new File(_workspace.getText()+"/"+_new_project.getText()); dir.mkdir(); tmp.setPath(_workspace.getText()+"/"+_new_project.getText()); String setting_init="<?xml version=\"1.0\"?>\n" +"<settings> \n"+"<!-- \n=========================================================================="+"\nDescription:"+_description.getText()+" \nCase:"+_case.getText()+" \nWriten By:"+_writen.getText()+" \nDate:"+_date.getText()+"\n==========================================================================\n -->"+"\n \n \n \n</settings>"; String geometry_init="<?xml version=\"1.0\"?>\n" +"<geometry> \n"+"<!-- \n=========================================================================="+"\nDescription:"+_description.getText()+" \nCase:"+_case.getText()+" \nWriten By:"+_writen.getText()+" \nDate:"+_date.getText()+"\n==========================================================================\n -->"+"\n \n \n \n</geometry>"; String materials_init="<?xml version=\"1.0\"?>\n" +"<materials> \n"+"<!-- \n=========================================================================="+"\nDescription:"+_description.getText()+" \nCase:"+_case.getText()+" \nWriten By:"+_writen.getText()+" \nDate:"+_date.getText()+"\n==========================================================================\n -->"+"\n \n \n \n</materials>"; String tallies_init="<?xml version=\"1.0\"?>\n" +"<tallies> \n"+"<!-- \n=========================================================================="+"\nDescription:"+_description.getText()+" \nCase:"+_case.getText()+" \nWriten By:"+_writen.getText()+" \nDate:"+_date.getText()+"\n==========================================================================\n -->"+"\n \n \n \n</tallies>"; String cmfd_init="<?xml version=\"1.0\"?>\n" +"<cmfd> \n"+"<!-- \n=========================================================================="+"\nDescription:"+_description.getText()+" \nCase:"+_case.getText()+" \nWriten By:"+_writen.getText()+" \nDate:"+_date.getText()+"\n==========================================================================\n -->"+"\n \n \n \n</cmfd>"; String plots_init="<?xml version=\"1.0\"?>\n" +"<plots> \n"+"<!-- \n=========================================================================="+"\nDescription:"+_description.getText()+" \nCase:"+_case.getText()+" \nWriten By:"+_writen.getText()+" \nDate:"+_date.getText()+"\n==========================================================================\n -->"+"\n \n \n \n</plots>"; create_empty_xml_file("settings.xml",setting_init); create_empty_xml_file("geometry.xml",geometry_init); create_empty_xml_file("materials.xml",materials_init); if (select_tallies.isSelected()==true) create_empty_xml_file("tallies.xml",tallies_init); if (select_cmfd.isSelected()==true) create_empty_xml_file("cmfd.xml",cmfd_init); if (select_plotting.isSelected()==true) create_empty_xml_file("plots.xml",plots_init); this.show(false); }//GEN-LAST:event_btn_createActionPerformed private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date = new Date(); _date.setText(dateFormat.format(date)); }//GEN-LAST:event_formWindowOpened private void jButton_abortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_abortActionPerformed this.show(false); }//GEN-LAST:event_jButton_abortActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(ERSNOpenMC_New_project.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { new ERSNOpenMC_New_project().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextField _case; private javax.swing.JTextField _date; private javax.swing.JTextField _description; private javax.swing.JTextField _new_project; private javax.swing.JTextField _workspace; private javax.swing.JTextField _writen; private javax.swing.JButton btn_create; private javax.swing.JButton btn_dir; private javax.swing.JButton jButton_abort; private javax.swing.JSeparator jSeparator1; private javax.swing.JLabel lbl_case; private javax.swing.JLabel lbl_date; private javax.swing.JLabel lbl_description; private javax.swing.JLabel lbl_project_name; private javax.swing.JLabel lbl_workspace; private javax.swing.JLabel lbl_writen_by; private javax.swing.JLabel lbl_xml_files; private javax.swing.JCheckBox select_cmfd; private javax.swing.JCheckBox select_geometry; private javax.swing.JCheckBox select_materials; private javax.swing.JCheckBox select_plotting; private javax.swing.JCheckBox select_settings; private javax.swing.JCheckBox select_tallies; // End of variables declaration//GEN-END:variables }