Skip to content

Commit e2b1c38

Browse files
committed
fix rename dialog scaling for high density (fixes processing#5368)
1 parent f442e3f commit e2b1c38

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

java/src/processing/mode/java/pdex/PDEX.java

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.eclipse.jdt.core.dom.VariableDeclaration;
1919

2020
import java.awt.Color;
21-
import java.awt.Dimension;
2221
import java.awt.EventQueue;
2322
import java.awt.GraphicsDevice;
2423
import 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
}

todo.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ X include newlines at end of files (i.e. when saving .pde files)
1212
X https://github.com/processing/processing/issues/5327
1313
X explanation: https://stackoverflow.com/a/729795
1414
X http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
15+
X Rename dialog is unusable on high density screen
16+
X https://github.com/processing/processing/issues/5368
1517

1618
jakub
1719
X Fix scrub comments for empty block comment /**/
@@ -58,8 +60,6 @@ _ https://github.com/processing/processing/issues/3911
5860

5961
_ windows defender blocks processing 3.3.6
6062
_ https://github.com/processing/processing/issues/5329
61-
_ Rename dialog is unusable on high density screen
62-
_ https://github.com/processing/processing/issues/5368
6363
_ Manager fails to complete install of PythonMode when no windows open
6464
_ https://github.com/processing/processing/issues/5309
6565
_ update to launch4j 3.11?

0 commit comments

Comments
 (0)