Skip to content

Commit

Permalink
message editor fix + dialog creation refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
z64a committed Apr 27, 2024
1 parent 34ce9f3 commit 099dd0e
Show file tree
Hide file tree
Showing 44 changed files with 2,402 additions and 2,014 deletions.
2 changes: 1 addition & 1 deletion .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line=one_line_if_e
org.eclipse.jdt.core.formatter.keep_record_declaration_on_one_line=one_line_if_empty
org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false
org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false
org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=true
org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false
org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false
org.eclipse.jdt.core.formatter.keep_switch_body_block_on_one_line=one_line_never
org.eclipse.jdt.core.formatter.keep_switch_case_with_arrow_on_one_line=one_line_never
Expand Down
2 changes: 1 addition & 1 deletion .vscode/eclipse-format.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_additive_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case_after_arrow" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
Expand Down
2 changes: 1 addition & 1 deletion app.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.9.1
version=0.9.2
108 changes: 68 additions & 40 deletions src/main/java/app/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@ private static enum OSFamily
private static String gitBuildTag;

public static boolean isDeluxe()
{ return isDeluxe; }
{
return isDeluxe;
}

public static String getVersionString()
{ return versionString; }
{
return versionString;
}

public static String decorateTitle(String title)
{
Expand Down Expand Up @@ -239,7 +243,9 @@ public static void exit(int status)
}

public static boolean isCommandLine()
{ return commandLine; }
{
return commandLine;
}

public static File getWorkingDirectory()
{
Expand All @@ -250,10 +256,14 @@ public static File getWorkingDirectory()
}

public static File getProjectDirectory()
{ return projectDirectory; }
{
return projectDirectory;
}

public static File getSourceDirectory()
{ return new File(projectDirectory, "/src/"); }
{
return new File(projectDirectory, "/src/");
}

public static File getProjectFile(String relativePath)
{
Expand All @@ -277,11 +287,11 @@ public static void checkForUpdate()

if (!latestVersion.equals("v" + versionString)) {
Logger.log("Detected newer remote version: " + latestVersion);
SwingUtils.showFramedMessageDialog(null,
"A newer version is available!\n" +
"Please visit the GitHub repo to download it.",
"Update Available",
JOptionPane.WARNING_MESSAGE);

SwingUtils.getWarningDialog()
.setTitle("Update Available")
.setMessage("A newer version is available!", "Please visit the GitHub repo to download it.")
.show();
}
}
else {
Expand All @@ -299,12 +309,13 @@ private static final void checkForDependencies() throws IOException
File db = Directories.DATABASE.toFile();

if (!db.exists() || !db.isDirectory()) {
SwingUtils.showFramedMessageDialog(null,
"Could not find required directory: " + db.getName() + System.lineSeparator() +
"It should be in the same directory as StarRod.jar" + System.lineSeparator() +
"Did you extract ALL the files for Star Rod?",
"Missing Directory",
JOptionPane.ERROR_MESSAGE);
SwingUtils.getMessageDialog()
.setTitle("Missing Directory")
.setMessage("Could not find required directory: " + db.getName(),
"It should be in the same directory as the jar.")
.setMessageType(JOptionPane.ERROR_MESSAGE)
.show();

exit();
}
}
Expand All @@ -315,21 +326,23 @@ private static final File readMainConfig() throws IOException

// we may need to create a new config file here
if (!configFile.exists()) {
int choice = SwingUtils.showFramedConfirmDialog(null,
String.format("Could not find Star Rod config! %nCreate a new one?"),
"Missing Config",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
int choice = SwingUtils.getConfirmDialog()
.setTitle("Missing Config")
.setMessage("Could not find Star Rod config!", "Create a new one?")
.setMessageType(JOptionPane.QUESTION_MESSAGE)
.setOptionsType(JOptionPane.YES_NO_OPTION)
.choose();

if (choice != JOptionPane.OK_OPTION)
exit();

mainConfig = makeConfig(configFile, Scope.Main);

SwingUtils.showFramedMessageDialog(null,
"Select your project directory.",
"Select Project Directory",
JOptionPane.PLAIN_MESSAGE);
SwingUtils.getMessageDialog()
.setTitle("Select Project Directory")
.setMessage("Select your project directory.")
.setMessageType(JOptionPane.PLAIN_MESSAGE)
.show();

return promptSelectProject();
}
Expand All @@ -353,10 +366,10 @@ private static final File readMainConfig() throws IOException
}

