/[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 1143 by iliev, Mon Apr 2 21:18:31 2007 UTC revision 1865 by iliev, Sun Mar 15 14:33:48 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-2006 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;
29  import java.awt.Dimension;  import java.awt.Dimension;
30  import java.awt.Point;  import java.awt.Frame;
31    import java.awt.Graphics;
32    import java.awt.Graphics2D;
33    import java.awt.GridBagConstraints;
34    import java.awt.GridBagLayout;
35    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.MouseAdapter;  import java.awt.event.KeyEvent;
 import java.awt.event.MouseEvent;  
42    
43  import java.util.logging.Level;  import java.beans.PropertyChangeEvent;
44    import java.beans.PropertyChangeListener;
45    
46  import javax.swing.Box;  import java.io.BufferedReader;
47    import java.io.File;
48    import java.io.FileNotFoundException;
49    import java.io.FileReader;
50    
51    import java.util.Vector;
52    
53    import javax.swing.BorderFactory;
54  import javax.swing.BoxLayout;  import javax.swing.BoxLayout;
55  import javax.swing.JCheckBoxMenuItem;  import javax.swing.JCheckBoxMenuItem;
56    import javax.swing.JFileChooser;
57  import javax.swing.JMenu;  import javax.swing.JMenu;
58    import javax.swing.JMenuBar;
59  import javax.swing.JMenuItem;  import javax.swing.JMenuItem;
60  import javax.swing.JPanel;  import javax.swing.JPanel;
61  import javax.swing.JPopupMenu;  import javax.swing.JSplitPane;
62  import javax.swing.JToggleButton;  import javax.swing.KeyStroke;
63  import javax.swing.UIManager;  import javax.swing.SwingUtilities;
64  import javax.swing.plaf.synth.SynthLookAndFeel;  import javax.swing.Timer;
65    
66  import net.sf.juife.TitleBar;  import javax.swing.event.ListSelectionEvent;
67    import javax.swing.event.ListSelectionListener;
68    
69  import org.jsampler.CC;  import org.jsampler.CC;
70  import org.jsampler.HF;  import org.jsampler.HF;
71    import org.jsampler.LSConsoleModel;
72    import org.jsampler.Server;
73    
 import org.jsampler.view.JSChannel;  
74  import org.jsampler.view.JSChannelsPane;  import org.jsampler.view.JSChannelsPane;
75  import org.jsampler.view.JSMainFrame;  import org.jsampler.view.LscpFileFilter;
76    import org.jsampler.view.SessionViewConfig;
77    
78    import org.jsampler.view.fantasia.basic.FantasiaPainter;
79    import org.jsampler.view.fantasia.basic.FantasiaPanel;
80    import org.jsampler.view.fantasia.basic.FantasiaSubPanel;
81    
82    import org.jsampler.view.std.JSBackendLogFrame;
83    import org.jsampler.view.std.JSConnectDlg;
84    import org.jsampler.view.std.JSDetailedErrorDlg;
85    import org.jsampler.view.std.JSQuitDlg;
86    import org.jsampler.view.std.JSamplerHomeChooser;
87    import org.jsampler.view.std.StdMainFrame;
88    import org.jsampler.view.std.StdUtils;
89    
90    import static org.jsampler.view.fantasia.A4n.a4n;
91  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
92    import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
93    import static org.jsampler.view.std.StdPrefs.*;
94    
95    
96  /**  /**
97   *   *
98   * @author Grigor Iliev   * @author Grigor Iliev
99   */   */
100  public class MainFrame extends JSMainFrame {  public class MainFrame extends StdMainFrame {
101          private final static int TITLE_BAR_WIDTH = 420;          private final StandardBar standardBar = new StandardBar();
102          private final static int TITLE_BAR_HEIGHT = 29;          private final FantasiaMenuBar menuBar = new FantasiaMenuBar();
103            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 =
109                    new JMenu(i18n.getMenuLabel("actions.recentScripts"));
110            
111            private final JSplitPane hSplitPane;
112            
113            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();
120            private final Vector<String> recentScripts = new Vector<String>();
121            
122            private final JSBackendLogFrame backendLogFrame = new JSBackendLogFrame();
123                    
124                    
125          private final ChannelsPane channelsPane = new ChannelsPane("");          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                  try {                  setTitle(i18n.getLabel("MainFrame.title"));
143                          SynthLookAndFeel synth = new SynthLookAndFeel();                  //setUndecorated(true);
144                          synth.load(MainFrame.class.getResourceAsStream("gui.xml"), MainFrame.class);                  if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage());
145                          UIManager.setLookAndFeel(synth);                  
146                  } catch(Exception e) {                  CC.setMainFrame(this); // TODO:
147                          CC.getLogger().log(Level.INFO, HF.getErrorMessage(e), e);                  mainPane = new MainPane();
148                    leftSidePane = new LeftSidePane();
149                    rightSidePane = new RightSidePane();
150                    
151                    setSelectedChannelsPane(mainPane.getChannelsPane(0));
152                    
153                    getContentPane().add(standardBar, BorderLayout.NORTH);
154                    
155                    rightPane = createRightPane();
156                    
157                    hSplitPane = new JSplitPane (
158                            JSplitPane.HORIZONTAL_SPLIT,
159                            true,   // continuousLayout
160                            leftSidePane, rightPane
161                    );
162                    hSplitPane.setResizeWeight(0.5);
163                    
164                    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                  setTitle(i18n.getLabel("MainFrame.title"));                  
172                  addChannelsPane(channelsPane);                  int h = preferences().getIntProperty("midiKeyboard.height");
173                  add(channelsPane);                  setMidiKeyboardHeight(h);
174                  setUndecorated(true);                  
175                                    PropertyChangeListener l = new PropertyChangeListener() {
176                  JToggleButton btn = new PixmapToggleButton(Res.iconPowerOff, Res.iconPowerOn) {                          public void
177                          public boolean                          propertyChange(PropertyChangeEvent e) {
178                          contains(int x, int y) {                                  int h = preferences().getIntProperty("midiKeyboard.height");
179                                  return (x - 11)*(x - 11) + (y - 11)*(y - 11) < 71;                                  setMidiKeyboardHeight(h);
180                          }                          }
181                  };                  };
182                                    
183                  btn.setSelected(true);                  CC.preferences().addPropertyChangeListener("midiKeyboard.height", l);
184                  btn.setAlignmentX(JPanel.LEFT_ALIGNMENT);                  
185                  btn.addActionListener(new ActionListener() {                  bottomPane = new BottomPane();
186                    
187                    hSplitPane.setOpaque(false);
188                    rootPane.add(hSplitPane);
189                    rootPane.add(bottomPane, BorderLayout.SOUTH);
190                    add(rootPane);
191    
192                    if(CC.isMacOS()) {
193                            try { new MacOSApplicationHandler(); }
194                            catch(Throwable e) { }
195                    }
196                    
197                    addMenu();
198                    
199                    if(CC.getViewConfig().isUsingScreenMenuBar()) {
200                            // fix for moving the menu bar on top of the screen
201                            // when running on Mac OS and third party plugin is used
202                            ((ViewConfig)CC.getViewConfig()).restoreMenuProperties();
203                    }
204                    
205                    int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
206                    hSplitPane.setDividerLocation(i);
207                    
208                    setSavedSize();
209                    
210                    guiTimer.start();
211            }
212            
213            private JPanel
214            createRightPane() {
215                    JPanel p = new FantasiaPanel();
216                    p.setOpaque(false);
217                    
218                    GridBagLayout gridbag = new GridBagLayout();
219                    GridBagConstraints c = new GridBagConstraints();
220                    
221                    p.setLayout(gridbag);
222                    
223                    c.fill = GridBagConstraints.BOTH;
224                    
225                    c.gridx = 1;
226                    c.gridy = 0;
227                    c.weightx = 1.0;
228                    c.weighty = 1.0;
229                    c.insets = new Insets(0, 3, 0, 0);
230                    gridbag.setConstraints(rightSidePane, c);
231                    p.add(rightSidePane);
232                    
233                    c.gridx = 0;
234                    c.gridy = 0;
235                    c.weightx = 0.0;
236                    c.weighty = 1.0;
237                    c.insets = new Insets(0, 0, 0, 3);
238                    c.fill = GridBagConstraints.VERTICAL;
239                    gridbag.setConstraints(mainPane, c);
240                    p.add(mainPane);
241                    
242                    return p;
243            }
244            
245            private void
246            setSavedSize() {
247                    Rectangle r = StdUtils.getWindowBounds("MainFrame");
248                    if(r == null) {
249                            setDefaultSizeAndLocation();
250                            return;
251                    }
252                    
253                    setBounds(r);
254            }
255            
256            private void
257            setDefaultSizeAndLocation() {
258                    setPreferredSize(new Dimension(900, 600));
259                    pack();
260                    setLocationRelativeTo(null);
261            }
262            
263            
264            /** Invoked when this window is about to close. */
265            @Override
266            public void
267            onWindowClose() {
268                    boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT);
269                    if(b && CC.getSamplerModel().isModified()) {
270                            JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32);
271                            dlg.setVisible(true);
272                            if(dlg.isCancelled()) return;
273                    }
274                    
275                    leftSidePane.savePreferences();
276                    rightSidePane.savePreferences();
277                    
278                    int i = hSplitPane.getDividerLocation();
279                    preferences().setIntProperty("MainFrame.hSplitDividerLocation", i);
280                    
281                    preferences().setBoolProperty (
282                            "MainFrame.windowMaximized",
283                            (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH
284                    );
285                    
286                    if(preferences().getBoolProperty("MainFrame.windowMaximized")) {
287                            super.onWindowClose();
288                            return;
289                    }
290                    
291                    StdUtils.saveWindowBounds("MainFrame", getBounds());
292                    
293                    String[] list = recentScripts.toArray(new String[recentScripts.size()]);
294                    preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list);
295                    
296                    if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) {
297                            if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory();
298                    }
299                    
300                    if(getBackendLogFrame() != null) getBackendLogFrame().stopTimer();
301                    if(getLSConsolePane() != null) getLSConsolePane().disconnect();
302                    
303                    super.onWindowClose();
304            }
305            
306            @Override
307            public void
308            setVisible(boolean b) {
309                    if(b == isVisible()) return;
310                    
311                    super.setVisible(b);
312                    
313                    if(b && preferences().getBoolProperty("MainFrame.windowMaximized")) {
314                            setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
315                    }
316            }
317            
318            private void
319            addMenu() {
320                    JMenu m;
321                    JMenuItem mi;
322                    
323                    setJMenuBar(menuBar);
324                    
325                    // Actions
326                    m = new FantasiaMenu(i18n.getMenuLabel("actions"));
327                    
328                    mi = new JMenuItem(a4n.refresh);
329                    mi.setIcon(null);
330                    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
331                    m.add(mi);
332                    
333                    mi = new JMenuItem(a4n.samplerInfo);
334                    mi.setIcon(null);
335                    m.add(mi);
336                    
337                    mi = new JMenuItem(a4n.resetSampler);
338                    mi.setIcon(null);
339                    m.add(mi);
340                    
341                    m.addSeparator();
342                    
343                    JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export"));
344                    m.add(exportMenu);
345    
346                    int modKey = CC.getViewConfig().getDefaultModKey();
347                    
348                    mi = new JMenuItem(a4n.exportSamplerConfig);
349                    mi.setIcon(null);
350                    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, modKey));
351                    exportMenu.add(mi);
352                    
353                    mi = new JMenuItem(a4n.exportMidiInstrumentMaps);
354                    mi.setIcon(null);
355                    exportMenu.add(mi);
356                    
357                    m.addSeparator();
358                    
359                    mi = new JMenuItem(a4n.loadScript);
360                    mi.setIcon(null);
361                    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, modKey));
362                    m.add(mi);
363                    
364                    String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS);
365                    for(String s : list) recentScripts.add(s);
366                    
367                    updateRecentScriptsMenu();
368                    
369                    m.add(recentScriptsMenu);
370                    
371                    m.addSeparator();
372                    
373                    mi = new JMenuItem(a4n.changeBackend);
374                    mi.setIcon(null);
375                    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, modKey));
376                    m.add(mi);
377                    
378                    m.addSeparator();
379                    
380                    mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));
381                    m.add(mi);
382                    mi.addActionListener(new ActionListener() {
383                          public void                          public void
384                          actionPerformed(ActionEvent e) { onWindowClose(); }                          actionPerformed(ActionEvent e) { onWindowClose(); }
385                  });                  });
386                                    
387                    menuBar.add(m);
388                                    
                 FantasiaTitleBar tb = new FantasiaTitleBar();  
                 tb.setName("FantasiaTitleBar");  
                 tb.setLayout(new BoxLayout(tb, BoxLayout.X_AXIS));  
                 tb.setOpaque(true);  
                 tb.add(Box.createRigidArea(new Dimension(4, 0)));  
                 tb.add(btn);  
                 tb.add(Box.createRigidArea(new Dimension(3, 0)));  
