view src/uk/ac/qmul/eecs/depic/daw/gui/PreferencesDialog.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
/*  
 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.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

/**
 * 
 * Preference Dialog. It contains preference panels and when OK button is pressed 
 * it calls {@code savePrefs()} on all the panels.
 *
 */
public class PreferencesDialog extends JDialog {
	private static final long serialVersionUID = 1L;
	private final JTabbedPane content = new JTabbedPane();
	private ArrayList<PreferencesPanel> panels;
	
	private ActionListener actionListener = new ActionListener(){
		@Override
		public void actionPerformed(ActionEvent evt) {
			if("OK".equals(evt.getActionCommand())){
				savePrefs();
				dispose();
			}else if("Cancel".equals(evt.getActionCommand())){
				dispose();
			}
		}
	};

	/**
	 * Create the dialog.
	 */
	public PreferencesDialog(Frame owner) {
		super(owner,"Preferences",true);
		panels = new ArrayList<>();
		
		setBounds(100, 100, 387, 269);
		getContentPane().setLayout(new BorderLayout());
		//content.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(content, BorderLayout.CENTER);

		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			buttonPane.setBorder(BorderFactory.createMatteBorder(1,0,0,0,Color.GRAY));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.setActionCommand("OK");
				okButton.addActionListener(actionListener);
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.setActionCommand("Cancel");
				cancelButton.addActionListener(actionListener);
				buttonPane.add(cancelButton);
			}
		}
	}
	
	private void savePrefs(){
		for(PreferencesPanel p : panels) 
			p.savePrefs();
		}
	
	public void addPanel(PreferencesPanel p){
		panels.add(p);
		content.add(p,p.getTitle());
	}
}