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/GammaTextArea.java | |
| download | worlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.tar.xz worlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.zip | |
Diffstat (limited to 'NET/worlds/console/GammaTextArea.java')
| -rw-r--r-- | NET/worlds/console/GammaTextArea.java | 1180 |
1 files changed, 1180 insertions, 0 deletions
diff --git a/NET/worlds/console/GammaTextArea.java b/NET/worlds/console/GammaTextArea.java new file mode 100644 index 0000000..6cbe85a --- /dev/null +++ b/NET/worlds/console/GammaTextArea.java @@ -0,0 +1,1180 @@ +/* */ package NET.worlds.console; +/* */ +/* */ import NET.worlds.core.IniFile; +/* */ import NET.worlds.scape.SendURLAction; +/* */ import NET.worlds.scape.TeleportAction; +/* */ import java.awt.Color; +/* */ import java.awt.Dimension; +/* */ import java.awt.Font; +/* */ import java.awt.FontMetrics; +/* */ import java.awt.Graphics; +/* */ import java.awt.GridBagConstraints; +/* */ import java.awt.GridBagLayout; +/* */ import java.awt.MenuItem; +/* */ import java.awt.Panel; +/* */ import java.awt.PopupMenu; +/* */ import java.awt.Scrollbar; +/* */ import java.awt.Toolkit; +/* */ import java.awt.datatransfer.Clipboard; +/* */ import java.awt.datatransfer.StringSelection; +/* */ import java.awt.event.ActionEvent; +/* */ import java.awt.event.ActionListener; +/* */ import java.awt.event.AdjustmentEvent; +/* */ import java.awt.event.AdjustmentListener; +/* */ import java.awt.event.FocusEvent; +/* */ import java.awt.event.KeyEvent; +/* */ import java.awt.event.MouseEvent; +/* */ import java.awt.event.MouseWheelEvent; +/* */ import java.io.PrintStream; +/* */ import java.util.StringTokenizer; +/* */ import java.util.Vector; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class GammaTextArea +/* */ extends Panel +/* */ implements AdjustmentListener, ActionListener +/* */ { +/* */ private static final long serialVersionUID = 4042890054976563288L; +/* */ public static final int SCROLLBARS_BOTH = 1; +/* */ public static final int SCROLLBARS_VERTICAL_ONLY = 2; +/* */ public static final int SCROLLBARS_HORIZONTAL_ONLY = 3; +/* */ public static final int SCROLLBARS_NONE = 4; +/* */ protected static final int _margin = 2; +/* */ private int _width; +/* */ private int _height; +/* */ private StyledTextCanvas _canvas; +/* */ private String _string; +/* */ private Font _font; +/* */ private int _currentStyle; +/* */ private String _currentFontName; +/* */ private int _currentPointSize; +/* */ private Color _currentColor; +/* */ private GammaTextScrollbar _vertBar; +/* */ private GammaTextScrollbar _horzBar; +/* */ private int _numLines; +/* */ private int _canvasLines; +/* */ private int _scrollLine; +/* */ private Vector<String> _lines; +/* */ private Vector<Integer> _pos; +/* 100 */ private int _lastpos = 0; +/* 101 */ protected int _curpos = 0; +/* */ protected boolean _hasFocus; +/* */ +/* */ public Font getFont() +/* */ { +/* 106 */ return this._font; +/* */ } +/* */ +/* */ public int getWidth() +/* */ { +/* 111 */ return this._width; +/* */ } +/* */ +/* */ public int getHeight() +/* */ { +/* 116 */ return this._height; +/* */ } +/* */ +/* */ public synchronized void setWidth(int w) { +/* 120 */ this._width = (w - 4); +/* */ } +/* */ +/* */ public synchronized void setHeight(int h) { +/* 124 */ this._height = (h - 4); +/* */ } +/* */ +/* */ public Vector<String> getLines() { +/* 128 */ return this._lines; +/* */ } +/* */ +/* */ public int getScrollLine() { +/* 132 */ return this._scrollLine; +/* */ } +/* */ +/* */ public int getCanvasLines() { +/* 136 */ return this._canvasLines; +/* */ } +/* */ +/* */ public int getNumLines() { +/* 140 */ return this._numLines; +/* */ } +/* */ +/* */ public boolean getHasFocus() { +/* 144 */ return this._hasFocus; +/* */ } +/* */ +/* */ public Scrollbar getVertScrollbar() { +/* 148 */ return this._vertBar; +/* */ } +/* */ +/* 151 */ protected int selectionStart = -1; +/* 152 */ protected int selectionEnd = -1; +/* 153 */ private static final Color skyblue = new Color(135, 206, 255); +/* */ +/* */ private PopupMenu rightMenu; +/* 156 */ private MenuItem textCopyItem = new MenuItem(Console.message("Copy")); +/* 157 */ private MenuItem textCopyTextItem = new MenuItem( +/* 158 */ Console.message("Copy Text")); +/* 159 */ private MenuItem textCopyAllItem = new MenuItem(Console.message("Copy All")); +/* 160 */ private MenuItem textCopyAllTextItem = new MenuItem( +/* 161 */ Console.message("Copy All Text")); +/* 162 */ private MenuItem textOpenURLItem = new MenuItem(Console.message("Open URL")); +/* */ +/* 164 */ static Color bgColor = null; +/* */ private int _numColumns; +/* */ +/* 167 */ static Color getBackgroundColor() { if (bgColor == null) { +/* 168 */ int bgR = IniFile.override().getIniInt("chatBgR", 255); +/* 169 */ int bgG = IniFile.override().getIniInt("chatBgG", 255); +/* 170 */ int bgB = IniFile.override().getIniInt("chatBgB", 203); +/* 171 */ bgColor = new Color(bgR, bgG, bgB); +/* */ } +/* 173 */ return bgColor; +/* */ } +/* */ +/* */ +/* */ GammaTextArea(String text, int rows, int columns, int scrollbars) +/* */ { +/* 179 */ this._string = text; +/* 180 */ this._numColumns = columns; +/* 181 */ this._numRows = rows; +/* */ +/* 183 */ this._lines = new Vector(); +/* 184 */ this._pos = new Vector(); +/* 185 */ this._lastpos = 0; +/* */ +/* 187 */ this._hasFocus = false; +/* */ +/* 189 */ this._numLines = (this._scrollLine = this._canvasLines = 0); +/* */ +/* 191 */ this._currentFontName = Console.message("GammaTextFont"); +/* 192 */ this._currentStyle = 0; +/* 193 */ this._currentPointSize = IniFile.gamma().getIniInt("ChatFontSize", 12); +/* 194 */ this._currentColor = Color.black; +/* */ +/* 196 */ this._canvas = new StyledTextCanvas(); +/* */ +/* */ +/* 199 */ setFontSize(this._currentPointSize); +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 211 */ switch (scrollbars) { +/* */ case 1: +/* 213 */ this._vertBar = new GammaTextScrollbar(1); +/* 214 */ this._horzBar = new GammaTextScrollbar(0); +/* 215 */ break; +/* */ +/* */ case 2: +/* 218 */ this._vertBar = new GammaTextScrollbar(1); +/* 219 */ this._horzBar = null; +/* 220 */ break; +/* */ +/* */ case 3: +/* 223 */ this._vertBar = null; +/* 224 */ this._horzBar = new GammaTextScrollbar(0); +/* 225 */ break; +/* */ +/* */ case 4: +/* 228 */ this._vertBar = (this._horzBar = null); +/* */ } +/* */ +/* */ +/* 232 */ GridBagLayout gridbag = new GridBagLayout(); +/* 233 */ setLayout(gridbag); +/* */ +/* */ +/* 236 */ GridBagConstraints c = new GridBagConstraints(); +/* 237 */ c.fill = 1; +/* 238 */ c.weightx = 1.0D; +/* 239 */ c.weighty = 1.0D; +/* 240 */ gridbag.setConstraints(this._canvas, c); +/* 241 */ add(this._canvas); +/* */ +/* */ +/* 244 */ if (this._vertBar != null) { +/* 245 */ GridBagConstraints c = new GridBagConstraints(); +/* 246 */ c.fill = 3; +/* 247 */ c.gridwidth = 0; +/* 248 */ gridbag.setConstraints(this._vertBar, c); +/* 249 */ add(this._vertBar); +/* 250 */ this._vertBar.addAdjustmentListener(this); +/* */ } +/* */ +/* 253 */ if (this._horzBar != null) { +/* 254 */ GridBagConstraints c = new GridBagConstraints(); +/* 255 */ c.fill = 2; +/* 256 */ c.gridwidth = 1; +/* 257 */ add(this._horzBar); +/* 258 */ this._horzBar.addAdjustmentListener(this); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* 265 */ enableEvents(131223L); +/* */ +/* */ +/* */ +/* */ +/* 270 */ this._canvas.repaint(); +/* */ } +/* */ +/* */ public synchronized void setFontSize(int fontsize) { +/* 274 */ this._currentPointSize = fontsize; +/* 275 */ this._font = new Font(this._currentFontName, this._currentStyle, this._currentPointSize); +/* */ +/* 277 */ recalcSize(); +/* */ } +/* */ +/* */ public synchronized void setRows(int rows) { +/* 281 */ this._numRows = rows; +/* */ +/* 283 */ recalcSize(); +/* */ } +/* */ +/* */ public synchronized void recalcSize() +/* */ { +/* 288 */ FontMetrics fm = this._canvas.getFontMetrics(this._font); +/* */ +/* 290 */ assert (fm != null); +/* */ +/* */ +/* 293 */ this._fmWidth = fm.charWidth('M'); +/* 294 */ int w = this._fmWidth * this._numColumns; +/* 295 */ int h = fm.getHeight() * this._numRows; +/* */ +/* 297 */ setWidth(w); +/* 298 */ setHeight(h); +/* 299 */ this._canvas.setSize(w, h); +/* */ +/* 301 */ setWidth(w); +/* 302 */ setHeight(h); +/* 303 */ super.setSize(w, h); +/* 304 */ rewrap(); +/* */ } +/* */ +/* */ public synchronized void setSize(int w, int h) +/* */ { +/* 309 */ setWidth(w); +/* 310 */ setHeight(h); +/* 311 */ this._canvas.setSize(w, h); +/* */ +/* 313 */ setWidth(w); +/* 314 */ setHeight(h); +/* 315 */ super.setSize(w, h); +/* 316 */ rewrap(); +/* */ } +/* */ +/* */ public synchronized void setBounds(int x, int y, int w, int h) +/* */ { +/* 321 */ setWidth(w); +/* 322 */ setHeight(h); +/* 323 */ this._canvas.setSize(w, h); +/* 324 */ setWidth(w); +/* 325 */ setHeight(h); +/* 326 */ super.setBounds(x, y, w, h); +/* 327 */ rewrap(); +/* */ } +/* */ +/* */ +/* */ public void update(Graphics g) +/* */ { +/* 333 */ paint(g); +/* */ } +/* */ +/* */ +/* */ protected synchronized void processMouseEvent(MouseEvent e) +/* */ { +/* 339 */ if (e.isPopupTrigger()) { +/* 340 */ if ((this.rightMenu == null) || (!this.rightMenu.isEnabled())) { +/* 341 */ showRightMenu(e.getX(), e.getY()); +/* */ } else { +/* 343 */ hideRightMenu(); +/* */ } +/* */ } +/* */ +/* 347 */ super.processMouseEvent(e); +/* */ } +/* */ +/* */ protected synchronized void processFocusEvent(FocusEvent e) +/* */ { +/* 352 */ if (e.getID() == 1004) { +/* 353 */ this._hasFocus = true; +/* 354 */ } else if (e.getID() == 1005) { +/* 355 */ this._hasFocus = false; +/* */ } +/* 357 */ this._canvas.repaint(); +/* */ +/* 359 */ super.processFocusEvent(e); +/* */ } +/* */ +/* */ private int _numRows; +/* */ private int _fmWidth; +/* */ protected synchronized void processKeyEvent(KeyEvent e) +/* */ { +/* 366 */ super.processKeyEvent(e); +/* */ } +/* */ +/* 369 */ private static int scrollWheelStep = IniFile.gamma().getIniInt("ScrollWheelStep", 3); +/* */ +/* */ protected synchronized void processMouseWheelEvent(MouseWheelEvent e) +/* */ { +/* 373 */ if (e.getID() == 507) { +/* 374 */ int move = 0; +/* 375 */ if (e.getScrollType() == 0) { +/* 376 */ move = e.getScrollAmount() * e.getWheelRotation(); +/* */ } else { +/* 378 */ move = scrollWheelStep * e.getWheelRotation(); +/* */ } +/* */ +/* 381 */ if (move != 0) +/* */ { +/* 383 */ this._vertBar.setValue(this._vertBar.getValue() + move); +/* 384 */ requestFocus(); +/* */ +/* 386 */ this._canvas.sendDelayedMouseEvent(e); +/* */ +/* 388 */ adjustmentValueChanged(null); +/* */ } +/* */ } +/* */ +/* 392 */ super.processMouseWheelEvent(e); +/* */ } +/* */ +/* */ public synchronized void adjustmentValueChanged(AdjustmentEvent e) +/* */ { +/* 397 */ this._scrollLine = this._vertBar.getValue(); +/* 398 */ this._canvas.repaint(); +/* */ } +/* */ +/* */ public void setEditable(boolean b) { +/* 402 */ if (b) { +/* 403 */ System.out.println("Can't set GammaTextArea to be editable."); +/* */ } +/* */ } +/* */ +/* */ public synchronized String getText() { +/* 408 */ return this._string; +/* */ } +/* */ +/* */ public synchronized void setText(String s) { +/* 412 */ this._string = s; +/* 413 */ wordWrapAll(); +/* 414 */ this._scrollLine = (this._numLines - this._canvasLines); +/* 415 */ if (this._scrollLine < 0) +/* 416 */ this._scrollLine = 0; +/* 417 */ setScrollBounds(); +/* */ } +/* */ +/* */ +/* */ public synchronized void repaint() +/* */ { +/* 423 */ this._canvas.repaint(); +/* 424 */ super.repaint(); +/* */ } +/* */ +/* */ public synchronized void paint(Graphics g) +/* */ { +/* 429 */ this._canvas.paint(g); +/* 430 */ super.paint(g); +/* */ } +/* */ +/* */ protected synchronized void wordWrapAll() { +/* 434 */ this._lines.removeAllElements(); +/* 435 */ this._pos.removeAllElements(); +/* 436 */ this._numLines = 0; +/* 437 */ this._lastpos = 0; +/* 438 */ wordWrap(this._string); +/* */ } +/* */ +/* */ protected synchronized boolean isLastLineVisible() +/* */ { +/* 443 */ if ((this._canvas.mouseActive) || ( +/* 444 */ (this.selectionStart >= 0) && (this.selectionEnd > this.selectionStart))) { +/* 445 */ return false; +/* */ } +/* 447 */ return (this._scrollLine >= this._numLines - this._canvasLines) || (this._numLines <= this._canvasLines); +/* */ } +/* */ +/* 450 */ public static String boldStartTag = "<b>"; +/* 451 */ public static String boldEndTag = "</b>"; +/* 452 */ public static String italicStartTag = "<i>"; +/* 453 */ public static String italicEndTag = "</i>"; +/* 454 */ public static String colorStartMagentaTag = "<color=\"#FF00FF\">"; +/* 455 */ public static String colorStartBlueTag = "<color=\"#0000FF\">"; +/* 456 */ public static String colorStartRedTag = "<color=\"#FF0000\">"; +/* 457 */ public static String colorStartGreenTag = "<color=\"#00FF00\">"; +/* 458 */ public static String colorEndTag = "</color>"; +/* 459 */ public static String colorMagenta2Tag = "<color=magenta>"; +/* 460 */ public static String colorBlue2Tag = "<color=blue>"; +/* 461 */ public static String colorRed2Tag = "<color=red>"; +/* 462 */ public static String colorGreen2Tag = "<color=green>"; +/* 463 */ public static String colorCyanTag = "<color=cyan>"; +/* 464 */ public static String colorDarkGrayTag = "<color=darkgray>"; +/* 465 */ public static String colorGrayTag = "<color=gray>"; +/* 466 */ public static String colorOrangeTag = "<color=orange>"; +/* 467 */ public static String colorPinkTag = "<color=pink>"; +/* 468 */ public static String colorYellowTag = "<color=yellow>"; +/* 469 */ public static String colorWhiteTag = "<color=white>"; +/* 470 */ public static String colorLightGrayTag = "<color=lightgray>"; +/* */ +/* 472 */ public static EmoteHandler emotes = new EmoteHandler(); +/* */ +/* 474 */ protected static String[] tagList = { boldStartTag, boldEndTag, +/* 475 */ italicStartTag, italicEndTag, colorStartMagentaTag, +/* 476 */ colorStartRedTag, colorStartGreenTag, colorStartBlueTag, +/* 477 */ colorEndTag, colorMagenta2Tag, colorBlue2Tag, colorRed2Tag, +/* 478 */ colorGreen2Tag, colorCyanTag, colorDarkGrayTag, colorGrayTag, +/* 479 */ colorOrangeTag, colorPinkTag, colorYellowTag, colorWhiteTag, +/* 480 */ colorLightGrayTag }; +/* */ +/* */ protected synchronized boolean handleTag(Graphics g, String word, int x, int y) { +/* 483 */ String lower = word.toLowerCase(); +/* */ +/* 485 */ if (word.charAt(0) == '<') { +/* 486 */ for (int i = 0; i < tagList.length; i++) { +/* 487 */ if (lower.equals(tagList[i].toLowerCase())) { +/* 488 */ switch (i) { +/* */ case 0: +/* 490 */ this._currentStyle |= 0x1; +/* 491 */ break; +/* */ +/* */ case 1: +/* 494 */ this._currentStyle &= 0xFFFFFFFE; +/* 495 */ break; +/* */ +/* */ case 2: +/* 498 */ this._currentStyle |= 0x2; +/* 499 */ break; +/* */ +/* */ case 3: +/* 502 */ this._currentStyle &= 0xFFFFFFFD; +/* 503 */ break; +/* */ +/* */ case 4: +/* 506 */ this._currentColor = Color.magenta; +/* 507 */ break; +/* */ +/* */ case 5: +/* 510 */ this._currentColor = Color.red; +/* 511 */ break; +/* */ +/* */ case 6: +/* 514 */ this._currentColor = Color.green; +/* 515 */ break; +/* */ +/* */ case 7: +/* 518 */ this._currentColor = Color.blue; +/* 519 */ break; +/* */ +/* */ case 8: +/* 522 */ this._currentColor = Color.black; +/* 523 */ break; +/* */ +/* */ case 9: +/* 526 */ this._currentColor = Color.magenta; +/* 527 */ break; +/* */ +/* */ case 10: +/* 530 */ this._currentColor = Color.blue; +/* 531 */ break; +/* */ +/* */ case 11: +/* 534 */ this._currentColor = Color.red; +/* 535 */ break; +/* */ +/* */ case 12: +/* 538 */ this._currentColor = Color.green; +/* 539 */ break; +/* */ +/* */ case 13: +/* 542 */ this._currentColor = Color.cyan; +/* 543 */ break; +/* */ +/* */ case 14: +/* 546 */ this._currentColor = Color.darkGray; +/* 547 */ break; +/* */ +/* */ case 15: +/* 550 */ this._currentColor = Color.gray; +/* 551 */ break; +/* */ +/* */ case 16: +/* 554 */ this._currentColor = Color.orange; +/* 555 */ break; +/* */ +/* */ case 17: +/* 558 */ this._currentColor = Color.pink; +/* 559 */ break; +/* */ +/* */ case 18: +/* 562 */ this._currentColor = Color.yellow; +/* 563 */ break; +/* */ +/* */ case 19: +/* 566 */ this._currentColor = Color.white; +/* 567 */ break; +/* */ +/* */ case 20: +/* 570 */ this._currentColor = Color.lightGray; +/* */ } +/* */ try +/* */ { +/* 574 */ this._font = new Font(this._currentFontName, this._currentStyle, +/* 575 */ this._currentPointSize); +/* */ } +/* */ catch (IllegalArgumentException localIllegalArgumentException) {} +/* */ +/* */ +/* 580 */ return true; +/* */ } +/* */ } +/* */ } +/* */ +/* */ +/* 586 */ if ((lower.startsWith("<color=\"#")) && (word.length() > 15)) +/* */ { +/* 588 */ int color = 0; +/* */ try +/* */ { +/* 591 */ int end = word.lastIndexOf('"'); +/* 592 */ if ((end < 10) || (end > 15)) { +/* 593 */ end = 15; +/* */ } +/* */ +/* 596 */ color = Integer.parseInt(word.substring(9, end).trim(), 16); +/* */ } +/* */ catch (Exception localException) {} +/* */ +/* 600 */ this._currentColor = new Color(color); +/* */ try { +/* 602 */ this._font = new Font(this._currentFontName, this._currentStyle, +/* 603 */ this._currentPointSize); +/* */ } +/* */ catch (IllegalArgumentException localIllegalArgumentException1) {} +/* */ +/* 607 */ return true; +/* */ } +/* */ +/* 610 */ if (handleSmiley(g, lower, x, y)) { +/* 611 */ return true; +/* */ } +/* */ +/* */ +/* 615 */ return false; +/* */ } +/* */ +/* */ private synchronized boolean handleSmiley(Graphics g, String lower, int x, int y) +/* */ { +/* 620 */ ImageCanvas image = emotes.getImage(lower); +/* 621 */ if (image != null) { +/* 622 */ drawImage(g, image, x, y); +/* 623 */ return true; +/* */ } +/* */ +/* 626 */ return false; +/* */ } +/* */ +/* */ private synchronized void drawImage(Graphics g, ImageCanvas image, int x, int y) { +/* 630 */ if ((image != null) && (image.loaded_)) +/* */ { +/* 632 */ Dimension size = image.imageSize(); +/* */ +/* */ +/* 635 */ if (g != null) +/* */ { +/* 637 */ image.paint(g, x, (int)(y - size.getHeight())); +/* */ } +/* */ +/* */ +/* 641 */ this.lastWidth = ((int)(this.lastWidth - (size.getWidth() + 8.0D))); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ protected void ClearTags(Graphics g) +/* */ { +/* 650 */ if (this._currentStyle != 0) { +/* 651 */ this._currentStyle = 0; +/* 652 */ this._font = new Font(this._currentFontName, this._currentStyle, this._currentPointSize); +/* */ } +/* */ +/* 655 */ if (this._currentColor != Color.black) { +/* 656 */ this._currentColor = Color.black; +/* */ } +/* */ +/* 659 */ g.setFont(this._font); +/* 660 */ g.setColor(this._currentColor); +/* */ } +/* */ +/* */ protected synchronized void wordWrap(String newText) { +/* 664 */ int canvasWidth = this._width - this._fmWidth * 2; +/* */ +/* 666 */ if (canvasWidth <= 0) { +/* 667 */ return; +/* */ } +/* 669 */ StringTokenizer rawLines = new StringTokenizer(newText, "\n\r"); +/* 670 */ while (rawLines.hasMoreTokens()) { +/* 671 */ String rawLine = rawLines.nextToken(); +/* */ +/* 673 */ StringTokenizer words = new StringTokenizer(rawLine, "\n\r\t -", +/* 674 */ true); +/* */ +/* 676 */ int lineWidth = 0; +/* 677 */ String thisLine = ""; +/* 678 */ this.lastWidth = 0; +/* */ +/* 680 */ FontMetrics fm = this._canvas.getFontMetrics(this._font); +/* 681 */ if ((!$assertionsDisabled) && (fm == null)) { throw new AssertionError(); +/* */ } +/* 683 */ while (words.hasMoreTokens()) { +/* 684 */ String word = words.nextToken(); +/* */ +/* 686 */ if ((!word.equals("\n")) && (!word.equals("\r"))) +/* */ { +/* */ +/* */ +/* */ +/* 691 */ if (handleTag(null, word, 0, 0)) +/* */ { +/* 693 */ lineWidth -= this.lastWidth; +/* */ +/* 695 */ thisLine = thisLine + word; +/* */ +/* 697 */ if (words.hasMoreTokens()) +/* 698 */ thisLine = thisLine + words.nextToken(); +/* 699 */ this.lastWidth = 0; +/* */ +/* 701 */ fm = this._canvas.getFontMetrics(this._font); +/* 702 */ if ((!$assertionsDisabled) && (fm == null)) throw new AssertionError(); +/* */ } +/* */ else +/* */ { +/* 706 */ this.lastWidth = fm.stringWidth(word); +/* */ +/* */ +/* 709 */ if (this.lastWidth >= canvasWidth) +/* */ { +/* 711 */ if (!thisLine.equals("")) { +/* 712 */ this._pos.addElement(Integer.valueOf(this._lastpos)); +/* 713 */ this._lastpos += thisLine.length(); +/* 714 */ this._lines.addElement(thisLine.trim()); +/* 715 */ this._numLines += 1; +/* 716 */ lineWidth = 0; +/* */ } +/* */ +/* 719 */ while (this.lastWidth >= canvasWidth) +/* */ { +/* 721 */ word = breakWord(word, fm); +/* */ +/* 723 */ lineWidth = this.lastWidth = 0; +/* 724 */ thisLine = ""; +/* */ +/* 726 */ if ((word != null) && (word.length() > 0)) { +/* 727 */ this.lastWidth = fm.stringWidth(word); +/* */ } +/* */ } +/* */ } +/* 731 */ lineWidth += this.lastWidth; +/* */ +/* 733 */ if ((lineWidth > 0) && (word != null) && (word.length() > 0)) { +/* 734 */ if (lineWidth >= canvasWidth) { +/* 735 */ this._pos.addElement(Integer.valueOf(this._lastpos)); +/* 736 */ this._lastpos += thisLine.length(); +/* 737 */ this._lines.addElement(thisLine.trim()); +/* 738 */ this._numLines += 1; +/* 739 */ lineWidth = this.lastWidth; +/* 740 */ thisLine = ""; +/* */ } +/* 742 */ thisLine = thisLine + word; +/* */ } +/* */ } } +/* */ } +/* 746 */ if (!thisLine.equals("")) { +/* 747 */ this._pos.addElement(Integer.valueOf(this._lastpos)); +/* 748 */ this._lastpos += thisLine.length() + 1; +/* 749 */ this._numLines += 1; +/* 750 */ this._lines.addElement(thisLine.trim()); +/* */ } +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ protected String breakWord(String longWord, FontMetrics fm) +/* */ { +/* 760 */ int lineWidth = 0; +/* 761 */ String thisLine = ""; +/* */ +/* 763 */ for (int c = 0; c < longWord.length(); c++) { +/* 764 */ char ch = longWord.charAt(c); +/* 765 */ lineWidth += fm.charWidth(ch); +/* 766 */ if (lineWidth >= this._width) +/* */ { +/* 768 */ this._pos.addElement(Integer.valueOf(this._lastpos)); +/* 769 */ this._lastpos += thisLine.length(); +/* 770 */ this._lines.addElement(thisLine); +/* 771 */ this._numLines += 1; +/* */ +/* 773 */ lineWidth = fm.charWidth(ch); +/* 774 */ thisLine = ""; +/* */ } +/* 776 */ thisLine = thisLine + ch; +/* */ } +/* */ +/* */ +/* 780 */ if (thisLine.length() > 0) { +/* 781 */ this._pos.addElement(Integer.valueOf(this._lastpos)); +/* 782 */ this._lastpos += thisLine.length(); +/* 783 */ this._lines.addElement(thisLine); +/* 784 */ this._numLines += 1; +/* */ } +/* 786 */ return ""; +/* */ } +/* */ +/* */ public synchronized void rewrap() { +/* 790 */ if ((this._width > 0) && (this._height > 0)) { +/* 791 */ wordWrapAll(); +/* 792 */ this._scrollLine = (this._numLines - this._canvasLines); +/* 793 */ if (this._scrollLine < 0) +/* 794 */ this._scrollLine = 0; +/* 795 */ setScrollBounds(); +/* 796 */ this._canvas.repaint(); +/* */ } +/* */ } +/* */ +/* */ public synchronized void setScrollBounds() +/* */ { +/* 802 */ FontMetrics fm = this._canvas.getFontMetrics(this._font); +/* 803 */ assert (fm != null); +/* */ +/* 805 */ int lineHeight = fm.getHeight(); +/* 806 */ this._canvasLines = ((this._height + fm.getDescent()) / lineHeight); +/* */ +/* 808 */ if (this._vertBar != null) { +/* 809 */ if (this._numLines <= this._canvasLines) { +/* 810 */ this._vertBar.setEnabled(false); +/* */ } else { +/* 812 */ this._vertBar.setEnabled(true); +/* 813 */ this._vertBar.setValues(this._scrollLine, this._canvasLines, 0, this._numLines); +/* 814 */ this._vertBar.setBlockIncrement(this._canvasLines); +/* */ } +/* */ } +/* */ } +/* */ +/* */ public synchronized void append(String s) { +/* 820 */ this._string += s; +/* 821 */ wordWrap(s); +/* 822 */ this._scrollLine = (this._numLines - this._canvasLines); +/* 823 */ if (this._scrollLine < 0) +/* 824 */ this._scrollLine = 0; +/* 825 */ setScrollBounds(); +/* */ } +/* */ +/* */ public synchronized void replaceRange(String s, int start, int end) +/* */ { +/* 830 */ String newString = this._string.substring(0, start) + s + +/* 831 */ this._string.substring(end); +/* 832 */ this._string = newString; +/* */ } +/* */ +/* */ +/* */ +/* 837 */ private int lastWidth = 0; +/* */ +/* */ public synchronized void drawLine(Graphics g, int lineNum, int y) { +/* 840 */ if (lineNum >= this._pos.size()) { +/* 841 */ return; +/* */ } +/* 843 */ String thisLine = (String)this._lines.elementAt(lineNum); +/* 844 */ assert (thisLine != null); +/* 845 */ this._curpos = ((Integer)this._pos.elementAt(lineNum)).intValue(); +/* */ +/* 847 */ StringTokenizer st = new StringTokenizer(thisLine, " \n\r", true); +/* */ +/* 849 */ int x = 0; +/* 850 */ this.lastWidth = 0; +/* */ +/* 852 */ while (st.hasMoreTokens()) { +/* 853 */ String word = st.nextToken(); +/* 854 */ if (!handleTag(g, word, 2 + x, y + 2)) +/* */ { +/* */ +/* 857 */ drawString(g, word, 2 + x, y + 2); +/* */ +/* 859 */ this.lastWidth = g.getFontMetrics().stringWidth(word); +/* 860 */ x += this.lastWidth; +/* */ } +/* */ else { +/* 863 */ x -= this.lastWidth; +/* */ +/* 865 */ if (st.hasMoreTokens()) { +/* 866 */ this._curpos += st.nextToken().length(); +/* */ } +/* 868 */ this.lastWidth = 0; +/* 869 */ g.setFont(this._font); +/* 870 */ g.setColor(this._currentColor); +/* 871 */ this._curpos += word.length(); +/* */ } +/* */ } +/* */ +/* 875 */ ClearTags(g); +/* */ } +/* */ +/* 878 */ protected boolean selectionConversion = false; +/* 879 */ protected int _initialSelection = -1; +/* */ +/* */ private void drawString(Graphics g, String text, int x, int y) { +/* 882 */ FontMetrics fm = g.getFontMetrics(); +/* */ +/* */ +/* 885 */ if (this.selectionConversion) { +/* 886 */ int height = fm.getHeight(); +/* 887 */ int pos = -1; +/* */ +/* 889 */ if (y - height < this._canvas.mouseY) { +/* 890 */ if (y >= this._canvas.mouseY) +/* */ { +/* */ +/* 893 */ if (x <= this._canvas.mouseX) +/* */ { +/* 895 */ if (this._canvas.mouseX <= x + g.getFontMetrics().stringWidth(text)) +/* */ { +/* */ +/* 898 */ if (this._canvas.mouseDoubleClick) { +/* 899 */ this._canvas.mouseDoubleClick = false; +/* */ +/* */ +/* */ +/* 903 */ this.selectionStart = (this._initialSelection = this._curpos); +/* 904 */ this.selectionEnd = (this._curpos + text.length()); +/* 905 */ pos = -1; +/* */ +/* */ +/* */ } +/* */ else +/* */ { +/* */ +/* */ +/* 913 */ int i = 0; +/* 914 */ while ((i < text.length() - 1) && ( +/* 915 */ x + +/* 916 */ fm.stringWidth(text +/* 917 */ .substring(0, i + 1)) < this._canvas.mouseX)) { +/* 918 */ i++; +/* */ } +/* */ +/* 921 */ pos = this._curpos + i; +/* */ } +/* 923 */ this.selectionConversion = false; +/* 924 */ } else if ((this.selectionStart >= 0) && +/* 925 */ (this._curpos >= this.selectionStart)) +/* */ { +/* */ +/* 928 */ pos = this._curpos + text.length(); +/* */ } +/* */ } +/* */ else { +/* 932 */ this.selectionConversion = false; +/* */ } +/* 934 */ } else if (y < this._canvas.mouseY) { +/* 935 */ if (this.selectionStart >= 0) +/* */ { +/* */ +/* 938 */ pos = this._curpos + text.length(); +/* */ } +/* */ } +/* */ else { +/* 942 */ this.selectionConversion = false; +/* */ } +/* 944 */ } else if ((this.selectionStart >= 0) && (this._curpos >= this.selectionStart)) +/* */ { +/* 946 */ this.selectionConversion = false; +/* */ } +/* */ +/* */ +/* 950 */ if (pos >= 0) +/* */ { +/* */ +/* 953 */ if (this.selectionStart < 0) +/* */ { +/* 955 */ this.selectionStart = (this._initialSelection = pos); +/* 956 */ this.selectionEnd = (this.selectionStart + 1); +/* */ +/* */ } +/* 959 */ else if (pos < this._initialSelection) +/* */ { +/* 961 */ this.selectionStart = pos; +/* 962 */ this.selectionEnd = (this._initialSelection + 1); +/* */ } +/* */ else { +/* 965 */ this.selectionStart = this._initialSelection; +/* 966 */ this.selectionEnd = (pos + 1); +/* */ } +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* 973 */ if ((this.selectionStart >= 0) && (this.selectionEnd > this.selectionStart)) +/* */ { +/* 975 */ int startdist = this.selectionStart - this._curpos; +/* 976 */ if (startdist > 0) +/* */ { +/* 978 */ if (startdist < text.length()) { +/* 979 */ int start = startdist; +/* 980 */ int end = text.length(); +/* */ +/* 982 */ if (this._curpos + end >= this.selectionEnd) +/* */ { +/* 984 */ end = this.selectionEnd - this._curpos; +/* */ } +/* */ +/* 987 */ drawHighlight(g, text.substring(start, end), +/* 988 */ x + fm.stringWidth(text.substring(0, startdist)), y); +/* */ } +/* 990 */ } else if (this.selectionEnd > this._curpos) +/* */ { +/* */ +/* */ +/* 994 */ if (this.selectionEnd - this._curpos < text.length()) +/* */ { +/* 996 */ drawHighlight(g, text.substring(0, this.selectionEnd - this._curpos), +/* 997 */ x, y); +/* */ } +/* */ else { +/* 1000 */ drawHighlight(g, text, x, y); +/* */ } +/* */ } +/* */ } +/* 1004 */ g.drawString(text, x, y); +/* 1005 */ this._curpos += text.length(); +/* */ } +/* */ +/* */ private void drawHighlight(Graphics g, String text, int x, int y) { +/* 1009 */ if ((text != null) && (text.length() > 0)) +/* */ { +/* 1011 */ Color c = g.getColor(); +/* */ +/* */ +/* 1014 */ g.setColor(skyblue); +/* 1015 */ int height = g.getFontMetrics().getHeight(); +/* 1016 */ g.fillRect(x, y - (height - 2), g.getFontMetrics() +/* 1017 */ .stringWidth(text), height); +/* */ +/* */ +/* 1020 */ g.setColor(c); +/* */ } +/* */ } +/* */ +/* */ public int getSelectionStart() { +/* 1025 */ return this.selectionStart; +/* */ } +/* */ +/* */ public int getSelectionEnd() { +/* 1029 */ return this.selectionEnd; +/* */ } +/* */ +/* */ public void setSelectionStart(int position) { +/* 1033 */ this.selectionStart = position; +/* */ } +/* */ +/* */ public void setSelectionEnd(int position) { +/* 1037 */ this.selectionEnd = position; +/* */ } +/* */ +/* */ public synchronized String getSelectionText() { +/* 1041 */ if ((this.selectionStart >= 0) && (this.selectionEnd > this.selectionStart)) { +/* 1042 */ if (this.selectionEnd >= getText().length()) { +/* 1043 */ return getText().substring(this.selectionStart); +/* */ } +/* 1045 */ return getText().substring(this.selectionStart, this.selectionEnd); +/* */ } +/* */ +/* 1048 */ return ""; +/* */ } +/* */ +/* */ private void initRightMenu() +/* */ { +/* 1053 */ this.rightMenu = new PopupMenu(); +/* */ +/* 1055 */ this.rightMenu.add(this.textCopyItem); +/* 1056 */ this.rightMenu.add(this.textCopyTextItem); +/* 1057 */ if ((this.selectionStart < 0) || (this.selectionEnd <= this.selectionStart)) { +/* 1058 */ this.textCopyItem.setEnabled(false); +/* 1059 */ this.textCopyTextItem.setEnabled(false); +/* */ } else { +/* 1061 */ this.textCopyItem.setEnabled(true); +/* 1062 */ this.textCopyTextItem.setEnabled(true); +/* */ } +/* 1064 */ this.rightMenu.add(this.textCopyAllItem); +/* 1065 */ this.rightMenu.add(this.textCopyAllTextItem); +/* 1066 */ this.rightMenu.add(this.textOpenURLItem); +/* 1067 */ this.rightMenu.addActionListener(this); +/* 1068 */ add(this.rightMenu); +/* */ } +/* */ +/* */ private void showRightMenu(int x, int y) { +/* 1072 */ if (this.rightMenu == null) { +/* 1073 */ initRightMenu(); +/* */ } +/* 1075 */ this.rightMenu.show(this, x, y); +/* */ } +/* */ +/* */ private void hideRightMenu() { +/* 1079 */ remove(this.rightMenu); +/* 1080 */ this.rightMenu = null; +/* */ } +/* */ +/* */ public synchronized void actionPerformed(ActionEvent e) +/* */ { +/* 1085 */ String text = null; +/* 1086 */ boolean doClean = false; +/* */ +/* 1088 */ if (e.getActionCommand() == this.textCopyItem.getActionCommand()) +/* */ { +/* 1090 */ text = getSelectionText(); +/* 1091 */ this.selectionStart = (this.selectionEnd = -1); +/* 1092 */ repaint(); +/* 1093 */ } else if (e.getActionCommand() == this.textCopyTextItem.getActionCommand()) +/* */ { +/* 1095 */ text = getSelectionText(); +/* 1096 */ doClean = true; +/* 1097 */ this.selectionStart = (this.selectionEnd = -1); +/* 1098 */ repaint(); +/* 1099 */ } else if (e.getActionCommand() == this.textCopyAllItem.getActionCommand()) +/* */ { +/* 1101 */ text = getText(); +/* */ } +/* 1103 */ else if (e.getActionCommand() == this.textCopyAllTextItem.getActionCommand()) +/* */ { +/* 1105 */ text = getText(); +/* 1106 */ doClean = true; +/* 1107 */ } else if (e.getActionCommand() == this.textOpenURLItem.getActionCommand()) { +/* 1108 */ text = getSelectionText().trim(); +/* 1109 */ if ((text != null) && (text.length() > 5)) { +/* 1110 */ if ((!text.startsWith("http://")) && (!text.startsWith("https://")) && +/* 1111 */ (!text.startsWith("world:"))) { +/* 1112 */ text = "http://" + text; +/* */ } +/* */ +/* 1115 */ if ((text.startsWith("world:")) || +/* 1116 */ (text.contains(".world#")) || ( +/* 1117 */ ((text.startsWith("http")) || +/* 1118 */ (text.startsWith("file:"))) && +/* 1119 */ (text.endsWith(".world")))) +/* */ { +/* 1121 */ if (text.startsWith("world:")) { +/* 1122 */ text = text.substring(6); +/* */ } +/* 1124 */ TeleportAction.teleport(text, null); +/* */ } +/* */ else +/* */ { +/* 1128 */ new SendURLAction(text).startBrowser(); +/* */ } +/* 1130 */ this.selectionStart = (this.selectionEnd = -1); +/* 1131 */ repaint(); +/* */ } +/* 1133 */ hideRightMenu(); +/* 1134 */ return; +/* */ } +/* */ +/* 1137 */ if (doClean) +/* */ { +/* 1139 */ StringTokenizer st = new StringTokenizer(text, " \n\r", true); +/* 1140 */ String newText = ""; +/* */ +/* 1142 */ while (st.hasMoreTokens()) { +/* 1143 */ String word = st.nextToken(); +/* 1144 */ if (!handleTag(null, word, 0, 0)) { +/* 1145 */ newText = newText + word; +/* */ +/* */ +/* */ } +/* */ else +/* */ { +/* */ +/* 1152 */ if ((newText.length() > 0) && +/* 1153 */ (newText.substring(newText.length() - 1) +/* 1154 */ .toCharArray()[0] == ' ')) { +/* 1155 */ newText = newText.substring(0, newText.length() - 1); +/* */ } +/* */ +/* */ +/* 1159 */ if (st.hasMoreTokens()) { +/* 1160 */ st.nextToken(); +/* */ } +/* */ } +/* */ } +/* 1164 */ text = newText; +/* */ } +/* */ +/* 1167 */ if ((text != null) && (text.length() > 0)) { +/* 1168 */ Clipboard clipboard = Toolkit.getDefaultToolkit() +/* 1169 */ .getSystemClipboard(); +/* 1170 */ clipboard.setContents(new StringSelection(text), null); +/* */ } +/* 1172 */ hideRightMenu(); +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\GammaTextArea.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |