]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/cache/TileSetTableModel.java
Version 13, August 2011
[GpsPrune.git] / tim / prune / function / cache / TileSetTableModel.java
1 package tim.prune.function.cache;
2
3 import javax.swing.table.AbstractTableModel;
4
5 import tim.prune.I18nManager;
6
7 /**
8  * Class to act as a table model for the list of tile sets
9  */
10 public final class TileSetTableModel extends AbstractTableModel
11 {
12         /** Model from which values are drawn */
13         private TileCacheModel _model = null;
14
15
16         /**
17          * Constructor
18          * @param inModel model to use
19          */
20         public TileSetTableModel(TileCacheModel inModel) {
21                 _model = inModel;
22         }
23
24         /** @return the column count (always constant) */
25         public int getColumnCount() {
26                 return 5;
27         }
28
29         /** @return name of specified column */
30         public String getColumnName(int inColumnIndex)
31         {
32                 switch (inColumnIndex)
33                 {
34                         case 0: return I18nManager.getText("dialog.diskcache.table.path");
35                         case 1: return I18nManager.getText("dialog.diskcache.table.usedby");
36                         case 2: return I18nManager.getText("dialog.diskcache.table.zoom");
37                         case 3: return I18nManager.getText("dialog.diskcache.table.tiles");
38                         case 4: return I18nManager.getText("dialog.diskcache.table.megabytes");
39                 }
40                 return "";
41         }
42
43         /**
44          * @return number of rows in the table
45          */
46         public int getRowCount()
47         {
48                 if (_model == null)
49                         return 0;
50                 return _model.getNumTileSets();
51         }
52
53         /**
54          * @param inRowIndex row index
55          * @param inColumnIndex column index
56          * @return the value of the specified cell
57          */
58         public Object getValueAt(int inRowIndex, int inColumnIndex)
59         {
60                 if (_model != null && inColumnIndex >= 0 && inColumnIndex < getColumnCount())
61                 {
62                         TileSet set = _model.getTileSet(inRowIndex);
63                         if (set != null)
64                         {
65                                 switch (inColumnIndex)
66                                 {
67                                         case 0: return set.getPath();
68                                         case 1: return set.getUsedBy();
69                                         case 2: return set.getRowInfo().getZoomRange();
70                                         case 3: return "" + set.getRowInfo().getNumTiles();
71                                         case 4: return "" + (set.getRowInfo().getTotalSize() / 1024 / 1024) + " MB";
72                                 }
73                         }
74                 }
75                 return null;
76         }
77 }