f@0: /*
f@0: Cross-Modal DAW Prototype - Prototype of a simple Cross-Modal Digital Audio Workstation.
f@0:
f@0: Copyright (C) 2015 Queen Mary University of London (http://depic.eecs.qmul.ac.uk/)
f@0:
f@0: This program is free software: you can redistribute it and/or modify
f@0: it under the terms of the GNU General Public License as published by
f@0: the Free Software Foundation, either version 3 of the License, or
f@0: (at your option) any later version.
f@0:
f@0: This program is distributed in the hope that it will be useful,
f@0: but WITHOUT ANY WARRANTY; without even the implied warranty of
f@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f@0: GNU General Public License for more details.
f@0:
f@0: You should have received a copy of the GNU General Public License
f@0: along with this program. If not, see .
f@0: */
f@0: package uk.ac.qmul.eecs.depic.daw.gui;
f@0:
f@0: import java.awt.BorderLayout;
f@0: import java.awt.Color;
f@0: import java.awt.FlowLayout;
f@0: import java.awt.Frame;
f@0: import java.awt.event.ActionEvent;
f@0: import java.awt.event.ActionListener;
f@0: import java.util.ArrayList;
f@0:
f@0: import javax.swing.BorderFactory;
f@0: import javax.swing.JButton;
f@0: import javax.swing.JDialog;
f@0: import javax.swing.JPanel;
f@0: import javax.swing.JTabbedPane;
f@0:
f@2: /**
f@2: *
f@2: * Preference Dialog. It contains preference panels and when OK button is pressed
f@2: * it calls {@code savePrefs()} on all the panels.
f@2: *
f@2: */
f@0: public class PreferencesDialog extends JDialog {
f@0: private static final long serialVersionUID = 1L;
f@0: private final JTabbedPane content = new JTabbedPane();
f@0: private ArrayList panels;
f@0:
f@0: private ActionListener actionListener = new ActionListener(){
f@0: @Override
f@0: public void actionPerformed(ActionEvent evt) {
f@0: if("OK".equals(evt.getActionCommand())){
f@0: savePrefs();
f@0: dispose();
f@0: }else if("Cancel".equals(evt.getActionCommand())){
f@0: dispose();
f@0: }
f@0: }
f@0: };
f@0:
f@0: /**
f@0: * Create the dialog.
f@0: */
f@0: public PreferencesDialog(Frame owner) {
f@0: super(owner,"Preferences",true);
f@0: panels = new ArrayList<>();
f@0:
f@0: setBounds(100, 100, 387, 269);
f@0: getContentPane().setLayout(new BorderLayout());
f@0: //content.setBorder(new EmptyBorder(5, 5, 5, 5));
f@0: getContentPane().add(content, BorderLayout.CENTER);
f@0:
f@0: {
f@0: JPanel buttonPane = new JPanel();
f@0: buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
f@0: buttonPane.setBorder(BorderFactory.createMatteBorder(1,0,0,0,Color.GRAY));
f@0: getContentPane().add(buttonPane, BorderLayout.SOUTH);
f@0: {
f@0: JButton okButton = new JButton("OK");
f@0: okButton.setActionCommand("OK");
f@0: okButton.addActionListener(actionListener);
f@0: buttonPane.add(okButton);
f@0: getRootPane().setDefaultButton(okButton);
f@0: }
f@0: {
f@0: JButton cancelButton = new JButton("Cancel");
f@0: cancelButton.setActionCommand("Cancel");
f@0: cancelButton.addActionListener(actionListener);
f@0: buttonPane.add(cancelButton);
f@0: }
f@0: }
f@0: }
f@0:
f@0: private void savePrefs(){
f@0: for(PreferencesPanel p : panels)
f@0: p.savePrefs();
f@0: }
f@0:
f@0: public void addPanel(PreferencesPanel p){
f@0: panels.add(p);
f@0: content.add(p,p.getTitle());
f@0: }
f@0: }
f@0: