use of com.biglybt.ui.swt.views.table.TableCellSWT in project BiglyBT by BiglySoftware.
the class SubscriptionWizard method initColumns.
private static void initColumns() {
if (columnsAdded) {
return;
}
columnsAdded = true;
UIManager uiManager = PluginInitializer.getDefaultInterface().getUIManager();
TableManager tableManager = uiManager.getTableManager();
tableManager.registerColumn(Subscription.class, "SubWizName", new TableColumnCreationListener() {
private Image rssIcon;
@Override
public void tableColumnCreated(com.biglybt.pif.ui.tables.TableColumn column) {
// this'll get triggered for the Subscriptions Overview table too - easiest fix is to default to hidden there
column.setVisible(column.getTableID().equals("SubscriptionWizard"));
ImageLoader imageLoader = ImageLoader.getInstance();
rssIcon = imageLoader.getImage("icon_rss");
column.addCellAddedListener(new TableCellAddedListener() {
@Override
public void cellAdded(TableCell cell) {
Subscription sub = (Subscription) cell.getDataSource();
if (sub.isSubscribed()) {
cell.setForeground(0xa0, 0xa0, 0xa0);
}
cell.setText(sub.getName());
((TableCellSWT) cell).setIcon(rssIcon);
cell.setToolTip(sub.getNameEx());
}
});
}
});
tableManager.registerColumn(Subscription.class, "SubWizRank", new TableColumnCreationListener() {
@Override
public void tableColumnCreated(com.biglybt.pif.ui.tables.TableColumn column) {
column.setWidthLimits(RANK_COLUMN_WIDTH, RANK_COLUMN_WIDTH);
// as above
column.setVisible(column.getTableID().equals("SubscriptionWizard"));
column.addCellRefreshListener(new TableCellRefreshListener() {
@Override
public void refresh(TableCell cell) {
Subscription sub = (Subscription) cell.getDataSource();
cell.setSortValue(sub.getCachedPopularity());
}
});
if (column instanceof TableColumnCore) {
TableColumnCore columnCore = (TableColumnCore) column;
columnCore.setSortAscending(false);
columnCore.addCellOtherListener("SWTPaint", new TableCellSWTPaintListener() {
@Override
public void cellPaint(GC gc, TableCellSWT cell) {
Subscription sub = (Subscription) cell.getDataSource();
Rectangle bounds = cell.getBounds();
bounds.width -= 5;
bounds.height -= 7;
bounds.x += 2;
bounds.y += 3;
gc.setBackground(ColorCache.getColor(gc.getDevice(), 255, 255, 255));
gc.fillRectangle(bounds);
gc.setForeground(ColorCache.getColor(gc.getDevice(), 200, 200, 200));
gc.drawRectangle(bounds);
bounds.width -= 2;
bounds.height -= 2;
bounds.x += 1;
bounds.y += 1;
long popularity = sub.getCachedPopularity();
// Rank in pixels between 0 and 80
// 0 -> no subscriber
// 80 -> 1000 subscribers
int rank = 80 * (int) popularity / 1000;
if (rank > 80)
rank = 80;
if (rank < 5)
rank = 5;
Rectangle clipping = gc.getClipping();
bounds.width = rank;
bounds.height -= 1;
bounds.x += 1;
bounds.y += 1;
Utils.setClipping(gc, bounds);
ImageLoader imageLoader = ImageLoader.getInstance();
Image rankingBars = imageLoader.getImage("ranking_bars");
gc.drawImage(rankingBars, bounds.x, bounds.y);
imageLoader.releaseImage("ranking_bars");
Utils.setClipping(gc, clipping);
}
});
}
}
});
TableColumnManager tcm = TableColumnManager.getInstance();
tcm.setDefaultColumnNames(TABLE_SUB_WIZ, new String[] { "SubWizName", "SubWizRank" });
}
Aggregations