Source code: com/memoire/dnd/DndTest.java
1 /**
2 * @modification $Date: 2002/05/28 14:26:10 $
3 * @statut unstable
4 * @file DndTest.java
5 * @version 0.36
6 * @author Guillaume Desnoix
7 * @email guillaume@desnoix.com
8 * @license GNU General Public License 2 (GPL2)
9 * @copyright 1998-2001 Guillaume Desnoix
10 */
11
12 package com.memoire.dnd;
13 import com.memoire.dnd.*;
14
15
16 import java.awt.*;
17 import javax.swing.*;
18
19 public class DndTest
20 {
21 public static void main(String[] args)
22 {
23 DndIcons.setNoDropIcon
24 (new ImageIcon(DndTest.class.getResource("dnd-nodrop_24.gif")));
25 DndIcons.setCanDropIcon
26 (new ImageIcon(DndTest.class.getResource("dnd-candrop_24.gif")));
27 DndIcons.setDefaultIcon
28 (new ImageIcon(DndTest.class.getResource("dnd-default_24.gif")));
29
30 Color[] COLOR=new Color[]
31 { Color.yellow, Color.blue, Color.red, Color.green, Color.magenta };
32
33 JPanel pc=new JPanel(new GridLayout(5,1));
34 JLabel[] cl=new JLabel[5];
35 for(int i=0;i<5;i++)
36 {
37 cl[i]=new JLabel(" ");
38 cl[i].setOpaque(true);
39 cl[i].setBackground(COLOR[i]);
40 pc.add(cl[i],i);
41
42 /*
43 new DndComponentSource(cl[i],new DndRequestData()
44 {
45 public Object[] request(Component _component,Point _location)
46 {
47 Color c=_component.getBackground();
48 return new Object[]
49 {
50 c,
51 "#"+Integer.toHexString(c.getRGB()),
52 };
53 }
54 });
55 */
56
57 new DndSource(new DndRequestObject
58 (new Object[]
59 {
60 new DndProperty("foreground",COLOR[i]),
61 COLOR[i],
62 "#"+Integer.toHexString(COLOR[i].getRGB())
63 } ))
64 .add(cl[i]);
65 }
66
67 JFrame frame=new JFrame("Drag&Drop Test");
68 JTextField tf=new JTextField(20);
69 JTextArea ta=new JTextArea(10,20); //tmp()
70 JLabel lb=new JLabel("file:///hello/");
71 JLabel no=new JLabel("<no>");
72 JPanel pn=new JPanel(new BorderLayout());
73
74 ta.setLineWrap(true);
75 //ta.setWrapStyleWord(true);
76
77 pn.add("North",tf);
78 pn.add("Center",new JScrollPane(ta));
79 pn.add("South",lb);
80 pn.add("East",no);
81 pn.add("West",pc);
82 frame.setContentPane(pn);
83
84 new DndSource(new DndRequestObject("machin"))
85 .add(lb);
86
87 new DndSource(new DndRequestObject
88 (new DndProperty("font",new Font("SansSerif",Font.PLAIN,10))))
89 .add(no);
90
91 new DndTarget()
92 .accept(Color.class,
93 DndTransferObject.SINGLETON,
94 DndManageBackground.SINGLETON)
95 .add(no);
96
97 new DndTarget("Drop me a text or a color")
98 .accept(Color.class,
99 DndTransferObject.SINGLETON,
100 DndManageBackground.SINGLETON)
101 .accept(String.class,
102 DndTransferString.SINGLETON,
103 DndManageText.SINGLETON_REPLACE_ALL)
104 .add(tf);
105
106 new DndTarget("String <--")
107 .accept(DndProperty.class,
108 DndTransferObject.SINGLETON,
109 DndManageProperty.SINGLETON)
110 .accept(String.class,
111 DndTransferString.SINGLETON,
112 DndManageText.SINGLETON_INSERT_AT_CURSOR)
113 .accept(Object.class,
114 DndTransferString.SINGLETON,
115 DndManageText.SINGLETON_INSERT_AT_CURSOR)
116 .add(ta);
117
118 /*
119 DndTargetText.setOn
120 (ta,DndTargetText.INSERT_AT_CURSOR);
121
122 DndComponentTarget dct=new DndComponentTarget(tf);
123 dct.addAcceptedClass(String.class,
124 DndTransferString.SINGLETON,
125 DndManageText.SINGLETON);
126 dct.addAcceptedClass(Color.class,
127 DndTransferObject.SINGLETON,
128 DndManageBackground.SINGLETON);
129 */
130 //DndTargetText.setOn
131 // (tf,DndTargetText.REPLACE_ALL);
132 //DndTargetColor.setOn(tf);
133
134 //DndTargetColor.setOn(no);
135
136 /*
137 new DndComponentSource(lb,new DndRequestData()
138 {
139 public Object[] request(Component _component,Point _location)
140 {
141 return new Object[]
142 {
143 _component,
144 ((JLabel)_component).getText(),
145 };
146 }
147 });
148 */
149
150 //DndTargetProperty.setOn(tf);
151 //DndTargetProperty.setOn(ta);
152 /*
153 new DndComponentSource
154 (no,new DndRequestProperty
155 ("font",new Font("SansSerif",Font.PLAIN,10)));
156 */
157
158 frame.pack();
159 frame.show();
160
161
162 JWindow f2=new JWindow(frame);
163 JTextField tf2=new JTextField(20);
164 f2.getContentPane().add(tf2);
165 new DndTarget("Drop me anything")
166 .accept(Color.class,
167 DndTransferObject.SINGLETON,
168 DndManageBackground.SINGLETON)
169 .accept(String.class,
170 DndTransferString.SINGLETON,
171 DndManageText.SINGLETON_REPLACE_ALL)
172 .add(tf2);
173 f2.pack();
174 f2.show();
175 }
176 }