View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2007 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // GenomeBrowser Project
18  //
19  // OldUTGBOperationParser.java
20  // Since: 2007/06/21
21  //
22  // $URL$ 
23  // $Author$
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   * @author ssksn
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++) { // STEP 1: for each rect_area node
64  			final Node rectAreaNode = rectAreaNodeList.item(i);
65  
66  			final OperationArea operationArea = OperationArea.newInstance(rectAreaNode); // STEP 1-1: construct an operationArea object
67  			OperationArea.add(panel, operationArea); // STEP 1-2: add(register) the operationArea object to AbsolutePanel
68  
69  			final NodeList eventNodeList = Utilities.getTagChildNodes(rectAreaNode);
70  			for (int j = 0; j < eventNodeList.getLength(); j++) { // STEP 2: for each event node
71  				final Node eventNode = eventNodeList.item(j);
72  
73  				final EventImpl eventListener = parseEventNode(eventNode); // STEP 2-1: construct an event node
74  
75  				operationArea.addEventHandler(eventListener); // STEP 2-2: add(register) the event node to the operationArea
76  
77  				final NodeList operationNodeList = Utilities.getTagChildNodes(eventNode);
78  				for (int k = 0; k < operationNodeList.getLength(); k++) { // STEP 3: for each operation node
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 }