Console: Consolidate "checked" code

This commit is contained in:
zzz
2015-12-18 14:43:31 +00:00
parent 8226e92973
commit c59496f30f
9 changed files with 34 additions and 42 deletions

View File

@ -6,7 +6,6 @@ import java.util.TreeMap;
import net.i2p.data.DataHelper;
public class ConfigAdvancedHelper extends HelperBase {
private final static String CHECKED = " checked=\"checked\" ";
static final String PROP_FLOODFILL_PARTICIPANT = "router.floodfillParticipant";
public String getSettings() {

View File

@ -64,7 +64,7 @@ public class ConfigClientsHelper extends HelperBase {
if ((mode == 0 && disabled) ||
(mode == 1 && (!disabled) && (!ssl)) ||
(mode == 2 && (!disabled) && ssl))
return "checked=\"checked\"";
return CHECKED;
return "";
}
@ -72,7 +72,7 @@ public class ConfigClientsHelper extends HelperBase {
public String getAuth() {
boolean enabled = _context.getBooleanProperty(PROP_AUTH);
if (enabled)
return "checked=\"checked\"";
return CHECKED;
return "";
}
@ -342,7 +342,7 @@ public class ConfigClientsHelper extends HelperBase {
}
buf.append("</td><td align=\"center\" width=\"10%\"><input type=\"checkbox\" class=\"optbox\" name=\"").append(index).append(".enabled\"");
if (enabled) {
buf.append("checked=\"checked\" ");
buf.append(CHECKED);
if (ro || preventDisable)
buf.append("disabled=\"disabled\" ");
}

View File

@ -25,7 +25,6 @@ public class ConfigNetHelper extends HelperBase {
final static String PROP_I2NP_NTCP_PORT = "i2np.ntcp.port";
final static String PROP_I2NP_NTCP_AUTO_PORT = "i2np.ntcp.autoport";
final static String PROP_I2NP_NTCP_AUTO_IP = "i2np.ntcp.autoip";
private final static String CHECKED = " checked=\"checked\" ";
public String getUdphostname() {
return _context.getProperty(UDPTransport.PROP_EXTERNAL_HOST, "");
@ -78,13 +77,6 @@ public class ConfigNetHelper extends HelperBase {
return _context.getProperty(UDPTransport.PROP_INTERNAL_PORT, "unset");
}
/** @param prop must default to false */
public String getChecked(String prop) {
if (_context.getBooleanProperty(prop))
return CHECKED;
return "";
}
public String getDynamicKeysChecked() {
return getChecked(Router.PROP_DYNAMIC_KEYS);
}

View File

@ -56,34 +56,26 @@ public class ConfigReseedHelper extends HelperBase {
if ((mode == 0 && (!disabled) && (!required)) ||
(mode == 1 && (!disabled) && required) ||
(mode == 2 && disabled))
return "checked=\"checked\"";
return CHECKED;
return "";
}
public String getEnable() {
return checked(Reseeder.PROP_PROXY_ENABLE);
return getChecked(Reseeder.PROP_PROXY_ENABLE);
}
/** @since 0.8.9 */
public String getAuth() {
return checked(Reseeder.PROP_PROXY_AUTH_ENABLE);
return getChecked(Reseeder.PROP_PROXY_AUTH_ENABLE);
}
public String getSenable() {
return checked(Reseeder.PROP_SPROXY_ENABLE);
return getChecked(Reseeder.PROP_SPROXY_ENABLE);
}
/** @since 0.8.9 */
public String getSauth() {
return checked(Reseeder.PROP_SPROXY_AUTH_ENABLE);
}
/** @since 0.8.9 */
private String checked(String prop) {
boolean enabled = _context.getBooleanProperty(prop);
if (enabled)
return "checked=\"checked\"";
return "";
return getChecked(Reseeder.PROP_SPROXY_AUTH_ENABLE);
}
public String getReseedURL() {

View File

@ -14,13 +14,13 @@ public class ConfigUIHelper extends HelperBase {
for (String theme : themes) {
buf.append("<input type=\"radio\" class=\"optbox\" name=\"theme\" ");
if (theme.equals(current))
buf.append("checked=\"checked\" ");
buf.append(CHECKED);
buf.append("value=\"").append(theme).append("\">").append(_t(theme)).append("<br>\n");
}
boolean universalTheming = _context.getBooleanProperty(CSSHelper.PROP_UNIVERSAL_THEMING);
buf.append("<input type=\"checkbox\" name=\"universalTheming\" ");
if (universalTheming)
buf.append("checked=\"checked\" ");
buf.append(CHECKED);
buf.append("value=\"1\">")
.append(_t("Set theme universally across all apps"))
.append("<br>\n");
@ -32,7 +32,7 @@ public class ConfigUIHelper extends HelperBase {
boolean forceMobileConsole = _context.getBooleanProperty(CSSHelper.PROP_FORCE_MOBILE_CONSOLE);
buf.append("<input type=\"checkbox\" name=\"forceMobileConsole\" ");
if (forceMobileConsole)
buf.append("checked=\"checked\" ");
buf.append(CHECKED);
buf.append("value=\"1\">")
.append(_t("Force the mobile console to be used"))
.append("<br>\n");
@ -138,7 +138,7 @@ public class ConfigUIHelper extends HelperBase {
buf.append("<input type=\"radio\" class=\"optbox\" name=\"lang\" ");
String lang = langs[i][0];
if (lang.equals(current))
buf.append("checked=\"checked\" ");
buf.append(CHECKED);
buf.append("value=\"").append(lang).append("\">")
.append("<img height=\"11\" width=\"16\" alt=\"\" src=\"/flags.jsp?c=").append(langs[i][1]).append("\"> ");
int under = lang.indexOf('_');

View File

@ -90,18 +90,14 @@ public class ConfigUpdateHelper extends HelperBase {
}
public String getUpdateUnsigned() {
if (_context.getBooleanProperty(ConfigUpdateHandler.PROP_UPDATE_UNSIGNED))
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateUnsigned\" checked=\"checked\" >";
else
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateUnsigned\" >";
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateUnsigned\" " +
getChecked(ConfigUpdateHandler.PROP_UPDATE_UNSIGNED) + '>';
}
/** @since 0.9.20 */
public String getUpdateDevSU3() {
if (_context.getBooleanProperty(ConfigUpdateHandler.PROP_UPDATE_DEV_SU3))
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateDevSU3\" checked=\"checked\" >";
else
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateDevSU3\" >";
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateDevSU3\" " +
getChecked(ConfigUpdateHandler.PROP_UPDATE_DEV_SU3) + '>';
}
private static final long PERIODS[] = new long[] { 12*60*60*1000l, 24*60*60*1000l,

View File

@ -358,8 +358,8 @@ public class GraphHelper extends FormHandler {
"<input type=\"hidden\" name=\"action\" value=\"save\">\n" +
"<input type=\"hidden\" name=\"nonce\" value=\"" + nonce + "\" >\n");
_out.write(_t("Periods") + ": <input size=\"5\" style=\"text-align: right;\" type=\"text\" name=\"periodCount\" value=\"" + _periodCount + "\"><br>\n");
_out.write(_t("Plot averages") + ": <input type=\"radio\" class=\"optbox\" name=\"showEvents\" value=\"false\" " + (_showEvents ? "" : "checked=\"checked\" ") + "> ");
_out.write(_t("or")+ " " +_t("plot events") + ": <input type=\"radio\" class=\"optbox\" name=\"showEvents\" value=\"true\" "+ (_showEvents ? "checked=\"checked\" " : "") + "><br>\n");
_out.write(_t("Plot averages") + ": <input type=\"radio\" class=\"optbox\" name=\"showEvents\" value=\"false\" " + (_showEvents ? "" : HelperBase.CHECKED) + "> ");
_out.write(_t("or")+ " " +_t("plot events") + ": <input type=\"radio\" class=\"optbox\" name=\"showEvents\" value=\"true\" "+ (_showEvents ? HelperBase.CHECKED : "") + "><br>\n");
_out.write(_t("Image sizes") + ": " + _t("width") + ": <input size=\"4\" style=\"text-align: right;\" type=\"text\" name=\"width\" value=\"" + _width
+ "\"> " + _t("pixels") + ", " + _t("height") + ": <input size=\"4\" style=\"text-align: right;\" type=\"text\" name=\"height\" value=\"" + _height
+ "\"> " + _t("pixels") + "<br>\n");
@ -382,7 +382,7 @@ public class GraphHelper extends FormHandler {
" <input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"persistent\"");
boolean persistent = _context.getBooleanPropertyDefaultTrue(SummaryListener.PROP_PERSISTENT);
if (persistent)
_out.write(" checked=\"checked\"");
_out.write(HelperBase.CHECKED);
_out.write(">" +
"<hr><div class=\"formaction\"><input type=\"submit\" class=\"accept\" value=\"" + _t("Save settings and redraw graphs") + "\"></div></form>");
} catch (IOException ioe) {

View File

@ -12,6 +12,7 @@ public abstract class HelperBase {
protected Writer _out;
static final String PROP_ADVANCED = "routerconsole.advanced";
static final String CHECKED = " checked=\"checked\" ";
/**
* Configure this bean to query a particular router context
@ -43,6 +44,19 @@ public abstract class HelperBase {
*/
public void storeWriter(Writer out) { _out = out; }
/**
* Is a boolean property set to true?
*
* @param prop must default to false
* @return non-null, either "" or " checked=\"checked\" "
* @since 0.9.24 consolidated from various helpers
*/
protected String getChecked(String prop) {
if (_context.getBooleanProperty(prop))
return CHECKED;
return "";
}
/** translate a string */
public String _t(String s) {
return Messages.getString(s, _context);

View File

@ -103,8 +103,7 @@ public class HomeHelper extends HelperBase {
}
public String getConfigHome() {
boolean oldHome = _context.getBooleanProperty(PROP_OLDHOME);
return oldHome ? "checked=\"checked\"" : "";
return getChecked(PROP_OLDHOME);
}
public String getProxyStatus() {