diff options
| author | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
| commit | e1e781bb2135ef78592226f1a3eaba4925702f1f (patch) | |
| tree | 8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/console/NewSharedTextArea.java | |
| download | worlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.tar.xz worlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.zip | |
Diffstat (limited to 'NET/worlds/console/NewSharedTextArea.java')
| -rw-r--r-- | NET/worlds/console/NewSharedTextArea.java | 415 |
1 files changed, 415 insertions, 0 deletions
diff --git a/NET/worlds/console/NewSharedTextArea.java b/NET/worlds/console/NewSharedTextArea.java new file mode 100644 index 0000000..95289a0 --- /dev/null +++ b/NET/worlds/console/NewSharedTextArea.java @@ -0,0 +1,415 @@ +/* */ package NET.worlds.console; +/* */ +/* */ import NET.worlds.core.IniFile; +/* */ import java.awt.AWTEvent; +/* */ import java.awt.Component; +/* */ import java.awt.event.FocusEvent; +/* */ 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 NewSharedTextArea +/* */ extends GammaTextArea +/* */ implements SharedTextArea +/* */ { +/* */ private static final long serialVersionUID = 6732411958099438561L; +/* */ private static String sharedText; +/* */ private boolean isShared; +/* */ private String unsharedText; +/* 138 */ private String unaddedText = null; +/* */ +/* */ +/* */ private PrintWriter logFile; +/* */ +/* */ private String logFileName; +/* */ +/* */ private static final long oneMeg = 1048576L; +/* */ +/* */ private static final long logLengthLimit = 524288L; +/* */ +/* */ +/* */ public NewSharedTextArea(int rows, int cols, boolean isShared) +/* */ { +/* 152 */ super("", rows, cols, 2); +/* 153 */ this.isShared = isShared; +/* 154 */ setEditable(false); +/* */ } +/* */ +/* */ +/* */ public void finalize() +/* */ { +/* 160 */ disableLogging(); +/* */ } +/* */ +/* */ public Component getComponent() +/* */ { +/* 165 */ return this; +/* */ } +/* */ +/* */ public synchronized void validate() +/* */ { +/* 170 */ super.validate(); +/* 171 */ String text = this.isShared ? sharedText : this.unsharedText; +/* 172 */ if (text != null) +/* */ { +/* */ +/* 175 */ setText(text); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public synchronized void enableLogging(String fileName, String title, boolean append) +/* */ { +/* 192 */ if (this.logFile != null) +/* */ { +/* 194 */ if (this.logFileName.equals(fileName)) { +/* 195 */ return; +/* */ } +/* 197 */ this.logFile.close(); +/* */ } +/* */ try { +/* 200 */ if ((append) && (new File(fileName).exists())) { +/* 201 */ truncateIfExceeds(fileName, title, 524288L); +/* 202 */ this.logFile = new PrintWriter(new FileWriter(fileName, true)); +/* */ } else { +/* 204 */ this.logFile = new PrintWriter(new FileWriter(fileName, false)); +/* 205 */ obsLogFile.setChanged(true); +/* 206 */ this.logFile.println("<html>"); +/* 207 */ this.logFile.println("<head>"); +/* 208 */ this.logFile.println("<title>" + title + "</title>"); +/* 209 */ this.logFile.println("</head>"); +/* 210 */ this.logFile.println("<body>"); +/* */ } +/* 212 */ this.logFileName = fileName; +/* 213 */ this.logFile.println("<hr>"); +/* 214 */ this.logFile.println("<h3>Conversation of " + +/* 215 */ DateFormat.getDateTimeInstance().format(new Date()) + +/* 216 */ "</h3>"); +/* 217 */ this.logFile.flush(); +/* 218 */ obsLogFile.notifyObservers(this); +/* */ } catch (IOException ex) { +/* 220 */ System.out.println("Log file not opened: " + ex); +/* */ } +/* */ } +/* */ +/* */ +/* 225 */ private static PublicObservable obsLogFile = new PublicObservable(); +/* */ +/* */ +/* */ +/* */ +/* */ public static void addLogObserver(Observer o) +/* */ { +/* 232 */ obsLogFile.addObserver(o); +/* */ } +/* */ +/* */ public static void deleteLogObserver(Observer o) +/* */ { +/* 237 */ obsLogFile.deleteObserver(o); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private void truncateIfExceeds(String fileName, String title, long lengthLimit) +/* */ { +/* 247 */ File f = new File(fileName); +/* 248 */ if (f.length() > lengthLimit) { +/* 249 */ File tf = new File(fileName + ".temp"); +/* */ +/* */ try +/* */ { +/* 253 */ BufferedReader in = new BufferedReader(new FileReader(f)); +/* 254 */ PrintWriter out = new PrintWriter(new FileWriter(tf)); +/* 255 */ out.println("<html>"); +/* 256 */ out.println("<head>"); +/* 257 */ out.println("<title>" + title + "</title>"); +/* 258 */ out.println("</head>"); +/* 259 */ out.println("<body>"); +/* 260 */ in.skip(f.length() - lengthLimit / 2L); +/* 261 */ String line = in.readLine(); +/* 262 */ line = in.readLine(); +/* 263 */ while (line != null) { +/* 264 */ out.println(line); +/* 265 */ line = in.readLine(); +/* */ } +/* 267 */ in.close(); +/* 268 */ out.close(); +/* */ +/* */ +/* 271 */ f.delete(); +/* 272 */ f = new File(fileName); +/* 273 */ tf.renameTo(f); +/* */ } catch (FileNotFoundException ex) { +/* 275 */ System.out.println("DuplexPart fatal: " + ex); +/* */ } catch (IOException ex) { +/* 277 */ System.out.println("DuplexPart: Unable to write, " + ex); +/* */ } +/* */ } +/* */ } +/* */ +/* */ +/* */ public synchronized void disableLogging() +/* */ { +/* 285 */ if (this.logFile != null) { +/* 286 */ this.logFile.close(); +/* 287 */ this.logFile = null; +/* */ } +/* */ } +/* */ +/* 291 */ private static int autoScrollLimit = IniFile.gamma().getIniInt("AutoScrollLimit", 0); +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public boolean canAddText() +/* */ { +/* 302 */ if (getText().length() < 3) { +/* 303 */ return true; +/* */ } +/* */ +/* */ +/* 307 */ if ((autoScrollLimit > 0) && (autoScrollLimit < this.unaddedText.length())) { +/* 308 */ return true; +/* */ } +/* 310 */ return isLastLineVisible(); +/* */ } +/* */ +/* 313 */ public static int chatLengthLimit = IniFile.gamma().getIniInt("ChatLengthLimit", 20000); +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public synchronized void println(String msg) +/* */ { +/* 323 */ if ((this.logFile != null) && (msg != null)) { +/* 324 */ this.logFile.println(DuplexPart.toHtml(msg) + "<br>"); +/* 325 */ this.logFile.flush(); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* 331 */ if (this.unaddedText == null) { +/* 332 */ this.unaddedText = msg; +/* 333 */ } else if (msg != null) { +/* 334 */ this.unaddedText = (this.unaddedText + "\n" + msg); +/* */ } +/* 336 */ if ((this.unaddedText == null) || (!canAddText())) { +/* 337 */ return; +/* */ } +/* 339 */ if (getText().length() == 0) { +/* 340 */ append(this.unaddedText); +/* */ } else +/* 342 */ append("\n" + this.unaddedText); +/* 343 */ this.unaddedText = null; +/* */ +/* */ +/* 346 */ String text = getText(); +/* 347 */ if (text.length() > chatLengthLimit) { +/* 348 */ int linePos = text.indexOf('\n', chatLengthLimit / 2 - 80); +/* 349 */ if (linePos >= 0) { +/* 350 */ text = text.substring(linePos + 1); +/* */ +/* */ +/* 353 */ linePos = text.lastIndexOf('\n'); +/* 354 */ if (linePos > 0) { +/* 355 */ setText(text.substring(0, linePos)); +/* 356 */ append(text.substring(linePos)); +/* */ } +/* */ } +/* */ } +/* 360 */ if (this.isShared) { +/* 361 */ sharedText = text; +/* */ } else { +/* 363 */ this.unsharedText = text; +/* */ } +/* 365 */ repaint(); +/* */ } +/* */ +/* */ +/* */ public synchronized void scrollToBottom() +/* */ { +/* 371 */ String text = getText(); +/* 372 */ setText(""); +/* 373 */ append(text); +/* 374 */ repaint(); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ protected void processFocusEvent(FocusEvent e) +/* */ { +/* 384 */ super.processFocusEvent(e); +/* */ } +/* */ +/* */ protected void processEvent(AWTEvent e) +/* */ { +/* 389 */ poll(); +/* */ +/* 391 */ super.processEvent(e); +/* */ } +/* */ +/* */ +/* */ public synchronized void poll() +/* */ { +/* 397 */ if (this.unaddedText != null) { +/* 398 */ println(null); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public boolean isFocusTraversable() +/* */ { +/* 407 */ return false; +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\NewSharedTextArea.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |