Skip to content
This repository has been archived by the owner on Apr 10, 2023. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
QuadratClown committed May 7, 2020
1 parent 4e53ce6 commit c798fbe
Show file tree
Hide file tree
Showing 9 changed files with 1,194 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-9">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="con" path="org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bin
out
.settings
.idea
/.project
24 changes: 24 additions & 0 deletions BracketGenerator.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="file://C:/Program Files/Java/javafx-sdk-11.0.1/lib" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://C:/Program Files/Java/javafx-sdk-11.0.1/lib" />
</SOURCES>
<jarDirectory url="file://C:/Program Files/Java/javafx-sdk-11.0.1/lib" recursive="false" />
<jarDirectory url="file://C:/Program Files/Java/javafx-sdk-11.0.1/lib" recursive="false" type="SOURCES" />
</library>
</orderEntry>
</component>
</module>
3 changes: 3 additions & 0 deletions src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: bracketgen.BracketGeneratorGUI

126 changes: 126 additions & 0 deletions src/bracketgen/BracketGeneratorGUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package bracketgen;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;

import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.Spinner;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Duration;

public class BracketGeneratorGUI extends Application {

int rounds = 0;
boolean DE = false;
String game = "";

public static void main(String[] args) {
launch();
}

@Override
public void start(Stage primaryStage) {
VBox wrap = new VBox();
wrap.setSpacing(10);
wrap.setPadding(new Insets(10));
BorderPane header_wrap = new BorderPane();
HBox header = new HBox();
header.setAlignment(Pos.CENTER_LEFT);
header.setSpacing(10);
Button apply = new Button("Apply");
TextField gameField = new TextField();
gameField.setMinWidth(200);
gameField.setPromptText("Game (e.g. \"rocketleague\")");
Button copyToClipboard = new Button("Copy to Clipboard");
copyToClipboard.setDisable(true);
Spinner<Integer> spinner = new Spinner<>(1, 10, 1);
CheckBox deBox = new CheckBox();
header.getChildren().addAll(new Label("Number of rounds:"), spinner, new Label("Double Elimination"), deBox,
gameField, apply, copyToClipboard);
ScrollPane content = new ScrollPane();
content.setPadding(new Insets(5, 0, 5, 0));
content.setStyle("-fx-background-color:transparent");
header_wrap.setLeft(header);
wrap.getChildren().addAll(header_wrap, content);

// handle apply
apply.setOnAction(e -> {
if (gameField.getText().equals("")) {
Timeline t = new Timeline(60,
new KeyFrame(Duration.seconds(0), new KeyValue(apply.textProperty(), "Please set a game first"),
new KeyValue(apply.disableProperty(), true)),
new KeyFrame(Duration.seconds(0.5), new KeyValue(apply.textProperty(), "Apply"),
new KeyValue(apply.disableProperty(), false)));
t.play();
} else {
rounds = spinner.getValue();
DE = deBox.isSelected();
game = gameField.getText();
copyToClipboard.setDisable(false);
content.setContent(LuaBracketRound.newBracket(rounds, DE, game));
}
});

// handle copy to Clipboard
copyToClipboard.setOnAction(e -> {
StringBuilder s = new StringBuilder();
int[] offset = new int[LuaBracketRound.ROUNDS_UPPER.size()];
int i = 0;
for (LuaBracketRound r : LuaBracketRound.ROUNDS_UPPER) {
s.append(r.toWikiCode(0));
offset[i] = r.matchCount;
i++;
}
i = 0;
for (LuaBracketRound r : LuaBracketRound.ROUNDS_LOWER) {
if (i >= LuaBracketRound.ROUNDS_UPPER.size()) {
break;
}
s.append(r.toWikiCode(i < offset.length ? offset[i] : 0));
i++;
}
if (!LuaBracketRound.ROUNDS_LOWER.isEmpty()) {
s.append((LuaBracketRound.ROUNDS_LOWER.get(LuaBracketRound.ROUNDS_LOWER.size() - 1))
.toWikiCode(i + 1));
} else {
s.append("{{#invoke:Bracket|BracketEnd}}\n");
}
StringSelection stringSelection = new StringSelection(s.toString());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);
});

//initialize stage and scene
primaryStage.setTitle("Lua Bracket Helper v 0.2");

Scene scene = new Scene(wrap, 1280, 720);
scene.getStylesheets().add(getClass().getResource("bracketstyle.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("bracketgen.png")));
primaryStage.show();

header_wrap.setPadding(new Insets(30, 0, 0, 0));
content.setPrefHeight(10000);
content.setPannable(true);
wrap.setPrefHeight(10000);
wrap.setPrefWidth(10000);
wrap.setStyle("-fx-background-color: -fx-background;");
}

}
Loading

0 comments on commit c798fbe

Please sign in to comment.