/[svn]/jsampler/trunk/src/org/jsampler/view/OrchestraTableModel.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/OrchestraTableModel.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 913 - (show annotations) (download)
Mon Aug 7 18:45:48 2006 UTC (17 years, 8 months ago) by iliev
File size: 4810 byte(s)
updating to JSampler 0.3a

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005, 2006 Grigor Kirilov Iliev
5 *
6 * This file is part of JSampler.
7 *
8 * JSampler is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
11 *
12 * JSampler is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with JSampler; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23 package org.jsampler.view;
24
25 import javax.swing.table.AbstractTableModel;
26
27 import org.jsampler.OrchestraListModel;
28 import org.jsampler.OrchestraModel;
29
30 import org.jsampler.event.OrchestraAdapter;
31 import org.jsampler.event.OrchestraEvent;
32 import org.jsampler.event.OrchestraListEvent;
33 import org.jsampler.event.OrchestraListListener;
34
35 import static org.jsampler.JSI18n.i18n;
36
37
38 /**
39 * A tabular data model for representing orchestras.
40 * @author Grigor Iliev
41 */
42 public class OrchestraTableModel extends AbstractTableModel {
43 private final OrchestraListModel orchestraListModel;
44
45 /**
46 * Creates a new instance of <code>OrchestraTableModel</code>.
47 * @param orchestraListModel The <code>OrchestraListModel</code>,
48 * which this table model should represent.
49 * @throws IllegalArgumentException If <code>orchestraListModel</code>
50 * is <code>null</code>.
51 */
52 public
53 OrchestraTableModel(OrchestraListModel orchestraListModel) {
54 if(orchestraListModel == null) throw new IllegalArgumentException (
55 "orchestraListModel should be non-null!"
56 );
57
58 this.orchestraListModel = orchestraListModel;
59 orchestraListModel.addOrchestraListListener(getHandler());
60
61 for(int i = 0; i < orchestraListModel.getOrchestraCount(); i++) {
62 orchestraListModel.getOrchestra(i).addOrchestraListener(getHandler());
63 }
64 orchestraListModel.addOrchestraListListener(getHandler());
65
66
67 }
68
69 /**
70 * Gets the number of columns in the model.
71 * @return The number of columns in the model.
72 */
73 public int
74 getColumnCount() { return 1; }
75
76 /**
77 * Gets the number of rows in the model.
78 * @return The number of rows in the model.
79 */
80 public int
81 getRowCount() { return orchestraListModel.getOrchestraCount(); }
82
83 /**
84 * Gets the name of the column at <code>columnIndex</code>.
85 * @return The name of the column at <code>columnIndex</code>.
86 */
87 public String
88 getColumnName(int col) { return i18n.getLabel("OrchestraTableModel.orchestras"); }
89
90 /**
91 * Gets the value for the cell at <code>columnIndex</code> and
92 * <code>rowIndex</code>.
93 * @param row The row whose value is to be queried.
94 * @param col The column whose value is to be queried.
95 * @return The value for the cell at <code>columnIndex</code> and
96 * <code>rowIndex</code>.
97 */
98 public Object
99 getValueAt(int row, int col) {
100 return orchestraListModel.getOrchestra(row);
101 }
102
103 /**
104 * Sets the value in the cell at <code>col</code>
105 * and <code>row</code> to <code>value</code>.
106 */
107 public void
108 setValueAt(Object value, int row, int col) {
109 orchestraListModel.getOrchestra(row).setName(value.toString());
110 fireTableCellUpdated(row, col);
111 }
112
113 /**
114 * Returns <code>true</code> if the cell at
115 * <code>row</code> and <code>col</code> is editable.
116 */
117 public boolean
118 isCellEditable(int row, int col) { return false; }
119
120 /**
121 * Gets the <code>OrchestraListModel</code>, represented by this table model.
122 */
123 public OrchestraListModel
124 getOrchestraListModel() { return orchestraListModel; }
125
126 private final Handler eventHandler = new Handler();
127
128 private Handler
129 getHandler() { return eventHandler; }
130
131 private class Handler extends OrchestraAdapter implements OrchestraListListener {
132 /** Invoked when an orchestra is added to the orchestra list. */
133 public void
134 orchestraAdded(OrchestraListEvent e) {
135 e.getOrchestraModel().addOrchestraListener(getHandler());
136 fireTableDataChanged();
137 }
138
139 /** Invoked when an orchestra is removed from the orchestra list. */
140 public void
141 orchestraRemoved(OrchestraListEvent e) {
142 e.getOrchestraModel().removeOrchestraListener(getHandler());
143 fireTableDataChanged();
144 }
145
146 /** Invoked when the name of orchestra is changed. */
147 public void
148 nameChanged(OrchestraEvent e) {
149 OrchestraModel m = (OrchestraModel)e.getSource();
150 int idx = orchestraListModel.getOrchestraIndex(m);
151 fireTableRowsUpdated(idx, idx);
152 }
153
154 /** Invoked when the description of orchestra is changed. */
155 public void
156 descriptionChanged(OrchestraEvent e) { }
157
158
159 }
160 }

  ViewVC Help
Powered by ViewVC