1   /**
2    * Distribution License:
3    * BibleDesktop is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU General Public License, version 2 as published by
5    * the Free Software Foundation. This program is distributed in the hope
6    * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8    * See the GNU General Public License for more details.
9    *
10   * The License is available on the internet at:
11   *       http://www.gnu.org/copyleft/gpl.html
12   * or by writing to:
13   *      Free Software Foundation, Inc.
14   *      59 Temple Place - Suite 330
15   *      Boston, MA 02111-1307, USA
16   *
17   * Copyright: 2005
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: InstallerFactoryComboBoxModel.java 2056 2010-12-12 04:34:41Z dmsmith $
21   */
22  package org.crosswire.bibledesktop.book.install;
23  
24  import java.util.ArrayList;
25  import java.util.Collections;
26  import java.util.List;
27  import java.util.Set;
28  
29  import javax.swing.AbstractListModel;
30  import javax.swing.ComboBoxModel;
31  
32  import org.crosswire.jsword.book.install.InstallManager;
33  
34  /**
35   * A ComboBoxModel that displays all the known InstallerFactory names.
36   * 
37   * @see gnu.gpl.License for license details.<br>
38   *      The copyright to this program is held by it's authors.
39   * @author Joe Walker [joe at eireneh dot com]
40   */
41  public class InstallerFactoryComboBoxModel extends AbstractListModel implements ComboBoxModel {
42      /**
43       * Simple ctor
44       */
45      public InstallerFactoryComboBoxModel(InstallManager imanager) {
46          Set<String> nameset = imanager.getInstallerFactoryNames();
47          names = new ArrayList<String>();
48          names.addAll(nameset);
49          Collections.sort(names);
50      }
51  
52      /* (non-Javadoc)
53       * @see javax.swing.ComboBoxModel#getSelectedItem()
54       */
55      public Object getSelectedItem() {
56          return selection;
57      }
58  
59      /* (non-Javadoc)
60       * @see javax.swing.ComboBoxModel#setSelectedItem(java.lang.Object)
61       */
62      public void setSelectedItem(Object selection) {
63          this.selection = selection;
64      }
65  
66      /* (non-Javadoc)
67       * @see javax.swing.ListModel#getSize()
68       */
69      public int getSize() {
70          return names.size();
71      }
72  
73      /* (non-Javadoc)
74       * @see javax.swing.ListModel#getElementAt(int)
75       */
76      public Object getElementAt(int index) {
77          return names.get(index);
78      }
79  
80      /**
81       * The list of installer names
82       */
83      private List<String> names;
84  
85      /**
86       * The currently selected object
87       */
88      private Object selection;
89  
90      /**
91       * Serialization ID
92       */
93      private static final long serialVersionUID = 3258134643734885174L;
94  }
95