use of com.biglybt.ui.selectedcontent.ISelectedContent in project BiglyBT by BiglySoftware.
the class UIManagerImpl method initialisationComplete.
public static void initialisationComplete() {
SelectedContentManager.addCurrentlySelectedContentListener(new SelectedContentListener() {
@Override
public void currentlySelectedContentChanged(ISelectedContent[] currentContent, String viewID) {
triggerDataSourceListeners(SelectedContentManager.convertSelectedContentToObject(null));
}
});
List<Object[]> to_fire = new ArrayList<>();
try {
class_mon.enter();
initialisation_complete = true;
for (int j = 0; j < ui_factories.size(); j++) {
UIInstanceFactory factory = (UIInstanceFactory) ui_factories.get(j);
Iterator<Object[]> it = ui_listeners.iterator();
while (it.hasNext()) {
Object[] entry = it.next();
List<UIInstanceFactory> fired = (List<UIInstanceFactory>) entry[2];
if (!fired.contains(factory)) {
fired.add(factory);
to_fire.add(new Object[] { entry[0], factory.getInstance((PluginInterface) entry[1]) });
}
}
}
} finally {
class_mon.exit();
}
for (Object[] entry : to_fire) {
try {
((UIManagerListener) entry[0]).UIAttached((UIInstance) entry[1]);
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
for (Object[] entry : to_fire) {
try {
if (entry[0] instanceof UIManagerListener2) {
((UIManagerListener2) entry[0]).UIAttachedComplete((UIInstance) entry[1]);
}
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
}
use of com.biglybt.ui.selectedcontent.ISelectedContent in project BiglyBT by BiglySoftware.
the class DataSourceUtils method getFileInfo.
public static com.biglybt.core.disk.DiskManagerFileInfo getFileInfo(Object ds) {
try {
if (ds instanceof DiskManagerFileInfo) {
return PluginCoreUtils.unwrap((DiskManagerFileInfo) ds);
} else if (ds instanceof com.biglybt.core.disk.DiskManagerFileInfo) {
return (com.biglybt.core.disk.DiskManagerFileInfo) ds;
} else if ((ds instanceof ISelectedContent) && ((ISelectedContent) ds).getFileIndex() >= 0) {
ISelectedContent sc = (ISelectedContent) ds;
int idx = sc.getFileIndex();
DownloadManager dm = sc.getDownloadManager();
return dm.getDiskManagerFileInfoSet().getFiles()[idx];
} else if (ds instanceof TranscodeJob) {
TranscodeJob tj = (TranscodeJob) ds;
try {
return PluginCoreUtils.unwrap(tj.getFile());
} catch (DownloadException e) {
}
} else if (ds instanceof TranscodeFile) {
TranscodeFile tf = (TranscodeFile) ds;
try {
DiskManagerFileInfo file = tf.getSourceFile();
return PluginCoreUtils.unwrap(file);
} catch (DownloadException e) {
}
}
} catch (Exception e) {
Debug.printStackTrace(e);
}
return null;
}
use of com.biglybt.ui.selectedcontent.ISelectedContent in project BiglyBT by BiglySoftware.
the class MyTorrentsView method refreshToolBarItems.
@Override
public void refreshToolBarItems(Map<String, Long> list) {
ISelectedContent[] datasource = SelectedContentManager.getCurrentlySelectedContent();
if (!isTableFocus()) {
UISWTViewCore active_view = getActiveView();
if (active_view != null) {
UIPluginViewToolBarListener l = active_view.getToolBarListener();
if (l != null) {
Map<String, Long> activeViewList = new HashMap<>();
l.refreshToolBarItems(activeViewList);
if (activeViewList.size() > 0) {
list.putAll(activeViewList);
return;
}
}
}
}
}
use of com.biglybt.ui.selectedcontent.ISelectedContent in project BiglyBT by BiglySoftware.
the class SBC_SearchResultsView method initTable.
private void initTable(Composite control) {
tv_subs_results = TableViewFactory.createTableViewSWT(SBC_SearchResult.class, TABLE_SR, TABLE_SR, new TableColumnCore[0], ColumnSearchSubResultName.COLUMN_ID, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
TableColumnManager tableManager = TableColumnManager.getInstance();
tableManager.setDefaultColumnNames(TABLE_SR, new String[] { ColumnSearchSubResultType.COLUMN_ID, ColumnSearchSubResultName.COLUMN_ID, ColumnSearchSubResultActions.COLUMN_ID, ColumnSearchSubResultSize.COLUMN_ID, ColumnSearchSubResultSeedsPeers.COLUMN_ID, ColumnSearchSubResultRatings.COLUMN_ID, ColumnSearchSubResultAge.COLUMN_ID, ColumnSearchSubResultRank.COLUMN_ID, ColumnSearchSubResultCategory.COLUMN_ID, ColumnSearchResultSite.COLUMN_ID });
tableManager.setDefaultSortColumnName(TABLE_SR, ColumnSearchSubResultRank.COLUMN_ID);
if (txtFilter != null) {
tv_subs_results.enableFilterCheck(txtFilter, this);
}
tv_subs_results.setRowDefaultHeight(COConfigurationManager.getIntParameter("Search Subs Row Height"));
SWTSkinObject soSizeSlider = getSkinObject("table-size-slider");
if (soSizeSlider instanceof SWTSkinObjectContainer) {
SWTSkinObjectContainer so = (SWTSkinObjectContainer) soSizeSlider;
if (!tv_subs_results.enableSizeSlider(so.getComposite(), 16, 100)) {
so.setVisible(false);
}
}
table_parent = new Composite(control, SWT.NONE);
table_parent.setLayoutData(Utils.getFilledFormData());
GridLayout layout = new GridLayout();
layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
table_parent.setLayout(layout);
tv_subs_results.addSelectionListener(new TableSelectionListener() {
@Override
public void selected(TableRowCore[] _rows) {
updateSelectedContent();
}
@Override
public void mouseExit(TableRowCore row) {
}
@Override
public void mouseEnter(TableRowCore row) {
}
@Override
public void focusChanged(TableRowCore focus) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.refreshIconBar();
}
}
@Override
public void deselected(TableRowCore[] rows) {
updateSelectedContent();
}
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask) {
if (rows.length == 1) {
SBC_SearchResult rc = (SBC_SearchResult) rows[0].getDataSource();
downloadAction(rc);
}
}
private void updateSelectedContent() {
TableRowCore[] rows = tv_subs_results.getSelectedRows();
ArrayList<ISelectedContent> valid = new ArrayList<>();
last_selected_content.clear();
for (int i = 0; i < rows.length; i++) {
SBC_SearchResult rc = (SBC_SearchResult) rows[i].getDataSource();
last_selected_content.add(rc);
byte[] hash = rc.getHash();
if (hash != null && hash.length > 0) {
SelectedContent sc = new SelectedContent(Base32.encode(hash), rc.getName());
sc.setDownloadInfo(new DownloadUrlInfo(getDownloadURI(rc)));
valid.add(sc);
}
}
ISelectedContent[] sels = valid.toArray(new ISelectedContent[valid.size()]);
SelectedContentManager.changeCurrentlySelectedContent("IconBarEnabler", sels, tv_subs_results);
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.refreshIconBar();
}
}
}, false);
tv_subs_results.addMenuFillListener(new TableViewSWTMenuFillListener() {
@Override
public void fillMenu(String sColumnName, Menu menu) {
Object[] _related_content = tv_subs_results.getSelectedDataSources().toArray();
final SBC_SearchResult[] results = new SBC_SearchResult[_related_content.length];
System.arraycopy(_related_content, 0, results, 0, results.length);
MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText(MessageText.getString("label.copy.url.to.clip"));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
StringBuffer buffer = new StringBuffer(1024);
for (SBC_SearchResult result : results) {
if (buffer.length() > 0) {
buffer.append("\r\n");
}
buffer.append(getDownloadURI(result));
}
ClipboardCopy.copyToClipBoard(buffer.toString());
}
});
item.setEnabled(results.length > 0);
SearchSubsUtils.addMenu(results, menu);
new MenuItem(menu, SWT.SEPARATOR);
if (results.length == 1) {
if (SearchSubsUtils.addMenu(results[0], menu)) {
new MenuItem(menu, SWT.SEPARATOR);
}
}
}
@Override
public void addThisColumnSubMenu(String columnName, Menu menuThisColumn) {
}
});
tv_subs_results.initialize(table_parent);
control.layout(true);
}
use of com.biglybt.ui.selectedcontent.ISelectedContent in project BiglyBT by BiglySoftware.
the class TableViewPainted method initialize.
@Override
public void initialize(UISWTView parentView, Composite parent) {
tvTabsCommon = new TableViewSWT_TabsCommon(parentView, this);
shell = parent.getShell();
mainComposite = tvTabsCommon.createSashForm(parent);
mainComposite.setData("Name", tableID);
mainComposite.setData("ObfuscateImage", this);
Composite cTableComposite = tvTabsCommon.tableComposite;
cTableComposite.setLayout(new FormLayout());
Layout layout = parent.getLayout();
if (layout instanceof FormLayout) {
FormData fd = Utils.getFilledFormData();
cTableComposite.setLayoutData(fd);
}
cHeaderArea = new Canvas(cTableComposite, SWT.DOUBLE_BUFFERED);
fontHeader = FontUtils.getFontWithHeight(cHeaderArea.getFont(), null, Utils.adjustPXForDPI(12));
fontHeaderSmall = FontUtils.getFontPercentOf(fontHeader, 0.8f);
cHeaderArea.setFont(fontHeader);
cTable = new Canvas(cTableComposite, SWT.NO_BACKGROUND | SWT.H_SCROLL | SWT.V_SCROLL);
int minRowHeight = FontUtils.getFontHeightInPX(cTable.getFont());
if (iHeightEM > 0) {
defaultRowHeight = (int) ((minRowHeight * iHeightEM) + iHeightEM);
iHeightEM = -1;
}
// good test
// cTable.setFont(FontUtils.getFontPercentOf(cTable.getFont(), 1.50f));
minRowHeight += Math.ceil(minRowHeight * 2.0 / 16.0);
if (defaultRowHeight < minRowHeight) {
defaultRowHeight = minRowHeight;
}
cTable.setBackground(Colors.getSystemColor(parent.getDisplay(), SWT.COLOR_LIST_BACKGROUND));
headerHeight = configMan.getIntParameter("Table.headerHeight");
if (headerHeight <= 0) {
headerHeight = Utils.adjustPXForDPI(DEFAULT_HEADER_HEIGHT);
}
FormData fd = Utils.getFilledFormData();
fd.height = headerHeight;
fd.bottom = null;
cHeaderArea.setLayoutData(fd);
fd = Utils.getFilledFormData();
fd.top = new FormAttachment(cHeaderArea);
cTable.setLayoutData(fd);
clientArea = cTable.getClientArea();
TableColumnCore[] tableColumns = getAllColumns();
TableColumnCore[] tmpColumnsOrdered = new TableColumnCore[tableColumns.length];
// Create all columns
int columnOrderPos = 0;
Arrays.sort(tableColumns, TableColumnManager.getTableColumnOrderComparator());
for (int i = 0; i < tableColumns.length; i++) {
int position = tableColumns[i].getPosition();
if (position != -1 && tableColumns[i].isVisible()) {
// table.createNewColumn(SWT.NULL);
// System.out.println(i + "] " + tableColumns[i].getName() + ";" + position);
tmpColumnsOrdered[columnOrderPos++] = tableColumns[i];
}
}
// int numSWTColumns = table.getColumnCount();
// int iNewLength = numSWTColumns - (bSkipFirstColumn ? 1 : 0);
TableColumnCore[] columnsOrdered = new TableColumnCore[columnOrderPos];
System.arraycopy(tmpColumnsOrdered, 0, columnsOrdered, 0, columnOrderPos);
setColumnsOrdered(columnsOrdered);
cTable.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
swt_paintComposite(e);
}
});
menu = createMenu();
cTable.setMenu(menu);
cHeaderArea.setMenu(menu);
setupHeaderArea(cHeaderArea);
cTable.addControlListener(new ControlListener() {
boolean inControlResize = false;
@Override
public void controlResized(ControlEvent e) {
if (inControlResize) {
return;
}
try {
inControlResize = true;
swt_calculateClientArea();
swt_fixupSize();
} finally {
inControlResize = false;
}
}
@Override
public void controlMoved(ControlEvent e) {
}
});
hBar = cTable.getHorizontalBar();
if (hBar != null) {
hBar.setValues(0, 0, 0, 10, 10, 100);
hBar.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
// swt_calculateClientArea();
if (DIRECT_DRAW) {
swt_calculateClientArea();
redrawTable();
} else {
cTable.redraw();
}
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
vBar = cTable.getVerticalBar();
if (vBar != null) {
vBar.setValues(0, 0, 0, 50, getRowDefaultHeight(), 50);
vBar.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
swt_vBarChanged();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
if (DEBUG_WITH_SHELL) {
Shell shell = new Shell();
sCanvasImage = new Canvas(shell, SWT.DOUBLE_BUFFERED);
shell.setLayout(new FillLayout());
sCanvasImage.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
if (canvasImage == null) {
return;
}
e.gc.drawImage(canvasImage, 0, 0);
// System.out.println(System.currentTimeMillis() + "] Paint " + e.x + "x" + e.y + " " + e.width + "x" + e.height);
}
});
shell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
sCanvasImage = null;
}
});
shell.setVisible(true);
}
cTable.addMouseListener(tvSWTCommon);
cTable.addMouseMoveListener(tvSWTCommon);
cTable.addKeyListener(tvSWTCommon);
// composite.addSelectionListener(tvSWTCommon);
cTable.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e) {
e.doit = true;
}
});
cTable.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (canvasImage != null) {
canvasImage.dispose();
canvasImage = null;
}
}
});
SelectedContentManager.addCurrentlySelectedContentListener(new SelectedContentListener() {
@Override
public void currentlySelectedContentChanged(ISelectedContent[] currentContent, String viewID) {
if (cTable == null || cTable.isDisposed()) {
SelectedContentManager.removeCurrentlySelectedContentListener(this);
} else {
redrawTable();
}
}
});
cTable.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
isFocused = false;
redrawTable();
}
@Override
public void focusGained(FocusEvent e) {
isFocused = true;
redrawTable();
}
});
isFocused = cTable.isFocusControl();
new TableTooltips(this, cTable);
TableColumnManager tcManager = TableColumnManager.getInstance();
String sSortColumn = tcManager.getDefaultSortColumnName(tableID);
if (sSortColumn == null || sSortColumn.length() == 0) {
sSortColumn = sDefaultSortOn;
}
TableColumnCore tc = tcManager.getTableColumnCore(tableID, sSortColumn);
if (tc == null && tableColumns.length > 0) {
tc = tableColumns[0];
}
setSortColumn(tc, false);
triggerLifeCycleListener(TableLifeCycleListener.EVENT_TABLELIFECYCLE_INITIALIZED);
configMan.addParameterListener("Graphics Update", this);
configMan.addParameterListener("ReOrder Delay", this);
configMan.addParameterListener("Table.extendedErase", this);
configMan.addParameterListener("Table.headerHeight", this);
Colors.getInstance().addColorsChangedListener(this);
// So all TableView objects of the same TableID have the same columns,
// and column widths, etc
TableStructureEventDispatcher.getInstance(tableID).addListener(this);
MessageText.addListener(this);
}
Aggregations