389                                    
390                    // Edit
391                    m = new FantasiaMenu(i18n.getMenuLabel("edit"));
392                    menuBar.add(m);
393                                    
394                    mi = new JMenuItem(i18n.getMenuLabel("edit.addChannel"));
395                    m.add(mi);
396                    mi.addActionListener(new ActionListener() {
397                            public void
398                            actionPerformed(ActionEvent e) {
399                                    CC.getSamplerModel().addBackendChannel();
400                            }
401                    });
402                                    
403                  tb.add(createVSeparator());                  m.addSeparator();
404                                    
405                  tb.add(Box.createRigidArea(new Dimension(275, 0)));                  mi = new JMenuItem(a4n.createMidiDevice);
406                    mi.setIcon(null);
407                    m.add(mi);
408                                    
409                  tb.add(createVSeparator());                  mi = new JMenuItem(a4n.createAudioDevice);
410                    mi.setIcon(null);
411                    m.add(mi);
412                                    
413                  tb.add(Box.createRigidArea(new Dimension(29, 0)));                  m.addSeparator();
414                                    
415                  tb.add(createVSeparator());                  mi = new JMenuItem(a4n.editPreferences);
416                    mi.setIcon(null);
417                    mi.setAccelerator(KeyStroke.getKeyStroke (
418                            KeyEvent.VK_P, modKey | KeyEvent.SHIFT_MASK
419                    ));
420                    m.add(mi);
421                                    
422                  tb.add(Box.createRigidArea(new Dimension(40, 0)));                  // View
423                    m = new FantasiaMenu(i18n.getMenuLabel("view"));
424                    menuBar.add(m);
425                                    
426                  tb.add(createVSeparator());                  m.add(cbmiToolBarVisible);
427                                    
428                  tb.setPreferredSize(new Dimension(TITLE_BAR_WIDTH, TITLE_BAR_HEIGHT));                  cbmiToolBarVisible.addActionListener(new ActionListener() {
429                  tb.setMinimumSize(tb.getPreferredSize());                          public void
430                  tb.setMaximumSize(tb.getPreferredSize());                          actionPerformed(ActionEvent e) {
431                  add(tb, BorderLayout.SOUTH);                                  showToolBar(cbmiToolBarVisible.getState());
432                            }
433                    });
434                                    
435                  getContentPane().setBackground(new java.awt.Color(0x818181));                  boolean b = preferences().getBoolProperty("toolBar.visible");
436                  getRootPane().setOpaque(false);                  cbmiToolBarVisible.setSelected(b);
437                  getLayeredPane().setOpaque(false);                  showToolBar(b);
438                  //getContentPane().setVisible(false);                  
439                    cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
440                            KeyEvent.VK_L, modKey | KeyEvent.SHIFT_MASK
441                    ));
442                    m.add(cbmiLeftSidePaneVisible);
443                                    
444                  setAlwaysOnTop(FantasiaPrefs.isAlwaysOnTop());                  cbmiLeftSidePaneVisible.addActionListener(new ActionListener() {
445                  pack();                          public void
446                            actionPerformed(ActionEvent e) {
447                                    showSidePane(cbmiLeftSidePaneVisible.getState());
448                            }
449                    });
450                                    
451                  String s = FantasiaPrefs.getWindowLocation();                  b = preferences().getBoolProperty("leftSidePane.visible");
452                    cbmiLeftSidePaneVisible.setSelected(b);
453                    showSidePane(b);
454                    
455                    cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
456                            KeyEvent.VK_R, modKey | KeyEvent.SHIFT_MASK
457                    ));
458                    m.add(cbmiRightSidePaneVisible);
459                                    
460                  try {                  cbmiRightSidePaneVisible.addActionListener(new ActionListener() {
461                          if(s == null) {                          public void
462                                  setDefaultLocation();                          actionPerformed(ActionEvent e) {
463                          } else {                                  showDevicesPane(cbmiRightSidePaneVisible.getState());
464                                  int i = s.indexOf(',');                          }
465                                  int x = Integer.parseInt(s.substring(0, i));                  });
466                    
467                    b = preferences().getBoolProperty("rightSidePane.visible");
468                    cbmiRightSidePaneVisible.setSelected(b);
469                    showDevicesPane(b);
470                    
471                    m.addSeparator();
472                    
473                    m.add(cbmiMidiKeyboardVisible);
474                    
475                    cbmiMidiKeyboardVisible.addActionListener(new ActionListener() {
476                            public void
477                            actionPerformed(ActionEvent e) {
478                                    setMidiKeyboardVisible(cbmiMidiKeyboardVisible.getState());
479                            }
480                    });
481                    
482                    b = preferences().getBoolProperty("midiKeyboard.visible");
483                    cbmiMidiKeyboardVisible.setSelected(b);
484                    setMidiKeyboardVisible(b);
485                    
486                    
487                    // Channels
488                    m = new FantasiaMenu(i18n.getMenuLabel("channels"));
489                    
490                    mi = new JMenuItem(i18n.getMenuLabel("channels.newChannel"));
491                    mi.addActionListener(new ActionListener() {
492                            public void
493                            actionPerformed(ActionEvent e) {
494                                    CC.getSamplerModel().addBackendChannel();
495                            }
496                    });
497                    m.add(mi);
498                    
499                    m.addSeparator();
500                    
501                    MenuManager.ChannelViewGroup group = new MenuManager.ChannelViewGroup();
502                    MenuManager.getMenuManager().registerChannelViewGroup(group);
503                    
504                    for(JMenuItem menuItem : group.getMenuItems()) m.add(menuItem);
505                    
506                    m.addSeparator();
507                    
508                    m.add(new JMenuItem(a4n.moveChannelsOnTop));
509                    m.add(new JMenuItem(a4n.moveChannelsUp));
510                    m.add(new JMenuItem(a4n.moveChannelsDown));
511                    m.add(new JMenuItem(a4n.moveChannelsAtBottom));
512                    
513                    m.add(new ToPanelMenu());
514                    
515                    m.addSeparator();
516                    
517                    mi = new JMenuItem(a4n.selectAllChannels);
518                    mi.setIcon(null);
519                    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, modKey));
520                    m.add(mi);
521                    
522                    mi = new JMenuItem(a4n.deselectChannels);
523                    mi.setIcon(null);
524                    mi.setAccelerator(KeyStroke.getKeyStroke (
525                            KeyEvent.VK_A, modKey | KeyEvent.SHIFT_MASK
526                    ));
527                    m.add(mi);
528                    
529                    menuBar.add(m);
530                    
531                    // Window
532                    m = new FantasiaMenu(i18n.getMenuLabel("window"));
533                    menuBar.add(m);
534                    
535                    mi = new JMenuItem(a4n.windowLSConsole);
536                    mi.setIcon(null);
537                    m.add(mi);
538                    
539                    mi = new JMenuItem(a4n.windowInstrumentsDb);
540                    mi.setIcon(null);
541                    m.add(mi);
542                    
543                    m.addSeparator();
544                    
545                    final JMenuItem mi2 = new JMenuItem(i18n.getMenuLabel("window.backendLog"));
546                    m.add(mi2);
547                    mi2.addActionListener(new ActionListener() {
548                            public void
549                            actionPerformed(ActionEvent e) {
550                                    if(getBackendLogFrame().isVisible()) {
551                                            getBackendLogFrame().setVisible(false);
552                                    }
553                                    
554                                    getBackendLogFrame().setVisible(true);
555                            }
556                    });
557                    
558                    mi2.setEnabled(CC.getBackendProcess() != null);
559                    
560                    CC.addBackendProcessListener(new ActionListener() {
561                            public void
562                            actionPerformed(ActionEvent e) {
563                                    mi2.setEnabled(CC.getBackendProcess() != null);
564                            }
565                    });
566                    
567                    
568                    // Help
569                    m = new FantasiaMenu(i18n.getMenuLabel("help"));
570                    
571                    mi = new JMenuItem(a4n.browseOnlineTutorial);
572                    mi.setIcon(null);
573                    m.add(mi);
574                    
575                    m.addSeparator();
576                    
577                    mi = new JMenuItem(a4n.helpAbout);
578                    mi.setIcon(null);
579                    m.add(mi);
580                    
581                    menuBar.add(m);
582            }
583            
584            public static class ToPanelMenu extends FantasiaMenu implements ListSelectionListener {
585                    public
586                    ToPanelMenu() {
587                            super(i18n.getMenuLabel("channels.toPanel"));
588                            setEnabled(CC.getMainFrame().getSelectedChannelsPane().hasSelectedChannel());
589                                                    
590                                  s = s.substring(i + 1);                          CC.getMainFrame().addChannelsPaneSelectionListener(this);
                                 int y = Integer.parseInt(s);  
591                                                    
592                                  setLocation(x, y);                          for(int i = 0; i < CC.getMainFrame().getChannelsPaneCount(); i++) {
593                                    JSChannelsPane p = CC.getMainFrame().getChannelsPane(i);
594                                    add(new JMenuItem(new A4n.MoveChannelsToPanel(p)));
595                                    p.addListSelectionListener(this);
596                          }                          }
597                  } catch(Exception x) {                  }
598                          String msg = "Parsing of window size and location string failed";                  
599                          CC.getLogger().log(Level.INFO, msg, x);                  @Override
600                          setDefaultLocation();                  public void
601                    valueChanged(ListSelectionEvent e) {
602                            setEnabled(CC.getMainFrame().getSelectedChannelsPane().hasSelectedChannel());
603                  }                  }
604          }          }
605                    
606          private void          public RightSidePane
607          setDefaultLocation() {          getRightSidePane() { return rightSidePane; }
                 Dimension d = java.awt.Toolkit.getDefaultToolkit().getScreenSize();  
                 setLocation((d.width - TITLE_BAR_WIDTH) / 2, (d.height - TITLE_BAR_HEIGHT) / 2);  
         }  
