Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Measurment_Result_Record; import MainPackage.MainWindow; import com.itextpdf.text.BaseColor; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; import com.itextpdf.text.FontFactory; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfPCell; import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfWriter; import java.awt.Color; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.JTabbedPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; /** * * @author Tibebu */ public class MeasurmentSetup extends javax.swing.JFrame { private int parameterCount; private int testNumberCount; public ArrayList<TestParameterGUI> selectedParameters; private boolean errorFlag; private String errorMessage; private String measurmentTitle; public ArrayList<JTable> resultTables; private boolean MeasurmentSetUpFinished; //presenter /parent class public MainWindow presenter; /** * Creates new form RecordMeasurmentResult */ public MeasurmentSetup() { initComponents(); parameterCount = 0; testNumberCount = 0; selectedParameters = new ArrayList<TestParameterGUI>(2); errorFlag = false; errorMessage = ""; MeasurmentSetUpFinished = false; resultTables = new ArrayList<JTable>(); //disable other steps jTabbedPane1.setEnabledAt(1, false); jTabbedPane1.setEnabledAt(2, false); } public void parameterCountIncreament() { parameterCount++; } public void parameterCountDecrement() { parameterCount--; } public void setParameterCount(int parameterCount) { this.parameterCount = parameterCount; } public int getParameterCount() { parameterCount = this.selectedParameters.size(); return parameterCount; } public void setTestNumberCount(int testNumberCount) { this.testNumberCount = testNumberCount; } public int getTestNumberCount() { return testNumberCount; } public void testNumberIncreament() { this.testNumberCount++; } public void testNumberDecreament() { this.testNumberCount--; } public JTabbedPane getjTabbedPane1() { return jTabbedPane1; } public JTabbedPane getTabParametersDetail() { return tabParametersDetail; } public JTable getRecordTablePreview() { return recordTablePreview; } public boolean isErrorFlag() { return errorFlag; } public void setErrorFlag(boolean errorFlag) { this.errorFlag = errorFlag; } public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; } public String getErrorMessage() { return errorMessage; } public void setMeasurmentTitle(String measurmentTitle) { this.measurmentTitle = measurmentTitle; } public String getMeasurmentTitle() { return measurmentTitle; } public boolean isMeasurmentSetUpFinished() { return MeasurmentSetUpFinished; } public void setMeasurmentSetUpFinished(boolean MeasurmentSetUpFinished) { this.MeasurmentSetUpFinished = MeasurmentSetUpFinished; } /** * set the selected theme * @param themeType MainWindow.THEME_STANDARD , MainWindow.THEME_CLASSICAL ,MainWindow.THEME_DARK, */ public void setTheme(int themeType) { Color bcolor; Color labelcolor; if (themeType == MainWindow.THEME_STANDARD) { bcolor = new Color(102, 102, 0); labelcolor = new Color(255, 255, 255); } else if (themeType == MainWindow.THEME_CLASSICAL) { bcolor = new Color(41, 60, 82); labelcolor = new Color(255, 255, 255); } else if (themeType == MainWindow.THEME_DARK) { bcolor = Color.BLACK; labelcolor = new Color(255, 255, 255); } else { bcolor = new Color(102, 102, 0); labelcolor = new Color(255, 255, 255); } jPanel1.setBackground(bcolor); jPanel2.setBackground(bcolor); jPanel3.setBackground(bcolor); jPanel4.setBackground(bcolor); jPanel5.setBackground(bcolor); panelStep2.setBackground(bcolor); panelStep3.setBackground(bcolor); voltageParameter.setBackground(bcolor); currentParameter.setBackground(bcolor); resistanceParameter.setBackground(bcolor); frequencyParameter.setBackground(bcolor); capacitanceParameter.setBackground(bcolor); powerParameter.setBackground(bcolor); jLabel4.setForeground(labelcolor); voltageParameter.setForeground(labelcolor); currentParameter.setForeground(labelcolor); resistanceParameter.setForeground(labelcolor); capacitanceParameter.setForeground(labelcolor); frequencyParameter.setForeground(labelcolor); powerParameter.setForeground(labelcolor); } public void setRecordTablePreview() { //builld defaulttablemodel int column = getParameterCount() + 1; //including the test no int row = getTestNumberCount(); Object data[][] = new Object[row][column]; String header[] = new String[column]; for (int i = 0; i < row; i++) { data[i][0] = i + 1; for (int j = 1; j < column; j++) { data[i][j] = selectedParameters.get(j - 1).getTestParameter().getTestValue().get(i); } } header[0] = "Test No"; for (int j = 1; j < column; j++) { header[j] = selectedParameters.get(j - 1).getTestParameter().parameterDetail(); } recordTablePreview.setModel(new DefaultTableModel(data, header)); //update the resultTablesArray } /** * 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() { jTabbedPane1 = new javax.swing.JTabbedPane(); jPanel1 = new javax.swing.JPanel(); jPanel4 = new javax.swing.JPanel(); voltageParameter = new javax.swing.JCheckBox(); resistanceParameter = new javax.swing.JCheckBox(); currentParameter = new javax.swing.JCheckBox(); capacitanceParameter = new javax.swing.JCheckBox(); powerParameter = new javax.swing.JCheckBox(); frequencyParameter = new javax.swing.JCheckBox(); nextStep1 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jPanel5 = new javax.swing.JPanel(); errorDisplay1 = new javax.swing.JLabel(); titleField = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); panelStep2 = new javax.swing.JPanel(); tabParametersDetail = new javax.swing.JTabbedPane(); nextStep2 = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); jPanel3 = new javax.swing.JPanel(); errorDisplay = new javax.swing.JLabel(); panelStep3 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); recordTablePreview = new javax.swing.JTable(); finishStep = new javax.swing.JButton(); jLabel3 = new javax.swing.JLabel(); jPanel2 = new javax.swing.JPanel(); jLabel4 = new javax.swing.JLabel(); titleDisplay = new javax.swing.JLabel(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItem_exportpdf = new javax.swing.JMenuItem(); jSeparator1 = new javax.swing.JPopupMenu.Separator(); jMenuItem_addmore = new javax.swing.JMenuItem(); jMenu2 = new javax.swing.JMenu(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Measurment Setup"); setResizable(false); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { formWindowClosing(evt); } }); jTabbedPane1.setTabPlacement(javax.swing.JTabbedPane.BOTTOM); jPanel1.setBackground(new java.awt.Color(41, 60, 82)); jPanel4.setBackground(new java.awt.Color(41, 60, 82)); jPanel4.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); voltageParameter.setText("Voltage"); voltageParameter .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); voltageParameter.setPreferredSize(new java.awt.Dimension(90, 23)); resistanceParameter.setText("Resistance"); resistanceParameter .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); resistanceParameter.setPreferredSize(new java.awt.Dimension(90, 23)); currentParameter.setText("Current"); currentParameter .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); currentParameter.setPreferredSize(new java.awt.Dimension(90, 23)); capacitanceParameter.setText("Capacitance"); capacitanceParameter .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); capacitanceParameter.setPreferredSize(new java.awt.Dimension(90, 23)); capacitanceParameter.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { capacitanceParameterActionPerformed(evt); } }); powerParameter.setText("Power"); powerParameter .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); powerParameter.setPreferredSize(new java.awt.Dimension(90, 23)); frequencyParameter.setText("Frequency"); frequencyParameter .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); frequencyParameter.setPreferredSize(new java.awt.Dimension(90, 23)); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup() .addGap(63, 63, 63) .addGroup( jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(currentParameter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(resistanceParameter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(voltageParameter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(213, 213, 213) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(frequencyParameter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(powerParameter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(capacitanceParameter, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup().addGap(40, 40, 40).addGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(voltageParameter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(capacitanceParameter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(currentParameter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(frequencyParameter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(resistanceParameter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(powerParameter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(48, Short.MAX_VALUE))); nextStep1.setText("Next"); nextStep1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { nextStep1ActionPerformed(evt); } }); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabel1.setForeground(new java.awt.Color(255, 255, 255)); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setText("Select Your Measurment Parameters"); jPanel5.setBackground(new java.awt.Color(41, 60, 82)); errorDisplay1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N errorDisplay1.setForeground(new java.awt.Color(204, 0, 0)); errorDisplay1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); errorDisplay1.setPreferredSize(new java.awt.Dimension(34, 14)); javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout .setHorizontalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(errorDisplay1, javax.swing.GroupLayout.DEFAULT_SIZE, 510, Short.MAX_VALUE)); jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup().addContainerGap().addComponent(errorDisplay1, javax.swing.GroupLayout.DEFAULT_SIZE, 18, Short.MAX_VALUE))); titleField.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabel5.setForeground(new java.awt.Color(255, 255, 255)); jLabel5.setText("Add Title"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout .createSequentialGroup().addContainerGap().addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(jPanel1Layout.createSequentialGroup().addGap(118, 118, 118).addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(nextStep1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup() .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(titleField))) .addGap(0, 212, Short.MAX_VALUE))) .addContainerGap())); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(titleField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5)) .addGap(18, 18, 18) .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(nextStep1, javax.swing.GroupLayout.Alignment.TRAILING)) .addGap(23, 23, 23))); jTabbedPane1.addTab("Step 1", jPanel1); panelStep2.setBackground(new java.awt.Color(41, 60, 82)); tabParametersDetail.setTabPlacement(javax.swing.JTabbedPane.LEFT); nextStep2.setText("Next"); nextStep2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { nextStep2ActionPerformed(evt); } }); jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jLabel2.setForeground(new java.awt.Color(255, 255, 255)); jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel2.setText("Set properties for each parameter"); jPanel3.setBackground(new java.awt.Color(41, 60, 82)); errorDisplay.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N errorDisplay.setForeground(new java.awt.Color(204, 0, 0)); errorDisplay.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(errorDisplay, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() .addGap(0, 19, Short.MAX_VALUE).addComponent(errorDisplay))); javax.swing.GroupLayout panelStep2Layout = new javax.swing.GroupLayout(panelStep2); panelStep2.setLayout(panelStep2Layout); panelStep2Layout .setHorizontalGroup(panelStep2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelStep2Layout.createSequentialGroup().addContainerGap() .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 946, Short.MAX_VALUE) .addContainerGap()) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelStep2Layout.createSequentialGroup().addGroup(panelStep2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(tabParametersDetail, javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelStep2Layout.createSequentialGroup() .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(18, 18, 18).addComponent(nextStep2))) .addGap(43, 43, 43))); panelStep2Layout.setVerticalGroup(panelStep2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelStep2Layout.createSequentialGroup().addContainerGap().addComponent(jLabel2) .addGap(18, 18, 18) .addComponent(tabParametersDetail, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(panelStep2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(nextStep2).addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap())); jTabbedPane1.addTab("Step 2", panelStep2); panelStep3.setBackground(new java.awt.Color(41, 60, 82)); recordTablePreview.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null }, { null, null, null, null } }, new String[] { "Test no", "para 1", "para 2", "Test 03" })); jScrollPane1.setViewportView(recordTablePreview); finishStep.setText("Finish"); finishStep.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { finishStepActionPerformed(evt); } }); jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jLabel3.setForeground(new java.awt.Color(255, 255, 255)); jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel3.setText("Measurment result preview"); jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jLabel4.setText( "You are finished setting parameters , when you are ready to record your test result press Tools -> Record test or shift+R"); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout .setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup().addContainerGap() .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(jLabel4) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); titleDisplay.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N titleDisplay.setForeground(new java.awt.Color(255, 255, 255)); titleDisplay.setText("measurment title"); javax.swing.GroupLayout panelStep3Layout = new javax.swing.GroupLayout(panelStep3); panelStep3.setLayout(panelStep3Layout); panelStep3Layout.setHorizontalGroup(panelStep3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelStep3Layout.createSequentialGroup().addGap(39, 39, 39) .addGroup(panelStep3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(titleDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 601, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(panelStep3Layout.createSequentialGroup() .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(67, 67, 67).addComponent(finishStep, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 826, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 841, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(86, Short.MAX_VALUE))); panelStep3Layout.setVerticalGroup(panelStep3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelStep3Layout.createSequentialGroup() .addContainerGap().addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 68, Short.MAX_VALUE) .addComponent(titleDisplay).addGap(18, 18, 18) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(45, 45, 45) .addGroup(panelStep3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(finishStep, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(29, 29, 29))); jTabbedPane1.addTab("Step 3", panelStep3); jMenu1.setText("File"); jMenuItem_exportpdf.setText("Export to pdf"); jMenuItem_exportpdf.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem_exportpdfActionPerformed(evt); } }); jMenu1.add(jMenuItem_exportpdf); jMenu1.add(jSeparator1); jMenuItem_addmore.setText("add More"); jMenuItem_addmore.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem_addmoreActionPerformed(evt); } }); jMenu1.add(jMenuItem_addmore); jMenuBar1.add(jMenu1); jMenu2.setText("Edit"); jMenuBar1.add(jMenu2); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jTabbedPane1)); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING)); jTabbedPane1.getAccessibleContext().setAccessibleName(""); setSize(new java.awt.Dimension(987, 484)); setLocationRelativeTo(null); }// </editor-fold>//GEN-END:initComponents private void capacitanceParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_capacitanceParameterActionPerformed // TODO add your handling code here: }//GEN-LAST:event_capacitanceParameterActionPerformed private void nextStep1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextStep1ActionPerformed //check for the title if (titleField.getText().trim().equals("")) { errorDisplay1.setText("Please Add the measurment title"); return; } else this.setMeasurmentTitle(titleField.getText().trim()); //clear the previous selectedParameters selectedParameters.removeAll(selectedParameters); //get the selected parameters if (voltageParameter.isSelected()) selectedParameters.add(new TestParameterGUI(new TestParameter(voltageParameter.getText()))); if (currentParameter.isSelected()) selectedParameters.add(new TestParameterGUI(new TestParameter(currentParameter.getText()))); if (resistanceParameter.isSelected()) selectedParameters.add(new TestParameterGUI(new TestParameter(resistanceParameter.getText()))); if (capacitanceParameter.isSelected()) selectedParameters.add(new TestParameterGUI(new TestParameter(capacitanceParameter.getText()))); if (powerParameter.isSelected()) selectedParameters.add(new TestParameterGUI(new TestParameter(powerParameter.getText()))); if (frequencyParameter.isSelected()) selectedParameters.add(new TestParameterGUI(new TestParameter(frequencyParameter.getText()))); //clear the tab first tabParametersDetail.removeAll(); //check if no parameter is selected if (selectedParameters.isEmpty()) { errorDisplay1.setText("Please select at least 1 parameter"); return; } //add to the tab and constarct step gui ; selcected parameters detail for (TestParameterGUI selectedParameter : selectedParameters) { addParameterTotheParameterDetailTabPane(selectedParameter); } //make step 2 tabpane active jTabbedPane1.setSelectedIndex(1); jTabbedPane1.setEnabledAt(1, true); }//GEN-LAST:event_nextStep1ActionPerformed private void nextStep2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextStep2ActionPerformed // TODO add your handling code here: setTestNumberCount(0); //set all the selected parameters parameter from the field values for (TestParameterGUI selectedParameter : selectedParameters) { selectedParameter.getTestParameter().setParameterTittle(selectedParameter.getParameterTittle()); if (selectedParameter.getTestParameter().getType() == TestParameter.TYPE_CONSTANT_INPUT) { double val = selectedParameter.getParameterValue(); //check if there is error before setting the test value if (isErrorFlag()) { setErrorFlag(false); errorDisplay.setText(getErrorMessage()); setErrorMessage(""); return; } selectedParameter.getTestParameter().setTestValue(val); } } titleDisplay.setText(measurmentTitle); setRecordTablePreview(); jTabbedPane1.setSelectedIndex(2); jTabbedPane1.setEnabledAt(2, true); }//GEN-LAST:event_nextStep2ActionPerformed private void finishStepActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_finishStepActionPerformed // TODO add your handling code here: if (presenter != null) { presenter.getRecordTest().setEnabled(true); } this.setVisible(false); this.setMeasurmentSetUpFinished(true); this.presenter.reportForm.jBPrv.doClick(); this.presenter.reportForm.jBNext.doClick(); }//GEN-LAST:event_finishStepActionPerformed private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing // if setup is not finished if (!this.isMeasurmentSetUpFinished()) { this.presenter.measurmentSetup = null; //remove what we instantiatiate first since it is not finished int lastIndex = this.presenter.allMeasurmentSetups.size() - 1; if (lastIndex >= 0) this.presenter.allMeasurmentSetups.remove(lastIndex); } }//GEN-LAST:event_formWindowClosing private void jMenuItem_exportpdfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_exportpdfActionPerformed // TODO add your handling code here: // TODO add your handling code here: try { // TODO add your handling code here: JFileChooser fchooser = new JFileChooser(); int status = fchooser.showSaveDialog(null); if (status != JFileChooser.APPROVE_OPTION) return; fchooser.setDialogTitle("Save the Measurment result to pdf."); File selectedF = fchooser.getSelectedFile(); String filename = selectedF.getAbsolutePath(); //get the file path to save the pdf Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(filename + ".pdf")); document.open(); //add the IPELS logo and title int size = 30; com.itextpdf.text.Font titleFont; titleFont = FontFactory.getFont(FontFactory.TIMES_BOLD, size, com.itextpdf.text.Font.BOLD, BaseColor.BLUE); Paragraph ipels = new Paragraph("IPELS", titleFont); ipels.setAlignment(Element.ALIGN_CENTER); document.add(ipels); titleFont.setSize(25); Paragraph para = new Paragraph("Measurment result \n ", titleFont); para.setAlignment(Element.ALIGN_CENTER); document.add(para); //loop through all the measurmentsetups tables and add each of them to the document for (MeasurmentSetup mesSetup : this.presenter.allMeasurmentSetups) { addResultTablesTotheDocument(document, mesSetup.recordTablePreview, mesSetup.getMeasurmentTitle()); } //close the document document.close(); //preview the document Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + filename + ".pdf"); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "Save to pdf", JOptionPane.ERROR_MESSAGE); } catch (DocumentException ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "Save to pdf", JOptionPane.ERROR_MESSAGE); } catch (IOException ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "opening pdf", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_jMenuItem_exportpdfActionPerformed private void jMenuItem_addmoreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_addmoreActionPerformed // TODO add your handling code here: //update the measurmentsetup in the list //remove the previous one int lastIndex = this.presenter.allMeasurmentSetups.size() - 1; if (lastIndex >= 0) { this.presenter.allMeasurmentSetups.remove(lastIndex); //add the new one this.presenter.allMeasurmentSetups.add(this); } this.presenter.measurmentSetup = null; this.presenter.getMeasurmentSetupButton().doClick(); this.dispose(); }//GEN-LAST:event_jMenuItem_addmoreActionPerformed /** * write the given table datas to the given document * @param doc document to write the result tables on * @param table the result table * @param m_title the measurment title */ public static void addResultTablesTotheDocument(Document doc, JTable table, String m_title) throws DocumentException { //add the measurment title and table Paragraph measurmenttitle = new Paragraph(m_title + "\n "); measurmenttitle.getFont().setStyle(com.itextpdf.text.Font.BOLD); doc.add(measurmenttitle); int colmWidth = table.getColumnCount(); int rowCount = table.getModel().getRowCount(); PdfPTable resultTable = new PdfPTable(colmWidth); resultTable.setHorizontalAlignment(Element.ALIGN_LEFT); //add the table headers for (int i = 0; i < colmWidth; i++) { String headertext = table.getModel().getColumnName(i); PdfPCell cell = new PdfPCell(new Paragraph(headertext)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); resultTable.addCell(cell); } //add the table body for (int r = 0; r < rowCount; r++) { for (int c = 0; c < colmWidth; c++) { String data = table.getValueAt(r, c).toString(); resultTable.addCell(data); } } resultTable.setSpacingAfter(10); //add the table to the document doc.add(resultTable); } /** * add the parameters to the parameter detail tabPane * @param pgui */ public void addParameterTotheParameterDetailTabPane(TestParameterGUI pgui) { parameterCountIncreament(); //set its measurment setup class pgui.measurmentSetup = this; String title = pgui.getTestParameter().getParameterName() + " (" + pgui.getParameterTittle() + ")"; tabParametersDetail.add(title, pgui); //set the parameter location pgui.indexLocation = tabParametersDetail.getTabCount() - 1; } public void deleteParameterFromtheParameterDetailTabPane(TestParameterGUI pgui) { parameterCountDecrement(); if (tabParametersDetail.getTabCount() == 1) jTabbedPane1.setSelectedIndex(0); tabParametersDetail.remove(pgui.indexLocation); } /** * @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 ex) { java.util.logging.Logger.getLogger(MeasurmentSetup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(MeasurmentSetup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(MeasurmentSetup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(MeasurmentSetup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new MeasurmentSetup().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox capacitanceParameter; private javax.swing.JCheckBox currentParameter; private javax.swing.JLabel errorDisplay; private javax.swing.JLabel errorDisplay1; private javax.swing.JButton finishStep; private javax.swing.JCheckBox frequencyParameter; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItem_addmore; private javax.swing.JMenuItem jMenuItem_exportpdf; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel5; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JPopupMenu.Separator jSeparator1; private javax.swing.JTabbedPane jTabbedPane1; private javax.swing.JButton nextStep1; private javax.swing.JButton nextStep2; private javax.swing.JPanel panelStep2; private javax.swing.JPanel panelStep3; private javax.swing.JCheckBox powerParameter; private javax.swing.JTable recordTablePreview; private javax.swing.JCheckBox resistanceParameter; private javax.swing.JTabbedPane tabParametersDetail; private javax.swing.JLabel titleDisplay; private javax.swing.JTextField titleField; private javax.swing.JCheckBox voltageParameter; // End of variables declaration//GEN-END:variables }