~ubuntu-branches/ubuntu/maverick/cdk/maverick

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/renderer/GraphRendererModel.java

  • Committer: Bazaar Package Importer
  • Author(s): Paul Cager
  • Date: 2008-04-09 21:17:53 UTC
  • Revision ID: james.westby@ubuntu.com-20080409211753-46lmjw5z8mx5pd8d
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Revision: 7636 $ $Author: egonw $ $Date: 2007-01-04 18:46:10 +0100 (Thu, 04 Jan 2007) $
 
2
 *
 
3
 * Copyright (C) 2001-2007  Stephan Michels <stephan@vern.chem.tu-berlin.de>
 
4
 * 
 
5
 * Contact: cdk-devel@lists.sourceforge.net
 
6
 * 
 
7
 * This program is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public License
 
9
 * as published by the Free Software Foundation; either version 2.1
 
10
 * of the License, or (at your option) any later version.
 
11
 * All we ask is that proper credit is given for our work, which includes
 
12
 * - but is not limited to - adding the above copyright notice to the beginning
 
13
 * of your source code files, and to any copyright notice that you may distribute
 
14
 * with programs based on this work.
 
15
 * 
 
16
 * This program is distributed in the hope that it will be useful,
 
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
 * GNU Lesser General Public License for more details.
 
20
 * 
 
21
 * You should have received a copy of the GNU Lesser General Public License
 
22
 * along with this program; if not, write to the Free Software
 
23
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
24
 *
 
25
 */
 
26
package org.openscience.cdk.renderer;
 
27
 
 
28
import java.awt.Color;
 
29
 
 
30
import org.openscience.cdk.math.IFunction;
 
31
 
 
32
/**
 
33
 * This class handles a set of function for the GraphRenderer
 
34
 *
 
35
 * @author  Stephan Michels <stephan@vern.chem.tu-berlin.de>
 
36
 * @cdk.created 2001-07-02
 
37
 */ 
 
38
public class GraphRendererModel
 
39
{
 
40
  private double xmin = -1d;
 
41
  private double xmax = +1d;
 
42
  private double ymin = -1d;
 
43
  private double ymax = +1d;
 
44
 
 
45
  private String title = "Main title"; // Main title
 
46
  private String xtitle = "X title"; // Title of the x axis
 
47
  private String ytitle = "Y title"; // Title of the y axis
 
48
 
 
49
  private java.util.Vector functions = new java.util.Vector();
 
50
  private java.util.Vector colors = new java.util.Vector();
 
51
 
 
52
  /** Paints the function normal */
 
53
  public final static int NORMAL = 0;
 
54
  /** Paints the area below the function */
 
55
  public final static int BELOWAREA = 1;
 
56
  /** Paints the area over the function */
 
57
  public final static int OVERAREA = 2;
 
58
 
 
59
  private int displaymode = NORMAL;
 
60
 
 
61
  /**
 
62
   * Sets the function area, which will painted
 
63
   */
 
64
  public void setX(double xmin, double xmax)
 
65
  {
 
66
    if (xmin<xmax)
 
67
    {
 
68
      this.xmin = xmin;
 
69
      this.xmax = xmax;
 
70
    }
 
71
  }
 
72
 
 
73
  /**
 
74
   * Sets the function area, which will painted
 
75
   */
 
76
  public void setY(double ymin, double ymax)
 
77
  {
 
78
    if (ymin<ymax)
 
79
    {
 
80
      this.ymin = ymin;
 
81
      this.ymax = ymax;
 
82
    }
 
83
  }
 
84
 
 
85
  /**
 
86
   * Gets the function area, which will painted
 
87
   */
 
88
  public double getXMin()
 
89
  {
 
90
    return xmin;
 
91
  }
 
92
 
 
93
  /**
 
94
   * Sets the function area, which will painted
 
95
   */
 
96
  public double getXMax()
 
97
  {
 
98
    return xmax;
 
99
  }
 
100
 
 
101
  /**
 
102
   * Sets the function area, which will painted
 
103
   */
 
104
  public double getYMin()
 
105
  {
 
106
    return ymin;
 
107
  }
 
108
 
 
109
  /**
 
110
   * Sets the function area, which will painted
 
111
   */
 
112
  public double getYMax()
 
113
  {
 
114
    return ymax;
 
115
  }
 
116
 
 
117
  /**
 
118
   * Set the main title
 
119
   */
 
120
  public void setTitle(String string)
 
121
  {
 
122
    if (string!=null)
 
123
      title = string;
 
124
  }
 
125
 
 
126
  /**
 
127
   * Get the main title
 
128
   */
 
129
  public String getTitle()
 
130
  {
 
131
    return title;
 
132
  }
 
133
 
 
134
  /**
 
135
   * Set the title of the x axis
 
136
   */
 
137
  public void setXTitle(String string)
 
138
  {
 
139
    if (string!=null)
 
140
      xtitle = string;
 
141
  }
 
142
 
 
143
  /**
 
144
   * Get the title of the x axis
 
145
   */
 
146
  public String getXTitle()
 
147
  {
 
148
    return xtitle;
 
149
  }
 
150
 
 
151
  /**
 
152
   * Set the title of the y axis
 
153
   */
 
154
  public void setYTitle(String string)
 
155
  {
 
156
    if (string!=null)
 
157
      ytitle = string;
 
158
  }
 
159
 
 
160
  /**
 
161
   * Get the title of the y axis
 
162
   */
 
163
  public String getYTitle()
 
164
  {
 
165
    return ytitle;
 
166
  }
 
167
 
 
168
  /**
 
169
   * Set the display mode
 
170
   */
 
171
  public void setDisplayMode(int mode)
 
172
  {
 
173
    if ((NORMAL<=mode) && (mode<=OVERAREA))
 
174
      displaymode = mode;
 
175
  }
 
176
 
 
177
  /**
 
178
   * Get the display mode
 
179
   */
 
180
  public int getDisplayMode()
 
181
  {
 
182
    return displaymode;
 
183
  }
 
184
 
 
185
  /**
 
186
   * Add a function to the set of functions
 
187
   */
 
188
  public void addFunction(IFunction function)
 
189
  {
 
190
    if ((function!=null) && (!functions.contains(function)))
 
191
    {
 
192
      functions.add(function);
 
193
      colors.add(Color.black);
 
194
    }
 
195
  }
 
196
  
 
197
  /**
 
198
   * Add a function to the set of functions
 
199
   */
 
200
  public void addFunction(IFunction function, Color color)
 
201
  {
 
202
    if ((function!=null) && (!functions.contains(function)))
 
203
    {
 
204
      functions.add(function);
 
205
      colors.add(color);
 
206
    }
 
207
    else
 
208
      colors.setElementAt(color, functions.indexOf(function));
 
209
  }
 
210
 
 
211
  /**
 
212
   * Get the count of functions in this set
 
213
   */
 
214
  public int getFunctionsSize()
 
215
  {
 
216
    return functions.size();
 
217
  }
 
218
 
 
219
  /**
 
220
   * Get a function from this set
 
221
   */
 
222
  public IFunction getFunction(int index)
 
223
  {
 
224
    return (IFunction) functions.elementAt(index);
 
225
  }
 
226
 
 
227
  /**
 
228
   * Get a color from a function in this set
 
229
   */
 
230
  public Color getFunctionColor(int index)
 
231
  {
 
232
    return (Color) colors.elementAt(index);
 
233
  }
 
234
}