Skip to content

Commit

Permalink
Add group randomization
Browse files Browse the repository at this point in the history
  • Loading branch information
Tech-FZ committed Oct 30, 2022
1 parent 564ad07 commit 6fa3365
Show file tree
Hide file tree
Showing 12 changed files with 249 additions and 29 deletions.
Binary file modified bin/randopackage/RandochooseMain$1.class
Binary file not shown.
Binary file modified bin/randopackage/RandochooseMain$2.class
Binary file not shown.
Binary file modified bin/randopackage/RandochooseMain$3.class
Binary file not shown.
Binary file modified bin/randopackage/RandochooseMain$4.class
Binary file not shown.
Binary file modified bin/randopackage/RandochooseMain$5.class
Binary file not shown.
Binary file modified bin/randopackage/RandochooseMain$6.class
Binary file not shown.
Binary file added bin/randopackage/RandochooseMain$7.class
Binary file not shown.
Binary file added bin/randopackage/RandochooseMain$8.class
Binary file not shown.
Binary file added bin/randopackage/RandochooseMain$9.class
Binary file not shown.
Binary file modified bin/randopackage/RandochooseMain.class
Binary file not shown.
7 changes: 6 additions & 1 deletion doc/Changelog English.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Randochoose 2022.10.0
- Completion: 30th October, 2022
- You can now choose between normal and group randomization.
- In group randomization, you can control the maximum size of a group (between 2 and 8 are supported) and the results are shown in a table.

Randochoose 2022.9.0
- Not yet complete
- Completion: September 2022
- Randochoose 0.2.x and older just picked from the candidates you typed in. That wasn't the best solution - that's why I'm happy to announce that the randomizing algorithm is a bit more complex now. Starting with this version of Randochoose, the list will be shuffled as many times as the number of your candidates before they are chosen.
- Also, the versioning scheme has been changed from x.y.z (0.2.x and older) to y.m.r (like 2022.9.0, 2022.9.1 etc.). y is the year, m the month and r tells you if it is the first/second/... release within a month.
- README.md has been corrected and updated.
Expand Down
271 changes: 243 additions & 28 deletions src/randopackage/RandochooseMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
import java.io.File;
import java.util.concurrent.*;
import java.util.*;
import java.util.List;

public class RandochooseMain {

public static int majorVer = 2022;
public static int minorVer1 = 9;
public static int minorVer1 = 10;
public static int minorVer2 = 0;
public static int verCode = 8;
public static int verCode = 9;
static boolean groupModeSelected = false;
static int maxCandidatesInGroup = 2;

public static void main(String[] args) {
public static void main(String[] args) {
String link = "https://raw.githubusercontent.com/Tech-FZ/randochoose/main/vercheck.rdc";
String link2 = "https://codeberg.org/lucien-rowan/randochoose/raw/branch/main/vercheck.rdc";
File out = new File("vercheck.rdc");
Expand All @@ -27,7 +30,7 @@ public static void main(String[] args) {
mainFrame.setMinimumSize(mainFrame.getSize());
mainFrame.setLocationRelativeTo(null);

JPanel mainPanel = new JPanel(new GridLayout(3, 0, 10, 10));
JPanel mainPanel = new JPanel(new GridLayout(0, 1, 10, 10));

/*JLabel alphaLabel = new JLabel("This program is an alpha! Major issues expected.");
alphaLabel.setFont(new Font("Arial", 0, 14));
Expand All @@ -37,6 +40,72 @@ public static void main(String[] args) {
noticeLabel.setFont(new Font("Arial", 0, 20));
mainPanel.add(noticeLabel);

JRadioButton normalMode = new JRadioButton();
JRadioButton groupMode = new JRadioButton();
ButtonGroup randomizerGroup = new ButtonGroup();

JSpinner groupModeSpinner = new JSpinner();
groupModeSpinner.setEnabled(false);

normalMode.setText("Normal randomization");
groupMode.setText("Randomize candidates into groups");

normalMode.addItemListener(new ItemListener() {

@Override
public void itemStateChanged(ItemEvent e) {
if (e.getSource() == normalMode) {
if (e.getStateChange() == 1) {
groupModeSpinner.setEnabled(false);
groupModeSelected = false;
}
}
else if (e.getSource() == groupMode) {
if (e.getStateChange() == 1) {
groupModeSpinner.setEnabled(true);
groupModeSelected = true;
}
}
}
});

groupMode.addItemListener(new ItemListener() {

@Override
public void itemStateChanged(ItemEvent e) {
if (e.getSource() == normalMode) {
if (e.getStateChange() == 1) {
groupModeSpinner.setEnabled(false);
groupModeSelected = false;
}
}
else if (e.getSource() == groupMode) {
if (e.getStateChange() == 1) {
groupModeSpinner.setEnabled(true);
groupModeSelected = true;
}
}
}
});

mainPanel.add(normalMode);
mainPanel.add(groupMode);

randomizerGroup.add(normalMode);
randomizerGroup.add(groupMode);

normalMode.setSelected(true);

JPanel groupModeSettingsPanel = new JPanel(new GridLayout(1, 2, 10, 10));

JLabel groupModeLbl = new JLabel("Group mode only: How many in one group?");
groupModeLbl.setFont(new Font("Arial", 0, 12));
groupModeSettingsPanel.add(groupModeLbl);

groupModeSettingsPanel.add(groupModeSpinner);

mainPanel.add(groupModeSettingsPanel);

JPanel textPanel = new JPanel(new GridLayout(1, 2, 10, 10));

JTextArea randomizerText = new JTextArea();
Expand All @@ -57,6 +126,7 @@ public static void main(String[] args) {

chooseCandidateBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
maxCandidatesInGroup = (int) groupModeSpinner.getValue();
scanTxtField(randomizerText.getText());
}
});
Expand Down Expand Up @@ -102,6 +172,7 @@ public static void scanTxtField(String candidates) {
}

catch (Exception e) {
e.printStackTrace();
noEntries();
}
}
Expand Down Expand Up @@ -157,32 +228,176 @@ public static void randomizedChoice(String[] candidates) {
// Prints the random array
System.out.println(Arrays.toString(candidates));

int randomizedInt = ThreadLocalRandom.current().nextInt(0, candidates.length);
String chosenCandidate = candidates[randomizedInt];

JDialog noEntryDialog = new JDialog();
noEntryDialog.setTitle("Randochoose");

JPanel noEntryPanel = new JPanel(new GridLayout(2, 1, 10, 10));

JLabel noticeLabel = new JLabel(chosenCandidate + " has been chosen.");
noticeLabel.setFont(new Font("Arial", 0, 16));
noEntryPanel.add(noticeLabel);

JButton okBtn = new JButton("OK!");
okBtn.setFont(new Font("Arial", 0, 14));

okBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
noEntryDialog.setVisible(false);
if (groupModeSelected == false) {
int randomizedInt = ThreadLocalRandom.current().nextInt(0, candidates.length);
String chosenCandidate = candidates[randomizedInt];

JDialog noEntryDialog = new JDialog();
noEntryDialog.setTitle("Randochoose");

JPanel noEntryPanel = new JPanel(new GridLayout(2, 1, 10, 10));

JLabel noticeLabel = new JLabel(chosenCandidate + " has been chosen.");
noticeLabel.setFont(new Font("Arial", 0, 16));
noEntryPanel.add(noticeLabel);

JButton okBtn = new JButton("OK!");
okBtn.setFont(new Font("Arial", 0, 14));

okBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
noEntryDialog.setVisible(false);
}
});

noEntryPanel.add(okBtn);

noEntryDialog.add(noEntryPanel);
noEntryDialog.pack();
noEntryDialog.setVisible(true);
}

else {
JDialog noEntryDialog = new JDialog();
noEntryDialog.setTitle("Randochoose");

JPanel noEntryPanel = new JPanel(new GridLayout(0, 1, 10, 10));

JLabel noticeLabel = new JLabel("These are the groups.");
noticeLabel.setFont(new Font("Arial", 0, 16));
noEntryPanel.add(noticeLabel);

JPanel tablePanel = new JPanel(new GridLayout(0, 2, 10, 10));

Object[] columns = new Object[maxCandidatesInGroup];
Object[][] groups = new Object[(int) Math.ceil(candidates.length / maxCandidatesInGroup) + 1][maxCandidatesInGroup];
System.out.println((int) Math.ceil(candidates.length / maxCandidatesInGroup));

for (int i = 1; i <= maxCandidatesInGroup; i++) {
columns[i - 1] = String.valueOf(groupModeSelected);
}

int k = 0;

for (int i = 0; i < candidates.length; i+=maxCandidatesInGroup) {
Object[] tempObj = new Object[maxCandidatesInGroup];
for (int j = 0; j < maxCandidatesInGroup; j++) {
try {
tempObj[j] = candidates[i+j];
}
catch (Exception e) {
try {
tempObj[j] = candidates[i+j];
}
catch (Exception e1) {
try {
tempObj[j] = candidates[i+j];
}
catch (Exception e2) {
if (candidates.length % maxCandidatesInGroup != 0) {
tempObj[j] = "";
}
}
}
}
}
groups[k] = tempObj;
k++;
}

int alreadyAssigned = 0;
Object[] alreadyAssignedCandidates = new Object[candidates.length];

for (Object[] group : groups) {
for (Object object : group) {
System.out.println(object);

/*if (object == null) {
for (int i = 0; i < groups.length; i++) {
if (groups[i] == group) {
for (int j = 0; j < group.length; j++) {
if (groups[i][j] == object) {
for (int k1 = 0; k1 < candidates.length; k1++) {
for (int l = 0; l < alreadyAssignedCandidates.length; l++) {
if (candidates[k1] != alreadyAssignedCandidates[l]) {
groups[i][j] = candidates[k1];
break;
}
}
}
}
}
}
}
}
if (object != null) {
alreadyAssignedCandidates[alreadyAssigned] = object;
alreadyAssigned++;
}*/
}
}
});