608                    
609            @Override
610            public A4n
611            getA4n() { return A4n.a4n; }
612                    
613          /** Invoked when this window is about to close. */          /**
614          protected void           * This method does nothing, because <b>Fantasia</b> has constant
615          onWindowClose() {           * number of panes containing sampler channels, which can not be changed.
616                  FantasiaPrefs.setAlwaysOnTop(isAlwaysOnTop());           */
617            @Override
618            public void
619            insertChannelsPane(JSChannelsPane pane, int idx) {
620                                    
621                  java.awt.Point p = getLocation();          }
622                  Dimension d = getSize();          
623                  StringBuffer sb = new StringBuffer();          @Override
624                  sb.append(p.x).append(',').append(p.y + getSize().height - TITLE_BAR_HEIGHT);          public JSChannelsPane
625                  FantasiaPrefs.setWindowLocation(sb.toString());          getSelectedChannelsPane() { return mainPane.getSelectedChannelsPane(); }
626            
627            @Override
628            public void
629            setSelectedChannelsPane(JSChannelsPane pane) {
630                    mainPane.setSelectedChannelsPane(pane);
631                    fireChannelsPaneSelectionChanged();
632            }
633            
634            @Override
635            public void
636            installJSamplerHome() {
637                    JSamplerHomeChooser chooser = new JSamplerHomeChooser(this);
638                    chooser.setVisible(true);
639                    if(chooser.isCancelled()) return;
640                                    
641                  super.onWindowClose();                  CC.changeJSamplerHome(chooser.getJSamplerHome());
642          }          }
643                    
644          private JPanel          @Override
645          createVSeparator() {          public void
646                  JPanel p = new JPanel();          showDetailedErrorMessage(Frame owner, String err, String details) {
647                  p.setName("VSeparator");                  JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
648                  p.setOpaque(false);                          owner, Res.iconWarning32, i18n.getError("error"), err, details
649                  p.setPreferredSize(new Dimension(2, 29));                  );
650                  p.setMinimumSize(p.getPreferredSize());                  dlg.setVisible(true);
                 p.setMaximumSize(p.getPreferredSize());  
                 return p;  
651          }          }
652                    
653          /**          @Override
          * This method does nothing, because <b>Fantasia</b> has exactly  
          * one pane containing sampler channels, which can not be changed.  
          */  
