KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > gui > windows > DCCListDialog


1 package rero.gui.windows;
2
3 import javax.swing.*;
4 import javax.swing.event.*;
5 import javax.swing.table.*;
6
7 import java.awt.*;
8 import java.awt.event.*;
9
10 import java.util.*;
11 import rero.util.*;
12
13 import contrib.javapro.*; // sorted JTable code...
14

15 import rero.ircfw.interfaces.*;
16
17 import rero.config.*;
18 import rero.client.*;
19
20 import rero.gui.*;
21 import rero.gui.windows.*;
22 import rero.gui.toolkit.*;
23
24 import text.*;
25
26 import rero.dcc.*;
27 import rero.client.output.*;
28
29 public class DCCListDialog extends GeneralListDialog implements TimerListener
30 {
31    public DCCListDialog()
32    {
33       super("DCC Sessions", "dcc", new DCCListModel());
34    }
35
36    public void timerExecute()
37    {
38       table.repaint();
39    }
40
41    private class DCCListener implements ChatListener, FrameworkConstants
42    {
43       public boolean isChatEvent(String JavaDoc event, HashMap eventData)
44       {
45          return (event.indexOf("CHAT_") > -1 || event.indexOf("SEND_") > -1 || event.indexOf("RECEIVE_") > -1);
46       }
47
48       public int fireChatEvent(HashMap data)
49       {
50          model.fireTableDataChanged();
51          return EVENT_DONE;
52       }
53    }
54
55    public void init()
56    {
57       ((DCCListModel)model).installData((DataDCC)capabilities.getDataStructure(DataStructures.DataDCC), capabilities.getOutputCapabilities());
58       model.fireTableDataChanged();
59
60       capabilities.getTimer().addTimer(this, 1000);
61       capabilities.addChatListener(new DCCListener());
62    }
63
64    private static class DCCListModel extends GeneralListModel
65    {
66       protected DataDCC data;
67       protected OutputCapabilities output;
68
69 // private HashMap event = new HashMap();
70

71       public HashMap getEventHashMap (int row)
72       {
73          HashMap event = new HashMap();
74
75          GenericDCC temp = (GenericDCC)getConnections().get(row);
76          event.put("$this", temp.getImplementation().toString());
77
78          return event;
79       }
80
81       public void installData(DataDCC d, OutputCapabilities o)
82       {
83          data = d;
84          output = o;
85       }
86
87       public void sortColumn(int col, boolean ascending)
88       {
89          fireTableDataChanged();
90       }
91
92       private java.util.List JavaDoc getConnections()
93       {
94          return data.getConnections(-1, ProtocolDCC.STATE_OPEN);
95       }
96
97       public int getRowCount()
98       {
99          if (data == null)
100              return 0;
101
102          return getConnections().size();
103       }
104
105       public int getColumnCount()
106       {
107          return 3;
108       }
109
110       public int getColumnWidth(int col)
111       {
112          if (col == 0)
113              return 75;
114
115          if (col == 1)
116              return 100;
117
118          return 400;
119       }
120
121       public String JavaDoc getColumnName(int col)
122       {
123          switch (col)
124          {
125             case 0:
126               return "Type";
127
128             case 1:
129               return "Nickname";
130
131             case 2:
132               return "Information";
133
134             case 3:
135               return "File";
136          }
137
138          return "Unknown";
139       }
140
141       public Object JavaDoc getValueAt(int row, int col)
142       {
143          if (row >= getRowCount())
144             return null;
145
146          HashMap temp = getEventHashMap(row);
147          String JavaDoc text = "";
148
149          switch (col)
150          {
151             case 0:
152               text = output.parseSet(temp, "DCC_LIST_TYPE");
153               break;
154
155             case 1:
156               text = output.parseSet(temp, "DCC_LIST_NICK");
157               break;
158
159             case 2:
160               text = output.parseSet(temp, "DCC_LIST_INFORMATION");
161               break;
162
163             case 3:
164               text = output.parseSet(temp, "DCC_LIST_FILE");
165               break;
166          }
167
168          AttributedString tempa = AttributedString.CreateAttributedString(text);
169          tempa.assignWidths();
170  
171          return tempa;
172       }
173
174       public boolean isSortable(int col)
175       {
176          return false;
177       }
178    }
179
180    public String JavaDoc getWindowType()
181    {
182       return "DCCStats";
183    }
184 }
185
Popular Tags