1 /* ============================================================
2 * JRobin : Pure java implementation of RRDTool's functionality
3 * ============================================================
4 *
5 * Project Info: http://www.jrobin.org
6 * Project Lead: Sasa Markovic (saxon@jrobin.org)
7 *
8 * Developers: Sasa Markovic (saxon@jrobin.org)
9 *
10 *
11 * (C) Copyright 2003-2005, by Sasa Markovic.
12 *
13 * This library is free software; you can redistribute it and/or modify it under the terms
14 * of the GNU Lesser General Public License as published by the Free Software Foundation;
15 * either version 2.1 of the License, or (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 * See the GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License along with this
22 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23 * Boston, MA 02111-1307, USA.
24 */
25 package org.jrobin.graph;
26
27 import java.util.ArrayList;
28 import java.util.List;
29
30 /**
31 * Class to represent successfully created JRobin graph. Objects of this class are created by method
32 * {@link RrdGraph#getRrdGraphInfo()}.
33 */
34 public class RrdGraphInfo {
35 String filename;
36 int width, height;
37 byte[] bytes;
38 String imgInfo;
39 private List<String> printLines = new ArrayList<String>();
40
41 RrdGraphInfo() {
42 // cannot instantiate this class
43 }
44
45 void addPrintLine(String printLine) {
46 printLines.add(printLine);
47 }
48
49 /**
50 * Returns filename of the graph
51 *
52 * @return filename of the graph. '-' denotes in-memory graph (no file created)
53 */
54 public String getFilename() {
55 return filename;
56 }
57
58 /**
59 * Returns total graph width
60 *
61 * @return total graph width
62 */
63 public int getWidth() {
64 return width;
65 }
66
67 /**
68 * Returns total graph height
69 *
70 * @return total graph height
71 */
72 public int getHeight() {
73 return height;
74 }
75
76 /**
77 * Returns graph bytes
78 *
79 * @return Graph bytes
80 */
81 public byte[] getBytes() {
82 return bytes;
83 }
84
85 /**
86 * Returns PRINT lines requested by {@link RrdGraphDef#print(String, String, String)} method.
87 *
88 * @return An array of formatted PRINT lines
89 */
90 public String[] getPrintLines() {
91 return printLines.toArray(new String[printLines.size()]);
92 }
93
94 /**
95 * Returns image information requested by {@link RrdGraphDef#setImageInfo(String)} method
96 *
97 * @return Image information
98 */
99 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 }
135