Search in sources :

Example 1 with ChangeSelectionActionPerformer

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

the class TorrentOptionsView method initialize.

private void initialize(Composite composite) {
    this.parent = composite;
    GridLayout layout;
    // I don't want to waste my time :) [tux]
    if (panel != null && !panel.isDisposed()) {
        Utils.disposeComposite(panel, false);
    } else {
        panel = new Composite(composite, SWT.NULL);
        layout = new GridLayout();
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 1;
        panel.setLayout(layout);
        Layout parentLayout = parent.getLayout();
        if (parentLayout instanceof FormLayout) {
            Utils.setLayoutData(panel, Utils.getFilledFormData());
        } else {
            Utils.setLayoutData(panel, new GridData(GridData.FILL_BOTH));
        }
    }
    if (managers == null) {
        return;
    }
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    // header
    Composite cHeader = new Composite(panel, SWT.BORDER);
    GridLayout configLayout = new GridLayout();
    configLayout.marginHeight = 3;
    configLayout.marginWidth = 0;
    cHeader.setLayout(configLayout);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
    Utils.setLayoutData(cHeader, gridData);
    Display d = panel.getDisplay();
    cHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
    cHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
    Label lHeader = new Label(cHeader, SWT.NULL);
    lHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
    lHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
    FontData[] fontData = lHeader.getFont().getFontData();
    fontData[0].setStyle(SWT.BOLD);
    int fontHeight = (int) (fontData[0].getHeight() * 1.2);
    fontData[0].setHeight(fontHeight);
    headerFont = new Font(d, fontData);
    lHeader.setFont(headerFont);
    if (managers.length == 1) {
        if (managers[0].getDownloadManager() == null) {
            lHeader.setText(" " + managers[0].getName().replaceAll("&", "&&"));
        } else {
            lHeader.setText(" " + MessageText.getString("authenticator.torrent") + " : " + managers[0].getName().replaceAll("&", "&&"));
        }
    } else {
        String str = "";
        for (int i = 0; i < Math.min(3, managers.length); i++) {
            str += (i == 0 ? "" : ", ") + managers[i].getName().replaceAll("&", "&&");
        }
        if (managers.length > 3) {
            str += "...";
        }
        lHeader.setText(" " + managers.length + " " + MessageText.getString("ConfigView.section.torrents") + " : " + str);
    }
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
    Utils.setLayoutData(lHeader, gridData);
    Group gTorrentOptions = new Group(panel, SWT.NULL);
    Messages.setLanguageText(gTorrentOptions, "ConfigView.section.transfer");
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    Utils.setLayoutData(gTorrentOptions, gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    gTorrentOptions.setLayout(layout);
    // Disabled for release. Need to convert from user-specified units to
    // KB/s before restoring the following line
    // String k_unit = DisplayFormatters.getRateUnit(DisplayFormatters.UNIT_KB).trim()
    String k_unit = DisplayFormatters.getRateUnitBase10(DisplayFormatters.UNIT_KB).trim();
    // max upload speed
    Label label = new Label(gTorrentOptions, SWT.NULL);
    gridData = new GridData();
    Utils.setLayoutData(label, gridData);
    label.setText(k_unit + " " + MessageText.getString("GeneralView.label.maxuploadspeed.tooltip"));
    GenericIntParameter max_upload = new GenericIntParameter(adhoc_param_adapter, gTorrentOptions, MAX_UPLOAD);
    adhoc_parameters.put(MAX_UPLOAD, max_upload);
    gridData = new GridData();
    max_upload.setLayoutData(gridData);
    if (userMode > 0) {
        // max upload when busy
        label = new Label(gTorrentOptions, SWT.NULL);
        gridData = new GridData();
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "TorrentOptionsView.param.max.uploads.when.busy");
        GenericIntParameter max_upload_when_busy = new GenericIntParameter(ds_param_adapter, gTorrentOptions, DownloadManagerState.PARAM_MAX_UPLOAD_WHEN_BUSY);
        ds_parameters.put(DownloadManagerState.PARAM_MAX_UPLOAD_WHEN_BUSY, max_upload_when_busy);
        gridData = new GridData();
        max_upload_when_busy.setLayoutData(gridData);
    }
    // max download speed
    label = new Label(gTorrentOptions, SWT.NULL);
    gridData = new GridData();
    Utils.setLayoutData(label, gridData);
    label.setText(k_unit + " " + MessageText.getString("GeneralView.label.maxdownloadspeed.tooltip"));
    GenericIntParameter max_download = new GenericIntParameter(adhoc_param_adapter, gTorrentOptions, MAX_DOWNLOAD);
    adhoc_parameters.put(MAX_DOWNLOAD, max_download);
    gridData = new GridData();
    max_download.setLayoutData(gridData);
    if (userMode > 0) {
        label = new Label(gTorrentOptions, SWT.NULL);
        gridData = new GridData();
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "TorrentOptionsView.param.max.uploads");
        GenericIntParameter max_uploads = new GenericIntParameter(ds_param_adapter, gTorrentOptions, DownloadManagerState.PARAM_MAX_UPLOADS);
        ds_parameters.put(DownloadManagerState.PARAM_MAX_UPLOADS, max_uploads);
        max_uploads.setMinimumValue(2);
        gridData = new GridData();
        max_uploads.setLayoutData(gridData);
        // max uploads when seeding enabled
        final Composite cMaxUploadsOptionsArea = new Composite(gTorrentOptions, SWT.NULL);
        layout = new GridLayout();
        layout.numColumns = 3;
        layout.marginWidth = 0;
        layout.marginHeight = 0;
        cMaxUploadsOptionsArea.setLayout(layout);
        gridData = new GridData();
        gridData.horizontalIndent = 15;
        gridData.horizontalSpan = 2;
        Utils.setLayoutData(cMaxUploadsOptionsArea, gridData);
        label = new Label(cMaxUploadsOptionsArea, SWT.NULL);
        ImageLoader.getInstance().setLabelImage(label, "subitem");
        gridData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
        Utils.setLayoutData(label, gridData);
        gridData = new GridData();
        GenericBooleanParameter max_uploads_when_seeding_enabled = new GenericBooleanParameter(ds_param_adapter, cMaxUploadsOptionsArea, DownloadManagerState.PARAM_MAX_UPLOADS_WHEN_SEEDING_ENABLED, false, "TorrentOptionsView.param.alternative.value.enable");
        ds_parameters.put(DownloadManagerState.PARAM_MAX_UPLOADS_WHEN_SEEDING_ENABLED, max_uploads_when_seeding_enabled);
        max_uploads_when_seeding_enabled.setLayoutData(gridData);
        GenericIntParameter max_uploads_when_seeding = new GenericIntParameter(ds_param_adapter, cMaxUploadsOptionsArea, DownloadManagerState.PARAM_MAX_UPLOADS_WHEN_SEEDING);
        ds_parameters.put(DownloadManagerState.PARAM_MAX_UPLOADS_WHEN_SEEDING, max_uploads_when_seeding);
        gridData = new GridData();
        max_uploads_when_seeding.setMinimumValue(2);
        max_uploads_when_seeding.setLayoutData(gridData);
        max_uploads_when_seeding_enabled.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(max_uploads_when_seeding.getControl()));
        // max peers
        label = new Label(gTorrentOptions, SWT.NULL);
        gridData = new GridData();
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "TorrentOptionsView.param.max.peers");
        GenericIntParameter max_peers = new GenericIntParameter(ds_param_adapter, gTorrentOptions, DownloadManagerState.PARAM_MAX_PEERS);
        ds_parameters.put(DownloadManagerState.PARAM_MAX_PEERS, max_peers);
        gridData = new GridData();
        max_peers.setLayoutData(gridData);
        // max peers when seeding
        final Composite cMaxPeersOptionsArea = new Composite(gTorrentOptions, SWT.NULL);
        layout = new GridLayout();
        layout.numColumns = 3;
        layout.marginWidth = 0;
        layout.marginHeight = 0;
        cMaxPeersOptionsArea.setLayout(layout);
        gridData = new GridData();
        gridData.horizontalIndent = 15;
        gridData.horizontalSpan = 2;
        Utils.setLayoutData(cMaxPeersOptionsArea, gridData);
        label = new Label(cMaxPeersOptionsArea, SWT.NULL);
        ImageLoader.getInstance().setLabelImage(label, "subitem");
        gridData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
        Utils.setLayoutData(label, gridData);
        gridData = new GridData();
        GenericBooleanParameter max_peers_when_seeding_enabled = new GenericBooleanParameter(ds_param_adapter, cMaxPeersOptionsArea, DownloadManagerState.PARAM_MAX_PEERS_WHEN_SEEDING_ENABLED, false, "TorrentOptionsView.param.alternative.value.enable");
        ds_parameters.put(DownloadManagerState.PARAM_MAX_PEERS_WHEN_SEEDING_ENABLED, max_peers_when_seeding_enabled);
        max_peers_when_seeding_enabled.setLayoutData(gridData);
        GenericIntParameter max_peers_when_seeding = new GenericIntParameter(ds_param_adapter, cMaxPeersOptionsArea, DownloadManagerState.PARAM_MAX_PEERS_WHEN_SEEDING);
        ds_parameters.put(DownloadManagerState.PARAM_MAX_PEERS_WHEN_SEEDING, max_peers_when_seeding);
        gridData = new GridData();
        max_peers_when_seeding.setLayoutData(gridData);
        max_peers_when_seeding_enabled.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(max_peers_when_seeding.getControl()));
        // max seeds
        label = new Label(gTorrentOptions, SWT.NULL);
        gridData = new GridData();
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "TorrentOptionsView.param.max.seeds");
        GenericIntParameter max_seeds = new GenericIntParameter(ds_param_adapter, gTorrentOptions, DownloadManagerState.PARAM_MAX_SEEDS);
        ds_parameters.put(DownloadManagerState.PARAM_MAX_SEEDS, max_seeds);
        gridData = new GridData();
        max_seeds.setLayoutData(gridData);
    }
    if (userMode > 0) {
        label = new Label(gTorrentOptions, SWT.NULL);
        gridData = new GridData();
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "TorrentOptionsView.param.upload.priority");
        gridData = new GridData();
        GenericIntParameter upload_priority_enabled = new GenericIntParameter(ds_param_adapter, gTorrentOptions, DownloadManagerState.PARAM_UPLOAD_PRIORITY, 0, 1);
        ds_parameters.put(DownloadManagerState.PARAM_UPLOAD_PRIORITY, upload_priority_enabled);
        upload_priority_enabled.setLayoutData(gridData);
        // min sr
        label = new Label(gTorrentOptions, SWT.NULL);
        gridData = new GridData();
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "TableColumn.header.min_sr");
        gridData = new GridData();
        gridData.widthHint = 50;
        GenericFloatParameter min_sr = new GenericFloatParameter(ds_param_adapter, gTorrentOptions, DownloadManagerState.PARAM_MIN_SHARE_RATIO, 0, Float.MAX_VALUE, true, 3);
        ds_parameters.put(DownloadManagerState.PARAM_MIN_SHARE_RATIO, min_sr);
        min_sr.setLayoutData(gridData);
        // max sr
        label = new Label(gTorrentOptions, SWT.NULL);
        gridData = new GridData();
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "TableColumn.header.max_sr");
        gridData = new GridData();
        gridData.widthHint = 50;
        GenericFloatParameter max_sr = new GenericFloatParameter(ds_param_adapter, gTorrentOptions, DownloadManagerState.PARAM_MAX_SHARE_RATIO, 0, Float.MAX_VALUE, true, 3);
        ds_parameters.put(DownloadManagerState.PARAM_MAX_SHARE_RATIO, max_sr);
        max_sr.setLayoutData(gridData);
    }
    // reset
    Label reset_label = new Label(gTorrentOptions, SWT.NULL);
    Messages.setLanguageText(reset_label, "TorrentOptionsView.param.reset.to.default");
    Button reset_button = new Button(gTorrentOptions, SWT.PUSH);
    Messages.setLanguageText(reset_button, "TorrentOptionsView.param.reset.button");
    reset_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            setDefaults();
        }
    });
    for (int i = 0; i < managers.length; i++) {
        managers[i].addListener(this);
    }
    Group gTorrentInfo = new Group(panel, SWT.NULL);
    Messages.setLanguageText(gTorrentInfo, "label.aggregate.info");
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    Utils.setLayoutData(gTorrentInfo, gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    gTorrentInfo.setLayout(layout);
    // total size
    label = new Label(gTorrentInfo, SWT.NULL);
    label.setText(MessageText.getString("TableColumn.header.size") + ": ");
    agg_size = new BufferedLabel(gTorrentInfo, SWT.LEFT | SWT.DOUBLE_BUFFERED);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    agg_size.setLayoutData(gridData);
    // remaining
    label = new Label(gTorrentInfo, SWT.NULL);
    label.setText(MessageText.getString("TableColumn.header.remaining") + ": ");
    agg_remaining = new BufferedLabel(gTorrentInfo, SWT.LEFT | SWT.DOUBLE_BUFFERED);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    agg_remaining.setLayoutData(gridData);
    // uploaded
    label = new Label(gTorrentInfo, SWT.NULL);
    label.setText(MessageText.getString("MyTracker.column.uploaded") + ": ");
    agg_uploaded = new BufferedLabel(gTorrentInfo, SWT.LEFT | SWT.DOUBLE_BUFFERED);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    agg_uploaded.setLayoutData(gridData);
    // downloaded
    label = new Label(gTorrentInfo, SWT.NULL);
    label.setText(MessageText.getString("MyTracker.column.downloaded") + ": ");
    agg_downloaded = new BufferedLabel(gTorrentInfo, SWT.LEFT | SWT.DOUBLE_BUFFERED);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    agg_downloaded.setLayoutData(gridData);
    // upload speed
    label = new Label(gTorrentInfo, SWT.NULL);
    label.setText(MessageText.getString("SpeedView.uploadSpeed.title") + ": ");
    agg_upload_speed = new BufferedLabel(gTorrentInfo, SWT.LEFT | SWT.DOUBLE_BUFFERED);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    agg_upload_speed.setLayoutData(gridData);
    // download speed
    label = new Label(gTorrentInfo, SWT.NULL);
    label.setText(MessageText.getString("SpeedView.downloadSpeed.title") + ": ");
    agg_download_speed = new BufferedLabel(gTorrentInfo, SWT.LEFT | SWT.DOUBLE_BUFFERED);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    agg_download_speed.setLayoutData(gridData);
    // share ratio
    label = new Label(gTorrentInfo, SWT.NULL);
    label.setText(MessageText.getString("TableColumn.header.shareRatio") + ": ");
    agg_share_ratio = new BufferedLabel(gTorrentInfo, SWT.LEFT | SWT.DOUBLE_BUFFERED);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    agg_share_ratio.setLayoutData(gridData);
    // reset
    Label stats_reset_label = new Label(gTorrentInfo, SWT.NULL);
    Messages.setLanguageText(stats_reset_label, "TorrentOptionsView.param.reset.stats");
    Button stats_reset_button = new Button(gTorrentInfo, SWT.PUSH);
    Messages.setLanguageText(stats_reset_button, "TorrentOptionsView.param.reset.button");
    stats_reset_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            for (DownloadManagerOptionsHandler dm : managers) {
                if (dm.getDownloadManager() != null) {
                    dm.getDownloadManager().getStats().resetTotalBytesSentReceived(0, 0);
                }
            }
        }
    });
    panel.layout(true, true);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) UISWTViewCoreEventListener(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener) DownloadManagerStateAttributeListener(com.biglybt.core.download.DownloadManagerStateAttributeListener) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) FontData(org.eclipse.swt.graphics.FontData) GenericIntParameter(com.biglybt.ui.swt.config.generic.GenericIntParameter) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) GenericFloatParameter(com.biglybt.ui.swt.config.generic.GenericFloatParameter) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) GenericBooleanParameter(com.biglybt.ui.swt.config.generic.GenericBooleanParameter) FormLayout(org.eclipse.swt.layout.FormLayout) GridLayout(org.eclipse.swt.layout.GridLayout) DownloadManagerOptionsHandler(com.biglybt.core.download.DownloadManagerOptionsHandler) GridData(org.eclipse.swt.layout.GridData) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) ChangeSelectionActionPerformer(com.biglybt.ui.swt.config.ChangeSelectionActionPerformer)

Example 2 with ChangeSelectionActionPerformer

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

the class ConfigSectionInterfaceLegacy method configSectionCreate.

// @see com.biglybt.ui.swt.pif.UISWTConfigSection#configSectionCreate(org.eclipse.swt.widgets.Composite)
@Override
public Composite configSectionCreate(Composite parent) {
    GridData gridData;
    GridLayout layout;
    Label label;
    Composite cSection = new Composite(parent, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    cSection.setLayoutData(gridData);
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    cSection.setLayout(layout);
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    if (userMode < REQUIRED_MODE) {
        label = new Label(cSection, SWT.WRAP);
        gridData = new GridData();
        gridData.horizontalSpan = 2;
        label.setLayoutData(gridData);
        final String[] modeKeys = { "ConfigView.section.mode.beginner", "ConfigView.section.mode.intermediate", "ConfigView.section.mode.advanced" };
        String param1, param2;
        if (REQUIRED_MODE < modeKeys.length)
            param1 = MessageText.getString(modeKeys[REQUIRED_MODE]);
        else
            param1 = String.valueOf(REQUIRED_MODE);
        if (userMode < modeKeys.length)
            param2 = MessageText.getString(modeKeys[userMode]);
        else
            param2 = String.valueOf(userMode);
        label.setText(MessageText.getString("ConfigView.notAvailableForMode", new String[] { param1, param2 }));
        return cSection;
    }
    /**
     * Old-style speed menus.
     */
    new BooleanParameter(cSection, "GUI_SWT_bOldSpeedMenu", "ConfigView.label.use_old_speed_menus");
    BooleanParameter bpCustomTab = new BooleanParameter(cSection, "useCustomTab", "ConfigView.section.style.useCustomTabs");
    Control cFancyTab = new BooleanParameter(cSection, "GUI_SWT_bFancyTab", "ConfigView.section.style.useFancyTabs").getControl();
    Control[] controls = { cFancyTab };
    bpCustomTab.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(controls));
    return cSection;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) ChangeSelectionActionPerformer(com.biglybt.ui.swt.config.ChangeSelectionActionPerformer) BooleanParameter(com.biglybt.ui.swt.config.BooleanParameter)

