use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.
the class ShellSlider method run.
public void run() {
while (canContinue()) {
long lStartedAt = System.currentTimeMillis();
shell.getDisplay().syncExec(new AERunnable() {
@Override
public void runSupport() {
if (shell == null || shell.isDisposed()) {
return;
}
if (shellBounds == null) {
shellBounds = shell.getBounds();
}
int delta;
if (slideIn) {
switch(direction) {
case SWT.UP:
delta = Math.min(endBounds.height - shellBounds.height, STEP);
shellBounds.height += delta;
delta = Math.min(shellBounds.y - endBounds.y, STEP);
shellBounds.y -= delta;
break;
default:
break;
}
} else {
switch(direction) {
case SWT.RIGHT:
delta = Math.min(shellBounds.width, STEP);
shellBounds.width -= delta;
shellBounds.x += delta;
if (shellBounds.width == 0) {
shell.dispose();
return;
}
break;
default:
break;
}
}
shell.setBounds(shellBounds);
shell.update();
}
});
try {
long lDrawTime = System.currentTimeMillis() - lStartedAt;
long lSleepTime = PAUSE - lDrawTime;
if (lSleepTime < 15) {
double d = (lDrawTime + 15.0) / PAUSE;
PAUSE *= d;
STEP *= d;
lSleepTime = 15;
}
Thread.sleep(lSleepTime);
} catch (Exception e) {
}
}
}
use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.
the class SearchUtils method importFromClipboard.
private static void importFromClipboard() {
final Shell shell = Utils.findAnyShell();
shell.getDisplay().asyncExec(new AERunnable() {
@Override
public void runSupport() {
try {
Clipboard clipboard = new Clipboard(Display.getDefault());
String text = (String) clipboard.getContents(TextTransfer.getInstance());
clipboard.dispose();
if (text != null) {
InputStream is = new ByteArrayInputStream(text.getBytes("UTF-8"));
try {
VuzeFileHandler vfh = VuzeFileHandler.getSingleton();
VuzeFile vf = vfh.loadVuzeFile(is);
if (vf != null) {
vfh.handleFiles(new VuzeFile[] { vf }, VuzeFileComponent.COMP_TYPE_NONE);
}
} finally {
is.close();
}
}
} catch (Throwable e) {
Debug.out(e);
}
}
});
}
use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.
the class GenericMessageConnectionDirect method startProcessing.
protected void startProcessing() {
connection.getIncomingMessageQueue().registerQueueListener(new IncomingMessageQueue.MessageQueueListener() {
@Override
public boolean messageReceived(Message _message) {
GenericMessage message = (GenericMessage) _message;
dispatcher.dispatch(new AERunnable() {
@Override
public void runSupport() {
if (dispatcher.getQueueSize() > 10) {
try {
close();
} catch (Throwable e) {
}
} else {
owner.receive(message);
}
}
});
return (true);
}
@Override
public void protocolBytesReceived(int byte_count) {
}
@Override
public void dataBytesReceived(int byte_count) {
}
@Override
public boolean isPriority() {
return false;
}
});
connection.getOutgoingMessageQueue().registerQueueListener(new OutgoingMessageQueue.MessageQueueListener() {
@Override
public boolean messageAdded(Message message) {
return (true);
}
@Override
public void messageQueued(Message message) {
// System.out.println( " queued: " + message );
}
@Override
public void messageRemoved(Message message) {
// System.out.println( " removed: " + message );
}
@Override
public void messageSent(Message message) {
// System.out.println( " sent: " + message );
}
@Override
public void protocolBytesSent(int byte_count) {
}
@Override
public void dataBytesSent(int byte_count) {
}
@Override
public void flush() {
}
});
connection.startMessageProcessing();
connection.enableEnhancedMessageProcessing(true, -1);
synchronized (this) {
if (inbound_rls != null) {
for (int i = 0; i < inbound_rls.size(); i++) {
connection.addRateLimiter((LimitedRateGroup) inbound_rls.get(i), false);
}
inbound_rls = null;
}
if (outbound_rls != null) {
for (int i = 0; i < outbound_rls.size(); i++) {
connection.addRateLimiter((LimitedRateGroup) outbound_rls.get(i), true);
}
outbound_rls = null;
}
processing = true;
}
}
use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.
the class SubscriptionWizard method createAvailableSubscriptionComposite.
private Composite createAvailableSubscriptionComposite(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
Label hsep1 = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
Label hsep2 = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
Label vsep = new Label(composite, SWT.SEPARATOR | SWT.VERTICAL);
Label subtitle1 = new Label(composite, SWT.NONE);
Label subtitle2 = new Label(composite, SWT.NONE);
subtitle1.setFont(subTitleFont);
subtitle2.setFont(subTitleFont);
subtitle1.setText(MessageText.getString("Wizard.Subscription.subscribe.library"));
subtitle2.setText(MessageText.getString("Wizard.Subscription.subscribe.subscriptions"));
libraryTable = new Table(composite, SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.V_SCROLL | SWT.SINGLE);
final TableColumn torrentColumn = new TableColumn(libraryTable, SWT.NONE);
torrentColumn.setWidth(50);
final Composite compEmpty = new Composite(composite, SWT.NONE);
if (!Utils.isDarkAppearanceNative()) {
compEmpty.setBackground(Colors.getSystemColor(display, SWT.COLOR_WHITE));
}
FillLayout fl = new FillLayout();
fl.marginHeight = 15;
fl.marginWidth = 15;
compEmpty.setLayout(fl);
compEmpty.setVisible(false);
final Link labelEmpty = new Link(compEmpty, SWT.WRAP);
labelEmpty.setText(MessageText.getString("Wizard.Subscription.subscribe.library.empty"));
labelEmpty.setFont(subTitleFont);
labelEmpty.setForeground(ColorCache.getColor(composite.getDisplay(), "#6D6F6E"));
labelEmpty.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (event.text != null && (event.text.startsWith("http://") || event.text.startsWith("https://"))) {
Utils.launch(event.text);
}
}
});
initColumns();
final Composite cTV = new Composite(composite, SWT.NONE);
cTV.setLayoutData(Utils.getFilledFormData());
GridLayout layout = new GridLayout();
layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
cTV.setLayout(layout);
tvSubscriptions = TableViewFactory.createTableViewSWT(Subscription.class, TABLE_SUB_WIZ, TABLE_SUB_WIZ, new TableColumnCore[0], "SubWizRank", SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.V_SCROLL | SWT.SINGLE);
tvSubscriptions.setMenuEnabled(false);
tvSubscriptions.setHeaderVisible(false);
tvSubscriptions.setRowDefaultHeightEM(1.4f);
tvSubscriptions.initialize(cTV);
tvSubscriptions.getComposite().addListener(SWT.Resize, new Listener() {
@Override
public void handleEvent(Event event) {
com.biglybt.pif.ui.tables.TableColumn tcName = tvSubscriptions.getTableColumn("SubWizName");
com.biglybt.pif.ui.tables.TableColumn tcRank = tvSubscriptions.getTableColumn("SubWizRank");
Rectangle clientArea = ((Composite) event.widget).getClientArea();
tcName.setWidthPX(clientArea.width - tcRank.getWidth() - 1);
}
});
tvSubscriptions.addSelectionListener(new TableSelectionListener() {
@Override
public void selected(TableRowCore[] row) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (tvSubscriptions.getSelectedRowsSize() == 0) {
addButton.setEnabled(false);
} else {
addButton.setEnabled(true);
TableRowCore[] rows = tvSubscriptions.getSelectedRows();
Subscription subscription = (Subscription) rows[0].getDataSource();
if (subscription.isSubscribed()) {
addButton.setEnabled(false);
} else {
addButton.setEnabled(true);
}
addButton.setData("subscription", subscription);
}
}
});
}
@Override
public void mouseExit(TableRowCore row) {
}
@Override
public void mouseEnter(TableRowCore row) {
}
@Override
public void focusChanged(TableRowCore focus) {
}
@Override
public void deselected(TableRowCore[] rows) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (tvSubscriptions.getSelectedRowsSize() == 0) {
addButton.setEnabled(false);
}
}
});
}
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask) {
}
}, false);
UIUpdaterSWT.getInstance().addUpdater(new UIUpdatable() {
@Override
public void updateUI() {
if (tvSubscriptions != null) {
tvSubscriptions.refreshTable(false);
}
}
@Override
public String getUpdateUIName() {
return "SubWiz";
}
});
Listener resizeListener = new Listener() {
int last_width;
@Override
public void handleEvent(Event event) {
Table table = (Table) event.widget;
Rectangle rect = table.getClientArea();
int width = rect.width - 3;
if (width == last_width) {
return;
}
last_width = width;
int nbColumns = table.getColumnCount();
if (nbColumns == 1) {
table.getColumns()[0].setWidth(width);
}
((Table) event.widget).update();
}
};
// subscriptionTable.addListener(SWT.Resize , resizeListener);
libraryTable.addListener(SWT.Resize, resizeListener);
final Listener selectionListener = new Listener() {
@Override
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
subscriptions = (Subscription[]) item.getData("subscriptions");
tvSubscriptions.removeDataSources(tvSubscriptions.getDataSources().toArray(new Subscription[0]));
if (subscriptions != null) {
tvSubscriptions.addDataSources(subscriptions);
}
tvSubscriptions.processDataSourceQueueSync();
addButton.setEnabled(false);
addButton.setData("subscription", null);
tvSubscriptions.setSelectedRows(new TableRowCore[0]);
if (subscriptions != null && subscriptions.length > 0) {
TableRowCore row = tvSubscriptions.getRow(subscriptions[0]);
if (row != null) {
row.setSelected(true);
}
}
}
};
libraryTable.addListener(SWT.Selection, selectionListener);
if (availableSubscriptions != null) {
libraryTable.addListener(SWT.SetData, new Listener() {
@Override
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
int index = libraryTable.indexOf(item);
SubscriptionDownloadDetails subInfo = availableSubscriptions[index];
item.setText(subInfo.getDownload().getDisplayName());
item.setData("subscriptions", subInfo.getSubscriptions());
boolean isSubscribed = false;
Subscription[] subs = subInfo.getSubscriptions();
for (int i = 0; i < subs.length; i++) {
if (subs[i].isSubscribed())
isSubscribed = true;
}
if (isSubscribed) {
item.setForeground(Colors.getSystemColor(display, SWT.COLOR_GRAY));
}
if (subInfo.getDownload() == download) {
libraryTable.setSelection(item);
selectionListener.handleEvent(event);
}
if (index == 0 && download == null) {
libraryTable.setSelection(item);
selectionListener.handleEvent(event);
}
if (libraryTable.getSelectionIndex() == index) {
// If the item was already selected and we got the SetData afterwards, then let's populate the
// subscriptionsTable
selectionListener.handleEvent(event);
}
}
});
libraryTable.setItemCount(availableSubscriptions.length);
if (availableSubscriptions.length == 0) {
libraryTable.setVisible(false);
compEmpty.setVisible(true);
}
} else {
// Test code
libraryTable.addListener(SWT.SetData, new Listener() {
@Override
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
int index = libraryTable.indexOf(item);
item.setText("test " + index);
}
});
libraryTable.setItemCount(20);
}
addButton.setEnabled(false);
addButton.setData("subscription", null);
// final Image rssIcon = imageLoader.getImage("icon_rss");
libraryTable.addListener(SWT.MeasureItem, new Listener() {
@Override
public void handleEvent(Event event) {
event.height = 20;
}
});
FormLayout formLayout = new FormLayout();
composite.setLayout(formLayout);
FormData data;
data = new FormData();
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(40, 0);
data.bottom = new FormAttachment(100, 0);
vsep.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(0, 5);
data.right = new FormAttachment(vsep, 0);
data.left = new FormAttachment(0, 5);
subtitle1.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(0, 5);
data.left = new FormAttachment(vsep, 5);
data.right = new FormAttachment(100, 0);
subtitle2.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(subtitle1, 5);
data.right = new FormAttachment(vsep, 0);
data.left = new FormAttachment(0, 0);
hsep1.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(subtitle2, 5);
data.left = new FormAttachment(vsep, -1);
data.right = new FormAttachment(100, 0);
hsep2.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(hsep1, 0);
data.right = new FormAttachment(vsep, 0);
data.left = new FormAttachment(0, 0);
data.bottom = new FormAttachment(100, 0);
if (availableSubscriptions != null && availableSubscriptions.length > 0) {
libraryTable.setLayoutData(data);
} else {
// hack: dispose libraryTable as it's not needed and draws over controls
// (makes a white box covering text). Would be smarter to not
// create the libraryTable at all..
libraryTable.dispose();
cancelButton.setFocus();
shell.setDefaultButton(cancelButton);
compEmpty.setLayoutData(data);
}
data = new FormData();
data.top = new FormAttachment(hsep2, 0);
data.left = new FormAttachment(vsep, 0);
data.right = new FormAttachment(100, 0);
data.bottom = new FormAttachment(100, 0);
cTV.setLayoutData(data);
return composite;
}
use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.
the class SWTSkinObjectCheckbox method setChecked.
public void setChecked(boolean b) {
checked = b;
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (button != null && !button.isDisposed()) {
button.setSelection(checked);
}
}
});
}
Aggregations