Notice something wrong, missing, or inadequate? Feel free to edit pages yourself and make use of discussion pages.
Wiki content is created, maintained, and administrated by players. Learn how you can help!
Wiki content is created, maintained, and administrated by players. Learn how you can help!
Spells/Parsing/code:MainFrame.java
From SoDWiki
Jump to navigationJump to searchpackage com.zak.sod.extractor; /****************************************************************************** * The Main GUI class as well as the class that stores the main method. * Changes done here are mainly cosmetic. The GUI itself is very basic, * simply giving a quick way to change input and output files without * editing code. It doesn't do much else. Very little error checking, data * verification, comments, or other safeties are in place. * * * The MIT License * * Copyright (c) 2008 Zak-Corps. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * 1) Credit given in derivative works * 2) Notification prior to distribution of derivative works * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * Now that the legal stuff is out of the way, enjoy. * * @author Tyrsell * @author [email protected] * * Based on the work by: * @author Windcatcher from EQEmulator Forums * (http://www.eqemulator.net/forums/index.php ) * * @version 1.5 release 1/09/2008 ******************************************************************************/ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class MainFrame extends JFrame{ private JPanel leftPanel = new JPanel(); private JPanel upperLeftPanel = new JPanel(); private JPanel lowerLeftPanel = new JPanel(); private JPanel centerPanel = new JPanel(); private JPanel rightPanel = new JPanel(); private JPanel southPanel = new JPanel(); private JTextField messageField = new JTextField( 45 ); private JLabel upperLeftLabel = new JLabel(" Input File "); private JLabel lowerLeftLabel = new JLabel("Output File "); private JFileChooser chooser = new JFileChooser(); private JTextField upperLeftField = new JTextField(25); private JTextField lowerLeftField = new JTextField(25); private JButton browseButton = new JButton( "Browse" ); private JButton parseButton = new JButton( "Parse File" ); private JButton blankBrowseButton = new JButton( " View Formatted Spells " ); private File file = null; public MainFrame(){ super( "EQ Spell Parser by Tyrsell" ); initalize(); } public void initalize(){ this.setResizable( false ); // Initial setup of this window this.setSize(new Dimension(800, 300)); this.getContentPane().setLayout(new BorderLayout()); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //The left side! // Adds annoymous action listener to handle button event browseButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { browseDirectory(); } }); // Adds annoymous action listener to handle button event parseButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { parseFile(); } }); upperLeftPanel.add( upperLeftLabel ); upperLeftPanel.add( upperLeftField ); upperLeftField.setBackground( Color.WHITE ); upperLeftField.setText("C:\\Program Files\\Sony\\Everquest\\spells_us.txt"); upperLeftPanel.add( browseButton ); upperLeftPanel.add( parseButton ); lowerLeftField.setBackground( Color.WHITE ); lowerLeftField.setText("C:\\Spell_Output_File.txt"); lowerLeftPanel.add( lowerLeftLabel ); lowerLeftPanel.add( lowerLeftField ); blankBrowseButton.setEnabled( false ); lowerLeftPanel.add( blankBrowseButton ); leftPanel.setLayout( new BorderLayout() ); leftPanel.add( upperLeftPanel, BorderLayout.NORTH ); leftPanel.add( lowerLeftPanel, BorderLayout.SOUTH ); postMessage( "Please select the 'spells_us.txt' file from your Everquest directory."); southPanel.add( messageField ); messageField.setEditable( false ); messageField.setBackground( Color.GRAY ); messageField.setForeground( Color.WHITE ); // Sets up the final placement, then makes it visible this.getContentPane().add(leftPanel, BorderLayout.WEST); this.getContentPane().add(centerPanel, BorderLayout.CENTER); this.getContentPane().add(rightPanel, BorderLayout.EAST); this.getContentPane().add(southPanel, BorderLayout.SOUTH); this.pack(); this.setVisible(true); } protected void postMessage(String message){ messageField.setText( message ); } protected void parseFile() { if( !upperLeftField.getText().equals("")){ if( !lowerLeftField.getText().equals("")){ try { file = new File( upperLeftField.getText() ); postMessage( "Parsing File..."); Main.mainProcess( file.getCanonicalPath(), lowerLeftField.getText() ); postMessage( "Successful Parse!"); } catch (FileNotFoundException fnfe ) { postMessage( "The file 'spells_us.txt' could not be found at the specified location"); } catch (IOException ioe ) { postMessage( "Unknown I/O Error I. Please verify file locations and validity." ); } } else{ postMessage("An output file must be defined."); } } else{ postMessage("'spells_us.txt' has not been selected."); } } protected void browseDirectory() { int retval = chooser.showOpenDialog( this ); if (retval == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); try { // Update user interface. upperLeftField.setText( file.getCanonicalPath() ); } catch (IOException e) { postMessage( "Unknown I/O Error II. Please verify file locations and validity." ); } } } public static void main(String [] args){ new MainFrame(); } }