/[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 1355 by iliev, Mon Sep 17 23:55:27 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-2007 Grigor Iliev <grigor@grigoriliev.com>   *   Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of JSampler.   *   This file is part of JSampler.
7   *   *
# Line 23  Line 23 
23  package org.jsampler.view.fantasia;  package org.jsampler.view.fantasia;
24    
25  import java.awt.BorderLayout;  import java.awt.BorderLayout;
26    import java.awt.Color;
27    import java.awt.Composite;
28  import java.awt.Dialog;  import java.awt.Dialog;
29  import java.awt.Dimension;  import java.awt.Dimension;
30  import java.awt.Frame;  import java.awt.Frame;
31  import java.awt.Graphics;  import java.awt.Graphics;
32    import java.awt.Graphics2D;
33  import java.awt.GridBagConstraints;  import java.awt.GridBagConstraints;
34  import java.awt.GridBagLayout;  import java.awt.GridBagLayout;
35  import java.awt.Insets;  import java.awt.Insets;
36  import java.awt.Point;  import java.awt.Paint;
37    import java.awt.Rectangle;
38    
39  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
40  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
41  import java.awt.event.KeyEvent;  import java.awt.event.KeyEvent;
42  import java.awt.event.MouseAdapter;  
43  import java.awt.event.MouseEvent;  import java.beans.PropertyChangeEvent;
44    import java.beans.PropertyChangeListener;
45    
46  import java.io.BufferedReader;  import java.io.BufferedReader;
47  import java.io.File;  import java.io.File;
# Line 44  import java.io.FileNotFoundException; Line 49  import java.io.FileNotFoundException;
49  import java.io.FileReader;  import java.io.FileReader;
50    
51  import java.util.Vector;  import java.util.Vector;
 import java.util.logging.Level;  
52    
53  import javax.swing.BorderFactory;  import javax.swing.BorderFactory;
 import javax.swing.Box;  
54  import javax.swing.BoxLayout;  import javax.swing.BoxLayout;
55  import javax.swing.JCheckBoxMenuItem;  import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JComponent;  
 import javax.swing.JDialog;  
 import javax.swing.JFileChooser;  
 import javax.swing.JFrame;  
56  import javax.swing.JMenu;  import javax.swing.JMenu;
57  import javax.swing.JMenuBar;  import javax.swing.JMenuBar;
58  import javax.swing.JMenuItem;  import javax.swing.JMenuItem;
59  import javax.swing.JPanel;  import javax.swing.JPanel;
 import javax.swing.JPopupMenu;  
 import javax.swing.JScrollPane;  
60  import javax.swing.JSplitPane;  import javax.swing.JSplitPane;
 import javax.swing.JToggleButton;  
61  import javax.swing.KeyStroke;  import javax.swing.KeyStroke;
62  import javax.swing.SwingUtilities;  import javax.swing.SwingUtilities;
63  import javax.swing.UIManager;  import javax.swing.Timer;
64    
65  import net.sf.juife.TitleBar;  import javax.swing.event.ListSelectionEvent;
66    import javax.swing.event.ListSelectionListener;
67    
68  import org.jsampler.CC;  import org.jsampler.CC;
69  import org.jsampler.HF;  import org.jsampler.HF;
70  import org.jsampler.LSConsoleModel;  import org.jsampler.LSConsoleModel;
71    import org.jsampler.Server;
72    
 import org.jsampler.view.JSChannel;  
73  import org.jsampler.view.JSChannelsPane;  import org.jsampler.view.JSChannelsPane;
74  import org.jsampler.view.JSMainFrame;  import org.jsampler.view.SessionViewConfig;
75  import org.jsampler.view.LscpFileFilter;  
76    import org.jsampler.view.fantasia.basic.FantasiaPainter;
77    import org.jsampler.view.fantasia.basic.FantasiaPanel;
78    import org.jsampler.view.fantasia.basic.FantasiaSubPanel;
79    
80    import org.jsampler.view.std.JSBackendLogFrame;
81    import org.jsampler.view.std.JSConnectDlg;
82  import org.jsampler.view.std.JSDetailedErrorDlg;  import org.jsampler.view.std.JSDetailedErrorDlg;
83    import org.jsampler.view.std.JSQuitDlg;
84  import org.jsampler.view.std.JSamplerHomeChooser;  import org.jsampler.view.std.JSamplerHomeChooser;
85    import org.jsampler.view.std.StdMainFrame;
86    import org.jsampler.view.std.StdUtils;
87    
88  import static org.jsampler.view.fantasia.A4n.a4n;  import static org.jsampler.view.fantasia.A4n.a4n;
89  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
# Line 90  import static org.jsampler.view.std.StdP Line 95  import static org.jsampler.view.std.StdP
95   *   *
96   * @author Grigor Iliev   * @author Grigor Iliev
97   */   */
98  public class MainFrame extends JSMainFrame {  public class MainFrame extends StdMainFrame {
99          private final StandardBar standardBar = new StandardBar();          private final StandardBar standardBar = new StandardBar();
100          private final FantasiaMenuBar menuBar = new FantasiaMenuBar();          private final FantasiaMenuBar menuBar = new FantasiaMenuBar();
101          private final JPanel rootPane = new JPanel();          private final JPanel rootPane = new RootPane();
102          private final MainPane mainPane = new MainPane();          private final BottomPane bottomPane;
103          private final DevicesPane devicesPane = new DevicesPane();          private final MainPane mainPane;
104          private final JScrollPane spDevicesPane = new JScrollPane();          private final PianoKeyboardPane pianoKeyboardPane;
105                    
106          private final JMenu recentScriptsMenu =          private final JMenu recentScriptsMenu =
107                  new JMenu(i18n.getMenuLabel("actions.recentScripts"));                  new JMenu(i18n.getMenuLabel("actions.recentScripts"));
108                    
109          private final JSplitPane hSplitPane;          private final JSplitPane hSplitPane;
110                    
111          private final SidePane sidePane = new SidePane();          private final LeftSidePane leftSidePane;
112            private final RightSidePane rightSidePane;
113          private final JPanel rightPane;          private final JPanel rightPane;
114                    
115            //private final StatusBar statusBar = new StatusBar();
116            
117          private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame();          private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame();
118          private final Vector<String> recentScripts = new Vector<String>();          private final Vector<String> recentScripts = new Vector<String>();
119            
120            private final JSBackendLogFrame backendLogFrame = new JSBackendLogFrame();
121                                    
122                    
123          private final JCheckBoxMenuItem cbmiToolBarVisible =          private final JCheckBoxMenuItem cbmiToolBarVisible =
124                          new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar"));                          new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar"));
125                    
126          private final JCheckBoxMenuItem cbmiSidePaneVisible =          private final JCheckBoxMenuItem cbmiLeftSidePaneVisible =
127                          new JCheckBoxMenuItem(i18n.getMenuLabel("view.sidePane"));                          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 JCheckBoxMenuItem cbmiDevicesPaneVisible =          private final Timer guiTimer = new Timer(1000, null);
                         new JCheckBoxMenuItem(i18n.getMenuLabel("view.devicesPane"));  
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                  setTitle(i18n.getLabel("MainFrame.title"));                  setTitle(i18n.getLabel("MainFrame.title"));
141                                    //setUndecorated(true);
142                  if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage());                  if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage());
143                                    
144                    CC.setMainFrame(this); // TODO:
145                    mainPane = new MainPane();
146                    leftSidePane = new LeftSidePane();
147                    rightSidePane = new RightSidePane();
148                    
149                    setSelectedChannelsPane(mainPane.getChannelsPane(0));
150                    
151                  getContentPane().add(standardBar, BorderLayout.NORTH);                  getContentPane().add(standardBar, BorderLayout.NORTH);
152                                    
153                  rightPane = createRightPane();                  rightPane = createRightPane();
# Line 133  public class MainFrame extends JSMainFra Line 155  public class MainFrame extends JSMainFra
155                  hSplitPane = new JSplitPane (                  hSplitPane = new JSplitPane (
156                          JSplitPane.HORIZONTAL_SPLIT,                          JSplitPane.HORIZONTAL_SPLIT,
157                          true,   // continuousLayout                          true,   // continuousLayout
158                          sidePane, rightPane                          leftSidePane, rightPane
159                  );                  );
160                  hSplitPane.setResizeWeight(0.5);                  hSplitPane.setResizeWeight(0.5);
161                                    
162                  rootPane.setLayout(new BorderLayout());                  pianoKeyboardPane = new PianoKeyboardPane();
163                  rootPane.setBorder(BorderFactory.createEmptyBorder(6, 0, 0, 0));                  
164                  rootPane.setOpaque(false);                  for(int i = 0; i < mainPane.getChannelsPaneCount(); i++) {
165                            addChannelsPane(mainPane.getChannelsPane(i));
166                            getChannelsPane(i).addListSelectionListener(pianoKeyboardPane);
167                    }
168                    
169                    
170                    int h = preferences().getIntProperty("midiKeyboard.height");
171                    setMidiKeyboardHeight(h);
172                    
173                    PropertyChangeListener l = new PropertyChangeListener() {
174                            public void
175                            propertyChange(PropertyChangeEvent e) {
176                                    int h = preferences().getIntProperty("midiKeyboard.height");
177                                    setMidiKeyboardHeight(h);
178                            }
179                    };
180                    
181                    CC.preferences().addPropertyChangeListener("midiKeyboard.height", l);
182                    
183                    bottomPane = new BottomPane();
184                    
185                    hSplitPane.setOpaque(false);
186                  rootPane.add(hSplitPane);                  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();                  addMenu();
198                                    
199                  addChannelsPane(mainPane.getChannelsPane());                  if(CC.getViewConfig().isUsingScreenMenuBar()) {
200                                            // fix for moving the menu bar on top of the screen
201                  getContentPane().add(rootPane);                          // 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);                  int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
206                  hSplitPane.setDividerLocation(i);                  hSplitPane.setDividerLocation(i);
207                                    
208                  setSavedSize();                  setSavedSize();
209                    
210                    guiTimer.start();
211          }          }
212                    
213          private JPanel          private JPanel
214          createRightPane() {          createRightPane() {
215                  JPanel p = new JPanel();                  JPanel p = new FantasiaPanel();
216                    p.setOpaque(false);
217                    
218                  GridBagLayout gridbag = new GridBagLayout();                  GridBagLayout gridbag = new GridBagLayout();
219                  GridBagConstraints c = new GridBagConstraints();                  GridBagConstraints c = new GridBagConstraints();
220                                    
# Line 164  public class MainFrame extends JSMainFra Line 222  public class MainFrame extends JSMainFra
222                                    
223                  c.fill = GridBagConstraints.BOTH;                  c.fill = GridBagConstraints.BOTH;
224                                    
                 spDevicesPane.setViewportView(devicesPane);  
                 spDevicesPane.setBorder(BorderFactory.createEmptyBorder());  
                 int h = spDevicesPane.getMinimumSize().height;  
                 spDevicesPane.setMinimumSize(new Dimension(200, h));  
                   
225                  c.gridx = 1;                  c.gridx = 1;
226                  c.gridy = 0;                  c.gridy = 0;
227                  c.weightx = 1.0;                  c.weightx = 1.0;
228                  c.weighty = 1.0;                  c.weighty = 1.0;
229                  c.insets = new Insets(0, 3, 3, 0);                  c.insets = new Insets(0, 3, 0, 0);
230                  gridbag.setConstraints(spDevicesPane, c);                  gridbag.setConstraints(rightSidePane, c);
231                  p.add(spDevicesPane);                  p.add(rightSidePane);
232                                    
233                  c.gridx = 0;                  c.gridx = 0;
234                  c.gridy = 0;                  c.gridy = 0;
235                  c.weightx = 0.0;                  c.weightx = 0.0;
236                  c.weighty = 1.0;                  c.weighty = 1.0;
237                  c.insets = new Insets(0, 3, 3, 3);                  c.insets = new Insets(0, 0, 0, 3);
238                  c.fill = GridBagConstraints.VERTICAL;                  c.fill = GridBagConstraints.VERTICAL;
239                  gridbag.setConstraints(mainPane, c);                  gridbag.setConstraints(mainPane, c);
240                  p.add(mainPane);                  p.add(mainPane);
# Line 191  public class MainFrame extends JSMainFra Line 244  public class MainFrame extends JSMainFra
244                    
245          private void          private void
246          setSavedSize() {          setSavedSize() {
247                  String s = preferences().getStringProperty("MainFrame.sizeAndLocation");                  Rectangle r = StdUtils.getWindowBounds("MainFrame");
248                  if(s == null) {                  if(r == null) {
249                          setDefaultSizeAndLocation();                          setDefaultSizeAndLocation();
250                          return;                          return;
251                  }                  }
                 pack();  
                 try {  
                         int i = s.indexOf(',');  
                         int x = Integer.parseInt(s.substring(0, i));  
                           
                         s = s.substring(i + 1);  
                         i = s.indexOf(',');  
                         int y = Integer.parseInt(s.substring(0, i));  
                           
                         s = s.substring(i + 1);  
                         i = s.indexOf(',');  
                         int width = Integer.parseInt(s.substring(0, i));  
                           
                         s = s.substring(i + 1);  
                         int height = Integer.parseInt(s);  
                           
                         setBounds(x, y, width, height);  
                 } catch(Exception x) {  
                         String msg = "Parsing of window size and location string failed";  
                         CC.getLogger().log(Level.INFO, msg, x);  
                         setDefaultSizeAndLocation();  
                 }  
252                                    
253                  if(preferences().getBoolProperty("MainFrame.windowMaximized")) {                  setBounds(r);
                         setExtendedState(getExtendedState() | MAXIMIZED_BOTH);  
                 }  
254          }          }
255                    
256          private void          private void
# Line 233  public class MainFrame extends JSMainFra Line 262  public class MainFrame extends JSMainFra
262                    
263                    
264          /** Invoked when this window is about to close. */          /** Invoked when this window is about to close. */
265          protected void          @Override
266            public void
267          onWindowClose() {          onWindowClose() {
268                  sidePane.savePreferences();                  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();                  int i = hSplitPane.getDividerLocation();
279                  preferences().setIntProperty("MainFrame.hSplitDividerLocation", i);                  preferences().setIntProperty("MainFrame.hSplitDividerLocation", i);
# Line 250  public class MainFrame extends JSMainFra Line 288  public class MainFrame extends JSMainFra
288                          return;                          return;
289                  }                  }
290                                    
291                  java.awt.Point p = getLocation();                  StdUtils.saveWindowBounds("MainFrame", getBounds());
                 Dimension d = getSize();  
                 StringBuffer sb = new StringBuffer();  
                 sb.append(p.x).append(',').append(p.y).append(',');  
                 sb.append(d.width).append(',').append(d.height);  
                 preferences().setStringProperty("MainFrame.sizeAndLocation", sb.toString());  
292                                    
293                  String[] list = recentScripts.toArray(new String[recentScripts.size()]);                  String[] list = recentScripts.toArray(new String[recentScripts.size()]);
294                  preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list);                  preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list);
# Line 264  public class MainFrame extends JSMainFra Line 297  public class MainFrame extends JSMainFra
297                          if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory();                          if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory();
298                  }                  }
299                                    
300                    if(getBackendLogFrame() != null) getBackendLogFrame().stopTimer();
301                    if(getLSConsolePane() != null) getLSConsolePane().disconnect();
302                    
303                  super.onWindowClose();                  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          private void
319          addMenu() {          addMenu() {
320                  JMenu m;                  JMenu m;
# Line 277  public class MainFrame extends JSMainFra Line 325  public class MainFrame extends JSMainFra
325                  // Actions                  // Actions
326                  m = new FantasiaMenu(i18n.getMenuLabel("actions"));                  m = new FantasiaMenu(i18n.getMenuLabel("actions"));
327                                    
328                  mi = new JMenuItem(a4n.connect);                  mi = new JMenuItem(a4n.refresh);
329                  mi.setIcon(null);                  mi.setIcon(null);
330                  //mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK));                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
331                  m.add(mi);                  m.add(mi);
332                                    
333                  mi = new JMenuItem(a4n.samplerInfo);                  mi = new JMenuItem(a4n.samplerInfo);
334                  mi.setIcon(null);                  mi.setIcon(null);
335                  m.add(mi);                  m.add(mi);
336                                    
337                    mi = new JMenuItem(a4n.resetSampler);
338                    mi.setIcon(null);
339                    m.add(mi);
340                    
341                  m.addSeparator();                  m.addSeparator();
342                                    
343                  JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export"));                  JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export"));
344                  m.add(exportMenu);                  m.add(exportMenu);
345    
346                    int modKey = CC.getViewConfig().getDefaultModKey();
347                                    
348                  mi = new JMenuItem(a4n.exportSamplerConfig);                  mi = new JMenuItem(a4n.exportSamplerConfig);
349                  mi.setIcon(null);                  mi.setIcon(null);
350                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, modKey));
351                  exportMenu.add(mi);                  exportMenu.add(mi);
352                                    
353                  mi = new JMenuItem(a4n.exportMidiInstrumentMaps);                  mi = new JMenuItem(a4n.exportMidiInstrumentMaps);
# Line 304  public class MainFrame extends JSMainFra Line 358  public class MainFrame extends JSMainFra
358                                    
359                  mi = new JMenuItem(a4n.loadScript);                  mi = new JMenuItem(a4n.loadScript);
360                  mi.setIcon(null);                  mi.setIcon(null);
361                    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, modKey));
362                  m.add(mi);                  m.add(mi);
363                                    
364                  String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS);                  String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS);
# Line 315  public class MainFrame extends JSMainFra Line 370  public class MainFrame extends JSMainFra
370                                    
371                  m.addSeparator();                  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"));                  mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));
381                  m.add(mi);                  m.add(mi);
382                  mi.addActionListener(new ActionListener() {                  mi.addActionListener(new ActionListener() {
# Line 353  public class MainFrame extends JSMainFra Line 415  public class MainFrame extends JSMainFra
415                  mi = new JMenuItem(a4n.editPreferences);                  mi = new JMenuItem(a4n.editPreferences);
416                  mi.setIcon(null);                  mi.setIcon(null);
417                  mi.setAccelerator(KeyStroke.getKeyStroke (                  mi.setAccelerator(KeyStroke.getKeyStroke (
418                          KeyEvent.VK_P, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK                          KeyEvent.VK_P, modKey | KeyEvent.SHIFT_MASK
419                  ));                  ));
420                  m.add(mi);                  m.add(mi);
421                                    
# Line 374  public class MainFrame extends JSMainFra Line 436  public class MainFrame extends JSMainFra
436                  cbmiToolBarVisible.setSelected(b);                  cbmiToolBarVisible.setSelected(b);
437                  showToolBar(b);                  showToolBar(b);
438                                    
439                  cbmiSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (                  cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
440                          KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK                          KeyEvent.VK_L, modKey | KeyEvent.SHIFT_MASK
441                  ));                  ));
442                  m.add(cbmiSidePaneVisible);                  m.add(cbmiLeftSidePaneVisible);
443                                    
444                  cbmiSidePaneVisible.addActionListener(new ActionListener() {                  cbmiLeftSidePaneVisible.addActionListener(new ActionListener() {
445                          public void                          public void
446                          actionPerformed(ActionEvent e) {                          actionPerformed(ActionEvent e) {
447                                  showSidePane(cbmiSidePaneVisible.getState());                                  showSidePane(cbmiLeftSidePaneVisible.getState());
448                          }                          }
449                  });                  });
450                                    
451                  b = preferences().getBoolProperty("sidePane.visible");                  b = preferences().getBoolProperty("leftSidePane.visible");
452                  cbmiSidePaneVisible.setSelected(b);                  cbmiLeftSidePaneVisible.setSelected(b);
453                  showSidePane(b);                  showSidePane(b);
454                                    
455                  cbmiDevicesPaneVisible.setAccelerator(KeyStroke.getKeyStroke (                  cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
456                          KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK                          KeyEvent.VK_R, modKey | KeyEvent.SHIFT_MASK
457                  ));                  ));
458                  m.add(cbmiDevicesPaneVisible);                  m.add(cbmiRightSidePaneVisible);
459                                    
460                  cbmiDevicesPaneVisible.addActionListener(new ActionListener() {                  cbmiRightSidePaneVisible.addActionListener(new ActionListener() {
461                          public void                          public void
462                          actionPerformed(ActionEvent e) {                          actionPerformed(ActionEvent e) {
463                                  showDevicesPane(cbmiDevicesPaneVisible.getState());                                  showDevicesPane(cbmiRightSidePaneVisible.getState());
464                          }                          }
465                  });                  });
466                                    
467                  b = preferences().getBoolProperty("devicesPane.visible");                  b = preferences().getBoolProperty("rightSidePane.visible");
468                  cbmiDevicesPaneVisible.setSelected(b);                  cbmiRightSidePaneVisible.setSelected(b);
469                  showDevicesPane(b);                  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                  // Window
532                  m = new FantasiaMenu(i18n.getMenuLabel("window"));                  m = new FantasiaMenu(i18n.getMenuLabel("window"));
# Line 419  public class MainFrame extends JSMainFra Line 540  public class MainFrame extends JSMainFra
540                  mi.setIcon(null);                  mi.setIcon(null);
541                  m.add(mi);                  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                  // Help
569                  m = new FantasiaMenu(i18n.getMenuLabel("help"));                  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);                  mi = new JMenuItem(a4n.helpAbout);
578                  mi.setIcon(null);                  mi.setIcon(null);
579                  m.add(mi);                  m.add(mi);
# Line 430  public class MainFrame extends JSMainFra Line 581  public class MainFrame extends JSMainFra
581                  menuBar.add(m);                  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                            CC.getMainFrame().addChannelsPaneSelectionListener(this);
591                            
592                            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                    }
598                    
599                    @Override
600                    public void
601                    valueChanged(ListSelectionEvent e) {
602                            setEnabled(CC.getMainFrame().getSelectedChannelsPane().hasSelectedChannel());
603                    }
604            }
605            
606            public RightSidePane
607            getRightSidePane() { return rightSidePane; }
608            
609            @Override
610            public A4n
611            getA4n() { return A4n.a4n; }
612            
613          /**          /**
614           * This method does nothing, because <b>Fantasia</b> has exactly           * This method does nothing, because <b>Fantasia</b> has constant
615           * one pane containing sampler channels, which can not be changed.           * number of panes containing sampler channels, which can not be changed.
616           */           */
617            @Override
618          public void          public void
619          insertChannelsPane(JSChannelsPane pane, int idx) {          insertChannelsPane(JSChannelsPane pane, int idx) {
620                                    
621          }          }
622                    
623          /**          @Override
          * This method always returns the <code>JSChannelsPane</code> at index 0,  
          * because the <b>Fantasia</b> view has exactly one pane containing sampler channels.  
          * @return The <code>JSChannelsPane</code> at index 0.  
          */  
624          public JSChannelsPane          public JSChannelsPane
625          getSelectedChannelsPane() { return getChannelsPane(0); }          getSelectedChannelsPane() { return mainPane.getSelectedChannelsPane(); }
626                    
627          /**          @Override
          * This method does nothing because the <b>Fantasia</b> view has  
          * exactly one pane containing sampler channels which is always shown.  
          */  
628          public void          public void
629          setSelectedChannelsPane(JSChannelsPane pane) { }          setSelectedChannelsPane(JSChannelsPane pane) {
630                    mainPane.setSelectedChannelsPane(pane);
631                    fireChannelsPaneSelectionChanged();
632            }
633                    
634            @Override
635          public void          public void
636          installJSamplerHome() {          installJSamplerHome() {
637                  JSamplerHomeChooser chooser = new JSamplerHomeChooser(this);                  JSamplerHomeChooser chooser = new JSamplerHomeChooser(this);
# Line 463  public class MainFrame extends JSMainFra Line 641  public class MainFrame extends JSMainFra
641                  CC.changeJSamplerHome(chooser.getJSamplerHome());                  CC.changeJSamplerHome(chooser.getJSamplerHome());
642          }          }
643                    
644            @Override
645          public void          public void
646          showDetailedErrorMessage(Frame owner, String err, String details) {          showDetailedErrorMessage(Frame owner, String err, String details) {
647                  JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (                  JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
# Line 471  public class MainFrame extends JSMainFra Line 650  public class MainFrame extends JSMainFra
650                  dlg.setVisible(true);                  dlg.setVisible(true);
651          }          }
652                    
653            @Override
654          public void          public void
655          showDetailedErrorMessage(Dialog owner, String err, String details) {          showDetailedErrorMessage(Dialog owner, String err, String details) {
656                  JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (                  JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
# Line 479  public class MainFrame extends JSMainFra Line 659  public class MainFrame extends JSMainFra
659                  dlg.setVisible(true);                  dlg.setVisible(true);
660          }          }
661                    
662            /**
663             * Gets the server address to which to connect. If the server should be
664             * manually selected, a dialog asking the user to choose a server is displayed.
665             */
666            @Override
667            public Server
668            getServer() {
669                    boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP);
670                    return getServer(b);
671            }
672            
673            /**
674             * Gets the server address to which to connect. If the server should be
675             * 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          protected LSConsoleModel
700          getLSConsoleModel() { return getLSConsolePane().getModel(); }          getLSConsoleModel() { return getLSConsolePane().getModel(); }
701                    
# Line 490  public class MainFrame extends JSMainFra Line 707  public class MainFrame extends JSMainFra
707          protected LSConsoleFrame          protected LSConsoleFrame
708          getLSConsoleFrame() { return lsConsoleFrame; }          getLSConsoleFrame() { return lsConsoleFrame; }
709                    
710          protected void          public JSBackendLogFrame
711            getBackendLogFrame() { return backendLogFrame; }
712            
713            protected boolean
714          runScript() {          runScript() {
715                  String s = preferences().getStringProperty("lastScriptLocation");                  File f = StdUtils.showOpenLscpFileChooser();
716                  JFileChooser fc = new JFileChooser(s);                  if(f == null) return false;
717                  fc.setFileFilter(new LscpFileFilter());                  runScript(f);
718                  int result = fc.showOpenDialog(this);                  
719                  if(result != JFileChooser.APPROVE_OPTION) return;                  return true;
                   
                 String path = fc.getCurrentDirectory().getAbsolutePath();  
                 preferences().setStringProperty("lastScriptLocation", path);  
                                           
                 runScript(fc.getSelectedFile());  
720          }          }
721                    
722          private void          @Override
723            public void
724          runScript(String script) { runScript(new File(script)); }          runScript(String script) { runScript(new File(script)); }
725                    
726          private void          private void
# Line 512  public class MainFrame extends JSMainFra Line 728  public class MainFrame extends JSMainFra
728                  FileReader fr;                  FileReader fr;
729                  try { fr = new FileReader(script); }                  try { fr = new FileReader(script); }
730                  catch(FileNotFoundException e) {                  catch(FileNotFoundException e) {
731                          HF.showErrorMessage(i18n.getMessage("FileNotFound!"));                          HF.showErrorMessage(i18n.getError("fileNotFound!"));
732                          return;                          return;
733                  }                  }
734                                    
735                    String prefix = "#jsampler.fantasia: ";
736                    Vector<String> v = new Vector<String>();
737                  BufferedReader br = new BufferedReader(fr);                  BufferedReader br = new BufferedReader(fr);
738                                    
739                  try {                  try {
# Line 523  public class MainFrame extends JSMainFra Line 741  public class MainFrame extends JSMainFra
741                          while(s != null) {                          while(s != null) {
742                                  getLSConsoleModel().setCommandLineText(s);                                  getLSConsoleModel().setCommandLineText(s);
743                                  getLSConsoleModel().execCommand();                                  getLSConsoleModel().execCommand();
744                                    if(s.startsWith(prefix)) v.add(s.substring(prefix.length()));
745                                  s = br.readLine();                                  s = br.readLine();
746                          }                          }
747                  } catch(Exception e) {                  } catch(Exception e) {
# Line 535  public class MainFrame extends JSMainFra Line 754  public class MainFrame extends JSMainFra
754                  recentScripts.insertElementAt(s, 0);                  recentScripts.insertElementAt(s, 0);
755                                    
756                  updateRecentScriptsMenu();                  updateRecentScriptsMenu();
757                    
758                    CC.getViewConfig().setSessionViewConfig(
759                            new SessionViewConfig(v.toArray(new String[v.size()]))
760                    );
761          }          }
762                    
763          protected void          protected void
# Line 569  public class MainFrame extends JSMainFra Line 792  public class MainFrame extends JSMainFra
792                    
793          private void          private void
794          showSidePane(boolean b) {          showSidePane(boolean b) {
795                  preferences().setBoolProperty("sidePane.visible", b);                  preferences().setBoolProperty("leftSidePane.visible", b);
796                  rootPane.remove(rightPane);                  rootPane.remove(rightPane);
797                  rootPane.remove(hSplitPane);                  rootPane.remove(hSplitPane);
798                                    
# Line 601  public class MainFrame extends JSMainFra Line 824  public class MainFrame extends JSMainFra
824                    
825          private void          private void
826          showDevicesPane(boolean b) {          showDevicesPane(boolean b) {
827                  preferences().setBoolProperty("devicesPane.visible", b);                  preferences().setBoolProperty("rightSidePane.visible", b);
828                                    
829                  int width = sidePane.getWidth();                  int width = leftSidePane.getWidth();
830                  int height = sidePane.getPreferredSize().height;                  int height = leftSidePane.getPreferredSize().height;
831                  if(width != 0) sidePane.setPreferredSize(new Dimension(width, height));                  if(width != 0) leftSidePane.setPreferredSize(new Dimension(width, height));
832                                    
833                  if(b) {                  if(b) {
834                          int w = preferences().getIntProperty("devicesPane.width", 200);                          int w = preferences().getIntProperty("devicesPane.width", 200);
835                                                    
836                          int h = spDevicesPane.getPreferredSize().height;                          int h = rightSidePane.getPreferredSize().height;
837                          spDevicesPane.setPreferredSize(new Dimension(w, h));                          rightSidePane.setPreferredSize(new Dimension(w, h));
838                  } else {                  } else {
839                          int w = spDevicesPane.getWidth();                          int w = rightSidePane.getWidth();
840                          if(w > 0 && w < 200) w = 200;                          if(w > 0 && w < 200) w = 200;
841                          if(w != 0) preferences().setIntProperty("devicesPane.width", w);                          if(w != 0) preferences().setIntProperty("devicesPane.width", w);
842                  }                  }
843                                    
844                  hSplitPane.setResizeWeight(0.0);                  hSplitPane.setResizeWeight(0.0);
845                  spDevicesPane.setVisible(b);                  rightSidePane.setVisible(b);
846                  hSplitPane.resetToPreferredSizes();                  hSplitPane.resetToPreferredSizes();
847                                    
848                  int w = getPreferredSize().width;                  int w = getPreferredSize().width;
# Line 636  public class MainFrame extends JSMainFra Line 859  public class MainFrame extends JSMainFra
859                  });                  });
860          }          }
861                    
862            public void
863            setMidiKeyboardVisible(boolean b) {
864                    preferences().setBoolProperty("midiKeyboard.visible", b);
865                    pianoKeyboardPane.setVisible(b);
866                    
867                    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            public void
884            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          private void
894          sidePanesVisibilityChanged() {          sidePanesVisibilityChanged() {
895                  boolean sidePaneVisible = cbmiSidePaneVisible.isSelected();                  boolean leftSidePaneVisible = cbmiLeftSidePaneVisible.isSelected();
896                  boolean devicesPaneVisible = cbmiDevicesPaneVisible.isSelected();                  boolean rightSidePaneVisible = cbmiRightSidePaneVisible.isSelected();
897                                    
898                  if(sidePaneVisible && devicesPaneVisible) {                  if(leftSidePaneVisible && rightSidePaneVisible) {
899                          hSplitPane.setResizeWeight(0.5);                          hSplitPane.setResizeWeight(0.5);
900                  } else if(sidePaneVisible && !devicesPaneVisible) {                  } else if(leftSidePaneVisible && !rightSidePaneVisible) {
901                          hSplitPane.setResizeWeight(1.0);                          hSplitPane.setResizeWeight(1.0);
902                  }                  }
903                                    
904                  if(!sidePaneVisible && !devicesPaneVisible) {                  if(!leftSidePaneVisible && !rightSidePaneVisible) {
905                          standardBar.showFantasiaLogo(false);                          standardBar.showFantasiaLogo(false);
906                          if(isResizable()) setResizable(false);                          if(isResizable()) setResizable(false);
907                  } else {                  } else {
# Line 661  public class MainFrame extends JSMainFra Line 915  public class MainFrame extends JSMainFra
915                                    
916                  RecentScriptHandler(String script) { this.script = script; }                  RecentScriptHandler(String script) { this.script = script; }
917                                    
918                    @Override
919                  public void                  public void
920                  actionPerformed(ActionEvent e) {                  actionPerformed(ActionEvent e) {
921                          runScript(script);                          runScript(script);
# Line 675  public class MainFrame extends JSMainFra Line 930  public class MainFrame extends JSMainFra
930                          super(s);                          super(s);
931                          setFont(getFont().deriveFont(java.awt.Font.BOLD));                          setFont(getFont().deriveFont(java.awt.Font.BOLD));
932                          setOpaque(false);                          setOpaque(false);
933                            setContentAreaFilled(false);
934                  }                  }
935          }          }
936    
937          private class FantasiaMenuBar extends JMenuBar {          private class FantasiaMenuBar extends JMenuBar {
                 private Insets pixmapInsets = new Insets(6, 6, 0, 6);  
                 private Insets pixmapInsets2 = new Insets(6, 6, 6, 6);  
                   
938                  FantasiaMenuBar() {                  FantasiaMenuBar() {
939                          setOpaque(false);                          setOpaque(false);
940                            setBorder(BorderFactory.createEmptyBorder(2, 6, 0, 0));
941                  }                  }
942                                    
943                    @Override
944                  protected void                  protected void
945                  paintComponent(Graphics g) {                  paintComponent(Graphics g) {
946                          super.paintComponent(g);                          //super.paintComponent(g);
947                            Graphics2D g2 = (Graphics2D)g;
948                            
949                            Paint oldPaint = g2.getPaint();
950                            Composite oldComposite = g2.getComposite();
951                            
952                            double h = getSize().getHeight();
953                            double w = getSize().getWidth();
954                            
955                            FantasiaPainter.paintGradient(g2, 0.0, 0.0, w - 1, h - 1, FantasiaPainter.color6, FantasiaPainter.color5);
956                            
957                            FantasiaPainter.Border b;
958                            
959                            
960                          if(standardBar.isVisible()) {                          if(standardBar.isVisible()) {
961                                  PixmapPane.paintComponent(this, g, Res.gfxMenuBarBg, pixmapInsets);                                  b = new FantasiaPainter.Border(true, true, false, true);
962                                    FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h + 1, b);
963                          } else {                          } else {
964                                  PixmapPane.paintComponent(this, g, Res.gfxRoundBg14, pixmapInsets2);                                  b = new FantasiaPainter.Border(true, true, true, true);
965                                    FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h - 1, b);
966                          }                          }
967                            
968                            g2.setPaint(oldPaint);
969                            g2.setComposite(oldComposite);
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                    
982                    }
983            
984                    @Override
985                    public void
986                    paintComponent(Graphics g) {
987                            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            class BottomPane extends FantasiaPanel {
1004                    BottomPane() {
1005                            setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
1006                            setOpaque(false);
1007                            add(pianoKeyboardPane);
1008                            
1009                  }                  }
1010          }          }
1011  }  }

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

  ViewVC Help
Powered by ViewVC