Search in sources :

Example 61 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class SBC_LibraryTableView method skinObjectShown.

// @see SkinView#skinObjectShown(SWTSkinObject, java.lang.Object)
@Override
public Object skinObjectShown(SWTSkinObject skinObject, Object params) {
    super.skinObjectShown(skinObject, params);
    if (view != null) {
        view.triggerEvent(UISWTViewEvent.TYPE_FOCUSGAINED, null);
    }
    Utils.execSWTThreadLater(0, new AERunnable() {

        @Override
        public void runSupport() {
            updateUI();
        }
    });
    return null;
}
Also used : AERunnable(com.biglybt.core.util.AERunnable)

Example 62 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class SBC_LibraryTableView method skinObjectInitialShow.

@Override
public Object skinObjectInitialShow(SWTSkinObject skinObject, Object params) {
    soParent = skinObject.getParent();
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(final Core core) {
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    if (soParent == null || soParent.isDisposed()) {
                        return;
                    }
                    initShow(core);
                }
            });
        }
    });
    return null;
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) CoreRunningListener(com.biglybt.core.CoreRunningListener) TableRowCore(com.biglybt.ui.common.table.TableRowCore) UISWTViewBuilderCore(com.biglybt.ui.swt.pifimpl.UISWTViewBuilderCore) Core(com.biglybt.core.Core) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore)

Example 63 with AERunnable

use of com.biglybt.core.util.AERunnable 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 64 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class FileInfoView method createFileInfoPanel.

