1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.utgenome.gwt.utgb.client.track.lib.old;
26
27 import org.utgenome.gwt.utgb.client.track.Track;
28 import org.utgenome.gwt.utgb.client.track.operation.EventImpl;
29 import org.utgenome.gwt.utgb.client.track.operation.FrameCommand;
30 import org.utgenome.gwt.utgb.client.track.operation.FrameOperation;
31 import org.utgenome.gwt.utgb.client.track.operation.LinkOperation;
32 import org.utgenome.gwt.utgb.client.track.operation.MenuOperation;
33 import org.utgenome.gwt.utgb.client.track.operation.MenuOperationItem;
34 import org.utgenome.gwt.utgb.client.track.operation.MouseClickEventImpl;
35 import org.utgenome.gwt.utgb.client.track.operation.Operation;
36 import org.utgenome.gwt.utgb.client.track.operation.OperationArea;
37 import org.utgenome.gwt.utgb.client.track.operation.OperationParser;
38 import org.utgenome.gwt.utgb.client.track.operation.SubOperation;
39
40 import com.google.gwt.core.client.GWT;
41 import com.google.gwt.user.client.ui.AbsolutePanel;
42 import com.google.gwt.xml.client.Document;
43 import com.google.gwt.xml.client.Node;
44 import com.google.gwt.xml.client.NodeList;
45
46
47
48
49
50 public class OldUTGBOperationParser extends OperationParser {
51
52 private static final OldUTGBOperationParser _parser = new OldUTGBOperationParser();
53
54 public static OperationParser getParser() {
55 return _parser;
56 }
57
58 private static final String RECT_AREA_NODE_NAME = "rect_area";
59
60 public final void parse(final Document document, final AbsolutePanel panel, final Track track) {
61 final NodeList rectAreaNodeList = document.getElementsByTagName(RECT_AREA_NODE_NAME);
62
63 for (int i = 0; i < rectAreaNodeList.getLength(); i++) {
64 final Node rectAreaNode = rectAreaNodeList.item(i);
65
66 final OperationArea operationArea = OperationArea.newInstance(rectAreaNode);
67 OperationArea.add(panel, operationArea);
68
69 final NodeList eventNodeList = Utilities.getTagChildNodes(rectAreaNode);
70 for (int j = 0; j < eventNodeList.getLength(); j++) {
71 final Node eventNode = eventNodeList.item(j);
72
73 final EventImpl eventListener = parseEventNode(eventNode);
74
75 operationArea.addEventHandler(eventListener);
76
77 final NodeList operationNodeList = Utilities.getTagChildNodes(eventNode);
78 for (int k = 0; k < operationNodeList.getLength(); k++) {
79 final Node operationNode = operationNodeList.item(k);
80
81 final Operation operation = parseOperationNode(operationNode, track);
82
83 eventListener.addOperation(operation);
84 }
85 }
86 }
87 }
88
89 protected final EventImpl parseEventNode(final Node eventNode) {
90 final String name = eventNode.getNodeName();
91
92 if (name.equals("mouseclick_event")) {
93 final MouseClickEventImpl mouseClickEvent = new MouseClickEventImpl();
94 return mouseClickEvent;
95 }
96
97 return null;
98 }
99
100 public final Operation parseOperationNode(final Node operationNode, final Track track) {
101 final String name = operationNode.getNodeName();
102
103 if (name.equals("link_operation")) {
104 final LinkOperation linkOperation = new LinkOperation(operationNode);
105 return linkOperation;
106 }
107
108 if (name.equals("menu_operation")) {
109 final MenuOperation menuOperation = new MenuOperation(operationNode);
110
111 final NodeList menuItemNodeList = Utilities.getTagChildNodes(operationNode);
112 for (int i = 0; i < menuItemNodeList.getLength(); i++) {
113 final Node menuItemNode = menuItemNodeList.item(i);
114
115 final MenuOperationItem menuItem = parseMenuItemNode(menuItemNode, track);
116 menuOperation.addMenuItem(menuItem);
117 }
118 return menuOperation;
119 }
120
121 if (name.equals("frame_operation")) {
122 final FrameOperation frameOperation = new FrameOperation(operationNode, track);
123
124 final NodeList commandNodeList = Utilities.getTagChildNodes(operationNode);
125 for (int i = 0; i < commandNodeList.getLength(); i++) {
126 final Node commandNode = commandNodeList.item(i);
127
128 try {
129 final FrameCommand frameCommand = parseCommandNode(commandNode, track);
130 frameOperation.addCommand(frameCommand);
131 }
132 catch (NumberFormatException e) {
133 GWT.log("invalid number", e);
134 }
135 }
136 return frameOperation;
137 }
138
139 if (name.equals("suboperation")) {
140 final SubOperation subOperation = new OldUTGBSubOperationImpl(operationNode, track);
141 return subOperation;
142 }
143
144 return null;
145 }
146
147 protected final MenuOperationItem parseMenuItemNode(final Node menuItemNode, final Track track) {
148 final MenuOperationItem menuItem = new MenuOperationItem(menuItemNode);
149 final NodeList operationNodeList = Utilities.getTagChildNodes(menuItemNode);
150 for (int i = 0; i < operationNodeList.getLength(); i++) {
151 final Node operationNode = operationNodeList.item(i);
152
153 final Operation operation = parseOperationNode(operationNode, track);
154
155 menuItem.addOperation(operation);
156 }
157
158 return menuItem;
159 }
160
161 protected final FrameCommand parseCommandNode(final Node commandNode, final Track track) {
162 final FrameCommand frameCommand = OldUTGBFrameCommandImpl.newInstance(commandNode);
163
164 return frameCommand;
165 }
166
167 }