diff -ruN a/1904/NET/worlds/console/ChatSavePart.java b/1904/NET/worlds/console/ChatSavePart.java --- a/1904/NET/worlds/console/ChatSavePart.java 1969-12-31 18:00:00.000000000 -0600 +++ b/1904/NET/worlds/console/ChatSavePart.java 2023-08-21 23:27:16.000000000 -0500 @@ -0,0 +1,49 @@ +package NET.worlds.console; + +import java.io.BufferedReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.StringReader; + +public class ChatSavePart implements DialogReceiver { + + String chat; + + ChatSavePart(String text) { + this.chat = text; + FileSysDialog fsd = new FileSysDialog(DefaultConsole.getFrame(), this, "Save Chat", 1, "Hypertext Markup|*.html|Plain Text|*.txt", "", true); + } + + public void dialogDone(Object var1, boolean var2) { + if (var2) { + FileSysDialog var3 = (FileSysDialog)var1; + String var4 = var3.fileName(); + this.doSave(var4); + } + } + + public boolean doSave(String path) { + try { + if (path != null) { + FileWriter textWriter = new FileWriter(path); + if (path.endsWith(".html") || path.endsWith(".htm")) { + BufferedReader bufReader = new BufferedReader(new StringReader(this.chat)); + String line = null; + while( (line = bufReader.readLine()) != null ) + { + textWriter.write(line + "
"); + } + } else { + textWriter.write(this.chat); + } + textWriter.close(); + Console.println("Saved chat!"); + return true; + } else return false; + } catch (IOException var5) { + Console.println("Failed to save chat: " + var5.getMessage()); + return false; + } + } + +} diff -ruN a/1904/NET/worlds/console/GammaTextArea.java b/1904/NET/worlds/console/GammaTextArea.java --- a/1904/NET/worlds/console/GammaTextArea.java 2020-08-06 15:46:20.000000000 -0500 +++ b/1904/NET/worlds/console/GammaTextArea.java 2023-08-21 23:27:16.000000000 -0500 @@ -2,515 +2,834 @@ import NET.worlds.core.Debug; import NET.worlds.core.IniFile; -import java.awt.Color; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Panel; -import java.awt.Scrollbar; -import java.awt.event.AdjustmentEvent; -import java.awt.event.AdjustmentListener; -import java.awt.event.FocusEvent; +import NET.worlds.network.URL; +import NET.worlds.scape.*; + +import java.awt.*; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.ClipboardOwner; +import java.awt.datatransfer.StringSelection; +import java.awt.event.*; import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.io.*; import java.util.StringTokenizer; import java.util.Vector; -public class GammaTextArea extends Panel implements AdjustmentListener { - 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 _lines; - private boolean _hasFocus; - public static String boldStartTag = ""; - public static String boldEndTag = ""; - public static String italicStartTag = ""; - public static String italicEndTag = ""; - public static String colorStartMagentaTag = ""; - public static String colorStartBlueTag = ""; - public static String colorStartRedTag = ""; - public static String colorStartGreenTag = ""; - public static String colorEndTag = ""; - public static String colorMagenta2Tag = ""; - public static String colorBlue2Tag = ""; - public static String colorRed2Tag = ""; - public static String colorGreen2Tag = ""; - public static String colorCyanTag = ""; - public static String colorDarkGrayTag = ""; - public static String colorGrayTag = ""; - public static String colorOrangeTag = ""; - public static String colorPinkTag = ""; - public static String colorYellowTag = ""; - public static String colorWhiteTag = ""; - public static String colorLightGrayTag = ""; - protected static String[] tagList; - - public Font getFont() { - return this._font; - } - - public int getWidth() { - return this._width; - } - - public int getHeight() { - return this._height; - } - - public void setWidth(int var1) { - this._width = var1 - 4; - } - - public void setHeight(int var1) { - this._height = var1 - 4; - } - - public Vector getLines() { - return this._lines; - } - - public int getScrollLine() { - return this._scrollLine; - } - - public int getCanvasLines() { - return this._canvasLines; - } - - public int getNumLines() { - return this._numLines; - } - - public boolean getHasFocus() { - return this._hasFocus; - } - - public Scrollbar getVertScrollbar() { - return this._vertBar; - } - - static Color getBackgroundColor() { - int var0 = IniFile.override().getIniInt("chatBgR", 255); - int var1 = IniFile.override().getIniInt("chatBgG", 255); - int var2 = IniFile.override().getIniInt("chatBgB", 203); - return new Color(var0, var1, var2); - } - - GammaTextArea(String var1, int var2, int var3, int var4) { - this._string = var1; - this._currentFontName = Console.message("GammaTextFont"); - this._currentStyle = 0; - this._currentPointSize = 12; - this._currentColor = Color.black; - this._font = new Font(this._currentFontName, this._currentStyle, this._currentPointSize); - this._canvas = new StyledTextCanvas(); - FontMetrics var5 = this._canvas.getFontMetrics(this._font); - Debug.dAssert(var5 != null); - int var6 = var5.getHeight(); - int var7 = var5.charWidth('M') * var3; - int var8 = var5.getHeight() * var2; - this._canvas.setSize(var7, var8); - this.setWidth(var7); - this.setHeight(var8); - this._lines = new Vector(); - this._hasFocus = false; - this._numLines = this._scrollLine = this._canvasLines = 0; - switch(var4) { - case 1: - this._vertBar = new GammaTextScrollbar(1); - this._horzBar = new GammaTextScrollbar(0); - break; - case 2: - this._vertBar = new GammaTextScrollbar(1); - this._horzBar = null; - break; - case 3: - this._vertBar = null; - this._horzBar = new GammaTextScrollbar(0); - break; - case 4: - this._vertBar = this._horzBar = null; - } - - GridBagLayout var9 = new GridBagLayout(); - this.setLayout(var9); - GridBagConstraints var10 = new GridBagConstraints(); - var10.fill = 1; - var10.weightx = 1.0D; - var10.weighty = 1.0D; - var9.setConstraints(this._canvas, var10); - this.add(this._canvas); - if (this._vertBar != null) { - var10 = new GridBagConstraints(); - var10.fill = 3; - var10.gridwidth = 0; - var9.setConstraints(this._vertBar, var10); - this.add(this._vertBar); - this._vertBar.addAdjustmentListener(this); - } - - if (this._horzBar != null) { - var10 = new GridBagConstraints(); - var10.fill = 2; - var10.gridwidth = 1; - this.add(this._horzBar); - this._horzBar.addAdjustmentListener(this); - } - - this.enableEvents(31L); - this._canvas.repaint(); - } - - public void update(Graphics var1) { - this.paint(var1); - } - - protected void processFocusEvent(FocusEvent var1) { - if (var1.getID() == 1004) { - this._hasFocus = true; - } else if (var1.getID() == 1005) { - this._hasFocus = false; - } - - this._canvas.repaint(); - super.processFocusEvent(var1); - } - - protected void processKeyEvent(KeyEvent var1) { - this._canvas.dispatchEvent(var1); - super.processKeyEvent(var1); - } - - public void adjustmentValueChanged(AdjustmentEvent var1) { - this._scrollLine = this._vertBar.getValue(); - this._canvas.repaint(); - } - - public void setEditable(boolean var1) { - if (var1) { - System.out.println("Can't set GammaTextArea to be editable."); - } - - } - - public synchronized String getText() { - return this._string; - } - - public synchronized void setText(String var1) { - this._string = var1; - this.wordWrapAll(); - this._scrollLine = this._numLines - this._canvasLines; - if (this._scrollLine < 0) { - this._scrollLine = 0; - } - - this.setScrollBounds(); - } - - public void repaint() { - this._canvas.repaint(); - super.repaint(); - } - - protected synchronized void wordWrapAll() { - this._lines.removeAllElements(); - this._numLines = 0; - this.wordWrap(this._string); - } - - protected boolean isLastLineVisible() { - return this._scrollLine == this._numLines - this._canvasLines || this._numLines <= this._canvasLines; - } - - protected boolean handleTag(String var1) { - if (var1.charAt(0) != '<') { - return false; - } else { - for(int var2 = 0; var2 < tagList.length; ++var2) { - if (var1.equals(tagList[var2])) { - switch(var2) { - case 0: - this._currentStyle |= 1; - break; - case 1: - this._currentStyle &= -2; - break; - case 2: - this._currentStyle |= 2; - break; - case 3: - this._currentStyle &= -3; - break; - case 4: - this._currentColor = Color.magenta; - break; - case 5: - this._currentColor = Color.red; - break; - case 6: - this._currentColor = Color.green; - break; - case 7: - this._currentColor = Color.blue; - break; - case 8: - this._currentColor = Color.black; - break; - case 9: - this._currentColor = Color.magenta; - break; - case 10: - this._currentColor = Color.blue; - break; - case 11: - this._currentColor = Color.red; - break; - case 12: - this._currentColor = Color.green; - break; - case 13: - this._currentColor = Color.cyan; - break; - case 14: - this._currentColor = Color.darkGray; - break; - case 15: - this._currentColor = Color.gray; - break; - case 16: - this._currentColor = Color.orange; - break; - case 17: - this._currentColor = Color.pink; - break; - case 18: - this._currentColor = Color.yellow; - break; - case 19: - this._currentColor = Color.white; - break; - case 20: - this._currentColor = Color.lightGray; - } - - try { - this._font = new Font(this._currentFontName, this._currentStyle, this._currentPointSize); - } catch (IllegalArgumentException var4) { - } - - return true; - } - } - - return false; - } - } - - protected void ClearTags(Graphics var1) { - if (this._currentStyle != 0) { - this._currentStyle = 0; - this._font = new Font(this._currentFontName, this._currentStyle, this._currentPointSize); - } - - if (this._currentColor != Color.black) { - this._currentColor = Color.black; - } - - var1.setFont(this._font); - var1.setColor(this._currentColor); - } - - protected synchronized void wordWrap(String var1) { - int var2 = this._width; - if (var2 > 0) { - StringTokenizer var3 = new StringTokenizer(var1, "\n\r"); - - label74: - while(var3.hasMoreTokens()) { - String var4 = var3.nextToken(); - StringTokenizer var5 = new StringTokenizer(var4, "\n\r\t -", true); - int var6 = 0; - String var7 = ""; - int var8 = 0; - FontMetrics var9 = this._canvas.getFontMetrics(this._font); - Debug.dAssert(var9 != null); - - while(true) { - while(true) { - String var10; - do { - do { - if (!var5.hasMoreTokens()) { - if (!var7.equals("")) { - ++this._numLines; - this._lines.addElement(var7.trim()); - } - continue label74; +public class GammaTextArea extends Panel implements AdjustmentListener, ActionListener { + 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 _lines; + private Vector _pos; + private int _lastpos = 0; + protected int _curpos = 0; + private boolean _hasFocus; + protected int selectionStart = -1; + protected int selectionEnd = -1; + private static final Color skyblue = new Color(135, 206, 255); + private PopupMenu rightMenu; + private MenuItem textCopyItem = new MenuItem(Console.message("Copy")); + private MenuItem textCopyTextItem = new MenuItem(Console.message("Copy Text")); + private MenuItem textCopyAllItem = new MenuItem(Console.message("Copy All")); + private MenuItem textCopyAllTextItem = new MenuItem(Console.message("Copy All Text")); + private MenuItem textSaveItem = new MenuItem(Console.message("Save All Text")); + private MenuItem textOpenURLItem = new MenuItem(Console.message("Open URL")); + static Color bgColor = null; + private int _numColumns; + private int _numRows; + private static int scrollWheelStep = IniFile.gamma().getIniInt("ScrollWheelStep", 3); + public static String boldStartTag = ""; + public static String boldEndTag = ""; + public static String italicStartTag = ""; + public static String italicEndTag = ""; + public static String colorStartMagentaTag = ""; + public static String colorStartBlueTag = ""; + public static String colorStartRedTag = ""; + public static String colorStartGreenTag = ""; + public static String colorEndTag = ""; + public static String colorMagenta2Tag = ""; + public static String colorBlue2Tag = ""; + public static String colorRed2Tag = ""; + public static String colorGreen2Tag = ""; + public static String colorCyanTag = ""; + public static String colorDarkGrayTag = ""; + public static String colorGrayTag = ""; + public static String colorOrangeTag = ""; + public static String colorPinkTag = ""; + public static String colorYellowTag = ""; + public static String colorWhiteTag = ""; + public static String colorLightGrayTag = ""; + protected static String[] tagList; + private int lastWidth = 0; + protected boolean selectionConversion = false; + protected int _initialSelection = -1; + + public Font getFont() { + return this._font; + } + + public int getWidth() { + return this._width; + } + + public int getHeight() { + return this._height; + } + + public void setWidth(int var1) { + this._width = var1 - 4; + } + + public void setHeight(int var1) { + this._height = var1 - 4; + } + + public Vector getLines() { + return this._lines; + } + + public int getScrollLine() { + return this._scrollLine; + } + + public int getCanvasLines() { + return this._canvasLines; + } + + public int getNumLines() { + return this._numLines; + } + + public boolean getHasFocus() { + return this._hasFocus; + } + + public Scrollbar getVertScrollbar() { + return this._vertBar; + } + + static Color getBackgroundColor() { + if (bgColor == null) { + int bgR = IniFile.override().getIniInt("chatBgR", 255); + int bgG = IniFile.override().getIniInt("chatBgG", 255); + int bgB = IniFile.override().getIniInt("chatBgB", 203); + bgColor = new Color(bgR, bgG, bgB); + } + + return bgColor; + } + + GammaTextArea(String text, int rows, int columns, int scrollbars) { + this._string = text; + this._numColumns = columns; + this._numRows = rows; + this._currentFontName = Console.message("GammaTextFont"); + this._currentStyle = 0; + this._currentPointSize = IniFile.gamma().getIniInt("ChatFontSize", 12); + this._currentColor = Color.black; + this._canvas = new StyledTextCanvas(); + this.setFontSize(this._currentPointSize); + this._lines = new Vector(); + this._pos = new Vector(); + this._lastpos = 0; + this._hasFocus = false; + this._numLines = this._scrollLine = this._canvasLines = 0; + switch(scrollbars) { + case 1: + this._vertBar = new GammaTextScrollbar(1); + this._horzBar = new GammaTextScrollbar(0); + break; + case 2: + this._vertBar = new GammaTextScrollbar(1); + this._horzBar = null; + break; + case 3: + this._vertBar = null; + this._horzBar = new GammaTextScrollbar(0); + break; + case 4: + this._vertBar = this._horzBar = null; + } + + GridBagLayout gridbag = new GridBagLayout(); + this.setLayout(gridbag); + GridBagConstraints c = new GridBagConstraints(); + c.fill = 1; + c.weightx = 1.0D; + c.weighty = 1.0D; + gridbag.setConstraints(this._canvas, c); + this.add(this._canvas); + if (this._vertBar != null) { + c = new GridBagConstraints(); + c.fill = 3; + c.gridwidth = 0; + gridbag.setConstraints(this._vertBar, c); + this.add(this._vertBar); + this._vertBar.addAdjustmentListener(this); + } + + if (this._horzBar != null) { + c = new GridBagConstraints(); + c.fill = 2; + c.gridwidth = 1; + this.add(this._horzBar); + this._horzBar.addAdjustmentListener(this); + } + + this.enableEvents(131231L); + this._canvas.repaint(); + } + + public synchronized void setFontSize(int fontsize) { + this._currentPointSize = fontsize; + this._font = new Font(this._currentFontName, this._currentStyle, this._currentPointSize); + this.recalcSize(); + } + + public synchronized void recalcSize() { + FontMetrics fm = this._canvas.getFontMetrics(this._font); + + if (fm == null) throw new AssertionError(); + + int w = fm.charWidth('M') * this._numColumns; + int h = fm.getHeight() * this._numRows; + this.setWidth(w); + this.setHeight(h); + this._canvas.setSize(w, h); + this.setWidth(w); + this.setHeight(h); + } + + public void update(Graphics var1) { + this.paint(var1); + } + + protected synchronized void processMouseEvent(MouseEvent e) { + if (e.isPopupTrigger()) { + if (this.rightMenu != null && this.rightMenu.isEnabled()) { + this.hideRightMenu(); + } else { + this.showRightMenu(e.getX(), e.getY()); + } + } + + super.processMouseEvent(e); + } + + protected synchronized void processFocusEvent(FocusEvent e) { + if (e.getID() == 1004) { + this._hasFocus = true; + } else if (e.getID() == 1005) { + this._hasFocus = false; + } + + this._canvas.repaint(); + super.processFocusEvent(e); + } + + protected synchronized void processKeyEvent(KeyEvent e) { + this._canvas.dispatchEvent(e); + super.processKeyEvent(e); + } + + protected synchronized void processMouseWheelEvent(MouseWheelEvent e) { + if (e.getID() == 507) { + int move; + if (e.getScrollType() == 0) { + move = e.getScrollAmount() * e.getWheelRotation(); + } else { + move = scrollWheelStep * e.getWheelRotation(); + } + + if (move != 0) { + this._vertBar.setValue(this._vertBar.getValue() + move); + this.requestFocus(); + this._canvas.sendDelayedMouseEvent(e); + this.adjustmentValueChanged((AdjustmentEvent)null); + } + } + + super.processMouseWheelEvent(e); + } + + public synchronized void adjustmentValueChanged(AdjustmentEvent e) { + this._scrollLine = this._vertBar.getValue(); + this._canvas.repaint(); + } + + public void setEditable(boolean var1) { + if (var1) { + System.out.println("Can't set GammaTextArea to be editable."); + } + + } + + public synchronized String getText() { + return this._string; + } + + public synchronized void setText(String s) { + this._string = s; + this.wordWrapAll(); + this._scrollLine = this._numLines - this._canvasLines; + if (this._scrollLine < 0) { + this._scrollLine = 0; + } + + this.setScrollBounds(); + } + + public synchronized void repaint() { + this._canvas.repaint(); + super.repaint(); + } + + protected synchronized void wordWrapAll() { + this._lines.removeAllElements(); + this._pos.removeAllElements(); + this._numLines = 0; + this._lastpos = 0; + this.wordWrap(this._string); + } + + protected synchronized boolean isLastLineVisible() { + if (!this._canvas.mouseActive && (this.selectionStart < 0 || this.selectionEnd <= this.selectionStart)) { + return this._scrollLine >= this._numLines - this._canvasLines || this._numLines <= this._canvasLines; + } else { + return false; + } + } + + protected synchronized boolean handleTag(Graphics g, String word, int x, int y) { + String lower = word.toLowerCase(); + int color; + if (word.charAt(0) == '<') { + for (color = 0; color < tagList.length; ++color) { + if (lower.equals(tagList[color].toLowerCase())) { + switch (color) { + case 0: + this._currentStyle |= 1; + break; + case 1: + this._currentStyle &= -2; + break; + case 2: + this._currentStyle |= 2; + break; + case 3: + this._currentStyle &= -3; + break; + case 4: + this._currentColor = Color.magenta; + break; + case 5: + this._currentColor = Color.red; + break; + case 6: + this._currentColor = Color.green; + break; + case 7: + this._currentColor = Color.blue; + break; + case 8: + this._currentColor = Color.black; + break; + case 9: + this._currentColor = Color.magenta; + break; + case 10: + this._currentColor = Color.blue; + break; + case 11: + this._currentColor = Color.red; + break; + case 12: + this._currentColor = Color.green; + break; + case 13: + this._currentColor = Color.cyan; + break; + case 14: + this._currentColor = Color.darkGray; + break; + case 15: + this._currentColor = Color.gray; + break; + case 16: + this._currentColor = Color.orange; + break; + case 17: + this._currentColor = Color.pink; + break; + case 18: + this._currentColor = Color.yellow; + break; + case 19: + this._currentColor = Color.white; + break; + case 20: + this._currentColor = Color.lightGray; + } + + try { + this._font = new Font(this._currentFontName, this._currentStyle, this._currentPointSize); + } catch (IllegalArgumentException var4) { + } + + return true; + } + } + + return false; + } else return false; + } + + protected void ClearTags(Graphics var1) { + if (this._currentStyle != 0) { + this._currentStyle = 0; + this._font = new Font(this._currentFontName, this._currentStyle, this._currentPointSize); + } + + if (this._currentColor != Color.black) { + this._currentColor = Color.black; + } + + var1.setFont(this._font); + var1.setColor(this._currentColor); + } + + protected synchronized void wordWrap(String newText) { + int canvasWidth = this._width; + if (canvasWidth > 0) { + StringTokenizer rawLines = new StringTokenizer(newText, "\n\r"); + + label82: + while(rawLines.hasMoreTokens()) { + String rawLine = rawLines.nextToken(); + StringTokenizer words = new StringTokenizer(rawLine, "\n\r\t -", true); + int lineWidth = 0; + String thisLine = ""; + this.lastWidth = 0; + FontMetrics fm = this._canvas.getFontMetrics(this._font); + + if (fm == null) throw new AssertionError(); + + while(true) { + while(true) { + String word; + do { + do { + if (!words.hasMoreTokens()) { + if (!thisLine.equals("")) { + this._pos.addElement(new Integer(this._lastpos)); + this._lastpos += thisLine.length() + 1; + ++this._numLines; + this._lines.addElement(thisLine.trim()); + } + continue label82; + } + + word = words.nextToken(); + } while(word.equals("\n")); + } while(word.equals("\r")); + + if (this.handleTag((Graphics)null, word, 0, 0)) { + lineWidth -= this.lastWidth; + thisLine = thisLine + word; + if (words.hasMoreTokens()) { + thisLine = thisLine + words.nextToken(); + } + + this.lastWidth = 0; + fm = this._canvas.getFontMetrics(this._font); + + if (fm == null) throw new AssertionError(); + } else { + this.lastWidth = fm.stringWidth(word); + if (this.lastWidth >= canvasWidth) { + if (!thisLine.equals("")) { + this._pos.addElement(new Integer(this._lastpos)); + this._lastpos += thisLine.length(); + this._lines.addElement(thisLine.trim()); + ++this._numLines; + lineWidth = 0; + } + + while(this.lastWidth >= canvasWidth) { + word = this.breakWord(word, fm); + lineWidth = this.lastWidth = 0; + thisLine = ""; + if (word != null && word.length() > 0) { + this.lastWidth = fm.stringWidth(word); + } + } + } + + lineWidth += this.lastWidth; + if (lineWidth > 0 && word != null && word.length() > 0) { + if (lineWidth >= canvasWidth) { + this._pos.addElement(new Integer(this._lastpos)); + this._lastpos += thisLine.length(); + this._lines.addElement(thisLine.trim()); + ++this._numLines; + lineWidth = this.lastWidth; + thisLine = ""; + } + + thisLine = thisLine + word; + } } + } + } + } + + } + } + + protected String breakWord(String var1, FontMetrics var2) { + int var3 = 0; + String var4 = ""; + + for(int var5 = 0; var5 < var1.length(); ++var5) { + char var6 = var1.charAt(var5); + var3 += var2.charWidth(var6); + if (var3 >= this._width) { + this._lines.addElement(var4); + ++this._numLines; + return var1.substring(var5); + } + + var4 = var4 + var6; + } + + this._lines.addElement(var4); + ++this._numLines; + return ""; + } + + public synchronized void rewrap() { + if (this._width > 0 && this._height > 0) { + this.wordWrapAll(); + this._scrollLine = this._numLines - this._canvasLines; + if (this._scrollLine < 0) { + this._scrollLine = 0; + } + + this.setScrollBounds(); + this._canvas.repaint(); + } + + } + + private synchronized void setScrollBounds() { + FontMetrics var1 = this._canvas.getFontMetrics(this._font); + Debug.dAssert(var1 != null); + int var2 = var1.getHeight(); + this._canvasLines = this._height / var2; + if (this._vertBar != null) { + if (this._numLines <= this._canvasLines) { + this._vertBar.setEnabled(false); + } else { + this._vertBar.setEnabled(true); + this._vertBar.setValues(this._scrollLine, this._canvasLines, 0, this._numLines); + this._vertBar.setBlockIncrement(this._canvasLines); + } + } + + } + + public synchronized void append(String var1) { + this._string = this._string + var1; + this.wordWrap(var1); + this._scrollLine = this._numLines - this._canvasLines; + if (this._scrollLine < 0) { + this._scrollLine = 0; + } - var10 = var5.nextToken(); - } while(var10.equals("\n")); - } while(var10.equals("\r")); - - if (this.handleTag(var10)) { - var6 -= var8; - var7 = var7 + var10; - if (var5.hasMoreTokens()) { - var7 = var7 + var5.nextToken(); - } - - var8 = 0; - var9 = this._canvas.getFontMetrics(this._font); - Debug.dAssert(var9 != null); - } else { - var8 = var9.stringWidth(var10); - if (var8 >= var2) { - if (!var7.equals("")) { - this._lines.addElement(var7.trim()); - ++this._numLines; - var6 = 0; + this.setScrollBounds(); + } + + public synchronized void replaceRange(String var1, int var2, int var3) { + String var4 = this._string.substring(0, var2) + var1 + this._string.substring(var3); + this._string = var4; + } + + public synchronized void drawLine(Graphics g, int lineNum, int y) { + if (lineNum < this._pos.size()) { + String thisLine = (String)this._lines.elementAt(lineNum); + + if (thisLine == null) throw new AssertionError(); + + this._curpos = ((Integer)this._pos.elementAt(lineNum)).intValue(); + StringTokenizer st = new StringTokenizer(thisLine, " \n\r", true); + int x = 0; + this.lastWidth = 0; + + while(st.hasMoreTokens()) { + String word = st.nextToken(); + if (!this.handleTag(g, word, 2 + x, y + 2)) { + this.drawString(g, word, 2 + x, y + 2); + this.lastWidth = g.getFontMetrics().stringWidth(word); + x += this.lastWidth; + } else { + x -= this.lastWidth; + if (st.hasMoreTokens()) { + this._curpos += st.nextToken().length(); + } + + this.lastWidth = 0; + g.setFont(this._font); + g.setColor(this._currentColor); + this._curpos += word.length(); + } + } + + this.ClearTags(g); + } + } + + private void drawString(Graphics g, String text, int x, int y) { + FontMetrics fm = g.getFontMetrics(); + int startdist; + int i; + if (this.selectionConversion) { + startdist = fm.getHeight(); + int pos = -1; + if (y - startdist < this._canvas.mouseY) { + if (y < this._canvas.mouseY) { + if (y < this._canvas.mouseY) { + if (this.selectionStart >= 0) { + pos = this._curpos + text.length(); } + } else { + this.selectionConversion = false; + } + } else if (x <= this._canvas.mouseX) { + if (this._canvas.mouseX > x + g.getFontMetrics().stringWidth(text)) { + if (this.selectionStart >= 0 && this._curpos >= this.selectionStart) { + pos = this._curpos + text.length(); + } + } else { + if (this._canvas.mouseDoubleClick) { + this._canvas.mouseDoubleClick = false; + this.selectionStart = this._initialSelection = this._curpos; + this.selectionEnd = this._curpos + text.length(); + pos = -1; + } else { + for(i = 0; i < text.length() - 1 && x + fm.stringWidth(text.substring(0, i + 1)) < this._canvas.mouseX; ++i) { + } - while(var8 >= var2) { - var10 = this.breakWord(var10, var9); - var6 = 0; - var7 = ""; - var8 = var9.stringWidth(var10); + pos = this._curpos + i; } - } - var6 += var8; - if (var6 >= var2) { - this._lines.addElement(var7.trim()); - ++this._numLines; - var6 = var8; - var7 = ""; - } - - var7 = var7 + var10; - } - } - } - } - - } - } - - protected String breakWord(String var1, FontMetrics var2) { - int var3 = 0; - String var4 = ""; - - for(int var5 = 0; var5 < var1.length(); ++var5) { - char var6 = var1.charAt(var5); - var3 += var2.charWidth(var6); - if (var3 >= this._width) { - this._lines.addElement(var4); - ++this._numLines; - return var1.substring(var5); - } - - var4 = var4 + var6; - } - - this._lines.addElement(var4); - ++this._numLines; - return ""; - } - - public synchronized void rewrap() { - if (this._width > 0 && this._height > 0) { - this.wordWrapAll(); - this._scrollLine = this._numLines - this._canvasLines; - if (this._scrollLine < 0) { - this._scrollLine = 0; - } + this.selectionConversion = false; + } + } else { + this.selectionConversion = false; + } + } else if (this.selectionStart >= 0 && this._curpos >= this.selectionStart) { + this.selectionConversion = false; + } + + if (pos >= 0) { + if (this.selectionStart < 0) { + this.selectionStart = this._initialSelection = pos; + this.selectionEnd = this.selectionStart + 1; + } else if (pos < this._initialSelection) { + this.selectionStart = pos; + this.selectionEnd = this._initialSelection + 1; + } else { + this.selectionStart = this._initialSelection; + this.selectionEnd = pos + 1; + } + } + } + + if (this.selectionStart >= 0 && this.selectionEnd > this.selectionStart) { + startdist = this.selectionStart - this._curpos; + if (startdist > 0) { + if (startdist < text.length()) { + i = text.length(); + if (this._curpos + i >= this.selectionEnd) { + i = this.selectionEnd - this._curpos; + } + + this.drawHighlight(g, text.substring(startdist, i), x + fm.stringWidth(text.substring(0, startdist)), y); + } + } else if (this.selectionEnd > this._curpos) { + if (this.selectionEnd - this._curpos < text.length()) { + this.drawHighlight(g, text.substring(0, this.selectionEnd - this._curpos), x, y); + } else { + this.drawHighlight(g, text, x, y); + } + } + } + + g.drawString(text, x, y); + this._curpos += text.length(); + } + + private void drawHighlight(Graphics g, String text, int x, int y) { + if (text != null && text.length() > 0) { + Color c = g.getColor(); + g.setColor(skyblue); + int height = g.getFontMetrics().getHeight(); + g.fillRect(x, y - (height - 2), g.getFontMetrics().stringWidth(text), height); + g.setColor(c); + } + + } + + public int getSelectionStart() { + return this.selectionStart; + } + + public int getSelectionEnd() { + return this.selectionEnd; + } + + public void setSelectionStart(int position) { + this.selectionStart = position; + } + + public void setSelectionEnd(int position) { + this.selectionEnd = position; + } + + public synchronized String getSelectionText() { + if (this.selectionStart >= 0 && this.selectionEnd > this.selectionStart) { + return this.getText().substring(this.selectionStart, this.selectionEnd); + } else { + return ""; + } + } + + private void initRightMenu() { + this.rightMenu = new PopupMenu(); + this.rightMenu.add(this.textCopyItem); + this.rightMenu.add(this.textCopyTextItem); + if (this.selectionStart >= 0 && this.selectionEnd > this.selectionStart) { + this.textCopyItem.setEnabled(true); + this.textCopyTextItem.setEnabled(true); + } else { + this.textCopyItem.setEnabled(false); + this.textCopyTextItem.setEnabled(false); + } + + this.rightMenu.add(this.textCopyAllItem); + this.rightMenu.add(this.textCopyAllTextItem); + this.rightMenu.add(this.textSaveItem); + this.rightMenu.add(this.textOpenURLItem); + this.rightMenu.addActionListener(this); + this.add(this.rightMenu); + } + + private void showRightMenu(int x, int y) { + if (this.rightMenu == null) { + this.initRightMenu(); + } + + this.rightMenu.show(this, x, y); + } + + private void hideRightMenu() { + this.remove(this.rightMenu); + this.rightMenu = null; + } + + public synchronized void actionPerformed(ActionEvent e) { + String text = null; + boolean doClean = false; + if (e.getActionCommand() == this.textCopyItem.getActionCommand()) { + text = this.getSelectionText(); + this.selectionStart = this.selectionEnd = -1; + this.repaint(); + } else if (e.getActionCommand() == this.textCopyTextItem.getActionCommand()) { + text = this.getSelectionText(); + doClean = true; + this.selectionStart = this.selectionEnd = -1; + this.repaint(); + } else if (e.getActionCommand() == this.textCopyAllItem.getActionCommand()) { + text = this.getText(); + } else if (e.getActionCommand() == this.textCopyAllTextItem.getActionCommand()) { + text = this.getText(); + doClean = true; + } else if (e.getActionCommand() == this.textOpenURLItem.getActionCommand()) { + text = this.getSelectionText().trim(); + if (text != null && text.length() > 5) { + if (!text.startsWith("http://") && !text.startsWith("https://") && !text.startsWith("world:")) { + text = "http://" + text; + } + + if (text.startsWith("world:") || text.indexOf(".world#") != -1 || (text.startsWith("http") || text.startsWith("file:")) && text.endsWith(".world")) { + if (text.startsWith("world:")) { + text = text.substring(6); + } + + TeleportAction.teleport(text, (TeleportStatus)null); + } else { + (new SendURLAction(text)).startBrowser(); + } + + this.selectionStart = this.selectionEnd = -1; + this.repaint(); + } + + this.hideRightMenu(); + return; + } else if (e.getActionCommand() == this.textSaveItem.getActionCommand()) { + new ChatSavePart(this._string); + return; + } + + if (doClean) { + StringTokenizer st = new StringTokenizer(text, " \n\r", true); + String newText = ""; + + while(st.hasMoreTokens()) { + String word = st.nextToken(); + if (!this.handleTag((Graphics)null, word, 0, 0)) { + newText = newText + word; + } else { + if (newText.length() > 0 && newText.substring(newText.length() - 1).toCharArray()[0] == ' ') { + newText = newText.substring(0, newText.length() - 1); + } + + if (st.hasMoreTokens()) { + st.nextToken(); + } + } + } + + text = newText; + } - this.setScrollBounds(); - this._canvas.repaint(); - } - - } - - private void setScrollBounds() { - FontMetrics var1 = this._canvas.getFontMetrics(this._font); - Debug.dAssert(var1 != null); - int var2 = var1.getHeight(); - this._canvasLines = this._height / var2; - if (this._vertBar != null) { - if (this._numLines <= this._canvasLines) { - this._vertBar.setEnabled(false); - } else { - this._vertBar.setEnabled(true); - this._vertBar.setValues(this._scrollLine, this._canvasLines, 0, this._numLines); - this._vertBar.setBlockIncrement(this._canvasLines); - } - } - - } - - public void append(String var1) { - this._string = this._string + var1; - this.wordWrap(var1); - this._scrollLine = this._numLines - this._canvasLines; - if (this._scrollLine < 0) { - this._scrollLine = 0; - } - - this.setScrollBounds(); - } - - public void replaceRange(String var1, int var2, int var3) { - String var4 = this._string.substring(0, var2) + var1 + this._string.substring(var3); - this._string = var4; - } - - public void drawLine(Graphics var1, int var2, int var3) { - String var4 = (String)this._lines.elementAt(var2); - Debug.dAssert(var4 != null); - StringTokenizer var5 = new StringTokenizer(var4, " \n\r", true); - int var6 = 0; - int var7 = 0; - - while(var5.hasMoreTokens()) { - String var8 = var5.nextToken(); - if (!this.handleTag(var8)) { - var1.drawString(var8, 2 + var6, var3 + 2); - var7 = var1.getFontMetrics().stringWidth(var8); - var6 += var7; - } else { - var6 -= var7; - if (var5.hasMoreTokens()) { - var5.nextToken(); - } - - var7 = 0; - var1.setFont(this._font); - var1.setColor(this._currentColor); - } - } - - this.ClearTags(var1); - } - - static { - tagList = new String[]{boldStartTag, boldEndTag, italicStartTag, italicEndTag, colorStartMagentaTag, colorStartRedTag, colorStartGreenTag, colorStartBlueTag, colorEndTag, colorMagenta2Tag, colorBlue2Tag, colorRed2Tag, colorGreen2Tag, colorCyanTag, colorDarkGrayTag, colorGrayTag, colorOrangeTag, colorPinkTag, colorYellowTag, colorWhiteTag, colorLightGrayTag}; - } + if (text != null && text.length() > 0) { + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(new StringSelection(text), (ClipboardOwner)null); + } + + this.hideRightMenu(); + } + + static { + tagList = new String[]{boldStartTag, boldEndTag, italicStartTag, italicEndTag, colorStartMagentaTag, colorStartRedTag, colorStartGreenTag, colorStartBlueTag, colorEndTag, colorMagenta2Tag, colorBlue2Tag, colorRed2Tag, colorGreen2Tag, colorCyanTag, colorDarkGrayTag, colorGrayTag, colorOrangeTag, colorPinkTag, colorYellowTag, colorWhiteTag, colorLightGrayTag}; + } } diff -ruN a/1904/NET/worlds/console/StyledTextCanvas.java b/1904/NET/worlds/console/StyledTextCanvas.java --- a/1904/NET/worlds/console/StyledTextCanvas.java 2020-08-06 15:46:22.000000000 -0500 +++ b/1904/NET/worlds/console/StyledTextCanvas.java 2023-08-21 23:27:16.000000000 -0500 @@ -1,5 +1,6 @@ package NET.worlds.console; +import NET.worlds.core.IniFile; import java.awt.Canvas; import java.awt.Color; import java.awt.FontMetrics; @@ -11,88 +12,196 @@ import java.awt.event.MouseEvent; class StyledTextCanvas extends Canvas { - public StyledTextCanvas() { - this.enableEvents(29L); - this.setEnabled(true); - } - - public void setBounds(int var1, int var2, int var3, int var4) { - if (this.getParent() instanceof GammaTextArea) { - GammaTextArea var5 = (GammaTextArea)this.getParent(); - var5.setWidth(var3); - var5.setHeight(var4); - var5.rewrap(); - } - - super.setBounds(var1, var2, var3, var4); - } - - protected void processMouseEvent(MouseEvent var1) { - if (var1.getID() == 500) { - this.getParent().requestFocus(); - } - - super.processMouseEvent(var1); - } - - protected void processKeyEvent(KeyEvent var1) { - if (var1.getID() == 401) { - Scrollbar var2 = null; - if (this.getParent() instanceof GammaTextArea) { - GammaTextArea var3 = (GammaTextArea)this.getParent(); - var2 = var3.getVertScrollbar(); - } - - if (var1.getKeyCode() == 33) { - if (var2 != null && var2.isEnabled()) { - var2.dispatchEvent(var1); + private static final long serialVersionUID = -2680423246934436331L; + private MouseEvent delayedMouseEvent = null; + protected int mouseX = -1; + protected int mouseY = -1; + protected int startX = -1; + protected int startY = -1; + protected int endX = -1; + protected int endY = -1; + protected long mouseWhen = 0L; + protected boolean mouseActive = false; + protected boolean mouseDoubleClick = false; + protected static long doubleClickSpeed = (long)IniFile.override().getIniInt("DoubleClickSpeed", 300); + + public StyledTextCanvas() { + this.enableEvents(61L); + this.setEnabled(true); + } + + public void sendDelayedMouseEvent(MouseEvent e) { + synchronized(this.getParent()) { + this.delayedMouseEvent = e; + } + } + + public void setBounds(int x, int y, int w, int h) { + if (this.getParent() != null && w >= 0 && h >= 0) { + synchronized(this.getParent()) { + if (this.getParent() instanceof GammaTextArea) { + GammaTextArea gta = (GammaTextArea)this.getParent(); + gta.setWidth(w); + gta.setHeight(h); + gta.rewrap(); + } + + super.setBounds(x, y, w, h); } - } else if (var1.getKeyCode() == 34 && var2 != null && var2.isEnabled()) { - var2.dispatchEvent(var1); - } - } - - super.processKeyEvent(var1); - } - - public void update(Graphics var1) { - this.paint(var1); - } - - public void paint(Graphics var1) { - if (this.getParent().isEnabled()) { - GammaTextArea var2 = (GammaTextArea)this.getParent(); - Rectangle var3 = this.getBounds(); - Image var4 = this.createImage(var3.width, var3.height); - Graphics var5 = var4.getGraphics(); - var5.setColor(GammaTextArea.getBackgroundColor()); - var5.fillRect(var3.x, var3.y, var3.width, var3.height); - var5.setColor(Color.black); - if (var2.getHasFocus()) { - var5.setColor(Color.blue); - var5.drawRect(var3.x, var3.y, var3.width - 1, var3.height - 1); - var5.drawRect(var3.x + 1, var3.y + 1, var3.width - 2, var3.height - 2); - var5.setColor(Color.black); - } - - var5.setFont(var2.getFont()); - FontMetrics var6 = var5.getFontMetrics(var2.getFont()); - int var7; - if (var2.getNumLines() <= var2.getCanvasLines()) { - for(var7 = 0; var7 < var2.getNumLines(); ++var7) { - var2.drawLine(var5, var7, (var7 + 1) * var6.getHeight()); + } + + } + + protected void processMouseMotionEvent(MouseEvent e) { + if (e.getID() == 506 && this.mouseActive) { + this.processMouseEvent(e); + } + + super.processMouseMotionEvent(e); + } + + protected void processMouseEvent(MouseEvent e) { + synchronized(this.getParent()) { + if (e.getID() == 500) { + if (this.mouseWhen > 0L && e.getWhen() - this.mouseWhen <= doubleClickSpeed) { + this.mouseDoubleClick = true; + this.mouseWhen = 0L; + this.mouseX = this.startX = this.endX = e.getX(); + this.mouseY = this.startY = this.endY = e.getY(); + ((GammaTextArea)this.getParent()).selectionConversion = true; + this.getParent().repaint(); + } else { + this.mouseDoubleClick = false; + this.mouseWhen = e.getWhen(); + if (e.getButton() == 1 && !this.mouseActive && (e.getModifiers() & 1) == 0) { + ((GammaTextArea)this.getParent()).selectionStart = -1; + ((GammaTextArea)this.getParent()).selectionEnd = -1; + } + } + + this.getParent().requestFocus(); + } else if (e.getID() == 501) { + if (e.getButton() == 1) { + if ((e.getModifiers() & 1) == 0) { + if (((GammaTextArea)this.getParent()).selectionStart >= 0 && ((GammaTextArea)this.getParent()).selectionEnd > ((GammaTextArea)this.getParent()).selectionStart) { + ((GammaTextArea)this.getParent()).selectionStart = -1; + ((GammaTextArea)this.getParent()).selectionEnd = -1; + } else { + this.mouseX = this.startX = this.endX = e.getX(); + this.mouseY = this.startY = this.endY = e.getY(); + this.mouseActive = true; + ((GammaTextArea)this.getParent()).selectionConversion = true; + } + } else { + this.mouseX = this.startX = this.endX = e.getX(); + this.mouseY = this.startY = this.endY = e.getY(); + this.mouseActive = true; + ((GammaTextArea)this.getParent()).selectionConversion = true; + } + + this.getParent().repaint(); + } + + this.getParent().requestFocus(); + } else if (!this.mouseActive || e.getID() != 506 && e.getID() != 507 && e.getID() != 507) { + if (e.getID() == 502) { + if (e.getButton() == 1 && this.mouseActive) { + this.mouseX = this.endX = e.getX(); + this.mouseY = this.endY = e.getY(); + this.mouseActive = false; + ((GammaTextArea)this.getParent()).selectionConversion = false; + this.getParent().repaint(); + } + + this.getParent().requestFocus(); + } + } else { + if ((e.getModifiers() & 16) != 0) { + this.mouseX = this.endX = e.getX(); + this.mouseY = this.endY = e.getY(); + ((GammaTextArea)this.getParent()).selectionConversion = true; + this.getParent().repaint(); + } + + this.getParent().requestFocus(); } - } else { - var7 = var2.getScrollLine(); - for(int var8 = 1; var7 < var2.getNumLines(); ++var8) { - var2.drawLine(var5, var7, var8 * var6.getHeight()); - ++var7; + ((GammaTextArea)this.getParent()).processMouseEvent(e); + super.processMouseEvent(e); + } + } + + public void update(Graphics g) { + this.paint(g); + } + + protected void processKeyEvent(KeyEvent e) { + synchronized(this.getParent()) { + if (e.getID() == 401) { + Scrollbar s = null; + if (this.getParent() instanceof GammaTextArea) { + GammaTextArea gta = (GammaTextArea)this.getParent(); + s = gta.getVertScrollbar(); + } + + if (e.getKeyCode() == 33) { + if (s != null && s.isEnabled()) { + s.dispatchEvent(e); + } + } else if (e.getKeyCode() == 34 && s != null && s.isEnabled()) { + s.dispatchEvent(e); + } } - } - var1.drawImage(var4, 0, 0, this); - } + super.processKeyEvent(e); + } + } + + public void paint(Graphics g) { + synchronized(this.getParent()) { + if (this.getParent().isEnabled()) { + GammaTextArea gta = (GammaTextArea)this.getParent(); + Rectangle r = this.getBounds(); + if (r.width <= 0 || r.height <= 0) { + return; + } + + Image offImage = this.createImage(r.width, r.height); + Graphics offGraphic = offImage.getGraphics(); + offGraphic.setColor(GammaTextArea.getBackgroundColor()); + offGraphic.fillRect(r.x, r.y, r.width, r.height); + offGraphic.setColor(Color.black); + if (gta.getHasFocus()) { + offGraphic.setColor(Color.blue); + offGraphic.drawRect(r.x, r.y, r.width - 1, r.height - 1); + offGraphic.drawRect(r.x + 1, r.y + 1, r.width - 2, r.height - 2); + offGraphic.setColor(Color.black); + } + + offGraphic.setFont(gta.getFont()); + FontMetrics fm = offGraphic.getFontMetrics(gta.getFont()); + gta._curpos = 0; + int i; + if (gta.getNumLines() <= gta.getCanvasLines()) { + for(i = 0; i < gta.getNumLines(); ++i) { + gta.drawLine(offGraphic, i, (i + 1) * fm.getHeight() - fm.getDescent()); + } + } else { + i = gta.getScrollLine(); + + for(int j = 1; i < gta.getNumLines(); ++j) { + gta.drawLine(offGraphic, i, j * fm.getHeight() - fm.getDescent()); + ++i; + } + } + + g.drawImage(offImage, 0, 0, this); + if (this.delayedMouseEvent != null) { + this.processMouseEvent(this.delayedMouseEvent); + this.delayedMouseEvent = null; + } + } - } + } + } }