Skip to content

anonymous /gist:1039379

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* GUI.java
*
* Created on Jun 17, 2011, 3:57:27 PM
*/
package ircbotgui;
import java.awt.Color;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
/**
*
* @author Malte
*/
public class GUI extends javax.swing.JFrame {
/** Creates new form GUI */
public GUI() {
initComponents();
}
/** 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">
private void initComponents() {
nickLbl = new javax.swing.JLabel();
serverLbl = new javax.swing.JLabel();
portLbl = new javax.swing.JLabel();
nickFld = new javax.swing.JTextField();
serverFld = new javax.swing.JTextField();
portFld = new javax.swing.JTextField();
servConnectBtn = new javax.swing.JButton();
chanLbl = new javax.swing.JLabel();
chanFld = new javax.swing.JTextField();
joinBtn = new javax.swing.JButton();
partBtn = new javax.swing.JButton();
sayLbl = new javax.swing.JLabel();
sayFld = new javax.swing.JTextField();
sayBtn = new javax.swing.JButton();
pwLbl = new javax.swing.JLabel();
pwFld = new javax.swing.JTextField();
jSeparator1 = new javax.swing.JSeparator();
defNickBtn = new javax.swing.JButton();
defPassBtn = new javax.swing.JButton();
defServBtn = new javax.swing.JButton();
defPortBtn = new javax.swing.JButton();
defChanBtn = new javax.swing.JButton();
clearErrBtn = new javax.swing.JButton();
clearErrFileBtn = new javax.swing.JButton();
clearConfButton = new javax.swing.JButton();
noPassChk = new javax.swing.JCheckBox();
jTabbedPane1 = new javax.swing.JTabbedPane();
jScrollPane1 = new javax.swing.JScrollPane();
rawOutPane = new javax.swing.JTextPane();
jScrollPane3 = new javax.swing.JScrollPane();
debugOutPane = new javax.swing.JTextPane();
jScrollPane2 = new javax.swing.JScrollPane();
servOutPane = new javax.swing.JTextPane();
jScrollPane4 = new javax.swing.JScrollPane();
chanOutPane = new javax.swing.JTextPane();
jTabbedPane2 = new javax.swing.JTabbedPane();
txtPane2 = new javax.swing.JScrollPane();
errPane = new javax.swing.JTextPane();
jScrollPane5 = new javax.swing.JScrollPane();
sysPane = new javax.swing.JTextPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
nickLbl.setText("Nickname:");
serverLbl.setText("Server:");
portLbl.setText("Port:");
servConnectBtn.setText("Connect to Server");
servConnectBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
servConnectBtnActionPerformed(evt);
}
});
chanLbl.setText("Channel: #");
joinBtn.setText("Join Channel");
partBtn.setText("Part Channel");
sayLbl.setText("Say:");
sayBtn.setText("Say");
pwLbl.setText("Password:");
defNickBtn.setText("Set Default");
defNickBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
defNickBtnActionPerformed(evt);
}
});
defPassBtn.setText("Set Default");
defPassBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
defPassBtnActionPerformed(evt);
}
});
defServBtn.setText("Set Default");
defServBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
defServBtnActionPerformed(evt);
}
});
defPortBtn.setText("Set Default");
defPortBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
defPortBtnActionPerformed(evt);
}
});
defChanBtn.setText("Add to default channel list");
defChanBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
defChanBtnActionPerformed(evt);
}
});
clearErrBtn.setText("Clear error logs");
clearErrBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearErrBtnActionPerformed(evt);
}
});
clearErrFileBtn.setText("Clear error file");
clearErrFileBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearErrFileBtnActionPerformed(evt);
}
});
clearConfButton.setText("Clear config file");
clearConfButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearConfButtonActionPerformed(evt);
}
});
noPassChk.setText("Connect without password");
jScrollPane1.setViewportView(rawOutPane);
jTabbedPane1.addTab("Raw", jScrollPane1);
jScrollPane3.setViewportView(debugOutPane);
jTabbedPane1.addTab("Parsing + Debug", jScrollPane3);
jScrollPane2.setViewportView(servOutPane);
jTabbedPane1.addTab("Server", jScrollPane2);
jScrollPane4.setViewportView(chanOutPane);
jTabbedPane1.addTab("Channel", jScrollPane4);
errPane.setDisabledTextColor(new java.awt.Color(204, 0, 0));
txtPane2.setViewportView(errPane);
jTabbedPane2.addTab("Error Output", txtPane2);
jScrollPane5.setViewportView(sysPane);
jTabbedPane2.addTab("System Output", jScrollPane5);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().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)
.addGroup(layout.createSequentialGroup()
.addComponent(portLbl)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(portFld, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(defPortBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(serverLbl)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(serverFld, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(defServBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(nickLbl)
.addComponent(pwLbl))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(pwFld, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
.addComponent(nickFld, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(defNickBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)
.addComponent(defPassBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)))
.addGroup(layout.createSequentialGroup()
.addComponent(sayLbl)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(sayFld, javax.swing.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE))
.addComponent(servConnectBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
.addComponent(sayBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(joinBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(partBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(chanLbl)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(chanFld, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(defChanBtn))
.addGroup(layout.createSequentialGroup()
.addComponent(clearErrBtn)
.addGap(18, 18, 18)
.addComponent(clearErrFileBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(clearConfButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(noPassChk))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1050, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 1441, Short.MAX_VALUE)
.addComponent(jTabbedPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 1441, Short.MAX_VALUE))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {nickLbl, portLbl, pwLbl, serverLbl});
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {chanFld, nickFld, portFld, pwFld, serverFld});
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {chanLbl, sayLbl});
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {defChanBtn, defNickBtn, defPassBtn, defPortBtn, defServBtn});
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {clearConfButton, clearErrBtn});
layout.setVerticalGroup(
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.BASELINE)
.addComponent(nickLbl)
.addComponent(nickFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(defNickBtn))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(pwLbl)
.addComponent(pwFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(defPassBtn))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(serverLbl)
.addComponent(serverFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(defServBtn))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(portLbl)
.addComponent(portFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(defPortBtn))
.addGap(14, 14, 14)
.addComponent(servConnectBtn)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(chanLbl)
.addComponent(chanFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(defChanBtn))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(joinBtn)
.addComponent(partBtn))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(sayLbl)
.addComponent(sayFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(sayBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 60, Short.MAX_VALUE)
.addComponent(noPassChk)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(clearConfButton)
.addComponent(clearErrFileBtn)
.addComponent(clearErrBtn)))
.addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 418, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTabbedPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 287, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void clearConfButtonActionPerformed(java.awt.event.ActionEvent evt) {
init();
int confirm = JOptionPane.showConfirmDialog(null, "Warning, this will erease all default options", null, JOptionPane.OK_CANCEL_OPTION);
if (confirm == JOptionPane.OK_OPTION) {
try {
confWriter.write("");
} catch (IOException ioe) {
try {
errWriter.write(ioe.getMessage());
logError(ioe);
} catch (IOException ioe2) {
Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ioe2);
}
}
}
close();
}
private void clearErrFileBtnActionPerformed(java.awt.event.ActionEvent evt) {
init();
int confirm = JOptionPane.showConfirmDialog(null, "Warning, this will erease all error logs", null, JOptionPane.OK_CANCEL_OPTION);
if (confirm == JOptionPane.OK_OPTION) {
try {
errWriter.write("");
} catch (IOException ioe) {
try {
errWriter.write(ioe.getMessage());
logError(ioe);
} catch (IOException ioe2) {
Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ioe2);
}
}
}
close();
}
private void clearErrBtnActionPerformed(java.awt.event.ActionEvent evt) {
errPane.setText("");
}
private void servConnectBtnActionPerformed(java.awt.event.ActionEvent evt) {
String server = serverFld.getText(), port = portFld.getText(), nick = nickFld.getText(), pw = pwFld.getText();
System.out.println("//" + server + "//" + port + "//" + nick + "//" + pw + "//");
if (!server.equalsIgnoreCase("") && !port.equalsIgnoreCase("")) {
if (!nick.equalsIgnoreCase("")) {
if (!pw.equalsIgnoreCase("")) {
bot.connect(server, Integer.parseInt(port), nick, pw);
} else {
boolean flag = noPassChk.isEnabled();
bot.connect(server, Integer.parseInt(port), nick, flag);
}
} else {
bot.connect(server, Integer.parseInt(port));
}
} else {
if(!(bot.server == null) && !(bot.server.equalsIgnoreCase("")) && !(bot.port == 0)) {
bot.connect();
}
else {
logError("Not enough arguments for action \"connect\": Given: none, Required: (server, port (, nick (, password)))");
appendSys("Need at least server and port to connect");
}
}
}
private void defNickBtnActionPerformed(java.awt.event.ActionEvent evt) {
String confText = "", line = null;
Boolean flag = false;
try {
while ((line = confReader.readLine()) != null) {
if (!line.startsWith("defNick=")) {
confText += line + "\n";
} else {
confText += "defNick=" + nickFld.getText() + "\n";
appendSys("Replaced default nick " + line.substring(line.indexOf("=") + 1) + " with " + nickFld.getText());
flag = true;
}
}
if (!flag) {
appendSys("Set default nickname: " + nickFld.getText());
confText += "defNick=" + nickFld.getText() + "\r\n";
}
confWriter.write(confText);
confWriter.flush();
} catch (IOException ioe) {
try {
errWriter.write(ioe.toString());
errWriter.flush();
logError(ioe);
} catch (IOException ex) {
Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
private void defPassBtnActionPerformed(java.awt.event.ActionEvent evt) {
String confText = "", line = null;
Boolean flag = false;
try {
while ((line = confReader.readLine()) != null) {
if (!line.startsWith("defPass=")) {
confText += line + "\n";
} else {
confText += "defPass=" + pwFld.getText() + "\n";
appendSys("Replaced default password " + line.substring(line.indexOf("=") + 1) + " with " + pwFld.getText());
flag = true;
}
}
if (!flag) {
confText += "defPass=" + pwFld.getText() + "\r\n";
appendSys("Set default password: " + pwFld.getText());
}
confWriter.write(confText);
confWriter.flush();
} catch (IOException ioe) {
try {
errWriter.write(ioe.toString());
errWriter.flush();
logError(ioe);
} catch (IOException ex) {
Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
private void defServBtnActionPerformed(java.awt.event.ActionEvent evt) {
String confText = "", line = null;
Boolean flag = false;
try {
while ((line = confReader.readLine()) != null) {
if (!line.startsWith("defServ=")) {
confText += line + "\n";
} else {
confText += "defServ=" + serverFld.getText() + "\n";
appendSys("Replaced default server " + line.substring(line.indexOf("=") + 1) + " with " + serverFld.getText());
flag = true;
}
}
if (!flag) {
confText += "defServ=" + serverFld.getText() + "\r\n";
appendSys("Set default server: " + serverFld.getText());
}
confWriter.write(confText);
confWriter.flush();
} catch (IOException ioe) {
try {
errWriter.write(ioe.toString());
logError(ioe);
errWriter.flush();
} catch (IOException ex) {
Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
private void defPortBtnActionPerformed(java.awt.event.ActionEvent evt) {
String confText = "", line = null;
Boolean flag = false;
try {
while ((line = confReader.readLine()) != null) {
if (!line.startsWith("defPort=")) {
confText += line + "\n";
} else {
confText += "defPort=" + portFld.getText() + "\n";
appendSys("Replaced default port " + line.substring(line.indexOf("=") + 1) + " with " + portFld.getText());
flag = true;
}
}
if (!flag) {
confText += "defPort=" + portFld.getText() + "\r\n";
appendSys("Set default port: " + portFld.getText());
}
confWriter.write(confText);
confWriter.flush();
} catch (IOException ioe) {
try {
errWriter.write(ioe.toString());
logError(ioe);
errWriter.flush();
} catch (IOException ex) {
Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
private void defChanBtnActionPerformed(java.awt.event.ActionEvent evt) {
String confText = "", line = null;
Boolean flag = false;
try {
while ((line = confReader.readLine()) != null) {
confText += line + "\n";
}
confText += "defChan=#" + chanFld.getText() + "\n";
appendSys("Added default channel #" + chanFld.getText());
confWriter.write(confText + "\r");
confWriter.flush();
} catch (IOException ioe) {
try {
errWriter.write(ioe.toString());
logError(ioe);
errWriter.flush();
} catch (IOException ex) {
Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new GUI().setVisible(true);
Instances.getGuiInstance().readConf();
}
});
}
public void logError(String string) {
init();
errPane.setText(errPane.getText() + "\n[" + getTime("HH:mm:ss") + "]\t" + string + " (See error file)\r\n");
try {
errWriter.write(string + "\n");
errWriter.flush();
} catch (IOException ex) {
Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
}
close();
}
public void logError(Exception e) {
init();
errPane.setText(errPane.getText() + "\n[" + getTime("HH:mm:ss") + "]\t" + e + " (See error file)\r\n");
try {
errWriter.write(e.getMessage() + "\n");
errWriter.flush();
} catch (IOException ex) {
Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
}
close();
}
public String getTime(String format) {
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(c.getTime());
}
public void readConf() {
init();
String line;
try {
while ((line = confReader.readLine()) != null) {
String var = line.substring(line.indexOf("=") + 1);
if (line.startsWith("defNick=")) {
nickFld.setText(var);
bot.nick = var;
}
else if (line.startsWith("defPass=")) {
pwFld.setText(var);
bot.password = var;
}
else if (line.startsWith("defServ=")) {
serverFld.setText(var);
bot.server = var;
}
else if (line.startsWith("defPort=")) {
portFld.setText(var);
bot.port = Integer.parseInt(var);
}
else if (line.startsWith("defChan=")) {
bot.channels[bot.chanIndex] = line.substring(line.indexOf("=") + 1);
bot.chanIndex += 1;
}
}
} catch (IOException ioe) {
logError(ioe);
}
close();
}
public void appendSys(String s) {
sysPane.setText(sysPane.getText() + s + "\n");
}
public void appendRaw(String s) {
rawOutPane.setText(rawOutPane.getText() + s + "\n");
}
public void init() {
final GUI secondGUI = Instances.getGuiInstance();
try {
errWriter = new BufferedWriter(new FileWriter(System.getProperty("user.home") + "/BorBot/debug.txt", true));
try {
confWriter = new BufferedWriter(new FileWriter(System.getProperty("user.home") + "/BorBot/config.txt"));
try {
confReader = new BufferedReader(new InputStreamReader(new FileInputStream(System.getProperty("user.home") + "/BorBot/config.txt")));
} catch (FileNotFoundException nfe) {
try {
boolean make = new File(System.getProperty("user.home") + "/BorBot/").mkdirs();
confWriter.write("");
} catch (IOException ioe) {
try {
errWriter.write(ioe.getMessage() + "\r\n");
secondGUI.logError(ioe);
} catch (IOException ioe2) {
Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ioe2);
secondGUI.logError(ioe2);
}
}
}
} catch (IOException ioe) {
try {
errWriter.write(ioe.getMessage() + "\r\n");
secondGUI.logError(ioe);
} catch (IOException ioe2) {
Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ioe2);
secondGUI.logError(ioe2);
}
}
} catch (FileNotFoundException nfe) {
boolean make = new File(System.getProperty("user.home") + "/BorBot/").mkdirs();
} catch (IOException ioe) {
Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ioe);
}
}
public void close() {
try {
errWriter.flush();
confWriter.flush();
errWriter.close();
confWriter.close();
confReader.close();
} catch (IOException ex) {
Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
// Variables declaration - do not modify
private javax.swing.JTextField chanFld;
private javax.swing.JLabel chanLbl;
private javax.swing.JTextPane chanOutPane;
private javax.swing.JButton clearConfButton;
private javax.swing.JButton clearErrBtn;
private javax.swing.JButton clearErrFileBtn;
private javax.swing.JTextPane debugOutPane;
private javax.swing.JButton defChanBtn;
private javax.swing.JButton defNickBtn;
private javax.swing.JButton defPassBtn;
private javax.swing.JButton defPortBtn;
private javax.swing.JButton defServBtn;
private javax.swing.JTextPane errPane;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JScrollPane jScrollPane5;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JTabbedPane jTabbedPane2;
private javax.swing.JButton joinBtn;
private javax.swing.JTextField nickFld;
private javax.swing.JLabel nickLbl;
private javax.swing.JCheckBox noPassChk;
private javax.swing.JButton partBtn;
private javax.swing.JTextField portFld;
private javax.swing.JLabel portLbl;
private javax.swing.JTextField pwFld;
private javax.swing.JLabel pwLbl;
private javax.swing.JTextPane rawOutPane;
private javax.swing.JButton sayBtn;
private javax.swing.JTextField sayFld;
private javax.swing.JLabel sayLbl;
private javax.swing.JButton servConnectBtn;
private javax.swing.JTextPane servOutPane;
private javax.swing.JTextField serverFld;
private javax.swing.JLabel serverLbl;
private javax.swing.JTextPane sysPane;
private javax.swing.JScrollPane txtPane2;
// End of variables declaration
public static BufferedReader confReader;
public static BufferedWriter confWriter;
public static BufferedWriter errWriter;
//Initialize your bot here
private BorBot bot = Instances.getBotInstance();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.