Example 3 with ChangeSelectionActionPerformer

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

the class ConfigSectionInterfaceStart method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    // "Start" Sub-Section
    // -------------------
    GridLayout layout;
    Composite cStart = new Composite(parent, SWT.NULL);
    cStart.setLayoutData(new GridData(GridData.FILL_BOTH));
    layout = new GridLayout();
    layout.numColumns = 1;
    cStart.setLayout(layout);
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    boolean isAZ3 = COConfigurationManager.getStringParameter("ui").equals("az3");
    if (userMode >= 2) {
        new BooleanParameter(cStart, "ui.startfirst", "ConfigView.label.StartUIBeforeCore");
    }
    new BooleanParameter(cStart, "Show Splash", "ConfigView.label.showsplash");
    new BooleanParameter(cStart, "update.start", "ConfigView.label.checkonstart");
    new BooleanParameter(cStart, "update.periodic", "ConfigView.label.periodiccheck");
    BooleanParameter autoDownload = new BooleanParameter(cStart, "update.autodownload", "ConfigView.section.update.autodownload");
    BooleanParameter openDialog = new BooleanParameter(cStart, "update.opendialog", "ConfigView.label.opendialog");
    autoDownload.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(new Control[] { openDialog.getControl() }, true));
    new BooleanParameter(cStart, "update.anonymous", "ConfigView.label.update.anonymous");
    new Label(cStart, SWT.NULL);
    new BooleanParameter(cStart, "Open Transfer Bar On Start", "ConfigView.label.open_transfer_bar_on_start");
    new BooleanParameter(cStart, "Start Minimized", "ConfigView.label.startminimized");
    if (Constants.isUnix) {
        new BooleanParameter(cStart, "ui.useGTK2", "ConfigView.label.useGTK2");
    }
    // UI switcher window.
    Composite cUISwitcher = new Composite(cStart, SWT.NONE);
    layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    cUISwitcher.setLayout(layout);
    final Label ui_switcher_label = new Label(cUISwitcher, SWT.NULL);
    Messages.setLanguageText(ui_switcher_label, "ConfigView.label.ui_switcher");
    final Button ui_switcher_button = new Button(cUISwitcher, SWT.PUSH);
    Messages.setLanguageText(ui_switcher_button, "ConfigView.label.ui_switcher_button");
    ui_switcher_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            UISwitcherUtil.openSwitcherWindow();
        }
    });
    return cStart;
}
Also used : BooleanParameter(com.biglybt.ui.swt.config.BooleanParameter) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ChangeSelectionActionPerformer(com.biglybt.ui.swt.config.ChangeSelectionActionPerformer)

