📄 configview.java
字号:
/*
* Created on 2 juil. 2003
* Copyright (C) 2003, 2004, 2005, 2006 Aelitis, 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, or (at your option) any later version.
* 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.
* 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;
import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.internat.MessageText;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.plugins.ui.config.ConfigSection;
import org.gudy.azureus2.plugins.ui.config.ConfigSectionSWT;
import org.gudy.azureus2.pluginsimpl.local.ui.config.ConfigSectionRepository;
import org.gudy.azureus2.ui.swt.Messages;
import org.gudy.azureus2.ui.swt.Utils;
import org.gudy.azureus2.ui.swt.mainwindow.MainWindow;
import org.gudy.azureus2.ui.swt.plugins.UISWTConfigSection;
import org.gudy.azureus2.ui.swt.views.configsections.*;
import com.aelitis.azureus.core.AzureusCore;
/**
* @author Olivier
*
*/
public class ConfigView extends AbstractIView {
private static final LogIDs LOGID = LogIDs.GUI;
public static final String sSectionPrefix = "ConfigView.section.";
AzureusCore azureus_core;
Composite cConfig;
Composite cConfigSection;
StackLayout layoutConfigSection;
Label lHeader;
Font headerFont;
Tree tree;
TreeItem treePlugins;
ArrayList pluginSections;
/**
* Main Initializer
*
* @param _azureus_core
*/
public
ConfigView(
AzureusCore _azureus_core )
{
azureus_core = _azureus_core;
}
/* (non-Javadoc)
* @see org.gudy.azureus2.ui.swt.IView#initialize(org.eclipse.swt.widgets.Composite)
*/
public void initialize(Composite composite) {
GridData gridData;
/*
/--cConfig-------------------------------------------------------\
| ###SashForm#form############################################## |
| # /--tree--\ /--cRightSide---------------------------------\ # |
| # | | | ***cHeader********************************* | # |
| # | | | * lHeader * | # |
| # | | | ******************************************* | # |
| # | | | ###Composite cConfigSection################ | # |
| # | | | # # | # |
| # | | | # # | # |
| # | | | # # | # |
| # | | | # # | # |
| # | | | ########################################### | # |
| # \--------/ \---------------------------------------------/ # |
| ############################################################## |
| [Button] |
\----------------------------------------------------------------/
*/
try {
cConfig = new Composite(composite, SWT.NONE);
GridLayout configLayout = new GridLayout();
configLayout.marginHeight = 0;
configLayout.marginWidth = 0;
cConfig.setLayout(configLayout);
gridData = new GridData(GridData.FILL_BOTH);
cConfig.setLayoutData(gridData);
SashForm form = new SashForm(cConfig,SWT.HORIZONTAL);
gridData = new GridData(GridData.FILL_BOTH);
form.setLayoutData(gridData);
tree = new Tree(form, SWT.BORDER);
tree.setLayout(new FillLayout());
Composite cRightSide = new Composite(form, SWT.NULL);
configLayout = new GridLayout();
configLayout.marginHeight = 3;
configLayout.marginWidth = 0;
cRightSide.setLayout(configLayout);
// Header
Composite cHeader = new Composite(cRightSide, SWT.BORDER);
configLayout = new GridLayout();
configLayout.marginHeight = 3;
configLayout.marginWidth = 0;
cHeader.setLayout(configLayout);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
cHeader.setLayoutData(gridData);
Display d = cRightSide.getDisplay();
cHeader.setBackground(d.getSystemColor(SWT.COLOR_LIST_SELECTION));
cHeader.setForeground(d.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
lHeader = new Label(cHeader, SWT.NULL);
lHeader.setBackground(d.getSystemColor(SWT.COLOR_LIST_SELECTION));
lHeader.setForeground(d.getSystemColor(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);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
lHeader.setLayoutData(gridData);
// Config Section
cConfigSection = new Composite(cRightSide, SWT.NULL);
layoutConfigSection = new StackLayout();
cConfigSection.setLayout(layoutConfigSection);
gridData = new GridData(GridData.FILL_BOTH);
cConfigSection.setLayoutData(gridData);
form.setWeights(new int[] {20,80});
tree.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
Tree tree = (Tree)e.getSource();
//Check that at least an item is selected
//OSX lets you select nothing in the tree for example when a child is selected
//and you close its parent.
if(tree.getSelection().length > 0)
showSection(tree.getSelection()[0]);
}
});
// Double click = expand/contract branch
tree.addListener(SWT.DefaultSelection, new Listener() {
public void handleEvent(Event e) {
TreeItem item = (TreeItem)e.item;
if (item != null)
item.setExpanded(!item.getExpanded());
}
});
} catch (Exception e) {
Logger.log(new LogEvent(LOGID, "Error initializing ConfigView", e));
}
// Add sections
/** How to add a new section
* 1) Create a new implementation of ConfigSectionSWT in a new file
* (Use the ConfigSectionTMP.java as a template if it's still around)
* 2) import it into here
* 3) add it to the internal sections list
*/
pluginSections = ConfigSectionRepository.getInstance().getList();
ConfigSection[] internalSections = { new ConfigSectionConnection(),
new ConfigSectionConnectionProxy(),
new ConfigSectionConnectionAdvanced(),
new ConfigSectionConnectionEncryption(),
new ConfigSectionTransfer(),
new ConfigSectionTransferLAN(),
new ConfigSectionFile(),
new ConfigSectionFileTorrents(),
new ConfigSectionFilePerformance(),
new ConfigSectionInterface(),
new ConfigSectionInterfaceLanguage(),
new ConfigSectionInterfaceStart(),
new ConfigSectionInterfaceDisplay(),
new ConfigSectionInterfaceColor(),
new ConfigSectionMode(),
new ConfigSectionIPFilter(azureus_core),
new ConfigSectionPlugins(this, azureus_core),
new ConfigSectionStats(),
new ConfigSectionTracker(azureus_core),
new ConfigSectionTrackerClient(),
new ConfigSectionTrackerServer(azureus_core),
new ConfigSectionSecurity(),
new ConfigSectionSharing(),
new ConfigSectionLogging()
};
pluginSections.addAll(0, Arrays.asList(internalSections));
for (int i = 0; i < pluginSections.size(); i++) {
// slip the non-standard "plugins" initialisation inbetween the internal ones
// and the plugin ones so plugin ones can be children of it
boolean plugin_section = i >= internalSections.length;
ConfigSection section = (ConfigSection)pluginSections.get(i);
if (section instanceof ConfigSectionSWT || section instanceof UISWTConfigSection ) {
String name;
try {
name = section.configSectionGetName();
} catch (Exception e) {
Logger.log(new LogEvent(LOGID, "A ConfigSection plugin caused an "
+ "error while trying to call its "
+ "configSectionGetName function", e));
name = "Bad Plugin";
}
try {
TreeItem treeItem = null;
String location = section.configSectionGetParentSection();
if (location.equalsIgnoreCase(ConfigSection.SECTION_ROOT))
treeItem = new TreeItem(tree, SWT.NULL);
else if (location != "") {
TreeItem treeItemFound = findTreeItem(tree, location);
if (treeItemFound != null)
treeItem = new TreeItem(treeItemFound, SWT.NULL);
}
if (treeItem == null)
treeItem = new TreeItem(treePlugins, SWT.NULL);
ScrolledComposite sc = new ScrolledComposite(cConfigSection, SWT.H_SCROLL | SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setLayoutData(new GridData(GridData.FILL_BOTH));
if(i == 0) {
Composite c;
if ( section instanceof ConfigSectionSWT ){
c = ((ConfigSectionSWT)section).configSectionCreate(sc);
}else{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -