/[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 1871 by iliev, Sun Mar 22 18:11:39 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.JMenu;  import javax.swing.JMenu;
57    import javax.swing.JMenuBar;
58  import javax.swing.JMenuItem;  import javax.swing.JMenuItem;
59  import javax.swing.JPanel;  import javax.swing.JPanel;
60  import javax.swing.JPopupMenu;  import javax.swing.JSplitPane;
61  import javax.swing.JToggleButton;  import javax.swing.KeyStroke;
62  import javax.swing.UIManager;  import javax.swing.SwingUtilities;
63  import javax.swing.plaf.synth.SynthLookAndFeel;  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;
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    
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;
85    import org.jsampler.view.std.StdMainFrame;
86    import org.jsampler.view.std.StdUtils;
87    
88    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;
90    import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
91    import static org.jsampler.view.std.StdPrefs.*;
92    
93    
94  /**  /**
95   *   *
96   * @author Grigor Iliev   * @author Grigor Iliev
97   */   */
98  public class MainFrame extends JSMainFrame {  public class MainFrame extends StdMainFrame {
99          private final static int TITLE_BAR_WIDTH = 420;          private final StandardBar standardBar = new StandardBar();
100          private final static int TITLE_BAR_HEIGHT = 29;          private final FantasiaMenuBar menuBar = new FantasiaMenuBar();
101            private final JPanel rootPane = new RootPane();
102            private final BottomPane bottomPane;
103            private final MainPane mainPane;
104            private final PianoKeyboardPane pianoKeyboardPane;
105            
106            private final JMenu recentScriptsMenu =
107                    new JMenu(i18n.getMenuLabel("actions.recentScripts"));
108            
109            private final JSplitPane hSplitPane;
110            
111            private final LeftSidePane leftSidePane;
112            private final RightSidePane rightSidePane;
113            private final JPanel rightPane;
114            
115            //private final StatusBar statusBar = new StatusBar();
116            
117            private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame();
118            private final Vector<String> recentScripts = new Vector<String>();
119            
120            private final JSBackendLogFrame backendLogFrame = new JSBackendLogFrame();
121                    
122                    
123          private final ChannelsPane channelsPane = new ChannelsPane("");          private final JCheckBoxMenuItem cbmiToolBarVisible =
124                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar"));
125            
126            private final JCheckBoxMenuItem cbmiLeftSidePaneVisible =
127                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftSidePane"));
128            
129            private final JCheckBoxMenuItem cbmiRightSidePaneVisible =
130                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.rightSidePane"));
131            
132            private final JCheckBoxMenuItem cbmiMidiKeyboardVisible =
133                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.midiKeyboard"));
134            
135            private final Timer guiTimer = new Timer(1000, null);
136                    
137          /** Creates a new instance of <code>MainFrame</code> */          /** Creates a new instance of <code>MainFrame</code> */
138          public          public
139          MainFrame() {          MainFrame() {
140                  try {                  setTitle(i18n.getLabel("MainFrame.title"));
141                          SynthLookAndFeel synth = new SynthLookAndFeel();                  //setUndecorated(true);
142                          synth.load(MainFrame.class.getResourceAsStream("gui.xml"), MainFrame.class);                  if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage());
143                          UIManager.setLookAndFeel(synth);                  
144                  } catch(Exception e) {                  CC.setMainFrame(this); // TODO:
145                          CC.getLogger().log(Level.INFO, HF.getErrorMessage(e), e);                  mainPane = new MainPane();
146                    leftSidePane = new LeftSidePane();
147                    rightSidePane = new RightSidePane();
148                    
149                    setSelectedChannelsPane(mainPane.getChannelsPane(0));
150                    
151                    getContentPane().add(standardBar, BorderLayout.NORTH);
152                    
153                    rightPane = createRightPane();
154                    
155                    hSplitPane = new JSplitPane (
156                            JSplitPane.HORIZONTAL_SPLIT,
157                            true,   // continuousLayout
158                            leftSidePane, rightPane
159                    );
160                    hSplitPane.setResizeWeight(0.5);
161                    
162                    pianoKeyboardPane = new PianoKeyboardPane();
163                    
164                    for(int i = 0; i < mainPane.getChannelsPaneCount(); i++) {
165                            addChannelsPane(mainPane.getChannelsPane(i));
166                            getChannelsPane(i).addListSelectionListener(pianoKeyboardPane);
167                  }                  }
168                                    
169                  setTitle(i18n.getLabel("MainFrame.title"));                  
170                  addChannelsPane(channelsPane);                  int h = preferences().getIntProperty("midiKeyboard.height");
171                  add(channelsPane);                  setMidiKeyboardHeight(h);
172                  setUndecorated(true);                  
173                                    PropertyChangeListener l = new PropertyChangeListener() {
174                  JToggleButton btn = new PixmapToggleButton(Res.iconPowerOff, Res.iconPowerOn) {                          public void
175                          public boolean                          propertyChange(PropertyChangeEvent e) {
176                          contains(int x, int y) {                                  int h = preferences().getIntProperty("midiKeyboard.height");
177                                  return (x - 11)*(x - 11) + (y - 11)*(y - 11) < 71;                                  setMidiKeyboardHeight(h);
178                          }                          }
179                  };                  };
180                                    
181                  btn.setSelected(true);                  CC.preferences().addPropertyChangeListener("midiKeyboard.height", l);
182                  btn.setAlignmentX(JPanel.LEFT_ALIGNMENT);                  
183                  btn.addActionListener(new ActionListener() {                  bottomPane = new BottomPane();
184                    
185                    hSplitPane.setOpaque(false);
186                    rootPane.add(hSplitPane);
187                    rootPane.add(bottomPane, BorderLayout.SOUTH);
188                    add(rootPane);
189    
190                    if(CC.isMacOS()) {
191                            try {
192                                    String s = "org.jsampler.view.fantasia.MacOSApplicationHandler";
193                                    Class.forName(s).newInstance(); }
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                    File f = StdUtils.showOpenLscpFileChooser();
716                    if(f == null) return false;
717                    runScript(f);
718                    
719                    return true;
720            }
721            
722            @Override
723          public void          public void
724          setSelectedChannelsPane(JSChannelsPane pane) { }          runScript(String script) { runScript(new File(script)); }
725            
726            private void
727            runScript(File script) {
728                    FileReader fr;
729                    try { fr = new FileReader(script); }
730                    catch(FileNotFoundException e) {
731                            HF.showErrorMessage(i18n.getError("fileNotFound!"));
732                            return;
733                    }
734                    
735                    String prefix = "#jsampler.fantasia: ";
736                    Vector<String> v = new Vector<String>();
737                    BufferedReader br = new BufferedReader(fr);
738                    
739                    try {
740                            String s = br.readLine();
741                            while(s != null) {
742                                    getLSConsoleModel().setCommandLineText(s);
743                                    getLSConsoleModel().execCommand();
744                                    if(s.startsWith(prefix)) v.add(s.substring(prefix.length()));
745                                    s = br.readLine();
746                            }
747                    } catch(Exception e) {
748                            HF.showErrorMessage(e);
749                            return;
750                    }
751                    
752                    String s = script.getAbsolutePath();
753                    recentScripts.remove(s);
754                    recentScripts.insertElementAt(s, 0);
755                    
756                    updateRecentScriptsMenu();
757                    
758                    CC.getViewConfig().setSessionViewConfig(
759                            new SessionViewConfig(v.toArray(new String[v.size()]))
760                    );
761            }
762                    
763          public static void          protected void
764          repack(JSMainFrame frame) {          clearRecentScripts() {
765                  int y = frame.getLocation().y;                  recentScripts.removeAllElements();
766                  int height = frame.getSize().height;                  updateRecentScriptsMenu();
767                  y += (height - frame.getPreferredSize().height);          }
768                            
769                  if((height - frame.getPreferredSize().height) > 0) {          protected void
770                          frame.pack();          updateRecentScriptsMenu() {
771                          frame.setLocation(frame.getLocation().x, y);                  int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE);
772                    while(recentScripts.size() > size) {
773                            recentScripts.removeElementAt(recentScripts.size() - 1);
774                    }
775                    
776                    recentScriptsMenu.removeAll();
777                    
778                    for(String script : recentScripts) {
779                            JMenuItem mi = new JMenuItem(script);
780                            recentScriptsMenu.add(mi);
781                            mi.addActionListener(new RecentScriptHandler(script));
782                    }
783                    
784                    recentScriptsMenu.setEnabled(recentScripts.size() != 0);
785            }
786            
787            private void
788            showToolBar(boolean b) {
789                    preferences().setBoolProperty("toolBar.visible", b);
790                    standardBar.setVisible(b);
791            }
792            
793            private void
794            showSidePane(boolean b) {
795                    preferences().setBoolProperty("leftSidePane.visible", b);
796                    rootPane.remove(rightPane);
797                    rootPane.remove(hSplitPane);
798                    
799                    if(b) {
800                            hSplitPane.setRightComponent(rightPane);
801                            rootPane.add(hSplitPane);
802                            int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
803                            
804                            hSplitPane.setDividerLocation(i);
805                            hSplitPane.validate();
806                  } else {                  } else {
807                          frame.setLocation(frame.getLocation().x, y);                          rootPane.add(rightPane);
808                          frame.pack();                          
809                  }                  }
810                    
811                    int w = getPreferredSize().width;
812                    int h = getSize().height;
813                    setSize(new Dimension(w, h));
814                    
815                    rootPane.revalidate();
816                    rootPane.validate();
817                    rootPane.repaint();
818                    
819                    SwingUtilities.invokeLater(new Runnable() {
820                            public void
821                            run() { sidePanesVisibilityChanged(); }
822                    });
823            }
824            
825            private void
826            showDevicesPane(boolean b) {
827                    preferences().setBoolProperty("rightSidePane.visible", b);
828                    
829                    int width = leftSidePane.getWidth();
830                    int height = leftSidePane.getPreferredSize().height;
831                    if(width != 0) leftSidePane.setPreferredSize(new Dimension(width, height));
832                    
833                    if(b) {
834                            int w = preferences().getIntProperty("devicesPane.width", 200);
835                            
836                            int h = rightSidePane.getPreferredSize().height;
837                            rightSidePane.setPreferredSize(new Dimension(w, h));
838                    } else {
839                            int w = rightSidePane.getWidth();
840                            if(w > 0 && w < 200) w = 200;
841                            if(w != 0) preferences().setIntProperty("devicesPane.width", w);
842                    }
843                    
844                    hSplitPane.setResizeWeight(0.0);
845                    rightSidePane.setVisible(b);
846                    hSplitPane.resetToPreferredSizes();
847                    
848                    int w = getPreferredSize().width;
849                    int h = getSize().height;
850                    setSize(new Dimension(w, h));
851                    
852                    rootPane.validate();
853                    rootPane.repaint();
854                    //hSplitPane.validate();
855                    
856                    SwingUtilities.invokeLater(new Runnable() {
857                            public void
858                            run() { sidePanesVisibilityChanged(); }
859                    });
860          }          }
861                    
862          public void          public void
863          installJSamplerHome() { }          setMidiKeyboardVisible(boolean b) {
864  }                  preferences().setBoolProperty("midiKeyboard.visible", b);
865                    pianoKeyboardPane.setVisible(b);
866  class FantasiaTitleBar extends TitleBar {                  
867          FantasiaTitleBar() { this.addMouseListener(new ContextMenu()); }                  if(cbmiMidiKeyboardVisible.isSelected() != b) {
868                            cbmiMidiKeyboardVisible.setSelected(b);
869                    }
870                    
871                    if(standardBar.btnMidiKeyboard.isSelected() != b) {
872                            standardBar.btnMidiKeyboard.setSelected(b);
873                    }
874                    
875                    if(pianoKeyboardPane.btnPower.isSelected() != b) {
876                            pianoKeyboardPane.btnPower.setSelected(b);
877                    }
878                    
879                    rootPane.validate();
880                    rootPane.repaint();
881            }
882                    
883          class ContextMenu extends MouseAdapter {          public void
884                  private final JPopupMenu cmenu = new JPopupMenu();          setMidiKeyboardHeight(int height) {
885                    Dimension d = pianoKeyboardPane.getPreferredSize();
886                    d = new Dimension(d.width, height);
887                    pianoKeyboardPane.setPreferredSize(d);
888                    pianoKeyboardPane.setMinimumSize(d);
889                    pianoKeyboardPane.revalidate();
890                    pianoKeyboardPane.repaint();
891            }
892            
893            private void
894            sidePanesVisibilityChanged() {
895                    boolean leftSidePaneVisible = cbmiLeftSidePaneVisible.isSelected();
896                    boolean rightSidePaneVisible = cbmiRightSidePaneVisible.isSelected();
897                    
898                    if(leftSidePaneVisible && rightSidePaneVisible) {
899                            hSplitPane.setResizeWeight(0.5);
900                    } else if(leftSidePaneVisible && !rightSidePaneVisible) {
901                            hSplitPane.setResizeWeight(1.0);
902                    }
903                                    
904                  ContextMenu() {                  if(!leftSidePaneVisible && !rightSidePaneVisible) {
905                          JMenuItem mi;                          standardBar.showFantasiaLogo(false);
906                            if(isResizable()) setResizable(false);
907                    } else {
908                            standardBar.showFantasiaLogo(true);
909                            if(!isResizable()) setResizable(true);
910                    }
911            }
912            
913            private class RecentScriptHandler implements ActionListener {
914                    private String script;
915                    
916                    RecentScriptHandler(String script) { this.script = script; }
917                    
918                    @Override
919                    public void
920                    actionPerformed(ActionEvent e) {
921                            runScript(script);
922                            if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) {
923                                    a4n.windowLSConsole.actionPerformed(null);
924                            }
925                    }
926            }
927            
928            private static class FantasiaMenu extends JMenu {
929                    FantasiaMenu(String s) {
930                            super(s);
931                            setFont(getFont().deriveFont(java.awt.Font.BOLD));
932                            setOpaque(false);
933                            setContentAreaFilled(false);
934                    }
935            }
936    
937            private class FantasiaMenuBar extends JMenuBar {
938                    FantasiaMenuBar() {
939                            setOpaque(false);
940                            setBorder(BorderFactory.createEmptyBorder(2, 6, 0, 0));
941                    }
942                    
943                    @Override
944                    protected void
945                    paintComponent(Graphics g) {
946                            //super.paintComponent(g);
947                            Graphics2D g2 = (Graphics2D)g;
948                                                    
949                          final JCheckBoxMenuItem cmi = new JCheckBoxMenuItem (                          Paint oldPaint = g2.getPaint();
950                                  i18n.getMenuLabel("FantasiaTitleBar.AlwaysOnTop")                          Composite oldComposite = g2.getComposite();
951                          );                          
952                          cmi.setIcon(null);                          double h = getSize().getHeight();
953                          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());  
                                 }  
                         });  
954                                                    
955                          /*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);  
956                                                    
957                          cmenu.addSeparator();                          FantasiaPainter.Border b;
958                            
959                            
960                            if(standardBar.isVisible()) {
961                                    b = new FantasiaPainter.Border(true, true, false, true);
962                                    FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h + 1, b);
963                            } else {
964                                    b = new FantasiaPainter.Border(true, true, true, true);
965                                    FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h - 1, b);
966                            }
967                                                    
968                          mi = new JMenuItem(A4n.removeChannels);                          g2.setPaint(oldPaint);
969                          mi.setIcon(null);                          g2.setComposite(oldComposite);
                         cmenu.add(mi);*/  
970                  }                  }
971            }
972            
973            class RootPane extends FantasiaSubPanel {
974                    private final Color color1 = new Color(0x454545);
975                    private final Color color2 = new Color(0x2e2e2e);
976                    
977                    RootPane() {
978                            setLayout(new BorderLayout());
979                            setBorder(BorderFactory.createEmptyBorder(9, 10, 6, 10));
980                            setOpaque(false);
981                                    
                 public void  
                 mousePressed(MouseEvent e) {  
                         if(e.isPopupTrigger()) show(e);  
982                  }                  }
983                    
984                    @Override
985                  public void                  public void
986                  mouseReleased(MouseEvent e) {                  paintComponent(Graphics g) {
987                          if(e.isPopupTrigger()) show(e);                          Graphics2D g2 = (Graphics2D)g;
988                            
989                            Paint oldPaint = g2.getPaint();
990                            Composite oldComposite = g2.getComposite();
991                            
992                            double h = getSize().getHeight();
993                            double w = getSize().getWidth();
994                            
995                            FantasiaPainter.paintBorder(g2, 0, -3, w - 1, h - 1, 6, false);
996                            paintComponent(g2, 5, 1, w - 10, h - 6, color1, color2);
997                            
998                            g2.setPaint(oldPaint);
999                            g2.setComposite(oldComposite);
1000                  }                  }
1001            }
1002                    
1003                  void          class BottomPane extends FantasiaPanel {
1004                  show(MouseEvent e) {                  BottomPane() {
1005                          cmenu.show(e.getComponent(), e.getX(), e.getY());                          setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
1006                            setOpaque(false);
1007                            add(pianoKeyboardPane);
1008                            
1009                  }                  }
1010          }          }
1011  }  }

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

  ViewVC Help
Powered by ViewVC