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

Legend:
Removed from v.912  
changed lines
  Added in v.1864

  ViewVC Help
Powered by ViewVC