Search in sources :

Example 1 with ImageLoader

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

the class SideBarEntrySWT method setTreeItem.

public void setTreeItem(TreeItem treeItem) {
    if (swtItem != null && treeItem != null) {
        Debug.out("Warning: Sidebar " + id + " already has a treeitem");
        return;
    }
    this.swtItem = treeItem;
    if (treeItem != null) {
        setDisposed(false);
        ImageLoader imageLoader = ImageLoader.getInstance();
        imgClose = imageLoader.getImage("image.sidebar.closeitem");
        imgCloseSelected = imageLoader.getImage("image.sidebar.closeitem-selected");
        treeItem.addDisposeListener(this);
        treeItem.getParent().addTreeListener(new TreeListener() {

            @Override
            public void treeExpanded(TreeEvent e) {
                if (e.item == swtItem) {
                    SideBarEntrySWT.super.setExpanded(true);
                }
            }

            @Override
            public void treeCollapsed(TreeEvent e) {
                if (e.item == swtItem) {
                    SideBarEntrySWT.super.setExpanded(false);
                }
            }
        });
        // Some/All OSes will auto-set treeitem's expanded flag to false if there
        // is no children.  To workaround, we store expanded state internally and
        // set parent to expanded when a child is added
        TreeItem parentItem = treeItem.getParentItem();
        if (parentItem != null) {
            MdiEntry parentEntry = (MdiEntry) parentItem.getData("MdiEntry");
            if (parentEntry.isExpanded()) {
                parentItem.setExpanded(true);
            }
        }
        setExpanded(isExpanded());
    }
    if (buildonSWTItemSet) {
        build();
    }
    if (showonSWTItemSet) {
        show();
    }
}
Also used : TreeListener(org.eclipse.swt.events.TreeListener) TreeEvent(org.eclipse.swt.events.TreeEvent) BaseMdiEntry(com.biglybt.ui.swt.mdi.BaseMdiEntry) MdiEntry(com.biglybt.ui.mdi.MdiEntry) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 2 with ImageLoader

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

the class SideBarEntrySWT method widgetDisposed.

@Override
public void widgetDisposed(DisposeEvent e) {
    ImageLoader imageLoader = ImageLoader.getInstance();
    if (imageLoader != null) {
        imageLoader.releaseImage("image.sidebar.closeitem");
        imageLoader.releaseImage("image.sidebar.closeitem-selected");
    }
    setDisposed(true);
    final TreeItem treeItem = (TreeItem) e.widget;
    if (treeItem != swtItem) {
        Debug.out("Warning: TreeItem changed for sidebar " + id);
        return;
    }
    if (swtItem == null) {
        return;
    }
    if (swtItem != null && !Constants.isOSX) {
        // In theory, the disposal of swtItem will trigger the disposal of the
        // children.  Let's force it just in case
        // On OSX this will cause disposal confusion in SWT, and possibly result
        // in a SIGSEGV crash.
        TreeItem[] children = swtItem.getItems();
        for (TreeItem child : children) {
            if (child.isDisposed()) {
                continue;
            }
            MdiEntry entry = (MdiEntry) child.getData("MdiEntry");
            if (entry != null) {
                entry.close(true);
            }
        }
    }
    final Tree tree = sidebar.getTree();
    if (tree.isDisposed() || (swtItem != null && swtItem.isDisposed()) || tree.getShell().isDisposed()) {
        return;
    }
    setTreeItem(null);
    mdi.removeItem(SideBarEntrySWT.this);
    SWTThread instance = SWTThread.getInstance();
    boolean user = instance != null && !instance.isTerminated();
    if (user) {
        // It's not a user close if the parent is making the children (this entry)
        // close.  parent will be marked disposed, so use that as a check.
        String parentID = getParentID();
        if (parentID != null) {
            MdiEntry entry = mdi.getEntry(parentID);
            if (entry != null && entry.isDisposed()) {
                user = false;
            }
        }
    }
    triggerCloseListeners(user);
    SWTSkinObject so = getSkinObject();
    if (so != null) {
        setSkinObjectMaster(null);
        so.getSkin().removeSkinObject(so);
    }
    for (SideBarVitalityImageSWT vitalityImage : listVitalityImages) {
        vitalityImage.dispose();
    }
    listVitalityImages.clear();
    // delay saving of removing of auto-open flag.  If after the delay, we are
    // still alive, it's assumed the user invoked the close, and we should
    // remove the auto-open flag
    Utils.execSWTThreadLater(0, new SWTRunnable() {

        @Override
        public void runWithDisplay(Display display) {
            // opposed to closing  the sidebar)
            if (tree.isDisposed()) {
                return;
            }
            try {
                COConfigurationManager.removeParameter("SideBar.AutoOpen." + id);
                // Force selection
                if (Constants.isOSX && !tree.isDisposed() && tree.getSelectionCount() == 0) {
                    String parentid = getParentID();
                    if (parentid != null && mdi.getEntry(parentid) != null) {
                        mdi.showEntryByID(parentid);
                    } else {
                        mdi.showEntryByID(SideBar.SIDEBAR_SECTION_LIBRARY);
                    }
                }
            } catch (Exception e2) {
                Debug.out(e2);
            }
            // See if this entry has been replaced by another in the meantime. This happens when we are
            // moving an entry in the sidebar by removing it and then re-adding it. We assume that the
            // auto-open properties of the replacement are the same as those of the initial entry
            boolean replaced = false;
            String my_id = SideBarEntrySWT.this.getId();
            if (my_id != null) {
                MdiEntry entry = mdi.getEntry(my_id);
                if (entry != null && entry != SideBarEntrySWT.this) {
                    replaced = true;
                }
            }
            if (!replaced) {
                mdi.removeEntryAutoOpen(id);
            }
        }
    });
}
Also used : SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) BaseMdiEntry(com.biglybt.ui.swt.mdi.BaseMdiEntry) MdiEntry(com.biglybt.ui.mdi.MdiEntry) SWTRunnable(com.biglybt.ui.swt.utils.SWTRunnable) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) SWTThread(com.biglybt.ui.swt.mainwindow.SWTThread)

