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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1285 - (show annotations) (download)
Fri Aug 10 19:55:03 2007 UTC (16 years, 8 months ago) by iliev
File size: 4832 byte(s)
* Updated to version 0.6a. The Fantasia distribution is now
  capable of controlling all features available in LinuxSampler

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.BorderLayout;
26 import java.awt.Color;
27 import java.awt.Dimension;
28 import java.awt.Font;
29 import java.awt.GridBagConstraints;
30 import java.awt.GridBagLayout;
31 import java.awt.Insets;
32
33 import javax.swing.BorderFactory;
34 import javax.swing.Box;
35 import javax.swing.BoxLayout;
36 import javax.swing.JLabel;
37 import javax.swing.JPanel;
38 import javax.swing.JProgressBar;
39
40 import org.jsampler.CC;
41
42 import org.jsampler.event.SamplerAdapter;
43 import org.jsampler.event.SamplerChannelListEvent;
44 import org.jsampler.event.SamplerChannelListListener;
45 import org.jsampler.event.SamplerEvent;
46
47 import static org.jsampler.view.classic.ClassicI18n.i18n;
48
49
50 /**
51 *
52 * @author Grigor Iliev
53 */
54 public class Statusbar extends JPanel {
55 JLabel l1;
56 JLabel l2;
57
58 private final JProgressBar pbTotalVoices = new JProgressBar();
59
60 /** Creates a new instance of StatusBar */
61 public Statusbar() {
62 GridBagLayout gridbag = new GridBagLayout();
63 GridBagConstraints c = new GridBagConstraints();
64 setLayout(gridbag);
65
66 l1 = new JLabel();
67 l1.setFont(l1.getFont().deriveFont(Font.PLAIN));
68 l1.setBorder(BorderFactory.createLoweredBevelBorder());
69
70 l2 = new JLabel(" ");
71 l2.setBorder(BorderFactory.createLoweredBevelBorder());
72 l2.setPreferredSize(l1.getPreferredSize());
73
74 setTotalChannelCount(CC.getSamplerModel().getChannelCount());
75
76 JPanel progressPane = new JPanel();
77 progressPane.setLayout(new BorderLayout());
78 progressPane.add(pbTotalVoices, BorderLayout.CENTER);
79 progressPane.setBorder(BorderFactory.createLoweredBevelBorder());
80
81 pbTotalVoices.setBorderPainted(false);
82 pbTotalVoices.setStringPainted(true);
83 float fsize = pbTotalVoices.getFont().getSize2D();
84 fsize = fsize > 10 ? fsize - 3 : 8;
85 pbTotalVoices.setFont(pbTotalVoices.getFont().deriveFont(fsize));
86
87 c.gridx = 0;
88 c.gridy = 0;
89 c.insets = new Insets(2, 0, 0, 2);
90 //c.anchor = GridBagConstraints.WEST;
91 c.weightx = 1;
92 c.weighty = 0;
93 c.fill = GridBagConstraints.HORIZONTAL;
94 gridbag.setConstraints(l1, c);
95 add(l1);
96
97 c.gridx = 1;
98 c.gridy = 0;
99 c.weightx = 0.3;
100 gridbag.setConstraints(progressPane, c);
101 add(progressPane);
102
103 c.gridx = 2;
104 c.gridy = 0;
105 c.weightx = 1;
106 c.insets = new Insets(2, 0, 0, 0);
107 gridbag.setConstraints(l2, c);
108 add(l2);
109
110 getHandler().totalVoiceCountChanged(null);
111
112 CC.getSamplerModel().addSamplerListener(getHandler());
113 CC.getSamplerModel().addSamplerChannelListListener(getHandler());
114 }
115
116 private void
117 setTotalChannelCount(int count) {
118 if(count == 1) l1.setText(" " + i18n.getLabel("Statusbar.totalChannel", count));
119 else l1.setText(" " + i18n.getLabel("Statusbar.totalChannels", count));
120 l2.setPreferredSize(l1.getPreferredSize());
121 }
122
123 private final Handler handler = new Handler();
124
125 private Handler
126 getHandler() { return handler; }
127
128 private class Handler extends SamplerAdapter implements SamplerChannelListListener {
129 /** Invoked when the total number of active voices is changed. */
130 public void
131 totalVoiceCountChanged(SamplerEvent e) {
132 int voices = CC.getSamplerModel().getTotalVoiceCount();
133 int voicesMax = CC.getSamplerModel().getTotalVoiceCountMax();
134
135 // workaround for bug #223 in substance
136 if(voicesMax == 0) voicesMax = 1;
137 pbTotalVoices.setMaximum(voicesMax);
138 pbTotalVoices.setValue(voices);
139 pbTotalVoices.setString(i18n.getLabel("Statusbar.pbTotalVoices", voices));
140 }
141
142 /**
143 * Invoked when a new sampler channel is created.
144 * @param e A <code>SamplerChannelListEvent</code>
145 * instance providing the event information.
146 */
147 public void
148 channelAdded(SamplerChannelListEvent e) {
149 setTotalChannelCount(CC.getSamplerModel().getChannelCount());
150 }
151
152 /**
153 * Invoked when a sampler channel is removed.
154 * @param e A <code>SamplerChannelListEvent</code>
155 * instance providing the event information.
156 */
157 public void
158 channelRemoved(SamplerChannelListEvent e) {
159 setTotalChannelCount(CC.getSamplerModel().getChannelCount());
160 }
161 }
162 }

  ViewVC Help
Powered by ViewVC