sort config tabs

This commit is contained in:
zzz
2015-03-20 16:51:34 +00:00
parent e02d44433d
commit aae801efaf

View File

@ -1,6 +1,12 @@
package net.i2p.router.web;
import java.io.IOException;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
/**
* Render the configuration menu at the top of all the config pages.
@ -21,6 +27,27 @@ public class ConfigNavHelper extends HelperBase {
_x("Clients"), _x("Peers"), _x("Keyring"), _x("Logging"), _x("Stats"),
_x("Reseeding"), _x("Advanced") };
private static class Tab {
public final String page, title;
public Tab(String p, String t) {
page = p; title = t;
}
}
private class TabComparator implements Comparator<Tab> {
private static final long serialVersionUID = 1L;
private final Collator coll;
public TabComparator() {
super();
coll = Collator.getInstance(new Locale(Messages.getLanguage(_context)));
}
public int compare(Tab l, Tab r) {
return coll.compare(l.title, r.title);
}
}
/**
* @param graphical false for text-mode browsers
*/
@ -31,18 +58,23 @@ public class ConfigNavHelper extends HelperBase {
boolean span = graphical && (theme == null || theme.equals(CSSHelper.DEFAULT_THEME));
if (!span)
buf.append("<center>");
List<Tab> tabs = new ArrayList<Tab>(pages.length);
for (int i = 0; i < pages.length; i++) {
String page = "config" + pages[i];
tabs.add(new Tab(pages[i], _(titles[i])));
}
Collections.sort(tabs, new TabComparator());
for (int i = 0; i < tabs.size(); i++) {
String page = "config" + tabs.get(i).page;
if (requestURI.endsWith(page) || requestURI.endsWith(page + ".jsp")) {
// we are there
if (span)
buf.append("<span class=\"tab2\">");
buf.append(_(titles[i]));
buf.append(tabs.get(i).title);
} else {
// we are not there, make a link
if (span)
buf.append("<span class=\"tab\">");
buf.append("<a href=\"").append(page).append("\">").append(_(titles[i])).append("</a>");
buf.append("<a href=\"").append(page).append("\">").append(tabs.get(i).title).append("</a>");
}
if (span)
buf.append(" </span>\n");