noEntryPanel.add(okBtn);

List<String> candidateAsList = new ArrayList<>(Arrays.asList(candidates));
int posInCandidateObj = 0;
int posInCandidateObj2 = 0;

for (int i = 0; i < groups.length; i++) {
for (int j = 0; j < groups[i].length; j++) {
if (groups[i][j] == null) {
for (int l = 0; l < candidates.length; l++) {
for (Object[] group : groups) {
for (Object object : group) {
if (object != candidates[l] && candidateAsList.contains(object) == false) {
boolean candidateAlreadyPresent = false;
for (int m = 0; m < groups.length; m++) {
for (int n = 0; n < groups[m].length; n++) {
if (groups[m][n] == candidates[l]) {
candidateAlreadyPresent = true;
}
posInCandidateObj = n;
}
posInCandidateObj2 = m;

if (candidateAlreadyPresent == false) {
groups[i][j] = candidates[l];
}
}
}
}
}
}
}
}
}


JTable table = new JTable(groups, columns);

JScrollPane scrollPane = new JScrollPane(table);
table.setFillsViewportHeight(true);

tablePanel.add(table);
tablePanel.add(scrollPane);

noEntryPanel.add(tablePanel);

JButton okBtn = new JButton("OK!");
okBtn.setFont(new Font("Arial", 0, 14));

okBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
noEntryDialog.setVisible(false);
}
});

noEntryPanel.add(okBtn);

noEntryDialog.add(noEntryPanel);
noEntryDialog.pack();
noEntryDialog.setVisible(true);
}

noEntryDialog.add(noEntryPanel);
noEntryDialog.pack();
noEntryDialog.setVisible(true);
}

public static void aboutThisSoftware() {
Expand Down

0 comments on commit 6fa3365

Please sign in to comment.