use of com.biglybt.activities.ActivitiesEntry in project BiglyBT by BiglySoftware.
the class ColumnActivityType method cellPaint.
// @see com.biglybt.ui.swt.views.table.TableCellSWTPaintListener#cellPaint(org.eclipse.swt.graphics.GC, com.biglybt.pif.ui.tables.TableCell)
@Override
public void cellPaint(GC gc, final TableCellSWT cell) {
ActivitiesEntry entry = (ActivitiesEntry) cell.getDataSource();
Image imgIcon;
String iconID = entry.getIconID();
if (iconID != null) {
ImageLoader imageLoader = ImageLoader.getInstance();
if (iconID.startsWith("http")) {
imgIcon = imageLoader.getUrlImage(iconID, new ImageDownloaderListener() {
@Override
public void imageDownloaded(Image image, boolean returnedImmediately) {
if (returnedImmediately) {
return;
}
cell.invalidate();
}
});
if (imgIcon == null) {
return;
}
} else {
imgIcon = imageLoader.getImage(iconID);
}
if (ImageLoader.isRealImage(imgIcon)) {
Rectangle cellBounds = cell.getBounds();
Rectangle imgBounds = imgIcon.getBounds();
gc.drawImage(imgIcon, cellBounds.x + ((cellBounds.width - imgBounds.width) / 2), cellBounds.y + ((cellBounds.height - imgBounds.height) / 2));
}
imageLoader.releaseImage(iconID);
}
}
use of com.biglybt.activities.ActivitiesEntry in project BiglyBT by BiglySoftware.
the class ColumnActivityType method refresh.
// @see com.biglybt.pif.ui.tables.TableCellRefreshListener#refresh(com.biglybt.pif.ui.tables.TableCell)
@Override
public void refresh(TableCell cell) {
ActivitiesEntry entry = (ActivitiesEntry) cell.getDataSource();
String sort = entry.getTypeID() + entry.getIconID();
if (cell.setSortValue(sort) || !cell.isValid()) {
String ts = timeFormat.format(new Date(entry.getTimestamp()));
cell.setToolTip("Activity occurred on " + ts);
}
}
use of com.biglybt.activities.ActivitiesEntry in project BiglyBT by BiglySoftware.
the class SBC_ActivityTableView method skinObjectInitialShow.
// @see SkinView#skinObjectInitialShow(SWTSkinObject, java.lang.Object)
@Override
public Object skinObjectInitialShow(SWTSkinObject skinObject, Object params) {
skinObject.addListener(new SWTSkinObjectListener() {
@Override
public Object eventOccured(SWTSkinObject skinObject, int eventType, Object params) {
if (eventType == SWTSkinObjectListener.EVENT_SHOW) {
SelectedContentManager.changeCurrentlySelectedContent(tableID, getCurrentlySelectedContent(), view);
} else if (eventType == SWTSkinObjectListener.EVENT_HIDE) {
SelectedContentManager.changeCurrentlySelectedContent(tableID, null, view);
}
return null;
}
});
SWTSkinObject soParent = skinObject.getParent();
Object data = soParent.getControl().getData("ViewMode");
if (data instanceof Long) {
viewMode = (int) ((Long) data).longValue();
}
boolean big = viewMode == SBC_ActivityView.MODE_BIGTABLE;
tableID = big ? TableManager.TABLE_ACTIVITY_BIG : TableManager.TABLE_ACTIVITY;
TableColumnCore[] columns = big ? TableColumnCreatorV3.createActivityBig(tableID) : TableColumnCreatorV3.createActivitySmall(tableID);
view = TableViewFactory.createTableViewSWT(ActivitiesEntry.class, tableID, tableID, columns, "name", SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
view.setRowDefaultHeightEM(big ? 3 : 2);
view.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.DEL) {
removeSelected();
} else if (e.keyCode == SWT.F5) {
if ((e.stateMask & SWT.SHIFT) != 0) {
ActivitiesManager.resetRemovedEntries();
}
if ((e.stateMask & SWT.CONTROL) != 0) {
System.out.println("pull all vuze news entries");
ActivitiesManager.clearLastPullTimes();
ActivitiesManager.pullActivitiesNow(0, "^F5", true);
} else {
System.out.println("pull latest vuze news entries");
ActivitiesManager.pullActivitiesNow(0, "F5", true);
}
}
}
});
view.addSelectionListener(new TableSelectionAdapter() {
// @see TableSelectionAdapter#selected(TableRowCore[])
@Override
public void selected(TableRowCore[] rows) {
selectionChanged();
for (int i = 0; i < rows.length; i++) {
ActivitiesEntry entry = (ActivitiesEntry) rows[i].getDataSource(true);
if (entry != null && !entry.isRead() && entry.canFlipRead()) {
entry.setRead(true);
}
}
}
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask) {
if (rows.length == 1) {
ActivitiesEntry ds = (ActivitiesEntry) rows[0].getDataSource();
if (ds.getTypeID().equals(ActivitiesConstants.TYPEID_LOCALNEWS)) {
String[] actions = ds.getActions();
if (actions.length == 1) {
ds.invokeCallback(actions[0]);
}
} else {
TorrentListViewsUtils.playOrStreamDataSource(ds, false);
}
}
}
@Override
public void deselected(TableRowCore[] rows) {
selectionChanged();
}
public void selectionChanged() {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
ISelectedContent[] contents = getCurrentlySelectedContent();
if (soMain.isVisible()) {
SelectedContentManager.changeCurrentlySelectedContent(tableID, contents, view);
}
}
});
}
}, false);
view.addLifeCycleListener(new TableLifeCycleListener() {
@Override
public void tableLifeCycleEventOccurred(TableView tv, int eventType, Map<String, Object> data) {
switch(eventType) {
case EVENT_TABLELIFECYCLE_INITIALIZED:
view.addDataSources(ActivitiesManager.getAllEntries().toArray(new ActivitiesEntry[0]));
ActivitiesManager.addListener(SBC_ActivityTableView.this);
break;
case EVENT_TABLELIFECYCLE_DESTROYED:
ActivitiesManager.removeListener(SBC_ActivityTableView.this);
break;
}
}
});
SWTSkinObjectContainer soContents = new SWTSkinObjectContainer(skin, skin.getSkinProperties(), getUpdateUIName(), "", soMain);
skin.layout();
viewComposite = soContents.getComposite();
viewComposite.setBackground(Colors.getSystemColor(viewComposite.getDisplay(), SWT.COLOR_WIDGET_BACKGROUND));
viewComposite.setForeground(Colors.getSystemColor(viewComposite.getDisplay(), SWT.COLOR_WIDGET_FOREGROUND));
viewComposite.setLayoutData(Utils.getFilledFormData());
GridLayout gridLayout = new GridLayout();
gridLayout.horizontalSpacing = gridLayout.verticalSpacing = gridLayout.marginHeight = gridLayout.marginWidth = 0;
viewComposite.setLayout(gridLayout);
view.initialize(viewComposite);
return null;
}
use of com.biglybt.activities.ActivitiesEntry in project BiglyBT by BiglySoftware.
the class SBC_ActivityTableView method getCurrentlySelectedContent.
public ISelectedContent[] getCurrentlySelectedContent() {
if (view == null) {
return null;
}
List listContent = new ArrayList();
Object[] selectedDataSources = view.getSelectedDataSources(true);
for (int i = 0; i < selectedDataSources.length; i++) {
ActivitiesEntry ds = (ActivitiesEntry) selectedDataSources[i];
if (ds != null) {
ISelectedContent currentContent;
try {
currentContent = ds.createSelectedContentObject();
if (currentContent != null) {
listContent.add(currentContent);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return (ISelectedContent[]) listContent.toArray(new ISelectedContent[listContent.size()]);
}
use of com.biglybt.activities.ActivitiesEntry in project BiglyBT by BiglySoftware.
the class SBC_ActivityTableView method setupSidebarEntry.
public static void setupSidebarEntry(final MultipleDocumentInterface mdi) {
// Put TitleInfo in another class
final ViewTitleInfo titleInfoActivityView = new ViewTitleInfo() {
boolean had_unviewed = false;
@Override
public Object getTitleInfoProperty(int propertyID) {
if (propertyID == TITLE_INDICATOR_TEXT) {
int num_unread = 0;
int num_unviewed = 0;
List<ActivitiesEntry> allEntries = ActivitiesManager.getAllEntries();
for (ActivitiesEntry entry : allEntries) {
if (!entry.isRead()) {
num_unread++;
}
if (!entry.getViewed()) {
num_unviewed++;
}
}
if (num_unread == 0) {
num_unviewed = 0;
}
boolean has_unviewed = num_unviewed > 0;
if (has_unviewed != had_unviewed) {
if (has_unviewed) {
MdiEntry parent = mdi.getEntry(MultipleDocumentInterface.SIDEBAR_HEADER_VUZE);
if (parent != null && !parent.isExpanded()) {
parent.setExpanded(true);
}
}
had_unviewed = has_unviewed;
}
if (num_unviewed > 0) {
return (String.valueOf(num_unviewed) + (num_unread == 0 ? "" : (":" + num_unread)));
} else if (num_unread > 0) {
return (String.valueOf(num_unread));
}
return null;
} else if (propertyID == TITLE_IMAGEID) {
return "image.sidebar.activity";
} else if (propertyID == TITLE_INDICATOR_COLOR) {
boolean has_unread = false;
boolean has_unviewed = false;
List<ActivitiesEntry> allEntries = ActivitiesManager.getAllEntries();
for (ActivitiesEntry entry : allEntries) {
if (!entry.isRead()) {
has_unread = true;
}
if (!entry.getViewed()) {
has_unviewed = true;
}
}
if (has_unread && has_unviewed) {
return (COLOR_UNVIEWED_ENTRIES);
}
}
return null;
}
};
activitiesListener = new ActivitiesListener() {
@Override
public void vuzeNewsEntryChanged(ActivitiesEntry entry) {
refresh();
}
@Override
public void vuzeNewsEntriesRemoved(ActivitiesEntry[] entries) {
refresh();
}
@Override
public void vuzeNewsEntriesAdded(ActivitiesEntry[] entries) {
refresh();
}
private void refresh() {
ViewTitleInfoManager.refreshTitleInfo(titleInfoActivityView);
if (mdi_entry != null) {
mdi_entry.redraw();
}
}
};
ActivitiesManager.addListener(activitiesListener);
MdiEntryCreationListener creationListener = new MdiEntryCreationListener() {
@Override
public MdiEntry createMDiEntry(String id) {
mdi_entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_VUZE, MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES, "activity", "{sidebar." + MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES + "}", titleInfoActivityView, null, false, null);
return (mdi_entry);
}
};
mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES, creationListener);
mdi.registerEntry("activities", creationListener);
PluginInterface pi = PluginInitializer.getDefaultInterface();
UIManager uim = pi.getUIManager();
MenuManager menuManager = uim.getMenuManager();
final MenuItem menuItem = menuManager.addMenuItem("sidebar." + MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES, "v3.activity.button.readall");
menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menuItem.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
List<ActivitiesEntry> allEntries = ActivitiesManager.getAllEntries();
for (ActivitiesEntry entry : allEntries) {
entry.setRead(true);
}
}
});
mdi.addListener(new MdiListener() {
@Override
public void mdiEntrySelected(MdiEntry newEntry, MdiEntry oldEntry) {
}
@Override
public void mdiDisposed(MultipleDocumentInterface mdi) {
if (activitiesListener != null) {
ActivitiesManager.removeListener(activitiesListener);
activitiesListener = null;
}
menuItem.remove();
}
});
}
Aggregations