View Javadoc
1   package wjhk.jupload2.gui.filepanel.treeview;
2   
3   import java.awt.Component;
4   import java.awt.event.MouseEvent;
5   import java.util.EventObject;
6   
7   import javax.swing.AbstractCellEditor;
8   import javax.swing.JTable;
9   import javax.swing.JTree;
10  import javax.swing.table.TableCellEditor;
11  
12  /**
13   * This code is taken from the tutorial written by Jörn Hameister, <A
14   * HREF="http://www.hameister.org/JavaSwingTreeTable.html">available here</A>.<BR/>
15   * <BR/>
16   * This class is a generic class. It has not been adapted for JUpload. It's directly taken from Jörn Hameister tutorial<BR/>
17   * In order to allow the unfolding of the tree one, needs a AbstractCellEditor . That's why you put a class
18   * MyTreeTableCellEditor to the AbstractCellEditor expanded and the TableCellEditor implemented interface. The only
19   * function of the class MyTreeTableCellEditor is forwarding a double-click on the tree. In the method isCellEditable is
20   * checked whether the first column ( column1 ) was clicked. If this is the case, a double click is on the tree forward,
21   * so that the ExpansionListener can respond.
22   * 
23   * @author Jörn Hameister
24   */
25  public class MyTreeTableCellEditor extends AbstractCellEditor implements TableCellEditor {
26  
27      private static final long serialVersionUID = 1L;
28  
29      private JTree tree;
30  
31      private JTable table;
32  
33      public MyTreeTableCellEditor(JTree tree, JTable table) {
34          this.tree = tree;
35          this.table = table;
36      }
37  
38      public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int r, int c) {
39          return tree;
40      }
41  
42      public boolean isCellEditable(EventObject e) {
43          if (e instanceof MouseEvent) {
44              int colunm1 = 0;
45              MouseEvent me = (MouseEvent) e;
46              int doubleClick = 2;
47              MouseEvent newME = new MouseEvent(tree, me.getID(), me.getWhen(), me.getModifiers(), me.getX()
48                      - table.getCellRect(0, colunm1, true).x, me.getY(), doubleClick, me.isPopupTrigger());
49              tree.dispatchEvent(newME);
50          }
51          return false;
52      }
53  
54      // @Override
55      public Object getCellEditorValue() {
56          return null;
57      }
58  
59  }