/[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 1776 by iliev, Thu Sep 11 18:48:36 2008 UTC revision 1872 by iliev, Mon Mar 23 15:34: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 23  Line 23 
23  package org.jsampler.view.fantasia;  package org.jsampler.view.fantasia;
24    
25  import java.awt.BorderLayout;  import java.awt.BorderLayout;
26    import java.awt.Color;
27    import java.awt.Composite;
28  import java.awt.Dialog;  import java.awt.Dialog;
29  import java.awt.Dimension;  import java.awt.Dimension;
30  import java.awt.Frame;  import java.awt.Frame;
31  import java.awt.Graphics;  import java.awt.Graphics;
32    import java.awt.Graphics2D;
33  import java.awt.GridBagConstraints;  import java.awt.GridBagConstraints;
34  import java.awt.GridBagLayout;  import java.awt.GridBagLayout;
35  import java.awt.Insets;  import java.awt.Insets;
36    import java.awt.Paint;
37    import java.awt.Rectangle;
38    
39  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
40  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
41  import java.awt.event.KeyEvent;  import java.awt.event.KeyEvent;
42    
43    import java.beans.PropertyChangeEvent;
44    import java.beans.PropertyChangeListener;
45    
46  import java.io.BufferedReader;  import java.io.BufferedReader;
47  import java.io.File;  import java.io.File;
48  import java.io.FileNotFoundException;  import java.io.FileNotFoundException;
49  import java.io.FileReader;  import java.io.FileReader;
50    
51  import java.util.Vector;  import java.util.Vector;
 import java.util.logging.Level;  
52    
53  import javax.swing.BorderFactory;  import javax.swing.BorderFactory;
54    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 55  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.LSConsoleModel;  import org.jsampler.LSConsoleModel;
71  import org.jsampler.Server;  import org.jsampler.Server;
72    
73  import org.jsampler.view.JSChannelsPane;  import org.jsampler.view.JSChannelsPane;
74  import org.jsampler.view.JSMainFrame;  import org.jsampler.view.SessionViewConfig;
75  import org.jsampler.view.LscpFileFilter;  
76    import org.jsampler.view.fantasia.basic.FantasiaPainter;
77    import org.jsampler.view.fantasia.basic.FantasiaPanel;
78    import org.jsampler.view.fantasia.basic.FantasiaSubPanel;
79    
80    import org.jsampler.view.std.JSBackendLogFrame;
81  import org.jsampler.view.std.JSConnectDlg;  import org.jsampler.view.std.JSConnectDlg;
82  import org.jsampler.view.std.JSDetailedErrorDlg;  import org.jsampler.view.std.JSDetailedErrorDlg;
83  import org.jsampler.view.std.JSQuitDlg;  import org.jsampler.view.std.JSQuitDlg;
84  import org.jsampler.view.std.JSamplerHomeChooser;  import org.jsampler.view.std.JSamplerHomeChooser;
85    import org.jsampler.view.std.StdMainFrame;
86    import org.jsampler.view.std.StdUtils;
87    
88  import static org.jsampler.view.fantasia.A4n.a4n;  import static org.jsampler.view.fantasia.A4n.a4n;
89  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
# Line 79  import static org.jsampler.view.std.StdP Line 95  import static org.jsampler.view.std.StdP
95   *   *
96   * @author Grigor Iliev   * @author Grigor Iliev
97   */   */
98  public class MainFrame extends JSMainFrame {  public class MainFrame extends StdMainFrame {
99            public final static int MAX_CHANNEL_LANE_NUMBER = 8;
100    
101          private final StandardBar standardBar = new StandardBar();          private final StandardBar standardBar = new StandardBar();
102          private final FantasiaMenuBar menuBar = new FantasiaMenuBar();          private final FantasiaMenuBar menuBar = new FantasiaMenuBar();
103          private final JPanel rootPane = new JPanel();          private final JPanel rootPane = new RootPane();
104          private final MainPane mainPane = new MainPane();          private final BottomPane bottomPane;
105            private final MainPane mainPane;
106          private final PianoKeyboardPane pianoKeyboardPane;          private final PianoKeyboardPane pianoKeyboardPane;
107                    
108          private final JMenu recentScriptsMenu =          private final JMenu recentScriptsMenu =
109                  new JMenu(i18n.getMenuLabel("actions.recentScripts"));                  new JMenu(i18n.getMenuLabel("actions.recentScripts"));
110                    
111          private final JSplitPane hSplitPane;          private final JSplitPane hSplitPane;
         private final JSplitPane pianoRollSplitPane;  
112                    
113          private final LeftSidePane leftSidePane = new LeftSidePane();          private final LeftSidePane leftSidePane;
114          private final RightSidePane rightSidePane = new RightSidePane();          private final RightSidePane rightSidePane;
115          private final JPanel rightPane;          private final JPanel rightPane;
116                    
117          //private final StatusBar statusBar = new StatusBar();          //private final StatusBar statusBar = new StatusBar();
118                    
119          private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame();          private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame();
120          private final Vector<String> recentScripts = new Vector<String>();          private final Vector<String> recentScripts = new Vector<String>();
121            
122            private final JSBackendLogFrame backendLogFrame = new JSBackendLogFrame();
123                                    
124                    
125          private final JCheckBoxMenuItem cbmiToolBarVisible =          private final JCheckBoxMenuItem cbmiToolBarVisible =
# Line 120  public class MainFrame extends JSMainFra Line 140  public class MainFrame extends JSMainFra
140          public          public
141          MainFrame() {          MainFrame() {
142                  setTitle(i18n.getLabel("MainFrame.title"));                  setTitle(i18n.getLabel("MainFrame.title"));
143                                    //setUndecorated(true);
144                  if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage());                  if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage());
145                                    
146                    CC.setMainFrame(this); // TODO:
147                    mainPane = new MainPane();
148                    leftSidePane = new LeftSidePane();
149                    rightSidePane = new RightSidePane();
150                    
151                    setSelectedChannelsPane(mainPane.getChannelsPane(0));
152                    
153                  getContentPane().add(standardBar, BorderLayout.NORTH);                  getContentPane().add(standardBar, BorderLayout.NORTH);
                 //getContentPane().add(statusBar, BorderLayout.SOUTH);  
154                                    
155                  rightPane = createRightPane();                  rightPane = createRightPane();
156                                    
# Line 135  public class MainFrame extends JSMainFra Line 161  public class MainFrame extends JSMainFra
161                  );                  );
162                  hSplitPane.setResizeWeight(0.5);                  hSplitPane.setResizeWeight(0.5);
163                                    
                 addChannelsPane(mainPane.getChannelsPane());  
                   
164                  pianoKeyboardPane = new PianoKeyboardPane();                  pianoKeyboardPane = new PianoKeyboardPane();
                 getChannelsPane(0).addListSelectionListener(pianoKeyboardPane);  
165                                    
166                  pianoRollSplitPane = new JSplitPane (                  for(int i = 0; i < mainPane.getChannelsPaneCount(); i++) {
167                          JSplitPane.VERTICAL_SPLIT,                          addChannelsPane(mainPane.getChannelsPane(i));
168                          true,   // continuousLayout                          getChannelsPane(i).addListSelectionListener(pianoKeyboardPane);
169                          rootPane, pianoKeyboardPane                  }
170                  );  
171                    PropertyChangeListener l = new PropertyChangeListener() {
172                            public void
173                            propertyChange(PropertyChangeEvent e) {
174                                    onChangeChannelLaneCount();
175                            }
176                    };
177    
178                    preferences().addPropertyChangeListener("channelLanes.count", l);
179                    
180                    int h = preferences().getIntProperty("midiKeyboard.height");
181                    setMidiKeyboardHeight(h);
182                    
183                    l = new PropertyChangeListener() {
184                            public void
185                            propertyChange(PropertyChangeEvent e) {
186                                    int h = preferences().getIntProperty("midiKeyboard.height");
187                                    setMidiKeyboardHeight(h);
188                            }
189                    };
190                                    
191                  pianoRollSplitPane.setResizeWeight(0.5);                  CC.preferences().addPropertyChangeListener("midiKeyboard.height", l);
192                                    
193                  rootPane.setLayout(new BorderLayout());                  bottomPane = new BottomPane();
194                  rootPane.setBorder(BorderFactory.createEmptyBorder(6, 0, 0, 0));                  
195                  rootPane.setOpaque(false);                  hSplitPane.setOpaque(false);
196                  rootPane.add(hSplitPane);                  rootPane.add(hSplitPane);
197                    rootPane.add(bottomPane, BorderLayout.SOUTH);
198                    add(rootPane);
199    
200                    if(CC.isMacOS()) {
201                            try {
202                                    String s = "org.jsampler.view.fantasia.MacOSApplicationHandler";
203                                    Class.forName(s).newInstance(); }
204                            catch(Throwable e) { }
205                    }
206                                    
207                  addMenu();                  addMenu();
208                                    
209                  getContentPane().add(pianoRollSplitPane);                  if(CC.getViewConfig().isUsingScreenMenuBar()) {
210                            // fix for moving the menu bar on top of the screen
211                            // when running on Mac OS and third party plugin is used
212                            ((ViewConfig)CC.getViewConfig()).restoreMenuProperties();
213                    }
214                                    
215                  int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);                  int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
216                  hSplitPane.setDividerLocation(i);                  hSplitPane.setDividerLocation(i);
# Line 167  public class MainFrame extends JSMainFra Line 222  public class MainFrame extends JSMainFra
222                    
223          private JPanel          private JPanel
224          createRightPane() {          createRightPane() {
225                  JPanel p = new JPanel();                  JPanel p = new FantasiaPanel();
226                    p.setOpaque(false);
227                    
228                  GridBagLayout gridbag = new GridBagLayout();                  GridBagLayout gridbag = new GridBagLayout();
229                  GridBagConstraints c = new GridBagConstraints();                  GridBagConstraints c = new GridBagConstraints();
230                                    
# Line 187  public class MainFrame extends JSMainFra Line 244  public class MainFrame extends JSMainFra
244                  c.gridy = 0;                  c.gridy = 0;
245                  c.weightx = 0.0;                  c.weightx = 0.0;
246                  c.weighty = 1.0;                  c.weighty = 1.0;
247                  c.insets = new Insets(0, 3, 0, 3);                  c.insets = new Insets(0, 0, 0, 3);
248                  c.fill = GridBagConstraints.VERTICAL;                  c.fill = GridBagConstraints.VERTICAL;
249                  gridbag.setConstraints(mainPane, c);                  gridbag.setConstraints(mainPane, c);
250                  p.add(mainPane);                  p.add(mainPane);
# Line 197  public class MainFrame extends JSMainFra Line 254  public class MainFrame extends JSMainFra
254                    
255          private void          private void
256          setSavedSize() {          setSavedSize() {
257                  String s = preferences().getStringProperty("MainFrame.sizeAndLocation");                  Rectangle r = StdUtils.getWindowBounds("MainFrame");
258                  if(s == null) {                  if(r == null) {
259                          setDefaultSizeAndLocation();                          setDefaultSizeAndLocation();
260                          return;                          return;
261                  }                  }
                 pack();  
                 try {  
                         int i = s.indexOf(',');  
                         int x = Integer.parseInt(s.substring(0, i));  
                           
                         s = s.substring(i + 1);  
                         i = s.indexOf(',');  
                         int y = Integer.parseInt(s.substring(0, i));  
                           
                         s = s.substring(i + 1);  
                         i = s.indexOf(',');  
                         int width = Integer.parseInt(s.substring(0, i));  
                           
                         s = s.substring(i + 1);  
                         int height = Integer.parseInt(s);  
                           
                         setBounds(x, y, width, height);  
                 } catch(Exception x) {  
                         String msg = "Parsing of window size and location string failed";  
                         CC.getLogger().log(Level.INFO, msg, x);  
                         setDefaultSizeAndLocation();  
                 }  
262                                    
263                  if(preferences().getBoolProperty("MainFrame.windowMaximized")) {                  setBounds(r);
                         setExtendedState(getExtendedState() | MAXIMIZED_BOTH);  
                 }  
264          }          }
265                    
266          private void          private void
# Line 239  public class MainFrame extends JSMainFra Line 272  public class MainFrame extends JSMainFra
272                    
273                    
274          /** Invoked when this window is about to close. */          /** Invoked when this window is about to close. */
275          protected void          @Override
276            public void
277          onWindowClose() {          onWindowClose() {
278                  boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT);                  boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT);
279                  if(b && CC.getSamplerModel().isModified()) {                  if(b && CC.getSamplerModel().isModified()) {
# Line 264  public class MainFrame extends JSMainFra Line 298  public class MainFrame extends JSMainFra
298                          return;                          return;
299                  }                  }
300                                    
301                  java.awt.Point p = getLocation();                  StdUtils.saveWindowBounds("MainFrame", getBounds());
                 Dimension d = getSize();  
                 StringBuffer sb = new StringBuffer();  
                 sb.append(p.x).append(',').append(p.y).append(',');  
                 sb.append(d.width).append(',').append(d.height);  
                 preferences().setStringProperty("MainFrame.sizeAndLocation", sb.toString());  
302                                    
303                  String[] list = recentScripts.toArray(new String[recentScripts.size()]);                  String[] list = recentScripts.toArray(new String[recentScripts.size()]);
304                  preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list);                  preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list);
# Line 278  public class MainFrame extends JSMainFra Line 307  public class MainFrame extends JSMainFra
307                          if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory();                          if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory();
308                  }                  }
309                                    
310                    if(getBackendLogFrame() != null) getBackendLogFrame().stopTimer();
311                    if(getLSConsolePane() != null) getLSConsolePane().disconnect();
312                    
313                  super.onWindowClose();                  super.onWindowClose();
314          }          }
315    
316            private void
317            onChangeChannelLaneCount() {
318                    int newCount = preferences().getIntProperty("channelLanes.count");
319                    if(newCount < 1 || newCount > MAX_CHANNEL_LANE_NUMBER) return;
320                    if(newCount == getChannelsPaneCount()) return;
321                    int current = getChannelsPaneIndex(getSelectedChannelsPane());
322    
323                    if(newCount > getChannelsPaneCount()) {
324                            int d = newCount - getChannelsPaneCount();
325                            for(int i = 0; i < d; i++) {
326                                    JSChannelsPane p = mainPane.addChannelsPane();
327                                    addChannelsPane(p);
328                                    p.addListSelectionListener(pianoKeyboardPane);
329                            }
330                    } else {
331                            int d = getChannelsPaneCount() - newCount;
332                            for(int i = 0; i < d; i++) {
333                                    int idx = getChannelsPaneCount() - 1 - i;
334                                    if(getChannelsPane(idx).getChannelCount() > 0) {
335                                            String s;
336                                            s = i18n.getError("MainFrame.notEmptyChannelLane!", idx + 1);
337                                            HF.showErrorMessage(s);
338                                            return;
339                                    }
340                            }
341    
342                            for(int i = 0; i < d; i++) {
343                                    int idx = getChannelsPaneCount() - 1;
344                                    JSChannelsPane p = getChannelsPane(idx);
345                                    removeChannelsPane(p);
346                                    p.removeListSelectionListener(pianoKeyboardPane);
347                                    mainPane.removeChannelsPane(idx);
348                            }
349                    }
350    
351                    if(newCount == 1) {
352                            mainPane.getButtonsPanel().setVisible(false);
353                    } else if(!mainPane.getButtonsPanel().isVisible()) {
354                            mainPane.getButtonsPanel().setVisible(true);
355                    }
356                    mainPane.getButtonsPanel().setButtonNumber(newCount);
357                    if(current < 0 || current >= getChannelsPaneCount()) current = 0;
358                    setSelectedChannelsPane(getChannelsPane(current));
359            }
360            
361            @Override
362            public void
363            setVisible(boolean b) {
364                    if(b == isVisible()) return;
365                    
366                    super.setVisible(b);
367                    
368                    if(b && preferences().getBoolProperty("MainFrame.windowMaximized")) {
369                            setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
370                    }
371            }
372                    
373          private void          private void
374          addMenu() {          addMenu() {
# Line 308  public class MainFrame extends JSMainFra Line 397  public class MainFrame extends JSMainFra
397                                    
398                  JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export"));                  JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export"));
399                  m.add(exportMenu);                  m.add(exportMenu);
400    
401                    int modKey = CC.getViewConfig().getDefaultModKey();
402                                    
403                  mi = new JMenuItem(a4n.exportSamplerConfig);                  mi = new JMenuItem(a4n.exportSamplerConfig);
404                  mi.setIcon(null);                  mi.setIcon(null);
405                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, modKey));
406                  exportMenu.add(mi);                  exportMenu.add(mi);
407                                    
408                  mi = new JMenuItem(a4n.exportMidiInstrumentMaps);                  mi = new JMenuItem(a4n.exportMidiInstrumentMaps);
# Line 322  public class MainFrame extends JSMainFra Line 413  public class MainFrame extends JSMainFra
413                                    
414                  mi = new JMenuItem(a4n.loadScript);                  mi = new JMenuItem(a4n.loadScript);
415                  mi.setIcon(null);                  mi.setIcon(null);
416                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK));                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, modKey));
417                  m.add(mi);                  m.add(mi);
418                                    
419                  String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS);                  String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS);
# Line 336  public class MainFrame extends JSMainFra Line 427  public class MainFrame extends JSMainFra
427                                    
428                  mi = new JMenuItem(a4n.changeBackend);                  mi = new JMenuItem(a4n.changeBackend);
429                  mi.setIcon(null);                  mi.setIcon(null);
430                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK));                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, modKey));
431                  m.add(mi);                  m.add(mi);
432                                    
433                  m.addSeparator();                  m.addSeparator();
# Line 379  public class MainFrame extends JSMainFra Line 470  public class MainFrame extends JSMainFra
470                  mi = new JMenuItem(a4n.editPreferences);                  mi = new JMenuItem(a4n.editPreferences);
471                  mi.setIcon(null);                  mi.setIcon(null);
472                  mi.setAccelerator(KeyStroke.getKeyStroke (                  mi.setAccelerator(KeyStroke.getKeyStroke (
473                          KeyEvent.VK_P, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK                          KeyEvent.VK_P, modKey | KeyEvent.SHIFT_MASK
474                  ));                  ));
475                  m.add(mi);                  m.add(mi);
476                                    
# Line 401  public class MainFrame extends JSMainFra Line 492  public class MainFrame extends JSMainFra
492                  showToolBar(b);                  showToolBar(b);
493                                    
494                  cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (                  cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
495                          KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK                          KeyEvent.VK_L, modKey | KeyEvent.SHIFT_MASK
496                  ));                  ));
497                  m.add(cbmiLeftSidePaneVisible);                  m.add(cbmiLeftSidePaneVisible);
498                                    
# Line 417  public class MainFrame extends JSMainFra Line 508  public class MainFrame extends JSMainFra
508                  showSidePane(b);                  showSidePane(b);
509                                    
510                  cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (                  cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
511                          KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK                          KeyEvent.VK_R, modKey | KeyEvent.SHIFT_MASK
512                  ));                  ));
513                  m.add(cbmiRightSidePaneVisible);                  m.add(cbmiRightSidePaneVisible);
514                                    
# Line 439  public class MainFrame extends JSMainFra Line 530  public class MainFrame extends JSMainFra
530                  cbmiMidiKeyboardVisible.addActionListener(new ActionListener() {                  cbmiMidiKeyboardVisible.addActionListener(new ActionListener() {
531                          public void                          public void
532                          actionPerformed(ActionEvent e) {                          actionPerformed(ActionEvent e) {
533                                  showMidiKeyboard(cbmiMidiKeyboardVisible.getState());                                  setMidiKeyboardVisible(cbmiMidiKeyboardVisible.getState());
534                          }                          }
535                  });                  });
536                                    
537                  b = preferences().getBoolProperty("midiKeyboard.visible");                  b = preferences().getBoolProperty("midiKeyboard.visible");
538                  cbmiMidiKeyboardVisible.setSelected(b);                  cbmiMidiKeyboardVisible.setSelected(b);
539                  showMidiKeyboard(b);                  setMidiKeyboardVisible(b);
540                    
541                    
542                    // Channels
543                    m = new FantasiaMenu(i18n.getMenuLabel("channels"));
544                    
545                    mi = new JMenuItem(i18n.getMenuLabel("channels.newChannel"));
546                    mi.addActionListener(new ActionListener() {
547                            public void
548                            actionPerformed(ActionEvent e) {
549                                    CC.getSamplerModel().addBackendChannel();
550                            }
551                    });
552                    m.add(mi);
553                    
554                    m.addSeparator();
555                    
556                    MenuManager.ChannelViewGroup group = new MenuManager.ChannelViewGroup();
557                    MenuManager.getMenuManager().registerChannelViewGroup(group);
558                    
559                    for(JMenuItem menuItem : group.getMenuItems()) m.add(menuItem);
560                                    
561                    m.addSeparator();
562                    
563                    m.add(new JMenuItem(a4n.moveChannelsOnTop));
564                    m.add(new JMenuItem(a4n.moveChannelsUp));
565                    m.add(new JMenuItem(a4n.moveChannelsDown));
566                    m.add(new JMenuItem(a4n.moveChannelsAtBottom));
567                    
568                    m.add(new ToPanelMenu());
569                    
570                    m.addSeparator();
571                    
572                    mi = new JMenuItem(a4n.selectAllChannels);
573                    mi.setIcon(null);
574                    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, modKey));
575                    m.add(mi);
576                    
577                    mi = new JMenuItem(a4n.deselectChannels);
578                    mi.setIcon(null);
579                    mi.setAccelerator(KeyStroke.getKeyStroke (
580                            KeyEvent.VK_A, modKey | KeyEvent.SHIFT_MASK
581                    ));
582                    m.add(mi);
583                    
584                    menuBar.add(m);
585                                    
586                  // Window                  // Window
587                  m = new FantasiaMenu(i18n.getMenuLabel("window"));                  m = new FantasiaMenu(i18n.getMenuLabel("window"));
# Line 460  public class MainFrame extends JSMainFra Line 595  public class MainFrame extends JSMainFra
595                  mi.setIcon(null);                  mi.setIcon(null);
596                  m.add(mi);                  m.add(mi);
597                                    
598                    m.addSeparator();
599                    
600                    final JMenuItem mi2 = new JMenuItem(i18n.getMenuLabel("window.backendLog"));
601                    m.add(mi2);
602                    mi2.addActionListener(new ActionListener() {
603                            public void
604                            actionPerformed(ActionEvent e) {
605                                    if(getBackendLogFrame().isVisible()) {
606                                            getBackendLogFrame().setVisible(false);
607                                    }
608                                    
609                                    getBackendLogFrame().setVisible(true);
610                            }
611                    });
612                    
613                    mi2.setEnabled(CC.getBackendProcess() != null);
614                    
615                    CC.addBackendProcessListener(new ActionListener() {
616                            public void
617                            actionPerformed(ActionEvent e) {
618                                    mi2.setEnabled(CC.getBackendProcess() != null);
619                            }
620                    });
621                    
622                                    
623                  // Help                  // Help
624                  m = new FantasiaMenu(i18n.getMenuLabel("help"));                  m = new FantasiaMenu(i18n.getMenuLabel("help"));
# Line 477  public class MainFrame extends JSMainFra Line 636  public class MainFrame extends JSMainFra
636                  menuBar.add(m);                  menuBar.add(m);
637          }          }
638                    
639            public static class ToPanelMenu extends FantasiaMenu implements ListSelectionListener {
640                    public
641                    ToPanelMenu() {
642                            super(i18n.getMenuLabel("channels.toPanel"));
643                            setEnabled(CC.getMainFrame().getSelectedChannelsPane().hasSelectedChannel());
644                            
645                            CC.getMainFrame().addChannelsPaneSelectionListener(this);
646                            
647                            for(int i = 0; i < CC.getMainFrame().getChannelsPaneCount(); i++) {
648                                    JSChannelsPane p = CC.getMainFrame().getChannelsPane(i);
649                                    add(new JMenuItem(new A4n.MoveChannelsToPanel(p)));
650                                    p.addListSelectionListener(this);
651                            }
652                    }
653                    
654                    @Override
655                    public void
656                    valueChanged(ListSelectionEvent e) {
657                            setEnabled(CC.getMainFrame().getSelectedChannelsPane().hasSelectedChannel());
658                    }
659            }
660            
661          public RightSidePane          public RightSidePane
662          getRightSidePane() { return rightSidePane; }          getRightSidePane() { return rightSidePane; }
663                    
664            @Override
665            public A4n
666            getA4n() { return A4n.a4n; }
667            
668          /**          /**
669           * This method does nothing, because <b>Fantasia</b> has exactly           * This method does nothing, because <b>Fantasia</b> has constant
670           * one pane containing sampler channels, which can not be changed.           * number of panes containing sampler channels, which can not be changed.
671           */           */
672            @Override
673          public void          public void
674          insertChannelsPane(JSChannelsPane pane, int idx) {          insertChannelsPane(JSChannelsPane pane, int idx) {
675                                    
676          }          }
677                    
678          /**          @Override
          * This method always returns the <code>JSChannelsPane</code> at index 0,  
          * because the <b>Fantasia</b> view has exactly one pane containing sampler channels.  
          * @return The <code>JSChannelsPane</code> at index 0.  
          */  
