Mercurial > hg > cmdp
view src/uk/ac/qmul/eecs/depic/daw/beads/sonification/SonificationPrefsPanel.java @ 2:c0412c81d274
Added documentation
author | Fiore Martin <f.martin@qmul.ac.uk> |
---|---|
date | Thu, 18 Feb 2016 18:35:26 +0000 |
parents | 3074a84ef81e |
children |
line wrap: on
line source
/* Cross-Modal DAW Prototype - Prototype of a simple Cross-Modal Digital Audio Workstation. Copyright (C) 2015 Queen Mary University of London (http://depic.eecs.qmul.ac.uk/) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package uk.ac.qmul.eecs.depic.daw.beads.sonification; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.util.prefs.Preferences; import javax.swing.JLabel; import javax.swing.JSpinner; import javax.swing.SpinnerNumberModel; import uk.ac.qmul.eecs.depic.daw.gui.PreferencesPanel; import javax.swing.JCheckBox; /** * * GUI panel for setting preferences for the sonification. It is in this package and not in * the gui package because it's specific to this sonification. The gui package is more * a general purpose set of graphical classes for the DAW, regardless of the sonification. * * However this class extends PreferencesPanel, which is an abstraction of a preference panel * to allow other packages to plug in their custom preference settings panels, * without making the gui package dependent on them. * */ public class SonificationPrefsPanel extends PreferencesPanel { private static String [] keys = new String [] { "selection.filter", "borders.threshold", "render_val.ref", "render_curve.gain" }; private static final long serialVersionUID = 1L; private JSpinner selectionFilterSpinner; private JSpinner borderThresholdSpinner; private JCheckBox valRefCheckBox; private JLabel lblRenderCurveGain; private JSpinner curveGainSpinner; private static SonificationPrefsPanel singleton; public static SonificationPrefsPanel getInstance(){ if(singleton == null) singleton = new SonificationPrefsPanel(); return singleton; } /** * Create the panel. */ private SonificationPrefsPanel() { GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[]{30, 70, 78, 53, 0}; gridBagLayout.rowHeights = new int[]{30, 18, 0, 0, 0, 0, 0}; gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; setLayout(gridBagLayout); JLabel selectionFilterLabel = new JLabel("Selection filter :"); GridBagConstraints gbc_selectionFilterLabel = new GridBagConstraints(); gbc_selectionFilterLabel.anchor = GridBagConstraints.WEST; gbc_selectionFilterLabel.insets = new Insets(0, 0, 5, 5); gbc_selectionFilterLabel.gridx = 1; gbc_selectionFilterLabel.gridy = 1; add(selectionFilterLabel, gbc_selectionFilterLabel); /* prefs are used to initialize the spinners and the grain ugens */ Preferences prefs = Preferences.userNodeForPackage(BeadsSonification.class); selectionFilterSpinner = new JSpinner(); selectionFilterSpinner.setModel(new SpinnerNumberModel( new Integer(prefs.getInt(getPrefsList()[0], new Integer(500))), new Integer(0), // min value new Integer(1000), // max value new Integer(10))); // increment GridBagConstraints gbc_selectionFilterSpinner = new GridBagConstraints(); gbc_selectionFilterSpinner.insets = new Insets(0, 0, 5, 0); gbc_selectionFilterSpinner.anchor = GridBagConstraints.NORTH; gbc_selectionFilterSpinner.fill = GridBagConstraints.HORIZONTAL; gbc_selectionFilterSpinner.gridx = 3; gbc_selectionFilterSpinner.gridy = 1; add(selectionFilterSpinner, gbc_selectionFilterSpinner); JLabel borderThreshLabel = new JLabel("Border Threshold :"); // FIXME boudles GridBagConstraints gbc_borderThreshLabel = new GridBagConstraints(); gbc_borderThreshLabel.anchor = GridBagConstraints.WEST; gbc_borderThreshLabel.insets = new Insets(0, 0, 5, 5); gbc_borderThreshLabel.gridx = 1; gbc_borderThreshLabel.gridy = 2; add(borderThreshLabel, gbc_borderThreshLabel); borderThresholdSpinner = new JSpinner(); borderThresholdSpinner.setModel(new SpinnerNumberModel( new Float(prefs.getFloat(getPrefsList()[1], new Float(-0.1f))), new Float(-0.1f), // min value new Float(1.0f), // max value new Float(0.05f))); // increment GridBagConstraints gbc_borderThreshSpinner = new GridBagConstraints(); gbc_borderThreshSpinner.insets = new Insets(0, 0, 5, 0); gbc_borderThreshSpinner.fill = GridBagConstraints.HORIZONTAL; gbc_borderThreshSpinner.anchor = GridBagConstraints.NORTH; gbc_borderThreshSpinner.gridx = 3; gbc_borderThreshSpinner.gridy = 2; add(borderThresholdSpinner, gbc_borderThreshSpinner); JLabel sequenceValRefLabel = new JLabel("Sequence val ref:"); GridBagConstraints gbc_sequenceValRefLabel = new GridBagConstraints(); gbc_sequenceValRefLabel.anchor = GridBagConstraints.WEST; gbc_sequenceValRefLabel.insets = new Insets(0, 0, 5, 5); gbc_sequenceValRefLabel.gridx = 1; gbc_sequenceValRefLabel.gridy = 3; add(sequenceValRefLabel, gbc_sequenceValRefLabel); valRefCheckBox = new JCheckBox(""); valRefCheckBox.setSelected(prefs.getBoolean(getPrefsList()[3], false)); sequenceValRefLabel.setLabelFor(valRefCheckBox); GridBagConstraints gbc_valRefCheckBox = new GridBagConstraints(); gbc_valRefCheckBox.anchor = GridBagConstraints.WEST; gbc_valRefCheckBox.insets = new Insets(0, 0, 5, 0); gbc_valRefCheckBox.gridx = 3; gbc_valRefCheckBox.gridy = 3; add(valRefCheckBox, gbc_valRefCheckBox); lblRenderCurveGain = new JLabel("Render Curve Gain:"); GridBagConstraints gbc_lblRenderCurveGain = new GridBagConstraints(); gbc_lblRenderCurveGain.insets = new Insets(0, 0, 5, 5); gbc_lblRenderCurveGain.gridx = 1; gbc_lblRenderCurveGain.gridy = 4; add(lblRenderCurveGain, gbc_lblRenderCurveGain); curveGainSpinner = new JSpinner(); curveGainSpinner.setModel(new SpinnerNumberModel( new Float(prefs.getFloat(getPrefsList()[3], new Float(1.0f))), new Float(0), // min value new Float(1), // max value new Float(0.1))); // increment GridBagConstraints gbc_spinner = new GridBagConstraints(); gbc_spinner.insets = new Insets(0, 0, 5, 0); gbc_spinner.fill = GridBagConstraints.HORIZONTAL; gbc_spinner.gridx = 3; gbc_spinner.gridy = 4; add(curveGainSpinner, gbc_spinner); /* sets all the strings for the screen reader */ configureAccessibleContext(); } private void configureAccessibleContext(){ borderThresholdSpinner.getEditor().getAccessibleContext().setAccessibleName("Border Threshold"); // FIXME bundle selectionFilterSpinner.getEditor().getAccessibleContext().setAccessibleName("Selectionf Filter"); } @Override public void savePrefs() { Preferences prefs = Preferences.userNodeForPackage(BeadsSonification.class); prefs.putInt(getPrefsList()[0], (Integer)selectionFilterSpinner.getValue()); prefs.putFloat(getPrefsList()[1], (Float)borderThresholdSpinner.getValue()); prefs.putBoolean(getPrefsList()[2], (Boolean)valRefCheckBox.isSelected()); prefs.putFloat(getPrefsList()[3], (Float)curveGainSpinner.getValue()); } @Override public String getTitle(){ return "Sonification Synthesis"; } @Override public String[] getPrefsList() { return keys; } }