Skip to content

Commit

Permalink
Import/export feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Jul 24, 2021
1 parent 170f763 commit e00ec64
Show file tree
Hide file tree
Showing 13 changed files with 397 additions and 74 deletions.
4 changes: 4 additions & 0 deletions Noisily sorted.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
N true RANDOM 56 71 0 1
N false SORTED 363 125 1 -1
C 0 1
C 1 2
4 changes: 4 additions & 0 deletions backwards slightly random.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
N false REVERSE 25 15 0 1
N false ALMOST 275 15 1 -1
C 0 1
C 1 2
18 changes: 9 additions & 9 deletions src/dialogs/CustomImageDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ public CustomImageDialog() {
FileNameExtensionFilter webmpImages = new FileNameExtensionFilter("WEBMP Images", "wbmp");

this.removeAllFilesOption();
this.fileDialog.addChoosableFileFilter(allImages);
this.fileDialog.addChoosableFileFilter(jpegImages);
this.fileDialog.addChoosableFileFilter(pngImages);
this.fileDialog.addChoosableFileFilter(gifImages);
this.fileDialog.addChoosableFileFilter(bmpImages);
this.fileDialog.addChoosableFileFilter(webmpImages);
fileDialog.addChoosableFileFilter(allImages);
fileDialog.addChoosableFileFilter(jpegImages);
fileDialog.addChoosableFileFilter(pngImages);
fileDialog.addChoosableFileFilter(gifImages);
fileDialog.addChoosableFileFilter(bmpImages);
fileDialog.addChoosableFileFilter(webmpImages);

this.fileDialog.setDialogTitle("Choose an image...");
fileDialog.setDialogTitle("Choose an image...");

this.fileDialog.showDialog(null, "Select");
this.file = this.fileDialog.getSelectedFile();
fileDialog.showDialog(null, "Select");
this.file = fileDialog.getSelectedFile();
}
}
12 changes: 12 additions & 0 deletions src/dialogs/ExportShuffleDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dialogs;

final public class ExportShuffleDialog extends FileDialog {
public ExportShuffleDialog() {
super();

fileDialog.setDialogTitle("Choose where to export the current shuffle graph...");

fileDialog.showSaveDialog(null);
this.file = fileDialog.getSelectedFile();
}
}
12 changes: 12 additions & 0 deletions src/dialogs/ImportShuffleDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dialogs;

final public class ImportShuffleDialog extends FileDialog {
public ImportShuffleDialog() {
super();

fileDialog.setDialogTitle("Choose where to import the current shuffle graph from...");

fileDialog.showOpenDialog(null);
this.file = fileDialog.getSelectedFile();
}
}
8 changes: 4 additions & 4 deletions src/dialogs/ImportSortDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public ImportSortDialog() {

FileNameExtensionFilter javaFiles = new FileNameExtensionFilter("Java Source Files (.java)", "java");
this.removeAllFilesOption();
this.fileDialog.addChoosableFileFilter(javaFiles);
fileDialog.addChoosableFileFilter(javaFiles);

this.fileDialog.setDialogTitle("Choose a sort file to import...");
fileDialog.setDialogTitle("Choose a sort file to import...");

this.fileDialog.showDialog(null, "Select");
this.file = this.fileDialog.getSelectedFile();
fileDialog.showOpenDialog(null);
this.file = fileDialog.getSelectedFile();
}
}
6 changes: 3 additions & 3 deletions src/dialogs/LoadCustomDistributionDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ final public class LoadCustomDistributionDialog extends FileDialog {
public LoadCustomDistributionDialog() {
super();

this.fileDialog.setDialogTitle("Choose a distribution file...");
fileDialog.setDialogTitle("Choose a distribution file...");

this.fileDialog.showDialog(null, "Select");
this.file = this.fileDialog.getSelectedFile();
fileDialog.showDialog(null, "Select");
this.file = fileDialog.getSelectedFile();
}
}
6 changes: 3 additions & 3 deletions src/dialogs/RunScriptDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ final public class RunScriptDialog extends FileDialog {
public RunScriptDialog() {
super();

this.fileDialog.setDialogTitle("Choose a script file...");
fileDialog.setDialogTitle("Choose a script file...");

this.fileDialog.showDialog(null, "Select");
this.file = this.fileDialog.getSelectedFile();
fileDialog.showDialog(null, "Select");
this.file = fileDialog.getSelectedFile();
}
}
8 changes: 3 additions & 5 deletions src/dialogs/SaveArrayDialog.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package dialogs;

