]> git.somenet.org - irc/pjirc-ng.git/blob - src/main/java/irc/gui/pixx/AWTDCCFile.java
Pjirc 2.2.1 as available on the net, reformatted and made it compile.
[irc/pjirc-ng.git] / src / main / java / irc / gui / pixx / AWTDCCFile.java
1 /*****************************************************/\r
2 /*          This java file is a part of the          */\r
3 /*                                                   */\r
4 /*           -  Plouf's Java IRC Client  -           */\r
5 /*                                                   */\r
6 /*   Copyright (C)  2002 - 2004 Philippe Detournay   */\r
7 /*                                                   */\r
8 /*         All contacts : theplouf@yahoo.com         */\r
9 /*                                                   */\r
10 /*  PJIRC is free software; you can redistribute     */\r
11 /*  it and/or modify it under the terms of the GNU   */\r
12 /*  General Public License as published by the       */\r
13 /*  Free Software Foundation; version 2 or later of  */\r
14 /*  the License.                                     */\r
15 /*                                                   */\r
16 /*  PJIRC is distributed in the hope that it will    */\r
17 /*  be useful, but WITHOUT ANY WARRANTY; without     */\r
18 /*  even the implied warranty of MERCHANTABILITY or  */\r
19 /*  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   */\r
20 /*  General Public License for more details.         */\r
21 /*                                                   */\r
22 /*  You should have received a copy of the GNU       */\r
23 /*  General Public License along with PJIRC; if      */\r
24 /*  not, write to the Free Software Foundation,      */\r
25 /*  Inc., 59 Temple Place, Suite 330, Boston,        */\r
26 /*  MA  02111-1307  USA                              */\r
27 /*                                                   */\r
28 /*****************************************************/\r
29 \r
30 package irc.gui.pixx;\r
31 \r
32 import irc.EventDispatcher;\r
33 import irc.dcc.DCCFile;\r
34 import irc.dcc.DCCFileListener;\r
35 \r
36 import java.awt.BorderLayout;\r
37 import java.awt.Color;\r
38 import java.awt.Frame;\r
39 import java.awt.Label;\r
40 import java.awt.event.WindowEvent;\r
41 import java.awt.event.WindowListener;\r
42 \r
43 /**\r
44  * The AWT dcc file interface.\r
45  */\r
46 public class AWTDCCFile implements DCCFileListener, WindowListener {\r
47         /**\r
48          * The file.\r
49          */\r
50         protected DCCFile _file;\r
51         /**\r
52          * The displayed frame.\r
53          */\r
54         protected Frame _frame;\r
55         /**\r
56          * The progress bar.\r
57          */\r
58         protected AWTProgressBar _bar;\r
59         private PixxConfiguration _pixxConfiguration;\r
60 \r
61         /**\r
62          * Create a new AWTDCCFile.\r
63          * \r
64          * @param config\r
65          *          the global irc configuration.\r
66          * @param file\r
67          *          the source DCCFile.\r
68          */\r
69         public AWTDCCFile(PixxConfiguration config, DCCFile file) {\r
70                 _pixxConfiguration = config;\r
71                 _file = file;\r
72                 _file.addDCCFileListener(this);\r
73 \r
74                 String str = "";\r
75                 if (file.isDownloading())\r
76                         str = _pixxConfiguration.getText(PixxTextProvider.GUI_RETREIVING_FILE, _file.getSize() + "");\r
77                 else\r
78                         str = _pixxConfiguration.getText(PixxTextProvider.GUI_SENDING_FILE, _file.getSize() + "");\r
79 \r
80                 Label label = new Label(str);\r
81 \r
82                 _frame = new Frame();\r
83                 _frame.setBackground(Color.white);\r
84 \r
85                 _frame.setLayout(new BorderLayout());\r
86                 _frame.addWindowListener(this);\r
87 \r
88                 _bar = new AWTProgressBar();\r
89                 _frame.add(label, BorderLayout.NORTH);\r
90                 _frame.add(_bar, BorderLayout.CENTER);\r
91 \r
92                 _frame.setTitle(_file.getName());\r
93                 _frame.setSize(400, 80);\r
94                 _frame.show();\r
95         }\r
96 \r
97         /**\r
98          * Release this object.\r
99          */\r
100         public void release() {\r
101                 _frame.removeAll();\r
102                 _file.removeDCCFileListener(this);\r
103                 _file = null;\r
104                 _frame.removeWindowListener(this);\r
105                 _frame.dispose();\r
106                 _frame = null;\r
107         }\r
108 \r
109         /**\r
110          * Get the source DCCFile.\r
111          * \r
112          * @return source DCCFile.\r
113          */\r
114         public DCCFile getFile() {\r
115                 return _file;\r
116         }\r
117 \r
118         /**\r
119          * Close this transfert.\r
120          */\r
121         public void close() {\r
122                 _frame.hide();\r
123         }\r
124 \r
125         @Override\r
126         public void transmitted(Integer icount, DCCFile file) {\r
127                 // activate();\r
128                 int count = icount.intValue();\r
129                 if ((count & 32767) == 0) {\r
130                         double pc = count;\r
131                         pc /= _file.getSize();\r
132                         _bar.setColor(Color.blue);\r
133                         _bar.setValue(pc);\r
134                         _bar.repaint();\r
135                 }\r
136         }\r
137 \r
138         @Override\r
139         public void finished(DCCFile file) {\r
140                 _frame.setTitle(_pixxConfiguration.getText(PixxTextProvider.GUI_TERMINATED, _file.getName()));\r
141                 _bar.setColor(Color.green);\r
142                 _bar.setValue(1);\r
143                 _bar.repaint();\r
144         }\r
145 \r
146         @Override\r
147         public void failed(DCCFile file) {\r
148                 _frame.setTitle(_pixxConfiguration.getText(PixxTextProvider.GUI_FAILED, _file.getName()));\r
149                 _bar.setColor(Color.red);\r
150                 _bar.repaint();\r
151 \r
152         }\r
153 \r
154         @Override\r
155         public void windowActivated(WindowEvent e) {\r
156         }\r
157 \r
158         @Override\r
159         public void windowClosed(WindowEvent e) {\r
160         }\r
161 \r
162         @Override\r
163         public void windowClosing(WindowEvent e) {\r
164                 EventDispatcher.dispatchEventAsync(_file, "leave", new Object[0]);\r
165         }\r
166 \r
167         @Override\r
168         public void windowDeactivated(WindowEvent e) {\r
169         }\r
170 \r
171         @Override\r
172         public void windowDeiconified(WindowEvent e) {\r
173         }\r
174 \r
175         @Override\r
176         public void windowIconified(WindowEvent e) {\r
177         }\r
178 \r
179         @Override\r
180         public void windowOpened(WindowEvent e) {\r
181         }\r
182 \r
183 }\r