Skip to content

Commit

Permalink
A shocking update!
Browse files Browse the repository at this point in the history
Made IO static because instancing it is pointless, some minor cleaning, and split the refresh button so you don't wipe the entire board when trying to reload just one (as well as changing the default width to acomadate the new buttons). Next up: Tournament name and current round options to fill the void in the middle
  • Loading branch information
Hay1tsme committed May 8, 2019
1 parent 1f44f1c commit a47dea6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 84 deletions.
2 changes: 1 addition & 1 deletion cfg/sb.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"width": 500,
"width": 550,
"height": 300,
"x": 500,
"y": 500
Expand Down
5 changes: 2 additions & 3 deletions src/me/hay1ts/sbtxt/Boot.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
* Main class, handles creating the initial GUI as well as initialization
*/
public class Boot {
public static IO io = new IO();
public static Main m = new Main();
public static String ver = "1.0.0";
public static String ver = "1.1.0";
public static void main(String[] args) {
if (io.init()) {
if (IO.init()) {
m.show();
}
}
Expand Down
61 changes: 21 additions & 40 deletions src/me/hay1ts/sbtxt/IO.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
package me.hay1ts.sbtxt;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;

import javax.swing.*;
import java.io.*;
import java.nio.file.Files;

//TODO: Allow the config file to be written to on resizing and moving the window
//TODO: Make new fields for tournament name and current round

/**
* Handles all file IO, including loading the config
* file and updating the text files
*/
public class IO {
public int width = 500;
public int height = 300;
public int x = 300;
public int y = 100;
public static int width = 550;
public static int height = 300;
public static int x = 300;
public static int y = 100;

private String cfgS;
private static String cfgS;

private File cfgF = new File("./cfg/sb.json");
public File p1 = new File("./txt/p1.txt");
public File p2 = new File("./txt/p2.txt");
public File c1 = new File("./txt/c1.txt");
public File c2 = new File("./txt/c2.txt");
public File players = new File("./txt/players.txt");
public File casters = new File("./txt/casters.txt");
private static File cfgF = new File("./cfg/sb.json");
public static File p1 = new File("./txt/p1.txt");
public static File p2 = new File("./txt/p2.txt");
public static File c1 = new File("./txt/c1.txt");
public static File c2 = new File("./txt/c2.txt");
public static File players = new File("./txt/players.txt");
public static File casters = new File("./txt/casters.txt");

public IO() {
}
Expand All @@ -36,8 +37,7 @@ public IO() {
* Initial file reading, checks for the presence of the config file as well as the other text files
* @return true if init passed without issues, false if unrecoverable error
*/
public boolean init() {
//TODO: Fix config file loading, it doesn't work right now but at least the rest of the files work
public static boolean init() {
System.out.println("Loading configuration file...");
try {
cfgS = new String(Files.readAllBytes(cfgF.toPath()));
Expand All @@ -64,7 +64,7 @@ public boolean init() {
System.out.println("Writing to new config file");
BufferedWriter w = new BufferedWriter(new FileWriter(cfgF, true));
w.append("{\n" +
" \"width\": 500,\n" +
" \"width\": 550,\n" +
" \"height\": 300,\n" +

" \"x\": 500,\n" +
Expand Down Expand Up @@ -92,7 +92,7 @@ public boolean init() {
return true;
}

private void findFiles (File f) {
private static void findFiles (File f) {
System.out.println("Looking for file " + f.getName());
if(!f.exists()) {
System.out.println("No " + f.getName() + " file found, creating...");
Expand Down Expand Up @@ -120,7 +120,7 @@ private void findFiles (File f) {
* @param f Text file to read from
* @return Array of names on success, null on fail
*/
public String[] updateR(File f) {
public static String[] updateR(File f) {
System.out.println("Reading from file " + f.getName());
String[] fa;
try {
Expand All @@ -140,7 +140,7 @@ public String[] updateR(File f) {
* @param s Text to write to file
* @return String on error, null on success
*/
public void updateW(File f, String s) {
public static void updateW(File f, String s) {
System.out.println("Writing " + s + " to " + f.getName());
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(f.toPath().toString()));
Expand All @@ -152,33 +152,14 @@ public void updateW(File f, String s) {
}
}

/**
* Loads the configuration file and sets the properties accordingly
* @param f configuration file to load
*/
public void loadCfg(File f) {
//TODO: Load config file, set values
}

/**
* Writes changes to the config file
* @param f Config file
* @param key key to be changed
* @param val value to change the key to
*/
public void writeCfg(File f, String key, String val) {
public static void writeCfg(File f, String key, String val) {
//TODO: Load config file, find the key, write the new value
}

/**
*
* @param f File to get text from
* @return The file contents in an array, separated by newline
*/
public String[] reload(File f) {
//TODO: Read file, seperate by newline, add to array, return array
String[] cts = {};
return cts;
}

}
45 changes: 30 additions & 15 deletions src/me/hay1ts/sbtxt/Main.form
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@
<grid row="1" column="6" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<vspacer id="7340c">
<constraints>
<grid row="5" column="3" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="b7745" class="javax.swing.JLabel" binding="lblP1">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
Expand Down Expand Up @@ -104,15 +99,6 @@
</constraints>
<properties/>
</component>
<component id="31c18" class="javax.swing.JButton" binding="btnRefresh">
<constraints>
<grid row="6" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Refresh Lists"/>
<toolTipText value="Refresh the caster and player lists"/>
</properties>
</component>
<vspacer id="d505c">
<constraints>
<grid row="8" column="3" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
Expand Down Expand Up @@ -148,13 +134,42 @@
</component>
<component id="67d3b" class="javax.swing.JButton" binding="btnPush">
<constraints>
<grid row="7" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="7" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<maximum-size width="270" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Force Push"/>
<toolTipText value="Force push to text files"/>
</properties>
</component>
<component id="35a0a" class="javax.swing.JButton" binding="btnRefreshP">
<constraints>
<grid row="6" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<maximum-size width="130" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Refresh Players"/>
<toolTipText value="Refresh player list"/>
</properties>
</component>
<vspacer id="7340c">
<constraints>
<grid row="5" column="3" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="31c18" class="javax.swing.JButton" binding="btnRefreshC">
<constraints>
<grid row="6" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<maximum-size width="130" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Refresh Casters"/>
<toolTipText value="Refresh caster list"/>
</properties>
</component>
</children>
</grid>
</form>
45 changes: 20 additions & 25 deletions src/me/hay1ts/sbtxt/Main.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package me.hay1ts.sbtxt;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;

//TODO: Add refresh buttons to pull players and casters from the text files without needing a restart
/**
* Handles all window operations including showing
* the window and updating the components
Expand All @@ -30,55 +24,56 @@ public class Main {
private JLabel lblC1;
private JLabel lblC2;

private JButton btnRefresh;
private JButton btnRefreshC;
private JButton btnPush;
private JButton btnRefreshP;

private String[] players;
private String[] casters;

private String er;

public Main() {
btnRefresh.addActionListener(e -> {
public Main() {
btnRefreshC.addActionListener(e -> {
updateCList();
updatePList();
});
btnPush.addActionListener(e -> {
Boot.io.updateW(Boot.io.c1, (String)jcbC1.getSelectedItem());
Boot.io.updateW(Boot.io.c2, (String)jcbC2.getSelectedItem());
Boot.io.updateW(Boot.io.p1, jcbP1.getSelectedItem() + " - " + jspP1s.getValue());
Boot.io.updateW(Boot.io.p2, jcbP2.getSelectedItem() + " - " + jspP2s.getValue());
IO.updateW(IO.c1, (String)jcbC1.getSelectedItem());
IO.updateW(IO.c2, (String)jcbC2.getSelectedItem());
IO.updateW(IO.p1, jcbP1.getSelectedItem() + " - " + jspP1s.getValue());
IO.updateW(IO.p2, jcbP2.getSelectedItem() + " - " + jspP2s.getValue());
});
jcbP1.addActionListener(e -> {
if (jcbP1.getSelectedItem() != null) {
Boot.io.updateW(Boot.io.p1, jcbP1.getSelectedItem() + " - " + jspP1s.getValue());
IO.updateW(IO.p1, jcbP1.getSelectedItem() + " - " + jspP1s.getValue());
}
});
jspP1s.addChangeListener(e -> {
if (jcbP1.getSelectedItem() != null) {
Boot.io.updateW(Boot.io.p1, jcbP1.getSelectedItem() + " - " + jspP1s.getValue());
IO.updateW(IO.p1, jcbP1.getSelectedItem() + " - " + jspP1s.getValue());
}
});
jcbP2.addActionListener(e -> {
if (jcbP2.getSelectedItem() != null) {
Boot.io.updateW(Boot.io.p2, jcbP2.getSelectedItem() + " - " + jspP2s.getValue());
IO.updateW(IO.p2, jcbP2.getSelectedItem() + " - " + jspP2s.getValue());
}
});
jspP2s.addChangeListener(e -> {
if (jcbP2.getSelectedItem() != null) {
Boot.io.updateW(Boot.io.p2, jcbP2.getSelectedItem() + " - " + jspP2s.getValue());
IO.updateW(IO.p2, jcbP2.getSelectedItem() + " - " + jspP2s.getValue());
}
});
jcbC1.addActionListener(e -> {
if (jcbC1.getSelectedItem() != null) {
Boot.io.updateW(Boot.io.c1, (String)jcbC1.getSelectedItem());
IO.updateW(IO.c1, (String)jcbC1.getSelectedItem());
}
});
jcbC2.addActionListener(e -> {
if (jcbC2.getSelectedItem() != null) {
Boot.io.updateW(Boot.io.c2, (String) jcbC2.getSelectedItem());
IO.updateW(IO.c2, (String) jcbC2.getSelectedItem());
}
});
btnRefreshP.addActionListener(e -> {
updatePList();
});
}

/**
Expand All @@ -88,14 +83,14 @@ public void show() {
jfrMain = new JFrame("ScoreboardTXT ver. " + Boot.ver);
jfrMain.setContentPane(jpnMain);
jfrMain.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jfrMain.setBounds(Boot.io.x,Boot.io.y, Boot.io.width, Boot.io.height);
jfrMain.setBounds(IO.x,IO.y, IO.width, IO.height);
jfrMain.setVisible(true);
updatePList();
updateCList();
}

private void updateCList(){
casters = Boot.io.updateR(Boot.io.casters);
casters = IO.updateR(IO.casters);

jcbC1.removeAllItems();
jcbC1.addItem("");
Expand All @@ -111,7 +106,7 @@ private void updateCList(){
}

private void updatePList() {
players = Boot.io.updateR(Boot.io.players);
players = IO.updateR(IO.players);
jcbP1.removeAllItems();
jcbP1.addItem("");
for (String s : players) {
Expand Down

0 comments on commit a47dea6

Please sign in to comment.