Search in sources :

Example 16 with ActivitiesEntry

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);
    }
}
Also used : ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) Rectangle(org.eclipse.swt.graphics.Rectangle) ImageDownloaderListener(com.biglybt.ui.swt.imageloader.ImageLoader.ImageDownloaderListener) Image(org.eclipse.swt.graphics.Image) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 17 with ActivitiesEntry

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);
    }
}
Also used : ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) Date(java.util.Date)

Example 18 with ActivitiesEntry

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;
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) SWTSkinObjectListener(com.biglybt.ui.swt.skin.SWTSkinObjectListener) KeyEvent(org.eclipse.swt.events.KeyEvent) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) GridLayout(org.eclipse.swt.layout.GridLayout) ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) SWTSkinObjectContainer(com.biglybt.ui.swt.skin.SWTSkinObjectContainer) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) KeyListener(org.eclipse.swt.events.KeyListener)

Example 19 with ActivitiesEntry

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()]);
}
Also used : ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject)

Example 20 with ActivitiesEntry

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();
        }
    });
}
Also used : ActivitiesListener(com.biglybt.activities.ActivitiesListener) MdiListener(com.biglybt.ui.mdi.MdiListener) MdiEntryCreationListener(com.biglybt.ui.mdi.MdiEntryCreationListener) PluginInterface(com.biglybt.pif.PluginInterface) UIManager(com.biglybt.pif.ui.UIManager) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface) ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) MdiEntry(com.biglybt.ui.mdi.MdiEntry) MenuManager(com.biglybt.pif.ui.menus.MenuManager) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) ArrayList(java.util.ArrayList) List(java.util.List) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)

Aggregations

ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)21 GCStringPrinter (com.biglybt.ui.swt.shells.GCStringPrinter)4 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)4 List (java.util.List)4 ISelectedContent (com.biglybt.ui.selectedcontent.ISelectedContent)3 URLInfo (com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo)3 Image (org.eclipse.swt.graphics.Image)3 DownloadManager (com.biglybt.core.download.DownloadManager)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 DiskManagerFileInfo (com.biglybt.pif.disk.DiskManagerFileInfo)2 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)2 ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)2 TableCellSWT (com.biglybt.ui.swt.views.table.TableCellSWT)2 ArrayList (java.util.ArrayList)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 ActivitiesListener (com.biglybt.activities.ActivitiesListener)1 TranscodeFile (com.biglybt.core.devices.TranscodeFile)1 TranscodeJob (com.biglybt.core.devices.TranscodeJob)1 GlobalManager (com.biglybt.core.global.GlobalManager)1 PlatformMessage (com.biglybt.core.messenger.PlatformMessage)1