📄 configsectionplugins.java
字号:
/*
* File : ConfigSectionPlguins.java
*
* 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.io.File;
import java.util.*;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.internat.MessageText;
import org.gudy.azureus2.core3.util.FileUtil;
import org.gudy.azureus2.plugins.PluginException;
import org.gudy.azureus2.plugins.PluginInterface;
import org.gudy.azureus2.plugins.ui.config.ConfigSection;
import org.gudy.azureus2.plugins.ui.config.Parameter;
import org.gudy.azureus2.pluginsimpl.local.PluginInitializer;
import org.gudy.azureus2.pluginsimpl.local.PluginInterfaceImpl;
import org.gudy.azureus2.pluginsimpl.local.ui.config.BooleanParameterImpl;
import org.gudy.azureus2.pluginsimpl.local.ui.config.ParameterRepository;
import org.gudy.azureus2.ui.swt.ImageRepository;
import org.gudy.azureus2.ui.swt.Messages;
import org.gudy.azureus2.ui.swt.Utils;
import org.gudy.azureus2.ui.swt.config.DualChangeSelectionActionPerformer;
import org.gudy.azureus2.ui.swt.config.IAdditionalActionPerformer;
import org.gudy.azureus2.ui.swt.config.plugins.PluginParameter;
import org.gudy.azureus2.ui.swt.mainwindow.Colors;
import org.gudy.azureus2.ui.swt.mainwindow.Cursors;
import org.gudy.azureus2.ui.swt.plugins.UISWTConfigSection;
import org.gudy.azureus2.ui.swt.views.ConfigView;
import com.aelitis.azureus.core.AzureusCore;
/**
* Configuration Section that lists all the plugins and sets up
* subsections for plugins that used the PluginConfigModel object.
*
* Moved from ConfigView
*
* @author TuxPaper
*
*/
public class ConfigSectionPlugins implements UISWTConfigSection {
private final static String HEADER_PREFIX = "ConfigView.pluginlist.column.";
private final static String[] COLUMN_HEADERS = { "loadAtStartup", "type",
"name", "version", "directory", "unloadable" };
private final static int[] COLUMN_SIZES = { 110, 50, 150, 75, 100, 50 };
private final static int[] COLUMN_ALIGNS = { SWT.CENTER, SWT.LEFT, SWT.LEFT,
SWT.RIGHT, SWT.LEFT, SWT.CENTER};
private ConfigView configView;
private AzureusCore azureusCore;
FilterComparator comparator;
List pluginIFs;
class FilterComparator implements Comparator {
boolean ascending = true;
static final int FIELD_LOAD = 0;
static final int FIELD_TYPE = 1;
static final int FIELD_NAME = 2;
static final int FIELD_VERSION = 3;
static final int FIELD_DIRECTORY = 4;
static final int FIELD_UNLOADABLE = 5;
int field = FIELD_NAME;
String sUserPluginDir;
String sAppPluginDir;
public FilterComparator() {
String sep = System.getProperty("file.separator");
sUserPluginDir = FileUtil.getUserFile("plugins").toString();
if (!sUserPluginDir.endsWith(sep))
sUserPluginDir += sep;
sAppPluginDir = FileUtil.getApplicationFile("plugins").toString();
if (!sAppPluginDir.endsWith(sep))
sAppPluginDir += sep;
}
public int compare(Object arg0, Object arg1) {
PluginInterface if0 = (PluginInterface) arg0;
PluginInterfaceImpl if1 = (PluginInterfaceImpl) arg1;
int result = 0;
switch (field) {
case FIELD_LOAD: {
boolean b0 = COConfigurationManager.getBooleanParameter("PluginInfo."
+ if0.getPluginID() + ".enabled", true);
boolean b1 = COConfigurationManager.getBooleanParameter("PluginInfo."
+ if1.getPluginID() + ".enabled", true);
result = (b0 == b1 ? 0 : (b0 ? 1 : -1));
break;
}
case FIELD_TYPE:
case FIELD_DIRECTORY: {
result = getFieldValue(field, if0).compareToIgnoreCase(
getFieldValue(field, if1));
break;
}
case FIELD_VERSION: { // XXX Not really right..
String s0 = if0.getPluginVersion();
String s1 = if1.getPluginVersion();
if (s0 == null)
s0 = "";
if (s1 == null)
s1 = "";
result = s0.compareToIgnoreCase(s1);
break;
}
case FIELD_UNLOADABLE: {
boolean b0 = if0.isUnloadable();
boolean b1 = if1.isUnloadable();
result = (b0 == b1 ? 0 : (b0 ? 1 : -1));
break;
}
}
if (result == 0)
result = if0.getPluginName().compareToIgnoreCase(if1.getPluginName());
if (!ascending)
result *= -1;
return result;
}
public boolean setField(int newField) {
if (field == newField)
ascending = !ascending;
else
ascending = true;
field = newField;
return ascending;
}
public String getFieldValue(int iField, PluginInterface pluginIF) {
switch (iField) {
case FIELD_LOAD: {
return pluginIF.getPluginID();
}
case FIELD_DIRECTORY: {
String sDirName = pluginIF.getPluginDirectoryName();
if (sDirName.length() > sUserPluginDir.length()
&& sDirName.substring(0, sUserPluginDir.length()).equals(
sUserPluginDir)) {
return sDirName.substring(sUserPluginDir.length());
} else if (sDirName.length() > sAppPluginDir.length()
&& sDirName.substring(0, sAppPluginDir.length()).equals(
sAppPluginDir)) {
return sDirName.substring(sAppPluginDir.length());
}
return sDirName;
}
case FIELD_NAME: {
return pluginIF.getPluginName();
}
case FIELD_TYPE: {
String sDirName = pluginIF.getPluginDirectoryName();
String sKey;
if (sDirName.length() > sUserPluginDir.length()
&& sDirName.substring(0, sUserPluginDir.length()).equals(
sUserPluginDir)) {
sKey = "perUser";
} else if (sDirName.length() > sAppPluginDir.length()
&& sDirName.substring(0, sAppPluginDir.length()).equals(
sAppPluginDir)) {
sKey = "shared";
} else {
sKey = "builtIn";
}
return MessageText.getString(HEADER_PREFIX + "type." + sKey);
}
case FIELD_VERSION: {
return pluginIF.getPluginVersion();
}
case FIELD_UNLOADABLE: {
return MessageText.getString("Button."
+ (pluginIF.isUnloadable() ? "yes" : "no"));
}
} // switch
return "";
}
}
/**
* Initialize
* @param _configView
*/
public ConfigSectionPlugins(ConfigView _configView, AzureusCore _azureusCore) {
configView = _configView;
azureusCore = _azureusCore;
comparator = new FilterComparator();
}
public String configSectionGetParentSection() {
return ConfigSection.SECTION_ROOT;
}
/* Name of section will be pulled from
* ConfigView.section.<i>configSectionGetName()</i>
*/
public String configSectionGetName() {
return ConfigSection.SECTION_PLUGINS;
}
public void configSectionSave() {
}
public void configSectionDelete() {
}
public Composite configSectionCreate(final Composite parent) {
GridLayout layout;
GridData gridData;
Label label;
Composite infoGroup = new Composite(parent, SWT.NULL);
gridData = new GridData(GridData.VERTICAL_ALIGN_FILL
| GridData.HORIZONTAL_ALIGN_FILL);
infoGroup.setLayoutData(gridData);
layout = new GridLayout();
layout.numColumns = 1;
layout.marginWidth = 0;
layout.marginHeight = 0;
infoGroup.setLayout(layout);
infoGroup.setLayout(new GridLayout());
if (SWT.getVersion() < 3105) { // screws up scrolling on 3.2M2
infoGroup.addControlListener(new Utils.LabelWrapControlListener());
}
String sep = System.getProperty("file.separator");
File fUserPluginDir = FileUtil.getUserFile("plugins");
String sUserPluginDir;
try{
sUserPluginDir = fUserPluginDir.getCanonicalPath();
}catch( Throwable e ){
sUserPluginDir = fUserPluginDir.toString();
}
if (!sUserPluginDir.endsWith(sep)) {
sUserPluginDir += sep;
}
File fAppPluginDir = FileUtil.getApplicationFile("plugins");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -