/[svn]/jsampler/trunk/src/org/jsampler/view/classic/ChannelsBar.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/view/classic/ChannelsBar.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1357 - (hide annotations) (download)
Sat Sep 22 17:27:06 2007 UTC (16 years, 7 months ago) by iliev
File size: 5401 byte(s)
* Added options for setting the maximum master and channel volume
  (choose Edit/Preferences)
* Fantasia: Edit instrument button is now shown on the channel
  screen only when there is loaded instrument on that channel
* Fantasia: Added options for showing additional device parameters in
  audio/MIDI device panes (Edit/Preferences, then click the `View' tab)
* Fantasia: Master volume is now fully implemented

1 iliev 1144 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4     * Copyright (C) 2005-2006 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.classic;
24    
25     import java.awt.Dimension;
26 iliev 1357 import java.awt.Point;
27 iliev 1144
28 iliev 1357 import java.awt.event.MouseAdapter;
29     import java.awt.event.MouseEvent;
30    
31     import java.beans.PropertyChangeEvent;
32     import java.beans.PropertyChangeListener;
33    
34 iliev 1144 import javax.swing.BorderFactory;
35     import javax.swing.BoxLayout;
36     import javax.swing.JButton;
37     import javax.swing.JLabel;
38     import javax.swing.JPanel;
39     import javax.swing.JSlider;
40     import javax.swing.JToolBar;
41 iliev 1357 import javax.swing.JToolTip;
42     import javax.swing.Popup;
43     import javax.swing.PopupFactory;
44 iliev 1144
45     import javax.swing.event.ChangeEvent;
46     import javax.swing.event.ChangeListener;
47    
48     import org.jsampler.CC;
49    
50     import org.jsampler.event.SamplerAdapter;
51     import org.jsampler.event.SamplerEvent;
52    
53     import static org.jsampler.view.classic.ClassicI18n.i18n;
54 iliev 1357 import static org.jsampler.view.classic.ClassicPrefs.preferences;
55     import static org.jsampler.view.std.StdPrefs.*;
56 iliev 1144
57    
58     /**
59     *
60     * @author Grigor Iliev
61     */
62     public class ChannelsBar extends JToolBar {
63     private final JButton btnNew = new ToolbarButton(A4n.newChannel);
64     private final JButton btnDuplicate = new ToolbarButton(A4n.duplicateChannels);
65     private final JButton btnUp = new ToolbarButton(A4n.moveChannelsUp);
66     private final JButton btnDown = new ToolbarButton(A4n.moveChannelsDown);
67     private final JButton btnRemove = new ToolbarButton(A4n.removeChannels);
68    
69     private final JButton btnNewTab = new ToolbarButton(A4n.newChannelsTab);
70     private final JButton btnRemoveTab = new ToolbarButton(A4n.closeChannelsTab);
71     private final JButton btnTabMoveLeft = new ToolbarButton(A4n.moveTab2Left);
72     private final JButton btnTabMoveRight = new ToolbarButton(A4n.moveTab2Right);
73    
74     private final JLabel lVolume = new JLabel(Res.iconVolume22);
75     private final JSlider slVolume = new JSlider(0, 100);
76 iliev 1357 private Popup popup = null;
77     private final JToolTip tip = new JToolTip();
78 iliev 1144
79    
80     /**
81     * Creates a new instance of ChannelsBar
82     */
83     public ChannelsBar() {
84     super(i18n.getLabel("ChanelsBar.name"));
85     setFloatable(false);
86    
87     add(lVolume);
88    
89     Dimension d = new Dimension(200, slVolume.getPreferredSize().height);
90     slVolume.setPreferredSize(d);
91     slVolume.setMaximumSize(d);
92     slVolume.setOpaque(false);
93     add(slVolume);
94    
95     addSeparator();
96    
97     add(btnNew);
98     add(btnDuplicate);
99     add(btnRemove);
100     add(btnUp);
101     add(btnDown);
102    
103     addSeparator();
104    
105     add(btnNewTab);
106     add(btnRemoveTab);
107     add(btnTabMoveLeft);
108     add(btnTabMoveRight);
109    
110 iliev 1357 // Setting the tooltip size
111     tip.setTipText(i18n.getLabel("ChannelsBar.volume", 1000));
112     tip.setMinimumSize(tip.getPreferredSize());
113     tip.setPreferredSize(tip.getPreferredSize()); // workaround for preserving that size
114     tip.setComponent(slVolume);
115     ///////
116    
117     int i = preferences().getIntProperty(MAXIMUM_MASTER_VOLUME);
118     slVolume.setMaximum(i);
119     String s = MAXIMUM_MASTER_VOLUME;
120     preferences().addPropertyChangeListener(s, new PropertyChangeListener() {
121     public void
122     propertyChange(PropertyChangeEvent e) {
123     int j = preferences().getIntProperty(MAXIMUM_MASTER_VOLUME);
124     slVolume.setMaximum(j);
125     }
126     });
127    
128 iliev 1144 slVolume.addChangeListener(new ChangeListener() {
129     public void
130     stateChanged(ChangeEvent e) { setVolume(); }
131     });
132    
133     CC.getSamplerModel().addSamplerListener(new SamplerAdapter() {
134     public void
135     volumeChanged(SamplerEvent e) { updateVolume(); }
136     });
137    
138     updateVolume();
139 iliev 1357
140     slVolume.addMouseListener(new MouseAdapter() {
141     public void
142     mousePressed(MouseEvent e) {
143     if(popup != null) {
144     popup.hide();
145     popup = null;
146     }
147    
148     Point p = slVolume.getLocationOnScreen();
149     PopupFactory pf = PopupFactory.getSharedInstance();
150     popup = pf.getPopup(slVolume, tip, p.x, p.y - 22);
151     popup.show();
152     }
153    
154     public void
155     mouseReleased(MouseEvent e) {
156     if(popup != null) {
157     popup.hide();
158     popup = null;
159     }
160     }
161     });
162 iliev 1144 }
163    
164     private void
165     setVolume() {
166     int volume = slVolume.getValue();
167 iliev 1357 String s = i18n.getLabel("ChannelsBar.volume", volume);
168     slVolume.setToolTipText(s);
169     lVolume.setToolTipText(s);
170     tip.setTipText(s);
171     tip.repaint();
172 iliev 1144
173     if(slVolume.getValueIsAdjusting()) return;
174    
175     int vol = (int)(CC.getSamplerModel().getVolume() * 100);
176    
177     if(vol == slVolume.getValue()) return;
178    
179     /*
180     * If the model's volume is not equal to the slider
181     * value we assume that the change is due to user input.
182     * So we must update the volume at the backend too.
183     */
184     float v = slVolume.getValue();
185     v /= 100;
186     CC.getSamplerModel().setBackendVolume(v);
187     }
188    
189     private void
190     updateVolume() {
191     slVolume.setValue((int)(CC.getSamplerModel().getVolume() * 100));
192     }
193     }

  ViewVC Help
Powered by ViewVC