use of com.biglybt.ui.swt.utils.SearchSubsResultBase 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.utils.SearchSubsResultBase in project BiglyBT by BiglySoftware.
the class ColumnSearchSubResultAge method refresh.
@Override
public void refresh(TableCell cell) {
SearchSubsResultBase rc = (SearchSubsResultBase) cell.getDataSource();
if (rc == null) {
return;
}
long time = rc.getTime();
long age_secs = (SystemTime.getCurrentTime() - time) / 1000;
if (cell.setSortValue(age_secs)) {
if (time <= 0) {
cell.setText("--");
} else {
cell.setToolTip(time <= 0 ? "--" : DisplayFormatters.formatCustomDateOnly(time));
cell.setText(age_secs < 0 ? "--" : TimeFormatter.format3(age_secs));
}
}
}
use of com.biglybt.ui.swt.utils.SearchSubsResultBase in project BiglyBT by BiglySoftware.
the class ColumnSearchSubResultHash method refresh.
@Override
public void refresh(TableCell cell) {
SearchSubsResultBase result = (SearchSubsResultBase) cell.getDataSource();
byte[] hash = result.getHash();
String str = hash == null ? "" : ByteFormatter.encodeString(hash);
if (!cell.setSortValue(str) && cell.isValid()) {
return;
}
if (!cell.isShown()) {
return;
}
cell.setText(str);
}
use of com.biglybt.ui.swt.utils.SearchSubsResultBase in project BiglyBT by BiglySoftware.
the class ColumnSearchSubResultSize method refresh.
@Override
public void refresh(TableCell cell) {
SearchSubsResultBase rc = (SearchSubsResultBase) cell.getDataSource();
if (rc == null) {
return;
}
long size = rc.getSize();
if (size > 0 && cell.setSortValue(size)) {
cell.setText(DisplayFormatters.formatByteCountToKiBEtc(size));
}
}
use of com.biglybt.ui.swt.utils.SearchSubsResultBase in project BiglyBT by BiglySoftware.
the class ColumnSearchSubResultType method cellPaint.
@Override
public void cellPaint(GC gc, TableCellSWT cell) {
SearchSubsResultBase entry = (SearchSubsResultBase) cell.getDataSource();
Rectangle cellBounds = cell.getBounds();
Image img;
if (entry == null) {
img = imgOther;
} else {
int ct = entry.getContentType();
switch(ct) {
case 0:
{
img = imgOther;
break;
}
case 1:
{
img = imgVideo;
break;
}
case 2:
{
img = imgAudio;
break;
}
case 3:
{
img = imgGame;
break;
}
default:
{
img = imgOther;
break;
}
}
}
if (img != null && !img.isDisposed()) {
Rectangle imgBounds = img.getBounds();
gc.drawImage(img, cellBounds.x + ((cellBounds.width - imgBounds.width) / 2), cellBounds.y + ((cellBounds.height - imgBounds.height) / 2));
}
}
Aggregations