use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.
the class IntListParameter method setIndex.
/**
* @param index
*/
protected void setIndex(final int index) {
int selected_value = values[index];
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (list == null || list.isDisposed()) {
return;
}
if (list.getSelectionIndex() != index) {
list.select(index);
}
}
});
if (COConfigurationManager.getIntParameter(name) != selected_value) {
COConfigurationManager.setParameter(name, selected_value);
}
}
use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.
the class GenericStringListParameter method setIndex.
protected void setIndex(final int index) {
if (index < 0) {
adapter.setStringListValue(name, null);
String defValue = adapter.getStringListValue(name);
int i = findIndex(defValue, values);
if (i >= 0) {
// no recursion, because this area only gets called again if i was < 0
setIndex(i);
} else {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (list == null || list.isDisposed()) {
return;
}
if (useCombo) {
((Combo) list).deselectAll();
} else {
((List) list).deselectAll();
}
}
});
}
return;
}
String selected_value = values[index];
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (list == null || list.isDisposed()) {
return;
}
if (useCombo) {
if (((Combo) list).getSelectionIndex() != index) {
((Combo) list).select(index);
}
} else {
if (((List) list).getSelectionIndex() != index) {
((List) list).select(index);
}
}
}
});
if (!adapter.getStringListValue(name).equals(selected_value)) {
adapter.setStringListValue(name, selected_value);
}
}
use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.
the class UISWTInstanceImpl method addView.
public void addView(String sParentID, final String sViewID, final UISWTViewEventListenerHolder holder) {
if (sParentID == null) {
sParentID = UISWTInstance.VIEW_MAIN;
}
Map<String, UISWTViewEventListenerHolder> subViews = views.get(sParentID);
if (subViews == null) {
subViews = new LinkedHashMap<>();
views.put(sParentID, subViews);
}
subViews.put(sViewID, holder);
if (sParentID.equals(UISWTInstance.VIEW_MAIN)) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
try {
uiFunctions.addPluginView(sViewID, holder);
} catch (Throwable e) {
// SWT not available prolly
}
}
});
}
SWTViewListener[] viewListeners = listSWTViewListeners.toArray(new SWTViewListener[0]);
for (SWTViewListener l : viewListeners) {
l.setViewAdded(sParentID, sViewID, holder);
}
}
use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.
the class ConfigSectionStats method configSectionCreate.
@Override
public Composite configSectionCreate(final Composite parent) {
ImageLoader imageLoader = ImageLoader.getInstance();
Image imgOpenFolder = imageLoader.getImage("openFolderButton");
GridData gridData;
GridLayout layout;
Composite gOutter = new Composite(parent, SWT.NULL);
gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
gOutter.setLayoutData(gridData);
layout = new GridLayout();
layout.numColumns = 1;
gOutter.setLayout(layout);
// general
Group gGeneral = new Group(gOutter, SWT.NULL);
Messages.setLanguageText(gGeneral, "ConfigView.section.general");
layout = new GridLayout(2, false);
gGeneral.setLayout(layout);
gGeneral.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label lSmooth = new Label(gGeneral, SWT.NULL);
Messages.setLanguageText(lSmooth, "stats.general.smooth_secs");
IntParameter smooth_secs = new IntParameter(gGeneral, "Stats Smoothing Secs", 30, 30 * 60);
// display
Group gDisplay = new Group(gOutter, SWT.NULL);
Messages.setLanguageText(gDisplay, "stats.display.group");
layout = new GridLayout(1, false);
gDisplay.setLayout(layout);
gDisplay.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
gridData = new GridData();
BooleanParameter graph_dividers = new BooleanParameter(gDisplay, "Stats Graph Dividers", "ConfigView.section.stats.graph_update_dividers");
graph_dividers.setLayoutData(gridData);
// snapshots
Group gSnap = new Group(gOutter, SWT.NULL);
Messages.setLanguageText(gSnap, "stats.snapshot.group");
layout = new GridLayout(3, false);
gSnap.setLayout(layout);
gSnap.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// row
gridData = new GridData();
gridData.horizontalSpan = 3;
BooleanParameter enableStats = new BooleanParameter(gSnap, "Stats Enable", "ConfigView.section.stats.enable");
enableStats.setLayoutData(gridData);
Control[] controls = new Control[13];
// row
Label lStatsPath = new Label(gSnap, SWT.NULL);
// $NON-NLS-1$
Messages.setLanguageText(lStatsPath, "ConfigView.section.stats.defaultsavepath");
gridData = new GridData();
gridData.widthHint = 150;
// $NON-NLS-1$ //$NON-NLS-2$
final StringParameter pathParameter = new StringParameter(gSnap, "Stats Dir", "");
pathParameter.setLayoutData(gridData);
controls[0] = lStatsPath;
controls[1] = pathParameter.getControl();
Button browse = new Button(gSnap, SWT.PUSH);
browse.setImage(imgOpenFolder);
imgOpenFolder.setBackground(browse.getBackground());
browse.setToolTipText(MessageText.getString("ConfigView.button.browse"));
controls[2] = browse;
browse.addListener(SWT.Selection, new Listener() {
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
*/
@Override
public void handleEvent(Event event) {
DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
dialog.setFilterPath(pathParameter.getValue());
// $NON-NLS-1$
dialog.setText(MessageText.getString("ConfigView.section.stats.choosedefaultsavepath"));
String path = dialog.open();
if (path != null) {
pathParameter.setValue(path);
}
}
});
// row
Label lSaveFile = new Label(gSnap, SWT.NULL);
// $NON-NLS-1$
Messages.setLanguageText(lSaveFile, "ConfigView.section.stats.savefile");
controls[3] = lSaveFile;
gridData = new GridData();
gridData.widthHint = 150;
final StringParameter fileParameter = new StringParameter(gSnap, "Stats File", StatsWriterPeriodic.DEFAULT_STATS_FILE_NAME);
fileParameter.setLayoutData(gridData);
controls[4] = fileParameter.getControl();
new Label(gSnap, SWT.NULL);
// row
Label lxslFile = new Label(gSnap, SWT.NULL);
// $NON-NLS-1$
Messages.setLanguageText(lxslFile, "ConfigView.section.stats.xslfile");
controls[5] = lxslFile;
gridData = new GridData();
gridData.widthHint = 150;
final StringParameter xslParameter = new StringParameter(gSnap, "Stats XSL File", "");
xslParameter.setLayoutData(gridData);
controls[6] = xslParameter.getControl();
Label lxslDetails = new Label(gSnap, SWT.NULL);
// $NON-NLS-1$
Messages.setLanguageText(lxslDetails, "ConfigView.section.stats.xslfiledetails");
final String linkFAQ = Constants.PLUGINS_WEB_SITE + "faq.php#20";
lxslDetails.setCursor(lxslDetails.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
lxslDetails.setForeground(Colors.blue);
lxslDetails.setData(linkFAQ);
lxslDetails.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent arg0) {
Utils.launch(linkFAQ);
}
@Override
public void mouseDown(MouseEvent arg0) {
Utils.launch(linkFAQ);
}
});
ClipboardCopy.addCopyToClipMenu(lxslDetails);
controls[7] = lxslDetails;
// row
Label lSaveFreq = new Label(gSnap, SWT.NULL);
Messages.setLanguageText(lSaveFreq, "ConfigView.section.stats.savefreq");
controls[8] = lSaveFreq;
final String[] spLabels = new String[statsPeriods.length];
final int[] spValues = new int[statsPeriods.length];
for (int i = 0; i < statsPeriods.length; i++) {
int num = statsPeriods[i];
if (num % 3600 == 0)
spLabels[i] = " " + (statsPeriods[i] / 3600) + " " + MessageText.getString("ConfigView.section.stats.hours");
else if (num % 60 == 0)
spLabels[i] = " " + (statsPeriods[i] / 60) + " " + MessageText.getString("ConfigView.section.stats.minutes");
else
spLabels[i] = " " + statsPeriods[i] + " " + MessageText.getString("ConfigView.section.stats.seconds");
spValues[i] = statsPeriods[i];
}
controls[9] = lSaveFreq;
controls[10] = new IntListParameter(gSnap, "Stats Period", defaultStatsPeriod, spLabels, spValues).getControl();
new Label(gSnap, SWT.NULL);
// ROW
gridData = new GridData();
gridData.horizontalSpan = 3;
BooleanParameter exportPeers = new BooleanParameter(gSnap, "Stats Export Peer Details", "ConfigView.section.stats.exportpeers");
exportPeers.setLayoutData(gridData);
controls[11] = exportPeers.getControl();
// ROW
gridData = new GridData();
gridData.horizontalSpan = 3;
BooleanParameter exportFiles = new BooleanParameter(gSnap, "Stats Export File Details", "ConfigView.section.stats.exportfiles");
exportFiles.setLayoutData(gridData);
controls[12] = exportFiles.getControl();
// control stuff
enableStats.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(controls));
// xfer
Group gXfer = new Group(gOutter, SWT.NULL);
Messages.setLanguageText(gXfer, "ConfigView.section.transfer");
layout = new GridLayout(3, false);
gXfer.setLayout(layout);
gXfer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
List<Button> buttons = new ArrayList<>();
// set mark
Label set_mark_label = new Label(gXfer, SWT.NULL);
Messages.setLanguageText(set_mark_label, "ConfigView.section.transfer.setmark");
Button set_mark_button = new Button(gXfer, SWT.PUSH);
buttons.add(set_mark_button);
Messages.setLanguageText(set_mark_button, "Button.set");
set_mark_button.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
OverallStats stats = StatsFactory.getStats();
stats.setMark();
}
});
Button clear_mark_button = new Button(gXfer, SWT.PUSH);
buttons.add(clear_mark_button);
Messages.setLanguageText(clear_mark_button, "Button.clear");
clear_mark_button.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
OverallStats stats = StatsFactory.getStats();
stats.clearMark();
}
});
// long term
Group gLong = new Group(gOutter, SWT.NULL);
Messages.setLanguageText(gLong, "stats.longterm.group");
layout = new GridLayout(2, false);
gLong.setLayout(layout);
gLong.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// row
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter enableLongStats = new BooleanParameter(gLong, "long.term.stats.enable", "ConfigView.section.stats.enable");
enableLongStats.setLayoutData(gridData);
// week start
Label lWeekStart = new Label(gLong, SWT.NULL);
Messages.setLanguageText(lWeekStart, "stats.long.weekstart");
final String[] wsLabels = new String[7];
final int[] wsValues = new int[7];
Calendar cal = new GregorianCalendar();
SimpleDateFormat format = new SimpleDateFormat("E");
for (int i = 0; i < 7; i++) {
// sun = 1 etc
int dow = i + 1;
cal.set(Calendar.DAY_OF_WEEK, dow);
wsLabels[i] = format.format(cal.getTime());
wsValues[i] = i + 1;
}
IntListParameter week_start = new IntListParameter(gLong, "long.term.stats.weekstart", Calendar.SUNDAY, wsLabels, wsValues);
// month start
Label lMonthStart = new Label(gLong, SWT.NULL);
Messages.setLanguageText(lMonthStart, "stats.long.monthstart");
IntParameter month_start = new IntParameter(gLong, "long.term.stats.monthstart", 1, 28);
enableLongStats.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(new Control[] { lWeekStart, lMonthStart }));
enableLongStats.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(week_start, month_start));
// reset
Label lt_reset_label = new Label(gLong, SWT.NULL);
Messages.setLanguageText(lt_reset_label, "ConfigView.section.transfer.lts.reset");
Button lt_reset_button = new Button(gLong, SWT.PUSH);
buttons.add(lt_reset_button);
Messages.setLanguageText(lt_reset_button, "Button.clear");
lt_reset_button.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
MessageBoxShell mb = new MessageBoxShell(SWT.ICON_WARNING | SWT.OK | SWT.CANCEL, MessageText.getString("ConfigView.section.security.resetcerts.warning.title"), MessageText.getString("ConfigView.section.transfer.ltsreset.warning.msg"));
mb.setDefaultButtonUsingStyle(SWT.CANCEL);
mb.setParent(parent.getShell());
mb.open(new UserPrompterResultListener() {
@Override
public void prompterClosed(int returnVal) {
if (returnVal != SWT.OK) {
return;
}
Utils.getOffOfSWTThread(new AERunnable() {
@Override
public void runSupport() {
StatsFactory.clearLongTermStats();
}
});
}
});
}
});
Utils.makeButtonsEqualWidth(buttons);
return gOutter;
}
use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.
the class UISWTInstanceImpl method eventOccurred.
@Override
public boolean eventOccurred(final UIManagerEvent event) {
boolean done = true;
final Object data = event.getData();
switch(event.getType()) {
case UIManagerEvent.ET_SHOW_TEXT_MESSAGE:
{
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
String[] params = (String[]) data;
new TextViewerWindow(params[0], params[1], params[2]);
}
});
break;
}
case UIManagerEvent.ET_SHOW_MSG_BOX:
{
final int[] result = { UIManagerEvent.MT_NONE };
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
uiFunctions.bringToFront();
Object[] params = (Object[]) data;
long _styles = ((Long) (params[2])).longValue();
int styles = 0;
int def = 0;
if ((_styles & UIManagerEvent.MT_YES) != 0) {
styles |= SWT.YES;
}
if ((_styles & UIManagerEvent.MT_YES_DEFAULT) != 0) {
styles |= SWT.YES;
def = SWT.YES;
}
if ((_styles & UIManagerEvent.MT_NO) != 0) {
styles |= SWT.NO;
}
if ((_styles & UIManagerEvent.MT_NO_DEFAULT) != 0) {
styles |= SWT.NO;
def = SWT.NO;
}
if ((_styles & UIManagerEvent.MT_OK) != 0) {
styles |= SWT.OK;
}
if ((_styles & UIManagerEvent.MT_OK_DEFAULT) != 0) {
styles |= SWT.OK;
def = SWT.OK;
}
if ((_styles & UIManagerEvent.MT_CANCEL) != 0) {
styles |= SWT.CANCEL;
}
MessageBoxShell mb = new MessageBoxShell(styles, MessageText.getString((String) params[0]), MessageText.getString((String) params[1]));
if (def != 0) {
mb.setDefaultButtonUsingStyle(def);
}
if (params.length == 4 && params[3] instanceof Map) {
Map<String, Object> options = (Map<String, Object>) params[3];
String rememberID = (String) options.get(UIManager.MB_PARAM_REMEMBER_ID);
Boolean rememberByDefault = (Boolean) options.get(UIManager.MB_PARAM_REMEMBER_BY_DEF);
String rememberText = (String) options.get(UIManager.MB_PARAM_REMEMBER_RES);
if (rememberID != null && rememberByDefault != null && rememberText != null) {
mb.setRemember(rememberID, rememberByDefault, rememberText);
Number rememberIfOnlyButton = (Number) options.get(UIManager.MB_PARAM_REMEMBER_IF_ONLY_BUTTON);
if (rememberIfOnlyButton != null) {
mb.setRememberOnlyIfButton(rememberIfOnlyButton.intValue());
}
}
Number auto_close_ms = (Number) options.get(UIManager.MB_PARAM_AUTO_CLOSE_MS);
if (auto_close_ms != null) {
mb.setAutoCloseInMS(auto_close_ms.intValue());
}
} else if (params.length >= 6) {
String rememberID = (String) params[3];
Boolean rememberByDefault = (Boolean) params[4];
String rememberText = (String) params[5];
if (rememberID != null && rememberByDefault != null && rememberText != null) {
mb.setRemember(rememberID, rememberByDefault, rememberText);
}
}
mb.open(null);
int _r = mb.waitUntilClosed();
int r = 0;
if ((_r & SWT.YES) != 0) {
r |= UIManagerEvent.MT_YES;
}
if ((_r & SWT.NO) != 0) {
r |= UIManagerEvent.MT_NO;
}
if ((_r & SWT.OK) != 0) {
r |= UIManagerEvent.MT_OK;
}
if ((_r & SWT.CANCEL) != 0) {
r |= UIManagerEvent.MT_CANCEL;
}
result[0] = r;
}
}, false);
event.setResult(new Long(result[0]));
break;
}
case UIManagerEvent.ET_OPEN_TORRENT_VIA_FILE:
{
TorrentOpener.openTorrent(((File) data).toString());
break;
}
case UIManagerEvent.ET_OPEN_TORRENT_VIA_TORRENT:
{
Torrent t = (Torrent) data;
try {
File f = AETemporaryFileHandler.createTempFile();
t.writeToFile(f);
TorrentOpener.openTorrent(f.toString());
} catch (Throwable e) {
Debug.printStackTrace(e);
}
break;
}
case UIManagerEvent.ET_OPEN_TORRENT_VIA_URL:
{
Display display = Utils.getDisplay();
display.syncExec(new AERunnable() {
@Override
public void runSupport() {
Object[] params = (Object[]) data;
URL target = (URL) params[0];
URL referrer = (URL) params[1];
boolean auto_download = ((Boolean) params[2]).booleanValue();
Map<?, ?> request_properties = (Map<?, ?>) params[3];
if (auto_download) {
final Shell shell = uiFunctions.getMainShell();
if (shell != null) {
final List<String> alt_uris = new ArrayList<>();
if (request_properties != null) {
request_properties = new HashMap(request_properties);
for (int i = 1; i < 16; i++) {
String key = "X-Alternative-URI-" + i;
String uri = (String) request_properties.remove(key);
if (uri != null) {
alt_uris.add(uri);
} else {
break;
}
}
}
final Map<?, ?> f_request_properties = request_properties;
new FileDownloadWindow(shell, target.toString(), referrer == null ? null : referrer.toString(), request_properties, new Runnable() {
int alt_index = 0;
@Override
public void run() {
if (alt_index < alt_uris.size()) {
String alt_target = alt_uris.get(alt_index++);
new FileDownloadWindow(shell, alt_target, null, f_request_properties, this);
}
}
});
}
} else {
// TODO: handle referrer?
TorrentOpener.openTorrent(target.toString());
}
}
});
break;
}
case UIManagerEvent.ET_PLUGIN_VIEW_MODEL_CREATED:
{
if (data instanceof BasicPluginViewModel) {
BasicPluginViewModel model = (BasicPluginViewModel) data;
// property bundles can't handle spaces in keys
//
// If this behaviour changes, change the openView(model)
// method lower down.
String sViewID = model.getName().replace(' ', '.');
UISWTInstance ui = getInstance(model.getPluginInterface());
ui.registerView(UISWTInstance.VIEW_MAIN, ui.createViewBuilder(sViewID, BasicPluginViewImpl.class).setInitialDatasource(data));
}
break;
}
case UIManagerEvent.ET_PLUGIN_VIEW_MODEL_DESTROYED:
{
if (data instanceof BasicPluginViewModel) {
BasicPluginViewModel model = (BasicPluginViewModel) data;
// property bundles can't handle spaces in keys
//
// If this behaviour changes, change the openView(model)
// method lower down.
String sViewID = model.getName().replace(' ', '.');
removeViews(UISWTInstance.VIEW_MAIN, sViewID);
}
break;
}
case UIManagerEvent.ET_COPY_TO_CLIPBOARD:
{
ClipboardCopy.copyToClipBoard((String) data, event.getPluginInterface());
break;
}
case UIManagerEvent.ET_OPEN_URL:
{
Utils.launch(((URL) data).toExternalForm());
break;
}
case UIManagerEvent.ET_SHOW_CONFIG_SECTION:
{
event.setResult(Boolean.FALSE);
if (!(data instanceof String)) {
break;
}
event.setResult(Boolean.TRUE);
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, data);
break;
}
case UIManagerEvent.ET_FILE_OPEN:
{
File file_to_use = (File) data;
Utils.launch(file_to_use.getAbsolutePath());
break;
}
case UIManagerEvent.ET_FILE_SHOW:
{
File file_to_use = (File) data;
final boolean use_open_containing_folder = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
ManagerUtils.open(file_to_use, use_open_containing_folder);
break;
}
case UIManagerEvent.ET_HIDE_ALL:
{
boolean hide = (Boolean) data;
uiFunctions.setHideAll(hide);
break;
}
case UIManagerEvent.ET_HIDE_ALL_TOGGLE:
{
uiFunctions.setHideAll(!uiFunctions.getHideAll());
break;
}
default:
{
done = false;
break;
}
}
return (done);
}
Aggregations