forked from I2P_Developers/i2p.i2p
Console: Stat group display names
This commit is contained in:
@ -3,6 +3,7 @@ package net.i2p.router.web.helpers;
|
|||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -158,8 +159,16 @@ public class ConfigStatsHelper extends HelperBase {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** What group is the current stat in */
|
/**
|
||||||
|
* What group is the current stat in, untranslated, not for display
|
||||||
|
* @return single word, no spaces
|
||||||
|
*/
|
||||||
public String getCurrentGroupName() { return _currentGroup; }
|
public String getCurrentGroupName() { return _currentGroup; }
|
||||||
|
/**
|
||||||
|
* What group is the current stat in, display name, translated
|
||||||
|
* @since 0.9.45
|
||||||
|
*/
|
||||||
|
public String getTranslatedGroupName() { return translateGroup(_currentGroup); }
|
||||||
public String getCurrentStatName() { return _currentStatName; }
|
public String getCurrentStatName() { return _currentStatName; }
|
||||||
public String getCurrentGraphName() { return _currentGraphName; }
|
public String getCurrentGraphName() { return _currentGraphName; }
|
||||||
public String getCurrentStatDescription() { return _currentStatDescription; }
|
public String getCurrentStatDescription() { return _currentStatDescription; }
|
||||||
@ -178,9 +187,19 @@ public class ConfigStatsHelper extends HelperBase {
|
|||||||
*/
|
*/
|
||||||
private class AlphaComparator implements Comparator<String> {
|
private class AlphaComparator implements Comparator<String> {
|
||||||
public int compare(String lhs, String rhs) {
|
public int compare(String lhs, String rhs) {
|
||||||
String lname = _t(lhs);
|
String lname = translateGroup(lhs);
|
||||||
String rname = _t(rhs);
|
String rname = translateGroup(rhs);
|
||||||
return Collator.getInstance().compare(lname, rname);
|
return Collator.getInstance().compare(lname, rname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.9.45
|
||||||
|
*/
|
||||||
|
private String translateGroup(String group) {
|
||||||
|
String disp = StatsGenerator.groupNames.get(group);
|
||||||
|
if (disp != null)
|
||||||
|
group = disp;
|
||||||
|
return _t(group);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import java.text.DecimalFormat;
|
|||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
@ -25,6 +26,32 @@ import net.i2p.stat.RateStat;
|
|||||||
public class StatsGenerator {
|
public class StatsGenerator {
|
||||||
private final RouterContext _context;
|
private final RouterContext _context;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map of group name to untranslated nice display name.
|
||||||
|
* If not present, just use the name.
|
||||||
|
* non-mapped names are tagged in Strings.java
|
||||||
|
* pkg private for ConfigStatsHelper
|
||||||
|
*/
|
||||||
|
static final Map<String, String> groupNames;
|
||||||
|
static {
|
||||||
|
String[] groups = {
|
||||||
|
"BandwidthLimiter", _x("Bandwidth Limiter"),
|
||||||
|
"ClientMessages", _x("Client Messages"),
|
||||||
|
"i2cp", _x("I2CP"),
|
||||||
|
"I2PTunnel", _x("Hidden Services Manager"),
|
||||||
|
"InNetPool", _x("Inbound Messages"),
|
||||||
|
"JobQueue", _x("Job Queue"),
|
||||||
|
"NetworkDatabase", _x("Network Database"),
|
||||||
|
"ntcp", _x("NTCP"),
|
||||||
|
"Throttle", _x("Router Limiter"),
|
||||||
|
"udp", _x("UDP")
|
||||||
|
};
|
||||||
|
groupNames = new HashMap<String, String>(groups.length / 2);
|
||||||
|
for (int i = 0; i < groups.length; i += 2) {
|
||||||
|
groupNames.put(groups[i], groups[i+1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public StatsGenerator(RouterContext context) {
|
public StatsGenerator(RouterContext context) {
|
||||||
_context = context;
|
_context = context;
|
||||||
}
|
}
|
||||||
@ -51,7 +78,7 @@ public class StatsGenerator {
|
|||||||
groups.putAll(unsorted);
|
groups.putAll(unsorted);
|
||||||
for (String group : groups.keySet()) {
|
for (String group : groups.keySet()) {
|
||||||
buf.append("<option value=\"#").append(group).append("\">");
|
buf.append("<option value=\"#").append(group).append("\">");
|
||||||
buf.append(_t(group)).append("</option>\n");
|
buf.append(translateGroup(group)).append("</option>\n");
|
||||||
// let's just do the groups
|
// let's just do the groups
|
||||||
//Set stats = (Set)entry.getValue();
|
//Set stats = (Set)entry.getValue();
|
||||||
//for (Iterator statIter = stats.iterator(); statIter.hasNext(); ) {
|
//for (Iterator statIter = stats.iterator(); statIter.hasNext(); ) {
|
||||||
@ -77,7 +104,7 @@ public class StatsGenerator {
|
|||||||
buf.append("<h3 class=\"stats\"><a name=\"");
|
buf.append("<h3 class=\"stats\"><a name=\"");
|
||||||
buf.append(group);
|
buf.append(group);
|
||||||
buf.append("\">");
|
buf.append("\">");
|
||||||
buf.append(_t(group));
|
buf.append(translateGroup(group));
|
||||||
buf.append("</a></h3>");
|
buf.append("</a></h3>");
|
||||||
buf.append("<ul class=\"statlist\">");
|
buf.append("<ul class=\"statlist\">");
|
||||||
out.write(buf.toString());
|
out.write(buf.toString());
|
||||||
@ -258,6 +285,16 @@ public class StatsGenerator {
|
|||||||
private final static DecimalFormat _pct = new DecimalFormat("#0.00%");
|
private final static DecimalFormat _pct = new DecimalFormat("#0.00%");
|
||||||
private final static String pct(double num) { synchronized (_pct) { return _pct.format(num); } }
|
private final static String pct(double num) { synchronized (_pct) { return _pct.format(num); } }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.9.45
|
||||||
|
*/
|
||||||
|
private String translateGroup(String group) {
|
||||||
|
String disp = groupNames.get(group);
|
||||||
|
if (disp != null)
|
||||||
|
group = disp;
|
||||||
|
return _t(group);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translated sort
|
* Translated sort
|
||||||
* Inner class, can't be Serializable
|
* Inner class, can't be Serializable
|
||||||
@ -265,8 +302,8 @@ public class StatsGenerator {
|
|||||||
*/
|
*/
|
||||||
private class AlphaComparator implements Comparator<String> {
|
private class AlphaComparator implements Comparator<String> {
|
||||||
public int compare(String lhs, String rhs) {
|
public int compare(String lhs, String rhs) {
|
||||||
String lname = _t(lhs);
|
String lname = translateGroup(lhs);
|
||||||
String rname = _t(rhs);
|
String rname = translateGroup(rhs);
|
||||||
return Collator.getInstance().compare(lname, rname);
|
return Collator.getInstance().compare(lname, rname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -285,4 +322,14 @@ public class StatsGenerator {
|
|||||||
private String ngettext(String s, String p, int n) {
|
private String ngettext(String s, String p, int n) {
|
||||||
return Messages.getString(n, s, p, _context);
|
return Messages.getString(n, s, p, _context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark a string for extraction by xgettext and translation.
|
||||||
|
* Use this only in static initializers.
|
||||||
|
* It does not translate!
|
||||||
|
* @return s
|
||||||
|
*/
|
||||||
|
private static String _x(String s) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,23 +55,14 @@ class Dummy {
|
|||||||
_t("midnight");
|
_t("midnight");
|
||||||
|
|
||||||
// stat groups for stats.jsp
|
// stat groups for stats.jsp
|
||||||
|
// See StatsGenerator for groups mapped to a display name
|
||||||
_t("Bandwidth");
|
_t("Bandwidth");
|
||||||
_t("BandwidthLimiter");
|
|
||||||
_t("ClientMessages");
|
|
||||||
_t("Encryption");
|
_t("Encryption");
|
||||||
_t("i2cp");
|
|
||||||
_t("I2PTunnel");
|
|
||||||
_t("InNetPool");
|
|
||||||
_t("JobQueue");
|
|
||||||
_t("NetworkDatabase");
|
|
||||||
_t("ntcp");
|
|
||||||
_t("Peers");
|
_t("Peers");
|
||||||
_t("Router");
|
_t("Router");
|
||||||
_t("Stream");
|
_t("Stream");
|
||||||
_t("Throttle");
|
|
||||||
_t("Transport");
|
_t("Transport");
|
||||||
_t("Tunnels");
|
_t("Tunnels");
|
||||||
_t("udp");
|
|
||||||
|
|
||||||
// parameters in transport addresses (netdb.jsp)
|
// parameters in transport addresses (netdb.jsp)
|
||||||
// may or may not be worth translating
|
// may or may not be worth translating
|
||||||
|
@ -98,7 +98,7 @@ Warning - Log with care, stat file grows without limit.<br>
|
|||||||
while (statshelper.groupRequired()) { %>
|
while (statshelper.groupRequired()) { %>
|
||||||
<tr>
|
<tr>
|
||||||
<th align="left" colspan="3" id=<%=statshelper.getCurrentGroupName()%>>
|
<th align="left" colspan="3" id=<%=statshelper.getCurrentGroupName()%>>
|
||||||
<b><%=intl._t(statshelper.getCurrentGroupName())%></b>
|
<b><%=statshelper.getTranslatedGroupName()%></b>
|
||||||
<a class="script" title="<%=intl._t("Toggle section graphing options")%>" href="javascript:void(null);" onclick="toggleAll('<%=statshelper.getCurrentGroupName()%>')">[<%=intl._t("toggle all")%>]</a>
|
<a class="script" title="<%=intl._t("Toggle section graphing options")%>" href="javascript:void(null);" onclick="toggleAll('<%=statshelper.getCurrentGroupName()%>')">[<%=intl._t("toggle all")%>]</a>
|
||||||
</th></tr>
|
</th></tr>
|
||||||
<tr class="tablefooter">
|
<tr class="tablefooter">
|
||||||
|
Reference in New Issue
Block a user