size limit on list

This commit is contained in:
Joseph Garcia 2020-12-18 17:12:32 -06:00
parent 8d711734da
commit 3674d63d0c
2 changed files with 25 additions and 19 deletions

View File

@ -77,10 +77,9 @@ public class ConfigFile {
public static void addObjectToCommList(JSONObject jsonObject) { public static void addObjectToCommList(JSONObject jsonObject) {
ArrayList<JSONObject> commListCopy = MacroButtons.getMasterCommList(); ArrayList<JSONObject> commListCopy = MacroButtons.getMasterCommList();
if (commListCopy.size() <= 20) { commListCopy.add(jsonObject);
commListCopy.add(jsonObject); MacroButtons.setMasterCommList(commListCopy);
MacroButtons.setMasterCommList(commListCopy);
}
} }
} }

View File

@ -35,6 +35,7 @@ public class ButtonGUI extends LightweightGuiDescription {
private void addCommandSection(WGridPanel root) { private void addCommandSection(WGridPanel root) {
// Add text field for command NAME entry // Add text field for command NAME entry
WTextField nameTextField = new WTextField(); WTextField nameTextField = new WTextField();
nameTextField.setMaxLength(10);
nameTextField.setSuggestion("Name"); nameTextField.setSuggestion("Name");
root.add(nameTextField, 0, 12, 6, 1); root.add(nameTextField, 0, 12, 6, 1);
@ -57,23 +58,25 @@ public class ButtonGUI extends LightweightGuiDescription {
// Only add the button if there are contents in both // Only add the button if there are contents in both
if (!name.getText().equals("") && !command.getText().equals("")) { if (!name.getText().equals("") && !command.getText().equals("")) {
String commandString = command.getText(); if (!isListTooLong()) {
WButton button = new WButton(new TranslatableText(name.getText())); String commandString = command.getText();
button.setOnClick(() -> { WButton button = new WButton(new TranslatableText(name.getText()));
MacroButtons.runCommand(commandString); button.setOnClick(() -> {
}); MacroButtons.runCommand(commandString);
root.add(button, xValue, yValue, 4, 1); });
root.add(button, xValue, yValue, 4, 1);
// Create a new Json object & append to masterCommList // Create a new Json object & append to masterCommList
JSONObject newJsonObject = new JSONObject(); JSONObject newJsonObject = new JSONObject();
newJsonObject.put("name", name.getText()); newJsonObject.put("name", name.getText());
newJsonObject.put("command", command.getText()); newJsonObject.put("command", command.getText());
// append the buttons to masterList for future loading // append the buttons to masterList for future loading
ConfigFile.addObjectToCommList(newJsonObject); ConfigFile.addObjectToCommList(newJsonObject);
ConfigFile.appendToFile(newJsonObject); ConfigFile.appendToFile(newJsonObject);
adjustBounds(); adjustBounds();
}
name.setText(""); name.setText("");
command.setText(""); command.setText("");
@ -127,6 +130,10 @@ public class ButtonGUI extends LightweightGuiDescription {
} }
} }
private boolean isListTooLong() {
return MacroButtons.getMasterCommList().size() > 19;
}
// Change background panel color to transparent black // Change background panel color to transparent black
@Override @Override
public void addPainters() { public void addPainters() {