Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.util.HashSet;

public class Main {
    private static String getControlByType(String prefs, String key, Object type, String value) {
        String htmlControl = "";
        String htmlControlVal = "";
        key = prefs + "_debugghostseperator_" + key;
        if (type instanceof Boolean) {
            htmlControlVal = (value.equalsIgnoreCase("true")) ? "checked=\"checked\"" : "";
            htmlControl = "<input id=\"" + key + "\" type=\"checkbox\" value=\"" + key + "\" " + htmlControlVal
                    + " />";
        } else if (type instanceof Integer) {
            htmlControlVal = value;
            htmlControl = "<input class=\"form-control\" type=\"number\" value=\"" + htmlControlVal + "\" id=\""
                    + key + "\">";
        } else if (type instanceof String) {
            htmlControlVal = (value != null) ? value : "null";
            htmlControl = "<input class=\"form-control\" type=\"text\" value=\"" + htmlControlVal + "\" id=\"" + key
                    + "\">";
        } else if (type instanceof Float) {
            htmlControlVal = value;
            htmlControl = "<input class=\"form-control\" type=\"number\" value=\"" + htmlControlVal + "\" id=\""
                    + key + "\">";
        } else if (type instanceof Long) {
            htmlControlVal = value;
            htmlControl = "<input class=\"form-control\" type=\"number\" value=\"" + htmlControlVal + "\" id=\""
                    + key + "\">";
        } else if (type instanceof HashSet) {
            StringBuilder sb = new StringBuilder();
            HashSet<String> valueSet = (HashSet) type;
            int rowHeight = Math.min(valueSet.size(), 5);
            sb.append("<textarea class=\"form-control\" id=\"" + key + "\" rows=\"" + rowHeight
                    + "\" style=\"margin-top: 0px; margin-bottom: 0px;\">");
            for (String val : valueSet) {
                sb.append(val);
                sb.append("\r\n");
            }
            sb.delete(sb.length() - 2, sb.length());
            sb.append("</textarea>");

            htmlControl = sb.toString();
        } else {
            htmlControl = "[DebugGhost has no control configured for type '" + type.getClass().getSimpleName()
                    + "']";
        }
        htmlControl += "<input id=\"" + key + "_TYPE\" type=\"hidden\" value=\"" + type.getClass().getSimpleName()
                + "\" />";

        return htmlControl;
    }
}