use of com.biglybt.ui.swt.views.table.TableCellSWT in project BiglyBT by BiglySoftware.
the class ColumnArchiveDLSize method refresh.
@Override
public void refresh(TableCell cell) {
DownloadStub dl = (DownloadStub) cell.getDataSource();
long size = 0;
if (dl != null) {
size = dl.getTorrentSize();
}
if (!cell.setSortValue(size) && cell.isValid()) {
// return;
}
if (!cell.isShown()) {
return;
}
cell.setText(DisplayFormatters.formatByteCountToKiBEtc(size));
if (Utils.getUserMode() > 0 && (cell instanceof TableCellSWT)) {
if (size >= 0x40000000l) {
((TableCellSWT) cell).setTextAlpha(200 | 0x100);
} else if (size < 0x100000) {
((TableCellSWT) cell).setTextAlpha(180);
} else {
((TableCellSWT) cell).setTextAlpha(255);
}
}
}
use of com.biglybt.ui.swt.views.table.TableCellSWT in project BiglyBT by BiglySoftware.
the class ColumnSearchSubResultActions method cellMouseTrigger.
@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
SearchSubsResultBase entry = (SearchSubsResultBase) event.cell.getDataSource();
String tooltip = null;
boolean invalidateAndRefresh = false;
Rectangle bounds = ((TableCellSWT) event.cell).getBounds();
String text = (String) event.cell.getTableRow().getData("text");
if (text == null) {
return;
}
GCStringPrinter sp = null;
GC gc = new GC(Display.getDefault());
try {
if (font != null) {
gc.setFont(font);
}
Rectangle drawBounds = getDrawBounds((TableCellSWT) event.cell);
sp = new GCStringPrinter(gc, text, drawBounds, true, true, SWT.WRAP | SWT.CENTER);
sp.calculateMetrics();
} catch (Exception e) {
Debug.out(e);
} finally {
gc.dispose();
}
if (sp != null) {
URLInfo hitUrl = sp.getHitUrl(event.x + bounds.x, event.y + bounds.y);
int newCursor;
if (hitUrl != null) {
if (event.eventType == TableCellMouseEvent.EVENT_MOUSEUP && event.button == 1) {
if (hitUrl.url.equals("download")) {
SBC_SearchResultsView.downloadAction(entry);
} else if (hitUrl.url.equals("details")) {
String details_url = entry.getDetailsLink();
try {
Utils.launch(new URL(details_url));
} catch (Throwable e) {
Debug.out(e);
}
}
} else {
if (hitUrl.url.equals("download")) {
tooltip = entry.getTorrentLink();
} else if (hitUrl.url.equals("details")) {
tooltip = entry.getDetailsLink();
}
}
newCursor = SWT.CURSOR_HAND;
} else {
newCursor = SWT.CURSOR_ARROW;
}
int oldCursor = ((TableCellSWT) event.cell).getCursorID();
if (oldCursor != newCursor) {
invalidateAndRefresh = true;
((TableCellSWT) event.cell).setCursorID(newCursor);
}
}
Object o = event.cell.getToolTip();
if ((o == null) || (o instanceof String)) {
String oldTooltip = (String) o;
if (!StringCompareUtils.equals(oldTooltip, tooltip)) {
invalidateAndRefresh = true;
event.cell.setToolTip(tooltip);
}
}
if (invalidateAndRefresh) {
event.cell.invalidate();
((TableCellSWT) event.cell).redraw();
}
}
use of com.biglybt.ui.swt.views.table.TableCellSWT in project BiglyBT by BiglySoftware.
the class SubscriptionManagerUI method createSubsColumns.
private void createSubsColumns(TableManager table_manager) {
final TableCellRefreshListener subs_refresh_listener = new TableCellRefreshListener() {
@Override
public void refresh(TableCell _cell) {
TableCellSWT cell = (TableCellSWT) _cell;
SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
Download dl = (Download) cell.getDataSource();
if (dl == null) {
return;
}
Torrent torrent = dl.getTorrent();
if (torrent != null) {
Subscription[] subs = subs_man.getKnownSubscriptions(torrent.getHash());
int num_subscribed = 0;
int num_unsubscribed = 0;
for (int i = 0; i < subs.length; i++) {
if (subs[i].isSubscribed()) {
num_subscribed++;
} else {
num_unsubscribed++;
}
}
Graphic graphic;
String tooltip;
int height = cell.getHeight();
int sort_order = 0;
if (subs.length == 0) {
graphic = null;
tooltip = null;
} else {
if (num_subscribed == subs.length) {
graphic = height >= 22 ? icon_rss_all_add_big : icon_rss_all_add_small;
tooltip = MessageText.getString("subscript.all.subscribed");
} else if (num_subscribed > 0) {
graphic = height >= 22 ? icon_rss_some_add_big : icon_rss_some_add_small;
tooltip = MessageText.getString("subscript.some.subscribed");
sort_order = 10000;
} else {
graphic = height >= 22 ? icon_rss_big : icon_rss_small;
tooltip = MessageText.getString("subscript.none.subscribed");
sort_order = 1000000;
}
}
sort_order += 1000 * num_unsubscribed + num_subscribed;
cell.setMarginHeight(0);
cell.setGraphic(graphic);
cell.setToolTip(tooltip);
cell.setSortValue(sort_order);
cell.setCursorID(graphic == null ? SWT.CURSOR_ARROW : SWT.CURSOR_HAND);
} else {
cell.setCursorID(SWT.CURSOR_ARROW);
cell.setSortValue(0);
}
}
};
final TableCellMouseListener subs_mouse_listener = new TableCellMouseListener() {
@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
if (event.eventType == TableCellMouseEvent.EVENT_MOUSEDOWN) {
TableCell cell = event.cell;
Download dl = (Download) cell.getDataSource();
Torrent torrent = dl.getTorrent();
if (torrent != null) {
SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
Subscription[] subs = subs_man.getKnownSubscriptions(torrent.getHash());
if (subs.length > 0) {
event.skipCoreFunctionality = true;
new SubscriptionWizard(PluginCoreUtils.unwrap(dl));
COConfigurationManager.setParameter("subscriptions.wizard.shown", true);
refreshTitles(mdiEntryOverview);
// new SubscriptionListWindow(PluginCoreUtils.unwrap(dl),true);
}
}
}
}
};
columnCreationSubs = new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn result) {
result.setAlignment(TableColumn.ALIGN_CENTER);
result.setPosition(TableColumn.POSITION_LAST);
result.setWidth(32);
result.setRefreshInterval(TableColumn.INTERVAL_INVALID_ONLY);
result.setType(TableColumn.TYPE_GRAPHIC);
result.addCellRefreshListener(subs_refresh_listener);
result.addCellMouseListener(subs_mouse_listener);
result.setIconReference("image.subscription.column", true);
synchronized (columns) {
columns.add(result);
}
}
};
table_manager.registerColumn(Download.class, "azsubs.ui.column.subs", columnCreationSubs);
final TableCellRefreshListener link_refresh_listener = new TableCellRefreshListener() {
@Override
public void refresh(TableCell _cell) {
TableCellSWT cell = (TableCellSWT) _cell;
SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
Download dl = (Download) cell.getDataSource();
if (dl == null) {
return;
}
String str = "";
Torrent torrent = dl.getTorrent();
if (torrent != null) {
byte[] hash = torrent.getHash();
Subscription[] subs = subs_man.getKnownSubscriptions(hash);
for (int i = 0; i < subs.length; i++) {
Subscription sub = subs[i];
if (sub.hasAssociation(hash)) {
str += (str.length() == 0 ? "" : "; ") + sub.getName();
}
}
}
cell.setCursorID(str.length() > 0 ? SWT.CURSOR_HAND : SWT.CURSOR_ARROW);
cell.setText(str);
}
};
final TableCellMouseListener link_mouse_listener = new TableCellMouseListener() {
@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
if (event.eventType == TableCellMouseEvent.EVENT_MOUSEDOWN) {
TableCell cell = event.cell;
Download dl = (Download) cell.getDataSource();
Torrent torrent = dl.getTorrent();
SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
if (torrent != null) {
byte[] hash = torrent.getHash();
Subscription[] subs = subs_man.getKnownSubscriptions(hash);
for (int i = 0; i < subs.length; i++) {
Subscription sub = subs[i];
if (sub.hasAssociation(hash)) {
showSubscriptionMDI(sub);
break;
}
}
}
}
}
};
columnCreationSubsLink = new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn result) {
result.setAlignment(TableColumn.ALIGN_LEAD);
result.setPosition(TableColumn.POSITION_INVISIBLE);
result.setWidth(85);
result.setRefreshInterval(TableColumn.INTERVAL_INVALID_ONLY);
result.setType(TableColumn.TYPE_TEXT_ONLY);
result.addCellRefreshListener(link_refresh_listener);
result.addCellMouseListener(link_mouse_listener);
result.setMinimumRequiredUserMode(Parameter.MODE_INTERMEDIATE);
synchronized (columns) {
columns.add(result);
}
}
};
table_manager.registerColumn(Download.class, "azsubs.ui.column.subs_link", columnCreationSubsLink);
}
use of com.biglybt.ui.swt.views.table.TableCellSWT in project BiglyBT by BiglySoftware.
the class PiecesItem method refresh.
@Override
public void refresh(final TableCell cell) {
/* Notes:
* We store our image and imageBufer in PEPeer using
* setData & getData.
*/
// Named infoObj so code can be copied easily to the other PiecesItem
final PEPeer infoObj = (PEPeer) cell.getDataSource();
long lCompleted = (infoObj == null) ? 0 : infoObj.getPercentDoneInThousandNotation();
if (!cell.setSortValue(lCompleted) && cell.isValid()) {
return;
}
if (infoObj == null)
return;
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (cell.isDisposed()) {
return;
}
// Compute bounds ...
int newWidth = cell.getWidth();
if (newWidth <= 0)
return;
int newHeight = cell.getHeight();
int x0 = borderVerticalSize;
int x1 = newWidth - 1 - borderVerticalSize;
int y0 = completionHeight + borderHorizontalSize + borderSplit;
int y1 = newHeight - 1 - borderHorizontalSize;
int drawWidth = x1 - x0 + 1;
if (drawWidth < 10 || y1 < 3)
return;
int[] imageBuffer = (int[]) infoObj.getData("PiecesImageBuffer");
boolean bImageBufferValid = imageBuffer != null && imageBuffer.length == drawWidth;
Image image = (Image) infoObj.getData("PiecesImage");
GC gcImage;
boolean bImageChanged;
Rectangle imageBounds;
if (image == null || image.isDisposed()) {
bImageChanged = true;
} else {
imageBounds = image.getBounds();
bImageChanged = imageBounds.width != newWidth || imageBounds.height != newHeight;
}
if (bImageChanged) {
if (image != null && !image.isDisposed()) {
image.dispose();
}
image = new Image(Utils.getDisplay(), newWidth, newHeight);
imageBounds = image.getBounds();
bImageBufferValid = false;
// draw border
gcImage = new GC(image);
gcImage.setForeground(Colors.grey);
if (borderHorizontalSize > 0) {
if (borderVerticalSize > 0) {
gcImage.drawRectangle(0, 0, newWidth - 1, newHeight - 1);
} else {
gcImage.drawLine(0, 0, newWidth - 1, 0);
gcImage.drawLine(0, newHeight - 1, newWidth - 1, newHeight - 1);
}
} else if (borderVerticalSize > 0) {
gcImage.drawLine(0, 0, 0, newHeight - 1);
gcImage.drawLine(newWidth - 1, 0, newWidth - 1, newHeight - 1);
}
if (borderSplit > 0) {
gcImage.setForeground(Colors.white);
gcImage.drawLine(x0, completionHeight + borderHorizontalSize, x1, completionHeight + borderHorizontalSize);
}
} else {
gcImage = new GC(image);
}
final BitFlags peerHave = infoObj.getAvailable();
boolean established = ((PEPeerTransport) infoObj).getConnectionState() == PEPeerTransport.CONNECTION_FULLY_ESTABLISHED;
if (established && peerHave != null && peerHave.flags.length > 0) {
if (imageBuffer == null || imageBuffer.length != drawWidth) {
imageBuffer = new int[drawWidth];
}
final boolean[] available = peerHave.flags;
try {
int nbComplete = 0;
int nbPieces = available.length;
DiskManager disk_manager = infoObj.getManager().getDiskManager();
DiskManagerPiece[] pieces = disk_manager == null ? null : disk_manager.getPieces();
int a0;
int a1 = 0;
for (int i = 0; i < drawWidth; i++) {
if (i == 0) {
// always start out with one piece
a0 = 0;
a1 = nbPieces / drawWidth;
if (a1 == 0)
a1 = 1;
} else {
// the last iteration, a1 will be nbPieces
a0 = a1;
a1 = ((i + 1) * nbPieces) / (drawWidth);
}
int index;
int nbNeeded = 0;
if (a1 <= a0) {
index = imageBuffer[i - 1];
} else {
int nbAvailable = 0;
for (int j = a0; j < a1; j++) {
if (available[j]) {
if (pieces == null || !pieces[j].isDone()) {
nbNeeded++;
}
nbAvailable++;
}
}
nbComplete += nbAvailable;
index = (nbAvailable * Colors.BLUES_DARKEST) / (a1 - a0);
if (nbNeeded <= nbAvailable / 2)
index += INDEX_COLOR_FADEDSTARTS;
}
if (imageBuffer[i] != index) {
imageBuffer[i] = index;
if (bImageBufferValid) {
bImageChanged = true;
if (imageBuffer[i] >= INDEX_COLOR_FADEDSTARTS)
gcImage.setForeground(Colors.faded[index - INDEX_COLOR_FADEDSTARTS]);
else
gcImage.setForeground(Colors.blues[index]);
gcImage.drawLine(i + x0, y0, i + x0, y1);
}
}
}
if (!bImageBufferValid) {
if (established) {
int iLastIndex = imageBuffer[0];
int iWidth = 1;
for (int i = 1; i < drawWidth; i++) {
if (iLastIndex == imageBuffer[i]) {
iWidth++;
} else {
if (iLastIndex >= INDEX_COLOR_FADEDSTARTS) {
gcImage.setBackground(Colors.faded[iLastIndex - INDEX_COLOR_FADEDSTARTS]);
} else
gcImage.setBackground(Colors.blues[iLastIndex]);
gcImage.fillRectangle(i - iWidth + x0, y0, iWidth, y1 - y0 + 1);
iWidth = 1;
iLastIndex = imageBuffer[i];
}
}
if (iLastIndex >= INDEX_COLOR_FADEDSTARTS)
gcImage.setBackground(Colors.faded[iLastIndex - INDEX_COLOR_FADEDSTARTS]);
else
gcImage.setBackground(Colors.blues[iLastIndex]);
gcImage.fillRectangle(x1 - iWidth + 1, y0, iWidth, y1 - y0 + 1);
bImageChanged = true;
}
}
int limit = (drawWidth * nbComplete) / nbPieces;
if (limit < drawWidth) {
gcImage.setBackground(Colors.blues[Colors.BLUES_LIGHTEST]);
gcImage.fillRectangle(limit + x0, borderHorizontalSize, x1 - limit, completionHeight);
}
gcImage.setBackground(Colors.colorProgressBar);
gcImage.fillRectangle(x0, borderHorizontalSize, limit, completionHeight);
} catch (Exception e) {
System.out.println("Error Drawing PiecesItem");
Debug.printStackTrace(e);
}
} else {
gcImage.setForeground(Colors.grey);
gcImage.setBackground(Colors.grey);
gcImage.fillRectangle(x0, y0, newWidth, y1);
}
gcImage.dispose();
Image oldImage = null;
Graphic graphic = cell.getGraphic();
if (graphic instanceof UISWTGraphic) {
oldImage = ((UISWTGraphic) graphic).getImage();
}
if (bImageChanged || image != oldImage || !cell.isValid()) {
if (cell instanceof TableCellSWT) {
((TableCellSWT) cell).setGraphic(image);
} else {
cell.setGraphic(new UISWTGraphicImpl(image));
}
if (oldImage != null && image != oldImage && !oldImage.isDisposed()) {
oldImage.dispose();
}
if (bImageChanged || image != oldImage) {
cell.invalidate();
}
infoObj.setData("PiecesImage", image);
infoObj.setData("PiecesImageBuffer", imageBuffer);
}
}
});
}
use of com.biglybt.ui.swt.views.table.TableCellSWT in project BiglyBT by BiglySoftware.
the class BlocksItem method refresh.
@Override
public void refresh(final TableCell cell) {
final PEPiece pePiece = (PEPiece) cell.getDataSource();
if (pePiece == null) {
cell.setSortValue(0);
dispose(cell);
cell.setGraphic(null);
return;
}
cell.setSortValue(pePiece.getNbWritten());
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
PiecePicker picker = pePiece.getPiecePicker();
long lNumBlocks = pePiece.getNbBlocks();
int newWidth = cell.getWidth();
if (newWidth <= 0) {
dispose(cell);
cell.setGraphic(null);
return;
}
int newHeight = cell.getHeight();
int x1 = newWidth - 2;
int y1 = newHeight - 3;
if (x1 < 10 || y1 < 3) {
dispose(cell);
cell.setGraphic(null);
return;
}
Image image = new Image(Utils.getDisplay(), newWidth, newHeight);
Color color;
GC gcImage = new GC(image);
gcImage.setForeground(Colors.grey);
gcImage.drawRectangle(0, 0, x1 + 1, y1 + 1);
int blocksPerPixel = 0;
int iPixelsPerBlock = 0;
int pxRes = 0;
long pxBlockStep = 0;
int factor = 4;
while (iPixelsPerBlock <= 0) {
blocksPerPixel++;
iPixelsPerBlock = (int) ((x1 + 1) / (lNumBlocks / blocksPerPixel));
}
pxRes = (int) (x1 - ((lNumBlocks / blocksPerPixel) * iPixelsPerBlock));
if (pxRes <= 0)
pxRes = 1;
pxBlockStep = (lNumBlocks * factor) / pxRes;
long addBlocks = (lNumBlocks * factor) / pxBlockStep;
if ((addBlocks * iPixelsPerBlock) > pxRes)
pxBlockStep += 1;
/* String msg = "iPixelsPerBlock = "+iPixelsPerBlock + ", blocksPerPixel = " + blocksPerPixel;
msg += ", pxRes = " + pxRes + ", pxBlockStep = " + pxBlockStep + ", addBlocks = " + addBlocks + ", x1 = " + x1;
Debug.out(msg);*/
TOTorrent torrent = pePiece.getManager().getDiskManager().getTorrent();
boolean[] written = pePiece.getDMPiece().getWritten();
boolean piece_written = pePiece.isWritten();
int drawnWidth = 0;
int blockStep = 0;
int pieceNumber = pePiece.getPieceNumber();
long[] offsets = new long[(int) lNumBlocks];
long[] lengths = (long[]) offsets.clone();
Arrays.fill(offsets, (long) pePiece.getManager().getDiskManager().getPieceLength() * (long) pieceNumber);
for (int i = 0; i < lNumBlocks; lengths[i] = pePiece.getBlockSize(i), offsets[i] += DiskManager.BLOCK_SIZE * i, i++) ;
boolean egm = picker.isInEndGameMode();
boolean[] isCached = cacheStats == null ? new boolean[(int) lNumBlocks] : cacheStats.getBytesInCache(torrent, offsets, lengths);
for (int i = 0; i < lNumBlocks; i += blocksPerPixel) {
int nextWidth = iPixelsPerBlock;
blockStep += blocksPerPixel * factor;
if (blockStep >= pxBlockStep) {
nextWidth += (int) (blockStep / pxBlockStep);
blockStep -= pxBlockStep;
}
if (i >= lNumBlocks - blocksPerPixel) {
nextWidth = x1 - drawnWidth;
}
color = Colors.white;
int num = -1;
if ((written == null && piece_written) || (written != null && written[i])) {
color = colors[COLOR_WRITTEN];
} else if (pePiece.isDownloaded(i)) {
color = colors[COLOR_DOWNLOADED];
} else if (pePiece.isRequested(i)) {
if (egm) {
int req_count = picker.getEGMRequestCount(pieceNumber, i);
if (req_count < 2) {
color = colors[COLOR_REQUESTED];
} else {
color = colors[COLOR_EGM];
num = req_count;
}
} else {
color = colors[COLOR_REQUESTED];
}
}
gcImage.setBackground(color);
gcImage.fillRectangle(drawnWidth + 1, 1, nextWidth, y1);
if (isCached[i]) {
gcImage.setBackground(colors[COLOR_INCACHE]);
gcImage.fillRectangle(drawnWidth + 1, 1, nextWidth, 3);
}
if (num >= 0) {
gcImage.setForeground(Colors.black);
gcImage.drawString(String.valueOf(num), drawnWidth + 1, 0, true);
}
drawnWidth += nextWidth;
}
gcImage.dispose();
Image oldImage = null;
Graphic graphic = cell.getGraphic();
if (graphic instanceof UISWTGraphic) {
oldImage = ((UISWTGraphic) graphic).getImage();
}
if (cell instanceof TableCellSWT) {
((TableCellSWT) cell).setGraphic(image);
} else {
cell.setGraphic(new UISWTGraphicImpl(image));
}
if (oldImage != null && !oldImage.isDisposed())
oldImage.dispose();
gcImage.dispose();
}
});
}
Aggregations