use of com.biglybt.ui.swt.views.table.TableViewSWT in project BiglyBT by BiglySoftware.
the class MenuFactory method buildTorrentMenu.
public static void buildTorrentMenu(Menu menu) {
DownloadManager[] current_dls = (DownloadManager[]) menu.getData("downloads");
current_dls = ManagerUtils.cleanUp(current_dls);
if (current_dls.length == 0) {
return;
}
if (CoreFactory.isCoreRunning()) {
boolean is_detailed_view = ((Boolean) menu.getData("is_detailed_view")).booleanValue();
TableViewSWT<?> tv = (TableViewSWT<?>) menu.getData("TableView");
Core core = CoreFactory.getSingleton();
TorrentUtil.fillTorrentMenu(menu, current_dls, core, !is_detailed_view, 0, tv);
}
com.biglybt.pif.ui.menus.MenuItem[] menu_items;
menu_items = MenuItemManager.getInstance().getAllAsArray(new String[] { MenuManager.MENU_TORRENT_MENU, MenuManager.MENU_DOWNLOAD_CONTEXT });
final Object[] plugin_dls = DownloadManagerImpl.getDownloadStatic(current_dls);
if (menu_items.length > 0) {
addSeparatorMenuItem(menu);
MenuBuildUtils.addPluginMenuItems(menu_items, menu, true, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(plugin_dls));
}
menu_items = null;
/**
* OK, "hack" time - we'll allow plugins which add menu items against
* a table to appear in this menu. We'll have to fake the table row
* object though. All downloads need to share a common table.
*/
String table_to_use = null;
for (int i = 0; i < current_dls.length; i++) {
String table_name = (current_dls[i].isDownloadComplete(false) ? TableManager.TABLE_MYTORRENTS_COMPLETE : TableManager.TABLE_MYTORRENTS_INCOMPLETE);
if (table_to_use == null || table_to_use.equals(table_name)) {
table_to_use = table_name;
} else {
table_to_use = null;
break;
}
}
if (table_to_use != null) {
menu_items = TableContextMenuManager.getInstance().getAllAsArray(table_to_use);
}
if (menu_items != null) {
addSeparatorMenuItem(menu);
TableRow[] dls_as_rows = null;
dls_as_rows = new TableRow[plugin_dls.length];
for (int i = 0; i < plugin_dls.length; i++) {
dls_as_rows[i] = wrapAsRow(plugin_dls[i], table_to_use);
}
MenuBuildUtils.addPluginMenuItems(menu_items, menu, true, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(dls_as_rows));
}
}
use of com.biglybt.ui.swt.views.table.TableViewSWT in project BiglyBT by BiglySoftware.
the class MyTorrentsSuperView method initializeWithCore.
private void initializeWithCore(Core core, Composite parent) {
torrentview = createTorrentView(core, TableManager.TABLE_MYTORRENTS_INCOMPLETE, false, getIncompleteColumns(), child1);
seedingview = createTorrentView(core, TableManager.TABLE_MYTORRENTS_COMPLETE, true, getCompleteColumns(), child2);
torrentview.getComposite().addListener(SWT.FocusIn, new Listener() {
@Override
public void handleEvent(Event event) {
seedingview.getTableView().getTabsCommon().setTvOverride(torrentview.getTableView());
}
});
seedingview.getComposite().addListener(SWT.FocusIn, new Listener() {
@Override
public void handleEvent(Event event) {
seedingview.getTableView().getTabsCommon().setTvOverride(null);
}
});
// delegate selections from the incomplete view to the sub-tabs owned by the seeding view
SelectedContentManager.addCurrentlySelectedContentListener(new SelectedContentListener() {
@Override
public void currentlySelectedContentChanged(ISelectedContent[] currentContent, String viewId) {
if (form.isDisposed() || torrentview == null || seedingview == null) {
SelectedContentManager.removeCurrentlySelectedContentListener(this);
} else {
TableView<?> selected_tv = SelectedContentManager.getCurrentlySelectedTableView();
TableViewSWT<?> incomp_tv = torrentview.getTableView();
TableViewSWT<?> comp_tv = seedingview.getTableView();
if (incomp_tv != null && comp_tv != null && (selected_tv == incomp_tv || selected_tv == comp_tv)) {
TableViewSWT_TabsCommon tabs = comp_tv.getTabsCommon();
if (tabs != null) {
Utils.execSWTThread(new Runnable() {
public void run() {
tabs.triggerTabViewsDataSourceChanged(selected_tv);
}
});
}
}
}
}
});
initializeDone();
}
use of com.biglybt.ui.swt.views.table.TableViewSWT in project BiglyBT by BiglySoftware.
the class TableRowPainted method swt_paintCell.
private boolean swt_paintCell(GC gc, Rectangle cellBounds, TableCellSWTBase cell, Color shadowColor) {
// Only called from swt_PaintGC, so we can assume GC, cell are valid
if (cellBounds == null) {
return false;
}
boolean gcChanged = false;
try {
gc.setTextAntialias(SWT.DEFAULT);
TableViewSWT<?> view = (TableViewSWT<?>) getView();
TableColumnCore column = (TableColumnCore) cell.getTableColumn();
view.invokePaintListeners(gc, this, column, cellBounds);
int fontStyle = getFontStyle();
Font oldFont = null;
if (fontStyle == SWT.BOLD) {
oldFont = gc.getFont();
gc.setFont(FontUtils.getAnyFontBold(gc));
gcChanged = true;
} else if (fontStyle == SWT.ITALIC) {
oldFont = gc.getFont();
gc.setFont(FontUtils.getAnyFontItalic(gc));
gcChanged = true;
}
if (!cell.isUpToDate()) {
// System.out.println("R " + rowIndex + ":" + iColumnNo);
cell.refresh(true, true);
// return;
}
String text = cell.getText();
Color fg = cell.getForegroundSWT();
if (fg != null) {
gcChanged = true;
if (isSelected()) {
shadowColor = fg;
} else {
gc.setForeground(fg);
}
}
Color bg = cell.getBackgroundSWT();
if (bg != null) {
gcChanged = true;
gc.setBackground(bg);
}
// }
if (cell.needsPainting()) {
Image graphicSWT = cell.getGraphicSWT();
if (graphicSWT != null && !graphicSWT.isDisposed()) {
Rectangle imageBounds = graphicSWT.getBounds();
Rectangle graphicBounds = new Rectangle(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height);
if (cell.getFillCell()) {
if (!graphicBounds.isEmpty()) {
gc.setAdvanced(true);
// System.out.println(imageBounds + ";" + graphicBounds);
gc.drawImage(graphicSWT, 0, 0, imageBounds.width, imageBounds.height, graphicBounds.x, graphicBounds.y, graphicBounds.width, graphicBounds.height);
}
} else {
if (imageBounds.width < graphicBounds.width) {
int alignment = column.getAlignment();
if ((alignment & TableColumn.ALIGN_CENTER) > 0) {
graphicBounds.x += (graphicBounds.width - imageBounds.width) / 2;
} else if ((alignment & TableColumn.ALIGN_TRAIL) > 0) {
graphicBounds.x = (graphicBounds.x + graphicBounds.width) - imageBounds.width;
}
}
if (imageBounds.height < graphicBounds.height) {
graphicBounds.y += (graphicBounds.height - imageBounds.height) / 2;
}
gc.drawImage(graphicSWT, graphicBounds.x, graphicBounds.y);
}
}
cell.doPaint(gc);
gcChanged = true;
}
if (text.length() > 0) {
int ofsx = 0;
Image image = cell.getIcon();
Rectangle imageBounds = null;
if (image != null && !image.isDisposed()) {
imageBounds = image.getBounds();
int ofs = imageBounds.width;
ofsx += ofs;
cellBounds.x += ofs;
cellBounds.width -= ofs;
}
// System.out.println("PS " + getIndex() + ";" + cellBounds + ";" + cell.getText());
int style = TableColumnSWTUtils.convertColumnAlignmentToSWT(column.getAlignment());
if (cellBounds.height > 20) {
style |= SWT.WRAP;
}
int textOpacity = cell.getTextAlpha();
// textOpacity = 130;
if (textOpacity < 255) {
// gc.setTextAntialias(SWT.ON);
gc.setAlpha(textOpacity);
gcChanged = true;
} else if (textOpacity > 255) {
boolean is_italic = (gc.getFont().getFontData()[0].getStyle() & SWT.ITALIC) != 0;
if (is_italic) {
gc.setFont(FontUtils.getAnyFontBoldItalic(gc));
} else {
gc.setFont(FontUtils.getAnyFontBold(gc));
}
// gc.setTextAntialias(SWT.ON);
// gc.setAlpha(textOpacity & 255);
gcChanged = true;
}
// put some padding on text
ofsx += 6;
cellBounds.x += 3;
cellBounds.width -= 6;
cellBounds.y += 2;
cellBounds.height -= 4;
if (!cellBounds.isEmpty()) {
GCStringPrinter sp = new GCStringPrinter(gc, text, cellBounds, true, cellBounds.height > 20, style);
boolean fit;
if (shadowColor != null) {
Color oldFG = gc.getForeground();
gc.setForeground(shadowColor);
cellBounds.x += 1;
cellBounds.y += 1;
int alpha = gc.getAlpha();
gc.setAlpha(0x40);
sp.printString(gc, cellBounds, style);
gc.setAlpha(alpha);
gc.setForeground(oldFG);
cellBounds.x -= 1;
cellBounds.y -= 1;
fit = sp.printString2(gc, cellBounds, style);
} else {
fit = sp.printString();
}
if (fit) {
cell.setDefaultToolTip(null);
} else {
cell.setDefaultToolTip(text);
}
Point psize = sp.getCalculatedPreferredSize();
psize.x += ofsx;
TableColumn tableColumn = cell.getTableColumn();
if (tableColumn != null && tableColumn.getPreferredWidth() < psize.x) {
tableColumn.setPreferredWidth(psize.x);
}
if (imageBounds != null) {
int drawToY = cellBounds.y + (cellBounds.height / 2) - (imageBounds.height / 2);
boolean hack_adv = Constants.isWindows8OrHigher && gc.getAdvanced();
if (hack_adv) {
// problem with icon transparency on win8
gc.setAdvanced(false);
}
if ((style & SWT.RIGHT) != 0) {
Point size = sp.getCalculatedSize();
size.x += ofsx;
int drawToX = cellBounds.x + cellBounds.width - size.x;
gc.drawImage(image, drawToX, drawToY);
} else {
if (imageBounds.height > cellBounds.height) {
float pct = cellBounds.height / (float) imageBounds.height;
gc.drawImage(image, 0, 0, imageBounds.width, imageBounds.height, cellBounds.x - imageBounds.width - 3, cellBounds.y, (int) (imageBounds.width * pct), (int) (imageBounds.height * pct));
} else {
gc.drawImage(image, cellBounds.x - imageBounds.width - 3, drawToY);
}
}
if (hack_adv) {
gc.setAdvanced(true);
}
}
} else {
cell.setDefaultToolTip(null);
}
}
cell.clearVisuallyChangedSinceRefresh();
if (oldFont != null) {
gc.setFont(oldFont);
}
} catch (Exception e) {
Debug.out(cell.getTableID() + ":" + cell.getTableColumn().getName(), e);
}
return gcChanged;
}
Aggregations