Java tutorial
/* Optical Workshop Monitoring System is a desktop application to fulfill the workflow control requirement at IRDE (DRDO) Dehradun. Copyright (C) 2014 Mayank Chaudhari (devil15) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. For any query mail me at m.charly3015@gmail.com */ package opticalworkshopmonitoringsystem; import com.itextpdf.text.Chunk; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Font; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfWriter; import java.beans.Beans; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.persistence.RollbackException; import javax.swing.JFileChooser; import javax.swing.JOptionPane; /** * * @author devil15 */ public class CenteringAndEdgingView extends javax.swing.JFrame { /** * Creates new form CenteringAndEdgingView */ public CenteringAndEdgingView() { initComponents(); if (!Beans.isDesignTime()) { entityManager.getTransaction().begin(); } } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { bindingGroup = new org.jdesktop.beansbinding.BindingGroup(); entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence .createEntityManagerFactory("drdo?zeroDateTimeBehavior=convertToNullPU") .createEntityManager(); centeringAndEdgingQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT c FROM CenteringAndEdging c"); centeringAndEdgingList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : centeringAndEdgingQuery.getResultList(); jScrollPane1 = new javax.swing.JScrollPane(); jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); jTextField2 = new javax.swing.JTextField(); jTextField3 = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jTextField4 = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jTextField5 = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); jTextField6 = new javax.swing.JTextField(); jLabel7 = new javax.swing.JLabel(); jTextField7 = new javax.swing.JTextField(); jLabel8 = new javax.swing.JLabel(); jTextField8 = new javax.swing.JTextField(); jLabel9 = new javax.swing.JLabel(); jTextField9 = new javax.swing.JTextField(); jLabel10 = new javax.swing.JLabel(); jTextField10 = new javax.swing.JTextField(); jLabel11 = new javax.swing.JLabel(); jTextField11 = new javax.swing.JTextField(); jLabel12 = new javax.swing.JLabel(); jTextField12 = new javax.swing.JTextField(); jLabel13 = new javax.swing.JLabel(); jTextField13 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jScrollPane4 = new javax.swing.JScrollPane(); jTable2 = new javax.swing.JTable(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Centering And Edging View"); jLabel1.setText("Project Name"); org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTable2, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.projectName}"), jTextField1, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jLabel2.setText("Component"); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTable2, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.component}"), jTextField2, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTable2, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.mode}"), jTextField3, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jLabel3.setText("Centering mode"); jLabel4.setText("Centering starting date"); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTable2, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.centeringStartDate}"), jTextField4, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jLabel5.setText("Centering completion date"); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTable2, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.centeringEndDate}"), jTextField5, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jLabel6.setText("Time taken in centering"); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTable2, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.TInCentering}"), jTextField6, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jLabel7.setText("Edging starting date"); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTable2, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.edgingStartDate}"), jTextField7, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jLabel8.setText("Edging completion date"); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTable2, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.edgingEndDate}"), jTextField8, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jLabel9.setText("Time taken in edging"); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTable2, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.TInEdging}"), jTextField9, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jLabel10.setText("Specified componentl diameter"); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTable2, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.diaCenteringToolSpecified}"), jTextField10, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jLabel11.setText("Measured component diameter"); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTable2, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.diaCenteringToolMeasured}"), jTextField11, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jLabel12.setText("Specified C T"); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTable2, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.surfaceSpecified}"), jTextField12, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jLabel13.setText("Measured C T"); jLabel13.setToolTipText(""); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTable2, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.surfaceMeasured}"), jTextField13, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jButton1.setText("New"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("Delete"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jButton5.setText("Save"); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); jButton3.setText("Generate Report"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jTable2.getTableHeader().setReorderingAllowed(false); org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings .createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, centeringAndEdgingList, jTable2); org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${projectName}")); columnBinding.setColumnName("Project Name"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${component}")); columnBinding.setColumnName("Component"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${surfaceMeasured}")); columnBinding.setColumnName("Surface Measured"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${surfaceSpecified}")); columnBinding.setColumnName("Surface Specified"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${diaCenteringToolMeasured}")); columnBinding.setColumnName("Dia Centering Tool Measured"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${diaCenteringToolSpecified}")); columnBinding.setColumnName("Dia Centering Tool Specified"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${TInEdging}")); columnBinding.setColumnName("TInEdging"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${edgingEndDate}")); columnBinding.setColumnName("Edging End Date"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${edgingStartDate}")); columnBinding.setColumnName("Edging Start Date"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${TInCentering}")); columnBinding.setColumnName("TInCentering"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${centeringEndDate}")); columnBinding.setColumnName("Centering End Date"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${centeringStartDate}")); columnBinding.setColumnName("Centering Start Date"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${mode}")); columnBinding.setColumnName("Mode"); columnBinding.setColumnClass(String.class); columnBinding.setEditable(false); bindingGroup.addBinding(jTableBinding); jTableBinding.bind(); jScrollPane4.setViewportView(jTable2); if (jTable2.getColumnModel().getColumnCount() > 0) { jTable2.getColumnModel().getColumn(0).setMinWidth(150); jTable2.getColumnModel().getColumn(0).setPreferredWidth(150); jTable2.getColumnModel().getColumn(1).setMinWidth(150); jTable2.getColumnModel().getColumn(1).setPreferredWidth(150); } javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGap(16, 16, 16).addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE) .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(56, 56, 56) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE) .addComponent(jTextField3).addComponent(jTextField4) .addComponent(jTextField5).addComponent(jTextField6) .addComponent(jTextField7).addComponent(jTextField8) .addComponent(jTextField9) .addComponent(jTextField10, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jTextField11, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jTextField12).addComponent(jTextField13)) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(32, 32, 32) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(32, 32, 32) .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(32, 32, 32).addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(186, Short.MAX_VALUE)) .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.TRAILING)); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 327, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField1) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(18, 18, 18) .addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField2).addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(18, 18, 18) .addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField3).addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(18, 18, 18) .addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField4) .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(18, 18, 18) .addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField5) .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(18, 18, 18) .addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField6) .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(21, 21, 21) .addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField7).addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(18, 18, 18) .addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField8).addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(18, 18, 18) .addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField9) .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(18, 18, 18) .addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField10) .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(18, 18, 18) .addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField11) .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField12).addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextField13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel13)) .addGap(25, 25, 25) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1).addComponent(jButton2).addComponent(jButton5) .addComponent(jButton3)) .addGap(38, 38, 38))); jScrollPane1.setViewportView(jPanel1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 817, Short.MAX_VALUE)); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 875, Short.MAX_VALUE)); bindingGroup.bind(); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed //code for the forating of the pdf report. try { Document document = new Document(); JFileChooser fc = new JFileChooser(); fc.showOpenDialog(null); PdfWriter.getInstance(document, new FileOutputStream(fc.getSelectedFile().getAbsolutePath())); document.open(); Font courierFontItalic = new Font(Font.FontFamily.COURIER, 10, Font.ITALIC); Font courierFontUnderline = new Font(Font.FontFamily.COURIER, 10, Font.UNDERLINE); Font tr = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); Font timesRomanUnderline = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.UNDERLINE); Font helvetica = new Font(Font.FontFamily.HELVETICA, 14, Font.UNDERLINE); document.add(new Paragraph( " Centering And Edging Division ", timesRomanUnderline)); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel1.getText(), tr)); document.add( new Chunk(" " + jTextField1.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel2.getText(), tr)); document.add( new Chunk(" " + jTextField2.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel3.getText(), tr)); document.add( new Chunk(" " + jTextField3.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel4.getText(), tr)); document.add( new Chunk(" " + jTextField4.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel5.getText(), tr)); document.add( new Chunk(" " + jTextField5.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel6.getText(), tr)); document.add( new Chunk(" " + jTextField6.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel7.getText(), tr)); document.add( new Chunk(" " + jTextField7.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel8.getText(), tr)); document.add( new Chunk(" " + jTextField8.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel9.getText(), tr)); document.add( new Chunk(" " + jTextField9.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel10.getText(), tr)); document.add( new Chunk(" " + jTextField10.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel11.getText(), tr)); document.add( new Chunk(" " + jTextField11.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel12.getText(), tr)); document.add( new Chunk(" " + jTextField12.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel13.getText(), tr)); document.add( new Chunk(" " + jTextField13.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph( " ")); document.add(new Paragraph( " ")); document.add(new Paragraph( " ")); document.add(new Paragraph( " ")); document.add(new Paragraph( " Prepared by Checked by Approved by ")); document.close(); JOptionPane.showMessageDialog(null, "report generated successfully"); } catch (DocumentException ex) { Logger.getLogger(CenteringAndEdgingView.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(CenteringAndEdgingView.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_jButton3ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed //delete button code int[] selected = jTable2.getSelectedRows(); List<opticalworkshopmonitoringsystem.CenteringAndEdging> toRemove = new ArrayList<opticalworkshopmonitoringsystem.CenteringAndEdging>( selected.length); for (int idx = 0; idx < selected.length; idx++) { opticalworkshopmonitoringsystem.CenteringAndEdging t = centeringAndEdgingList .get(jTable2.convertRowIndexToModel(selected[idx])); toRemove.add(t); entityManager.remove(t); } centeringAndEdgingList.removeAll(toRemove); }//GEN-LAST:event_jButton2ActionPerformed private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed // save button code try { entityManager.getTransaction().commit(); entityManager.getTransaction().begin(); } catch (RollbackException rex) { rex.printStackTrace(); entityManager.getTransaction().begin(); List<opticalworkshopmonitoringsystem.CenteringAndEdging> merged = new ArrayList<opticalworkshopmonitoringsystem.CenteringAndEdging>( centeringAndEdgingList.size()); for (opticalworkshopmonitoringsystem.CenteringAndEdging t : centeringAndEdgingList) { merged.add(entityManager.merge(t)); } centeringAndEdgingList.clear(); centeringAndEdgingList.addAll(merged); } JOptionPane.showMessageDialog(this.getParent(), "Record Updated Successfully , PLease reload the page to view the changes"); }//GEN-LAST:event_jButton5ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // Code for new button opticalworkshopmonitoringsystem.CenteringAndEdging t = new opticalworkshopmonitoringsystem.CenteringAndEdging(); entityManager.persist(t); centeringAndEdgingList.add(t); int row = centeringAndEdgingList.size() - 1; jTable2.setRowSelectionInterval(row, row); jTable2.scrollRectToVisible(jTable2.getCellRect(row, 0, true)); }//GEN-LAST:event_jButton1ActionPerformed public static void main(String args[]) { 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 ex) { java.util.logging.Logger.getLogger(CenteringAndEdgingView.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(CenteringAndEdgingView.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(CenteringAndEdgingView.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(CenteringAndEdgingView.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new CenteringAndEdgingView().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private java.util.List<opticalworkshopmonitoringsystem.CenteringAndEdging> centeringAndEdgingList; private javax.persistence.Query centeringAndEdgingQuery; private javax.persistence.EntityManager entityManager; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton5; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane4; private javax.swing.JTable jTable2; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField10; private javax.swing.JTextField jTextField11; private javax.swing.JTextField jTextField12; private javax.swing.JTextField jTextField13; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3; private javax.swing.JTextField jTextField4; private javax.swing.JTextField jTextField5; private javax.swing.JTextField jTextField6; private javax.swing.JTextField jTextField7; private javax.swing.JTextField jTextField8; private javax.swing.JTextField jTextField9; private org.jdesktop.beansbinding.BindingGroup bindingGroup; // End of variables declaration//GEN-END:variables }