1 |
iliev |
787 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
|
|
* Copyright (C) 2005 Grigor Kirilov Iliev |
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 |
iliev |
842 |
import java.awt.Font; |
29 |
iliev |
787 |
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 |
iliev |
842 |
import org.jsampler.event.SamplerChannelListEvent; |
43 |
|
|
import org.jsampler.event.SamplerChannelListListener; |
44 |
iliev |
787 |
import org.jsampler.event.SamplerEvent; |
45 |
|
|
import org.jsampler.event.SamplerListener; |
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 |
iliev |
842 |
JLabel l1; |
56 |
|
|
JLabel l2; |
57 |
|
|
|
58 |
iliev |
787 |
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 |
iliev |
842 |
l1 = new JLabel(); |
67 |
|
|
l1.setFont(l1.getFont().deriveFont(Font.PLAIN)); |
68 |
iliev |
787 |
l1.setBorder(BorderFactory.createLoweredBevelBorder()); |
69 |
|
|
|
70 |
iliev |
842 |
l2 = new JLabel(" "); |
71 |
iliev |
787 |
l2.setBorder(BorderFactory.createLoweredBevelBorder()); |
72 |
iliev |
842 |
l2.setPreferredSize(l1.getPreferredSize()); |
73 |
iliev |
787 |
|
74 |
iliev |
842 |
setTotalChannelCount(CC.getSamplerModel().getChannelCount()); |
75 |
|
|
|
76 |
iliev |
787 |
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 |
iliev |
842 |
CC.getSamplerModel().addSamplerChannelListListener(getHandler()); |
114 |
iliev |
787 |
} |
115 |
|
|
|
116 |
iliev |
842 |
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 |
iliev |
787 |
private final Handler handler = new Handler(); |
124 |
|
|
|
125 |
|
|
private Handler |
126 |
|
|
getHandler() { return handler; } |
127 |
|
|
|
128 |
iliev |
842 |
private class Handler implements SamplerListener, SamplerChannelListListener { |
129 |
iliev |
787 |
/** 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 |
|
|
pbTotalVoices.setMaximum(voicesMax); |
135 |
|
|
pbTotalVoices.setValue(voices); |
136 |
|
|
pbTotalVoices.setString(i18n.getLabel("Statusbar.pbTotalVoices", voices)); |
137 |
|
|
} |
138 |
iliev |
842 |
|
139 |
|
|
/** |
140 |
|
|
* Invoked when a new sampler channel is created. |
141 |
|
|
* @param e A <code>SamplerChannelListEvent</code> |
142 |
|
|
* instance providing the event information. |
143 |
|
|
*/ |
144 |
|
|
public void |
145 |
|
|
channelAdded(SamplerChannelListEvent e) { |
146 |
|
|
setTotalChannelCount(CC.getSamplerModel().getChannelCount()); |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
/** |
150 |
|
|
* Invoked when a sampler channel is removed. |
151 |
|
|
* @param e A <code>SamplerChannelListEvent</code> |
152 |
|
|
* instance providing the event information. |
153 |
|
|
*/ |
154 |
|
|
public void |
155 |
|
|
channelRemoved(SamplerChannelListEvent e) { |
156 |
|
|
setTotalChannelCount(CC.getSamplerModel().getChannelCount()); |
157 |
|
|
} |
158 |
iliev |
787 |
} |
159 |
|
|
} |