use of com.biglybt.ui.swt.utils.SWTRunnable in project BiglyBT by BiglySoftware.
the class SideBarEntrySWT method widgetDisposed.
@Override
public void widgetDisposed(DisposeEvent e) {
ImageLoader imageLoader = ImageLoader.getInstance();
if (imageLoader != null) {
imageLoader.releaseImage("image.sidebar.closeitem");
imageLoader.releaseImage("image.sidebar.closeitem-selected");
}
setDisposed(true);
final TreeItem treeItem = (TreeItem) e.widget;
if (treeItem != swtItem) {
Debug.out("Warning: TreeItem changed for sidebar " + id);
return;
}
if (swtItem == null) {
return;
}
if (swtItem != null && !Constants.isOSX) {
// In theory, the disposal of swtItem will trigger the disposal of the
// children. Let's force it just in case
// On OSX this will cause disposal confusion in SWT, and possibly result
// in a SIGSEGV crash.
TreeItem[] children = swtItem.getItems();
for (TreeItem child : children) {
if (child.isDisposed()) {
continue;
}
MdiEntry entry = (MdiEntry) child.getData("MdiEntry");
if (entry != null) {
entry.close(true);
}
}
}
final Tree tree = sidebar.getTree();
if (tree.isDisposed() || (swtItem != null && swtItem.isDisposed()) || tree.getShell().isDisposed()) {
return;
}
setTreeItem(null);
mdi.removeItem(SideBarEntrySWT.this);
SWTThread instance = SWTThread.getInstance();
boolean user = instance != null && !instance.isTerminated();
if (user) {
// It's not a user close if the parent is making the children (this entry)
// close. parent will be marked disposed, so use that as a check.
String parentID = getParentID();
if (parentID != null) {
MdiEntry entry = mdi.getEntry(parentID);
if (entry != null && entry.isDisposed()) {
user = false;
}
}
}
triggerCloseListeners(user);
SWTSkinObject so = getSkinObject();
if (so != null) {
setSkinObjectMaster(null);
so.getSkin().removeSkinObject(so);
}
for (SideBarVitalityImageSWT vitalityImage : listVitalityImages) {
vitalityImage.dispose();
}
listVitalityImages.clear();
// delay saving of removing of auto-open flag. If after the delay, we are
// still alive, it's assumed the user invoked the close, and we should
// remove the auto-open flag
Utils.execSWTThreadLater(0, new SWTRunnable() {
@Override
public void runWithDisplay(Display display) {
// opposed to closing the sidebar)
if (tree.isDisposed()) {
return;
}
try {
COConfigurationManager.removeParameter("SideBar.AutoOpen." + id);
// Force selection
if (Constants.isOSX && !tree.isDisposed() && tree.getSelectionCount() == 0) {
String parentid = getParentID();
if (parentid != null && mdi.getEntry(parentid) != null) {
mdi.showEntryByID(parentid);
} else {
mdi.showEntryByID(SideBar.SIDEBAR_SECTION_LIBRARY);
}
}
} catch (Exception e2) {
Debug.out(e2);
}
// See if this entry has been replaced by another in the meantime. This happens when we are
// moving an entry in the sidebar by removing it and then re-adding it. We assume that the
// auto-open properties of the replacement are the same as those of the initial entry
boolean replaced = false;
String my_id = SideBarEntrySWT.this.getId();
if (my_id != null) {
MdiEntry entry = mdi.getEntry(my_id);
if (entry != null && entry != SideBarEntrySWT.this) {
replaced = true;
}
}
if (!replaced) {
mdi.removeEntryAutoOpen(id);
}
}
});
}
use of com.biglybt.ui.swt.utils.SWTRunnable in project BiglyBT by BiglySoftware.
the class TableViewPainted method __refreshTable.
private void __refreshTable(boolean bForceSort) {
long lStart = SystemTime.getCurrentTime();
super.refreshTable(bForceSort);
Utils.execSWTThread(new SWTRunnable() {
@Override
public void runWithDisplay(Display display) {
// call to trigger invalidation if visibility changes
isVisible();
}
});
final boolean bDoGraphics = (loopFactor % graphicsUpdate) == 0;
final boolean bWillSort = bForceSort || (reOrderDelay != 0) && ((loopFactor % reOrderDelay) == 0);
if (bWillSort) {
TableColumnCore sortColumn = getSortColumn();
if (bForceSort && sortColumn != null) {
resetLastSortedOn();
sortColumn.setLastSortValueChange(SystemTime.getCurrentTime());
}
_sortColumn(true, false, false);
}
runForAllRows(new TableGroupRowVisibilityRunner() {
@Override
public void run(TableRowCore row, boolean bVisible) {
row.refresh(bDoGraphics, bVisible);
}
});
loopFactor++;
long diff = SystemTime.getCurrentTime() - lStart;
if (diff > 0) {
// debug("refreshTable took " + diff);
}
if (tvTabsCommon != null) {
Utils.execSWTThread(new SWTRunnable() {
@Override
public void runWithDisplay(Display display) {
if (tvTabsCommon != null) {
tvTabsCommon.swt_refresh();
}
}
});
}
}
use of com.biglybt.ui.swt.utils.SWTRunnable in project BiglyBT by BiglySoftware.
the class TableViewPainted method rowHeightChanged.
public void rowHeightChanged(final TableRowCore row, int oldHeight, int newHeight) {
synchronized (heightChangeSync) {
totalHeight += (newHeight - oldHeight);
if (qdRowHeightChanged) {
return;
}
qdRowHeightChanged = true;
}
Utils.execSWTThreadLater(0, new SWTRunnable() {
@Override
public void runWithDisplay(Display display) {
synchronized (heightChangeSync) {
qdRowHeightChanged = false;
}
// if moving visibleRowsChanged(), make sure subrows being resized on
// add trigger work properly
visibleRowsChanged();
swt_fixupSize();
}
@Override
public void runNoDisplay() {
synchronized (heightChangeSync) {
qdRowHeightChanged = false;
}
}
});
}
use of com.biglybt.ui.swt.utils.SWTRunnable in project BiglyBT by BiglySoftware.
the class TableViewPainted method swt_updateCanvasImage.
protected void swt_updateCanvasImage(final Rectangle bounds, final boolean immediateRedraw) {
// be on SWT thread and in_swt_updateCanvasImage is only used here
if (in_swt_updateCanvasImage) {
Utils.execSWTThreadLater(0, new SWTRunnable() {
@Override
public void runWithDisplay(Display display) {
in_swt_updateCanvasImage = false;
swt_updateCanvasImage(bounds, immediateRedraw);
}
});
return;
}
in_swt_updateCanvasImage = true;
try {
int x;
if (!DIRECT_DRAW) {
if (canvasImage == null || canvasImage.isDisposed() || bounds == null) {
return;
}
// System.out.println("UpdateCanvasImage " + bounds + "; via " + Debug.getCompressedStackTrace());
GC gc = new GC(canvasImage);
swt_paintCanvasImage(gc, bounds);
gc.dispose();
if (DEBUG_WITH_SHELL) {
if (sCanvasImage != null) {
Point size = sCanvasImage.getShell().computeSize(canvasImage.getBounds().width, canvasImage.getBounds().height);
sCanvasImage.getShell().setSize(size);
sCanvasImage.redraw(bounds.x, bounds.y, bounds.width, bounds.height, true);
sCanvasImage.update();
}
}
x = bounds.x - clientArea.x;
} else {
x = bounds.x;
}
if (cTable != null && !cTable.isDisposed()) {
if (DEBUG_REDRAW_CLIP) {
GC gc = new GC(cTable);
gc.setBackground(ColorCache.getRandomColor());
gc.fillRectangle(x, bounds.y, bounds.width, bounds.height);
gc.dispose();
}
cTable.redraw(x, bounds.y, bounds.width, bounds.height, false);
if (immediateRedraw) {
cTable.update();
}
}
} finally {
in_swt_updateCanvasImage = false;
}
}
use of com.biglybt.ui.swt.utils.SWTRunnable in project BiglyBT by BiglySoftware.
the class SWTSkinObjectText2 method setText.
/**
* @param searchText
*/
@Override
public void setText(String text) {
if (text == null) {
text = "";
}
if (text.equals(sText)) {
return;
}
this.sText = text;
this.sDisplayText = isAllcaps && sText != null ? sText.toUpperCase() : sText;
this.sKey = null;
bIsTextDefault = false;
// Doing execSWTThreadLater delays the relayout for too long at skin startup
// Since there are a lot of async execs at skin startup, we generally
// see the window a second or two before this async call would get called
// (if it were async)
Utils.execSWTThread(new SWTRunnable() {
@Override
public void runWithDisplay(Display display) {
// lastStringPrinter must be set while in SWT Thread otherwise
// sync issues happen
lastStringPrinter = null;
if (canvas != null && !canvas.isDisposed()) {
canvas.setCursor(null);
canvas.redraw();
if (relayoutOnTextChange) {
Utils.relayout(canvas);
}
}
}
});
}
Aggregations