Mercurial Hosting > luan
changeset 1949:0de03667a950 default tip
misc
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 22 May 2025 19:04:23 -0600 |
parents | d90f12acb222 |
children | |
files | src/luan/LuanJavaFunction.java src/luan/LuanRuntimeException.java src/luan/modules/swing/SwingLuan.java src/luan/modules/swing/TextAreaLineNumbersLuan.java |
diffstat | 4 files changed, 40 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/LuanJavaFunction.java Thu May 22 14:29:11 2025 -0600 +++ b/src/luan/LuanJavaFunction.java Thu May 22 19:04:23 2025 -0600 @@ -11,9 +11,13 @@ import java.util.Set; import java.util.Arrays; import java.util.Collection; +import goodjava.logging.Logger; +import goodjava.logging.LoggerFactory; public final class LuanJavaFunction extends LuanFunction { + private static final Logger logger = LoggerFactory.getLogger(LuanJavaFunction.class); + private final JavaMethod method; private Object obj; private final RtnConverter rtnConverter; @@ -99,6 +103,8 @@ throw (Error)cause; if( cause instanceof LuanException ) throw (LuanException)cause; + if( cause instanceof LuanRuntimeException ) + throw ((LuanRuntimeException)cause).luanException; throw new LuanException(cause); } catch(InstantiationException e) { throw new RuntimeException(e);
--- a/src/luan/LuanRuntimeException.java Thu May 22 14:29:11 2025 -0600 +++ b/src/luan/LuanRuntimeException.java Thu May 22 19:04:23 2025 -0600 @@ -5,8 +5,11 @@ public final class LuanRuntimeException extends RuntimeException { + public final LuanException luanException; + public LuanRuntimeException(LuanException e) { super(e); + luanException = e; } @Override public void printStackTrace(PrintStream s) {
--- a/src/luan/modules/swing/SwingLuan.java Thu May 22 14:29:11 2025 -0600 +++ b/src/luan/modules/swing/SwingLuan.java Thu May 22 19:04:23 2025 -0600 @@ -52,6 +52,8 @@ fn.call(luan); } catch(LuanException e) { exception(e); + } catch(LuanRuntimeException e) { + exception(e.luanException); } } };
--- a/src/luan/modules/swing/TextAreaLineNumbersLuan.java Thu May 22 14:29:11 2025 -0600 +++ b/src/luan/modules/swing/TextAreaLineNumbersLuan.java Thu May 22 19:04:23 2025 -0600 @@ -22,6 +22,8 @@ import javax.swing.border.EmptyBorder; import goodjava.logging.Logger; import goodjava.logging.LoggerFactory; +import luan.LuanException; +import luan.LuanRuntimeException; public class TextAreaLineNumbersLuan extends JComponent implements DocumentUpdateListener { @@ -39,16 +41,14 @@ } private final TextAreaLuan textArea; - private int currentLine = -1; + private int lines; private int height; private int lineStartSelection = -1; private final LuanDocumentListener ldl = new LuanDocumentListener(this); public TextAreaLineNumbersLuan(TextAreaLuan textArea) { - Insets textInsets = textArea.getInsets(); - Border border = new EmptyBorder(textInsets.top,0,textInsets.bottom,0); - setBorder(border); this.textArea = textArea; + this.lines = textArea.getLineCount(); //logger.info("lines "+lines); setFont(textArea.getFont()); textArea.getDocument().addDocumentListener(new WeakDocumentListener(ldl)); @@ -57,9 +57,8 @@ } @Override public void setBorder(Border border) { - Insets borderInsets = ((EmptyBorder)border).getBorderInsets(); - Insets insets = getInsets(); - border = new EmptyBorder(insets.top,borderInsets.left,insets.bottom,borderInsets.right); + if( !border.getClass().equals(EmptyBorder.class) ) + throw new LuanRuntimeException(new LuanException("border must be EmptyBorder")); super.setBorder(border); } @@ -79,12 +78,16 @@ @Override public Dimension getPreferredSize() { //logger.info("getPreferredSize"); int height = getInnerHeight(); - int lines = textArea.getLineCount(); int width = getFontMetrics(getFont()).stringWidth(intToString(lines)); //logger.info("lines = "+lines); //logger.info("height = "+height); + Insets textInsets = textArea.getInsets(); Insets insets = getInsets(); - height += insets.top + insets.bottom; + if( textInsets.top != insets.top || textInsets.bottom != insets.bottom ) { + Border border = new EmptyBorder(textInsets.top,insets.left,textInsets.bottom,insets.right); + setBorder(border); + } + height += textInsets.top + textInsets.bottom; width += insets.left + insets.right; return new Dimension(width, height); } @@ -93,7 +96,6 @@ //logger.info("paintComponent"); super.paintComponent(g); FontMetrics fm = g.getFontMetrics(); - int lines = textArea.getLineCount(); int xRight = getInsets().left + fm.stringWidth(intToString(lines)); try { for( int i = 0; i < lines; i++ ) { @@ -110,24 +112,26 @@ } @Override public void updated(final DocumentEvent event) { + final int oldLine = lines; + lines = textArea.getLineCount(); SwingUtilities.invokeLater(new Runnable(){public void run(){ //logger.info(event.getType().toString()+" "+event.getOffset()+" "+event.getLength()); - try { - int startOffset = event.getOffset(); - int startLine = textArea.getLineOfOffset(startOffset); - int endOffset = startOffset + event.getLength(); - endOffset = Math.min( endOffset, textArea.getText().length() ); - int endLine = textArea.getLineOfOffset(endOffset); - //logger.info("lines "+startLine+" to "+endLine); - if( startLine == endLine ) { - if( currentLine == startLine && height == getInnerHeight() ) - return; - currentLine = startLine; - } else { - currentLine = -1; + if( oldLine == lines ) { + try { + int startOffset = event.getOffset(); + int startLine = textArea.getLineOfOffset(startOffset); + int endOffset = startOffset + event.getLength(); + endOffset = Math.min( endOffset, textArea.getText().length() ); + int endLine = textArea.getLineOfOffset(endOffset); + //logger.info("lines "+startLine+" to "+endLine); + if( startLine == endLine ) { + int height = TextAreaLineNumbersLuan.this.height; + if( height == getInnerHeight() ) + return; + } + } catch(BadLocationException e) { + throw new RuntimeException(e); } - } catch(BadLocationException e) { - throw new RuntimeException(e); } revalidate(); repaint();