1818import org .eclipse .jdt .core .dom .VariableDeclaration ;
1919
2020import java .awt .Color ;
21- import java .awt .Dimension ;
2221import java .awt .EventQueue ;
2322import java .awt .GraphicsDevice ;
2423import java .awt .GraphicsEnvironment ;
@@ -648,9 +647,7 @@ public String toString() {
648647 }
649648
650649
651-
652650 private class Rename {
653-
654651 final JDialog window ;
655652 final JTextField textField ;
656653 final JLabel oldNameLabel ;
@@ -684,26 +681,28 @@ public void componentHidden(ComponentEvent e) {
684681 ps = null ;
685682 }
686683 });
687- window .setSize (250 , 130 );
684+ window .setSize (Toolkit . zoom ( 250 , 130 ) );
688685 window .setLayout (new BoxLayout (window .getContentPane (), BoxLayout .Y_AXIS ));
689686 Toolkit .setIcon (window );
690687
688+ final int b = Toolkit .zoom (5 );
689+
691690 { // Top panel
692691
693692 // Text field
694693 textField = new JTextField ();
695- textField .setPreferredSize (new Dimension (150 , 60 ));
694+ textField .setPreferredSize (Toolkit . zoom (150 , 60 ));
696695
697696 // Old name label
698697 oldNameLabel = new JLabel ();
699- oldNameLabel .setText ("Old Name: " );
698+ oldNameLabel .setText ("Current Name: " );
700699
701700 // Top panel
702701 JPanel panelTop = new JPanel ();
703702 panelTop .setLayout (new BoxLayout (panelTop , BoxLayout .Y_AXIS ));
704- panelTop .setBorder (BorderFactory .createEmptyBorder (5 , 5 , 5 , 5 ));
703+ panelTop .setBorder (BorderFactory .createEmptyBorder (b , b , b , b ));
705704 panelTop .add (textField );
706- panelTop .add (Box .createRigidArea (new Dimension (0 , 10 )));
705+ panelTop .add (Box .createRigidArea (Toolkit . zoom (0 , 10 )));
707706 panelTop .add (oldNameLabel );
708707 window .add (panelTop );
709708 }
@@ -717,28 +716,27 @@ public void componentHidden(ComponentEvent e) {
717716
718717 JButton renameButton = new JButton ("Rename" );
719718 renameButton .addActionListener (e -> {
720- if (textField .getText ().length () == 0 ) {
721- return ;
722- }
723- String newName = textField .getText ().trim ();
724- boolean isNewNameValid = newName .length () >= 1 &&
725- newName .chars ().limit (1 ).allMatch (Character ::isUnicodeIdentifierStart ) &&
726- newName .chars ().skip (1 ).allMatch (Character ::isUnicodeIdentifierPart );
727- if (!isNewNameValid ) {
728- JOptionPane .showMessageDialog (new JFrame (), "'" + newName
729- + "' isn't a valid name." , "Uh oh.." , JOptionPane .PLAIN_MESSAGE );
730- } else {
731- rename (ps , binding , newName );
732- window .setVisible (false );
719+ final String newName = textField .getText ().trim ();
720+ if (!newName .isEmpty ()) {
721+ if (newName .length () >= 1 &&
722+ newName .chars ().limit (1 ).allMatch (Character ::isUnicodeIdentifierStart ) &&
723+ newName .chars ().skip (1 ).allMatch (Character ::isUnicodeIdentifierPart )) {
724+ rename (ps , binding , newName );
725+ window .setVisible (false );
726+ } else {
727+ String msg = String .format ("'%s' is not a valid name" , newName );
728+ JOptionPane .showMessageDialog (editor , msg , "Naming is Hard" ,
729+ JOptionPane .PLAIN_MESSAGE );
730+ }
733731 }
734732 });
735733
736734 JPanel panelBottom = new JPanel ();
737735 panelBottom .setLayout (new BoxLayout (panelBottom , BoxLayout .X_AXIS ));
738- panelBottom .setBorder (BorderFactory .createEmptyBorder (5 , 5 , 5 , 5 ));
736+ panelBottom .setBorder (BorderFactory .createEmptyBorder (b , b , b , b ));
739737 panelBottom .add (Box .createHorizontalGlue ());
740738 panelBottom .add (showUsageButton );
741- panelBottom .add (Box .createRigidArea (new Dimension (15 , 0 )));
739+ panelBottom .add (Box .createRigidArea (Toolkit . zoom (15 , 0 )));
742740 panelBottom .add (renameButton );
743741 window .add (panelBottom );
744742 }
0 commit comments