]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/GenericChart.java
Version 6, October 2008
[GpsPrune.git] / tim / prune / gui / GenericChart.java
1 package tim.prune.gui;
2
3 import java.awt.Color;
4 import java.awt.Dimension;
5 import java.awt.Graphics;
6 import java.awt.event.MouseEvent;
7 import java.awt.event.MouseListener;
8
9 import tim.prune.I18nManager;
10 import tim.prune.data.TrackInfo;
11
12
13 /**
14  * Generic chart component to form baseclass for map and profile charts
15  */
16 public abstract class GenericChart extends GenericDisplay implements MouseListener
17 {
18         protected Dimension MINIMUM_SIZE = new Dimension(200, 250);
19         protected static final int BORDER_WIDTH = 8;
20
21         // Colours
22         private static final Color COLOR_BORDER_BG   = Color.WHITE;
23         private static final Color COLOR_CHART_BG    = Color.WHITE;
24         private static final Color COLOR_CHART_LINE  = Color.BLACK;
25         private static final Color COLOR_NODATA_TEXT = Color.GRAY;
26
27
28         /**
29          * Constructor
30          * @param inTrackInfo track info object
31          */
32         protected GenericChart(TrackInfo inTrackInfo)
33         {
34                 super(inTrackInfo);
35         }
36
37         /**
38          * Override minimum size method to restrict map
39          */
40         public Dimension getMinimumSize()
41         {
42                 return MINIMUM_SIZE;
43         }
44
45         /**
46          * Override paint method to draw map
47          */
48         public void paint(Graphics g)
49         {
50                 super.paint(g);
51                 int width = getWidth();
52                 int height = getHeight();
53                 // border background
54                 g.setColor(COLOR_BORDER_BG);
55                 g.fillRect(0, 0, width, height);
56                 if (width < 2*BORDER_WIDTH || height < 2*BORDER_WIDTH) return;
57                 // blank graph area, with line border
58                 g.setColor(COLOR_CHART_BG);
59                 g.fillRect(BORDER_WIDTH, BORDER_WIDTH, width - 2*BORDER_WIDTH, height-2*BORDER_WIDTH);
60                 g.setColor(COLOR_CHART_LINE);
61                 g.drawRect(BORDER_WIDTH, BORDER_WIDTH, width - 2*BORDER_WIDTH, height-2*BORDER_WIDTH);
62                 // Display message if no data to be displayed
63                 if (_track == null || _track.getNumPoints() <= 0)
64                 {
65                         g.setColor(COLOR_NODATA_TEXT);
66                         g.drawString(I18nManager.getText("display.nodata"), 50, height/2);
67                 }
68         }
69
70
71         /**
72          * Method to inform map that data has changed
73          */
74         public void dataUpdated(byte inUpdateType)
75         {
76                 repaint();
77         }
78
79
80         /**
81          * mouse enter events ignored
82          */
83         public void mouseEntered(MouseEvent e)
84         {}
85
86         /**
87          * mouse exit events ignored
88          */
89         public void mouseExited(MouseEvent e)
90         {}
91
92         /**
93          * ignore mouse pressed for now too
94          */
95         public void mousePressed(MouseEvent e)
96         {}
97
98         /**
99          * and also ignore mouse released
100          */
101         public void mouseReleased(MouseEvent e)
102         {}
103 }