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

Diff of /jsampler/trunk/src/org/jsampler/view/std/StdA4n.java

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

revision 1784 by iliev, Thu Feb 14 16:52:36 2008 UTC revision 1785 by iliev, Tue Oct 7 00:07:14 2008 UTC
# Line 1  Line 1 
1  /*  /*
2   *   JSampler - a java front-end for LinuxSampler   *   JSampler - a java front-end for LinuxSampler
3   *   *
4   *   Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>   *   Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of JSampler.   *   This file is part of JSampler.
7   *   *
# Line 32  import javax.swing.AbstractAction; Line 32  import javax.swing.AbstractAction;
32  import javax.swing.Action;  import javax.swing.Action;
33  import javax.swing.JFileChooser;  import javax.swing.JFileChooser;
34    
35    import javax.swing.JMenu;
36    import javax.swing.JMenuItem;
37    import javax.swing.SwingUtilities;
38  import org.jsampler.CC;  import org.jsampler.CC;
39  import org.jsampler.HF;  import org.jsampler.HF;
40  import org.jsampler.JSPrefs;  import org.jsampler.JSPrefs;
41    
42    import org.jsampler.SamplerChannelModel;
43    import org.jsampler.view.JSChannelsPane;
44  import org.jsampler.view.LscpFileFilter;  import org.jsampler.view.LscpFileFilter;
45    
46  import static org.jsampler.view.std.StdI18n.i18n;  import static org.jsampler.view.std.StdI18n.i18n;
# Line 91  public class StdA4n { Line 96  public class StdA4n {
96                  } catch(Exception x) {                  } catch(Exception x) {
97                          CC.getLogger().log(Level.FINE, HF.getErrorMessage(x), x);                          CC.getLogger().log(Level.FINE, HF.getErrorMessage(x), x);
98                          HF.showErrorMessage(x);                          HF.showErrorMessage(x);
99                  };                  }
100          }          }
101                    
102          public final Action connect = new Connect();          public final Action connect = new Connect();
# Line 103  public class StdA4n { Line 108  public class StdA4n {
108                          putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("actions.connect.tt"));                          putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("actions.connect.tt"));
109                  }                  }
110                                    
111                    @Override
112                  public void                  public void
113                  actionPerformed(ActionEvent e) { CC.reconnect(); }                  actionPerformed(ActionEvent e) { CC.reconnect(); }
114          }          }
# Line 207  public class StdA4n { Line 213  public class StdA4n {
213                          StdUtils.browse("http://jsampler.sourceforge.net/");                          StdUtils.browse("http://jsampler.sourceforge.net/");
214                  }                  }
215          }          }
216            
217            public static abstract class LoadInstrumentAction extends AbstractAction {
218                    protected final SamplerChannelModel channelModel;
219                    
220                    LoadInstrumentAction(SamplerChannelModel model) { this(model, false); }
221                    
222                    LoadInstrumentAction(SamplerChannelModel model, boolean onPanel) {
223                            String s = onPanel ? "instrumentsdb.actions.loadInstrument.onPanel.channel"
224                                               : "instrumentsdb.actions.loadInstrument.onChannel";
225                            int i = CC.getMainFrame().getChannelNumber(model) + 1;
226                            putValue(Action.NAME, i18n.getMenuLabel(s, i));
227                            channelModel = model;
228                    }
229            }
230            
231            public static interface LoadInstrumentActionFactory {
232                    public LoadInstrumentAction
233                    createLoadInstrumentAction(SamplerChannelModel model, boolean onPanel);
234            }
235            
236            
237            
238            public static void
239            updateLoadInstrumentMenu(final JMenu menu, final LoadInstrumentActionFactory factory) {
240                    SwingUtilities.invokeLater(new Runnable() {
241                            public void
242                            run() { updateLoadInstrumentMenu0(menu, factory); }
243                    });
244            }
245            
246            private static void
247            updateLoadInstrumentMenu0(JMenu menu, LoadInstrumentActionFactory factory) {
248                    if(CC.getMainFrame() == null) return;
249                    menu.removeAll();
250                    int count = 0;
251                    JSChannelsPane chnPane = null;
252                    for(int i = 0; i < CC.getMainFrame().getChannelsPaneCount(); i++) {
253                            if(CC.getMainFrame().getChannelsPane(i).getChannelCount() == 0) continue;
254                            
255                            chnPane = CC.getMainFrame().getChannelsPane(i);
256                            count++;
257                            String s = "instrumentsdb.actions.loadInstrument.onPanel";
258                            JMenu m = new JMenu(i18n.getMenuLabel(s, i + 1));
259                            for(int j = 0; j < chnPane.getChannelCount(); j++) {
260                                    SamplerChannelModel chn = chnPane.getChannel(j).getModel();
261                                    m.add(new JMenuItem(factory.createLoadInstrumentAction(chn, true)));
262                            }
263                            menu.add(m);
264                    }
265                    
266                    if(count == 1 && CC.getMainFrame().getSelectedChannelsPane() == chnPane) {
267                            menu.removeAll();
268                            
269                            for(int j = 0; j < chnPane.getChannelCount(); j++) {
270                                    SamplerChannelModel chn = chnPane.getChannel(j).getModel();
271                                    menu.add(new JMenuItem(factory.createLoadInstrumentAction(chn, false)));
272                            }
273                    }
274            }
275  }  }

Legend:
Removed from v.1784  
changed lines
  Added in v.1785

  ViewVC Help
Powered by ViewVC