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  // MenuOperation.java
20  // Since: 2007/06/14
21  //
22  // $URL$ 
23  // $Author$ ssksn
24  //--------------------------------------
25  package org.utgenome.gwt.utgb.client.track.operation;
26  
27  import java.util.ArrayList;
28  
29  import org.utgenome.gwt.utgb.client.track.lib.old.Utilities;
30  
31  import com.google.gwt.user.client.ui.DockPanel;
32  import com.google.gwt.user.client.ui.Label;
33  import com.google.gwt.user.client.ui.PopupPanel;
34  import com.google.gwt.user.client.ui.ScrollPanel;
35  import com.google.gwt.user.client.ui.VerticalPanel;
36  import com.google.gwt.user.client.ui.Widget;
37  import com.google.gwt.xml.client.Node;
38  
39  /**
40   * @author ssksn
41   * 
42   */
43  public class MenuOperation implements Operation {
44  	final String title;
45  	final ArrayList<MenuOperationItem> menuItems = new ArrayList<MenuOperationItem>();
46  
47  	public MenuOperation(final Node menuOperationNode) {
48  		this(Utilities.getAttributeValue(menuOperationNode, "title"));
49  	}
50  
51  	public MenuOperation(final String title) {
52  		this.title = title;
53  	}
54  
55  	class MenuPopupWindow extends PopupPanel {
56  		public MenuPopupWindow(final String title, final boolean autoHide, final ArrayList<MenuOperationItem> _menuItems) {
57  			super(autoHide);
58  
59  			setTitle(title);
60  
61  			final DockPanel _panel = new DockPanel();
62  			_panel.setHorizontalAlignment(DockPanel.ALIGN_CENTER);
63  			_panel.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
64  			_panel.setStyleName("menu-popup");
65  			// _panel.setSize("150px", "150px");
66  
67  			final Label titleLabel = new Label(title);
68  			titleLabel.setStyleName("menu-popup-title");
69  			_panel.add(titleLabel, DockPanel.NORTH);
70  
71  			final VerticalPanel verticalPanel = new VerticalPanel();
72  			verticalPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
73  			verticalPanel.setVerticalAlignment(VerticalPanel.ALIGN_TOP);
74  			verticalPanel.setWidth("100%");
75  
76  			{ // add menu items
77  				final int itemNum = menuItems.size();
78  				for (int i = 0; i < itemNum; i++) {
79  					final MenuOperationItem menuItem = (MenuOperationItem) (menuItems.get(i));
80  
81  					final Widget menuWidget = menuItem.getWidget(this);
82  					menuWidget.setWidth("100%");
83  					verticalPanel.add(menuWidget);
84  				}
85  			}
86  
87  			final ScrollPanel scrollPanel = new ScrollPanel(verticalPanel);
88  			scrollPanel.setAlwaysShowScrollBars(false);
89  			_panel.add(scrollPanel, DockPanel.CENTER);
90  			scrollPanel.setWidth("100%");
91  			scrollPanel.setHeight("150px");
92  			setWidget(_panel);
93  
94  			// setSize("150px", "150px");
95  		}
96  	}
97  
98  	public void execute(Widget sender, int x, int y) {
99  		final MenuPopupWindow menuWindow = new MenuPopupWindow(title, true, menuItems);
100 
101 		{ // set location
102 			final int offsetX = sender.getAbsoluteLeft();
103 			final int offsetY = sender.getAbsoluteTop();
104 
105 			menuWindow.setPopupPosition(offsetX + x, offsetY + y);
106 		}
107 
108 		menuWindow.show();
109 	}
110 
111 	public void addMenuItem(final MenuOperationItem menuItem) {
112 		menuItems.add(menuItem);
113 	}
114 
115 }