This repository contains MadHelix itself, along with compiled libraries with its dependencies.
Clone
HTTPS:
git clone https://vervis.peers.community/repos/ZEkyo
SSH:
git clone USERNAME@vervis.peers.community:ZEkyo
Branches
Tags
PrefsDialog.java
/*
* 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);
}
}