[jmsl] ScoreCanvasSwingJPanel

jmsl at music.columbia.edu jmsl at music.columbia.edu
Wed Dec 10 14:54:43 EST 2008


Hi Nick,

Small question:  I was just curious as to what ScoreCanvasSwingJPanel  
does, and as to the difference between it and ScoreCanvasSwing.  I'm  
using ActionMap and InputMap to handle input events so it's important  
to have the reference to the Swing component.  The code below works,  
but it feels a bit weird.

I can't get ScoreCanvasSwingJPanel to work in the same way that  
ScoreCanvasSwing does (using score.setCanvas(canvas)). Is there  
something I'm missing?

thanks,
Peter McCulloch

package demos;

import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.KeyStroke;

import com.didkovsky.portview.swing.ViewFactorySwing;
import com.softsynth.jmsl.JMSL;
import com.softsynth.jmsl.score.Score;

public class ScoreCanvasPanelDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		JMSL.setViewFactory(new ViewFactorySwing());

		Score score = new Score(2, 800, 400);

		score.addMeasures(10);

		JFrame frame = new JFrame();

		JPanel panel = (JPanel) score.getScoreCanvas().getComponent();

		Action doNothing = new AbstractAction() {
			public void actionPerformed(ActionEvent e) {
				System.out.println("Foo.  Bar.  Etc.");
			}
		};

		panel.getInputMap().put(KeyStroke.getKeyStroke("1"), "doSomething");
		panel.getActionMap().put("doSomething", doNothing);

		frame.add(panel);

		frame.addWindowStateListener(new WindowAdapter() {
			@Override
			public void windowClosed(WindowEvent e) {
				JMSL.closeMusicDevices();
				System.exit(0);
			}
		});

		frame.pack();

		score.render();

		frame.setVisible(true);

	}

}



More information about the jmsl mailing list