View Javadoc

1   // Copyright (C) 2004, Brian Enigma <enigma at netninja.com>
2   // This file is part of iGallery.
3   //
4   // iGallery is free software; you can redistribute it and/or modify
5   // it under the terms of the GNU General Public License as published by
6   // the Free Software Foundation; either version 2 of the License, or
7   // (at your option) any later version.
8   //
9   // iGallery is distributed in the hope that it will be useful,
10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  // GNU General Public License for more details.
13  //
14  // You should have received a copy of the GNU General Public License
15  // along with Foobar; if not, write to the Free Software
16  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  package org.ninjasoft.igallery.swingui;
18  
19  import java.util.*;
20  import javax.swing.event.*;
21  import javax.swing.table.TableModel;
22  import org.ninjasoft.igallery.data.*;
23  
24  /***
25   * Table model to represent the Gallery albums
26   * @author enigma
27   */
28  public class GalleryTableModel implements TableModel {
29      Vector listeners = new Vector();
30      Vector albumList = new Vector();
31      
32      public void setAlbumList(Vector list) {
33          this.albumList = list;
34          tellChanged();
35      }
36      public void tellChanged() {
37          TableModelEvent e = new TableModelEvent(this);
38          for (Iterator i = listeners.iterator(); i.hasNext(); )
39              ((TableModelListener) i.next()).tableChanged(e);
40      }
41      public void addTableModelListener(TableModelListener l) {
42          listeners.add(l);
43      }
44      public Class getColumnClass(int i) {
45          return String.class;
46      }
47      public int getColumnCount() {
48          return 2;
49      }
50      public String getColumnName(int i) {
51          if (i==0)
52              return "Name";
53          return "Photo Count";
54      }
55      public int getRowCount() {
56          return albumList.size();
57      }
58      public Object getValueAt(int row, int column) {
59          GalleryAlbum album = (GalleryAlbum) albumList.get(row);
60          if (column == 0)
61              return album.getName();
62          int count = album.getPictureCount();
63          if (count >= 0)
64              return Integer.toString(count);
65          return "?";
66      }
67      public boolean isCellEditable(int arg0, int arg1) {
68          return false;
69      }
70      public void removeTableModelListener(TableModelListener l) {
71          listeners.remove(l);
72      }
73      public void setValueAt(Object arg0, int arg1, int arg2) {
74          
75      }
76  }