001 /* ============================================================
002 * JRobin : Pure java implementation of RRDTool's functionality
003 * ============================================================
004 *
005 * Project Info: http://www.jrobin.org
006 * Project Lead: Sasa Markovic (saxon@jrobin.org)
007 *
008 * Developers: Sasa Markovic (saxon@jrobin.org)
009 *
010 *
011 * (C) Copyright 2003-2005, by Sasa Markovic.
012 *
013 * This library is free software; you can redistribute it and/or modify it under the terms
014 * of the GNU Lesser General Public License as published by the Free Software Foundation;
015 * either version 2.1 of the License, or (at your option) any later version.
016 *
017 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
018 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
019 * See the GNU Lesser General Public License for more details.
020 *
021 * You should have received a copy of the GNU Lesser General Public License along with this
022 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
023 * Boston, MA 02111-1307, USA.
024 */
025 package org.jrobin.graph;
026
027 import java.util.ArrayList;
028 import java.util.List;
029
030 /**
031 * Class to represent successfully created JRobin graph. Objects of this class are created by method
032 * {@link RrdGraph#getRrdGraphInfo()}.
033 */
034 public class RrdGraphInfo {
035 String filename;
036 int width, height;
037 byte[] bytes;
038 String imgInfo;
039 private List<String> printLines = new ArrayList<String>();
040
041 RrdGraphInfo() {
042 // cannot instantiate this class
043 }
044
045 void addPrintLine(String printLine) {
046 printLines.add(printLine);
047 }
048
049 /**
050 * Returns filename of the graph
051 *
052 * @return filename of the graph. '-' denotes in-memory graph (no file created)
053 */
054 public String getFilename() {
055 return filename;
056 }
057
058 /**
059 * Returns total graph width
060 *
061 * @return total graph width
062 */
063 public int getWidth() {
064 return width;
065 }
066
067 /**
068 * Returns total graph height
069 *
070 * @return total graph height
071 */
072 public int getHeight() {
073 return height;
074 }
075
076 /**
077 * Returns graph bytes
078 *
079 * @return Graph bytes
080 */
081 public byte[] getBytes() {
082 return bytes;
083 }
084
085 /**
086 * Returns PRINT lines requested by {@link RrdGraphDef#print(String, String, String)} method.
087 *
088 * @return An array of formatted PRINT lines
089 */
090 public String[] getPrintLines() {
091 return printLines.toArray(new String[printLines.size()]);
092 }
093
094 /**
095 * Returns image information requested by {@link RrdGraphDef#setImageInfo(String)} method
096 *
097 * @return Image information
098 */
099 public String getImgInfo() {
100 return imgInfo;
101 }
102
103 /**
104 * Returns the number of bytes in the graph file
105 *
106 * @return Length of the graph file
107 */
108 public int getByteCount() {
109 return bytes != null ? bytes.length : 0;
110 }
111
112 /**
113 * Dumps complete graph information. Useful for debugging purposes.
114 *
115 * @return String containing complete graph information
116 */
117 public String dump() {
118 StringBuffer b = new StringBuffer();
119 b.append("filename = \"").append(getFilename()).append("\"\n");
120 b.append("width = ").append(getWidth()).append(", height = ").append(getHeight()).append("\n");
121 b.append("byteCount = ").append(getByteCount()).append("\n");
122 b.append("imginfo = \"").append(getImgInfo()).append("\"\n");
123 String[] plines = getPrintLines();
124 if (plines.length == 0) {
125 b.append("No print lines found\n");
126 }
127 else {
128 for (int i = 0; i < plines.length; i++) {
129 b.append("print[").append(i).append("] = \"").append(plines[i]).append("\"\n");
130 }
131 }
132 return b.toString();
133 }
134 }