commit b2a3478a834c4e8127e34dd0d3526bd263fc9899
parent 54e917d744815a33311f7253e66b1acdcd6da1ad
Author: tomas <tomas@logand.com>
Date: Sun, 1 Nov 2009 15:22:58 +0100
swing.l swt.l and examples added
Diffstat:
A | swing.l | | | 5 | +++++ |
A | swt.l | | | 16 | ++++++++++++++++ |
A | swt1.l | | | 14 | ++++++++++++++ |
A | swt2.l | | | 20 | ++++++++++++++++++++ |
A | swt3.l | | | 51 | +++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 files changed, 106 insertions(+), 0 deletions(-)
diff --git a/swing.l b/swing.l
@@ -0,0 +1,5 @@
+(import javax.swing JFrame JButton JLabel JTextField JPanel JComboBox BoxLayout
+ BorderFactory ImageIcon JTable JScrollPane )
+(import javax.swing.table DefaultTableModel)
+(import java.awt Container BorderLayout GridLayout)
+(import java.awt.event ActionListener)
diff --git a/swt.l b/swt.l
@@ -0,0 +1,16 @@
+#import org.eclipse.swt.*; TODO wildcard import
+
+(import org.eclipse.swt SWT)
+(import org.eclipse.swt.widgets Display Shell Label Composite Text)
+(import org.eclipse.swt.events PaintListener)
+(import org.eclipse.swt.layout FillLayout)
+(import org.eclipse.swt.dnd DND
+ DragSource DragSourceEvent DragSourceListener
+ DropTarget DropTargetEvent DropTargetListener DropTargetAdapter
+ TextTransfer Transfer DragSourceListener )
+
+(de swtLoop (D S)
+ (until (jeq true (S 'isDisposed))
+ (unless (jeq true (D 'readAndDispatch))
+ (D 'sleep) ) )
+ (D 'dispose) )
diff --git a/swt1.l b/swt1.l
@@ -0,0 +1,14 @@
+# http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet1.java?view=co
+
+(load "swt.l")
+
+(setq D (jnew Display)
+ S (jnew Shell D)
+ L (jnew Label S (jfield SWT 'NONE)) )
+
+(L 'setText "Hello World")
+(L 'pack)
+(S 'pack)
+(S 'open)
+
+(swtLoop D S)
diff --git a/swt2.l b/swt2.l
@@ -0,0 +1,20 @@
+# http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet245.java?view=co
+
+(load "swt.l")
+
+(setq D (jnew Display)
+ S (jnew Shell D) )
+
+(de w (R) (jnum (jfield R 'width)))
+(de h (R) (jnum (jfield R 'height)))
+
+(de onPaint (M E)
+ (job '((S . `S))
+ (let R (S 'getClientArea)
+ ((jfield E 'gc) 'drawOval 0 0 (1- (w R)) (1- (h R))) ) ) )
+
+(S 'addPaintListener (jproxy NIL 'onPaint PaintListener))
+(S 'setBounds 10 10 200 200)
+(S 'open)
+
+(swtLoop D S)
diff --git a/swt3.l b/swt3.l
@@ -0,0 +1,51 @@
+# http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet78.java?view=co
+
+(load "swt.l")
+
+(setq D (jnew Display)
+ S (jnew Shell D) )
+(S 'setLayout (jnew FillLayout))
+(setq L1 (jnew Label S (jfield SWT 'BORDER))
+ L2 (jnew Label S (jfield SWT 'BORDER)) )
+(L1 'setText "TEXT")
+
+(de s (M E)
+ #(println 's M E)
+ (case M
+ ("dragStart" (jfield E 'doit (n0 ((L 'getText) 'length))))
+ ("dragSetData" (jfield E 'data (L 'getText)))
+ ("dragFinished"
+ (when (jeq (jfield DND 'DROP_MOVE) (jfield E 'detail))
+ (L 'setText "") ) ) ) )
+
+(de z (M E)
+ #(println 'z M E)
+ (case M
+ ("drop"
+ (if (jeq null (jfield E 'data))
+ (jfield E 'detail (jfield DND 'DROP_NONE))
+ (L 'setText (jfield E 'data)) ) ) ) )
+
+(de handler (K V F) # TODO curry
+ (cons 'quote (list '@ (list 'job (cons 'quote (list (cons K V))) (list 'pass F)))) )
+
+(de setDragDrop (L)
+ (let (X ((jvector (TextTransfer 'getInstance)) 'toArray
+ ((jclass 'java.lang.reflect.Array) 'newInstance
+ (jclass 'org.eclipse.swt.dnd.Transfer)
+ 1 ) )
+ O (| (jnum (jfield DND 'DROP_MOVE))
+ (jnum (jfield DND 'DROP_COPY))
+ (jnum (jfield DND 'DROP_LINK)) )
+ S (jnew DragSource L O)
+ Z (jnew DropTarget L O) )
+ (S 'setTransfer X)
+ (Z 'setTransfer X)
+ (S 'addDragListener (jproxy NIL (handler 'L L 's) DragSourceListener))
+ (Z 'addDropListener (jproxy NIL (handler 'L L 'z) DropTargetListener)) ) )
+
+(setDragDrop L1)
+(setDragDrop L2)
+(S 'setSize 200 200)
+(S 'open)
+(swtLoop D S)