use of com.biglybt.ui.swt.SimpleTextEntryWindow in project BiglyBT by BiglySoftware.
the class TagUIUtils method createSideBarMenuItems.
public static void createSideBarMenuItems(final Menu menu, final Tag tag) {
int userMode = COConfigurationManager.getIntParameter("User Mode");
final TagType tag_type = tag.getTagType();
boolean needs_separator_next = false;
int countBefore = menu.getItemCount();
if (tag_type.hasTagTypeFeature(TagFeature.TF_RATE_LIMIT)) {
createTF_RateLimitMenuItems(menu, tag, tag_type, userMode);
}
if (tag_type.hasTagTypeFeature(TagFeature.TF_RUN_STATE)) {
createTF_RunState(menu, tag);
}
if (tag_type.hasTagTypeFeature(TagFeature.TF_FILE_LOCATION)) {
createTF_FileLocationMenuItems(menu, tag);
}
if (tag_type.hasTagTypeFeature(TagFeature.TF_EXEC_ON_ASSIGN)) {
final TagFeatureExecOnAssign tf_eoa = (TagFeatureExecOnAssign) tag;
int supported_actions = tf_eoa.getSupportedActions();
if (supported_actions != TagFeatureExecOnAssign.ACTION_NONE) {
final Menu eoa_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
MenuItem eoa_item = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(eoa_item, "label.exec.on.assign");
eoa_item.setMenu(eoa_menu);
int[] action_ids = { TagFeatureExecOnAssign.ACTION_APPLY_OPTIONS_TEMPLATE, TagFeatureExecOnAssign.ACTION_DESTROY, TagFeatureExecOnAssign.ACTION_START, TagFeatureExecOnAssign.ACTION_FORCE_START, TagFeatureExecOnAssign.ACTION_NOT_FORCE_START, TagFeatureExecOnAssign.ACTION_STOP, TagFeatureExecOnAssign.ACTION_PAUSE, TagFeatureExecOnAssign.ACTION_RESUME, TagFeatureExecOnAssign.ACTION_SCRIPT };
String[] action_keys = { "label.apply.options.template", "v3.MainWindow.button.delete", "v3.MainWindow.button.start", "v3.MainWindow.button.forcestart", "v3.MainWindow.button.notforcestart", "v3.MainWindow.button.stop", "v3.MainWindow.button.pause", "v3.MainWindow.button.resume", "label.script" };
for (int i = 0; i < action_ids.length; i++) {
final int action_id = action_ids[i];
if (tf_eoa.supportsAction(action_id)) {
if (action_id == TagFeatureExecOnAssign.ACTION_APPLY_OPTIONS_TEMPLATE) {
final MenuItem opts_item = new MenuItem(eoa_menu, SWT.CHECK);
opts_item.setText(MessageText.getString(action_keys[i]) + "...");
opts_item.setSelection(tf_eoa.getOptionsTemplateHandler().isActive());
opts_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, tf_eoa.getOptionsTemplateHandler());
}
}
});
new MenuItem(eoa_menu, SWT.SEPARATOR);
} else if (action_id == TagFeatureExecOnAssign.ACTION_SCRIPT) {
final MenuItem action_item = new MenuItem(eoa_menu, SWT.PUSH);
String script = tf_eoa.getActionScript();
if (script.length() > 23) {
script = script.substring(0, 20) + "...";
}
String msg = MessageText.getString(action_keys[i]);
if (script.length() > 0) {
msg += ": " + script;
}
msg += "...";
action_item.setText(msg);
action_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
String msg = MessageText.getString("UpdateScript.message");
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("UpdateScript.title", "!" + msg + "!");
entryWindow.setPreenteredText(tf_eoa.getActionScript(), false);
entryWindow.selectPreenteredText(true);
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
if (entryWindow.hasSubmittedInput()) {
String text = entryWindow.getSubmittedInput().trim();
tf_eoa.setActionScript(text);
}
}
});
}
});
} else {
final MenuItem action_item = new MenuItem(eoa_menu, SWT.CHECK);
Messages.setLanguageText(action_item, action_keys[i]);
action_item.setSelection(tf_eoa.isActionEnabled(action_id));
action_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
tf_eoa.setActionEnabled(action_id, action_item.getSelection());
}
});
}
}
}
}
}
if (tag instanceof TagDownload) {
needs_separator_next = true;
MenuItem itemOptions = new MenuItem(menu, SWT.PUSH);
final Set<DownloadManager> dms = ((TagDownload) tag).getTaggedDownloads();
Messages.setLanguageText(itemOptions, "cat.options");
itemOptions.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, dms.toArray(new DownloadManager[dms.size()]));
}
}
});
if (dms.size() == 0) {
itemOptions.setEnabled(false);
}
}
if (userMode > 0) {
if (tag_type.hasTagTypeFeature(TagFeature.TF_PROPERTIES)) {
createTFProperitesMenuItems(menu, tag);
}
}
if (menu.getItemCount() > countBefore) {
needs_separator_next = true;
}
if (needs_separator_next) {
new MenuItem(menu, SWT.SEPARATOR);
needs_separator_next = false;
}
if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
needs_separator_next = true;
MenuItem search = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(search, "tag.search");
search.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
UIFunctionsManager.getUIFunctions().doSearch("tag:" + tag.getTagName(true));
}
});
}
// share with friends
addShareWithFriendsMenuItems(menu, tag, tag_type);
if (tag_type.hasTagTypeFeature(TagFeature.TF_RSS_FEED)) {
final TagFeatureRSSFeed tfrss = (TagFeatureRSSFeed) tag;
// rss feed
final MenuItem rssOption = new MenuItem(menu, SWT.CHECK);
rssOption.setSelection(tfrss.isTagRSSFeedEnabled());
Messages.setLanguageText(rssOption, "cat.rss.gen");
rssOption.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
boolean set = rssOption.getSelection();
tfrss.setTagRSSFeedEnabled(set);
}
});
}
if (tag_type.hasTagTypeFeature(TagFeature.TF_XCODE)) {
createXCodeMenuItems(menu, tag);
}
needs_separator_next = true;
if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
MenuBuildUtils.addChatMenu(menu, "label.chat", getChatKey(tag));
}
MenuItem itemShowStats = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemShowStats, "tag.show.stats");
itemShowStats.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
uiFunctions.getMDI().loadEntryByID(StatsView.VIEW_ID, true, false, "TagStatsView");
}
});
if (tag.getTaggableTypes() == Taggable.TT_DOWNLOAD) {
MenuItem itemShowFiles = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemShowFiles, "menu.show.files");
itemShowFiles.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
showFilesView((TagDownload) tag);
}
});
}
if (needs_separator_next) {
new MenuItem(menu, SWT.SEPARATOR);
needs_separator_next = false;
}
boolean auto = tag_type.isTagTypeAuto();
boolean closable = auto;
if (tag.getTaggableTypes() == Taggable.TT_DOWNLOAD) {
// extended closable tags to include manual ones due to user request
closable = true;
}
Menu[] menuShowHide = { null };
if (closable) {
createCloseableMenuItems(menu, tag, tag_type, menuShowHide, needs_separator_next);
}
if (!auto) {
createNonAutoMenuItems(menu, tag, tag_type, menuShowHide);
}
if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
MenuItem itemExport = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemExport, "Subscription.menu.export");
itemExport.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
export(Arrays.asList(tag));
}
});
}
MenuItem menuSettings = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(menuSettings, "TagSettingsView.title");
menuSettings.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TAGS, tag);
}
});
com.biglybt.pif.ui.menus.MenuItem[] items = MenuItemManager.getInstance().getAllAsArray(MenuManager.MENU_TAG_CONTEXT);
if (items.length > 0) {
MenuFactory.addSeparatorMenuItem(menu);
// TODO: Don't send Tag.. send a yet-to-be-created plugin interface version of Tag
MenuBuildUtils.addPluginMenuItems(items, menu, true, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Tag[] { tag }));
}
}
use of com.biglybt.ui.swt.SimpleTextEntryWindow in project BiglyBT by BiglySoftware.
the class CategoryUIUtils method showCreateCategoryDialog.
public static void showCreateCategoryDialog(final UIFunctions.TagReturner tagReturner) {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("CategoryAddWindow.title", "CategoryAddWindow.message");
entryWindow.setParentShell(Utils.findAnyShell());
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
if (entryWindow.hasSubmittedInput()) {
TagUIUtils.checkTagSharing(false);
Category newCategory = CategoryManager.createCategory(entryWindow.getSubmittedInput());
if (tagReturner != null) {
tagReturner.returnedTags(new Tag[] { newCategory });
}
}
}
});
}
use of com.biglybt.ui.swt.SimpleTextEntryWindow in project BiglyBT by BiglySoftware.
the class BuddyPluginView method buildMenu.
private void buildMenu(final Set<ChatInstance> current_instances) {
if (menu_items.size() == 0 || !menu_latest_instances.equals(current_instances)) {
for (MenuItem mi : menu_items) {
mi.remove();
}
menu_items.clear();
final MenuManager menu_manager = plugin.getPluginInterface().getUIManager().getMenuManager();
MenuContext mc = beta_status.getMenuContext();
for (final ChatInstance chat : sortChats(current_instances)) {
String short_name = chat.getShortName();
MenuItem mi = menu_manager.addMenuItem(mc, "!" + short_name + "!");
mi.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
try {
openChat(chat.getClone());
} catch (Throwable e) {
Debug.out(e);
}
}
});
menu_items.add(mi);
}
boolean need_sep = true;
if (current_instances.size() > 1) {
MenuItem mi = menu_manager.addMenuItem(mc, "sep1");
need_sep = false;
mi.setStyle(MenuItem.STYLE_SEPARATOR);
menu_items.add(mi);
mi = menu_manager.addMenuItem(mc, "label.open.all");
mi.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
for (ChatInstance chat : current_instances) {
try {
openChat(chat.getClone());
} catch (Throwable e) {
Debug.out(e);
}
}
}
});
menu_items.add(mi);
}
if (need_sep) {
MenuItem mi = menu_manager.addMenuItem(mc, "sep2");
mi.setStyle(MenuItem.STYLE_SEPARATOR);
menu_items.add(mi);
}
// create channel
MenuItem mi = menu_manager.addMenuItem(mc, "chat.view.create.chat");
mi.setStyle(MenuItem.STYLE_MENU);
menu_items.add(mi);
mi.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
menu.removeAllChildItems();
MenuItem mi = menu_manager.addMenuItem(menu, "!" + MessageText.getString("label.public") + "...!");
mi.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("chat.view.enter.key.title", "chat.view.enter.key.msg");
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver receiver) {
if (!receiver.hasSubmittedInput()) {
return;
}
String key = receiver.getSubmittedInput().trim();
BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_PUBLIC, key, null);
}
});
}
});
mi = menu_manager.addMenuItem(menu, "!" + MessageText.getString("label.anon") + "...!");
mi.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
if (plugin.getBeta().isI2PAvailable()) {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("chat.view.enter.key.title", "chat.view.enter.key.msg");
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver receiver) {
if (!receiver.hasSubmittedInput()) {
return;
}
String key = receiver.getSubmittedInput().trim();
BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_I2P, key, null);
}
});
} else {
I2PHelpers.installI2PHelper(null, null, null);
}
}
});
if (I2PHelpers.isInstallingI2PHelper()) {
mi.setEnabled(false);
mi.setText(mi.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
}
}
});
// chat overview
mi = menu_manager.addMenuItem(mc, "!" + MessageText.getString("chats.view.heading") + "...!");
mi.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (uif != null) {
uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CHAT);
}
}
});
menu_items.add(mi);
mi = menu_manager.addMenuItem(mc, "sep3");
mi.setStyle(MenuItem.STYLE_SEPARATOR);
menu_items.add(mi);
// options
mi = menu_manager.addMenuItem(mc, "MainWindow.menu.view.configuration");
mi.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
ui_instance.openView(UISWTInstance.VIEW_MAIN, VIEW_ID, null);
}
});
menu_items.add(mi);
menu_latest_instances = current_instances;
}
}
use of com.biglybt.ui.swt.SimpleTextEntryWindow in project BiglyBT by BiglySoftware.
the class PeersViewBase method addPeersMenu.
protected static boolean addPeersMenu(final DownloadManager man, String column_name, Menu menu) {
new MenuItem(menu, SWT.SEPARATOR);
MenuItem copy_me_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(copy_me_item, "menu.copy.my.peer");
copy_me_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
String str = getMyPeerDetails();
if (str.isEmpty()) {
str = "<no usable peers>";
}
ClipboardCopy.copyToClipBoard(str);
}
});
if (man == null) {
return (true);
}
PEPeerManager pm = man.getPeerManager();
if (pm == null) {
return (true);
}
if (TorrentUtils.isReallyPrivate(man.getTorrent())) {
return (true);
}
MenuItem copy_all_peers = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(copy_all_peers, "menu.copy.all.peers");
copy_all_peers.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
List<PEPeer> peers = pm.getPeers();
String str = getMyPeerDetails();
for (PEPeer peer : peers) {
int port = peer.getTCPListenPort();
if (port > 0) {
String address = peer.getIp() + ":" + port;
str += (str.isEmpty() ? "" : ",") + address;
}
}
if (str.isEmpty()) {
str = "<no usable peers>";
}
ClipboardCopy.copyToClipBoard(str);
}
});
MenuItem add_peers_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(add_peers_item, "menu.add.peers");
add_peers_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("dialog.add.peers.title", "dialog.add.peers.msg");
String def = COConfigurationManager.getStringParameter("add.peers.default", "");
entryWindow.setPreenteredText(String.valueOf(def), false);
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
if (!entryWindow.hasSubmittedInput()) {
return;
}
String sReturn = entryWindow.getSubmittedInput();
if (sReturn == null) {
return;
}
COConfigurationManager.setParameter("add.peers.default", sReturn);
PEPeerManager pm = man.getPeerManager();
if (pm == null) {
return;
}
String[] bits = sReturn.split(",");
for (String bit : bits) {
bit = bit.trim();
int pos = bit.lastIndexOf(':');
if (pos != -1) {
String host = bit.substring(0, pos).trim();
String port = bit.substring(pos + 1).trim();
try {
int i_port = Integer.parseInt(port);
pm.addPeer(host, i_port, 0, NetworkManager.getCryptoRequired(NetworkManager.CRYPTO_OVERRIDE_NONE), null);
} catch (Throwable e) {
}
} else {
pm.addPeer(bit, 6881, 0, NetworkManager.getCryptoRequired(NetworkManager.CRYPTO_OVERRIDE_NONE), null);
}
}
}
});
}
});
return (true);
}
use of com.biglybt.ui.swt.SimpleTextEntryWindow 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