1 /* 2 * Created on 01-Dec-2004 3 * Created by Paul Gardner 4 * Copyright (C) Azureus Software, Inc, All Rights Reserved. 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * 18 */ 19 20 package org.gudy.azureus2.ui.swt.update; 21 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.custom.StyledText; 24 import org.eclipse.swt.layout.FormAttachment; 25 import org.eclipse.swt.layout.FormData; 26 import org.eclipse.swt.layout.FormLayout; 27 import org.eclipse.swt.widgets.*; 28 import org.gudy.azureus2.core3.internat.MessageText; 29 import org.gudy.azureus2.core3.util.AERunnable; 30 import org.gudy.azureus2.plugins.update.*; 31 import org.gudy.azureus2.ui.swt.Messages; 32 import org.gudy.azureus2.ui.swt.Utils; 33 34 import java.util.ArrayList; 35 36 /** 37 * @author parg 38 * @deprecated This class is no longer maintained and may be removed sometime in the future; its 39 * functionality has been replaced by the new implementation of ProgressReportingWindow and ProgressReporter usage. KN 40 */ 41 42 public class 43 UpdateProgressWindow 44 implements UpdateManagerListener 45 { 46 public static void show( UpdateCheckInstance[] instances, Shell shell )47 show( 48 UpdateCheckInstance[] instances, 49 Shell shell ) 50 { 51 if ( instances.length == 0){ 52 53 return; 54 } 55 56 new UpdateProgressWindow().showSupport(instances,shell); 57 } 58 59 protected Display display; 60 protected Shell window; 61 protected StyledText text_area; 62 63 protected UpdateManager manager; 64 65 protected ArrayList current_instances = new ArrayList(); 66 67 protected void showSupport( UpdateCheckInstance[] instances, Shell shell )68 showSupport( 69 UpdateCheckInstance[] instances, 70 Shell shell ) 71 { 72 manager = instances[0].getManager(); 73 74 display = shell.getDisplay(); 75 76 window = org.gudy.azureus2.ui.swt.components.shell.ShellFactory.createShell(display,SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL); 77 Messages.setLanguageText(window,"updater.progress.window.title"); 78 Utils.setShellIcon(shell); 79 FormLayout layout = new FormLayout(); 80 try { 81 layout.spacing = 5; 82 } catch (NoSuchFieldError e) { 83 /* Ignore for Pre 3.0 SWT.. */ 84 } 85 layout.marginHeight = 5; 86 layout.marginWidth = 5; 87 window.setLayout(layout); 88 FormData formData; 89 90 // text area 91 92 text_area = new StyledText(window,SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); 93 94 text_area.setEditable(false); 95 96 Button btnOk = new Button(window,SWT.PUSH); 97 Button btnAbort = new Button(window,SWT.PUSH); 98 99 100 formData = new FormData(); 101 formData.left = new FormAttachment(0,0); 102 formData.right = new FormAttachment(100,0); 103 formData.top = new FormAttachment(0,0); 104 formData.bottom = new FormAttachment(90,0); 105 Utils.setLayoutData(text_area, formData); 106 107 108 // label 109 110 Label info_label = new Label(window, SWT.NULL); 111 Messages.setLanguageText(info_label,"updater.progress.window.info"); 112 formData = new FormData(); 113 formData.top = new FormAttachment(text_area); 114 formData.right = new FormAttachment(btnAbort); 115 formData.left = new FormAttachment(0,0); 116 Utils.setLayoutData(info_label, formData ); 117 118 119 // abort button 120 121 Messages.setLanguageText(btnAbort,"Button.abort"); 122 formData = new FormData(); 123 formData.right = new FormAttachment(btnOk); 124 formData.bottom = new FormAttachment(100,0); 125 formData.width = 70; 126 Utils.setLayoutData(btnAbort, formData); 127 btnAbort.addListener( 128 SWT.Selection, 129 new Listener() 130 { 131 public void 132 handleEvent( 133 Event e) 134 { 135 manager.removeListener( UpdateProgressWindow.this ); 136 137 for (int i=0;i<current_instances.size();i++){ 138 139 ((UpdateCheckInstance)current_instances.get(i)).cancel(); 140 } 141 142 window.dispose(); 143 } 144 }); 145 146 // ok button 147 148 Messages.setLanguageText(btnOk,"Button.ok"); 149 formData = new FormData(); 150 formData.right = new FormAttachment(95,0); 151 formData.bottom = new FormAttachment(100,0); 152 formData.width = 70; 153 Utils.setLayoutData(btnOk, formData); 154 btnOk.addListener( 155 SWT.Selection, 156 new Listener() 157 { 158 public void 159 handleEvent( 160 Event e) 161 { 162 manager.removeListener( UpdateProgressWindow.this ); 163 164 window.dispose(); 165 } 166 }); 167 168 window.setDefaultButton( btnOk ); 169 170 window.addListener(SWT.Traverse, new Listener() { 171 public void handleEvent(Event e) { 172 if ( e.character == SWT.ESC){ 173 174 manager.removeListener( UpdateProgressWindow.this ); 175 176 window.dispose(); 177 } 178 } 179 }); 180 181 manager.addListener( this ); 182 183 window.setSize(620,450); 184 window.layout(); 185 186 Utils.centreWindow( window ); 187 188 window.open(); 189 190 for (int i=0;i<instances.length;i++){ 191 192 addInstance( instances[i] ); 193 } 194 } 195 196 protected void log( UpdateCheckInstance instance, String str )197 log( 198 UpdateCheckInstance instance, 199 String str ) 200 { 201 String name = instance.getName(); 202 203 if ( MessageText.keyExists(name)){ 204 205 name = MessageText.getString( name ); 206 } 207 208 log( name + " - " + str ); 209 } 210 211 protected void log( UpdateChecker checker, String str )212 log( 213 UpdateChecker checker, 214 String str ) 215 { 216 log( " " + checker.getComponent().getName() + " - " + str ); 217 } 218 219 protected void log( final String str )220 log( 221 final String str ) 222 { 223 try{ 224 if ( !display.isDisposed()){ 225 226 display.asyncExec( 227 new AERunnable() 228 { 229 public void 230 runSupport() 231 { 232 if ( !text_area.isDisposed()){ 233 234 text_area.append( str + "\n" ); 235 } 236 } 237 }); 238 } 239 }catch( Throwable e ){ 240 241 } 242 } 243 public void checkInstanceCreated( UpdateCheckInstance instance )244 checkInstanceCreated( 245 UpdateCheckInstance instance ) 246 { 247 addInstance( instance ); 248 } 249 250 protected void addInstance( final UpdateCheckInstance instance )251 addInstance( 252 final UpdateCheckInstance instance ) 253 { 254 if ( !display.isDisposed()){ 255 256 display.asyncExec( 257 new AERunnable() 258 { 259 public void 260 runSupport() 261 { 262 if ( display.isDisposed() || window.isDisposed()){ 263 264 return; 265 } 266 267 if ( !current_instances.contains( instance )){ 268 269 current_instances.add( instance ); 270 271 log( instance, "added" ); 272 273 instance.addListener( 274 new UpdateCheckInstanceListener() 275 { 276 public void 277 cancelled( 278 UpdateCheckInstance instance ) 279 { 280 log( instance, "cancelled" ); 281 } 282 283 public void 284 complete( 285 UpdateCheckInstance instance ) 286 { 287 log( instance, "complete" ); 288 } 289 }); 290 291 UpdateChecker[] checkers = instance.getCheckers(); 292 293 for (int i=0;i<checkers.length;i++){ 294 295 final UpdateChecker checker = checkers[i]; 296 297 log( checker, "added" ); 298 299 checker.addListener( 300 new UpdateCheckerListener() 301 { 302 public void 303 completed( 304 UpdateChecker checker ) 305 { 306 log( checker, "completed" ); 307 } 308 309 public void 310 failed( 311 UpdateChecker checker ) 312 { 313 log( checker, "failed" ); 314 } 315 316 317 public void 318 cancelled( 319 UpdateChecker checker ) 320 { 321 log( checker, "cancelled" ); 322 } 323 }); 324 325 checker.addProgressListener( 326 new UpdateProgressListener() 327 { 328 public void 329 reportProgress( 330 String str ) 331 { 332 log( checker, " " + str ); 333 } 334 }); 335 } 336 } 337 } 338 }); 339 } 340 } 341 } 342