01: /*
02: * Beryl - A web platform based on XML, XSLT and Java
03: * This file is part of the Beryl XML GUI
04: *
05: * Copyright (C) 2004 Wenzel Jakob <wazlaf@tigris.org>
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11:
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-3107 USA
20: */
21:
22: package org.beryl.gui.test;
23:
24: import org.beryl.gui.Controller;
25: import org.beryl.gui.GUIEvent;
26: import org.beryl.gui.GUIException;
27: import org.beryl.gui.MessageDialog;
28: import org.beryl.gui.SimpleTransferable;
29: import org.beryl.gui.model.ListDataModel;
30: import org.beryl.gui.model.MapDataModel;
31: import org.beryl.gui.widgets.Frame;
32: import org.beryl.gui.widgets.List;
33:
34: /**
35: * Drag'n'Drop test
36: */
37: public class DnDTest extends Controller {
38: private Frame frame = null;
39: private MapDataModel dataModel = null;
40:
41: public DnDTest() throws GUIException {
42: dataModel = new MapDataModel();
43: frame = constructFrame("DnDTest", dataModel);
44: List list1 = (List) frame.getWidget("List1");
45: List list2 = (List) frame.getWidget("List2");
46:
47: ListDataModel strings = new ListDataModel();
48: for (int i = 1; i <= 10; i++)
49: strings.addValue("Item " + i);
50:
51: list1.setListDataModel(strings);
52: list2.setListDataModel(new ListDataModel());
53:
54: dataModel.setValue("list1.value", new Object[] {});
55:
56: frame.show();
57: }
58:
59: public void eventOccured(GUIEvent event) {
60: try {
61: log.debug("Caught event : " + event.toString());
62: if (event.getName().equals("ok")) {
63: frame.dispose();
64: } else if (event.getName().equals("drag")) {
65: Object values[] = (Object[]) dataModel
66: .getValue("list1.value");
67: if (values.length > 0) {
68: SimpleTransferable transferable = new SimpleTransferable();
69: transferable.addData("text/x-stringarray", values);
70: event.setData(transferable);
71: }
72: } else if (event.getName().equals("drop")) {
73: Object values[] = (Object[]) event.getData();
74: List list2 = (List) event.getSource();
75: ListDataModel model = list2.getListDataModel();
76:
77: for (int i = 0; i < values.length; i++)
78: model.addValue(list2, values[i]);
79: }
80: } catch (Exception e) {
81: new MessageDialog(e);
82: }
83: }
84: }
|