Search in sources :

Example 21 with UIFunctionsSWT

use of com.biglybt.ui.swt.UIFunctionsSWT in project BiglyBT by BiglySoftware.

the class DebugMenuHelper method createDebugMenuItem.

/**
 * Creates the Debug menu and its children
 * NOTE: This is a development only menu and so it's not modularized into separate menu items
 * because this menu is always rendered in its entirety
 * @param menu
 * @param mainWindow
 * @return
 */
public static Menu createDebugMenuItem(final Menu menu) {
    MenuItem item;
    final UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
    if (null == uiFunctions) {
        throw new IllegalStateException("UIFunctionsManagerSWT.getUIFunctionsSWT() is returning null");
    }
    item = new MenuItem(menu, SWT.CASCADE);
    Messages.setLanguageText(item, "MainWindow.menu.debug");
    Menu menuDebug = new Menu(menu.getParent(), SWT.DROP_DOWN);
    item.setMenu(menuDebug);
    item = new MenuItem(menuDebug, SWT.CASCADE);
    item.setText("ScreenSize");
    Menu menuSS = new Menu(menu.getParent(), SWT.DROP_DOWN);
    item.setMenu(menuSS);
    item = new MenuItem(menuSS, SWT.NONE);
    item.setText("640x400");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            uiFunctions.getMainShell().setSize(640, 400);
        }
    });
    item = new MenuItem(menuSS, SWT.NONE);
    item.setText("800x560");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            uiFunctions.getMainShell().setSize(850, 560);
        }
    });
    item = new MenuItem(menuSS, SWT.NONE);
    item.setText("1024x700");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            uiFunctions.getMainShell().setSize(1024, 700);
        }
    });
    item = new MenuItem(menuSS, SWT.NONE);
    item.setText("1024x768");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            uiFunctions.getMainShell().setSize(1024, 768);
        }
    });
    item = new MenuItem(menuSS, SWT.NONE);
    item.setText("1152x784");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            uiFunctions.getMainShell().setSize(1152, 784);
        }
    });
    item = new MenuItem(menuSS, SWT.NONE);
    item.setText("1280x720");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            uiFunctions.getMainShell().setSize(1280, 720);
        }
    });
    item = new MenuItem(menuSS, SWT.NONE);
    item.setText("1280x1024");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            uiFunctions.getMainShell().setSize(1280, 1024);
        }
    });
    item = new MenuItem(menuSS, SWT.NONE);
    item.setText("1440x820");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            uiFunctions.getMainShell().setSize(1440, 820);
        }
    });
    item = new MenuItem(menuSS, SWT.NONE);
    item.setText("1600x970");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            uiFunctions.getMainShell().setSize(1600, 970);
        }
    });
    item = new MenuItem(menuSS, SWT.NONE);
    item.setText("1920x1200");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            uiFunctions.getMainShell().setSize(1920, 1200);
        }
    });
    item = new MenuItem(menuSS, SWT.NONE);
    item.setText("2560x1520");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            uiFunctions.getMainShell().setSize(2560, 1520);
        }
    });
    item = new MenuItem(menuDebug, SWT.NONE);
    item.setText("Reload messagebundle");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            MessageText.loadBundle(true);
            DisplayFormatters.setUnits();
            DisplayFormatters.loadMessages();
            UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
            if (uiFunctions != null) {
                uiFunctions.refreshLanguage();
            }
        }
    });
    item = new MenuItem(menuDebug, SWT.CHECK);
    item.setText("SR ChangeFlagChecker Paused");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            StartStopRulesDefaultPlugin.pauseChangeFlagChecker = !StartStopRulesDefaultPlugin.pauseChangeFlagChecker;
            ((MenuItem) e.widget).setSelection(StartStopRulesDefaultPlugin.pauseChangeFlagChecker);
        }
    });
    return menuDebug;
}
Also used : UIFunctions(com.biglybt.ui.UIFunctions) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) Menu(org.eclipse.swt.widgets.Menu)

Example 22 with UIFunctionsSWT

use of com.biglybt.ui.swt.UIFunctionsSWT in project BiglyBT by BiglySoftware.

the class PeersViewBase method initYourTableView.

