public
anonymous / gist:1039379
Created

  • Download Gist
gistfile1.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
/*
* 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();
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.