/[svn]/jsampler/trunk/src/org/jsampler/view/fantasia/MenuManager.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/fantasia/MenuManager.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1818 - (show annotations) (download)
Wed Dec 24 17:29:47 2008 UTC (15 years, 4 months ago) by iliev
File size: 4109 byte(s)
* Added support for controlling the global sampler-wide limit of
  maximum voices and disk streams
  (choose Edit/Preferences, then click the `General' tab)
* Fantasia: store the view configuration of audio/MIDI devices and sampler
  channels in the LSCP script when exporting sampler configuration
* Fantasia: Implemented multiple sampler channels' selection
* Fantasia: Added option to move sampler channels up and down
  in the channels list
* Fantasia: Added option to move sampler channels
  to another channels panels

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>
5 *
6 * This file is part of JSampler.
7 *
8 * JSampler is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
11 *
12 * JSampler is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with JSampler; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23 package org.jsampler.view.fantasia;
24
25 import java.awt.event.KeyEvent;
26
27 import java.util.Vector;
28
29 import javax.swing.ButtonGroup;
30 import javax.swing.JRadioButtonMenuItem;
31 import javax.swing.KeyStroke;
32
33 import javax.swing.event.ListSelectionEvent;
34 import javax.swing.event.ListSelectionListener;
35
36 import org.jsampler.CC;
37
38 import static org.jsampler.view.fantasia.A4n.a4n;
39
40 /**
41 *
42 * @author Grigor Iliev
43 */
44 public class MenuManager implements ListSelectionListener {
45 private static MenuManager menuManager = null;
46 private final Vector<ChannelViewGroup> channelViewGroups =
47 new Vector<ChannelViewGroup>();
48
49 private
50 MenuManager() {
51 CC.getMainFrame().addChannelsPaneSelectionListener(this);
52
53 for(int i = 0; i < CC.getMainFrame().getChannelsPaneCount(); i++) {
54 CC.getMainFrame().getChannelsPane(i).addListSelectionListener(this);
55 }
56 }
57
58 public static MenuManager
59 getMenuManager() {
60 if(menuManager == null) menuManager = new MenuManager();
61 return menuManager;
62 }
63
64 @Override
65 public void
66 valueChanged(ListSelectionEvent e) {
67 if(e.getValueIsAdjusting()) return;
68 updateChannelViewGroups();
69 }
70
71 public void
72 updateChannelViewGroups() {
73 boolean sv = false, nv = false;
74
75 int i = A4n.SetView.getViewCount(ChannelView.Type.SMALL);
76 int j = A4n.SetView.getViewCount(ChannelView.Type.NORMAL);
77
78 if( (i != 0 && j != 0) || (i == 0 && j == 0) );
79 else if(i != 0) sv = true;
80 else nv = true;
81
82 boolean enable = i != 0 || j != 0;
83
84 for(ChannelViewGroup g : channelViewGroups) {
85 g.rbmiSmallView.setSelected(sv);
86 g.rbmiNormalView.setSelected(nv);
87 if(!sv && !nv) g.clearSelection();
88 g.setEnabled(enable);
89 }
90 }
91
92 public void
93 registerChannelViewGroup(ChannelViewGroup group) {
94 channelViewGroups.add(group);
95 if(channelViewGroups.size() < 2) updateChannelViewGroups();
96 else {
97 boolean sv = channelViewGroups.get(0).rbmiSmallView.isSelected();
98 boolean nv = channelViewGroups.get(0).rbmiNormalView.isSelected();
99 group.rbmiSmallView.setSelected(sv);
100 group.rbmiNormalView.setSelected(nv);
101 }
102 }
103
104 public void
105 unregisterChannelViewGroup(ChannelViewGroup group) {
106 channelViewGroups.remove(group);
107 }
108
109 public static class ChannelViewGroup extends ButtonGroup {
110 private JRadioButtonMenuItem rbmiSmallView;
111 private JRadioButtonMenuItem rbmiNormalView;
112
113 private boolean alwaysEnabled;
114
115 public
116 ChannelViewGroup() { this(false, false); }
117
118 public
119 ChannelViewGroup(boolean alwaysEnabled, boolean noAccel) {
120 this.alwaysEnabled = alwaysEnabled;
121
122 rbmiSmallView = new JRadioButtonMenuItem(a4n.setSmallView);
123 KeyStroke k = KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.ALT_MASK);
124 if(!noAccel) rbmiSmallView.setAccelerator(k);
125
126 rbmiNormalView = new JRadioButtonMenuItem(a4n.setNormalView);
127 k = KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.ALT_MASK);
128 if(!noAccel) rbmiNormalView.setAccelerator(k);
129
130 add(rbmiSmallView);
131 add(rbmiNormalView);
132 }
133
134 public JRadioButtonMenuItem[]
135 getMenuItems() {
136 JRadioButtonMenuItem[] m = new JRadioButtonMenuItem[2];
137 m[0] = rbmiSmallView;
138 m[1] = rbmiNormalView;
139
140 return m;
141 }
142
143 public void
144 setEnabled(boolean b) {
145 if(alwaysEnabled) return;
146
147 rbmiSmallView.setEnabled(b);
148 rbmiNormalView.setEnabled(b);
149 }
150 }
151 }

  ViewVC Help
Powered by ViewVC