import javax.swing.filechooser.FileNameExtensionFilter;

final public class SaveArrayDialog extends FileDialog {
public SaveArrayDialog() {
super();

this.fileDialog.setDialogTitle("Choose where to save the contents of the main array...");
fileDialog.setDialogTitle("Choose where to save the contents of the main array...");

this.fileDialog.showSaveDialog(null);
this.file = this.fileDialog.getSelectedFile();
fileDialog.showSaveDialog(null);
this.file = fileDialog.getSelectedFile();
}
}
134 changes: 91 additions & 43 deletions src/dialogs/ShuffleDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@
package dialogs;

import java.awt.Dimension;
import java.io.IOException;
import java.awt.Dialog;

import javax.swing.GroupLayout;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

import frames.AppFrame;
import frames.UtilFrame;
import main.ArrayManager;
import panels.ShufflePanel;
import panes.JErrorPane;
import utils.Distributions;
import utils.ShuffleGraph;
import utils.ShuffleInfo;
import utils.Shuffles;
import utils.shuffle_utils.GraphReader;
import utils.shuffle_utils.GraphWriter;
import utils.shuffle_utils.GraphReader.MalformedGraphFileException;
import panels.ShufflePanel;

/*
Expand Down Expand Up @@ -85,6 +91,7 @@ public ShuffleDialog(ArrayManager ArrayManager, JFrame frame, UtilFrame utilFram

reposition();
setVisible(true);
setAlwaysOnTop(false);
}

@Override
Expand All @@ -103,6 +110,9 @@ private void initComponents() {

this.shuffleEditor = new ShufflePanel();

this.jButton1 = new javax.swing.JButton();
this.jButton2 = new javax.swing.JButton();

this.jScrollPane1 = new javax.swing.JScrollPane();
this.jList1 = new javax.swing.JList();

Expand All @@ -111,11 +121,27 @@ private void initComponents() {

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
jButton1.setText("Import...");
jButton1.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed();
}
});

jButton2.setText("Export...");
jButton2.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed();
}
});

jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane1.setViewportView(this.jList1);

jScrollPane2.setViewportView(this.jList2);
jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
@Override
Expand Down Expand Up @@ -153,6 +179,12 @@ public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
.addGap(75, 75, 75)
.addComponent(this.jScrollPane2, 175, 175, 175)
.addGap(75, 75, 75))
.addGroup(layout.createSequentialGroup()
.addGap(150, 150, 150)
.addComponent(this.jButton1)
.addGap(20, 20, 20)
.addComponent(this.jButton2)
.addGap(150, 150, 150))
);
layout.setVerticalGroup(
layout.createSequentialGroup()
Expand All @@ -163,51 +195,64 @@ public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
.addComponent(this.jScrollPane1, 175, 175, 175)
.addComponent(this.jScrollPane2, 175, 175, 175))
.addGap(10, 10, 10)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(this.jButton1)
.addComponent(this.jButton2))
.addGap(10, 10, 10)
);
// layout.setHorizontalGroup(
// layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
// .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
// .addGroup(layout.createSequentialGroup()
// .addGap(20, 20, 20)
// .addComponent(this.jLabel1)
// .addGap(5, 5, 5))
// .addGroup(layout.createSequentialGroup()
// .addComponent(this.jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))
// .addGap(20, 20, 20))
// .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
// .addGap(475, 475, 475)
// .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
// .addGroup(layout.createSequentialGroup()
// .addGap(20, 20, 20)
// .addComponent(this.jLabel2)
// .addGap(5, 5, 5))
// .addGroup(layout.createSequentialGroup()
// .addComponent(this.jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))
// .addGap(20, 20, 20)))
// );
// layout.setVerticalGroup(
// layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
// .addGroup(layout.createSequentialGroup()
// .addContainerGap()
// .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
// .addComponent(this.jLabel1))
// .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
// .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, true)
// .addComponent(this.jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))
// .addGap(20, 20, 20))
// .addGroup(layout.createSequentialGroup()
// .addContainerGap()
// .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
// .addComponent(this.jLabel2))
// .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
// .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, true)
// .addComponent(this.jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))
// .addGap(20, 20, 20))
// );

pack();
}// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed() {//GEN-FIRST:event_jButton1ActionPerformed
FileDialog fileDialog = new ImportShuffleDialog();
ShuffleGraph newShuffle;
try {
newShuffle = new GraphReader().read(fileDialog.file);
} catch (IOException e) {
e.printStackTrace();
JErrorPane.invokeCustomErrorMessage("IO Error: " + e.getMessage());
return;
} catch (MalformedGraphFileException e) {
e.printStackTrace();
JErrorPane.invokeCustomErrorMessage("Error Parsing File: " + e.getMessage());
return;
} catch (IllegalArgumentException e) {
e.printStackTrace();
String message = e.getMessage();
if (message.startsWith("No enum constant utils.")) {
message = message.substring("No enum constant utils.".length());
if (message.startsWith("Shuffles.")) {
message = message.substring("Shuffles.".length());
JErrorPane.invokeCustomErrorMessage("No shuffle with the ID \"" + message + "\"");
return;
} else if (message.startsWith("Distributions.")) {
message = message.substring("Distributions.".length());
JErrorPane.invokeCustomErrorMessage("No distribution with the ID \"" + message + "\"");
return;
}
}
JErrorPane.invokeErrorMessage(e, "Import Advanced Shuffle");;
return;
}
ArrayManager.setShuffle(newShuffle);
this.shuffleEditor.graph = newShuffle;
this.shuffleEditor.repaint();
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton2ActionPerformed() {//GEN-FIRST:event_jButton1ActionPerformed
FileDialog fileDialog = new ExportShuffleDialog();
try {
new GraphWriter(shuffleEditor.graph).write(fileDialog.file);
} catch (IOException e) {
e.printStackTrace();
JErrorPane.invokeCustomErrorMessage("IO Error: " + e.getMessage());
return;
}
JOptionPane.showMessageDialog(null,
"Successfully exported current shuffle to file \"" + fileDialog.file.getAbsolutePath() + "\"",
"Advanced Shuffle Editor", JOptionPane.INFORMATION_MESSAGE);
}//GEN-LAST:event_jButton1ActionPerformed

private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) throws Exception {//GEN-FIRST:event_jList1ValueChanged
// TODO add your handling code here:
if (bypassEvents)
Expand Down Expand Up @@ -239,6 +284,9 @@ private void jList2ValueChanged(javax.swing.event.ListSelectionEvent evt) throws
// Variables declaration - do not modify//GEN-BEGIN:variables
private ShufflePanel shuffleEditor;

private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;

@SuppressWarnings("rawtypes")
private javax.swing.JList jList1;
private javax.swing.JScrollPane jScrollPane1;
Expand Down
14 changes: 7 additions & 7 deletions src/dialogs/SoundbankDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public SoundbankDialog() {
FileNameExtensionFilter generalMIDI = new FileNameExtensionFilter("General MIDI (.gm)", "gm");

this.removeAllFilesOption();
this.fileDialog.addChoosableFileFilter(allSoundbanks);
this.fileDialog.addChoosableFileFilter(soundfonts);
this.fileDialog.addChoosableFileFilter(downloadableSounds);
this.fileDialog.addChoosableFileFilter(generalMIDI);
fileDialog.addChoosableFileFilter(allSoundbanks);
fileDialog.addChoosableFileFilter(soundfonts);
fileDialog.addChoosableFileFilter(downloadableSounds);
fileDialog.addChoosableFileFilter(generalMIDI);

this.fileDialog.setDialogTitle("Choose a MIDI soundbank...");
fileDialog.setDialogTitle("Choose a MIDI soundbank...");

this.fileDialog.showDialog(null, "Select");
this.file = this.fileDialog.getSelectedFile();
fileDialog.showDialog(null, "Select");
this.file = fileDialog.getSelectedFile();
}
}
Loading

0 comments on commit e00ec64

Please sign in to comment.