// project directory is missing, prompt to select new one
SwingUtils.showFramedMessageDialog(null,
String.format("Could not find project directory! %nPlease select a new one."),
"Missing Project Directory",
JOptionPane.ERROR_MESSAGE);
SwingUtils.getErrorDialog()
.setTitle("Missing Project Directory")
.setMessage("Could not find project directory!", "Please select a new one.")
.show();

return promptSelectProject();
}
Expand Down Expand Up @@ -384,7 +397,10 @@ private static void showErrorMessage(String title, String fmt, Object ... args)
if (isCommandLine())
Logger.logError(message);
else
SwingUtils.showFramedMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
SwingUtils.getErrorDialog()
.setTitle(title)
.setMessage(message)
.show();
}

public static boolean loadProject(File projectDir) throws IOException
Expand Down Expand Up @@ -475,11 +491,13 @@ private static void readProjectConfig() throws IOException
File configFile = new File(projectDirectory, FN_PROJ_CONFIG);

if (!configFile.exists()) {
int choice = SwingUtils.showFramedConfirmDialog(null,
"Could not find project config!\nCreate a new one?",
"Missing Config",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);

int choice = SwingUtils.getConfirmDialog()
.setTitle("Missing Config")
.setMessage("Could not find project config!", "Create a new one?")
.setMessageType(JOptionPane.QUESTION_MESSAGE)
.setOptionsType(JOptionPane.YES_NO_OPTION)
.choose();

if (choice != JOptionPane.OK_OPTION)
exit();
Expand Down Expand Up @@ -545,13 +563,19 @@ private static List<File> getAssetDirs(File directory, File splatFile) throws IO
}

public static boolean isWindows()
{ return osFamily == OSFamily.Windows; }
{
return osFamily == OSFamily.Windows;
}

public static boolean isMacOS()
{ return osFamily == OSFamily.Mac; }
{
return osFamily == OSFamily.Mac;
}

public static boolean isLinux()
{ return osFamily == OSFamily.Linux; }
{
return osFamily == OSFamily.Linux;
}

public static void reloadIcons()
{
Expand All @@ -562,10 +586,14 @@ public static void reloadIcons()
}

public static final Image getDefaultIconImage()
{ return (ICON_DEFAULT == null) ? null : ICON_DEFAULT.getImage(); }
{
return (ICON_DEFAULT == null) ? null : ICON_DEFAULT.getImage();
}

public static final Image getErrorIconImage()
{ return (ICON_DEFAULT == null) ? null : ICON_DEFAULT.getImage(); }
{
return (ICON_DEFAULT == null) ? null : ICON_DEFAULT.getImage();
}

