You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ecs-dev@jakarta.apache.org by rd...@apache.org on 2002/01/10 23:34:31 UTC
cvs commit: jakarta-ecs/src/java/org/apache/ecs/examples WebColors.java
rdonkin 02/01/10 14:34:31
Modified: src/java/org/apache/ecs/examples WebColors.java
Log:
Christian Brensing <ho...@gmx.de> submitted an improved version of his ecs example
Revision Changes Path
1.3 +102 -110 jakarta-ecs/src/java/org/apache/ecs/examples/WebColors.java
Index: WebColors.java
===================================================================
RCS file: /home/cvs/jakarta-ecs/src/java/org/apache/ecs/examples/WebColors.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WebColors.java 6 Nov 2001 23:06:44 -0000 1.2
+++ WebColors.java 10 Jan 2002 22:34:31 -0000 1.3
@@ -15,23 +15,23 @@
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
- * "This product includes software developed by the Java Apache
+ * "This product includes software developed by the Java Apache
* Project. <http://java.apache.org/>"
*
- * 4. The names "Java Apache Element Construction Set", "Java Apache ECS" and
- * "Java Apache Project" must not be used to endorse or promote products
+ * 4. The names "Java Apache Element Construction Set", "Java Apache ECS" and
+ * "Java Apache Project" must not be used to endorse or promote products
* derived from this software without prior written permission.
*
- * 5. Products derived from this software may not be called
- * "Java Apache Element Construction Set" nor "Java Apache ECS" appear
- * in their names without prior written permission of the
+ * 5. Products derived from this software may not be called
+ * "Java Apache Element Construction Set" nor "Java Apache ECS" appear
+ * in their names without prior written permission of the
* Java Apache Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
- * "This product includes software developed by the Java Apache
+ * "This product includes software developed by the Java Apache
* Project. <http://java.apache.org/>"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -62,107 +62,99 @@
* This simple servlet displays the 216 safe web colors that can be
* rendered by any browser on any platform.
*
+ * @version 1.1, 2001/12/30, removed all CSS code and switched back
+ * to full HTML 3.2 compatibility
+ * @version 1.0, 2001/07/04, initial release
* @author <a href="mailto:horombo@gmx.de">Christian Brensing</a>
- * @version 1.0, 04.07.2001
*/
-public class WebColors extends HttpServlet {
-
- /** Valid rgb components */
- private String[] hex = { "00","33","66","99","CC","FF" };
-
- /**
- * Processes a GET request.
- */
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
-
- // Set response type to html
- response.setContentType("text/html");
-
- // Get PrintWriter
- PrintWriter out = response.getWriter();
-
- // New <html>
- Html html = new Html();
-
- // New <head>
- Head head = new Head();
- Title title = new Title("The 216 safe web colors");
- head.addElement(title);
-
- // Add <head> to <html>
- html.addElement(head);
-
- // New <body>
- Body body = new Body();
- body.setStyle("background: none white;");
-
- // New <table>
- Table table = new Table();
- table.setCellSpacing(0).setAlign("center");
- table.setStyle("border: none; width: 600px; "
- .concat("font: normal 10pt Times,serif;"));
-
- // Modulate green
- for (int g = 0; g < hex.length; g++) {
-
- // Get current green component
- String green = hex[g];
-
- // Modulate red
- for (int r = 0; r < hex.length; r++) {
-
- // Get current red component
- String red = hex[r];
-
- // New <tr>
- TR tr = new TR();
- tr.setStyle("color: white;");
-
- // Change fontcolor if cell background is to bright
- if (g > 3) { tr.setStyle("color: black;"); }
-
- // Modulate blue
- for (int b = 0; b < hex.length; b++) {
-
- // Get current blue component
- String blue = hex[b];
-
- // Generate new rgb with modulated green, red and blue
- StringBuffer rgb = new StringBuffer("#");
- rgb.append(red).append(green).append(blue);
-
- // New <td> for each color
- TD td = new TD(rgb.toString()).setAlign("center");
-
- // Generate background style for each color
- StringBuffer bg = new StringBuffer("background: ");
- bg.append("none ").append(rgb.toString()).append(";");
-
- // Set background for this <td>-tag
- td.setStyle(bg.toString());
-
- // Add <td> to <tr>
- tr.addElement(td);
-
- } // next b
-
- // Add this <tr> to <table>
- table.addElement(tr);
-
- } // next r
-
- } // next g
-
- // Add <table> to <body>
- body.addElement(table);
-
- // Add <body> to <html>
- html.addElement(body);
-
- // Return <html>
- out.println(html.toString());
-
- } // doGet
-
-} // WebColors
\ No newline at end of file
+public class WebColors extends HttpServlet
+{
+ /**
+ * Valid RGB components.
+ */
+ private String[] hex = { "00","33","66","99","CC","FF" };
+
+ /**
+ * Processes a GET request.
+ */
+ public void doGet(HttpServletRequest request, HttpServletResponse
+ response) throws ServletException, IOException
+ {
+ // Set response type to html
+ response.setContentType("text/html");
+
+ // Get PrintWriter
+ PrintWriter out = response.getWriter();
+
+ // New <html>
+ Html html = new Html();
+
+ // New <head> with <title>
+ Head head = new Head(new Title
+ ("The 216 safe web colors"));
+
+ // Add <head> to <html>
+ html.addElement(head);
+
+ // New <body> with white background-color
+ Body body = new Body().setBgColor("#FFFFFF");
+
+ // New <table> with no border
+ Table table = new Table(0).setWidth(600);
+ table.setCellSpacing(0).setAlign("center");
+
+ // Modulate green
+ for (int g = 0; g < hex.length; g++)
+ {
+ // Get current green component
+ String green = hex[g];
+
+ // Modulate red
+ for (int r = 0; r < hex.length; r++)
+ {
+ // Get current red component
+ String red = hex[r];
+
+ // New <tr>
+ TR tr = new TR();
+
+ // Modulate blue
+ for (int b = 0; b < hex.length; b++)
+ {
+ // Get current blue component
+ String blue = hex[b];
+
+ // New RGB with modulated green, red and blue
+ String rgb = "#" + red + green + blue;
+
+ // New <font> with white foreground-color
+ Font font = new Font().setColor("#FFFFFF");
+
+ // Change font-color if cell background is to bright
+ if (g > 3) { font.setColor("#000000"); }
+
+ // New <td> for each color
+ TD td = new TD(font.addElement(rgb));
+
+ // Set background for this <td>-tag
+ td.setBgColor(rgb).setAlign("center");
+
+ // Add <td> to <tr>
+ tr.addElement(td);
+ }
+
+ // Add this <tr> to <table>
+ table.addElement(tr);
+ }
+ }
+
+ // Add <table> to <body>
+ body.addElement(table);
+
+ // Add <body> to <html>
+ html.addElement(body);
+
+ // Return <html>
+ out.println(html.toString());
+ }
+}
\ No newline at end of file
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>