use of com.biglybt.pif.ui.config.ConfigSection in project BiglyBT by BiglySoftware.
the class ConfigView method delete.
private void delete() {
for (ConfigSection section : sectionsCreated) {
try {
section.configSectionDelete();
} catch (Exception e) {
Debug.out("Error while deleting config section", e);
}
}
sectionsCreated.clear();
if (pluginSections != null) {
pluginSections.clear();
}
if (tree != null) {
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;
}
use of com.biglybt.pif.ui.config.ConfigSection in project BiglyBT by BiglySoftware.
the class ConfigView method updateHeader.
private void updateHeader(TreeItem section) {
if (section == null)
return;
lHeader.setData("TreeItem", section);
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) {
// Debug.printStackTrace(e);
}
String id = (String) section.getData("ID");
String shortcut = COConfigurationManager.getStringParameter("config.section.shortcut.key." + id, null);
String sc_text;
if (shortcut != null && shortcut.length() > 0) {
sc_text = " (Ctrl+" + shortcut.charAt(0) + ")";
} else {
sc_text = "";
}
if (userMode < maxUsermode)
Messages.setLanguageText(usermodeHint, "ConfigView.higher.mode.available");
else
usermodeHint.setText("");
String sHeader = section.getText();
section = section.getParentItem();
while (section != null) {
sHeader = section.getText() + " : " + sHeader;
section = section.getParentItem();
}
lHeader.setText(" " + sHeader.replaceAll("&", "&&") + sc_text);
lHeader.getParent().layout(true, true);
}
use of com.biglybt.pif.ui.config.ConfigSection in project BiglyBT by BiglySoftware.
the class ConfigView method ensureSectionBuilt.
private void ensureSectionBuilt(TreeItem treeSection, boolean recreateIfAlreadyThere) {
ScrolledComposite item = (ScrolledComposite) treeSection.getData("Panel");
if (item != null) {
ConfigSection configSection = (ConfigSection) treeSection.getData("ConfigSectionSWT");
if (configSection != null) {
Control previous = item.getContent();
if (previous instanceof Composite) {
if (!recreateIfAlreadyThere) {
return;
}
configSection.configSectionDelete();
sectionsCreated.remove(configSection);
Utils.disposeComposite((Composite) previous, true);
}
Composite c = ((UISWTConfigSection) configSection).configSectionCreate(item);
sectionsCreated.add(configSection);
item.setContent(c);
}
}
}
use of com.biglybt.pif.ui.config.ConfigSection in project BiglyBT by BiglySoftware.
the class ConfigView method _initialize.
private void _initialize(final Composite composite) {
GridData gridData;
/*
/--cConfig-----------------------------------------------------------\
| ###SashForm#form################################################## |
| # /--cLeftSide-\ /--cRightSide---------------------------------\ # |
| # | ##tree#### | | ***cHeader********************************* | # |
| # | # # | | * lHeader usermodeHint * | # |
| # | # # | | ******************************************* | # |
| # | # # | | ###Composite cConfigSection################ | # |
| # | # # | | # # | # |
| # | # # | | # # | # |
| # | # # | | # # | # |
| # | ########## | | # # | # |
| # |txtFilter X | | ########################################### | # |
| # \------------/ \---------------------------------------------/ # |
| ################################################################## |
| [Buttons] |
\--------------------------------------------------------------------/
*/
try {
Display d = composite.getDisplay();
GridLayout configLayout;
SashForm form = new SashForm(cConfig, SWT.HORIZONTAL);
gridData = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(form, gridData);
Composite cLeftSide = new Composite(form, SWT.BORDER);
gridData = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(cLeftSide, gridData);
FormLayout layout = new FormLayout();
cLeftSide.setLayout(layout);
Composite cFilterArea = new Composite(cLeftSide, SWT.NONE);
cFilterArea.setLayout(new FormLayout());
final Text txtFilter = new Text(cFilterArea, SWT.BORDER);
txtFilter.setMessage(MessageText.getString("ConfigView.filter"));
txtFilter.selectAll();
txtFilter.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
filterTree(txtFilter.getText());
}
});
ImageLoader imageLoader = ImageLoader.getInstance();
imgSmallXGray = imageLoader.getImage("smallx-gray");
imgSmallX = imageLoader.getImage("smallx");
lblX = new Label(cFilterArea, SWT.WRAP);
Messages.setLanguageTooltip(lblX, "MyTorrentsView.clearFilter.tooltip");
lblX.setImage(imgSmallXGray);
lblX.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
txtFilter.setText("");
}
});
lblX.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent arg0) {
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.releaseImage("smallx-gray");
imageLoader.releaseImage("smallx");
}
});
Label lblSearch = new Label(cFilterArea, SWT.NONE);
imageLoader.setLabelImage(lblSearch, "search");
tree = new Tree(cLeftSide, SWT.NONE);
FontData[] fontData = tree.getFont().getFontData();
fontData[0].setStyle(SWT.BOLD);
filterFoundFont = new Font(d, fontData);
FormData formData;
formData = new FormData();
formData.bottom = new FormAttachment(100, -5);
formData.left = new FormAttachment(0, 0);
formData.right = new FormAttachment(100, 0);
Utils.setLayoutData(cFilterArea, formData);
formData = new FormData();
formData.top = new FormAttachment(txtFilter, 0, SWT.CENTER);
formData.left = new FormAttachment(0, 5);
Utils.setLayoutData(lblSearch, formData);
formData = new FormData();
formData.top = new FormAttachment(0, 5);
formData.left = new FormAttachment(lblSearch, 5);
formData.right = new FormAttachment(lblX, -3);
Utils.setLayoutData(txtFilter, formData);
formData = new FormData();
formData.top = new FormAttachment(0, 5);
formData.right = new FormAttachment(100, -5);
Utils.setLayoutData(lblX, formData);
formData = new FormData();
formData.top = new FormAttachment(0, 0);
formData.left = new FormAttachment(0, 0);
formData.right = new FormAttachment(100, 0);
formData.bottom = new FormAttachment(cFilterArea, -1);
Utils.setLayoutData(tree, formData);
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;
configLayout.numColumns = 2;
configLayout.marginRight = 5;
cHeader.setLayout(configLayout);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
Utils.setLayoutData(cHeader, gridData);
cHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
cHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
lHeader = new Label(cHeader, SWT.NULL);
lHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
lHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
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.VERTICAL_ALIGN_CENTER | GridData.HORIZONTAL_ALIGN_BEGINNING);
Utils.setLayoutData(lHeader, gridData);
usermodeHint = new Label(cHeader, SWT.NULL);
usermodeHint.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
usermodeHint.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
gridData = new GridData(GridData.VERTICAL_ALIGN_CENTER | GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL);
Utils.setLayoutData(usermodeHint, gridData);
Menu headerMenu = new Menu(cHeader.getShell(), SWT.POP_UP);
final MenuItem menuShortCut = new MenuItem(headerMenu, SWT.PUSH);
Messages.setLanguageText(menuShortCut, "label.set.shortcut");
menuShortCut.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
final TreeItem tree_item = (TreeItem) lHeader.getData("TreeItem");
if (tree_item != null) {
final String id = (String) tree_item.getData("ID");
if (id != null) {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("config.dialog.shortcut.title", "config.dialog.shortcut.text");
entryWindow.setPreenteredText(COConfigurationManager.getStringParameter("config.section.shortcut.key." + id, ""), false);
entryWindow.setTextLimit(1);
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
if (!entryWindow.hasSubmittedInput()) {
return;
}
String sReturn = entryWindow.getSubmittedInput();
if (sReturn != null) {
sReturn = sReturn.trim();
if (sReturn.length() > 1) {
sReturn = sReturn.substring(0, 1);
}
COConfigurationManager.setParameter("config.section.shortcut.key." + id, sReturn);
updateHeader(tree_item);
}
}
});
}
}
}
});
cHeader.setMenu(headerMenu);
lHeader.setMenu(headerMenu);
usermodeHint.setMenu(headerMenu);
// Config Section
cConfigSection = new Composite(cRightSide, SWT.NULL);
layoutConfigSection = new StackLayout();
cConfigSection.setLayout(layoutConfigSection);
gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalIndent = 2;
Utils.setLayoutData(cConfigSection, gridData);
form.setWeights(new int[] { 20, 80 });
tree.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Tree tree = (Tree) e.getSource();
// and you close its parent.
if (tree.getSelection().length > 0)
showSection(tree.getSelection()[0], false);
}
});
// Double click = expand/contract branch
tree.addListener(SWT.DefaultSelection, new Listener() {
@Override
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));
}
scResizeListener = new Listener() {
@Override
public void handleEvent(Event event) {
setupSC((ScrolledComposite) event.widget);
}
};
// 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 ConfigSectionMode(), new ConfigSectionStartShutdown(), new ConfigSectionBackupRestore(), new ConfigSectionConnection(), new ConfigSectionConnectionProxy(), new ConfigSectionConnectionAdvanced(), new ConfigSectionConnectionEncryption(), new ConfigSectionConnectionDNS(), new ConfigSectionTransfer(), new ConfigSectionTransferAutoSpeedSelect(), new ConfigSectionTransferAutoSpeed(), new ConfigSectionTransferAutoSpeedBeta(), new ConfigSectionTransferLAN(), new ConfigSectionFile(), new ConfigSectionFileMove(), new ConfigSectionFileTorrents(), new ConfigSectionFileTorrentsDecoding(), new ConfigSectionFilePerformance(), new ConfigSectionInterface(), new ConfigSectionInterfaceLanguage(), new ConfigSectionInterfaceStart(), new ConfigSectionInterfaceDisplay(), new ConfigSectionInterfaceTables(), new ConfigSectionInterfaceColor(), new ConfigSectionInterfaceAlerts(), new ConfigSectionInterfacePassword(), new ConfigSectionInterfaceLegacy(), new ConfigSectionIPFilter(), new ConfigSectionPlugins(this), new ConfigSectionStats(), new ConfigSectionTracker(), new ConfigSectionTrackerClient(), new ConfigSectionTrackerServer(), 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 = pluginSections.get(i);
if (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";
}
String section_key = name;
if (plugin_section) {
if (!MessageText.keyExists(section_key)) {
section_key = sSectionPrefix + name;
}
} else {
section_key = sSectionPrefix + name;
}
String section_name = MessageText.getString(section_key);
try {
TreeItem treeItem;
String location = section.configSectionGetParentSection();
if (location.length() == 0 || location.equalsIgnoreCase(ConfigSection.SECTION_ROOT)) {
// int position = findInsertPointFor(section_name, tree);
// if ( position == -1 ){
treeItem = new TreeItem(tree, SWT.NULL);
// }else{
// treeItem = new TreeItem(tree, SWT.NULL, position);
// }
} else {
TreeItem treeItemFound = findTreeItem(tree, location);
if (treeItemFound != null) {
if (location.equalsIgnoreCase(ConfigSection.SECTION_PLUGINS)) {
// Force ordering by name here.
int position = findInsertPointFor(section_name, treeItemFound);
if (position == -1) {
treeItem = new TreeItem(treeItemFound, SWT.NULL);
} else {
treeItem = new TreeItem(treeItemFound, SWT.NULL, position);
}
} else {
treeItem = new TreeItem(treeItemFound, SWT.NULL);
}
} else {
treeItem = new TreeItem(tree, SWT.NULL);
}
}
ScrolledComposite sc = new ScrolledComposite(cConfigSection, SWT.H_SCROLL | SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
Utils.setLayoutData(sc, new GridData(GridData.FILL_BOTH));
sc.getVerticalBar().setIncrement(16);
sc.addListener(SWT.Resize, scResizeListener);
if (i == 0) {
Composite c = ((UISWTConfigSection) section).configSectionCreate(sc);
sectionsCreated.add(section);
sc.setContent(c);
}
Messages.setLanguageText(treeItem, section_key);
treeItem.setData("Panel", sc);
treeItem.setData("ID", name);
treeItem.setData("ConfigSectionSWT", section);
sections.put(treeItem, section);
// PluginConfigModel config pages
if (section instanceof ConfigSectionPlugins)
((ConfigSectionPlugins) section).initPluginSubSections();
} catch (Exception e) {
Logger.log(new LogEvent(LOGID, "ConfigSection plugin '" + name + "' caused an error", e));
}
}
}
final Display d = composite.getDisplay();
final Listener shortcut_listener = new Listener() {
@Override
public void handleEvent(Event e) {
if ((e.stateMask & (SWT.MOD1 | SWT.CONTROL)) != 0 || e.keyCode == SWT.COMMAND) {
char key = e.character;
if (key <= 26 && key > 0) {
key += 'a' - 1;
}
if ((e.stateMask & SWT.SHIFT) != 0) {
key = Character.toUpperCase(key);
}
if (!Character.isISOControl(key)) {
for (TreeItem ti : sections.keySet()) {
if (ti.isDisposed()) {
continue;
}
String id = (String) ti.getData("ID");
if (id != null) {
String shortcut = COConfigurationManager.getStringParameter("config.section.shortcut.key." + id, "");
if (shortcut.equals(String.valueOf(key))) {
// findFocus( cConfig );
selectSection(id, true);
e.doit = false;
break;
}
}
}
}
}
}
};
d.addFilter(SWT.KeyDown, shortcut_listener);
cConfigSection.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
d.removeFilter(SWT.KeyDown, shortcut_listener);
}
});
if (composite instanceof Shell) {
initApplyCloseButton();
} else {
initSaveButton();
}
if (startSection != null) {
if (selectSection(startSection, false)) {
return;
}
}
TreeItem selection = getLatestSelection();
TreeItem[] items = { selection };
tree.setSelection(items);
// setSelection doesn't trigger a SelectionListener, so..
showSection(selection, false);
}
Aggregations