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