/[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 1318 by iliev, Sat Sep 1 13:46:04 2007 UTC revision 1883 by iliev, Sun Apr 5 09:15:35 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-2007 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.Point;  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  import java.awt.event.MouseAdapter;  
43  import java.awt.event.MouseEvent;  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;
# Line 44  import java.io.FileNotFoundException; Line 49  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;
 import javax.swing.Box;  
54  import javax.swing.BoxLayout;  import javax.swing.BoxLayout;
55  import javax.swing.JCheckBoxMenuItem;  import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JDialog;  
 import javax.swing.JFileChooser;  
 import javax.swing.JFrame;  
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;
59  import javax.swing.JPanel;  import javax.swing.JPanel;
 import javax.swing.JPopupMenu;  
 import javax.swing.JScrollPane;  
60  import javax.swing.JSplitPane;  import javax.swing.JSplitPane;
 import javax.swing.JToggleButton;  
61  import javax.swing.KeyStroke;  import javax.swing.KeyStroke;
62  import javax.swing.SwingUtilities;  import javax.swing.SwingUtilities;
63  import javax.swing.UIManager;  import javax.swing.Timer;
64    
65  import net.sf.juife.TitleBar;  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;
72    
 import org.jsampler.view.JSChannel;  
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;
82    import org.jsampler.view.std.JSDetailedErrorDlg;
83    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 88  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          private final FantasiaMenuBar menuBar = new FantasiaMenuBar();          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 MainPane mainPane = new MainPane();          private final FantasiaMenuBar menuBar = new FantasiaMenuBar();
103          private final DevicesPane devicesPane = new DevicesPane();          private final JPanel rootPane = new RootPane();
104            private final BottomPane bottomPane;
105            private final MainPane mainPane;
106            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;
112                    
113          private final SidePane sidePane = new SidePane();          private final LeftSidePane leftSidePane;
114            private final RightSidePane rightSidePane;
115            private final JPanel rightPane;
116            
117            //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 =
126                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar"));
127            
128            private final JCheckBoxMenuItem cbmiLeftSidePaneVisible =
129                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftSidePane"));
130            
131            private final JCheckBoxMenuItem cbmiRightSidePaneVisible =
132                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.rightSidePane"));
133            
134            private final JCheckBoxMenuItem cbmiMidiKeyboardVisible =
135                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.midiKeyboard"));
136            
137            private final Timer guiTimer = new Timer(1000, null);
138            
139          /** Creates a new instance of <code>MainFrame</code> */          /** Creates a new instance of <code>MainFrame</code> */
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                  getContentPane().add(standardBar, BorderLayout.NORTH);                  CC.setMainFrame(this); // TODO:
147                    mainPane = new MainPane();
148                    leftSidePane = new LeftSidePane();
149                    rightSidePane = new RightSidePane();
150                                    
151                  addMenu();                  setSelectedChannelsPane(mainPane.getChannelsPane(0));
152                                    
153                  addChannelsPane(mainPane.getChannelsPane());                  getContentPane().add(standardBar, BorderLayout.NORTH);
154                                    
155                  JPanel rp = createRightPane();                  rightPane = createRightPane();
156                                    
157                  hSplitPane = new JSplitPane (                  hSplitPane = new JSplitPane (
158                          JSplitPane.HORIZONTAL_SPLIT,                          JSplitPane.HORIZONTAL_SPLIT,
159                          true,   // continuousLayout                          true,   // continuousLayout
160                          sidePane, rp                          leftSidePane, rightPane
161                  );                  );
162                    hSplitPane.setResizeWeight(0.5);
163                                    
164                  getContentPane().add(hSplitPane);                  pianoKeyboardPane = new PianoKeyboardPane();
165                    
166                    for(int i = 0; i < mainPane.getChannelsPaneCount(); i++) {
167                            addChannelsPane(mainPane.getChannelsPane(i));
168                            getChannelsPane(i).addListSelectionListener(pianoKeyboardPane);
169                    }
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                    CC.preferences().addPropertyChangeListener("midiKeyboard.height", l);
192                    
193                    bottomPane = new BottomPane();
194                    
195                    hSplitPane.setOpaque(false);
196                    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();
208                    
209                    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);
217                                    
218                  setSavedSize();                  setSavedSize();
219                    
220                    guiTimer.start();
221          }          }
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 144  public class MainFrame extends JSMainFra Line 232  public class MainFrame extends JSMainFra
232                                    
233                  c.fill = GridBagConstraints.BOTH;                  c.fill = GridBagConstraints.BOTH;
234                                    
                 JScrollPane sp = new JScrollPane(devicesPane);  
                 sp.setBorder(BorderFactory.createEmptyBorder());  
                   
