/*
PseudoCode Interpreted Language (PCIL): Part of the algoviz@vt collection of algorithm visualizations.
Copyright (C) 2008 Brandon Malone, Frank Hadlock
This file is part of the PseudoCode Interpreted Language.
PseudoCode Interpreted Language is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
PseudoCode Interpreted Language is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along with
PseudoCode Interpreted Language. If not, see
.
*/
/*
* AnalyzerPanel.java
*
* Created on February 26, 2008, 11:07 AM
*/
package lex;
import java.awt.HeadlessException;
import java.io.IOException;
import javax.swing.JFileChooser;
/**
*
* @author Brandon
*/
public class AnalyzerPanel extends javax.swing.JPanel {
/** Creates new form AnalyzerPanel */
public AnalyzerPanel() {
initComponents();
// some defaults
this.tbSourceFile.setText("C:\\Users\\Brandon\\Documents\\JavaProjects\\DynamicMVC\\input\\Euclid.txt");
this.tbTokenFile.setText("C:\\Users\\Brandon\\Documents\\JavaProjects\\DynamicMVC\\input\\tokens.txt");
}
/** 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.
*/
// //GEN-BEGIN:initComponents
private void initComponents() {
jFileChooser1 = new javax.swing.JFileChooser();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
tbSourceFile = new javax.swing.JTextField();
tbTokenFile = new javax.swing.JTextField();
btnBrowseSourceFile = new javax.swing.JButton();
btnBrowseTokenFile = new javax.swing.JButton();
btnParse = new javax.swing.JButton();
setBorder(javax.swing.BorderFactory.createTitledBorder("Lexical Analysis"));
jLabel1.setText("Source File");
jLabel2.setText("Token File");
btnBrowseSourceFile.setText("Browse");
btnBrowseSourceFile.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnBrowseSourceFileMouseClicked(evt);
}
});
btnBrowseTokenFile.setText("Browse");
btnBrowseTokenFile.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnBrowseTokenFileMouseClicked(evt);
}
});
btnParse.setText("Parse");
btnParse.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnParseMouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tbTokenFile, javax.swing.GroupLayout.DEFAULT_SIZE, 259, Short.MAX_VALUE)
.addComponent(tbSourceFile, javax.swing.GroupLayout.DEFAULT_SIZE, 259, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(btnBrowseSourceFile)
.addComponent(btnBrowseTokenFile)))
.addComponent(btnParse, javax.swing.GroupLayout.Alignment.TRAILING))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(btnBrowseSourceFile)
.addComponent(tbSourceFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(btnBrowseTokenFile)
.addComponent(tbTokenFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnParse)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}// //GEN-END:initComponents
private void btnParseMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnParseMouseClicked
// TODO add your handling code here:
String sourceFilePath = tbSourceFile.getText();
String tokenFilePath = tbTokenFile.getText();
try {
Analyzer a = new Analyzer();
a.analyze(sourceFilePath, tokenFilePath);
javax.swing.JOptionPane.showMessageDialog(null, "The file has been successfully parsed.");
} catch (IOException ex) {
javax.swing.JOptionPane.showMessageDialog(null, "Encounterd an exception while parsing the file:\n" + ex.getMessage());
ex.printStackTrace();
}
}//GEN-LAST:event_btnParseMouseClicked
private void btnBrowseTokenFileMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnBrowseTokenFileMouseClicked
// TODO add your handling code here:
jFileChooser1.setFileSelectionMode(JFileChooser.FILES_ONLY);
if(this.jFileChooser1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
this.tbTokenFile.setText(jFileChooser1.getSelectedFile().getCanonicalPath());
} catch (IOException ex) {
javax.swing.JOptionPane.showMessageDialog(null, "Encounterd an exception while selecting the file:\n" + ex.getMessage());
ex.printStackTrace();
}
}
}//GEN-LAST:event_btnBrowseTokenFileMouseClicked
private void btnBrowseSourceFileMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnBrowseSourceFileMouseClicked
// TODO add your handling code here:
jFileChooser1.setFileSelectionMode(JFileChooser.FILES_ONLY);
if(this.jFileChooser1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
this.tbSourceFile.setText(jFileChooser1.getSelectedFile().getCanonicalPath());
} catch (IOException ex) {
javax.swing.JOptionPane.showMessageDialog(null, "Encounterd an exception while selecting the file:\n" + ex.getMessage());
ex.printStackTrace();
}
}
}//GEN-LAST:event_btnBrowseSourceFileMouseClicked
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnBrowseSourceFile;
private javax.swing.JButton btnBrowseTokenFile;
private javax.swing.JButton btnParse;
private javax.swing.JFileChooser jFileChooser1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField tbSourceFile;
private javax.swing.JTextField tbTokenFile;
// End of variables declaration//GEN-END:variables
}