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

Diff of /jsampler/trunk/src/org/jsampler/view/classic/MidiInstrumentMapsPage.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1284 by iliev, Thu May 24 21:43:45 2007 UTC revision 1285 by iliev, Fri Aug 10 19:55:03 2007 UTC
# Line 22  Line 22 
22    
23  package org.jsampler.view.classic;  package org.jsampler.view.classic;
24    
25    import java.awt.BorderLayout;
26  import java.awt.Dimension;  import java.awt.Dimension;
27    
28  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
# Line 37  import javax.swing.JPanel; Line 38  import javax.swing.JPanel;
38  import javax.swing.JScrollPane;  import javax.swing.JScrollPane;
39  import javax.swing.JToolBar;  import javax.swing.JToolBar;
40    
41  import javax.swing.event.TreeSelectionEvent;  import javax.swing.tree.DefaultTreeCellRenderer;
 import javax.swing.event.TreeSelectionListener;  
42    
43  import net.sf.juife.LinkButton;  import net.sf.juife.LinkButton;
44  import net.sf.juife.NavigationPage;  import net.sf.juife.NavigationPage;
# Line 51  import org.jsampler.event.ListEvent; Line 51  import org.jsampler.event.ListEvent;
51  import org.jsampler.event.ListListener;  import org.jsampler.event.ListListener;
52  import org.jsampler.event.MidiInstrumentMapEvent;  import org.jsampler.event.MidiInstrumentMapEvent;
53  import org.jsampler.event.MidiInstrumentMapListener;  import org.jsampler.event.MidiInstrumentMapListener;
54    import org.jsampler.view.std.JSEditMidiInstrumentDlg;
55    
56    import org.jsampler.view.std.JSAddMidiInstrumentMapDlg;
57    import org.jsampler.view.std.JSMidiInstrumentTree;
58    import org.jsampler.view.std.JSMidiInstrumentsPane;
59    
60  import org.linuxsampler.lscp.MidiInstrumentInfo;  import org.linuxsampler.lscp.MidiInstrumentInfo;
61    
62    import static org.jsampler.view.classic.A4n.a4n;
63  import static org.jsampler.view.classic.ClassicI18n.i18n;  import static org.jsampler.view.classic.ClassicI18n.i18n;
64    
65    
# Line 63  import static org.jsampler.view.classic. Line 69  import static org.jsampler.view.classic.
69   */   */
70  public class MidiInstrumentMapsPage extends NavigationPage {  public class MidiInstrumentMapsPage extends NavigationPage {
71          private final JToolBar tbMaps = new JToolBar();          private final JToolBar tbMaps = new JToolBar();
         private final JToolBar tbInstruments = new JToolBar();  
72                    
73          private final EditMap actionEditMap = new EditMap();          private final EditMap actionEditMap = new EditMap();
74          private final RemoveMap actionRemoveMap = new RemoveMap();          private final RemoveMap actionRemoveMap = new RemoveMap();
         private final EditInstrument actionEditInstrument = new EditInstrument();  
         private final RemoveInstrument removeInstrument = new RemoveInstrument();  
75                    
76          private final ToolbarButton btnAddMap = new ToolbarButton(A4n.addMidiInstrumentMap);          private final ToolbarButton btnAddMap = new ToolbarButton(A4n.addMidiInstrumentMap);
77          private final ToolbarButton btnEditMap = new ToolbarButton(actionEditMap);          private final ToolbarButton btnEditMap = new ToolbarButton(actionEditMap);
78          private final ToolbarButton btnRemoveMap = new ToolbarButton(actionRemoveMap);          private final ToolbarButton btnRemoveMap = new ToolbarButton(actionRemoveMap);
79          private final ToolbarButton btnExportMaps = new ToolbarButton(A4n.exportMidiInstrumentMaps);          private final ToolbarButton btnExportMaps = new ToolbarButton(a4n.exportMidiInstrumentMaps);
80          //private final ToolbarButton btnCloseMapBar = new ToolbarButton();          //private final ToolbarButton btnCloseMapBar = new ToolbarButton();
81                    
         private final ToolbarButton btnAddInstrument =  
                 new ToolbarButton(A4n.addMidiInstrumentWizard);  
           
         private final ToolbarButton btnEditInstrument = new ToolbarButton(actionEditInstrument);  
         private final ToolbarButton btnRemoveInstrument = new ToolbarButton(removeInstrument);  
82          //private final ToolbarButton btnCloseInstrumentBar = new ToolbarButton();          //private final ToolbarButton btnCloseInstrumentBar = new ToolbarButton();
83                    
84          private final JComboBox cbMaps = new JComboBox();          private final JComboBox cbMaps = new JComboBox();
85          private final MidiInstrumentTree midiInstrumentTree = new MidiInstrumentTree();          private final MidiInstrumentsPane midiInstrumentsPane = new MidiInstrumentsPane();
86                    
87          /** Creates a new instance of MidiInstrumentMapsPage */          /** Creates a new instance of MidiInstrumentMapsPage */
88          public          public
# Line 158  public class MidiInstrumentMapsPage exte Line 156  public class MidiInstrumentMapsPage exte
156                  p.add(Box.createRigidArea(new Dimension(0, 12)));                  p.add(Box.createRigidArea(new Dimension(0, 12)));
157                  add(p);                  add(p);
158                                    
                 tbInstruments.add(btnAddInstrument);  
                 tbInstruments.add(btnEditInstrument);  
                 tbInstruments.add(btnRemoveInstrument);  
                   
159                  /*tbInstruments.add(Box.createHorizontalGlue());                  /*tbInstruments.add(Box.createHorizontalGlue());
160                  tbInstruments.add(btnCloseInstrumentBar); */                  tbInstruments.add(btnCloseInstrumentBar); */
161                                                                    
162                  d = new Dimension(Short.MAX_VALUE, tbInstruments.getPreferredSize().height);                  add(midiInstrumentsPane);
                 tbInstruments.setMaximumSize(d);  
                 tbInstruments.setFloatable(false);  
                 tbInstruments.setAlignmentX(LEFT_ALIGNMENT);  
                   
                 add(tbInstruments);  
                   
                 p = new JPanel();  
                 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));  
                 p.setAlignmentX(LEFT_ALIGNMENT);  
                 p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));  
                                   
                 p.add(new JScrollPane(midiInstrumentTree));  
                   
                 add(p);  
