FileDocCategorySizeDatePackage
StartStopRulesDefaultPluginSWTUI.javaAPI DocAzureus 3.0.3.44964Mon Feb 19 16:07:28 GMT 2007com.aelitis.azureus.plugins.startstoprules.defaultplugin.ui.swt

StartStopRulesDefaultPluginSWTUI

public class StartStopRulesDefaultPluginSWTUI extends Object

Fields Summary
Constructors Summary
public StartStopRulesDefaultPluginSWTUI(org.gudy.azureus2.plugins.PluginInterface plugin_interface)

		plugin_interface.addConfigSection(new ConfigSectionQueue());
		plugin_interface.addConfigSection(new ConfigSectionSeeding());
		plugin_interface.addConfigSection(new ConfigSectionSeedingAutoStarting());
		plugin_interface.addConfigSection(new ConfigSectionSeedingFirstPriority());
		plugin_interface.addConfigSection(new ConfigSectionSeedingIgnore());
	
Methods Summary
public static voidopenDebugWindow(com.aelitis.azureus.plugins.startstoprules.defaultplugin.DefaultRankCalculator dlData)

		final Shell shell = new Shell(Display.getCurrent(), SWT.ON_TOP
				| SWT.SHELL_TRIM | SWT.TOOL | SWT.CLOSE);

		GridLayout layout = new GridLayout();
		layout.numColumns = 4;
		GridData gd;
		shell.setLayout(layout);

		shell.setText("Debug for " + dlData.getDownloadObject().getName());

		final Text txtFP = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL);
		gd = new GridData(GridData.FILL_BOTH);
		gd.horizontalSpan = 4;
		txtFP.setLayoutData(gd);

		final Button btnAutoRefresh = new Button(shell, SWT.CHECK);
		btnAutoRefresh.setText("Auto-Refresh");
		btnAutoRefresh.setLayoutData(new GridData());

		final Button btnRefresh = new Button(shell, SWT.NONE);
		btnRefresh.setLayoutData(new GridData());
		btnRefresh.setText("Refresh");

		final Button btnToClip = new Button(shell, SWT.NONE);
		btnToClip.setLayoutData(new GridData());
		btnToClip.setText("To Clipboard");
		btnToClip.addListener(SWT.MouseUp, new Listener() {
			public void handleEvent(Event event) {
        new Clipboard(Display.getCurrent()).setContents(
						new Object[] { txtFP.getText() },
						new Transfer[] { TextTransfer.getInstance() });
			}
		});

		final Label lbl = new Label(shell, SWT.NONE);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		lbl.setLayoutData(gd);

		final TimerTask task = new TimerTask() {
			String lastText = "";

			public String formatString() {
				return "FP:\n" + dlData.sExplainFP + "\n" + "SR:" + dlData.sExplainSR
						+ "\n" + "TRACE:\n" + dlData.sTrace;
			}

			public void setText(final String s) {
				lastText = s;

				txtFP.setText(s);
			}

			public void run() {
				if (shell.isDisposed())
					return;

				shell.getDisplay().syncExec(new Runnable() {
					public void run() {
						if (shell.isDisposed()) {
							return;
						}
						String s = formatString();
						if (s.compareTo(lastText) != 0) {
							if (lastText.length() == 0 || btnAutoRefresh.getSelection()
									|| btnRefresh.getData("Pressing") != null)
								setText(s);
							else
								lbl.setText("Information is outdated.  Press refresh.");
						} else {
							lbl.setText("");
						}
					}
				});
			}
		};
		btnAutoRefresh.addListener(SWT.MouseUp, new Listener() {
			public void handleEvent(Event event) {
				if (btnAutoRefresh.getSelection())
					lbl.setText("");
				task.run();
			}
		});

		btnRefresh.addListener(SWT.MouseUp, new Listener() {
			public void handleEvent(Event event) {
				btnRefresh.setData("Pressing", "1");
				task.run();
				btnRefresh.setData("Pressing", null);
			}
		});
		
		shell.addTraverseListener(new TraverseListener() {
			public void keyTraversed(TraverseEvent e) {
				if (e.detail == SWT.TRAVERSE_ESCAPE) {
					shell.dispose();
				}
			}
		});

		shell.setSize(550, 350);
		shell.open();

		Timer timer = new Timer(true);
		timer.schedule(task, 0, 2000);