Example 3 with ImageLoader

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

the class SideBarVitalityImageSWT method createTimerEvent.

/**
 * @since 3.1.1.1
 */
private synchronized void createTimerEvent() {
    if (timerEvent != null) {
        timerEvent.cancel();
    }
    if (images != null && images.length > 1) {
        ImageLoader imageLoader = ImageLoader.getInstance();
        int delay = delayTime == -1 ? imageLoader.getAnimationDelay(imageID) : delayTime;
        if (performer == null) {
            performer = new TimerEventPerformer() {

                private boolean exec_pending = false;

                private Object lock = this;

                @Override
                public void perform(TimerEvent event) {
                    synchronized (lock) {
                        if (exec_pending) {
                            return;
                        }
                        exec_pending = true;
                    }
                    Utils.execSWTThread(new AERunnable() {

                        @Override
                        public void runSupport() {
                            synchronized (lock) {
                                exec_pending = false;
                            }
                            if (images == null || images.length == 0 || !visible || hitArea == null) {
                                return;
                            }
                            currentAnimationIndex++;
                            if (currentAnimationIndex >= images.length) {
                                currentAnimationIndex = 0;
                            }
                            if (mdiEntry instanceof SideBarEntrySWT) {
                                SideBarEntrySWT sbEntry = (SideBarEntrySWT) mdiEntry;
                                TreeItem treeItem = sbEntry.getTreeItem();
                                if (treeItem == null || treeItem.isDisposed() || !sbEntry.swt_isVisible()) {
                                    return;
                                }
                                if (Utils.isGTK3) {
                                    // parent.clear(parent.indexOf(treeItem), true);
                                    try {
                                        Method m = treeItem.getClass().getDeclaredMethod("clear");
                                        m.setAccessible(true);
                                        m.invoke(treeItem);
                                    } catch (Throwable e) {
                                    }
                                } else {
                                    Tree parent = treeItem.getParent();
                                    parent.redraw(hitArea.x, hitArea.y + treeItem.getBounds().y, hitArea.width, hitArea.height, true);
                                    parent.update();
                                }
                            }
                        }
                    });
                }
            };
        }
        timerEvent = SimpleTimer.addPeriodicEvent("Animate " + mdiEntry.getId() + "::" + imageID + suffix, delay, performer);
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) Method(java.lang.reflect.Method) Tree(org.eclipse.swt.widgets.Tree) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 4 with ImageLoader

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

the class ConfigSectionPlugins method configSectionDelete.

@Override
public void configSectionDelete() {
    ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.releaseImage("redled");
    imageLoader.releaseImage("greenled");
}
Also used : ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 5 with ImageLoader

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

the class ConfigSectionSecurity method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    java.util.List<Button> buttons = new ArrayList<>();
    GridData gridData;
    Composite gSecurity = new Composite(parent, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    gSecurity.setLayoutData(gridData);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    gSecurity.setLayout(layout);
    // row
    Label cert_label = new Label(gSecurity, SWT.NULL);
    Messages.setLanguageText(cert_label, "ConfigView.section.tracker.createcert");
    Button cert_button = new Button(gSecurity, SWT.PUSH);
    buttons.add(cert_button);
    Messages.setLanguageText(cert_button, "ConfigView.section.tracker.createbutton");
    cert_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            new CertificateCreatorWindow();
        }
    });
    new Label(gSecurity, SWT.NULL);
    // row
    Label reset_certs_label = new Label(gSecurity, SWT.NULL);
    Messages.setLanguageText(reset_certs_label, "ConfigView.section.security.resetcerts");
    Button reset_certs_button = new Button(gSecurity, SWT.PUSH);
    buttons.add(reset_certs_button);
    Messages.setLanguageText(reset_certs_button, "Button.reset");
    reset_certs_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            MessageBoxShell mb = new MessageBoxShell(SWT.ICON_WARNING | SWT.OK | SWT.CANCEL, MessageText.getString("ConfigView.section.security.resetcerts.warning.title"), MessageText.getString("ConfigView.section.security.resetcerts.warning.msg"));
            mb.setDefaultButtonUsingStyle(SWT.CANCEL);
            mb.setParent(parent.getShell());
            mb.open(new UserPrompterResultListener() {

                @Override
                public void prompterClosed(int returnVal) {
                    if (returnVal != SWT.OK) {
                        return;
                    }
                    if (SESecurityManager.resetTrustStore(false)) {
                        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(null);
                        UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
                        if (uiFunctions != null) {
                            uiFunctions.dispose(true, false);
                        }
                    } else {
                        MessageBoxShell mb = new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("ConfigView.section.security.resetcerts.error.title"), MessageText.getString("ConfigView.section.security.resetcerts.error.msg"));
                        mb.setParent(parent.getShell());
                        mb.open(null);
                    }
                }
            });
        }
    });
    reset_certs_button.setEnabled(SESecurityManager.resetTrustStore(true));
    new Label(gSecurity, SWT.NULL);
    // row
    gridData = new GridData();
    gridData.horizontalSpan = 3;
    new BooleanParameter(gSecurity, "security.cert.auto.install", "security.cert.auto.install").setLayoutData(gridData);
    // row
    Label info_label = new Label(gSecurity, SWT.WRAP);
    Messages.setLanguageText(info_label, "ConfigView.section.security.toolsinfo");
    info_label.setLayoutData(Utils.getWrappableLabelGridData(3, 0));
    // row
    Label lStatsPath = new Label(gSecurity, SWT.NULL);
    // $NON-NLS-1$
    Messages.setLanguageText(lStatsPath, "ConfigView.section.security.toolsdir");
    ImageLoader imageLoader = ImageLoader.getInstance();
    Image imgOpenFolder = imageLoader.getImage("openFolderButton");
    gridData = new GridData();
    gridData.widthHint = 150;
    // $NON-NLS-1$ //$NON-NLS-2$
    final StringParameter pathParameter = new StringParameter(gSecurity, "Security.JAR.tools.dir", "");
    pathParameter.setLayoutData(gridData);
    Button browse = new Button(gSecurity, SWT.PUSH);
    browse.setImage(imgOpenFolder);
    imgOpenFolder.setBackground(browse.getBackground());
    browse.setToolTipText(MessageText.getString("ConfigView.button.browse"));
    browse.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
            dialog.setFilterPath(pathParameter.getValue());
            // $NON-NLS-1$
            dialog.setText(MessageText.getString("ConfigView.section.security.choosetoolssavedir"));
            String path = dialog.open();
            if (path != null) {
                pathParameter.setValue(path);
            }
        }
    });
    // row
    Label pw_label = new Label(gSecurity, SWT.NULL);
    Messages.setLanguageText(pw_label, "ConfigView.section.security.clearpasswords");
    Button pw_button = new Button(gSecurity, SWT.PUSH);
    buttons.add(pw_button);
    Messages.setLanguageText(pw_button, "ConfigView.section.security.clearpasswords.button");
    pw_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            SESecurityManager.clearPasswords();
            CryptoManagerFactory.getSingleton().clearPasswords();
        }
    });
    new Label(gSecurity, SWT.NULL);
    if (userMode >= 2) {
        final CryptoManager crypt_man = CryptoManagerFactory.getSingleton();
        final Group crypto_group = new Group(gSecurity, SWT.NULL);
        gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 3;
        crypto_group.setLayoutData(gridData);
        layout = new GridLayout();
        layout.numColumns = 3;
        crypto_group.setLayout(layout);
        Messages.setLanguageText(crypto_group, "ConfigView.section.security.group.crypto");
        // wiki link
        final Label linkLabel = new Label(crypto_group, SWT.NULL);
        linkLabel.setText(MessageText.getString("ConfigView.label.please.visit.here"));
        linkLabel.setData(Constants.URL_WIKI + "w/Public_Private_Keys");
        linkLabel.setCursor(linkLabel.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
        linkLabel.setForeground(Colors.blue);
        gridData = new GridData();
        gridData.horizontalSpan = 3;
        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);
        // publick key display
        byte[] public_key = crypt_man.getECCHandler().peekPublicKey();
        Label public_key_label = new Label(crypto_group, SWT.NULL);
        Messages.setLanguageText(public_key_label, "ConfigView.section.security.publickey");
        final Label public_key_value = new Label(crypto_group, SWT.NULL);
        if (public_key == null) {
            Messages.setLanguageText(public_key_value, "ConfigView.section.security.publickey.undef");
        } else {
            public_key_value.setText(Base32.encode(public_key));
        }
        Messages.setLanguageText(public_key_value, "ConfigView.copy.to.clipboard.tooltip", true);
        public_key_value.setCursor(public_key_value.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
        public_key_value.setForeground(Colors.blue);
        public_key_value.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDoubleClick(MouseEvent arg0) {
                copyToClipboard();
            }

            @Override
            public void mouseDown(MouseEvent arg0) {
                copyToClipboard();
            }

            protected void copyToClipboard() {
                new Clipboard(parent.getDisplay()).setContents(new Object[] { public_key_value.getText() }, new Transfer[] { TextTransfer.getInstance() });
            }
        });
        final CryptoManagerKeyListener cryptoManagerKeyListener = new CryptoManagerKeyListener() {

            @Override
            public void keyChanged(final CryptoHandler handler) {
                final CryptoManagerKeyListener me = this;
                Utils.execSWTThread(new Runnable() {

                    @Override
                    public void run() {
                        if (public_key_value.isDisposed()) {
                            crypt_man.removeKeyListener(me);
                        } else {
                            if (handler.getType() == CryptoManager.HANDLER_ECC) {
                                byte[] public_key = handler.peekPublicKey();
                                if (public_key == null) {
                                    Messages.setLanguageText(public_key_value, "ConfigView.section.security.publickey.undef");
                                } else {
                                    public_key_value.setText(Base32.encode(public_key));
                                }
                                crypto_group.layout();
                            }
                        }
                    }
                });
            }

            @Override
            public void keyLockStatusChanged(CryptoHandler handler) {
            }
        };
        crypt_man.addKeyListener(cryptoManagerKeyListener);
        parent.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                if (cryptoManagerKeyListener != null) {
                    CryptoManagerFactory.getSingleton().removeKeyListener(cryptoManagerKeyListener);
                }
            }
        });
        new Label(crypto_group, SWT.NULL);
        // manage keys
        /*
		    gridData = new GridData();
		    gridData.horizontalSpan = 3;

		    final BooleanParameter manage_keys = new BooleanParameter(
		    		crypto_group, "crypto.keys.system.managed.temp",
		    		"ConfigView.section.security.system.managed");

		    manage_keys.setLayoutData( gridData );

		    final ClientCryptoManager crypto_man 	= CryptoManagerFactory.getSingleton();
			final CryptoHandler ecc_handler = crypto_man.getECCHandler();

		    manage_keys.setSelected(
		    		ecc_handler.getDefaultPasswordHandlerType() == CryptoManagerPasswordHandler.HANDLER_TYPE_SYSTEM );


		    manage_keys.addChangeListener(
		    	new ParameterChangeAdapter ()
		    	{
		    		public void
		    		parameterChanged(
		    			Parameter 	p,
		    			boolean 	caused_internally )
		    		{
	    				boolean existing_value = ecc_handler.getDefaultPasswordHandlerType() == CryptoManagerPasswordHandler.HANDLER_TYPE_SYSTEM;

	    				if ( existing_value == manage_keys.isSelected()){

	    					return;
	    				}

	    				String	error = null;

	    				int	new_type = manage_keys.isSelected()?CryptoManagerPasswordHandler.HANDLER_TYPE_SYSTEM:CryptoManagerPasswordHandler.HANDLER_TYPE_USER;

    					try{
    						ecc_handler.setDefaultPasswordHandlerType( new_type );

    						error = null;

    					}catch( CryptoManagerPasswordException e ){

    						if ( e.wasIncorrect()){

    							error = MessageText.getString( "ConfigView.section.security.unlockkey.error" );

    						}else{

    							if ( existing_value || !ecc_handler.isUnlocked()){

    								error = MessageText.getString( "Torrent.create.progress.cancelled" );

    							}else{

    								error = MessageText.getString( "ConfigView.section.security.vuze.login" );
    							}
    						}
    					}catch( Throwable e ){

    						error = Debug.getNestedExceptionMessage( e );
    					}

	    				if ( error != null ){

	    					MessageBoxShell mb = new MessageBoxShell(
	    							SWT.ICON_ERROR | SWT.OK,
	    							MessageText.getString("ConfigView.section.security.op.error.title"),
	    							MessageText.getString("ConfigView.section.security.op.error",
	    									new String[] { error }));
	      				mb.setParent(parent.getShell());
	    					mb.open(null);
	    				}

	    				boolean new_value = ecc_handler.getDefaultPasswordHandlerType() == CryptoManagerPasswordHandler.HANDLER_TYPE_SYSTEM;

	    				if ( new_value != manage_keys.isSelected()){

	    					manage_keys.setSelected( new_value );
	    				}
		    		}
		    	});
		    */
        // reset keys
        Label reset_key_label = new Label(crypto_group, SWT.NULL);
        Messages.setLanguageText(reset_key_label, "ConfigView.section.security.resetkey");
        Button reset_key_button = new Button(crypto_group, SWT.PUSH);
        buttons.add(reset_key_button);
        Messages.setLanguageText(reset_key_button, "ConfigView.section.security.clearpasswords.button");
        reset_key_button.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                MessageBoxShell mb = new MessageBoxShell(SWT.ICON_WARNING | SWT.OK | SWT.CANCEL, MessageText.getString("ConfigView.section.security.resetkey.warning.title"), MessageText.getString("ConfigView.section.security.resetkey.warning"));
                mb.setDefaultButtonUsingStyle(SWT.CANCEL);
                mb.setParent(parent.getShell());
                mb.open(new UserPrompterResultListener() {

                    @Override
                    public void prompterClosed(int returnVal) {
                        if (returnVal != SWT.OK) {
                            return;
                        }
                        try {
                            crypt_man.getECCHandler().resetKeys("Manual key reset");
                        } catch (Throwable e) {
                            MessageBoxShell mb = new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("ConfigView.section.security.resetkey.error.title"), getError(e));
                            mb.setParent(parent.getShell());
                            mb.open(null);
                        }
                    }
                });
            }
        });
        new Label(crypto_group, SWT.NULL);
        // unlock
        Label priv_key_label = new Label(crypto_group, SWT.NULL);
        Messages.setLanguageText(priv_key_label, "ConfigView.section.security.unlockkey");
        Button priv_key_button = new Button(crypto_group, SWT.PUSH);
        buttons.add(priv_key_button);
        Messages.setLanguageText(priv_key_button, "ConfigView.section.security.unlockkey.button");
        priv_key_button.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                try {
                    crypt_man.getECCHandler().getEncryptedPrivateKey("Manual unlock");
                } catch (Throwable e) {
                    MessageBoxShell mb = new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("ConfigView.section.security.resetkey.error.title"), getError(e));
                    mb.setParent(parent.getShell());
                    mb.open(null);
                }
            }
        });
        new Label(crypto_group, SWT.NULL);
        // backup
        Label backup_keys_label = new Label(crypto_group, SWT.NULL);
        Messages.setLanguageText(backup_keys_label, "ConfigView.section.security.backupkeys");
        final Button backup_keys_button = new Button(crypto_group, SWT.PUSH);
        buttons.add(backup_keys_button);
        Messages.setLanguageText(backup_keys_button, "ConfigView.section.security.backupkeys.button");
        backup_keys_button.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                FileDialog dialog = new FileDialog(backup_keys_button.getShell(), SWT.APPLICATION_MODAL);
                String target = dialog.open();
                if (target != null) {
                    try {
                        String keys = crypt_man.getECCHandler().exportKeys();
                        PrintWriter pw = new PrintWriter(new FileWriter(target));
                        pw.println(keys);
                        pw.close();
                    } catch (Throwable e) {
                        MessageBoxShell mb = new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("ConfigView.section.security.op.error.title"), MessageText.getString("ConfigView.section.security.op.error", new String[] { getError(e) }));
                        mb.setParent(parent.getShell());
                        mb.open(null);
                    }
                }
            }
        });
        new Label(crypto_group, SWT.NULL);
        // restore
        Label restore_keys_label = new Label(crypto_group, SWT.NULL);
        Messages.setLanguageText(restore_keys_label, "ConfigView.section.security.restorekeys");
        final Button restore_keys_button = new Button(crypto_group, SWT.PUSH);
        buttons.add(restore_keys_button);
        Messages.setLanguageText(restore_keys_button, "ConfigView.section.security.restorekeys.button");
        restore_keys_button.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                FileDialog dialog = new FileDialog(backup_keys_button.getShell(), SWT.APPLICATION_MODAL);
                String target = dialog.open();
                if (target != null) {
                    try {
                        LineNumberReader reader = new LineNumberReader(new FileReader(target));
                        String str = "";
                        try {
                            while (true) {
                                String line = reader.readLine();
                                if (line == null) {
                                    break;
                                }
                                str += line + "\r\n";
                            }
                        } finally {
                            reader.close();
                        }
                        boolean restart = crypt_man.getECCHandler().importKeys(str);
                        if (restart) {
                            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(null);
                            UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
                            if (uiFunctions != null) {
                                uiFunctions.dispose(true, false);
                            }
                        }
                    } catch (Throwable e) {
                        MessageBoxShell mb = new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("ConfigView.section.security.op.error.title"), MessageText.getString("ConfigView.section.security.op.error", new String[] { getError(e) }));
                        mb.setParent(parent.getShell());
                        mb.open(null);
                    }
                }
            }
        });
        new Label(crypto_group, SWT.NULL);
    }
    Utils.makeButtonsEqualWidth(buttons);
    return gSecurity;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) DisposeListener(org.eclipse.swt.events.DisposeListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) DisposeEvent(org.eclipse.swt.events.DisposeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) MouseEvent(org.eclipse.swt.events.MouseEvent) CertificateCreatorWindow(com.biglybt.ui.swt.auth.CertificateCreatorWindow) MouseAdapter(org.eclipse.swt.events.MouseAdapter) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) GridData(org.eclipse.swt.layout.GridData) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) DisposeEvent(org.eclipse.swt.events.DisposeEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Clipboard(org.eclipse.swt.dnd.Clipboard) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Aggregations

ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)71 Image (org.eclipse.swt.graphics.Image)18 GridData (org.eclipse.swt.layout.GridData)14 GridLayout (org.eclipse.swt.layout.GridLayout)14 CoreRunningListener (com.biglybt.core.CoreRunningListener)5 MessageText (com.biglybt.core.internat.MessageText)5 AERunnable (com.biglybt.core.util.AERunnable)5 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)5 ArrayList (java.util.ArrayList)5 Rectangle (org.eclipse.swt.graphics.Rectangle)5 Core (com.biglybt.core.Core)4 LinkLabel (com.biglybt.ui.swt.components.LinkLabel)4 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)4 File (java.io.File)4 DisposeEvent (org.eclipse.swt.events.DisposeEvent)4 DisposeListener (org.eclipse.swt.events.DisposeListener)4 MouseAdapter (org.eclipse.swt.events.MouseAdapter)4 MouseEvent (org.eclipse.swt.events.MouseEvent)4 FormData (org.eclipse.swt.layout.FormData)4 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)3