]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/GenericChart.java
Version 7, February 2009
[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          * @param inG graphics object
48          */
49         public void paint(Graphics inG)
50         {
51                 super.paint(inG);
52                 int width = getWidth();
53                 int height = getHeight();
54                 // border background
55                 inG.setColor(COLOR_BORDER_BG);
56                 inG.fillRect(0, 0, width, height);
57                 if (width < 2*BORDER_WIDTH || height < 2*BORDER_WIDTH) return;
58                 // blank graph area, with line border
59                 inG.setColor(COLOR_CHART_BG);
60                 inG.fillRect(BORDER_WIDTH, BORDER_WIDTH, width - 2*BORDER_WIDTH, height-2*BORDER_WIDTH);
61                 // Display message if no data to be displayed
62                 if (_track == null || _track.getNumPoints() <= 0)
63                 {
64                         inG.setColor(COLOR_NODATA_TEXT);
65                         inG.drawString(I18nManager.getText("display.nodata"), 50, height/2);
66                 }
67                 else {
68                         inG.setColor(COLOR_CHART_LINE);
69                         inG.drawRect(BORDER_WIDTH, BORDER_WIDTH, width - 2*BORDER_WIDTH, height-2*BORDER_WIDTH);
70                 }
71         }
72
73
74         /**
75          * Method to inform map that data has changed
76          */
77         public void dataUpdated(byte inUpdateType)
78         {
79                 repaint();
80         }
81
82
83         /**
84          * mouse enter events ignored
85          */
86         public void mouseEntered(MouseEvent e)
87         {}
88
89         /**
90          * mouse exit events ignored
91          */
92         public void mouseExited(MouseEvent e)
93         {}
94
95         /**
96          * ignore mouse pressed for now too
97          */
98         public void mousePressed(MouseEvent e)
99         {}
100
101         /**
102          * and also ignore mouse released
103          */
104         public void mouseReleased(MouseEvent e)
105         {}
106 }