Java tutorial
/* Erudite v1.1.0 Copyright(c) 2013 Adam A Lara This software is dedicated to the pursuit of knowledge, the generations before(Dad) and after(Harrison) me, and the love of my life - Jord'an <3 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import au.com.bytecode.opencsv.CSVReader; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Image; import java.awt.Toolkit; import java.awt.Window; import java.awt.event.ActionEvent; import java.io.*; import java.net.URL; import java.net.URLDecoder; import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; import javax.swing.table.DefaultTableModel; import javax.swing.text.html.HTMLDocument; import javax.swing.text.html.HTMLEditorKit; import org.jdom2.*; import org.jdom2.input.*; import org.jdom2.input.sax.XMLReaderJDOMFactory; import org.jdom2.input.sax.XMLReaderXSDFactory; import org.jdom2.xpath.*; import org.xml.sax.InputSource; public class Erudite_gui extends javax.swing.JFrame implements FileHistory.IFileHistory { private FileHistory fileHistory; static volatile Document NNetMap; static double input[]; static double output[]; static String rsCNAME[]; static double inputRunset[][]; static double desiredOutput[]; static double tsInput[][]; static double tsOutput[][]; static String inputNID[]; static String outputNID[]; static String inputCNAME[]; static String outputCNAME[]; static int maxThreads; static int cycles; static int trainingCycles; /** Creates new form nmp_gui */ public Erudite_gui() throws UnsupportedEncodingException { super("NMP GUI"); try { // Set System L&F UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } URL imgPath = ClassLoader.getSystemResource("erudite-32x32icon.png"); Toolkit kit = Toolkit.getDefaultToolkit(); Image img = kit.createImage(imgPath); getFrame().setIconImage(img); initComponents(); Font font = new Font("Segoe UI", Font.PLAIN, 12); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; ((HTMLDocument) jEditorPane1.getDocument()).getStyleSheet().addRule(bodyRule); jTable1.getColumnModel().getColumn(0).setPreferredWidth(8); jTable2.getColumnModel().getColumn(0).setPreferredWidth(8); jTable2.getColumnModel().getColumn(2).setPreferredWidth(8); fileHistory = new FileHistory(this); // init FileHistory with our frame as the only parameter. fileHistory.initFileMenuHistory(); // Start file history initialization. clearUI(); maxThreads = java.lang.Runtime.getRuntime().availableProcessors(); } /** 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. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { buttonGroup1 = new javax.swing.ButtonGroup(); jPanel1 = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jComboBox1 = new javax.swing.JComboBox(); jButton2 = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jPanel3 = new javax.swing.JPanel(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jButton3 = new javax.swing.JButton(); jScrollPane3 = new javax.swing.JScrollPane(); jTable2 = new javax.swing.JTable(); jButton4 = new javax.swing.JButton(); jPanel4 = new javax.swing.JPanel(); jCheckBox1 = new javax.swing.JCheckBox(); jLabel9 = new javax.swing.JLabel(); jRadioButton2 = new javax.swing.JRadioButton(); jRadioButton3 = new javax.swing.JRadioButton(); jTextField3 = new javax.swing.JTextField(); jTextField4 = new javax.swing.JTextField(); jButton7 = new javax.swing.JButton(); jButton8 = new javax.swing.JButton(); jScrollPane4 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jLabel4 = new javax.swing.JLabel(); jCheckBox2 = new javax.swing.JCheckBox(); jCheckBox13 = new javax.swing.JCheckBox(); jCheckBox4 = new javax.swing.JCheckBox(); jRadioButton1 = new javax.swing.JRadioButton(); jTextField1 = new javax.swing.JTextField(); jPanel5 = new javax.swing.JPanel(); jScrollPane2 = new javax.swing.JScrollPane(); jTree1 = new javax.swing.JTree(); jScrollPane1 = new javax.swing.JScrollPane(); jEditorPane1 = new javax.swing.JEditorPane(); jProgressBar2 = new javax.swing.JProgressBar(); jButton1 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jLabel8 = new javax.swing.JLabel(); jButton9 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Erudite v1.1.0"); setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); setMaximumSize(new java.awt.Dimension(974, 724)); setMinimumSize(new java.awt.Dimension(974, 724)); setPreferredSize(new java.awt.Dimension(974, 724)); setResizable(false); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { formWindowClosing(evt); } }); jPanel1.setMaximumSize(new java.awt.Dimension(968, 710)); jPanel1.setMinimumSize(new java.awt.Dimension(968, 710)); jPanel1.setPreferredSize(new java.awt.Dimension(968, 710)); jPanel2.setBorder( javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder(""), "File Settings", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N jPanel2.setToolTipText("File settings, open and load different ANNeML files."); jPanel2.setMaximumSize(new java.awt.Dimension(230, 127)); jPanel2.setMinimumSize(new java.awt.Dimension(230, 127)); jLabel1.setText("File Select: "); jLabel1.setToolTipText("Currently selected/loaded ANNeML neural network"); jComboBox1.setToolTipText("Recently opened ANNeML files"); jComboBox1.setMaximumSize(new java.awt.Dimension(28, 20)); jComboBox1.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { jComboBox1ItemStateChanged(evt); } }); jComboBox1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jComboBox1ActionPerformed(evt); } }); jButton2.setText("Browse..."); jButton2.setToolTipText("Browse file system for valid ANNeML file to load"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jLabel2.setText("File Status"); jLabel2.setToolTipText("Current file status"); jLabel2.setMaximumSize(new java.awt.Dimension(50, 18)); jLabel2.setMinimumSize(new java.awt.Dimension(50, 18)); jLabel2.setPreferredSize(new java.awt.Dimension(50, 18)); jLabel3.setText("NNet Layout"); jLabel3.setToolTipText("Neural network layout"); jLabel3.setMaximumSize(new java.awt.Dimension(60, 18)); jLabel3.setMinimumSize(new java.awt.Dimension(60, 18)); jLabel3.setPreferredSize(new java.awt.Dimension(60, 18)); 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() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2).addGap(0, 0, Short.MAX_VALUE))) .addGap(14, 14, 14))); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton2)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(34, 34, 34))); jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Input Settings", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N jPanel3.setToolTipText("Data input settings for currently loaded ANNeML neural network."); jPanel3.setMaximumSize(new java.awt.Dimension(180, 121)); jPanel3.setMinimumSize(new java.awt.Dimension(180, 121)); jLabel6.setText("NNet Inputs: "); jLabel6.setToolTipText("Total number of inputs found in currently loaded ANNeML neural network"); jLabel6.setEnabled(false); jLabel7.setText("# of inputs"); jLabel7.setToolTipText("Total number of inputs found in currently loaded ANNeML neural network"); jLabel7.setEnabled(false); jLabel7.addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent evt) { jLabel7PropertyChange(evt); } }); jButton3.setText("Input Data"); jButton3.setToolTipText("Bring up prompt to input data for neural network processing. "); jButton3.setEnabled(false); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jTable2.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { }, new String[] { "Proc Run", "Neurode", "Input Value" }) { Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.String.class }; public Class getColumnClass(int columnIndex) { return types[columnIndex]; } }); jTable2.setToolTipText("Table of input neurodes found and their input values."); jScrollPane3.setViewportView(jTable2); jButton4.setText("Import Batch"); jButton4.setEnabled(false); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(jPanel3Layout.createSequentialGroup() .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) .addContainerGap())); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton4) .addGap(14, 14, 14)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE).addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap())); jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Training Settings", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N jPanel4.setToolTipText("Training settings for the currently loaded ANNeML neural network."); jPanel4.setMaximumSize(new java.awt.Dimension(451, 349)); jPanel4.setMinimumSize(new java.awt.Dimension(451, 349)); jCheckBox1.setText("Enable Training"); jCheckBox1.setToolTipText("Check to enable training mode for the currently loaded ANNeML neural network."); jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); jCheckBox1.setEnabled(false); jCheckBox1.setMargin(new java.awt.Insets(0, 0, 0, 0)); jCheckBox1.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { jCheckBox1StateChanged(evt); } }); jCheckBox1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jCheckBox1ActionPerformed(evt); } }); jLabel9.setText("Train to: "); jLabel9.setEnabled(false); buttonGroup1.add(jRadioButton2); jRadioButton2.setText("Avg. error <"); jRadioButton2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); jRadioButton2.setEnabled(false); jRadioButton2.setMargin(new java.awt.Insets(0, 0, 0, 0)); jRadioButton2.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { jRadioButton2StateChanged(evt); } }); jRadioButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton2ActionPerformed(evt); } }); buttonGroup1.add(jRadioButton3); jRadioButton3.setText("Epochs End"); jRadioButton3.setToolTipText(""); jRadioButton3.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); jRadioButton3.setEnabled(false); jRadioButton3.setMargin(new java.awt.Insets(0, 0, 0, 0)); jRadioButton3.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { jRadioButton3StateChanged(evt); } }); jRadioButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton3ActionPerformed(evt); } }); jTextField3.setEnabled(false); jTextField3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField3ActionPerformed(evt); } }); jTextField4.setEnabled(false); jTextField4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField4ActionPerformed(evt); } }); jButton7.setText("Enter Training Set"); jButton7.setToolTipText( "Bring up prompt to enter a training set for the currently loaded ANNeML neural network."); jButton7.setEnabled(false); jButton7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton7ActionPerformed(evt); } }); jButton8.setText("Import Training Set"); jButton8.setToolTipText( "Bring up file browser to load a premade training set as a comma seperated value(.csv) file."); jButton8.setEnabled(false); jButton8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton8ActionPerformed(evt); } }); jScrollPane4.setEnabled(false); jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { }, new String[] { "Example", "Neurode", "Value" }) { Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.String.class }; boolean[] canEdit = new boolean[] { false, false, false }; public Class getColumnClass(int columnIndex) { return types[columnIndex]; } public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); jTable1.setEnabled(false); jScrollPane4.setViewportView(jTable1); jLabel4.setText("Options:"); jLabel4.setEnabled(false); jCheckBox2.setText("Adaptable Learning"); jCheckBox2.setToolTipText( "Use adaptable learning. Learning rate decreases as error decreases. CPU intensive."); jCheckBox2.setEnabled(false); jCheckBox2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jCheckBox2ActionPerformed(evt); } }); jCheckBox13.setText("Random Training"); jCheckBox13.setToolTipText("Randomize training set(order) presentation."); jCheckBox13.setEnabled(false); jCheckBox4.setText("Auto-Save"); jCheckBox4.setToolTipText("Automatically save the ANNeML file after training."); jCheckBox4.setEnabled(false); buttonGroup1.add(jRadioButton1); jRadioButton1.setText("Correct % >"); jRadioButton1.setEnabled(false); jRadioButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton1ActionPerformed(evt); } }); jTextField1.setEnabled(false); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup( jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel4Layout .createSequentialGroup().addContainerGap().addGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent( jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) .addGroup(jPanel4Layout.createSequentialGroup() .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel4Layout.createSequentialGroup().addComponent(jLabel9) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jRadioButton3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jRadioButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(jRadioButton1).addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel4Layout.createSequentialGroup().addGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jCheckBox1) .addGroup(jPanel4Layout.createSequentialGroup().addComponent(jLabel4) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jCheckBox2).addGap(10, 10, 10) .addComponent(jCheckBox13).addGap(10, 10, 10) .addComponent(jCheckBox4))) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap())); jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup().addGap(8, 8, 8).addComponent(jCheckBox1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton7).addComponent(jButton8)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4).addComponent(jCheckBox2).addComponent(jCheckBox13) .addComponent(jCheckBox4)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel9).addComponent(jRadioButton3).addComponent(jRadioButton2) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jRadioButton1).addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel5.setBorder( javax.swing.BorderFactory.createTitledBorder(null, "Console", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N jPanel5.setToolTipText( "Console, view ANNeML neural network layout in tree format and see output from training/testing."); javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root"); jTree1.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1)); jTree1.setToolTipText("Currently loaded ANNeML neural network in tree layout."); jTree1.setCellRenderer(null); jScrollPane2.setViewportView(jTree1); jEditorPane1.setEditable(false); jEditorPane1.setContentType("text/html"); // NOI18N jScrollPane1.setViewportView(jEditorPane1); jEditorPane1.getAccessibleContext().setAccessibleName(""); jProgressBar2.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N jProgressBar2.setForeground(new java.awt.Color(0, 153, 255)); jProgressBar2.setString(""); jProgressBar2.setStringPainted(true); javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout.setHorizontalGroup(jPanel5Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jProgressBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 459, Short.MAX_VALUE)) .addContainerGap())); jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 426, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jProgressBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(16, 16, 16))); jButton1.setText("Run NNet"); jButton1.setToolTipText( "Run one iteration of the currently loaded ANNeML neural network with the inputted data values."); jButton1.setEnabled(false); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton5.setText("Save NNet"); jButton5.setToolTipText("Save the currently loaded ANNeML neural network to file."); jButton5.setEnabled(false); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/erudite.png"))); // NOI18N jLabel8.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jLabel8MouseClicked(evt); } }); jButton9.setText("Train NNet"); jButton9.setToolTipText( "Train the currently loaded ANNeML neural network using the training set entered and options selected."); jButton9.setEnabled(false); jButton9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton9ActionPerformed(evt); } }); 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(jPanel1Layout.createSequentialGroup().addGap(53, 53, 53) .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(31, 31, 31).addComponent(jLabel8).addGap(32, 32, 32).addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel1Layout.createSequentialGroup().addGap(181, 181, 181).addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap())); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING)) .addGap(30, 30, 30)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 687, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 724, Short.MAX_VALUE)); getAccessibleContext().setAccessibleName("Erudite"); getAccessibleContext().setAccessibleDescription(""); pack(); }// </editor-fold>//GEN-END:initComponents private void clearUI() { DefaultTableModel tblmodel = (DefaultTableModel) jTable1.getModel(); tblmodel.setRowCount(0); DefaultTableModel tblmodel2 = (DefaultTableModel) jTable2.getModel(); tblmodel2.setRowCount(0); NNetMap = null; jEditorPane1.setText(""); jEditorPane1.setCaretPosition(0); jLabel2.setText(""); jLabel3.setText(""); jLabel7.setText(""); jCheckBox1.setEnabled(false); jButton3.setEnabled(false); jButton4.setEnabled(false); jLabel7.setEnabled(false); jLabel6.setEnabled(false); jTree1.setModel(null); jComboBox1.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing exit(); }//GEN-LAST:event_formWindowClosing private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed //save nnet button/function try { SaveNet save = new SaveNet(); save.WriteFile(NNetMap, jComboBox1.getSelectedItem().toString()); } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(jPanel1, "Problem encountered while saving file\n" + e.toString(), "Warning", JOptionPane.WARNING_MESSAGE); } JOptionPane.showMessageDialog(jPanel1, (("File saved as:\n" + jComboBox1.getSelectedItem().toString()) + ".new.xml"), "File saved", JOptionPane.WARNING_MESSAGE); }//GEN-LAST:event_jButton5ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed //run nnet button/function jEditorPane1.setEnabled(true); jButton5.setEnabled(true); Erudite_gui.jProgressBar2.setMaximum(Erudite_gui.inputRunset.length); runCmd(); }//GEN-LAST:event_jButton1ActionPerformed private void runCmd() { Erudite_SW_runCmd worker = new Erudite_SW_runCmd(jEditorPane1) { @Override protected void done() { try { } catch (Exception e) { JOptionPane.showMessageDialog(null, JOptionPane.ERROR_MESSAGE); } } }; // Start the worker and setup ESC key listener/binding worker.cancelKey = 1; runCancelListen(worker); worker.execute(); } private void runCancelListen(final Erudite_SW_runCmd worker) { Action cancelAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { HTMLEditorKit kit = (HTMLEditorKit) jEditorPane1.getEditorKit(); HTMLDocument doc = (HTMLDocument) jEditorPane1.getDocument(); try { kit.insertHTML(doc, jEditorPane1.getCaretPosition(), "<b>Canceling Processing run...</b>", 0, 0, null); worker.cancelKey = -1; jPanel1.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke("ESCAPE"), "doSomething"); jPanel1.getActionMap().put("doSomething", null); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(jPanel1, "Option missing or in wrong format.", "Warning", JOptionPane.WARNING_MESSAGE); } } }; jPanel1.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("ESCAPE"), "doSomething"); jPanel1.getActionMap().put("doSomething", cancelAction); } private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed //enter training set DefaultTableModel tblmodel = (DefaultTableModel) jTable1.getModel(); tblmodel.setRowCount(0); String examples = JOptionPane.showInputDialog(jButton7, "How many examples in the set?", "Enter a Training Set", JOptionPane.QUESTION_MESSAGE); if (isInteger(examples) != true) { JOptionPane.showMessageDialog(null, "An integer must be entered."); } else { int i = 0; Erudite_gui.tsInput = new double[Integer.valueOf(examples)][inputNID.length]; Erudite_gui.tsOutput = new double[Integer.valueOf(examples)][outputNID.length]; do { tblmodel.addRow(new String[] { String.valueOf(i), null, null }); int x = 0; int y = 0; do { String entry = JOptionPane.showInputDialog(jButton7, "Desired Input for " + inputNID[x] + " (" + inputCNAME[x] + "):", "Training Example #" + String.valueOf(i + 1) + " Data Values", JOptionPane.QUESTION_MESSAGE); Erudite_gui.tsInput[i][x] = java.lang.Double.parseDouble(entry); tblmodel.addRow( new String[] { String.valueOf(i), inputNID[x] + " '" + inputCNAME[x] + "' ", entry }); x++; } while (x < inputNID.length); do { String entry = JOptionPane.showInputDialog(jButton7, "Desired Output for " + outputNID[y] + " (" + outputCNAME[y] + "):", "Training Example #" + String.valueOf(i + 1) + " Data Values", JOptionPane.QUESTION_MESSAGE); Erudite_gui.tsOutput[i][y] = java.lang.Double.parseDouble(entry); tblmodel.addRow( new String[] { String.valueOf(i), outputNID[y] + " '" + outputCNAME[y] + "' ", entry }); y++; } while (y < outputNID.length); i++; } while (i < Integer.valueOf(examples)); jButton9.setEnabled(true); } }//GEN-LAST:event_jButton7ActionPerformed private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField4ActionPerformed }//GEN-LAST:event_jTextField4ActionPerformed private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField3ActionPerformed }//GEN-LAST:event_jTextField3ActionPerformed private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton3ActionPerformed jTextField4.setEnabled(true); if (jTextField3.isEnabled()) { jTextField3.setEnabled(false); } if (jTextField1.isEnabled()) { jTextField1.setEnabled(false); } }//GEN-LAST:event_jRadioButton3ActionPerformed private void jRadioButton3StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jRadioButton3StateChanged }//GEN-LAST:event_jRadioButton3StateChanged private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed jTextField3.setEnabled(true); if (jTextField4.isEnabled()) { jTextField4.setEnabled(false); } if (jTextField1.isEnabled()) { jTextField1.setEnabled(false); } }//GEN-LAST:event_jRadioButton2ActionPerformed private void jRadioButton2StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jRadioButton2StateChanged }//GEN-LAST:event_jRadioButton2StateChanged private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed if (this.jCheckBox1.isSelected() == false) { jButton3.setEnabled(true); jButton4.setEnabled(true); jLabel6.setEnabled(true); jLabel7.setEnabled(true); jPanel3.setEnabled(true); jTextField4.setText(""); jTextField3.setText(""); jTextField1.setText(""); jLabel4.setEnabled(false); jCheckBox2.setEnabled(false); jCheckBox13.setEnabled(false); jCheckBox4.setEnabled(false); jButton7.setEnabled(false); jButton8.setEnabled(false); jButton9.setEnabled(false); jButton5.setEnabled(false); jLabel9.setEnabled(false); jRadioButton1.setEnabled(false); jTextField1.setEnabled(false); jRadioButton2.setEnabled(false); jTextField4.setEnabled(false); jRadioButton3.setEnabled(false); buttonGroup1.clearSelection(); } else if (this.jCheckBox1.isSelected() == true) { jButton3.setEnabled(false); jButton4.setEnabled(false); jLabel6.setEnabled(false); jLabel7.setEnabled(false); jPanel3.setEnabled(false); jTextField4.setText("1"); jTextField3.setText("0.10"); jTextField1.setText("90"); jLabel4.setEnabled(true); jCheckBox2.setEnabled(true); jCheckBox13.setEnabled(true); jCheckBox4.setEnabled(true); jButton7.setEnabled(true); jButton8.setEnabled(true); jLabel9.setEnabled(true); jTextField4.setEnabled(true); jRadioButton1.setEnabled(true); jRadioButton2.setEnabled(true); jRadioButton3.setEnabled(true); jRadioButton3.setSelected(true); } }//GEN-LAST:event_jCheckBox1ActionPerformed private void jCheckBox1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBox1StateChanged }//GEN-LAST:event_jCheckBox1StateChanged private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed //input data int iN = 0; DefaultTableModel tblmodel = (DefaultTableModel) jTable2.getModel(); tblmodel.setRowCount(0); String examples = JOptionPane.showInputDialog(jButton3, "How many examples in this processing run?", "Enter a Processing Run", JOptionPane.QUESTION_MESSAGE); if (isInteger(examples) != true) { JOptionPane.showMessageDialog(null, "An integer must be entered."); } else { int i = 0; Erudite_gui.inputRunset = new double[Integer.valueOf(examples)][inputNID.length]; Erudite_gui.rsCNAME = new String[Integer.valueOf(examples)]; do { String exName = JOptionPane.showInputDialog(jButton7, "Enter a name for this run example:", "Processing Run #" + String.valueOf(i + 1) + " Data Values", JOptionPane.QUESTION_MESSAGE); Erudite_gui.rsCNAME[i] = exName; tblmodel.addRow(new String[] { rsCNAME[i], null, null }); int x = 0; int y = 0; do { String entry = JOptionPane.showInputDialog(jButton7, "Desired Input for " + inputNID[x] + " (" + inputCNAME[x] + "):", "Processing Run #" + String.valueOf(i + 1) + " Data Values", JOptionPane.QUESTION_MESSAGE); Erudite_gui.inputRunset[i][x] = java.lang.Double.parseDouble(entry); tblmodel.addRow(new String[] { rsCNAME[i], inputNID[x] + " '" + inputCNAME[x] + "' ", entry }); x++; } while (x < inputNID.length); i++; } while (i < Integer.valueOf(examples)); jButton1.setEnabled(true); } }//GEN-LAST:event_jButton3ActionPerformed private void jLabel7PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jLabel7PropertyChange }//GEN-LAST:event_jLabel7PropertyChange private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed //Browse/Load file button JFileChooser fc = new JFileChooser(); xFilter x1 = new xFilter(); fc.setFileFilter(x1); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); int returnVal = fc.showOpenDialog(jButton2); if (returnVal == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); if (f == null) { return; } if (f.getName().equals("")) { return; } String path = f.getAbsolutePath(); String name = f.getName(); fileHistory.insertPathname(path, name); // Hook into FileHistory class. loadFile(path, name); // Do the file processing activity in the application. } }//GEN-LAST:event_jButton2ActionPerformed private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed loadFile((String) fileHistory.pathnameHistory.get(jComboBox1.getSelectedIndex()), (String) fileHistory.itemnameHistory.get(jComboBox1.getSelectedIndex())); }//GEN-LAST:event_jComboBox1ActionPerformed private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox1ItemStateChanged }//GEN-LAST:event_jComboBox1ItemStateChanged private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed //train NNet button/function Erudite_gui.jProgressBar2.setMaximum(Erudite_gui.tsInput.length); trainCmd(); }//GEN-LAST:event_jButton9ActionPerformed private void trainCmd() { final Erudite_SW_trainCmd worker = new Erudite_SW_trainCmd(jEditorPane1) { @Override protected void done() { try { jButton5.setEnabled(true); } catch (Exception e) { JOptionPane.showMessageDialog(null, JOptionPane.ERROR_MESSAGE); } } }; // Start the worker and setup ESC key listener/binding worker.cancelKey = 1; trainCancelListen(worker); worker.execute(); } private void trainCancelListen(final Erudite_SW_trainCmd worker) { Action cancelAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { HTMLEditorKit kit = (HTMLEditorKit) jEditorPane1.getEditorKit(); HTMLDocument doc = (HTMLDocument) jEditorPane1.getDocument(); try { kit.insertHTML(doc, jEditorPane1.getCaretPosition(), "<b>Canceling Training...</b>", 0, 0, null); worker.cancelKey = -1; jPanel1.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke("ESCAPE"), "doSomething"); jPanel1.getActionMap().put("doSomething", null); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(jPanel1, "Option missing or in wrong format.", "Warning", JOptionPane.WARNING_MESSAGE); } } }; jPanel1.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("ESCAPE"), "doSomething"); jPanel1.getActionMap().put("doSomething", cancelAction); } private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed //Import training set .csv import function/button /* DefaultTableModel tblmodel = (DefaultTableModel) jTable1.getModel(); tblmodel.setRowCount(0); JFileChooser fc = new JFileChooser(); csvFilter filter= new csvFilter(); fc.setFileFilter(filter); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); int returnVal = fc.showOpenDialog(jButton8); if (returnVal == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); if (f == null) { return; } if (f.getName().equals("")) { return; } try { CSVReader reader = new CSVReader(new FileReader(f)); String [] csvLine; if ((csvLine = reader.readNext()) != null) { int examples = java.lang.Integer.parseInt(csvLine[0]); int inputs = java.lang.Integer.parseInt(csvLine[1]); int outputs = java.lang.Integer.parseInt(csvLine[2]); if (inputs!=Erudite_gui.inputNID.length) { JOptionPane.showMessageDialog(jPanel1, "CSV inputs do not match ANNeML file inputs.","Warning", JOptionPane.WARNING_MESSAGE); return; } if (outputs!=Erudite_gui.outputNID.length) { JOptionPane.showMessageDialog(jPanel1, "CSV outputs do not match ANNeML file outputs.","Warning", JOptionPane.WARNING_MESSAGE); return; } else{ Erudite_gui.tsInput=new double[examples][inputs]; Erudite_gui.tsOutput=new double[examples][outputs]; int x=0; int inCnt=0; int outCnt=0; do{ tblmodel.addRow(new String[]{String.valueOf(x+1), null, null}); int y=0; int z=0; do{ Erudite_gui.tsInput[x][y]=java.lang.Double.parseDouble(csvLine[3+inCnt+y]); tblmodel.addRow(new String[]{String.valueOf(x+1), inputNID[y] + " '" + inputCNAME[y] + "' ", csvLine[3+inCnt+y]}); y++; }while(y<inputs); inCnt+=inputs+outputs; do{ Erudite_gui.tsOutput[x][z]=java.lang.Double.parseDouble(csvLine[3+inputs+outCnt+z]); tblmodel.addRow(new String[]{String.valueOf(x+1), outputNID[z] + " '" + outputCNAME[z] + "' ", csvLine[3+inputs+outCnt+z]}); z++; }while(z<outputs); outCnt+=outputs+inputs; x++; }while(x<examples); jButton9.setEnabled(true); HTMLEditorKit kit = (HTMLEditorKit)jEditorPane1.getEditorKit(); HTMLDocument doc = (HTMLDocument)jEditorPane1.getDocument(); kit.insertHTML(doc, jEditorPane1.getCaretPosition(),"<b>Training set csv loaded successfully.</b><br>Training examples in set: " + examples + "<br>Inputs per example: " + inputs + "<br>Outputs per example: " + outputs + "<br><br>", 0, 0,null); } } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(jPanel1, "Option missing or in wrong format.","Warning", JOptionPane.WARNING_MESSAGE); } } */ DefaultTableModel tblmodel = (DefaultTableModel) jTable1.getModel(); tblmodel.setRowCount(0); JFileChooser fc = new JFileChooser(); csvFilter filter = new csvFilter(); fc.setFileFilter(filter); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); int returnVal = fc.showOpenDialog(jButton3); if (returnVal == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); if (f == null) { return; } if (f.getName().equals("")) { return; } try { CSVReader reader = new CSVReader(new FileReader(f)); String[] headerLine; if ((headerLine = reader.readNext()) != null) { int examples = java.lang.Integer.parseInt(headerLine[0]); int inputs = java.lang.Integer.parseInt(headerLine[1]); int outputs = java.lang.Integer.parseInt(headerLine[2]); Erudite_gui.tsInput = new double[examples][inputs]; Erudite_gui.tsOutput = new double[examples][outputs]; CSVReader readerData = new CSVReader(new FileReader(f), ',', '/', 1); String[] csvLine; int x = 0; do { tblmodel.addRow(new String[] { String.valueOf(x + 1), null, null }); int y = 0; int z = 0; csvLine = readerData.readNext(); do { Erudite_gui.tsInput[x][y] = java.lang.Double.parseDouble(csvLine[y]); tblmodel.addRow(new String[] { String.valueOf(x + 1), inputNID[y] + " '" + inputCNAME[y] + "' ", csvLine[y] }); y++; } while (y < inputs); csvLine = readerData.readNext(); do { Erudite_gui.tsOutput[x][z] = java.lang.Double.parseDouble(csvLine[z]); tblmodel.addRow(new String[] { String.valueOf(x + 1), outputNID[z] + " '" + outputCNAME[z] + "' ", csvLine[z] }); z++; } while (z < outputs); x++; } while (x < examples); jButton9.setEnabled(true); HTMLEditorKit kit = (HTMLEditorKit) jEditorPane1.getEditorKit(); HTMLDocument doc = (HTMLDocument) jEditorPane1.getDocument(); kit.insertHTML(doc, jEditorPane1.getCaretPosition(), "<b>Processing set csv loaded successfully.</b><br>Examples to run: " + examples + "<br>Inputs per example: " + inputs + "<br>", 0, 0, null); } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(jPanel1, "Option missing or in wrong format.", "Warning", JOptionPane.WARNING_MESSAGE); } } }//GEN-LAST:event_jButton8ActionPerformed private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox2ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jCheckBox2ActionPerformed private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed // TODO add your handling code here: jTextField1.setEnabled(true); if (jTextField4.isEnabled()) { jTextField4.setEnabled(false); } if (jTextField3.isEnabled()) { jTextField3.setEnabled(false); } }//GEN-LAST:event_jRadioButton1ActionPerformed private void jLabel8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel8MouseClicked //pop-up about/copyright/license jdialog JOptionPane.showMessageDialog(jPanel1, "Erudite v1.1.0 Copyright(c) 2013 Adam A Lara\nErudite is distributed under an Apache v2 open source license\nSee LICENSE file for full license terms.\nErudite utilizes the ANNeML XML specification, released under Creative Commons.\nErudite includes software developed by the JDOM Project(www.jdom.org)", "About Erudite", JOptionPane.PLAIN_MESSAGE); }//GEN-LAST:event_jLabel8MouseClicked private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed //Import process batch run .csv function/button DefaultTableModel tblmodel = (DefaultTableModel) jTable2.getModel(); tblmodel.setRowCount(0); JFileChooser fc = new JFileChooser(); csvFilter filter = new csvFilter(); fc.setFileFilter(filter); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); int returnVal = fc.showOpenDialog(jButton3); if (returnVal == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); if (f == null) { return; } if (f.getName().equals("")) { return; } try { CSVReader reader = new CSVReader(new FileReader(f)); String[] headerLine; if ((headerLine = reader.readNext()) != null) { int examples = java.lang.Integer.parseInt(headerLine[0]); int inputs = java.lang.Integer.parseInt(headerLine[1]); Erudite_gui.inputRunset = new double[examples][inputs]; Erudite_gui.rsCNAME = new String[examples]; CSVReader readerData = new CSVReader(new FileReader(f), ',', '/', 1); String[] csvLine; int x = 0; do { csvLine = readerData.readNext(); rsCNAME[x] = csvLine[0]; csvLine = readerData.readNext(); tblmodel.addRow(new String[] { rsCNAME[x], null, null }); int y = 0; do { Erudite_gui.inputRunset[x][y] = java.lang.Double.parseDouble(csvLine[y]); tblmodel.addRow(new String[] { rsCNAME[x], inputNID[y] + " '" + inputCNAME[y] + "' ", csvLine[y] }); y++; } while (y < inputs); x++; } while (x < examples); jButton1.setEnabled(true); HTMLEditorKit kit = (HTMLEditorKit) jEditorPane1.getEditorKit(); HTMLDocument doc = (HTMLDocument) jEditorPane1.getDocument(); kit.insertHTML(doc, jEditorPane1.getCaretPosition(), "<b>Processing set csv loaded successfully.</b><br>Examples to run: " + examples + "<br>Inputs per example: " + inputs + "<br>", 0, 0, null); } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(jPanel1, "Option missing or in wrong format.", "Warning", JOptionPane.WARNING_MESSAGE); } } }//GEN-LAST:event_jButton4ActionPerformed public boolean isInteger(String string) { try { Integer.valueOf(string); return true; } catch (NumberFormatException e) { return false; } } public boolean isDouble(String string) { try { Double.parseDouble(string); return true; } catch (NumberFormatException e) { return false; } } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { Erudite_gui E = null; try { E = new Erudite_gui(); } catch (UnsupportedEncodingException ex) { Logger.getLogger(Erudite_gui.class.getName()).log(Level.SEVERE, null, ex); } centerWindow(E); E.setVisible(true); } }); } public static void centerWindow(Window frame) { Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - frame.getWidth()) / 2); int y = (int) ((dimension.getHeight() - frame.getHeight()) / 2); frame.setLocation(x, y); } public String getApplicationName() { return "Erudite"; } public JComboBox getFileMenu() { return this.jComboBox1; } public JFrame getFrame() { return this; } public Dimension getSize() { return super.getSize(); } public void loadFile(String pathname, String filename) { jLabel6.setEnabled(true); jLabel7.setEnabled(true); jButton3.setEnabled(true); jButton4.setEnabled(true); jCheckBox1.setSelected(false); jCheckBox1.setEnabled(true); jEditorPane1.setEnabled(true); DefaultTableModel tblmodel = (DefaultTableModel) jTable2.getModel(); tblmodel.setRowCount(0); try { // Build & creat the document with SAX, use XML schema validation URL path = ClassLoader.getSystemResource("ANNeML.xsd"); if (path.getFile() == null) { jLabel2.setForeground(Color.RED); jLabel2.setText("error loading XML schema"); } else { //File argylexsd = new File(path.toURI()); //XMLReaderJDOMFactory schemafac = new XMLReaderXSDFactory(argylexsd); XMLReaderJDOMFactory schemafac = new XMLReaderXSDFactory("ANNeML.xsd"); //***for .jar deployment SAXBuilder builder = new SAXBuilder(schemafac); Erudite_gui.NNetMap = builder.build(pathname); JDOMToTreeModelAdapter model = new JDOMToTreeModelAdapter(Erudite_gui.NNetMap); XMLTreeCellRenderer renderer = new XMLTreeCellRenderer(); jTree1.setCellRenderer(renderer); jTree1.setModel(model); java.util.List subnets = XPath.newInstance("//SUBNET").selectNodes(Erudite_gui.NNetMap); java.util.List layers = XPath.newInstance("//LAYER").selectNodes(Erudite_gui.NNetMap); java.util.List inputNeurodes = XPath.newInstance("//NEURODE[SYNAPSE/@ORG_NEURODE='INPUT']") .selectNodes(Erudite_gui.NNetMap); java.util.List hiddenNeurodes = XPath.newInstance("//LAYER[@LAYER_NAME='HIDDEN']/NEURODE") .selectNodes(Erudite_gui.NNetMap); java.util.List outputNeurodes = XPath.newInstance("//LAYER[@LAYER_NAME='OUTPUT']/NEURODE") .selectNodes(Erudite_gui.NNetMap); Color colr = new Color(0, 153, 255); jLabel2.setForeground(colr); jLabel2.setText("Valid ANNeML file."); HTMLEditorKit kit = (HTMLEditorKit) jEditorPane1.getEditorKit(); HTMLDocument doc = (HTMLDocument) jEditorPane1.getDocument(); kit.insertHTML(doc, jEditorPane1.getCaretPosition(), "<b>" + filename + " loaded...</b>", 0, 0, null); jLabel3.setText("Subnet(s): " + subnets.size() + " Layers: " + layers.size() + " Inputs: " + inputNeurodes.size() + " Hidden: " + hiddenNeurodes.size() + " Outputs: " + outputNeurodes.size()); jLabel7.setText(java.lang.String.valueOf(inputNeurodes.size())); Erudite_gui.inputNID = new String[inputNeurodes.size()]; Erudite_gui.inputCNAME = new String[inputNeurodes.size()]; Erudite_gui.outputNID = new String[outputNeurodes.size()]; Erudite_gui.outputCNAME = new String[outputNeurodes.size()]; int i = 0; for (Iterator it = inputNeurodes.iterator(); it.hasNext();) { Element InputNode = (Element) it.next(); Erudite_gui.inputNID[i] = InputNode.getAttributeValue("N_ID"); Erudite_gui.inputCNAME[i] = InputNode.getAttributeValue("CNAME"); tblmodel.addRow( new String[] { null, Erudite_gui.inputNID[i] + " '" + inputCNAME[i] + "' ", null }); kit.insertHTML(doc, jEditorPane1.getCaretPosition(), "<b>" + inputNID[i] + "</b> " + inputCNAME[i] + "<br>", 0, 0, null); i++; } int y = 0; for (Iterator it = outputNeurodes.iterator(); it.hasNext();) { Element OutputNode = (Element) it.next(); Erudite_gui.outputCNAME[y] = OutputNode.getAttributeValue("CNAME"); Erudite_gui.outputNID[y] = OutputNode.getAttributeValue("N_ID"); kit.insertHTML(doc, jEditorPane1.getCaretPosition(), "<b>" + outputNID[y] + "</b> " + outputCNAME[y] + "<br>", 0, 0, null); y++; } kit.insertHTML(doc, jEditorPane1.getCaretPosition(), "Ready for input processing or training...<br><br>", 0, 0, null); } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(jPanel1, "There was an error parsing the file.\n" + e.toString(), "Warning", JOptionPane.WARNING_MESSAGE); } } private void exit() { setVisible(false); dispose(); fileHistory.saveHistoryEntries(); // Save pathname entries for next session. System.exit(0); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.ButtonGroup buttonGroup1; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JButton jButton7; private javax.swing.JButton jButton8; private javax.swing.JButton jButton9; private javax.swing.JCheckBox jCheckBox1; public static javax.swing.JCheckBox jCheckBox13; public static javax.swing.JCheckBox jCheckBox2; public static javax.swing.JCheckBox jCheckBox4; public static javax.swing.JComboBox jComboBox1; public static javax.swing.JEditorPane jEditorPane1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; 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.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel5; public static javax.swing.JProgressBar jProgressBar2; public static javax.swing.JRadioButton jRadioButton1; public static javax.swing.JRadioButton jRadioButton2; public static javax.swing.JRadioButton jRadioButton3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JScrollPane jScrollPane4; private javax.swing.JTable jTable1; private javax.swing.JTable jTable2; public static javax.swing.JTextField jTextField1; public static javax.swing.JTextField jTextField3; public static javax.swing.JTextField jTextField4; private javax.swing.JTree jTree1; // End of variables declaration//GEN-END:variables }