Example usage for java.text DateFormat MEDIUM

List of usage examples for java.text DateFormat MEDIUM

Introduction

In this page you can find the example usage for java.text DateFormat MEDIUM.

Prototype

int MEDIUM

To view the source code for java.text DateFormat MEDIUM.

Click Source Link

Document

Constant for medium style pattern.

Usage

From source file:net.spfbl.http.ServerHTTP.java

private static String getControlPanel(Locale locale, User user, Long begin, String filter) {
    StringBuilder builder = new StringBuilder();
    if (begin == null && filter == null) {
        //            builder.append("<!DOCTYPE html>\n");
        builder.append("<html lang=\"");
        builder.append(locale.getLanguage());
        builder.append("\">\n");
        builder.append("  <head>\n");
        builder.append("    <meta charset=\"UTF-8\">\n");
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("    <title>Painel de controle do SPFBL</title>\n");
        } else {/*from  w w w  .jav  a 2 s.c o m*/
            builder.append("    <title>SPFBL control panel</title>\n");
        }
        // Styled page.
        builder.append("    <style type=\"text/css\">\n");
        builder.append("      body {\n");
        builder.append("        margin:180px 0px 30px 0px;\n");
        builder.append("        background:lightgray;\n");
        builder.append("      }\n");
        builder.append("      iframe {\n");
        builder.append("        border-width: 0px 0px 0px 0px;\n");
        builder.append("        width:100%;\n");
        builder.append("        height:150px;\n");
        builder.append("      }\n");
        builder.append("      .header {\n");
        builder.append("        background-color:lightgray;\n");
        builder.append("        border-width: 0px 0px 0px 0px;\n");
        builder.append("        position:fixed;\n");
        builder.append("        top:0px;\n");
        builder.append("        margin:auto;\n");
        builder.append("        z-index:1;\n");
        builder.append("        width:100%;\n");
        builder.append("        height:180px;\n");
        builder.append("      }\n");
        builder.append("      .bottom {\n");
        builder.append("        background-color:lightgray;\n");
        builder.append("        border-width: 0px 0px 0px 0px;\n");
        builder.append("        position:fixed;\n");
        builder.append("        bottom:0px;\n");
        builder.append("        margin:auto;\n");
        builder.append("        z-index:1;\n");
        builder.append("        width:100%;\n");
        builder.append("        height:30px;\n");
        builder.append("      }\n");
        builder.append("      .button {\n");
        builder.append("          background-color: #4CAF50;\n");
        builder.append("          border: none;\n");
        builder.append("          color: white;\n");
        builder.append("          padding: 16px 32px;\n");
        builder.append("          text-align: center;\n");
        builder.append("          text-decoration: none;\n");
        builder.append("          display: inline-block;\n");
        builder.append("          font-size: 16px;\n");
        builder.append("          margin: 4px 2px;\n");
        builder.append("          -webkit-transition-duration: 0.4s;\n");
        builder.append("          transition-duration: 0.4s;\n");
        builder.append("          cursor: pointer;\n");
        builder.append("      }\n");
        builder.append("      .sender {\n");
        builder.append("          background-color: white; \n");
        builder.append("          color: black; \n");
        builder.append("          border: 2px solid #008CBA;\n");
        builder.append("          width: 100%;\n");
        builder.append("          word-wrap: break-word;\n");
        builder.append("      }\n");
        builder.append("      .sender:hover {\n");
        builder.append("          background-color: #008CBA;\n");
        builder.append("          color: white;\n");
        builder.append("      }\n");
        builder.append("      .highlight {\n");
        builder.append("        background: #b4b9d2;\n");
        builder.append("        color:black;\n");
        builder.append("        border-top: 1px solid #22262e;\n");
        builder.append("        border-bottom: 1px solid #22262e;\n");
        builder.append("      }\n");
        builder.append("      .highlight:nth-child(odd) td {\n");
        builder.append("        background: #b4b9d2;\n");
        builder.append("      }\n");
        builder.append("      .click {\n");
        builder.append("        cursor:pointer;\n");
        builder.append("        cursor:hand;\n");
        builder.append("      }\n");
        builder.append("      table {\n");
        builder.append("        background: white;\n");
        builder.append("        table-layout:fixed;\n");
        builder.append("        border-collapse: collapse;\n");
        builder.append("        word-wrap:break-word;\n");
        builder.append("        border-radius:3px;\n");
        builder.append("        border-collapse: collapse;\n");
        builder.append("        margin: auto;\n");
        builder.append("        padding:2px;\n");
        builder.append("        width: 100%;\n");
        builder.append("        box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);\n");
        builder.append("        animation: float 5s infinite;\n");
        builder.append("      }\n");
        builder.append("      th {\n");
        builder.append("        color:#FFFFFF;;\n");
        builder.append("        background:#1b1e24;\n");
        builder.append("        border-bottom:4px solid #9ea7af;\n");
        builder.append("        border-right: 0px;\n");
        builder.append("        font-size:16px;\n");
        builder.append("        font-weight: bold;\n");
        builder.append("        padding:4px;\n");
        builder.append("        text-align:left;\n");
        builder.append("        text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);\n");
        builder.append("        vertical-align:middle;\n");
        builder.append("        height:30px;\n");
        builder.append("      }\n");
        builder.append("      tr {\n");
        builder.append("        border-top: 1px solid #C1C3D1;\n");
        builder.append("        border-bottom-: 1px solid #C1C3D1;\n");
        builder.append("        font-size:16px;\n");
        builder.append("        font-weight:normal;\n");
        builder.append("        text-shadow: 0 1px 1px rgba(256, 256, 256, 0.1);\n");
        builder.append("      }\n");
        builder.append("      tr:nth-child(odd) td {\n");
        builder.append("        background:#EBEBEB;\n");
        builder.append("      }\n");
        builder.append("      td {\n");
        builder.append("        padding:2px;\n");
        builder.append("        vertical-align:middle;\n");
        builder.append("        font-size:16px;\n");
        builder.append("        text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);\n");
        builder.append("        border-right: 1px solid #C1C3D1;\n");
        builder.append("      }\n");
        builder.append("      input[type=text], select {\n");
        builder.append("        width: 400px;\n");
        builder.append("        padding: 0px 4px;\n");
        builder.append("        margin: 1px 0;\n");
        builder.append("        display: inline-block;\n");
        builder.append("        background: #b4b9d2;\n");
        builder.append("        border: 1px solid #ccc;\n");
        builder.append("        border-radius: 4px;\n");
        builder.append("        box-sizing: border-box;\n");
        builder.append("      }\n");
        builder.append("    </style>\n");
        // JavaScript functions.
        TreeMap<Long, Query> queryMap = user.getQueryMap(null, null);
        builder.append(
                "    <script type=\"text/javascript\" src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js\"></script>\n");
        builder.append("    <script type=\"text/javascript\">\n");
        builder.append("      window.onbeforeunload = function () {\n");
        builder.append("        document.getElementById('filterField').value = '';\n");
        builder.append("        window.scrollTo(0, 0);\n");
        builder.append("      }\n");
        builder.append("      var last = ");
        if (queryMap.isEmpty()) {
            builder.append(0);
        } else {
            builder.append(queryMap.lastKey());
        }
        builder.append(";\n");
        builder.append("      var filterText = '';\n");
        builder.append("      function view(query) {\n");
        builder.append("        if (query == undefined || query == 0) {\n");
        builder.append("          var viewer = document.getElementById('viewer');\n");
        builder.append("          viewer.src = 'about:blank';\n");
        builder.append("          last = 0;\n");
        builder.append("        } else if (last != query) {\n");
        builder.append("          var viewer = document.getElementById('viewer');\n");
        builder.append("          viewer.addEventListener('load', function() {\n");
        builder.append("            if (document.getElementById(last)) {\n");
        builder.append("              document.getElementById(last).className = 'tr';\n");
        builder.append("              document.getElementById(last).className = 'click';\n");
        builder.append("            }\n");
        builder.append("            document.getElementById(query).className = 'highlight';\n");
        builder.append("            last = query;\n");
        builder.append("          });\n");
        builder.append("          viewer.src = '");
        builder.append(Core.getURL());
        builder.append("' + query;\n");
        builder.append("        }\n");
        builder.append("      }\n");
        builder.append("      function more(query) {\n");
        builder.append("        var rowMore = document.getElementById('rowMore');\n");
        builder.append("        rowMore.onclick = '';\n");
        builder.append("        rowMore.className = 'tr';\n");
        builder.append("        var columnMore = document.getElementById('columnMore');\n");
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("        columnMore.innerHTML = 'carregando mais registros';\n");
        } else {
            builder.append("        columnMore.innerHTML = 'loading more records';\n");
        }
        builder.append("        $.post(\n");
        builder.append("          '");
        builder.append(Core.getURL());
        builder.append(user.getEmail());
        builder.append("',\n");
        builder.append("          {filter:filterText,begin:query},\n");
        builder.append("          function(data, status) {\n");
        builder.append("            if (status == 'success') {\n");
        builder.append("              rowMore.parentNode.removeChild(rowMore);\n");
        builder.append("              $('#tableBody').append(data);\n");
        builder.append("            } else {\n");
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append(
                    "              alert('Houve uma falha de sistema ao tentar realizar esta operao.');\n");
        } else {
            builder.append(
                    "              alert('There was a system crash while trying to perform this operation.');\n");
        }
        builder.append("            }\n");
        builder.append("          }\n");
        builder.append("        );\n");
        builder.append("      }\n");
        builder.append("      function refresh() {\n");
        builder.append("        filterText = document.getElementById('filterField').value;\n");
        builder.append("        $.post(\n");
        builder.append("          '");
        builder.append(Core.getURL());
        builder.append(user.getEmail());
        builder.append("',\n");
        builder.append("          {filter:filterText},\n");
        builder.append("          function(data, status) {\n");
        builder.append("            if (status == 'success') {\n");
        builder.append("              $('#tableBody').html(data);\n");
        builder.append("              view($('#tableBody tr').attr('id'));\n");
        builder.append("            } else {\n");
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append(
                    "              alert('Houve uma falha de sistema ao tentar realizar esta operao.');\n");
        } else {
            builder.append(
                    "              alert('There was a system crash while trying to perform this operation.');\n");
        }
        builder.append("            }\n");
        builder.append("          }\n");
        builder.append("        );\n");
        builder.append("      }\n");
        builder.append("    </script>\n");
        builder.append("  </head>\n");
        // Body.
        builder.append("  <body>\n");
        builder.append("    <div class=\"header\">\n");
        if (queryMap.isEmpty()) {
            builder.append("      <iframe id=\"viewer\" src=\"about:blank\"></iframe>\n");
        } else {
            builder.append("      <iframe id=\"viewer\" src=\"");
            builder.append(Core.getURL());
            builder.append(queryMap.lastKey());
            builder.append("\"></iframe>\n");
        }
        // Construo da tabela de consultas.
        builder.append("      <table>\n");
        builder.append("        <thead>\n");
        builder.append("          <tr>\n");
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("            <th style=\"width:120px;\">Recepo</th>\n");
            builder.append("            <th>Origem</th>\n");
            builder.append("            <th>Remetente</th>\n");
            builder.append("            <th>Contedo</th>\n");
            builder.append("            <th>Entrega</th>\n");
        } else {
            builder.append("            <th style=\"width:160px;\">Reception</th>\n");
            builder.append("            <th style=\"width:auto;\">Source</th>\n");
            builder.append("            <th style=\"width:auto;\">Sender</th>\n");
            builder.append("            <th style=\"width:auto;\">Content</th>\n");
            builder.append("            <th style=\"width:auto;\">Delivery</th>\n");
        }
        builder.append("          </tr>\n");
        builder.append("        </thead>\n");
        builder.append("      </table>\n");
        builder.append("    </div>\n");
        if (queryMap.isEmpty()) {
            builder.append("    <table>\n");
            builder.append("      <tbody>\n");
            builder.append("        <tr>\n");
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append(
                        "          <td colspan=\"5\" align=\"center\">nenhum registro encontrado</td>\n");
            } else {
                builder.append("          <td colspan=\"5\" align=\"center\">no records found</td>\n");
            }
            builder.append("        </tr>\n");
            builder.append("      </tbody>\n");
            builder.append("    </table>\n");
        } else {
            DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
            GregorianCalendar calendar = new GregorianCalendar();
            Long nextQuery = null;
            while (queryMap.size() > User.QUERY_MAX_ROWS) {
                nextQuery = queryMap.pollFirstEntry().getKey();
            }
            builder.append("    <table>\n");
            builder.append("      <tbody id=\"tableBody\">\n");
            for (Long time : queryMap.descendingKeySet()) {
                User.Query query = queryMap.get(time);
                boolean highlight = time.equals(queryMap.lastKey());
                buildQueryRow(locale, builder, dateFormat, calendar, time, query, highlight);
            }
            if (nextQuery == null) {
                builder.append("      <tr>\n");
                if (locale.getLanguage().toLowerCase().equals("pt")) {
                    builder.append(
                            "        <td colspan=\"5\" align=\"center\">no foram encontrados outros registros</td>\n");
                } else {
                    builder.append("        <td colspan=\"5\" align=\"center\">no more records found</td>\n");
                }
                builder.append("      </tr>\n");
            } else {
                builder.append("        <tr id=\"rowMore\" class=\"click\" onclick=\"more('");
                builder.append(nextQuery);
                builder.append("')\">\n");
                if (locale.getLanguage().toLowerCase().equals("pt")) {
                    builder.append(
                            "          <td id=\"columnMore\" colspan=\"5\" align=\"center\">clique para ver mais registros</td>\n");
                } else {
                    builder.append(
                            "          <td id=\"columnMore\" colspan=\"5\" align=\"center\">click to see more records</td>\n");
                }
                builder.append("        </tr>\n");
            }
            builder.append("      </tbody>\n");
            builder.append("    </table>\n");
        }
        builder.append("    <div class=\"bottom\">\n");
        builder.append("      <table>\n");
        builder.append("        <tr>\n");
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append(
                    "          <th>Pesquisar <input type=\"text\" id=\"filterField\" name=\"filterField\" onkeydown=\"if (event.keyCode == 13) refresh();\" autofocus></th>\n");
        } else {
            builder.append(
                    "          <th>Search <input type=\"text\" id=\"filterField\" name=\"filterField\" onkeydown=\"if (event.keyCode == 13) refresh();\" autofocus></th>\n");
        }
        builder.append("          <th style=\"text-align:right;\"><small>");
        builder.append(
                "Powered by <a target=\"_blank\" href=\"http://spfbl.net/\" style=\"color: #b4b9d2;\">SPFBL.net</a></small>");
        builder.append("</th>\n");
        builder.append("        </tr>\n");
        builder.append("      <table>\n");
        builder.append("    </div>\n");
        builder.append("  </body>\n");
        builder.append("</html>\n");
    } else {
        TreeMap<Long, Query> queryMap = user.getQueryMap(begin, filter);
        if (queryMap.isEmpty()) {
            builder.append("        <tr>\n");
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append(
                        "          <td colspan=\"5\" align=\"center\">nenhum registro encontrado</td>\n");
            } else {
                builder.append("          <td colspan=\"5\" align=\"center\">no records found</td>\n");
            }
            builder.append("        </tr>\n");
        } else {
            DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
            GregorianCalendar calendar = new GregorianCalendar();
            Long nextQuery = null;
            while (queryMap.size() > User.QUERY_MAX_ROWS) {
                nextQuery = queryMap.pollFirstEntry().getKey();
            }
            for (Long time : queryMap.descendingKeySet()) {
                User.Query query = queryMap.get(time);
                buildQueryRow(locale, builder, dateFormat, calendar, time, query, false);
            }
            if (nextQuery == null) {
                builder.append("        <tr>\n");
                if (locale.getLanguage().toLowerCase().equals("pt")) {
                    builder.append(
                            "          <td colspan=\"5\" align=\"center\">no foram encontrados outros registros</td>\n");
                } else {
                    builder.append("          <td colspan=\"5\" align=\"center\">no more records found</td>\n");
                }
                builder.append("        </tr>\n");
            } else {
                builder.append("        <tr id=\"rowMore\" class=\"click\" onclick=\"more('");
                builder.append(nextQuery);
                builder.append("')\">\n");
                if (locale.getLanguage().toLowerCase().equals("pt")) {
                    builder.append(
                            "          <td id=\"columnMore\" colspan=\"5\" align=\"center\">clique para ver mais registros</td>\n");
                } else {
                    builder.append(
                            "          <td id=\"columnMore\" colspan=\"5\" align=\"center\">click to see more records</td>\n");
                }
                builder.append("        </tr>\n");
            }
        }
    }
    return builder.toString();
}