654          public void          public void
655          insertChannelsPane(JSChannelsPane pane, int idx) {          showDetailedErrorMessage(Dialog owner, String err, String details) {
656                  getChannelsPaneList().removeAllElements();                  JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
657                  addChannelsPane(pane);                          owner, Res.iconWarning32, i18n.getError("error"), err, details
658                    );
659                    dlg.setVisible(true);
660          }          }
661                    
662          /**          /**
663           * This method always returns the <code>JSChannelsPane</code> at index 0,           * Gets the server address to which to connect. If the server should be
664           * because the <b>Fantasia</b> view has exactly one pane containing sampler channels.           * manually selected, a dialog asking the user to choose a server is displayed.
          * @return The <code>JSChannelsPane</code> at index 0.  
665           */           */
666          public JSChannelsPane          @Override
667          getSelectedChannelsPane() { return getChannelsPane(0); }          public Server
668            getServer() {
669                    boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP);
670                    return getServer(b);
671            }
672                    
673          /**          /**
674           * This method does nothing because the <b>Fantasia</b> view has           * Gets the server address to which to connect. If the server should be
675           * exactly one pane containing sampler channels which is always shown.           * manually selected, a dialog asking the user to choose a server is displayed.
676             * @param manualSelect Determines whether the server should be manually selected.
677           */           */
678            @Override
679            public Server
680            getServer(boolean manualSelect) {
681                    if(manualSelect) {
682                            JSConnectDlg dlg = new JSConnectDlg();
683                            dlg.setVisible(true);
684                            
685                            return dlg.getSelectedServer();
686                    }
687                    
688                    int i = preferences().getIntProperty(SERVER_INDEX);
689                    int size = CC.getServerList().getServerCount();
690                    if(size == 0) return null;
691                    if(i >= size) return CC.getServerList().getServer(0);
692                    
693                    return CC.getServerList().getServer(i);
694            }
695            
696            public Timer
697            getGuiTimer() { return guiTimer; }
698            
699            protected LSConsoleModel
700            getLSConsoleModel() { return getLSConsolePane().getModel(); }
701            
702            protected LSConsolePane
703            getLSConsolePane() {
704                    return getLSConsoleFrame().getLSConsolePane();
705            }
706            
707            protected LSConsoleFrame
708            getLSConsoleFrame() { return lsConsoleFrame; }
709            
710            public JSBackendLogFrame
711            getBackendLogFrame() { return backendLogFrame; }
712            
713            protected boolean
714            runScript() {
715                    String s = preferences().getStringProperty("lastScriptLocation");
716                    JFileChooser fc = new JFileChooser(s);
717                    fc.setFileFilter(new LscpFileFilter());
718                    int result = fc.showOpenDialog(this);
719                    if(result != JFileChooser.APPROVE_OPTION) return false;
720                    
721                    String path = fc.getCurrentDirectory().getAbsolutePath();
722                    preferences().setStringProperty("lastScriptLocation", path);
723                                            
724                    runScript(fc.getSelectedFile());
725                    
726                    return true;
727            }
728            
729            @Override
730          public void          public void
731          setSelectedChannelsPane(JSChannelsPane pane) { }          runScript(String script) { runScript(new File(script)); }
732            
733            private void
734            runScript(File script) {
735                    FileReader fr;
736                    try { fr = new FileReader(script); }
737                    catch(FileNotFoundException e) {
738                            HF.showErrorMessage(i18n.getMessage("FileNotFound!"));
739                            return;
740                    }
741                    
742                    String prefix = "#jsampler.fantasia: ";
743                    Vector<String> v = new Vector<String>();
744                    BufferedReader br = new BufferedReader(fr);
745                    
746                    try {
747                            String s = br.readLine();
748                            while(s != null) {
749                                    getLSConsoleModel().setCommandLineText(s);
750                                    getLSConsoleModel().execCommand();
751                                    if(s.startsWith(prefix)) v.add(s.substring(prefix.length()));
752                                    s = br.readLine();
753                            }
754                    } catch(Exception e) {
755                            HF.showErrorMessage(e);
756                            return;
757                    }
758                    
759                    String s = script.getAbsolutePath();
760                    recentScripts.remove(s);
761                    recentScripts.insertElementAt(s, 0);
762                    
763                    updateRecentScriptsMenu();
764                    
765                    CC.getViewConfig().setSessionViewConfig(
766                            new SessionViewConfig(v.toArray(new String[v.size()]))
767                    );
768            }
769                    
770          public static void          protected void
771          repack(JSMainFrame frame) {          clearRecentScripts() {
772                  int y = frame.getLocation().y;                  recentScripts.removeAllElements();
773                  int height = frame.getSize().height;                  updateRecentScriptsMenu();
774                  y += (height - frame.getPreferredSize().height);          }
775                            
776                  if((height - frame.getPreferredSize().height) > 0) {          protected void
777                          frame.pack();          updateRecentScriptsMenu() {
778                          frame.setLocation(frame.getLocation().x, y);                  int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE);
779                    while(recentScripts.size() > size) {
780                            recentScripts.removeElementAt(recentScripts.size() - 1);
781                    }
782                    
783                    recentScriptsMenu.removeAll();
784                    
785                    for(String script : recentScripts) {
786                            JMenuItem mi = new JMenuItem(script);
787                            recentScriptsMenu.add(mi);
788                            mi.addActionListener(new RecentScriptHandler(script));
789                    }
790                    
791                    recentScriptsMenu.setEnabled(recentScripts.size() != 0);
792            }
793            
794            private void
795            showToolBar(boolean b) {
796                    preferences().setBoolProperty("toolBar.visible", b);
797                    standardBar.setVisible(b);
798            }
799            
800            private void
801            showSidePane(boolean b) {
802                    preferences().setBoolProperty("leftSidePane.visible", b);
803                    rootPane.remove(rightPane);
804                    rootPane.remove(hSplitPane);
805                    
806                    if(b) {
807                            hSplitPane.setRightComponent(rightPane);
808                            rootPane.add(hSplitPane);
809                            int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
810                            
811                            hSplitPane.setDividerLocation(i);
812                            hSplitPane.validate();
813                  } else {                  } else {
814                          frame.setLocation(frame.getLocation().x, y);                          rootPane.add(rightPane);
815                          frame.pack();                          
816                  }                  }
817                    
818                    int w = getPreferredSize().width;
819                    int h = getSize().height;
820                    setSize(new Dimension(w, h));
821                    
822                    rootPane.revalidate();
823                    rootPane.validate();
824                    rootPane.repaint();
825                    
826                    SwingUtilities.invokeLater(new Runnable() {
827                            public void
828                            run() { sidePanesVisibilityChanged(); }
829                    });
830            }
831            
832            private void
833            showDevicesPane(boolean b) {
834                    preferences().setBoolProperty("rightSidePane.visible", b);
835                    
836                    int width = leftSidePane.getWidth();
837                    int height = leftSidePane.getPreferredSize().height;
838                    if(width != 0) leftSidePane.setPreferredSize(new Dimension(width, height));
839                    
840                    if(b) {
841                            int w = preferences().getIntProperty("devicesPane.width", 200);
842                            
843                            int h = rightSidePane.getPreferredSize().height;
844                            rightSidePane.setPreferredSize(new Dimension(w, h));
845                    } else {
846                            int w = rightSidePane.getWidth();
847                            if(w > 0 && w < 200) w = 200;
848                            if(w != 0) preferences().setIntProperty("devicesPane.width", w);
849                    }
850                    
851                    hSplitPane.setResizeWeight(0.0);
852                    rightSidePane.setVisible(b);
853                    hSplitPane.resetToPreferredSizes();
854                    
855                    int w = getPreferredSize().width;
856                    int h = getSize().height;
857                    setSize(new Dimension(w, h));
858                    
859                    rootPane.validate();
860                    rootPane.repaint();
861                    //hSplitPane.validate();
862                    
863                    SwingUtilities.invokeLater(new Runnable() {
864                            public void
865                            run() { sidePanesVisibilityChanged(); }
866                    });
867          }          }
868                    
869          public void          public void
870          installJSamplerHome() { }          setMidiKeyboardVisible(boolean b) {
871  }                  preferences().setBoolProperty("midiKeyboard.visible", b);
872                    pianoKeyboardPane.setVisible(b);
873  class FantasiaTitleBar extends TitleBar {                  
874          FantasiaTitleBar() { this.addMouseListener(new ContextMenu()); }                  if(cbmiMidiKeyboardVisible.isSelected() != b) {
875                            cbmiMidiKeyboardVisible.setSelected(b);
876                    }
877                    
878                    if(standardBar.btnMidiKeyboard.isSelected() != b) {
879                            standardBar.btnMidiKeyboard.setSelected(b);
880                    }
881                    
882                    if(pianoKeyboardPane.btnPower.isSelected() != b) {
883                            pianoKeyboardPane.btnPower.setSelected(b);
884                    }
885                    
886                    rootPane.validate();
887                    rootPane.repaint();
888            }
889                    
890          class ContextMenu extends MouseAdapter {          public void
891                  private final JPopupMenu cmenu = new JPopupMenu();          setMidiKeyboardHeight(int height) {
892                    Dimension d = pianoKeyboardPane.getPreferredSize();
893                    d = new Dimension(d.width, height);
894                    pianoKeyboardPane.setPreferredSize(d);
895                    pianoKeyboardPane.setMinimumSize(d);
896                    pianoKeyboardPane.revalidate();
897                    pianoKeyboardPane.repaint();
898            }
899            
900            private void
901            sidePanesVisibilityChanged() {
902                    boolean leftSidePaneVisible = cbmiLeftSidePaneVisible.isSelected();
903                    boolean rightSidePaneVisible = cbmiRightSidePaneVisible.isSelected();
904                    
905                    if(leftSidePaneVisible && rightSidePaneVisible) {
906                            hSplitPane.setResizeWeight(0.5);
907                    } else if(leftSidePaneVisible && !rightSidePaneVisible) {
908                            hSplitPane.setResizeWeight(1.0);
909                    }
910                                    
911                  ContextMenu() {                  if(!leftSidePaneVisible && !rightSidePaneVisible) {
912                          JMenuItem mi;                          standardBar.showFantasiaLogo(false);
913                            if(isResizable()) setResizable(false);
914                    } else {
915                            standardBar.showFantasiaLogo(true);
916                            if(!isResizable()) setResizable(true);
917                    }
918            }
919            
920            private class RecentScriptHandler implements ActionListener {
921                    private String script;
922                    
923                    RecentScriptHandler(String script) { this.script = script; }
924                    
925                    @Override
926                    public void
927                    actionPerformed(ActionEvent e) {
928                            runScript(script);
929                            if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) {
930                                    a4n.windowLSConsole.actionPerformed(null);
931                            }
932                    }
933            }
934            
935            private static class FantasiaMenu extends JMenu {
936                    FantasiaMenu(String s) {
937                            super(s);
938                            setFont(getFont().deriveFont(java.awt.Font.BOLD));
939                            setOpaque(false);
940                            setContentAreaFilled(false);
941                    }
942            }
943    
944            private class FantasiaMenuBar extends JMenuBar {
945                    FantasiaMenuBar() {
946                            setOpaque(false);
947                            setBorder(BorderFactory.createEmptyBorder(2, 6, 0, 0));
948                    }
949                    
950                    @Override
951                    protected void
952                    paintComponent(Graphics g) {
953                            //super.paintComponent(g);
954                            Graphics2D g2 = (Graphics2D)g;
955                                                    
956                          final JCheckBoxMenuItem cmi = new JCheckBoxMenuItem (                          Paint oldPaint = g2.getPaint();
957                                  i18n.getMenuLabel("FantasiaTitleBar.AlwaysOnTop")                          Composite oldComposite = g2.getComposite();
958                          );                          
959                          cmi.setIcon(null);                          double h = getSize().getHeight();
960                          cmi.setSelected(FantasiaPrefs.isAlwaysOnTop());                          double w = getSize().getWidth();
                           
                         cmenu.add(cmi);  
                           
                         cmi.addActionListener(new ActionListener() {  
                                 public void  
                                 actionPerformed(ActionEvent e) {  
                                         CC.getMainFrame().setAlwaysOnTop(cmi.isSelected());  
                                 }  
                         });  
961                                                    
962                          /*mi = new JMenuItem(A4n.moveChannelsUp);                          FantasiaPainter.paintGradient(g2, 0.0, 0.0, w - 1, h - 1, FantasiaPainter.color6, FantasiaPainter.color5);
                         mi.setIcon(null);  
                         cmenu.add(mi);  
963                                                    
964                          cmenu.addSeparator();                          FantasiaPainter.Border b;
965                            
966                            
967                            if(standardBar.isVisible()) {
968                                    b = new FantasiaPainter.Border(true, true, false, true);
969                                    FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h + 1, b);
970                            } else {
971                                    b = new FantasiaPainter.Border(true, true, true, true);
972                                    FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h - 1, b);
973                            }
974                                                    
975                          mi = new JMenuItem(A4n.removeChannels);                          g2.setPaint(oldPaint);
976                          mi.setIcon(null);                          g2.setComposite(oldComposite);
                         cmenu.add(mi);*/  
977                  }                  }
978            }
979            
980            class RootPane extends FantasiaSubPanel {
981                    private final Color color1 = new Color(0x454545);
982                    private final Color color2 = new Color(0x2e2e2e);
983                    
984                    RootPane() {
985                            setLayout(new BorderLayout());
986                            setBorder(BorderFactory.createEmptyBorder(9, 10, 6, 10));
987                            setOpaque(false);
988                                    
                 public void  
                 mousePressed(MouseEvent e) {  
                         if(e.isPopupTrigger()) show(e);  
989                  }                  }
990                    
991                    @Override
992                  public void                  public void
993                  mouseReleased(MouseEvent e) {                  paintComponent(Graphics g) {
994                          if(e.isPopupTrigger()) show(e);                          Graphics2D g2 = (Graphics2D)g;
995                            
996                            Paint oldPaint = g2.getPaint();
997                            Composite oldComposite = g2.getComposite();
998                            
999                            double h = getSize().getHeight();
1000                            double w = getSize().getWidth();
1001                            
1002                            FantasiaPainter.paintBorder(g2, 0, -3, w - 1, h - 1, 6, false);
1003                            paintComponent(g2, 5, 1, w - 10, h - 6, color1, color2);
1004                            
1005                            g2.setPaint(oldPaint);
1006                            g2.setComposite(oldComposite);
1007                  }                  }
1008            }
1009                    
1010                  void          class BottomPane extends FantasiaPanel {
1011                  show(MouseEvent e) {                  BottomPane() {
1012                          cmenu.show(e.getComponent(), e.getX(), e.getY());                          setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
1013                            setOpaque(false);
1014                            add(pianoKeyboardPane);
1015                            
1016                  }                  }
1017          }          }
1018  }  }

Legend:
Removed from v.1143  
changed lines
  Added in v.1865

  ViewVC Help
Powered by ViewVC