diff options
Diffstat (limited to 'NET/worlds/console/ClassicSharedTextArea.java')
| -rw-r--r-- | NET/worlds/console/ClassicSharedTextArea.java | 765 |
1 files changed, 765 insertions, 0 deletions
diff --git a/NET/worlds/console/ClassicSharedTextArea.java b/NET/worlds/console/ClassicSharedTextArea.java new file mode 100644 index 0000000..139a54c --- /dev/null +++ b/NET/worlds/console/ClassicSharedTextArea.java @@ -0,0 +1,765 @@ +/* */ package NET.worlds.console; +/* */ +/* */ import NET.worlds.core.IniFile; +/* */ import java.awt.Color; +/* */ import java.awt.Component; +/* */ import java.awt.Event; +/* */ import java.awt.FontMetrics; +/* */ import java.awt.Graphics; +/* */ import java.awt.Image; +/* */ import java.awt.Point; +/* */ import java.awt.Rectangle; +/* */ import java.awt.TextArea; +/* */ import java.io.BufferedReader; +/* */ import java.io.File; +/* */ import java.io.FileNotFoundException; +/* */ import java.io.FileReader; +/* */ import java.io.FileWriter; +/* */ import java.io.IOException; +/* */ import java.io.PrintStream; +/* */ import java.io.PrintWriter; +/* */ import java.text.DateFormat; +/* */ import java.util.Date; +/* */ import java.util.Observer; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ class ClassicSharedTextArea +/* */ extends TextArea +/* */ implements SharedTextArea +/* */ { +/* */ private static final long serialVersionUID = -3315186117230082655L; +/* */ private static String sharedText; +/* */ private boolean isShared; +/* */ private String unsharedText; +/* */ private String unaddedText; +/* */ private boolean haveFocus; +/* */ private PrintWriter logFile; +/* */ private String logFileName; +/* */ private static final long oneMeg = 1048576L; +/* */ private static final long logLengthLimit = 524288L; +/* */ +/* */ public ClassicSharedTextArea(int rows, int cols, boolean isShared) +/* */ { +/* 445 */ super("", rows, cols, 1); +/* 446 */ this.isShared = isShared; +/* 447 */ setEditable(false); +/* */ } +/* */ +/* */ public Component getComponent() { +/* 451 */ return this; +/* */ } +/* */ +/* */ +/* */ public void finalize() +/* */ { +/* 457 */ disableLogging(); +/* */ } +/* */ +/* */ public synchronized void validate() +/* */ { +/* 462 */ super.validate(); +/* 463 */ String text = this.isShared ? sharedText : this.unsharedText; +/* 464 */ if (text != null) { +/* 465 */ replaceRange("", 0, getText().length()); +/* 466 */ append(text); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public synchronized void enableLogging(String fileName, String title, boolean append) +/* */ { +/* 483 */ if (this.logFile != null) +/* */ { +/* 485 */ if (this.logFileName.equals(fileName)) { +/* 486 */ return; +/* */ } +/* 488 */ this.logFile.close(); +/* */ } +/* */ try { +/* 491 */ if ((append) && (new File(fileName).exists())) { +/* 492 */ truncateIfExceeds(fileName, title, 524288L); +/* 493 */ this.logFile = new PrintWriter(new FileWriter(fileName, true)); +/* */ } else { +/* 495 */ this.logFile = new PrintWriter(new FileWriter(fileName, false)); +/* 496 */ obsLogFile.setChanged(true); +/* 497 */ this.logFile.println("<html>"); +/* 498 */ this.logFile.println("<head>"); +/* 499 */ this.logFile.println("<title>" + title + "</title>"); +/* 500 */ this.logFile.println("</head>"); +/* 501 */ this.logFile.println("<body>"); +/* */ } +/* 503 */ this.logFileName = fileName; +/* 504 */ this.logFile.println("<hr>"); +/* 505 */ this.logFile.println("<h3>Conversation of " + +/* 506 */ DateFormat.getDateTimeInstance().format(new Date()) + +/* 507 */ "</h3>"); +/* 508 */ this.logFile.flush(); +/* 509 */ obsLogFile.notifyObservers(this); +/* */ } catch (IOException ex) { +/* 511 */ System.out.println("Log file not opened: " + ex); +/* */ } +/* */ } +/* */ +/* */ +/* 516 */ private static PublicObservable obsLogFile = new PublicObservable(); +/* */ +/* */ +/* */ +/* */ +/* */ public static void addLogObserver(Observer o) +/* */ { +/* 523 */ obsLogFile.addObserver(o); +/* */ } +/* */ +/* */ public static void deleteLogObserver(Observer o) +/* */ { +/* 528 */ obsLogFile.deleteObserver(o); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private void truncateIfExceeds(String fileName, String title, long lengthLimit) +/* */ { +/* 539 */ File f = new File(fileName); +/* 540 */ if (f.length() > lengthLimit) { +/* 541 */ File tf = new File(fileName + ".temp"); +/* */ +/* */ try +/* */ { +/* 545 */ BufferedReader in = new BufferedReader(new FileReader(f)); +/* 546 */ PrintWriter out = new PrintWriter(new FileWriter(tf)); +/* 547 */ out.println("<html>"); +/* 548 */ out.println("<head>"); +/* 549 */ out.println("<title>" + title + "</title>"); +/* 550 */ out.println("</head>"); +/* 551 */ out.println("<body>"); +/* 552 */ in.skip(f.length() - lengthLimit / 2L); +/* 553 */ String line = in.readLine(); +/* 554 */ line = in.readLine(); +/* 555 */ while (line != null) { +/* 556 */ out.println(line); +/* 557 */ line = in.readLine(); +/* */ } +/* 559 */ in.close(); +/* 560 */ out.close(); +/* */ +/* */ +/* 563 */ f.delete(); +/* 564 */ f = new File(fileName); +/* 565 */ tf.renameTo(f); +/* */ } catch (FileNotFoundException ex) { +/* 567 */ System.out.println("DuplexPart fatal: " + ex); +/* */ } catch (IOException ex) { +/* 569 */ System.out.println("DuplexPart: Unable to write, " + ex); +/* */ } +/* */ } +/* */ } +/* */ +/* */ public synchronized void disableLogging() +/* */ { +/* 576 */ if (this.logFile != null) { +/* 577 */ this.logFile.close(); +/* 578 */ this.logFile = null; +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public boolean canAddText() +/* */ { +/* 588 */ if (!this.haveFocus) { +/* 589 */ return true; +/* */ } +/* 591 */ return true; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 614 */ public static int chatLengthLimit = IniFile.gamma().getIniInt("ChatLengthLimit", 20000); +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public synchronized void println(String msg) +/* */ { +/* 623 */ if ((this.logFile != null) && (msg != null)) { +/* 624 */ this.logFile.println(DuplexPart.toHtml(msg) + "<br>"); +/* 625 */ this.logFile.flush(); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* 631 */ if (this.unaddedText == null) { +/* 632 */ this.unaddedText = msg; +/* 633 */ } else if (msg != null) { +/* 634 */ this.unaddedText = (this.unaddedText + "\n" + msg); +/* */ } +/* 636 */ if ((this.unaddedText == null) || (!canAddText())) { +/* 637 */ return; +/* */ } +/* 639 */ if (getText().length() == 0) { +/* 640 */ append(this.unaddedText); +/* */ } else +/* 642 */ append("\n" + this.unaddedText); +/* 643 */ this.unaddedText = null; +/* */ +/* */ +/* 646 */ String text = getText(); +/* 647 */ if (text.length() > chatLengthLimit) { +/* 648 */ int linePos = text.indexOf('\n', chatLengthLimit / 2 - 80); +/* 649 */ if (linePos >= 0) { +/* 650 */ text = text.substring(linePos + 1); +/* */ +/* */ +/* 653 */ linePos = text.lastIndexOf('\n'); +/* 654 */ if (linePos > 0) { +/* 655 */ setText(text.substring(0, linePos)); +/* 656 */ append(text.substring(linePos)); +/* */ } +/* */ } +/* */ } +/* */ +/* 661 */ if (this.isShared) { +/* 662 */ sharedText = text; +/* */ } else { +/* 664 */ this.unsharedText = text; +/* */ } +/* */ } +/* */ +/* */ public synchronized void scrollToBottom() { +/* 669 */ String text = getText(); +/* 670 */ int textlen = text.length(); +/* 671 */ select(textlen, textlen); +/* */ } +/* */ +/* */ +/* */ +/* */ @Deprecated +/* */ public boolean handleEvent(Event event) +/* */ { +/* 679 */ if (event.id == 1004) { +/* 680 */ this.haveFocus = true; +/* 681 */ } else if (event.id == 1005) { +/* 682 */ this.haveFocus = false; +/* */ } +/* */ +/* 685 */ poll(); +/* */ +/* 687 */ return super.handleEvent(event); +/* */ } +/* */ +/* */ public void poll() +/* */ { +/* 692 */ if (this.unaddedText != null) { +/* 693 */ println(null); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public boolean isFocusTraversable() +/* */ { +/* 702 */ return false; +/* */ } +/* */ +/* */ public synchronized void paint(Graphics g) +/* */ { +/* 707 */ String[] fulltext = getText().split("\n"); +/* 708 */ Rectangle r = getBounds(); +/* 709 */ if ((r.height < 0) || (r.width < 0)) { +/* 710 */ return; +/* */ } +/* */ +/* */ +/* 714 */ Point offset = new Point(0, 0); +/* */ +/* */ +/* */ +/* 718 */ Image offImage = createImage(r.width, r.height); +/* 719 */ Graphics offGraphic = offImage.getGraphics(); +/* */ +/* 721 */ offGraphic.setColor(GammaTextArea.getBackgroundColor()); +/* 722 */ offGraphic.fillRect(r.x, r.y, r.width, r.height); +/* 723 */ offGraphic.setColor(Color.black); +/* */ +/* 725 */ offGraphic.setFont(getFont()); +/* 726 */ FontMetrics fm = offGraphic.getFontMetrics(getFont()); +/* 727 */ int windowY = offset.y; +/* 728 */ int curY = fm.getHeight(); +/* 729 */ int curLine = 0; +/* */ +/* 731 */ int mode = -1; +/* */ +/* 733 */ System.out.println("paint (" + r.x + "," + r.y + "):" + r.height + "," + +/* 734 */ r.width + " Offset=" + offset.x + "," + offset.y + " lines=" + +/* 735 */ fulltext.length); +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 742 */ System.out.println("curLine=" + curLine + " curY=" + curY); +/* 743 */ for (int i = curLine; (i < fulltext.length) && (curY <= windowY + r.height); i++) +/* */ { +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 752 */ if (mode != 0) +/* */ { +/* 754 */ offGraphic.drawString(fulltext[i], offset.x, curY); +/* 755 */ curY += fm.getHeight(); +/* */ } +/* */ } +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\ClassicSharedTextArea.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |