File: PhotoTableModel.java

package info (click to toggle)
gpsprune 17-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,984 kB
  • ctags: 5,218
  • sloc: java: 39,403; sh: 25; makefile: 17; python: 15
file content (139 lines) | stat: -rw-r--r-- 2,843 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package tim.prune.save;

import javax.swing.table.AbstractTableModel;

import tim.prune.I18nManager;

/**
 * Class to hold table model information for save exif dialog
 */
public class PhotoTableModel extends AbstractTableModel
{
	private PhotoTableEntry[] _photos = null;
	private int _addIndex = 0;


	/**
	 * Constructor giving list size
	 * @param inSize number of photos
	 */
	public PhotoTableModel(int inSize)
	{
		_photos = new PhotoTableEntry[inSize];
	}


	/**
	 * Set the given PhotoTableEntry object in the array
	 * @param inEntry PhotoTableEntry object describing the photo
	 */
	public void addPhotoInfo(PhotoTableEntry inEntry)
	{
		if (_addIndex < _photos.length && inEntry != null
			&& inEntry.getStatus() != null)
		{
			_photos[_addIndex] = inEntry;
			_addIndex++;
		}
	}

	/**
	 * @return the number of photos in the list whose status has changed
	 */
	public int getNumSaveablePhotos()
	{
		return _addIndex;
	}

	/**
	 * @see javax.swing.table.TableModel#getColumnCount()
	 */
	public int getColumnCount()
	{
		return 3;
	}


	/**
	 * @see javax.swing.table.TableModel#getRowCount()
	 */
	public int getRowCount()
	{
		return _addIndex;
	}


	/**
	 * @see javax.swing.table.TableModel#getValueAt(int, int)
	 */
	public Object getValueAt(int inRowIndex, int inColumnIndex)
	{
		if (inColumnIndex == 0)
		{
			return _photos[inRowIndex].getName();
		}
		else if (inColumnIndex == 1)
		{
			return _photos[inRowIndex].getStatus();
		}
		return Boolean.valueOf(_photos[inRowIndex].getSaveFlag());
	}


	/**
	 * @return true if cell is editable
	 */
	public boolean isCellEditable(int inRowIndex, int inColumnIndex)
	{
		// only the save column is editable
		return inColumnIndex == 2;
	}


	/**
	 * Set the given cell value
	 * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
	 */
	public void setValueAt(Object inValue, int inRowIndex, int inColumnIndex)
	{
		// ignore edits to other columns
		if (inColumnIndex == 2)
			_photos[inRowIndex].setSaveFlag(((Boolean) inValue).booleanValue());
	}


	/**
	 * @return Class of cell data
	 */
	public Class<?> getColumnClass(int inColumnIndex)
	{
		if (inColumnIndex < 2) return String.class;
		return Boolean.class;
	}


	/**
	 * Get the name of the column
	 */
	public String getColumnName(int inColNum)
	{
		if (inColNum == 0) return I18nManager.getText("dialog.saveexif.table.photoname");
		else if (inColNum == 1) return I18nManager.getText("dialog.saveexif.table.status");
		return I18nManager.getText("dialog.saveexif.table.save");
	}


	/**
	 * Retrieve the object at the given index
	 * @param inIndex index, starting at 0
	 * @return PhotoTableEntry object at this position
	 */
	public PhotoTableEntry getPhotoTableEntry(int inIndex)
	{
		if (inIndex < 0 || inIndex >= _photos.length)
		{
			return null;
		}
		return _photos[inIndex];
	}
}