001    package org.jgnuplot;
002    
003    import java.io.File;
004    
005    /**
006     * This class models graphs, defined in terms of functions or data files, that
007     * are used by the plot command.
008     * 
009     * @author Pander
010     */
011    public class Graph {
012       private String itsDataFileName;
013    
014       private String itsUsing;
015    
016       private String itsDataModifiers;
017    
018       private String itsFunction;
019    
020       private String itsAxes;
021    
022       private String itsName;
023    
024       private int itsStyle;
025    
026       private int itsLineType;
027    
028       private int itsPointType;
029    
030       // function
031       public Graph(String theFunction, int theAxes, String theName, int theStyle,
032             int theLineType, int thePointType) {
033          itsFunction = theFunction;
034          itsAxes = Axes.toString(theAxes);
035          itsName = theName;
036          itsStyle = theStyle;
037          itsLineType = theLineType;
038          itsPointType = thePointType;
039       }
040    
041       // function
042       public Graph(String theFunction, int theAxes, String theName, int theStyle) {
043          itsFunction = theFunction;
044          itsAxes = Axes.toString(theAxes);
045          itsName = theName;
046          itsStyle = theStyle;
047          itsLineType = LineType.NOT_SPECIFIED;
048          itsPointType = PointType.NOT_SPECIFIED;
049       }
050    
051       // function
052       public Graph(String theFunction, int theAxes, String theName) {
053          itsFunction = theFunction;
054          itsAxes = Axes.toString(theAxes);
055          itsName = theName;
056          itsStyle = Style.NOT_SPECIFIED;
057          itsLineType = LineType.NOT_SPECIFIED;
058          itsPointType = PointType.NOT_SPECIFIED;
059       }
060    
061       // function
062       public Graph(String theFunction, int theAxes) {
063          itsFunction = theFunction;
064          itsAxes = Axes.toString(theAxes);
065          itsName = null;
066          itsStyle = Style.NOT_SPECIFIED;
067          itsLineType = LineType.NOT_SPECIFIED;
068          itsPointType = PointType.NOT_SPECIFIED;
069       }
070    
071       // function
072       public Graph(String theFunction) {
073          itsFunction = theFunction;
074          itsAxes = Axes.toString(Axes.NOT_SPECIFIED);
075          itsName = null;
076          itsStyle = Style.NOT_SPECIFIED;
077          itsLineType = LineType.NOT_SPECIFIED;
078          itsPointType = PointType.NOT_SPECIFIED;
079       }
080    
081       // datafile
082       public Graph(String theDataFileName, String theUsing,
083             String theDataModifiers, int theAxes, String theName, int theStyle,
084             int theLineType, int thePointType) {
085          if (theDataFileName == null) {
086             throw new IllegalArgumentException("DataFileName cannot be null");
087          }
088          // make path absolute for .plt file which is in temp directory
089          if (!theDataFileName.startsWith(File.separator)
090                && theDataFileName.charAt(1) != ':') {
091             itsDataFileName = (new File("")).getAbsolutePath() + File.separator
092                   + theDataFileName;
093          }
094          else {
095             itsDataFileName = theDataFileName;
096          }
097          // escape backslashes
098          itsDataFileName = itsDataFileName.replaceAll("\\\\", "\\\\\\\\");
099          itsUsing = theUsing;
100          itsDataModifiers = theDataModifiers;
101          itsAxes = Axes.toString(theAxes);
102          itsName = theName;
103          itsStyle = theStyle;
104          itsLineType = theLineType;
105          itsPointType = thePointType;
106       }
107    
108       // datafile
109       public Graph(String theDataFileName, String theUsing, int theAxes,
110             String theName, int theStyle, int theLineType, int thePointType) {
111          if (theDataFileName == null) {
112             throw new IllegalArgumentException("DataFileName cannot be null");
113          }
114          // make path absolute for .plt file which is in temp directory
115          if (!theDataFileName.startsWith(File.separator)
116                && theDataFileName.charAt(1) != ':') {
117             itsDataFileName = (new File("")).getAbsolutePath() + File.separator
118                   + theDataFileName;
119          }
120          else {
121             itsDataFileName = theDataFileName;
122          }
123          // escape backslashes
124          itsDataFileName = itsDataFileName.replaceAll("\\\\", "\\\\\\\\");
125          itsUsing = theUsing;
126          itsAxes = Axes.toString(theAxes);
127          itsName = theName;
128          itsStyle = theStyle;
129          itsLineType = theLineType;
130          itsPointType = thePointType;
131       }
132    
133       // datafile
134       public Graph(String theDataFileName, String theUsing, int theAxes,
135             int theStyle, int theLineType, int thePointType) {
136          if (theDataFileName == null) {
137             throw new IllegalArgumentException("DataFileName cannot be null");
138          }
139          // make path absolute for .plt file which is in temp directory
140          if (!theDataFileName.startsWith(File.separator)
141                && theDataFileName.charAt(1) != ':') {
142             itsDataFileName = (new File("")).getAbsolutePath() + File.separator
143                   + theDataFileName;
144          }
145          else {
146             itsDataFileName = theDataFileName;
147          }
148          // escape backslashes
149          itsDataFileName = itsDataFileName.replaceAll("\\\\", "\\\\\\\\");
150          itsUsing = theUsing;
151          itsAxes = Axes.toString(theAxes);
152          itsName = "";
153          itsStyle = theStyle;
154          itsLineType = theLineType;
155          itsPointType = thePointType;
156       }
157    
158       // datafile
159       public Graph(String theDataFileName, String theUsing, int theAxes,
160             String theName, int theStyle) {
161          if (theDataFileName == null) {
162             throw new IllegalArgumentException("DataFileName cannot be null");
163          }
164          // make path absolute for .plt file which is in temp directory
165          if (!theDataFileName.startsWith(File.separator)
166                && theDataFileName.charAt(1) != ':') {
167             itsDataFileName = (new File("")).getAbsolutePath() + File.separator
168                   + theDataFileName;
169          }
170          else {
171             itsDataFileName = theDataFileName;
172          }
173          // escape backslashes
174          itsDataFileName = itsDataFileName.replaceAll("\\\\", "\\\\\\\\");
175          itsUsing = theUsing;
176          itsAxes = Axes.toString(theAxes);
177          itsName = theName;
178          itsStyle = theStyle;
179          itsLineType = LineType.NOT_SPECIFIED;
180          itsPointType = PointType.NOT_SPECIFIED;
181       }
182    
183       public Graph(Graph theGraph) {
184          itsFunction = theGraph.getFunction();
185          itsDataFileName = theGraph.getDataFileName();
186          itsDataModifiers = theGraph.getDataModifiers();
187          itsUsing = theGraph.getUsing();
188          itsAxes = theGraph.getAxes();
189          itsName = theGraph.getName();
190          itsStyle = theGraph.getStyle();
191          itsLineType = theGraph.getLineType();
192          itsPointType = theGraph.getPointType();
193       }
194    
195       public final void setFunction(String theFunction) {
196          itsFunction = theFunction;
197          itsDataFileName = null;
198          itsDataModifiers = null;
199       }
200    
201       public final void setName(String theName) {
202          itsName = theName;
203       }
204    
205       public final String getFunction() {
206          return itsFunction;
207       }
208    
209       public final String getDataFileName() {
210          return itsDataFileName;
211       }
212    
213       public final String getUsing() {
214          return itsUsing;
215       }
216    
217       public final String getDataModifiers() {
218          return itsDataModifiers;
219       }
220    
221       public final String getAxes() {
222          return itsAxes;
223       }
224    
225       public final String getName() {
226          return itsName;
227       }
228    
229       public final int getStyle() {
230          return itsStyle;
231       }
232    
233       public final int getLineType() {
234          return itsLineType;
235       }
236    
237       public final int getPointType() {
238          return itsPointType;
239       }
240    
241       public final boolean isFunction() {
242          if (itsFunction == null) {
243             return false;
244          }
245          return true;
246       }
247    }