679          public JSChannelsPane          public JSChannelsPane
680          getSelectedChannelsPane() { return getChannelsPane(0); }          getSelectedChannelsPane() { return mainPane.getSelectedChannelsPane(); }
681                    
682          /**          @Override
          * This method does nothing because the <b>Fantasia</b> view has  
          * exactly one pane containing sampler channels which is always shown.  
          */  
683          public void          public void
684          setSelectedChannelsPane(JSChannelsPane pane) { }          setSelectedChannelsPane(JSChannelsPane pane) {
685                    mainPane.setSelectedChannelsPane(pane);
686                    fireChannelsPaneSelectionChanged();
687            }
688                    
689            @Override
690          public void          public void
691          installJSamplerHome() {          installJSamplerHome() {
692                  JSamplerHomeChooser chooser = new JSamplerHomeChooser(this);                  JSamplerHomeChooser chooser = new JSamplerHomeChooser(this);
# Line 513  public class MainFrame extends JSMainFra Line 696  public class MainFrame extends JSMainFra
696                  CC.changeJSamplerHome(chooser.getJSamplerHome());                  CC.changeJSamplerHome(chooser.getJSamplerHome());
697          }          }
698                    
699            @Override
700          public void          public void
701          showDetailedErrorMessage(Frame owner, String err, String details) {          showDetailedErrorMessage(Frame owner, String err, String details) {
702                  JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (                  JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
# Line 521  public class MainFrame extends JSMainFra Line 705  public class MainFrame extends JSMainFra
705                  dlg.setVisible(true);                  dlg.setVisible(true);
706          }          }
707                    
708            @Override
709          public void          public void
710          showDetailedErrorMessage(Dialog owner, String err, String details) {          showDetailedErrorMessage(Dialog owner, String err, String details) {
711                  JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (                  JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
# Line 533  public class MainFrame extends JSMainFra Line 718  public class MainFrame extends JSMainFra
718           * Gets the server address to which to connect. If the server should be           * Gets the server address to which to connect. If the server should be
719           * manually selected, a dialog asking the user to choose a server is displayed.           * manually selected, a dialog asking the user to choose a server is displayed.
720           */           */
721            @Override
722          public Server          public Server
723          getServer() {          getServer() {
724                  boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP);                  boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP);
# Line 544  public class MainFrame extends JSMainFra Line 730  public class MainFrame extends JSMainFra
730           * manually selected, a dialog asking the user to choose a server is displayed.           * manually selected, a dialog asking the user to choose a server is displayed.
731           * @param manualSelect Determines whether the server should be manually selected.           * @param manualSelect Determines whether the server should be manually selected.
732           */           */
733            @Override
734          public Server          public Server
735          getServer(boolean manualSelect) {          getServer(boolean manualSelect) {
736                  if(manualSelect) {                  if(manualSelect) {
737                          JSConnectDlg dlg = new JSConnectDlg();                          JSConnectDlg dlg = new JSConnectDlg();
738                          dlg.setVisible(true);                          dlg.setVisible(true);
739                            
740                          return dlg.getSelectedServer();                          return dlg.getSelectedServer();
741                  }                  }
742                                    
# Line 574  public class MainFrame extends JSMainFra Line 762  public class MainFrame extends JSMainFra
762          protected LSConsoleFrame          protected LSConsoleFrame
763          getLSConsoleFrame() { return lsConsoleFrame; }          getLSConsoleFrame() { return lsConsoleFrame; }
764                    
765            public JSBackendLogFrame
766            getBackendLogFrame() { return backendLogFrame; }
767            
768          protected boolean          protected boolean
769          runScript() {          runScript() {
770                  String s = preferences().getStringProperty("lastScriptLocation");                  File f = StdUtils.showOpenLscpFileChooser();
771                  JFileChooser fc = new JFileChooser(s);                  if(f == null) return false;
772                  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());  
773                                    
774                  return true;                  return true;
775          }          }
776                    
777          private void          @Override
778            public void
779          runScript(String script) { runScript(new File(script)); }          runScript(String script) { runScript(new File(script)); }
780                    
781          private void          private void
# Line 598  public class MainFrame extends JSMainFra Line 783  public class MainFrame extends JSMainFra
783                  FileReader fr;                  FileReader fr;
784                  try { fr = new FileReader(script); }                  try { fr = new FileReader(script); }
785                  catch(FileNotFoundException e) {                  catch(FileNotFoundException e) {
786                          HF.showErrorMessage(i18n.getMessage("FileNotFound!"));                          HF.showErrorMessage(i18n.getError("fileNotFound!"));
787                          return;                          return;
788                  }                  }
789                                    
790                    String prefix = "#jsampler.fantasia: ";
791                    Vector<String> v = new Vector<String>();
792                  BufferedReader br = new BufferedReader(fr);                  BufferedReader br = new BufferedReader(fr);
793                                    
794                  try {                  try {
# Line 609  public class MainFrame extends JSMainFra Line 796  public class MainFrame extends JSMainFra
796                          while(s != null) {                          while(s != null) {
797                                  getLSConsoleModel().setCommandLineText(s);                                  getLSConsoleModel().setCommandLineText(s);
798                                  getLSConsoleModel().execCommand();                                  getLSConsoleModel().execCommand();
799                                    if(s.startsWith(prefix)) v.add(s.substring(prefix.length()));
800                                  s = br.readLine();                                  s = br.readLine();
801                          }                          }
802                  } catch(Exception e) {                  } catch(Exception e) {
# Line 621  public class MainFrame extends JSMainFra Line 809  public class MainFrame extends JSMainFra
809                  recentScripts.insertElementAt(s, 0);                  recentScripts.insertElementAt(s, 0);
810                                    
811                  updateRecentScriptsMenu();                  updateRecentScriptsMenu();
812                    
813                    CC.getViewConfig().setSessionViewConfig(
814                            new SessionViewConfig(v.toArray(new String[v.size()]))
815                    );
816          }          }
817                    
818          protected void          protected void
# Line 722  public class MainFrame extends JSMainFra Line 914  public class MainFrame extends JSMainFra
914                  });                  });
915          }          }
916                    
917          private void          public void
918          showMidiKeyboard(boolean b) {          setMidiKeyboardVisible(boolean b) {
919                  preferences().setBoolProperty("midiKeyboard.visible", b);                  preferences().setBoolProperty("midiKeyboard.visible", b);
920                  if(b) {                  pianoKeyboardPane.setVisible(b);
921                          getContentPane().remove(rootPane);                  
922                          pianoRollSplitPane.setTopComponent(rootPane);                  if(cbmiMidiKeyboardVisible.isSelected() != b) {
923                          getContentPane().add(pianoRollSplitPane);                          cbmiMidiKeyboardVisible.setSelected(b);
924                  } else {                  }
925                          getContentPane().remove(pianoRollSplitPane);                  
926                          pianoRollSplitPane.remove(rootPane);                  if(standardBar.btnMidiKeyboard.isSelected() != b) {
927                          getContentPane().add(rootPane);                          standardBar.btnMidiKeyboard.setSelected(b);
928                    }
929                    
930                    if(pianoKeyboardPane.btnPower.isSelected() != b) {
931                            pianoKeyboardPane.btnPower.setSelected(b);
932                  }                  }
933                                    
934                  getContentPane().validate();                  rootPane.validate();
935                  getContentPane().repaint();                  rootPane.repaint();
936            }
937            
938            public void
939            setMidiKeyboardHeight(int height) {
940                    Dimension d = pianoKeyboardPane.getPreferredSize();
941                    d = new Dimension(d.width, height);
942                    pianoKeyboardPane.setPreferredSize(d);
943                    pianoKeyboardPane.setMinimumSize(d);
944                    pianoKeyboardPane.revalidate();
945                    pianoKeyboardPane.repaint();
946          }          }
947                    
948          private void          private void
# Line 764  public class MainFrame extends JSMainFra Line 970  public class MainFrame extends JSMainFra
970                                    
971                  RecentScriptHandler(String script) { this.script = script; }                  RecentScriptHandler(String script) { this.script = script; }
972                                    
973                    @Override
974                  public void                  public void
975                  actionPerformed(ActionEvent e) {                  actionPerformed(ActionEvent e) {
976                          runScript(script);                          runScript(script);
# Line 783  public class MainFrame extends JSMainFra Line 990  public class MainFrame extends JSMainFra
990          }          }
991    
992          private class FantasiaMenuBar extends JMenuBar {          private class FantasiaMenuBar extends JMenuBar {
                 private Insets pixmapInsets = new Insets(6, 6, 0, 6);  
                 private Insets pixmapInsets2 = new Insets(6, 6, 6, 6);  
                   
993                  FantasiaMenuBar() {                  FantasiaMenuBar() {
994                          setOpaque(false);                          setOpaque(false);
995                            setBorder(BorderFactory.createEmptyBorder(2, 6, 0, 0));
996                  }                  }
997                                    
998                    @Override
999                  protected void                  protected void
1000                  paintComponent(Graphics g) {                  paintComponent(Graphics g) {
1001                          super.paintComponent(g);                          //super.paintComponent(g);
1002                            Graphics2D g2 = (Graphics2D)g;
1003                            
1004                            Paint oldPaint = g2.getPaint();
1005                            Composite oldComposite = g2.getComposite();
1006                            
1007                            double h = getSize().getHeight();
1008                            double w = getSize().getWidth();
1009                            
1010                            FantasiaPainter.paintGradient(g2, 0.0, 0.0, w - 1, h - 1, FantasiaPainter.color6, FantasiaPainter.color5);
1011                            
1012                            FantasiaPainter.Border b;
1013                            
1014                            
1015                          if(standardBar.isVisible()) {                          if(standardBar.isVisible()) {
1016                                  PixmapPane.paintComponent(this, g, Res.gfxMenuBarBg, pixmapInsets);                                  b = new FantasiaPainter.Border(true, true, false, true);
1017                                    FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h + 1, b);
1018                          } else {                          } else {
1019                                  PixmapPane.paintComponent(this, g, Res.gfxRoundBg14, pixmapInsets2);                                  b = new FantasiaPainter.Border(true, true, true, true);
1020                                    FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h - 1, b);
1021                          }                          }
1022                            
1023                            g2.setPaint(oldPaint);
1024                            g2.setComposite(oldComposite);
1025                    }
1026            }
1027            
1028            class RootPane extends FantasiaSubPanel {
1029                    private final Color color1 = new Color(0x454545);
1030                    private final Color color2 = new Color(0x2e2e2e);
1031                    
1032                    RootPane() {
1033                            setLayout(new BorderLayout());
1034                            setBorder(BorderFactory.createEmptyBorder(9, 10, 6, 10));
1035                            setOpaque(false);
1036                    
1037                    }
1038            
1039                    @Override
1040                    public void
1041                    paintComponent(Graphics g) {
1042                            Graphics2D g2 = (Graphics2D)g;
1043                            
1044                            Paint oldPaint = g2.getPaint();
1045                            Composite oldComposite = g2.getComposite();
1046                            
1047                            double h = getSize().getHeight();
1048                            double w = getSize().getWidth();
1049                            
1050                            FantasiaPainter.paintBorder(g2, 0, -3, w - 1, h - 1, 6, false);
1051                            paintComponent(g2, 5, 1, w - 10, h - 6, color1, color2);
1052                            
1053                            g2.setPaint(oldPaint);
1054                            g2.setComposite(oldComposite);
1055                    }
1056            }
1057            
1058            class BottomPane extends FantasiaPanel {
1059                    BottomPane() {
1060                            setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
1061                            setOpaque(false);
1062                            add(pianoKeyboardPane);
1063                            
1064                  }                  }
1065          }          }
1066  }  }

Legend:
Removed from v.1776  
changed lines
  Added in v.1872

  ViewVC Help
Powered by ViewVC