-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
conforms some variable, colortype, color names to valid tapaal format
- Loading branch information
Showing
3 changed files
with
55 additions
and
7 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,43 @@ | ||
package dk.aau.cs.util; | ||
|
||
import javax.swing.JOptionPane; | ||
import javax.swing.SwingUtilities; | ||
|
||
import pipe.gui.TAPAALGUI; | ||
|
||
public class NameConformer { | ||
private boolean hasConformed = false; | ||
|
||
/** | ||
* Conforms a string to the following regex pattern: | ||
* {@code [a-zA-Z][_a-zA-Z0-9]*} | ||
*/ | ||
public String conform(String name) { | ||
String conformedName = name; | ||
|
||
conformedName = conformedName.replaceAll("\\s+|-", "_"); | ||
conformedName = conformedName.replace("*", "star"); | ||
conformedName = conformedName.replace("/", "slash"); | ||
conformedName = conformedName.replace("+", "plus"); | ||
conformedName = conformedName.replace("-", "minus"); | ||
|
||
Require.that(conformedName.matches("[a-zA-Z][_a-zA-Z0-9]*"), "Name: " + name + " does not conform to the pattern [a-zA-Z][_a-zA-Z0-9]*, and could not be conformed automatically"); | ||
|
||
// Displays warning only once for a instance | ||
if (!hasConformed && !conformedName.equals(name)) { | ||
hasConformed = true; | ||
SwingUtilities.invokeLater(() -> { | ||
StringBuilder message = new StringBuilder(); | ||
message.append("Some names were incompatible with TAPAAL, and have\n"); | ||
message.append("been conformed to the pattern [a-zA-Z][_a-zA-Z0-9]*"); | ||
JOptionPane.showMessageDialog( | ||
TAPAALGUI.getApp(), | ||
message.toString(), | ||
"Warning", | ||
JOptionPane.WARNING_MESSAGE); | ||
}); | ||
} | ||
|
||
return conformedName; | ||
} | ||
} |