⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configsectionipfilter.java

📁 这是一个基于java编写的torrent的P2P源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * File    : ConfigPanel*.java
 * Created : 11 mar. 2004
 * By      : TuxPaper
 * 
 * Copyright (C) 2004, 2005, 2006 Aelitis SAS, All rights Reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details ( see the LICENSE file ).
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * AELITIS, SAS au capital de 46,603.30 euros,
 * 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
 */

package org.gudy.azureus2.ui.swt.views.configsections;

import java.util.Arrays;
import java.util.Comparator;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;

import com.aelitis.azureus.core.*;
import org.gudy.azureus2.plugins.ui.config.ConfigSection;
import org.gudy.azureus2.ui.swt.config.*;
import org.gudy.azureus2.ui.swt.plugins.UISWTConfigSection;
import org.gudy.azureus2.ui.swt.Messages;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.ipfilter.IpFilter;
import org.gudy.azureus2.core3.ipfilter.IpFilterManager;
import org.gudy.azureus2.core3.ipfilter.IpRange;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.util.DisplayFormatters;

public class ConfigSectionIPFilter implements UISWTConfigSection {
  AzureusCore	azureus_core;
  
  IpFilter filter;
  Table table;
  boolean noChange;
  
  FilterComparator comparator;
  
  private boolean bIsCachingDescriptions = false;
  
  class FilterComparator implements Comparator {
    
    boolean ascending = true;
    
    static final int FIELD_NAME = 0;
    static final int FIELD_START_IP = 1;
    static final int FIELD_END_IP = 2;
    
    int field = FIELD_START_IP;
   
    
    public int compare(Object arg0,Object arg1) {
      IpRange range0 = (IpRange) arg0;
      IpRange range1 = (IpRange) arg1;
      if(field == FIELD_NAME) {
        return (ascending ? 1 : -1) * ( range0.compareDescription( range1 ));
      }
      if(field == FIELD_START_IP) {
        return (ascending ? 1 : -1) * ( range0.compareStartIpTo( range1 ));
      }
      if(field == FIELD_END_IP) {
        return (ascending ? 1 : -1) * ( range0.compareEndIpTo( range1 ));
      }
      return 0;
    }
    
    public void setField(int newField) {      
      if(field == newField) ascending = ! ascending;
      field = newField;
    }
    
    
  }
  
  IpRange 	ipRanges[];
  Label		percentage_blocked;
  
  public
  ConfigSectionIPFilter(
  	AzureusCore		_azureus_core )
  {
  	azureus_core	= _azureus_core;
  	comparator = new FilterComparator();
  }
  
  public String configSectionGetParentSection() {
    return ConfigSection.SECTION_ROOT;
  }

	public String configSectionGetName() {
		return "ipfilter";
	}

  public void configSectionSave() {
    try{
      if (filter != null)
      	filter.save();
    }catch( Exception e ){
    	Logger.log(new LogAlert(LogAlert.UNREPEATABLE,
					"Save of filter file fails", e));
    }
  }

  public void configSectionDelete() {
  	if (bIsCachingDescriptions) {
	    IpFilterManager ipFilterManager = azureus_core.getIpFilterManager();
	  	ipFilterManager.clearDescriptionCache();
	  	bIsCachingDescriptions = false;
  	}
  }

  public Composite configSectionCreate(final Composite parent) {
    GridData gridData;

    int userMode = COConfigurationManager.getIntParameter("User Mode");

    final IpFilterManager ipFilterManager = azureus_core.getIpFilterManager();
    filter = ipFilterManager.getIPFilter();
    

    Composite gFilter = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
		layout.marginHeight = 0;
		layout.marginWidth = 0;
    gFilter.setLayout(layout);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    gFilter.setLayoutData(gridData);
    
    
    percentage_blocked  = new Label(gFilter, SWT.NULL);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
	gridData.horizontalSpan = 3;

    percentage_blocked.setLayoutData(gridData);

    setPercentageBlocked();
    
    // start controls

    	// row: enable filter + allow/deny
    
	gridData = new GridData();

    BooleanParameter enabled = new BooleanParameter(gFilter, "Ip Filter Enabled",true);
	enabled.setLayoutData( gridData ); 
    Messages.setLanguageText(enabled.getControl(), "ConfigView.section.ipfilter.enable");

	gridData = new GridData();

    BooleanParameter deny = new BooleanParameter(gFilter, "Ip Filter Allow",false);
	deny.setLayoutData( gridData ); 
    Messages.setLanguageText(deny.getControl(), "ConfigView.section.ipfilter.allow");
  
    deny.addChangeListener(
    	new ParameterChangeAdapter()
		{
    		public void
    		parameterChanged(
    			Parameter	p,
    			boolean		caused_internally )
			{
    			setPercentageBlocked();
			}
		});
    
    	// row persist banning
    
	gridData = new GridData();

  BooleanParameter persist_bad_data_banning = new BooleanParameter(gFilter, "Ip Filter Banning Persistent",true);
  persist_bad_data_banning.setLayoutData( gridData );
  Messages.setLanguageText(persist_bad_data_banning.getControl(), "ConfigView.section.ipfilter.persistblocking");

    	// row block bad + group ban
    
	gridData = new GridData();
	
    BooleanParameter enable_bad_data_banning = new BooleanParameter(gFilter, "Ip Filter Enable Banning",true);
	enable_bad_data_banning.setLayoutData( gridData );
    Messages.setLanguageText(enable_bad_data_banning.getControl(), "ConfigView.section.ipfilter.enablebanning");

  	// description scratch file
		if (userMode > 0) {
			gridData = new GridData();
			BooleanParameter enableDesc = new BooleanParameter(gFilter,
					"Ip Filter Enable Description Cache", true);
			enableDesc.setLayoutData(gridData);
			Messages.setLanguageText(enableDesc.getControl(),
					"ConfigView.section.ipfilter.enable.descriptionCache");
		}
      
    	// block banning

    Composite cLine = new Composite(gFilter, SWT.NULL);
		layout = new GridLayout();
		layout.marginHeight = 0;
		layout.marginWidth = 0;
		layout.numColumns = 2;
		cLine.setLayout(layout);

		Label block_label = new Label(cLine, SWT.NULL);
		Messages.setLanguageText(block_label,
				"ConfigView.section.ipfilter.blockbanning");

		IntParameter block_banning = new IntParameter(cLine,
				"Ip Filter Ban Block Limit");
		gridData = new GridData();
		gridData.widthHint = 30;
		block_banning.setLayoutData(gridData);

		enable_bad_data_banning
				.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(
						new Control[] { block_banning.getControl(), block_label }));
	
		// table
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -