forked from I2P_Developers/i2p.i2p
sort config tabs
This commit is contained in:
@ -1,6 +1,12 @@
|
|||||||
package net.i2p.router.web;
|
package net.i2p.router.web;
|
||||||
|
|
||||||
import java.io.IOException;
|
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.
|
* 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("Clients"), _x("Peers"), _x("Keyring"), _x("Logging"), _x("Stats"),
|
||||||
_x("Reseeding"), _x("Advanced") };
|
_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
|
* @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));
|
boolean span = graphical && (theme == null || theme.equals(CSSHelper.DEFAULT_THEME));
|
||||||
if (!span)
|
if (!span)
|
||||||
buf.append("<center>");
|
buf.append("<center>");
|
||||||
|
List<Tab> tabs = new ArrayList<Tab>(pages.length);
|
||||||
for (int i = 0; i < pages.length; i++) {
|
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")) {
|
if (requestURI.endsWith(page) || requestURI.endsWith(page + ".jsp")) {
|
||||||
// we are there
|
// we are there
|
||||||
if (span)
|
if (span)
|
||||||
buf.append("<span class=\"tab2\">");
|
buf.append("<span class=\"tab2\">");
|
||||||
buf.append(_(titles[i]));
|
buf.append(tabs.get(i).title);
|
||||||
} else {
|
} else {
|
||||||
// we are not there, make a link
|
// we are not there, make a link
|
||||||
if (span)
|
if (span)
|
||||||
buf.append("<span class=\"tab\">");
|
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)
|
if (span)
|
||||||
buf.append(" </span>\n");
|
buf.append(" </span>\n");
|
||||||
|
Reference in New Issue
Block a user