1
23package org.jzuul.gdk.swt;
24
25import java.util.Iterator;
26import java.util.List;
27
28import org.eclipse.swt.SWT;
29import org.eclipse.swt.events.SelectionEvent;
30import org.eclipse.swt.events.SelectionListener;
31import org.eclipse.swt.layout.GridData;
32import org.eclipse.swt.layout.GridLayout;
33import org.eclipse.swt.widgets.Button;
34import org.eclipse.swt.widgets.Combo;
35import org.eclipse.swt.widgets.Composite;
36import org.eclipse.swt.widgets.Label;
37import org.eclipse.swt.widgets.Shell;
38import org.eclipse.swt.widgets.Text;
39import org.jdom.Element;
40
41
48
49public class DefaultRoomPropertyComposite extends RoomPropertyComposite {
50 Combo northRoomCombo, eastRoomCombo, southRoomCombo, westRoomCombo,
51 upRoomCombo, downRoomCombo;
52
53 Text northRoomDescription, eastRoomDescription, southRoomDescription,
54 westRoomDescription, upRoomDescription, downRoomDescription;
55
56 Element room;
57
58 String map;
59
60
64 public DefaultRoomPropertyComposite(Composite arg0, int arg1,
65 Element roomElement, String mapName) {
66 super(arg0, arg1);
67 room = roomElement;
68 map = mapName;
69 GridData wvDat = new GridData(GridData.FILL_BOTH);
71 wvDat.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER;
72 this.setLayoutData(wvDat);
73 this.setLayout(new GridLayout(5, false));
74
75 {
77 Label nLabel = new Label(this, SWT.NONE);
78 nLabel.setText(Messages.getString("NORTH"));
80 northRoomCombo = new Combo(this, SWT.READ_ONLY);
81 GridData nrcData = new GridData(GridData.FILL_HORIZONTAL);
82 nrcData.horizontalSpan = 2;
83 northRoomCombo.setLayoutData(nrcData);
84
85 northRoomDescription = new Text(this, SWT.BORDER);
86 GridData nrdData = new GridData(GridData.FILL_HORIZONTAL);
87 nrdData.horizontalSpan = 2;
88 northRoomDescription.setLayoutData(nrdData);
89 northRoomDescription.setToolTipText(Messages.getString("VIEW_TOOLTIP")); }
91 {
93 Label eLabel = new Label(this, SWT.NONE);
94 eLabel.setText(Messages.getString("EAST"));
96 eastRoomCombo = new Combo(this, SWT.READ_ONLY);
97 GridData ercData = new GridData(GridData.FILL_HORIZONTAL);
98 ercData.horizontalSpan = 2;
99 eastRoomCombo.setLayoutData(ercData);
00
01 eastRoomDescription = new Text(this, SWT.BORDER);
02 GridData erdData = new GridData(GridData.FILL_HORIZONTAL);
03 erdData.horizontalSpan = 2;
04 eastRoomDescription.setLayoutData(erdData);
05 eastRoomDescription.setToolTipText(Messages.getString("VIEW_TOOLTIP")); }
07 {
09 Label sLabel = new Label(this, SWT.NONE);
10 sLabel.setText(Messages.getString("SOUTH"));
12 southRoomCombo = new Combo(this, SWT.READ_ONLY);
13 GridData srcData = new GridData(GridData.FILL_HORIZONTAL);
14 srcData.horizontalSpan = 2;
15 southRoomCombo.setLayoutData(srcData);
16
17 southRoomDescription = new Text(this, SWT.BORDER);
18 GridData srdData = new GridData(GridData.FILL_HORIZONTAL);
19 srdData.horizontalSpan = 2;
20 southRoomDescription.setLayoutData(srdData);
21 southRoomDescription.setToolTipText(Messages.getString("VIEW_TOOLTIP")); }
23 {
25 Label wLabel = new Label(this, SWT.NONE);
26 wLabel.setText(Messages.getString("WEST"));
28 westRoomCombo = new Combo(this, SWT.READ_ONLY);
29 GridData wrcData = new GridData(GridData.FILL_HORIZONTAL);
30 wrcData.horizontalSpan = 2;
31 westRoomCombo.setLayoutData(wrcData);
32
33 westRoomDescription = new Text(this, SWT.BORDER);
34 GridData wrdData = new GridData(GridData.FILL_HORIZONTAL);
35 wrdData.horizontalSpan = 2;
36 westRoomDescription.setLayoutData(wrdData);
37 westRoomDescription.setToolTipText(Messages.getString("VIEW_TOOLTIP")); }
39 {
41 Label uLabel = new Label(this, SWT.NONE);
42 uLabel.setText(Messages.getString("UP"));
44 upRoomCombo = new Combo(this, SWT.READ_ONLY);
45 GridData upcData = new GridData(GridData.FILL_HORIZONTAL);
46 upcData.horizontalSpan = 2;
47 upRoomCombo.setLayoutData(upcData);
48
49 upRoomDescription = new Text(this, SWT.BORDER);
50 GridData updData = new GridData(GridData.FILL_HORIZONTAL);
51 updData.horizontalSpan = 2;
52 upRoomDescription.setLayoutData(updData);
53 upRoomDescription.setToolTipText(Messages.getString("VIEW_TOOLTIP")); }
55 {
57 Label dLabel = new Label(this, SWT.NONE);
58 dLabel.setText(Messages.getString("DOWN"));
60 downRoomCombo = new Combo(this, SWT.READ_ONLY);
61 GridData docData = new GridData(GridData.FILL_HORIZONTAL);
62 docData.horizontalSpan = 2;
63 downRoomCombo.setLayoutData(docData);
64
65 downRoomDescription = new Text(this, SWT.BORDER);
66 GridData dodData = new GridData(GridData.FILL_HORIZONTAL);
67 dodData.horizontalSpan = 2;
68 downRoomDescription.setLayoutData(dodData);
69 downRoomDescription.setToolTipText(Messages.getString("VIEW_TOOLTIP")); }
71
72 Button contents = new Button(this, SWT.PUSH);
73 contents.setText(Messages.getString("EDIT_CONTENTS")); contents.addSelectionListener(new SelectionListener() {
75
76 public void widgetSelected(SelectionEvent arg0) {
77 ContentsEditorDialog ed = new ContentsEditorDialog(new Shell(
78 arg0.display), SWT.NONE);
79 ed.open(room);
80 }
81
82 public void widgetDefaultSelected(SelectionEvent arg0) {}
83 });
84
85 Button events = new Button(this, SWT.PUSH);
86 events.setText(Messages.getString("EDIT_EVENTS")); events.addSelectionListener(new SelectionListener() {
88
89 public void widgetSelected(SelectionEvent arg0) {
90 String[] roomEvents = { "playerenter", "playerleave", "timer" }; EventEditorDialog ed = new EventEditorDialog(new Shell(
92 arg0.display), SWT.NONE);
93 ed.setEvents(roomEvents);
94 ed.open(room.getChildren("event"));
96 }
97
98 public void widgetDefaultSelected(SelectionEvent arg0) {}
99 });
00
01 }
02
03 public void showRoomProperties() {
04 String[] rooms = JdomHelpers.getRoomListForMap(room, map);
05
06 northRoomCombo.setItems(rooms);
07 northRoomCombo.add(""); northRoomCombo.remove(room.getAttributeValue("name"));
10 eastRoomCombo.setItems(rooms);
11 eastRoomCombo.add(""); eastRoomCombo.remove(room.getAttributeValue("name"));
14 southRoomCombo.setItems(rooms);
15 southRoomCombo.add(""); southRoomCombo.remove(room.getAttributeValue("name"));
18 westRoomCombo.setItems(rooms);
19 westRoomCombo.add(""); westRoomCombo.remove(room.getAttributeValue("name"));
22 upRoomCombo.setItems(rooms);
23 upRoomCombo.add(""); upRoomCombo.remove(room.getAttributeValue("name"));
26 downRoomCombo.setItems(rooms);
27 downRoomCombo.add(""); downRoomCombo.remove(room.getAttributeValue("name"));
30 Element description = room.getChild("views"); if (description != null) {
32 List views = description.getChildren("view"); for (Iterator viewIter = views.iterator(); viewIter.hasNext();) {
34 Element viewElement = (Element) viewIter.next();
35 if (viewElement.getAttributeValue("direction").equals("north")) { northRoomDescription.setText(viewElement.getText());
37 }
38 if (viewElement.getAttributeValue("direction").equals("east")) { eastRoomDescription.setText(viewElement.getText());
40 }
41 if (viewElement.getAttributeValue("direction").equals("south")) { southRoomDescription.setText(viewElement.getText());
43 }
44 if (viewElement.getAttributeValue("direction").equals("west")) { westRoomDescription.setText(viewElement.getText());
46 }
47 if (viewElement.getAttributeValue("direction").equals("above")) { upRoomDescription.setText(viewElement.getText());
49 }
50 if (viewElement.getAttributeValue("direction").equals("below")) { downRoomDescription.setText(viewElement.getText());
52 }
53 }
54
55 }
56 Element ways = room.getChild("ways"); if (ways != null) {
58 List wayList = ways.getChildren("way"); for (Iterator wayIter = wayList.iterator(); wayIter.hasNext();) {
60 Element wayElement = (Element) wayIter.next();
61 if (wayElement.getAttributeValue("direction").equals("north")) { northRoomCombo.select(northRoomCombo.indexOf(wayElement
63 .getAttributeValue("room"))); }
65 if (wayElement.getAttributeValue("direction").equals("east")) { eastRoomCombo.select(eastRoomCombo.indexOf(wayElement
67 .getAttributeValue("room"))); }
69 if (wayElement.getAttributeValue("direction").equals("south")) { southRoomCombo.select(southRoomCombo.indexOf(wayElement
71 .getAttributeValue("room"))); }
73 if (wayElement.getAttributeValue("direction").equals("west")) { westRoomCombo.select(westRoomCombo.indexOf(wayElement
75 .getAttributeValue("room"))); }
77 if (wayElement.getAttributeValue("direction").equals("above")) { upRoomCombo.select(upRoomCombo.indexOf(wayElement
79 .getAttributeValue("room"))); }
81 if (wayElement.getAttributeValue("direction").equals("below")) { downRoomCombo.select(downRoomCombo.indexOf(wayElement
83 .getAttributeValue("room"))); }
85 }
86
87 }
88 }
89
90 public void clear() {
91 northRoomCombo.removeAll();
92 northRoomDescription.setText("");
94 eastRoomCombo.removeAll();
95 eastRoomDescription.setText("");
97 southRoomCombo.removeAll();
98 southRoomDescription.setText("");
00 westRoomCombo.removeAll();
01 westRoomDescription.setText("");
03 upRoomCombo.removeAll();
04 upRoomDescription.setText("");
06 downRoomCombo.removeAll();
07 downRoomDescription.setText("");
09 room = null;
10 }
11
12 public void dispose() {
13 if (room != null) {
14
15 Element views = new Element("views"); Element ways = new Element("ways");
18 if (!northRoomCombo.getText().equals("")) { Element way = new Element("way"); way.setAttribute("direction", "north"); way.setAttribute("room", northRoomCombo.getText()); ways.addContent(way);
23 }
24 if (!northRoomDescription.getText().equals("")) { Element view = new Element("view"); view.setAttribute("direction", "north"); view.setText(northRoomDescription.getText());
28 views.addContent(view);
29 }
30
31 if (!eastRoomCombo.getText().equals("")) { Element way = new Element("way"); way.setAttribute("direction", "east"); way.setAttribute("room", eastRoomCombo.getText()); ways.addContent(way);
36 }
37 if (!eastRoomDescription.getText().equals("")) { Element view = new Element("view"); view.setAttribute("direction", "east"); view.setText(eastRoomDescription.getText());
41 views.addContent(view);
42 }
43
44 if (!southRoomCombo.getText().equals("")) { Element way = new Element("way"); way.setAttribute("direction", "south"); way.setAttribute("room", southRoomCombo.getText()); ways.addContent(way);
49 }
50 if (!southRoomDescription.getText().equals("")) { Element view = new Element("view"); view.setAttribute("direction", "south"); view.setText(southRoomDescription.getText());
54 views.addContent(view);
55 }
56
57 if (!westRoomCombo.getText().equals("")) { Element way = new Element("way"); way.setAttribute("direction", "west"); way.setAttribute("room", westRoomCombo.getText()); ways.addContent(way);
62 }
63 if (!westRoomDescription.getText().equals("")) { Element view = new Element("view"); view.setAttribute("direction", "west"); view.setText(westRoomDescription.getText());
67 views.addContent(view);
68 }
69 if (!upRoomCombo.getText().equals("")) { Element way = new Element("way"); way.setAttribute("direction", "above"); way.setAttribute("room", upRoomCombo.getText()); ways.addContent(way);
74 }
75 if (!upRoomDescription.getText().equals("")) { Element view = new Element("view"); view.setAttribute("direction", "above"); view.setText(upRoomDescription.getText());
79 views.addContent(view);
80 }
81 if (!downRoomCombo.getText().equals("")) { Element way = new Element("way"); way.setAttribute("direction", "below"); way.setAttribute("room", downRoomCombo.getText()); ways.addContent(way);
86 }
87 if (!downRoomDescription.getText().equals("")) { Element view = new Element("view"); view.setAttribute("direction", "below"); view.setText(downRoomDescription.getText());
91 views.addContent(view);
92 }
93
94 room.removeChildren("views"); room.removeChildren("ways");
97 if (ways.getChildren().size() > 0) {
98 room.addContent(ways);
99 }
00 if (views.getChildren().size() > 0) {
01 room.addContent(views);
02 }
03 }
04
05 super.dispose();
06 }
07
08}