123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- /*
- * MadHelix is a Java Swing-based GUI frontend for SoundHelix.
- * Copyright (C) 2018 UltrasonicMadness
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 only,
- * as published by the Free Software Foundation.
- *
- * 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 org.ultrasonicmadness.madhelix.dialogs;
- // Assorted imports
- import java.io.File;
- // AWT widgets
- import java.awt.FlowLayout;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.Insets;
- // Swing widgets
- import javax.swing.JButton;
- import javax.swing.JCheckBox;
- import javax.swing.JDialog;
- import javax.swing.JFileChooser;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- // MadHelix imports
- import org.ultrasonicmadness.madhelix.MadHelix;
- public class PrefsDialog extends JDialog
- {
- // The settings are stored in the main window if the OK button is clicked.
- private MadHelix mainWindow;
-
- // Components
- private JPanel prefsPanel = new JPanel();
- private JPanel fileLocationPanel = new JPanel();
- private JPanel buttonPanel = new JPanel();
- private JFileChooser fileChooser = new JFileChooser();
-
- // Option components
- JCheckBox fileExportCheckBox;
- JTextField fileLocationField = new JTextField();
-
- // Initial options
- boolean initExportingMidi;
-
- // Options
- boolean exportingMidi;
-
- public PrefsDialog(MadHelix mainWindow)
- {
- super(mainWindow, true);
- this.mainWindow = mainWindow;
- initExportingMidi = mainWindow.isExportingMidi();
- setUpSettingsDialog();
- }
-
- private void setUpSettingsDialog()
- {
- this.setTitle("MadHelix preferences");
- JPanel mainPanel = new JPanel();
-
- setUpPrefsPanel();
- setUpButtonPanel();
-
- mainPanel.setLayout(new GridBagLayout());
-
- GridBagConstraints constraints = new GridBagConstraints();
- constraints.insets = new Insets(4, 4, 4, 4);
- constraints.fill = GridBagConstraints.BOTH;
- constraints.weightx = 1;
-
- constraints.gridy = 0;
- constraints.weighty = 1;
- mainPanel.add(prefsPanel, constraints);
-
- constraints.gridy = 1;
- constraints.weighty = 0;
- mainPanel.add(buttonPanel, constraints);
-
- this.add(mainPanel);
- this.pack();
- this.setResizable(false);
- this.setSize(320, 160);
- this.setLocationRelativeTo(null);
- }
-
- private void setUpPrefsPanel()
- {
- fileExportCheckBox = new JCheckBox("Export MIDI files when playing",
- mainWindow.isExportingMidi());
-
- fileExportCheckBox.addActionListener(ev ->
- {
- exportingMidi = fileExportCheckBox.isSelected();
- });
-
- setUpFileLocationPanel();
-
- GridBagConstraints constraints = new GridBagConstraints();
- constraints.insets = new Insets(4, 4, 4, 4);
- constraints.fill = GridBagConstraints.BOTH;
- constraints.weightx = 1;
-
- prefsPanel.setLayout(new GridBagLayout());
-
- constraints.gridy = 0;
- prefsPanel.add(fileLocationPanel, constraints);
-
- constraints.gridy = 1;
- prefsPanel.add(fileExportCheckBox, constraints);
- }
-
- private void setUpFileLocationPanel()
- {
- JLabel fileLocationLabel = new JLabel("MIDI output directory",
- JLabel.LEFT);
- JButton fileBrowseButton = new JButton("Browse...");
-
- fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
- fileLocationField.setText(mainWindow.getMidiOutDir().toString());
-
- fileBrowseButton.addActionListener(ev ->
- {
- int fileStatus = fileChooser.showOpenDialog(this);
-
- // If 'Open' is clicked
- if (fileStatus == 0)
- {
- fileLocationField.setText(fileChooser.getSelectedFile().toString());
- }
- });
-
- fileLocationPanel.setLayout(new GridBagLayout());
- GridBagConstraints constraints = new GridBagConstraints();
- constraints.fill = GridBagConstraints.BOTH;
-
- constraints.gridwidth = 2;
- constraints.gridy = 0;
- fileLocationPanel.add(fileLocationLabel, constraints);
-
- constraints.gridwidth = 1;
- constraints.gridy = 1;
-
- constraints.gridx = 0;
- constraints.weightx = 1;
- fileLocationPanel.add(fileLocationField, constraints);
-
- constraints.gridx = 1;
- constraints.weightx = 0;
- fileLocationPanel.add(fileBrowseButton, constraints);
- }
-
- private void setUpButtonPanel()
- {
- JButton okButton = new JButton("OK");
- JButton cancelButton = new JButton("Cancel");
-
- // Set up the layout
- buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
-
- // Add listeners to buttons
- okButton.addActionListener(e ->
- {
- initExportingMidi = exportingMidi;
- mainWindow.setExportingMidi(initExportingMidi);
- mainWindow.setMidiOutDir(new File(fileLocationField.getText()));
-
- this.dispose();
- });
-
- cancelButton.addActionListener(e ->
- {
- fileExportCheckBox.setSelected(initExportingMidi);
- fileLocationField.setText(mainWindow.getMidiOutDir().toString());
-
- this.dispose();
- });
-
- // Add the button to the panel
- buttonPanel.add(okButton);
- buttonPanel.add(cancelButton);
- }
- }
|