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

Diff of /jsampler/trunk/src/org/jsampler/view/fantasia/MainFrame.java

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

revision 1786 by iliev, Wed Oct 8 22:38:15 2008 UTC revision 1919 by iliev, Sat Jun 20 19:25:50 2009 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-2008 Grigor Iliev <grigor@grigoriliev.com>   *   Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of JSampler.   *   This file is part of JSampler.
7   *   *
# Line 53  import java.util.Vector; Line 53  import java.util.Vector;
53  import javax.swing.BorderFactory;  import javax.swing.BorderFactory;
54  import javax.swing.BoxLayout;  import javax.swing.BoxLayout;
55  import javax.swing.JCheckBoxMenuItem;  import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JFileChooser;  
56  import javax.swing.JMenu;  import javax.swing.JMenu;
57  import javax.swing.JMenuBar;  import javax.swing.JMenuBar;
58  import javax.swing.JMenuItem;  import javax.swing.JMenuItem;
# Line 63  import javax.swing.KeyStroke; Line 62  import javax.swing.KeyStroke;
62  import javax.swing.SwingUtilities;  import javax.swing.SwingUtilities;
63  import javax.swing.Timer;  import javax.swing.Timer;
64    
65    import javax.swing.event.ListSelectionEvent;
66    import javax.swing.event.ListSelectionListener;
67    
68  import org.jsampler.CC;  import org.jsampler.CC;
69  import org.jsampler.HF;  import org.jsampler.HF;
70    import org.jsampler.JSUtils;
71  import org.jsampler.LSConsoleModel;  import org.jsampler.LSConsoleModel;
72  import org.jsampler.Server;  import org.jsampler.Server;
73    
74  import org.jsampler.view.JSChannelsPane;  import org.jsampler.view.JSChannelsPane;
75  import org.jsampler.view.JSMainFrame;  import org.jsampler.view.SessionViewConfig;
 import org.jsampler.view.LscpFileFilter;  
