Groovyã§Swing
ãªãã¨ããã¤ã«ããã¿ã¤ãã«!!
...ã¦ãªãã¨ã¯ã©ãã§ãããã
åæãããã£ã¦ï¼ã©ãã«ãããã©ãã°ï¼ãããããããï¼ãã®ãã¡ã¤ã«ããªã¹ãã¢ããããJListããä½ã£ããã
åèãªã³ã¯å ã¯ä»¥ä¸ã®éãã
- http://terai.xrea.jp/Swing/FileListFlavor.html
- Swingã§ãã©ãã°ï¼ãããããããµã³ãã«
- 1GBレンタルサーバー・プロバイダー Amusement BiG-NET | www5.big.or.jp/~tera/Labo/Java2/j2dnd.html
- Swingã§ãã©ãã°ï¼ãããããããµã³ãã«
- O'Reilly Media - Technology and Business Training
- SwingBuilderã®åºç¤
- O'Reilly Media - Technology and Business Training
- SwingBuilderã®å¿ç¨ï¼widget()ã®ä½¿ãæ¹ï¼
- http://groovy.codehaus.org/SwingBuilder+with+custom+widgets+and+observer+pattern
- widget()ã®ä½¿ãæ¹ãã®ï¼
- http://groovy.codehaus.org/Categorical+Widget+List
- SwingBuilderã§ä½ããã¦ã£ã¸ã§ããã®ä¸è¦§
ã¾ã 試ãã¦ãªããï¼ListenerãAdapterãGroovyãããå®è£ ããæ¹æ³ã¯ãªããã®ã...ã
- http://groovy.codehaus.org/Groovy+Alternatives+to+Inner+Classes
- ã³ã³ãã¼ãã³ãå´ã«"
addXXXListener()
"ãããã°ï¼ãããªãã¯ã使ããã¿ããï¼ä»å試ããDropTargetListenerã¯addã§ãããã£ããã©ï¼
- ã³ã³ãã¼ãã³ãå´ã«"
- http://glenp.net/articles/swing-events-with-groovy-closures
- é¢ç½ããã©ï¼ãã¡ãã¡ã¯ã©ã¹ä½ã£ã¦ãããªããmetaClassããã£ã¦ãã§ããããªï¼
ã¡ãªã¿ã«ä½ã£ãã³ã¼ãã¯ãããªæãã
== DnDList.groovy ==
import java.awt.dnd.DnDConstants as DnD import java.awt.datatransfer.DataFlavor as DF import java.awt.dnd.DropTarget import java.awt.dnd.DropTargetListener import java.awt.dnd.DropTargetEvent import java.awt.dnd.DropTargetDropEvent import java.awt.dnd.DropTargetDragEvent import javax.swing.JList import javax.swing.DefaultListModel class DnDList extends JList implements DropTargetListener { private dropTarget DnDList() { dropTarget = new DropTarget(this, DnD.ACTION_COPY_OR_MOVE, this, true) model = new DefaultListModel() } void drop(DropTargetDropEvent e) { e.acceptDrop(DnD.ACTION_COPY_OR_MOVE) model.removeAllElements() try { if (e.isDataFlavorSupported(DF.javaFileListFlavor)) { def trans = e.transferable trans.getTransferData(DF.javaFileListFlavor).each { model.addElement(it) } } } catch (ex) { ex.printStackTrace() e.dropComplete(false) } } void dragEnter(DropTargetDragEvent e) { e.acceptDrag(DnD.ACTION_COPY_OR_MOVE) } void dragOver(DropTargetDragEvent dtde) { } void dropActionChanged(DropTargetDragEvent dtde) { } void dragExit(DropTargetEvent dte) { } }
== GuiTest.groovy ==
import groovy.swing.SwingBuilder import javax.swing.WindowConstants as WC import gui.DnDList class GuiTest { GuiTest() { def swing = new SwingBuilder() def frame = swing.frame(title: 'Drag&Drop Test', defaultCloseOperation: WC.EXIT_ON_CLOSE) { scrollPane() { widget(new DnDList()) } } frame.pack() frame.show() } static void main(String[] args) { def gui = new GuiTest() } }