Mercurial Hosting > luan
changeset 1890:4e7090ca4581
swing
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 11 Apr 2025 11:43:12 -0600 |
parents | 0d11447423a2 |
children | 6a95ec46404a |
files | src/luan/Luan.java src/luan/impl/LuanParser.java src/luan/modules/swing/Swing.luan src/luan/modules/swing/SwingLuan.java |
diffstat | 4 files changed, 25 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/Luan.java Thu Apr 10 18:48:50 2025 -0600 +++ b/src/luan/Luan.java Fri Apr 11 11:43:12 2025 -0600 @@ -415,9 +415,12 @@ } public static LuanFunction checkFunction(Object obj) throws LuanException { + return checkFunction(obj,""); + } + public static LuanFunction checkFunction(Object obj,String s) throws LuanException { if( obj instanceof LuanFunction ) return (LuanFunction)obj; - throw new LuanException("attempt to call a " + Luan.type(obj) + " value" ); + throw new LuanException("attempt to call a " + Luan.type(obj) + " value" + s ); } public LuanFunction load(String text,String sourceName,boolean persist,LuanTable env)
--- a/src/luan/impl/LuanParser.java Thu Apr 10 18:48:50 2025 -0600 +++ b/src/luan/impl/LuanParser.java Fri Apr 11 11:43:12 2025 -0600 @@ -524,7 +524,7 @@ Stmts stmt = new Stmts(); stmt.add( "LuanFunction "+fnVar+" = Luan.checkFunction(" ); stmt.addAll( expr ); - stmt.add( "); " ); + stmt.add( ",\" in a for statement\"); " ); stmt.add( "while(true) { " ); stmt.addAll( makeLocalSetStmt(names,fnExp) ); stmt.add( "if( " );
--- a/src/luan/modules/swing/Swing.luan Thu Apr 10 18:48:50 2025 -0600 +++ b/src/luan/modules/swing/Swing.luan Fri Apr 11 11:43:12 2025 -0600 @@ -1,12 +1,32 @@ local Luan = require "luan:Luan.luan" local error = Luan.error +local ipairs = Luan.ipairs or error() require "java" +local System = require "java:java.lang.System" local Insets = require "java:java.awt.Insets" +local UIManager = require "java:javax.swing.UIManager" local SwingLuan = require "java:luan.modules.swing.SwingLuan" local Swing = {} +System.setProperty("apple.laf.useScreenMenuBar", "true") + +function Swing.get_installed_look_and_feels() + local list = {} + for _, info in ipairs{UIManager.getInstalledLookAndFeels()} do + list[#list+1] = info.getClassName() + end + return list +end + +function Swing.get_look_and_feel() + return UIManager.getLookAndFeel().getClass().getName() +end + +Swing.ui_manager_put = UIManager.put +Swing.set_look_and_feel = UIManager.setLookAndFeel + Swing.run = SwingLuan.run Swing.new_insets = Insets.new -- top, left, bottom, right
--- a/src/luan/modules/swing/SwingLuan.java Thu Apr 10 18:48:50 2025 -0600 +++ b/src/luan/modules/swing/SwingLuan.java Fri Apr 11 11:43:12 2025 -0600 @@ -2,16 +2,13 @@ import java.lang.reflect.InvocationTargetException; import javax.swing.SwingUtilities; -import javax.swing.UIManager; import javax.swing.KeyStroke; import javax.swing.Action; import javax.swing.AbstractAction; import javax.swing.JComponent; -import javax.swing.UnsupportedLookAndFeelException; import javax.swing.text.JTextComponent; import javax.swing.text.Document; import javax.swing.undo.UndoManager; -import java.awt.Color; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.event.WindowListener; @@ -29,33 +26,6 @@ public class SwingLuan { private static final Logger logger = LoggerFactory.getLogger(SwingLuan.class); - static { - //System.setProperty("apple.awt.application.name", "MyApplication"); - System.setProperty("apple.laf.useScreenMenuBar", "true"); - //System.out.println(UIManager.getLookAndFeel()); -/* - for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { - logger.info(info.toString()); - } -*/ - UIManager.put("control",new Color(0xedeff2)); - try { - //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); - UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); - //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); - //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); - } catch(ClassNotFoundException e) { - throw new RuntimeException(e); - } catch(InstantiationException e) { - throw new RuntimeException(e); - } catch(IllegalAccessException e) { - throw new RuntimeException(e); - } catch(UnsupportedLookAndFeelException e) { - throw new RuntimeException(e); - } - } - private static void exception(LuanException e) { System.err.println(e.getLuanStackTraceString()); System.exit(1);