| 1 19 20 package com.sslexplorer.agent.client.gui.swt; 21 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.layout.GridData; 24 import org.eclipse.swt.layout.GridLayout; 25 import org.eclipse.swt.widgets.Button; 26 import org.eclipse.swt.widgets.Event; 27 import org.eclipse.swt.widgets.Label; 28 import org.eclipse.swt.widgets.Listener; 29 import org.eclipse.swt.widgets.ProgressBar; 30 import org.eclipse.swt.widgets.Shell; 31 32 import com.sslexplorer.agent.client.TaskProgress; 33 34 39 public class SWTProgressDialog implements TaskProgress { 40 41 43 private Shell shell; 44 private SWTSystemTrayGUI gui; 45 private ProgressBar progressBar; 46 private Label label; 47 48 55 public SWTProgressDialog(SWTSystemTrayGUI gui, final int maxValue, final boolean allowCancel, final String message, final String note) { 56 this.gui = gui; 57 58 gui.getDisplay().asyncExec(new Runnable () { 60 public void run() { 61 doInit(maxValue, allowCancel, message, note); 62 } 63 }); 64 } 65 66 void doInit(int maxValue, boolean allowCancel, String message, String note) { 67 shell = new Shell(gui.getDisplay(), SWT.TITLE | SWT.CLOSE | SWT.BORDER); 68 GridLayout gridLayout = new GridLayout (); 69 gridLayout.marginHeight = 10; 70 gridLayout.verticalSpacing = 10; 71 shell.setLayout (gridLayout); 72 shell.setText(note); shell.setImage(gui.loadImage(SWTSystemTrayGUI.class, "/images/frame-agent.png")); 75 label = new Label(shell, SWT.CENTER); 77 label.setText(message); 78 GridData data = new GridData (); 79 data.horizontalAlignment = GridData.CENTER; 80 label.setLayoutData (data); 81 82 progressBar = new ProgressBar(shell, SWT.CENTER); 84 progressBar.setMinimum(0); 85 progressBar.setMaximum(maxValue); 86 progressBar.setSelection(0); 87 progressBar.setToolTipText(message); 88 data = new GridData (); 89 data.widthHint = 200; 90 data.horizontalAlignment = GridData.CENTER; 91 progressBar.setLayoutData (data); 92 93 95 if(allowCancel) { 97 final Button cancel = new Button(shell, SWT.PUSH); 98 cancel.setText(Messages.getString("TaskProgress.cancel")); cancel.addListener(SWT.Selection, new Listener() { 100 public void handleEvent(Event event) { 101 } 102 }); 103 data = new GridData (); 104 data.horizontalAlignment = GridData.CENTER; 105 cancel.setLayoutData (data); 106 } 107 108 shell.pack(); 109 SWTUtil.center(shell); 110 shell.open(); 111 } 112 113 public void dispose() { 114 gui.getDisplay().syncExec(new Runnable () { 115 public void run() { 116 shell.setVisible(false); 117 } 118 }); 119 } 120 121 public void setMessage(final String text) { 122 gui.getDisplay().syncExec(new Runnable () { 123 public void run() { 124 label.setText(text); 125 } 126 }); 127 } 128 129 public void updateValue(final long value) { 130 gui.getDisplay().syncExec(new Runnable () { 131 public void run() { 132 progressBar.setSelection((int)value); 133 } 134 }); 135 } 136 } | Popular Tags |