forked from I2P_Developers/i2p.i2p
Console: Consolidate "checked" code
This commit is contained in:
@ -6,7 +6,6 @@ import java.util.TreeMap;
|
|||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
|
|
||||||
public class ConfigAdvancedHelper extends HelperBase {
|
public class ConfigAdvancedHelper extends HelperBase {
|
||||||
private final static String CHECKED = " checked=\"checked\" ";
|
|
||||||
static final String PROP_FLOODFILL_PARTICIPANT = "router.floodfillParticipant";
|
static final String PROP_FLOODFILL_PARTICIPANT = "router.floodfillParticipant";
|
||||||
|
|
||||||
public String getSettings() {
|
public String getSettings() {
|
||||||
|
@ -64,7 +64,7 @@ public class ConfigClientsHelper extends HelperBase {
|
|||||||
if ((mode == 0 && disabled) ||
|
if ((mode == 0 && disabled) ||
|
||||||
(mode == 1 && (!disabled) && (!ssl)) ||
|
(mode == 1 && (!disabled) && (!ssl)) ||
|
||||||
(mode == 2 && (!disabled) && ssl))
|
(mode == 2 && (!disabled) && ssl))
|
||||||
return "checked=\"checked\"";
|
return CHECKED;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ public class ConfigClientsHelper extends HelperBase {
|
|||||||
public String getAuth() {
|
public String getAuth() {
|
||||||
boolean enabled = _context.getBooleanProperty(PROP_AUTH);
|
boolean enabled = _context.getBooleanProperty(PROP_AUTH);
|
||||||
if (enabled)
|
if (enabled)
|
||||||
return "checked=\"checked\"";
|
return CHECKED;
|
||||||
return "";
|
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\"");
|
buf.append("</td><td align=\"center\" width=\"10%\"><input type=\"checkbox\" class=\"optbox\" name=\"").append(index).append(".enabled\"");
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
buf.append("checked=\"checked\" ");
|
buf.append(CHECKED);
|
||||||
if (ro || preventDisable)
|
if (ro || preventDisable)
|
||||||
buf.append("disabled=\"disabled\" ");
|
buf.append("disabled=\"disabled\" ");
|
||||||
}
|
}
|
||||||
|
@ -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_PORT = "i2np.ntcp.port";
|
||||||
final static String PROP_I2NP_NTCP_AUTO_PORT = "i2np.ntcp.autoport";
|
final static String PROP_I2NP_NTCP_AUTO_PORT = "i2np.ntcp.autoport";
|
||||||
final static String PROP_I2NP_NTCP_AUTO_IP = "i2np.ntcp.autoip";
|
final static String PROP_I2NP_NTCP_AUTO_IP = "i2np.ntcp.autoip";
|
||||||
private final static String CHECKED = " checked=\"checked\" ";
|
|
||||||
|
|
||||||
public String getUdphostname() {
|
public String getUdphostname() {
|
||||||
return _context.getProperty(UDPTransport.PROP_EXTERNAL_HOST, "");
|
return _context.getProperty(UDPTransport.PROP_EXTERNAL_HOST, "");
|
||||||
@ -78,13 +77,6 @@ public class ConfigNetHelper extends HelperBase {
|
|||||||
return _context.getProperty(UDPTransport.PROP_INTERNAL_PORT, "unset");
|
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() {
|
public String getDynamicKeysChecked() {
|
||||||
return getChecked(Router.PROP_DYNAMIC_KEYS);
|
return getChecked(Router.PROP_DYNAMIC_KEYS);
|
||||||
}
|
}
|
||||||
|
@ -56,34 +56,26 @@ public class ConfigReseedHelper extends HelperBase {
|
|||||||
if ((mode == 0 && (!disabled) && (!required)) ||
|
if ((mode == 0 && (!disabled) && (!required)) ||
|
||||||
(mode == 1 && (!disabled) && required) ||
|
(mode == 1 && (!disabled) && required) ||
|
||||||
(mode == 2 && disabled))
|
(mode == 2 && disabled))
|
||||||
return "checked=\"checked\"";
|
return CHECKED;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEnable() {
|
public String getEnable() {
|
||||||
return checked(Reseeder.PROP_PROXY_ENABLE);
|
return getChecked(Reseeder.PROP_PROXY_ENABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @since 0.8.9 */
|
/** @since 0.8.9 */
|
||||||
public String getAuth() {
|
public String getAuth() {
|
||||||
return checked(Reseeder.PROP_PROXY_AUTH_ENABLE);
|
return getChecked(Reseeder.PROP_PROXY_AUTH_ENABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSenable() {
|
public String getSenable() {
|
||||||
return checked(Reseeder.PROP_SPROXY_ENABLE);
|
return getChecked(Reseeder.PROP_SPROXY_ENABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @since 0.8.9 */
|
/** @since 0.8.9 */
|
||||||
public String getSauth() {
|
public String getSauth() {
|
||||||
return checked(Reseeder.PROP_SPROXY_AUTH_ENABLE);
|
return getChecked(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 "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getReseedURL() {
|
public String getReseedURL() {
|
||||||
|
@ -14,13 +14,13 @@ public class ConfigUIHelper extends HelperBase {
|
|||||||
for (String theme : themes) {
|
for (String theme : themes) {
|
||||||
buf.append("<input type=\"radio\" class=\"optbox\" name=\"theme\" ");
|
buf.append("<input type=\"radio\" class=\"optbox\" name=\"theme\" ");
|
||||||
if (theme.equals(current))
|
if (theme.equals(current))
|
||||||
buf.append("checked=\"checked\" ");
|
buf.append(CHECKED);
|
||||||
buf.append("value=\"").append(theme).append("\">").append(_t(theme)).append("<br>\n");
|
buf.append("value=\"").append(theme).append("\">").append(_t(theme)).append("<br>\n");
|
||||||
}
|
}
|
||||||
boolean universalTheming = _context.getBooleanProperty(CSSHelper.PROP_UNIVERSAL_THEMING);
|
boolean universalTheming = _context.getBooleanProperty(CSSHelper.PROP_UNIVERSAL_THEMING);
|
||||||
buf.append("<input type=\"checkbox\" name=\"universalTheming\" ");
|
buf.append("<input type=\"checkbox\" name=\"universalTheming\" ");
|
||||||
if (universalTheming)
|
if (universalTheming)
|
||||||
buf.append("checked=\"checked\" ");
|
buf.append(CHECKED);
|
||||||
buf.append("value=\"1\">")
|
buf.append("value=\"1\">")
|
||||||
.append(_t("Set theme universally across all apps"))
|
.append(_t("Set theme universally across all apps"))
|
||||||
.append("<br>\n");
|
.append("<br>\n");
|
||||||
@ -32,7 +32,7 @@ public class ConfigUIHelper extends HelperBase {
|
|||||||
boolean forceMobileConsole = _context.getBooleanProperty(CSSHelper.PROP_FORCE_MOBILE_CONSOLE);
|
boolean forceMobileConsole = _context.getBooleanProperty(CSSHelper.PROP_FORCE_MOBILE_CONSOLE);
|
||||||
buf.append("<input type=\"checkbox\" name=\"forceMobileConsole\" ");
|
buf.append("<input type=\"checkbox\" name=\"forceMobileConsole\" ");
|
||||||
if (forceMobileConsole)
|
if (forceMobileConsole)
|
||||||
buf.append("checked=\"checked\" ");
|
buf.append(CHECKED);
|
||||||
buf.append("value=\"1\">")
|
buf.append("value=\"1\">")
|
||||||
.append(_t("Force the mobile console to be used"))
|
.append(_t("Force the mobile console to be used"))
|
||||||
.append("<br>\n");
|
.append("<br>\n");
|
||||||
@ -138,7 +138,7 @@ public class ConfigUIHelper extends HelperBase {
|
|||||||
buf.append("<input type=\"radio\" class=\"optbox\" name=\"lang\" ");
|
buf.append("<input type=\"radio\" class=\"optbox\" name=\"lang\" ");
|
||||||
String lang = langs[i][0];
|
String lang = langs[i][0];
|
||||||
if (lang.equals(current))
|
if (lang.equals(current))
|
||||||
buf.append("checked=\"checked\" ");
|
buf.append(CHECKED);
|
||||||
buf.append("value=\"").append(lang).append("\">")
|
buf.append("value=\"").append(lang).append("\">")
|
||||||
.append("<img height=\"11\" width=\"16\" alt=\"\" src=\"/flags.jsp?c=").append(langs[i][1]).append("\"> ");
|
.append("<img height=\"11\" width=\"16\" alt=\"\" src=\"/flags.jsp?c=").append(langs[i][1]).append("\"> ");
|
||||||
int under = lang.indexOf('_');
|
int under = lang.indexOf('_');
|
||||||
|
@ -90,18 +90,14 @@ public class ConfigUpdateHelper extends HelperBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getUpdateUnsigned() {
|
public String getUpdateUnsigned() {
|
||||||
if (_context.getBooleanProperty(ConfigUpdateHandler.PROP_UPDATE_UNSIGNED))
|
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateUnsigned\" " +
|
||||||
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateUnsigned\" checked=\"checked\" >";
|
getChecked(ConfigUpdateHandler.PROP_UPDATE_UNSIGNED) + '>';
|
||||||
else
|
|
||||||
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateUnsigned\" >";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @since 0.9.20 */
|
/** @since 0.9.20 */
|
||||||
public String getUpdateDevSU3() {
|
public String getUpdateDevSU3() {
|
||||||
if (_context.getBooleanProperty(ConfigUpdateHandler.PROP_UPDATE_DEV_SU3))
|
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateDevSU3\" " +
|
||||||
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateDevSU3\" checked=\"checked\" >";
|
getChecked(ConfigUpdateHandler.PROP_UPDATE_DEV_SU3) + '>';
|
||||||
else
|
|
||||||
return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateDevSU3\" >";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final long PERIODS[] = new long[] { 12*60*60*1000l, 24*60*60*1000l,
|
private static final long PERIODS[] = new long[] { 12*60*60*1000l, 24*60*60*1000l,
|
||||||
|
@ -358,8 +358,8 @@ public class GraphHelper extends FormHandler {
|
|||||||
"<input type=\"hidden\" name=\"action\" value=\"save\">\n" +
|
"<input type=\"hidden\" name=\"action\" value=\"save\">\n" +
|
||||||
"<input type=\"hidden\" name=\"nonce\" value=\"" + nonce + "\" >\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("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("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 ? "checked=\"checked\" " : "") + "><br>\n");
|
_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
|
_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") + ", " + _t("height") + ": <input size=\"4\" style=\"text-align: right;\" type=\"text\" name=\"height\" value=\"" + _height
|
||||||
+ "\"> " + _t("pixels") + "<br>\n");
|
+ "\"> " + _t("pixels") + "<br>\n");
|
||||||
@ -382,7 +382,7 @@ public class GraphHelper extends FormHandler {
|
|||||||
" <input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"persistent\"");
|
" <input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"persistent\"");
|
||||||
boolean persistent = _context.getBooleanPropertyDefaultTrue(SummaryListener.PROP_PERSISTENT);
|
boolean persistent = _context.getBooleanPropertyDefaultTrue(SummaryListener.PROP_PERSISTENT);
|
||||||
if (persistent)
|
if (persistent)
|
||||||
_out.write(" checked=\"checked\"");
|
_out.write(HelperBase.CHECKED);
|
||||||
_out.write(">" +
|
_out.write(">" +
|
||||||
"<hr><div class=\"formaction\"><input type=\"submit\" class=\"accept\" value=\"" + _t("Save settings and redraw graphs") + "\"></div></form>");
|
"<hr><div class=\"formaction\"><input type=\"submit\" class=\"accept\" value=\"" + _t("Save settings and redraw graphs") + "\"></div></form>");
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
|
@ -12,6 +12,7 @@ public abstract class HelperBase {
|
|||||||
protected Writer _out;
|
protected Writer _out;
|
||||||
|
|
||||||
static final String PROP_ADVANCED = "routerconsole.advanced";
|
static final String PROP_ADVANCED = "routerconsole.advanced";
|
||||||
|
static final String CHECKED = " checked=\"checked\" ";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure this bean to query a particular router context
|
* Configure this bean to query a particular router context
|
||||||
@ -43,6 +44,19 @@ public abstract class HelperBase {
|
|||||||
*/
|
*/
|
||||||
public void storeWriter(Writer out) { _out = out; }
|
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 */
|
/** translate a string */
|
||||||
public String _t(String s) {
|
public String _t(String s) {
|
||||||
return Messages.getString(s, _context);
|
return Messages.getString(s, _context);
|
||||||
|
@ -103,8 +103,7 @@ public class HomeHelper extends HelperBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getConfigHome() {
|
public String getConfigHome() {
|
||||||
boolean oldHome = _context.getBooleanProperty(PROP_OLDHOME);
|
return getChecked(PROP_OLDHOME);
|
||||||
return oldHome ? "checked=\"checked\"" : "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProxyStatus() {
|
public String getProxyStatus() {
|
||||||
|
Reference in New Issue
Block a user