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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1567 - (show annotations) (download)
Thu Dec 6 19:37:41 2007 UTC (16 years, 4 months ago) by iliev
File size: 4441 byte(s)
* added confirmation dialog on exit
* some minor gui enhancements
* preparations for release 0.8a

1 /*
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 import java.awt.Point;
27
28 import java.awt.event.MouseAdapter;
29 import java.awt.event.MouseEvent;
30
31 import java.beans.PropertyChangeEvent;
32 import java.beans.PropertyChangeListener;
33
34 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
42 import javax.swing.event.ChangeEvent;
43 import javax.swing.event.ChangeListener;
44
45 import org.jsampler.CC;
46
47 import org.jsampler.event.SamplerAdapter;
48 import org.jsampler.event.SamplerEvent;
49
50 import org.jsampler.view.std.StdUtils;
51
52 import static org.jsampler.view.classic.ClassicI18n.i18n;
53 import static org.jsampler.view.classic.ClassicPrefs.preferences;
54 import static org.jsampler.view.std.StdPrefs.*;
55
56
57 /**
58 *
59 * @author Grigor Iliev
60 */
61 public class ChannelsBar extends JToolBar {
62 private final JButton btnNew = new ToolbarButton(A4n.newChannel);
63 private final JButton btnDuplicate = new ToolbarButton(A4n.duplicateChannels);
64 private final JButton btnUp = new ToolbarButton(A4n.moveChannelsUp);
65 private final JButton btnDown = new ToolbarButton(A4n.moveChannelsDown);
66 private final JButton btnRemove = new ToolbarButton(A4n.removeChannels);
67
68 private final JButton btnNewTab = new ToolbarButton(A4n.newChannelsTab);
69 private final JButton btnRemoveTab = new ToolbarButton(A4n.closeChannelsTab);
70 private final JButton btnTabMoveLeft = new ToolbarButton(A4n.moveTab2Left);
71 private final JButton btnTabMoveRight = new ToolbarButton(A4n.moveTab2Right);
72
73 private final JLabel lVolume = new JLabel(Res.iconVolume22);
74 private final JSlider slVolume = StdUtils.createVolumeSlider();
75
76
77 /**
78 * Creates a new instance of ChannelsBar
79 */
80 public ChannelsBar() {
81 super(i18n.getLabel("ChanelsBar.name"));
82 setFloatable(false);
83
84 add(lVolume);
85
86 Dimension d = new Dimension(200, slVolume.getPreferredSize().height);
87 slVolume.setPreferredSize(d);
88 slVolume.setMaximumSize(d);
89 slVolume.setOpaque(false);
90 add(slVolume);
91
92 addSeparator();
93
94 add(btnNew);
95 add(btnDuplicate);
96 add(btnRemove);
97 add(btnUp);
98 add(btnDown);
99
100 addSeparator();
101
102 add(btnNewTab);
103 add(btnRemoveTab);
104 add(btnTabMoveLeft);
105 add(btnTabMoveRight);
106
107 int i = preferences().getIntProperty(MAXIMUM_MASTER_VOLUME);
108 slVolume.setMaximum(i);
109 String s = MAXIMUM_MASTER_VOLUME;
110 preferences().addPropertyChangeListener(s, new PropertyChangeListener() {
111 public void
112 propertyChange(PropertyChangeEvent e) {
113 int j = preferences().getIntProperty(MAXIMUM_MASTER_VOLUME);
114 slVolume.setMaximum(j);
115 }
116 });
117
118 slVolume.addChangeListener(new ChangeListener() {
119 public void
120 stateChanged(ChangeEvent e) { setVolume(); }
121 });
122
123 CC.getSamplerModel().addSamplerListener(new SamplerAdapter() {
124 public void
125 volumeChanged(SamplerEvent e) { updateVolume(); }
126 });
127
128 updateVolume();
129 }
130
131 private void
132 setVolume() {
133 int volume = slVolume.getValue();
134 String s = i18n.getLabel("ChannelsBar.volume", volume);
135
136 if(slVolume.getValueIsAdjusting()) return;
137
138 int vol = (int)(CC.getSamplerModel().getVolume() * 100);
139
140 if(vol == slVolume.getValue()) return;
141
142 /*
143 * If the model's volume is not equal to the slider
144 * value we assume that the change is due to user input.
145 * So we must update the volume at the backend too.
146 */
147 float v = slVolume.getValue();
148 v /= 100;
149 CC.getSamplerModel().setBackendVolume(v);
150 }
151
152 private void
153 updateVolume() {
154 slVolume.setValue((int)(CC.getSamplerModel().getVolume() * 100));
155 }
156 }

  ViewVC Help
Powered by ViewVC