163                                    
164                  boolean b = cbMaps.getItemCount() != 0;                  boolean b = cbMaps.getItemCount() != 0;
165                  actionEditMap.setEnabled(b);                  actionEditMap.setEnabled(b);
166                  actionRemoveMap.setEnabled(b);                  actionRemoveMap.setEnabled(b);
167                  A4n.removeMidiInstrumentMap.setEnabled(b);                  A4n.removeMidiInstrumentMap.setEnabled(b);
168                                    A4n.addMidiInstrumentWizard.setEnabled(b);
                 midiInstrumentTree.addTreeSelectionListener(getHandler());  
                 removeInstrument.setEnabled(midiInstrumentTree.getSelectionCount() > 0);  
                 actionEditInstrument.setEnabled(midiInstrumentTree.getSelectedInstrument() != null);  
169          }          }
170                    
171          private void          private void
172          mapChanged() {          mapChanged() {
173                  MidiInstrumentMap map = (MidiInstrumentMap)cbMaps.getSelectedItem();                  MidiInstrumentMap map = (MidiInstrumentMap)cbMaps.getSelectedItem();
174                  midiInstrumentTree.setMidiInstrumentMap(map);                  midiInstrumentsPane.setMidiInstrumentMap(map);
175                                    
176                  boolean b = cbMaps.getItemCount() != 0;                  boolean b = cbMaps.getItemCount() != 0;
177                  actionEditMap.setEnabled(b);                  actionEditMap.setEnabled(b);
178                  actionRemoveMap.setEnabled(b);                  actionRemoveMap.setEnabled(b);
179                  A4n.removeMidiInstrumentMap.setEnabled(b);                  A4n.removeMidiInstrumentMap.setEnabled(b);
180                    A4n.addMidiInstrumentWizard.setEnabled(b);
181          }          }
182                    
183            class MidiInstrumentsPane extends JSMidiInstrumentsPane {
184                    private final JToolBar tbInstruments = new JToolBar();
185                    
186                    private final ToolbarButton btnAddInstrument =
187                            new ToolbarButton(A4n.addMidiInstrumentWizard);
188                    
189                    private final ToolbarButton btnEditInstrument
190                            = new ToolbarButton(actionEditInstrument);
191                    
192                    private final ToolbarButton btnRemoveInstrument = new ToolbarButton(actionRemove);
193                    
194                    MidiInstrumentsPane() {
195                            actionEditInstrument.putValue(Action.SMALL_ICON, Res.iconEdit16);
196                            actionRemove.putValue(Action.SMALL_ICON, Res.iconDelete16);
197                            
198                            removeAll();
199                            
200                            tbInstruments.add(btnAddInstrument);
201                            tbInstruments.add(btnEditInstrument);
202                            tbInstruments.add(btnRemoveInstrument);
203                            
204                            Dimension d;
205                            d = new Dimension(Short.MAX_VALUE, tbInstruments.getPreferredSize().height);
206                            tbInstruments.setMaximumSize(d);
207                            tbInstruments.setFloatable(false);
208                            
209                            add(tbInstruments, BorderLayout.NORTH);
210                            JScrollPane sp = new JScrollPane(midiInstrumentTree);
211                            
212                            DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
213                            renderer.setClosedIcon(Res.iconFolder16);
214                            renderer.setOpenIcon(Res.iconFolderOpen16);
215                            renderer.setLeafIcon(Res.iconInstrument16);
216                    
217                            midiInstrumentTree.setCellRenderer(renderer);
218                            
219                            JPanel p = new JPanel();
220                            p.setLayout(new BorderLayout());
221                            p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
222                            
223                            p.add(sp);
224                            
225                            add(p);
226                            
227                            setAlignmentX(LEFT_ALIGNMENT);
228                    }
229            }
230                    
231          private class EditMap extends AbstractAction {          private class EditMap extends AbstractAction {
232                  EditMap() {                  EditMap() {
# Line 216  public class MidiInstrumentMapsPage exte Line 241  public class MidiInstrumentMapsPage exte
241                  actionPerformed(ActionEvent e) {                  actionPerformed(ActionEvent e) {
242                          MidiInstrumentMap map = (MidiInstrumentMap)cbMaps.getSelectedItem();                          MidiInstrumentMap map = (MidiInstrumentMap)cbMaps.getSelectedItem();
243                          int id = map.getMapId();                          int id = map.getMapId();
244                          AddMidiInstrumentMapDlg dlg = new AddMidiInstrumentMapDlg();                          JSAddMidiInstrumentMapDlg dlg = new JSAddMidiInstrumentMapDlg();
245                          dlg.setTitle(i18n.getLabel("MidiInstrumentMapsPage.editMap"));                          dlg.setTitle(i18n.getLabel("MidiInstrumentMapsPage.editMap"));
246                          dlg.setMapName(map.getName());                          dlg.setMapName(map.getName());
247                          dlg.setVisible(true);                          dlg.setVisible(true);
# Line 247  public class MidiInstrumentMapsPage exte Line 272  public class MidiInstrumentMapsPage exte
272                  }                  }
273          }          }
274                    
         private class EditInstrument extends AbstractAction {  
                 EditInstrument() {  
                         super(i18n.getLabel("MidiInstrumentMapsPage.EditInstrument"));  
                           
                         String s = i18n.getLabel("MidiInstrumentMapsPage.EditInstrument.tt");  
                         putValue(SHORT_DESCRIPTION, s);  
                         putValue(Action.SMALL_ICON, Res.iconEdit16);  
                 }  
                   
                 public void  
                 actionPerformed(ActionEvent e) {  
                         MidiInstrument i = midiInstrumentTree.getSelectedInstrument();  
                         EditMidiInstrumentDlg dlg = new EditMidiInstrumentDlg(i.getInfo());  
                         dlg.setVisible(true);  
                           
                         if(dlg.isCancelled()) return;  
                           
                         MidiInstrumentInfo info = dlg.getInstrument();  
                         CC.getSamplerModel().mapBackendMidiInstrument (  
                                 info.getMapId(), info.getMidiBank(), info.getMidiProgram(), info  
                         );  
                 }  
         }  
           
         private class RemoveInstrument extends AbstractAction {  
                 RemoveInstrument() {  
                         String s = i18n.getLabel("MidiInstrumentMapsPage.RemoveInstrument.tt");  
                         putValue(SHORT_DESCRIPTION, s);  
                         putValue(Action.SMALL_ICON, Res.iconDelete16);  
                 }  
                   
                 public void  
                 actionPerformed(ActionEvent e) {  
                         midiInstrumentTree.removeSelectedInstrumentOrBank();  
                 }  
         }  
           
275          private final Handler handler = new Handler();          private final Handler handler = new Handler();
276                    
277          private Handler          private Handler
278          getHandler() { return handler; }          getHandler() { return handler; }
279                    
280          private class Handler implements ListListener<MidiInstrumentMap>,          private class Handler implements ListListener<MidiInstrumentMap>,
281                                  MidiInstrumentMapListener, TreeSelectionListener {                                                          MidiInstrumentMapListener {
282                                    
283                  /** Invoked when a new map is added. */                  /** Invoked when a new map is added. */
284                  public void                  public void
# Line 321  public class MidiInstrumentMapsPage exte Line 309  public class MidiInstrumentMapsPage exte
309                                    
310                  /** Invoked when an instrument is removed from a MIDI instrument map. */                  /** Invoked when an instrument is removed from a MIDI instrument map. */
311                  public void instrumentRemoved(MidiInstrumentMapEvent e) { }                  public void instrumentRemoved(MidiInstrumentMapEvent e) { }
                   
                 public void  
                 valueChanged(TreeSelectionEvent e) {  
                         removeInstrument.setEnabled(midiInstrumentTree.getSelectionCount() > 0);  
                         boolean b = midiInstrumentTree.getSelectedInstrument() != null;  
                         actionEditInstrument.setEnabled(b);  
                 }  
312          }          }
313  }  }

Legend:
Removed from v.1284  
changed lines
  Added in v.1285

  ViewVC Help
Powered by ViewVC