235                  c.gridx = 1;                  c.gridx = 1;
236                  c.gridy = 0;                  c.gridy = 0;
237                  c.weightx = 1.0;                  c.weightx = 1.0;
238                  c.weighty = 1.0;                  c.weighty = 1.0;
239                  c.insets = new Insets(0, 3, 3, 0);                  c.insets = new Insets(0, 3, 0, 0);
240                  gridbag.setConstraints(sp, c);                  gridbag.setConstraints(rightSidePane, c);
241                  p.add(sp);                  p.add(rightSidePane);
242                                    
243                  c.gridx = 0;                  c.gridx = 0;
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, 3, 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 169  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 211  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                  sidePane.savePreferences();                  boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT);
279                    if(b && CC.getSamplerModel().isModified()) {
280                            JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32);
281                            dlg.setVisible(true);
282                            if(dlg.isCancelled()) return;
283                    }
284                    
285                    leftSidePane.savePreferences();
286                    rightSidePane.savePreferences();
287                                    
288                  int i = hSplitPane.getDividerLocation();                  int i = hSplitPane.getDividerLocation();
289                  preferences().setIntProperty("MainFrame.hSplitDividerLocation", i);                  preferences().setIntProperty("MainFrame.hSplitDividerLocation", i);
# Line 228  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 242  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 255  public class MainFrame extends JSMainFra Line 380  public class MainFrame extends JSMainFra
380                  // Actions                  // Actions
381                  m = new FantasiaMenu(i18n.getMenuLabel("actions"));                  m = new FantasiaMenu(i18n.getMenuLabel("actions"));
382                                    
383                  mi = new JMenuItem(a4n.connect);                  mi = new JMenuItem(a4n.refresh);
384                  mi.setIcon(null);                  mi.setIcon(null);
385                  //mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK));                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
386                  m.add(mi);                  m.add(mi);
387                                    
388                  mi = new JMenuItem(a4n.samplerInfo);                  mi = new JMenuItem(a4n.samplerInfo);
389                  mi.setIcon(null);                  mi.setIcon(null);
390                  m.add(mi);                  m.add(mi);
391                                    
392                    mi = new JMenuItem(a4n.resetSampler);
393                    mi.setIcon(null);
394                    m.add(mi);
395                    
396                  m.addSeparator();                  m.addSeparator();
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 282  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, 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 293  public class MainFrame extends JSMainFra Line 425  public class MainFrame extends JSMainFra
425                                    
426                  m.addSeparator();                  m.addSeparator();
427                                    
428                    mi = new JMenuItem(a4n.changeBackend);
429                    mi.setIcon(null);
430                    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, modKey));
431                    m.add(mi);
432                    
433                    m.addSeparator();
434                    
435                  mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));                  mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));
436                  m.add(mi);                  m.add(mi);
437                  mi.addActionListener(new ActionListener() {                  mi.addActionListener(new ActionListener() {
# Line 307  public class MainFrame extends JSMainFra Line 446  public class MainFrame extends JSMainFra
446                  m = new FantasiaMenu(i18n.getMenuLabel("edit"));                  m = new FantasiaMenu(i18n.getMenuLabel("edit"));
447                  menuBar.add(m);                  menuBar.add(m);
448                                    
449                    mi = new JMenuItem(i18n.getMenuLabel("edit.addChannel"));
450                    m.add(mi);
451                    mi.addActionListener(new ActionListener() {
452                            public void
453                            actionPerformed(ActionEvent e) {
454                                    CC.getSamplerModel().addBackendChannel();
455                            }
456                    });
457                    
458                    m.addSeparator();
459                    
460                    mi = new JMenuItem(a4n.createMidiDevice);
461                    mi.setIcon(null);
462                    m.add(mi);
463                    
464                    mi = new JMenuItem(a4n.createAudioDevice);
465                    mi.setIcon(null);
466                    m.add(mi);
467                    
468                    m.addSeparator();
469                    
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);
476                    
477                    // View
478                    m = new FantasiaMenu(i18n.getMenuLabel("view"));
479                    menuBar.add(m);
480                    
481                    m.add(cbmiToolBarVisible);
482                    
483                    cbmiToolBarVisible.addActionListener(new ActionListener() {
484                            public void
485                            actionPerformed(ActionEvent e) {
486                                    showToolBar(cbmiToolBarVisible.getState());
487                            }
488                    });
489                    
490                    boolean b = preferences().getBoolProperty("toolBar.visible");
491                    cbmiToolBarVisible.setSelected(b);
492                    showToolBar(b);
493                    
494                    cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
495                            KeyEvent.VK_L, modKey | KeyEvent.SHIFT_MASK
496                    ));
497                    m.add(cbmiLeftSidePaneVisible);
498                    
499                    cbmiLeftSidePaneVisible.addActionListener(new ActionListener() {
500                            public void
501                            actionPerformed(ActionEvent e) {
502                                    showSidePane(cbmiLeftSidePaneVisible.getState());
503                            }
504                    });
505                    
506                    b = preferences().getBoolProperty("leftSidePane.visible");
507                    cbmiLeftSidePaneVisible.setSelected(b);
508                    showSidePane(b);
509                    
510                    cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
511                            KeyEvent.VK_R, modKey | KeyEvent.SHIFT_MASK
512                    ));
513                    m.add(cbmiRightSidePaneVisible);
514                    
515                    cbmiRightSidePaneVisible.addActionListener(new ActionListener() {
516                            public void
517                            actionPerformed(ActionEvent e) {
518                                    showDevicesPane(cbmiRightSidePaneVisible.getState());
519                            }
520                    });
521                    
522                    b = preferences().getBoolProperty("rightSidePane.visible");
523                    cbmiRightSidePaneVisible.setSelected(b);
524                    showDevicesPane(b);
525                    
526                    m.addSeparator();
527                    
528                    m.add(cbmiMidiKeyboardVisible);
529                    
530                    cbmiMidiKeyboardVisible.addActionListener(new ActionListener() {
531                            public void
532                            actionPerformed(ActionEvent e) {
533                                    setMidiKeyboardVisible(cbmiMidiKeyboardVisible.getState());
534                            }
535                    });
536                    
537                    b = preferences().getBoolProperty("midiKeyboard.visible");
538                    cbmiMidiKeyboardVisible.setSelected(b);
539                    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);                  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 327  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"));
625                                    
626                    mi = new JMenuItem(a4n.browseOnlineTutorial);
627                    mi.setIcon(null);
628                    m.add(mi);
629                    
630                    m.addSeparator();
631                    
632                  mi = new JMenuItem(a4n.helpAbout);                  mi = new JMenuItem(a4n.helpAbout);
633                  mi.setIcon(null);                  mi.setIcon(null);
634                  m.add(mi);                  m.add(mi);
# Line 338  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
662            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 371  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                  // TODO:                  JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
703                            owner, Res.iconWarning32, i18n.getError("error"), err, details
704                    );
705                    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                  // TODO:                  JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
712                            owner, Res.iconWarning32, i18n.getError("error"), err, details
713                    );
714                    dlg.setVisible(true);
715            }
716            
717            /**
718             * 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.
720             */
721            @Override
722            public Server
723            getServer() {
724                    boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP);
725                    return getServer(b);
726          }          }
727                    
728          protected LSConsoleModel          /**
729             * Gets the server address to which to connect. If the server should be
730             * manually selected, a dialog asking the user to choose a server is displayed.
731             * @param manualSelect Determines whether the server should be manually selected.
732             */
733            @Override
734            public Server
735            getServer(boolean manualSelect) {
736                    if(manualSelect) {
737                            JSConnectDlg dlg = new JSConnectDlg();
738                            dlg.setVisible(true);
739                            
740                            return dlg.getSelectedServer();
741                    }
742                    
743                    int i = preferences().getIntProperty(SERVER_INDEX);
744                    int size = CC.getServerList().getServerCount();
745                    if(size == 0) return null;
746                    if(i >= size) return CC.getServerList().getServer(0);
747                    
748                    return CC.getServerList().getServer(i);
749            }
750            
751            public Timer
752            getGuiTimer() { return guiTimer; }
753            
754            @Override
755            public LSConsoleModel
756          getLSConsoleModel() { return getLSConsolePane().getModel(); }          getLSConsoleModel() { return getLSConsolePane().getModel(); }
757                    
758          protected LSConsolePane          protected LSConsolePane
# Line 392  public class MainFrame extends JSMainFra Line 763  public class MainFrame extends JSMainFra
763          protected LSConsoleFrame          protected LSConsoleFrame
764          getLSConsoleFrame() { return lsConsoleFrame; }          getLSConsoleFrame() { return lsConsoleFrame; }
765                    
766          protected void          public JSBackendLogFrame
767            getBackendLogFrame() { return backendLogFrame; }
768            
769            protected boolean
770          runScript() {          runScript() {
771                  String s = preferences().getStringProperty("lastScriptLocation");                  File f = StdUtils.showOpenLscpFileChooser();
772                  JFileChooser fc = new JFileChooser(s);                  if(f == null) return false;
773                  fc.setFileFilter(new LscpFileFilter());                  runScript(f);
774                  int result = fc.showOpenDialog(this);                  
775                  if(result != JFileChooser.APPROVE_OPTION) return;                  return true;
                   
                 String path = fc.getCurrentDirectory().getAbsolutePath();  
                 preferences().setStringProperty("lastScriptLocation", path);  
                                           
                 runScript(fc.getSelectedFile());  
776          }          }
777                    
778          private void          @Override
779            public void
780          runScript(String script) { runScript(new File(script)); }          runScript(String script) { runScript(new File(script)); }
781                    
782          private void          private void
# Line 414  public class MainFrame extends JSMainFra Line 784  public class MainFrame extends JSMainFra
784                  FileReader fr;                  FileReader fr;
785                  try { fr = new FileReader(script); }                  try { fr = new FileReader(script); }
786                  catch(FileNotFoundException e) {                  catch(FileNotFoundException e) {
787                          HF.showErrorMessage(i18n.getMessage("FileNotFound!"));                          HF.showErrorMessage(i18n.getError("fileNotFound!"));
788                          return;                          return;
789                  }                  }
790                                    
791                    String prefix = "#jsampler.fantasia: ";
792                    Vector<String> v = new Vector<String>();
793                  BufferedReader br = new BufferedReader(fr);                  BufferedReader br = new BufferedReader(fr);
794                                    
795                  try {                  try {
# Line 425  public class MainFrame extends JSMainFra Line 797  public class MainFrame extends JSMainFra
797                          while(s != null) {                          while(s != null) {
798                                  getLSConsoleModel().setCommandLineText(s);                                  getLSConsoleModel().setCommandLineText(s);
799                                  getLSConsoleModel().execCommand();                                  getLSConsoleModel().execCommand();
800                                    if(s.startsWith(prefix)) v.add(s.substring(prefix.length()));
801                                  s = br.readLine();                                  s = br.readLine();
802                          }                          }
803                  } catch(Exception e) {                  } catch(Exception e) {
# Line 437  public class MainFrame extends JSMainFra Line 810  public class MainFrame extends JSMainFra
810                  recentScripts.insertElementAt(s, 0);                  recentScripts.insertElementAt(s, 0);
811                                    
812                  updateRecentScriptsMenu();                  updateRecentScriptsMenu();
813                    
814                    CC.getViewConfig().setSessionViewConfig(
815                            new SessionViewConfig(v.toArray(new String[v.size()]))
816                    );
817          }          }
818                    
819          protected void          protected void
# Line 463  public class MainFrame extends JSMainFra Line 840  public class MainFrame extends JSMainFra
840                  recentScriptsMenu.setEnabled(recentScripts.size() != 0);                  recentScriptsMenu.setEnabled(recentScripts.size() != 0);
841          }          }
842                    
843            private void
844            showToolBar(boolean b) {
845                    preferences().setBoolProperty("toolBar.visible", b);
846                    standardBar.setVisible(b);
847            }
848            
849            private void
850            showSidePane(boolean b) {
851                    preferences().setBoolProperty("leftSidePane.visible", b);
852                    rootPane.remove(rightPane);
853                    rootPane.remove(hSplitPane);
854                    
855                    if(b) {
856                            hSplitPane.setRightComponent(rightPane);
857                            rootPane.add(hSplitPane);
858                            int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
859                            
860                            hSplitPane.setDividerLocation(i);
861                            hSplitPane.validate();
862                    } else {
863                            rootPane.add(rightPane);
864                            
865                    }
866                    
867                    int w = getPreferredSize().width;
868                    int h = getSize().height;
869                    setSize(new Dimension(w, h));
870                    
871                    rootPane.revalidate();
872                    rootPane.validate();
873                    rootPane.repaint();
874                    
875                    SwingUtilities.invokeLater(new Runnable() {
876                            public void
877                            run() { sidePanesVisibilityChanged(); }
878                    });
879            }
880            
881            private void
882            showDevicesPane(boolean b) {
883                    preferences().setBoolProperty("rightSidePane.visible", b);
884                    
885                    int width = leftSidePane.getWidth();
886                    int height = leftSidePane.getPreferredSize().height;
887                    if(width != 0) leftSidePane.setPreferredSize(new Dimension(width, height));
888                    
889                    if(b) {
890                            int w = preferences().getIntProperty("devicesPane.width", 200);
891                            
892                            int h = rightSidePane.getPreferredSize().height;
893                            rightSidePane.setPreferredSize(new Dimension(w, h));
894                    } else {
895                            int w = rightSidePane.getWidth();
896                            if(w > 0 && w < 200) w = 200;
897                            if(w != 0) preferences().setIntProperty("devicesPane.width", w);
898                    }
899                    
900                    hSplitPane.setResizeWeight(0.0);
901                    rightSidePane.setVisible(b);
902                    hSplitPane.resetToPreferredSizes();
903                    
904                    int w = getPreferredSize().width;
905                    int h = getSize().height;
906                    setSize(new Dimension(w, h));
907                    
908                    rootPane.validate();
909                    rootPane.repaint();
910                    //hSplitPane.validate();
911                    
912                    SwingUtilities.invokeLater(new Runnable() {
913                            public void
914                            run() { sidePanesVisibilityChanged(); }
915                    });
916            }
917            
918            public void
919            setMidiKeyboardVisible(boolean b) {
920                    preferences().setBoolProperty("midiKeyboard.visible", b);
921                    pianoKeyboardPane.setVisible(b);
922                    
923                    if(cbmiMidiKeyboardVisible.isSelected() != b) {
924                            cbmiMidiKeyboardVisible.setSelected(b);
925                    }
926                    
927                    if(standardBar.btnMidiKeyboard.isSelected() != b) {
928                            standardBar.btnMidiKeyboard.setSelected(b);
929                    }
930                    
931                    if(pianoKeyboardPane.btnPower.isSelected() != b) {
932                            pianoKeyboardPane.btnPower.setSelected(b);
933                    }
934                    
935                    rootPane.validate();
936                    rootPane.repaint();
937            }
938            
939            public void
940            setMidiKeyboardHeight(int height) {
941                    Dimension d = pianoKeyboardPane.getPreferredSize();
942                    d = new Dimension(d.width, height);
943                    pianoKeyboardPane.setPreferredSize(d);
944                    pianoKeyboardPane.setMinimumSize(d);
945                    pianoKeyboardPane.revalidate();
946                    pianoKeyboardPane.repaint();
947            }
948            
949            private void
950            sidePanesVisibilityChanged() {
951                    boolean leftSidePaneVisible = cbmiLeftSidePaneVisible.isSelected();
952                    boolean rightSidePaneVisible = cbmiRightSidePaneVisible.isSelected();
953                    
954                    if(leftSidePaneVisible && rightSidePaneVisible) {
955                            hSplitPane.setResizeWeight(0.5);
956                    } else if(leftSidePaneVisible && !rightSidePaneVisible) {
957                            hSplitPane.setResizeWeight(1.0);
958                    }
959                    
960                    if(!leftSidePaneVisible && !rightSidePaneVisible) {
961                            standardBar.showFantasiaLogo(false);
962                            if(isResizable()) setResizable(false);
963                    } else {
964                            standardBar.showFantasiaLogo(true);
965                            if(!isResizable()) setResizable(true);
966                    }
967            }
968            
969          private class RecentScriptHandler implements ActionListener {          private class RecentScriptHandler implements ActionListener {
970                  private String script;                  private String script;
971                                    
972                  RecentScriptHandler(String script) { this.script = script; }                  RecentScriptHandler(String script) { this.script = script; }
973                                    
974                    @Override
975                  public void                  public void
976                  actionPerformed(ActionEvent e) {                  actionPerformed(ActionEvent e) {
977                          runScript(script);                          runScript(script);
# Line 482  public class MainFrame extends JSMainFra Line 986  public class MainFrame extends JSMainFra
986                          super(s);                          super(s);
987                          setFont(getFont().deriveFont(java.awt.Font.BOLD));                          setFont(getFont().deriveFont(java.awt.Font.BOLD));
988                          setOpaque(false);                          setOpaque(false);
989                            setContentAreaFilled(false);
990                  }                  }
991          }          }
992    
993          private static class FantasiaMenuBar extends JMenuBar {          private class FantasiaMenuBar extends JMenuBar {
                 private static Insets pixmapInsets = new Insets(6, 6, 0, 6);  
                   
994                  FantasiaMenuBar() {                  FantasiaMenuBar() {
995                          setOpaque(false);                          setOpaque(false);
996                            setBorder(BorderFactory.createEmptyBorder(2, 6, 0, 0));
997                  }                  }
998                                    
999                    @Override
1000                  protected void                  protected void
1001                  paintComponent(Graphics g) {                  paintComponent(Graphics g) {
1002                          super.paintComponent(g);                          //super.paintComponent(g);
1003                            Graphics2D g2 = (Graphics2D)g;
1004                            
1005                            Paint oldPaint = g2.getPaint();
1006                            Composite oldComposite = g2.getComposite();
1007                            
1008                            double h = getSize().getHeight();
1009                            double w = getSize().getWidth();
1010                            
1011                            FantasiaPainter.paintGradient(g2, 0.0, 0.0, w - 1, h - 1, FantasiaPainter.color6, FantasiaPainter.color5);
1012                            
1013                            FantasiaPainter.Border b;
1014                            
1015                            
1016                            if(standardBar.isVisible()) {
1017                                    b = new FantasiaPainter.Border(true, true, false, true);
1018                                    FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h + 1, b);
1019                            } else {
1020                                    b = new FantasiaPainter.Border(true, true, true, true);
1021                                    FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h - 1, b);
1022                            }
1023                            
1024                            g2.setPaint(oldPaint);
1025                            g2.setComposite(oldComposite);
1026                    }
1027            }
1028            
1029            class RootPane extends FantasiaSubPanel {
1030                    private final Color color1 = new Color(0x454545);
1031                    private final Color color2 = new Color(0x2e2e2e);
1032                    
1033                    RootPane() {
1034                            setLayout(new BorderLayout());
1035                            setBorder(BorderFactory.createEmptyBorder(9, 10, 6, 10));
1036                            setOpaque(false);
1037                    
1038                    }
1039            
1040                    @Override
1041                    public void
1042                    paintComponent(Graphics g) {
1043                            Graphics2D g2 = (Graphics2D)g;
1044                            
1045                            Paint oldPaint = g2.getPaint();
1046                            Composite oldComposite = g2.getComposite();
1047                            
1048                            double h = getSize().getHeight();
1049                            double w = getSize().getWidth();
1050                            
1051                            FantasiaPainter.paintBorder(g2, 0, -3, w - 1, h - 1, 6, false);
1052                            paintComponent(g2, 5, 1, w - 10, h - 6, color1, color2);
1053                            
1054                            g2.setPaint(oldPaint);
1055                            g2.setComposite(oldComposite);
1056                    }
1057            }
1058            
1059            class BottomPane extends FantasiaPanel {
1060                    BottomPane() {
1061                            setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
1062                            setOpaque(false);
1063                            add(pianoKeyboardPane);
1064                                                    
                         PixmapPane.paintComponent(this, g, Res.gfxMenuBarBg, pixmapInsets);  
1065                  }                  }
1066          }          }
1067  }  }

Legend:
Removed from v.1318  
changed lines
  Added in v.1883

  ViewVC Help
Powered by ViewVC