private Composite createFileInfoPanel(Composite parent) {
    GridLayout layout;
    GridData gridData;
    // Peer Info section contains
    // - Peer's Block display
    // - Peer's Datarate
    fileInfoComposite = new Composite(parent, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    fileInfoComposite.setLayout(layout);
    gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    fileInfoComposite.setLayoutData(gridData);
    new Label(fileInfoComposite, SWT.NULL).setLayoutData(new GridData());
    topLabel = new Label(fileInfoComposite, SWT.NULL);
    gridData = new GridData(SWT.FILL, SWT.DEFAULT, false, false);
    topLabel.setLayoutData(gridData);
    sc = new ScrolledComposite(fileInfoComposite, SWT.V_SCROLL);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    layout = new GridLayout();
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    sc.setLayout(layout);
    gridData = new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1);
    sc.setLayoutData(gridData);
    fileInfoCanvas = new Canvas(sc, SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
    gridData = new GridData(GridData.FILL, SWT.DEFAULT, true, false);
    fileInfoCanvas.setLayoutData(gridData);
    fileInfoCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            if (e.width <= 0 || e.height <= 0)
                return;
            try {
                Rectangle bounds = (img == null) ? null : img.getBounds();
                if (bounds == null) {
                    e.gc.fillRectangle(e.x, e.y, e.width, e.height);
                } else {
                    if (e.x + e.width > bounds.width)
                        e.gc.fillRectangle(bounds.width, e.y, e.x + e.width - bounds.width + 1, e.height);
                    if (e.y + e.height > bounds.height)
                        e.gc.fillRectangle(e.x, bounds.height, e.width, e.y + e.height - bounds.height + 1);
                    int width = Math.min(e.width, bounds.width - e.x);
                    int height = Math.min(e.height, bounds.height - e.y);
                    e.gc.drawImage(img, e.x, e.y, width, height, e.x, e.y, width, height);
                }
            } catch (Exception ex) {
            }
        }
    });
    fileInfoCanvas.addMouseTrackListener(new MouseTrackAdapter() {

        @Override
        public void mouseHover(MouseEvent event) {
            showPieceDetails(event.x, event.y);
        }
    });
    Listener doNothingListener = new Listener() {

        @Override
        public void handleEvent(Event event) {
        }
    };
    fileInfoCanvas.addListener(SWT.KeyDown, doNothingListener);
    final Menu menu = new Menu(fileInfoCanvas.getShell(), SWT.POP_UP);
    fileInfoCanvas.setMenu(menu);
    fileInfoCanvas.addListener(SWT.MenuDetect, new Listener() {

        @Override
        public void handleEvent(Event event) {
            Point pt = fileInfoCanvas.toControl(event.x, event.y);
            int piece_number = getPieceNumber(pt.x, pt.y);
            menu.setData("pieceNumber", piece_number);
        }
    });
    MenuBuildUtils.addMaintenanceListenerForMenu(menu, new MenuBuildUtils.MenuBuilder() {

        @Override
        public void buildMenu(Menu menu, MenuEvent event) {
            Integer pn = (Integer) menu.getData("pieceNumber");
            if (pn != null && pn != -1) {
                DownloadManager download_manager = file.getDownloadManager();
                if (download_manager == null) {
                    return;
                }
                DiskManager disk_manager = download_manager.getDiskManager();
                PEPeerManager peer_manager = download_manager.getPeerManager();
                if (disk_manager == null || peer_manager == null) {
                    return;
                }
                final PiecePicker picker = peer_manager.getPiecePicker();
                DiskManagerPiece[] dm_pieces = disk_manager.getPieces();
                PEPiece[] pe_pieces = peer_manager.getPieces();
                final int piece_number = pn;
                final DiskManagerPiece dm_piece = dm_pieces[piece_number];
                final PEPiece pe_piece = pe_pieces[piece_number];
                final MenuItem force_piece = new MenuItem(menu, SWT.CHECK);
                Messages.setLanguageText(force_piece, "label.force.piece");
                boolean done = dm_piece.isDone();
                force_piece.setEnabled(!done);
                if (!done) {
                    force_piece.setSelection(picker.isForcePiece(piece_number));
                    force_piece.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            picker.setForcePiece(piece_number, force_piece.getSelection());
                        }
                    });
                }
                final MenuItem reset_piece = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(reset_piece, "label.reset.piece");
                boolean can_reset = dm_piece.isDone() || dm_piece.getNbWritten() > 0;
                reset_piece.setEnabled(can_reset);
                reset_piece.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        if (pe_piece != null) {
                            pe_piece.reset();
                        } else {
                            dm_piece.reset();
                        }
                    }
                });
            }
        }
    });
    fileInfoCanvas.addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event e) {
            if (refreshInfoCanvasQueued) {
                return;
            }
            refreshInfoCanvasQueued = true;
            // wrap in asyncexec because sc.setMinWidth (called later) doesn't work
            // too well inside a resize (the canvas won't size isn't always updated)
            Utils.execSWTThreadLater(0, new AERunnable() {

                @Override
                public void runSupport() {
                    if (img != null) {
                        int iOldColCount = img.getBounds().width / BLOCK_SIZE;
                        int iNewColCount = fileInfoCanvas.getClientArea().width / BLOCK_SIZE;
                        if (iOldColCount != iNewColCount)
                            refreshInfoCanvas();
                    }
                }
            });
        }
    });
    sc.setContent(fileInfoCanvas);
    Legend.createLegendComposite(fileInfoComposite, blockColors, new String[] { "FileView.BlockView.Done", "FileView.BlockView.Skipped", "FileView.BlockView.Active", "FileView.BlockView.Outstanding" }, new GridData(SWT.FILL, SWT.DEFAULT, true, false, 2, 1));
    return fileInfoComposite;
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) UISWTViewCoreEventListener(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener) PiecePicker(com.biglybt.core.peermanager.piecepicker.PiecePicker) DiskManager(com.biglybt.core.disk.DiskManager) DownloadManager(com.biglybt.core.download.DownloadManager) GridLayout(org.eclipse.swt.layout.GridLayout) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) DiskManagerPiece(com.biglybt.core.disk.DiskManagerPiece) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) PEPiece(com.biglybt.core.peer.PEPiece) GridData(org.eclipse.swt.layout.GridData) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) LogEvent(com.biglybt.core.logging.LogEvent) PEPeerManager(com.biglybt.core.peer.PEPeerManager) MenuBuildUtils(com.biglybt.ui.swt.MenuBuildUtils)

Example 65 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class PeerInfoView method createPeerInfoPanel.

private Composite createPeerInfoPanel(Composite parent) {
    GridLayout layout;
    GridData gridData;
    // Peer Info section contains
    // - Peer's Block display
    // - Peer's Datarate
    peerInfoComposite = new Composite(parent, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    peerInfoComposite.setLayout(layout);
    gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    peerInfoComposite.setLayoutData(gridData);
    imageLabel = new Label(peerInfoComposite, SWT.NULL);
    gridData = new GridData();
    if (ImageRepository.hasCountryFlags(false) || countryLocator != null)
        gridData.widthHint = 28;
    imageLabel.setLayoutData(gridData);
    topLabel = new Label(peerInfoComposite, SWT.NULL);
    gridData = new GridData(SWT.FILL, SWT.DEFAULT, false, false);
    topLabel.setLayoutData(gridData);
    sc = new ScrolledComposite(peerInfoComposite, SWT.V_SCROLL);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    layout = new GridLayout();
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    sc.setLayout(layout);
    gridData = new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1);
    sc.setLayoutData(gridData);
    sc.getVerticalBar().setIncrement(BLOCK_SIZE);
    peerInfoCanvas = new Canvas(sc, SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
    gridData = new GridData(GridData.FILL, SWT.DEFAULT, true, false);
    peerInfoCanvas.setLayoutData(gridData);
    peerInfoCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            if (e.width <= 0 || e.height <= 0)
                return;
            try {
                Rectangle bounds = (img == null) ? null : img.getBounds();
                if (bounds == null) {
                    e.gc.fillRectangle(e.x, e.y, e.width, e.height);
                } else {
                    if (e.x + e.width > bounds.width)
                        e.gc.fillRectangle(bounds.width, e.y, e.x + e.width - bounds.width + 1, e.height);
                    if (e.y + e.height > bounds.height)
                        e.gc.fillRectangle(e.x, bounds.height, e.width, e.y + e.height - bounds.height + 1);
                    int width = Math.min(e.width, bounds.width - e.x);
                    int height = Math.min(e.height, bounds.height - e.y);
                    e.gc.drawImage(img, e.x, e.y, width, height, e.x, e.y, width, height);
                }
            } catch (Exception ex) {
            }
        }
    });
    Listener doNothingListener = new Listener() {

        @Override
        public void handleEvent(Event event) {
        }
    };
    peerInfoCanvas.addListener(SWT.KeyDown, doNothingListener);
    peerInfoCanvas.addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event e) {
            if (refreshInfoCanvasQueued || !peerInfoCanvas.isVisible()) {
                return;
            }
            // wrap in asyncexec because sc.setMinWidth (called later) doesn't work
            // too well inside a resize (the canvas won't size isn't always updated)
            Utils.execSWTThreadLater(100, new AERunnable() {

                @Override
                public void runSupport() {
                    if (refreshInfoCanvasQueued) {
                        return;
                    }
                    refreshInfoCanvasQueued = true;
                    if (img != null) {
                        int iOldColCount = img.getBounds().width / BLOCK_SIZE;
                        int iNewColCount = peerInfoCanvas.getClientArea().width / BLOCK_SIZE;
                        if (iOldColCount != iNewColCount)
                            refreshInfoCanvas();
                    }
                }
            });
        }
    });
    sc.setContent(peerInfoCanvas);
    Legend.createLegendComposite(peerInfoComposite, blockColors, new String[] { "PeersView.BlockView.Avail.Have", "PeersView.BlockView.Avail.NoHave", "PeersView.BlockView.NoAvail.Have", "PeersView.BlockView.NoAvail.NoHave", "PeersView.BlockView.Transfer", "PeersView.BlockView.NextRequest", "PeersView.BlockView.AvailCount" }, new GridData(SWT.FILL, SWT.DEFAULT, true, false, 2, 1));
    font = FontUtils.getFontPercentOf(peerInfoCanvas.getFont(), 0.7f);
    return peerInfoComposite;
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) UISWTViewCoreEventListener(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) PaintListener(org.eclipse.swt.events.PaintListener) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) LogEvent(com.biglybt.core.logging.LogEvent)

Aggregations

AERunnable (com.biglybt.core.util.AERunnable)92 GridLayout (org.eclipse.swt.layout.GridLayout)12 DownloadManager (com.biglybt.core.download.DownloadManager)11 Image (org.eclipse.swt.graphics.Image)10 ArrayList (java.util.ArrayList)9 GridData (org.eclipse.swt.layout.GridData)9 CoreRunningListener (com.biglybt.core.CoreRunningListener)7 File (java.io.File)7 PEPeer (com.biglybt.core.peer.PEPeer)6 Shell (org.eclipse.swt.widgets.Shell)6 Core (com.biglybt.core.Core)5 ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)5 Point (org.eclipse.swt.graphics.Point)5 PEPeerManager (com.biglybt.core.peer.PEPeerManager)4 Subscription (com.biglybt.core.subs.Subscription)3 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)3 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)3 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)3 MouseAdapter (org.eclipse.swt.events.MouseAdapter)3 MouseEvent (org.eclipse.swt.events.MouseEvent)3