view src/uk/ac/qmul/eecs/depic/daw/haptics/HaptificationPrefsPanel.java @ 4:473da40f3d39 tip

added html formatting to Daw/package-info.java
author Fiore Martin <f.martin@qmul.ac.uk>
date Thu, 25 Feb 2016 17:50:09 +0000
parents c0412c81d274
children
line wrap: on
line source
package uk.ac.qmul.eecs.depic.daw.haptics;


import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.prefs.Preferences;

import javax.swing.JLabel;

import uk.ac.qmul.eecs.depic.daw.gui.PreferencesPanel;
import uk.ac.qmul.eecs.depic.daw.referencesound.GridSound;

import javax.swing.JComboBox;

/**
 * 
 * Preference panel for the haptic display of the DAW. 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 HaptificationPrefsPanel extends PreferencesPanel {
	
	public static GridSound.Type [] SOUND_TYPES = {
		GridSound.Type.NONE, 
		GridSound.Type.PITCH,
		GridSound.Type.PITCH_ONE_REF,
		GridSound.Type.PITCH_MUL_REF 
	};
	
	public static String [] GRID_TYPES = {
		"freeform","grid0","grid1", "grid3"
	};
	
	private static String [] keys = new String [] {
		"sound_type",
		"grid_type",
	};

	private static final long serialVersionUID = 1L;

	
	private static HaptificationPrefsPanel singleton;
	private JComboBox<GridSound.Type> soundComboBox;
	private JComboBox<String> gridComboBox;
	public static HaptificationPrefsPanel getInstance(){
		if(singleton == null)
			singleton = new HaptificationPrefsPanel();
		return singleton;
	}

	/**
	 * Create the panel.
	 */
	private HaptificationPrefsPanel() {
		
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{30, 70, 78, 189, 0, 0};
		gridBagLayout.rowHeights = new int[]{30, 18, 0, 0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 1.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("Sound Type:");
		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(this.getClass());
		
		soundComboBox = new JComboBox<>(SOUND_TYPES);
		soundComboBox.setSelectedItem(prefs.get(keys[1], SOUND_TYPES[0].toString()));
		GridBagConstraints gbc_soundComboBox = new GridBagConstraints();
		gbc_soundComboBox.fill = GridBagConstraints.HORIZONTAL;
		gbc_soundComboBox.insets = new Insets(0, 0, 5, 5);
		gbc_soundComboBox.gridx = 3;
		gbc_soundComboBox.gridy = 1;
		add(soundComboBox, gbc_soundComboBox);
		
		JLabel borderThreshLabel = new JLabel("Grid Type :"); // 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);
		
		gridComboBox = new JComboBox<>(GRID_TYPES);
		gridComboBox.setSelectedItem(prefs.get(keys[1], GRID_TYPES[0]));
		GridBagConstraints gbc_gridComboBox = new GridBagConstraints();
		gbc_gridComboBox.insets = new Insets(0, 0, 5, 5);
		gbc_gridComboBox.fill = GridBagConstraints.HORIZONTAL;
		gbc_gridComboBox.gridx = 3;
		gbc_gridComboBox.gridy = 2;
		add(gridComboBox, gbc_gridComboBox);
		
		/* sets all the strings for the screen reader  */
		configureAccessibleContext();
	}

	
	private void configureAccessibleContext(){
	}
	
	@Override
	public void savePrefs() {
		Preferences prefs = Preferences.userNodeForPackage(this.getClass());
		
		prefs.put(getPrefsList()[0], soundComboBox.getItemAt(soundComboBox.getSelectedIndex()).toString());
		prefs.put(getPrefsList()[1], gridComboBox.getItemAt(gridComboBox.getSelectedIndex()));
				
	}
	
	public Preferences getPrefs(){
		Preferences prefs = Preferences.userNodeForPackage(this.getClass());
		
		prefs.put(getPrefsList()[0], prefs.get(getPrefsList()[0], SOUND_TYPES[0].toString()));
		prefs.put(getPrefsList()[1], prefs.get(getPrefsList()[1], GRID_TYPES[0]));
				
		return prefs;
	}
	
	@Override
	public String getTitle(){
		return "Haptics";
	}

	@Override
	public String[] getPrefsList() {
		return keys;
	}
}