protected TableViewSWT<PEPeer> initYourTableView(String table_id, boolean enable_tabs) {
    if (table_id == TableManager.TABLE_TORRENT_PEERS) {
        tv = TableViewFactory.createTableViewSWT(Peer.class, TableManager.TABLE_TORRENT_PEERS, getPropertiesPrefix(), basicItems, "pieces", SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
    } else {
        TableColumnCore[] items = PeersView.getBasicColumnItems(TableManager.TABLE_ALL_PEERS);
        TableColumnCore[] basicItems = new TableColumnCore[items.length + 1];
        System.arraycopy(items, 0, basicItems, 0, items.length);
        basicItems[items.length] = new DownloadNameItem(TableManager.TABLE_ALL_PEERS);
        TableColumnManager tcManager = TableColumnManager.getInstance();
        tcManager.setDefaultColumnNames(TableManager.TABLE_ALL_PEERS, basicItems);
        tv = TableViewFactory.createTableViewSWT(Peer.class, TableManager.TABLE_ALL_PEERS, getPropertiesPrefix(), basicItems, "connected_time", SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
    }
    tv.setRowDefaultHeightEM(1);
    tv.setEnableTabViews(enable_tabs, true, null);
    UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
    if (uiFunctions != null) {
        UISWTInstance pluginUI = uiFunctions.getUISWTInstance();
        registerPluginViews(table_id, pluginUI);
    }
    tv.addLifeCycleListener(this);
    tv.addMenuFillListener(this);
    tv.addSelectionListener(this, false);
    return tv;
}
Also used : Peer(com.biglybt.pif.peers.Peer) PEPeer(com.biglybt.core.peer.PEPeer) DownloadNameItem(com.biglybt.ui.swt.views.tableitems.peers.DownloadNameItem) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) UISWTInstance(com.biglybt.ui.swt.pif.UISWTInstance) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager)

Example 23 with UIFunctionsSWT

use of com.biglybt.ui.swt.UIFunctionsSWT in project BiglyBT by BiglySoftware.

the class PiecesView method initYourTableView.

// @see com.biglybt.ui.swt.views.table.impl.TableViewTab#initYourTableView()
@Override
public TableViewSWT<PEPiece> initYourTableView() {
    tv = TableViewFactory.createTableViewSWT(PEPiece.class, TableManager.TABLE_TORRENT_PIECES, getPropertiesPrefix(), basicItems, basicItems[0].getName(), SWT.SINGLE | SWT.FULL_SELECTION | SWT.VIRTUAL);
    tv.setEnableTabViews(enable_tabs, true, null);
    UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
    if (uiFunctions != null) {
        UISWTInstance pluginUI = uiFunctions.getUISWTInstance();
        registerPluginViews(pluginUI);
    }
    tv.addTableDataSourceChangedListener(this, true);
    tv.addMenuFillListener(this);
    tv.addLifeCycleListener(this);
    tv.addSelectionListener(this, false);
    return tv;
}
Also used : PEPiece(com.biglybt.core.peer.PEPiece) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) UISWTInstance(com.biglybt.ui.swt.pif.UISWTInstance)

Example 24 with UIFunctionsSWT

use of com.biglybt.ui.swt.UIFunctionsSWT in project BiglyBT by BiglySoftware.

