📄 configview.java
字号:
initSaveButton();
TreeItem[] items = { tree.getItems()[0] };
tree.setSelection(items);
// setSelection doesn't trigger a SelectionListener, so..
showSection(items[0]);
}
/**
* @param text
*/
protected void filterTree(String text) {
filterText = text;
if (filterDelayTimer != null) {
filterDelayTimer.destroy();
}
if (lblX != null && !lblX.isDisposed()) {
Image img = ImageRepository.getImage(filterText.length() > 0 ? "smallx"
: "smallx-gray");
lblX.setImage(img);
}
filterDelayTimer = new Timer("Filter");
filterDelayTimer.addEvent(SystemTime.getCurrentTime() + 300,
new TimerEventPerformer() {
public void perform(TimerEvent event) {
filterDelayTimer.destroy();
filterDelayTimer = null;
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
// TODO Auto-generated method stub
ArrayList foundItems = new ArrayList();
TreeItem[] items = tree.getItems();
try {
tree.setRedraw(false);
for (int i = 0; i < items.length; i++) {
items[i].setExpanded(false);
}
filterTree(items, filterText, foundItems);
} finally {
tree.setRedraw(true);
}
}
});
}
});
}
protected void filterTree(TreeItem[] items, String text, ArrayList foundItems)
{
text = text.toLowerCase();
for (int i = 0; i < items.length; i++) {
ensureSectionBuilt(items[i]);
ScrolledComposite composite = (ScrolledComposite) items[i].getData("Panel");
if (text.length() > 0
&& (items[i].getText().toLowerCase().indexOf(text) >= 0 || compositeHasText(
composite, text))) {
foundItems.add(items[i]);
ensureExpandedTo(items[i]);
items[i].setFont(filterFoundFont);
} else {
items[i].setFont(null);
}
filterTree(items[i].getItems(), text, foundItems);
}
}
private void ensureExpandedTo(TreeItem item) {
TreeItem itemParent = item.getParentItem();
if (itemParent != null) {
itemParent.setExpanded(true);
ensureExpandedTo(itemParent);
}
}
/**
* @param composite
* @param text
* @return
*/
private boolean compositeHasText(Composite composite, String text) {
Control[] children = composite.getChildren();
for (int i = 0; i < children.length; i++) {
Control child = children[i];
if (child instanceof Label) {
if (((Label)child).getText().toLowerCase().indexOf(text) >= 0) {
return true;
}
} else if (child instanceof Group) {
if (((Group)child).getText().toLowerCase().indexOf(text) >= 0) {
return true;
}
} else if (child instanceof Button) {
if (((Button)child).getText().toLowerCase().indexOf(text) >= 0) {
return true;
}
}
if (child instanceof Composite) {
if (compositeHasText((Composite) child, text)) {
return true;
}
}
}
return false;
}
private void showSection(TreeItem section) {
ScrolledComposite item = (ScrolledComposite)section.getData("Panel");
if (item != null) {
ensureSectionBuilt(section);
layoutConfigSection.topControl = item;
Composite c = (Composite)item.getContent();
item.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT));
cConfigSection.layout();
updateHeader(section);
}
}
private void ensureSectionBuilt(TreeItem section) {
ScrolledComposite item = (ScrolledComposite)section.getData("Panel");
if (item != null) {
ConfigSection configSection = (ConfigSection)section.getData("ConfigSectionSWT");
if (configSection != null) {
Control previous = item.getContent();
if (previous instanceof Composite) {
configSection.configSectionDelete();
Utils.disposeComposite((Composite)previous,true);
}
Composite c;
if ( configSection instanceof ConfigSectionSWT ){
c = ((ConfigSectionSWT)configSection).configSectionCreate(item);
}else{
c = ((UISWTConfigSection)configSection).configSectionCreate(item);
}
item.setContent(c);
}
}
}
private void updateHeader(TreeItem section) {
if (section == null)
return;
String sHeader = section.getText();
section = section.getParentItem();
while (section != null) {
sHeader = section.getText() + " : " + sHeader;
section = section.getParentItem();
}
lHeader.setText(" " + sHeader.replaceAll("&", "&&"));
}
private Composite createConfigSection(String sNameID) {
return createConfigSection(null, sNameID, -1, true);
}
private Composite createConfigSection(String sNameID, int position) {
return createConfigSection(null, sNameID, position, true);
}
public Composite createConfigSection(TreeItem treeItemParent,
String sNameID,
int position,
boolean bPrefix) {
ScrolledComposite sc = new ScrolledComposite(cConfigSection, SWT.H_SCROLL | SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setLayoutData(new GridData(GridData.FILL_BOTH));
sc.getVerticalBar().setIncrement(16);
sc.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event event) {
ScrolledComposite sc = (ScrolledComposite)event.widget;
sc.getVerticalBar().setPageIncrement(sc.getSize().y);
}
});
Composite cConfigSection = new Composite(sc, SWT.NULL);
String section_key = ((bPrefix) ? sSectionPrefix : "") + sNameID;
if (position == -2) { // Means "auto-order".
position = findInsertPointFor(MessageText.getString(section_key), (treeItemParent == null) ? (Object)tree : (Object)treeItemParent);
}
TreeItem treeItem;
if (treeItemParent == null) {
if (position >= 0)
treeItem = new TreeItem(tree, SWT.NULL, position);
else
treeItem = new TreeItem(tree, SWT.NULL);
} else {
if (position >= 0)
treeItem = new TreeItem(treeItemParent, SWT.NULL, position);
else
treeItem = new TreeItem(treeItemParent, SWT.NULL);
}
Messages.setLanguageText(treeItem, section_key);
treeItem.setData("Panel", sc);
treeItem.setData("ID", sNameID);
sc.setContent(cConfigSection);
return cConfigSection;
}
private static Comparator insert_point_comparator = new Comparator() {
private String asString(Object o) {
if (o instanceof String) {
return (String)o;
}
else if (o instanceof TreeItem) {
return ((TreeItem)o).getText();
}
else {
throw new ClassCastException("object is not String or TreeItem: " + o.getClass().getName());
}
}
public int compare(Object o1, Object o2) {
int result = String.CASE_INSENSITIVE_ORDER.compare(asString(o1), asString(o2));
return result;
}
};
public static int findInsertPointFor(String name, Object structure) {
TreeItem[] children = null;
if (structure instanceof Tree) {
children = ((Tree)structure).getItems();
}
else {
children = ((TreeItem)structure).getItems();
}
if (children.length == 0) {return -1;}
int result = Arrays.binarySearch(children, name, insert_point_comparator);
if (result > 0) {return result;}
result = -(result+1);
if (result == children.length) {
result = -1;
}
return result;
}
public TreeItem findTreeItem(String ID) {
return findTreeItem((Tree)null, ID);
}
private TreeItem findTreeItem(Tree tree, String ID) {
if (tree == null)
tree = this.tree;
TreeItem[] items = tree.getItems();
for (int i = 0; i < items.length; i++) {
String itemID = (String)items[i].getData("ID");
if (itemID != null && itemID.equalsIgnoreCase(ID)) {
return items[i];
}
TreeItem itemFound = findTreeItem(items[i], ID);
if (itemFound != null)
return itemFound;
}
return null;
}
private TreeItem findTreeItem(TreeItem item, String ID) {
TreeItem[] subItems = item.getItems();
for (int i = 0; i < subItems.length; i++) {
String itemID = (String)subItems[i].getData("ID");
if (itemID != null && itemID.equalsIgnoreCase(ID)) {
return subItems[i];
}
TreeItem itemFound = findTreeItem(subItems[i], ID);
if (itemFound != null)
return itemFound;
}
return null;
}
private void initSaveButton() {
GridData gridData;
final Button save = new Button(cConfig, SWT.PUSH);
Messages.setLanguageText(save, "ConfigView.button.save"); //$NON-NLS-1$
gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gridData.horizontalSpan = 2;
gridData.widthHint = 80;
save.setLayoutData(gridData);
save.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
// force focusout on osx
save.setFocus();
COConfigurationManager.setParameter("updated", 1);
COConfigurationManager.save();
for (int i = 0; i < pluginSections.size(); i++)
((ConfigSection) pluginSections.get(i)).configSectionSave();
}
});
}
/* (non-Javadoc)
* @see org.gudy.azureus2.ui.swt.IView#getComposite()
*/
public Composite getComposite() {
return cConfig;
}
public void updateLanguage() {
super.updateLanguage();
updateHeader(tree.getSelection()[0]);
// cConfig.setSize(cConfig.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
public void delete() {
for (int i = 0; i < pluginSections.size(); i++)
((ConfigSection)pluginSections.get(i)).configSectionDelete();
pluginSections.clear();
if(! tree.isDisposed()) {
TreeItem[] items = tree.getItems();
for (int i = 0; i < items.length; i++) {
Composite c = (Composite)items[i].getData("Panel");
Utils.disposeComposite(c);
items[i].setData("Panel", null);
items[i].setData("ConfigSectionSWT", null);
}
}
Utils.disposeComposite(cConfig);
Utils.disposeSWTObjects(new Object[] { headerFont, filterFoundFont });
headerFont = null;
filterFoundFont = null;
}
public String getFullTitle() {
return MessageText.getString("ConfigView.title.full"); //$NON-NLS-1$
}
public boolean selectSection(String id) {
TreeItem ti = findTreeItem(id);
if (ti == null)
return false;
tree.setSelection(new TreeItem[] { ti });
showSection(ti);
return true;
}
public void
selectSection(
Class config_section_class )
{
TreeItem[] items = tree.getItems();
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 );
break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -