--- jsampler/trunk/src/org/jsampler/view/fantasia/Channel.java 2007/08/10 19:55:03 1285
+++ jsampler/trunk/src/org/jsampler/view/fantasia/Channel.java 2007/09/10 22:29:09 1341
@@ -29,6 +29,8 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.HierarchyEvent;
+import java.awt.event.HierarchyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@@ -51,6 +53,7 @@
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
+import javax.swing.Timer;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
@@ -130,6 +133,19 @@
*/
public
Channel(SamplerChannelModel model) {
+ this(model, null);
+ }
+
+ /**
+ * Creates a new instance of Channel
using the specified
+ * non-null
channel model.
+ * @param model The model to be used by this channel.
+ * @param listener A listener which is notified when the newly created
+ * channel is fully expanded on the screen.
+ * @throws IllegalArgumentException If the model is null
.
+ */
+ public
+ Channel(SamplerChannelModel model, final ActionListener listener) {
super(model);
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
@@ -238,6 +254,19 @@
add(mainPane);
+ if(listener != null) {
+ final String s = JXCollapsiblePane.ANIMATION_STATE_KEY;
+ mainPane.addPropertyChangeListener(s, new PropertyChangeListener() {
+ public void
+ propertyChange(PropertyChangeEvent e) {
+ if(e.getNewValue() == "expanded") {
+ mainPane.removePropertyChangeListener(s, this);
+ listener.actionPerformed(null);
+ }
+ }
+ });
+ }
+
mainPane.setAnimated(false);
mainPane.setCollapsed(true);
mainPane.setAnimated(preferences().getBoolProperty(ANIMATED));
@@ -249,6 +278,15 @@
mainPane.setAnimated(preferences().getBoolProperty(ANIMATED));
}
});
+
+ if(listener != null) {
+ javax.swing.SwingUtilities.invokeLater(new Runnable() {
+ public void
+ run() { listener.actionPerformed(null); }
+ });
+ }
+
+ CC.getSamplerModel().addSamplerChannelListListener(getHandler());
}
private JPanel
@@ -380,12 +418,20 @@
}
}
+ protected void
+ onDestroy() {
+ CC.getSamplerModel().removeSamplerChannelListListener(getHandler());
+
+ screen.onDestroy();
+ optionsPane.onDestroy();
+ }
+
private final EventHandler eventHandler = new EventHandler();
private EventHandler
getHandler() { return eventHandler; }
- private class EventHandler implements SamplerChannelListener {
+ private class EventHandler implements SamplerChannelListener, SamplerChannelListListener {
/**
* Invoked when changes are made to a sampler channel.
* @param e A SamplerChannelEvent
instance
@@ -413,6 +459,27 @@
voiceCountChanged(SamplerChannelEvent e) {
screen.updateVoiceCount(getModel().getVoiceCount());
}
+
+ /**
+ * Invoked when a new sampler channel is created.
+ * @param e A SamplerChannelListEvent
+ * instance providing the event information.
+ */
+ public void
+ channelAdded(SamplerChannelListEvent e) { }
+
+ /**
+ * Invoked when a sampler channel is removed.
+ * @param e A SamplerChannelListEvent
+ * instance providing the event information.
+ */
+ public void
+ channelRemoved(SamplerChannelListEvent e) {
+ // Some cleanup when the channel is removed.
+ if(e.getChannelModel().getChannelId() == getChannelId()) {
+ onDestroy();
+ }
+ }
}
@@ -556,8 +623,14 @@
class ChannelScreen extends PixmapPane {
private final Channel channel;
+
+ private final InstrumentPane instrumentPane;
private JButton btnInstr = new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr"));
+ private final JButton btnEditInstr =
+ new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnEditInstr"));
+ private final ScreenButtonBg sbbEditInstr = new ScreenButtonBg(btnEditInstr);
+
private final JButton btnFxSends =
new ScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends"));
@@ -574,6 +647,8 @@
private Dimension dimVolume;
+ private Timer timer;
+
class Label extends JLabel {
Label() { this(""); }
@@ -599,7 +674,8 @@
btnInstr.setRolloverEnabled(false);
btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));
- add(btnInstr);
+ instrumentPane = new InstrumentPane();
+ add(instrumentPane);
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
@@ -666,6 +742,9 @@
installListeners();
}
+ protected void
+ onDestroy() { timer.stop(); }
+
private void
createEngineMenu() {
for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) {
@@ -689,6 +768,13 @@
actionPerformed(ActionEvent e) { loadInstrument(); }
});
+ btnEditInstr.addActionListener(new ActionListener() {
+ public void
+ actionPerformed(ActionEvent e) {
+ CC.getSamplerModel().editBackendInstrument(channel.getChannelId());
+ }
+ });
+
btnEngine.addActionListener(new ActionListener() {
public void
actionPerformed(ActionEvent e) {
@@ -696,6 +782,22 @@
menuEngines.show(btnEngine, 0, y);
}
});
+
+ addMouseListener(getHandler());
+ addHierarchyListener(getHandler());
+
+ ActionListener l = new ActionListener() {
+ public void
+ actionPerformed(ActionEvent e) {
+ if(getMousePosition(true) != null) {
+ getHandler().mouseEntered(null);
+ } else {
+ getHandler().mouseExited(null);
+ }
+ }
+ };
+ timer = new Timer(1000, l);
+ timer.start();
}
private void
@@ -722,6 +824,8 @@
if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());
else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));
}
+
+ instrumentPane.update();
if(sc.getEngine() != null) {
String s = sc.getEngine().getDescription();
@@ -766,6 +870,58 @@
lVoices.setMaximumSize(d);
}
+ class InstrumentPane extends JPanel {
+ private final JPanel leftPane = new JPanel();
+ private final JPanel rightPane = new JPanel();
+
+ InstrumentPane() {
+ setOpaque(false);
+ setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
+ add(leftPane);
+ add(btnInstr);
+ add(rightPane);
+ add(sbbEditInstr);
+ sbbEditInstr.setVisible(false);
+ setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 6));
+
+ update();
+ }
+
+ public void
+ update() {
+ int a = btnInstr.getMinimumSize().width;
+ int b = 0;
+ if(sbbEditInstr.isVisible()) b = sbbEditInstr.getPreferredSize().width;
+
+ int max = 254 - b;
+ if(a > max) a = max;
+
+ int h = btnInstr.getPreferredSize().height;
+ btnInstr.setPreferredSize(new Dimension(a, h));
+ h = btnInstr.getMaximumSize().height;
+ btnInstr.setMaximumSize(new Dimension(a, h));
+
+
+ int i = (254 - btnInstr.getPreferredSize().width) / 2;
+
+ int j = i;
+ if(sbbEditInstr.isVisible()) j -= sbbEditInstr.getPreferredSize().width;
+ if(i < 0 || j < 0) i = j = 0;
+
+ Dimension d = new Dimension(i, 1);
+ leftPane.setMinimumSize(d);
+ leftPane.setPreferredSize(d);
+ leftPane.setMaximumSize(d);
+
+ d = new Dimension(j, 1);
+ rightPane.setMinimumSize(d);
+ rightPane.setPreferredSize(d);
+ rightPane.setMaximumSize(d);
+
+ validate();
+ }
+ }
+
class FxSendsPane extends JSFxSendsPane {
FxSendsPane(SamplerChannelModel model) {
super(model);
@@ -814,6 +970,55 @@
setForeground(new java.awt.Color(0xFFA300));
}
}
+
+ static class ScreenButtonBg extends PixmapPane {
+ ScreenButtonBg(JButton btn) {
+ super(Res.gfxScreenBtnBg);
+ setPixmapInsets(new Insets(4, 4, 4, 4));
+ setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
+ setBorder(BorderFactory.createEmptyBorder(0, 7, 0, 7));
+ add(btn);
+ setPreferredSize(new Dimension(getPreferredSize().width, 13));
+ }
+
+ public Dimension
+ getPreferredSize() {
+ return new Dimension(super.getPreferredSize().width, 13);
+ }
+ }
+
+ private final EventHandler eventHandler = new EventHandler();
+
+ private EventHandler
+ getHandler() { return eventHandler; }
+
+ private class EventHandler extends MouseAdapter implements HierarchyListener {
+ public void
+ mouseEntered(MouseEvent e) {
+ if(!sbbEditInstr.isVisible()) {
+ sbbEditInstr.setVisible(true);
+ instrumentPane.update();
+ }
+ }
+
+ public void
+ mouseExited(MouseEvent e) {
+ if(getMousePosition(true) != null) return;
+ if(sbbEditInstr.isVisible()) {
+ sbbEditInstr.setVisible(false);
+ instrumentPane.update();
+ }
+ }
+
+ /** Called when the hierarchy has been changed. */
+ public void
+ hierarchyChanged(HierarchyEvent e) {
+ if((e.getChangeFlags() & e.SHOWING_CHANGED) == e.SHOWING_CHANGED) {
+ if(getMousePosition() == null) mouseExited(null);
+ else mouseEntered(null);
+ }
+ }
+ }
}
class ChannelOptions extends JXCollapsiblePane {
@@ -1047,7 +1252,6 @@
actionPerformed(ActionEvent e) { updateInstrumentMap(); }
});
- CC.getSamplerModel().addSamplerChannelListListener(getHandler());
CC.getSamplerModel().addMidiInstrumentMapListListener(mapListListener);
cbAudioDevice.addActionListener(new ActionListener() {
@@ -1281,13 +1485,27 @@
private void
setUpdate(boolean b) { update = b; }
+ protected void
+ onDestroy() {
+ SamplerModel sm = CC.getSamplerModel();
+
+ sm.removeMidiDeviceListListener(getHandler());
+ sm.removeAudioDeviceListListener(getHandler());
+ sm.removeMidiInstrumentMapListListener(mapListListener);
+ sm.removeSamplerListener(samplerListener);
+
+ if(midiDevice != null) {
+ midiDevice.removeMidiDeviceListener(getHandler());
+ }
+ }
+
private final Handler handler = new Handler();
private Handler
getHandler() { return handler; }
private class Handler implements MidiDeviceListListener, ListListener,
- SamplerChannelListListener, MidiDeviceListener {
+ MidiDeviceListener {
/**
* Invoked when a new MIDI device is created.
* @param e A MidiDeviceListEvent
@@ -1328,37 +1546,6 @@
cbAudioDevice.removeItem(e.getEntry().getDeviceInfo());
}
- /**
- * Invoked when a new sampler channel is created.
- * @param e A SamplerChannelListEvent
- * instance providing the event information.
- */
- public void
- channelAdded(SamplerChannelListEvent e) { }
-
- /**
- * Invoked when a sampler channel is removed.
- * @param e A SamplerChannelListEvent
- * instance providing the event information.
- */
- public void
- channelRemoved(SamplerChannelListEvent e) {
- // Some cleanup when the channel is removed.
- if(e.getChannelModel().getChannelId() == channel.getChannelId()) {
- SamplerModel sm = CC.getSamplerModel();
-
- sm.removeMidiDeviceListListener(getHandler());
- sm.removeAudioDeviceListListener(getHandler());
- sm.removeMidiInstrumentMapListListener(mapListListener);
- sm.removeSamplerListener(samplerListener);
- sm.removeSamplerChannelListListener(getHandler());
-
- if(midiDevice != null) {
- midiDevice.removeMidiDeviceListener(getHandler());
- }
- }
- }
-
public void
settingsChanged(MidiDeviceEvent e) {
if(isUpdate()) {