76    
77  import org.jsampler.view.fantasia.basic.FantasiaPainter;  import org.jsampler.view.fantasia.basic.FantasiaPainter;
78  import org.jsampler.view.fantasia.basic.FantasiaPanel;  import org.jsampler.view.fantasia.basic.FantasiaPanel;
# Line 81  import org.jsampler.view.std.JSConnectDl Line 83  import org.jsampler.view.std.JSConnectDl
83  import org.jsampler.view.std.JSDetailedErrorDlg;  import org.jsampler.view.std.JSDetailedErrorDlg;
84  import org.jsampler.view.std.JSQuitDlg;  import org.jsampler.view.std.JSQuitDlg;
85  import org.jsampler.view.std.JSamplerHomeChooser;  import org.jsampler.view.std.JSamplerHomeChooser;
86    import org.jsampler.view.std.StdMainFrame;
87  import org.jsampler.view.std.StdUtils;  import org.jsampler.view.std.StdUtils;
88    
89  import static org.jsampler.view.fantasia.A4n.a4n;  import static org.jsampler.view.fantasia.A4n.a4n;
# Line 93  import static org.jsampler.view.std.StdP Line 96  import static org.jsampler.view.std.StdP
96   *   *
97   * @author Grigor Iliev   * @author Grigor Iliev
98   */   */
99  public class MainFrame extends JSMainFrame {  public class MainFrame extends StdMainFrame {
100            public final static int MAX_CHANNEL_LANE_NUMBER = 8;
101    
102          private final StandardBar standardBar = new StandardBar();          private final StandardBar standardBar = new StandardBar();
103          private final FantasiaMenuBar menuBar = new FantasiaMenuBar();          private final FantasiaMenuBar menuBar = new FantasiaMenuBar();
104          private final JPanel rootPane = new RootPane();          private final JPanel rootPane = new RootPane();
# Line 163  public class MainFrame extends JSMainFra Line 168  public class MainFrame extends JSMainFra
168                          addChannelsPane(mainPane.getChannelsPane(i));                          addChannelsPane(mainPane.getChannelsPane(i));
169                          getChannelsPane(i).addListSelectionListener(pianoKeyboardPane);                          getChannelsPane(i).addListSelectionListener(pianoKeyboardPane);
170                  }                  }
171                    
172                    PropertyChangeListener l = new PropertyChangeListener() {
173                            public void
174                            propertyChange(PropertyChangeEvent e) {
175                                    onChangeChannelLaneCount();
176                            }
177                    };
178    
179                    preferences().addPropertyChangeListener("channelLanes.count", l);
180                                    
181                  int h = preferences().getIntProperty("midiKeyboard.height");                  int h = preferences().getIntProperty("midiKeyboard.height");
182                  setMidiKeyboardHeight(h);                  setMidiKeyboardHeight(h);
183                                    
184                  PropertyChangeListener l = new PropertyChangeListener() {                  l = new PropertyChangeListener() {
185                          public void                          public void
186                          propertyChange(PropertyChangeEvent e) {                          propertyChange(PropertyChangeEvent e) {
187                                  int h = preferences().getIntProperty("midiKeyboard.height");                                  int h = preferences().getIntProperty("midiKeyboard.height");
# Line 184  public class MainFrame extends JSMainFra Line 197  public class MainFrame extends JSMainFra
197                  rootPane.add(hSplitPane);                  rootPane.add(hSplitPane);
198                  rootPane.add(bottomPane, BorderLayout.SOUTH);                  rootPane.add(bottomPane, BorderLayout.SOUTH);
199                  add(rootPane);                  add(rootPane);
200    
201                    if(CC.isMacOS()) {
202                            try {
203                                    String s = "org.jsampler.view.fantasia.MacOSApplicationHandler";
204                                    Class.forName(s).newInstance(); }
205                            catch(Throwable e) { }
206                    }
207                                    
208                  addMenu();                  addMenu();
209                                    
210                    if(CC.getViewConfig().isUsingScreenMenuBar()) {
211                            // fix for moving the menu bar on top of the screen
212                            // when running on Mac OS and third party plugin is used
213                            ((ViewConfig)CC.getViewConfig()).restoreMenuProperties();
214                    }
215                    
216                  int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);                  int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
217                  hSplitPane.setDividerLocation(i);                  hSplitPane.setDividerLocation(i);
218                                    
# Line 248  public class MainFrame extends JSMainFra Line 274  public class MainFrame extends JSMainFra
274                    
275          /** Invoked when this window is about to close. */          /** Invoked when this window is about to close. */
276          @Override          @Override
277          protected void          public void
278          onWindowClose() {          onWindowClose() {
279                  boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT);                  boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT);
280                  if(b && CC.getSamplerModel().isModified()) {                  if(b && CC.getSamplerModel().isModified()) {
# Line 287  public class MainFrame extends JSMainFra Line 313  public class MainFrame extends JSMainFra
313                                    
314                  super.onWindowClose();                  super.onWindowClose();
315          }          }
316    
317            private void
318            onChangeChannelLaneCount() {
319                    int newCount = preferences().getIntProperty("channelLanes.count");
320                    if(newCount < 1 || newCount > MAX_CHANNEL_LANE_NUMBER) return;
321                    if(newCount == getChannelsPaneCount()) return;
322                    int current = getChannelsPaneIndex(getSelectedChannelsPane());
323    
324                    if(newCount > getChannelsPaneCount()) {
325                            int d = newCount - getChannelsPaneCount();
326                            for(int i = 0; i < d; i++) {
327                                    JSChannelsPane p = mainPane.addChannelsPane();
328                                    addChannelsPane(p);
329                                    p.addListSelectionListener(pianoKeyboardPane);
330                            }
331                    } else {
332                            int d = getChannelsPaneCount() - newCount;
333                            for(int i = 0; i < d; i++) {
334                                    int idx = getChannelsPaneCount() - 1 - i;
335                                    if(getChannelsPane(idx).getChannelCount() > 0) {
336                                            String s;
337                                            s = i18n.getError("MainFrame.notEmptyChannelLane!", idx + 1);
338                                            HF.showErrorMessage(s);
339                                            return;
340                                    }
341                            }
342    
343                            for(int i = 0; i < d; i++) {
344                                    int idx = getChannelsPaneCount() - 1;
345                                    JSChannelsPane p = getChannelsPane(idx);
346                                    removeChannelsPane(p);
347                                    p.removeListSelectionListener(pianoKeyboardPane);
348                                    mainPane.removeChannelsPane(idx);
349                            }
350                    }
351    
352                    if(newCount == 1) {
353                            mainPane.getButtonsPanel().setVisible(false);
354                    } else if(!mainPane.getButtonsPanel().isVisible()) {
355                            mainPane.getButtonsPanel().setVisible(true);
356                    }
357                    mainPane.getButtonsPanel().setButtonNumber(newCount);
358                    if(current < 0 || current >= getChannelsPaneCount()) current = 0;
359                    setSelectedChannelsPane(getChannelsPane(current));
360            }
361                    
362          @Override          @Override
363          public void          public void
# Line 327  public class MainFrame extends JSMainFra Line 398  public class MainFrame extends JSMainFra
398                                    
399                  JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export"));                  JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export"));
400                  m.add(exportMenu);                  m.add(exportMenu);
401    
402                    int modKey = CC.getViewConfig().getDefaultModKey();
403                                    
404                  mi = new JMenuItem(a4n.exportSamplerConfig);                  mi = new JMenuItem(a4n.exportSamplerConfig);
405                  mi.setIcon(null);                  mi.setIcon(null);
406                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, modKey));
407                  exportMenu.add(mi);                  exportMenu.add(mi);
408                                    
409                  mi = new JMenuItem(a4n.exportMidiInstrumentMaps);                  mi = new JMenuItem(a4n.exportMidiInstrumentMaps);
# Line 341  public class MainFrame extends JSMainFra Line 414  public class MainFrame extends JSMainFra
414                                    
415                  mi = new JMenuItem(a4n.loadScript);                  mi = new JMenuItem(a4n.loadScript);
416                  mi.setIcon(null);                  mi.setIcon(null);
417                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK));                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, modKey));
418                  m.add(mi);                  m.add(mi);
419                                    
420                  String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS);                  String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS);
# Line 355  public class MainFrame extends JSMainFra Line 428  public class MainFrame extends JSMainFra
428                                    
429                  mi = new JMenuItem(a4n.changeBackend);                  mi = new JMenuItem(a4n.changeBackend);
430                  mi.setIcon(null);                  mi.setIcon(null);
431                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK));                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, modKey));
432                  m.add(mi);                  m.add(mi);
433                                    
434                  m.addSeparator();                  m.addSeparator();
# Line 398  public class MainFrame extends JSMainFra Line 471  public class MainFrame extends JSMainFra
471                  mi = new JMenuItem(a4n.editPreferences);                  mi = new JMenuItem(a4n.editPreferences);
472                  mi.setIcon(null);                  mi.setIcon(null);
473                  mi.setAccelerator(KeyStroke.getKeyStroke (                  mi.setAccelerator(KeyStroke.getKeyStroke (
474                          KeyEvent.VK_P, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK                          KeyEvent.VK_P, modKey | KeyEvent.SHIFT_MASK
475                  ));                  ));
476                  m.add(mi);                  m.add(mi);
477                                    
# Line 420  public class MainFrame extends JSMainFra Line 493  public class MainFrame extends JSMainFra
493                  showToolBar(b);                  showToolBar(b);
494                                    
495                  cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (                  cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
496                          KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK                          KeyEvent.VK_L, modKey | KeyEvent.SHIFT_MASK
497                  ));                  ));
498                  m.add(cbmiLeftSidePaneVisible);                  m.add(cbmiLeftSidePaneVisible);
499                                    
# Line 436  public class MainFrame extends JSMainFra Line 509  public class MainFrame extends JSMainFra
509                  showSidePane(b);                  showSidePane(b);
510                                    
511                  cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (                  cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
512                          KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK                          KeyEvent.VK_R, modKey | KeyEvent.SHIFT_MASK
513                  ));                  ));
514                  m.add(cbmiRightSidePaneVisible);                  m.add(cbmiRightSidePaneVisible);
515                                    
# Line 467  public class MainFrame extends JSMainFra Line 540  public class MainFrame extends JSMainFra
540                  setMidiKeyboardVisible(b);                  setMidiKeyboardVisible(b);
541                                    
542                                    
543                    // Channels
544                    m = new FantasiaMenu(i18n.getMenuLabel("channels"));
545                    
546                    mi = new JMenuItem(i18n.getMenuLabel("channels.newChannel"));
547                    mi.addActionListener(new ActionListener() {
548                            public void
549                            actionPerformed(ActionEvent e) {
550                                    CC.getSamplerModel().addBackendChannel();
551                            }
552                    });
553                    m.add(mi);
554                    
555                    m.addSeparator();
556                    
557                    MenuManager.ChannelViewGroup group = new MenuManager.ChannelViewGroup();
558                    MenuManager.getMenuManager().registerChannelViewGroup(group);
559                    
560                    for(JMenuItem menuItem : group.getMenuItems()) m.add(menuItem);
561                    
562                    m.addSeparator();
563                    
564                    m.add(new JMenuItem(a4n.moveChannelsOnTop));
565                    m.add(new JMenuItem(a4n.moveChannelsUp));
566                    m.add(new JMenuItem(a4n.moveChannelsDown));
567                    m.add(new JMenuItem(a4n.moveChannelsAtBottom));
568                    
569                    m.add(new ToPanelMenu());
570                    
571                    m.addSeparator();
572                    
573                    mi = new JMenuItem(a4n.selectAllChannels);
574                    mi.setIcon(null);
575                    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, modKey));
576                    m.add(mi);
577                    
578                    mi = new JMenuItem(a4n.deselectChannels);
579                    mi.setIcon(null);
580                    mi.setAccelerator(KeyStroke.getKeyStroke (
581                            KeyEvent.VK_A, modKey | KeyEvent.SHIFT_MASK
582                    ));
583                    m.add(mi);
584                    
585                    menuBar.add(m);
586                    
587                  // Window                  // Window
588                  m = new FantasiaMenu(i18n.getMenuLabel("window"));                  m = new FantasiaMenu(i18n.getMenuLabel("window"));
589                  menuBar.add(m);                  menuBar.add(m);
# Line 520  public class MainFrame extends JSMainFra Line 637  public class MainFrame extends JSMainFra
637                  menuBar.add(m);                  menuBar.add(m);
638          }          }
639                    
640            public static class ToPanelMenu extends FantasiaMenu implements ListSelectionListener {
641                    public
642                    ToPanelMenu() {
643                            super(i18n.getMenuLabel("channels.toPanel"));
644                            setEnabled(CC.getMainFrame().getSelectedChannelsPane().hasSelectedChannel());
645                            
646                            CC.getMainFrame().addChannelsPaneSelectionListener(this);
647                            
648                            for(int i = 0; i < CC.getMainFrame().getChannelsPaneCount(); i++) {
649                                    JSChannelsPane p = CC.getMainFrame().getChannelsPane(i);
650                                    add(new JMenuItem(new A4n.MoveChannelsToPanel(p)));
651                                    p.addListSelectionListener(this);
652                            }
653                    }
654                    
655                    @Override
656                    public void
657                    valueChanged(ListSelectionEvent e) {
658                            setEnabled(CC.getMainFrame().getSelectedChannelsPane().hasSelectedChannel());
659                    }
660            }
661            
662          public RightSidePane          public RightSidePane
663          getRightSidePane() { return rightSidePane; }          getRightSidePane() { return rightSidePane; }
664                    
665            @Override
666            public A4n
667            getA4n() { return A4n.a4n; }
668            
669          /**          /**
670           * This method does nothing, because <b>Fantasia</b> has constant           * This method does nothing, because <b>Fantasia</b> has constant
671           * number of panes containing sampler channels, which can not be changed.           * number of panes containing sampler channels, which can not be changed.
# Line 551  public class MainFrame extends JSMainFra Line 694  public class MainFrame extends JSMainFra
694                  chooser.setVisible(true);                  chooser.setVisible(true);
695                  if(chooser.isCancelled()) return;                  if(chooser.isCancelled()) return;
696                                    
697                  CC.changeJSamplerHome(chooser.getJSamplerHome());                  JSUtils.changeJSamplerHome(chooser.getJSamplerHome());
698          }          }
699                    
700          @Override          @Override
# Line 609  public class MainFrame extends JSMainFra Line 752  public class MainFrame extends JSMainFra
752          public Timer          public Timer
753          getGuiTimer() { return guiTimer; }          getGuiTimer() { return guiTimer; }
754                    
755          protected LSConsoleModel          @Override
756            public LSConsoleModel
757          getLSConsoleModel() { return getLSConsolePane().getModel(); }          getLSConsoleModel() { return getLSConsolePane().getModel(); }
758                    
759          protected LSConsolePane          protected LSConsolePane
# Line 625  public class MainFrame extends JSMainFra Line 769  public class MainFrame extends JSMainFra
769                    
770          protected boolean          protected boolean
771          runScript() {          runScript() {
772                  String s = preferences().getStringProperty("lastScriptLocation");                  File f = StdUtils.showOpenLscpFileChooser();
773                  JFileChooser fc = new JFileChooser(s);                  if(f == null) return false;
774                  fc.setFileFilter(new LscpFileFilter());                  runScript(f);
                 int result = fc.showOpenDialog(this);  
                 if(result != JFileChooser.APPROVE_OPTION) return false;  
                   
                 String path = fc.getCurrentDirectory().getAbsolutePath();  
                 preferences().setStringProperty("lastScriptLocation", path);  
                                           
                 runScript(fc.getSelectedFile());  
775                                    
776                  return true;                  return true;
777          }          }
# Line 648  public class MainFrame extends JSMainFra Line 785  public class MainFrame extends JSMainFra
785                  FileReader fr;                  FileReader fr;
786                  try { fr = new FileReader(script); }                  try { fr = new FileReader(script); }
787                  catch(FileNotFoundException e) {                  catch(FileNotFoundException e) {
788                          HF.showErrorMessage(i18n.getMessage("FileNotFound!"));                          HF.showErrorMessage(i18n.getError("fileNotFound!", script.getAbsolutePath()));
789                          return;                          return;
790                  }                  }
791                                    
792                    String prefix = "#jsampler.fantasia: ";
793                    Vector<String> v = new Vector<String>();
794                  BufferedReader br = new BufferedReader(fr);                  BufferedReader br = new BufferedReader(fr);
795                                    
796                  try {                  try {
# Line 659  public class MainFrame extends JSMainFra Line 798  public class MainFrame extends JSMainFra
798                          while(s != null) {                          while(s != null) {
799                                  getLSConsoleModel().setCommandLineText(s);                                  getLSConsoleModel().setCommandLineText(s);
800                                  getLSConsoleModel().execCommand();                                  getLSConsoleModel().execCommand();
801                                    if(s.startsWith(prefix)) v.add(s.substring(prefix.length()));
802                                  s = br.readLine();                                  s = br.readLine();
803                          }                          }
804                  } catch(Exception e) {                  } catch(Exception e) {
# Line 671  public class MainFrame extends JSMainFra Line 811  public class MainFrame extends JSMainFra
811                  recentScripts.insertElementAt(s, 0);                  recentScripts.insertElementAt(s, 0);
812                                    
813                  updateRecentScriptsMenu();                  updateRecentScriptsMenu();
814                    
815                    CC.getViewConfig().setSessionViewConfig(
816                            new SessionViewConfig(v.toArray(new String[v.size()]))
817                    );
818          }          }
819                    
820          protected void          protected void

Legend:
Removed from v.1786  
changed lines
  Added in v.1919

  ViewVC Help
Powered by ViewVC