View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.support.dnd;
14  
15  import java.awt.Point;
16  import java.awt.Rectangle;
17  
18  import javax.swing.JComponent;
19  import javax.swing.JList;
20  
21  import com.eviware.soapui.model.ModelItem;
22  
23  public abstract class JListDragAndDropable<T extends JList> implements SoapUIDragAndDropable<ModelItem>
24  {
25  	private T list;
26  	private ModelItem parent;
27  
28  	public JListDragAndDropable( T list, ModelItem parent )
29  	{
30  		this.list = list;
31  		this.parent = parent;
32  	}
33  
34  	public T getList()
35  	{
36  		return list;
37  	}
38  
39  	public abstract ModelItem getModelItemAtRow( int row );
40  
41  	public JComponent getComponent()
42  	{
43  		return list;
44  	}
45  
46  	public Rectangle getModelItemBounds( ModelItem modelItem )
47  	{
48  		if( modelItem == parent )
49  			return list.getBounds();
50  
51  		int ix = getModelItemRow( modelItem );
52  		return list.getCellBounds( ix, ix );
53  	}
54  
55  	public abstract int getModelItemRow( ModelItem modelItem );
56  
57  	public void selectModelItem( ModelItem modelItem )
58  	{
59  		list.setSelectedIndex( getModelItemRow( modelItem ) );
60  	}
61  
62  	public void setDragInfo( String dropInfo )
63  	{
64  		list.setToolTipText( dropInfo );
65  	}
66  
67  	public ModelItem getModelItemForLocation( int x, int y )
68  	{
69  		int index = list.locationToIndex( new Point( x, y ) );
70  		return index == -1 ? parent : getModelItemAtRow( index );
71  	}
72  
73  	public void toggleExpansion( ModelItem last )
74  	{
75  	}
76  }