Example 4 with ChangeSelectionActionPerformer

use of com.biglybt.ui.swt.config.ChangeSelectionActionPerformer 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)

Aggregations

ChangeSelectionActionPerformer (com.biglybt.ui.swt.config.ChangeSelectionActionPerformer)4 GridData (org.eclipse.swt.layout.GridData)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 BooleanParameter (com.biglybt.ui.swt.config.BooleanParameter)3 BackupManager (com.biglybt.core.backup.BackupManager)1 DownloadManagerOptionsHandler (com.biglybt.core.download.DownloadManagerOptionsHandler)1 DownloadManagerStateAttributeListener (com.biglybt.core.download.DownloadManagerStateAttributeListener)1 AERunnable (com.biglybt.core.util.AERunnable)1 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)1 TextViewerWindow (com.biglybt.ui.swt.TextViewerWindow)1 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)1 BufferedLabel (com.biglybt.ui.swt.components.BufferedLabel)1 IntParameter (com.biglybt.ui.swt.config.IntParameter)1 Parameter (com.biglybt.ui.swt.config.Parameter)1 ParameterChangeAdapter (com.biglybt.ui.swt.config.ParameterChangeAdapter)1 ParameterChangeListener (com.biglybt.ui.swt.config.ParameterChangeListener)1 StringParameter (com.biglybt.ui.swt.config.StringParameter)1 GenericBooleanParameter (com.biglybt.ui.swt.config.generic.GenericBooleanParameter)1 GenericFloatParameter (com.biglybt.ui.swt.config.generic.GenericFloatParameter)1 GenericIntParameter (com.biglybt.ui.swt.config.generic.GenericIntParameter)1