Esempio n. 1
0
        private static void ColorSample(HtmlRenderer html, string s)
        {
            int        c     = ColorParser.Parse(s);
            Parameters style = new Parameters();

            if (c == ColorParser.InvalidColor)
            {
                style["color"]            = "#000000";
                style["background-color"] = "#ffffff";
            }
            else
            {
                s = "#" + c.ToString("x6");
                style["color"]            = s;
                style["background-color"] = s;
                HlsColor hls = ColorTransform.RgbToHls(ColorTransform.IntToRgb(c));
                if (hls.L > 800)
                {
                    style["border"] = "1px solid #808080";
                }
            }
            html.Add("<div");
            html.Style(style);
            html.Add(">");
            html.Add(String.IsNullOrEmpty(s) ? "X" : "?");
            html.Add("</div>");
        }
Esempio n. 2
0
        protected string RenderMessage()
        {
            if (this.message == null)
            {
                return(String.Empty);
            }



            HtmlRenderer html = new HtmlRenderer();

            html.Add("<tr><td align=\"center\" style=\"padding:8px;font-size:small;color:#909090;\" colspan=\"2\">");
            html.Text(this.message);
            html.Add("</td></tr>");

            if (this.paletteId > 0)
            {
                PaletteManager mgr = new PaletteManager(Utils.ConnectionString);
                PaletteItem    pi  = mgr.Load(this.paletteId);

                if (pi.Id == this.paletteId)
                {
                    html.Add("<tr><td align=\"center\" style=\"padding:2px;font-size:small;color:#909090; border:2px solid #909090;\" colspan=\"2\">");
                    html.Add("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
                    search.RenderPaletteItem(html, pi, this.parameters["Key", String.Empty], false);
                    search.RenderPaletteItem(html, pi, this.parameters["Key", String.Empty], true);
                    html.Add("</table></td></tr>");
                }
            }

            return(html.ToString());
        }
Esempio n. 3
0
 private static void EmptyResultTable(HtmlRenderer html, string message)
 {
     html.Clear();
     html.Add("<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">");
     html.Add("<tr valign=\"middle\"><td class=\"empty_results\">");
     html.Image("img/error.png", "Warning");
     html.Add("</td><td class=\"empty_results\">");
     html.Text(message);
     html.Add("</td></tr></table>");
 }
Esempio n. 4
0
        private static void RenderPager(HtmlRenderer html, int page, int lastPage)
        {
            if (lastPage == 1)
            {
                return;
            }

            html.Add("\r\n<tr><td align=\"left\" colspan=\"2\">");
            html.Add("<table border=\"0\" cellpadding=\"0\" cellspacing=\"4\"><tr valign=\"middle\">");

            if (lastPage <= 5)
            {
                for (int i = 1; i <= lastPage; i++)
                {
                    search.RenderPageMarker(html, i, i == page);
                }
            }
            else
            {
                int l = page - 2;
                int h = page + 2;
                if (l < 1)
                {
                    l = 1;
                    h = l + 4;
                }
                if (h > lastPage)
                {
                    h = lastPage;
                    l = h - 4;
                }
                if (l > 1)
                {
                    search.RenderPageMarker(html, 1, 1 == page);
                    if (l > 2)
                    {
                        html.Add("<td style=\"font-size:20px;color:#909090;\">&nbsp;&nbsp;...&nbsp;&nbsp;</td>");
                    }
                }
                for (int i = l; i <= h; i++)
                {
                    search.RenderPageMarker(html, i, i == page);
                }
                if (h < lastPage)
                {
                    if ((h + 1) < lastPage)
                    {
                        html.Add("<td style=\"font-size:20px;color:#909090;\">&nbsp;&nbsp;...&nbsp;&nbsp;</td>");
                    }
                    search.RenderPageMarker(html, lastPage, lastPage == page);
                }
            }
            html.Add("</tr></table></td></tr>");
        }
Esempio n. 5
0
        protected string RenderError()
        {
            if (this.errorMessage == null)
            {
                return(String.Empty);
            }



            HtmlRenderer html = new HtmlRenderer();

            html.Add("<tr><td align=\"center\" style=\"padding:16px;\" colspan=\"2\">");
            html.Error(this.errorMessage, null);
            html.Add("</td></tr>");

            return(html.ToString());
        }
Esempio n. 6
0
        private static void RenderPageMarker(HtmlRenderer html, int page, bool current)
        {
            Parameters attrs = new Parameters();

            attrs["align"] = "center";
            attrs["class"] = current ? "pager_selected" : "pager_page";
            if (!current)
            {
                Parameters p = new Parameters();
                p.Set("Page", (long)page);
                attrs["onclick"] = "submitEvent('" + Utils.PackEvent("page", p) + "');";
            }
            html.Add("td", attrs, true);

            html.Text(page.ToString());

            html.Add("</td>");
        }
Esempio n. 7
0
        protected string RenderCheckbox(string name, string paramName)
        {
            HtmlRenderer html = new HtmlRenderer();

            html.Add("<input");
            html.Add("type", "checkbox");
            html.Add("name", name);
            html.Add("value", "yes");
            if (this.parameters.Get(paramName, false))
            {
                html.Add("checked", "yes");
            }
            html.Add("/>");
            return(html.ToString());
        }
Esempio n. 8
0
        private static void ColorInfo(HtmlRenderer html, string s)
        {
            if (String.IsNullOrEmpty(s))
            {
                html.Text("Color not specified");
                return;
            }
            int c = ColorParser.Parse(s);

            if (c == ColorParser.InvalidColor)
            {
                html.Text("Invalid color string");
                return;
            }

            html.Text("WEB #" + c.ToString("x6"));

            Color cc = Color.FromArgb(c);

            html.Text(String.Format(", RGB({0},{1},{2}),",
                                    ((double)cc.R / 255f).ToString("######0.0##"),
                                    ((double)cc.G / 255f).ToString("######0.0##"),
                                    ((double)cc.B / 255f).ToString("######0.0##")));

            HlsColor hls = ColorTransform.RgbToHls(cc);

            html.Add("<br>");
            html.Text(String.Format("HLS({0},{1},{2})",
                                    ((double)hls.H / 100f).ToString("######0.0##"),
                                    ((double)hls.L / 1000f).ToString("######0.0##"),
                                    ((double)hls.S / 1000f).ToString("######0.0##")));

            LabColor lab = ColorTransform.RgbToLab(cc);

            html.Text(String.Format(", LAB({0},{1},{2})",
                                    lab.L.ToString("######0.0##"),
                                    lab.A.ToString("######0.0##"),
                                    lab.B.ToString("######0.0##")));
        }
Esempio n. 9
0
        public static void RenderPaletteItem(HtmlRenderer html, PaletteItem item, string key, bool black)
        {
            html.Add("\r\n<tr");
            html.Add("valign", "middle");
            html.Add("bgcolor", black ? "#000000" : "#ffffff");
            html.Add("><td align=\"center\"");

            Parameters style = new Parameters();

            style["border-bottom"] = "2px solid #909090";
            style["padding"]       = "8px";
            style["font-size"]     = "small";
            style["color"]         = black ? "#c0c0c0" : "#404040";

            html.Style(style);

            html.Add(">");

            if (search.showThumblains)
            {
                Parameters par = new Parameters();
                par["Id"]  = item.Id.ToString();
                par["Key"] = key;
                html.Image("handler.ashx?q=thumbnail&t=" + HttpUtility.UrlEncode(par.Serialize()), "Palette source image thumbnail");
            }
            else
            {
                html.Text("No image");
            }

            html.Add("</td>\r\n<td");
            html.Add("align", "left");

            html.Style(style);

            html.Add(">");

            html.Add("<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\"><tr><td align=\"left\"");

            style.Clear();
            style["padding"]       = "8px";
            style["border-bottom"] = "1px solid #909090";

            html.Style(style);

            html.Add(">");

            if (item.Colors.Length > 0)
            {
                html.Add("<table border=\"0\" cellpadding=\"0\" cellspacing=\"4\"><tr valign=\"middle\">");

                style.Clear();
                style["width"]       = "96px";
                style["height"]      = "56px";
                style["padding-top"] = "40px";
                style["text-align"]  = "center";

                for (int i = 0; i < item.Colors.Length; i++)
                {
                    html.Add("<td><div");

                    string c = "#" + (item.Colors[i].ToArgb() & 0xffffff).ToString("x6");

                    style["background-color"] = c;

                    HlsColor hls = ColorTransform.RgbToHls(item.Colors[i]);

                    style["color"] = hls.L > 500 ? "#202020" : "#f0f0f0";

                    html.Style(style);

                    html.Add(">");

                    html.Text(c);

                    html.Add("</div></td>");
                }


                html.Add("</tr></table>");
            }
            else
            {
                html.Text("Empty color list");
            }

            html.Add("</td></tr>\r\n<tr><td");

            style.Clear();
            style["font-size"] = "medium";
            style["padding"]   = "8px";
            style["color"]     = black ? "#c0c0c0" : "#404040";

            html.Style(style);

            html.Add(">");

            html.Text(item.Title);

            html.Add("</td></tr></table></td></tr>");
        }
Esempio n. 10
0
        protected string RenderSearchResults()
        {
            Color  color1 = Color.Transparent;
            Color  color2 = Color.Transparent;
            bool   ok     = true;
            string s      = this.parameters["_Color1", null];

            if (!String.IsNullOrEmpty(s))
            {
                long c = ColorParser.Parse(s);
                if (c == ColorParser.InvalidColor)
                {
                    ok = false;
                }
                else
                {
                    color1 = ColorTransform.IntToRgb((int)c);
                }
            }
            s = this.parameters["_Color2", null];
            if (!String.IsNullOrEmpty(s))
            {
                long c = ColorParser.Parse(s);
                if (c == ColorParser.InvalidColor)
                {
                    ok = false;
                }
                else
                {
                    color2 = ColorTransform.IntToRgb((int)c);
                }
            }

            HtmlRenderer html = new HtmlRenderer();

            if (!ok)
            {
                search.EmptyResultTable(html, "One of the colors is invalid");
                return(html.ToString());
            }
            if ((color1 == Color.Transparent) && (color2 == Color.Transparent))
            {
                search.EmptyResultTable(html, "One of the colors must be specified");
                return(html.ToString());
            }

            PaletteManager     mgr    = new PaletteManager(Utils.ConnectionString);
            List <PaletteItem> result = null;
            string             msg    = null;

            try
            {
                DateTime start = DateTime.Now;

                result = mgr.Find(color1, color2,
                                  (ColorSearchWidth)this.parameters.Get("_Comparison", (long)ColorSearchWidth.Wide),
                                  this.parameters.Get("_ShowSimilar", false),
                                  1000);

                if (result != null)
                {
                    if (result.Count > 0)
                    {
                        PaletteListSortMode mode = (PaletteListSortMode)this.parameters.Get("_Sort", (long)PaletteListSortMode.Title);
                        PaletteManager.Sort(result, mode, mode == PaletteListSortMode.ClusterColor ? mgr.LoadClusters() : null);
                    }
                    else
                    {
                        result = null;
                    }
                }
                double sec = DateTime.Now.Subtract(start).TotalSeconds;
                if (result != null)
                {
                    msg = String.Format("{0} item(s) found, {1} seconds", result.Count, sec.ToString("#####0.0##"));
                }
            }
            catch
            {
                result = null;
            }
            if (result == null)
            {
                search.EmptyResultTable(html, "No palette(s) found or error occured");
                return(html.ToString());
            }

            bool paging = !this.parameters.Get("_ShowAll", false);

            int first     = 0;
            int last      = result.Count - 1;
            int pageCount = 0;
            int page      = 0;

            if (paging)
            {
                pageCount = result.Count / search.PageSize;
                if ((pageCount * search.PageSize) < result.Count)
                {
                    pageCount++;
                }

                page = (int)this.parameters.Get("Page", 1L);

                if (page < 1)
                {
                    page = 1;
                }
                if (page > pageCount)
                {
                    page = pageCount;
                }

                this.parameters.Set("Page", (long)page);

                first = (page - 1) * search.PageSize;
                last  = first + search.PageSize;
                if (last >= result.Count)
                {
                    last = result.Count - 1;
                }
            }

            html.Add("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");

            if (msg != null)
            {
                html.Add("<tr><td colspan=\"2\" align=\"center\" style=\"font-size:small;color:#909090;padding-bottom:2px;\">");
                html.Text(msg);
                html.Add("</td></tr>");
            }

            string key   = Utils.GetTimeKey(60);
            bool   black = (BackgroundColor)this.parameters.Get("BgColor", (long)BackgroundColor.White) == BackgroundColor.Black;

            if (paging)
            {
                search.RenderPager(html, page, pageCount);
            }

            for (int i = first; i <= last; i++)
            {
                search.RenderPaletteItem(html, result[i], key, black);
            }

            if (paging)
            {
                search.RenderPager(html, page, pageCount);
            }

            html.Add("</table>");

            return(html.ToString());
        }