View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2008 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  // utgb-widget Project
18  //
19  // HorizontalDraggablePanel.java
20  // Since: May 1, 2008
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.gwt.widget.client;
26  
27  import java.util.Iterator;
28  
29  import com.allen_sauer.gwt.dnd.client.PickupDragController;
30  import com.allen_sauer.gwt.dnd.client.drop.IndexedDropController;
31  import com.google.gwt.user.client.ui.AbsolutePanel;
32  import com.google.gwt.user.client.ui.Composite;
33  import com.google.gwt.user.client.ui.VerticalPanel;
34  import com.google.gwt.user.client.ui.Widget;
35  
36  /**
37   * VerticalPanel with Drag & Drop support
38   * 
39   * @author leo
40   * 
41   */
42  public class VerticalDraggableTrackPanel extends Composite implements TrackPanel {
43  
44  	private class MyDragController extends PickupDragController {
45  		public MyDragController(AbsolutePanel boundaryPanel, boolean allowDroppingOnBoundaryPanel) {
46  			super(boundaryPanel, allowDroppingOnBoundaryPanel);
47  		}
48  
49  		@Override
50  		public void dragStart() {
51  			Style.overflowHidden(absolutePanel);
52  			super.dragStart();
53  		}
54  
55  		@Override
56  		public void dragEnd() {
57  			Style.overflowAuto(absolutePanel);
58  			super.dragEnd();
59  		}
60  	}
61  
62  	public static final String TABLE_STYLE = "dg-table";
63  
64  	private AbsolutePanel absolutePanel = new AbsolutePanel();
65  	private VerticalPanel verticalPanel = new VerticalPanel();
66  
67  	private MyDragController widgetDragController;
68  	private IndexedDropController widgetDropController;
69  
70  	public VerticalDraggableTrackPanel() {
71  
72  		initWidget(absolutePanel);
73  		drawWidget();
74  
75  		widgetDragController = new MyDragController(absolutePanel, false);
76  		widgetDropController = new IndexedDropController(verticalPanel);
77  
78  		widgetDragController.setBehaviorConstrainedToBoundaryPanel(false);
79  		widgetDragController.registerDropController(widgetDropController);
80  
81  	}
82  
83  	public void setSpacing(int spacing) {
84  		verticalPanel.setSpacing(0);
85  	}
86  
87  	public void setBorderWidth(int borderWidth) {
88  		verticalPanel.setBorderWidth(0);
89  	}
90  
91  	protected void drawWidget() {
92  		Style.fullSize(absolutePanel);
93  		Style.overflowAuto(absolutePanel);
94  		absolutePanel.add(verticalPanel);
95  	}
96  
97  	/**
98  	 * Do not make the widget draggable
99  	 * 
100 	 * @param w
101 	 */
102 	public void add(Widget w) {
103 		if (w instanceof TrackFrame) {
104 			TrackFrame frame = (TrackFrame) w;
105 			add(frame, frame.getDraggableWidget());
106 		}
107 		else
108 			verticalPanel.add(w);
109 	}
110 
111 	/**
112 	 * Get the index of the specified child widget position
113 	 * 
114 	 * @param w
115 	 * @return
116 	 */
117 	public int getIndex(Widget w) {
118 		return verticalPanel.getWidgetIndex(w);
119 	}
120 
121 	/**
122 	 * Add the widge with the specified drag handle before the location beforeIndex
123 	 * 
124 	 * @param w
125 	 * @param dragHandle
126 	 * @param beforeIndex
127 	 */
128 	public void insert(Widget w, Widget dragHandle, int beforeIndex) {
129 		widgetDragController.makeDraggable(w, dragHandle);
130 		verticalPanel.insert(w, beforeIndex);
131 	}
132 
133 	/**
134 	 * Add the widget with the specified drag hanel
135 	 * 
136 	 * @param w
137 	 * @param dragHandle
138 	 *            draggable part in the Widget w
139 	 */
140 	public void add(Widget w, Widget dragHandle) {
141 		widgetDragController.makeDraggable(w, dragHandle);
142 		verticalPanel.add(w);
143 	}
144 
145 	public Iterator<Widget> iterator() {
146 		return verticalPanel.iterator();
147 	}
148 
149 	public boolean remove(Widget w) {
150 		return verticalPanel.remove(w);
151 	}
152 
153 	public boolean empty() {
154 		return verticalPanel.getWidgetCount() == 0;
155 	}
156 
157 	public void clear() {
158 		verticalPanel.clear();
159 	}
160 
161 }