Skip to content

Commit

Permalink
Hash Tool: Convert to upper/lower case
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadelessFox committed Aug 6, 2024
1 parent fdcccca commit 821f57c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ private void configureUI() {
UIManager.put("Action.splitDownIcon", new FlatSVGIcon("icons/actions/split_down.svg"));
UIManager.put("Action.splitRightIcon", new FlatSVGIcon("icons/actions/split_right.svg"));
UIManager.put("Action.starIcon", new FlatSVGIcon("icons/actions/star.svg"));
UIManager.put("Action.lowerCaseIcon", new FlatSVGIcon("icons/actions/lowercase.svg"));
UIManager.put("Action.upperCaseIcon", new FlatSVGIcon("icons/actions/uppercase.svg"));
UIManager.put("Action.undoIcon", new FlatSVGIcon("icons/actions/undo.svg"));
UIManager.put("Action.wireframeIcon", new FlatSVGIcon("icons/actions/wireframe.svg"));
UIManager.put("Action.zoomFitIcon", new FlatSVGIcon("icons/actions/zoom_fit.svg"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,35 @@ public void windowDeactivated(WindowEvent e) {
private static class ContentPanel extends JPanel {
private final List<HasherInfo> converters = new ArrayList<>();
private final JTextField inputField;
private final JToggleButton upperCaseButton;
private final JToggleButton lowerCaseButton;
private final JToggleButton nullTerminatedButton;

public ContentPanel() {
setLayout(new MigLayout("ins dialog,wrap 3", "[][grow,fill,150lp]"));
setLayout(new MigLayout("ins dialog,wrap 3", "[][grow,fill,200lp]"));

upperCaseButton = new JToggleButton(UIManager.getIcon("Action.upperCaseIcon"));
upperCaseButton.setToolTipText("Treat as uppercase");

lowerCaseButton = new JToggleButton(UIManager.getIcon("Action.lowerCaseIcon"));
lowerCaseButton.setToolTipText("Treat as lowercase");

nullTerminatedButton = new JToggleButton(UIManager.getIcon("Action.nullTerminatorIcon"));
nullTerminatedButton.setToolTipText("Null-terminated string");
nullTerminatedButton.setToolTipText("Include null terminator");

upperCaseButton.addActionListener(e -> {
lowerCaseButton.setSelected(false);
update();
});
lowerCaseButton.addActionListener(e -> {
upperCaseButton.setSelected(false);
update();
});
nullTerminatedButton.addActionListener(e -> update());

final JToolBar toolBar = new JToolBar();
toolBar.add(upperCaseButton);
toolBar.add(lowerCaseButton);
toolBar.add(nullTerminatedButton);

inputField = new JTextField();
Expand All @@ -73,6 +92,7 @@ public ContentPanel() {

add(new JLabel("Text:"));
add(inputField, "span 2");
add(new JSeparator(), "growx,span 3");

for (Hasher hasher : Hasher.availableHashers()) {
final JTextField decField = new JTextField();
Expand All @@ -92,7 +112,15 @@ public ContentPanel() {
}

private void update() {
byte[] data = inputField.getText().getBytes(StandardCharsets.UTF_8);
String text = inputField.getText();

if (upperCaseButton.isSelected()) {
text = text.toUpperCase();
} else if (lowerCaseButton.isSelected()) {
text = text.toLowerCase();
}

byte[] data = text.getBytes(StandardCharsets.UTF_8);

if (nullTerminatedButton.isSelected()) {
data = Arrays.copyOf(data, data.length + 1);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 821f57c

Please sign in to comment.