01: /*
02: ** $Id: ConnectionListModel.java,v 1.4 2000/10/21 14:56:29 mrw Exp $
03: **
04: ** Controller for the main view. The view container a menubar, toolbar
05: ** and a tab sheet. This controller responds to menu and toolbar events
06: ** from the view.
07: **
08: ** Mike Wilson, July 2000, mrw@whisperingwind.co.uk
09: **
10: ** (C) Copyright 2000, Mike Wilson, Reading, Berkshire, UK
11: **
12: ** This program is free software; you can redistribute it and/or modify
13: ** it under the terms of the GNU General Public License as published by
14: ** the Free Software Foundation; either version 2 of the License, or
15: ** (at your option) any later version.
16: **
17: ** This program is distributed in the hope that it will be useful,
18: ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20: ** GNU General Public License for more details.
21: **
22: ** You should have received a copy of the GNU Library General
23: ** Public License along with this library; if not, write to the
24: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25: ** Boston, MA 02111-1307 USA.
26: */
27:
28: package uk.co.whisperingwind.vienna;
29:
30: import uk.co.whisperingwind.framework.Model;
31: import java.util.Vector;
32: import javax.swing.ComboBoxModel;
33: import javax.swing.DefaultComboBoxModel;
34: import javax.swing.ListModel;
35:
36: class ConnectionListModel extends Model {
37: private ConnectionListComboBoxModel comboBoxModel = null;
38:
39: public ConnectionListModel(Vector items) {
40: comboBoxModel = new ConnectionListComboBoxModel(items);
41: }
42:
43: public ComboBoxModel getComboBoxModel() {
44: return comboBoxModel;
45: }
46:
47: public ListModel getListModel() {
48: return comboBoxModel;
49: }
50:
51: public void addElement(Object element) {
52: comboBoxModel.addElement(element);
53: }
54:
55: public void removeElement(Object element) {
56: comboBoxModel.removeElement(element);
57: }
58:
59: /*
60: ** Returns true if the named item is in the model.
61: */
62:
63: public boolean contains(String item) {
64: boolean found = false;
65:
66: for (int i = 0; i < comboBoxModel.getSize() && !found; i++)
67: found = item.equals((String) comboBoxModel.getElementAt(i));
68:
69: return found;
70: }
71:
72: public void assign(ConnectionListModel copy) {
73: comboBoxModel.removeAllElements();
74: ConnectionListComboBoxModel model = copy.comboBoxModel;
75:
76: for (int i = 0; i < model.getSize(); i++) {
77: comboBoxModel.addElement(model.getElementAt(i));
78: }
79: }
80:
81: private class ConnectionListComboBoxModel extends
82: DefaultComboBoxModel implements ListModel {
83: public ConnectionListComboBoxModel(Vector items) {
84: super(items);
85: }
86: }
87: }
|