-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor gui, cli, and pruner into individual files
Signed-off-by: Christopher White <[email protected]>
- Loading branch information
1 parent
612228c
commit 9a0f4c5
Showing
5 changed files
with
195 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package oc.tc.autopruner; | ||
|
||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.CommandLineParser; | ||
import org.apache.commons.cli.DefaultParser; | ||
import org.apache.commons.cli.HelpFormatter; | ||
import org.apache.commons.cli.Option; | ||
import org.apache.commons.cli.Options; | ||
import org.apache.commons.cli.ParseException; | ||
|
||
import java.io.File; | ||
|
||
public class AutoPrunerCLIMain { | ||
public static void main(String[] args) { | ||
CommandLine cmd = processOptions(args); | ||
if (cmd == null) return; | ||
|
||
if (cmd.hasOption("file")) { | ||
String filePath = cmd.getOptionValue("file"); | ||
AutoPruner.pruneMCAFileLogger(filePath); | ||
} else if (cmd.hasOption("directory")) { | ||
String directoryPath = cmd.getOptionValue("directory"); | ||
AutoPruner.recursivelyProcessFiles(new File(directoryPath), 0); | ||
} else { | ||
new AutoPrunerGui().buildAndRunGui(); | ||
} | ||
} | ||
|
||
private static CommandLine processOptions(String[] args) { | ||
Options options = new Options(); | ||
|
||
Option fileOption = new Option( | ||
"f", | ||
"file", | ||
true, | ||
"Path for .mca file to prune"); | ||
fileOption.setRequired(false); | ||
options.addOption(fileOption); | ||
|
||
Option directoryOption = new Option( | ||
"d", | ||
"directory", | ||
true, | ||
"Path for directory containing .mca files"); | ||
directoryOption.setRequired(false); | ||
options.addOption(directoryOption); | ||
|
||
CommandLineParser parser = new DefaultParser(); | ||
HelpFormatter formatter = new HelpFormatter(); | ||
try { | ||
return parser.parse(options, args); | ||
} catch (ParseException e) { | ||
System.out.println(e.getMessage()); | ||
formatter.printHelp("java -jar AutoPruner.jar", options); | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package oc.tc.autopruner; | ||
|
||
import com.formdev.flatlaf.FlatLightLaf; | ||
|
||
import javax.swing.JFileChooser; | ||
import javax.swing.JFrame; | ||
import javax.swing.JScrollPane; | ||
import javax.swing.JTextArea; | ||
import javax.swing.SwingUtilities; | ||
import javax.swing.SwingWorker; | ||
import java.awt.Dimension; | ||
import java.io.File; | ||
|
||
public class AutoPrunerGui { | ||
|
||
//TODO: Refactor and improve this class | ||
|
||
public AutoPrunerGui() { | ||
FlatLightLaf.setup(); | ||
} | ||
|
||
public void buildAndRunGui() { | ||
SwingUtilities.invokeLater(() -> { | ||
JFrame frame = new JFrame("AutoPruner"); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
|
||
JTextArea textArea = new JTextArea(); | ||
textArea.setEditable(false); | ||
|
||
JScrollPane areaScrollPane = new JScrollPane(textArea); | ||
areaScrollPane.setVerticalScrollBarPolicy( | ||
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); | ||
areaScrollPane.setPreferredSize(new Dimension(900, 400)); | ||
|
||
frame.add(areaScrollPane); | ||
frame.pack(); | ||
frame.setVisible(true); | ||
|
||
JFileChooser fc = new JFileChooser(); | ||
fc.setCurrentDirectory(new File("")); | ||
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); | ||
int option = fc.showDialog(frame, "Prune Map(s)"); | ||
|
||
if (option == JFileChooser.APPROVE_OPTION) { | ||
File file = fc.getSelectedFile(); | ||
textArea.append("Selected: " + file.getAbsolutePath() + "\n"); | ||
|
||
new SwingWorker() { | ||
@Override | ||
protected Object doInBackground() { | ||
return AutoPruner.recursivelyProcessFiles( | ||
file, | ||
28, | ||
(message) -> textArea.append(message + "\n")); | ||
} | ||
}.execute(); | ||
} else { | ||
System.exit(0); | ||
} | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.