Source code: graph/LineDrawer.java
1 /* Copyright 1998 - 2003: Jim Cochrane - see file forum.txt */
2
3 package graph;
4
5 import java.awt.*;
6 import java.util.*;
7 import support.*;
8
9 /**
10 * Abstraction for drawing data tuples as points connected by lines
11 */
12 public class LineDrawer extends IndicatorDrawer {
13
14 public LineDrawer(MarketDrawer md) { super(md); }
15
16 /**
17 * Draw the data bars and the line segments connecting them.
18 * @param g Graphics context
19 * @param w Data window
20 */
21 protected void draw_tuples(Graphics g, Rectangle bounds) {
22 int i, row;
23 int x0, y0;
24 int x1, y1;
25 int lngth = 0;
26 int right_adjust = bar_width() / 2;
27 if (_data != null) lngth = _data.length;
28 double height_factor;
29 Configuration conf = Configuration.instance();
30 if (draw_color == null) {
31 draw_color = conf.line_color();
32 }
33 int[] _x_values = x_values();
34
35 // Is there any data to draw? Sometimes the draw command will
36 // will be called before any data has been placed in the class.
37 if (lngth == 0 || _x_values == null) return;
38
39 g.setColor(draw_color);
40 height_factor = height_factor_value(bounds);
41 row = first_row() - 1;
42 x0 = _x_values[row] + right_adjust;
43 y0 = (int)(bounds.height - (_data[0]-ymin) * height_factor + bounds.y);
44 ++row;
45
46 for (i = 1; row < _x_values.length && i < lngth; ++i, ++row) {
47 x1 = _x_values[row] + right_adjust;
48 y1 = (int)(bounds.height - (_data[i]-ymin) * height_factor +
49 bounds.y);
50 g.drawLine(x0,y0,x1,y1);
51
52 x0 = x1;
53 y0 = y1;
54 }
55 }
56
57 void draw_reference_values(Graphics g, Rectangle main_bounds,
58 Rectangle ref_bounds) {
59 super.draw_reference_values(g, main_bounds, ref_bounds);
60 }
61 }