the class ConfigSectionBackupRestore method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    ImageLoader imageLoader = ImageLoader.getInstance();
    Image imgOpenFolder = imageLoader.getImage("openFolderButton");
    GridData gridData;
    GridLayout layout;
    final Composite cBR = new Composite(parent, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    cBR.setLayoutData(gridData);
    layout = new GridLayout();
    layout.numColumns = 1;
    cBR.setLayout(layout);
    Label info_label = new Label(cBR, SWT.WRAP);
    Messages.setLanguageText(info_label, "ConfigView.section.br.overview");
    gridData = Utils.getWrappableLabelGridData(1, GridData.HORIZONTAL_ALIGN_FILL);
    info_label.setLayoutData(gridData);
    // wiki link
    final Label linkLabel = new Label(cBR, SWT.NULL);
    linkLabel.setText(MessageText.getString("ConfigView.label.please.visit.here"));
    linkLabel.setData(Constants.URL_WIKI + "w/Backup_And_Restore");
    linkLabel.setCursor(linkLabel.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    linkLabel.setForeground(Colors.blue);
    gridData = Utils.getWrappableLabelGridData(1, 0);
    linkLabel.setLayoutData(gridData);
    linkLabel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent arg0) {
            Utils.launch((String) ((Label) arg0.widget).getData());
        }

        @Override
        public void mouseDown(MouseEvent arg0) {
            Utils.launch((String) ((Label) arg0.widget).getData());
        }
    });
    ClipboardCopy.addCopyToClipMenu(linkLabel);
    final BackupManager backup_manager = BackupManagerFactory.getManager(CoreFactory.getSingleton());
    // backup
    Group gBackup = new Group(cBR, SWT.NULL);
    Messages.setLanguageText(gBackup, "br.backup");
    layout = new GridLayout(2, false);
    gBackup.setLayout(layout);
    gBackup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // info
    Label last_backup_label = new Label(gBackup, SWT.NULL);
    Messages.setLanguageText(last_backup_label, "br.backup.last.time");
    final Label last_backup_time = new Label(gBackup, SWT.NULL);
    Label last_backup_error_label = new Label(gBackup, SWT.NULL);
    Messages.setLanguageText(last_backup_error_label, "br.backup.last.error");
    final Label last_backup_error = new Label(gBackup, SWT.NULL);
    final Runnable stats_updater = new Runnable() {

        @Override
        public void run() {
            long backup_time = backup_manager.getLastBackupTime();
            last_backup_time.setText(backup_time == 0 ? "" : String.valueOf(new Date(backup_time)));
            last_backup_error.setText(backup_manager.getLastBackupError());
        }
    };
    stats_updater.run();
    // manual button
    Label backup_manual_label = new Label(gBackup, SWT.NULL);
    Messages.setLanguageText(backup_manual_label, "br.backup.manual.info");
    Button backup_button = new Button(gBackup, SWT.PUSH);
    Messages.setLanguageText(backup_button, "br.backup");
    backup_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            String def_dir = COConfigurationManager.getStringParameter("br.backup.folder.default");
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
            if (def_dir != null) {
                dialog.setFilterPath(def_dir);
            }
            dialog.setMessage(MessageText.getString("br.backup.folder.info"));
            dialog.setText(MessageText.getString("br.backup.folder.title"));
            String path = dialog.open();
            if (path != null) {
                COConfigurationManager.setParameter("br.backup.folder.default", path);
                runBackup(backup_manager, path, stats_updater);
            }
        }
    });
    final BooleanParameter auto_backup_enable = new BooleanParameter(gBackup, "br.backup.auto.enable", "br.backup.auto.enable");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    auto_backup_enable.setLayoutData(gridData);
    Composite gDefaultDir = new Composite(gBackup, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 3;
    layout.marginHeight = 2;
    gDefaultDir.setLayout(layout);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    gDefaultDir.setLayoutData(gridData);
    Label lblDefaultDir = new Label(gDefaultDir, SWT.NONE);
    Messages.setLanguageText(lblDefaultDir, "ConfigView.section.file.defaultdir.ask");
    lblDefaultDir.setLayoutData(new GridData());
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    final StringParameter pathParameter = new StringParameter(gDefaultDir, "br.backup.auto.dir", "");
    pathParameter.setLayoutData(gridData);
    if (pathParameter.getValue().length() == 0) {
        String def_dir = COConfigurationManager.getStringParameter("br.backup.folder.default");
        pathParameter.setValue(def_dir);
    }
    Button browse = new Button(gDefaultDir, SWT.PUSH);
    browse.setImage(imgOpenFolder);
    imgOpenFolder.setBackground(browse.getBackground());
    browse.setToolTipText(MessageText.getString("ConfigView.button.browse"));
    browse.addListener(SWT.Selection, new Listener() {

        /* (non-Javadoc)
			 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
			 */
        @Override
        public void handleEvent(Event event) {
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
            dialog.setFilterPath(pathParameter.getValue());
            dialog.setMessage(MessageText.getString("br.backup.auto.dir.select"));
            dialog.setText(MessageText.getString("ConfigView.section.file.defaultdir.ask"));
            String path = dialog.open();
            if (path != null) {
                pathParameter.setValue(path);
                COConfigurationManager.setParameter("br.backup.folder.default", path);
            }
        }
    });
    Composite gPeriod = new Composite(gDefaultDir, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 6;
    layout.marginLeft = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.marginTop = 0;
    layout.marginBottom = 0;
    gPeriod.setLayout(layout);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    gPeriod.setLayoutData(gridData);
    Label lbl_backup_days = new Label(gPeriod, SWT.NULL);
    Messages.setLanguageText(lbl_backup_days, "br.backup.auto.everydays");
    IntParameter backup_everydays = new IntParameter(gPeriod, "br.backup.auto.everydays", 0, Integer.MAX_VALUE);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    backup_everydays.setLayoutData(gridData);
    Label lbl_backup_hours = new Label(gPeriod, SWT.NULL);
    Messages.setLanguageText(lbl_backup_hours, "br.backup.auto.everyhours");
    IntParameter backup_everyhours = new IntParameter(gPeriod, "br.backup.auto.everyhours", 1, Integer.MAX_VALUE);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    backup_everyhours.setLayoutData(gridData);
    // for whatever reason if you set enable synchronously it gets reset :(
    Utils.execSWTThreadLater(1, new Runnable() {

        public void run() {
            backup_everyhours.setEnabled(backup_everydays.getValue() == 0);
        }
    });
    backup_everydays.addChangeListener(new ParameterChangeAdapter() {

        @Override
        public void parameterChanged(Parameter p, boolean caused_internally) {
            backup_everyhours.setEnabled(backup_everydays.getValue() == 0);
        }
    });
    Label lbl_backup_retain = new Label(gDefaultDir, SWT.NULL);
    Messages.setLanguageText(lbl_backup_retain, "br.backup.auto.retain");
    IntParameter backup_retain = new IntParameter(gDefaultDir, "br.backup.auto.retain", 1, Integer.MAX_VALUE);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    backup_retain.setLayoutData(gridData);
    BooleanParameter chkNotify = new BooleanParameter(gDefaultDir, "br.backup.notify", "br.backup.notify");
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    chkNotify.setLayoutData(gridData);
    Label backup_auto_label = new Label(gDefaultDir, SWT.NULL);
    Messages.setLanguageText(backup_auto_label, "br.backup.auto.now");
    Button backup_auto_button = new Button(gDefaultDir, SWT.PUSH);
    Messages.setLanguageText(backup_auto_button, "br.test");
    backup_auto_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            runBackup(backup_manager, null, stats_updater);
        }
    });
    auto_backup_enable.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(gDefaultDir));
    // restore
    Group gRestore = new Group(cBR, SWT.NULL);
    Messages.setLanguageText(gRestore, "br.restore");
    layout = new GridLayout(2, false);
    gRestore.setLayout(layout);
    gRestore.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Label restore_label = new Label(gRestore, SWT.NULL);
    Messages.setLanguageText(restore_label, "br.restore.info");
    Button restore_button = new Button(gRestore, SWT.PUSH);
    Messages.setLanguageText(restore_button, "br.restore");
    restore_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            String def_dir = COConfigurationManager.getStringParameter("br.backup.folder.default");
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
            if (def_dir != null) {
                dialog.setFilterPath(def_dir);
            }
            dialog.setMessage(MessageText.getString("br.restore.folder.info"));
            dialog.setText(MessageText.getString("br.restore.folder.title"));
            final String path = dialog.open();
            if (path != null) {
                MessageBoxShell mb = new MessageBoxShell(SWT.ICON_WARNING | SWT.OK | SWT.CANCEL, MessageText.getString("br.restore.warning.title"), MessageText.getString("br.restore.warning.info"));
                mb.setDefaultButtonUsingStyle(SWT.CANCEL);
                mb.setParent(parent.getShell());
                mb.open(new UserPrompterResultListener() {

                    @Override
                    public void prompterClosed(int returnVal) {
                        if (returnVal != SWT.OK) {
                            return;
                        }
                        final TextViewerWindow viewer = new TextViewerWindow(MessageText.getString("br.backup.progress"), null, "", true, true);
                        viewer.setEditable(false);
                        viewer.setOKEnabled(false);
                        backup_manager.restore(new File(path), new BackupManager.BackupListener() {

                            @Override
                            public boolean reportProgress(String str) {
                                return (append(str, false));
                            }

                            @Override
                            public void reportComplete() {
                                append("Restore Complete!", true);
                                Utils.execSWTThread(new AERunnable() {

                                    @Override
                                    public void runSupport() {
                                        MessageBoxShell mb = new MessageBoxShell(SWT.ICON_INFORMATION | SWT.OK, MessageText.getString("ConfigView.section.security.restart.title"), MessageText.getString("ConfigView.section.security.restart.msg"));
                                        mb.setParent(parent.getShell());
                                        mb.open(new UserPrompterResultListener() {

                                            @Override
                                            public void prompterClosed(int returnVal) {
                                                UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
                                                if (uiFunctions != null) {
                                                    uiFunctions.dispose(true, false);
                                                }
                                            }
                                        });
                                    }
                                });
                            }

                            @Override
                            public void reportError(Throwable error) {
                                append("Restore Failed: " + Debug.getNestedExceptionMessage(error), true);
                            }

                            private boolean append(final String str, final boolean complete) {
                                if (viewer.isDisposed()) {
                                    return (false);
                                }
                                Utils.execSWTThread(new AERunnable() {

                                    @Override
                                    public void runSupport() {
                                        if (str.endsWith("...")) {
                                            viewer.append(str);
                                        } else {
                                            viewer.append(str + "\r\n");
                                        }
                                        if (complete) {
                                            viewer.setOKEnabled(true);
                                        }
                                    }
                                });
                                return (true);
                            }
                        });
                        viewer.goModal();
                    }
                });
            }
        }
    });
    return (cBR);
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) ParameterChangeListener(com.biglybt.ui.swt.config.ParameterChangeListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) TextViewerWindow(com.biglybt.ui.swt.TextViewerWindow) StringParameter(com.biglybt.ui.swt.config.StringParameter) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) ParameterChangeAdapter(com.biglybt.ui.swt.config.ParameterChangeAdapter) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) BackupManager(com.biglybt.core.backup.BackupManager) BooleanParameter(com.biglybt.ui.swt.config.BooleanParameter) Date(java.util.Date) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) AERunnable(com.biglybt.core.util.AERunnable) GridData(org.eclipse.swt.layout.GridData) MouseEvent(org.eclipse.swt.events.MouseEvent) BooleanParameter(com.biglybt.ui.swt.config.BooleanParameter) StringParameter(com.biglybt.ui.swt.config.StringParameter) IntParameter(com.biglybt.ui.swt.config.IntParameter) Parameter(com.biglybt.ui.swt.config.Parameter) ChangeSelectionActionPerformer(com.biglybt.ui.swt.config.ChangeSelectionActionPerformer) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) File(java.io.File) IntParameter(com.biglybt.ui.swt.config.IntParameter)

