Package org.gudy.azureus2.plugins.utils

Examples of org.gudy.azureus2.plugins.utils.LocaleUtilities


   
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    int maxUsermode = 0;
    try
    {
      ConfigSection sect = sections.get(section);
      if (sect instanceof UISWTConfigSection)
      {
        maxUsermode = ((UISWTConfigSection) sect).maxUserMode();
      }
    } catch (Error e)
View Full Code Here


   
    for (int i=0;i<items.length;i++){
     
      TreeItem  item = items[i];
             
      ConfigSection section = (ConfigSection)item.getData("ConfigSectionSWT");
       
      if ( section != null && section.getClass() == config_section_class ){
         
        tree.setSelection( new TreeItem[]{ item });
       
        showSection( item );
       
View Full Code Here

            && (!(currentContent[0] instanceof ISelectedVuzeFileContent))
            && currentContent[0].getDownloadManager() == null
            && (currentContent[0].getHash() != null || currentContent[0].getDownloadInfo() != null));
 
      if (tv != null) {
        TableColumn tc = tv.getTableColumn(RankItem.COLUMN_ID);
        if (tc != null && !tc.isVisible()) {
          mapNewToolbarStates.put("up", false);
          mapNewToolbarStates.put("down", false);
        }
      }
     
View Full Code Here

    start();
  }

  private void start() {
    for (int i = 0; i < updates.length; i++) {
      Update update = updates[i];
      ResourceDownloader[] rds = update.getDownloaders();
      for (int j = 0; j < rds.length; j++) {
        ResourceDownloader rd = rds[j];
        downloaders.add(rd);
      }
    }
View Full Code Here

  private void allDownloadsComplete() {
    boolean bRequiresRestart = false;
    boolean bHadMandatoryUpdates = false;
   
    for (int i = 0; i < updates.length; i++) {
      Update update = updates[i];
        // updates with no downloaders exist for admin purposes only
      if ( update.getDownloaders().length > 0){
        if (update.getRestartRequired() != Update.RESTART_REQUIRED_NO) {
          bRequiresRestart = true;
        }
        if ( update.isMandatory()){
          bHadMandatoryUpdates = true;
        }
      }
    }
View Full Code Here

          handleEvent(Event event)
          {
            try{
              PluginInterface pi = AzureusCoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface();
             
              UpdateInstaller installer = pi.getUpdateManager().createInstaller();
           
              installer.addMoveAction(
                "C:\\temp\\file1", "C:\\temp\\file2" );
           
              installer.installNow(
                new UpdateInstallerListener()
                {
                  public void
                  reportProgress(
                    String    str )
View Full Code Here

           
              installer.addMoveAction(
                "C:\\temp\\file1", "C:\\temp\\file2" );
           
              installer.installNow(
                new UpdateInstallerListener()
                {
                  public void
                  reportProgress(
                    String    str )
                  {
View Full Code Here

          public void perform(TimerEvent ev) {
            performAutoCheck(false);
          }
        });

    DelayedTask delayed_task =
      UtilitiesImpl.addDelayedTask(
        "Update Check",
        new Runnable()
        {
          public void
          run()
          {
            // check for non-writeable app dir on non-vista platforms (vista we've got a chance of
            // elevating perms when updating) and warn user. Particularly useful on OSX when
            // users haven't installed properly
   
            if ( !( Constants.isWindowsVistaOrHigher || SystemProperties.isJavaWebStartInstance())){
   
              String  app_str = SystemProperties.getApplicationPath();
   
              if ( !new File(app_str).canWrite()){
   
                final UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
   
                if ( uiFunctions != null ){
   
                  if ( app_str.endsWith( File.separator )){
   
                    app_str = app_str.substring(0, app_str.length()-1);
                  }
                 
                  final String f_app_str = app_str;
                 
                  Utils.execSWTThread(
                    new Runnable()
                    {
                      public void
                      run()
                      {
                        UIFunctionsUserPrompter prompt =
                          uiFunctions.getUserPrompter(
                            MessageText.getString("updater.cant.write.to.app.title"),
                            MessageText.getString("updater.cant.write.to.app.details", new String[]{f_app_str}),
                            new String[]{ MessageText.getString( "Button.ok" )},
                            0 );
       
                        //prompt.setHtml( "http://a.b.c/" );
         
                        prompt.setIconResource( "warning" );
         
                        prompt.setRemember( "UpdateMonitor.can.not.write.to.app.dir.2", false,
                            MessageText.getString( "MessageBoxWindow.nomoreprompting" ));
         
                        prompt.open(null);
                      }
                    },
                    true );
                }
              }
            }
   
            performAutoCheck(true);
          }
        });
   
    delayed_task.queue();
  }
View Full Code Here

  {
    plugin    = _plugin;
    ui_instance  = _ui_instance;
    composite  = _composite;

    final LocaleUtilities lu = plugin.getPluginInterface().getUtilities().getLocaleUtilities();
     
    Composite main = new Composite(composite, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    main.setLayout(layout);
    GridData grid_data = new GridData(GridData.FILL_BOTH );
    main.setLayoutData(grid_data);

    if ( !plugin.isEnabled()){
     
      Label control_label = new Label( main, SWT.NULL );
      control_label.setText( lu.getLocalisedMessageText( "azbuddy.disabled" ));

      return;
    }
      // control area
   
    final Composite controls = new Composite(main, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 6;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    controls.setLayout(layout);
    grid_data = new GridData(GridData.FILL_HORIZONTAL );
    controls.setLayoutData(grid_data);
   
    Label control_label = new Label( controls, SWT.NULL );
    control_label.setText( lu.getLocalisedMessageText( "azbuddy.ui.new_buddy" ) + " " );
   
    final Text control_text = new Text( controls, SWT.BORDER );
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    control_text.setLayoutData(gridData);
 
    final Button control_button = new Button( controls, SWT.NULL );
    control_button.setText( lu.getLocalisedMessageText( "azbuddy.ui.add" ));
   
    control_button.setEnabled( false );
   
    control_text.addModifyListener(
      new ModifyListener() {
            public void
            modifyText(
              ModifyEvent e )
            {         
          control_button.setEnabled( plugin.verifyPublicKey( control_text.getText().trim()));
            }
          });
   
    control_button.addSelectionListener(
      new SelectionAdapter()
      {
        public void
        widgetSelected(
          SelectionEvent e )
        {
          plugin.addBuddy( control_text.getText().trim(), BuddyPlugin.SUBSYSTEM_AZ2 );
         
          control_text.setText( "" );
        }
      });
   
    final Label control_lab_pk = new Label( controls, SWT.NULL );
    control_lab_pk.setText( lu.getLocalisedMessageText( "azbuddy.ui.mykey" ) + " ");

    final Text control_val_pk = new Text( controls, SWT.NULL );
    gridData = new GridData();
    gridData.widthHint = 400;
    control_val_pk.setLayoutData(gridData);

    control_val_pk.setEditable( false );
    control_val_pk.setBackground( control_lab_pk.getBackground());
   
    control_val_pk.addKeyListener(
      new KeyListener()
      {
        public void
        keyPressed(
          KeyEvent event)
        {
          int  key = event.character;
         
          if (key <= 26 && key > 0){
           
            key += 'a' - 1;
          }
       
          if ( event.stateMask == SWT.MOD1 && key == 'a' ){
 
            control_val_pk.setSelection( 0, control_val_pk.getText().length())
          }
        }
       
        public void
        keyReleased(
          KeyEvent event)
        { 
        }
      });
   

 

      final CryptoManager crypt_man = CryptoManagerFactory.getSingleton();

    byte[]  public_key = crypt_man.getECCHandler().peekPublicKey();
     
    if ( public_key == null ){
     
        Messages.setLanguageText(control_val_pk, "ConfigView.section.security.publickey.undef");

    }else{
                           
      control_val_pk.setText( Base32.encode( public_key ));
    }
   
      Messages.setLanguageText(control_val_pk, "ConfigView.copy.to.clipboard.tooltip", true);

      control_val_pk.setCursor(main.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
      control_val_pk.setForeground(Colors.blue);
      control_val_pk.addMouseListener(new MouseAdapter() {
        public void mouseDoubleClick(MouseEvent arg0) {
          copyToClipboard();
        }
        public void mouseDown(MouseEvent arg0) {
          copyToClipboard();
        }
        protected void
        copyToClipboard()
        {
          new Clipboard(control_val_pk.getDisplay()).setContents(new Object[] {control_val_pk.getText()}, new Transfer[] {TextTransfer.getInstance()});
        }
      });
   
    crypt_man.addKeyListener(
        new CryptoManagerKeyListener()
        {
          public void
          keyChanged(
            final CryptoHandler handler )
          {
            if ( control_val_pk.isDisposed()){
             
              crypt_man.removeKeyListener( this );
             
            }else if ( handler.getType() == CryptoManager.HANDLER_ECC ){
             
              control_val_pk.getDisplay().asyncExec(
                new Runnable()
                {
                  public void
                  run()
                  {
                    byte[]  public_key = handler.peekPublicKey();
   
                    if ( public_key == null ){
                                       
                       Messages.setLanguageText(control_val_pk, "ConfigView.section.security.publickey.undef");
                     
                    }else{
                     
                      control_val_pk.setText( Base32.encode( public_key ));
                    }
                    
                    controls.layout();
                  }
                });
            }
          }
         
          public void
          keyLockStatusChanged(
            CryptoHandler    handler )
          {
          }
        });
   
    final Button config_button = new Button( controls, SWT.NULL );
    config_button.setText( lu.getLocalisedMessageText( "plugins.basicview.config" ));

    config_button.addSelectionListener(
        new SelectionAdapter()
        {
          public void
          widgetSelected(
            SelectionEvent e )
          {
            plugin.showConfig();
          }
        });
   
      // table and log
   
    final Composite form = new Composite(main, SWT.NONE);
    FormLayout flayout = new FormLayout();
    flayout.marginHeight = 0;
    flayout.marginWidth = 0;
    form.setLayout(flayout);
    gridData = new GridData(GridData.FILL_BOTH);
    form.setLayoutData(gridData);


    final Composite child1 = new Composite(form,SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    child1.setLayout(layout);

    final Sash sash = new Sash(form, SWT.HORIZONTAL);
 
    final Composite child2 = new Composite(form,SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    child2.setLayout(layout);

    FormData formData;

      // child1
   
    formData = new FormData();
    formData.left = new FormAttachment(0, 0);
    formData.right = new FormAttachment(100, 0);
    formData.top = new FormAttachment(0, 0);
    child1.setLayoutData(formData);

    final FormData child1Data = formData;
   
    final int SASH_WIDTH = 4;
   
      // sash
   
    formData = new FormData();
    formData.left = new FormAttachment(0, 0);
    formData.right = new FormAttachment(100, 0);
    formData.top = new FormAttachment(child1);
    formData.height = SASH_WIDTH;
    sash.setLayoutData(formData);

      // child2
   
    formData = new FormData();
    formData.left = new FormAttachment(0, 0);
    formData.right = new FormAttachment(100, 0);
    formData.bottom = new FormAttachment(100, 0);
    formData.top = new FormAttachment(sash);
    child2.setLayoutData(formData);

    final PluginConfig pc = plugin.getPluginInterface().getPluginconfig();
   
    sash.setData( "PCT", new Float( pc.getPluginFloatParameter( "swt.sash.position", 0.7f )));
   
    sash.addSelectionListener(
      new SelectionAdapter()
      {
        public void
        widgetSelected(
          SelectionEvent e )
        {
          if (e.detail == SWT.DRAG){
            return;
          }
         
          child1Data.height = e.y + e.height - SASH_WIDTH;
         
          form.layout();
 
          Float l = new Float((double)child1.getBounds().height / form.getBounds().height);
         
          sash.setData( "PCT", l );
         
          pc.setPluginParameter( "swt.sash.position", l.floatValue());
        }
      });

    form.addListener(
      SWT.Resize,
      new Listener()
      {
        public void
        handleEvent(Event e)
        {
          Float l = (Float) sash.getData( "PCT" );
         
          if ( l != null ){
           
            child1Data.height = (int) (form.getBounds().height * l.doubleValue());
         
            form.layout();
          }
        }
      });
     
      // table
   
    buddy_table = new Table(child1, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL);

    final String[] headers = {
        "azbuddy.ui.table.name",
        "azbuddy.ui.table.online"
        "azbuddy.ui.table.lastseen",
        "azbuddy.ui.table.last_ygm",
        "azbuddy.ui.table.last_msg",
        "azbuddy.ui.table.loc_cat",
        "azbuddy.ui.table.rem_cat",
        "azbuddy.ui.table.read_cat",
        "azbuddy.ui.table.con",
        "azbuddy.ui.table.msg_in",
        "azbuddy.ui.table.msg_out",
        "azbuddy.ui.table.msg_queued",
        "MyTrackerView.bytesin",
        "MyTrackerView.bytesout",
        "azbuddy.ui.table.ss" };

    int[] sizes = { 250, 100, 100, 100, 200, 100, 100, 100, 75, 75, 75, 75, 75, 75, 40 };

    int[] aligns = { SWT.LEFT, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.LEFT, SWT.LEFT, SWT.LEFT, SWT.LEFT, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER };

    for (int i = 0; i < headers.length; i++){

      TableColumn tc = new TableColumn(buddy_table, aligns[i]);
       
      tc.setWidth(sizes[i]);

      Messages.setLanguageText(tc, headers[i]);
   

      buddy_table.setHeaderVisible(true);

      TableColumn[] columns = buddy_table.getColumns();
      columns[0].setData(new Integer(FilterComparator.FIELD_NAME));
      columns[1].setData(new Integer(FilterComparator.FIELD_ONLINE));
      columns[2].setData(new Integer(FilterComparator.FIELD_LAST_SEEN));
      columns[3].setData(new Integer(FilterComparator.FIELD_YGM));
      columns[4].setData(new Integer(FilterComparator.FIELD_LAST_MSG));
      columns[5].setData(new Integer(FilterComparator.FIELD_LOC_CAT));
      columns[6].setData(new Integer(FilterComparator.FIELD_REM_CAT));
      columns[7].setData(new Integer(FilterComparator.FIELD_READ_CAT));
      columns[8].setData(new Integer(FilterComparator.FIELD_CON));
      columns[9].setData(new Integer(FilterComparator.FIELD_MSG_IN));
      columns[10].setData(new Integer(FilterComparator.FIELD_MSG_OUT));
      columns[11].setData(new Integer(FilterComparator.FIELD_QUEUED));
      columns[12].setData(new Integer(FilterComparator.FIELD_BYTES_IN));
      columns[13].setData(new Integer(FilterComparator.FIELD_BYTES_OUT));
      columns[14].setData(new Integer(FilterComparator.FIELD_SS));
     
     
      final FilterComparator comparator = new FilterComparator();
     
      Listener sort_listener =
        new Listener()
        {
          public void
          handleEvent(
            Event e )
          {
            TableColumn tc = (TableColumn) e.widget;
 
            int field = ((Integer) tc.getData()).intValue();
 
            comparator.setField( field );
 
            Collections.sort( buddies,comparator);
 
            updateTable();
          }
        };
     
      for (int i=0;i<columns.length;i++){
       
        columns[i].addListener(SWT.Selection,sort_listener);
      }     
     
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.heightHint = buddy_table.getHeaderHeight() * 3;
    buddy_table.setLayoutData(gridData);
   
   
    buddy_table.addListener(
      SWT.SetData,
      new Listener()
      {
        public void
        handleEvent(
          Event event)
        {
          TableItem item = (TableItem)event.item;
         
          int index = buddy_table.indexOf(item);
 
          if ( index < 0 || index >= buddies.size()){
           
            return;
          }
         
          BuddyPluginBuddy  buddy = (BuddyPluginBuddy)buddies.get(index);
         
          item.setText(0, buddy.getName());
         
          int  os;
         
          if ( buddy.isOnline( false )){
           
            os = buddy.getOnlineStatus();
           
          }else{
           
            os = BuddyPlugin.STATUS_APPEAR_OFFLINE;
          }
         
          if ( os == BuddyPlugin.STATUS_APPEAR_OFFLINE ){
           
            item.setText( 1, "" );
           
          }else{
         
            item.setText(1, plugin.getOnlineStatus( os ));
          }
         
          long lo = buddy.getLastTimeOnline();
         
          item.setText(2, lo==0?"":new SimpleDateFormat().format(new Date( lo )));

          long  last_ygm = buddy.getLastMessagePending();;
         
          item.setText(3, last_ygm==0?"":new SimpleDateFormat().format(new Date( last_ygm )));
         
          String  lm = buddy.getLastMessageReceived();
         
          item.setText(4, lm==null?"":lm);
         
          String loc_cat = buddy.getLocalAuthorisedRSSCategoriesAsString();
          if ( loc_cat == null ){
            loc_cat = "";
          }
          item.setText(5, "" + loc_cat);

          String rem_cat = buddy.getRemoteAuthorisedRSSCategoriesAsString();
          if ( rem_cat == null ){
            rem_cat = "";
          }
          item.setText(6, "" + rem_cat);

          String read_cat = buddy.getLocalReadCategoriesAsString();
          if ( read_cat == null ){
            read_cat = "";
          }
          item.setText(7, "" + read_cat);

          item.setText(8, "" + buddy.getConnectionsString());
         
          String in_frag = buddy.getMessageInFragmentDetails();
         
          item.setText(9, "" + buddy.getMessageInCount() + (in_frag.length()==0?"":("+" + in_frag )));
          item.setText(10, "" + buddy.getMessageOutCount());
          item.setText(11, "" + buddy.getMessageHandler().getMessageCount());
          item.setText(12, "" + DisplayFormatters.formatByteCountToKiBEtc(buddy.getBytesInCount()));
          item.setText(13, "" + DisplayFormatters.formatByteCountToKiBEtc(buddy.getBytesOutCount()));

          item.setText(14, "" + buddy.getSubsystem() + " v" + buddy.getVersion());
         
          item.setData( buddy );
        }
      });
   
    final Listener tt_label_listener =
      new Listener()
      {
        public void handleEvent(Event event) {
          Label label = (Label) event.widget;
          Shell shell = label.getShell();
          switch (event.type) {
          case SWT.MouseDown:
            Event e = new Event();
            e.item = (TableItem) label.getData("_TABLEITEM");
            buddy_table.setSelection(new TableItem[] { (TableItem) e.item });
            buddy_table.notifyListeners(SWT.Selection, e);
            // fall through
          case SWT.MouseExit:
            shell.dispose();
            break;
          }
        }
      };


    Listener  tt_table_listener =
      new Listener()
      {
        private Shell tip = null;

        private Label label = null;

        public void
        handleEvent(
          Event event )
        {
          switch (event.type){
            case SWT.Dispose:
            case SWT.KeyDown:
            case SWT.MouseMove: {
              if (tip == null)
                break;
              tip.dispose();
              tip = null;
              label = null;
              break;
            }
            case SWT.MouseHover:
            {
              Point mouse_position = new Point(event.x, event.y);
             
              TableItem item = buddy_table.getItem( mouse_position );
                           
              if (item != null) {
               
                if (tip != null && !tip.isDisposed()){
                 
                  tip.dispose();
                 
                  tip = null;
                }
               
                int index = buddy_table.indexOf(item);
               
                if ( index < 0 || index >= buddies.size()){
                 
                  return;
                }

                BuddyPluginBuddy  buddy = (BuddyPluginBuddy)buddies.get(index);

                int  item_index = 0;
               
                for (int i=0;i<headers.length;i++){
                 
                  Rectangle bounds = item.getBounds(i);
                 
                  if ( bounds.contains( mouse_position )){
                   
                    item_index = i;
                   
                    break;
                  }
                }
               
                if( item_index != 0 ){
                 
                  return;
                }
               
                tip = new Shell(buddy_table.getShell(), SWT.ON_TOP | SWT.TOOL);
                tip.setLayout(new FillLayout());
                label = new Label(tip, SWT.NONE);
                label.setForeground(buddy_table.getDisplay()
                    .getSystemColor(SWT.COLOR_INFO_FOREGROUND));
                label.setBackground(buddy_table.getDisplay()
                    .getSystemColor(SWT.COLOR_INFO_BACKGROUND));
                label.setData("_TABLEITEM", item);
               
                label.setText( getToolTip( buddy ));
               
                label.addListener(SWT.MouseExit, tt_label_listener);
                label.addListener(SWT.MouseDown, tt_label_listener);
                Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                Rectangle rect = item.getBounds(item_index);
                Point pt = buddy_table.toDisplay(rect.x, rect.y);
                tip.setBounds(pt.x, pt.y, size.x, size.y);
                tip.setVisible(true);
              }
            }
          }
        }
       
        protected String
        getToolTip(
          BuddyPluginBuddy  buddy )
        {
          List addresses = buddy.getAdjustedIPs();
         
          InetAddress  ip  = buddy.getIP();
         
          InetAddress adj = buddy.getAdjustedIP();
         
          String  str = "";
         
          if ( ip == null ){
           
            str = "<none>";
           
          }else if ( ip == adj ){
           
            str = ip.getHostAddress();
           
          }else{
           
            str = ip.getHostAddress() + "{";
         
            for (int i=0;i<addresses.size();i++){
             
              str += (i==0?"":"/") + ((InetAddress)addresses.get(i)).getHostAddress();
            }
           
            str += "}";
          }
         
          return"ip=" + str + ",tcp=" + buddy.getTCPPort() + ",udp=" + buddy.getUDPPort());
        }
      };
     
    buddy_table.addListener(SWT.Dispose, tt_table_listener);
    buddy_table.addListener(SWT.KeyDown, tt_table_listener);
    buddy_table.addListener(SWT.MouseMove, tt_table_listener);
    buddy_table.addListener(SWT.MouseHover, tt_table_listener);
             


    final Menu menu = new Menu(buddy_table);
   
    final MenuItem remove_item = new MenuItem(menu, SWT.PUSH);
   
    remove_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.remove" ));

    remove_item.addSelectionListener(
      new SelectionAdapter()
      {
        public void
        widgetSelected(
          SelectionEvent e)
        {
          TableItem[] selection = buddy_table.getSelection();
         
          for (int i=0;i<selection.length;i++){
           
            BuddyPluginBuddy buddy = (BuddyPluginBuddy)selection[i].getData();
           
            buddy.remove();
          }
        };
      });
   
      // get public key
       
    final MenuItem get_pk_item = new MenuItem(menu, SWT.PUSH);

    get_pk_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.copypk" ) );

    get_pk_item.addSelectionListener(
      new SelectionAdapter()
      {
        public void
        widgetSelected(
          SelectionEvent event )
        {
          TableItem[] selection = buddy_table.getSelection();
         
          StringBuffer sb = new StringBuffer();
         
          for (int i=0;i<selection.length;i++){
           
            BuddyPluginBuddy buddy = (BuddyPluginBuddy)selection[i].getData();
           
            sb.append( buddy.getPublicKey() + "\r\n" );
          }
         
          if ( sb.length() > 0 ){
         
            writeToClipboard( sb.toString());
          }
        };
      });
   
      // disconnect message
   
    if ( Constants.isCVSVersion()){
      final  MenuItem send_msg_item = new MenuItem(menu, SWT.PUSH);
 
      send_msg_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.disconnect" ) );
 
      send_msg_item.addSelectionListener(
        new SelectionAdapter()
        {
          public void
          widgetSelected(
            SelectionEvent event )
          {
            TableItem[] selection = buddy_table.getSelection();
       
            for (int i=0;i<selection.length;i++){
             
              BuddyPluginBuddy buddy = (BuddyPluginBuddy)selection[i].getData();
             
              buddy.disconnect();
            }
          }
        });
    }
   
      // send message
   
    final  MenuItem send_msg_item = new MenuItem(menu, SWT.PUSH);

    send_msg_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.send" ) );

    send_msg_item.addSelectionListener(
      new SelectionAdapter()
      {
        public void
        widgetSelected(
          SelectionEvent event )
        {
          final TableItem[] selection = buddy_table.getSelection();
         
          UIInputReceiver prompter = ui_instance.getInputReceiver();
         
          prompter.setLocalisedTitle( lu.getLocalisedMessageText( "azbuddy.ui.menu.send" ));
          prompter.setLocalisedMessage( lu.getLocalisedMessageText( "azbuddy.ui.menu.send_msg" ) );
         
          try{
            prompter.prompt(new UIInputReceiverListener() {
              public void UIInputReceiverClosed(UIInputReceiver prompter) {
                String text = prompter.getSubmittedInput();
               
                if ( text != null ){
                 
                  for (int i=0;i<selection.length;i++){
                   
                    BuddyPluginBuddy buddy = (BuddyPluginBuddy)selection[i].getData();
                   
                    plugin.getAZ2Handler().sendAZ2Message( buddy, text );
                  }
                }
              }
            });
           
          }catch( Throwable e ){
           
          }
        };
      });
   
      // chat
   
    final  MenuItem chat_item = new MenuItem(menu, SWT.PUSH);

    chat_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.chat" ) );

    chat_item.addSelectionListener(
      new SelectionAdapter()
      {
        public void
        widgetSelected(
          SelectionEvent event )
        {
          TableItem[] selection = buddy_table.getSelection();
         
          BuddyPluginBuddy[] buddies = new BuddyPluginBuddy[selection.length];
         
          for (int i=0;i<selection.length;i++){
           
            BuddyPluginBuddy buddy = (BuddyPluginBuddy)selection[i].getData();

            buddies[i] = buddy;
          }
               
          plugin.getAZ2Handler().createChat( buddies );
        };
      });
   
      // ping
   
    final MenuItem ping_item = new MenuItem(menu, SWT.PUSH);

    ping_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.ping" ) );

    ping_item.addSelectionListener(
      new SelectionAdapter()
      {
        public void
        widgetSelected(
          SelectionEvent event )
        {
          TableItem[] selection = buddy_table.getSelection();
         
          for (int i=0;i<selection.length;i++){
           
            BuddyPluginBuddy buddy = (BuddyPluginBuddy)selection[i].getData();
           
            try{         
              buddy.ping();
             
            }catch( Throwable e ){
             
              print( "Ping failed", e );
            }
          }
        };
      });
   
      // ygm
   
    final MenuItem ygm_item = new MenuItem(menu, SWT.PUSH);

    ygm_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.ygm" ) );

    ygm_item.addSelectionListener(
      new SelectionAdapter()
      {
        public void
        widgetSelected(
          SelectionEvent event )
        {
          TableItem[] selection = buddy_table.getSelection();
         
          for (int i=0;i<selection.length;i++){
           
            BuddyPluginBuddy buddy = (BuddyPluginBuddy)selection[i].getData();
           
            try{
              buddy.setMessagePending();
             
            }catch( Throwable e ){
             
              print( "YGM failed", e );
            }
          }
        };
      });
   
   
      // encrypt
   
    final MenuItem encrypt_item = new MenuItem(menu, SWT.PUSH);

    encrypt_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.enc" ) );

    encrypt_item.addSelectionListener(
      new SelectionAdapter()
      {
        public void
        widgetSelected(
          SelectionEvent event )
        {
          TableItem[] selection = buddy_table.getSelection();
         
          String  str = readFromClipboard();
         
          if( str != null ){
           
            StringBuffer sb = new StringBuffer();
           
            for (int i=0;i<selection.length;i++){
             
              BuddyPluginBuddy buddy = (BuddyPluginBuddy)selection[i].getData();
             
              try{
                byte[]  contents = str.getBytes( "UTF-8" );
               
                BuddyPlugin.cryptoResult result = buddy.encrypt( contents );
               
                sb.append( "key: " );
                sb.append( plugin.getPublicKey());
                sb.append( "\r\n" );
               
                sb.append( "hash: " );
                sb.append( Base32.encode( result.getChallenge()));
                sb.append( "\r\n" );

                sb.append( "payload: " );
                sb.append( Base32.encode( result.getPayload()));
                sb.append( "\r\n\r\n" );
               
              }catch( Throwable e ){
               
                print( "YGM failed", e );
              }
            }
           
            writeToClipboard( sb.toString());
          }
        };
      });
   
      // decrypt
   
    final MenuItem decrypt_item = new MenuItem(menu, SWT.PUSH);

    decrypt_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.dec" ) );

    decrypt_item.addSelectionListener(
      new SelectionAdapter()
      {
        public void
        widgetSelected(
          SelectionEvent event )
        {
          String  str = readFromClipboard();
         
          if ( str != null ){
           
            String[]   bits = str.split( "\n" );
           
            StringBuffer sb = new StringBuffer();
 
            BuddyPluginBuddy  buddy   = null;
            byte[]        hash  = null;
           
            for (int i=0;i<bits.length;i++){
             
              String  bit = bits[i].trim();
             
              if ( bit.length() > 0 ){
             
                int  pos = bit.indexOf( ':' );
               
                if ( pos == -1 ){
                 
                  continue;
                }
               
                String  lhs = bit.substring( 0, pos ).trim();
                String  rhs  = bit.substring( pos+1 ).trim();
               
                if ( lhs.equals( "key" )){
                 
                  buddy = plugin.getBuddyFromPublicKey( rhs );
                 
                }else if ( lhs.equals( "hash" )){
                 
                  hash  = Base32.decode( rhs );
                 
                }else if ( lhs.equals( "payload" )){
               
                  byte[]  payload = Base32.decode( rhs );
                 
                  if ( buddy != null ){
                   
                    try{
                      BuddyPlugin.cryptoResult result = buddy.decrypt( payload );
                     
                      byte[] sha1 = new SHA1Simple().calculateHash( result.getChallenge());
                     
                      sb.append( "key: " );
                      sb.append( buddy.getPublicKey());
                      sb.append( "\r\n" );

                      sb.append( "hash_ok: " + Arrays.equals( hash, sha1 ));
                      sb.append( "\r\n" );
                     
                      sb.append( "payload: " );
                      sb.append( new String( result.getPayload(), "UTF-8" ));
                      sb.append( "\r\n\r\n" );
                     
                    }catch( Throwable e ){
                     
                      print( "decrypt failed", e );
                    }
                  }
                }
              }
            }
           
            if ( sb.length() > 0 ){
           
              writeToClipboard( sb.toString());
            }
          }
        };
      });
   
      // sign
   
    final MenuItem sign_item = new MenuItem(menu, SWT.PUSH);

    sign_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.sign" ) );

    sign_item.addSelectionListener(
      new SelectionAdapter()
      {
        public void
        widgetSelected(
          SelectionEvent event )
        {
          String  str = readFromClipboard();
         
          if ( str != null ){
           
            StringBuffer sb = new StringBuffer();
           
            try{
              sb.append( "key: " );
              sb.append( plugin.getPublicKey());
              sb.append( "\r\n" );

              byte[] payload = str.getBytes( "UTF-8" );
             
              sb.append( "data: " );
              sb.append( Base32.encode( payload ));
              sb.append( "\r\n" );

              byte[]  sig = plugin.sign( payload );

              sb.append( "sig: " );
              sb.append( Base32.encode( sig ));
              sb.append( "\r\n" );

            }catch( Throwable e ){
             
              print( "sign failed", e );
            }
           
            if ( sb.length() > 0 ){
           
              writeToClipboard( sb.toString());
            }
          }
        };
      });
   
      // verify
   
    final MenuItem verify_item = new MenuItem(menu, SWT.PUSH);

    verify_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.verify" ) );

    verify_item.addSelectionListener(
      new SelectionAdapter()
      {
        public void
        widgetSelected(
          SelectionEvent event )
        {
          String  str = readFromClipboard();
         
          if ( str != null ){
           
            String[]   bits = str.split( "\n" );
           
            StringBuffer sb = new StringBuffer();
 
            String        pk     = null;
            byte[]        data  = null;
           
            for (int i=0;i<bits.length;i++){
             
              String  bit = bits[i].trim();
             
              if ( bit.length() > 0 ){
             
                int  pos = bit.indexOf( ':' );
               
                if ( pos == -1 ){
                 
                  continue;
                }
               
                String  lhs = bit.substring( 0, pos ).trim();
                String  rhs  = bit.substring( pos+1 ).trim();
               
                if ( lhs.equals( "key" )){
                 
                  pk = rhs;
                 
                }else if ( lhs.equals( "data" )){
                 
                  data  = Base32.decode( rhs );
                 
                }else if ( lhs.equals( "sig" )){
               
                  byte[]  sig = Base32.decode( rhs );
                 
                  if ( pk != null && data != null ){
                   
                    try{
                     
                      sb.append( "key: " );
                      sb.append( pk );
                      sb.append( "\r\n" );

                      boolean ok = plugin.verify( pk, data, sig );
                     
                      sb.append( "sig_ok: " + ok  );
                      sb.append( "\r\n" );
                     
                      sb.append( "data: " );
                      sb.append( new String( data, "UTF-8" ));
                      sb.append( "\r\n\r\n" );
                     
                    }catch( Throwable e ){
                     
                      print( "decrypt failed", e );
                    }
                  }
                }
              }
            }
           
            if ( sb.length() > 0 ){
           
              writeToClipboard( sb.toString());
            }
          }
        };
      });
       
   
      // cats
   
    Menu cat_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
    MenuItem cat_item = new MenuItem(menu, SWT.CASCADE);
    Messages.setLanguageText(cat_item, "azbuddy.ui.menu.cat" );
    cat_item.setMenu(cat_menu);

      // cats - share
   
    final MenuItem cat_share_item = new MenuItem(cat_menu, SWT.PUSH);

    cat_share_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.cat.share" ) );

    cat_share_item.addSelectionListener(
      new SelectionAdapter()
      {
        public void
        widgetSelected(
          SelectionEvent event )
        {
          UIInputReceiver prompter = ui_instance.getInputReceiver();
         
          prompter.setLocalisedTitle( lu.getLocalisedMessageText( "azbuddy.ui.menu.cat.set" ));
          prompter.setLocalisedMessage( lu.getLocalisedMessageText( "azbuddy.ui.menu.cat.set_msg" ));
         
          prompter.prompt(new UIInputReceiverListener() {
            public void UIInputReceiverClosed(UIInputReceiver prompter) {
              String cats = prompter.getSubmittedInput();
             
View Full Code Here

// -------------------------- STATIC METHODS --------------------------

    public static void initializeConfigPage(final PluginInterface pluginInterface) {
        final BasicPluginConfigModel cfg = pluginInterface.getUIManager().createBasicPluginConfigModel(_BaseConfigName);
        LocaleUtilities localeUtil = pluginInterface.getUtilities().getLocaleUtilities();

        cfg.addBooleanParameter2(_PluginActive, _BaseConfigName + "." + _PluginActive, false);
        cfg.addIntParameter2(_IntervalSearch, _BaseConfigName + "." + _IntervalSearch, _IntervalSearchDefault);
        cfg.addStringParameter2(_ExcludeFilesRegex, _BaseConfigName + "." + _ExcludeFilesRegex, "");
View Full Code Here

TOP

Related Classes of org.gudy.azureus2.plugins.utils.LocaleUtilities

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.