Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c59a468
create Java 11 copypasta sort
warmCabin Nov 7, 2023
267ac75
rename to Java14Sort
warmCabin Nov 8, 2023
c43f375
fix IndexOutOfBoundsException
warmCabin Nov 11, 2023
a2ff108
add more bounds checking to Highlights.markArray()
warmCabin Nov 11, 2023
661c77d
just throw IndexOutOfBoundsExceptions
warmCabin Nov 11, 2023
519dd2d
add SMB3 Shuffle
warmCabin Nov 11, 2023
e977376
document leftRotation
warmCabin Nov 11, 2023
272beab
first pass at minimizing parameters
warmCabin Nov 11, 2023
65bd221
second pass at minimizing parameter clutter
warmCabin Nov 11, 2023
36e090e
"Use default" no longer accepts your input
warmCabin Nov 15, 2023
383c3e6
fix Distribution naming issues
warmCabin Nov 15, 2023
b8fb9d3
improve error handling for custom distributions
warmCabin Nov 15, 2023
67e15ff
fix double update bug in shuffle selection
warmCabin Nov 15, 2023
982c8c7
Revert "fix double update bug in shuffle selection"
warmCabin Nov 15, 2023
711a5d1
fix double update bug in shuffle selection, for real
warmCabin Nov 15, 2023
4dada9c
put parentheses around the "Advanced" ghost option
warmCabin Nov 15, 2023
ada0ceb
fix the same darn thing in ShuffleDialog
warmCabin Nov 16, 2023
7218085
return boolean from ArrayManager so we can revert list selection on f…
warmCabin Nov 18, 2023
e909a31
whoops!
warmCabin Nov 19, 2023
8c68d97
fix precision error in perlin noise distribution
warmCabin Nov 19, 2023
0a0dd4f
fix possibly redundant Math.abs
warmCabin Nov 19, 2023
252c704
docs
warmCabin Nov 19, 2023
28c66dd
increment aux writes in a couple of places
warmCabin Nov 19, 2023
9cf8bdd
don't decrement allocAmount if array wasn't actually removed
warmCabin Nov 19, 2023
da42b68
fix javadoc
warmCabin Dec 5, 2023
5588c74
whoops
warmCabin Dec 5, 2023
6511f14
fix whatever this is
warmCabin Dec 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/main/java/io/github/arrayv/dialogs/ShuffleDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public ShuffleDialog(ArrayManager arrayManager, JFrame frame) {

bypassEvents = true;
this.shuffleEditor.setShuffle(arrayManager.getShuffle());
jList4.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jList4.setListData(arrayManager.getDistributionIDs());
for (int i = 0; i < arrayManager.getDistributions().length; i++) {
if (arrayManager.getDistribution().equals(arrayManager.getDistributions()[i])) {
Expand All @@ -81,13 +82,16 @@ public ShuffleDialog(ArrayManager arrayManager, JFrame frame) {
}

distributions = Arrays.stream(arrayManager.getDistributions())
.filter(dist -> !dist.getName().equals("Custom"))
.filter(dist -> dist != Distributions.CUSTOM)
.collect(Collectors.toList());
Object[] distributionNames = distributions.stream()
.map(Distributions::getName).toArray();
jList1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jList1.setListData(distributionNames);
jList3.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jList3.setListData(distributionNames);

jList2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jList2.setListData(arrayManager.getShuffleIDs());

jTextField1.setText(Double.toString(
Expand Down Expand Up @@ -376,17 +380,29 @@ private void addToGraph(ShuffleInfo shuffle) {
shuffleEditor.getShuffle().addDisconnected(shuffle, safePos.x, safePos.y);
}

private int jList4PrevSelection;

// Base Distribution
private void jList4ValueChanged() {//GEN-FIRST:event_jList1ValueChanged
if (bypassEvents)
if (bypassEvents || jList4.getValueIsAdjusting())
return;
int selection = jList4.getSelectedIndex();
Distributions[] distributions = arrayManager.getDistributions();
if (selection >= 0 && selection < distributions.length)
arrayManager.setDistribution(distributions[selection]);
if (selection >= 0 && selection < distributions.length) {
if (arrayManager.setDistribution(distributions[selection])) {
jList4PrevSelection = selection;
} else {
// Selection failed for whatever reason. Need to revert to the previous selection.
bypassEvents = true;
jList4.setSelectedIndex(jList4PrevSelection);
bypassEvents = false;
}
}
}//GEN-LAST:event_jList1ValueChanged

// Distribution Stretch
private void jList1ValueChanged() {//GEN-FIRST:event_jList1ValueChanged
if (bypassEvents)
if (bypassEvents || jList1.getValueIsAdjusting())
return;
String selection = (String)jList1.getSelectedValue();
distributions.stream()
Expand All @@ -398,8 +414,9 @@ private void jList1ValueChanged() {//GEN-FIRST:event_jList1ValueChanged
bypassEvents = false;
}//GEN-LAST:event_jList1ValueChanged

// Distribution Warp
private void jList3ValueChanged() {//GEN-FIRST:event_jList1ValueChanged
if (bypassEvents)
if (bypassEvents || jList3.getValueIsAdjusting())
return;
String selection = (String)jList3.getSelectedValue();
distributions.stream()
Expand All @@ -411,8 +428,9 @@ private void jList3ValueChanged() {//GEN-FIRST:event_jList1ValueChanged
bypassEvents = false;
}//GEN-LAST:event_jList1ValueChanged

// Shuffle
private void jList2ValueChanged() {//GEN-FIRST:event_jList1ValueChanged
if (bypassEvents)
if (bypassEvents || jList2.getValueIsAdjusting())
return;
int selection = jList2.getSelectedIndex();
Shuffles[] shuffles = arrayManager.getShuffles();
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/io/github/arrayv/main/ArrayManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,14 @@ public Distributions[] getDistributions() {
public Distributions getDistribution() {
return this.distribution;
}
public void setDistribution(Distributions choice) {
this.distribution = choice;
this.distribution.selectDistribution(arrayVisualizer.getArray(), arrayVisualizer);
if (!arrayVisualizer.isActive())
this.initializeArray(arrayVisualizer.getArray());
public boolean setDistribution(Distributions choice) {
if (choice.selectDistribution(arrayVisualizer.getArray(), arrayVisualizer)) {
this.distribution = choice;
if (!arrayVisualizer.isActive())
this.initializeArray(arrayVisualizer.getArray());
return true;
}
return false;
}

public boolean containsShuffle(Shuffles shuffle) {
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/io/github/arrayv/panes/JEnhancedOptionPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
public final class JEnhancedOptionPane extends JOptionPane {
private static final long serialVersionUID = 1L;

/**
* Prompts the user with a textbox and returns their answer, or null if they didn't confirm.
* The buttons are customizable, but option 0 is always defined as the Confirm action.
*
* @param title Title bar
* @param message Prompt message
* @param options Buttons to be clicked. You usually just want to pass a String[] of labels here, e.g. ["OK", "Cancel"].
*
* @return The user input, or null if they closed out or picked a secondary option.
*/
public static String showInputDialog(final String title, final Object message, final Object[] options)
throws HeadlessException {
final JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE,
Expand All @@ -17,10 +27,14 @@ public static String showInputDialog(final String title, final Object message, f
pane.setComponentOrientation((getRootFrame()).getComponentOrientation());
pane.setMessageType(QUESTION_MESSAGE);
pane.selectInitialValue();

final JDialog dialog = pane.createDialog(null, title);
dialog.setVisible(true);
dialog.dispose();
final Object value = pane.getInputValue();
return (value == UNINITIALIZED_VALUE) ? null : (String) value;

final Object input = pane.getInputValue();
final Object button = pane.getValue();

return button == options[0] ? (String) input : null;
}
}
29 changes: 22 additions & 7 deletions src/main/java/io/github/arrayv/prompts/ShufflePrompt.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ of this software and associated documentation files (the "Software"), to deal

public final class ShufflePrompt extends javax.swing.JFrame implements AppFrame {
private static final long serialVersionUID = 1L;
private static final String ADVANCED = "(Advanced)";

private final ArrayManager arrayManager;
private final JFrame frame;
Expand All @@ -62,6 +63,7 @@ public ShufflePrompt(ArrayManager arrayManager, JFrame frame, UtilFrame utilFram
initComponents();

initializing = true;
jList1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jList1.setListData(arrayManager.getDistributionIDs());
for (int i = 0; i < arrayManager.getDistributions().length; i++) {
if (arrayManager.getDistribution().equals(arrayManager.getDistributions()[i])) {
Expand All @@ -70,10 +72,12 @@ public ShufflePrompt(ArrayManager arrayManager, JFrame frame, UtilFrame utilFram
}
}
shuffleModel = new DefaultListModel<>();
jList2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jList2.setModel(shuffleModel);
Arrays.stream(arrayManager.getShuffleIDs()).forEach(shuffleModel::addElement);
// Add ghost option if advanced shuffle graph is active
if (arrayManager.getShuffle().size() > 1) {
shuffleModel.add(0, "Advanced");
shuffleModel.add(0, ADVANCED);
jList2.setSelectedIndex(0);
} else {
for (int i = 0; i < arrayManager.getShuffles().length; i++) {
Expand All @@ -83,7 +87,7 @@ public ShufflePrompt(ArrayManager arrayManager, JFrame frame, UtilFrame utilFram
}
}
if (jList2.getSelectedIndex() == -1) {
shuffleModel.add(0, "Advanced");
shuffleModel.add(0, ADVANCED);
jList2.setSelectedIndex(0);
}
}
Expand Down Expand Up @@ -205,20 +209,31 @@ private void jButton1ActionPerformed() {//GEN-FIRST:event_jList1ValueChanged
new ShuffleDialog(arrayManager, this);
}//GEN-LAST:event_jList1ValueChanged

private int jList1PrevSelection;

private void jList1ValueChanged() {//GEN-FIRST:event_jList1ValueChanged
if (initializing)
if (initializing || jList1.getValueIsAdjusting())
return;
int selection = jList1.getSelectedIndex();
Distributions[] distributions = arrayManager.getDistributions();
if (selection >= 0 && selection < distributions.length)
arrayManager.setDistribution(distributions[selection]);
if (selection >= 0 && selection < distributions.length) {
if (arrayManager.setDistribution(distributions[selection])) {
jList1PrevSelection = selection;
} else {
// Selection failed for whatever reason. Need to revert to the previous selection.
initializing = true;
jList1.setSelectedIndex(jList1PrevSelection);
initializing = false;
}
}
}//GEN-LAST:event_jList1ValueChanged

private void jList2ValueChanged() {//GEN-FIRST:event_jList1ValueChanged
if (initializing)
if (initializing || jList2.getValueIsAdjusting())
return;
int selection = jList2.getSelectedIndex();
if (shuffleModel.getElementAt(0).equals("Advanced")) {
// Remove ghost option if something else has been selected
if (shuffleModel.getElementAt(0).equals(ADVANCED)) {
if (selection == 0) return;
shuffleModel.remove(0);
selection--;
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/io/github/arrayv/sortdata/SortMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,16 @@
boolean bucketSort() default false;

/**
* A question to ask the user when they choose this sort. You can perform response validation by creating a method
* that is {@code public static int validateAnswer(int answer)}.
* If specified, a prompt for the runSort {@code param} will pop up when this sort is selected. You can perform
* response validation by creating a method with the following signature in your sort class:
* {@code public static int validateAnswer(int answer)}. It will get called automagically.
* @return The question to ask the user, or {@code ""} if there isn't one.
*/
String question() default "";

/**
* The default response to use for {@link #question()}. This is used when the user pressed "Use default". This
* value is ignored if there is no question. This value is <i>not</i> passed through {@code validatorAnswer}.
* The default response to use for {@link #question()}. This is used when the user presses "Use default". This
* value is ignored if there is no question. This value is <i>not</i> passed through {@code validateAnswer}.
* @return The default answer response.
*/
int defaultAnswer() default 0;
Expand Down
Loading