Example 25 with UIFunctionsSWT

use of com.biglybt.ui.swt.UIFunctionsSWT in project BiglyBT by BiglySoftware.

the class ColumnActivityActions method cellMouseTrigger.

// @see com.biglybt.pif.ui.tables.TableCellMouseListener#cellMouseTrigger(com.biglybt.pif.ui.tables.TableCellMouseEvent)
@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
    ActivitiesEntry entry = (ActivitiesEntry) event.cell.getDataSource();
    String tooltip = null;
    boolean invalidateAndRefresh = false;
    Rectangle bounds = ((TableCellSWT) event.cell).getBounds();
    String text = (String) event.cell.getTableRow().getData("text");
    if (text == null) {
        return;
    }
    GCStringPrinter sp = null;
    GC gc = new GC(Display.getDefault());
    try {
        if (font != null) {
            gc.setFont(font);
        }
        Rectangle drawBounds = getDrawBounds((TableCellSWT) event.cell);
        sp = new GCStringPrinter(gc, text, drawBounds, true, true, SWT.WRAP | SWT.CENTER);
        sp.calculateMetrics();
    } catch (Exception e) {
        Debug.out(e);
    } finally {
        gc.dispose();
    }
    if (sp != null) {
        URLInfo hitUrl = sp.getHitUrl(event.x + bounds.x, event.y + bounds.y);
        int newCursor;
        if (hitUrl != null) {
            if (event.eventType == TableCellMouseEvent.EVENT_MOUSEUP) {
                if (hitUrl.url.equals("download")) {
                    String referal = null;
                    Object ds = event.cell.getDataSource();
                    if (ds instanceof ActivitiesEntry) {
                        referal = DLReferals.DL_REFERAL_DASHACTIVITY + "-" + ((ActivitiesEntry) ds).getTypeID();
                    }
                    TorrentListViewsUtils.downloadDataSource(ds, false, referal);
                } else if (hitUrl.url.equals("play")) {
                    String referal = null;
                    Object ds = event.cell.getDataSource();
                    if (ds instanceof ActivitiesEntry) {
                        referal = DLReferals.DL_REFERAL_PLAYDASHACTIVITY + "-" + ((ActivitiesEntry) ds).getTypeID();
                    }
                    TorrentListViewsUtils.playOrStreamDataSource(ds, referal, false, true);
                } else if (hitUrl.url.equals("launch")) {
                    // run via play or stream so we get the security warning
                    Object ds = event.cell.getDataSource();
                    TorrentListViewsUtils.playOrStreamDataSource(ds, DLReferals.DL_REFERAL_LAUNCH, false, true);
                } else if (hitUrl.url.startsWith("action:")) {
                    entry.invokeCallback(hitUrl.url.substring(7));
                } else if (!UrlFilter.getInstance().urlCanRPC(hitUrl.url)) {
                    Utils.launch(hitUrl.url);
                } else {
                    UIFunctionsSWT uif = UIFunctionsManagerSWT.getUIFunctionsSWT();
                    if (uif != null) {
                        String target = hitUrl.target;
                        if (target == null) {
                            target = SkinConstants.VIEWID_BROWSER_BROWSE;
                        }
                        uif.viewURL(hitUrl.url, target, "column.activity.action");
                        return;
                    }
                }
            }
            Object ds = event.cell.getDataSource();
            newCursor = SWT.CURSOR_HAND;
            if (UrlFilter.getInstance().urlCanRPC(hitUrl.url)) {
                tooltip = hitUrl.title;
            } else {
                tooltip = hitUrl.url;
            }
        } else {
            newCursor = SWT.CURSOR_ARROW;
        }
        int oldCursor = ((TableCellSWT) event.cell).getCursorID();
        if (oldCursor != newCursor) {
            invalidateAndRefresh = true;
            ((TableCellSWT) event.cell).setCursorID(newCursor);
        }
    }
    Object o = event.cell.getToolTip();
    if ((o == null) || (o instanceof String)) {
        String oldTooltip = (String) o;
        if (!StringCompareUtils.equals(oldTooltip, tooltip)) {
            invalidateAndRefresh = true;
            event.cell.setToolTip(tooltip);
        }
    }
    if (invalidateAndRefresh) {
        event.cell.invalidate();
        ((TableCellSWT) event.cell).redraw();
    }
}
Also used : GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) URLInfo(com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo)

Aggregations

UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)33 UISWTInstance (com.biglybt.ui.swt.pif.UISWTInstance)10 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)6 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 DownloadManager (com.biglybt.core.download.DownloadManager)3 UIFunctions (com.biglybt.ui.UIFunctions)3 Composite (org.eclipse.swt.widgets.Composite)3 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)2 Core (com.biglybt.core.Core)2 CoreRunningListener (com.biglybt.core.CoreRunningListener)2 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)2 PEPeer (com.biglybt.core.peer.PEPeer)2 AERunnable (com.biglybt.core.util.AERunnable)2 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)2 UIPluginViewToolBarListener (com.biglybt.pif.ui.UIPluginViewToolBarListener)2 TabbedMdiMaximizeListener (com.biglybt.ui.swt.mdi.TabbedMdiMaximizeListener)2 UISWTViewEventListenerWrapper (com.biglybt.ui.swt.pif.UISWTInstance.UISWTViewEventListenerWrapper)2