KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > gui > base > dir > DirComponent


1 package net.sf.jftp.gui.base.dir;
2
3 import java.util.Vector JavaDoc;
4
5 import javax.swing.JTable JavaDoc;
6 import javax.swing.event.ListSelectionEvent JavaDoc;
7 import javax.swing.event.ListSelectionListener JavaDoc;
8
9 import net.sf.jftp.config.Settings;
10
11
12 public class DirComponent extends DirPanel implements ListSelectionListener JavaDoc {
13
14     public JTable JavaDoc table = new JTable JavaDoc();
15     DirPanel target;
16     
17     public DirComponent() {
18     
19         table.setDefaultRenderer(Object JavaDoc.class, new ColoredCellRenderer());
20         table.getSelectionModel().addListSelectionListener(this);
21         
22         //table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
23
table.setRowSelectionAllowed(true);
24         table.setColumnSelectionAllowed(false);
25     }
26     
27     public void update() {
28         if(Settings.getUseJTableLayout()) {
29             Vector JavaDoc colNames = new Vector JavaDoc();
30             colNames.add("");
31             colNames.add("Name");
32             colNames.add("Size");
33             colNames.add("##");
34
35             TableUtils.layoutTable(jl, table, colNames);
36         }
37     }
38
39        /**
40         * This manages the selections
41         */

42         public void valueChanged(ListSelectionEvent JavaDoc e)
43         {
44             if(e.getValueIsAdjusting() == false)
45             {
46                 if(Settings.getUseJTableLayout()) {
47                     TableUtils.copyTableSelectionsToJList(jl, table);
48                 }
49                 
50                 // ui refresh bugfix
51
int index = jl.getSelectedIndex() - 1;
52
53                 if((index < 0) || (dirEntry == null) || (dirEntry.length < index) ||
54                        (dirEntry[index] == null))
55                 {
56                     return;
57                 }
58                 else
59                 { // -------------------- local --------------------------
60

61                     String JavaDoc tgt = (String JavaDoc) jl.getSelectedValue().toString();
62
63                     for(int i = 0; i < dirEntry.length; i++)
64                     {
65                         dirEntry[i].setSelected(jl.isSelectedIndex(i + 1));
66                     }
67                 }
68             }
69         }
70
71     
72 }
73
Popular Tags