summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/gui/Gui.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/Gui.java')
-rw-r--r--src/main/java/cuchaz/enigma/gui/Gui.java38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java
index 3e85920..304b779 100644
--- a/src/main/java/cuchaz/enigma/gui/Gui.java
+++ b/src/main/java/cuchaz/enigma/gui/Gui.java
@@ -79,6 +79,8 @@ public class Gui {
79 private JList<Token> tokens; 79 private JList<Token> tokens;
80 private JTabbedPane tabs; 80 private JTabbedPane tabs;
81 81
82 public JTextField renameTextField;
83
82 public void setEditorTheme(Config.LookAndFeel feel) { 84 public void setEditorTheme(Config.LookAndFeel feel) {
83 if (editor != null && (editorFeel == null || editorFeel != feel)) { 85 if (editor != null && (editorFeel == null || editorFeel != feel)) {
84 editor.updateUI(); 86 editor.updateUI();
@@ -570,22 +572,22 @@ public class Gui {
570 public void startRename() { 572 public void startRename() {
571 573
572 // init the text box 574 // init the text box
573 final JTextField text = new JTextField(); 575 renameTextField = new JTextField();
574 576
575 EntryReference<Entry<?>, Entry<?>> translatedReference = controller.getDeobfuscator().deobfuscate(cursorReference); 577 EntryReference<Entry<?>, Entry<?>> translatedReference = controller.getDeobfuscator().deobfuscate(cursorReference);
576 text.setText(translatedReference.getNameableName()); 578 renameTextField.setText(translatedReference.getNameableName());
577 579
578 text.setPreferredSize(new Dimension(360, text.getPreferredSize().height)); 580 renameTextField.setPreferredSize(new Dimension(360, renameTextField.getPreferredSize().height));
579 text.addKeyListener(new KeyAdapter() { 581 renameTextField.addKeyListener(new KeyAdapter() {
580 @Override 582 @Override
581 public void keyPressed(KeyEvent event) { 583 public void keyPressed(KeyEvent event) {
582 switch (event.getKeyCode()) { 584 switch (event.getKeyCode()) {
583 case KeyEvent.VK_ENTER: 585 case KeyEvent.VK_ENTER:
584 finishRename(text, true); 586 finishRename(true);
585 break; 587 break;
586 588
587 case KeyEvent.VK_ESCAPE: 589 case KeyEvent.VK_ESCAPE:
588 finishRename(text, false); 590 finishRename(false);
589 break; 591 break;
590 default: 592 default:
591 break; 593 break;
@@ -596,28 +598,28 @@ public class Gui {
596 // find the label with the name and replace it with the text box 598 // find the label with the name and replace it with the text box
597 JPanel panel = (JPanel) infoPanel.getComponent(0); 599 JPanel panel = (JPanel) infoPanel.getComponent(0);
598 panel.remove(panel.getComponentCount() - 1); 600 panel.remove(panel.getComponentCount() - 1);
599 panel.add(text); 601 panel.add(renameTextField);
600 text.grabFocus(); 602 renameTextField.grabFocus();
601 603
602 int offset = text.getText().lastIndexOf('/') + 1; 604 int offset = renameTextField.getText().lastIndexOf('/') + 1;
603 // If it's a class and isn't in the default package, assume that it's deobfuscated. 605 // If it's a class and isn't in the default package, assume that it's deobfuscated.
604 if (translatedReference.getNameableEntry() instanceof ClassEntry && text.getText().contains("/") && offset != 0) 606 if (translatedReference.getNameableEntry() instanceof ClassEntry && renameTextField.getText().contains("/") && offset != 0)
605 text.select(offset, text.getText().length()); 607 renameTextField.select(offset, renameTextField.getText().length());
606 else 608 else
607 text.selectAll(); 609 renameTextField.selectAll();
608 610
609 redraw(); 611 redraw();
610 } 612 }
611 613
612 private void finishRename(JTextField text, boolean saveName) { 614 private void finishRename(boolean saveName) {
613 String newName = text.getText(); 615 String newName = renameTextField.getText();
614 if (saveName && newName != null && !newName.isEmpty()) { 616 if (saveName && newName != null && !newName.isEmpty()) {
615 try { 617 try {
616 this.controller.rename(cursorReference, newName, true); 618 this.controller.rename(cursorReference, newName, true);
617 } catch (IllegalNameException ex) { 619 } catch (IllegalNameException ex) {
618 text.setBorder(BorderFactory.createLineBorder(Color.red, 1)); 620 renameTextField.setBorder(BorderFactory.createLineBorder(Color.red, 1));
619 text.setToolTipText(ex.getReason()); 621 renameTextField.setToolTipText(ex.getReason());
620 Utils.showToolTipNow(text); 622 Utils.showToolTipNow(renameTextField);
621 } 623 }
622 return; 624 return;
623 } 625 }
@@ -627,6 +629,8 @@ public class Gui {
627 panel.remove(panel.getComponentCount() - 1); 629 panel.remove(panel.getComponentCount() - 1);
628 panel.add(Utils.unboldLabel(new JLabel(cursorReference.getNameableName(), JLabel.LEFT))); 630 panel.add(Utils.unboldLabel(new JLabel(cursorReference.getNameableName(), JLabel.LEFT)));
629 631
632 renameTextField = null;
633
630 this.editor.grabFocus(); 634 this.editor.grabFocus();
631 635
632 redraw(); 636 redraw();