Mercurial Hosting > luan
changeset 1946:92fe3927a090 default tip
swing
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 20 May 2025 19:06:57 -0600 |
parents | e2d69cfe1b3c |
children | |
files | src/luan/modules/swing/List.luan src/luan/modules/swing/ListLuan.java src/luan/modules/swing/SwingLuan.java |
diffstat | 3 files changed, 28 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
diff -r e2d69cfe1b3c -r 92fe3927a090 src/luan/modules/swing/List.luan --- a/src/luan/modules/swing/List.luan Tue May 20 18:32:45 2025 -0600 +++ b/src/luan/modules/swing/List.luan Tue May 20 19:06:57 2025 -0600 @@ -60,6 +60,9 @@ function list.repaint(value) jlist.repaint() end + function list.add_list_selection_listener(fn) + jlist.addListSelectionListener(fn) + end set_metatable(list,mt) return list end
diff -r e2d69cfe1b3c -r 92fe3927a090 src/luan/modules/swing/ListLuan.java --- a/src/luan/modules/swing/ListLuan.java Tue May 20 18:32:45 2025 -0600 +++ b/src/luan/modules/swing/ListLuan.java Tue May 20 19:06:57 2025 -0600 @@ -5,6 +5,8 @@ import javax.swing.ListCellRenderer; import javax.swing.DefaultListCellRenderer; import javax.swing.JLabel; +import javax.swing.event.ListSelectionListener; +import javax.swing.event.ListSelectionEvent; import java.awt.Component; import java.awt.Color; import java.awt.event.MouseMotionAdapter; @@ -12,7 +14,10 @@ import java.awt.event.MouseAdapter; import goodjava.logging.Logger; import goodjava.logging.LoggerFactory; +import luan.Luan; +import luan.LuanFunction; import luan.LuanTable; +import luan.LuanException; public class ListLuan extends JList<Object> { @@ -80,4 +85,18 @@ this.hoveredIndex = -1; repaint(); } + + public void addListSelectionListener(final Luan luan,final LuanFunction fn) { + addListSelectionListener( new ListSelectionListener() { + @Override public void valueChanged(ListSelectionEvent event) { + if( event.getValueIsAdjusting() ) + return; + try { + fn.call(luan,getSelectedValue()); + } catch(LuanException e) { + SwingLuan.exception(e); + } + } + } ); + } }
diff -r e2d69cfe1b3c -r 92fe3927a090 src/luan/modules/swing/SwingLuan.java --- a/src/luan/modules/swing/SwingLuan.java Tue May 20 18:32:45 2025 -0600 +++ b/src/luan/modules/swing/SwingLuan.java Tue May 20 19:06:57 2025 -0600 @@ -36,7 +36,7 @@ public class SwingLuan { private static final Logger logger = LoggerFactory.getLogger(SwingLuan.class); - private static void exception(LuanException e) { + static void exception(LuanException e) { System.err.println(e.getLuanStackTraceString()); System.exit(1); } @@ -93,7 +93,7 @@ }; } - public static WindowListener newCloseListener(final Luan luan,LuanFunction fn) { + public static WindowListener newCloseListener(final Luan luan,final LuanFunction fn) { return new WindowAdapter() { @Override public void windowClosed(WindowEvent event) { try { @@ -105,7 +105,7 @@ }; } - public static WindowListener newWindowFocusListener(final Luan luan,LuanFunction fn) { + public static WindowListener newWindowFocusListener(final Luan luan,final LuanFunction fn) { return new WindowAdapter() { @Override public void windowGainedFocus(WindowEvent event) { try { @@ -117,7 +117,7 @@ }; } - public static ComponentListener newResizeListener(final Luan luan,LuanFunction fn) { + public static ComponentListener newResizeListener(final Luan luan,final LuanFunction fn) { return new ComponentAdapter() { @Override public void componentResized(ComponentEvent event) { try { @@ -149,7 +149,7 @@ } ); } - public static ComponentListener newMoveListener(final Luan luan,LuanFunction fn) { + public static ComponentListener newMoveListener(final Luan luan,final LuanFunction fn) { return new ComponentAdapter() { @Override public void componentMoved(ComponentEvent event) { try { @@ -161,7 +161,7 @@ }; } - public static ChangeListener newChangeListener(final Luan luan,LuanFunction fn) { + public static ChangeListener newChangeListener(final Luan luan,final LuanFunction fn) { return new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { try {