private static ImageIcon loadIconAsset(ExpectedAsset asset)
{
Expand Down
72 changes: 44 additions & 28 deletions src/main/java/app/RomValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ public class RomValidator
public static File validateROM(File f) throws IOException
{
if (f.length() != LENGTH) {
SwingUtils.showFramedMessageDialog(null,
"Selected file is not the correct size.",
"ROM Validation Error",
JOptionPane.ERROR_MESSAGE);
SwingUtils.getMessageDialog()
.setTitle("ROM Validation Error")
.setMessage("Selected file is not the correct size.")
.setMessageType(JOptionPane.ERROR_MESSAGE)
.show();

return null;
}

Expand Down Expand Up @@ -76,10 +78,11 @@ public static File validateROM(File f) throws IOException

if (v64 || n64 || x64) {
// just need to byteswap
SwingUtils.showFramedMessageDialog(null,
"Selected ROM has incorrect byte order.\nA corrected copy will be made.",
"ROM Validation Warning",
JOptionPane.WARNING_MESSAGE);
SwingUtils.getMessageDialog()
.setTitle("ROM Validation Warning")
.setMessage("Selected ROM has incorrect byte order.", "A corrected copy will be made.")
.setMessageType(JOptionPane.WARNING_MESSAGE)
.show();

pleaseWait.setVisible(true);

Expand Down Expand Up @@ -114,10 +117,13 @@ else if (x64)
}
else {
pleaseWait.setVisible(false);
SwingUtils.showFramedMessageDialog(null,
"Incorrect ROM or version, CRC does not match.",
"ROM Validation Failure",
JOptionPane.ERROR_MESSAGE);

SwingUtils.getMessageDialog()
.setTitle("ROM Validation Failure")
.setMessage("Incorrect ROM or version, CRC does not match.")
.setMessageType(JOptionPane.ERROR_MESSAGE)
.show();

raf.close();
return null;
}
Expand All @@ -129,19 +135,25 @@ else if (x64)
// now compute the checksum
if (!verifyCRCs(raf)) {
pleaseWait.setVisible(false);
SwingUtils.showFramedMessageDialog(null,
"ROM data does not match CRC values!",
"ROM Validation Failure",
JOptionPane.ERROR_MESSAGE);

SwingUtils.getMessageDialog()
.setTitle("ROM Validation Failure")
.setMessage("ROM data does not match CRC values!")
.setMessageType(JOptionPane.ERROR_MESSAGE)
.show();

return null;
}
}
else {
pleaseWait.setVisible(false);
SwingUtils.showFramedMessageDialog(null,
"Incorrect ROM or version, CRC does not match.",
"ROM Validation Failure",
JOptionPane.ERROR_MESSAGE);

SwingUtils.getMessageDialog()
.setTitle("ROM Validation Failure")
.setMessage("Incorrect ROM or version, CRC does not match.")
.setMessageType(JOptionPane.ERROR_MESSAGE)
.show();

raf.close();
return null;
}
Expand All @@ -162,18 +174,22 @@ else if (x64)
String fileMD5 = sb.toString();
if (!fileMD5.equals(MD5)) {
pleaseWait.setVisible(false);
SwingUtils.showFramedMessageDialog(null,
"MD5 hash does not match!",
"ROM Validation Failure",
JOptionPane.ERROR_MESSAGE);

SwingUtils.getMessageDialog()
.setTitle("ROM Validation Failure")
.setMessage("MD5 hash does not match!")
.setMessageType(JOptionPane.ERROR_MESSAGE)
.show();

return null;
}
}
catch (NoSuchAlgorithmException e) {
SwingUtils.showFramedMessageDialog(null,
"Missing MD5 hash algorithm, could not complete validation!",
"ROM Validation Warning",
JOptionPane.WARNING_MESSAGE);
SwingUtils.getMessageDialog()
.setTitle("ROM Validation Warning")
.setMessage("Missing MD5 hash algorithm, could not complete validation!")
.setMessageType(JOptionPane.WARNING_MESSAGE)
.show();
}

pleaseWait.setVisible(false);
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/app/StackTraceDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,19 @@ public void propertyChange(PropertyChangeEvent e)
JOptionPane.UNINITIALIZED_VALUE);

if (value.equals(OPT_DETAILS)) {
String[] options = { "OK", "Copy to Clipboard" };

JScrollPane detailScrollPane = new JScrollPane(textArea);
detailScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

int selection = SwingUtils.showFramedOptionDialog(null,
detailScrollPane,
"Exception Details",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.ERROR_MESSAGE,
Environment.ICON_ERROR,
options,
options[0]);
int choice = SwingUtils.getOptionDialog()
.setTitle("Exception Details")
.setMessage(detailScrollPane)
.setMessageType(JOptionPane.ERROR_MESSAGE)
.setOptionsType(JOptionPane.YES_NO_CANCEL_OPTION)
.setIcon(Environment.ICON_ERROR)
.setOptions("OK", "Copy to Clipboard")
.choose();

if (selection == 1) {
if (choice == 1) {
StringSelection stringSelection = new StringSelection(textArea.getText());
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
cb.setContents(stringSelection, null);
Expand Down
Loading

0 comments on commit 099dd0e

Please sign in to comment.