1
23package org.jzuul.gdk.swt;
24
25import org.eclipse.swt.SWT;
26import org.eclipse.swt.events.SelectionEvent;
27import org.eclipse.swt.events.SelectionListener;
28import org.eclipse.swt.layout.GridData;
29import org.eclipse.swt.layout.GridLayout;
30import org.eclipse.swt.widgets.Button;
31import org.eclipse.swt.widgets.Combo;
32import org.eclipse.swt.widgets.Composite;
33import org.eclipse.swt.widgets.Event;
34import org.eclipse.swt.widgets.FileDialog;
35import org.eclipse.swt.widgets.Group;
36import org.eclipse.swt.widgets.Label;
37import org.eclipse.swt.widgets.Shell;
38import org.eclipse.swt.widgets.Text;
39import org.jdom.Element;
40
41
48public class RoomDetailsComposite extends Composite {
49
50 protected RoomPropertyComposite roomProperties;
51
52 protected Element room;
53
54 private Text description;
55
56 private Text image;
57
58 private Combo type;
59
60 private Button findButton;
61
62 private String map;
63
64
68 public RoomDetailsComposite(Composite arg0, int arg1) {
69 super(arg0, arg1);
70 GridData myDat = new GridData(GridData.FILL_BOTH);
71 myDat.horizontalSpan = 4;
72 this.setLayoutData(myDat);
73 this.setLayout(new GridLayout(1, false));
74
75 Group roomProperty = new Group(this, SWT.NONE);
77 GridData rpDat = new GridData(GridData.FILL_HORIZONTAL);
78 rpDat.horizontalSpan = 1;
79 roomProperty.setLayoutData(rpDat);
80 roomProperty.setLayout(new GridLayout(4, false));
81
82 Label dLabel = new Label(roomProperty, SWT.NONE);
83 GridData dlData = new GridData(GridData.HORIZONTAL_ALIGN_END);
84 dlData.horizontalSpan = 1;
85 dLabel.setLayoutData(dlData);
86 dLabel.setText(Messages.getString("ROOM_DESCRIPTION"));
88 description = new Text(roomProperty, SWT.BORDER);
89 GridData dData = new GridData(GridData.FILL_HORIZONTAL);
90 dData.horizontalSpan = 3;
91 description.setLayoutData(dData);
92
93 Label iLabel = new Label(roomProperty, SWT.NONE);
94 GridData ilData = new GridData(GridData.HORIZONTAL_ALIGN_END);
95 ilData.horizontalSpan = 1;
96 iLabel.setLayoutData(ilData);
97 iLabel.setText(Messages.getString("ROOM_IMAGE"));
99 image = new Text(roomProperty, SWT.BORDER);
00 GridData iData = new GridData(GridData.FILL_HORIZONTAL);
01 iData.horizontalSpan = 2;
02 image.setLayoutData(iData);
03
04 findButton = new Button(roomProperty, SWT.PUSH);
05 GridData fbData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
06 fbData.horizontalSpan = 1;
07 findButton.setLayoutData(fbData);
08 findButton.setText(Messages.getString("SELECT")); findButton.addSelectionListener(new SelectionListener() {
10
11 public void widgetSelected(SelectionEvent arg0) {
12 FileDialog fd = new FileDialog(new Shell(arg0.display), SWT.OPEN);
13 fd.setText(Messages.getString("PICK_IMAGE")); fd.setFileName(image.getText());
15 String newName = fd.open();
16 if (newName != null) {
17 image.setText(newName);
18 }
19
20 }
21
22 public void widgetDefaultSelected(SelectionEvent arg0) {
23 }
24 });
25
26 Label tLabel = new Label(roomProperty, SWT.NONE);
27 GridData tlData = new GridData(GridData.HORIZONTAL_ALIGN_END);
28 tlData.horizontalSpan = 1;
29 tLabel.setLayoutData(tlData);
30 tLabel.setText(Messages.getString("TYPE_ROOM"));
32 type = new Combo(roomProperty, SWT.READ_ONLY);
33 GridData tcData = new GridData(GridData.FILL_HORIZONTAL);
34 tcData.horizontalSpan = 1;
35 type.setLayoutData(tcData);
36 type.add("room"); type.add("transitionroom"); type.add("beamroom"); type.select(0);
40 type.addSelectionListener(new SelectionListener() {
41
42 public void widgetSelected(SelectionEvent arg0) {
43 if (roomProperties != null) roomProperties.dispose();
44 if (type.getText().equals("room")) { roomProperties = new DefaultRoomPropertyComposite((Composite) RoomDetailsComposite.this,
46 SWT.NONE, room, map);
47 if (room != null) {
48 room.setName("room"); room.removeAttribute("final"); room.removeAttribute("target"); room.setAttribute("class", "org.jzuul.engine.rooms.Room"); }
53 }
54 if (type.getText().equals("transitionroom")) { roomProperties = new TransitionRoomPropertyComposite((Composite) RoomDetailsComposite.this,
56 SWT.NONE, room, map);
57 if (room != null) {
58 room.removeAttribute("class"); room.setName("transitionroom"); }
61 }
62 if (type.getText().equals("beamroom")) { roomProperties = new BeamRoomPropertyComposite((Composite) RoomDetailsComposite.this, SWT.NONE,
64 room, map);
65 if (room != null) {
66 room.setName("room"); room.removeAttribute("final"); room.removeAttribute("target"); room.setAttribute("class", "org.jzuul.engine.rooms.BeamRoom"); }
71 }
72 setEnabled(!type.getText().equals("transitionroom")); if (type.getText().equals("transitionroom")) { type.setEnabled(true);
75 }
76 RoomDetailsComposite.this.layout();
77 RoomDetailsComposite.this.redraw();
78
79 }
80
81 public void widgetDefaultSelected(SelectionEvent arg0) {
82 }
83 });
84 }
85
86 protected void showRoomDetails(Element roomElement, String mapName) {
87 this.cleanUpData();
88 this.map = mapName;
89 this.room = roomElement;
90 String desc = roomElement.getChildText("description"); if (desc != null && !desc.equals("")) { this.description.setText(desc);
93 } else {
94 this.description.setText(""); this.description.setFocus();
96 }
97 Element imageEl = roomElement.getChild("image"); if (imageEl != null) {
99 this.image.setText(imageEl.getAttributeValue("file")); } else {
01 this.image.setText(""); }
03 String typeName = getRoomType(roomElement);
04 setEnabled(!typeName.equals("transitionroom")); type.select(type.indexOf(typeName));
06 type.notifyListeners(SWT.Selection, new Event());
07 type.setEnabled(true);
08 roomProperties.showRoomProperties();
09 }
10
11 protected String getRoomType(Element roomElement) {
12 if (roomElement.getName().equals("transitionroom")) { return "transitionroom"; } String roomClass = roomElement.getAttributeValue("class"); if (roomClass == null) return "room"; roomClass = roomClass.replaceAll(".+\\.", ""); System.err.println("Room class is " + roomClass); return roomClass.toLowerCase();
18 }
19
20 protected void clear() {
21 setEnabled(false);
22 if (roomProperties != null) {
23 roomProperties.dispose();
24 roomProperties = null;
25 }
26
27 room = null;
28 description.setText(""); image.setText(""); type.select(0);
31
32 }
33
34 protected void cleanUpData() {
35 if (room != null) {
36 room.removeChildren("description"); if (!description.getText().equals("")) { room.addContent(new Element("description").setText(description.getText())); }
40
41 room.removeChildren("image"); if (!image.getText().equals("")) { room.addContent(new Element("image").setAttribute("file", image.getText())); }
45
46
47 }
48
49 }
50
51 public void setEnabled(boolean enabled) {
52 description.setEnabled(enabled);
53 image.setEnabled(enabled);
54 type.setEnabled(enabled);
55 findButton.setEnabled(enabled);
56 }
57
58 public void enable() {
59 setEnabled(true);
60 }
61
62 public void disable() {
63 setEnabled(false);
64 }
65
66}