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

Annotation of /jsampler/trunk/src/org/jsampler/view/LostFilesTable.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1729 - (hide annotations) (download)
Tue Apr 29 22:22:40 2008 UTC (16 years ago) by iliev
File size: 4051 byte(s)
* Added support for handling lost files in the Instruments Database
  (In the Instruments Database window choose Actions/Check For Lost Files)
* Fantasia: Added option to show the Instruments Database
  on the Right-Side Pane of the Fantasia's main window
  (choose Edit/Preferences, then click the `View' tab)
* Added new menu item in the Instruments Database window: Edit/Find
* Some minor bugfixes and enhancements

1 iliev 1729 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4     * Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>
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 java.awt.Component;
26    
27     import javax.swing.JTable;
28     import javax.swing.JTextField;
29    
30     import javax.swing.event.ChangeEvent;
31     import javax.swing.event.ChangeListener;
32    
33     import javax.swing.table.AbstractTableModel;
34    
35     import net.sf.juife.event.TaskEvent;
36     import net.sf.juife.event.TaskListener;
37    
38     import org.jsampler.CC;
39     import org.jsampler.task.InstrumentsDb.SetInstrumentFilePath;
40    
41     import static org.jsampler.JSI18n.i18n;
42    
43     /**
44     * A table for representing the list of lost instrument files in the instruments database.
45     * @author Grigor Iliev
46     */
47     public class LostFilesTable extends JTable {
48    
49     /** Creates a new instance of <code>LostFilesTable</code> */
50     public
51     LostFilesTable() {
52     super(new LostFilesTableModel());
53     }
54    
55     public void
56     editSelectedFile() {
57     int i = getSelectedRow();
58     if(i == -1) return;
59     editCellAt(i, 0);
60    
61     if(getEditorComponent() == null) return;
62    
63     Component c = getEditorComponent();
64     c.requestFocus();
65     //if(c instanceof JTextField) ((JTextField)c).selectAll();
66     }
67     }
68    
69     /**
70     * A tabular data model for representing the list
71     * of lost instrument files in the instruments database.
72     * @author Grigor Iliev
73     */
74     class LostFilesTableModel extends AbstractTableModel {
75    
76     /**
77     * Creates a new instance of <code>MidiMapTableModel</code>.
78     */
79     public
80     LostFilesTableModel() {
81     CC.getLostFilesModel().addChangeListener(new ChangeListener() {
82     public void
83     stateChanged(ChangeEvent e) { fireTableDataChanged(); }
84     });
85     }
86    
87     /**
88     * Gets the number of columns in the model.
89     * @return The number of columns in the model.
90     */
91     public int
92     getColumnCount() { return 1; }
93    
94     /**
95     * Gets the number of rows in the model.
96     * @return The number of rows in the model.
97     */
98     public int
99     getRowCount() { return CC.getLostFilesModel().getLostFileCount(); }
100    
101     /**
102     * Gets the name of the column at <code>columnIndex</code>.
103     * @return The name of the column at <code>columnIndex</code>.
104     */
105     public String
106     getColumnName(int col) { return i18n.getLabel("LostFilesTableModel.title"); }
107    
108     /**
109     * Gets the value for the cell at <code>columnIndex</code> and
110     * <code>rowIndex</code>.
111     * @param row The row whose value is to be queried.
112     * @param col The column whose value is to be queried.
113     * @return The value for the cell at <code>columnIndex</code> and
114     * <code>rowIndex</code>.
115     */
116     public Object
117     getValueAt(int row, int col) {
118     return CC.getLostFilesModel().getLostFile(row);
119     }
120    
121     /**
122     * Sets the value in the cell at <code>col</code>
123     * and <code>row</code> to <code>value</code>.
124     */
125     public void
126     setValueAt(Object value, int row, int col) {
127     String oldPath = CC.getLostFilesModel().getLostFile(row);
128     String newPath = value.toString();
129     if(newPath.equals(oldPath)) return;
130    
131     final SetInstrumentFilePath t = new SetInstrumentFilePath(oldPath, newPath);
132    
133     t.addTaskListener(new TaskListener() {
134     public void
135     taskPerformed(TaskEvent e) {
136     CC.getLostFilesModel().update();
137     }
138     });
139    
140     CC.getTaskQueue().add(t);
141     //fireTableCellUpdated(row, col);
142     }
143    
144     /**
145     * Returns <code>true</code> if the cell at
146     * <code>row</code> and <code>col</code> is editable.
147     */
148     public boolean
149     isCellEditable(int row, int col) { return true; }
150     }

  ViewVC Help
Powered by ViewVC