spark-1.2-src/ 000700 000765 000024 00000000000 11474330132 013541 5 ustar 00larry staff 000000 000000 spark-1.2-src/build.properties 000644 000765 000024 00000000000 10454015201 016750 0 ustar 00larry staff 000000 000000 spark-1.2-src/build.xml 000644 000765 000024 00000006350 10456770132 015407 0 ustar 00larry staff 000000 000000
spark-1.2-src/docs/ 000755 000765 000024 00000000000 10572117021 014501 5 ustar 00larry staff 000000 000000 spark-1.2-src/lib/ 000755 000765 000024 00000000000 10575064435 014334 5 ustar 00larry staff 000000 000000 spark-1.2-src/LICENSE.txt 000644 000765 000024 00000026136 10572077137 015421 0 ustar 00larry staff 000000 000000
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
spark-1.2-src/src/ 000755 000765 000024 00000000000 11474330050 014341 5 ustar 00larry staff 000000 000000 spark-1.2-src/test/ 000755 000765 000024 00000000000 11474330050 014531 5 ustar 00larry staff 000000 000000 spark-1.2-src/test/com/ 000755 000765 000024 00000000000 11474330050 015307 5 ustar 00larry staff 000000 000000 spark-1.2-src/test/com/representqueens/ 000755 000765 000024 00000000000 11474330050 020537 5 ustar 00larry staff 000000 000000 spark-1.2-src/test/com/representqueens/spark/ 000755 000765 000024 00000000000 11474330050 021657 5 ustar 00larry staff 000000 000000 spark-1.2-src/test/com/representqueens/util/ 000755 000765 000024 00000000000 11474330050 021514 5 ustar 00larry staff 000000 000000 spark-1.2-src/test/com/representqueens/util/StringUtilsTest.java 000644 000765 000024 00000002665 10572077361 025532 0 ustar 00larry staff 000000 000000 /*
* $Id: StringUtilsTest.java,v 1.1 2007-03-02 19:45:53 larry Exp $
*/
package com.representqueens.util;
/*
*
* Copyright 2007 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
/**
* @author Larry Ogrodnek
* @version $Revision: 1.1 $ $Date: 2007-03-02 19:45:53 $
*/
public class StringUtilsTest extends TestCase
{
/**
* Test method for {@link com.representqueens.util.StringUtils#toString(java.util.List)}.
*/
public void testToStringListOfInteger()
{
final List data = new ArrayList();
assertEquals("", StringUtils.toString(data));
data.add(5);
assertEquals("5", StringUtils.toString(data));
data.add(6);
assertEquals("5,6", StringUtils.toString(data));
data.add(7);
assertEquals("5,6,7", StringUtils.toString(data));
}
}
spark-1.2-src/test/com/representqueens/spark/TestColor.java 000644 000765 000024 00000003154 10575064532 024455 0 ustar 00larry staff 000000 000000 /*
* $Id: TestColor.java,v 1.7 2007-03-11 20:40:58 larry Exp $
*/
package com.representqueens.spark;
/*
*
* Copyright 2006 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.representqueens.util.ColorUtils;
/**
* @author Larry Ogrodnek
* @version $Revision: 1.7 $ $Date: 2007-03-11 20:40:58 $
*/
public class TestColor
{
public static void main(final String[] args)
throws IOException
{
final Number[] data = {5, 23, 11, 25, -19, 4, 2, 3, -13, 2, 3, 4, 5};
final Color color = ColorUtils.parseColor("black");
final Color back = ColorUtils.parseColor("red");
System.out.println("Found color: " + color);
final BufferedImage i = LineGraph.createGraph(data, LineGraph.DEFAULT_SIZE, color, back);
//final BufferedImage i = BarGraph.createGraph(data, BarGraph.DEFAULT_SIZE, color, null, null);
final File file = new File(args[0]);
ImageIO.write(i, "png", file);
}
}
spark-1.2-src/test/com/representqueens/spark/TestEncoder.java 000644 000765 000024 00000002420 10456770620 024751 0 ustar 00larry staff 000000 000000 /*
* $Id: TestEncoder.java,v 1.3 2006/07/17 20:22:40 larry Exp $
*/
package com.representqueens.spark;
/*
*
* Copyright 2006 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.awt.image.BufferedImage;
import java.io.IOException;
/**
* @author Larry Ogrodnek
* @version $Revision: 1.3 $ $Date: 2006/07/17 20:22:40 $
*/
public class TestEncoder
{
/**
* @param args
*/
public static void main(final String[] args) throws IOException
{
final Number[] data = {3, 5, 3, 7, 20, 17, 12, 4, 13, 11, 7, 20, 17, 7, 9, 8, 10, 12};
final BufferedImage i = BarGraph.createGraph(data);
//final BufferedImage i = LineGraph.createGraph(data);
System.out.println(Encoder.encode(i, Encoder.Format.DATA));
}
}
spark-1.2-src/test/com/representqueens/spark/TestGraph.java 000644 000765 000024 00000002474 10456770620 024444 0 ustar 00larry staff 000000 000000 /*
* $Id: TestGraph.java,v 1.5 2006/07/17 20:22:40 larry Exp $
*/
package com.representqueens.spark;
/*
*
* Copyright 2006 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
* @author Larry Ogrodnek
* @version $Revision: 1.5 $ $Date: 2006/07/17 20:22:40 $
*/
public class TestGraph
{
public static void main(final String[] args)
throws IOException
{
final Number[] data = {3, 5, 3, 7, 20, 17, 12, 4, 13, 11, 7, 20, 17, 7, 9, 8, 10, 12};
final BufferedImage i = BarGraph.createGraph(data);
//final BufferedImage i = LineGraph.createGraph(data);
final File file = new File(args[0]);
ImageIO.write(i, "png", file);
}
}
spark-1.2-src/test/com/representqueens/spark/VisitorGraph.java 000644 000765 000024 00000003346 10456770620 025163 0 ustar 00larry staff 000000 000000 /*
* $Id: VisitorGraph.java,v 1.2 2006/07/17 20:22:40 larry Exp $
*/
package com.representqueens.spark;
/*
*
* Copyright 2006 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.representqueens.util.StringUtils;
/**
* @author Larry Ogrodnek
* @version $Revision: 1.2 $ $Date: 2006/07/17 20:22:40 $
*/
public final class VisitorGraph
{
/**
* @param args
*/
public static void main(final String[] args) throws IOException
{
final BufferedReader br = new BufferedReader(new FileReader(args[0]));
final Number[] data =
StringUtils.toIntList(br.readLine(), "\\s+").toArray(new Number[0]);
final BufferedImage i =
BarGraph.createGraph(data, BarGraph.DEFAULT_SIZE,
BarGraph.DEFAULT_COLOR,
BarGraph.DEFAULT_HIGH_COLOR,
BarGraph.DEFAULT_LAST_COLOR);
final File out = new File(args[2]);
if (out.exists())
{
out.delete();
}
ImageIO.write(i, "png", out);
}
}
spark-1.2-src/src/com/ 000755 000765 000024 00000000000 11474330050 015117 5 ustar 00larry staff 000000 000000 spark-1.2-src/src/manifest.mf 000644 000765 000024 00000000300 10454016663 016474 0 ustar 00larry staff 000000 000000 Manifest-Version: 1.0
Name: com/representqueens/web/tags/spark
Sealed: true
Implementation-Title: "Sparkline Tag Library"
Implementation-Version: "1.1"
Implementation-Vendor: "Larry Ogrodnek"
spark-1.2-src/src/META-INF/ 000755 000765 000024 00000000000 11474330050 015501 5 ustar 00larry staff 000000 000000 spark-1.2-src/src/META-INF/spark.tld 000644 000765 000024 00000006746 10575064736 017363 0 ustar 00larry staff 000000 000000
Sparkline generation1.11.2sparkhttp://www.representqueens.com/taglibs/sparkbar
com.representqueens.web.tags.spark.BarGraph
emptynametruefalsewidthfalsetrueheightfalsetruespacingfalsetruecolorfalsetruehighColorfalsetruelastColorfalsetruebackgroundfalsetruepathfalsetrueoutputfalsetrueline
com.representqueens.web.tags.spark.LineGraph
emptynametruefalsewidthfalsetrueheightfalsetruespacingfalsetruecolorfalsetruebackgroundfalsetruepathfalsetrueoutputfalsetrue spark-1.2-src/src/META-INF/spark_em.tld 000644 000765 000024 00000005614 10572064350 020022 0 ustar 00larry staff 000000 000000
Sparkline generation1.11.2sparkhttp://www.representqueens.com/taglibs/spark_embar
com.representqueens.web.tags.spark.embedded.BarGraph
emptynametruefalsewidthfalsetrueheightfalsetruespacingfalsetruecolorfalsetruehighColorfalsetruelastColorfalsetrueoutputfalsetrueline
com.representqueens.web.tags.spark.embedded.LineGraph
emptynametruefalsewidthfalsetrueheightfalsetruespacingfalsetruecolorfalsetrueoutputfalsetrue spark-1.2-src/src/com/representqueens/ 000755 000765 000024 00000000000 11474330050 020347 5 ustar 00larry staff 000000 000000 spark-1.2-src/src/com/representqueens/spark/ 000755 000765 000024 00000000000 11474330050 021467 5 ustar 00larry staff 000000 000000 spark-1.2-src/src/com/representqueens/util/ 000755 000765 000024 00000000000 11474330050 021324 5 ustar 00larry staff 000000 000000 spark-1.2-src/src/com/representqueens/web/ 000755 000765 000024 00000000000 11474330050 021124 5 ustar 00larry staff 000000 000000 spark-1.2-src/src/com/representqueens/web/tags/ 000755 000765 000024 00000000000 11474330050 022062 5 ustar 00larry staff 000000 000000 spark-1.2-src/src/com/representqueens/web/tags/spark/ 000755 000765 000024 00000000000 11474330050 023202 5 ustar 00larry staff 000000 000000 spark-1.2-src/src/com/representqueens/web/tags/spark/AbstractGraph.java 000644 000765 000024 00000011565 10575064532 026614 0 ustar 00larry staff 000000 000000 /*
* $Id: AbstractGraph.java,v 1.3 2007-03-11 20:40:58 larry Exp $
*/
package com.representqueens.web.tags.spark;
/*
*
* Copyright 2006 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.List;
import javax.servlet.jsp.tagext.TagSupport;
import com.representqueens.spark.BarGraph;
import com.representqueens.spark.Encoder;
import com.representqueens.spark.LineGraph;
import com.representqueens.spark.SizeParams;
import com.representqueens.spark.Encoder.Format;
import com.representqueens.spark.util.StringConversion;
import com.representqueens.util.StringUtils;
/**
* @author Larry Ogrodnek
* @version $Revision: 1.3 $ $Date: 2007-03-11 20:40:58 $
*/
public abstract class AbstractGraph extends TagSupport
{
private String name;
private String width;
private String height;
private String spacing;
private String color;
private String highColor;
private String lastColor;
private String background;
private String output;
public String getColor()
{
return this.color;
}
public void setColor(final String color)
{
this.color = color;
}
public String getHeight()
{
return this.height;
}
public void setHeight(final String height)
{
this.height = height;
}
public String getName()
{
return this.name;
}
public void setName(final String name)
{
this.name = name;
}
public String getOutput()
{
return this.output;
}
public void setOutput(final String output)
{
this.output = output;
}
public String getSpacing()
{
return this.spacing;
}
public void setSpacing(final String spacing)
{
this.spacing = spacing;
}
public String getWidth()
{
return this.width;
}
public void setWidth(final String width)
{
this.width = width;
}
public String getHighColor()
{
return this.highColor;
}
public void setHighColor(final String highColor)
{
this.highColor = highColor;
}
public String getLastColor()
{
return this.lastColor;
}
public void setLastColor(final String lastColor)
{
this.lastColor = lastColor;
}
public String getBackground()
{
return this.background;
}
public void setBackground(final String background)
{
this.background = background;
}
protected String getBarGraphData() throws IOException
{
final BufferedImage image =
BarGraph.createGraph(getData(),
getSizeParams(BarGraph.DEFAULT_SIZE),
StringConversion.convertColor(this.color, BarGraph.DEFAULT_COLOR),
StringConversion.convertColor(this.highColor, null),
StringConversion.convertColor(this.lastColor, null));
return Encoder.encode(image, getOutputFormat());
}
protected String getLineGraphData() throws IOException
{
final BufferedImage image =
LineGraph.createGraph(getData(),
getSizeParams(LineGraph.DEFAULT_SIZE),
StringConversion.convertColor(this.color, LineGraph.DEFAULT_COLOR));
return Encoder.encode(image, getOutputFormat());
}
protected SizeParams getSizeParams(final SizeParams defaults)
{
return new SizeParams(StringConversion.convertInt(this.width, defaults.getWidth()),
StringConversion.convertInt(this.height, defaults.getHeight()),
StringConversion.convertInt(this.spacing, defaults.getSpacing()));
}
protected Number[] getData()
{
final Object o = this.pageContext.findAttribute(this.name);
if (o instanceof List)
{
final List l = (List) o;
return (Number[]) l.toArray(new Number[l.size()]);
}
if (o instanceof Number[])
{
return (Number[]) o;
}
if (o instanceof String)
{
try
{
final List l = StringUtils.toIntList((String) o);
return l.toArray(new Number[l.size()]);
}
catch (final NumberFormatException nfe)
{
// fall through...
}
}
return new Number[0];
}
protected Format getOutputFormat()
{
if (! StringUtils.isEmpty(this.output))
{
if ("data".equalsIgnoreCase(this.output))
{
return Format.DATA;
}
}
return Format.JAVASCRIPT;
}
}
spark-1.2-src/src/com/representqueens/web/tags/spark/AbstractServerGraph.java 000644 000765 000024 00000005143 10575064532 027776 0 ustar 00larry staff 000000 000000 /*
* $Id: AbstractServerGraph.java,v 1.3 2007-03-11 20:40:58 larry Exp $
*/
package com.representqueens.web.tags.spark;
/*
*
* Copyright 2007 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import javax.servlet.http.HttpServletRequest;
import com.representqueens.util.StringUtils;
/**
* @author Larry Ogrodnek
* @version $Revision: 1.3 $ $Date: 2007-03-11 20:40:58 $
*/
public abstract class AbstractServerGraph extends AbstractGraph
{
private static final String DEFAULT_PATH = "/spark";
private String path;
public String getPath()
{
return this.path;
}
public void setPath(final String path)
{
this.path = path;
}
public String getRealPath()
{
final Object o = this.pageContext.findAttribute("sparkPath");
if (o instanceof String)
{
return convertPath(o.toString());
}
return convertPath((this.path == null ? DEFAULT_PATH : this.path));
}
private String convertPath(final String s)
{
final String c = ((HttpServletRequest) this.pageContext.getRequest()).getContextPath();
return String.format("%s%s", c, s);
}
protected String getQueryParams()
{
final StringBuilder sb = new StringBuilder();
final String[] n = new String[] { "color", "highcolor", "lastcolor", "background", "width", "height", "spacing", "output" };
final String[] p = new String[] { getColor(), getHighColor(), getLastColor(), getBackground(), getWidth(), getHeight(), getSpacing(), getOutput() };
try
{
for (int i = 0; i < n.length; i++)
{
if (!StringUtils.isEmpty(p[i]))
{
sb.append("&").append(n[i]).append("=").append(URLEncoder.encode(p[i], "UTF-8"));
}
}
}
catch (final UnsupportedEncodingException uee)
{
// won't happen...
}
final Number[] data = getData();
if (data != null && data.length > 0)
{
sb.append("&data=");
sb.append(StringUtils.toString(data));
}
return sb.toString();
}
}
spark-1.2-src/src/com/representqueens/web/tags/spark/BarGraph.java 000644 000765 000024 00000002522 10575064532 025546 0 ustar 00larry staff 000000 000000 /*
* $Id: BarGraph.java,v 1.3 2007-03-11 20:40:58 larry Exp $
*/
package com.representqueens.web.tags.spark;
/*
*
* Copyright 2007 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.IOException;
/**
* @author Larry Ogrodnek
* @version $Revision: 1.3 $ $Date: 2007-03-11 20:40:58 $
*/
public final class BarGraph extends AbstractServerGraph
{
@Override
public int doEndTag()
{
try
{
this.pageContext.getOut().write(constructImagePath());
}
catch (final IOException ioe)
{
// nothing to do...
}
return EVAL_PAGE;
}
public String constructImagePath()
{
final StringBuilder sb = new StringBuilder();
sb.append(String.format("%s?type=bar%s", getRealPath(), getQueryParams()));
return sb.toString();
}
}
spark-1.2-src/src/com/representqueens/web/tags/spark/embedded/ 000755 000765 000024 00000000000 11474330050 024733 5 ustar 00larry staff 000000 000000 spark-1.2-src/src/com/representqueens/web/tags/spark/LineGraph.java 000644 000765 000024 00000002525 10575064532 025734 0 ustar 00larry staff 000000 000000 /*
* $Id: LineGraph.java,v 1.3 2007-03-11 20:40:58 larry Exp $
*/
package com.representqueens.web.tags.spark;
/*
*
* Copyright 2007 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.IOException;
/**
* @author Larry Ogrodnek
* @version $Revision: 1.3 $ $Date: 2007-03-11 20:40:58 $
*/
public final class LineGraph extends AbstractServerGraph
{
@Override
public int doEndTag()
{
try
{
this.pageContext.getOut().write(constructImagePath());
}
catch (final IOException ioe)
{
// nothing to do...
}
return EVAL_PAGE;
}
public String constructImagePath()
{
final StringBuilder sb = new StringBuilder();
sb.append(String.format("%s?type=line%s", getRealPath(), getQueryParams()));
return sb.toString();
}
}
spark-1.2-src/src/com/representqueens/web/tags/spark/embedded/BarGraph.java 000644 000765 000024 00000002256 10572077361 027304 0 ustar 00larry staff 000000 000000 /*
* $Id: BarGraph.java,v 1.1 2007-03-02 19:45:53 larry Exp $
*/
package com.representqueens.web.tags.spark.embedded;
/*
*
* Copyright 2006 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.IOException;
import com.representqueens.web.tags.spark.AbstractGraph;
/**
* @author Larry Ogrodnek
* @version $Revision: 1.1 $ $Date: 2007-03-02 19:45:53 $
*/
public class BarGraph extends AbstractGraph
{
@Override
public int doEndTag()
{
try
{
this.pageContext.getOut().write(getBarGraphData());
}
catch (final IOException ioe)
{
// what can we do?
}
return EVAL_PAGE;
}
}
spark-1.2-src/src/com/representqueens/web/tags/spark/embedded/LineGraph.java 000644 000765 000024 00000002261 10572077361 027463 0 ustar 00larry staff 000000 000000 /*
* $Id: LineGraph.java,v 1.1 2007-03-02 19:45:53 larry Exp $
*/
package com.representqueens.web.tags.spark.embedded;
/*
*
* Copyright 2006 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.IOException;
import com.representqueens.web.tags.spark.AbstractGraph;
/**
* @author Larry Ogrodnek
* @version $Revision: 1.1 $ $Date: 2007-03-02 19:45:53 $
*/
public class LineGraph extends AbstractGraph
{
@Override
public int doEndTag()
{
try
{
this.pageContext.getOut().write(getLineGraphData());
}
catch (final IOException ioe)
{
// what can we do?
}
return EVAL_PAGE;
}
}
spark-1.2-src/src/com/representqueens/util/ColorUtils.java 000644 000765 000024 00000004335 10456770620 024305 0 ustar 00larry staff 000000 000000 /*
* $Id: ColorUtils.java,v 1.2 2006/07/17 20:22:40 larry Exp $
*/
package com.representqueens.util;
/*
*
* Copyright 2006 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.awt.Color;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
/**
* Utility methods for parsing Strings into Color Objects.
*
* @author Larry Ogrodnek
* @version $Revision: 1.2 $ $Date: 2006/07/17 20:22:40 $
*/
public final class ColorUtils
{
private ColorUtils() { }
/**
* Parse a String into a Color.
*
* This method will accept either a color name (a field name from {@link Color},
* case insensitive e.g. "red"), or a HTML hex color string (e.g. "#ff0000"
* for Color.RED).
*
* @param s String to parse for color name or color number.
* @return Color for s.
*/
public static Color parseColor(final String s)
{
Color color = null;
if (! StringUtils.isEmpty(s))
{
try
{
color = Color.decode(s);
}
catch (final NumberFormatException nfe)
{
color = colorByField(s);
}
}
return color;
}
private static Color colorByField(final String _s)
{
final Field[] fields = Color.class.getFields();
final String s = _s.toLowerCase();
try
{
for (final Field f : fields)
{
if (f.getName().toLowerCase().equals(s))
{
final int mod = f.getModifiers();
if (Modifier.isStatic(mod) && Modifier.isPublic(mod) && Color.class.equals(f.getType()))
{
return (Color) f.get(null);
}
}
}
}
catch (final IllegalAccessException iae)
{
// ?
}
return null;
}
}
spark-1.2-src/src/com/representqueens/util/StringUtils.java 000644 000765 000024 00000004166 10572077361 024500 0 ustar 00larry staff 000000 000000 /*
* $Id: StringUtils.java,v 1.5 2007-03-02 19:45:53 larry Exp $
*/
package com.representqueens.util;
/*
*
* Copyright 2006 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* Some simple String utilities.
*
* @author Larry Ogrodnek
* @version $Revision: 1.5 $ $Date: 2007-03-02 19:45:53 $
*/
public final class StringUtils
{
private StringUtils() { }
public static boolean isEmpty(final String s)
{
return (s == null || "".equals(s));
}
public static List toIntList(final String s)
{
return toIntList(s, "\\s*,\\s*");
}
public static List toIntList(final String s, final String sep)
{
if (isEmpty(s))
{
return Collections.emptyList();
}
final String[] n = s.split(sep);
final List ret = new ArrayList(n.length);
for (int i=0; i< n.length; i++)
{
ret.add(Integer.parseInt(n[i]));
}
return ret;
}
public static String toString(final Number[] data)
{
return toString(Arrays.asList(data));
}
public static String toString(final List extends Number> data)
{
if (data.size() == 0)
{
return "";
}
if (data.size() == 1)
{
return data.get(0).toString();
}
final StringBuilder sb = new StringBuilder();
for (int i=0; i< data.size() - 1; i++)
{
sb.append(data.get(i)).append(",");
}
sb.append(data.get(data.size() - 1));
return sb.toString();
}
}
spark-1.2-src/src/com/representqueens/spark/BarGraph.java 000644 000765 000024 00000010670 10575064532 024036 0 ustar 00larry staff 000000 000000 /*
* $Id: BarGraph.java,v 1.6 2007-03-11 20:40:58 larry Exp $
*/
package com.representqueens.spark;
/*
*
* Copyright 2006 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
/**
* Bargraph generation.
*
* @author Larry Ogrodnek
* @version $Revision: 1.6 $ $Date: 2007-03-11 20:40:58 $
*/
public class BarGraph
{
public static final int DEFAULT_WIDTH = 100;
public static final int DEFAULT_HEIGHT = 25;
public static final int DEFAULT_SPACING = 2;
public static final SizeParams DEFAULT_SIZE = new SizeParams(DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_SPACING);
public static final Color DEFAULT_COLOR = Color.GRAY;
public static final Color DEFAULT_HIGH_COLOR = Color.BLACK;
public static final Color DEFAULT_LAST_COLOR = Color.RED;
/**
* Create a Bargraph from an array of numbers, using default colors and sizes.
*
* @param data Array of Number Objects.
*
* @return BufferedImage containing a Bargraph of data.
*/
public static BufferedImage createGraph(final Number[] data)
{
return createGraph(data, DEFAULT_SIZE, DEFAULT_COLOR, DEFAULT_HIGH_COLOR, DEFAULT_LAST_COLOR);
}
/**
* Create a Bargraph.
*
* @param data Array of Number Objects to graph.
* @param size SizeParams specifying graph size attributes.
* @param color main graph color
* @param highColor color for above average data points (or null).
* @param lastColor color for last data point (or null).
*
* @return BufferedImage containing a Bargraph of data.
*/
public static BufferedImage createGraph(final Number[] data, final SizeParams size, final Color color, final Color highColor, final Color lastColor)
{
return createGraph(data, size, color, highColor, lastColor, null);
}
/**
* Create a Bargraph.
*
* @param data Array of Number Objects to graph.
* @param size SizeParams specifying graph size attributes.
* @param color main graph color
* @param highColor color for above average data points (or null).
* @param lastColor color for last data point (or null).
* @param background background color, or null for transparency.
*
* @return BufferedImage containing a Bargraph of data.
*/
public static BufferedImage createGraph(final Number[] data, final SizeParams size, final Color color, final Color highColor, final Color lastColor, final Color background)
{
final BufferedImage bi = new BufferedImage(size.getWidth(), size.getHeight(), BufferedImage.TYPE_INT_ARGB);
if (data == null || data.length < 1)
{
return bi;
}
final Graphics2D g = bi.createGraphics();
//g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (background != null)
{
g.setBackground(background);
g.clearRect(0, 0, size.getWidth(), size.getHeight());
}
final float d = GraphUtils.getDivisor(data, size.getHeight());
final int a = getAvg(data);
final int w = (size.getWidth() - (size.getSpacing() * data.length))/ data.length;
int x = 0;
final int y = 0;
int c = 0;
for (final Number i : data)
{
final int h = (int) (i.floatValue() / d);
if (c == (data.length - 1) && lastColor != null)
{
g.setPaint(lastColor);
}
else if (i.intValue() < a || (highColor == null))
{
g.setPaint(color);
}
else
{
g.setPaint(highColor);
}
g.fill(new Rectangle2D.Double(x, y + (size.getHeight() - h), w, i.intValue() / d));
x+=(w + size.getSpacing());
c++;
}
return bi;
}
private static final int getAvg(final Number[] data)
{
int total = 0;
for (final Number i : data)
{
total += i.intValue();
}
return (total / data.length);
}
}
spark-1.2-src/src/com/representqueens/spark/Encoder.java 000644 000765 000024 00000003735 10456770620 023733 0 ustar 00larry staff 000000 000000 /*
* $Id: Encoder.java,v 1.2 2006/07/17 20:22:40 larry Exp $
*/
package com.representqueens.spark;
/*
*
* Copyright 2006 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import javax.imageio.ImageIO;
/**
* Encodes Image data as Strings, using code from David Flanagan's
* website (http://www.davidflanagan.com/).
*
* @author David Flanagan
* @author Larry Ogrodnek
* @version $Revision: 1.2 $ $Date: 2006/07/17 20:22:40 $
*/
public class Encoder
{
public enum Format
{
DATA,
JAVASCRIPT
};
public static String encode(final BufferedImage bi,
final Format format) throws IOException
{
try
{
final ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(bi, "png", os);
final byte[] data = os.toByteArray();
final String rawString = new String(data, "iso8859-1");
String encoded = URLEncoder.encode(rawString, "iso8859-1");
encoded = encoded.replaceAll("\\+", "%20");
if (Format.JAVASCRIPT.equals(format))
{
return "javascript:'" + encoded.replaceAll("%", "\\\\x") + "'";
}
return "data:image/png," + encoded;
}
catch (final UnsupportedEncodingException uee)
{
throw new RuntimeException(uee);
}
}
}
spark-1.2-src/src/com/representqueens/spark/GraphUtils.java 000644 000765 000024 00000002346 10552603721 024425 0 ustar 00larry staff 000000 000000 /*
* $Id: GraphUtils.java,v 1.3 2007-01-15 04:49:21 larry Exp $
*/
package com.representqueens.spark;
/*
*
* Copyright 2006 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @author Larry Ogrodnek
* @version $Revision: 1.3 $ $Date: 2007-01-15 04:49:21 $
*/
final class GraphUtils
{
private GraphUtils() { }
static final float getDivisor(final Number[] data, final int height)
{
float max = Float.MIN_VALUE;
float min = Float.MAX_VALUE;
for (final Number i : data)
{
min = Math.min(min,i.floatValue());
max = Math.max(max,i.floatValue());
}
if (max <= min) {
return 1.0f;
}
return (max-min)/(height-1);
}
}
spark-1.2-src/src/com/representqueens/spark/LineGraph.java 000644 000765 000024 00000007324 10575064532 024223 0 ustar 00larry staff 000000 000000 /*
* $Id: LineGraph.java,v 1.7 2007-03-11 20:40:58 larry Exp $
*/
package com.representqueens.spark;
/*
*
* Copyright 2006 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Line2D;
import java.awt.image.BufferedImage;
/**
* Linegraph generation.
*
* @author Larry Ogrodnek
* @version $Revision: 1.7 $ $Date: 2007-03-11 20:40:58 $
*/
public class LineGraph
{
private static final int WIDTH = 100;
private static final int HEIGHT = 25;
private static final int SPACING = 2;
public static final SizeParams DEFAULT_SIZE = new SizeParams(WIDTH, HEIGHT, SPACING);
public static final Color DEFAULT_COLOR = Color.GRAY;
/**
* Create a Linegraph using defaults.
*
* @param data Array of Number Objects to graph.
*
* @return BufferedImage containing a Linegraph of data.
*/
public static BufferedImage createGraph(final Number[] data)
{
return createGraph(data, DEFAULT_SIZE, DEFAULT_COLOR);
}
/**
* Create a Linegraph.
*
* @param data Array of Number Objects to graph.
* @param size SizeParams specifying graph size attributes.
* @param color graph Color.
*
* @return BufferedImage containing a Linegraph of data.
*/
public static BufferedImage createGraph(final Number[] data, final SizeParams size, final Color color)
{
return createGraph(data, size, color, null);
}
/**
* Create a Linegraph.
*
* @param data Array of Number Objects to graph.
* @param size SizeParams specifying graph size attributes.
* @param color graph Color.
* @param background background color, or null for transparent.
*
* @return BufferedImage containing a Linegraph of data.
*/
public static BufferedImage createGraph(final Number[] data, final SizeParams size, final Color color, final Color background)
{
final BufferedImage bi = new BufferedImage(size.getWidth(), size.getHeight(), BufferedImage.TYPE_INT_ARGB);
if (data == null || data.length < 2)
{
return bi;
}
final Graphics2D g = bi.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (background != null)
{
g.setBackground(background);
g.clearRect(0, 0, size.getWidth(), size.getHeight());
}
float d = GraphUtils.getDivisor(data, size.getHeight());
final int w = (size.getWidth() - (size.getSpacing() * (data.length -1)))/ (data.length - 1);
float min = Float.MAX_VALUE;
for (final Number i : data)
{
min = Math.min(min,i.floatValue());
}
int x = 0;
int y = -1;
if (d == 0.0)
{
//special case -- a horizontal straight line
d = 1.0f;
y = - size.getHeight()/2;
}
for (int i=0; i< data.length - 1; i++)
{
final int px1 = x;
x+= (w + size.getSpacing());
final int px2 = x;
g.setPaint(color);
g.draw(new Line2D.Double(px1, y + (size.getHeight() - ((data[i].floatValue()-min) / d)),
px2, y + (size.getHeight() - ((data[i+1].floatValue()-min) / d))));
}
return bi;
}
}
spark-1.2-src/src/com/representqueens/spark/service/ 000755 000765 000024 00000000000 11474330050 023127 5 ustar 00larry staff 000000 000000 spark-1.2-src/src/com/representqueens/spark/SizeParams.java 000644 000765 000024 00000003332 10456770620 024423 0 ustar 00larry staff 000000 000000 /*
* $Id: SizeParams.java,v 1.2 2006/07/17 20:22:40 larry Exp $
*/
package com.representqueens.spark;
/*
*
* Copyright 2006 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Graph size attributes.
*
* @author Larry Ogrodnek
* @version $Revision: 1.2 $ $Date: 2006/07/17 20:22:40 $
*/
public final class SizeParams
{
private final int width;
private final int height;
private final int spacing;
/**
* Constructor.
*
* @param width graph width (in pixels).
* @param height graph height (in pixels).
* @param spacing spacing between data points (in pixels).
*/
public SizeParams(final int width, final int height, final int spacing)
{
this.width = width;
this.height = height;
this.spacing = spacing;
}
/**
* Get the graph height.
* @return graph height (in pixels).
*/
public int getHeight()
{
return this.height;
}
/**
* Get the spacing between data points.
* @return spacing between data points (in pixels).
*/
public int getSpacing()
{
return this.spacing;
}
/**
* Get the graph width.
* @return graph width (in pixels).
*/
public int getWidth()
{
return this.width;
}
}
spark-1.2-src/src/com/representqueens/spark/util/ 000755 000765 000024 00000000000 11474330050 022444 5 ustar 00larry staff 000000 000000 spark-1.2-src/src/com/representqueens/spark/util/StringConversion.java 000644 000765 000024 00000003635 11474327771 026652 0 ustar 00larry staff 000000 000000 package com.representqueens.spark.util;
/*
*
* Copyright 2006 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import com.representqueens.util.ColorUtils;
import com.representqueens.util.StringUtils;
/**
*
* @author Larry Ogrodnek
* @version $Revision: 1.1 $ $Date: 2006-11-20 02:58:38 $
*/
public final class StringConversion
{
private StringConversion() { }
public static final Number[] getData(final String s)
{
final String[] data = s.split(",");
final List out = new ArrayList(data.length);
for (final String d : data)
{
out.add(Float.parseFloat(d));
}
return out.toArray(new Number[out.size()]);
}
public static final Color convertColor(final String s,
final Color defValue)
{
Color color = null;
if (!StringUtils.isEmpty(s))
{
color = ColorUtils.parseColor(s);
}
return (color == null ? defValue : color);
}
public static final int convertInt(final String s,
final int defValue)
{
if (! StringUtils.isEmpty(s))
{
try
{
return Integer.parseInt(s);
}
catch (final NumberFormatException nfe)
{
// fall through, return default
}
}
return defValue;
}
}
spark-1.2-src/src/com/representqueens/spark/service/SparkController.java 000644 000765 000024 00000007076 10575064532 027142 0 ustar 00larry staff 000000 000000 /*
* $Id: SparkController.java,v 1.3 2007-03-11 20:40:58 larry Exp $
*/
package com.representqueens.spark.service;
/*
*
* Copyright 2007 Larry Ogrodnek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.representqueens.spark.BarGraph;
import com.representqueens.spark.LineGraph;
import com.representqueens.spark.SizeParams;
import com.representqueens.spark.util.StringConversion;
import com.representqueens.util.StringUtils;
/**
* @author Larry Ogrodnek
* @version $Revision: 1.3 $ $Date: 2007-03-11 20:40:58 $
*/
public final class SparkController extends HttpServlet
{
@Override
public void doGet(final HttpServletRequest request,
final HttpServletResponse response) throws IOException
{
final Number[] data = StringConversion.getData(request.getParameter("data"));
final String type = request.getParameter("type");
final BufferedImage image;
if (type != null && type.equals("line"))
{
image = LineGraph.createGraph(data,
getSizeParams(request, LineGraph.DEFAULT_SIZE),
StringConversion.convertColor(request.getParameter("color"), LineGraph.DEFAULT_COLOR),
StringConversion.convertColor(request.getParameter("background"), null));
}
else
{
image = BarGraph.createGraph(data,
getSizeParams(request, BarGraph.DEFAULT_SIZE),
StringConversion.convertColor(request.getParameter("color"), BarGraph.DEFAULT_COLOR),
StringConversion.convertColor(request.getParameter("highcolor"), null),
StringConversion.convertColor(request.getParameter("lastcolor"), null),
StringConversion.convertColor(request.getParameter("background"), null));
}
final String _output = request.getParameter("output");
final String output = StringUtils.isEmpty(_output) ? "png" : _output;
response.setContentType("image/" + output);
ImageIO.write(image, output, response.getOutputStream());
response.getOutputStream().close();
}
@Override
public void doPut(final HttpServletRequest request,
final HttpServletResponse response) throws IOException
{
doGet(request, response);
}
private static SizeParams getSizeParams(final HttpServletRequest request,
final SizeParams defaults)
{
return new SizeParams(StringConversion.convertInt(request.getParameter("width"), defaults.getWidth()),
StringConversion.convertInt(request.getParameter("height"), defaults.getHeight()),
StringConversion.convertInt(request.getParameter("spacing"), defaults.getSpacing()));
}
}
spark-1.2-src/docs/allclasses-frame.html 000644 000765 000024 00000005335 10572117021 020613 0 ustar 00larry staff 000000 000000
All Classes
All Classes
This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
Overview
The Overview page is the front page of this API document and provides a list of all packages with a summary for each. This page can also contain an overall description of the set of packages.
Package
Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:
Interfaces (italic)
Classes
Enums
Exceptions
Errors
Annotation Types
Class/Interface
Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:
Class inheritance diagram
Direct Subclasses
All Known Subinterfaces
All Known Implementing Classes
Class/interface declaration
Class/interface description
Nested Class Summary
Field Summary
Constructor Summary
Method Summary
Field Detail
Constructor Detail
Method Detail
Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
Annotation Type
Each annotation type has its own separate page with the following sections:
Annotation Type declaration
Annotation Type description
Required Element Summary
Optional Element Summary
Element Detail
Enum
Each enum has its own separate page with the following sections:
Enum declaration
Enum description
Enum Constant Summary
Enum Constant Detail
Tree (Class Hierarchy)
There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.
When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
Deprecated API
The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
Index
The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
Prev/Next
These links take you to the next or previous class, interface, package, or related page.
Frames/No Frames
These links show and hide the HTML frames. All pages are available with or without frames.
Serialized Form
Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description.
public static java.awt.Color parseColor(java.lang.String s)
Parse a String into a Color.
This method will accept either a color name (a field name from Color,
case insensitive e.g. "red"), or a HTML hex color string (e.g. "#ff0000"
for Color.RED).
Parameters:
s - String to parse for color name or color number.
Returns an array containing the constants of this enum type, in
the order they're declared. This method may be used to iterate
over the constants as follows:
for(Encoder.Format c : Encoder.Format.values())
System.out.println(c);
Returns:
an array containing the constants of this enum type, in
the order they're declared
valueOf
public static Encoder.FormatvalueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.
The string must match exactly an identifier used to declare an
enum constant in this type. (Extraneous whitespace characters are
not permitted.)
Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
java.lang.IllegalArgumentException - if this enum type has no constant
with the specified name